pi-spine 2.4.0 → 2.6.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 (38) hide show
  1. package/bin/spine.mjs +22 -0
  2. package/package.json +1 -1
  3. package/src/batch/attached-runner-promote.mjs +95 -11
  4. package/src/batch/blocker-codes.mjs +63 -0
  5. package/src/batch/diagnosis-alternatives.mjs +18 -0
  6. package/src/batch/diagnosis-gate-ready.mjs +23 -0
  7. package/src/batch/diagnosis-pending-lane.mjs +63 -0
  8. package/src/batch/diagnosis-retry-command.mjs +23 -0
  9. package/src/batch/diagnosis-tail-state.mjs +68 -0
  10. package/src/batch/diagnosis.mjs +69 -52
  11. package/src/batch/engine-lanes/commit.mjs +2 -0
  12. package/src/batch/engine-lanes.mjs +2 -3
  13. package/src/batch/evidence-command.mjs +125 -4
  14. package/src/batch/gate-posture-approve.mjs +345 -0
  15. package/src/batch/gate-posture-defaults.mjs +64 -0
  16. package/src/batch/gate-posture-evaluate.mjs +133 -0
  17. package/src/batch/gate-posture-streak.mjs +290 -0
  18. package/src/batch/gate-revision.mjs +95 -0
  19. package/src/batch/gate.mjs +89 -117
  20. package/src/batch/integrate.mjs +1 -0
  21. package/src/batch/lane-commit.mjs +77 -8
  22. package/src/batch/lifecycle-archive.mjs +71 -0
  23. package/src/batch/lifecycle.mjs +27 -67
  24. package/src/batch/orphan-detect.mjs +68 -5
  25. package/src/batch/post-merge-limbo.mjs +137 -22
  26. package/src/batch/reconcile-batch.mjs +40 -43
  27. package/src/batch/reconcile-diagnosis-context.mjs +88 -0
  28. package/src/batch/reconcile-diagnosis.mjs +14 -32
  29. package/src/batch/resume-multi-validate.mjs +51 -9
  30. package/src/batch/retry.mjs +18 -2
  31. package/src/batch/sequence-wait.mjs +20 -6
  32. package/src/config/gate-posture-config.mjs +190 -0
  33. package/src/config/pi-spine-root.mjs +22 -0
  34. package/src/config/spine-config-load.mjs +33 -0
  35. package/src/doctor/duplicate-install.mjs +100 -0
  36. package/src/doctor/run-doctor-checks.mjs +10 -1
  37. package/src/doctor/worktree-health.mjs +4 -0
  38. package/templates/spine-config.json +3 -2
@@ -5,12 +5,38 @@ import path from "node:path";
5
5
  import { applyEnvOverrides } from "./env-overrides.mjs";
6
6
  import { applyConfigDefaults } from "./merge-defaults.mjs";
7
7
  import { validateContractConfig } from "./contract.mjs";
8
+ import { resolveGatePostureConfig } from "./gate-posture-config.mjs";
8
9
  import { validateWorkerBackendConfig } from "./worker-backend.mjs";
9
10
  import { validateWorkerContextConfig } from "./worker-context.mjs";
10
11
  import { validateWorkerLaunchScriptConfig } from "./worker-launch-script.mjs";
11
12
  import { validateWorktreeSetupHookConfig } from "./worktree-setup-hook.mjs";
12
13
  import { validateOrchestratorConfig } from "./spine-config-schema.mjs";
13
14
 
15
+ export { resolveGatePostureConfig } from "./gate-posture-config.mjs";
16
+
17
+ /**
18
+ * Default hook paths skipped at lane commit when config omits ignore paths (SP-640 / #200).
19
+ * Worktree setup hooks commonly `ln -s` `.venv` into lane worktrees; do not stage that symlink.
20
+ */
21
+ export const DEFAULT_WORKTREE_SETUP_IGNORE_PATHS = Object.freeze([".venv"]);
22
+
23
+ /**
24
+ * Resolve effective `worktreeSetupIgnorePaths`, always unioning defaults so hook `.venv`
25
+ * stays ignored. Opt in to committing an ignore path via task `fileScope`, not by clearing config.
26
+ *
27
+ * @param {Record<string, unknown> | null | undefined} config
28
+ * @returns {string[]}
29
+ */
30
+ export function resolveWorktreeSetupIgnorePaths(config) {
31
+ const raw = config?.worktreeSetupIgnorePaths;
32
+ const configured = Array.isArray(raw)
33
+ ? raw
34
+ .filter((/** @type {unknown} */ entry) => typeof entry === "string" && entry.trim())
35
+ .map((/** @type {unknown} */ entry) => /** @type {string} */ (entry).trim())
36
+ : [];
37
+ return [...new Set([...DEFAULT_WORKTREE_SETUP_IGNORE_PATHS, ...configured])];
38
+ }
39
+
14
40
  const REQUIRED_TOP_LEVEL = [
15
41
  "configVersion",
16
42
  "project",
@@ -88,6 +114,9 @@ export function loadSpineConfig(projectRoot) {
88
114
 
89
115
  const config = structuredClone(fileResult.config);
90
116
  applyConfigDefaults(config);
117
+ if (config.worktreeSetupIgnorePaths == null) {
118
+ config.worktreeSetupIgnorePaths = [...DEFAULT_WORKTREE_SETUP_IGNORE_PATHS];
119
+ }
91
120
 
92
121
  const contractError = validateContractConfig(config);
93
122
  if (contractError) {
@@ -107,10 +136,14 @@ export function loadSpineConfig(projectRoot) {
107
136
  };
108
137
  }
109
138
 
139
+ // Soft attach: posture merge fails closed inside the helper and never rejects load.
140
+ const gatePostureConfig = resolveGatePostureConfig(envResult.config);
141
+
110
142
  return {
111
143
  configPath: fileResult.configPath,
112
144
  config: envResult.config,
113
145
  fileConfig: config,
146
+ gatePostureConfig,
114
147
  sources: envResult.sources,
115
148
  envVars: envResult.envVars,
116
149
  error: null,
@@ -82,6 +82,106 @@ export function detectDuplicatePiSpineInstall({
82
82
  };
83
83
  }
84
84
 
85
+ /**
86
+ * Read pi-spine version from a checkout cwd when package.json name matches.
87
+ *
88
+ * @param {string} projectRoot
89
+ * @param {(p: string) => boolean} [exists]
90
+ */
91
+ export function readCheckoutPiSpineVersion(projectRoot, exists = fs.existsSync) {
92
+ const packageJsonPath = path.join(projectRoot, "package.json");
93
+ if (!exists(packageJsonPath)) return null;
94
+ try {
95
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
96
+ if (String(pkg.name ?? "").trim() !== PI_SPINE_PACKAGE_NAME) return null;
97
+ return String(pkg.version ?? "").trim() || null;
98
+ } catch {
99
+ return null;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Detect when the running CLI package version differs from checkout package.json (#204 / SP-648).
105
+ *
106
+ * @param {object} [options]
107
+ * @param {string} [options.runningPackageRoot]
108
+ * @param {string} [options.runningVersion]
109
+ * @param {string} [options.projectRoot]
110
+ * @param {(p: string) => boolean} [options.exists]
111
+ */
112
+ export function detectPathSpineVersionSkew({
113
+ runningPackageRoot,
114
+ runningVersion,
115
+ projectRoot = process.cwd(),
116
+ exists = fs.existsSync,
117
+ } = {}) {
118
+ const cliVersion =
119
+ runningVersion ??
120
+ (runningPackageRoot ? readInstalledPackageVersion(runningPackageRoot) : null);
121
+ const checkoutVersion = readCheckoutPiSpineVersion(projectRoot, exists);
122
+ const checkoutPresent = checkoutVersion != null;
123
+ const skewed =
124
+ checkoutPresent && cliVersion != null && cliVersion !== checkoutVersion;
125
+
126
+ return {
127
+ cliVersion,
128
+ checkoutVersion,
129
+ checkoutPresent,
130
+ skewed,
131
+ projectRoot,
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Remediation when PATH/global CLI skews checkout dogfood (#204).
137
+ */
138
+ export function formatCheckoutVersionSkewRemediation() {
139
+ return "node bin/spine.mjs # or: npm link";
140
+ }
141
+
142
+ /**
143
+ * @param {object} [options]
144
+ * @param {string} [options.runningPackageRoot]
145
+ * @param {string} [options.runningVersion]
146
+ * @param {string} [options.projectRoot]
147
+ * @param {(p: string) => boolean} [options.exists]
148
+ */
149
+ export function buildCheckoutVersionSkewDoctorCheck(options = {}) {
150
+ const assessment = detectPathSpineVersionSkew(options);
151
+
152
+ if (!assessment.checkoutPresent) {
153
+ return {
154
+ label: "pi-spine checkout version skew",
155
+ ok: true,
156
+ detail: "no pi-spine checkout package.json in cwd",
157
+ };
158
+ }
159
+
160
+ if (!assessment.cliVersion) {
161
+ return {
162
+ label: "pi-spine checkout version skew",
163
+ ok: true,
164
+ detail: `checkout v${assessment.checkoutVersion} (running CLI version unknown)`,
165
+ };
166
+ }
167
+
168
+ if (!assessment.skewed) {
169
+ return {
170
+ label: "pi-spine checkout version skew",
171
+ ok: true,
172
+ detail: `running and checkout both v${assessment.cliVersion}`,
173
+ };
174
+ }
175
+
176
+ return {
177
+ label: "pi-spine checkout version skew",
178
+ ok: true,
179
+ warning: true,
180
+ detail: `running v${assessment.cliVersion} vs checkout v${assessment.checkoutVersion}`,
181
+ suggestedCommand: formatCheckoutVersionSkewRemediation(),
182
+ };
183
+ }
184
+
85
185
  /**
86
186
  * Platform-aware remediation when duplicate installs diverge.
87
187
  */
@@ -33,7 +33,10 @@ import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
33
33
  import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
34
34
  import { buildSupervisorConfigDoctorCheck } from "./supervisor.mjs";
35
35
  import { buildAttachedOrphanRiskDoctorCheck } from "./attached-orphan-risk.mjs";
36
- import { buildDuplicateInstallDoctorCheck } from "./duplicate-install.mjs";
36
+ import {
37
+ buildCheckoutVersionSkewDoctorCheck,
38
+ buildDuplicateInstallDoctorCheck,
39
+ } from "./duplicate-install.mjs";
37
40
  import { buildPiCliResolutionDoctorCheck } from "./pi-cli-resolution.mjs";
38
41
  import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
39
42
  import { RULES_PROFILE_REL_PATH } from "../config/cursor-rules/profile.mjs";
@@ -258,6 +261,12 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
258
261
  record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
259
262
  checks.push(buildPiCliResolutionDoctorCheck());
260
263
  checks.push(buildDuplicateInstallDoctorCheck());
264
+ checks.push(
265
+ buildCheckoutVersionSkewDoctorCheck({
266
+ runningPackageRoot: PACKAGE_ROOT,
267
+ projectRoot,
268
+ }),
269
+ );
261
270
  checks.push(buildPiExtensionConflictDoctorCheck({ projectRoot }));
262
271
  checks.push(buildAttachedOrphanRiskDoctorCheck());
263
272
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
+ import { ensureDefaultPiSpineRootEnv } from "../config/pi-spine-root.mjs";
8
9
 
9
10
  /**
10
11
  * @param {string} gitFilePath
@@ -51,6 +52,9 @@ export function buildWorktreeHealthDoctorCheck({ projectRoot, config = {} }) {
51
52
 
52
53
  const hook = config.worktreeSetupHook;
53
54
  const hookConfigured = typeof hook === "string" && hook.trim().length > 0;
55
+ // CLI defaults unset PI_SPINE_ROOT to cwd (SP-643); apply here so doctor
56
+ // library callers get the same behavior without requiring bin/spine.mjs.
57
+ ensureDefaultPiSpineRootEnv();
54
58
  if (!process.env.PI_SPINE_ROOT && hookConfigured) {
55
59
  issues.push("PI_SPINE_ROOT unset with worktreeSetupHook configured");
56
60
  }
@@ -80,10 +80,11 @@
80
80
  },
81
81
  "_examples": {
82
82
  "worktreeSetupHook": "scripts/spine-worktree-setup-flutter.sh",
83
- "_worktreeSetupHookNote": "Optional Flutter: symlink gitignored pubspec assets from SPINE_PROJECT_ROOT into lane worktrees — see docs/adoption/flutter-worktree-guide.md"
83
+ "_worktreeSetupHookNote": "Optional Flutter: symlink gitignored pubspec assets from SPINE_PROJECT_ROOT into lane worktrees — see docs/adoption/flutter-worktree-guide.md",
84
+ "_testingScriptsNote": "testing.build/test/testWithCoverage may use a relative scripts/*.sh path (validated sandbox, no shell metacharacters); e.g. scripts/run-gate-evidence.sh"
84
85
  },
85
86
  "worktreeSetupHook": "",
86
- "worktreeSetupIgnorePaths": [],
87
+ "worktreeSetupIgnorePaths": [".venv"],
87
88
  "referenceDocs": ["docs/constitution.md"],
88
89
  "standards": [],
89
90
  "neverLoad": []