pi-spine 1.0.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +563 -0
  3. package/bin/get-version.mjs +35 -0
  4. package/bin/spine-batch.mjs +425 -0
  5. package/bin/spine-cli/batch.mjs +47 -0
  6. package/bin/spine-cli/gate.mjs +10 -0
  7. package/bin/spine-cli/integrate.mjs +10 -0
  8. package/bin/spine-cli/plan.mjs +12 -0
  9. package/bin/spine-cli/shared.mjs +73 -0
  10. package/bin/spine-cli/status.mjs +18 -0
  11. package/bin/spine-cli/verify.mjs +199 -0
  12. package/bin/spine-config.mjs +212 -0
  13. package/bin/spine-dashboard.mjs +178 -0
  14. package/bin/spine-deps.mjs +69 -0
  15. package/bin/spine-doctor.mjs +468 -0
  16. package/bin/spine-gate.mjs +137 -0
  17. package/bin/spine-init.mjs +398 -0
  18. package/bin/spine-integrate.mjs +77 -0
  19. package/bin/spine-journal.mjs +198 -0
  20. package/bin/spine-migrate-from-taskplane.mjs +136 -0
  21. package/bin/spine-plan.mjs +83 -0
  22. package/bin/spine-preflight.mjs +700 -0
  23. package/bin/spine-report-progress.d.mts +28 -0
  24. package/bin/spine-report-progress.mjs +126 -0
  25. package/bin/spine-review-step.d.mts +24 -0
  26. package/bin/spine-review-step.mjs +124 -0
  27. package/bin/spine-rules.mjs +35 -0
  28. package/bin/spine-settings.mjs +186 -0
  29. package/bin/spine-state.mjs +110 -0
  30. package/bin/spine-status.mjs +79 -0
  31. package/bin/spine-tasks.mjs +293 -0
  32. package/bin/spine-worker-runner.mjs +314 -0
  33. package/bin/spine.mjs +404 -0
  34. package/extensions/spine/settings-slash.ts +20 -0
  35. package/extensions/spine/slash-commands.ts +806 -0
  36. package/extensions/spine/worker-tools.ts +279 -0
  37. package/extensions/spine-orchestrator.ts +12 -0
  38. package/package.json +72 -0
  39. package/skills/.gitkeep +0 -0
  40. package/skills/create-spine-tasks/SKILL.md +375 -0
  41. package/skills/create-spine-tasks/references/context-template.md +25 -0
  42. package/skills/create-spine-tasks/references/contract-template.md +98 -0
  43. package/skills/create-spine-tasks/references/explore-template.md +63 -0
  44. package/skills/create-spine-tasks/references/prompt-template.md +276 -0
  45. package/src/batch/abort.mjs +272 -0
  46. package/src/batch/agent-session-worker.mjs +297 -0
  47. package/src/batch/batch-state-io.mjs +53 -0
  48. package/src/batch/contract-verify.mjs +310 -0
  49. package/src/batch/detached-start.mjs +778 -0
  50. package/src/batch/diagnosis.mjs +378 -0
  51. package/src/batch/engine-lanes/merge.mjs +632 -0
  52. package/src/batch/engine-lanes/queue.mjs +208 -0
  53. package/src/batch/engine-lanes/review.mjs +970 -0
  54. package/src/batch/engine-lanes.mjs +388 -0
  55. package/src/batch/engine-scope.mjs +251 -0
  56. package/src/batch/engine.mjs +445 -0
  57. package/src/batch/evidence-command.mjs +157 -0
  58. package/src/batch/evidence.mjs +203 -0
  59. package/src/batch/gate.mjs +359 -0
  60. package/src/batch/git-commit-env.mjs +46 -0
  61. package/src/batch/git-exec.mjs +26 -0
  62. package/src/batch/heartbeat.mjs +430 -0
  63. package/src/batch/integrate.mjs +414 -0
  64. package/src/batch/journal-rebuild.mjs +388 -0
  65. package/src/batch/journal.mjs +373 -0
  66. package/src/batch/lane-commit.mjs +153 -0
  67. package/src/batch/lifecycle.mjs +364 -0
  68. package/src/batch/metrics.mjs +265 -0
  69. package/src/batch/orphan-detect.mjs +210 -0
  70. package/src/batch/post-merge-limbo.mjs +80 -0
  71. package/src/batch/postmortem.mjs +296 -0
  72. package/src/batch/readers/spine-state.mjs +95 -0
  73. package/src/batch/readers/taskplane-state.mjs +136 -0
  74. package/src/batch/reconcile.mjs +729 -0
  75. package/src/batch/resume-common.mjs +104 -0
  76. package/src/batch/resume-engine.mjs +66 -0
  77. package/src/batch/resume-multi-lanes.mjs +479 -0
  78. package/src/batch/resume-multi-validate.mjs +187 -0
  79. package/src/batch/resume-multi.mjs +254 -0
  80. package/src/batch/resume.mjs +475 -0
  81. package/src/batch/retry.mjs +257 -0
  82. package/src/batch/review-scope.mjs +136 -0
  83. package/src/batch/review.mjs +1045 -0
  84. package/src/batch/salvage.mjs +332 -0
  85. package/src/batch/state.mjs +680 -0
  86. package/src/batch/task-stall-budget.mjs +88 -0
  87. package/src/batch/worker-host.mjs +683 -0
  88. package/src/batch/worker-output.mjs +253 -0
  89. package/src/batch/worker-prompt.mjs +84 -0
  90. package/src/batch/worktree.mjs +290 -0
  91. package/src/cli/deps.mjs +141 -0
  92. package/src/cli/handoff.mjs +364 -0
  93. package/src/cli/rules.mjs +429 -0
  94. package/src/cli/settings-set.mjs +171 -0
  95. package/src/cli/settings-show.mjs +140 -0
  96. package/src/cli/settings-slash.mjs +107 -0
  97. package/src/config/contract.mjs +56 -0
  98. package/src/config/cursor-rules/discover.mjs +416 -0
  99. package/src/config/cursor-rules/index.mjs +39 -0
  100. package/src/config/cursor-rules/match-globs.mjs +132 -0
  101. package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
  102. package/src/config/cursor-rules/priority.mjs +26 -0
  103. package/src/config/cursor-rules/profile.mjs +403 -0
  104. package/src/config/cursor-rules/select.mjs +259 -0
  105. package/src/config/defaults.mjs +36 -0
  106. package/src/config/env-overrides.mjs +207 -0
  107. package/src/config/merge-defaults.mjs +47 -0
  108. package/src/config/pi-spine-root.mjs +93 -0
  109. package/src/config/reviewer-context.mjs +243 -0
  110. package/src/config/settings-fields.mjs +265 -0
  111. package/src/config/worker-backend.mjs +116 -0
  112. package/src/config/worker-context.mjs +402 -0
  113. package/src/config/worker-launch-script.mjs +130 -0
  114. package/src/config/worktree-setup-hook.mjs +122 -0
  115. package/src/dashboard/public/dashboard.css +77 -0
  116. package/src/dashboard/public/dashboard.js +349 -0
  117. package/src/dashboard/public/index.html +80 -0
  118. package/src/dashboard/server.mjs +155 -0
  119. package/src/dashboard/snapshot.mjs +414 -0
  120. package/src/dashboard/sse.mjs +15 -0
  121. package/src/dashboard/view.mjs +292 -0
  122. package/src/doctor/agent-model-inherit.mjs +101 -0
  123. package/src/doctor/batch-size-guidance.mjs +72 -0
  124. package/src/doctor/coexistence.mjs +312 -0
  125. package/src/doctor/rules-manifest.mjs +133 -0
  126. package/src/doctor/stale-path.mjs +156 -0
  127. package/src/doctor/stall-config.mjs +108 -0
  128. package/src/doctor/suggest-max-parallel.mjs +53 -0
  129. package/src/doctor/task-packet-size.mjs +110 -0
  130. package/src/doctor/worktree-health.mjs +71 -0
  131. package/src/migrate/taskplane-config.mjs +116 -0
  132. package/src/planner/cycles.mjs +63 -0
  133. package/src/planner/format-plan.mjs +132 -0
  134. package/src/planner/graph.mjs +99 -0
  135. package/src/planner/index.mjs +125 -0
  136. package/src/planner/lanes.mjs +111 -0
  137. package/src/planner/pending.mjs +39 -0
  138. package/src/planner/scope.mjs +142 -0
  139. package/src/process/liveness.mjs +21 -0
  140. package/src/tasks/packet/discover.mjs +40 -0
  141. package/src/tasks/packet/index.mjs +81 -0
  142. package/src/tasks/packet/merge-deps.mjs +79 -0
  143. package/src/tasks/packet/parse-prompt.mjs +445 -0
  144. package/src/tasks/packet/parse-status.mjs +118 -0
  145. package/src/tasks/packet/validate-contract.mjs +115 -0
  146. package/src/tasks/packet/validate-prompt.mjs +99 -0
  147. package/src/worker-tools/report-progress.d.mts +18 -0
  148. package/src/worker-tools/report-progress.mjs +59 -0
  149. package/src/worker-tools/request-gate.d.mts +17 -0
  150. package/src/worker-tools/request-gate.mjs +54 -0
  151. package/templates/agents/reviewer.md +123 -0
  152. package/templates/agents/supervisor.md +59 -0
  153. package/templates/agents/worker.md +122 -0
  154. package/templates/rules-profile.json +27 -0
  155. package/templates/spine-config.json +64 -0
  156. package/templates/tasks/CONTEXT.md +30 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Doctor warning when spine agents inherit pi's global model and pi defaults to LM Studio (SP-238).
3
+ */
4
+
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+
9
+ const LMSTUDIO_PROVIDER = "lmstudio";
10
+
11
+ /**
12
+ * @param {string} settingsPath
13
+ * @returns {Record<string, unknown>|null}
14
+ */
15
+ export function readPiSettingsFile(settingsPath) {
16
+ try {
17
+ if (!fs.existsSync(settingsPath)) {
18
+ return null;
19
+ }
20
+ return JSON.parse(fs.readFileSync(settingsPath, "utf-8"));
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Resolve pi defaultProvider (project `.pi/settings.json` overrides global).
28
+ *
29
+ * @param {string} projectRoot
30
+ * @param {object} [options]
31
+ * @param {string} [options.globalSettingsPath]
32
+ * @param {string} [options.projectSettingsPath]
33
+ * @returns {string|null}
34
+ */
35
+ export function resolvePiDefaultProvider(
36
+ projectRoot,
37
+ { globalSettingsPath, projectSettingsPath } = {},
38
+ ) {
39
+ const globalPath =
40
+ globalSettingsPath ?? path.join(os.homedir(), ".pi", "agent", "settings.json");
41
+ const projectPath = projectSettingsPath ?? path.join(projectRoot, ".pi", "settings.json");
42
+ const global = readPiSettingsFile(globalPath);
43
+ const project = readPiSettingsFile(projectPath);
44
+ const provider = project?.defaultProvider ?? global?.defaultProvider;
45
+ if (typeof provider !== "string" || !provider.trim()) {
46
+ return null;
47
+ }
48
+ return provider.trim().toLowerCase();
49
+ }
50
+
51
+ /**
52
+ * @param {object} [config]
53
+ * @returns {boolean}
54
+ */
55
+ export function spineAgentsUseInherit(config = {}) {
56
+ const workerModel = config.agents?.worker?.model;
57
+ const reviewerModel = config.agents?.reviewer?.model;
58
+ const inherits = (model) => !model || model === "inherit";
59
+ return inherits(workerModel) || inherits(reviewerModel);
60
+ }
61
+
62
+ /**
63
+ * @param {object} params
64
+ * @param {object} [params.config]
65
+ * @param {string} [params.projectRoot]
66
+ * @param {() => string|null} [params.resolveProvider]
67
+ */
68
+ export function buildAgentModelInheritDoctorCheck({
69
+ config = {},
70
+ projectRoot = process.cwd(),
71
+ resolveProvider,
72
+ } = {}) {
73
+ if (!spineAgentsUseInherit(config)) {
74
+ return {
75
+ label: "agents model inherit (pi-lmstudio)",
76
+ ok: true,
77
+ detail: "worker/reviewer pinned or inherit not used",
78
+ };
79
+ }
80
+
81
+ const provider = resolveProvider
82
+ ? resolveProvider()
83
+ : resolvePiDefaultProvider(projectRoot);
84
+ if (provider !== LMSTUDIO_PROVIDER) {
85
+ return {
86
+ label: "agents model inherit (pi-lmstudio)",
87
+ ok: true,
88
+ detail: provider ? `pi default provider ${provider}` : "pi default provider unset",
89
+ };
90
+ }
91
+
92
+ return {
93
+ label: "agents model inherit (pi-lmstudio)",
94
+ ok: true,
95
+ warning: true,
96
+ detail:
97
+ "inherit + pi defaultProvider lmstudio — batch workers/reviewers may use local LM Studio; pin cursor/auto in spine-config",
98
+ suggestedCommand:
99
+ "spine settings set agents.worker.model cursor/auto && spine settings set agents.reviewer.model cursor/auto",
100
+ };
101
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Soft warnings when batch scope includes many M/L tasks (SP-087).
3
+ */
4
+
5
+ import { discoverTasks } from "../tasks/packet/index.mjs";
6
+ import { parseTaskSizeFromFolder } from "../batch/task-stall-budget.mjs";
7
+ import { isStubWorkerMode } from "./stall-config.mjs";
8
+
9
+ const MEDIUM_LARGE_SIZES = new Set(["M", "L"]);
10
+ const WARN_AT_MEDIUM_LARGE_COUNT = 4;
11
+
12
+ /**
13
+ * @param {object} params
14
+ * @param {string} params.tasksRoot
15
+ * @param {string[]} params.taskIds
16
+ */
17
+ export function countMediumLargeTasks({ tasksRoot, taskIds }) {
18
+ const discovered = discoverTasks(tasksRoot);
19
+ const folderById = Object.fromEntries(discovered.map((task) => [task.taskId, task.folderPath]));
20
+
21
+ /** @type {string[]} */
22
+ const mediumLargeTaskIds = [];
23
+ for (const taskId of taskIds) {
24
+ const folderPath = folderById[taskId];
25
+ if (!folderPath) continue;
26
+ const size = parseTaskSizeFromFolder(folderPath);
27
+ if (size && MEDIUM_LARGE_SIZES.has(size)) {
28
+ mediumLargeTaskIds.push(taskId);
29
+ }
30
+ }
31
+
32
+ return {
33
+ count: mediumLargeTaskIds.length,
34
+ taskIds: mediumLargeTaskIds,
35
+ };
36
+ }
37
+
38
+ /**
39
+ * @param {object} params
40
+ * @param {string} params.tasksRoot
41
+ * @param {string[]} params.taskIds
42
+ * @returns {string|null}
43
+ */
44
+ export function buildBatchSizeGuidanceWarning({ tasksRoot, taskIds }) {
45
+ if (isStubWorkerMode()) return null;
46
+
47
+ const { count, taskIds: mediumLargeTaskIds } = countMediumLargeTasks({ tasksRoot, taskIds });
48
+ if (count < WARN_AT_MEDIUM_LARGE_COUNT) return null;
49
+
50
+ const preview = mediumLargeTaskIds.slice(0, 6).join(", ");
51
+ const suffix = mediumLargeTaskIds.length > 6 ? ", ..." : "";
52
+
53
+ return (
54
+ `⚠ Batch includes ${count} M/L task(s) (${preview}${suffix}) — ` +
55
+ "prefer smaller batches for real pi workers; set lanes.stallTimeoutMinutes ≥120"
56
+ );
57
+ }
58
+
59
+ /**
60
+ * @param {string} planText
61
+ * @param {{ scope?: { taskIds?: string[] }, metadata?: { tasksRoot?: string } }} plan
62
+ */
63
+ export function appendBatchSizeGuidanceToPlanOutput(planText, plan) {
64
+ const tasksRoot = plan.metadata?.tasksRoot;
65
+ const taskIds = plan.scope?.taskIds ?? [];
66
+ if (!tasksRoot || taskIds.length === 0) return planText;
67
+
68
+ const warning = buildBatchSizeGuidanceWarning({ tasksRoot, taskIds });
69
+ if (!warning) return planText;
70
+
71
+ return `${planText.trimEnd()}\n\n${warning}\n`;
72
+ }
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Taskplane / pi-spine mutual exclusion (PRD §22.1).
3
+ * Inspects `.spine/batch-state.json` and `.pi/batch-state.json` independently.
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { ACTIVE_PHASES } from "../batch/state.mjs";
9
+ import { parseBatchState, runReconciliationCheck } from "../batch/reconcile.mjs";
10
+
11
+ export const SPINE_BATCH_STATE_REL = path.join(".spine", "batch-state.json");
12
+ export const TASKPLANE_BATCH_STATE_REL = path.join(".pi", "batch-state.json");
13
+
14
+ /** @typedef {"spine"|"taskplane"} OrchestratorSource */
15
+
16
+ /** @typedef {object} OrchestratorBatchSnapshot
17
+ * @property {OrchestratorSource} source
18
+ * @property {string} path
19
+ * @property {string|null} batchId
20
+ * @property {string|null} phase
21
+ * @property {string|null} diagnosis
22
+ * @property {boolean} blocking
23
+ */
24
+
25
+ /** @typedef {object} CoexistenceAssessment
26
+ * @property {boolean} ok
27
+ * @property {"none"|"taskplane_active"|"spine_active"|"dual_active"} kind
28
+ * @property {string} message
29
+ * @property {string|null} suggestedCommand
30
+ * @property {string[]} alternatives
31
+ * @property {OrchestratorBatchSnapshot|null} spine
32
+ * @property {OrchestratorBatchSnapshot|null} taskplane
33
+ */
34
+
35
+ const NON_BLOCKING_DIAGNOSES = new Set(["completed"]);
36
+
37
+ const TASKPLANE_ACTIVE_PHASES = new Set([
38
+ "planning",
39
+ "running",
40
+ "paused",
41
+ "executing",
42
+ "merging",
43
+ "stopped",
44
+ ]);
45
+
46
+ /**
47
+ * @param {string} projectRoot
48
+ */
49
+ export function resolveOrchestratorBatchPaths(projectRoot) {
50
+ return {
51
+ spine: path.join(projectRoot, SPINE_BATCH_STATE_REL),
52
+ taskplane: path.join(projectRoot, TASKPLANE_BATCH_STATE_REL),
53
+ };
54
+ }
55
+
56
+ /**
57
+ * @param {string} batchStatePath
58
+ * @param {Record<string, unknown>|null} [raw]
59
+ * @returns {OrchestratorSource|null}
60
+ */
61
+ export function classifyBatchStateSource(batchStatePath, raw = null) {
62
+ const normalized = batchStatePath.replace(/\\/g, "/");
63
+ if (normalized.includes("/.spine/")) return "spine";
64
+ if (normalized.includes("/.pi/")) return "taskplane";
65
+ if (raw) return inferBatchStateSourceFromRaw(raw);
66
+ return null;
67
+ }
68
+
69
+ /**
70
+ * @param {Record<string, unknown>} raw
71
+ * @returns {OrchestratorSource|null}
72
+ */
73
+ export function inferBatchStateSourceFromRaw(raw) {
74
+ if (raw.schemaVersion === 1 && (raw.wavePlan != null || raw.resilience != null)) {
75
+ return "spine";
76
+ }
77
+
78
+ const phase = String(raw.phase ?? raw.status ?? "").toLowerCase();
79
+ if (phase === "executing") return "taskplane";
80
+ if (raw.operator != null) return "taskplane";
81
+ if (raw.schemaVersion === 1) return "spine";
82
+
83
+ return null;
84
+ }
85
+
86
+ /**
87
+ * @param {string} filePath
88
+ */
89
+ function loadBatchStateAtPath(filePath) {
90
+ if (!fs.existsSync(filePath)) {
91
+ return { path: null, raw: null, parseError: null, source: null };
92
+ }
93
+
94
+ try {
95
+ const raw = JSON.parse(fs.readFileSync(filePath, "utf-8"));
96
+ return {
97
+ path: filePath,
98
+ raw,
99
+ parseError: null,
100
+ source: classifyBatchStateSource(filePath, raw),
101
+ };
102
+ } catch (err) {
103
+ return {
104
+ path: filePath,
105
+ raw: null,
106
+ parseError: err instanceof Error ? err.message : String(err),
107
+ source: classifyBatchStateSource(filePath, null),
108
+ };
109
+ }
110
+ }
111
+
112
+ /**
113
+ * @param {object} loaded
114
+ * @param {string} projectRoot
115
+ * @param {typeof runReconciliationCheck} runReconciliation
116
+ */
117
+ function isBlockingBatchState(loaded, projectRoot, runReconciliation) {
118
+ if (!loaded.path || loaded.parseError || !loaded.raw) return false;
119
+
120
+ const reconciliation = runReconciliation({
121
+ projectRoot,
122
+ batchState: loaded.raw,
123
+ batchStatePath: loaded.path,
124
+ });
125
+
126
+ if (reconciliation.diagnosis && NON_BLOCKING_DIAGNOSES.has(reconciliation.diagnosis)) {
127
+ return false;
128
+ }
129
+
130
+ if (reconciliation.diagnosis) return true;
131
+
132
+ const phase = String(loaded.raw.phase ?? loaded.raw.status ?? "").toLowerCase();
133
+ const source = loaded.source ?? classifyBatchStateSource(loaded.path, loaded.raw);
134
+
135
+ if (source === "spine") {
136
+ return ACTIVE_PHASES.has(phase) || loaded.raw.endedAt == null;
137
+ }
138
+
139
+ if (source === "taskplane") {
140
+ return TASKPLANE_ACTIVE_PHASES.has(phase) && loaded.raw.endedAt == null;
141
+ }
142
+
143
+ return loaded.raw.endedAt == null;
144
+ }
145
+
146
+ /**
147
+ * @param {object} loaded
148
+ * @param {string} projectRoot
149
+ * @param {boolean} blocking
150
+ * @param {typeof runReconciliationCheck} runReconciliation
151
+ * @returns {OrchestratorBatchSnapshot|null}
152
+ */
153
+ function toSnapshot(loaded, projectRoot, blocking, runReconciliation) {
154
+ if (!loaded.path || !loaded.raw || loaded.parseError) return null;
155
+
156
+ const reconciliation = runReconciliation({
157
+ projectRoot,
158
+ batchState: loaded.raw,
159
+ batchStatePath: loaded.path,
160
+ });
161
+ const parsed = parseBatchState(loaded.raw, loaded.path);
162
+
163
+ return {
164
+ source:
165
+ loaded.source ??
166
+ parsed?.source ??
167
+ classifyBatchStateSource(loaded.path, loaded.raw) ??
168
+ "taskplane",
169
+ path: loaded.path,
170
+ batchId: String(loaded.raw.batchId ?? loaded.raw.id ?? "").trim() || null,
171
+ phase: String(loaded.raw.phase ?? loaded.raw.status ?? null),
172
+ diagnosis: reconciliation.diagnosis ?? null,
173
+ blocking,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * @param {object} ctx
179
+ * @param {string} ctx.projectRoot
180
+ * @param {typeof runReconciliationCheck} [ctx.runReconciliation]
181
+ * @returns {CoexistenceAssessment}
182
+ */
183
+ export function assessOrchestratorCoexistence(ctx) {
184
+ const { projectRoot } = ctx;
185
+ const runReconciliation = ctx.runReconciliation ?? runReconciliationCheck;
186
+ const paths = resolveOrchestratorBatchPaths(projectRoot);
187
+
188
+ const spineLoaded = loadBatchStateAtPath(paths.spine);
189
+ const taskplaneLoaded = loadBatchStateAtPath(paths.taskplane);
190
+
191
+ const spineBlocking = isBlockingBatchState(spineLoaded, projectRoot, runReconciliation);
192
+ const taskplaneBlocking = isBlockingBatchState(taskplaneLoaded, projectRoot, runReconciliation);
193
+
194
+ const spineSnapshot = spineBlocking
195
+ ? toSnapshot(spineLoaded, projectRoot, true, runReconciliation)
196
+ : null;
197
+ const taskplaneSnapshot = taskplaneBlocking
198
+ ? toSnapshot(taskplaneLoaded, projectRoot, true, runReconciliation)
199
+ : null;
200
+
201
+ if (spineBlocking && taskplaneBlocking) {
202
+ const spineId = spineSnapshot?.batchId ?? "unknown";
203
+ const taskplaneId = taskplaneSnapshot?.batchId ?? "unknown";
204
+ return {
205
+ ok: false,
206
+ kind: "dual_active",
207
+ message: `Taskplane batch ${taskplaneId} and pi-spine batch ${spineId} are both active — run only one orchestrator (PRD §22.1)`,
208
+ suggestedCommand: "spine batch dismiss",
209
+ alternatives: [
210
+ "spine batch dismiss",
211
+ "Run spine batch dismiss again if .pi/batch-state.json remains",
212
+ "Abort Taskplane via /orch abort in a Pi session",
213
+ ],
214
+ spine: spineSnapshot,
215
+ taskplane: taskplaneSnapshot,
216
+ };
217
+ }
218
+
219
+ if (taskplaneBlocking) {
220
+ const taskplaneId = taskplaneSnapshot?.batchId ?? "unknown";
221
+ const phase = taskplaneSnapshot?.phase ?? "unknown";
222
+ return {
223
+ ok: false,
224
+ kind: "taskplane_active",
225
+ message: `Taskplane batch ${taskplaneId} is active (phase: ${phase}) in .pi/batch-state.json — dismiss before starting a pi-spine batch`,
226
+ suggestedCommand: "spine batch dismiss",
227
+ alternatives: ["spine status --diagnose", "/orch abort"],
228
+ spine: null,
229
+ taskplane: taskplaneSnapshot,
230
+ };
231
+ }
232
+
233
+ if (spineBlocking) {
234
+ return {
235
+ ok: true,
236
+ kind: "spine_active",
237
+ message: "pi-spine batch active (no Taskplane conflict)",
238
+ suggestedCommand: null,
239
+ alternatives: [],
240
+ spine: spineSnapshot,
241
+ taskplane: null,
242
+ };
243
+ }
244
+
245
+ return {
246
+ ok: true,
247
+ kind: "none",
248
+ message: "no concurrent Taskplane and pi-spine batch state",
249
+ suggestedCommand: null,
250
+ alternatives: [],
251
+ spine: null,
252
+ taskplane: null,
253
+ };
254
+ }
255
+
256
+ /**
257
+ * @param {object} ctx
258
+ * @param {string} ctx.projectRoot
259
+ * @param {typeof runReconciliationCheck} [ctx.runReconciliation]
260
+ */
261
+ export function buildCoexistencePreflightCheck(ctx) {
262
+ const assessment = assessOrchestratorCoexistence(ctx);
263
+
264
+ if (assessment.ok) {
265
+ return {
266
+ id: "orchestrator-coexistence",
267
+ ok: true,
268
+ message: assessment.message,
269
+ };
270
+ }
271
+
272
+ return {
273
+ id: "orchestrator-coexistence",
274
+ ok: false,
275
+ message: assessment.message,
276
+ details: {
277
+ kind: assessment.kind,
278
+ spine: assessment.spine,
279
+ taskplane: assessment.taskplane,
280
+ },
281
+ suggestedCommand: assessment.suggestedCommand,
282
+ alternatives: assessment.alternatives,
283
+ };
284
+ }
285
+
286
+ /**
287
+ * @param {object} ctx
288
+ * @param {string} ctx.projectRoot
289
+ * @param {typeof runReconciliationCheck} [ctx.runReconciliation]
290
+ */
291
+ export function buildCoexistenceDoctorCheck(ctx) {
292
+ const assessment = assessOrchestratorCoexistence(ctx);
293
+
294
+ if (assessment.kind === "none" || assessment.kind === "spine_active") {
295
+ return {
296
+ label: "Taskplane / pi-spine mutual exclusion",
297
+ ok: true,
298
+ detail:
299
+ assessment.kind === "spine_active"
300
+ ? "pi-spine batch only (.spine/batch-state.json)"
301
+ : "no blocking batch in .pi and .spine",
302
+ };
303
+ }
304
+
305
+ return {
306
+ label: "Taskplane / pi-spine mutual exclusion",
307
+ ok: false,
308
+ detail: assessment.message,
309
+ suggestedCommand: assessment.suggestedCommand,
310
+ alternatives: assessment.alternatives,
311
+ };
312
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Doctor warnings for committed `.spine/rules-manifest.json` (SP-093).
3
+ */
4
+
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+
8
+ import {
9
+ discoverCursorRules,
10
+ fingerprintRulesManifest,
11
+ loadRulesManifest,
12
+ RULES_MANIFEST_REL_PATH,
13
+ } from "../config/cursor-rules/discover.mjs";
14
+ import { loadRulesProfile } from "../config/cursor-rules/profile.mjs";
15
+
16
+ export { fingerprintRulesManifest };
17
+
18
+ export const RULES_MANIFEST_MISSING = "RULES_MANIFEST_MISSING";
19
+ export const RULES_MANIFEST_STALE = "RULES_MANIFEST_STALE";
20
+
21
+ /**
22
+ * @param {import("../config/cursor-rules/discover.mjs").CursorRulesManifest} manifest
23
+ */
24
+ export function rulesManifestSummary(manifest) {
25
+ return {
26
+ rules: manifest.rules.length,
27
+ excluded: manifest.excluded.length,
28
+ warnings: manifest.warnings?.length ?? 0,
29
+ };
30
+ }
31
+
32
+ /**
33
+ * @param {string} projectRoot
34
+ * @param {object} [deps]
35
+ * @param {typeof discoverCursorRules} [deps.discoverCursorRules]
36
+ * @param {typeof loadRulesManifest} [deps.loadRulesManifest]
37
+ * @param {typeof loadRulesProfile} [deps.loadRulesProfile]
38
+ */
39
+ export function evaluateRulesManifestState(
40
+ projectRoot,
41
+ {
42
+ discoverCursorRules: discoverFn = discoverCursorRules,
43
+ loadRulesManifest: loadFn = loadRulesManifest,
44
+ loadRulesProfile: loadProfileFn = loadRulesProfile,
45
+ } = {},
46
+ ) {
47
+ const manifestPath = path.join(projectRoot, RULES_MANIFEST_REL_PATH);
48
+ if (!fs.existsSync(manifestPath)) {
49
+ return {
50
+ missing: true,
51
+ stale: false,
52
+ manifest: null,
53
+ manifestPath: RULES_MANIFEST_REL_PATH,
54
+ };
55
+ }
56
+
57
+ const committed = loadFn(projectRoot);
58
+ const profileResult = loadProfileFn(projectRoot);
59
+ if (!profileResult.ok) {
60
+ return {
61
+ missing: false,
62
+ stale: false,
63
+ manifest: committed,
64
+ profileError: profileResult.error,
65
+ };
66
+ }
67
+
68
+ const fresh = discoverFn({
69
+ projectRoot,
70
+ profile: profileResult.profile,
71
+ writeManifest: false,
72
+ });
73
+ const stale =
74
+ committed != null &&
75
+ fresh.manifest != null &&
76
+ fingerprintRulesManifest(committed) !== fingerprintRulesManifest(fresh.manifest);
77
+
78
+ return {
79
+ missing: false,
80
+ stale,
81
+ manifest: committed,
82
+ freshManifest: fresh.manifest,
83
+ };
84
+ }
85
+
86
+ /**
87
+ * @param {string} projectRoot
88
+ */
89
+ export function buildRulesManifestDoctorCheck(projectRoot) {
90
+ const state = evaluateRulesManifestState(projectRoot);
91
+
92
+ if (state.profileError) {
93
+ return {
94
+ label: ".spine/rules-manifest.json fresh",
95
+ ok: true,
96
+ warning: true,
97
+ code: state.profileError.code,
98
+ detail: state.profileError.message,
99
+ suggestedCommand: "fix .spine/rules-profile.json",
100
+ };
101
+ }
102
+
103
+ if (state.missing) {
104
+ return {
105
+ label: ".spine/rules-manifest.json present",
106
+ ok: true,
107
+ warning: true,
108
+ code: RULES_MANIFEST_MISSING,
109
+ detail: "missing — commit manifest after discovery",
110
+ suggestedCommand: "spine rules sync",
111
+ };
112
+ }
113
+
114
+ if (state.stale) {
115
+ const onDisk = state.manifest ? rulesManifestSummary(state.manifest) : { rules: 0, excluded: 0 };
116
+ const fresh = state.freshManifest ? rulesManifestSummary(state.freshManifest) : onDisk;
117
+ return {
118
+ label: ".spine/rules-manifest.json fresh",
119
+ ok: true,
120
+ warning: true,
121
+ code: RULES_MANIFEST_STALE,
122
+ detail: `stale (on disk: ${onDisk.rules} rules; rescan: ${fresh.rules} rules)`,
123
+ suggestedCommand: "spine rules sync",
124
+ };
125
+ }
126
+
127
+ const summary = state.manifest ? rulesManifestSummary(state.manifest) : { rules: 0, excluded: 0 };
128
+ return {
129
+ label: ".spine/rules-manifest.json fresh",
130
+ ok: true,
131
+ detail: `${summary.rules} rules, ${summary.excluded} excluded`,
132
+ };
133
+ }