This document is a reference plan rewritten from the code that exists today.
It answers two questions:
- what has actually been implemented in this plugin
- what implementation plan we would have written if we were planning toward the current design from the start
Build an OpenCode-native workflow plugin that can:
- create and persist a scoped planning session
- turn a goal into a structured feature plan
- approve or narrow that plan before execution
- execute one feature at a time
- require validation evidence before a feature can complete
- require reviewer approval before a feature or full session can advance
- support autonomous plan, run, review, and replan loops
- expose status and reset flows through runtime tools and slash commands
- persist durable state and readable markdown artifacts under
.flow/
The plugin is a small TypeScript package built with Bun:
package.jsontsconfig.jsonsrc/index.tssrc/config.tssrc/tools.tssrc/runtime/src/prompts/tests/
The entrypoint in src/index.ts exports a plugin that registers:
- a
confighook - a Flow tool surface
The config hook in src/config.ts injects five agents:
flow-plannerflow-workerflow-autoflow-reviewerflow-control
It also injects seven slash commands:
/flow-plan/flow-run/flow-auto/flow-status/flow-history/flow-session/flow-reset
This is unconditional config injection. There is no workspace-detection gate in the current implementation.
The canonical session artifact is:
.flow/active.flow/sessions/<session-id>/session.json
The plugin also renders derived markdown artifacts on every save:
.flow/sessions/<session-id>/docs/index.md.flow/sessions/<session-id>/docs/features/<feature-id>.md
State is loaded and saved through src/runtime/session.ts, with paths defined in src/runtime/paths.ts.
The runtime schema in src/runtime/schema.ts implements a single active session with:
versionidgoalstatusapprovalplanningplanexecutionnotesartifactstimestamps
The planning model includes:
- plan summary and overview
- requirements
- architecture decisions
- ordered features
- goal mode
- decomposition policy
- completion policy
- planning context such as repo profile, research, and implementation approach
The execution model includes:
- active feature tracking
- last outcome, next step, and validation run
- last reviewer decision
- last feature result
- execution history
The tool runtime in src/tools.ts currently exposes:
flow_statusflow_historyflow_history_showflow_auto_prepareflow_plan_startflow_plan_applyflow_plan_approveflow_plan_select_featuresflow_run_startflow_run_complete_featureflow_review_record_featureflow_review_record_finalflow_session_activateflow_reset_featureflow_reset_session
Compared with the earlier plan, the implemented runtime is stricter and more complete because reviewer decisions are first-class state transitions.
The transition engine in src/runtime/transitions/ enforces:
- plan schema validation through Zod
- feature dependency and blocker graph validation
- duplicate and cyclic dependency rejection
- plan narrowing only while the plan is still a draft
- plan approval only before execution starts
- one active feature at a time
- runnable feature selection based on dependencies and blockers
- replan flow when a worker returns
replan_required - blocked flow when a worker returns a blocking outcome
- dependency-aware feature reset that also resets downstream dependents
This is a major implemented behavior and should be part of any accurate plan.
A feature cannot complete successfully unless:
- validation evidence is present
- validation passes fully
- a reviewer decision has already been recorded
- the reviewer decision is approved for the active scope
featureReviewis passing
The final completion path is stricter. When the last feature completes, the runtime also requires:
validationScope: broad- a recorded final reviewer decision through
flow_review_record_final - a passing
finalReview
This means the plugin does not treat review as advisory text. Review is a persisted workflow gate.
The current runtime also returns structured recovery metadata for retryable failures.
That recovery metadata includes:
errorCoderesolutionHintrecoveryStageprerequisite- optional
requiredArtifact nextCommand- optional
nextRuntimeTool - optional
nextRuntimeArgs
This matters because the implemented system now distinguishes between:
- failures blocked on missing prerequisites such as reviewer decisions or validation reruns
- failures that have an immediately executable next step such as
flow_reset_feature
Blocked session summaries also became smarter. When the latest blocked outcome is retryable or auto-resolvable and does not require human input, the runtime now points the next command back to /flow-reset feature <id> instead of stopping at /flow-status.
The prompt layer in src/prompts/agents.ts defines clear roles:
flow-planner: read-only planning agentflow-worker: single-feature execution agentflow-auto: autonomous orchestration agentflow-reviewer: read-only approval gate for feature and final reviewflow-control: status and reset agent only
Notable implemented constraints:
- planner, reviewer, and control agents are explicitly read-only
- worker must not complete work while findings remain
- autonomous flow must keep looping through fix, validate, and review until clean or truly blocked
- final completion requires broad validation and final cross-feature review
- autonomous recovery must satisfy structured prerequisites before using any runtime recovery action
The command templates in src/prompts/commands.ts implement the user-facing workflow:
/flow-plansupports draft creation, feature selection, and approval from arguments/flow-runexecutes exactly one approved feature/flow-autoruns plan, approval, execution, review, and replanning autonomously/flow-statusreads runtime state only/flow-historyreads current and archived session history, and can inspect one stored session by id/flow-sessionrepoints the active session pointer to a stored session id/flow-resetresets a feature or archives the active session
The current autonomous contract is also intentionally strict about empty-input behavior:
- empty
/flow-autois resume-only - empty
/flow-autowith no active session must stop and request a goal - completed sessions are not resumable in that path
- the autonomous agent must not invent a new goal from repository inspection in that path
- a dedicated
flow_auto_prepareruntime tool now gates that decision before planning starts
The current implementation did not stop at JSON-only summaries.
src/runtime/render.ts renders:
- a session index document with plan, status, next command, notes, artifacts, validation, reviewer state, and history
- per-feature documents with summaries, file targets, verification, dependencies, and execution history
Markdown rendering also normalizes multiline content to avoid malformed docs.
The current test suite covers both configuration and runtime behavior.
tests/config.test.ts covers:
- command and agent injection
- read-only agent configuration
- tool arg-shape compatibility
- prompt and contract expectations for worker, reviewer, and autonomous flows
tests/runtime.test.ts covers:
- session creation, save, and load
- markdown doc rendering
- plan apply, select, and approve flows
- feature start and completion flows
- reviewer recording behavior
- blocked and replan-required outcomes
- final-review completion rules
- reset behavior
- prerequisite-aware recovery metadata for review, validation, payload, and reset failures
If we reduce the implemented design to its core architectural decisions, it is this:
- Build a TypeScript plugin package.
- Use the plugin
confighook to inject commands and agents. - Make Flow tools the only authoritative state transition layer.
- Keep one active durable session pointer in
.flow/activeand store run history under.flow/sessions/<session-id>/session.json. - Treat planning, execution, review, and reset as explicit runtime transitions.
- Keep slash commands prompt-driven, but always tool-backed.
- Require persisted reviewer decisions before successful completion.
- Render markdown docs as derived artifacts for human inspection.
- Keep autonomous execution inside OpenCode's agent model rather than a terminal-owned loop.
If we were planning toward the current implementation from scratch, this is the plan we would write.
- create
package.json,tsconfig.json, andsrc/index.ts - set up Bun build, test, and typecheck scripts
- export a plugin that wires config injection and custom tools
- add a config hook in
src/config.ts - inject planner, worker, auto, reviewer, and control agents
- inject
/flow-plan,/flow-run,/flow-auto,/flow-status,/flow-history,/flow-session, and/flow-reset - lock planner, reviewer, and control to read-only tool permissions
- create Zod schemas for sessions, plans, features, worker results, and reviewer decisions
- persist the active session under
.flow/sessions/<session-id>/session.jsonand track it via.flow/active - create session load, save, create, and delete helpers
- define runtime path helpers for session and docs artifacts
- implement
flow_plan_start - implement
flow_plan_apply - implement
flow_plan_select_features - implement
flow_plan_approve - validate feature ids, dependency graphs, and selection consistency
- store planning context such as repo profile, research, and implementation approach
- implement
flow_run_start - select the next runnable feature from dependency-aware plan state
- enforce single active feature execution
- implement
flow_run_complete_feature - support successful completion, replanning, and blocked outcomes
- record artifacts, notes, validation runs, and execution history
- add reviewer decision schema and persistence
- implement
flow_review_record_feature - implement
flow_review_record_final - require recorded approval before successful feature completion
- require broad validation and final review on session completion
- add typed recovery metadata to transition failures
- distinguish missing prerequisites from executable next actions
- keep user-facing
nextCommandvalid even when no runtime action is yet possible - expose runtime reset actions only when they are actually executable
- make blocked session summaries point back into recovery when the outcome is retryable
- implement
flow_status - implement
flow_history - implement
flow_history_show - implement
flow_session_activate - implement
flow_reset_feature - implement
flow_reset_session - make feature reset dependency-aware so downstream work returns to pending when needed
- render
.flow/sessions/<session-id>/docs/index.md - render
.flow/sessions/<session-id>/docs/features/<feature-id>.md - include summary, feature progress, validation evidence, reviewer decisions, and history
- prune stale feature docs after plan changes
- define plan, worker, and reviewer contracts in prompts
- make planner produce compact structured plans
- make worker operate on exactly one feature
- make reviewer return
approved,needs_fix, orblocked - encode autonomous review and fix loops in the auto prompt
- encode prerequisite-aware recovery handling in the auto prompt so structured runtime errors lead back into execution instead of stopping
- test config injection and permissions
- test raw tool arg shapes
- test session persistence and doc rendering
- test planning and approval transitions
- test execution and review gating
- test replan-required and blocked outcomes
- test final-review completion rules
- test reset behavior
Implemented now:
- plugin scaffold and build pipeline
- config-driven command and agent injection
- single-session durable runtime
- planning and execution transition tools
- explicit reviewer and final-review tools
- autonomous prompt-driven loop design
- prerequisite-aware structured recovery metadata on transition failures
- status and reset flows
- derived markdown docs
- transition and prompt tests
Not implemented in the current codebase:
- multi-session support
- conditional activation based on workspace detection
- additional hooks beyond
config - external notifications
- history archives outside the session artifact
- tools own runtime state transitions
- one active pointer with retained session history is enough for v1
- one active feature at a time keeps execution deterministic
- review approval is persisted, not implied
- final completion requires broader validation than normal feature work
- replanning is a normal path, not a failure mode
- runtime recovery should distinguish missing prerequisites from executable next actions
- markdown docs are derived artifacts, not the source of truth
- autonomy stays inside OpenCode's native agent model
Use this document as the reference implementation plan for the plugin as-built.
It reflects the current codebase more accurately than the original draft because it captures the parts that turned out to matter most in implementation: strict transition ownership in tools, persisted reviewer gates, final-review completion rules, and derived session docs beside .flow/sessions/<session-id>/session.json.