@bonesofspring/ai-rules 0.2.68 → 0.2.70

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 (115) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/package.json +2 -2
  4. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +137 -2
  5. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +137 -2
  6. package/presets/claude/go/hooks/chain-team-phases.sh +137 -2
  7. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +137 -2
  8. package/presets/claude/java/hooks/chain-team-phases.sh +137 -2
  9. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +137 -2
  10. package/presets/claude/mol/hooks/chain-team-phases.sh +137 -2
  11. package/presets/claude/next/commands/README.md +5 -0
  12. package/presets/claude/next/commands/task-continue.md +17 -6
  13. package/presets/claude/next/commands/ui-start.md +54 -0
  14. package/presets/claude/next/commands/ui-stop.md +43 -0
  15. package/presets/claude/next/hooks/chain-team-phases.sh +137 -2
  16. package/presets/claude/nuxt/hooks/chain-team-phases.sh +137 -2
  17. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  18. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +137 -2
  19. package/presets/claude/svelte/hooks/chain-team-phases.sh +137 -2
  20. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +137 -2
  21. package/presets/cursor/go/hooks/chain-team-phases.sh +137 -2
  22. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +137 -2
  23. package/presets/cursor/java/hooks/chain-team-phases.sh +137 -2
  24. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +137 -2
  25. package/presets/cursor/mol/hooks/chain-team-phases.sh +137 -2
  26. package/presets/cursor/next/commands/README.md +5 -0
  27. package/presets/cursor/next/commands/task-continue.md +17 -6
  28. package/presets/cursor/next/commands/ui-start.md +54 -0
  29. package/presets/cursor/next/commands/ui-stop.md +43 -0
  30. package/presets/cursor/next/hooks/chain-team-phases.sh +137 -2
  31. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +137 -2
  32. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  33. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +137 -2
  34. package/presets/cursor/svelte/hooks/chain-team-phases.sh +137 -2
  35. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  36. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +137 -2
  37. package/presets/mavis/go/adapter-map.json +1 -1
  38. package/presets/mavis/go/hooks/chain-team-phases.sh +137 -2
  39. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  40. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +137 -2
  41. package/presets/mavis/java/adapter-map.json +1 -1
  42. package/presets/mavis/java/hooks/chain-team-phases.sh +137 -2
  43. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  44. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +137 -2
  45. package/presets/mavis/mol/adapter-map.json +1 -1
  46. package/presets/mavis/mol/hooks/chain-team-phases.sh +137 -2
  47. package/presets/mavis/next/adapter-map.json +17 -1
  48. package/presets/mavis/next/commands/README.md +5 -0
  49. package/presets/mavis/next/commands/task-continue.md +16 -5
  50. package/presets/mavis/next/commands/ui-start.md +49 -0
  51. package/presets/mavis/next/commands/ui-stop.md +38 -0
  52. package/presets/mavis/next/hooks/chain-team-phases.sh +137 -2
  53. package/presets/mavis/nuxt/adapter-map.json +1 -1
  54. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +137 -2
  55. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  56. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  57. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  58. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +137 -2
  59. package/presets/mavis/svelte/adapter-map.json +1 -1
  60. package/presets/mavis/svelte/hooks/chain-team-phases.sh +137 -2
  61. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  62. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +137 -2
  63. package/presets/opencode/go/adapter-map.json +1 -1
  64. package/presets/opencode/go/hooks/chain-team-phases.sh +137 -2
  65. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  66. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +137 -2
  67. package/presets/opencode/java/adapter-map.json +1 -1
  68. package/presets/opencode/java/hooks/chain-team-phases.sh +137 -2
  69. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  70. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +137 -2
  71. package/presets/opencode/mol/adapter-map.json +1 -1
  72. package/presets/opencode/mol/hooks/chain-team-phases.sh +137 -2
  73. package/presets/opencode/next/adapter-map.json +17 -1
  74. package/presets/opencode/next/commands/README.md +5 -0
  75. package/presets/opencode/next/commands/task-continue.md +17 -6
  76. package/presets/opencode/next/commands/ui-start.md +57 -0
  77. package/presets/opencode/next/commands/ui-stop.md +46 -0
  78. package/presets/opencode/next/hooks/chain-team-phases.sh +137 -2
  79. package/presets/opencode/nuxt/adapter-map.json +1 -1
  80. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +137 -2
  81. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  82. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  83. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  84. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +137 -2
  85. package/presets/opencode/plugins/output-guard/README.md +33 -0
  86. package/presets/opencode/plugins/output-guard/index.ts +225 -3
  87. package/presets/opencode/svelte/adapter-map.json +1 -1
  88. package/presets/opencode/svelte/hooks/chain-team-phases.sh +137 -2
  89. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  90. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +137 -2
  91. package/presets/zcode/go/adapter-map.json +1 -1
  92. package/presets/zcode/go/hooks/chain-team-phases.sh +137 -2
  93. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  94. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +137 -2
  95. package/presets/zcode/java/adapter-map.json +1 -1
  96. package/presets/zcode/java/hooks/chain-team-phases.sh +137 -2
  97. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  98. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +137 -2
  99. package/presets/zcode/mol/adapter-map.json +1 -1
  100. package/presets/zcode/mol/hooks/chain-team-phases.sh +137 -2
  101. package/presets/zcode/next/adapter-map.json +17 -1
  102. package/presets/zcode/next/commands/README.md +5 -0
  103. package/presets/zcode/next/commands/task-continue.md +17 -6
  104. package/presets/zcode/next/commands/ui-start.md +57 -0
  105. package/presets/zcode/next/commands/ui-stop.md +46 -0
  106. package/presets/zcode/next/hooks/chain-team-phases.sh +137 -2
  107. package/presets/zcode/nuxt/adapter-map.json +1 -1
  108. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +137 -2
  109. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  110. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  111. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  112. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +137 -2
  113. package/presets/zcode/svelte/adapter-map.json +1 -1
  114. package/presets/zcode/svelte/hooks/chain-team-phases.sh +137 -2
  115. package/scripts/report-context-cost.mjs +216 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.70
4
+
5
+ ### `next` — `/ui-start` and `/ui-stop` return
6
+
7
+ - **Commands.** The Cursor source and Claude twin, plus the generated Mavis, OpenCode, and ZCode `next` trees, ship `ui-start` and `ui-stop`. `ui-start` stops a running `team-tasks-ui` compose stack, runs `team-db.mjs migrate-tasks`, then rebuilds and starts it; `ui-stop` takes the project down and stops only the API `/ui-start` started.
8
+ - **Scope.** The commands target repositories that contain `apps/team-tasks-ui`; both stop with a clear message when `apps/team-tasks-ui/scripts/stack.mjs` is absent.
9
+
10
+ ### `resume_blocked` — the chain hook re-arms a blocked step
11
+
12
+ - **Action.** `chain-team-phases.sh` accepts `{"action":"resume_blocked"}` on a `state: blocked` step: it arms attempt N+1 (`<runId>:step-N:<agent>:attempt-<M+1>`, one `attempt_started` in `metrics.json`), sets `state: in_progress` / `phase: executing`, keeps `pipelineIndex` / `currentAgent`, and hands off to the blocked producer. The gate stays receipt-driven: the retried `completed` receipt opens it (`awaiting_approval`) when the step has `after:<agent>` in `humanGates`, and advances the chain otherwise.
13
+ - **Refusals.** A repeat, any other `state`, a malformed `pipeline.json`, graph mode (`status.blockedSteps` / `dependsOn`), and the `mockup-reviewer` `BLOCKED_MCP` state answer `ok:false` with a `reason` and change nothing; the mockup case names the `end_human_gate` + `activateNext` skip-forward. A refusal carries no `followup_message`, and the pause sentinel wins over the whole action.
14
+ - **Ledger.** The ordinal read and the `attempt_started` append share one metrics critical section, and `metrics.task.runId` is never re-minted; the stale attempt-1 receipt cannot bind the re-armed attempt.
15
+ - **Command.** `/task-continue` lists `state: blocked` in its preconditions and invokes the action through the installed hook; the `bootstrap` → `completed` recipe survives only as a fallback for an installed hook that predates it.
16
+ - **Test.** `test-chain-team-phases-resume-blocked.mjs` covers gated and non-gated resume, repeat, pause, malformed pipeline, graph mode, stale receipt, `BLOCKED_MCP`, and the field contract; `yarn test:hooks` and `check-preset-structure.sh` run it.
17
+
3
18
  ## 0.2.68
4
19
 
5
20
  ### One UI surface — legacy team-db dashboard removed
package/README.md CHANGED
@@ -201,7 +201,7 @@ Mavis never writes `~/.minimax/**`. OpenCode never writes `~/.config/opencode/**
201
201
 
202
202
  **Shared:** stack semantics, root `AGENTS.md`, `.ai.local/` overlay, `/task` slugs at `.ai.local/team/tasks/<slug>/` (one `status.json` / `metrics.json`).
203
203
 
204
- **Per-tool:** how the chain runs. Cursor auto-chains via `hooks.json` / `subagentStop`. Claude, Mavis, OpenCode, and ZCode use `bash .<tool>/hooks/chain-team-phases.sh` after a producer receipt (Mavis/OpenCode/ZCode: semi-auto).
204
+ **Per-tool:** how the chain runs. Cursor auto-chains via `hooks.json` / `subagentStop`. Claude, Mavis, OpenCode, and ZCode use `bash .<tool>/hooks/chain-team-phases.sh` after a producer receipt (Mavis/OpenCode/ZCode: semi-auto). A producer that ended `blocked` resumes with the same hook's `{"action":"resume_blocked"}`: it arms attempt N+1 for that step and leaves the gate or the advance to the retried receipt.
205
205
 
206
206
  `init multi --preset <stack>` installs every platform that lists the stack in `releasedStacks` (all 11 stacks on all five platforms). Commit the five trees, root `AGENTS.md`, and `.ai.local/team/` templates if you want them in the clone.
207
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.68",
3
+ "version": "0.2.70",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -42,7 +42,7 @@
42
42
  "check:fast": "bash scripts/check-preset-fast.sh",
43
43
  "check:changed": "node scripts/check-preset-delta.mjs --base HEAD",
44
44
  "check:task": "node scripts/check-preset-delta.mjs --since-task",
45
- "test:hooks": "node scripts/test-chain-team-phases-coverage.mjs && node scripts/test-agent-task-metrics-hooks.mjs && node scripts/test-chain-team-phases-dev-cleanup.mjs",
45
+ "test:hooks": "node scripts/test-chain-team-phases-coverage.mjs && node scripts/test-chain-team-phases-resume-blocked.mjs && node scripts/test-agent-task-metrics-hooks.mjs && node scripts/test-chain-team-phases-dev-cleanup.mjs",
46
46
  "check:preset-structure": "bash scripts/check-preset-structure.sh",
47
47
  "release:gate": "bash scripts/release-gate.sh",
48
48
  "check:platform-scripts": "node scripts/check-platform-scripts.mjs",
@@ -25,8 +25,12 @@ try {
25
25
  // <<<hook-slot:/PLATFORM_PREAMBLE>>>
26
26
 
27
27
  if (hookInput.status !== 'completed') {
28
- process.stdout.write('{}');
29
- process.exit(0);
28
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
29
+ // with no `status`, and a `status` it carries is ignored.
30
+ if (hookInput.action !== 'resume_blocked') {
31
+ process.stdout.write('{}');
32
+ process.exit(0);
33
+ }
30
34
  }
31
35
 
32
36
  // Slug resolution, strongest first:
@@ -1956,6 +1960,137 @@ function syncMetricsProfile(pipeline) {
1956
1960
  });
1957
1961
  }
1958
1962
 
1963
+ function resumeBlockedRefuse(reason) {
1964
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
1965
+ }
1966
+
1967
+ /**
1968
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
1969
+ * one metrics critical section, like `completeTaskMetrics`: a second process
1970
+ * serializes on the lock and sees the first attempt instead of minting the
1971
+ * same ordinal.
1972
+ */
1973
+ function armResumedAttempt(step, stepIndex, agent) {
1974
+ let attemptId = null;
1975
+ mutateMetrics((metrics) => {
1976
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
1977
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1978
+ metrics.task = { ...(metrics.task || {}), runId };
1979
+ status.metricsRunId = runId;
1980
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
1981
+ const attempt =
1982
+ events.reduce(
1983
+ (highest, event) =>
1984
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
1985
+ ? Math.max(highest, Number(event.attempt) || 0)
1986
+ : highest,
1987
+ 0,
1988
+ ) + 1;
1989
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
1990
+ status.activeAttempts = {
1991
+ ...(status.activeAttempts || {}),
1992
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
1993
+ };
1994
+ events.push({
1995
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
1996
+ type: 'attempt_started',
1997
+ at: now,
1998
+ attemptId,
1999
+ stepIndex,
2000
+ stepLabel: step.label || null,
2001
+ agent,
2002
+ role: roleFor(agent),
2003
+ attempt,
2004
+ parallelGroupId: null,
2005
+ waveId: null,
2006
+ source: 'hook',
2007
+ attributionConfidence: 'high',
2008
+ });
2009
+ });
2010
+ return attemptId;
2011
+ }
2012
+
2013
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2014
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2015
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2016
+ if (hookInput.action === 'resume_blocked') {
2017
+ if (pauseBlocksAdvance()) process.exit(0);
2018
+ const pipeline = readPipeline();
2019
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2020
+ resumeBlockedRefuse(
2021
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2022
+ );
2023
+ process.exit(0);
2024
+ }
2025
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2026
+ const step = pipeline.steps[stepIndex];
2027
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2028
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2029
+ resumeBlockedRefuse(
2030
+ `graph mode is not supported by resume_blocked for slug "${slug}" (status.blockedSteps or a step.dependsOn): nothing was armed; resume the wave by hand.`,
2031
+ );
2032
+ process.exit(0);
2033
+ }
2034
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2035
+ if (agents.length === 0) {
2036
+ resumeBlockedRefuse(
2037
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2038
+ );
2039
+ process.exit(0);
2040
+ }
2041
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2042
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2043
+ if (agents.length > 1) {
2044
+ resumeBlockedRefuse(
2045
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2046
+ );
2047
+ process.exit(0);
2048
+ }
2049
+ if (status.state !== 'blocked') {
2050
+ resumeBlockedRefuse(
2051
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2052
+ );
2053
+ process.exit(0);
2054
+ }
2055
+ if (status.currentAgent === 'mockup-reviewer') {
2056
+ resumeBlockedRefuse(
2057
+ `the mockup-reviewer BLOCKED_MCP skip-forward owns this state for slug "${slug}": run {"action":"end_human_gate","activateNext":true} instead; resume_blocked armed nothing.`,
2058
+ );
2059
+ process.exit(0);
2060
+ }
2061
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2062
+ (entry) => entry && entry.stepIndex === stepIndex,
2063
+ );
2064
+ if (activeForStep.length > 0) {
2065
+ resumeBlockedRefuse(
2066
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2067
+ );
2068
+ process.exit(0);
2069
+ }
2070
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2071
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2072
+ // (missing consumer artifacts) falls back to the step's agent.
2073
+ const resumedAgent = status.currentAgent || agents[0];
2074
+ writeStatus({
2075
+ pipelineIndex: stepIndex,
2076
+ currentAgent: resumedAgent,
2077
+ phase: 'executing',
2078
+ state: 'in_progress',
2079
+ awaitingHumanGate: false,
2080
+ });
2081
+ process.stdout.write(
2082
+ JSON.stringify({
2083
+ ok: true,
2084
+ action: 'resume_blocked',
2085
+ pipelineIndex: stepIndex,
2086
+ agents,
2087
+ attemptIds: [attemptId],
2088
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2089
+ }),
2090
+ );
2091
+ process.exit(0);
2092
+ }
2093
+
1959
2094
  if (hookInput.action === 'bootstrap') {
1960
2095
  if (pauseBlocksAdvance()) process.exit(0);
1961
2096
  const pipeline = readPipeline();
@@ -41,8 +41,12 @@ if (hookInput.hook_event_name === 'SubagentStop') {
41
41
  }
42
42
 
43
43
  if (hookInput.status !== 'completed') {
44
- process.stdout.write('{}');
45
- process.exit(0);
44
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
45
+ // with no `status`, and a `status` it carries is ignored.
46
+ if (hookInput.action !== 'resume_blocked') {
47
+ process.stdout.write('{}');
48
+ process.exit(0);
49
+ }
46
50
  }
47
51
 
48
52
  // Slug resolution, strongest first:
@@ -2115,6 +2119,137 @@ function syncMetricsProfile(pipeline) {
2115
2119
  });
2116
2120
  }
2117
2121
 
2122
+ function resumeBlockedRefuse(reason) {
2123
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2124
+ }
2125
+
2126
+ /**
2127
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2128
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2129
+ * serializes on the lock and sees the first attempt instead of minting the
2130
+ * same ordinal.
2131
+ */
2132
+ function armResumedAttempt(step, stepIndex, agent) {
2133
+ let attemptId = null;
2134
+ mutateMetrics((metrics) => {
2135
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2136
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2137
+ metrics.task = { ...(metrics.task || {}), runId };
2138
+ status.metricsRunId = runId;
2139
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2140
+ const attempt =
2141
+ events.reduce(
2142
+ (highest, event) =>
2143
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2144
+ ? Math.max(highest, Number(event.attempt) || 0)
2145
+ : highest,
2146
+ 0,
2147
+ ) + 1;
2148
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2149
+ status.activeAttempts = {
2150
+ ...(status.activeAttempts || {}),
2151
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2152
+ };
2153
+ events.push({
2154
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2155
+ type: 'attempt_started',
2156
+ at: now,
2157
+ attemptId,
2158
+ stepIndex,
2159
+ stepLabel: step.label || null,
2160
+ agent,
2161
+ role: roleFor(agent),
2162
+ attempt,
2163
+ parallelGroupId: null,
2164
+ waveId: null,
2165
+ source: 'hook',
2166
+ attributionConfidence: 'high',
2167
+ });
2168
+ });
2169
+ return attemptId;
2170
+ }
2171
+
2172
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2173
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2174
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2175
+ if (hookInput.action === 'resume_blocked') {
2176
+ if (pauseBlocksAdvance()) process.exit(0);
2177
+ const pipeline = readPipeline();
2178
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2179
+ resumeBlockedRefuse(
2180
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2181
+ );
2182
+ process.exit(0);
2183
+ }
2184
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2185
+ const step = pipeline.steps[stepIndex];
2186
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2187
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2188
+ resumeBlockedRefuse(
2189
+ `graph mode is not supported by resume_blocked for slug "${slug}" (status.blockedSteps or a step.dependsOn): nothing was armed; resume the wave by hand.`,
2190
+ );
2191
+ process.exit(0);
2192
+ }
2193
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2194
+ if (agents.length === 0) {
2195
+ resumeBlockedRefuse(
2196
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2197
+ );
2198
+ process.exit(0);
2199
+ }
2200
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2201
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2202
+ if (agents.length > 1) {
2203
+ resumeBlockedRefuse(
2204
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2205
+ );
2206
+ process.exit(0);
2207
+ }
2208
+ if (status.state !== 'blocked') {
2209
+ resumeBlockedRefuse(
2210
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2211
+ );
2212
+ process.exit(0);
2213
+ }
2214
+ if (status.currentAgent === 'mockup-reviewer') {
2215
+ resumeBlockedRefuse(
2216
+ `the mockup-reviewer BLOCKED_MCP skip-forward owns this state for slug "${slug}": run {"action":"end_human_gate","activateNext":true} instead; resume_blocked armed nothing.`,
2217
+ );
2218
+ process.exit(0);
2219
+ }
2220
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2221
+ (entry) => entry && entry.stepIndex === stepIndex,
2222
+ );
2223
+ if (activeForStep.length > 0) {
2224
+ resumeBlockedRefuse(
2225
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2226
+ );
2227
+ process.exit(0);
2228
+ }
2229
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2230
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2231
+ // (missing consumer artifacts) falls back to the step's agent.
2232
+ const resumedAgent = status.currentAgent || agents[0];
2233
+ writeStatus({
2234
+ pipelineIndex: stepIndex,
2235
+ currentAgent: resumedAgent,
2236
+ phase: 'executing',
2237
+ state: 'in_progress',
2238
+ awaitingHumanGate: false,
2239
+ });
2240
+ process.stdout.write(
2241
+ JSON.stringify({
2242
+ ok: true,
2243
+ action: 'resume_blocked',
2244
+ pipelineIndex: stepIndex,
2245
+ agents,
2246
+ attemptIds: [attemptId],
2247
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2248
+ }),
2249
+ );
2250
+ process.exit(0);
2251
+ }
2252
+
2118
2253
  if (hookInput.action === 'bootstrap') {
2119
2254
  if (pauseBlocksAdvance()) process.exit(0);
2120
2255
  const pipeline = readPipeline();
@@ -42,8 +42,12 @@ if (hookInput.hook_event_name === 'SubagentStop') {
42
42
  }
43
43
 
44
44
  if (hookInput.status !== 'completed') {
45
- process.stdout.write('{}');
46
- process.exit(0);
45
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
46
+ // with no `status`, and a `status` it carries is ignored.
47
+ if (hookInput.action !== 'resume_blocked') {
48
+ process.stdout.write('{}');
49
+ process.exit(0);
50
+ }
47
51
  }
48
52
 
49
53
  // Slug resolution, strongest first:
@@ -2110,6 +2114,137 @@ function syncMetricsProfile(pipeline) {
2110
2114
  });
2111
2115
  }
2112
2116
 
2117
+ function resumeBlockedRefuse(reason) {
2118
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2119
+ }
2120
+
2121
+ /**
2122
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2123
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2124
+ * serializes on the lock and sees the first attempt instead of minting the
2125
+ * same ordinal.
2126
+ */
2127
+ function armResumedAttempt(step, stepIndex, agent) {
2128
+ let attemptId = null;
2129
+ mutateMetrics((metrics) => {
2130
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2131
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2132
+ metrics.task = { ...(metrics.task || {}), runId };
2133
+ status.metricsRunId = runId;
2134
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2135
+ const attempt =
2136
+ events.reduce(
2137
+ (highest, event) =>
2138
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2139
+ ? Math.max(highest, Number(event.attempt) || 0)
2140
+ : highest,
2141
+ 0,
2142
+ ) + 1;
2143
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2144
+ status.activeAttempts = {
2145
+ ...(status.activeAttempts || {}),
2146
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2147
+ };
2148
+ events.push({
2149
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2150
+ type: 'attempt_started',
2151
+ at: now,
2152
+ attemptId,
2153
+ stepIndex,
2154
+ stepLabel: step.label || null,
2155
+ agent,
2156
+ role: roleFor(agent),
2157
+ attempt,
2158
+ parallelGroupId: null,
2159
+ waveId: null,
2160
+ source: 'hook',
2161
+ attributionConfidence: 'high',
2162
+ });
2163
+ });
2164
+ return attemptId;
2165
+ }
2166
+
2167
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2168
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2169
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2170
+ if (hookInput.action === 'resume_blocked') {
2171
+ if (pauseBlocksAdvance()) process.exit(0);
2172
+ const pipeline = readPipeline();
2173
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2174
+ resumeBlockedRefuse(
2175
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2176
+ );
2177
+ process.exit(0);
2178
+ }
2179
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2180
+ const step = pipeline.steps[stepIndex];
2181
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2182
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2183
+ resumeBlockedRefuse(
2184
+ `graph mode is not supported by resume_blocked for slug "${slug}" (status.blockedSteps or a step.dependsOn): nothing was armed; resume the wave by hand.`,
2185
+ );
2186
+ process.exit(0);
2187
+ }
2188
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2189
+ if (agents.length === 0) {
2190
+ resumeBlockedRefuse(
2191
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2192
+ );
2193
+ process.exit(0);
2194
+ }
2195
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2196
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2197
+ if (agents.length > 1) {
2198
+ resumeBlockedRefuse(
2199
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2200
+ );
2201
+ process.exit(0);
2202
+ }
2203
+ if (status.state !== 'blocked') {
2204
+ resumeBlockedRefuse(
2205
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2206
+ );
2207
+ process.exit(0);
2208
+ }
2209
+ if (status.currentAgent === 'mockup-reviewer') {
2210
+ resumeBlockedRefuse(
2211
+ `the mockup-reviewer BLOCKED_MCP skip-forward owns this state for slug "${slug}": run {"action":"end_human_gate","activateNext":true} instead; resume_blocked armed nothing.`,
2212
+ );
2213
+ process.exit(0);
2214
+ }
2215
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2216
+ (entry) => entry && entry.stepIndex === stepIndex,
2217
+ );
2218
+ if (activeForStep.length > 0) {
2219
+ resumeBlockedRefuse(
2220
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2221
+ );
2222
+ process.exit(0);
2223
+ }
2224
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2225
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2226
+ // (missing consumer artifacts) falls back to the step's agent.
2227
+ const resumedAgent = status.currentAgent || agents[0];
2228
+ writeStatus({
2229
+ pipelineIndex: stepIndex,
2230
+ currentAgent: resumedAgent,
2231
+ phase: 'executing',
2232
+ state: 'in_progress',
2233
+ awaitingHumanGate: false,
2234
+ });
2235
+ process.stdout.write(
2236
+ JSON.stringify({
2237
+ ok: true,
2238
+ action: 'resume_blocked',
2239
+ pipelineIndex: stepIndex,
2240
+ agents,
2241
+ attemptIds: [attemptId],
2242
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2243
+ }),
2244
+ );
2245
+ process.exit(0);
2246
+ }
2247
+
2113
2248
  if (hookInput.action === 'bootstrap') {
2114
2249
  if (pauseBlocksAdvance()) process.exit(0);
2115
2250
  const pipeline = readPipeline();
@@ -41,8 +41,12 @@ if (hookInput.hook_event_name === 'SubagentStop') {
41
41
  }
42
42
 
43
43
  if (hookInput.status !== 'completed') {
44
- process.stdout.write('{}');
45
- process.exit(0);
44
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
45
+ // with no `status`, and a `status` it carries is ignored.
46
+ if (hookInput.action !== 'resume_blocked') {
47
+ process.stdout.write('{}');
48
+ process.exit(0);
49
+ }
46
50
  }
47
51
 
48
52
  // Slug resolution, strongest first:
@@ -2115,6 +2119,137 @@ function syncMetricsProfile(pipeline) {
2115
2119
  });
2116
2120
  }
2117
2121
 
2122
+ function resumeBlockedRefuse(reason) {
2123
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2124
+ }
2125
+
2126
+ /**
2127
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2128
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2129
+ * serializes on the lock and sees the first attempt instead of minting the
2130
+ * same ordinal.
2131
+ */
2132
+ function armResumedAttempt(step, stepIndex, agent) {
2133
+ let attemptId = null;
2134
+ mutateMetrics((metrics) => {
2135
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2136
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2137
+ metrics.task = { ...(metrics.task || {}), runId };
2138
+ status.metricsRunId = runId;
2139
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2140
+ const attempt =
2141
+ events.reduce(
2142
+ (highest, event) =>
2143
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2144
+ ? Math.max(highest, Number(event.attempt) || 0)
2145
+ : highest,
2146
+ 0,
2147
+ ) + 1;
2148
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2149
+ status.activeAttempts = {
2150
+ ...(status.activeAttempts || {}),
2151
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2152
+ };
2153
+ events.push({
2154
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2155
+ type: 'attempt_started',
2156
+ at: now,
2157
+ attemptId,
2158
+ stepIndex,
2159
+ stepLabel: step.label || null,
2160
+ agent,
2161
+ role: roleFor(agent),
2162
+ attempt,
2163
+ parallelGroupId: null,
2164
+ waveId: null,
2165
+ source: 'hook',
2166
+ attributionConfidence: 'high',
2167
+ });
2168
+ });
2169
+ return attemptId;
2170
+ }
2171
+
2172
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2173
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2174
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2175
+ if (hookInput.action === 'resume_blocked') {
2176
+ if (pauseBlocksAdvance()) process.exit(0);
2177
+ const pipeline = readPipeline();
2178
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2179
+ resumeBlockedRefuse(
2180
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2181
+ );
2182
+ process.exit(0);
2183
+ }
2184
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2185
+ const step = pipeline.steps[stepIndex];
2186
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2187
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2188
+ resumeBlockedRefuse(
2189
+ `graph mode is not supported by resume_blocked for slug "${slug}" (status.blockedSteps or a step.dependsOn): nothing was armed; resume the wave by hand.`,
2190
+ );
2191
+ process.exit(0);
2192
+ }
2193
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2194
+ if (agents.length === 0) {
2195
+ resumeBlockedRefuse(
2196
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2197
+ );
2198
+ process.exit(0);
2199
+ }
2200
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2201
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2202
+ if (agents.length > 1) {
2203
+ resumeBlockedRefuse(
2204
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2205
+ );
2206
+ process.exit(0);
2207
+ }
2208
+ if (status.state !== 'blocked') {
2209
+ resumeBlockedRefuse(
2210
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2211
+ );
2212
+ process.exit(0);
2213
+ }
2214
+ if (status.currentAgent === 'mockup-reviewer') {
2215
+ resumeBlockedRefuse(
2216
+ `the mockup-reviewer BLOCKED_MCP skip-forward owns this state for slug "${slug}": run {"action":"end_human_gate","activateNext":true} instead; resume_blocked armed nothing.`,
2217
+ );
2218
+ process.exit(0);
2219
+ }
2220
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2221
+ (entry) => entry && entry.stepIndex === stepIndex,
2222
+ );
2223
+ if (activeForStep.length > 0) {
2224
+ resumeBlockedRefuse(
2225
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2226
+ );
2227
+ process.exit(0);
2228
+ }
2229
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2230
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2231
+ // (missing consumer artifacts) falls back to the step's agent.
2232
+ const resumedAgent = status.currentAgent || agents[0];
2233
+ writeStatus({
2234
+ pipelineIndex: stepIndex,
2235
+ currentAgent: resumedAgent,
2236
+ phase: 'executing',
2237
+ state: 'in_progress',
2238
+ awaitingHumanGate: false,
2239
+ });
2240
+ process.stdout.write(
2241
+ JSON.stringify({
2242
+ ok: true,
2243
+ action: 'resume_blocked',
2244
+ pipelineIndex: stepIndex,
2245
+ agents,
2246
+ attemptIds: [attemptId],
2247
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2248
+ }),
2249
+ );
2250
+ process.exit(0);
2251
+ }
2252
+
2118
2253
  if (hookInput.action === 'bootstrap') {
2119
2254
  if (pauseBlocksAdvance()) process.exit(0);
2120
2255
  const pipeline = readPipeline();