@devcxl/opencode-cabbage 0.3.2 → 1.1.0

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.
Files changed (179) hide show
  1. package/README.md +34 -19
  2. package/README.zh.md +34 -19
  3. package/assets/agents/dev-lifecycle.md +60 -49
  4. package/assets/agents/team/architect.md +8 -1
  5. package/assets/agents/team/developer.md +89 -0
  6. package/assets/agents/team/goal-verify.md +5 -1
  7. package/assets/agents/team/reviewer.md +6 -0
  8. package/assets/commands/code.md +3 -2
  9. package/assets/commands/design.md +3 -2
  10. package/assets/commands/release.md +3 -2
  11. package/assets/commands/requirements.md +3 -2
  12. package/assets/commands/review.md +3 -2
  13. package/assets/commands/setup.md +3 -2
  14. package/assets/commands/tasks.md +2 -1
  15. package/assets/prompts/bootstrap.md +9 -8
  16. package/assets/prompts/stage-contract.md +55 -0
  17. package/assets/skills/flow-code/SKILL.md +38 -140
  18. package/assets/skills/flow-design/SKILL.md +28 -79
  19. package/assets/skills/flow-release/SKILL.md +31 -51
  20. package/assets/skills/flow-requirements/SKILL.md +31 -196
  21. package/assets/skills/flow-review/SKILL.md +26 -123
  22. package/assets/skills/flow-setup/SKILL.md +40 -43
  23. package/assets/skills/flow-tasks/SKILL.md +23 -153
  24. package/assets/skills/flow-tdd/SKILL.md +30 -31
  25. package/dist/kernel/caller.d.ts +48 -0
  26. package/dist/kernel/caller.js +88 -0
  27. package/dist/kernel/caller.js.map +1 -0
  28. package/dist/kernel/context.d.ts +27 -0
  29. package/dist/kernel/context.js +84 -0
  30. package/dist/kernel/context.js.map +1 -0
  31. package/dist/kernel/flow.d.ts +175 -0
  32. package/dist/kernel/flow.js +467 -0
  33. package/dist/kernel/flow.js.map +1 -0
  34. package/dist/kernel/legacy.d.ts +19 -0
  35. package/dist/kernel/legacy.js +34 -0
  36. package/dist/kernel/legacy.js.map +1 -0
  37. package/dist/kernel/mutex.d.ts +8 -0
  38. package/dist/kernel/mutex.js +23 -0
  39. package/dist/kernel/mutex.js.map +1 -0
  40. package/dist/kernel/permission.d.ts +21 -0
  41. package/dist/kernel/permission.js +45 -0
  42. package/dist/kernel/permission.js.map +1 -0
  43. package/dist/kernel/profile.d.ts +35 -0
  44. package/dist/kernel/profile.js +147 -0
  45. package/dist/kernel/profile.js.map +1 -0
  46. package/dist/kernel/records.d.ts +103 -0
  47. package/dist/kernel/records.js +240 -0
  48. package/dist/kernel/records.js.map +1 -0
  49. package/dist/kernel/release.d.ts +106 -0
  50. package/dist/kernel/release.js +241 -0
  51. package/dist/kernel/release.js.map +1 -0
  52. package/dist/kernel/review.d.ts +34 -0
  53. package/dist/kernel/review.js +82 -0
  54. package/dist/kernel/review.js.map +1 -0
  55. package/dist/kernel/session-index.d.ts +45 -0
  56. package/dist/kernel/session-index.js +136 -0
  57. package/dist/kernel/session-index.js.map +1 -0
  58. package/dist/kernel/setup.d.ts +95 -0
  59. package/dist/kernel/setup.js +401 -0
  60. package/dist/kernel/setup.js.map +1 -0
  61. package/dist/kernel/slug.d.ts +23 -0
  62. package/dist/kernel/slug.js +67 -0
  63. package/dist/kernel/slug.js.map +1 -0
  64. package/dist/kernel/task.d.ts +213 -0
  65. package/dist/kernel/task.js +873 -0
  66. package/dist/kernel/task.js.map +1 -0
  67. package/dist/{flowrun → kernel/tdd}/adapter.d.ts +1 -1
  68. package/dist/{flowrun → kernel/tdd}/adapter.js +27 -26
  69. package/dist/kernel/tdd/adapter.js.map +1 -0
  70. package/dist/{flowrun → kernel/tdd}/digest.d.ts +2 -1
  71. package/dist/{flowrun → kernel/tdd}/digest.js +6 -4
  72. package/dist/kernel/tdd/digest.js.map +1 -0
  73. package/dist/{flowrun → kernel/tdd}/evaluator.d.ts +1 -1
  74. package/dist/{flowrun → kernel/tdd}/evaluator.js +1 -1
  75. package/dist/kernel/tdd/evaluator.js.map +1 -0
  76. package/dist/kernel/tdd/evidence.d.ts +42 -0
  77. package/dist/kernel/tdd/evidence.js +48 -0
  78. package/dist/kernel/tdd/evidence.js.map +1 -0
  79. package/dist/{flowrun → kernel/tdd}/state.d.ts +2 -2
  80. package/dist/{flowrun → kernel/tdd}/state.js +1 -1
  81. package/dist/kernel/tdd/state.js.map +1 -0
  82. package/dist/kernel/types.d.ts +180 -0
  83. package/dist/kernel/types.js +2 -0
  84. package/dist/kernel/types.js.map +1 -0
  85. package/dist/kernel/worktree.d.ts +45 -0
  86. package/dist/kernel/worktree.js +156 -0
  87. package/dist/kernel/worktree.js.map +1 -0
  88. package/dist/plugin/agents.d.ts +5 -17
  89. package/dist/plugin/agents.js +0 -23
  90. package/dist/plugin/agents.js.map +1 -1
  91. package/dist/plugin/flow-control.d.ts +91 -0
  92. package/dist/plugin/flow-control.js +287 -0
  93. package/dist/plugin/flow-control.js.map +1 -0
  94. package/dist/plugin/goal.d.ts +17 -46
  95. package/dist/plugin/goal.js +47 -117
  96. package/dist/plugin/goal.js.map +1 -1
  97. package/dist/plugin/prompt-lint.js +78 -6
  98. package/dist/plugin/prompt-lint.js.map +1 -1
  99. package/dist/plugin/release-control.d.ts +39 -0
  100. package/dist/plugin/release-control.js +343 -0
  101. package/dist/plugin/release-control.js.map +1 -0
  102. package/dist/plugin/server.d.ts +19 -0
  103. package/dist/plugin/server.js +198 -320
  104. package/dist/plugin/server.js.map +1 -1
  105. package/dist/plugin/setup-control.d.ts +59 -0
  106. package/dist/plugin/setup-control.js +111 -0
  107. package/dist/plugin/setup-control.js.map +1 -0
  108. package/dist/plugin/shell.d.ts +7 -34
  109. package/dist/plugin/shell.js +12 -137
  110. package/dist/plugin/shell.js.map +1 -1
  111. package/dist/plugin/skills.d.ts +1 -1
  112. package/dist/plugin/skills.js +1 -7
  113. package/dist/plugin/skills.js.map +1 -1
  114. package/dist/plugin/task-control.d.ts +90 -0
  115. package/dist/plugin/task-control.js +208 -0
  116. package/dist/plugin/task-control.js.map +1 -0
  117. package/dist/plugin/tdd-checkpoint.d.ts +128 -0
  118. package/dist/plugin/tdd-checkpoint.js +664 -0
  119. package/dist/plugin/tdd-checkpoint.js.map +1 -0
  120. package/dist/util/gh.d.ts +5 -0
  121. package/dist/util/gh.js +12 -0
  122. package/dist/util/gh.js.map +1 -1
  123. package/dist/util/paths.d.ts +6 -2
  124. package/dist/util/paths.js +15 -7
  125. package/dist/util/paths.js.map +1 -1
  126. package/package.json +4 -4
  127. package/assets/agents/team/backend.md +0 -100
  128. package/assets/agents/team/frontend.md +0 -98
  129. package/assets/commands/handoff.md +0 -4
  130. package/assets/commands/test.md +0 -4
  131. package/assets/context/CONTEXT.md +0 -41
  132. package/assets/skills/flow-handoff/SKILL.md +0 -76
  133. package/assets/skills/flow-test/SKILL.md +0 -75
  134. package/dist/flowrun/adapter.js.map +0 -1
  135. package/dist/flowrun/audit.d.ts +0 -5
  136. package/dist/flowrun/audit.js +0 -67
  137. package/dist/flowrun/audit.js.map +0 -1
  138. package/dist/flowrun/ci.d.ts +0 -64
  139. package/dist/flowrun/ci.js +0 -184
  140. package/dist/flowrun/ci.js.map +0 -1
  141. package/dist/flowrun/coverage.d.ts +0 -70
  142. package/dist/flowrun/coverage.js +0 -207
  143. package/dist/flowrun/coverage.js.map +0 -1
  144. package/dist/flowrun/digest.js.map +0 -1
  145. package/dist/flowrun/evaluator.js.map +0 -1
  146. package/dist/flowrun/gate.d.ts +0 -28
  147. package/dist/flowrun/gate.js +0 -139
  148. package/dist/flowrun/gate.js.map +0 -1
  149. package/dist/flowrun/github.d.ts +0 -24
  150. package/dist/flowrun/github.js +0 -154
  151. package/dist/flowrun/github.js.map +0 -1
  152. package/dist/flowrun/index.d.ts +0 -14
  153. package/dist/flowrun/index.js +0 -15
  154. package/dist/flowrun/index.js.map +0 -1
  155. package/dist/flowrun/merge.d.ts +0 -57
  156. package/dist/flowrun/merge.js +0 -180
  157. package/dist/flowrun/merge.js.map +0 -1
  158. package/dist/flowrun/migration.d.ts +0 -11
  159. package/dist/flowrun/migration.js +0 -276
  160. package/dist/flowrun/migration.js.map +0 -1
  161. package/dist/flowrun/resilience.d.ts +0 -18
  162. package/dist/flowrun/resilience.js +0 -80
  163. package/dist/flowrun/resilience.js.map +0 -1
  164. package/dist/flowrun/state.js.map +0 -1
  165. package/dist/flowrun/transitions.d.ts +0 -66
  166. package/dist/flowrun/transitions.js +0 -168
  167. package/dist/flowrun/transitions.js.map +0 -1
  168. package/dist/flowrun/types.d.ts +0 -356
  169. package/dist/flowrun/types.js +0 -21
  170. package/dist/flowrun/types.js.map +0 -1
  171. package/dist/flowrun/validator.d.ts +0 -19
  172. package/dist/flowrun/validator.js +0 -209
  173. package/dist/flowrun/validator.js.map +0 -1
  174. package/dist/plugin/broker.d.ts +0 -73
  175. package/dist/plugin/broker.js +0 -140
  176. package/dist/plugin/broker.js.map +0 -1
  177. package/dist/plugin/tdd-tool.d.ts +0 -62
  178. package/dist/plugin/tdd-tool.js +0 -336
  179. package/dist/plugin/tdd-tool.js.map +0 -1
@@ -0,0 +1,287 @@
1
+ /**
2
+ * flow_control 工具(spec §2.3):Flow Record 生命周期(替代旧 FlowRun 状态机)。
3
+ * 九 op:create-flow / status / planning-start / planning-pr / stage-start / stage-complete /
4
+ * complete-flow / cancel-flow / takeover。
5
+ * caller:primary 全量(除 complete-flow);complete-flow 仅 goal-verify。
6
+ * server.ts 接线由后续批次统一处理(本批不注册,避免文件冲突)。
7
+ */
8
+ import { tool } from "@opencode-ai/plugin/tool";
9
+ import { resolveProjectDir } from "../util/paths.js";
10
+ import { requireToolCaller, CALLER_NOT_AUTHORIZED } from "../kernel/caller.js";
11
+ import { FLOW_STAGES, createFlow, readFlowStatus, planningStart, planningPr, applyStageOp, completeFlow, cancelFlow, takeoverFlow, } from "../kernel/flow.js";
12
+ import { readIndex, getFlowSession } from "../kernel/session-index.js";
13
+ import { detectLegacyFlowRun } from "../kernel/legacy.js";
14
+ import { flowGh } from "../kernel/flow.js";
15
+ /**
16
+ * flow_control 工具工厂(spec §2.3)。
17
+ * caller 门禁:primary(除 complete-flow 外);complete-flow 仅 goal-verify。
18
+ */
19
+ export function createFlowControlTool(deps) {
20
+ return tool({
21
+ description: `Control the Flow Record lifecycle (a Flow = one GitHub Parent Issue).
22
+
23
+ Operations:
24
+ - create-flow: Validate the functional title, derive the slug, create a Draft Parent Issue (body contains goal/acceptance/stage checklist, label cabbage:flow), bind the session, and write the minimal goal. When parent_issue_number is given, bind an existing issue instead (legacy FlowRun detection + double-session check).
25
+ - status: Aggregate the Flow Record body, subtasks (issue list --json parent 过滤), and related PR checks into one report.
26
+ - planning-start: Create the planning worktree .worktree/planning-<slug> for the architect.
27
+ - planning-pr: Commit/push the planning worktree changes and open the Planning PR (Planning Baseline).
28
+ - stage-start / stage-complete: Enforce stage gates (requirements baseline confirmed once; design must complete before tasks; high-risk flows pause between design and tasks) and update the Parent Issue checklist + cabbage:stage:* label.
29
+ - complete-flow: goal-verify only. After independent verification, close the Parent Issue.
30
+ - cancel-flow: Controlled cancellation (requires user_confirmed).
31
+ - takeover: Take over a flow bound to another active session (requires user_confirmed; old session goal is paused).
32
+
33
+ Caller: primary for all ops except complete-flow (goal-verify only).`,
34
+ args: {
35
+ op: tool.schema
36
+ .enum(["create-flow", "status", "planning-start", "planning-pr", "stage-start", "stage-complete", "complete-flow", "cancel-flow", "takeover"])
37
+ .describe("Flow control operation"),
38
+ title: tool.schema.string().optional().describe("Functional title (kebab-case slug) for create-flow"),
39
+ auto_mode: tool.schema
40
+ .boolean()
41
+ .optional()
42
+ .describe("Full-auto mode: label the flow cabbage:auto so stage confirmation gates (requirements/high-risk) pass without user_confirmed"),
43
+ goal: tool.schema.string().optional().describe("Initial objective to fill the Flow Record Goal block (create-flow)"),
44
+ acceptance_criteria: tool.schema
45
+ .array(tool.schema.string())
46
+ .optional()
47
+ .describe("Initial acceptance criteria list to fill the Flow Record Acceptance Criteria block (create-flow)"),
48
+ parent_issue_number: tool.schema.number().optional().describe("Parent GitHub Issue number of the Flow Record"),
49
+ stage: tool.schema
50
+ .enum(["requirements", "design", "tasks", "code", "review"])
51
+ .optional()
52
+ .describe("Stage name (for stage-start/stage-complete)"),
53
+ risk: tool.schema
54
+ .enum(["high", "low"])
55
+ .optional()
56
+ .describe("Risk declaration for stage-start/stage-complete tasks handoff: high triggers the R11 user-confirmation gate (user_confirmed) and persists the cabbage:risk:high label"),
57
+ user_confirmed: tool.schema.boolean().optional().describe("User confirmation (required for cancel-flow/takeover and high-risk gates)"),
58
+ },
59
+ async execute(args, ctx) {
60
+ const op = args.op;
61
+ // caller 门禁(矩阵单一来源,§2.2):complete-flow 仅 goal-verify;status 另开放 architect;其余仅 primary
62
+ const denied = await requireToolCaller(ctx, "flow_control", op, deps.sessionClient);
63
+ if (denied)
64
+ return errorResponse(CALLER_NOT_AUTHORIZED, denied);
65
+ // 会话级项目目录优先(workspace root 异常会话下插件级 projectDir 可能是 `/`)
66
+ const runtimeDeps = { ...deps, projectDir: resolveProjectDir(ctx.directory, deps.projectDir) };
67
+ try {
68
+ switch (op) {
69
+ case "create-flow":
70
+ return handleCreateFlow(runtimeDeps, args, ctx.sessionID);
71
+ case "status":
72
+ return handleStatus(runtimeDeps, args);
73
+ case "planning-start":
74
+ return handlePlanningStart(runtimeDeps, args);
75
+ case "planning-pr":
76
+ return handlePlanningPr(runtimeDeps, args);
77
+ case "stage-start":
78
+ case "stage-complete":
79
+ return handleStage(runtimeDeps, args, op);
80
+ case "complete-flow":
81
+ return handleCompleteFlow(runtimeDeps, args, ctx);
82
+ case "cancel-flow":
83
+ return handleCancelFlow(runtimeDeps, args);
84
+ case "takeover":
85
+ return handleTakeover(runtimeDeps, args, ctx.sessionID);
86
+ default:
87
+ return errorResponse("UNKNOWN_OP", `Unknown op: "${op}"`);
88
+ }
89
+ }
90
+ catch (err) {
91
+ return errorResponse("INTERNAL_ERROR", String(err));
92
+ }
93
+ },
94
+ });
95
+ }
96
+ /** 独立注册辅助:把 flow_control 挂到工具注册表(后续接线批次使用) */
97
+ export function registerFlowControl(registry, deps) {
98
+ registry.flow_control = createFlowControlTool(deps);
99
+ }
100
+ // ─── op handlers ───
101
+ async function handleCreateFlow(deps, args, sessionID) {
102
+ const parent = args.parent_issue_number !== undefined ? Number(args.parent_issue_number) : undefined;
103
+ const title = args.title ?? "";
104
+ if (parent === undefined && title.trim() === "") {
105
+ return errorResponse("POLICY_INVALID", "title is required for create-flow (or pass parent_issue_number to bind an existing issue)");
106
+ }
107
+ const result = await createFlow({
108
+ projectDir: deps.projectDir,
109
+ title,
110
+ sessionID,
111
+ autoMode: args.auto_mode === true,
112
+ goal: args.goal,
113
+ acceptanceCriteria: args.acceptance_criteria,
114
+ parentIssueNumber: parent,
115
+ });
116
+ if (!result.ok) {
117
+ return errorResponse(result.code, result.message);
118
+ }
119
+ const goalWritten = await writeMinimalGoal(deps.sessionClient, sessionID, result.ref.parentIssueNumber);
120
+ if (!goalWritten) {
121
+ return errorResponse("GOAL_WRITE_FAILED", "flow created but failed to write the minimal goal to the session");
122
+ }
123
+ return okResponse({ flow: result.ref });
124
+ }
125
+ async function handleStatus(_deps, args) {
126
+ const n = requireParentIssueNumber(args);
127
+ if (typeof n === "string")
128
+ return n;
129
+ const legacy = await detectLegacyFlowRun(n, flowGh);
130
+ if (legacy.legacy)
131
+ return legacyDetectedResponse(legacy);
132
+ const result = await readFlowStatus(n);
133
+ if (!result.ok) {
134
+ return errorResponse(result.code, result.message);
135
+ }
136
+ return okResponse({ status: result.status });
137
+ }
138
+ async function handlePlanningStart(deps, args) {
139
+ const n = requireParentIssueNumber(args);
140
+ if (typeof n === "string")
141
+ return n;
142
+ const result = await planningStart(deps.projectDir, n);
143
+ if (!result.ok) {
144
+ return errorResponse(result.code, result.message);
145
+ }
146
+ return okResponse({ worktreePath: result.worktreePath, branch: result.branch });
147
+ }
148
+ async function handlePlanningPr(deps, args) {
149
+ const n = requireParentIssueNumber(args);
150
+ if (typeof n === "string")
151
+ return n;
152
+ const result = await planningPr(deps.projectDir, n);
153
+ if (!result.ok) {
154
+ return errorResponse(result.code, result.message);
155
+ }
156
+ return okResponse({ prNumber: result.prNumber, worktreePath: result.worktreePath, branch: result.branch });
157
+ }
158
+ async function handleStage(deps, args, op) {
159
+ const n = requireParentIssueNumber(args);
160
+ if (typeof n === "string")
161
+ return n;
162
+ const stage = args.stage;
163
+ if (!stage || !FLOW_STAGES.includes(stage)) {
164
+ return errorResponse("POLICY_INVALID", "stage is required for stage ops: requirements|design|tasks|code|review");
165
+ }
166
+ const risk = args.risk;
167
+ if (risk !== undefined && risk !== "high" && risk !== "low") {
168
+ return errorResponse("POLICY_INVALID", "risk must be \"high\" or \"low\"");
169
+ }
170
+ const result = await applyStageOp(deps.projectDir, n, op, stage, args.user_confirmed === true, risk);
171
+ if (!result.ok) {
172
+ return errorResponse(result.code, result.message);
173
+ }
174
+ const note = op === "stage-complete" && stage === "requirements"
175
+ ? "requirements 产物(PRD/CONTEXT/decision-map)请 commit+push 到 main:planning worktree 基于 main HEAD 创建,未提交的文件在其中不可见"
176
+ : undefined;
177
+ return okResponse({
178
+ stage: result.stage,
179
+ completedStages: result.completedStages,
180
+ ...(result.highRisk ? { highRisk: true } : {}),
181
+ ...(note ? { note } : {}),
182
+ });
183
+ }
184
+ async function handleCompleteFlow(deps, args, ctx) {
185
+ const n = requireParentIssueNumber(args);
186
+ if (typeof n === "string")
187
+ return n;
188
+ // 独立 goal-verify 验证通过:flow 级 goalComplete 标记(跨会话持久,最可靠)
189
+ // 或绑定 session 的 goal 已 complete(向后兼容)
190
+ const index = await readIndex(deps.projectDir);
191
+ const entry = getFlowSession(index, n);
192
+ const goalCompleteAtFlowLevel = entry?.goalComplete === true;
193
+ const targetSessionID = entry?.sessionID ?? ctx.sessionID;
194
+ const goalStatus = await readGoalStatus(deps.sessionClient, targetSessionID);
195
+ if (!goalCompleteAtFlowLevel && goalStatus !== "complete") {
196
+ return errorResponse("GOAL_NOT_COMPLETE", "complete-flow requires the goal to be verified complete first (goal({op:'complete'}) by goal-verify)");
197
+ }
198
+ const result = await completeFlow(deps.projectDir, n);
199
+ if (!result.ok) {
200
+ return errorResponse(result.code, result.message);
201
+ }
202
+ return okResponse({ flow: { parentIssueNumber: result.parentIssueNumber } });
203
+ }
204
+ async function handleCancelFlow(deps, args) {
205
+ const n = requireParentIssueNumber(args);
206
+ if (typeof n === "string")
207
+ return n;
208
+ const result = await cancelFlow(deps.projectDir, n, args.user_confirmed === true);
209
+ if (!result.ok) {
210
+ return errorResponse(result.code, result.message);
211
+ }
212
+ return okResponse({ flow: { parentIssueNumber: result.parentIssueNumber } });
213
+ }
214
+ async function handleTakeover(deps, args, sessionID) {
215
+ const n = requireParentIssueNumber(args);
216
+ if (typeof n === "string")
217
+ return n;
218
+ const result = await takeoverFlow(deps.projectDir, n, sessionID, args.user_confirmed === true);
219
+ if (!result.ok) {
220
+ return errorResponse(result.code, result.message);
221
+ }
222
+ if (result.oldSessionID && result.oldSessionID !== sessionID) {
223
+ await pauseOldSessionGoal(deps.sessionClient, result.oldSessionID);
224
+ }
225
+ return okResponse({ flow: { parentIssueNumber: result.parentIssueNumber }, oldSessionID: result.oldSessionID });
226
+ }
227
+ // ─── helpers ───
228
+ function requireParentIssueNumber(args) {
229
+ const n = Number(args.parent_issue_number);
230
+ if (!Number.isInteger(n) || n <= 0) {
231
+ return errorResponse("POLICY_INVALID", "parent_issue_number is required");
232
+ }
233
+ return n;
234
+ }
235
+ /** 写最小 goal(§10.2):{parentIssueNumber, status:"active", continuationCount:0} */
236
+ async function writeMinimalGoal(client, sessionID, parentIssueNumber) {
237
+ try {
238
+ const { data } = await client.session.get({ sessionID });
239
+ const existing = data?.metadata ?? {};
240
+ await client.session.update({
241
+ sessionID,
242
+ metadata: { ...existing, goal: { parentIssueNumber, status: "active", continuationCount: 0 } },
243
+ });
244
+ return true;
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ }
250
+ /** 读指定 session 的 goal 状态;无 goal 返回 null */
251
+ async function readGoalStatus(client, sessionID) {
252
+ try {
253
+ const { data } = await client.session.get({ sessionID });
254
+ const goal = data?.metadata?.goal;
255
+ return goal?.status ?? null;
256
+ }
257
+ catch {
258
+ return null;
259
+ }
260
+ }
261
+ /** takeover 后把旧 session 的 goal 置 paused(§10.3) */
262
+ async function pauseOldSessionGoal(client, sessionID) {
263
+ try {
264
+ const { data } = await client.session.get({ sessionID });
265
+ const metadata = data?.metadata;
266
+ const goal = metadata?.goal;
267
+ if (!goal)
268
+ return;
269
+ await client.session.update({ sessionID, metadata: { ...metadata, goal: { ...goal, status: "paused" } } });
270
+ }
271
+ catch {
272
+ // 旧 session goal 置 paused 失败不阻断 takeover
273
+ }
274
+ }
275
+ function legacyDetectedResponse(legacy) {
276
+ const detail = legacy.flowRunId ? ` (flowRunId: ${legacy.flowRunId})` : "";
277
+ return errorResponse("LEGACY_FLOW_DETECTED", `This issue is a legacy-architecture FlowRun${detail}; complete it with the old plugin version (0.x). New versions do not auto-migrate.`);
278
+ }
279
+ function okResponse(overrides = {}) {
280
+ const resp = { ok: true, ...overrides };
281
+ return JSON.stringify(resp, null, 2);
282
+ }
283
+ function errorResponse(code, message) {
284
+ const resp = { ok: false, error: { code, message } };
285
+ return JSON.stringify(resp, null, 2);
286
+ }
287
+ //# sourceMappingURL=flow-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-control.js","sourceRoot":"","sources":["../../src/plugin/flow-control.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EACL,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,GAEb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,mBAAmB,EAA4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
3
  import type { Session } from "@opencode-ai/sdk/v2";
4
- import type { GoalFlowRunRef } from "../flowrun/types.js";
5
4
  export type GoalStatus = "active" | "paused" | "complete";
5
+ /** 用户最后使用的会话配置快照:续接注入时显式传回,防止 idle 后回落/切换默认 agent 与模型 */
6
+ export interface GoalSessionProfile {
7
+ agent: string;
8
+ model?: {
9
+ providerID: string;
10
+ modelID: string;
11
+ };
12
+ }
13
+ /** 最小化 goal(§10.2):目标与验收条件从 Flow Record(Parent Issue body)读取 */
6
14
  export interface GoalData {
7
- objective: string;
8
- completionCriterion: string;
15
+ parentIssueNumber: number;
9
16
  status: GoalStatus;
10
17
  continuationCount: number;
18
+ /** 用户最后使用的 agent/模型(create 或用户消息时快照) */
19
+ sessionProfile?: GoalSessionProfile;
11
20
  }
21
+ export declare function createGoal(parentIssueNumber: number, sessionProfile?: GoalSessionProfile): GoalData;
12
22
  export declare function canTransitionTo(goal: GoalData, target: GoalStatus): boolean;
13
23
  export declare function formatGoal(goal: GoalData): string;
14
24
  export declare const MAX_CONTINUATIONS = 50;
15
- export declare function continuationPrompt(objective: string, completionCriterion: string): string;
25
+ export declare function continuationPrompt(parentIssueNumber: number): string;
16
26
  export declare function verifyAgentPrompt(): string;
17
27
  export declare function createGoalClient(serverUrl: URL, v1Client: any): import("@opencode-ai/sdk/v2").OpencodeClient;
18
28
  export declare function readGoal(client: ReturnType<typeof createOpencodeClient>, sessionID: string): Promise<{
@@ -20,44 +30,7 @@ export declare function readGoal(client: ReturnType<typeof createOpencodeClient>
20
30
  session: Session | null;
21
31
  }>;
22
32
  export declare function writeGoal(client: ReturnType<typeof createOpencodeClient>, sessionID: string, goal: GoalData | null, existingSession?: Session | null): Promise<void>;
23
- /**
24
- * 读取 session metadata 中的 GoalFlowRunRef。
25
- * 返回 null 表示尚未绑定。
26
- */
27
- export declare function readFlowRunRef(client: ReturnType<typeof createOpencodeClient>, sessionID: string): Promise<GoalFlowRunRef | null>;
28
- /**
29
- * Goal → FlowRun 绑定结果。
30
- */
31
- export type BindFlowRunResult = {
32
- ok: true;
33
- } | {
34
- ok: false;
35
- code: "GOAL_FLOW_CONFLICT";
36
- message: string;
37
- };
38
- /**
39
- * 原子绑定 Goal → FlowRun。
40
- *
41
- * 规则:
42
- * - 未绑定 → 写入 flowRunRef,返回 ok
43
- * - 已绑定同一 FlowRun(repo + parentIssueNumber + flowRunId 相同)→ 幂等,返回 ok
44
- * - 已绑定不同 FlowRun → 返回 GOAL_FLOW_CONFLICT
45
- */
46
- export declare function bindFlowRunRef(client: ReturnType<typeof createOpencodeClient>, sessionID: string, ref: GoalFlowRunRef): Promise<BindFlowRunResult>;
47
- /**
48
- * 解析 GoalFlowRunRef 的显示名称。
49
- */
50
- export declare function formatFlowRunRef(ref: GoalFlowRunRef): string;
51
- /**
52
- * 验证 FlowRun 终态 — 检查是否满足 Goal complete 的前提条件。
53
- *
54
- * 返回 null 表示允许完成;
55
- * 返回错误信息字符串表示阻止完成。
56
- *
57
- * @param flowRunStatus FlowRun 当前状态,null 表示无绑定的 FlowRun
58
- */
59
- export declare function checkFlowRunBlockers(flowRunStatus: string | null): string | null;
60
- export declare function createGoalTool(client: ReturnType<typeof createOpencodeClient>, onBeforeComplete?: (parentSessionID: string) => Promise<string | null>): {
33
+ export declare function createGoalTool(client: ReturnType<typeof createOpencodeClient>): {
61
34
  description: string;
62
35
  args: {
63
36
  op: import("zod").ZodEnum<{
@@ -68,12 +41,10 @@ export declare function createGoalTool(client: ReturnType<typeof createOpencodeC
68
41
  cancel: "cancel";
69
42
  pause: "pause";
70
43
  }>;
71
- objective: import("zod").ZodString;
72
- completion_criterion: import("zod").ZodString;
44
+ parent_issue_number: import("zod").ZodNumber;
73
45
  };
74
46
  execute(args: {
75
47
  op: "complete" | "create" | "get" | "resume" | "cancel" | "pause";
76
- objective: string;
77
- completion_criterion: string;
48
+ parent_issue_number: number;
78
49
  }, context: ToolContext): Promise<ToolResult>;
79
50
  };