Skip to content

Commit 0645ffc

Browse files
committed
Harden Flow runtime boundaries to reduce contract drift and cleanup overhead
This cutover consolidates tool/runtime boundary handling, removes obsolete adapter/helper layers, and centralizes completion/time logic so summary, rendering, and transition behavior stay aligned under one domain model. Constraint: OpenCode tool arg surfaces must remain SDK-compatible while runtime validation remains authoritative Rejected: Keep adapter shim layer | duplicated boundary logic and slower cleanup convergence Confidence: high Scope-risk: moderate Reversibility: clean Directive: Keep transitions return-value based; avoid introducing throw-driven control flow in domain transitions Tested: bun run check (typecheck + deadcode + tests + build) Not-tested: External OpenCode host integration with tool calls outside repository tests
1 parent 96676a3 commit 0645ffc

35 files changed

Lines changed: 825 additions & 429 deletions

bun.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/development.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bun run check
1616
Useful scripts:
1717

1818
- `bun run build`
19+
- `bun run deadcode`
1920
- `bun run test`
2021
- `bun run typecheck`
2122
- `bun run check`
@@ -27,10 +28,12 @@ Useful scripts:
2728
- `src/index.ts` — plugin entrypoint
2829
- `src/installer.ts` — local OpenCode plugin installer
2930
- `src/config.ts` — command and agent injection
30-
- `src/tools.ts` — runtime tool surface
31+
- `src/tools.ts`OpenCode runtime tool surface
3132
- `src/runtime/schema.ts` — session and contract schemas
32-
- `src/runtime/transitions/` — state transition rules split by lifecycle phase
33-
- `src/runtime/session.ts` — load and save helpers
33+
- `src/runtime/transitions/` — domain state transition rules split by lifecycle phase
34+
- `src/runtime/domain/completion.ts` — shared completion-policy calculations
35+
- `src/runtime/application/tool-runtime.ts` — application-level tool orchestration helpers
36+
- `src/runtime/session.ts` — persistence and lifecycle exports
3437
- `src/runtime/render.ts` — derived markdown rendering
3538
- `src/prompts/agents.ts` — agent instructions
3639
- `src/prompts/commands.ts` — slash-command templates
@@ -40,10 +43,11 @@ Useful scripts:
4043
Flow is built around a small set of responsibilities:
4144

4245
1. A plugin `config` hook injects commands and agents.
43-
2. Runtime tools own all state transitions.
46+
2. Runtime tools are adapter entrypoints and delegate to application/domain runtime helpers.
4447
3. Session state is stored under `.flow/sessions/<session-id>/session.json` with `.flow/active` pointing at the current run.
45-
4. Prompted agents call runtime tools instead of mutating state directly.
46-
5. Readable markdown docs are rendered beside each saved session under `.flow/sessions/<session-id>/docs/`.
48+
4. Domain transitions remain authoritative for workflow state changes.
49+
5. Prompted agents call runtime tools instead of mutating state directly.
50+
6. Readable markdown docs are rendered beside each saved session under `.flow/sessions/<session-id>/docs/`.
4751

4852
## Current Agent Roles
4953

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
],
1010
"scripts": {
1111
"build": "bun build ./src/index.ts --outfile ./dist/index.js --target node",
12+
"deadcode": "knip --include files,dependencies",
1213
"test": "bun test",
1314
"typecheck": "tsc --noEmit",
14-
"check": "bun run typecheck && bun run test && bun run build",
15+
"check": "bun run typecheck && bun run deadcode && bun run test && bun run build",
1516
"install:opencode": "bun run ./src/install-opencode.ts",
1617
"uninstall:opencode": "bun run ./src/uninstall-opencode.ts"
1718
},
@@ -33,6 +34,7 @@
3334
"devDependencies": {
3435
"@opencode-ai/plugin": "^1.3.10",
3536
"bun-types": "latest",
37+
"knip": "^5.63.1",
3638
"typescript": "^6.0.2"
3739
}
3840
}

src/prompts/agents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Execution flow:
6464
4. Run targeted validation.
6565
5. Review the changed files.
6666
6. If review finds blocking issues, fix them, rerun targeted validation, and review again. Repeat until review passes or a real blocker remains.
67-
7. On the final completion path, run broad validation, ask flow-reviewer for a final review, and persist that approval with flow_review_record_final.
67+
7. On the final completion path, run broad validation, ask flow-reviewer for a final review, and persist that approval with flow_review_record_final. Treat the active feature as the final completion path whenever completing it would satisfy the session completion policy, including completionPolicy.minCompletedFeatures even if other plan features remain pending.
6868
8. Otherwise ask flow-reviewer to review the feature and persist the decision with flow_review_record_feature.
6969
9. Return one worker result matching:
7070
@@ -106,7 +106,7 @@ Autonomous loop:
106106
7. If the reviewer returns needs_fix, or the runtime marks the outcome retryable or auto-resolvable, keep the same feature active, coordinate the smallest credible fix/review/reset step, and continue.
107107
8. Persist an approved feature result with flow_run_complete_feature. If flow_run_complete_feature fails, inspect the runtime error and any structured recovery metadata, satisfy the stated prerequisite, and perform the indicated runtime action when one is provided.
108108
9. If the runtime routes back into planning because the feature needs decomposition, refresh the plan and continue.
109-
10. On the final completion path, have flow-worker run broad validation, use flow-reviewer for the final cross-feature review, persist it with flow_review_record_final, and keep fixing/revalidating until the final review passes.
109+
10. On the final completion path, have flow-worker run broad validation, use flow-reviewer for the final cross-feature review, persist it with flow_review_record_final, and keep fixing/revalidating until the final review passes. Treat the active feature as the final completion path whenever completing it would satisfy the session completion policy, including completionPolicy.minCompletedFeatures even if other plan features remain pending.
110110
11. Only then allow final completion.
111111
12. Repeat until the session is complete or blocked.
112112

0 commit comments

Comments
 (0)