This file is for contributors working on the plugin itself.
If you are trying to use Flow inside OpenCode, start with the top-level README.md instead.
Install dependencies and run the full local check:
bun install
bun run checkUseful scripts:
bun run buildbun run deadcodebun run testbun run typecheckbun run checkbun run install:opencodebun run uninstall:opencode
src/index.ts— plugin entrypointsrc/installer.ts— local OpenCode plugin installersrc/config.ts— command and agent injectionsrc/tools.ts— OpenCode runtime tool surfacesrc/runtime/schema.ts— session and contract schemassrc/runtime/transitions/— domain state transition rules split by lifecycle phasesrc/runtime/domain/completion.ts— shared completion-policy calculationssrc/runtime/application/tool-runtime.ts— application-level tool orchestration helperssrc/runtime/session.ts— persistence and lifecycle exportssrc/runtime/render.ts— derived markdown renderingsrc/prompts/agents.ts— agent instructionssrc/prompts/commands.ts— slash-command templates
Flow is built around a small set of responsibilities:
- A plugin
confighook injects commands and agents. - Runtime tools are adapter entrypoints and delegate to application/domain runtime helpers.
- Session state is stored under
.flow/sessions/<session-id>/session.jsonwith.flow/activepointing at the current run. - Domain transitions remain authoritative for workflow state changes.
- Prompted agents call runtime tools instead of mutating state directly.
- Readable markdown docs are rendered beside each saved session under
.flow/sessions/<session-id>/docs/.
flow-plannerflow-workerflow-autoflow-reviewerflow-control
flow-plannerreads the repo and creates a compact execution-ready planflow-workerexecutes exactly one approved featureflow-reviewerreviews feature-level or final cross-feature stateflow-autocoordinates planning, execution, review, recovery, and continuationflow-controlhandles status/history/session/reset requests only
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
Retryable runtime failures can include structured recovery metadata alongside the error summary.
That metadata can include:
errorCoderesolutionHintrecoveryStageprerequisite- optional
requiredArtifact nextCommand- optional
nextRuntimeTool - optional
nextRuntimeArgs
The runtime uses this to distinguish between:
- missing prerequisites
- immediately executable recovery actions
Examples:
- missing reviewer approval reports a
reviewer_result_requiredprerequisite - missing validation scope or evidence reports
validation_rerun_required - missing final review payload reports
completion_payload_rebuild_required - failing review or validation can point directly to
flow_reset_feature
Keep Flow prompts narrow and stable. Prefer platform-native efficiency controls before adding plugin-specific machinery:
- keep orchestration prompts focused on routing and recovery, not duplicated workflow narration
- enable OpenCode compaction and provider cache keys when sessions get long
- treat
experimental.session.compactingas optional escalation only if there is real evidence of Flow state loss - avoid introducing Flow-owned compaction or measurement plumbing unless a concrete failure mode justifies it
OpenCode plugin tools expect args to be provided as a raw Zod shape, not a top-level schema object.
Example:
const FlowRunStartArgsShape = {
featureId: z.string().optional(),
};This plugin uses two validation layers:
- SDK-facing tool
argsstay as raw shapes for OpenCode compatibility - stricter runtime validation happens later through schemas such as
WorkerResultSchema
The test suite covers:
- command and agent injection
- tool argument shape compatibility
- session creation, save, and load
- markdown doc rendering
- plan application, selection, and approval
- feature execution and reviewer gating
- blocked and replan-required outcomes
- final-review completion rules
- reset behavior
- prerequisite-aware recovery metadata and autonomous recovery behavior
Run tests with:
bun test