pi-spine 1.7.0 → 1.8.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 (125) hide show
  1. package/package.json +2 -2
  2. package/skills/spine-autonomous-operator/SKILL.md +264 -0
  3. package/skills/spine-autonomous-operator/references/issue-template.md +45 -0
  4. package/skills/spine-orchestrate-waves/SKILL.md +1 -0
  5. package/skills/spine-release-operator/SKILL.md +44 -8
  6. package/skills/spine-release-operator/references/pi-async-orchestration.md +88 -0
  7. package/skills/spine-release-operator/scripts/collect-release-intake.sh +71 -0
  8. package/src/batch/abort.mjs +1 -0
  9. package/src/batch/agent-session-worker.mjs +1 -0
  10. package/src/batch/attached-engine-handoff.mjs +1 -0
  11. package/src/batch/attached-runner.mjs +1 -0
  12. package/src/batch/contract-prelanded.mjs +1 -0
  13. package/src/batch/contract-task-start.mjs +1 -0
  14. package/src/batch/contract-verify.mjs +1 -0
  15. package/src/batch/detached-start.mjs +1 -0
  16. package/src/batch/diagnosis-launch-failure.mjs +1 -0
  17. package/src/batch/diagnosis-merge-failure.mjs +1 -0
  18. package/src/batch/diagnosis-retry-limbo.mjs +1 -0
  19. package/src/batch/diagnosis-tail-state.mjs +1 -0
  20. package/src/batch/diagnosis-task-done.mjs +1 -0
  21. package/src/batch/diagnosis-worker-done-missing.mjs +1 -0
  22. package/src/batch/diagnosis.mjs +1 -0
  23. package/src/batch/engine-lanes/commit.mjs +1 -0
  24. package/src/batch/engine-lanes/merge.mjs +1 -0
  25. package/src/batch/engine-lanes/queue.mjs +1 -0
  26. package/src/batch/engine-lanes/review.mjs +1 -0
  27. package/src/batch/engine-lanes.mjs +1 -0
  28. package/src/batch/engine-scope.mjs +1 -0
  29. package/src/batch/engine.mjs +19 -9
  30. package/src/batch/evidence.mjs +1 -0
  31. package/src/batch/gate-evidence-collect.mjs +1 -0
  32. package/src/batch/gate-evidence-read.mjs +1 -0
  33. package/src/batch/gate.mjs +1 -0
  34. package/src/batch/git-helpers.mjs +1 -1
  35. package/src/batch/heartbeat-git-debounce.mjs +83 -0
  36. package/src/batch/heartbeat.mjs +17 -20
  37. package/src/batch/integrate-worktree.mjs +1 -0
  38. package/src/batch/integrate.mjs +1 -0
  39. package/src/batch/journal-rebuild.mjs +1 -0
  40. package/src/batch/journal.mjs +2 -1
  41. package/src/batch/lane-commit.mjs +1 -0
  42. package/src/batch/lane-dirty-check.mjs +1 -0
  43. package/src/batch/lifecycle.mjs +1 -0
  44. package/src/batch/limbo-detect.mjs +1 -0
  45. package/src/batch/macro-phase.mjs +1 -0
  46. package/src/batch/merge/adoption-doc-merge.mjs +1 -0
  47. package/src/batch/merge/wave-merge-state.mjs +1 -0
  48. package/src/batch/metrics.mjs +1 -0
  49. package/src/batch/orphan-detect.mjs +1 -0
  50. package/src/batch/pause.mjs +1 -0
  51. package/src/batch/post-merge-limbo.mjs +1 -0
  52. package/src/batch/postmortem.mjs +1 -0
  53. package/src/batch/readers/spine-state.mjs +1 -0
  54. package/src/batch/readers/taskplane-state.mjs +1 -0
  55. package/src/batch/reconcile.mjs +84 -8
  56. package/src/batch/resume-common.mjs +1 -0
  57. package/src/batch/resume-engine.mjs +1 -0
  58. package/src/batch/resume-multi-lanes.mjs +1 -0
  59. package/src/batch/resume-multi-validate.mjs +1 -0
  60. package/src/batch/resume-multi.mjs +1 -0
  61. package/src/batch/resume-validation.mjs +1 -0
  62. package/src/batch/resume.mjs +1 -0
  63. package/src/batch/retry.mjs +1 -0
  64. package/src/batch/review-shared.mjs +1 -0
  65. package/src/batch/review-spawn.mjs +1 -0
  66. package/src/batch/review.mjs +1 -0
  67. package/src/batch/rules-manifest-drift.mjs +1 -0
  68. package/src/batch/salvage.mjs +1 -0
  69. package/src/batch/sequence.mjs +5 -2
  70. package/src/batch/state.mjs +1 -0
  71. package/src/batch/supervisor-spawn.mjs +1 -0
  72. package/src/batch/task-stall-budget.mjs +3 -4
  73. package/src/batch/worker-host.mjs +31 -25
  74. package/src/batch/worker-output.mjs +1 -0
  75. package/src/batch/worker-prompt.mjs +1 -0
  76. package/src/cli/journal-follow.mjs +1 -1
  77. package/src/config/agent-model-resolve.mjs +1 -0
  78. package/src/config/contract.mjs +1 -0
  79. package/src/config/cursor-rules/discover.mjs +1 -0
  80. package/src/config/cursor-rules/match-globs.mjs +1 -0
  81. package/src/config/cursor-rules/parse-frontmatter.mjs +1 -0
  82. package/src/config/cursor-rules/profile.mjs +1 -0
  83. package/src/config/cursor-rules/select.mjs +1 -0
  84. package/src/config/env-overrides.mjs +1 -0
  85. package/src/config/pi-spine-root.mjs +1 -0
  86. package/src/config/preflight/discovery.mjs +333 -0
  87. package/src/config/preflight/git-batch.mjs +320 -0
  88. package/src/config/preflight/integrate-plan.mjs +460 -0
  89. package/src/config/reviewer-context.mjs +1 -0
  90. package/src/config/settings-fields.mjs +1 -0
  91. package/src/config/spine-config-schema.mjs +1 -0
  92. package/src/config/spine-init-constants.mjs +1 -0
  93. package/src/config/spine-preflight-lib.mjs +54 -1013
  94. package/src/config/worker-backend.mjs +1 -0
  95. package/src/config/worker-context.mjs +1 -0
  96. package/src/config/worker-launch-script.mjs +1 -0
  97. package/src/config/worktree-setup-hook.mjs +1 -0
  98. package/src/dashboard/public/dashboard.js +6 -1
  99. package/src/dashboard/running-tail-state.mjs +1 -0
  100. package/src/dashboard/server.mjs +136 -16
  101. package/src/dashboard/snapshot-lanes.mjs +479 -0
  102. package/src/dashboard/snapshot-waves.mjs +272 -0
  103. package/src/dashboard/snapshot.mjs +41 -862
  104. package/src/doctor/agent-model-inherit.mjs +1 -0
  105. package/src/doctor/agent-models.mjs +1 -0
  106. package/src/doctor/coexistence.mjs +1 -0
  107. package/src/doctor/run-doctor-checks.mjs +1 -0
  108. package/src/doctor/stale-path.mjs +1 -0
  109. package/src/doctor/stall-config.mjs +1 -0
  110. package/src/doctor/suggest-max-parallel.mjs +1 -0
  111. package/src/doctor/task-packet-size.mjs +3 -10
  112. package/src/doctor/worktree-health.mjs +1 -0
  113. package/src/planner/cycles.mjs +1 -0
  114. package/src/planner/file-scope.mjs +1 -0
  115. package/src/planner/format-plan.mjs +1 -0
  116. package/src/planner/graph.mjs +1 -0
  117. package/src/planner/scope.mjs +1 -0
  118. package/src/planner/wave-scope.mjs +1 -0
  119. package/src/planner/waves.mjs +1 -0
  120. package/src/tasks/packet/merge-deps.mjs +1 -0
  121. package/src/tasks/packet/parse-prompt.mjs +4 -3
  122. package/src/tasks/packet/parse-status.mjs +1 -0
  123. package/src/tasks/packet/size-line.mjs +12 -0
  124. package/src/tasks/packet/validate-contract.mjs +1 -0
  125. package/src/tasks/packet/validate-prompt.mjs +1 -0
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Running diagnosis headlines when batch phase is active but no workers are scheduled (GitHub #68).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Per-task done-marker semantics for reconcile / status JSON (SP-344 / GitHub #35).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Worker exited without `.DONE` diagnosis helpers (SP-313 / issue #18).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * FR-BATCH-13 diagnosis taxonomy and operator messaging (§18.3).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Lane commit and post-commit dirty validation (SP-427 / #73).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Engine lane merge-phase wiring — lane→orch merges and rules-manifest conflict resolution.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Lane queue and provisioning — build lane/task state from plan and handle
3
4
  * per-lane task prep (file scope) plus skip-when-done-on-disk queue behavior.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Engine lane review-phase wiring — code/final review loops after worker success.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Lane task execution facade — re-exports split modules and phase transitions.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch scope resolution and wave merge policy (extracted from engine.mjs).
3
4
  */
@@ -72,6 +72,16 @@ export {
72
72
  } from "./engine-scope.mjs";
73
73
  export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
74
74
 
75
+ /**
76
+ * Mutable batch-state fields are widened from createInitialBatchState literals so
77
+ * terminal transitions can assign endedAt/lastError without any casts.
78
+ *
79
+ * @typedef {Omit<ReturnType<typeof createInitialBatchState>, "endedAt" | "lastError"> & {
80
+ * endedAt: number | null;
81
+ * lastError: string | null;
82
+ * }} SpineBatchState
83
+ */
84
+
75
85
  const WORKTREE_SPINE_PATTERN = /[/\\]\.worktrees[/\\]spine-/;
76
86
 
77
87
  /**
@@ -149,7 +159,7 @@ export async function startBatch({
149
159
  ok: false,
150
160
  exitCode: preflight.exitCode ?? 1,
151
161
  error: "preflight_failed",
152
- output: /** @type {string | undefined} */ (/** @type {any} */ (preflight).output),
162
+ output: /** @type {{ output?: string }} */ (preflight).output,
153
163
  };
154
164
  }
155
165
  }
@@ -241,8 +251,8 @@ export async function startBatch({
241
251
  maxLaneNumber,
242
252
  });
243
253
 
244
- /** @type {ReturnType<typeof createInitialBatchState>} */
245
- let state = createInitialBatchState({
254
+ /** @type {SpineBatchState} */
255
+ const state = createInitialBatchState({
246
256
  batchId,
247
257
  baseBranch,
248
258
  orchBranch,
@@ -425,8 +435,8 @@ export async function startBatch({
425
435
 
426
436
  if (batchAborted) {
427
437
  const abortedTask = state.tasks.find((/** @type {{ status: string }} */ task) => task.status === "aborted");
428
- /** @type {any} */ (state).endedAt = Date.now();
429
- /** @type {any} */ (state).lastError = "batch aborted";
438
+ state.endedAt = Date.now();
439
+ state.lastError = "batch aborted";
430
440
  transitionPhase(state, "aborted", {
431
441
  projectRoot,
432
442
  batchId,
@@ -444,8 +454,8 @@ export async function startBatch({
444
454
 
445
455
  const mergeEligibility = assessWaveMergeEligibility(state, wave.index);
446
456
  if (!mergeEligibility.ok) {
447
- /** @type {any} */ (state).endedAt = Date.now();
448
- /** @type {any} */ (state).lastError = mergeEligibility.message?.slice(0, 500) ?? "mixed_outcome";
457
+ state.endedAt = Date.now();
458
+ state.lastError = mergeEligibility.message?.slice(0, 500) ?? "mixed_outcome";
449
459
  transitionPhase(state, "failed", {
450
460
  projectRoot,
451
461
  batchId,
@@ -531,8 +541,8 @@ export async function startBatch({
531
541
  });
532
542
  } catch (err) {
533
543
  const message = err instanceof Error ? err.message : String(err);
534
- /** @type {any} */ (state).endedAt = Date.now();
535
- /** @type {any} */ (state).lastError = message;
544
+ state.endedAt = Date.now();
545
+ state.lastError = message;
536
546
  transitionPhase(state, "failed", {
537
547
  projectRoot,
538
548
  batchId,
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Integrate gate evidence bundle (PRD §12.2, FR-GATE).
3
4
  * Collection orchestration lives in gate.mjs; path readers in gate-evidence-read.mjs (SP-432 / #83-D).
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Integrate gate evidence collection (SP-432 / #83-D).
3
4
  * Split from gate.mjs to keep gate FSM under phase-23 LOC policy.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Gate and evidence path readers — leaf module (SP-432 / #83-D).
3
4
  * No imports from evidence, gate, reconcile, or postmortem.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Integrate gate FSM and persistence (PRD §12, FR-GATE, FR-INT-02).
3
4
  */
@@ -17,7 +17,7 @@ export function filterGitignoredPaths(projectRoot, paths) {
17
17
  }
18
18
 
19
19
  /** @type {Set<string>} */
20
- let ignoredSet = new Set();
20
+ const ignoredSet = new Set();
21
21
  try {
22
22
  const output = execFileSync("git", ["check-ignore", "--no-index", "--stdin"], {
23
23
  cwd: projectRoot,
@@ -0,0 +1,83 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Git porcelain debounce for lane heartbeat progress signals (issue #98 P1).
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+
9
+ /**
10
+ * Per-lane file-scope mtime snapshot; reused when mtimes are unchanged.
11
+ * @type {Map<string, { fileScopeMtimeMs: number | null, dirtyPaths: string[] }>}
12
+ */
13
+ const _gitPorcelainDebounceByLane = new Map();
14
+
15
+ let _gitPorcelainCallCount = 0;
16
+
17
+ /**
18
+ * @param {string} worktreePath
19
+ * @param {string[]} [fileScopePaths]
20
+ */
21
+ function gitPorcelainDebounceKey(worktreePath, fileScopePaths) {
22
+ const scopeKey = Array.isArray(fileScopePaths) ? fileScopePaths.join("\0") : "";
23
+ return `${worktreePath}\0${scopeKey}`;
24
+ }
25
+
26
+ /** Clear git porcelain debounce cache. Useful for test isolation. */
27
+ export function clearGitPorcelainDebounceCache() {
28
+ _gitPorcelainDebounceByLane.clear();
29
+ }
30
+
31
+ /** Reset git porcelain invocation counter (tests only). */
32
+ export function resetGitPorcelainCallCount() {
33
+ _gitPorcelainCallCount = 0;
34
+ }
35
+
36
+ /** @returns {number} git status --porcelain invocations since last reset. */
37
+ export function getGitPorcelainCallCount() {
38
+ return _gitPorcelainCallCount;
39
+ }
40
+
41
+ /**
42
+ * Max mtime among existing file-scope paths (FR-WORK-10 activity signal).
43
+ * @param {string} worktreePath
44
+ * @param {string[]} [fileScopePaths]
45
+ */
46
+ export function resolveFileScopeMtimeMs(worktreePath, fileScopePaths) {
47
+ if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return null;
48
+ let max = null;
49
+ for (const rel of fileScopePaths) {
50
+ if (!rel || typeof rel !== "string") continue;
51
+ const target = path.join(worktreePath, rel);
52
+ if (!fs.existsSync(target)) continue;
53
+ const stat = fs.statSync(target);
54
+ if (!stat.isFile()) continue;
55
+ max = max === null ? stat.mtimeMs : Math.max(max, stat.mtimeMs);
56
+ }
57
+ return max;
58
+ }
59
+
60
+ /**
61
+ * Debounced wrapper around fresh scoped porcelain resolution.
62
+ * @param {string} worktreePath
63
+ * @param {string[]} [fileScopePaths]
64
+ * @param {string} [taskFolder]
65
+ * @param {(worktreePath: string, fileScopePaths?: string[], taskFolder?: string) => string[]} resolveFresh
66
+ */
67
+ export function resolveDebouncedScopedDirtyPaths(
68
+ worktreePath,
69
+ fileScopePaths,
70
+ taskFolder,
71
+ resolveFresh,
72
+ ) {
73
+ const fileScopeMtimeMs = resolveFileScopeMtimeMs(worktreePath, fileScopePaths);
74
+ const debounceKey = gitPorcelainDebounceKey(worktreePath, fileScopePaths);
75
+ const debounced = _gitPorcelainDebounceByLane.get(debounceKey);
76
+ if (debounced && debounced.fileScopeMtimeMs === fileScopeMtimeMs) {
77
+ return debounced.dirtyPaths;
78
+ }
79
+ _gitPorcelainCallCount += 1;
80
+ const dirtyPaths = resolveFresh(worktreePath, fileScopePaths, taskFolder);
81
+ _gitPorcelainDebounceByLane.set(debounceKey, { fileScopeMtimeMs, dirtyPaths });
82
+ return dirtyPaths;
83
+ }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Lane heartbeat and progress-aware stall helpers (FR-WORK-09, PRD §18.4, FR-STALL-02).
3
4
  */
@@ -6,6 +7,16 @@ import fs from "node:fs";
6
7
  import path from "node:path";
7
8
  import { execFileSync } from "node:child_process";
8
9
  import { appendJournalEvent, readJournalEventsCached } from "./journal.mjs";
10
+ import {
11
+ resolveDebouncedScopedDirtyPaths,
12
+ resolveFileScopeMtimeMs,
13
+ } from "./heartbeat-git-debounce.mjs";
14
+
15
+ export {
16
+ clearGitPorcelainDebounceCache,
17
+ getGitPorcelainCallCount,
18
+ resetGitPorcelainCallCount,
19
+ } from "./heartbeat-git-debounce.mjs";
9
20
 
10
21
  const DEFAULT_STALL_TIMEOUT_MIN = 60;
11
22
  const DEFAULT_GRACE_AFTER_PROGRESS_MIN = 15;
@@ -76,25 +87,6 @@ function git(worktreePath, args) {
76
87
  }
77
88
  }
78
89
 
79
- /**
80
- * Max mtime among existing file-scope paths (FR-WORK-10 activity signal; warning only by default).
81
- * @param {string} worktreePath
82
- * @param {string[]} [fileScopePaths]
83
- */
84
- function resolveFileScopeMtimeMs(worktreePath, fileScopePaths) {
85
- if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return null;
86
- let max = null;
87
- for (const rel of fileScopePaths) {
88
- if (!rel || typeof rel !== "string") continue;
89
- const target = path.join(worktreePath, rel);
90
- if (!fs.existsSync(target)) continue;
91
- const stat = fs.statSync(target);
92
- if (!stat.isFile()) continue;
93
- max = max === null ? stat.mtimeMs : Math.max(max, stat.mtimeMs);
94
- }
95
- return max;
96
- }
97
-
98
90
  /**
99
91
  * Scoped git porcelain paths under File Scope or the task folder (FR-STALL-02 activity).
100
92
  * @param {string} worktreePath
@@ -196,7 +188,12 @@ export function collectProgressSignals({
196
188
  }
197
189
 
198
190
  const fileScopeMtimeMs = resolveFileScopeMtimeMs(worktreePath, fileScopePaths);
199
- const dirtyPaths = resolveScopedDirtyPaths(worktreePath, fileScopePaths, taskFolder);
191
+ const dirtyPaths = resolveDebouncedScopedDirtyPaths(
192
+ worktreePath,
193
+ fileScopePaths,
194
+ taskFolder,
195
+ resolveScopedDirtyPaths,
196
+ );
200
197
 
201
198
  let stepCompletedAtMs = null;
202
199
  if (journalContext?.projectRoot && journalContext?.batchId) {
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Isolated orch→base integrate (FR-WT-08 / #91 slice 1).
3
4
  * Never checks out baseBranch in the human projectRoot worktree.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Orch → base integration (FR-INT-01–05, TP-016).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Rebuild batch task/segment status from append-only journal (FR-REL-01/02, PRD §11.4).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Append-only orchestration journal (FR-JRN, PRD §11).
3
4
  */
@@ -83,7 +84,7 @@ export function redactSecrets(value) {
83
84
  * @param {Record<string, unknown>} payload
84
85
  */
85
86
  export function capPayloadSize(payload) {
86
- let serialized = JSON.stringify(payload);
87
+ const serialized = JSON.stringify(payload);
87
88
  if (Buffer.byteLength(serialized, "utf-8") <= MAX_PAYLOAD_BYTES) {
88
89
  return payload;
89
90
  }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Auto-commit lane worktree before merge (TP-015, FR-WORK-02/03).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Post-lane-commit dirty worktree hygiene (SP-427 / #73).
3
4
  * Coverage artifacts regenerated by npm test are ephemeral when not in task file scope.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch lifecycle: dismiss, complete, archive-first (FR-BATCH-15/16, §18.6).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Post-merge limbo predicates — pure state readers (leaf module, SP-424 / #83-A).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch macro-phase derivation (Phase 41 — operator lifecycle label).
3
4
  *
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Safe auto-merge for additive conflicts in docs/adoption/* during lane→orch wave merge.
3
4
  * @see GitHub #14 — serial README wave tasks overlapping operator-runbook.md
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Wave merge bookkeeping — detect waves missing mergeResults entries.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Append-only run-metrics.jsonl writer (handoff §6.5, SP-158).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Orphan running batch detection (SP-082, FR-BATCH-12 extension).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch pause CLI with attached-engine confirmation (SP-376, GitHub #57).
3
4
  * Engine pause propagation helpers (SP-375).
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Post-merge limbo detection — merges done, tasks succeeded, phase still running (SP-204).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Honest batch post-mortem (NFR-OBS-03, GAP-POST-01).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Parse pi-spine batch-state.json (schema v1, tolerant reader).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Parse Taskplane `.pi/batch-state.json` for dogfood reconciliation.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch reconciliation (FR-BATCH-12, §17.5).
3
4
  */
@@ -56,6 +57,53 @@ export { loadBatchStateFile, parseBatchState, resolveBatchStatePath } from "./ba
56
57
  const LIMBO_PHASES = new Set(["stopped", "failed", "executing"]);
57
58
  const RUNNING_PHASES = new Set(["planning", "running", "executing", "merging"]);
58
59
 
60
+ /** @type {{ projectRoot: string|null, batchId: string|null, phase: string|null, git: object|null, diagnosis: string|null }} */
61
+ let _lightReconcileCache = {
62
+ projectRoot: null,
63
+ batchId: null,
64
+ phase: null,
65
+ git: null,
66
+ diagnosis: null,
67
+ };
68
+
69
+ /**
70
+ * Clears light-reconcile git cache (test isolation).
71
+ */
72
+ export function clearLightReconcileCache() {
73
+ _lightReconcileCache = {
74
+ projectRoot: null,
75
+ batchId: null,
76
+ phase: null,
77
+ git: null,
78
+ diagnosis: null,
79
+ };
80
+ }
81
+
82
+ /**
83
+ * @param {string} projectRoot
84
+ * @param {string} batchId
85
+ * @param {string} phase
86
+ */
87
+ function lightReconcileCacheMatches(projectRoot, batchId, phase) {
88
+ return (
89
+ _lightReconcileCache.projectRoot === projectRoot &&
90
+ _lightReconcileCache.batchId === batchId &&
91
+ _lightReconcileCache.phase === phase &&
92
+ _lightReconcileCache.git != null
93
+ );
94
+ }
95
+
96
+ /**
97
+ * @param {string} projectRoot
98
+ * @param {string} batchId
99
+ * @param {string} phase
100
+ * @param {object} git
101
+ * @param {string|null} diagnosis
102
+ */
103
+ function updateLightReconcileCache(projectRoot, batchId, phase, git, diagnosis) {
104
+ _lightReconcileCache = { projectRoot, batchId, phase, git, diagnosis };
105
+ }
106
+
59
107
  /**
60
108
  * @typedef {object} NormalizedTask
61
109
  * @property {string} taskId
@@ -975,8 +1023,10 @@ export function deriveDiagnosis(signals) {
975
1023
  * @param {object|null} [ctx.batchState]
976
1024
  * @param {string|null} [ctx.batchStatePath]
977
1025
  * @param {boolean} [ctx.verbose]
1026
+ * @param {boolean} [ctx.light] Skip git branch scans when batch phase unchanged since last full reconcile.
1027
+ * @param {boolean} [ctx._lightRetry] Internal — full reconcile after light diagnosis transition.
978
1028
  */
979
- export function reconcileBatch(ctx) {
1029
+ export function reconcileBatch(ctx, _lightRetry = false) {
980
1030
  const { projectRoot } = ctx;
981
1031
  const loaded = ctx.batchState
982
1032
  ? {
@@ -987,6 +1037,7 @@ export function reconcileBatch(ctx) {
987
1037
  : loadBatchStateFile(projectRoot, ctx.batchStatePath ?? null);
988
1038
 
989
1039
  if (!loaded.path && !loaded.raw) {
1040
+ clearLightReconcileCache();
990
1041
  return {
991
1042
  diagnosis: null,
992
1043
  headline: "No active batch — ready to plan or start",
@@ -1033,12 +1084,18 @@ export function reconcileBatch(ctx) {
1033
1084
 
1034
1085
  const tasksRoot = resolveTasksRoot(projectRoot);
1035
1086
  const classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
1036
- const git = inspectGitState({
1037
- projectRoot,
1038
- batchId: batch.batchId,
1039
- baseBranch: batch.baseBranch,
1040
- orchBranch: batch.orchBranch,
1041
- });
1087
+ const useLightGit =
1088
+ ctx.light === true &&
1089
+ !_lightRetry &&
1090
+ lightReconcileCacheMatches(projectRoot, batch.batchId, batch.phase);
1091
+ const git = useLightGit
1092
+ ? /** @type {ReturnType<typeof inspectGitState>} */ (_lightReconcileCache.git)
1093
+ : inspectGitState({
1094
+ projectRoot,
1095
+ batchId: batch.batchId,
1096
+ baseBranch: batch.baseBranch,
1097
+ orchBranch: batch.orchBranch,
1098
+ });
1042
1099
 
1043
1100
  const hasRunningTasks = classifiedTasks.some((task) => task.classification === "running");
1044
1101
  const hasPendingTasks = classifiedTasks.some((task) => task.classification === "pending");
@@ -1110,7 +1167,9 @@ export function reconcileBatch(ctx) {
1110
1167
  const pendingTaskCount = computePendingTasks(batch.raw ?? {}).length;
1111
1168
  signals.pendingTaskCount = pendingTaskCount;
1112
1169
 
1113
- let { diagnosis, failedTaskId, exitReason, launchFailureKind } = deriveDiagnosis(signals);
1170
+ const derived = deriveDiagnosis(signals);
1171
+ let { diagnosis, failedTaskId, exitReason } = derived;
1172
+ const launchFailureKind = derived.launchFailureKind;
1114
1173
  const stubSucceededTaskId = findStubMarkedSucceededTask(tasksRoot, classifiedTasks);
1115
1174
  if (
1116
1175
  stubSucceededTaskId &&
@@ -1191,6 +1250,7 @@ export function reconcileBatch(ctx) {
1191
1250
  const resolvedMacroPhaseLabel = macroPhaseLabel(macroPhase);
1192
1251
  if (ctx.verbose) {
1193
1252
  signals.macroPhase = macroPhase;
1253
+ signals.reconcileMode = useLightGit ? "light" : "full";
1194
1254
  }
1195
1255
 
1196
1256
  const stalePathCheck = buildStalePathDoctorCheck({
@@ -1275,6 +1335,22 @@ export function reconcileBatch(ctx) {
1275
1335
  pendingTasks: pendingTaskCount,
1276
1336
  });
1277
1337
 
1338
+ if (
1339
+ ctx.light === true &&
1340
+ useLightGit &&
1341
+ !_lightRetry &&
1342
+ _lightReconcileCache.diagnosis != null &&
1343
+ _lightReconcileCache.diagnosis !== diagnosis
1344
+ ) {
1345
+ return reconcileBatch({ ...ctx, light: false }, true);
1346
+ }
1347
+
1348
+ if (!useLightGit) {
1349
+ updateLightReconcileCache(projectRoot, batch.batchId, batch.phase, git, diagnosis);
1350
+ } else {
1351
+ _lightReconcileCache.diagnosis = diagnosis;
1352
+ }
1353
+
1278
1354
  return {
1279
1355
  ...output,
1280
1356
  batchId: batch.batchId,
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Shared resume validation and task-path helpers (SP-076).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Detached engine lifecycle helpers for batch resume (SP-203).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Per-lane task execution and wave queue wiring for multi-task resume (extracted from resume-multi.mjs).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Multi-task batch resume validation and worktree health checks (extracted from resume-multi.mjs).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Multi-task batch resume validation (TP-039) and execution (TP-040).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Pure resume validation helpers — leaf module (SP-468 / #83-B).
3
4
  * No reconcile import; I/O wrappers live in resume-multi-validate.mjs.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Batch pause and resume for single-lane batches (TP-015, PRD §18.2).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Atomic task retry and skip (TP-017, PRD §18.5, FR-BATCH-09/10).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Pure review helpers shared by `review.mjs` and `engine-lanes/review.mjs`.
3
4
  * SP-265 extraction target; SP-266 wires imports.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Reviewer pi spawn assembly and child process (FR-REV spawn contract).
3
4
  * SP-259 strangler extract from review.mjs.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Step review spawn + verdict parsing (FR-REV, GAP-REV-01).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Rules-manifest drift resolution for integrate prep (SP-317 / #22).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * FR-STALL-03A/03B: salvage inspection and optional WIP commit on stall (no `.DONE`).
3
4
  *