pi-spine 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/bin/spine-batch.mjs +160 -53
  2. package/bin/spine-cli/batch.mjs +3 -3
  3. package/bin/spine-cli/lane-logs.mjs +24 -0
  4. package/bin/spine-cli/scenarios.mjs +298 -0
  5. package/bin/spine-cli/wait.mjs +30 -0
  6. package/bin/spine-cli/watch.mjs +27 -0
  7. package/bin/spine-issue.mjs +196 -0
  8. package/bin/spine-journal.mjs +1 -0
  9. package/bin/spine-run.mjs +30 -0
  10. package/bin/spine-status.mjs +19 -1
  11. package/bin/spine-tasks.mjs +16 -2
  12. package/bin/spine-worker-runner.mjs +10 -10
  13. package/bin/spine.mjs +49 -1
  14. package/package.json +1 -1
  15. package/skills/create-spine-tasks/references/contract-template.md +19 -0
  16. package/src/batch/abort.mjs +2 -11
  17. package/src/batch/agent-session-worker.mjs +45 -5
  18. package/src/batch/attached-engine-handoff.mjs +188 -0
  19. package/src/batch/attached-runner.mjs +312 -0
  20. package/src/batch/contract-prelanded.mjs +180 -0
  21. package/src/batch/contract-verify.mjs +140 -2
  22. package/src/batch/detached-start.mjs +66 -2
  23. package/src/batch/diagnosis-alternatives.mjs +46 -0
  24. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  25. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  26. package/src/batch/diagnosis-stub.mjs +109 -0
  27. package/src/batch/diagnosis-task-done.mjs +110 -0
  28. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  29. package/src/batch/diagnosis.mjs +135 -68
  30. package/src/batch/engine-lanes/merge.mjs +110 -82
  31. package/src/batch/engine-lanes/queue.mjs +4 -1
  32. package/src/batch/engine-lanes/watch.mjs +29 -0
  33. package/src/batch/engine-lanes.mjs +1 -0
  34. package/src/batch/engine-scope.mjs +11 -1
  35. package/src/batch/engine.mjs +79 -24
  36. package/src/batch/evidence.mjs +78 -15
  37. package/src/batch/gate.mjs +43 -14
  38. package/src/batch/git-helpers.mjs +96 -0
  39. package/src/batch/heartbeat.mjs +73 -7
  40. package/src/batch/integrate.mjs +2 -4
  41. package/src/batch/journal.mjs +3 -0
  42. package/src/batch/lane-commit.mjs +90 -5
  43. package/src/batch/lifecycle.mjs +130 -3
  44. package/src/batch/macro-phase.mjs +226 -0
  45. package/src/batch/merge/adoption-doc-merge.mjs +93 -10
  46. package/src/batch/merge/wave-merge-state.mjs +3 -0
  47. package/src/batch/metrics.mjs +74 -5
  48. package/src/batch/orphan-detect.mjs +74 -0
  49. package/src/batch/pause.mjs +223 -0
  50. package/src/batch/post-merge-limbo.mjs +264 -8
  51. package/src/batch/reconcile.mjs +429 -54
  52. package/src/batch/resume-common.mjs +5 -1
  53. package/src/batch/resume-lane-reviews.mjs +16 -0
  54. package/src/batch/resume-multi-lanes.mjs +56 -1
  55. package/src/batch/resume-multi-validate.mjs +67 -6
  56. package/src/batch/resume-multi.mjs +9 -4
  57. package/src/batch/resume.mjs +52 -45
  58. package/src/batch/retry.mjs +56 -5
  59. package/src/batch/review-spawn.mjs +8 -2
  60. package/src/batch/rules-manifest-drift.mjs +157 -0
  61. package/src/batch/salvage.mjs +2 -1
  62. package/src/batch/sequence.mjs +454 -0
  63. package/src/batch/state.mjs +18 -3
  64. package/src/batch/status-json.mjs +67 -0
  65. package/src/batch/task-stall-budget.mjs +22 -10
  66. package/src/batch/worker-host.mjs +95 -7
  67. package/src/batch/worker-output.mjs +196 -3
  68. package/src/cli/issue-draft.mjs +180 -0
  69. package/src/cli/journal-follow.mjs +239 -0
  70. package/src/cli/lane-logs.mjs +291 -0
  71. package/src/cli/sequence.mjs +108 -0
  72. package/src/cli/settings-set.mjs +2 -21
  73. package/src/cli/wait.mjs +187 -0
  74. package/src/cli/watch.mjs +160 -0
  75. package/src/config/agent-model-resolve.mjs +48 -0
  76. package/src/config/cursor-rules/discover.mjs +3 -21
  77. package/src/config/defaults.mjs +7 -1
  78. package/src/config/settings-fields.mjs +48 -0
  79. package/src/config/spine-init-constants.mjs +1 -0
  80. package/src/config/spine-preflight-lib.mjs +471 -16
  81. package/src/dashboard/lane-throughput.mjs +351 -0
  82. package/src/dashboard/public/dashboard.css +25 -1
  83. package/src/dashboard/public/dashboard.js +223 -18
  84. package/src/dashboard/public/index.html +14 -2
  85. package/src/dashboard/server.mjs +4 -0
  86. package/src/dashboard/snapshot.mjs +215 -1
  87. package/src/dashboard/view.mjs +170 -17
  88. package/src/doctor/agent-model-inherit.mjs +61 -6
  89. package/src/doctor/run-doctor-checks.mjs +26 -1
  90. package/src/doctor/sequence-safety.mjs +57 -0
  91. package/src/doctor/stale-worktrees.mjs +102 -0
  92. package/src/fixtures/scenario-registry.mjs +194 -0
  93. package/src/fs/atomic-write.mjs +49 -0
  94. package/src/planner/file-scope.mjs +246 -0
  95. package/src/planner/format-plan.mjs +9 -7
  96. package/src/planner/index.mjs +6 -2
  97. package/src/planner/wave-scope.mjs +136 -0
  98. package/src/planner/waves.mjs +133 -0
  99. package/src/tasks/packet/index.mjs +1 -0
  100. package/src/tasks/packet/parse-prompt.mjs +42 -1
  101. package/src/tasks/packet/validate-prompt.mjs +124 -0
  102. package/templates/spine-config.json +8 -1
@@ -116,16 +116,18 @@ export function formatPlanHuman(plan) {
116
116
  lines.push("");
117
117
  }
118
118
 
119
- const firstWave = plan.waves?.[0];
120
- if (firstWave?.taskIds?.length) {
121
- lines.push(`Start: spine batch start ${firstWave.taskIds.join(" ")}`);
122
- }
119
+ const waves = plan.waves ?? [];
120
+ const firstWave = waves[0];
121
+ const multiWave = waves.length > 1;
123
122
 
124
- if ((plan.waves?.length ?? 0) > 1) {
123
+ if (multiWave && firstWave != null) {
124
+ lines.push(`Start: spine batch start ${mode} --wave ${firstWave.index}`);
125
125
  lines.push("Then (after each wave lands):");
126
- for (const wave of plan.waves.slice(1)) {
127
- lines.push(` Wave ${wave.index}: spine batch start ${wave.taskIds.join(" ")}`);
126
+ for (const wave of waves.slice(1)) {
127
+ lines.push(` Wave ${wave.index}: spine batch start ${mode} --wave ${wave.index}`);
128
128
  }
129
+ } else if (firstWave?.taskIds?.length) {
130
+ lines.push(`Start: spine batch start ${firstWave.taskIds.join(" ")}`);
129
131
  }
130
132
 
131
133
  return appendBatchSizeGuidanceToPlanOutput(`${lines.join("\n").trimEnd()}\n`, plan);
@@ -15,8 +15,8 @@ import {
15
15
 
16
16
  import { buildGraph, topoWaves } from './graph.mjs';
17
17
  import { findCyclePath } from './cycles.mjs';
18
- import { assignLanesToWaves } from './lanes.mjs';
19
18
  import { parseScope } from './scope.mjs';
19
+ import { formatFileScopeOverlapWarnings, planWaves } from './waves.mjs';
20
20
 
21
21
  /**
22
22
  * @param {{ scope?: any, config: { lanes?: { maxParallel?: number, queueExcess?: boolean } }, tasksRoot: string }} args
@@ -87,13 +87,15 @@ export function buildPlan({ scope, config, tasksRoot }) {
87
87
  const maxParallel = config.lanes?.maxParallel ?? 1;
88
88
  const queueExcess = config.lanes?.queueExcess ?? true;
89
89
 
90
- const wavesWithLanes = assignLanesToWaves({
90
+ const { waves: wavesWithLanes, fileScopeOverlaps } = planWaves({
91
91
  waves,
92
92
  tasksById,
93
93
  maxParallel,
94
94
  queueExcess,
95
95
  });
96
96
 
97
+ const overlapWarnings = formatFileScopeOverlapWarnings(fileScopeOverlaps);
98
+
97
99
  return {
98
100
  generatedAt: new Date().toISOString(),
99
101
  scope: {
@@ -120,6 +122,8 @@ export function buildPlan({ scope, config, tasksRoot }) {
120
122
  ...(scopeResult.mode === 'pending'
121
123
  ? { tasksExcluded: scopeResult.excludedCount ?? 0 }
122
124
  : {}),
125
+ ...(fileScopeOverlaps.length > 0 ? { fileScopeOverlaps } : {}),
123
126
  },
127
+ ...(overlapWarnings.length > 0 ? { overlapWarnings } : {}),
124
128
  };
125
129
  }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Planner wave filtering for batch start (GitHub #54 Tier 1 SP-A).
3
+ */
4
+
5
+ /**
6
+ * @param {string[]} args
7
+ * @returns {{ waveFilter: number|null, error?: string, output?: string }}
8
+ */
9
+ export function parseBatchStartWaveFilter(args) {
10
+ const throughIdx = args.indexOf("--through-wave");
11
+ const waveIdx = args.indexOf("--wave");
12
+
13
+ if (throughIdx >= 0 && waveIdx >= 0) {
14
+ return {
15
+ waveFilter: null,
16
+ error: "conflicting_wave_flags",
17
+ output:
18
+ "Use either --wave N or --through-wave N for batch start, not both.\n",
19
+ };
20
+ }
21
+
22
+ const flagIdx = throughIdx >= 0 ? throughIdx : waveIdx;
23
+ if (flagIdx < 0) {
24
+ return { waveFilter: null };
25
+ }
26
+
27
+ const flagName = throughIdx >= 0 ? "--through-wave" : "--wave";
28
+ const raw = args[flagIdx + 1];
29
+ if (raw == null || raw.startsWith("--")) {
30
+ return {
31
+ waveFilter: null,
32
+ error: "wave_flag_missing_value",
33
+ output: `${flagName} requires a non-negative integer wave index.\n`,
34
+ };
35
+ }
36
+
37
+ const waveIndex = Number(raw);
38
+ if (!Number.isInteger(waveIndex) || waveIndex < 0) {
39
+ return {
40
+ waveFilter: null,
41
+ error: "wave_flag_invalid_value",
42
+ output: `${flagName} requires a non-negative integer wave index (got ${JSON.stringify(raw)}).\n`,
43
+ };
44
+ }
45
+
46
+ return { waveFilter: waveIndex };
47
+ }
48
+
49
+ /**
50
+ * @param {object} plan
51
+ * @param {number} waveIndex
52
+ */
53
+ export function resolveWaveTaskIds(plan, waveIndex) {
54
+ const waves = plan?.waves ?? [];
55
+ if (!Number.isInteger(waveIndex) || waveIndex < 0 || waveIndex >= waves.length) {
56
+ return {
57
+ ok: /** @type {const} */ (false),
58
+ error: "wave_out_of_range",
59
+ waveIndex,
60
+ waveCount: waves.length,
61
+ output: `Wave index ${waveIndex} is out of range (plan has ${waves.length} wave(s)).`,
62
+ };
63
+ }
64
+
65
+ const taskIds = [...(waves[waveIndex]?.taskIds ?? [])];
66
+ if (taskIds.length === 0) {
67
+ return {
68
+ ok: /** @type {const} */ (false),
69
+ error: "wave_empty",
70
+ waveIndex,
71
+ waveCount: waves.length,
72
+ output: `Planner wave ${waveIndex} has no tasks.`,
73
+ };
74
+ }
75
+
76
+ return { ok: /** @type {const} */ (true), waveIndex, taskIds, waveCount: waves.length };
77
+ }
78
+
79
+ /**
80
+ * Restrict a planner plan to a single wave for batch start.
81
+ *
82
+ * @param {object} plan
83
+ * @param {number} waveIndex
84
+ */
85
+ export function filterPlanToWave(plan, waveIndex) {
86
+ const resolved = resolveWaveTaskIds(plan, waveIndex);
87
+ if (!resolved.ok) {
88
+ return resolved;
89
+ }
90
+
91
+ const selectedWave = plan.waves?.[waveIndex];
92
+ if (!selectedWave) {
93
+ return {
94
+ ok: /** @type {const} */ (false),
95
+ error: "wave_missing",
96
+ waveIndex,
97
+ waveCount: resolved.waveCount,
98
+ output: `Planner wave ${waveIndex} is missing from plan.`,
99
+ };
100
+ }
101
+
102
+ /** @type {Record<string, object>} */
103
+ const filteredTasks = {};
104
+ for (const taskId of resolved.taskIds) {
105
+ if (plan.tasks?.[taskId]) {
106
+ filteredTasks[taskId] = plan.tasks[taskId];
107
+ }
108
+ }
109
+
110
+ const filteredWave = {
111
+ ...selectedWave,
112
+ index: 0,
113
+ taskIds: [...resolved.taskIds],
114
+ };
115
+
116
+ return {
117
+ ok: /** @type {const} */ (true),
118
+ waveIndex: resolved.waveIndex,
119
+ taskIds: resolved.taskIds,
120
+ waveCount: resolved.waveCount,
121
+ plan: {
122
+ ...plan,
123
+ scope: {
124
+ ...plan.scope,
125
+ taskIds: [...resolved.taskIds],
126
+ },
127
+ waves: [filteredWave],
128
+ tasks: filteredTasks,
129
+ metadata: {
130
+ ...plan.metadata,
131
+ tasksSelected: resolved.taskIds.length,
132
+ waveFilter: resolved.waveIndex,
133
+ },
134
+ },
135
+ };
136
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Wave planning with file-scope overlap detection and lane serialization (SP-353 / issue #31).
3
+ */
4
+
5
+ import { fileScopesOverlap, findWaveFileScopeOverlaps } from './file-scope.mjs';
6
+
7
+ /**
8
+ * @param {string[]} taskScope
9
+ * @param {string[][]} laneTaskScopes
10
+ * @returns {boolean}
11
+ */
12
+ function taskOverlapsLane(taskScope, laneTaskScopes) {
13
+ for (const laneScope of laneTaskScopes) {
14
+ if (fileScopesOverlap(taskScope, laneScope)) return true;
15
+ }
16
+ return false;
17
+ }
18
+
19
+ /**
20
+ * Greedy lane packing using glob-aware overlap checks from file-scope.mjs.
21
+ *
22
+ * @param {{ waves: string[][], tasksById: Record<string, { fileScope?: string[] }>, maxParallel: number, queueExcess?: boolean }} args
23
+ * @returns {Array<{ index: number, taskIds: string[], virtualLaneCount: number, ticks: Array<{ index: number, lanes: string[][] }>, laneAssignments: Record<string, { virtualLane: number, tick: number, laneInTick: number }> }>}
24
+ */
25
+ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess = true }) {
26
+ const planned = [];
27
+
28
+ for (let waveIndex = 0; waveIndex < waves.length; waveIndex++) {
29
+ const waveTaskIds = waves[waveIndex];
30
+
31
+ /** @type {{ taskScopes: string[][] }} */
32
+ const virtualLanes = [];
33
+
34
+ /** @type {Record<string, { virtualLane: number, tick: number, laneInTick: number }>} */
35
+ const laneAssignments = {};
36
+
37
+ const virtualLaneForTask = {};
38
+
39
+ for (const taskId of waveTaskIds) {
40
+ const task = tasksById[taskId];
41
+ if (!task) {
42
+ throw new Error(`Missing task packet for ${taskId} during lane assignment`);
43
+ }
44
+
45
+ const taskScope = Array.isArray(task.fileScope) ? task.fileScope : [];
46
+
47
+ let placed = false;
48
+ for (let i = 0; i < virtualLanes.length; i++) {
49
+ const lane = virtualLanes[i];
50
+ if (taskOverlapsLane(taskScope, lane.taskScopes)) {
51
+ virtualLaneForTask[taskId] = i;
52
+ lane.taskScopes.push(taskScope);
53
+ placed = true;
54
+ break;
55
+ }
56
+ }
57
+
58
+ if (!placed) {
59
+ const i = virtualLanes.length;
60
+ virtualLanes.push({ taskScopes: [taskScope] });
61
+ virtualLaneForTask[taskId] = i;
62
+ }
63
+ }
64
+
65
+ const virtualLaneCount = virtualLanes.length;
66
+ const tickCount = queueExcess ? Math.ceil(virtualLaneCount / maxParallel) : 1;
67
+
68
+ const ticks = Array.from({ length: tickCount }, (_, t) => {
69
+ return {
70
+ index: t,
71
+ lanes: Array.from({ length: maxParallel }, () => []),
72
+ };
73
+ });
74
+
75
+ for (const taskId of waveTaskIds) {
76
+ const virtualLane = virtualLaneForTask[taskId];
77
+ const tick = queueExcess ? Math.floor(virtualLane / maxParallel) : 0;
78
+ const laneInTick = virtualLane % maxParallel;
79
+ laneAssignments[taskId] = { virtualLane, tick, laneInTick };
80
+ ticks[tick].lanes[laneInTick].push(taskId);
81
+ }
82
+
83
+ planned.push({
84
+ index: waveIndex,
85
+ taskIds: waveTaskIds,
86
+ virtualLaneCount,
87
+ ticks,
88
+ laneAssignments,
89
+ });
90
+ }
91
+
92
+ return planned;
93
+ }
94
+
95
+ /**
96
+ * @typedef {import('./file-scope.mjs').FileScopeOverlapPair} FileScopeOverlapPair
97
+ */
98
+
99
+ /**
100
+ * Detect same-wave file-scope overlaps and assign lanes that serialize conflicts.
101
+ *
102
+ * @param {{ waves: string[][], tasksById: Record<string, { fileScope?: string[] }>, maxParallel: number, queueExcess?: boolean }} args
103
+ * @returns {{ waves: ReturnType<typeof assignLanesToWaves>, fileScopeOverlaps: FileScopeOverlapPair[] }}
104
+ */
105
+ export function planWaves({ waves, tasksById, maxParallel, queueExcess = true }) {
106
+ const fileScopeOverlaps = findWaveFileScopeOverlaps(waves, tasksById);
107
+ const wavesWithLanes = assignLanesToWaves({
108
+ waves,
109
+ tasksById,
110
+ maxParallel,
111
+ queueExcess,
112
+ });
113
+
114
+ return { waves: wavesWithLanes, fileScopeOverlaps };
115
+ }
116
+
117
+ /**
118
+ * Human-readable overlap report lines for plan output consumers.
119
+ *
120
+ * @param {FileScopeOverlapPair[]} overlaps
121
+ * @returns {string[]}
122
+ */
123
+ export function formatFileScopeOverlapWarnings(overlaps) {
124
+ if (!Array.isArray(overlaps) || overlaps.length === 0) {
125
+ return [];
126
+ }
127
+
128
+ const lines = ['File scope overlaps (tasks serialized to the same lane):'];
129
+ for (const overlap of overlaps) {
130
+ lines.push(` Wave ${overlap.waveIndex}: ${overlap.taskA} ↔ ${overlap.taskB}`);
131
+ }
132
+ return lines;
133
+ }
@@ -46,6 +46,7 @@ export { mergeDeps, mergeTaskDeps, loadDependenciesJson } from "./merge-deps.mjs
46
46
  export {
47
47
  assertValidTaskPacket,
48
48
  collectPromptValidationFailure,
49
+ collectStaleFileScopeMustChangeWarnings,
49
50
  formatPromptValidationFailures,
50
51
  validatePrompt,
51
52
  } from "./validate-prompt.mjs";
@@ -23,6 +23,8 @@ export const CONTRACT_FIELD_NAMES = Object.freeze([
23
23
  "fileScopeMustNotChange",
24
24
  "minLineCoverage",
25
25
  "artifactsMustExist",
26
+ "stallTimeoutMinutes",
27
+ "extendGraceOnFileScope",
26
28
  ]);
27
29
 
28
30
  const CONTRACT_KNOWN_FIELDS = new Set(CONTRACT_FIELD_NAMES);
@@ -32,7 +34,15 @@ const CONTRACT_TABLE_ROW_RE = /^\|\s*([^|]+?)\s*\|\s*([^|]+?)\s*\|$/;
32
34
  const TEST_COMMAND_MAX_LENGTH = 500;
33
35
  export const SEE_FILE_SCOPE_RE = /^see\s+file\s+scope$/i;
34
36
  const CONTRACT_EM_DASH_PLACEHOLDER_RE = /^[—\-]$/;
35
- const CONTRACT_NONE_VALUES = new Set(["—", "-", "none", "n/a", "na"]);
37
+ const CONTRACT_NONE_VALUES = new Set([
38
+ "—",
39
+ "-",
40
+ "none",
41
+ "n/a",
42
+ "na",
43
+ "(none beyond tests)",
44
+ "none beyond tests",
45
+ ]);
36
46
 
37
47
  /**
38
48
  * @param {string} markdown PROMPT.md contents
@@ -113,6 +123,8 @@ export function validatePrompt(markdown) {
113
123
  * fileScopeMustNotChange: string[],
114
124
  * minLineCoverage: number | null,
115
125
  * artifactsMustExist: string[],
126
+ * stallTimeoutMinutes: number | null,
127
+ * extendGraceOnFileScope: boolean | null,
116
128
  * rawTableValid: boolean,
117
129
  * errors: string[],
118
130
  * unknownFields: string[],
@@ -133,6 +145,8 @@ export function parseContract(markdown) {
133
145
  fileScopeMustNotChange: [],
134
146
  minLineCoverage: null,
135
147
  artifactsMustExist: [],
148
+ stallTimeoutMinutes: null,
149
+ extendGraceOnFileScope: null,
136
150
  rawTableValid: false,
137
151
  errors: [],
138
152
  unknownFields: [],
@@ -276,6 +290,33 @@ function applyContractField(parsed, field, rawValue) {
276
290
  parsed.minLineCoverage = numeric;
277
291
  return;
278
292
  }
293
+ case "stallTimeoutMinutes": {
294
+ const minutes = parseContractScalar(value);
295
+ if (!/^\d+(\.\d+)?$/.test(minutes)) {
296
+ parsed.errors.push("Contract stallTimeoutMinutes must be a positive number");
297
+ return;
298
+ }
299
+ const numeric = Number(minutes);
300
+ if (numeric <= 0) {
301
+ parsed.errors.push("Contract stallTimeoutMinutes must be a positive number");
302
+ return;
303
+ }
304
+ parsed.stallTimeoutMinutes = numeric;
305
+ return;
306
+ }
307
+ case "extendGraceOnFileScope": {
308
+ const flag = parseContractScalar(value).toLowerCase();
309
+ if (flag === "true") {
310
+ parsed.extendGraceOnFileScope = true;
311
+ return;
312
+ }
313
+ if (flag === "false") {
314
+ parsed.extendGraceOnFileScope = false;
315
+ return;
316
+ }
317
+ parsed.errors.push("Contract extendGraceOnFileScope must be true or false");
318
+ return;
319
+ }
279
320
  default:
280
321
  return;
281
322
  }
@@ -2,6 +2,9 @@
2
2
  * Shared fail-loud PROMPT validation helpers (planner, preflight, rules CLI, batch engine).
3
3
  */
4
4
 
5
+ import { execFileSync } from "node:child_process";
6
+
7
+ import { matchesContractPattern } from "../../batch/contract-verify.mjs";
5
8
  import { CONTRACT_DEFAULTS } from "../../config/defaults.mjs";
6
9
  import {
7
10
  parseContract,
@@ -10,6 +13,10 @@ import {
10
13
  } from "./parse-prompt.mjs";
11
14
  import { validateContract } from "./validate-contract.mjs";
12
15
 
16
+ /** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
17
+ export const STALE_FILE_SCOPE_AMENDMENT_HINT =
18
+ "Amend PROMPT.md ## Contract before batch start (e.g. point fileScopeMustChange at delivery artifacts such as STATUS.md, or add an ## Amendments note documenting pre-landed implementation)";
19
+
13
20
  /**
14
21
  * Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
15
22
  *
@@ -97,3 +104,120 @@ export function assertValidTaskPacket(packet, taskId) {
97
104
  function formatErrorLines(errors) {
98
105
  return errors.map((error) => ` - ${error}`).join("\n");
99
106
  }
107
+
108
+ /**
109
+ * @param {string} projectRoot
110
+ * @param {string} relPath
111
+ */
112
+ function gitFirstCommitTouchingPath(projectRoot, relPath) {
113
+ try {
114
+ const output = execFileSync("git", ["log", "--reverse", "--format=%H", "--", relPath], {
115
+ cwd: projectRoot,
116
+ encoding: "utf-8",
117
+ stdio: ["ignore", "pipe", "pipe"],
118
+ timeout: 10_000,
119
+ }).trim();
120
+ return output.split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? null;
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @param {string} projectRoot
128
+ * @param {string} [baseRef]
129
+ */
130
+ function resolveComparisonBaseRef(projectRoot, baseRef = "main") {
131
+ try {
132
+ execFileSync("git", ["rev-parse", "--verify", baseRef], {
133
+ cwd: projectRoot,
134
+ stdio: "ignore",
135
+ timeout: 5000,
136
+ });
137
+ return baseRef;
138
+ } catch {
139
+ return "HEAD";
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @param {string} projectRoot
145
+ * @param {string} sinceCommit
146
+ * @param {string} baseRef
147
+ * @param {string} pattern
148
+ */
149
+ function listPathsChangedSinceCommit(projectRoot, sinceCommit, baseRef, pattern) {
150
+ try {
151
+ const output = execFileSync(
152
+ "git",
153
+ ["diff", "--name-only", `${sinceCommit}..${baseRef}`, "--", pattern],
154
+ {
155
+ cwd: projectRoot,
156
+ encoding: "utf-8",
157
+ stdio: ["ignore", "pipe", "pipe"],
158
+ timeout: 10_000,
159
+ },
160
+ );
161
+ return output
162
+ .split(/\r?\n/)
163
+ .map((line) => line.trim())
164
+ .filter(Boolean);
165
+ } catch {
166
+ return [];
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Warn when fileScopeMustChange paths were already modified on main after the task PROMPT was introduced.
172
+ *
173
+ * @param {string} projectRoot
174
+ * @param {ReturnType<typeof parseContract>} parsedContract
175
+ * @param {string} promptRelPath Path to PROMPT.md relative to projectRoot
176
+ * @param {{ baseRef?: string }} [options]
177
+ * @returns {string[]}
178
+ */
179
+ export function collectStaleFileScopeMustChangeWarnings(
180
+ projectRoot,
181
+ parsedContract,
182
+ promptRelPath,
183
+ options = {},
184
+ ) {
185
+ const patterns = parsedContract?.fileScopeMustChange ?? [];
186
+ if (patterns.length === 0) {
187
+ return [];
188
+ }
189
+
190
+ const introCommit = gitFirstCommitTouchingPath(projectRoot, promptRelPath);
191
+ if (!introCommit) {
192
+ return [];
193
+ }
194
+
195
+ const baseRef = resolveComparisonBaseRef(projectRoot, options.baseRef ?? "main");
196
+ /** @type {string[]} */
197
+ const stalePatterns = [];
198
+
199
+ for (const pattern of patterns) {
200
+ const changedPaths = listPathsChangedSinceCommit(
201
+ projectRoot,
202
+ introCommit,
203
+ baseRef,
204
+ pattern,
205
+ );
206
+ const matching = changedPaths.filter((filePath) =>
207
+ matchesContractPattern(filePath, pattern),
208
+ );
209
+ if (matching.length > 0) {
210
+ stalePatterns.push(pattern);
211
+ }
212
+ }
213
+
214
+ if (stalePatterns.length === 0) {
215
+ return [];
216
+ }
217
+
218
+ const preview = stalePatterns.slice(0, 5).join(", ");
219
+ const suffix = stalePatterns.length > 5 ? ` (+${stalePatterns.length - 5} more)` : "";
220
+ return [
221
+ `Contract fileScopeMustChange path(s) (${preview}${suffix}) already changed on ${baseRef} since task was added — implementation may be pre-landed and will not diff in a new lane. ${STALE_FILE_SCOPE_AMENDMENT_HINT}`,
222
+ ];
223
+ }
@@ -15,7 +15,11 @@
15
15
  },
16
16
  "agents": {
17
17
  "worker": { "model": "cursor/auto", "thinking": "high" },
18
- "reviewer": { "model": "cursor/auto", "thinking": "medium" },
18
+ "reviewer": {
19
+ "model": "cursor/auto",
20
+ "thinking": "medium",
21
+ "plan": { "model": "google/gemini-flash-latest", "thinking": "low" }
22
+ },
19
23
  "supervisor": { "model": "inherit", "thinking": "off" }
20
24
  },
21
25
  "lanes": {
@@ -25,9 +29,12 @@
25
29
  "workerOutputMaxBytes": 262144,
26
30
  "workerOutputTailLines": 200,
27
31
  "retainWorkerOutputOnSuccess": false,
32
+ "streamWorkerOutputLive": false,
33
+ "workerLiveLogMaxBytes": 262144,
28
34
  "stallTimeoutMinutes": 120,
29
35
  "stallGraceAfterProgressMinutes": 30,
30
36
  "heartbeatIntervalMinutes": 10,
37
+ "progressSnapshotIntervalMinutes": 2,
31
38
  "checkpointWarningMinutes": 10,
32
39
  "extendGraceOnFileScope": false,
33
40
  "autoCommitOnStall": false