@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
@@ -23,8 +23,12 @@ try {
23
23
  }
24
24
 
25
25
  if (hookInput.status !== 'completed') {
26
- process.stdout.write('{}');
27
- process.exit(0);
26
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
27
+ // with no `status`, and a `status` it carries is ignored.
28
+ if (hookInput.action !== 'resume_blocked') {
29
+ process.stdout.write('{}');
30
+ process.exit(0);
31
+ }
28
32
  }
29
33
 
30
34
  // Slug resolution, strongest first:
@@ -2095,6 +2099,137 @@ function syncMetricsProfile(pipeline) {
2095
2099
  });
2096
2100
  }
2097
2101
 
2102
+ function resumeBlockedRefuse(reason) {
2103
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2104
+ }
2105
+
2106
+ /**
2107
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2108
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2109
+ * serializes on the lock and sees the first attempt instead of minting the
2110
+ * same ordinal.
2111
+ */
2112
+ function armResumedAttempt(step, stepIndex, agent) {
2113
+ let attemptId = null;
2114
+ mutateMetrics((metrics) => {
2115
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2116
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2117
+ metrics.task = { ...(metrics.task || {}), runId };
2118
+ status.metricsRunId = runId;
2119
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2120
+ const attempt =
2121
+ events.reduce(
2122
+ (highest, event) =>
2123
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2124
+ ? Math.max(highest, Number(event.attempt) || 0)
2125
+ : highest,
2126
+ 0,
2127
+ ) + 1;
2128
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2129
+ status.activeAttempts = {
2130
+ ...(status.activeAttempts || {}),
2131
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2132
+ };
2133
+ events.push({
2134
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2135
+ type: 'attempt_started',
2136
+ at: now,
2137
+ attemptId,
2138
+ stepIndex,
2139
+ stepLabel: step.label || null,
2140
+ agent,
2141
+ role: roleFor(agent),
2142
+ attempt,
2143
+ parallelGroupId: null,
2144
+ waveId: null,
2145
+ source: 'hook',
2146
+ attributionConfidence: 'high',
2147
+ });
2148
+ });
2149
+ return attemptId;
2150
+ }
2151
+
2152
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2153
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2154
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2155
+ if (hookInput.action === 'resume_blocked') {
2156
+ if (pauseBlocksAdvance()) process.exit(0);
2157
+ const pipeline = readPipeline();
2158
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2159
+ resumeBlockedRefuse(
2160
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2161
+ );
2162
+ process.exit(0);
2163
+ }
2164
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2165
+ const step = pipeline.steps[stepIndex];
2166
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2167
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2168
+ resumeBlockedRefuse(
2169
+ `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.`,
2170
+ );
2171
+ process.exit(0);
2172
+ }
2173
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2174
+ if (agents.length === 0) {
2175
+ resumeBlockedRefuse(
2176
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2177
+ );
2178
+ process.exit(0);
2179
+ }
2180
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2181
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2182
+ if (agents.length > 1) {
2183
+ resumeBlockedRefuse(
2184
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2185
+ );
2186
+ process.exit(0);
2187
+ }
2188
+ if (status.state !== 'blocked') {
2189
+ resumeBlockedRefuse(
2190
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2191
+ );
2192
+ process.exit(0);
2193
+ }
2194
+ if (status.currentAgent === 'mockup-reviewer') {
2195
+ resumeBlockedRefuse(
2196
+ `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.`,
2197
+ );
2198
+ process.exit(0);
2199
+ }
2200
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2201
+ (entry) => entry && entry.stepIndex === stepIndex,
2202
+ );
2203
+ if (activeForStep.length > 0) {
2204
+ resumeBlockedRefuse(
2205
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2206
+ );
2207
+ process.exit(0);
2208
+ }
2209
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2210
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2211
+ // (missing consumer artifacts) falls back to the step's agent.
2212
+ const resumedAgent = status.currentAgent || agents[0];
2213
+ writeStatus({
2214
+ pipelineIndex: stepIndex,
2215
+ currentAgent: resumedAgent,
2216
+ phase: 'executing',
2217
+ state: 'in_progress',
2218
+ awaitingHumanGate: false,
2219
+ });
2220
+ process.stdout.write(
2221
+ JSON.stringify({
2222
+ ok: true,
2223
+ action: 'resume_blocked',
2224
+ pipelineIndex: stepIndex,
2225
+ agents,
2226
+ attemptIds: [attemptId],
2227
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2228
+ }),
2229
+ );
2230
+ process.exit(0);
2231
+ }
2232
+
2098
2233
  if (hookInput.action === 'bootstrap') {
2099
2234
  if (pauseBlocksAdvance()) process.exit(0);
2100
2235
  const pipeline = readPipeline();
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "nuxt",
5
5
  "semanticSource": "cursor/nuxt",
6
- "sourceRevision": "5b024037189002d202ec8810b57225421507f917d6df5f6be75e1d1fa1a4fbad",
6
+ "sourceRevision": "7a42e1cc5fc51ed53de8e97d9ecf35259a3915fb4b793255caee0f80096a7625",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -23,8 +23,12 @@ try {
23
23
  }
24
24
 
25
25
  if (hookInput.status !== 'completed') {
26
- process.stdout.write('{}');
27
- process.exit(0);
26
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
27
+ // with no `status`, and a `status` it carries is ignored.
28
+ if (hookInput.action !== 'resume_blocked') {
29
+ process.stdout.write('{}');
30
+ process.exit(0);
31
+ }
28
32
  }
29
33
 
30
34
  // Slug resolution, strongest first:
@@ -2095,6 +2099,137 @@ function syncMetricsProfile(pipeline) {
2095
2099
  });
2096
2100
  }
2097
2101
 
2102
+ function resumeBlockedRefuse(reason) {
2103
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2104
+ }
2105
+
2106
+ /**
2107
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2108
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2109
+ * serializes on the lock and sees the first attempt instead of minting the
2110
+ * same ordinal.
2111
+ */
2112
+ function armResumedAttempt(step, stepIndex, agent) {
2113
+ let attemptId = null;
2114
+ mutateMetrics((metrics) => {
2115
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2116
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2117
+ metrics.task = { ...(metrics.task || {}), runId };
2118
+ status.metricsRunId = runId;
2119
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2120
+ const attempt =
2121
+ events.reduce(
2122
+ (highest, event) =>
2123
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2124
+ ? Math.max(highest, Number(event.attempt) || 0)
2125
+ : highest,
2126
+ 0,
2127
+ ) + 1;
2128
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2129
+ status.activeAttempts = {
2130
+ ...(status.activeAttempts || {}),
2131
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2132
+ };
2133
+ events.push({
2134
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2135
+ type: 'attempt_started',
2136
+ at: now,
2137
+ attemptId,
2138
+ stepIndex,
2139
+ stepLabel: step.label || null,
2140
+ agent,
2141
+ role: roleFor(agent),
2142
+ attempt,
2143
+ parallelGroupId: null,
2144
+ waveId: null,
2145
+ source: 'hook',
2146
+ attributionConfidence: 'high',
2147
+ });
2148
+ });
2149
+ return attemptId;
2150
+ }
2151
+
2152
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2153
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2154
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2155
+ if (hookInput.action === 'resume_blocked') {
2156
+ if (pauseBlocksAdvance()) process.exit(0);
2157
+ const pipeline = readPipeline();
2158
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2159
+ resumeBlockedRefuse(
2160
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2161
+ );
2162
+ process.exit(0);
2163
+ }
2164
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2165
+ const step = pipeline.steps[stepIndex];
2166
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2167
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2168
+ resumeBlockedRefuse(
2169
+ `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.`,
2170
+ );
2171
+ process.exit(0);
2172
+ }
2173
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2174
+ if (agents.length === 0) {
2175
+ resumeBlockedRefuse(
2176
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2177
+ );
2178
+ process.exit(0);
2179
+ }
2180
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2181
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2182
+ if (agents.length > 1) {
2183
+ resumeBlockedRefuse(
2184
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2185
+ );
2186
+ process.exit(0);
2187
+ }
2188
+ if (status.state !== 'blocked') {
2189
+ resumeBlockedRefuse(
2190
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2191
+ );
2192
+ process.exit(0);
2193
+ }
2194
+ if (status.currentAgent === 'mockup-reviewer') {
2195
+ resumeBlockedRefuse(
2196
+ `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.`,
2197
+ );
2198
+ process.exit(0);
2199
+ }
2200
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2201
+ (entry) => entry && entry.stepIndex === stepIndex,
2202
+ );
2203
+ if (activeForStep.length > 0) {
2204
+ resumeBlockedRefuse(
2205
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2206
+ );
2207
+ process.exit(0);
2208
+ }
2209
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2210
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2211
+ // (missing consumer artifacts) falls back to the step's agent.
2212
+ const resumedAgent = status.currentAgent || agents[0];
2213
+ writeStatus({
2214
+ pipelineIndex: stepIndex,
2215
+ currentAgent: resumedAgent,
2216
+ phase: 'executing',
2217
+ state: 'in_progress',
2218
+ awaitingHumanGate: false,
2219
+ });
2220
+ process.stdout.write(
2221
+ JSON.stringify({
2222
+ ok: true,
2223
+ action: 'resume_blocked',
2224
+ pipelineIndex: stepIndex,
2225
+ agents,
2226
+ attemptIds: [attemptId],
2227
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2228
+ }),
2229
+ );
2230
+ process.exit(0);
2231
+ }
2232
+
2098
2233
  if (hookInput.action === 'bootstrap') {
2099
2234
  if (pauseBlocksAdvance()) process.exit(0);
2100
2235
  const pipeline = readPipeline();
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "php-hexagonal",
5
5
  "semanticSource": "cursor/php-hexagonal",
6
- "sourceRevision": "e3b0794965b87bff3fff8f7b92fa82946cd2bedeaf59e996bb2dccf51756ac69",
6
+ "sourceRevision": "26fef1ff3ccb39fdd39409fe8f94795f060126934716ce58e8f93c16c90a7ce3",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -25,8 +25,12 @@ try {
25
25
  }
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:
@@ -2093,6 +2097,137 @@ function syncMetricsProfile(pipeline) {
2093
2097
  });
2094
2098
  }
2095
2099
 
2100
+ function resumeBlockedRefuse(reason) {
2101
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2102
+ }
2103
+
2104
+ /**
2105
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2106
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2107
+ * serializes on the lock and sees the first attempt instead of minting the
2108
+ * same ordinal.
2109
+ */
2110
+ function armResumedAttempt(step, stepIndex, agent) {
2111
+ let attemptId = null;
2112
+ mutateMetrics((metrics) => {
2113
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2114
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2115
+ metrics.task = { ...(metrics.task || {}), runId };
2116
+ status.metricsRunId = runId;
2117
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2118
+ const attempt =
2119
+ events.reduce(
2120
+ (highest, event) =>
2121
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2122
+ ? Math.max(highest, Number(event.attempt) || 0)
2123
+ : highest,
2124
+ 0,
2125
+ ) + 1;
2126
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2127
+ status.activeAttempts = {
2128
+ ...(status.activeAttempts || {}),
2129
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2130
+ };
2131
+ events.push({
2132
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2133
+ type: 'attempt_started',
2134
+ at: now,
2135
+ attemptId,
2136
+ stepIndex,
2137
+ stepLabel: step.label || null,
2138
+ agent,
2139
+ role: roleFor(agent),
2140
+ attempt,
2141
+ parallelGroupId: null,
2142
+ waveId: null,
2143
+ source: 'hook',
2144
+ attributionConfidence: 'high',
2145
+ });
2146
+ });
2147
+ return attemptId;
2148
+ }
2149
+
2150
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2151
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2152
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2153
+ if (hookInput.action === 'resume_blocked') {
2154
+ if (pauseBlocksAdvance()) process.exit(0);
2155
+ const pipeline = readPipeline();
2156
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2157
+ resumeBlockedRefuse(
2158
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2159
+ );
2160
+ process.exit(0);
2161
+ }
2162
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2163
+ const step = pipeline.steps[stepIndex];
2164
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2165
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2166
+ resumeBlockedRefuse(
2167
+ `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.`,
2168
+ );
2169
+ process.exit(0);
2170
+ }
2171
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2172
+ if (agents.length === 0) {
2173
+ resumeBlockedRefuse(
2174
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2175
+ );
2176
+ process.exit(0);
2177
+ }
2178
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2179
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2180
+ if (agents.length > 1) {
2181
+ resumeBlockedRefuse(
2182
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2183
+ );
2184
+ process.exit(0);
2185
+ }
2186
+ if (status.state !== 'blocked') {
2187
+ resumeBlockedRefuse(
2188
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2189
+ );
2190
+ process.exit(0);
2191
+ }
2192
+ if (status.currentAgent === 'mockup-reviewer') {
2193
+ resumeBlockedRefuse(
2194
+ `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.`,
2195
+ );
2196
+ process.exit(0);
2197
+ }
2198
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2199
+ (entry) => entry && entry.stepIndex === stepIndex,
2200
+ );
2201
+ if (activeForStep.length > 0) {
2202
+ resumeBlockedRefuse(
2203
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2204
+ );
2205
+ process.exit(0);
2206
+ }
2207
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2208
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2209
+ // (missing consumer artifacts) falls back to the step's agent.
2210
+ const resumedAgent = status.currentAgent || agents[0];
2211
+ writeStatus({
2212
+ pipelineIndex: stepIndex,
2213
+ currentAgent: resumedAgent,
2214
+ phase: 'executing',
2215
+ state: 'in_progress',
2216
+ awaitingHumanGate: false,
2217
+ });
2218
+ process.stdout.write(
2219
+ JSON.stringify({
2220
+ ok: true,
2221
+ action: 'resume_blocked',
2222
+ pipelineIndex: stepIndex,
2223
+ agents,
2224
+ attemptIds: [attemptId],
2225
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2226
+ }),
2227
+ );
2228
+ process.exit(0);
2229
+ }
2230
+
2096
2231
  if (hookInput.action === 'bootstrap') {
2097
2232
  if (pauseBlocksAdvance()) process.exit(0);
2098
2233
  const pipeline = readPipeline();
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "php-laravel",
5
5
  "semanticSource": "cursor/php-laravel",
6
- "sourceRevision": "f3d586ca7fdf8c622d9964c8ab4862d0c6e7a114d89f22bdf780d6348fc88732",
6
+ "sourceRevision": "f3a71c3f7a5460b445bca1490d7c59132c0df35a8e3fb21f8bf491c099364a5e",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -25,8 +25,12 @@ try {
25
25
  }
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:
@@ -2093,6 +2097,137 @@ function syncMetricsProfile(pipeline) {
2093
2097
  });
2094
2098
  }
2095
2099
 
2100
+ function resumeBlockedRefuse(reason) {
2101
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2102
+ }
2103
+
2104
+ /**
2105
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2106
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2107
+ * serializes on the lock and sees the first attempt instead of minting the
2108
+ * same ordinal.
2109
+ */
2110
+ function armResumedAttempt(step, stepIndex, agent) {
2111
+ let attemptId = null;
2112
+ mutateMetrics((metrics) => {
2113
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2114
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2115
+ metrics.task = { ...(metrics.task || {}), runId };
2116
+ status.metricsRunId = runId;
2117
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2118
+ const attempt =
2119
+ events.reduce(
2120
+ (highest, event) =>
2121
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2122
+ ? Math.max(highest, Number(event.attempt) || 0)
2123
+ : highest,
2124
+ 0,
2125
+ ) + 1;
2126
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2127
+ status.activeAttempts = {
2128
+ ...(status.activeAttempts || {}),
2129
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2130
+ };
2131
+ events.push({
2132
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2133
+ type: 'attempt_started',
2134
+ at: now,
2135
+ attemptId,
2136
+ stepIndex,
2137
+ stepLabel: step.label || null,
2138
+ agent,
2139
+ role: roleFor(agent),
2140
+ attempt,
2141
+ parallelGroupId: null,
2142
+ waveId: null,
2143
+ source: 'hook',
2144
+ attributionConfidence: 'high',
2145
+ });
2146
+ });
2147
+ return attemptId;
2148
+ }
2149
+
2150
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2151
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2152
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2153
+ if (hookInput.action === 'resume_blocked') {
2154
+ if (pauseBlocksAdvance()) process.exit(0);
2155
+ const pipeline = readPipeline();
2156
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2157
+ resumeBlockedRefuse(
2158
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2159
+ );
2160
+ process.exit(0);
2161
+ }
2162
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2163
+ const step = pipeline.steps[stepIndex];
2164
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2165
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2166
+ resumeBlockedRefuse(
2167
+ `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.`,
2168
+ );
2169
+ process.exit(0);
2170
+ }
2171
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2172
+ if (agents.length === 0) {
2173
+ resumeBlockedRefuse(
2174
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2175
+ );
2176
+ process.exit(0);
2177
+ }
2178
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2179
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2180
+ if (agents.length > 1) {
2181
+ resumeBlockedRefuse(
2182
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2183
+ );
2184
+ process.exit(0);
2185
+ }
2186
+ if (status.state !== 'blocked') {
2187
+ resumeBlockedRefuse(
2188
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2189
+ );
2190
+ process.exit(0);
2191
+ }
2192
+ if (status.currentAgent === 'mockup-reviewer') {
2193
+ resumeBlockedRefuse(
2194
+ `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.`,
2195
+ );
2196
+ process.exit(0);
2197
+ }
2198
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2199
+ (entry) => entry && entry.stepIndex === stepIndex,
2200
+ );
2201
+ if (activeForStep.length > 0) {
2202
+ resumeBlockedRefuse(
2203
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2204
+ );
2205
+ process.exit(0);
2206
+ }
2207
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2208
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2209
+ // (missing consumer artifacts) falls back to the step's agent.
2210
+ const resumedAgent = status.currentAgent || agents[0];
2211
+ writeStatus({
2212
+ pipelineIndex: stepIndex,
2213
+ currentAgent: resumedAgent,
2214
+ phase: 'executing',
2215
+ state: 'in_progress',
2216
+ awaitingHumanGate: false,
2217
+ });
2218
+ process.stdout.write(
2219
+ JSON.stringify({
2220
+ ok: true,
2221
+ action: 'resume_blocked',
2222
+ pipelineIndex: stepIndex,
2223
+ agents,
2224
+ attemptIds: [attemptId],
2225
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2226
+ }),
2227
+ );
2228
+ process.exit(0);
2229
+ }
2230
+
2096
2231
  if (hookInput.action === 'bootstrap') {
2097
2232
  if (pauseBlocksAdvance()) process.exit(0);
2098
2233
  const pipeline = readPipeline();