How afloresc/opencode-lite works
Purpose and Entry Point
This is a Go CLI implementing an autonomous, project-scoped cognitive agent runtime. It accepts a goal, plans and grounds work into filesystem/code operations within workspace/, monitors execution, and adapts future behavior through persistent memory. Process startup is cmd/cli/main.go; configuration is centralized in internal/config/config.go.
Runtime Orchestration
AgentRuntime is the core control loop: it executes goals, invokes planning and tools, captures results, and feeds observations into monitoring and adaptive subsystems. Agent context and shared contracts define the boundaries among stages.
Paths: internal/agent/runtime.go, internal/agent/context.go, internal/agent/interfaces.go.
Goal Routing and Specialized Agents
A supervisor/classifier selects or biases execution toward specialized analysis, refactoring, or documentation agents. These agents expose a common interface and delegate actual execution back to the shared runtime, preserving one execution path while allowing goal-specific policy.
Paths: internal/agent/supervisor.go, internal/agent/goal_classifier.go, internal/agent/analysis_agent.go, internal/agent/refactor_agent.go, internal/agent/docs_agent.go.
Hybrid Planning and Step Expansion
The planner combines deterministic rules, LLM-derived reasoning, and planner memory to produce executable steps. Step expansion/mapping transforms broad plans into operations, filters historically failing work, and supports planner modes such as coarse, fine, aggressive, and conservative.
Paths: internal/agent/planner.go, internal/agent/master_planner.go, internal/agent/planner_rules.go, internal/agent/step_expander.go, internal/agent/step_mapper.go.
Tool Grounding and Execution Boundary
The contextual grounder maps abstract plan steps to registered concrete tools, using strict or flexible selection modes and project context. Tools are the safety boundary for workspace interaction: filesystem changes, search, patches/refactors, formatting, analysis, and sandbox command dispatch all reside behind the tool package.
Paths: internal/agent/tool_grounder.go, internal/agent/tool_grounder_contextual.go, internal/tools/registry.go, internal/tools/filesystem.go, internal/tools/patches.go, internal/tools/run_command_dispatch.go.
Feedback, Memory, and Self-Optimization
Execution monitoring detects repeats, consecutive failures, and stalled output. Metacognition evaluates those signals and provides confidence/advice; the strategy engine adjusts planner/grounder modes and tool or agent bias. Cognitive and planner memory persist project-specific outcomes, while AOC records longer-term optimization preferences.
Paths: internal/agent/execution_monitor.go, internal/agent/metacognition.go, internal/agent/strategy_engine.go, internal/agent/cognitive_memory.go, internal/agent/planner_memory.go, internal/agent/aoc.go.
LLM and Infrastructure Integration
The runtime has an LLM client/prompt boundary with an Ollama provider implementation, making local Ollama the identified model-service integration. Persistent cognitive state is stored under .opencode/<projectID>/; mutable target content is constrained to workspace/. The system runs as a Go binary and uses local command/file operations rather than a web service.
Paths: internal/agent/llm_client.go, internal/agent/llm_prompt.go, internal/providers/ollama.go, internal/runtime/runtime.go, internal/runtime/system_prompt.go.
Main entry points: agent/runtime.go Agent runtime · planner.go Hybrid planner · strategy_engine.go Strategy engine · runtime/runtime.go Runtime host
Components 19
CLI & Runtime
- Go CLI entrypoint
cmd/cli/main.go - Configuration
internal/config/config.go - Runtime host
internal/runtime/runtime.go
Agent Control Loop
- Agent runtime · Executes goals and coordinates planning, tools, and feedback.
internal/agent/runtime.go - Agent context & contracts
internal/agent/interfaces.go - Supervisor & classifier
internal/agent/supervisor.go - Specialized agents · Analysis, refactor, and documentation policies share the execution path.
internal/agent/analysis_agent.go
Planning & Grounding
- Hybrid planner · Combines rules, LLM reasoning, and planner memory.
internal/agent/planner.go - Step expansion & mapping · Converts broad plans to operations and filters failing work.
internal/agent/step_expander.go - Contextual tool grounder · Maps plan operations to concrete tools under selection modes.
internal/agent/tool_grounder_contextual.go
Feedback & Adaptation
- Execution monitor · Detects repeats, failures, and stalled output.
internal/agent/execution_monitor.go - Metacognition
internal/agent/metacognition.go - Strategy engine · Adjusts planner, grounder, tool, and agent bias.
internal/agent/strategy_engine.go - Cognitive & planner memory · Stores project outcomes and planning history.
internal/agent/cognitive_memory.go - AOC preferences · Records longer-term optimization preferences.
internal/agent/aoc.go
Execution & Model
- Tool registry · Registered tools constrain workspace interaction.
internal/tools/registry.go - Workspace & command tools · Filesystem, patching, and sandbox command dispatch.
internal/tools/filesystem.go - LLM client & prompts
internal/agent/llm_client.go - Ollama provider
internal/providers/ollama.go
Connections 23
- Go CLI entrypoint → Runtime host: starts
- Configuration → Runtime host: configures
- Runtime host → Agent runtime: hosts
- Agent context & contracts → Agent runtime: defines context
- Agent runtime → Supervisor & classifier: routes goal
- Supervisor & classifier → Specialized agents: selects policy
- Specialized agents → Agent runtime: delegates execution
- Agent runtime → Hybrid planner: requests plan
- Hybrid planner → Step expansion & mapping: produces steps
- Step expansion & mapping → Contextual tool grounder: maps operations
- Contextual tool grounder → Tool registry: selects tools
- Tool registry → Workspace & command tools: dispatches
- Workspace & command tools → Agent runtime: returns results
- Agent runtime → Execution monitor: emits execution signals
- Execution monitor → Metacognition: reports signals
- Metacognition → Strategy engine: advice & confidence
- Strategy engine → Hybrid planner: adjusts modes
- Strategy engine → Contextual tool grounder: adjusts selection
- Agent runtime → Cognitive & planner memory: records outcomes
- Cognitive & planner memory → Hybrid planner: supplies history
- AOC preferences → Strategy engine: optimization preferences
- Hybrid planner → LLM client & prompts: requests reasoning
- LLM client & prompts → Ollama provider: uses