repl-core
Core REPL engine for the Symbiont agent framework. Provides DSL evaluation, agent lifecycle management, and execution monitoring capabilities.
Features
- DSL Evaluation: Execute Symbiont DSL programs with runtime integration
- Agent Management: Create, start, stop, pause, resume, and destroy agents
- Execution Monitoring: Real-time monitoring with statistics and tracing
- Policy Enforcement: Capability checking and security policy integration
- Session Management: Snapshot and restore functionality
- Built-in Functions: Standard library of DSL functions
Architecture
repl-core/
├── src/
│ ├── dsl/ # DSL implementation
│ │ ├── ast.rs # Abstract syntax tree definitions
│ │ ├── lexer.rs # Lexical analysis
│ │ ├── parser.rs # Parser implementation
│ │ ├── evaluator.rs # DSL evaluator with runtime integration
│ │ └── mod.rs # DSL module exports
│ ├── execution_monitor.rs # Execution monitoring and tracing
│ ├── eval.rs # REPL evaluation engine
│ ├── error.rs # Error handling
│ ├── runtime_bridge.rs # Runtime system integration
│ ├── session.rs # Session management
│ └── lib.rs # Library exports
└── tests/
└── golden.rs # Golden tests for parser
Usage
use ;
use Arc;
async
DSL Components
AST (Abstract Syntax Tree)
The AST module defines the structure of parsed DSL programs:
- Agents: Agent definitions with metadata and security requirements
- Behaviors: Executable behavior definitions with input/output types
- Functions: User-defined functions with parameters and bodies
- Expressions: Literals, identifiers, function calls, operations
- Statements: Control flow, variable assignments, requirements
Lexer
The lexer converts source text into tokens:
- Keywords (
agent,behavior,function,let,if, etc.) - Identifiers and literals (strings, numbers, booleans)
- Operators and punctuation
- Duration and size literals (
30s,100MB) - Comments (single-line and multi-line)
Parser
The parser builds an AST from tokens using recursive descent parsing:
- Agent definitions with nested blocks
- Function and behavior definitions
- Expression parsing with operator precedence
- Error recovery and reporting
Evaluator
The evaluator executes parsed DSL programs:
- Agent Lifecycle: Create, start, stop, pause, resume, destroy
- Policy Enforcement: Capability checking via runtime bridge
- Built-in Functions:
print,len,upper,lower,format - Execution Context: Variable scoping and function definitions
- Monitoring Integration: Execution tracing and statistics
Built-in Functions
| Function | Description | Example |
|---|---|---|
print(...) |
Print values to output | print("Hello", name) |
len(value) |
Get length of string, list, or map | len("hello") → 5 |
upper(string) |
Convert string to uppercase | upper("hello") → "HELLO" |
lower(string) |
Convert string to lowercase | lower("HELLO") → "hello" |
format(template, ...) |
Format string with arguments | format("Hello, {}!", name) |
Execution Monitoring
The execution monitor provides comprehensive tracking:
use ExecutionMonitor;
let monitor = new;
// Get execution statistics
let stats = monitor.get_stats;
println!;
println!;
// Get recent traces
let traces = monitor.get_traces;
for trace in traces
Trace Events
AgentCreated- Agent instance createdAgentStarted- Agent started executionAgentPaused- Agent pausedAgentResumed- Agent resumed from pauseAgentDestroyed- Agent destroyedBehaviorExecuted- Agent behavior executedExecutionStarted- Function execution startedExecutionCompleted- Function execution completed
Security & Policy
The REPL core integrates with the Symbiont runtime for security:
// Capability checking
if !evaluator.check_capability.await?
// Policy enforcement
let decision = runtime_bridge.check_capability.await?;
match decision
Error Handling
The ReplError enum covers all error conditions:
Testing
Run the test suite:
# Run all tests
# Run specific test categories
# Run golden tests
Dependencies
tokio- Async runtimeserde- Serialization frameworkserde_json- JSON supportuuid- UUID generationchrono- Date/time handlingtracing- Structured loggingsymbi-runtime- Runtime system integration
See Also
repl-cli- CLI interface and JSON-RPC serverrepl-proto- Protocol definitionsrepl-lsp- Language Server Protocol implementation- REPL Guide - Complete user guide