Documentation
¶
Overview ¶
Package repl provides the Effects Inspector for introspecting types and effects.
Package repl provides planning commands for the REPL.
Index ¶
- func CreateExamplePlan() (string, error)
- func EffectsCommand(input string) error
- func ParseProposeCommand(input string) (string, error)
- func ParseScaffoldCommand(input string) (planFile, outputDir string, overwrite bool, err error)
- func PrintPlanHelp()
- func ProposePlanCommand(filename string) error
- func SaveExamplePlan(filename string) error
- func ScaffoldCommand(planFile, outputDir string, overwrite bool) error
- func ValidatePlanJSON(jsonData []byte) error
- type CachedConstructor
- type Config
- type EffectsResult
- type Export
- type ModuleRegistry
- func (mr *ModuleRegistry) CallExport(moduleName, funcName string, args []eval.Value) (string, error)
- func (mr *ModuleRegistry) GetExport(moduleName, funcName string) (*Export, error)
- func (mr *ModuleRegistry) GetModule(name string) (*RegisteredModule, bool)
- func (mr *ModuleRegistry) InvokeExport(moduleName, funcName string, args []eval.Value) (eval.Value, error)
- func (mr *ModuleRegistry) ListModules() []string
- func (mr *ModuleRegistry) LoadModule(name, sourceCode string) ([]string, error)
- func (mr *ModuleRegistry) SetEffContext(ctx *effects.EffContext)
- type REPL
- func (r *REPL) ApplyClosure(fn eval.Value, args []eval.Value) (eval.Value, error)
- func (r *REPL) EnableTrace()
- func (r *REPL) GetEffContext() *effects.EffContext
- func (r *REPL) GetRegistry() *ModuleRegistry
- func (r *REPL) GrantCapability(name string)
- func (r *REPL) HandleCommand(cmd string, out io.Writer)
- func (r *REPL) ProcessExpression(input string, out io.Writer)
- func (r *REPL) SetAIHandler(handler effects.AIHandler)
- func (r *REPL) SetRegistry(reg *ModuleRegistry)
- func (r *REPL) SetStrictSyntaxMode(strict bool)
- func (r *REPL) Start(in io.Reader, out io.Writer)
- func (r *REPL) StartWithContext(ctx context.Context, in io.Reader, out io.Writer)
- type RegisteredModule
- type RegistryResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateExamplePlan ¶
CreateExamplePlan creates an example plan and returns it as JSON
func EffectsCommand ¶
EffectsCommand implements the :effects REPL command For now, this is a placeholder that will be implemented once we have proper effect tracking in the type system
func ParseProposeCommand ¶
ParseProposeCommand parses the :propose command arguments Format: :propose <filename.json>
func ParseScaffoldCommand ¶
ParseScaffoldCommand parses the :scaffold command arguments Format: :scaffold --from-plan <plan.json> [--output <dir>] [--overwrite]
func ProposePlanCommand ¶
ProposePlanCommand validates a plan file and prints the result
func SaveExamplePlan ¶
SaveExamplePlan saves an example plan to a file
func ScaffoldCommand ¶
ScaffoldCommand generates code from a plan file
func ValidatePlanJSON ¶
ValidatePlanJSON validates raw JSON against the plan schema
Types ¶
type CachedConstructor ¶
type CachedConstructor struct {
TypeName string
CtorName string
Arity int
TypeParamCount int
TypeParamNames []string
FieldTypes []types.Type
}
CachedConstructor stores constructor info for cross-module import resolution
type Config ¶
type Config struct {
TraceDefaulting bool
ShowCore bool
ShowTyped bool
DryLink bool
Verbose bool
StrictSyntaxMode bool
ImportedModules []string
}
Config holds REPL configuration
type EffectsResult ¶
type EffectsResult struct {
Schema string `json:"schema"`
Type string `json:"type"`
Effects []string `json:"effects"`
Decisions []any `json:"decisions,omitempty"` // from ledger slice when defaulting occurs
}
EffectsResult represents the result of effects introspection
type Export ¶
type Export struct {
Name string // Export name
Value interface{} // Evaluated value (closure, constant, etc.)
Scheme *types.Scheme // Type signature for type checking
}
Export represents a single exported function or value from a module.
type ModuleRegistry ¶
type ModuleRegistry struct {
// contains filtered or unexported fields
}
ModuleRegistry stores compiled modules for REPL access. It enables loading AILANG modules in the browser via ailangLoadModule() and makes their exports available for subsequent ailangEval() calls.
func NewModuleRegistry ¶
func NewModuleRegistry() *ModuleRegistry
NewModuleRegistry creates an empty module registry.
func (*ModuleRegistry) CallExport ¶
func (mr *ModuleRegistry) CallExport(moduleName, funcName string, args []eval.Value) (string, error)
CallExport formats a function call expression string for use with the REPL. This returns the expression that can be evaluated via ProcessExpression. Arguments are converted to their AILANG string representation.
func (*ModuleRegistry) GetExport ¶
func (mr *ModuleRegistry) GetExport(moduleName, funcName string) (*Export, error)
GetExport retrieves a specific export from a loaded module.
func (*ModuleRegistry) GetModule ¶
func (mr *ModuleRegistry) GetModule(name string) (*RegisteredModule, bool)
GetModule retrieves a loaded module by name.
func (*ModuleRegistry) InvokeExport ¶
func (mr *ModuleRegistry) InvokeExport(moduleName, funcName string, args []eval.Value) (eval.Value, error)
InvokeExport calls an exported function directly with the provided arguments. This method bypasses REPL string evaluation and calls the function closure directly, ensuring that captured imports (like decode, encode from std/json) are properly resolved from the function's environment.
Returns the result value and any error that occurred during execution.
func (*ModuleRegistry) ListModules ¶
func (mr *ModuleRegistry) ListModules() []string
ListModules returns the names of all loaded modules.
func (*ModuleRegistry) LoadModule ¶
func (mr *ModuleRegistry) LoadModule(name, sourceCode string) ([]string, error)
LoadModule compiles and registers a module from source code. Returns the list of exported names on success.
func (*ModuleRegistry) SetEffContext ¶
func (mr *ModuleRegistry) SetEffContext(ctx *effects.EffContext)
SetEffContext sets the shared effect context used by InvokeExport. This allows WASM-configured effect handlers (AI, IO, etc.) to be available when calling module exports.
type REPL ¶
type REPL struct {
// contains filtered or unexported fields
}
REPL represents the Read-Eval-Print Loop
func NewWithVersion ¶
NewWithVersion creates a new REPL with version info
func (*REPL) ApplyClosure ¶
ApplyClosure invokes an AILANG closure (FunctionValue) with the given arguments. For multi-arg closures, it applies arguments one at a time (curried application). This is used by the WASM bridge to invoke AILANG callbacks from JavaScript.
M-WASM-CLOSURE-ENV: When the REPL has a ModuleRegistry, ApplyClosure creates an evaluator with a RegistryResolver so that cross-module VarGlobal references (imported functions) resolve correctly. Without this, only same-module Var references work (via the closure's captured env chain).
func (*REPL) GetEffContext ¶
func (r *REPL) GetEffContext() *effects.EffContext
GetEffContext returns the effect context for external configuration (used by WASM)
func (*REPL) GetRegistry ¶
func (r *REPL) GetRegistry() *ModuleRegistry
GetRegistry returns the module registry (nil if not set)
func (*REPL) GrantCapability ¶
GrantCapability grants a named capability to the effect context
func (*REPL) HandleCommand ¶
HandleCommand processes REPL commands (exported for WASM)
func (*REPL) ProcessExpression ¶
ProcessExpression runs an expression through the full pipeline (exported for WASM)
func (*REPL) SetAIHandler ¶
SetAIHandler configures the AI effect handler and grants the AI capability
func (*REPL) SetRegistry ¶
func (r *REPL) SetRegistry(reg *ModuleRegistry)
SetRegistry sets the module registry for import resolution (used by WASM)
func (*REPL) SetStrictSyntaxMode ¶
SetStrictSyntaxMode enables or disables strict syntax mode
type RegisteredModule ¶
type RegisteredModule struct {
Name string // Module name (e.g., "invoice_processor")
Source string // Original source code
Exports map[string]*Export // Exported functions and values
}
RegisteredModule represents a compiled and evaluated AILANG module.
type RegistryResolver ¶
type RegistryResolver struct {
// contains filtered or unexported fields
}
RegistryResolver resolves global references for module evaluation in WASM. It resolves: 1. Builtin functions ($builtin module or names starting with _) 2. ADT constructor factories ($adt module) 3. Exports from previously loaded modules
func NewRegistryResolver ¶
func NewRegistryResolver(registry *ModuleRegistry, builtins *runtime.BuiltinRegistry) *RegistryResolver
NewRegistryResolver creates a resolver that can access the module registry
func (*RegistryResolver) ResolveValue ¶
ResolveValue resolves a global reference to a runtime value