@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
@@ -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();
@@ -15,3 +15,8 @@ Slash-command definitions and on-demand scenarios. Copied to `.claude/commands/`
15
15
  `/task-evil` is intentionally autonomous: no plan confirmation, no human gates, no questions; recommended assumptions are recorded in `decisions.md`, and only hard blockers stop the run. On OpenCode, the command selects the `task-evil` primary agent with a hard `question: deny`, broad shell access except `git commit`/`git push` (and `npx jest*`), and edits limited to `.ai.local/team/**`.
16
16
 
17
17
  See also the preset root `README.md`. Artifacts: `.ai.local/team/README.md`.
18
+
19
+ ## UI stack commands
20
+
21
+ - **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
22
+ - **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
@@ -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
 
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: ui-start
3
+ description: "Restart the team-tasks UI stack: stop it when running, refresh the task projection, then start."
4
+ ---
5
+
6
+ # Start the team-tasks UI
7
+
8
+ Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
9
+ from the current source, and guarantee the host team-db API the UI reads from.
10
+
11
+ ## What to do
12
+
13
+ 1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
14
+ repository has no team-tasks UI. Otherwise, from the repository root, run:
15
+
16
+ ```bash
17
+ node apps/team-tasks-ui/scripts/stack.mjs start
18
+ ```
19
+
20
+ 2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
21
+ including the owner state. On success the script prints
22
+ `ui: http://127.0.0.1:4300` and
23
+ `api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
24
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
25
+ with a different compose command and do not start the API by hand.
26
+ 4. The start is restart-safe: when the `team-tasks-ui` project is already
27
+ running, the script stops it first, runs `team-db.mjs migrate-tasks` against
28
+ the projection, then rebuilds the image from the current source and starts
29
+ again. A second start never binds a second stack or a second listener on the
30
+ published port.
31
+
32
+ ## What the script does
33
+
34
+ - Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
35
+ `team-tasks-ui` project name.
36
+ - Stops a running `team-tasks-ui` project and the API this script started
37
+ before refreshing the projection.
38
+ - Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
39
+ after that stop and before the rebuild, so the UI serves the current task
40
+ projection.
41
+ - Seeds `team/runner.json` from the default when it is absent.
42
+ - Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
43
+ nothing answers on `127.0.0.1:4178`, and records that ownership in the
44
+ git-ignored `.ai.local/.ui/api.json` marker.
45
+ - Repairs a missing derived database once through `team-db.mjs sync`, and never
46
+ repairs an API this script did not start.
47
+
48
+ ## Do not
49
+
50
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
51
+ - Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
52
+ - Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
53
+ or the team-db API.
54
+ - Open a browser, tail container logs, or start a second copy of the app.
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: ui-stop
3
+ description: Stop the team-tasks UI compose project and the team-db API that /ui-start started.
4
+ ---
5
+
6
+ # Stop the team-tasks UI
7
+
8
+ Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
9
+ team-db API only when `/ui-start` started it.
10
+
11
+ ## What to do
12
+
13
+ 1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
14
+ repository has no team-tasks UI. Otherwise, from the repository root, run:
15
+
16
+ ```bash
17
+ node apps/team-tasks-ui/scripts/stack.mjs stop
18
+ ```
19
+
20
+ 2. Quote the command's stdout verbatim. On an already stopped stack it prints
21
+ `nothing running` and exits 0.
22
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop.
23
+ 4. The stop is idempotent: a second stop exits 0 and changes nothing.
24
+
25
+ ## What the script does
26
+
27
+ - Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
28
+ `team-tasks-ui` project name, and removes that project's containers and
29
+ network.
30
+ - Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
31
+ command line is still `team-db.mjs serve`, then removes that marker.
32
+ - Leaves a foreign API alone: a process the marker does not prove is never
33
+ signalled.
34
+
35
+ ## Do not
36
+
37
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
38
+ - Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
39
+ - Stop a container outside the `team-tasks-ui` project.
40
+ - Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
41
+ source.
42
+ - Kill a process on `127.0.0.1:4178` by port; only the ownership marker
43
+ authorizes a stop.