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
@@ -82,10 +82,13 @@ export async function waitForSequenceBatchTerminal({
82
82
  pollIntervalMs = DEFAULT_SEQUENCE_POLL_MS,
83
83
  timeoutMs = 120_000,
84
84
  enginePid = null,
85
+ reconcileFn = reconcileBatch,
85
86
  }) {
86
87
  const deadline = Date.now() + timeoutMs;
88
+ let useLightReconcile = false;
87
89
  while (Date.now() < deadline || isEngineStillRunning(enginePid, projectRoot)) {
88
- const reconciliation = reconcileBatch({ projectRoot });
90
+ const reconciliation = reconcileFn({ projectRoot, light: useLightReconcile });
91
+ useLightReconcile = true;
89
92
  const diagnosis = reconciliation.diagnosis;
90
93
  if (isSequenceBatchFailure(diagnosis)) {
91
94
  return {
@@ -106,7 +109,7 @@ export async function waitForSequenceBatchTerminal({
106
109
  }
107
110
  await sleep(pollIntervalMs);
108
111
  }
109
- const reconciliation = reconcileBatch({ projectRoot });
112
+ const reconciliation = reconcileFn({ projectRoot });
110
113
  return {
111
114
  ok: false,
112
115
  error: "timeout_waiting_for_batch",
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * pi-spine batch-state.json read/write (schema v1, PRD §10.1).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * FR-SHIP-11 Tier 1 — opt-in supervisor monitor spawn on detached batch start.
3
4
  * Detached node child polls reconcileBatch and journals supervisor.* events.
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Per-task stall timeout budget from PROMPT Size (SP-088).
3
4
  */
@@ -5,8 +6,7 @@
5
6
  import fs from "node:fs";
6
7
  import path from "node:path";
7
8
  import { resolveStallConfig } from "./heartbeat.mjs";
8
-
9
- const SIZE_LINE_RE = /^\*\*Size:\*\*\s*(S|M|L|XL)\s*$/im;
9
+ import { parseSizeLineFromMarkdown } from "../tasks/packet/size-line.mjs";
10
10
 
11
11
  /** Minimum stall timeout minutes by packet size (floor for real pi work). */
12
12
  export const STALL_MINUTES_BY_SIZE = Object.freeze({
@@ -20,8 +20,7 @@ export const STALL_MINUTES_BY_SIZE = Object.freeze({
20
20
  * @returns {"S"|"M"|"L"|"XL"|null}
21
21
  */
22
22
  export function parseTaskSizeFromMarkdown(markdown) {
23
- const match = SIZE_LINE_RE.exec(markdown);
24
- return match ? /** @type {"S"|"M"|"L"|"XL"} */ (match[1].toUpperCase()) : null;
23
+ return parseSizeLineFromMarkdown(markdown);
25
24
  }
26
25
 
27
26
  /**
@@ -606,16 +606,18 @@ export async function runWorker({
606
606
  continue;
607
607
  }
608
608
 
609
- const signals = collectProgressSignals(/** @type {any} */ ({
610
- worktreePath,
611
- taskFolder,
612
- laneBranch,
613
- fileScopePaths,
614
- journalContext:
615
- projectRoot && batchId
616
- ? { projectRoot, batchId, laneNumber, taskId }
617
- : undefined,
618
- }));
609
+ const signals = collectProgressSignals(
610
+ /** @type {Parameters<typeof collectProgressSignals>[0]} */ ({
611
+ worktreePath,
612
+ taskFolder,
613
+ laneBranch,
614
+ fileScopePaths,
615
+ journalContext:
616
+ projectRoot && batchId
617
+ ? { projectRoot, batchId, laneNumber, taskId }
618
+ : undefined,
619
+ }),
620
+ );
619
621
  const nextWorkerPhase = resolveWorkerPhase({ childPastPreflight, useStub, workerBackend });
620
622
  if (nextWorkerPhase !== "launching" && workerPhase === "launching") {
621
623
  stallAnchorAt = now;
@@ -700,21 +702,25 @@ export async function runWorker({
700
702
  batchId &&
701
703
  now - lastHeartbeatAt >= stallConfig.heartbeatIntervalMs
702
704
  ) {
703
- const heartbeatKind = resolveHeartbeatKind(/** @type {any} */ ({
704
- workerPhase,
705
- checkpointChanged,
706
- activityChanged,
707
- }));
708
- recordLaneHeartbeat(/** @type {any} */ ({
709
- projectRoot,
710
- batchId,
711
- laneNumber,
712
- taskId,
713
- signals,
714
- correlationId: laneCorrelationId,
715
- workerPhase,
716
- heartbeatKind,
717
- }));
705
+ const heartbeatKind = resolveHeartbeatKind(
706
+ /** @type {Parameters<typeof resolveHeartbeatKind>[0]} */ ({
707
+ workerPhase,
708
+ checkpointChanged,
709
+ activityChanged,
710
+ }),
711
+ );
712
+ recordLaneHeartbeat(
713
+ /** @type {Parameters<typeof recordLaneHeartbeat>[0]} */ ({
714
+ projectRoot,
715
+ batchId,
716
+ laneNumber,
717
+ taskId,
718
+ signals,
719
+ correlationId: laneCorrelationId,
720
+ workerPhase,
721
+ heartbeatKind,
722
+ }),
723
+ );
718
724
  stallAnchorAt = nextStallAnchorAt({
719
725
  stallAnchorAt,
720
726
  now,
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Bounded worker stdout/stderr capture on terminal failure (FR-STALL-01).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Shared worker tail prompt text for pi runners (SP-067).
3
4
  */
@@ -109,7 +109,7 @@ export function formatJournalFollowOutputLine(rawLine, options = {}) {
109
109
  * @returns {string}
110
110
  */
111
111
  export function drainJournalFollowChunk(chunk, partial, options) {
112
- let buffer = partial + chunk;
112
+ const buffer = partial + chunk;
113
113
  const parts = buffer.split("\n");
114
114
  const remainder = parts.pop() ?? "";
115
115
 
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Agent model/thinking pin resolution for reviewer spawns (issue #53 / SP-369).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * contract.mode config validation (SP-142, handoff §3.1).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Discover `.cursor/rules/` and build `.spine/rules-manifest.json`.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Micromatch helpers for PROMPT File Scope vs rule globs (SP-091).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Minimal YAML frontmatter parser for `.cursor/rules/*.{mdc,md}`.
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Rules profile loader for `.spine/rules-profile.json` (cursor rules discovery).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Select Cursor rules for spine workers from manifest + PROMPT File Scope (SP-091).
3
4
  */
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * FR-CFG-04 environment variable overrides (TP-046).
3
4
  * Precedence: env > file > defaults (applied in loadSpineConfig after file parse).
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Resolve pi-spine package root for worker subprocess env (SP-103).
3
4
  */
@@ -0,0 +1,333 @@
1
+ // @ts-nocheck
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { spawnSync } from "node:child_process";
5
+ import { loadSpineConfig } from "../spine-config-load.mjs";
6
+ import { resolveTasksRootPath } from "../env-overrides.mjs";
7
+ import { validateWorktreeSetupHookConfig } from "../worktree-setup-hook.mjs";
8
+ import { discoverTasks } from "../../tasks/packet/discover.mjs";
9
+ import { NO_PENDING_TASKS_ERROR } from "../../planner/scope.mjs";
10
+ import { summarizePendingScope } from "../../planner/pending.mjs";
11
+ import { validatePrompt } from "../../tasks/packet/validate-prompt.mjs";
12
+
13
+ const DEPENDENCIES_SCHEMA_VERSION = 1;
14
+ const TASK_ID_PATTERN = /^[A-Z]{2,}-\d{3,}$/;
15
+
16
+ function makeCheck(id, ok, message, extra = {}) {
17
+ return { id, ok, message, ...extra };
18
+ }
19
+
20
+ /**
21
+ * @param {object} ctx
22
+ * @param {string} ctx.projectRoot
23
+ * @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
24
+ */
25
+ export function resolveTasksRoot(projectRoot, configResult) {
26
+ const loaded = configResult ?? loadSpineConfig(projectRoot);
27
+ if (!loaded.config) {
28
+ return null;
29
+ }
30
+ return resolveTasksRootPath(projectRoot, loaded.config);
31
+ }
32
+
33
+ export function taskIdFromFolder(folderName) {
34
+ const match = String(folderName).match(/^([A-Z]{2,}-\d{3,})/);
35
+ return match?.[1] ?? null;
36
+ }
37
+
38
+ export function discoverTaskFolders(tasksRootPath) {
39
+ if (!tasksRootPath || !fs.existsSync(tasksRootPath)) return [];
40
+
41
+ return fs
42
+ .readdirSync(tasksRootPath, { withFileTypes: true })
43
+ .filter((entry) => entry.isDirectory())
44
+ .map((entry) => entry.name)
45
+ .filter((name) => fs.existsSync(path.join(tasksRootPath, name, "PROMPT.md")))
46
+ .sort();
47
+ }
48
+
49
+ export function discoverTaskIds(tasksRootPath) {
50
+ return [...new Set(discoverTaskFolders(tasksRootPath).map(taskIdFromFolder).filter(Boolean))].sort();
51
+ }
52
+
53
+ /**
54
+ * @param {object} ctx
55
+ * @param {string} ctx.projectRoot
56
+ * @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
57
+ */
58
+ export function checkTasksRoot(ctx) {
59
+ const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
60
+ const tasksRootPath = resolveTasksRoot(ctx.projectRoot, configResult);
61
+
62
+ if (!tasksRootPath) {
63
+ return makeCheck("tasks-root", false, "tasks root not configured", {
64
+ suggestedCommand: "spine init",
65
+ });
66
+ }
67
+
68
+ if (!fs.existsSync(tasksRootPath)) {
69
+ return makeCheck(
70
+ "tasks-root",
71
+ false,
72
+ `tasks root missing: ${path.relative(ctx.projectRoot, tasksRootPath)}`,
73
+ {
74
+ suggestedCommand: `mkdir -p ${path.relative(ctx.projectRoot, tasksRootPath)}`,
75
+ },
76
+ );
77
+ }
78
+
79
+ const taskFolders = discoverTaskFolders(tasksRootPath);
80
+ if (taskFolders.length === 0) {
81
+ return makeCheck("tasks-root", false, "no discoverable task folders (PROMPT.md)", {
82
+ details: { tasksRootPath: path.relative(ctx.projectRoot, tasksRootPath) },
83
+ suggestedCommand: "spine init",
84
+ });
85
+ }
86
+
87
+ return makeCheck(
88
+ "tasks-root",
89
+ true,
90
+ `tasks root valid (${taskFolders.length} task folder(s))`,
91
+ {
92
+ details: {
93
+ tasksRootPath: path.relative(ctx.projectRoot, tasksRootPath),
94
+ taskFolders,
95
+ },
96
+ },
97
+ );
98
+ }
99
+
100
+ /**
101
+ * @param {object} ctx
102
+ * @param {string} ctx.projectRoot
103
+ * @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
104
+ */
105
+ export function checkDependenciesJson(ctx) {
106
+ const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
107
+ const tasksRootPath = resolveTasksRoot(ctx.projectRoot, configResult);
108
+
109
+ if (!tasksRootPath) {
110
+ return makeCheck("dependencies-json", false, "tasks root not configured", {
111
+ suggestedCommand: "spine init",
112
+ });
113
+ }
114
+
115
+ const depsPath = path.join(tasksRootPath, "dependencies.json");
116
+ if (!fs.existsSync(depsPath)) {
117
+ return makeCheck(
118
+ "dependencies-json",
119
+ false,
120
+ `dependencies.json missing: ${path.relative(ctx.projectRoot, depsPath)}`,
121
+ { suggestedCommand: "spine init" },
122
+ );
123
+ }
124
+
125
+ let parsed;
126
+ try {
127
+ parsed = JSON.parse(fs.readFileSync(depsPath, "utf-8"));
128
+ } catch (err) {
129
+ return makeCheck("dependencies-json", false, `cannot parse dependencies.json: ${err.message}`, {
130
+ suggestedCommand: "spine init",
131
+ });
132
+ }
133
+
134
+ if (parsed.version !== DEPENDENCIES_SCHEMA_VERSION) {
135
+ return makeCheck(
136
+ "dependencies-json",
137
+ false,
138
+ `dependencies.json version must be ${DEPENDENCIES_SCHEMA_VERSION} (found ${parsed.version ?? "missing"})`,
139
+ { suggestedCommand: "spine init" },
140
+ );
141
+ }
142
+
143
+ if (typeof parsed.tasks !== "object" || parsed.tasks === null || Array.isArray(parsed.tasks)) {
144
+ return makeCheck("dependencies-json", false, "dependencies.json tasks must be an object", {
145
+ suggestedCommand: "spine init",
146
+ });
147
+ }
148
+
149
+ const taskIds = Object.keys(parsed.tasks);
150
+ const invalidIds = taskIds.filter((id) => !TASK_ID_PATTERN.test(id));
151
+ if (invalidIds.length > 0) {
152
+ return makeCheck(
153
+ "dependencies-json",
154
+ false,
155
+ `dependencies.json has invalid task IDs: ${invalidIds.slice(0, 5).join(", ")}`,
156
+ { details: { invalidIds }, suggestedCommand: "spine init --tasks-root taskplane-tasks" },
157
+ );
158
+ }
159
+
160
+ const discovered = new Set(discoverTaskIds(tasksRootPath));
161
+ const unknownIds = taskIds.filter((id) => !discovered.has(id));
162
+ if (unknownIds.length > 0) {
163
+ return makeCheck(
164
+ "dependencies-json",
165
+ false,
166
+ `dependencies.json references unknown task folders: ${unknownIds.slice(0, 5).join(", ")}`,
167
+ { details: { unknownIds }, suggestedCommand: "spine init --tasks-root taskplane-tasks" },
168
+ );
169
+ }
170
+
171
+ return makeCheck(
172
+ "dependencies-json",
173
+ true,
174
+ `dependencies.json valid (${taskIds.length} task(s))`,
175
+ { details: { path: path.relative(ctx.projectRoot, depsPath), taskIds } },
176
+ );
177
+ }
178
+
179
+ /**
180
+ * @param {object} ctx
181
+ * @param {string} ctx.projectRoot
182
+ * @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
183
+ */
184
+ export function checkWorktreeSetupHook(ctx) {
185
+ const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
186
+ const config = configResult?.config;
187
+ if (!config || configResult?.error) {
188
+ return makeCheck("worktree-setup-hook", true, "worktree setup hook not configured");
189
+ }
190
+
191
+ const hookError = validateWorktreeSetupHookConfig(config, ctx.projectRoot);
192
+ if (hookError) {
193
+ return makeCheck("worktree-setup-hook", false, hookError.message, {
194
+ suggestedCommand: hookError.suggestedCommand,
195
+ });
196
+ }
197
+
198
+ if (!config.worktreeSetupHook) {
199
+ return makeCheck("worktree-setup-hook", true, "worktree setup hook not configured");
200
+ }
201
+
202
+ return makeCheck("worktree-setup-hook", true, "worktree setup hook path valid");
203
+ }
204
+
205
+ /**
206
+ * Read multiple UTF-8 text files concurrently in a child process (sync parent API).
207
+ *
208
+ * @param {string[]} filePaths
209
+ * @returns {Map<string, string>}
210
+ */
211
+ export function readUtf8FilesBatchSync(filePaths) {
212
+ const uniquePaths = [...new Set(filePaths)];
213
+ if (uniquePaths.length === 0) {
214
+ return new Map();
215
+ }
216
+
217
+ const child = spawnSync(
218
+ process.execPath,
219
+ [
220
+ "--input-type=module",
221
+ "-e",
222
+ `const paths = JSON.parse(process.argv[1]);
223
+ const fs = await import("node:fs/promises");
224
+ const entries = await Promise.all(
225
+ paths.map(async (filePath) => [filePath, await fs.readFile(filePath, "utf-8")]),
226
+ );
227
+ process.stdout.write(JSON.stringify(entries));`,
228
+ JSON.stringify(uniquePaths),
229
+ ],
230
+ {
231
+ encoding: "utf-8",
232
+ maxBuffer: 10 * 1024 * 1024,
233
+ },
234
+ );
235
+
236
+ if (child.error) {
237
+ throw child.error;
238
+ }
239
+ if (child.status !== 0) {
240
+ throw new Error(child.stderr?.trim() || `batch read failed with status ${child.status}`);
241
+ }
242
+
243
+ /** @type {[string, string][]} */
244
+ const entries = JSON.parse(child.stdout);
245
+ return new Map(entries);
246
+ }
247
+
248
+ /**
249
+ * @param {object} ctx
250
+ * @param {string} ctx.projectRoot
251
+ * @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
252
+ */
253
+ export function checkTasksValidate(ctx) {
254
+ const { projectRoot, configResult } = ctx;
255
+ const config = configResult?.config;
256
+
257
+ if (!config || configResult?.error) {
258
+ return makeCheck("tasks-validate", false, "cannot validate tasks without spine config", {
259
+ suggestedCommand: "spine init",
260
+ });
261
+ }
262
+
263
+ const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
264
+ if (!tasksRootPath) {
265
+ return makeCheck("tasks-validate", false, "tasks root not configured", {
266
+ suggestedCommand: "spine init",
267
+ });
268
+ }
269
+
270
+ try {
271
+ const discovered = discoverTasks(tasksRootPath);
272
+ const { pendingIds } = summarizePendingScope(discovered, tasksRootPath);
273
+ if (pendingIds.length === 0) {
274
+ return makeCheck(
275
+ "tasks-validate",
276
+ true,
277
+ "no pending tasks (all discovered tasks have .DONE)",
278
+ );
279
+ }
280
+
281
+ const selectedTaskIds = new Set(pendingIds);
282
+ /** @type {string[]} */
283
+ const failures = [];
284
+ /** @type {Array<{ discoveredTask: (typeof discovered)[number], promptPath: string }>} */
285
+ const pendingPrompts = [];
286
+
287
+ for (const discoveredTask of discovered) {
288
+ if (!selectedTaskIds.has(discoveredTask.taskId)) continue;
289
+ pendingPrompts.push({
290
+ discoveredTask,
291
+ promptPath: path.join(discoveredTask.folderPath, "PROMPT.md"),
292
+ });
293
+ }
294
+
295
+ const promptContents = readUtf8FilesBatchSync(
296
+ pendingPrompts.map((entry) => entry.promptPath),
297
+ );
298
+
299
+ for (const { discoveredTask, promptPath } of pendingPrompts) {
300
+ const promptMarkdown = promptContents.get(promptPath);
301
+ const validation = validatePrompt(promptMarkdown, {
302
+ taskId: discoveredTask.taskId,
303
+ contract: config.contract,
304
+ });
305
+ if (!validation.ok) {
306
+ failures.push(
307
+ `${discoveredTask.taskId}: ${validation.errors[0] ?? "invalid PROMPT packet"}`,
308
+ );
309
+ }
310
+ }
311
+
312
+ if (failures.length === 0) {
313
+ return makeCheck("tasks-validate", true, "pending task PROMPT packets valid");
314
+ }
315
+
316
+ return makeCheck("tasks-validate", false, failures[0], {
317
+ suggestedCommand: "spine tasks validate pending",
318
+ details: { failures },
319
+ });
320
+ } catch (err) {
321
+ const message = err?.message ?? String(err);
322
+ if (message === NO_PENDING_TASKS_ERROR) {
323
+ return makeCheck(
324
+ "tasks-validate",
325
+ true,
326
+ "no pending tasks (all discovered tasks have .DONE)",
327
+ );
328
+ }
329
+ return makeCheck("tasks-validate", false, `tasks validate failed: ${message}`, {
330
+ suggestedCommand: "spine tasks validate pending",
331
+ });
332
+ }
333
+ }