opencode-plugin-flow 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +37 -6
- package/dist/cli.js +1066 -4
- package/dist/index.js +178 -177
- package/dist/index.js.map +8 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,159 @@
|
|
|
1
|
-
|
|
1
|
+
var U=`# Review rubric
|
|
2
|
+
|
|
3
|
+
Use this to decide whether a \`featureReview\` or \`finalReview\` payload may pass.
|
|
4
|
+
|
|
5
|
+
## Finding classes
|
|
6
|
+
|
|
7
|
+
- **correctness**: wrong result, broken state transition, bad edge case, race, data loss, or crash.
|
|
8
|
+
- **contract**: public API, CLI, config, persisted data, or documented behavior changed without plan approval.
|
|
9
|
+
- **security/privacy**: unsafe input handling, secret exposure, permission bypass, or insecure default.
|
|
10
|
+
- **test-coverage**: behavioral change lacks a check strong enough for the risk.
|
|
11
|
+
- **maintainability**: complexity or coupling creates concrete future-change risk.
|
|
12
|
+
- **ui/accessibility**: user cannot complete the workflow, layout breaks, accessibility basics fail, or visual claims lack evidence.
|
|
13
|
+
|
|
14
|
+
## Severity
|
|
15
|
+
|
|
16
|
+
- **blocking**: must fail the review. Includes incorrect behavior, data loss, security risk, unverifiable completion claims, missing validation for behavioral work, or unresolved scope drift.
|
|
17
|
+
- **advisory**: worth noting but does not block the current goal.
|
|
18
|
+
|
|
19
|
+
If unsure whether a finding is real, read more or downgrade it. Do not promote guesses to blockers.
|
|
20
|
+
|
|
21
|
+
## Feature review checklist
|
|
22
|
+
|
|
23
|
+
- The work matches the active feature's \`summary\`, \`targets\`, and dependencies.
|
|
24
|
+
- Plan \`requirements\` and \`decisions\` are still honored.
|
|
25
|
+
- Changed files were read, not just summarized.
|
|
26
|
+
- Validation evidence covers the behavior touched.
|
|
27
|
+
- New tests or manual checks would fail or visibly differ without the change where practical.
|
|
28
|
+
- No unrelated scope slipped in.
|
|
29
|
+
- Public contracts and downstream callers still work.
|
|
30
|
+
|
|
31
|
+
## Final review checklist
|
|
32
|
+
|
|
33
|
+
- Every feature is complete and together they satisfy the original goal.
|
|
34
|
+
- Broad validation ran and passed.
|
|
35
|
+
- The final review depth equals the approved \`finalReviewPolicy\`.
|
|
36
|
+
- Feature-level reviews have no unresolved blocking findings.
|
|
37
|
+
- Docs, commands, package metadata, and release surfaces match the delivered behavior.
|
|
38
|
+
- Remaining gaps are explicit and do not contradict \`kind: "completed"\`.
|
|
39
|
+
|
|
40
|
+
## Payloads
|
|
41
|
+
|
|
42
|
+
Feature review:
|
|
43
|
+
|
|
44
|
+
\`\`\`json
|
|
45
|
+
{
|
|
46
|
+
"status": "passed",
|
|
47
|
+
"summary": "Reviewed changed runtime files and focused tests; validation covers the new gate.",
|
|
48
|
+
"blockingFindings": []
|
|
49
|
+
}
|
|
50
|
+
\`\`\`
|
|
51
|
+
|
|
52
|
+
Failed feature review:
|
|
53
|
+
|
|
54
|
+
\`\`\`json
|
|
55
|
+
{
|
|
56
|
+
"status": "failed",
|
|
57
|
+
"summary": "Validation does not exercise the changed persistence path.",
|
|
58
|
+
"blockingFindings": [
|
|
59
|
+
{
|
|
60
|
+
"summary": "No test covers archive removal of .flow/session.json after close.",
|
|
61
|
+
"severity": "blocking"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
Final review:
|
|
68
|
+
|
|
69
|
+
\`\`\`json
|
|
70
|
+
{
|
|
71
|
+
"status": "passed",
|
|
72
|
+
"summary": "Reviewed plan scope, all changed files, broad validation, and release metadata.",
|
|
73
|
+
"blockingFindings": [],
|
|
74
|
+
"reviewDepth": "detailed"
|
|
75
|
+
}
|
|
76
|
+
\`\`\`
|
|
77
|
+
|
|
78
|
+
## Audit report reviews
|
|
79
|
+
|
|
80
|
+
When reviewing a findings report, verify findings adversarially:
|
|
81
|
+
|
|
82
|
+
- Check the cited file and surrounding code.
|
|
83
|
+
- Trace mitigating paths before accepting blocking severity.
|
|
84
|
+
- Confirm the deployment model used for severity.
|
|
85
|
+
- Dedupe overlapping findings.
|
|
86
|
+
- Downgrade or reject findings that do not survive refutation.
|
|
87
|
+
|
|
88
|
+
Approve only on evidence actually inspected. A review is a claim of coverage, not a courtesy stamp.
|
|
89
|
+
`;var j=`---
|
|
90
|
+
name: flow-review
|
|
91
|
+
description: Review Flow work in the v4 runtime: inspect feature or final-session changes, classify findings, and return featureReview or finalReview payloads for flow_feature_complete.
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
# Flow Review
|
|
95
|
+
|
|
96
|
+
Use this skill for review. The reviewer is usually read-only and does not mutate Flow state. The manager records the returned review payload inside \`flow_feature_complete\`.
|
|
97
|
+
|
|
98
|
+
If Flow tools are unavailable, perform an advisory review and say that no Flow-gated review payload was recorded.
|
|
99
|
+
|
|
100
|
+
## Start
|
|
101
|
+
|
|
102
|
+
- Call \`flow_status\` when available.
|
|
103
|
+
- Identify whether this is a feature review or final review.
|
|
104
|
+
- Read the approved plan fields relevant to the work: \`requirements\`, \`decisions\`, feature \`targets\`, feature \`validation\`, and dependencies.
|
|
105
|
+
- Inspect the actual diff, changed files, tests, and validation output. Do not review only the completion summary.
|
|
106
|
+
- Load \`references/review-rubric.md\` for severity, depth, and payload shape.
|
|
107
|
+
|
|
108
|
+
## Depth
|
|
109
|
+
|
|
110
|
+
- **quick**: docs, comments, config-only changes, or mechanical changes fully covered by tooling.
|
|
111
|
+
- **standard**: default feature review. Read every changed file and relevant tests.
|
|
112
|
+
- **detailed**: final review, risky behavior, persistence, security, cross-module refactors, migrations, releases, or weak validation.
|
|
113
|
+
|
|
114
|
+
Claim only the depth actually performed. Missing evidence is a finding, not a nuisance.
|
|
115
|
+
|
|
116
|
+
## Output
|
|
117
|
+
|
|
118
|
+
For a feature review, return:
|
|
119
|
+
|
|
120
|
+
\`\`\`json
|
|
121
|
+
{
|
|
122
|
+
"status": "passed",
|
|
123
|
+
"summary": "what was reviewed and why it is acceptable",
|
|
124
|
+
"blockingFindings": []
|
|
125
|
+
}
|
|
126
|
+
\`\`\`
|
|
127
|
+
|
|
128
|
+
For a final review, return:
|
|
129
|
+
|
|
130
|
+
\`\`\`json
|
|
131
|
+
{
|
|
132
|
+
"status": "passed",
|
|
133
|
+
"summary": "session-level review summary",
|
|
134
|
+
"blockingFindings": [],
|
|
135
|
+
"reviewDepth": "detailed"
|
|
136
|
+
}
|
|
137
|
+
\`\`\`
|
|
138
|
+
|
|
139
|
+
Use \`status: "failed"\` when any blocking finding remains. Advisory findings may be included in the prose summary, but \`blockingFindings\` contains only blockers.
|
|
140
|
+
|
|
141
|
+
## Special cases
|
|
142
|
+
|
|
143
|
+
- Cleanup/refactor: load \`flow-deslop\`; verify the smell was real, refutation paths were checked, and behavior was preserved.
|
|
144
|
+
- UI/frontend: load \`flow-ui-quality\`; verify state coverage and visual evidence when a local target was available.
|
|
145
|
+
- Audit reports: use \`flow-run/references/audit-rubric.md\`; findings must survive refutation before they can drive fix features.
|
|
146
|
+
- Large reviews: use \`../flow/references/parallel-orchestration.md\` for
|
|
147
|
+
read-only slices by changed-file group, risk lens, or validation surface.
|
|
148
|
+
Use the named review, audit, evidence, or validation agents from that
|
|
149
|
+
reference instead of generic subagents. Apply its handoff format and
|
|
150
|
+
verification gates; only the manager returns the final \`featureReview\` or
|
|
151
|
+
\`finalReview\` payload.
|
|
152
|
+
|
|
153
|
+
Never approve to unblock completion, fix findings in the review pass, or vouch for validation you did not inspect.
|
|
154
|
+
`;var bt=["Use Flow review mode. Load `flow-review` when the skill registry is current. If Flow setup reports stale skills or the skill loader reports that `flow-review` is unavailable, continue with the bundled review instructions below instead.","","## Bundled Flow review fallback","","## Bundled flow-review/SKILL.md",j,"## Bundled flow-review/references/review-rubric.md",U].join(`
|
|
155
|
+
|
|
156
|
+
`),kt={"flow-reviewer":{mode:"subagent",hidden:!0,description:"Internal read-only reviewer for Flow-guided work.",prompt:bt,permission:{edit:"deny",bash:"deny",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-evidence-worker":{mode:"subagent",hidden:!0,description:"Internal read-only evidence worker for Flow planning and execution support.",prompt:"Use Flow evidence mode. Inspect only the assigned slice, do not edit files, do not call state-changing Flow tools, and return coverage, evidence inspected, confidence-tagged findings or facts, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"deny",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-validation-worker":{mode:"subagent",hidden:!0,description:"Internal validation worker for Flow check selection and command evidence.",prompt:"Use Flow validation mode. Run only manager-specified commands or propose focused checks, do not edit files, do not call state-changing Flow tools, and report exact command, status, raw outcome summary, coverage, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-audit-worker":{mode:"subagent",hidden:!0,description:"Internal read-only audit worker for refuted or surviving finding candidates.",prompt:"Use Flow audit mode. Inspect only the assigned slice, actively refute candidate findings before reporting them, do not edit files, do not call state-changing Flow tools, and return coverage, evidence, guards checked, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-candidate-worker":{mode:"subagent",hidden:!0,description:"Internal candidate implementation worker for isolated Flow worktrees or exact non-overlapping path ownership.",prompt:"Use Flow candidate-implementation mode only when the manager assigned an isolated worktree or exact non-overlapping path ownership. Do not edit .flow/**, do not call state-changing Flow tools, do not complete Flow state, and return changed or proposed patch, verification run, coverage, confidence, merge risks, and manager follow-ups.",permission:{edit:"ask",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-verifier-worker":{mode:"subagent",hidden:!0,description:"Internal verifier worker for checking Flow worker claims against cited evidence.",prompt:"Use Flow verifier mode. Verify only the assigned claims against the provided sources, commands, counts, or current docs. Do not generate new scope, do not edit files, do not call state-changing Flow tools, and return supported, partly-supported, unsupported, or source-not-found per claim with evidence, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}}},K={"flow-auto":{description:"Drive Flow skills against the minimal runtime ledger",template:"Load the `flow` skill and drive the Flow loop until completion or a real blocker: $ARGUMENTS"},"flow-plan":{description:"Create or approve a Flow plan",template:"Load the `flow-plan` skill and plan: $ARGUMENTS"},"flow-run":{description:"Run one approved Flow feature",template:"Load the `flow-run` skill and execute the next approved feature. $ARGUMENTS"},"flow-review":{description:"Run a read-only Flow review",agent:"flow-reviewer",subtask:!0,template:"Load `flow-review`; if loading fails because the skill is unavailable, use the bundled review fallback. Review: $ARGUMENTS"},"flow-status":{description:"Inspect the active Flow session",template:"Call flow_status and report the session state and next action."}};function xt(){return{agent:Object.fromEntries(Object.entries(kt).map(([e,a])=>{let t=a.permission?{...a.permission,...a.permission.task?{task:{...a.permission.task}}:{}}:void 0;return[e,{...a,...t?{permission:t}:{}}]})),command:Object.fromEntries(Object.entries(K).map(([e,a])=>[e,{...a}]))}}function ue(e){let a=xt();e.agent={...e.agent??{},...a.agent},e.command={...e.command??{},...a.command}}import{createHash as zt}from"node:crypto";import{mkdir as $t,readdir as _r,readFile as Mt,rm as Sr,writeFile as E}from"node:fs/promises";import{createRequire as Vt}from"node:module";import{dirname as Bt,join as P,normalize as Jt,sep as Lt}from"node:path";var pe=`# Flow worker handoff contract
|
|
2
157
|
|
|
3
158
|
Flow managers merge only the worker's final response. Treat that response as the
|
|
4
159
|
worker report of record: it must include the assigned scope, what was actually
|
|
@@ -117,7 +272,7 @@ live-verified | test-verified | type-check-only | not-verified
|
|
|
117
272
|
|
|
118
273
|
The manager must inspect and validate any candidate patch before recording Flow
|
|
119
274
|
completion.
|
|
120
|
-
`;var
|
|
275
|
+
`;var fe=`# Parallel orchestration
|
|
121
276
|
|
|
122
277
|
Use fan-out when Flow work is broad enough that independent workers can gather
|
|
123
278
|
evidence faster than one linear pass. The manager still owns the Flow session:
|
|
@@ -245,7 +400,7 @@ Start a follow-up wave when first-wave handoffs reveal:
|
|
|
245
400
|
|
|
246
401
|
Do not recurse by default. If a worker says it needs another worker, the manager
|
|
247
402
|
decides whether that is a second wave and writes the next bounded prompt.
|
|
248
|
-
`;var
|
|
403
|
+
`;var me='# Recovery playbook\n\nUse this when a Flow tool returns `status: "error"`, a blocker, or a `nextAction` that conflicts with memory.\n\n## First response\n\n1. Re-anchor with `flow_status`.\n2. Read the returned `summary`, `recovery`, `lastError`, and active feature.\n3. Fix the cause, then retry the smallest valid Flow action.\n\n## Common cases\n\n- `missing_session`: start with `flow_plan_save` using the user\'s goal.\n- `missing_goal`: ask for a concrete goal before planning.\n- `Approved plans cannot be changed`: use `flow_feature_reset` when only affected features need another pass; otherwise close and start a new goal.\n- `No feature is currently running`: call `flow_run_start` before completing.\n- `already in progress`: finish, reset, or block the active feature before starting another.\n- `Completion requires recorded validation evidence`: run real validation and include at least one passing `validationRun`.\n- `Completion requires all recorded validation to pass`: fix failures and rerun. Do not relabel failed checks as passed.\n- `Non-final feature completion requires targeted validation`: use `validationScope: "targeted"` for ordinary features.\n- `Final feature completion requires broad validation`: run the project-level gate and use `validationScope: "broad"`.\n- `Completion requires a passing featureReview`: run or request a real review and include a passing `featureReview` only when there are no blocking findings.\n- `Final feature completion requires a finalReview`: perform final review and include `finalReview`.\n- `Final review depth must match the plan policy`: use `reviewDepth` equal to the approved plan\'s `finalReviewPolicy`.\n- `Cannot close ... unfinished features`: complete, reset, defer, or abandon honestly. Do not mark completed while work remains.\n\n## Reset guidance\n\nUse `flow_feature_reset` when the active or completed work was built on the wrong assumption, validation revealed a design issue, dependencies need to be rerun, or dependent features must be invalidated. Resetting a feature also resets its dependents.\n\n## Closure guidance\n\nUse `flow_session_close`:\n\n- `completed`: only after all planned features are complete.\n- `deferred`: the user intentionally postpones unfinished work.\n- `abandoned`: the session should be archived without claiming delivery.\n\nAfter closure, the active `.flow/session.json` is removed and the archived JSON is stored under `.flow/history/`.\n';var he=`# Verification gates
|
|
249
404
|
|
|
250
405
|
Verification is how Flow keeps parallel work from turning into parallel
|
|
251
406
|
guesswork. Worker handoffs are candidate evidence; the manager decides what can
|
|
@@ -335,7 +490,7 @@ Before presenting or recording the result:
|
|
|
335
490
|
|
|
336
491
|
\`Status: success\` only says the worker believes its slice is done. The manager
|
|
337
492
|
still checks coverage and evidence before trusting the result.
|
|
338
|
-
`;var
|
|
493
|
+
`;var ge="---\nname: flow\ndescription: Main Flow loop for skills-first OpenCode work. Use when a user asks for Flow-guided planning, autonomous execution, resumable implementation, session status, or end-to-end delivery with validation and review gates.\n---\n\n# Flow\n\nUse Flow as a minimal state ledger, not as a framework. Skills provide judgment; the runtime only records the approved plan, active feature, validation evidence, review evidence, and closure.\n\n## Loop\n\n1. Call `flow_status` first. Trust its active session and next action over conversation memory.\n2. If there is no active session and the user gave a goal, load `flow-plan`, save a plan with `flow_plan_save`, then approve it with `flow_plan_approve`. If there is no goal, ask for one.\n3. Load `flow-run`, call `flow_run_start`, implement exactly one feature, validate it, and prepare a `flow_feature_complete` payload.\n4. Load `flow-review` for the required feature review. The reviewer reports a `featureReview` payload; the manager records it inside `flow_feature_complete`.\n5. On the final feature, run broad validation and include `finalReview` in the same `flow_feature_complete` call. Its `reviewDepth` must match the plan's `finalReviewPolicy`.\n6. After all features are complete, archive the session with `flow_session_close` using `kind: \"completed\"`.\n\nUse `references/parallel-orchestration.md` for broad read-only discovery, audit, validation, review, verification, or candidate implementation waves. Its `references/handoff-format.md` and `references/verification-gates.md` companions define the worker contracts. The manager owns every `flow_*` state change.\n\n## Runtime Surface\n\n- `flow_status`: read the active session.\n- `flow_plan_save`: create a session and/or save a draft plan.\n- `flow_plan_approve`: lock the draft plan.\n- `flow_run_start`: start one runnable feature.\n- `flow_feature_complete`: record completion or a real blocker with validation and review evidence.\n- `flow_feature_reset`: reset one feature and its dependents.\n- `flow_session_close`: archive the active session as `completed`, `deferred`, or `abandoned`.\n\nThere is no `flow_context`, no separate review-record tool, and no multi-session activation surface. The single active source of truth is `.flow/session.json`; closed sessions are archived under `.flow/history/`.\n\n## Hard Gates\n\n- Approved plans are immutable. To change direction, reset affected features or close the session and start a new goal.\n- Only one feature can be active at a time.\n- Completion requires at least one passing `validationRun` entry.\n- Non-final completion requires `validationScope: \"targeted\"`.\n- Final completion requires `validationScope: \"broad\"` and a passing `finalReview`.\n- Every completed feature requires a passing `featureReview` with no blocking findings.\n- `flow_session_close` accepts `kind: \"completed\"` only after an approved plan has passed final completion.\n\n## Recovery\n\n- Confused state: call `flow_status` and follow `nextAction`.\n- Wrong assumption or failed implementation path: use `flow_feature_reset` for the feature and dependents, then rerun from the corrected plan.\n- Missing validation or review evidence: gather real evidence, then call `flow_feature_complete`.\n- Approved plan is materially wrong: reset the affected features, save a revised plan if the session is back in planning; otherwise close and start a new goal.\n- Unknown runtime error: read `summary` and `recovery`; see `references/recovery-playbook.md` for common cases.\n\nNever fabricate validation output, backfill review approval you did not perform, or close as `deferred`/`abandoned` merely to avoid an unfinished-work blocker.\n";var ve=`# Safe refactor workflow
|
|
339
494
|
|
|
340
495
|
Refactoring is a behavior-preserving sequence of small changes. This workflow keeps cleanup from becoming an unreviewable rewrite.
|
|
341
496
|
|
|
@@ -377,7 +532,7 @@ Weak evidence includes:
|
|
|
377
532
|
- Public contracts and compatibility shims remain intact or were explicitly planned.
|
|
378
533
|
- Deleted code is actually unreachable or obsolete.
|
|
379
534
|
- Validation can catch a realistic mistake in the refactor.
|
|
380
|
-
`;var
|
|
535
|
+
`;var we=`# Deslop smell rubric
|
|
381
536
|
|
|
382
537
|
Use this rubric to turn vague cleanup instincts into reviewable findings.
|
|
383
538
|
|
|
@@ -411,7 +566,7 @@ class; severity; location; evidence read; refutation checked; why it matters; sa
|
|
|
411
566
|
\`\`\`
|
|
412
567
|
|
|
413
568
|
Rate as blocking only when the smell materially raises defect risk, blocks planned work, hides behavior, or makes the success claim unverifiable. Style-only cleanup is advisory.
|
|
414
|
-
`;var
|
|
569
|
+
`;var ye=`---
|
|
415
570
|
name: flow-deslop
|
|
416
571
|
description: Flow guidance for evidence-backed code smell cleanup, AI-slop removal, overengineering reduction, maintainability refactors, and behavior-preserving cleanup. Use when planning, executing, or reviewing broad cleanup/refactor work, code smell findings, duplicated or bloated code, speculative abstractions, dead code, or agent-introduced mess.
|
|
417
572
|
---
|
|
@@ -453,7 +608,7 @@ For each claimed smell removal, verify:
|
|
|
453
608
|
- **blast radius** — public contracts and downstream callers still work.
|
|
454
609
|
|
|
455
610
|
Never approve cleanup because it "looks cleaner" without evidence. Tests passing is necessary but not sufficient when the refactor changes structure across files.
|
|
456
|
-
`;var
|
|
611
|
+
`;var be=`# Parallel discovery
|
|
457
612
|
|
|
458
613
|
Use this only after a serial orientation pass has identified the repo shape and the likely slices. Workers are read-only evidence gatherers; the planner owns the plan.
|
|
459
614
|
|
|
@@ -519,7 +674,7 @@ Convert only evidence-backed work into plan fields:
|
|
|
519
674
|
- feature \`validation\`: checks expected to prove the feature.
|
|
520
675
|
|
|
521
676
|
If workers disagree, inspect the source artifact yourself. If a candidate finding lacks a concrete citation or refutation pass, make it a review-first deliverable rather than a fix feature.
|
|
522
|
-
`;var
|
|
677
|
+
`;var ke=`# Planning examples
|
|
523
678
|
|
|
524
679
|
## Rate limiting feature set
|
|
525
680
|
|
|
@@ -604,7 +759,7 @@ Better plan:
|
|
|
604
759
|
- Validation that only says "manual testing".
|
|
605
760
|
- Targets that name the entire repo.
|
|
606
761
|
- Features with hidden dependencies instead of \`dependsOn\`.
|
|
607
|
-
`;var
|
|
762
|
+
`;var xe=`---
|
|
608
763
|
name: flow-plan
|
|
609
764
|
description: Plan Flow work for the v4 skills-first runtime: inspect the repo, decompose a user goal into right-sized features, save a draft with flow_plan_save, and approve it with flow_plan_approve.
|
|
610
765
|
---
|
|
@@ -665,160 +820,7 @@ Use \`finalReviewPolicy: "broad"\` only for low-risk, narrow work. Use \`"detail
|
|
|
665
820
|
After saving, summarize the plan to the user or proceed if they already authorized implementation. Then call \`flow_plan_approve\`. Approved plans are immutable; changing them later requires reset/closure rather than silent edits.
|
|
666
821
|
|
|
667
822
|
See \`references/planning-examples.md\` for payload examples and decomposition anti-patterns.
|
|
668
|
-
`;var
|
|
669
|
-
|
|
670
|
-
Use this to decide whether a \`featureReview\` or \`finalReview\` payload may pass.
|
|
671
|
-
|
|
672
|
-
## Finding classes
|
|
673
|
-
|
|
674
|
-
- **correctness**: wrong result, broken state transition, bad edge case, race, data loss, or crash.
|
|
675
|
-
- **contract**: public API, CLI, config, persisted data, or documented behavior changed without plan approval.
|
|
676
|
-
- **security/privacy**: unsafe input handling, secret exposure, permission bypass, or insecure default.
|
|
677
|
-
- **test-coverage**: behavioral change lacks a check strong enough for the risk.
|
|
678
|
-
- **maintainability**: complexity or coupling creates concrete future-change risk.
|
|
679
|
-
- **ui/accessibility**: user cannot complete the workflow, layout breaks, accessibility basics fail, or visual claims lack evidence.
|
|
680
|
-
|
|
681
|
-
## Severity
|
|
682
|
-
|
|
683
|
-
- **blocking**: must fail the review. Includes incorrect behavior, data loss, security risk, unverifiable completion claims, missing validation for behavioral work, or unresolved scope drift.
|
|
684
|
-
- **advisory**: worth noting but does not block the current goal.
|
|
685
|
-
|
|
686
|
-
If unsure whether a finding is real, read more or downgrade it. Do not promote guesses to blockers.
|
|
687
|
-
|
|
688
|
-
## Feature review checklist
|
|
689
|
-
|
|
690
|
-
- The work matches the active feature's \`summary\`, \`targets\`, and dependencies.
|
|
691
|
-
- Plan \`requirements\` and \`decisions\` are still honored.
|
|
692
|
-
- Changed files were read, not just summarized.
|
|
693
|
-
- Validation evidence covers the behavior touched.
|
|
694
|
-
- New tests or manual checks would fail or visibly differ without the change where practical.
|
|
695
|
-
- No unrelated scope slipped in.
|
|
696
|
-
- Public contracts and downstream callers still work.
|
|
697
|
-
|
|
698
|
-
## Final review checklist
|
|
699
|
-
|
|
700
|
-
- Every feature is complete and together they satisfy the original goal.
|
|
701
|
-
- Broad validation ran and passed.
|
|
702
|
-
- The final review depth equals the approved \`finalReviewPolicy\`.
|
|
703
|
-
- Feature-level reviews have no unresolved blocking findings.
|
|
704
|
-
- Docs, commands, package metadata, and release surfaces match the delivered behavior.
|
|
705
|
-
- Remaining gaps are explicit and do not contradict \`kind: "completed"\`.
|
|
706
|
-
|
|
707
|
-
## Payloads
|
|
708
|
-
|
|
709
|
-
Feature review:
|
|
710
|
-
|
|
711
|
-
\`\`\`json
|
|
712
|
-
{
|
|
713
|
-
"status": "passed",
|
|
714
|
-
"summary": "Reviewed changed runtime files and focused tests; validation covers the new gate.",
|
|
715
|
-
"blockingFindings": []
|
|
716
|
-
}
|
|
717
|
-
\`\`\`
|
|
718
|
-
|
|
719
|
-
Failed feature review:
|
|
720
|
-
|
|
721
|
-
\`\`\`json
|
|
722
|
-
{
|
|
723
|
-
"status": "failed",
|
|
724
|
-
"summary": "Validation does not exercise the changed persistence path.",
|
|
725
|
-
"blockingFindings": [
|
|
726
|
-
{
|
|
727
|
-
"summary": "No test covers archive removal of .flow/session.json after close.",
|
|
728
|
-
"severity": "blocking"
|
|
729
|
-
}
|
|
730
|
-
]
|
|
731
|
-
}
|
|
732
|
-
\`\`\`
|
|
733
|
-
|
|
734
|
-
Final review:
|
|
735
|
-
|
|
736
|
-
\`\`\`json
|
|
737
|
-
{
|
|
738
|
-
"status": "passed",
|
|
739
|
-
"summary": "Reviewed plan scope, all changed files, broad validation, and release metadata.",
|
|
740
|
-
"blockingFindings": [],
|
|
741
|
-
"reviewDepth": "detailed"
|
|
742
|
-
}
|
|
743
|
-
\`\`\`
|
|
744
|
-
|
|
745
|
-
## Audit report reviews
|
|
746
|
-
|
|
747
|
-
When reviewing a findings report, verify findings adversarially:
|
|
748
|
-
|
|
749
|
-
- Check the cited file and surrounding code.
|
|
750
|
-
- Trace mitigating paths before accepting blocking severity.
|
|
751
|
-
- Confirm the deployment model used for severity.
|
|
752
|
-
- Dedupe overlapping findings.
|
|
753
|
-
- Downgrade or reject findings that do not survive refutation.
|
|
754
|
-
|
|
755
|
-
Approve only on evidence actually inspected. A review is a claim of coverage, not a courtesy stamp.
|
|
756
|
-
`;var me=`---
|
|
757
|
-
name: flow-review
|
|
758
|
-
description: Review Flow work in the v4 runtime: inspect feature or final-session changes, classify findings, and return featureReview or finalReview payloads for flow_feature_complete.
|
|
759
|
-
---
|
|
760
|
-
|
|
761
|
-
# Flow Review
|
|
762
|
-
|
|
763
|
-
Use this skill for review. The reviewer is usually read-only and does not mutate Flow state. The manager records the returned review payload inside \`flow_feature_complete\`.
|
|
764
|
-
|
|
765
|
-
If Flow tools are unavailable, perform an advisory review and say that no Flow-gated review payload was recorded.
|
|
766
|
-
|
|
767
|
-
## Start
|
|
768
|
-
|
|
769
|
-
- Call \`flow_status\` when available.
|
|
770
|
-
- Identify whether this is a feature review or final review.
|
|
771
|
-
- Read the approved plan fields relevant to the work: \`requirements\`, \`decisions\`, feature \`targets\`, feature \`validation\`, and dependencies.
|
|
772
|
-
- Inspect the actual diff, changed files, tests, and validation output. Do not review only the completion summary.
|
|
773
|
-
- Load \`references/review-rubric.md\` for severity, depth, and payload shape.
|
|
774
|
-
|
|
775
|
-
## Depth
|
|
776
|
-
|
|
777
|
-
- **quick**: docs, comments, config-only changes, or mechanical changes fully covered by tooling.
|
|
778
|
-
- **standard**: default feature review. Read every changed file and relevant tests.
|
|
779
|
-
- **detailed**: final review, risky behavior, persistence, security, cross-module refactors, migrations, releases, or weak validation.
|
|
780
|
-
|
|
781
|
-
Claim only the depth actually performed. Missing evidence is a finding, not a nuisance.
|
|
782
|
-
|
|
783
|
-
## Output
|
|
784
|
-
|
|
785
|
-
For a feature review, return:
|
|
786
|
-
|
|
787
|
-
\`\`\`json
|
|
788
|
-
{
|
|
789
|
-
"status": "passed",
|
|
790
|
-
"summary": "what was reviewed and why it is acceptable",
|
|
791
|
-
"blockingFindings": []
|
|
792
|
-
}
|
|
793
|
-
\`\`\`
|
|
794
|
-
|
|
795
|
-
For a final review, return:
|
|
796
|
-
|
|
797
|
-
\`\`\`json
|
|
798
|
-
{
|
|
799
|
-
"status": "passed",
|
|
800
|
-
"summary": "session-level review summary",
|
|
801
|
-
"blockingFindings": [],
|
|
802
|
-
"reviewDepth": "detailed"
|
|
803
|
-
}
|
|
804
|
-
\`\`\`
|
|
805
|
-
|
|
806
|
-
Use \`status: "failed"\` when any blocking finding remains. Advisory findings may be included in the prose summary, but \`blockingFindings\` contains only blockers.
|
|
807
|
-
|
|
808
|
-
## Special cases
|
|
809
|
-
|
|
810
|
-
- Cleanup/refactor: load \`flow-deslop\`; verify the smell was real, refutation paths were checked, and behavior was preserved.
|
|
811
|
-
- UI/frontend: load \`flow-ui-quality\`; verify state coverage and visual evidence when a local target was available.
|
|
812
|
-
- Audit reports: use \`flow-run/references/audit-rubric.md\`; findings must survive refutation before they can drive fix features.
|
|
813
|
-
- Large reviews: use \`../flow/references/parallel-orchestration.md\` for
|
|
814
|
-
read-only slices by changed-file group, risk lens, or validation surface.
|
|
815
|
-
Use the named review, audit, evidence, or validation agents from that
|
|
816
|
-
reference instead of generic subagents. Apply its handoff format and
|
|
817
|
-
verification gates; only the manager returns the final \`featureReview\` or
|
|
818
|
-
\`finalReview\` payload.
|
|
819
|
-
|
|
820
|
-
Never approve to unblock completion, fix findings in the review pass, or vouch for validation you did not inspect.
|
|
821
|
-
`;var he=`# Audit findings rubric
|
|
823
|
+
`;var Re=`# Audit findings rubric
|
|
822
824
|
|
|
823
825
|
What counts as a valid finding when the feature's deliverable is a findings report: a codebase audit, a review-first feature, or any report whose findings a later feature will fix. The commands you run are still governed by \`validation-rubric.md\`; this rubric governs the findings themselves.
|
|
824
826
|
|
|
@@ -871,7 +873,7 @@ follow-up order — correctness and persisted/user-input surfaces first
|
|
|
871
873
|
\`\`\`
|
|
872
874
|
|
|
873
875
|
Never: promote a hypothesis to blocking severity; cite a line you did not read in context; rate severity against a deployment model the product does not have; pad the report to look thorough — six verified findings outrank nine where three die on first contact.
|
|
874
|
-
`;var
|
|
876
|
+
`;var Fe=`# Validation evidence rubric
|
|
875
877
|
|
|
876
878
|
Use this before recording \`flow_feature_complete\`.
|
|
877
879
|
|
|
@@ -928,7 +930,7 @@ Broad validation usually means the repo's full check command, full relevant test
|
|
|
928
930
|
- If validation needs external access, missing credentials, or ambiguous user input, record \`status: "needs_input"\` with an honest \`outcome\`.
|
|
929
931
|
|
|
930
932
|
Never trim failing output, relabel a failed command as passed, or use "not run" as completion evidence.
|
|
931
|
-
`;var
|
|
933
|
+
`;var _e="---\nname: flow-run\ndescription: Execute one approved Flow feature in the v4 runtime: start a feature with flow_run_start, make scoped changes, gather real validation evidence, obtain review payloads, and complete with flow_feature_complete.\n---\n\n# Flow Run\n\nUse this skill for implementation after a Flow plan is approved. Work one feature at a time.\n\nIf `flow_run_start` is unavailable, stop and tell the user to check that `opencode-plugin-flow` is loaded in OpenCode.\n\n## Start\n\n- Call `flow_status`.\n- Call `flow_run_start` with no `featureId` unless the user or plan requires a specific runnable feature.\n- Treat the returned feature as the sole scope until it is completed, blocked, or reset.\n- Load `flow-deslop` for cleanup/refactor features.\n- Load `flow-ui-quality` for frontend, UX, responsive, accessibility, or visual work.\n\n## Implement\n\n- Read the feature `targets`, `summary`, `validation`, dependencies, and plan `requirements`/`decisions`.\n- Keep edits scoped to the active feature. If new scope appears, stop and replan or defer it to another feature.\n- Preserve unrelated user changes in the worktree.\n- When a wrong assumption invalidates the feature, use `flow_feature_reset`; do not pile patches onto a bad path.\n\n## Validate\n\n- Read `references/validation-rubric.md` before completing.\n- Run the strongest practical checks for the changed behavior.\n- Record concrete command names, status, and observed results. \"Tests pass\" is not evidence.\n- Non-final features complete with `validationScope: \"targeted\"`.\n- The final feature must run a broad project-level gate and use `validationScope: \"broad\"`.\n\nFor broad validation research, risky changes, or unclear coverage, use\n`../flow/references/parallel-orchestration.md` to fan out named Flow workers.\nUse the mode-to-agent mapping in that reference instead of generic subagents.\nWorkers must use the handoff format and verification gates from that reference.\nThey may report command output they actually ran or propose focused checks; the\nmanager decides what is strong enough to record.\n\nFor independent implementation attempts, use candidate workers only with\nexplicit user authorization plus isolated worktrees or exact non-overlapping\npath ownership. Treat their output as candidate patches. The manager inspects,\nmerges, validates, and records Flow state serially.\n\n## Review and complete\n\nBefore `flow_feature_complete`, obtain a `featureReview` payload. Load `flow-review`; for read-only subagent reviews, the manager receives the payload and records it.\n\nFor the final feature, also obtain a `finalReview` payload whose `reviewDepth` equals the approved plan's `finalReviewPolicy`.\n\nComplete with:\n\n```json\n{\n \"status\": \"ok\",\n \"featureId\": \"active-feature-id\",\n \"summary\": \"what changed\",\n \"artifactsChanged\": [{ \"path\": \"src/file.ts\" }],\n \"validationRun\": [\n { \"command\": \"bun test tests/foo.test.ts\", \"status\": \"passed\", \"summary\": \"3 pass, exercised foo behavior\" }\n ],\n \"validationScope\": \"targeted\",\n \"featureReview\": { \"status\": \"passed\", \"summary\": \"review summary\", \"blockingFindings\": [] }\n}\n```\n\nIf genuinely blocked, call `flow_feature_complete` with `status: \"needs_input\"` and an `outcome` that explains the blocker and next step. Never fabricate validation or review evidence to force progress.\n";var Se=`# UI quality rubric
|
|
932
934
|
|
|
933
935
|
Use this rubric for frontend planning, implementation, and review.
|
|
934
936
|
|
|
@@ -972,7 +974,7 @@ class; severity; location or screenshot area; evidence inspected; user impact; f
|
|
|
972
974
|
\`\`\`
|
|
973
975
|
|
|
974
976
|
Blocking UI findings are issues that prevent task completion, hide required information, break accessibility basics, create incoherent layout at supported sizes, or make the visual success claim unverifiable.
|
|
975
|
-
`;var
|
|
977
|
+
`;var Ie=`# Visual verification workflow
|
|
976
978
|
|
|
977
979
|
Use this workflow when UI changes can be run locally. Flow execution may create visual evidence; Flow review usually assesses recorded evidence because the reviewer is read-only.
|
|
978
980
|
|
|
@@ -1012,7 +1014,7 @@ Record the reason and use the strongest available substitute:
|
|
|
1012
1014
|
- code inspection against existing component patterns.
|
|
1013
1015
|
|
|
1014
1016
|
Do not claim visual polish was verified if no visual artifact was inspected.
|
|
1015
|
-
`;var
|
|
1017
|
+
`;var Pe=`---
|
|
1016
1018
|
name: flow-ui-quality
|
|
1017
1019
|
description: Flow guidance for UX/UI design, frontend polish, visual quality review, responsive and accessible interfaces, and avoiding generic AI-generated UI. Use when planning, executing, or reviewing frontend pages, components, dashboards, visual redesigns, interaction states, screenshots, or browser-verified UI work.
|
|
1018
1020
|
---
|
|
@@ -1057,13 +1059,12 @@ Approve only when the interface is both useful and inspectable:
|
|
|
1057
1059
|
- Screenshot/browser evidence supports the claim whenever feasible.
|
|
1058
1060
|
|
|
1059
1061
|
Never approve a UI change based only on code shape. If users will judge it visually, Flow evidence should include visual inspection.
|
|
1060
|
-
`;var
|
|
1061
|
-
`)}async function
|
|
1062
|
-
`),await Le(t),n}async function
|
|
1063
|
-
`),await
|
|
1064
|
-
session.lock/
|
|
1065
|
-
`,"utf8")}catch(t){if(t.code!=="ENOENT")throw t;await je(a,`session.lock/
|
|
1066
|
-
`,"utf8")}}var na={"flow-reviewer":{mode:"subagent",hidden:!0,description:"Internal read-only reviewer for Flow-guided work.",prompt:"Load `flow-review`. Inspect the current work read-only, report coverage, evidence-backed findings, confidence, gaps, and manager follow-ups, and do not mutate Flow state.",permission:{edit:"deny",bash:"deny",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-evidence-worker":{mode:"subagent",hidden:!0,description:"Internal read-only evidence worker for Flow planning and execution support.",prompt:"Use Flow evidence mode. Inspect only the assigned slice, do not edit files, do not call state-changing Flow tools, and return coverage, evidence inspected, confidence-tagged findings or facts, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"deny",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-validation-worker":{mode:"subagent",hidden:!0,description:"Internal validation worker for Flow check selection and command evidence.",prompt:"Use Flow validation mode. Run only manager-specified commands or propose focused checks, do not edit files, do not call state-changing Flow tools, and report exact command, status, raw outcome summary, coverage, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-audit-worker":{mode:"subagent",hidden:!0,description:"Internal read-only audit worker for refuted or surviving finding candidates.",prompt:"Use Flow audit mode. Inspect only the assigned slice, actively refute candidate findings before reporting them, do not edit files, do not call state-changing Flow tools, and return coverage, evidence, guards checked, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-candidate-worker":{mode:"subagent",hidden:!0,description:"Internal candidate implementation worker for isolated Flow worktrees or exact non-overlapping path ownership.",prompt:"Use Flow candidate-implementation mode only when the manager assigned an isolated worktree or exact non-overlapping path ownership. Do not edit .flow/**, do not call state-changing Flow tools, do not complete Flow state, and return changed or proposed patch, verification run, coverage, confidence, merge risks, and manager follow-ups.",permission:{edit:"ask",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}},"flow-verifier-worker":{mode:"subagent",hidden:!0,description:"Internal verifier worker for checking Flow worker claims against cited evidence.",prompt:"Use Flow verifier mode. Verify only the assigned claims against the provided sources, commands, counts, or current docs. Do not generate new scope, do not edit files, do not call state-changing Flow tools, and return supported, partly-supported, unsupported, or source-not-found per claim with evidence, confidence, gaps, and manager follow-ups.",permission:{edit:"deny",bash:"ask",task:{"*":"deny"},"flow_*":"deny",flow_status:"allow"}}},ra={"flow-auto":{description:"Drive Flow skills against the minimal runtime ledger",template:"Load the `flow` skill and drive the Flow loop until completion or a real blocker: $ARGUMENTS"},"flow-plan":{description:"Create or approve a Flow plan",template:"Load the `flow-plan` skill and plan: $ARGUMENTS"},"flow-run":{description:"Run one approved Flow feature",template:"Load the `flow-run` skill and execute the next approved feature. $ARGUMENTS"},"flow-review":{description:"Run a read-only Flow review",agent:"flow-reviewer",subtask:!0,template:"Load the `flow-review` skill and review: $ARGUMENTS"},"flow-status":{description:"Inspect the active Flow session",template:"Call flow_status and report the session state and next action."}};function oa(){return{agent:Object.fromEntries(Object.entries(na).map(([e,a])=>{let t=a.permission?{...a.permission,...a.permission.task?{task:{...a.permission.task}}:{}}:void 0;return[e,{...a,...t?{permission:t}:{}}]})),command:Object.fromEntries(Object.entries(ra).map(([e,a])=>[e,{...a}]))}}function Me(e){let a=oa();e.agent={...e.agent??{},...a.agent},e.command={...e.command??{},...a.command}}function Ve(e){return async(a)=>{Me(a)}}function z(e){let a=e?.client,t=a?.app?.log;return(n,r)=>{if(typeof t!=="function")return;try{t.call(a?.app,{body:{service:"opencode-plugin-flow",level:n,message:r}})}catch{}}}import{z as p}from"zod";import{randomUUID as sa}from"node:crypto";var ia=null;function h(){return ia?.()??new Date().toISOString()}function u(e){return{ok:!0,value:e}}function l(e,a,t){return{ok:!1,message:e,...a?{recovery:a}:{},...t?{session:t}:{}}}function la(e){let a=E.parse(e);return{summary:a.summary,overview:a.overview,requirements:a.requirements??[],decisions:a.decisions??[],finalReviewPolicy:a.finalReviewPolicy??"detailed",features:a.features.map((t)=>({id:t.id,title:t.title,summary:t.summary,status:"pending",targets:t.targets??[],validation:t.validation??[],dependsOn:t.dependsOn??[]}))}}function ca(e){let a=new Set;for(let s of e.features){if(a.has(s.id))return`Duplicate feature id '${s.id}'.`;a.add(s.id)}for(let s of e.features)for(let d of s.dependsOn){if(!a.has(d))return`Feature '${s.id}' depends on unknown feature '${d}'.`;if(d===s.id)return`Feature '${s.id}' cannot depend on itself.`}let t=new Set,n=new Set,r=new Map(e.features.map((s)=>[s.id,s]));function i(s){if(n.has(s))return!1;if(t.has(s))return!0;t.add(s);for(let d of r.get(s)?.dependsOn??[])if(i(d))return!0;return t.delete(s),n.add(s),!1}return e.features.some((s)=>i(s.id))?"Feature dependencies contain a cycle.":null}function L(e){let a=h();return{version:2,id:sa(),goal:e,status:"planning",approval:"pending",plan:null,activeFeatureId:null,history:[],closure:null,lastError:null,timestamps:{createdAt:a,updatedAt:a,completedAt:null}}}function y(e){return{...e,timestamps:{...e.timestamps,updatedAt:h()}}}function Je(e,a){if(e.approval==="approved"||e.status!=="planning")return l("Approved plans cannot be changed. Reset or start a new session.");let t=la(a),n=ca(t);if(n)return l(n);return u(y({...e,status:"planning",approval:"pending",plan:t,activeFeatureId:null,history:[],closure:null,lastError:null,timestamps:{...e.timestamps,completedAt:null}}))}function Ke(e){if(!e.plan)return l("There is no draft plan to approve.");if(e.approval==="approved"&&e.status==="ready")return u(e);if(e.status!=="planning")return l("Only planning sessions can be approved.");return u(y({...e,approval:"approved",status:"ready"}))}function Be(e,a){return e.status==="pending"&&e.dependsOn.every((t)=>a.has(t))}function da(e,a){let t=new Set(e.filter((i)=>i.status==="completed").map((i)=>i.id)),n=new Map(e.map((i)=>[i.id,i]));if(a){let i=n.get(a);if(!i)return l(`Feature '${a}' is not in the plan.`);if(i.status==="completed")return l(`Feature '${a}' is already completed.`);if(i.status!=="pending")return l(`Feature '${a}' is ${i.status} and must be reset before it can run.`);if(!Be(i,t))return l(`Feature '${a}' has incomplete dependencies.`);return u(i)}let r=e.find((i)=>Be(i,t));return r?u(r):l("No runnable feature is available.")}function Q(e,a,t){return e.map((n)=>n.id===a?{...n,status:t}:n.status==="in_progress"&&t==="in_progress"?{...n,status:"pending"}:n)}function He(e,a){if(e.status==="completed")return l("This Flow session is already completed.");if(!e.plan||e.approval!=="approved")return l("There is no approved plan to run.");if(e.status==="blocked")return l("Blocked features must be reset before rerun.","Call flow_feature_reset for the blocked feature, then start it again.");if(e.activeFeatureId){if(!a||a===e.activeFeatureId){let i=e.plan.features.find((s)=>s.id===e.activeFeatureId);if(i)return u({session:e,feature:i})}return l(`Feature '${e.activeFeatureId}' is already in progress.`)}let t=da(e.plan.features,a);if(!t.ok)return t;let n={...e.plan,features:Q(e.plan.features,t.value.id,"in_progress")},r=y({...e,status:"running",plan:n,activeFeatureId:t.value.id,lastError:null});return u({session:r,feature:r.plan?.features.find((i)=>i.id===t.value.id)??t.value})}function Ge(e){return e.status==="passed"&&e.blockingFindings.length===0}function ua(e,a){if(!e.plan)return!1;return e.plan.features.every((t)=>t.id===a||t.status==="completed")}function g(e,a,t,n){return l(t,n,{...e,lastError:{tool:a,summary:t,recovery:n,recordedAt:h()}})}function pa(e,a){let t=ua(e,a.featureId);if(a.validationRun.length===0)return g(e,"flow_feature_complete","Completion requires recorded validation evidence.","Run the targeted or broad validation command and record the result.");if(!a.validationRun.every((n)=>n.status==="passed"))return g(e,"flow_feature_complete","Completion requires all recorded validation to pass.","Fix failures, rerun validation, then complete the feature.");if(!t&&a.validationScope!=="targeted")return g(e,"flow_feature_complete","Non-final feature completion requires targeted validation.","Record validationScope: targeted for ordinary feature completion.");if(t&&a.validationScope!=="broad")return g(e,"flow_feature_complete","Final feature completion requires broad validation.","Run the project-level gate and record validationScope: broad.");if(!Ge(a.featureReview))return g(e,"flow_feature_complete","Completion requires a passing featureReview with no blocking findings.","Fix or acknowledge the review findings before completing.");if(t){if(!a.finalReview)return g(e,"flow_feature_complete","Final feature completion requires a finalReview.","Run final review and include the finalReview payload.");if(!Ge(a.finalReview))return g(e,"flow_feature_complete","Final completion requires a passing finalReview.","Resolve final review findings before completing the session.");let n=e.plan?.finalReviewPolicy??"detailed";if(a.finalReview.reviewDepth!==n)return g(e,"flow_feature_complete",`Final review depth must match the plan policy '${n}'.`,"Record a finalReview whose reviewDepth matches the approved plan.")}return u(void 0)}function Xe(e,a){if(!e.plan||e.status!=="running"||!e.activeFeatureId)return l("No feature is currently running.");let t=U.parse(a);if(t.featureId!==e.activeFeatureId)return l(`Worker result feature '${t.featureId}' does not match active feature '${e.activeFeatureId}'.`);if(t.status==="needs_input"){let m={featureId:t.featureId,status:"needs_input",summary:t.summary,recordedAt:h(),artifactsChanged:t.artifactsChanged,validationRun:t.validationRun,validationScope:t.validationScope,featureReview:t.featureReview,finalReview:t.finalReview,outcome:t.outcome};return u(y({...e,status:"blocked",activeFeatureId:null,plan:{...e.plan,features:Q(e.plan.features,t.featureId,"blocked")},history:[...e.history,m]}))}let n=pa(e,t);if(!n.ok)return n;let r={featureId:t.featureId,status:"completed",summary:t.summary,recordedAt:h(),artifactsChanged:t.artifactsChanged,validationRun:t.validationRun,validationScope:t.validationScope,featureReview:t.featureReview,finalReview:t.finalReview,outcome:t.outcome},i=Q(e.plan.features,t.featureId,"completed"),s=i.every((m)=>m.status==="completed"),d=h();return u(y({...e,status:s?"completed":"ready",activeFeatureId:null,plan:{...e.plan,features:i},history:[...e.history,r],closure:s?{kind:"completed",summary:t.summary,recordedAt:d}:null,lastError:null,timestamps:{...e.timestamps,completedAt:s?d:e.timestamps.completedAt}}))}function fa(e,a){let t=new Set([a]),n=!0;while(n){n=!1;for(let r of e){if(t.has(r.id))continue;if(r.dependsOn.some((i)=>t.has(i)))t.add(r.id),n=!0}}return t}function Ye(e,a){if(!e.plan)return l("There is no active plan to reset.");if(!e.plan.features.some((s)=>s.id===a))return l(`Feature '${a}' is not in the plan.`);let t=fa(e.plan.features,a),n=e.activeFeatureId&&t.has(e.activeFeatureId)?null:e.activeFeatureId,r=e.plan.features.map((s)=>t.has(s.id)?{...s,status:"pending"}:s),i=e.approval!=="approved"?"planning":n?"running":r.some((s)=>s.status==="blocked")?"blocked":"ready";return u(y({...e,status:i,activeFeatureId:n,plan:{...e.plan,features:r},closure:null,lastError:null,timestamps:{...e.timestamps,completedAt:null}}))}function Ze(e,a,t){if(a==="completed"){if(!e.plan||e.approval!=="approved")return l("Cannot close a Flow session as completed without an approved plan.");let r=e.plan.features.filter((i)=>i.status!=="completed");if(r.length>0)return l("Cannot close a Flow session as completed with unfinished features.",`Unfinished features: ${r.map((i)=>i.id).join(", ")}`);if(e.status!=="completed")return l("Cannot close a Flow session as completed before final completion gates pass.")}let n=h();return u(y({...e,status:a==="completed"?"completed":e.status,activeFeatureId:null,closure:{kind:a,summary:t??`Session closed as ${a}.`,recordedAt:n},timestamps:{...e.timestamps,completedAt:a==="completed"?n:e.timestamps.completedAt}}))}function b(e){if(!e)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"Start with /flow-plan <goal>."};let a=e.plan?.features??[],t=a.filter((s)=>s.status==="completed"),n=e.history.at(-1)??null,r=e.status==="blocked"?n:null,i=e.activeFeatureId?a.find((s)=>s.id===e.activeFeatureId):null;return{status:e.status,summary:e.closure?.summary??e.lastError?.summary??r?.summary??e.plan?.summary??"Flow session is active.",nextAction:ma(e),session:{id:e.id,goal:e.goal,status:e.status,approval:e.approval,activeFeature:i??null,progress:{completed:t.length,total:a.length},features:a,closure:e.closure,lastError:e.lastError,latestHistoryEntry:n,historyCount:e.history.length,timestamps:e.timestamps}}}function ma(e){if(!e.plan)return"Save a plan with flow_plan_save.";if(e.approval!=="approved")return"Approve the plan.";if(e.status==="ready")return"Start the next feature.";if(e.status==="running")return"Complete or reset the active feature.";if(e.status==="blocked")return"Reset the blocked feature or close the session.";if(e.status==="completed")return"Close/archive the session or start a new goal.";return"Inspect session state."}var ha=p.object({goal:p.string().trim().min(1).optional(),plan:E.optional()}).strict(),ga=p.object({featureId:p.string().min(1).optional()}).strict(),wa=p.object({featureId:p.string().min(1)}).strict(),va=p.object({kind:p.enum(["completed","deferred","abandoned"]),summary:p.string().trim().min(1).optional()}).strict();function R(e){return{status:"error",summary:e.message,...e.recovery?{recovery:e.recovery}:{}}}async function S(e,a){return ze(e,async()=>a(await A(e)))}async function Qe(e){return b(await A(e))}async function et(e,a){let t=ha.parse(a??{});return S(e,async(n)=>{let r=t.goal??n?.goal;if(!r)return{status:"missing_goal",summary:"Provide a goal before saving a Flow plan.",nextAction:"/flow-plan <goal>"};if(n?.status==="completed")await Z(e,n);let i=n?.status==="completed"?L(r):n??L(r);if(i.goal!==r){if(i.approval==="approved")return{status:"error",summary:"An approved Flow session already exists for a different goal. Close it before starting a new one."}}let s=i.goal===r?i:L(r),d=t.plan?Je(s,t.plan):{ok:!0,value:s};if(!d.ok)return R(d);let m=await v(e,d.value);return{...b(m),status:"ok",summary:t.plan?"Flow plan saved.":"Flow session ready."}})}async function tt(e){return S(e,async(a)=>{if(!a)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let t=Ke(a);if(!t.ok)return R(t);let n=await v(e,t.value);return{...b(n),status:"ok",summary:"Flow plan approved."}})}async function at(e,a){let t=ga.parse(a??{});return S(e,async(n)=>{if(!n)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let r=He(n,t.featureId);if(!r.ok)return R(r);let i=await v(e,r.value.session);return{...b(i),status:"ok",summary:`Started feature '${r.value.feature.id}'.`,feature:r.value.feature}})}async function nt(e,a){let t=U.parse(a??{});return S(e,async(n)=>{if(!n)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let r=Xe(n,t);if(!r.ok){if(r.session)await v(e,r.session);return R(r)}let i=await v(e,r.value);return{...b(i),status:"ok",summary:"Feature result recorded."}})}async function rt(e,a){let t=wa.parse(a??{});return S(e,async(n)=>{if(!n)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let r=Ye(n,t.featureId);if(!r.ok)return R(r);let i=await v(e,r.value);return{...b(i),status:"ok",summary:`Feature '${t.featureId}' reset.`}})}async function ot(e,a){let t=va.parse(a??{});return S(e,async(n)=>{if(!n)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let r=Ze(n,t.kind,t.summary);if(!r.ok)return R(r);return await Z(e,r.value),{status:"ok",summary:`Flow session closed as ${t.kind}.`,archivedSessionId:r.value.id,closure:r.value.closure}})}import{tool as f}from"@opencode-ai/plugin";var c=f.schema;function it(e){return JSON.stringify(e,null,2)}function ya(e){return it({status:"error",summary:e instanceof Error?e.message:String(e)})}async function k(e,a){try{return it(await a(De(e)))}catch(t){return ya(t)}}function st(e){return z(e)("info","Creating minimal Flow v4 tool surface."),{flow_status:f({description:"Show the active Flow session and next action",args:{},execute:(a,t)=>k(t,Qe)}),flow_plan_save:f({description:"Create or update a draft Flow plan for the active goal",args:{goal:c.string().optional(),plan:c.any().optional()},execute:(a,t)=>k(t,(n)=>et(n,a))}),flow_plan_approve:f({description:"Approve the current draft Flow plan",args:{},execute:(a,t)=>k(t,tt)}),flow_run_start:f({description:"Start the next runnable approved Flow feature",args:{featureId:c.string().optional()},execute:(a,t)=>k(t,(n)=>at(n,a))}),flow_feature_complete:f({description:"Record a completed or blocked active feature with validation and review evidence",args:{status:c.enum(["ok","needs_input"]),featureId:c.string(),summary:c.string(),artifactsChanged:c.array(c.object({path:c.string()})).optional(),validationRun:c.array(c.object({command:c.string(),status:c.enum(["passed","failed"]),summary:c.string()})).optional(),validationScope:c.enum(["targeted","broad"]).optional(),featureReview:c.any().optional(),finalReview:c.any().optional(),outcome:c.any().optional()},execute:(a,t)=>k(t,(n)=>nt(n,a))}),flow_feature_reset:f({description:"Reset one feature and its dependents to pending",args:{featureId:c.string()},execute:(a,t)=>k(t,(n)=>rt(n,a))}),flow_session_close:f({description:"Close and archive the active Flow session",args:{kind:c.enum(["completed","deferred","abandoned"]),summary:c.string().optional()},execute:(a,t)=>k(t,(n)=>ot(n,a))})}}async function lt(e){let a=e.worktree??e.directory;if(!a)return null;try{let t=await A(a);if(!t)return null;return["Flow session facts:",`- goal: ${t.goal}`,`- status: ${t.status}`,`- approval: ${t.approval}`,`- active feature: ${t.activeFeatureId??"none"}`,`- progress: ${t.plan?.features.filter((n)=>n.status==="completed").length??0}/${t.plan?.features.length??0}`,"Call flow_status before any Flow action."].join(`
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
//# debugId=E0CD440B3A586E5F64756E2164756E21
|
|
1062
|
+
`;var X=[{name:"flow",files:[{relativePath:"SKILL.md",content:ge},{relativePath:"references/recovery-playbook.md",content:me},{relativePath:"references/parallel-orchestration.md",content:fe},{relativePath:"references/handoff-format.md",content:pe},{relativePath:"references/verification-gates.md",content:he}]},{name:"flow-plan",files:[{relativePath:"SKILL.md",content:xe},{relativePath:"references/planning-examples.md",content:ke},{relativePath:"references/parallel-discovery.md",content:be}]},{name:"flow-run",files:[{relativePath:"SKILL.md",content:_e},{relativePath:"references/validation-rubric.md",content:Fe},{relativePath:"references/audit-rubric.md",content:Re}]},{name:"flow-review",files:[{relativePath:"SKILL.md",content:j},{relativePath:"references/review-rubric.md",content:U}]},{name:"flow-deslop",files:[{relativePath:"SKILL.md",content:ye},{relativePath:"references/smell-rubric.md",content:we},{relativePath:"references/refactor-workflow.md",content:ve}]},{name:"flow-ui-quality",files:[{relativePath:"SKILL.md",content:Pe},{relativePath:"references/ui-rubric.md",content:Se},{relativePath:"references/visual-verification.md",content:Ie}]}];var Gt=".flow-skill-version",v=null;function Z(){return process.env.HOME??process.env.USERPROFILE??""}function Ce(e=Z()){return P(e,".config","opencode","skills")}function Te(e){return zt("sha256").update(e).digest("hex")}function Y(e,a){return[`version=${a}`,...e.files.map((t)=>`file=${t.relativePath} sha256=${Te(t.content)}`),""].join(`
|
|
1063
|
+
`)}async function H(e){try{return await Mt(e,"utf8")}catch(a){if(a.code==="ENOENT")return null;throw a}}function Kt(e){let a=new Map;if(!e)return a;for(let t of e.split(/\r?\n/)){let r=/^file=(.+) sha256=([a-f0-9]{64})$/.exec(t)??/^file=(.+)=sha256:([a-f0-9]{64})$/.exec(t);if(r?.[1]&&r[2])a.set(r[1],r[2]);let n=/^hash=sha256:([a-f0-9]{64})$/.exec(t);if(n?.[1]&&!a.has("SKILL.md"))a.set("SKILL.md",n[1])}return a}function Ae(e,a){let t=Jt(P(e,...a.split("/")));if(t!==e&&t.startsWith(`${e}${Lt}`))return t;throw Error(`Unsafe skill file path '${a}'.`)}async function Xt(e,a,t){let r=P(t,e.name),n=P(r,Gt),i=await H(n),s=Kt(i);if(await H(P(r,"SKILL.md"))!==null&&i===null)return{name:e.name,action:"skipped_foreign"};let p=!1,le=!1;for(let R of e.files){let I=Ae(r,R.relativePath),T=await H(I);if(T===R.content)continue;p=!0;let de=s.get(R.relativePath);if(T!==null&&(de?Te(T)!==de:i!==null))await E(`${I}.backup`,T,"utf8"),le=!0}if(!p&&i===Y(e,a))return{name:e.name,action:"unchanged"};if(!p)return await E(n,Y(e,a),"utf8"),{name:e.name,action:"marker_updated"};let vt=i!==null;for(let R of e.files){let I=Ae(r,R.relativePath);await $t(Bt(I),{recursive:!0}),await E(I,R.content,"utf8")}return await E(n,Y(e,a),"utf8"),{name:e.name,action:le?"updated_with_backup":vt?"updated":"installed"}}function Ue(){return X.map((e)=>e.name)}function Yt(e,a,t){let r=t.filter((c)=>["installed","updated","updated_with_backup"].includes(c.action)).map((c)=>c.name),n=t.filter((c)=>c.action==="skipped_foreign").map((c)=>c.name),i=n.length>0?"action_required":r.length>0?"restart_required":"ok",s=i==="restart_required"?`Flow installed or updated skills during this startup (${r.join(", ")}). Restart OpenCode before loading Flow skills.`:i==="action_required"?`Flow found user-owned skill folders for managed skills (${n.join(", ")}). Run ${je(e)} for repair guidance.`:"Flow skills are synced.";return{status:i,version:e,root:a,checkedAt:new Date().toISOString(),expectedSkills:Ue(),results:t,changedSkills:r,actionRequiredSkills:n,restartRequired:i==="restart_required",summary:s}}function Ht(e,a,t){let r=t instanceof Error?t.message:String(t);return{status:"error",version:e,root:a,checkedAt:new Date().toISOString(),expectedSkills:Ue(),results:[],changedSkills:[],actionRequiredSkills:[],restartRequired:!1,summary:`Flow skill sync failed: ${r}`,error:r}}function je(e){return`npx -y opencode-plugin-flow@${e} doctor`}function Q(e=v){if(!e||e.status==="ok")return null;return{status:e.status==="error"?"sync_failed":e.status,summary:e.summary,version:e.version,root:e.root,...e.changedSkills.length>0?{changed:e.changedSkills}:{},...e.actionRequiredSkills.length>0?{actionRequired:e.actionRequiredSkills}:{},...e.error?{error:e.error}:{}}}function O(e=v){let a=Q(e);if(!a)return null;return["Flow setup warning:",a.summary,`Skills root: ${a.root}`,`Use \`${je(a.version)}\` for details.`].join(`
|
|
1064
|
+
`)}function Ee(){if(process.env.npm_package_version)return process.env.npm_package_version;try{let e=Vt(import.meta.url);for(let a of["../package.json","../../package.json"])try{let t=e(a);if(t.version)return t.version}catch{}}catch{}return"0.0.0"}async function Zt(e,a=Z()){let t=Ce(a);return Promise.all(X.map((r)=>Xt(r,e,t)))}async function Oe(e,a,t=Z()){let r=Ce(t);try{let n=await Zt(e,t);v=Yt(e,r,n);let i=n.filter((s)=>s.action==="installed"||s.action==="updated"||s.action==="updated_with_backup");if(i.length>0)a("info",`Flow synced skills (${i.map((s)=>`${s.name}:${s.action}`).join(", ")}). Restart OpenCode if skills were just installed.`);if(v.status==="action_required")a("warn",v.summary)}catch(n){v=Ht(e,r,n),a("warn",v.summary)}}import{randomUUID as ia}from"node:crypto";import{mkdir as $,open as $e,readFile as Je,rename as sa,rm as M,writeFile as Me}from"node:fs/promises";import{homedir as ca}from"node:os";import{dirname as Ve,isAbsolute as Dr,join as F,parse as la,resolve as Le}from"node:path";import{setTimeout as da}from"node:timers/promises";function Qt(e){let a=[],t=0;while(t<e.length){let r=e[t];if(r==="{"){a.push({isObject:!0,keys:new Set,awaitingKey:!0}),t+=1;continue}if(r==="["){a.push({isObject:!1,keys:new Set,awaitingKey:!1}),t+=1;continue}if(r==="}"||r==="]"){a.pop(),t+=1;continue}if(r===","){let n=a.at(-1);if(n?.isObject)n.awaitingKey=!0;t+=1;continue}if(r===":"){let n=a.at(-1);if(n?.isObject)n.awaitingKey=!1;t+=1;continue}if(r==='"'){let n=t+1;while(n<e.length){if(e[n]==="\\"){n+=2;continue}if(e[n]==='"')break;n+=1}let i=a.at(-1);if(i?.isObject&&i.awaitingKey){let s=JSON.parse(e.slice(t,n+1));if(i.keys.has(s))return s;i.keys.add(s)}t=n+1;continue}t+=1}return null}function qe(e,a){if(e.trim().length===0)return{ok:!1,error:`${a} is empty.`};let t;try{t=JSON.parse(e)}catch(n){return{ok:!1,error:n instanceof Error?`${a} is not valid JSON: ${n.message}`:`${a} is not valid JSON.`}}if(t===null||typeof t!=="object"||Array.isArray(t))return{ok:!1,error:`${a} must be a JSON object.`};let r=Qt(e);if(r)return{ok:!1,error:`${a} has duplicate key '${r}'.`};return{ok:!0,value:t}}import{z as o}from"zod";var w=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,A="Feature ids must be lowercase kebab-case",Ne=o.enum(["pending","in_progress","completed","blocked"]),ea=o.enum(["planning","ready","running","blocked","completed"]),ta=o.enum(["passed","failed"]),aa=o.enum(["passed","failed"]),ee=o.enum(["targeted","broad"]),ne=o.enum(["broad","detailed"]),ra=o.object({summary:o.string().min(1),severity:o.enum(["blocking","advisory"]).default("blocking")}).strict(),q=o.object({status:ta,summary:o.string().min(1),blockingFindings:o.array(ra).default([])}).strict(),te=q.extend({reviewDepth:ne}).strict(),ae=o.object({command:o.string().min(1),status:aa,summary:o.string().min(1)}).strict(),re=o.object({path:o.string().min(1)}).strict(),De=o.object({id:o.string().regex(w,A),title:o.string().min(1),summary:o.string().min(1),status:Ne.default("pending"),targets:o.array(o.string().min(1)).default([]),validation:o.array(o.string().min(1)).default([]),dependsOn:o.array(o.string().regex(w)).default([])}).strict(),We=o.object({summary:o.string().min(1),overview:o.string().min(1),requirements:o.array(o.string().min(1)).default([]),decisions:o.array(o.string().min(1)).default([]),finalReviewPolicy:ne.default("detailed"),features:o.array(De).min(1)}).strict(),N=We.omit({features:!0}).extend({finalReviewPolicy:ne.optional(),features:o.array(De.omit({status:!0}).extend({status:Ne.optional(),targets:o.array(o.string().min(1)).optional(),validation:o.array(o.string().min(1)).optional(),dependsOn:o.array(o.string().regex(w)).optional()}).strict()).min(1)}),ze=o.object({kind:o.enum(["completed","blocked","needs_input","replan_required"]).default("completed"),summary:o.string().min(1).optional(),resolutionHint:o.string().min(1).optional()}).strict(),na=o.object({kind:o.enum(["blocked","needs_input","replan_required"]).default("needs_input"),summary:o.string().min(1),resolutionHint:o.string().min(1).optional()}).strict(),D=o.discriminatedUnion("status",[o.object({status:o.literal("ok"),featureId:o.string().regex(w,A),summary:o.string().min(1),artifactsChanged:o.array(re).default([]),validationRun:o.array(ae).default([]),validationScope:ee,featureReview:q,finalReview:te.optional(),outcome:ze.optional()}).strict(),o.object({status:o.literal("needs_input"),featureId:o.string().regex(w,A),summary:o.string().min(1),artifactsChanged:o.array(re).default([]),validationRun:o.array(ae).default([]),validationScope:ee.optional(),featureReview:q.optional(),finalReview:te.optional(),outcome:na}).strict()]).superRefine((e,a)=>{if(e.status==="ok"&&e.outcome?.kind&&e.outcome.kind!=="completed")a.addIssue({code:"custom",path:["outcome","kind"],message:'ok worker results must use outcome.kind "completed".'})}),oa=o.object({featureId:o.string().regex(w,A),status:o.enum(["completed","blocked","needs_input"]),summary:o.string().min(1),recordedAt:o.string().min(1),artifactsChanged:o.array(re).default([]),validationRun:o.array(ae).default([]),validationScope:ee.optional(),featureReview:q.optional(),finalReview:te.optional(),outcome:ze.optional()}).strict(),W=o.object({version:o.literal(2),id:o.string().min(1),goal:o.string().min(1),status:ea,approval:o.enum(["pending","approved"]),plan:We.nullable(),activeFeatureId:o.string().regex(w,A).nullable(),history:o.array(oa).default([]),closure:o.object({kind:o.enum(["completed","deferred","abandoned"]),summary:o.string().min(1),recordedAt:o.string().min(1)}).strict().nullable(),lastError:o.object({tool:o.string().min(1),summary:o.string().min(1),recovery:o.string().min(1).optional(),recordedAt:o.string().min(1)}).strict().nullable().default(null),timestamps:o.object({createdAt:o.string().min(1),updatedAt:o.string().min(1),completedAt:o.string().min(1).nullable()}).strict()}).strict();class V extends Error{code="INVALID_FLOW_WORKSPACE_ROOT";constructor(e){super(e);this.name="InvalidFlowWorkspaceRootError"}}function oe(e){let a=e?.trim();if(!a)return null;let t=Le(a);return la(t).root===t?null:t}function B(e){let a=oe(e);if(!a)throw new V("Flow requires a non-root workspace path.");if(a===Le(process.env.HOME??ca()))throw new V("Flow refuses to use $HOME itself as a mutable workspace root.");return a}function Ge(e){let a=oe(e.worktree)??oe(e.directory);if(!a)throw new V("Flow could not resolve a workspace root from tool context.");return B(a)}function J(e){return F(e,".flow")}function ie(e){return F(J(e),"session.json")}function Ke(e){return F(J(e),"history")}function ua(e,a){if(!/^[a-zA-Z0-9_-]+$/.test(a))throw Error("Invalid session id.");return F(Ke(e),`${a}.json`)}async function Xe(e,a){await $(Ve(e),{recursive:!0});let t=`${e}.${process.pid}.${ia()}.tmp`,r=await $e(t,"w");try{await r.writeFile(a,"utf8"),await r.sync()}catch(i){throw await r.close(),await M(t,{force:!0}),i}await r.close();try{await sa(t,e)}catch(i){throw await M(t,{force:!0}),i}let n=await $e(Ve(e),"r");try{await n.sync()}finally{await n.close()}}var z=new Map,pa=30000,fa=25;async function ma(e){let a=J(e),t=F(a,"session.lock"),r=Date.now();while(!0)try{return await $(t,{recursive:!1}),async()=>{await M(t,{recursive:!0,force:!0})}}catch(n){let i=n.code;if(i==="ENOENT"){await $(a,{recursive:!0});continue}if(i!=="EEXIST")throw n;if(Date.now()-r>pa)throw Error(`Timed out waiting for Flow session lock at ${t}.`);await da(fa)}}async function Ye(e,a){let t=z.get(e)??Promise.resolve(),r=()=>{},n=new Promise((c)=>{r=c}),i=t.catch(()=>{return}).then(()=>n);z.set(e,i);let s=null;try{return await t.catch(()=>{return}),s=await ma(e),await a()}finally{try{await s?.()}finally{if(r(),z.get(e)===i)z.delete(e)}}}async function C(e){let a=B(e),t;try{t=await Je(ie(a),"utf8")}catch(n){if(n.code==="ENOENT")return null;throw n}let r=qe(t,"Flow session file");if(!r.ok)throw Error(r.error);return W.parse(r.value)}async function y(e,a){let t=B(e),r=W.parse(a);return await Xe(ie(t),`${JSON.stringify(r,null,2)}
|
|
1065
|
+
`),await He(t),r}async function se(e,a){let t=B(e);await $(Ke(t),{recursive:!0}),await Xe(ua(t,a.id),`${JSON.stringify(W.parse(a),null,2)}
|
|
1066
|
+
`),await M(ie(t),{force:!0}),await He(t)}var Be=["session.json","history/","session.lock/",".gitignore",""].join(`
|
|
1067
|
+
`);async function He(e){let a=F(J(e),".gitignore");try{if((await Je(a,"utf8")).trim()==="session.lock/")await Me(a,Be,"utf8")}catch(t){if(t.code!=="ENOENT")throw t;await Me(a,Be,"utf8")}}function Ze(e){return async(a)=>{ue(a)}}function L(e){let a=e?.client,t=a?.app?.log;return(r,n)=>{if(typeof t!=="function")return;try{t.call(a?.app,{body:{service:"opencode-plugin-flow",level:r,message:n}})}catch{}}}import{z as f}from"zod";import{randomUUID as ga}from"node:crypto";var ha=null;function h(){return ha?.()??new Date().toISOString()}function u(e){return{ok:!0,value:e}}function l(e,a,t){return{ok:!1,message:e,...a?{recovery:a}:{},...t?{session:t}:{}}}function va(e){let a=N.parse(e);return{summary:a.summary,overview:a.overview,requirements:a.requirements??[],decisions:a.decisions??[],finalReviewPolicy:a.finalReviewPolicy??"detailed",features:a.features.map((t)=>({id:t.id,title:t.title,summary:t.summary,status:"pending",targets:t.targets??[],validation:t.validation??[],dependsOn:t.dependsOn??[]}))}}function wa(e){let a=new Set;for(let s of e.features){if(a.has(s.id))return`Duplicate feature id '${s.id}'.`;a.add(s.id)}for(let s of e.features)for(let c of s.dependsOn){if(!a.has(c))return`Feature '${s.id}' depends on unknown feature '${c}'.`;if(c===s.id)return`Feature '${s.id}' cannot depend on itself.`}let t=new Set,r=new Set,n=new Map(e.features.map((s)=>[s.id,s]));function i(s){if(r.has(s))return!1;if(t.has(s))return!0;t.add(s);for(let c of n.get(s)?.dependsOn??[])if(i(c))return!0;return t.delete(s),r.add(s),!1}return e.features.some((s)=>i(s.id))?"Feature dependencies contain a cycle.":null}function G(e){let a=h();return{version:2,id:ga(),goal:e,status:"planning",approval:"pending",plan:null,activeFeatureId:null,history:[],closure:null,lastError:null,timestamps:{createdAt:a,updatedAt:a,completedAt:null}}}function b(e){return{...e,timestamps:{...e.timestamps,updatedAt:h()}}}function tt(e,a){if(e.approval==="approved"||e.status!=="planning")return l("Approved plans cannot be changed. Reset or start a new session.");let t=va(a),r=wa(t);if(r)return l(r);return u(b({...e,status:"planning",approval:"pending",plan:t,activeFeatureId:null,history:[],closure:null,lastError:null,timestamps:{...e.timestamps,completedAt:null}}))}function at(e){if(!e.plan)return l("There is no draft plan to approve.");if(e.approval==="approved"&&e.status==="ready")return u(e);if(e.status!=="planning")return l("Only planning sessions can be approved.");return u(b({...e,approval:"approved",status:"ready"}))}function Qe(e,a){return e.status==="pending"&&e.dependsOn.every((t)=>a.has(t))}function ya(e,a){let t=new Set(e.filter((i)=>i.status==="completed").map((i)=>i.id)),r=new Map(e.map((i)=>[i.id,i]));if(a){let i=r.get(a);if(!i)return l(`Feature '${a}' is not in the plan.`);if(i.status==="completed")return l(`Feature '${a}' is already completed.`);if(i.status!=="pending")return l(`Feature '${a}' is ${i.status} and must be reset before it can run.`);if(!Qe(i,t))return l(`Feature '${a}' has incomplete dependencies.`);return u(i)}let n=e.find((i)=>Qe(i,t));return n?u(n):l("No runnable feature is available.")}function ce(e,a,t){return e.map((r)=>r.id===a?{...r,status:t}:r.status==="in_progress"&&t==="in_progress"?{...r,status:"pending"}:r)}function rt(e,a){if(e.status==="completed")return l("This Flow session is already completed.");if(!e.plan||e.approval!=="approved")return l("There is no approved plan to run.");if(e.status==="blocked")return l("Blocked features must be reset before rerun.","Call flow_feature_reset for the blocked feature, then start it again.");if(e.activeFeatureId){if(!a||a===e.activeFeatureId){let i=e.plan.features.find((s)=>s.id===e.activeFeatureId);if(i)return u({session:e,feature:i})}return l(`Feature '${e.activeFeatureId}' is already in progress.`)}let t=ya(e.plan.features,a);if(!t.ok)return t;let r={...e.plan,features:ce(e.plan.features,t.value.id,"in_progress")},n=b({...e,status:"running",plan:r,activeFeatureId:t.value.id,lastError:null});return u({session:n,feature:n.plan?.features.find((i)=>i.id===t.value.id)??t.value})}function et(e){return e.status==="passed"&&e.blockingFindings.length===0}function ba(e,a){if(!e.plan)return!1;return e.plan.features.every((t)=>t.id===a||t.status==="completed")}function g(e,a,t,r){return l(t,r,{...e,lastError:{tool:a,summary:t,recovery:r,recordedAt:h()}})}function ka(e,a){let t=ba(e,a.featureId);if(a.validationRun.length===0)return g(e,"flow_feature_complete","Completion requires recorded validation evidence.","Run the targeted or broad validation command and record the result.");if(!a.validationRun.every((r)=>r.status==="passed"))return g(e,"flow_feature_complete","Completion requires all recorded validation to pass.","Fix failures, rerun validation, then complete the feature.");if(!t&&a.validationScope!=="targeted")return g(e,"flow_feature_complete","Non-final feature completion requires targeted validation.","Record validationScope: targeted for ordinary feature completion.");if(t&&a.validationScope!=="broad")return g(e,"flow_feature_complete","Final feature completion requires broad validation.","Run the project-level gate and record validationScope: broad.");if(!et(a.featureReview))return g(e,"flow_feature_complete","Completion requires a passing featureReview with no blocking findings.","Fix or acknowledge the review findings before completing.");if(t){if(!a.finalReview)return g(e,"flow_feature_complete","Final feature completion requires a finalReview.","Run final review and include the finalReview payload.");if(!et(a.finalReview))return g(e,"flow_feature_complete","Final completion requires a passing finalReview.","Resolve final review findings before completing the session.");let r=e.plan?.finalReviewPolicy??"detailed";if(a.finalReview.reviewDepth!==r)return g(e,"flow_feature_complete",`Final review depth must match the plan policy '${r}'.`,"Record a finalReview whose reviewDepth matches the approved plan.")}return u(void 0)}function nt(e,a){if(!e.plan||e.status!=="running"||!e.activeFeatureId)return l("No feature is currently running.");let t=D.parse(a);if(t.featureId!==e.activeFeatureId)return l(`Worker result feature '${t.featureId}' does not match active feature '${e.activeFeatureId}'.`);if(t.status==="needs_input"){let p={featureId:t.featureId,status:"needs_input",summary:t.summary,recordedAt:h(),artifactsChanged:t.artifactsChanged,validationRun:t.validationRun,validationScope:t.validationScope,featureReview:t.featureReview,finalReview:t.finalReview,outcome:t.outcome};return u(b({...e,status:"blocked",activeFeatureId:null,plan:{...e.plan,features:ce(e.plan.features,t.featureId,"blocked")},history:[...e.history,p]}))}let r=ka(e,t);if(!r.ok)return r;let n={featureId:t.featureId,status:"completed",summary:t.summary,recordedAt:h(),artifactsChanged:t.artifactsChanged,validationRun:t.validationRun,validationScope:t.validationScope,featureReview:t.featureReview,finalReview:t.finalReview,outcome:t.outcome},i=ce(e.plan.features,t.featureId,"completed"),s=i.every((p)=>p.status==="completed"),c=h();return u(b({...e,status:s?"completed":"ready",activeFeatureId:null,plan:{...e.plan,features:i},history:[...e.history,n],closure:s?{kind:"completed",summary:t.summary,recordedAt:c}:null,lastError:null,timestamps:{...e.timestamps,completedAt:s?c:e.timestamps.completedAt}}))}function xa(e,a){let t=new Set([a]),r=!0;while(r){r=!1;for(let n of e){if(t.has(n.id))continue;if(n.dependsOn.some((i)=>t.has(i)))t.add(n.id),r=!0}}return t}function ot(e,a){if(!e.plan)return l("There is no active plan to reset.");if(!e.plan.features.some((s)=>s.id===a))return l(`Feature '${a}' is not in the plan.`);let t=xa(e.plan.features,a),r=e.activeFeatureId&&t.has(e.activeFeatureId)?null:e.activeFeatureId,n=e.plan.features.map((s)=>t.has(s.id)?{...s,status:"pending"}:s),i=e.approval!=="approved"?"planning":r?"running":n.some((s)=>s.status==="blocked")?"blocked":"ready";return u(b({...e,status:i,activeFeatureId:r,plan:{...e.plan,features:n},closure:null,lastError:null,timestamps:{...e.timestamps,completedAt:null}}))}function it(e,a,t){if(a==="completed"){if(!e.plan||e.approval!=="approved")return l("Cannot close a Flow session as completed without an approved plan.");let n=e.plan.features.filter((i)=>i.status!=="completed");if(n.length>0)return l("Cannot close a Flow session as completed with unfinished features.",`Unfinished features: ${n.map((i)=>i.id).join(", ")}`);if(e.status!=="completed")return l("Cannot close a Flow session as completed before final completion gates pass.")}let r=h();return u(b({...e,status:a==="completed"?"completed":e.status,activeFeatureId:null,closure:{kind:a,summary:t??`Session closed as ${a}.`,recordedAt:r},timestamps:{...e.timestamps,completedAt:a==="completed"?r:e.timestamps.completedAt}}))}function k(e){if(!e)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"Start with /flow-plan <goal>."};let a=e.plan?.features??[],t=a.filter((s)=>s.status==="completed"),r=e.history.at(-1)??null,n=e.status==="blocked"?r:null,i=e.activeFeatureId?a.find((s)=>s.id===e.activeFeatureId):null;return{status:e.status,summary:e.closure?.summary??e.lastError?.summary??n?.summary??e.plan?.summary??"Flow session is active.",nextAction:Ra(e),session:{id:e.id,goal:e.goal,status:e.status,approval:e.approval,activeFeature:i??null,progress:{completed:t.length,total:a.length},features:a,closure:e.closure,lastError:e.lastError,latestHistoryEntry:r,historyCount:e.history.length,timestamps:e.timestamps}}}function Ra(e){if(!e.plan)return"Save a plan with flow_plan_save.";if(e.approval!=="approved")return"Approve the plan.";if(e.status==="ready")return"Start the next feature.";if(e.status==="running")return"Complete or reset the active feature.";if(e.status==="blocked")return"Reset the blocked feature or close the session.";if(e.status==="completed")return"Close/archive the session or start a new goal.";return"Inspect session state."}var Fa=f.object({goal:f.string().trim().min(1).optional(),plan:N.optional()}).strict(),_a=f.object({featureId:f.string().min(1).optional()}).strict(),Sa=f.object({featureId:f.string().min(1)}).strict(),Ia=f.object({kind:f.enum(["completed","deferred","abandoned"]),summary:f.string().trim().min(1).optional()}).strict();function _(e){return{status:"error",summary:e.message,...e.recovery?{recovery:e.recovery}:{}}}async function S(e,a){return Ye(e,async()=>a(await C(e)))}async function st(e){return k(await C(e))}async function ct(e,a){let t=Fa.parse(a??{});return S(e,async(r)=>{let n=t.goal??r?.goal;if(!n)return{status:"missing_goal",summary:"Provide a goal before saving a Flow plan.",nextAction:"/flow-plan <goal>"};if(r?.status==="completed")await se(e,r);let i=r?.status==="completed"?G(n):r??G(n);if(i.goal!==n){if(i.approval==="approved")return{status:"error",summary:"An approved Flow session already exists for a different goal. Close it before starting a new one."}}let s=i.goal===n?i:G(n),c=t.plan?tt(s,t.plan):{ok:!0,value:s};if(!c.ok)return _(c);let p=await y(e,c.value);return{...k(p),status:"ok",summary:t.plan?"Flow plan saved.":"Flow session ready."}})}async function lt(e){return S(e,async(a)=>{if(!a)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let t=at(a);if(!t.ok)return _(t);let r=await y(e,t.value);return{...k(r),status:"ok",summary:"Flow plan approved."}})}async function dt(e,a){let t=_a.parse(a??{});return S(e,async(r)=>{if(!r)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let n=rt(r,t.featureId);if(!n.ok)return _(n);let i=await y(e,n.value.session);return{...k(i),status:"ok",summary:`Started feature '${n.value.feature.id}'.`,feature:n.value.feature}})}async function ut(e,a){let t=D.parse(a??{});return S(e,async(r)=>{if(!r)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let n=nt(r,t);if(!n.ok){if(n.session)await y(e,n.session);return _(n)}let i=await y(e,n.value);return{...k(i),status:"ok",summary:"Feature result recorded."}})}async function pt(e,a){let t=Sa.parse(a??{});return S(e,async(r)=>{if(!r)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let n=ot(r,t.featureId);if(!n.ok)return _(n);let i=await y(e,n.value);return{...k(i),status:"ok",summary:`Feature '${t.featureId}' reset.`}})}async function ft(e,a){let t=Ia.parse(a??{});return S(e,async(r)=>{if(!r)return{status:"missing_session",summary:"No active Flow session exists.",nextAction:"/flow-plan <goal>"};let n=it(r,t.kind,t.summary);if(!n.ok)return _(n);return await se(e,n.value),{status:"ok",summary:`Flow session closed as ${t.kind}.`,archivedSessionId:n.value.id,closure:n.value.closure}})}import{tool as m}from"@opencode-ai/plugin";var d=m.schema;function mt(e){return JSON.stringify(e,null,2)}function Pa(e){return mt({status:"error",summary:e instanceof Error?e.message:String(e)})}async function x(e,a){try{return mt(await a(Ge(e)))}catch(t){return Pa(t)}}async function Aa(e){let a=await st(e),t=Q();if(!t)return a;return{...a,setup:{skills:t}}}function ht(e){return L(e)("info","Creating minimal Flow v4 tool surface."),{flow_status:m({description:"Show the active Flow session and next action",args:{},execute:(a,t)=>x(t,Aa)}),flow_plan_save:m({description:"Create or update a draft Flow plan for the active goal",args:{goal:d.string().optional(),plan:d.any().optional()},execute:(a,t)=>x(t,(r)=>ct(r,a))}),flow_plan_approve:m({description:"Approve the current draft Flow plan",args:{},execute:(a,t)=>x(t,lt)}),flow_run_start:m({description:"Start the next runnable approved Flow feature",args:{featureId:d.string().optional()},execute:(a,t)=>x(t,(r)=>dt(r,a))}),flow_feature_complete:m({description:"Record a completed or blocked active feature with validation and review evidence",args:{status:d.enum(["ok","needs_input"]),featureId:d.string(),summary:d.string(),artifactsChanged:d.array(d.object({path:d.string()})).optional(),validationRun:d.array(d.object({command:d.string(),status:d.enum(["passed","failed"]),summary:d.string()})).optional(),validationScope:d.enum(["targeted","broad"]).optional(),featureReview:d.any().optional(),finalReview:d.any().optional(),outcome:d.any().optional()},execute:(a,t)=>x(t,(r)=>ut(r,a))}),flow_feature_reset:m({description:"Reset one feature and its dependents to pending",args:{featureId:d.string()},execute:(a,t)=>x(t,(r)=>pt(r,a))}),flow_session_close:m({description:"Close and archive the active Flow session",args:{kind:d.enum(["completed","deferred","abandoned"]),summary:d.string().optional()},execute:(a,t)=>x(t,(r)=>ft(r,a))})}}async function gt(e){let a=e.worktree??e.directory;if(!a)return null;try{let t=await C(a);if(!t)return null;return["Flow session facts:",`- goal: ${t.goal}`,`- status: ${t.status}`,`- approval: ${t.approval}`,`- active feature: ${t.activeFeatureId??"none"}`,`- progress: ${t.plan?.features.filter((r)=>r.status==="completed").length??0}/${t.plan?.features.length??0}`,"Call flow_status before any Flow action."].join(`
|
|
1068
|
+
`)}catch{return null}}function Ca(e){return async(a,t)=>{let r=O();if(r)t.system.push(r);let n=await gt(e);if(n)t.system.push(n)}}function Ta(){let e=new Set(Object.keys(K));return async(a,t)=>{let r=a.command.replace(/^\/+/,"");if(!e.has(r))return;let n=O();if(!n)return;t.parts.push({type:"text",text:n,synthetic:!0})}}var Ua=async(e)=>{let a=L(e);return a("info","Flow v4 plugin initialized."),await Oe(Ee(),a),{config:Ze(e),tool:ht(e),"command.execute.before":Ta(),"experimental.chat.system.transform":Ca(e),"experimental.session.compacting":async(t,r)=>{let n=O();if(n)r.context=[...r.context??[],n];let i=await gt(e);if(!i)return;r.context=[...r.context??[],i]}}},ja=Ua;export{ja as default};
|
|
1069
|
+
|
|
1070
|
+
//# debugId=112D83C8D7323A1964756E2164756E21
|