@bonesofspring/ai-rules 0.2.68 → 0.2.69

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 (97) hide show
  1. package/CHANGELOG.md +10 -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/task-continue.md +17 -6
  12. package/presets/claude/next/hooks/chain-team-phases.sh +137 -2
  13. package/presets/claude/nuxt/hooks/chain-team-phases.sh +137 -2
  14. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  15. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +137 -2
  16. package/presets/claude/svelte/hooks/chain-team-phases.sh +137 -2
  17. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +137 -2
  18. package/presets/cursor/go/hooks/chain-team-phases.sh +137 -2
  19. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +137 -2
  20. package/presets/cursor/java/hooks/chain-team-phases.sh +137 -2
  21. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +137 -2
  22. package/presets/cursor/mol/hooks/chain-team-phases.sh +137 -2
  23. package/presets/cursor/next/commands/task-continue.md +17 -6
  24. package/presets/cursor/next/hooks/chain-team-phases.sh +137 -2
  25. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +137 -2
  26. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  27. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +137 -2
  28. package/presets/cursor/svelte/hooks/chain-team-phases.sh +137 -2
  29. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  30. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +137 -2
  31. package/presets/mavis/go/adapter-map.json +1 -1
  32. package/presets/mavis/go/hooks/chain-team-phases.sh +137 -2
  33. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  34. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +137 -2
  35. package/presets/mavis/java/adapter-map.json +1 -1
  36. package/presets/mavis/java/hooks/chain-team-phases.sh +137 -2
  37. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  38. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +137 -2
  39. package/presets/mavis/mol/adapter-map.json +1 -1
  40. package/presets/mavis/mol/hooks/chain-team-phases.sh +137 -2
  41. package/presets/mavis/next/adapter-map.json +1 -1
  42. package/presets/mavis/next/commands/task-continue.md +16 -5
  43. package/presets/mavis/next/hooks/chain-team-phases.sh +137 -2
  44. package/presets/mavis/nuxt/adapter-map.json +1 -1
  45. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +137 -2
  46. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  47. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  48. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  49. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +137 -2
  50. package/presets/mavis/svelte/adapter-map.json +1 -1
  51. package/presets/mavis/svelte/hooks/chain-team-phases.sh +137 -2
  52. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  53. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +137 -2
  54. package/presets/opencode/go/adapter-map.json +1 -1
  55. package/presets/opencode/go/hooks/chain-team-phases.sh +137 -2
  56. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  57. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +137 -2
  58. package/presets/opencode/java/adapter-map.json +1 -1
  59. package/presets/opencode/java/hooks/chain-team-phases.sh +137 -2
  60. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  61. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +137 -2
  62. package/presets/opencode/mol/adapter-map.json +1 -1
  63. package/presets/opencode/mol/hooks/chain-team-phases.sh +137 -2
  64. package/presets/opencode/next/adapter-map.json +1 -1
  65. package/presets/opencode/next/commands/task-continue.md +17 -6
  66. package/presets/opencode/next/hooks/chain-team-phases.sh +137 -2
  67. package/presets/opencode/nuxt/adapter-map.json +1 -1
  68. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +137 -2
  69. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  70. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  71. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  72. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +137 -2
  73. package/presets/opencode/svelte/adapter-map.json +1 -1
  74. package/presets/opencode/svelte/hooks/chain-team-phases.sh +137 -2
  75. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  76. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +137 -2
  77. package/presets/zcode/go/adapter-map.json +1 -1
  78. package/presets/zcode/go/hooks/chain-team-phases.sh +137 -2
  79. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  80. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +137 -2
  81. package/presets/zcode/java/adapter-map.json +1 -1
  82. package/presets/zcode/java/hooks/chain-team-phases.sh +137 -2
  83. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  84. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +137 -2
  85. package/presets/zcode/mol/adapter-map.json +1 -1
  86. package/presets/zcode/mol/hooks/chain-team-phases.sh +137 -2
  87. package/presets/zcode/next/adapter-map.json +1 -1
  88. package/presets/zcode/next/commands/task-continue.md +17 -6
  89. package/presets/zcode/next/hooks/chain-team-phases.sh +137 -2
  90. package/presets/zcode/nuxt/adapter-map.json +1 -1
  91. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +137 -2
  92. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  93. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +137 -2
  94. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  95. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +137 -2
  96. package/presets/zcode/svelte/adapter-map.json +1 -1
  97. package/presets/zcode/svelte/hooks/chain-team-phases.sh +137 -2
@@ -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();
@@ -44,8 +44,12 @@ if (hookInput.hook_event_name === 'SubagentStop') {
44
44
  }
45
45
 
46
46
  if (hookInput.status !== 'completed') {
47
- process.stdout.write('{}');
48
- process.exit(0);
47
+ // `resume_blocked` is a lifecycle repair, not a producer receipt: it runs
48
+ // with no `status`, and a `status` it carries is ignored.
49
+ if (hookInput.action !== 'resume_blocked') {
50
+ process.stdout.write('{}');
51
+ process.exit(0);
52
+ }
49
53
  }
50
54
 
51
55
  // Slug resolution, strongest first:
@@ -2057,6 +2061,137 @@ function syncMetricsProfile(pipeline) {
2057
2061
  });
2058
2062
  }
2059
2063
 
2064
+ function resumeBlockedRefuse(reason) {
2065
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2066
+ }
2067
+
2068
+ /**
2069
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2070
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2071
+ * serializes on the lock and sees the first attempt instead of minting the
2072
+ * same ordinal.
2073
+ */
2074
+ function armResumedAttempt(step, stepIndex, agent) {
2075
+ let attemptId = null;
2076
+ mutateMetrics((metrics) => {
2077
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2078
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2079
+ metrics.task = { ...(metrics.task || {}), runId };
2080
+ status.metricsRunId = runId;
2081
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2082
+ const attempt =
2083
+ events.reduce(
2084
+ (highest, event) =>
2085
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2086
+ ? Math.max(highest, Number(event.attempt) || 0)
2087
+ : highest,
2088
+ 0,
2089
+ ) + 1;
2090
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2091
+ status.activeAttempts = {
2092
+ ...(status.activeAttempts || {}),
2093
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2094
+ };
2095
+ events.push({
2096
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2097
+ type: 'attempt_started',
2098
+ at: now,
2099
+ attemptId,
2100
+ stepIndex,
2101
+ stepLabel: step.label || null,
2102
+ agent,
2103
+ role: roleFor(agent),
2104
+ attempt,
2105
+ parallelGroupId: null,
2106
+ waveId: null,
2107
+ source: 'hook',
2108
+ attributionConfidence: 'high',
2109
+ });
2110
+ });
2111
+ return attemptId;
2112
+ }
2113
+
2114
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2115
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2116
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2117
+ if (hookInput.action === 'resume_blocked') {
2118
+ if (pauseBlocksAdvance()) process.exit(0);
2119
+ const pipeline = readPipeline();
2120
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2121
+ resumeBlockedRefuse(
2122
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2123
+ );
2124
+ process.exit(0);
2125
+ }
2126
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2127
+ const step = pipeline.steps[stepIndex];
2128
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2129
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2130
+ resumeBlockedRefuse(
2131
+ `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.`,
2132
+ );
2133
+ process.exit(0);
2134
+ }
2135
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2136
+ if (agents.length === 0) {
2137
+ resumeBlockedRefuse(
2138
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2139
+ );
2140
+ process.exit(0);
2141
+ }
2142
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2143
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2144
+ if (agents.length > 1) {
2145
+ resumeBlockedRefuse(
2146
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2147
+ );
2148
+ process.exit(0);
2149
+ }
2150
+ if (status.state !== 'blocked') {
2151
+ resumeBlockedRefuse(
2152
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2153
+ );
2154
+ process.exit(0);
2155
+ }
2156
+ if (status.currentAgent === 'mockup-reviewer') {
2157
+ resumeBlockedRefuse(
2158
+ `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.`,
2159
+ );
2160
+ process.exit(0);
2161
+ }
2162
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2163
+ (entry) => entry && entry.stepIndex === stepIndex,
2164
+ );
2165
+ if (activeForStep.length > 0) {
2166
+ resumeBlockedRefuse(
2167
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2168
+ );
2169
+ process.exit(0);
2170
+ }
2171
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2172
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2173
+ // (missing consumer artifacts) falls back to the step's agent.
2174
+ const resumedAgent = status.currentAgent || agents[0];
2175
+ writeStatus({
2176
+ pipelineIndex: stepIndex,
2177
+ currentAgent: resumedAgent,
2178
+ phase: 'executing',
2179
+ state: 'in_progress',
2180
+ awaitingHumanGate: false,
2181
+ });
2182
+ process.stdout.write(
2183
+ JSON.stringify({
2184
+ ok: true,
2185
+ action: 'resume_blocked',
2186
+ pipelineIndex: stepIndex,
2187
+ agents,
2188
+ attemptIds: [attemptId],
2189
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2190
+ }),
2191
+ );
2192
+ process.exit(0);
2193
+ }
2194
+
2060
2195
  if (hookInput.action === 'bootstrap') {
2061
2196
  if (pauseBlocksAdvance()) process.exit(0);
2062
2197
  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:
@@ -2112,6 +2116,137 @@ function syncMetricsProfile(pipeline) {
2112
2116
  });
2113
2117
  }
2114
2118
 
2119
+ function resumeBlockedRefuse(reason) {
2120
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2121
+ }
2122
+
2123
+ /**
2124
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2125
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2126
+ * serializes on the lock and sees the first attempt instead of minting the
2127
+ * same ordinal.
2128
+ */
2129
+ function armResumedAttempt(step, stepIndex, agent) {
2130
+ let attemptId = null;
2131
+ mutateMetrics((metrics) => {
2132
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2133
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2134
+ metrics.task = { ...(metrics.task || {}), runId };
2135
+ status.metricsRunId = runId;
2136
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2137
+ const attempt =
2138
+ events.reduce(
2139
+ (highest, event) =>
2140
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2141
+ ? Math.max(highest, Number(event.attempt) || 0)
2142
+ : highest,
2143
+ 0,
2144
+ ) + 1;
2145
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2146
+ status.activeAttempts = {
2147
+ ...(status.activeAttempts || {}),
2148
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2149
+ };
2150
+ events.push({
2151
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2152
+ type: 'attempt_started',
2153
+ at: now,
2154
+ attemptId,
2155
+ stepIndex,
2156
+ stepLabel: step.label || null,
2157
+ agent,
2158
+ role: roleFor(agent),
2159
+ attempt,
2160
+ parallelGroupId: null,
2161
+ waveId: null,
2162
+ source: 'hook',
2163
+ attributionConfidence: 'high',
2164
+ });
2165
+ });
2166
+ return attemptId;
2167
+ }
2168
+
2169
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2170
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2171
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2172
+ if (hookInput.action === 'resume_blocked') {
2173
+ if (pauseBlocksAdvance()) process.exit(0);
2174
+ const pipeline = readPipeline();
2175
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2176
+ resumeBlockedRefuse(
2177
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2178
+ );
2179
+ process.exit(0);
2180
+ }
2181
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2182
+ const step = pipeline.steps[stepIndex];
2183
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2184
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2185
+ resumeBlockedRefuse(
2186
+ `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.`,
2187
+ );
2188
+ process.exit(0);
2189
+ }
2190
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2191
+ if (agents.length === 0) {
2192
+ resumeBlockedRefuse(
2193
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2194
+ );
2195
+ process.exit(0);
2196
+ }
2197
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2198
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2199
+ if (agents.length > 1) {
2200
+ resumeBlockedRefuse(
2201
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2202
+ );
2203
+ process.exit(0);
2204
+ }
2205
+ if (status.state !== 'blocked') {
2206
+ resumeBlockedRefuse(
2207
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2208
+ );
2209
+ process.exit(0);
2210
+ }
2211
+ if (status.currentAgent === 'mockup-reviewer') {
2212
+ resumeBlockedRefuse(
2213
+ `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.`,
2214
+ );
2215
+ process.exit(0);
2216
+ }
2217
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2218
+ (entry) => entry && entry.stepIndex === stepIndex,
2219
+ );
2220
+ if (activeForStep.length > 0) {
2221
+ resumeBlockedRefuse(
2222
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2223
+ );
2224
+ process.exit(0);
2225
+ }
2226
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2227
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2228
+ // (missing consumer artifacts) falls back to the step's agent.
2229
+ const resumedAgent = status.currentAgent || agents[0];
2230
+ writeStatus({
2231
+ pipelineIndex: stepIndex,
2232
+ currentAgent: resumedAgent,
2233
+ phase: 'executing',
2234
+ state: 'in_progress',
2235
+ awaitingHumanGate: false,
2236
+ });
2237
+ process.stdout.write(
2238
+ JSON.stringify({
2239
+ ok: true,
2240
+ action: 'resume_blocked',
2241
+ pipelineIndex: stepIndex,
2242
+ agents,
2243
+ attemptIds: [attemptId],
2244
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2245
+ }),
2246
+ );
2247
+ process.exit(0);
2248
+ }
2249
+
2115
2250
  if (hookInput.action === 'bootstrap') {
2116
2251
  if (pauseBlocksAdvance()) process.exit(0);
2117
2252
  const pipeline = readPipeline();
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  name: task-continue
3
- description: Continue an agent-team task after a human gate, pause, or review changes request using pipeline.json and status.json.
3
+ description: Continue an agent-team task after a human gate, pause, blocked receipt, or review changes request using pipeline.json and status.json.
4
4
  ---
5
5
 
6
- # Task continue — after human gate or pause
6
+ # Task continue — after human gate, pause, or blocked receipt
7
7
 
8
8
  Resume the pipeline from `pipeline.json`.
9
9
 
@@ -17,6 +17,7 @@ Resume the pipeline from `pipeline.json`.
17
17
  2. Continue if:
18
18
  - `awaitingHumanGate: true` or `state: awaiting_approval`, **or**
19
19
  - `state: changes_requested` (after review), **or**
20
+ - `state: blocked` (a producer's terminal `blocked` receipt and the owner has resolved the blockers), **or**
20
21
  - `state: paused` (the `.ai.local/STOP` / `.ai.local/ESTOP` sentinel is gone), **or**
21
22
  - the task was interrupted and must resume from `pipelineIndex`.
22
23
 
@@ -34,10 +35,20 @@ printf '%s\n' '{"status":"completed","action":"end_human_gate","activateNext":tr
34
35
  3. Re-read `status.json` (and the hook `followup_message`).
35
36
  4. Invoke the subagent named in `status.currentAgent` / followup — do **not** advance the pipeline a second time.
36
37
  3. **Review `changes_requested`** (not a human gate): if `currentAgent` is **`mockup-reviewer`**, this is the FAIL-only mockup gate — do **not** retry `feature-developer`. Read `mockup-review.md` and resume via the human-gate path (`end_human_gate` / `activateNext`). Otherwise: set `currentAgent` to `feature-developer` (same index / find developer in steps), `state: in_progress`, then invoke developer. Do **not** call `end_human_gate` unless `activeHumanGateEventId` is set.
37
- 4. **`blocked` + `currentAgent: mockup-reviewer`** (`BLOCKED_MCP`): skip-forward via the same `end_human_gate`/`activateNext` path (explicit «proceed without MCP»). Do not invent DS claims.
38
- 5. **Other resume**: restore `pipelineIndex` / `currentAgent` from status and invoke that agent.
39
- 6. **Paused** (`state: paused`, sentinel removed): if `awaitingHumanGate` is still true, use the human-gate resume path above. Otherwise close the pause through the installed hook with `{"status":"completed"}` and no `action`, then re-read `status.json` and the hook `followup_message`; do not advance by hand.
40
- 7. After the invoked agent completes, `chain-team-phases.sh` on `subagentStop` continues the chain when `autoChain: true`.
38
+ 4. **`blocked` + `currentAgent: mockup-reviewer`** (`BLOCKED_MCP`): skip-forward via the same `end_human_gate`/`activateNext` path (explicit «proceed without MCP»). Do not invent DS claims. This exception keeps precedence: `resume_blocked` refuses this state and names the skip-forward.
39
+ 5. **`state: blocked`** (every other producer): re-arm the blocked step through the **installed** hook — it activates attempt N+1 and is the **single authority** for the ledger:
40
+ 1. **Do not** manually increment `pipelineIndex` or hand-write `status.json` fields.
41
+
42
+ ```bash
43
+ printf '%s\n' '{"action":"resume_blocked"}' | TEAM_TASK_SLUG=<slug> bash .claude/hooks/chain-team-phases.sh
44
+ ```
45
+
46
+ 2. `ok:false` with a `reason` (`is not blocked`, `pipeline.json`, `graph mode`, `already has an active attempt`) means nothing was armed: re-read `status.json` and act on the reason. A refusal carries no `followup_message` — never re-invoke a producer on it.
47
+ 3. `ok:true` arms attempt N+1 on the same step: re-read `status.json`, then invoke the subagent named in `status.currentAgent` with the hook `followup_message`. Do **not** open the gate yourself: the retried receipt opens it (`awaiting_approval`) when the step has `after:<agent>` in `humanGates`, and advances the chain otherwise.
48
+ 4. Fallback only for an installed hook that predates the action (the call answers `{}`): run `{"status":"completed","action":"bootstrap"}` then `{"status":"completed"}`. The second run opens the gate or advances; the retried producer is not ledgered, so record it in `.memlog.md`.
49
+ 6. **Other resume**: restore `pipelineIndex` / `currentAgent` from status and invoke that agent.
50
+ 7. **Paused** (`state: paused`, sentinel removed): if `awaitingHumanGate` is still true, use the human-gate resume path above. Otherwise close the pause through the installed hook with `{"status":"completed"}` and no `action`, then re-read `status.json` and the hook `followup_message`; do not advance by hand.
51
+ 8. After the invoked agent completes, `chain-team-phases.sh` on `subagentStop` continues the chain when `autoChain: true`.
41
52
 
42
53
  ## Checkpoint & resume
43
54
 
@@ -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:
@@ -2113,6 +2117,137 @@ function syncMetricsProfile(pipeline) {
2113
2117
  });
2114
2118
  }
2115
2119
 
2120
+ function resumeBlockedRefuse(reason) {
2121
+ process.stdout.write(JSON.stringify({ ok: false, action: 'resume_blocked', reason }));
2122
+ }
2123
+
2124
+ /**
2125
+ * Arm attempt N+1 for one linear step. The ordinal read and the append share
2126
+ * one metrics critical section, like `completeTaskMetrics`: a second process
2127
+ * serializes on the lock and sees the first attempt instead of minting the
2128
+ * same ordinal.
2129
+ */
2130
+ function armResumedAttempt(step, stepIndex, agent) {
2131
+ let attemptId = null;
2132
+ mutateMetrics((metrics) => {
2133
+ const ledgerRunId = metrics.task && typeof metrics.task.runId === 'string' ? metrics.task.runId : '';
2134
+ const runId = ledgerRunId || status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2135
+ metrics.task = { ...(metrics.task || {}), runId };
2136
+ status.metricsRunId = runId;
2137
+ const events = Array.isArray(metrics.events) ? metrics.events : (metrics.events = []);
2138
+ const attempt =
2139
+ events.reduce(
2140
+ (highest, event) =>
2141
+ event && event.type === 'attempt_started' && event.stepIndex === stepIndex && event.agent === agent
2142
+ ? Math.max(highest, Number(event.attempt) || 0)
2143
+ : highest,
2144
+ 0,
2145
+ ) + 1;
2146
+ attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2147
+ status.activeAttempts = {
2148
+ ...(status.activeAttempts || {}),
2149
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2150
+ };
2151
+ events.push({
2152
+ eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
2153
+ type: 'attempt_started',
2154
+ at: now,
2155
+ attemptId,
2156
+ stepIndex,
2157
+ stepLabel: step.label || null,
2158
+ agent,
2159
+ role: roleFor(agent),
2160
+ attempt,
2161
+ parallelGroupId: null,
2162
+ waveId: null,
2163
+ source: 'hook',
2164
+ attributionConfidence: 'high',
2165
+ });
2166
+ });
2167
+ return attemptId;
2168
+ }
2169
+
2170
+ // Re-arm the step a producer left `blocked`. It arms the attempt only: a stop
2171
+ // that finds `awaitingHumanGate: true` returns before the stop tail, so an open
2172
+ // gate would swallow the retried receipt. Gate/advance stays receipt-driven.
2173
+ if (hookInput.action === 'resume_blocked') {
2174
+ if (pauseBlocksAdvance()) process.exit(0);
2175
+ const pipeline = readPipeline();
2176
+ if (!pipeline || !Array.isArray(pipeline.steps) || pipeline.steps.length === 0) {
2177
+ resumeBlockedRefuse(
2178
+ `pipeline.json is missing, unparseable, or has no steps for slug "${slug}"; no attempt was armed and status.json is unchanged.`,
2179
+ );
2180
+ process.exit(0);
2181
+ }
2182
+ const stepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
2183
+ const step = pipeline.steps[stepIndex];
2184
+ const blockedSteps = Array.isArray(status.blockedSteps) ? status.blockedSteps : [];
2185
+ if (blockedSteps.length > 0 || pipeline.steps.some((entry) => entry && Array.isArray(entry.dependsOn))) {
2186
+ resumeBlockedRefuse(
2187
+ `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.`,
2188
+ );
2189
+ process.exit(0);
2190
+ }
2191
+ const agents = step ? getStepAgents(step).filter((agent) => typeof agent === 'string' && agent.length > 0) : [];
2192
+ if (agents.length === 0) {
2193
+ resumeBlockedRefuse(
2194
+ `pipeline.json has no executable step at pipelineIndex ${stepIndex} for slug "${slug}"; nothing was armed.`,
2195
+ );
2196
+ process.exit(0);
2197
+ }
2198
+ // A parallel wave is not a single linear step: re-arming it would re-run the
2199
+ // agents that already succeeded. Refuse the shape instead of arming the wave.
2200
+ if (agents.length > 1) {
2201
+ resumeBlockedRefuse(
2202
+ `step ${stepIndex} is a parallel wave for slug "${slug}" (${agents.join(', ')}); resume_blocked arms one linear step, so nothing was armed.`,
2203
+ );
2204
+ process.exit(0);
2205
+ }
2206
+ if (status.state !== 'blocked') {
2207
+ resumeBlockedRefuse(
2208
+ `state "${status.state || 'unknown'}" is not blocked for slug "${slug}"; resume_blocked only re-arms the step a producer left blocked.`,
2209
+ );
2210
+ process.exit(0);
2211
+ }
2212
+ if (status.currentAgent === 'mockup-reviewer') {
2213
+ resumeBlockedRefuse(
2214
+ `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.`,
2215
+ );
2216
+ process.exit(0);
2217
+ }
2218
+ const activeForStep = Object.values(status.activeAttempts || {}).filter(
2219
+ (entry) => entry && entry.stepIndex === stepIndex,
2220
+ );
2221
+ if (activeForStep.length > 0) {
2222
+ resumeBlockedRefuse(
2223
+ `step ${stepIndex} already has an active attempt for slug "${slug}" (${activeForStep.map((entry) => entry.agent).join(', ')}); resume_blocked changed nothing.`,
2224
+ );
2225
+ process.exit(0);
2226
+ }
2227
+ const attemptId = armResumedAttempt(step, stepIndex, agents[0]);
2228
+ // `currentAgent` names the blocked producer; a pipeline blocked without one
2229
+ // (missing consumer artifacts) falls back to the step's agent.
2230
+ const resumedAgent = status.currentAgent || agents[0];
2231
+ writeStatus({
2232
+ pipelineIndex: stepIndex,
2233
+ currentAgent: resumedAgent,
2234
+ phase: 'executing',
2235
+ state: 'in_progress',
2236
+ awaitingHumanGate: false,
2237
+ });
2238
+ process.stdout.write(
2239
+ JSON.stringify({
2240
+ ok: true,
2241
+ action: 'resume_blocked',
2242
+ pipelineIndex: stepIndex,
2243
+ agents,
2244
+ attemptIds: [attemptId],
2245
+ followup_message: handoffForAgent(resumedAgent, step.scope, step),
2246
+ }),
2247
+ );
2248
+ process.exit(0);
2249
+ }
2250
+
2116
2251
  if (hookInput.action === 'bootstrap') {
2117
2252
  if (pauseBlocksAdvance()) process.exit(0);
2118
2253
  const pipeline = readPipeline();