pi-spine 1.2.0 → 1.3.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 (60) hide show
  1. package/README.md +4 -4
  2. package/bin/spine-cli/verify.mjs +3 -0
  3. package/bin/spine-plan.mjs +49 -1
  4. package/bin/spine-worker-runner.mjs +136 -4
  5. package/package.json +1 -1
  6. package/skills/create-spine-tasks/SKILL.md +7 -2
  7. package/skills/create-spine-tasks/references/contract-template.md +95 -3
  8. package/src/batch/attached-runner.mjs +81 -5
  9. package/src/batch/contract-stub-delivery.mjs +110 -0
  10. package/src/batch/contract-task-start.mjs +204 -0
  11. package/src/batch/contract-verify.mjs +55 -8
  12. package/src/batch/detached-start.mjs +72 -2
  13. package/src/batch/diagnosis-launch-failure.mjs +114 -0
  14. package/src/batch/diagnosis-primary-failure.mjs +89 -0
  15. package/src/batch/diagnosis-tail-state.mjs +57 -0
  16. package/src/batch/diagnosis.mjs +22 -113
  17. package/src/batch/engine-lanes/commit.mjs +145 -0
  18. package/src/batch/engine-lanes/review.mjs +67 -87
  19. package/src/batch/engine-lanes.mjs +21 -79
  20. package/src/batch/engine.mjs +46 -0
  21. package/src/batch/heartbeat.mjs +2 -2
  22. package/src/batch/integrate-assert.mjs +69 -0
  23. package/src/batch/integrate-worktree.mjs +354 -0
  24. package/src/batch/integrate.mjs +195 -102
  25. package/src/batch/journal-rebuild.mjs +48 -2
  26. package/src/batch/journal.mjs +63 -0
  27. package/src/batch/lane-dirty-check.mjs +437 -0
  28. package/src/batch/limbo-detect.mjs +34 -0
  29. package/src/batch/macro-phase.mjs +76 -0
  30. package/src/batch/metrics.mjs +2 -0
  31. package/src/batch/pause.mjs +18 -7
  32. package/src/batch/post-merge-limbo.mjs +3 -28
  33. package/src/batch/reconcile.mjs +79 -9
  34. package/src/batch/resume-common.mjs +27 -0
  35. package/src/batch/resume-multi-lanes.mjs +11 -0
  36. package/src/batch/resume-multi.mjs +2 -0
  37. package/src/batch/resume.mjs +8 -1
  38. package/src/batch/retry.mjs +41 -10
  39. package/src/batch/rules-manifest-drift.mjs +43 -2
  40. package/src/batch/sequence-state.mjs +290 -0
  41. package/src/batch/sequence.mjs +113 -51
  42. package/src/batch/state.mjs +16 -0
  43. package/src/batch/worker-host.mjs +1 -0
  44. package/src/cli/sequence.mjs +14 -1
  45. package/src/cli/settings-set.mjs +33 -3
  46. package/src/config/model-id.mjs +103 -0
  47. package/src/config/spine-init-constants.mjs +1 -0
  48. package/src/config/spine-preflight-lib.mjs +23 -1
  49. package/src/dashboard/public/dashboard.js +14 -3
  50. package/src/dashboard/running-tail-state.mjs +31 -0
  51. package/src/dashboard/server.mjs +4 -0
  52. package/src/dashboard/snapshot.mjs +260 -28
  53. package/src/dashboard/view.mjs +112 -2
  54. package/src/doctor/agent-models.mjs +53 -0
  55. package/src/doctor/batch-size-guidance.mjs +30 -2
  56. package/src/doctor/pi-extension-conflict.mjs +169 -0
  57. package/src/doctor/run-doctor-checks.mjs +6 -0
  58. package/src/planner/scope.mjs +5 -1
  59. package/src/tasks/packet/parse-prompt.mjs +31 -1
  60. package/src/tasks/packet/validate-contract.mjs +108 -0
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Detect pi-web-access duplicate extension sources (GitHub #104, SP-450).
3
+ */
4
+
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+
9
+ /** Tools registered by pi-web-access that collide when loaded twice. */
10
+ export const PI_WEB_ACCESS_TOOL_NAMES = ["web_search", "fetch_content", "get_search_content"];
11
+
12
+ const PI_WEB_ACCESS_PACKAGE_RE = /pi-web-access/i;
13
+
14
+ /**
15
+ * @param {string} [agentDir]
16
+ */
17
+ export function resolvePiAgentDir(agentDir = process.env.PI_AGENT_DIR) {
18
+ if (agentDir && String(agentDir).trim()) {
19
+ return path.resolve(String(agentDir));
20
+ }
21
+ return path.join(os.homedir(), ".pi", "agent");
22
+ }
23
+
24
+ /**
25
+ * @param {string} settingsPath
26
+ * @returns {string[]}
27
+ */
28
+ export function readPiPackageSources(settingsPath) {
29
+ if (!fs.existsSync(settingsPath)) return [];
30
+ try {
31
+ const raw = JSON.parse(fs.readFileSync(settingsPath, "utf-8"));
32
+ const packages = raw?.packages;
33
+ if (!Array.isArray(packages)) return [];
34
+ return packages.map((entry) => String(entry ?? "").trim()).filter(Boolean);
35
+ } catch {
36
+ return [];
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param {string} source
42
+ * @returns {boolean}
43
+ */
44
+ export function isPiWebAccessPackageSource(source) {
45
+ return PI_WEB_ACCESS_PACKAGE_RE.test(String(source ?? ""));
46
+ }
47
+
48
+ /**
49
+ * Resolve a package source entry to an absolute path when possible.
50
+ *
51
+ * @param {string} source
52
+ * @param {string} settingsDir
53
+ * @param {string} [agentDir]
54
+ */
55
+ export function resolvePiPackageSourcePath(source, settingsDir, agentDir = resolvePiAgentDir()) {
56
+ const normalized = String(source ?? "").trim();
57
+ if (!normalized) return null;
58
+ if (normalized.startsWith("npm:")) {
59
+ const pkgName = normalized.slice(4);
60
+ const segments = pkgName.split("/").filter(Boolean);
61
+ return path.join(agentDir, "npm", "node_modules", ...segments);
62
+ }
63
+ if (path.isAbsolute(normalized)) {
64
+ return normalized;
65
+ }
66
+ return path.resolve(settingsDir, normalized);
67
+ }
68
+
69
+ /**
70
+ * @param {object} [options]
71
+ * @param {string} [options.projectRoot]
72
+ * @param {string} [options.agentDir]
73
+ * @returns {{ conflict: boolean, sources: string[], detail: string }}
74
+ */
75
+ export function detectPiWebAccessExtensionConflict({
76
+ projectRoot = process.cwd(),
77
+ agentDir = resolvePiAgentDir(),
78
+ } = {}) {
79
+ /** @type {Set<string>} */
80
+ const resolvedSources = new Set();
81
+ /** @type {string[]} */
82
+ const rawSources = [];
83
+
84
+ const userSettings = path.join(agentDir, "settings.json");
85
+ for (const source of readPiPackageSources(userSettings)) {
86
+ if (!isPiWebAccessPackageSource(source)) continue;
87
+ rawSources.push(source);
88
+ const resolved = resolvePiPackageSourcePath(source, agentDir);
89
+ if (resolved) resolvedSources.add(path.resolve(resolved));
90
+ }
91
+
92
+ const projectSettings = path.join(projectRoot, ".pi", "settings.json");
93
+ for (const source of readPiPackageSources(projectSettings)) {
94
+ if (!isPiWebAccessPackageSource(source)) continue;
95
+ rawSources.push(source);
96
+ const resolved = resolvePiPackageSourcePath(source, path.dirname(projectSettings));
97
+ if (resolved) resolvedSources.add(path.resolve(resolved));
98
+ }
99
+
100
+ const npmDefault = path.join(agentDir, "npm", "node_modules", "pi-web-access");
101
+ if (fs.existsSync(npmDefault)) {
102
+ resolvedSources.add(path.resolve(npmDefault));
103
+ if (!rawSources.some((entry) => entry.startsWith("npm:pi-web-access"))) {
104
+ rawSources.push("npm:pi-web-access");
105
+ }
106
+ }
107
+
108
+ const conflict = resolvedSources.size > 1 || rawSources.length > 1;
109
+ const detail =
110
+ rawSources.length === 0
111
+ ? "no pi-web-access sources detected"
112
+ : conflict
113
+ ? `duplicate pi-web-access sources: ${rawSources.join(", ")}`
114
+ : `single pi-web-access source: ${rawSources[0]}`;
115
+
116
+ return { conflict, sources: [...rawSources], detail };
117
+ }
118
+
119
+ /**
120
+ * Whether batch workers should pass `pi -ne` (skip user extension discovery).
121
+ *
122
+ * @param {object} [options]
123
+ * @param {string} [options.projectRoot]
124
+ * @param {string} [options.agentDir]
125
+ * @returns {boolean}
126
+ */
127
+ export function shouldWorkerUsePiNoExtensions({
128
+ projectRoot = process.cwd(),
129
+ agentDir = resolvePiAgentDir(),
130
+ } = {}) {
131
+ return detectPiWebAccessExtensionConflict({ projectRoot, agentDir }).conflict;
132
+ }
133
+
134
+ /**
135
+ * @param {string} output
136
+ */
137
+ export function isPiExtensionConflictOutput(output) {
138
+ const text = String(output ?? "");
139
+ if (!/conflicts with/i.test(text)) return false;
140
+ return PI_WEB_ACCESS_TOOL_NAMES.some((tool) => text.includes(`Tool "${tool}"`));
141
+ }
142
+
143
+ /**
144
+ * @param {object} [options]
145
+ * @param {string} [options.projectRoot]
146
+ * @param {string} [options.agentDir]
147
+ */
148
+ export function buildPiExtensionConflictDoctorCheck({
149
+ projectRoot = process.cwd(),
150
+ agentDir = resolvePiAgentDir(),
151
+ } = {}) {
152
+ const assessment = detectPiWebAccessExtensionConflict({ projectRoot, agentDir });
153
+ if (!assessment.conflict) {
154
+ return {
155
+ label: "pi-web-access extension conflict",
156
+ ok: true,
157
+ detail: assessment.detail,
158
+ };
159
+ }
160
+
161
+ return {
162
+ label: "pi-web-access extension conflict",
163
+ ok: true,
164
+ warning: true,
165
+ detail: `${assessment.detail} — batch workers pass pi -ne when this conflict is detected; remove duplicate source or run pi remove for npm:pi-web-access`,
166
+ suggestedCommand:
167
+ "pi remove npm:pi-web-access -l || pi remove ../../Documents/github/pi-web-access -l",
168
+ };
169
+ }
@@ -25,6 +25,8 @@ import { buildWorktreeHealthDoctorCheck } from "./worktree-health.mjs";
25
25
  import { buildStaleWorktreesDoctorCheck } from "./stale-worktrees.mjs";
26
26
  import { buildWorkerBackendDoctorCheck } from "../config/worker-backend.mjs";
27
27
  import { buildAgentModelInheritDoctorCheck, buildReviewerPerTypePinsDoctorCheck } from "./agent-model-inherit.mjs";
28
+ import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
29
+ import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
28
30
  import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
29
31
  import { RULES_PROFILE_REL_PATH } from "../config/cursor-rules/profile.mjs";
30
32
  import {
@@ -246,6 +248,7 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
246
248
  record("git installed", commandExists("git"), { detail: getVersion("git") });
247
249
  record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
248
250
  record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
251
+ checks.push(buildPiExtensionConflictDoctorCheck({ projectRoot }));
249
252
 
250
253
  const piVersionText = getVersion("pi");
251
254
  const minPiVersion = getMinPiVersion();
@@ -352,6 +355,9 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
352
355
  config: configResult.config,
353
356
  projectRoot,
354
357
  }));
358
+ const modelIdsCheck = buildAgentModelIdsDoctorCheck({ config: configResult.config });
359
+ checks.push(modelIdsCheck);
360
+ if (!modelIdsCheck.ok) issueCount++;
355
361
  const worktreeHealthCheck = buildWorktreeHealthDoctorCheck({
356
362
  projectRoot,
357
363
  config: configResult.config,
@@ -87,7 +87,11 @@ export function parseScope(scopeArg, { tasksRoot, discoveredTasks }) {
87
87
  if (tokens.length === 1 && tokens[0] === 'pending') {
88
88
  const { pendingIds, excludedCount } = summarizePendingScope(discoveredTasks, tasksRoot);
89
89
  if (pendingIds.length === 0) {
90
- throw new Error(NO_PENDING_TASKS_ERROR);
90
+ const err = new Error(NO_PENDING_TASKS_ERROR);
91
+ err.code = 'NO_PENDING_TASKS';
92
+ err.excludedCount = excludedCount;
93
+ err.discoveredCount = discoveredTasks.length;
94
+ throw err;
91
95
  }
92
96
  return { mode: 'pending', taskIds: pendingIds, excludedCount };
93
97
  }
@@ -382,12 +382,42 @@ function parseContractScalar(raw) {
382
382
  return raw;
383
383
  }
384
384
 
385
+ /** Comma-separated paths inside one backtick pair (authoring anti-pattern). */
386
+ const CONTRACT_COMMA_IN_SINGLE_BACKTICK_RE = /^`[^`,]+,[^`]+`$/;
387
+
388
+ /**
389
+ * Detect contract path-list cells that comma-separate paths inside one backtick wrapper.
390
+ *
391
+ * @param {Record<string, string>} rawFieldValues
392
+ * @param {string[]} fields
393
+ * @returns {string[]}
394
+ */
395
+ export function detectCommaInSingleBacktickPathLists(rawFieldValues, fields) {
396
+ /** @type {string[]} */
397
+ const issues = [];
398
+ for (const field of fields) {
399
+ const value = String(rawFieldValues?.[field] ?? "").trim();
400
+ if (!value) {
401
+ continue;
402
+ }
403
+ if (CONTRACT_COMMA_IN_SINGLE_BACKTICK_RE.test(value)) {
404
+ issues.push(
405
+ `Contract ${field}: comma-separated paths inside one backtick pair; use per-path backticks (e.g. \`path-a\`, \`path-b\`)`,
406
+ );
407
+ }
408
+ }
409
+ return issues;
410
+ }
411
+
385
412
  /**
386
413
  * @param {string} raw
387
414
  * @returns {string[]}
388
415
  */
389
416
  function parseContractPathList(raw) {
390
- return raw
417
+ const trimmed = raw.trim();
418
+ const singleBacktick = trimmed.match(/^`([^`]+)`$/);
419
+ const source = singleBacktick ? singleBacktick[1] : trimmed;
420
+ return source
391
421
  .split(",")
392
422
  .map((part) => parseContractScalar(part.trim()))
393
423
  .filter((part) => part && !isContractNoneValue(part));
@@ -4,6 +4,24 @@
4
4
 
5
5
  import micromatch from "micromatch";
6
6
 
7
+ import { matchesContractPattern } from "../../batch/contract-verify.mjs";
8
+ import { detectCommaInSingleBacktickPathLists } from "./parse-prompt.mjs";
9
+
10
+ /** Operator-facing hint when must-not-change blocks worker orchestration artifacts. */
11
+ export const FILE_SCOPE_MUST_NOT_SPINE_TASKS_FIX_HINT =
12
+ "Remove spine-tasks paths from fileScopeMustNotChange; workers must update STATUS.md, create .DONE, and may write .reviews/. See skills/create-spine-tasks/references/contract-template.md#filescopemustnotchange-semantics";
13
+
14
+ const DEFAULT_TASKS_ROOT = "spine-tasks";
15
+
16
+ /** Probe paths for any task folder orchestration outputs (not the current task id). */
17
+ const SPINE_TASKS_ORCHESTRATION_PROBES = [
18
+ `${DEFAULT_TASKS_ROOT}/SP-999-example-slug/STATUS.md`,
19
+ `${DEFAULT_TASKS_ROOT}/SP-999-example-slug/.DONE`,
20
+ `${DEFAULT_TASKS_ROOT}/SP-999-example-slug/.reviews/1.md`,
21
+ ];
22
+
23
+ const CURRENT_TASK_ORCHESTRATION_SUFFIXES = ["STATUS.md", ".DONE", ".reviews/1.md"];
24
+
7
25
  const GLOB_PROBE = "__probe__.mjs";
8
26
 
9
27
  /**
@@ -70,6 +88,17 @@ export function validateContract(parsed, options = {}) {
70
88
  }
71
89
  }
72
90
 
91
+ for (const authoringIssue of detectCommaInSingleBacktickPathLists(parsed.rawFieldValues ?? {}, [
92
+ "fileScopeMustChange",
93
+ "artifactsMustExist",
94
+ ])) {
95
+ if (mode === "required") {
96
+ errors.push(authoringIssue);
97
+ } else {
98
+ warnings.push(authoringIssue);
99
+ }
100
+ }
101
+
73
102
  for (const field of ["fileScopeMustChange", "fileScopeMustNotChange", "artifactsMustExist"]) {
74
103
  for (const pattern of parsed[field] ?? []) {
75
104
  if (!isValidContractGlob(pattern)) {
@@ -78,9 +107,88 @@ export function validateContract(parsed, options = {}) {
78
107
  }
79
108
  }
80
109
 
110
+ warnings.push(
111
+ ...collectFileScopeMustNotChangeWarnings(parsed, {
112
+ taskId: options.taskId ?? null,
113
+ tasksRoot: options.tasksRoot ?? DEFAULT_TASKS_ROOT,
114
+ }),
115
+ );
116
+
81
117
  return { ok: errors.length === 0, errors, warnings, mode };
82
118
  }
83
119
 
120
+ /**
121
+ * Warn when fileScopeMustNotChange blocks spine-tasks orchestration artifacts (issue #63).
122
+ *
123
+ * @param {ReturnType<import("./parse-prompt.mjs").parseContract>} parsed
124
+ * @param {{ taskId?: string | null, tasksRoot?: string }} [options]
125
+ * @returns {string[]}
126
+ */
127
+ export function collectFileScopeMustNotChangeWarnings(parsed, options = {}) {
128
+ const patterns = parsed?.fileScopeMustNotChange ?? [];
129
+ if (patterns.length === 0) {
130
+ return [];
131
+ }
132
+
133
+ const tasksRoot = options.tasksRoot ?? DEFAULT_TASKS_ROOT;
134
+ const taskId = options.taskId ?? null;
135
+ /** @type {string[]} */
136
+ const warnings = [];
137
+
138
+ for (const pattern of patterns) {
139
+ const bansSpineTasksRoot = patternBlocksSpineTasksOrchestration(pattern, tasksRoot);
140
+ const bansCurrentTaskFolder =
141
+ !bansSpineTasksRoot && patternBlocksCurrentTaskFolder(pattern, taskId, tasksRoot);
142
+
143
+ if (bansSpineTasksRoot) {
144
+ warnings.push(
145
+ `Contract fileScopeMustNotChange: "${pattern}" blocks required worker orchestration artifacts under ${tasksRoot}/. ${FILE_SCOPE_MUST_NOT_SPINE_TASKS_FIX_HINT}`,
146
+ );
147
+ continue;
148
+ }
149
+
150
+ if (bansCurrentTaskFolder) {
151
+ warnings.push(
152
+ `Contract fileScopeMustNotChange: "${pattern}" blocks required worker outputs for this task folder. ${FILE_SCOPE_MUST_NOT_SPINE_TASKS_FIX_HINT}`,
153
+ );
154
+ }
155
+ }
156
+
157
+ return warnings;
158
+ }
159
+
160
+ /**
161
+ * @param {string} pattern
162
+ * @param {string} tasksRoot
163
+ */
164
+ function patternBlocksSpineTasksOrchestration(pattern, tasksRoot) {
165
+ const probes = SPINE_TASKS_ORCHESTRATION_PROBES.map((probe) =>
166
+ probe.replace(DEFAULT_TASKS_ROOT, tasksRoot),
167
+ );
168
+ return probes.some((probe) => matchesContractPattern(probe, pattern));
169
+ }
170
+
171
+ /**
172
+ * @param {string} pattern
173
+ * @param {string | null} taskId
174
+ * @param {string} tasksRoot
175
+ */
176
+ function patternBlocksCurrentTaskFolder(pattern, taskId, tasksRoot) {
177
+ if (!taskId) {
178
+ return false;
179
+ }
180
+
181
+ const slugPrefix = `${tasksRoot}/${taskId}-`;
182
+ const exactPrefix = `${tasksRoot}/${taskId}/`;
183
+ if (!pattern.startsWith(slugPrefix) && !pattern.startsWith(exactPrefix)) {
184
+ return false;
185
+ }
186
+
187
+ const folderBase = pattern.replace(/\/(\*\*|\*)(\/(\*\*|\*))?$/, "");
188
+ const probes = CURRENT_TASK_ORCHESTRATION_SUFFIXES.map((suffix) => `${folderBase}/${suffix}`);
189
+ return probes.some((probe) => matchesContractPattern(probe, pattern));
190
+ }
191
+
84
192
  /**
85
193
  * @param {ReturnType<import("./parse-prompt.mjs").parseContract>} parsed
86
194
  */