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.
- package/LICENSE +21 -0
- package/README.md +563 -0
- package/bin/get-version.mjs +35 -0
- package/bin/spine-batch.mjs +425 -0
- package/bin/spine-cli/batch.mjs +47 -0
- package/bin/spine-cli/gate.mjs +10 -0
- package/bin/spine-cli/integrate.mjs +10 -0
- package/bin/spine-cli/plan.mjs +12 -0
- package/bin/spine-cli/shared.mjs +73 -0
- package/bin/spine-cli/status.mjs +18 -0
- package/bin/spine-cli/verify.mjs +199 -0
- package/bin/spine-config.mjs +212 -0
- package/bin/spine-dashboard.mjs +178 -0
- package/bin/spine-deps.mjs +69 -0
- package/bin/spine-doctor.mjs +468 -0
- package/bin/spine-gate.mjs +137 -0
- package/bin/spine-init.mjs +398 -0
- package/bin/spine-integrate.mjs +77 -0
- package/bin/spine-journal.mjs +198 -0
- package/bin/spine-migrate-from-taskplane.mjs +136 -0
- package/bin/spine-plan.mjs +83 -0
- package/bin/spine-preflight.mjs +700 -0
- package/bin/spine-report-progress.d.mts +28 -0
- package/bin/spine-report-progress.mjs +126 -0
- package/bin/spine-review-step.d.mts +24 -0
- package/bin/spine-review-step.mjs +124 -0
- package/bin/spine-rules.mjs +35 -0
- package/bin/spine-settings.mjs +186 -0
- package/bin/spine-state.mjs +110 -0
- package/bin/spine-status.mjs +79 -0
- package/bin/spine-tasks.mjs +293 -0
- package/bin/spine-worker-runner.mjs +314 -0
- package/bin/spine.mjs +404 -0
- package/extensions/spine/settings-slash.ts +20 -0
- package/extensions/spine/slash-commands.ts +806 -0
- package/extensions/spine/worker-tools.ts +279 -0
- package/extensions/spine-orchestrator.ts +12 -0
- package/package.json +72 -0
- package/skills/.gitkeep +0 -0
- package/skills/create-spine-tasks/SKILL.md +375 -0
- package/skills/create-spine-tasks/references/context-template.md +25 -0
- package/skills/create-spine-tasks/references/contract-template.md +98 -0
- package/skills/create-spine-tasks/references/explore-template.md +63 -0
- package/skills/create-spine-tasks/references/prompt-template.md +276 -0
- package/src/batch/abort.mjs +272 -0
- package/src/batch/agent-session-worker.mjs +297 -0
- package/src/batch/batch-state-io.mjs +53 -0
- package/src/batch/contract-verify.mjs +310 -0
- package/src/batch/detached-start.mjs +778 -0
- package/src/batch/diagnosis.mjs +378 -0
- package/src/batch/engine-lanes/merge.mjs +632 -0
- package/src/batch/engine-lanes/queue.mjs +208 -0
- package/src/batch/engine-lanes/review.mjs +970 -0
- package/src/batch/engine-lanes.mjs +388 -0
- package/src/batch/engine-scope.mjs +251 -0
- package/src/batch/engine.mjs +445 -0
- package/src/batch/evidence-command.mjs +157 -0
- package/src/batch/evidence.mjs +203 -0
- package/src/batch/gate.mjs +359 -0
- package/src/batch/git-commit-env.mjs +46 -0
- package/src/batch/git-exec.mjs +26 -0
- package/src/batch/heartbeat.mjs +430 -0
- package/src/batch/integrate.mjs +414 -0
- package/src/batch/journal-rebuild.mjs +388 -0
- package/src/batch/journal.mjs +373 -0
- package/src/batch/lane-commit.mjs +153 -0
- package/src/batch/lifecycle.mjs +364 -0
- package/src/batch/metrics.mjs +265 -0
- package/src/batch/orphan-detect.mjs +210 -0
- package/src/batch/post-merge-limbo.mjs +80 -0
- package/src/batch/postmortem.mjs +296 -0
- package/src/batch/readers/spine-state.mjs +95 -0
- package/src/batch/readers/taskplane-state.mjs +136 -0
- package/src/batch/reconcile.mjs +729 -0
- package/src/batch/resume-common.mjs +104 -0
- package/src/batch/resume-engine.mjs +66 -0
- package/src/batch/resume-multi-lanes.mjs +479 -0
- package/src/batch/resume-multi-validate.mjs +187 -0
- package/src/batch/resume-multi.mjs +254 -0
- package/src/batch/resume.mjs +475 -0
- package/src/batch/retry.mjs +257 -0
- package/src/batch/review-scope.mjs +136 -0
- package/src/batch/review.mjs +1045 -0
- package/src/batch/salvage.mjs +332 -0
- package/src/batch/state.mjs +680 -0
- package/src/batch/task-stall-budget.mjs +88 -0
- package/src/batch/worker-host.mjs +683 -0
- package/src/batch/worker-output.mjs +253 -0
- package/src/batch/worker-prompt.mjs +84 -0
- package/src/batch/worktree.mjs +290 -0
- package/src/cli/deps.mjs +141 -0
- package/src/cli/handoff.mjs +364 -0
- package/src/cli/rules.mjs +429 -0
- package/src/cli/settings-set.mjs +171 -0
- package/src/cli/settings-show.mjs +140 -0
- package/src/cli/settings-slash.mjs +107 -0
- package/src/config/contract.mjs +56 -0
- package/src/config/cursor-rules/discover.mjs +416 -0
- package/src/config/cursor-rules/index.mjs +39 -0
- package/src/config/cursor-rules/match-globs.mjs +132 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
- package/src/config/cursor-rules/priority.mjs +26 -0
- package/src/config/cursor-rules/profile.mjs +403 -0
- package/src/config/cursor-rules/select.mjs +259 -0
- package/src/config/defaults.mjs +36 -0
- package/src/config/env-overrides.mjs +207 -0
- package/src/config/merge-defaults.mjs +47 -0
- package/src/config/pi-spine-root.mjs +93 -0
- package/src/config/reviewer-context.mjs +243 -0
- package/src/config/settings-fields.mjs +265 -0
- package/src/config/worker-backend.mjs +116 -0
- package/src/config/worker-context.mjs +402 -0
- package/src/config/worker-launch-script.mjs +130 -0
- package/src/config/worktree-setup-hook.mjs +122 -0
- package/src/dashboard/public/dashboard.css +77 -0
- package/src/dashboard/public/dashboard.js +349 -0
- package/src/dashboard/public/index.html +80 -0
- package/src/dashboard/server.mjs +155 -0
- package/src/dashboard/snapshot.mjs +414 -0
- package/src/dashboard/sse.mjs +15 -0
- package/src/dashboard/view.mjs +292 -0
- package/src/doctor/agent-model-inherit.mjs +101 -0
- package/src/doctor/batch-size-guidance.mjs +72 -0
- package/src/doctor/coexistence.mjs +312 -0
- package/src/doctor/rules-manifest.mjs +133 -0
- package/src/doctor/stale-path.mjs +156 -0
- package/src/doctor/stall-config.mjs +108 -0
- package/src/doctor/suggest-max-parallel.mjs +53 -0
- package/src/doctor/task-packet-size.mjs +110 -0
- package/src/doctor/worktree-health.mjs +71 -0
- package/src/migrate/taskplane-config.mjs +116 -0
- package/src/planner/cycles.mjs +63 -0
- package/src/planner/format-plan.mjs +132 -0
- package/src/planner/graph.mjs +99 -0
- package/src/planner/index.mjs +125 -0
- package/src/planner/lanes.mjs +111 -0
- package/src/planner/pending.mjs +39 -0
- package/src/planner/scope.mjs +142 -0
- package/src/process/liveness.mjs +21 -0
- package/src/tasks/packet/discover.mjs +40 -0
- package/src/tasks/packet/index.mjs +81 -0
- package/src/tasks/packet/merge-deps.mjs +79 -0
- package/src/tasks/packet/parse-prompt.mjs +445 -0
- package/src/tasks/packet/parse-status.mjs +118 -0
- package/src/tasks/packet/validate-contract.mjs +115 -0
- package/src/tasks/packet/validate-prompt.mjs +99 -0
- package/src/worker-tools/report-progress.d.mts +18 -0
- package/src/worker-tools/report-progress.mjs +59 -0
- package/src/worker-tools/request-gate.d.mts +17 -0
- package/src/worker-tools/request-gate.mjs +54 -0
- package/templates/agents/reviewer.md +123 -0
- package/templates/agents/supervisor.md +59 -0
- package/templates/agents/worker.md +122 -0
- package/templates/rules-profile.json +27 -0
- package/templates/spine-config.json +64 -0
- package/templates/tasks/CONTEXT.md +30 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolve `spine` on PATH via `which` (injectable for tests).
|
|
7
|
+
* @param {(cmd: string) => string | null} [which]
|
|
8
|
+
* @returns {string | null} absolute path to spine binary, or null
|
|
9
|
+
*/
|
|
10
|
+
export function resolveSpineOnPath(which = defaultWhich) {
|
|
11
|
+
return which("spine");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function defaultWhich(cmd) {
|
|
15
|
+
try {
|
|
16
|
+
const out = execFileSync("which", [cmd], {
|
|
17
|
+
encoding: "utf-8",
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19
|
+
});
|
|
20
|
+
const resolved = out.trim().split(/\r?\n/)[0]?.trim();
|
|
21
|
+
return resolved || null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} packageRoot
|
|
29
|
+
*/
|
|
30
|
+
export function readPackageVersion(packageRoot) {
|
|
31
|
+
try {
|
|
32
|
+
const pkg = JSON.parse(
|
|
33
|
+
fs.readFileSync(path.join(packageRoot, "package.json"), "utf-8"),
|
|
34
|
+
);
|
|
35
|
+
return pkg.version ?? "unknown";
|
|
36
|
+
} catch {
|
|
37
|
+
return "unknown";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run `node spine.mjs --version` and parse package version line.
|
|
43
|
+
* @param {string} spinePath
|
|
44
|
+
* @param {(cmd: string, args: string[], opts?: object) => { status: number | null, stdout?: string, stderr?: string }} [spawn]
|
|
45
|
+
*/
|
|
46
|
+
export function readSpineCliVersion(spinePath, spawn = spawnSync) {
|
|
47
|
+
const result = spawn(process.execPath, [spinePath, "--version"], {
|
|
48
|
+
encoding: "utf-8",
|
|
49
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
50
|
+
timeout: 30_000,
|
|
51
|
+
});
|
|
52
|
+
if (result.status !== 0) return null;
|
|
53
|
+
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
|
|
54
|
+
const match = output.match(/v(\d+\.\d+\.\d+)/);
|
|
55
|
+
return match?.[1] ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} filePath
|
|
60
|
+
* @param {(p: string) => string} [realpathFn]
|
|
61
|
+
*/
|
|
62
|
+
function safeRealpath(filePath, realpathFn = fs.realpathSync) {
|
|
63
|
+
try {
|
|
64
|
+
return realpathFn(filePath);
|
|
65
|
+
} catch {
|
|
66
|
+
return path.resolve(filePath);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Compare PATH `spine` with this package's bin/spine.mjs (version and mtime).
|
|
72
|
+
*
|
|
73
|
+
* @param {{
|
|
74
|
+
* packageRoot: string,
|
|
75
|
+
* runningSpinePath?: string,
|
|
76
|
+
* which?: (cmd: string) => string | null,
|
|
77
|
+
* spawn?: typeof spawnSync,
|
|
78
|
+
* stat?: typeof fs.statSync,
|
|
79
|
+
* realpath?: (p: string) => string,
|
|
80
|
+
* }} args
|
|
81
|
+
*/
|
|
82
|
+
export function buildStalePathDoctorCheck({
|
|
83
|
+
packageRoot,
|
|
84
|
+
runningSpinePath,
|
|
85
|
+
which,
|
|
86
|
+
spawn,
|
|
87
|
+
stat = fs.statSync,
|
|
88
|
+
realpath = fs.realpathSync,
|
|
89
|
+
}) {
|
|
90
|
+
const repoSpinePath = path.join(packageRoot, "bin", "spine.mjs");
|
|
91
|
+
const pathSpine = resolveSpineOnPath(which);
|
|
92
|
+
|
|
93
|
+
if (!pathSpine) {
|
|
94
|
+
return {
|
|
95
|
+
label: "spine on PATH",
|
|
96
|
+
ok: true,
|
|
97
|
+
warning: true,
|
|
98
|
+
detail: "not found (use npm link, npx spine, or node bin/spine.mjs)",
|
|
99
|
+
suggestedCommand: `cd ${packageRoot} && npm link`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const pathResolved = safeRealpath(pathSpine, realpath);
|
|
104
|
+
const repoResolved = safeRealpath(repoSpinePath, realpath);
|
|
105
|
+
const runningResolved = runningSpinePath
|
|
106
|
+
? safeRealpath(runningSpinePath, realpath)
|
|
107
|
+
: repoResolved;
|
|
108
|
+
|
|
109
|
+
if (pathResolved === repoResolved || pathResolved === runningResolved) {
|
|
110
|
+
return {
|
|
111
|
+
label: "spine on PATH",
|
|
112
|
+
ok: true,
|
|
113
|
+
detail: pathSpine,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let pathMtime;
|
|
118
|
+
let repoMtime;
|
|
119
|
+
try {
|
|
120
|
+
pathMtime = stat(pathSpine).mtimeMs;
|
|
121
|
+
repoMtime = stat(repoSpinePath).mtimeMs;
|
|
122
|
+
} catch {
|
|
123
|
+
return {
|
|
124
|
+
label: "spine on PATH",
|
|
125
|
+
ok: true,
|
|
126
|
+
warning: true,
|
|
127
|
+
detail: `PATH: ${pathSpine} (could not stat vs ${repoSpinePath})`,
|
|
128
|
+
suggestedCommand: `cd ${packageRoot} && npm link`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const repoVersion = readPackageVersion(packageRoot);
|
|
133
|
+
const pathVersion = readSpineCliVersion(pathSpine, spawn) ?? "unknown";
|
|
134
|
+
const versionStale = pathVersion !== "unknown" && pathVersion !== repoVersion;
|
|
135
|
+
const mtimeStale = pathMtime !== repoMtime;
|
|
136
|
+
|
|
137
|
+
if (!versionStale && !mtimeStale) {
|
|
138
|
+
return {
|
|
139
|
+
label: "spine on PATH",
|
|
140
|
+
ok: true,
|
|
141
|
+
detail: `${pathSpine} (same version/mtime as package)`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const reasons = [];
|
|
146
|
+
if (versionStale) reasons.push(`PATH v${pathVersion} vs package v${repoVersion}`);
|
|
147
|
+
if (mtimeStale) reasons.push("binary mtime differs from checkout");
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
label: "spine on PATH (stale)",
|
|
151
|
+
ok: true,
|
|
152
|
+
warning: true,
|
|
153
|
+
detail: `${pathSpine} — ${reasons.join("; ")}`,
|
|
154
|
+
suggestedCommand: `cd ${packageRoot} && npm link`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor warnings for stall config when running real pi workers (SP-087).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_PI_WORKER_TIMEOUT_MS,
|
|
7
|
+
resolveTaskStallMinutes,
|
|
8
|
+
} from "../batch/task-stall-budget.mjs";
|
|
9
|
+
|
|
10
|
+
const DEFAULT_IMPLICIT_STALL_MIN = 60;
|
|
11
|
+
const RECOMMENDED_STALL_MIN = 120;
|
|
12
|
+
const RUNNER_IMPLICIT_PI_TIMEOUT_MIN = DEFAULT_PI_WORKER_TIMEOUT_MS / 60_000;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
export function isStubWorkerMode() {
|
|
18
|
+
const stub = process.env.SPINE_WORKER_STUB;
|
|
19
|
+
return stub === "1" || stub === "true";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} [config]
|
|
24
|
+
*/
|
|
25
|
+
export function resolveConfiguredStallMinutes(config = {}) {
|
|
26
|
+
const raw = Number(config.lanes?.stallTimeoutMinutes);
|
|
27
|
+
return Number.isFinite(raw) && raw > 0 ? raw : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {object} params
|
|
32
|
+
* @param {object} [params.config]
|
|
33
|
+
*/
|
|
34
|
+
export function buildStallConfigDoctorCheck({ config = {} }) {
|
|
35
|
+
if (isStubWorkerMode()) {
|
|
36
|
+
return {
|
|
37
|
+
label: "lanes.stallTimeoutMinutes (real pi)",
|
|
38
|
+
ok: true,
|
|
39
|
+
detail: "SPINE_WORKER_STUB set — stall defaults not required",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const configured = resolveConfiguredStallMinutes(config);
|
|
44
|
+
if (configured === null) {
|
|
45
|
+
return {
|
|
46
|
+
label: "lanes.stallTimeoutMinutes (real pi)",
|
|
47
|
+
ok: true,
|
|
48
|
+
warning: true,
|
|
49
|
+
detail: `unset (implicit ${DEFAULT_IMPLICIT_STALL_MIN}m) — set ≥${RECOMMENDED_STALL_MIN} for long pi tasks`,
|
|
50
|
+
suggestedCommand: "spine settings set lanes.stallTimeoutMinutes 120",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (configured <= DEFAULT_IMPLICIT_STALL_MIN) {
|
|
55
|
+
return {
|
|
56
|
+
label: "lanes.stallTimeoutMinutes (real pi)",
|
|
57
|
+
ok: true,
|
|
58
|
+
warning: true,
|
|
59
|
+
detail: `${configured}m is low for M/L tasks — recommend ≥${RECOMMENDED_STALL_MIN}`,
|
|
60
|
+
suggestedCommand: "spine settings set lanes.stallTimeoutMinutes 120",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
label: "lanes.stallTimeoutMinutes (real pi)",
|
|
66
|
+
ok: true,
|
|
67
|
+
detail: `${configured}m`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {object} params
|
|
73
|
+
* @param {object} [params.config]
|
|
74
|
+
*/
|
|
75
|
+
export function buildPiWorkerTimeoutDoctorCheck({ config = {} }) {
|
|
76
|
+
if (isStubWorkerMode()) {
|
|
77
|
+
return {
|
|
78
|
+
label: "pi worker timeout (real pi)",
|
|
79
|
+
ok: true,
|
|
80
|
+
detail: "SPINE_WORKER_STUB set — pi subprocess timeout not used",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (process.env.SPINE_WORKER_PI_TIMEOUT_MS) {
|
|
85
|
+
const minutes = Math.round(Number(process.env.SPINE_WORKER_PI_TIMEOUT_MS) / 60_000);
|
|
86
|
+
return {
|
|
87
|
+
label: "pi worker timeout (real pi)",
|
|
88
|
+
ok: true,
|
|
89
|
+
detail: `SPINE_WORKER_PI_TIMEOUT_MS override (${minutes}m)`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const configured = resolveConfiguredStallMinutes(config) ?? DEFAULT_IMPLICIT_STALL_MIN;
|
|
94
|
+
const mFloorMinutes = resolveTaskStallMinutes("M", config);
|
|
95
|
+
if (mFloorMinutes > RUNNER_IMPLICIT_PI_TIMEOUT_MIN) {
|
|
96
|
+
return {
|
|
97
|
+
label: "pi worker timeout (real pi)",
|
|
98
|
+
ok: true,
|
|
99
|
+
detail: `follows stall budget (M tasks ≥${mFloorMinutes}m; configured ${configured}m)`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
label: "pi worker timeout (real pi)",
|
|
105
|
+
ok: true,
|
|
106
|
+
detail: `aligned with stall budget (≥${configured}m)`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
|
|
3
|
+
const MIN_SUGGESTED = 1;
|
|
4
|
+
const MAX_SUGGESTED = 4;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Physical/logical CPU count for sizing hints only.
|
|
8
|
+
* Lanes are parallel agents and git worktrees — never set maxParallel = cpuCount.
|
|
9
|
+
*/
|
|
10
|
+
export function detectCpuCount() {
|
|
11
|
+
return os.availableParallelism?.() ?? os.cpus().length;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function clamp(min, max, value) {
|
|
15
|
+
return Math.min(max, Math.max(min, value));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Conservative maxParallel suggestion (heuristic v1).
|
|
20
|
+
* suggested = clamp(1, 4, floor(cpuCount / 2)) — do not use cpuCount as maxParallel.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} cpuCount
|
|
23
|
+
* @returns {{ suggested: number, rationale: string }}
|
|
24
|
+
*/
|
|
25
|
+
export function suggestMaxParallel(cpuCount) {
|
|
26
|
+
const raw = Math.floor(cpuCount / 2);
|
|
27
|
+
const suggested = clamp(MIN_SUGGESTED, MAX_SUGGESTED, raw);
|
|
28
|
+
const rationale =
|
|
29
|
+
"lanes are parallel agents/worktrees, not CPU threads; cap limits API cost, supervision, and merge risk";
|
|
30
|
+
return { suggested, rationale };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {{ configured: number, cpuCount: number }} args
|
|
35
|
+
*/
|
|
36
|
+
export function buildMaxParallelDoctorCheck({ configured, cpuCount }) {
|
|
37
|
+
const { suggested, rationale } = suggestMaxParallel(cpuCount);
|
|
38
|
+
const overParallel = configured > suggested + 1;
|
|
39
|
+
const detail = `configured=${configured}, suggested=${suggested} (${cpuCount} CPU threads) — ${rationale}`;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
label: "lanes.maxParallel sizing",
|
|
43
|
+
ok: true,
|
|
44
|
+
warning: overParallel,
|
|
45
|
+
detail,
|
|
46
|
+
...(overParallel
|
|
47
|
+
? {
|
|
48
|
+
suggestedCommand:
|
|
49
|
+
"edit .spine/spine-config.json → lanes.maxParallel (advisory only)",
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor warnings for oversized task packets (SP-086).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { discoverTasks } from "../tasks/packet/discover.mjs";
|
|
7
|
+
import { loadTaskPacket } from "../tasks/packet/index.mjs";
|
|
8
|
+
|
|
9
|
+
const MAX_IMPLEMENTATION_STEPS = 4;
|
|
10
|
+
const MAX_FILE_SCOPE_ENTRIES = 8;
|
|
11
|
+
const SIZE_LINE_RE = /^\*\*Size:\*\*\s*(S|M|L|XL)\s*$/im;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} folderPath
|
|
15
|
+
*/
|
|
16
|
+
function isPendingTask(folderPath) {
|
|
17
|
+
return !fs.existsSync(`${folderPath}/.DONE`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} promptMarkdown
|
|
22
|
+
*/
|
|
23
|
+
function parseSizeLine(promptMarkdown) {
|
|
24
|
+
const match = SIZE_LINE_RE.exec(promptMarkdown);
|
|
25
|
+
return match ? match[1].toUpperCase() : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} prompt
|
|
30
|
+
*/
|
|
31
|
+
function countImplementationSteps(prompt) {
|
|
32
|
+
return (prompt.steps ?? []).filter(
|
|
33
|
+
(step) => !/testing|verification|documentation|delivery/i.test(step.title),
|
|
34
|
+
).length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {object} params
|
|
39
|
+
* @param {string} params.tasksRoot
|
|
40
|
+
*/
|
|
41
|
+
export function collectTaskPacketSizeIssues({ tasksRoot }) {
|
|
42
|
+
if (!tasksRoot || !fs.existsSync(tasksRoot)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @type {string[]} */
|
|
47
|
+
const issues = [];
|
|
48
|
+
for (const discovered of discoverTasks(tasksRoot)) {
|
|
49
|
+
if (!isPendingTask(discovered.folderPath)) continue;
|
|
50
|
+
|
|
51
|
+
const promptMarkdown = fs.readFileSync(discovered.promptPath, "utf-8");
|
|
52
|
+
const size = parseSizeLine(promptMarkdown);
|
|
53
|
+
|
|
54
|
+
const packet = loadTaskPacket(discovered.folderPath);
|
|
55
|
+
if (!packet.validation?.ok) {
|
|
56
|
+
if (size === "XL") {
|
|
57
|
+
issues.push(`${discovered.taskId}: Size XL — must split into multiple tasks`);
|
|
58
|
+
}
|
|
59
|
+
for (const err of packet.validation?.errors ?? []) {
|
|
60
|
+
if (/Size XL/i.test(err)) {
|
|
61
|
+
issues.push(`${discovered.taskId}: ${err}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const prompt = packet.prompt;
|
|
68
|
+
const implSteps = countImplementationSteps(prompt);
|
|
69
|
+
const fileScopeCount = prompt.fileScope?.length ?? 0;
|
|
70
|
+
|
|
71
|
+
if (size === "XL") {
|
|
72
|
+
issues.push(`${discovered.taskId}: Size XL — must split into multiple tasks`);
|
|
73
|
+
} else if (size === "L") {
|
|
74
|
+
issues.push(`${discovered.taskId}: Size L — prefer splitting into S/M deliverables`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (implSteps > MAX_IMPLEMENTATION_STEPS) {
|
|
78
|
+
issues.push(
|
|
79
|
+
`${discovered.taskId}: ${implSteps} implementation steps (max ${MAX_IMPLEMENTATION_STEPS}) — split task`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (fileScopeCount > MAX_FILE_SCOPE_ENTRIES) {
|
|
84
|
+
issues.push(
|
|
85
|
+
`${discovered.taskId}: ${fileScopeCount} file-scope entries (max ${MAX_FILE_SCOPE_ENTRIES}) — narrow scope or split`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return issues;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {object} params
|
|
95
|
+
* @param {string} params.tasksRoot
|
|
96
|
+
*/
|
|
97
|
+
export function buildTaskPacketSizeDoctorCheck({ tasksRoot }) {
|
|
98
|
+
const issues = collectTaskPacketSizeIssues({ tasksRoot });
|
|
99
|
+
return {
|
|
100
|
+
label: "task packet sizing (pending tasks)",
|
|
101
|
+
ok: true,
|
|
102
|
+
warning: issues.length > 0,
|
|
103
|
+
detail:
|
|
104
|
+
issues.length === 0 ? "no oversized pending packets" : issues.slice(0, 5).join("; "),
|
|
105
|
+
suggestedCommand:
|
|
106
|
+
issues.length > 0 ? "Review skills/create-spine-tasks — split oversized tasks" : undefined,
|
|
107
|
+
issueCount: issues.length,
|
|
108
|
+
issues,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor checks for lane worktree / devcontainer health (FR-REL-11, SP-101–105).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} gitFilePath
|
|
10
|
+
* @returns {string|null}
|
|
11
|
+
*/
|
|
12
|
+
function readGitdirPointer(gitFilePath) {
|
|
13
|
+
if (!fs.existsSync(gitFilePath)) return null;
|
|
14
|
+
const content = fs.readFileSync(gitFilePath, "utf-8").trim();
|
|
15
|
+
const match = content.match(/^gitdir:\s*(.+)$/m);
|
|
16
|
+
return match ? match[1].trim() : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} params
|
|
21
|
+
* @param {string} params.projectRoot
|
|
22
|
+
* @param {object} [params.config]
|
|
23
|
+
*/
|
|
24
|
+
export function buildWorktreeHealthDoctorCheck({ projectRoot, config = {} }) {
|
|
25
|
+
const worktreesRoot = path.join(projectRoot, ".worktrees");
|
|
26
|
+
if (!fs.existsSync(worktreesRoot)) {
|
|
27
|
+
return {
|
|
28
|
+
label: "lane worktree health",
|
|
29
|
+
ok: true,
|
|
30
|
+
detail: "no .worktrees/ yet",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {string[]} */
|
|
35
|
+
const issues = [];
|
|
36
|
+
const entries = fs.readdirSync(worktreesRoot, { withFileTypes: true });
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
if (!entry.isDirectory()) continue;
|
|
39
|
+
const batchDir = path.join(worktreesRoot, entry.name);
|
|
40
|
+
const laneDirs = fs.readdirSync(batchDir, { withFileTypes: true });
|
|
41
|
+
for (const lane of laneDirs) {
|
|
42
|
+
if (!lane.isDirectory() || !lane.name.startsWith("lane-")) continue;
|
|
43
|
+
const gitFile = path.join(batchDir, lane.name, ".git");
|
|
44
|
+
const gitdir = readGitdirPointer(gitFile);
|
|
45
|
+
if (gitdir && path.isAbsolute(gitdir)) {
|
|
46
|
+
issues.push(`${entry.name}/${lane.name}: absolute gitdir`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const hook = config.lanes?.worktreeSetupHook;
|
|
52
|
+
const hookConfigured = typeof hook === "string" && hook.trim().length > 0;
|
|
53
|
+
if (!process.env.PI_SPINE_ROOT && hookConfigured) {
|
|
54
|
+
issues.push("PI_SPINE_ROOT unset with worktreeSetupHook configured");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (issues.length === 0) {
|
|
58
|
+
return {
|
|
59
|
+
label: "lane worktree health",
|
|
60
|
+
ok: true,
|
|
61
|
+
detail: "relative gitdir pointers; PI_SPINE_ROOT ok",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
label: "lane worktree health",
|
|
67
|
+
ok: false,
|
|
68
|
+
detail: issues.slice(0, 3).join("; "),
|
|
69
|
+
suggestion: "spine doctor; see docs/incidents/20260605-lane-worktree-devcontainer.md",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { loadSpineConfigTemplate } from "../../bin/spine-init.mjs";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_TASKPLANE_SOURCE_PATH = ".pi/taskplane-config.json";
|
|
5
|
+
export const defaultTaskplaneSourcePath = DEFAULT_TASKPLANE_SOURCE_PATH;
|
|
6
|
+
|
|
7
|
+
const MAX_PARALLEL_CAP = 8;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {unknown} value
|
|
11
|
+
* @returns {number}
|
|
12
|
+
*/
|
|
13
|
+
export function mapMaxParallel(value) {
|
|
14
|
+
const parsed = Number(value);
|
|
15
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
16
|
+
return 3;
|
|
17
|
+
}
|
|
18
|
+
return Math.min(Math.floor(parsed), MAX_PARALLEL_CAP);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} sourcePath
|
|
23
|
+
* @returns {object}
|
|
24
|
+
*/
|
|
25
|
+
export function loadTaskplaneConfig(sourcePath) {
|
|
26
|
+
if (!sourcePath || typeof sourcePath !== "string") {
|
|
27
|
+
throw new Error("Taskplane config source path is required.");
|
|
28
|
+
}
|
|
29
|
+
if (!fs.existsSync(sourcePath)) {
|
|
30
|
+
throw new Error(`Taskplane config not found: ${sourcePath}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(fs.readFileSync(sourcePath, "utf-8"));
|
|
36
|
+
} catch (err) {
|
|
37
|
+
throw new Error(`Cannot parse Taskplane config: ${err.message}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
41
|
+
throw new Error("Taskplane config must be a JSON object.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {object} commands
|
|
49
|
+
* @returns {{ build: string, test: string, testWithCoverage: string }}
|
|
50
|
+
*/
|
|
51
|
+
function mapTestingCommands(commands) {
|
|
52
|
+
const unit = typeof commands?.unit === "string" ? commands.unit.trim() : "";
|
|
53
|
+
const build = typeof commands?.build === "string" ? commands.build.trim() : "";
|
|
54
|
+
const test =
|
|
55
|
+
(typeof commands?.test === "string" ? commands.test.trim() : "") ||
|
|
56
|
+
unit ||
|
|
57
|
+
"";
|
|
58
|
+
const testWithCoverage =
|
|
59
|
+
(typeof commands?.testWithCoverage === "string" ? commands.testWithCoverage.trim() : "") ||
|
|
60
|
+
(typeof commands?.coverage === "string" ? commands.coverage.trim() : "") ||
|
|
61
|
+
"";
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
build,
|
|
65
|
+
test,
|
|
66
|
+
testWithCoverage,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {object} taskplaneConfig
|
|
72
|
+
* @param {{ tasksRootOverride?: string }} [options]
|
|
73
|
+
* @returns {object}
|
|
74
|
+
*/
|
|
75
|
+
export function mapTaskplaneToSpine(taskplaneConfig, { tasksRootOverride } = {}) {
|
|
76
|
+
const template = loadSpineConfigTemplate();
|
|
77
|
+
const config = structuredClone(template);
|
|
78
|
+
|
|
79
|
+
const taskRunner = taskplaneConfig.taskRunner ?? {};
|
|
80
|
+
const orchestrator = taskplaneConfig.orchestrator?.orchestrator ?? taskplaneConfig.orchestrator ?? {};
|
|
81
|
+
|
|
82
|
+
const tasksRoot =
|
|
83
|
+
(typeof tasksRootOverride === "string" && tasksRootOverride.trim()) ||
|
|
84
|
+
(typeof taskRunner.paths?.tasks === "string" && taskRunner.paths.tasks.trim()) ||
|
|
85
|
+
config.paths.tasksRoot;
|
|
86
|
+
|
|
87
|
+
config.paths.tasksRoot = tasksRoot;
|
|
88
|
+
|
|
89
|
+
if (typeof taskRunner.project?.name === "string" && taskRunner.project.name.trim()) {
|
|
90
|
+
config.project.name = taskRunner.project.name.trim();
|
|
91
|
+
}
|
|
92
|
+
if (typeof taskRunner.project?.description === "string") {
|
|
93
|
+
config.project.description = taskRunner.project.description;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const testing = mapTestingCommands(taskRunner.testing?.commands ?? taskRunner.testing ?? {});
|
|
97
|
+
config.testing.build = testing.build;
|
|
98
|
+
config.testing.test = testing.test;
|
|
99
|
+
config.testing.testWithCoverage = testing.testWithCoverage;
|
|
100
|
+
|
|
101
|
+
if (orchestrator.maxLanes !== undefined) {
|
|
102
|
+
config.lanes.maxParallel = mapMaxParallel(orchestrator.maxLanes);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(taskRunner.referenceDocs)) {
|
|
106
|
+
config.referenceDocs = taskRunner.referenceDocs;
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(taskRunner.standards)) {
|
|
109
|
+
config.standards = taskRunner.standards;
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(taskRunner.neverLoad)) {
|
|
112
|
+
config.neverLoad = taskRunner.neverLoad;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return config;
|
|
116
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FR-SCHED-02: detect dependency cycles.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {{ nodes: string[], depsByTask: Record<string, string[]> }} graph
|
|
7
|
+
* @returns {string[] | null} cycle path like [A, B, C, A]
|
|
8
|
+
*/
|
|
9
|
+
export function findCyclePath(graph) {
|
|
10
|
+
const visited = new Set();
|
|
11
|
+
const inStack = new Set();
|
|
12
|
+
const stack = [];
|
|
13
|
+
const stackIndex = new Map();
|
|
14
|
+
|
|
15
|
+
/** @type {(id: string) => string[] | null} */
|
|
16
|
+
function dfs(id) {
|
|
17
|
+
visited.add(id);
|
|
18
|
+
inStack.add(id);
|
|
19
|
+
stackIndex.set(id, stack.length);
|
|
20
|
+
stack.push(id);
|
|
21
|
+
|
|
22
|
+
const deps = graph.depsByTask[id] ?? [];
|
|
23
|
+
for (const dep of deps) {
|
|
24
|
+
const next = String(dep);
|
|
25
|
+
if (!visited.has(next)) {
|
|
26
|
+
const cycle = dfs(next);
|
|
27
|
+
if (cycle) return cycle;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (inStack.has(next)) {
|
|
32
|
+
const start = stackIndex.get(next);
|
|
33
|
+
if (start == null) continue;
|
|
34
|
+
const cycle = stack.slice(start).concat([next]);
|
|
35
|
+
return cycle;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
stack.pop();
|
|
40
|
+
inStack.delete(id);
|
|
41
|
+
stackIndex.delete(id);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const id of graph.nodes) {
|
|
46
|
+
if (!visited.has(id)) {
|
|
47
|
+
const cycle = dfs(id);
|
|
48
|
+
if (cycle) return cycle;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {ReturnType<typeof import('./graph.mjs').buildGraph>} graph
|
|
57
|
+
*/
|
|
58
|
+
export function assertAcyclic(graph) {
|
|
59
|
+
const cycle = findCyclePath(graph);
|
|
60
|
+
if (cycle) {
|
|
61
|
+
throw new Error('Dependency cycle detected: ' + cycle.join(' -> '));
|
|
62
|
+
}
|
|
63
|
+
}
|