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,398 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { validateSpineConfig } from "./spine-config.mjs";
|
|
5
|
+
import { applyConfigDefaults } from "../src/config/merge-defaults.mjs";
|
|
6
|
+
import { discoverCursorRules } from "../src/config/cursor-rules/discover.mjs";
|
|
7
|
+
import { RULES_PROFILE_REL_PATH } from "../src/config/cursor-rules/profile.mjs";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
export const PACKAGE_ROOT = path.resolve(__dirname, "..");
|
|
12
|
+
|
|
13
|
+
export const TEMPLATE_PATHS = {
|
|
14
|
+
spineConfig: path.join(PACKAGE_ROOT, "templates", "spine-config.json"),
|
|
15
|
+
rulesProfile: path.join(PACKAGE_ROOT, "templates", "rules-profile.json"),
|
|
16
|
+
tasksContext: path.join(PACKAGE_ROOT, "templates", "tasks", "CONTEXT.md"),
|
|
17
|
+
agents: {
|
|
18
|
+
worker: path.join(PACKAGE_ROOT, "templates", "agents", "worker.md"),
|
|
19
|
+
reviewer: path.join(PACKAGE_ROOT, "templates", "agents", "reviewer.md"),
|
|
20
|
+
supervisor: path.join(PACKAGE_ROOT, "templates", "agents", "supervisor.md"),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_NEXT_TASK_ID = "SP-001";
|
|
25
|
+
|
|
26
|
+
export const AGENT_STUB_FILES = [
|
|
27
|
+
{ templateKey: "worker", destName: "worker.md" },
|
|
28
|
+
{ templateKey: "reviewer", destName: "reviewer.md" },
|
|
29
|
+
{ templateKey: "supervisor", destName: "supervisor.md" },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export const DEFAULT_TASKS_ROOT = "spine-tasks";
|
|
33
|
+
export const TASKPLANE_COMPAT_TASKS_ROOT = "taskplane-tasks";
|
|
34
|
+
/** @deprecated Use plain `spine init`; kept for Taskplane migrants. */
|
|
35
|
+
export const TASKPLANE_COMPAT_PRESET = "taskplane-compat";
|
|
36
|
+
export const LEGACY_TASKPLANE_PRESET_ALIASES = [TASKPLANE_COMPAT_PRESET];
|
|
37
|
+
|
|
38
|
+
export const SPINE_INIT_TESTING_COMMAND = "npm run typecheck && npm test";
|
|
39
|
+
export const SPINE_INIT_COVERAGE_COMMAND = "npm run coverage:check";
|
|
40
|
+
|
|
41
|
+
export const SPINE_GITIGNORE_ENTRIES = [
|
|
42
|
+
".spine/runtime/",
|
|
43
|
+
".spine/batch-state.json",
|
|
44
|
+
".spine/batch-history.json",
|
|
45
|
+
".worktrees/",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const SPINE_GITIGNORE_HEADER = "# pi-spine runtime";
|
|
49
|
+
|
|
50
|
+
export function getTemplatePaths() {
|
|
51
|
+
for (const templatePath of [
|
|
52
|
+
TEMPLATE_PATHS.spineConfig,
|
|
53
|
+
TEMPLATE_PATHS.rulesProfile,
|
|
54
|
+
TEMPLATE_PATHS.tasksContext,
|
|
55
|
+
...Object.values(TEMPLATE_PATHS.agents),
|
|
56
|
+
]) {
|
|
57
|
+
if (!fs.existsSync(templatePath)) {
|
|
58
|
+
throw new Error(`Missing init template: ${templatePath}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return TEMPLATE_PATHS;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function loadSpineConfigTemplate() {
|
|
65
|
+
const templatePath = getTemplatePaths().spineConfig;
|
|
66
|
+
return JSON.parse(fs.readFileSync(templatePath, "utf-8"));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function loadRulesProfileTemplate() {
|
|
70
|
+
const templatePath = getTemplatePaths().rulesProfile;
|
|
71
|
+
return fs.readFileSync(templatePath, "utf-8");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function loadTasksContextTemplate() {
|
|
75
|
+
const templatePath = getTemplatePaths().tasksContext;
|
|
76
|
+
return fs.readFileSync(templatePath, "utf-8");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function buildContextMd(projectRoot, { nextTaskId = DEFAULT_NEXT_TASK_ID } = {}) {
|
|
80
|
+
const template = loadTasksContextTemplate();
|
|
81
|
+
const projectTitle = path.basename(projectRoot);
|
|
82
|
+
const lastUpdated = new Date().toISOString().slice(0, 10);
|
|
83
|
+
return template
|
|
84
|
+
.replaceAll("{{PROJECT_TITLE}}", projectTitle)
|
|
85
|
+
.replaceAll("{{LAST_UPDATED}}", lastUpdated)
|
|
86
|
+
.replaceAll("{{NEXT_TASK_ID}}", nextTaskId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function normalizeTasksRoot(tasksRootRaw) {
|
|
90
|
+
if (!tasksRootRaw || tasksRootRaw.startsWith("--")) {
|
|
91
|
+
throw new Error("Missing value for --tasks-root <relative-path>.");
|
|
92
|
+
}
|
|
93
|
+
if (path.isAbsolute(tasksRootRaw)) {
|
|
94
|
+
throw new Error("--tasks-root must be relative to the project root (absolute paths are not allowed).");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const normalized = tasksRootRaw
|
|
98
|
+
.trim()
|
|
99
|
+
.replace(/\\/g, "/")
|
|
100
|
+
.replace(/^\.\/+/, "")
|
|
101
|
+
.replace(/\/+$/, "");
|
|
102
|
+
|
|
103
|
+
if (!normalized || normalized === ".") {
|
|
104
|
+
throw new Error("--tasks-root must not be empty.");
|
|
105
|
+
}
|
|
106
|
+
if (normalized === ".." || normalized.startsWith("../")) {
|
|
107
|
+
throw new Error("--tasks-root must stay within the project root (paths starting with .. are not allowed).");
|
|
108
|
+
}
|
|
109
|
+
return normalized;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function parseInitArgs(args) {
|
|
113
|
+
const force = args.includes("--force");
|
|
114
|
+
const dryRun = args.includes("--dry-run");
|
|
115
|
+
const tasksRootIdx = args.indexOf("--tasks-root");
|
|
116
|
+
const tasksRootRaw = tasksRootIdx !== -1 ? args[tasksRootIdx + 1] : null;
|
|
117
|
+
const presetIdx = args.indexOf("--preset");
|
|
118
|
+
const presetRaw = presetIdx !== -1 ? args[presetIdx + 1] : null;
|
|
119
|
+
|
|
120
|
+
if (presetRaw?.startsWith("--")) {
|
|
121
|
+
throw new Error("Missing value for --preset <name>.");
|
|
122
|
+
}
|
|
123
|
+
if (presetRaw && !LEGACY_TASKPLANE_PRESET_ALIASES.includes(presetRaw)) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Unknown preset: ${presetRaw}. Supported: ${LEGACY_TASKPLANE_PRESET_ALIASES.join(", ")} (deprecated — use plain spine init).`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const preset = presetRaw ?? null;
|
|
130
|
+
let tasksRoot = DEFAULT_TASKS_ROOT;
|
|
131
|
+
if (preset === TASKPLANE_COMPAT_PRESET && !tasksRootRaw) {
|
|
132
|
+
tasksRoot = TASKPLANE_COMPAT_TASKS_ROOT;
|
|
133
|
+
}
|
|
134
|
+
if (tasksRootRaw) {
|
|
135
|
+
tasksRoot = normalizeTasksRoot(tasksRootRaw);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { force, dryRun, tasksRoot, preset };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Apply production-ready defaults for every greenfield init. */
|
|
142
|
+
export function applySpineInitDefaults(config) {
|
|
143
|
+
config.testing.build = SPINE_INIT_TESTING_COMMAND;
|
|
144
|
+
config.testing.test = SPINE_INIT_TESTING_COMMAND;
|
|
145
|
+
config.testing.testWithCoverage = SPINE_INIT_COVERAGE_COMMAND;
|
|
146
|
+
config.dashboard = { ...(config.dashboard ?? {}), port: 8109 };
|
|
147
|
+
config.gates = {
|
|
148
|
+
...(config.gates ?? {}),
|
|
149
|
+
requireBeforeIntegrate: true,
|
|
150
|
+
collectBuildEvidence: true,
|
|
151
|
+
collectTestEvidence: true,
|
|
152
|
+
};
|
|
153
|
+
config.lanes = { ...(config.lanes ?? {}), maxParallel: 3, queueExcess: true };
|
|
154
|
+
const standards = Array.isArray(config.standards) ? config.standards : [];
|
|
155
|
+
const neverLoad = Array.isArray(config.neverLoad) ? config.neverLoad : [];
|
|
156
|
+
config.standards = standards.filter((entry) => !neverLoad.includes(entry));
|
|
157
|
+
applyConfigDefaults(config);
|
|
158
|
+
return config;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** @deprecated Alias for {@link applySpineInitDefaults}. */
|
|
162
|
+
export function applyTaskplaneCompatPreset(config) {
|
|
163
|
+
return applySpineInitDefaults(config);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function buildSpineConfig(projectRoot, tasksRoot, { preset } = {}) {
|
|
167
|
+
const template = loadSpineConfigTemplate();
|
|
168
|
+
const config = structuredClone(template);
|
|
169
|
+
config.project.name = path.basename(projectRoot);
|
|
170
|
+
config.paths.tasksRoot = tasksRoot;
|
|
171
|
+
applySpineInitDefaults(config);
|
|
172
|
+
if (preset === TASKPLANE_COMPAT_PRESET) {
|
|
173
|
+
// Preset only affects default tasks root when --tasks-root omitted; config already applied.
|
|
174
|
+
void preset;
|
|
175
|
+
}
|
|
176
|
+
return config;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function ensureGitignoreEntries(projectRoot, { dryRun = false } = {}) {
|
|
180
|
+
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
181
|
+
const fileExists = fs.existsSync(gitignorePath);
|
|
182
|
+
const existingContent = fileExists ? fs.readFileSync(gitignorePath, "utf-8") : "";
|
|
183
|
+
const existingLines = new Set(existingContent.split(/\r?\n/).map((line) => line.trim()));
|
|
184
|
+
|
|
185
|
+
const added = [];
|
|
186
|
+
const skipped = [];
|
|
187
|
+
|
|
188
|
+
for (const entry of SPINE_GITIGNORE_ENTRIES) {
|
|
189
|
+
if (existingLines.has(entry)) {
|
|
190
|
+
skipped.push(entry);
|
|
191
|
+
} else {
|
|
192
|
+
added.push(entry);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (added.length === 0) {
|
|
197
|
+
return { created: false, added, skipped };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!dryRun) {
|
|
201
|
+
const newLines = [];
|
|
202
|
+
if (!existingLines.has(SPINE_GITIGNORE_HEADER)) {
|
|
203
|
+
newLines.push(SPINE_GITIGNORE_HEADER);
|
|
204
|
+
}
|
|
205
|
+
newLines.push(...added);
|
|
206
|
+
|
|
207
|
+
const suffix = newLines.join("\n") + "\n";
|
|
208
|
+
const nextContent = fileExists ? `${existingContent.replace(/\s*$/, "")}\n\n${suffix}` : `${suffix}`;
|
|
209
|
+
fs.mkdirSync(projectRoot, { recursive: true });
|
|
210
|
+
fs.writeFileSync(gitignorePath, nextContent, "utf-8");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { created: !fileExists, added, skipped };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function writeFileIfAllowed(projectRoot, relativePath, content, { force, dryRun }) {
|
|
217
|
+
const fullPath = path.join(projectRoot, relativePath);
|
|
218
|
+
if (fs.existsSync(fullPath) && !force) {
|
|
219
|
+
return { action: "skip", path: relativePath };
|
|
220
|
+
}
|
|
221
|
+
if (!dryRun) {
|
|
222
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
223
|
+
fs.writeFileSync(fullPath, content, "utf-8");
|
|
224
|
+
}
|
|
225
|
+
return { action: fs.existsSync(fullPath) && force ? "overwrite" : "create", path: relativePath };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param {string} projectRoot
|
|
230
|
+
* @param {{ dryRun?: boolean, force?: boolean }} [options]
|
|
231
|
+
*/
|
|
232
|
+
export function runInitRulesDiscover(projectRoot, { dryRun = false, force = false } = {}) {
|
|
233
|
+
if (dryRun) {
|
|
234
|
+
return { ok: true, dryRun: true, skipped: true };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const profilePath = path.join(projectRoot, RULES_PROFILE_REL_PATH);
|
|
238
|
+
if (!fs.existsSync(profilePath)) {
|
|
239
|
+
return {
|
|
240
|
+
ok: false,
|
|
241
|
+
error: `${RULES_PROFILE_REL_PATH} missing — init should copy templates/rules-profile.json first`,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const discovered = discoverCursorRules({ projectRoot, writeManifest: true });
|
|
246
|
+
return {
|
|
247
|
+
ok: true,
|
|
248
|
+
manifestPath: discovered.manifestPath,
|
|
249
|
+
ruleCount: discovered.manifest.rules.length,
|
|
250
|
+
excludedCount: discovered.manifest.excluded.length,
|
|
251
|
+
force,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function runInit(projectRoot, args = []) {
|
|
256
|
+
getTemplatePaths();
|
|
257
|
+
|
|
258
|
+
let parsed;
|
|
259
|
+
try {
|
|
260
|
+
parsed = parseInitArgs(args);
|
|
261
|
+
} catch (err) {
|
|
262
|
+
return { ok: false, error: err.message, exitCode: 1 };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const { force, dryRun, tasksRoot, preset } = parsed;
|
|
266
|
+
const configPath = path.join(projectRoot, ".spine", "spine-config.json");
|
|
267
|
+
|
|
268
|
+
if (fs.existsSync(configPath) && !force) {
|
|
269
|
+
return {
|
|
270
|
+
ok: false,
|
|
271
|
+
error: "Project already initialized (.spine/spine-config.json exists). Use --force to overwrite.",
|
|
272
|
+
exitCode: 1,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const config = buildSpineConfig(projectRoot, tasksRoot, { preset });
|
|
277
|
+
const validationError = validateSpineConfig(config);
|
|
278
|
+
if (validationError) {
|
|
279
|
+
return {
|
|
280
|
+
ok: false,
|
|
281
|
+
error: validationError.message,
|
|
282
|
+
exitCode: 1,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const actions = [];
|
|
287
|
+
|
|
288
|
+
const configResult = writeFileIfAllowed(
|
|
289
|
+
projectRoot,
|
|
290
|
+
".spine/spine-config.json",
|
|
291
|
+
`${JSON.stringify(config, null, 2)}\n`,
|
|
292
|
+
{ force, dryRun },
|
|
293
|
+
);
|
|
294
|
+
actions.push(configResult);
|
|
295
|
+
|
|
296
|
+
const profileTemplate = loadRulesProfileTemplate();
|
|
297
|
+
const profileResult = writeFileIfAllowed(
|
|
298
|
+
projectRoot,
|
|
299
|
+
RULES_PROFILE_REL_PATH,
|
|
300
|
+
profileTemplate.endsWith("\n") ? profileTemplate : `${profileTemplate}\n`,
|
|
301
|
+
{ force, dryRun },
|
|
302
|
+
);
|
|
303
|
+
actions.push(profileResult);
|
|
304
|
+
|
|
305
|
+
for (const { templateKey, destName } of AGENT_STUB_FILES) {
|
|
306
|
+
const templateContent = fs.readFileSync(TEMPLATE_PATHS.agents[templateKey], "utf-8");
|
|
307
|
+
const agentResult = writeFileIfAllowed(
|
|
308
|
+
projectRoot,
|
|
309
|
+
`.spine/agents/${destName}`,
|
|
310
|
+
templateContent,
|
|
311
|
+
{ force, dryRun },
|
|
312
|
+
);
|
|
313
|
+
actions.push(agentResult);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const tasksRootPath = path.join(projectRoot, tasksRoot);
|
|
317
|
+
if (!dryRun && !fs.existsSync(tasksRootPath)) {
|
|
318
|
+
fs.mkdirSync(tasksRootPath, { recursive: true });
|
|
319
|
+
actions.push({ action: "create", path: `${tasksRoot}/` });
|
|
320
|
+
} else if (dryRun && !fs.existsSync(tasksRootPath)) {
|
|
321
|
+
actions.push({ action: "create", path: `${tasksRoot}/` });
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const contextContent = buildContextMd(projectRoot);
|
|
325
|
+
const contextResult = writeFileIfAllowed(
|
|
326
|
+
projectRoot,
|
|
327
|
+
`${tasksRoot}/CONTEXT.md`,
|
|
328
|
+
contextContent,
|
|
329
|
+
{ force, dryRun },
|
|
330
|
+
);
|
|
331
|
+
actions.push(contextResult);
|
|
332
|
+
|
|
333
|
+
const gitignoreResult = ensureGitignoreEntries(projectRoot, { dryRun });
|
|
334
|
+
if (gitignoreResult.added.length > 0) {
|
|
335
|
+
actions.push({
|
|
336
|
+
action: gitignoreResult.created ? "create" : "update",
|
|
337
|
+
path: ".gitignore",
|
|
338
|
+
added: gitignoreResult.added,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const rulesDiscoverResult = runInitRulesDiscover(projectRoot, { dryRun, force });
|
|
343
|
+
if (!rulesDiscoverResult.ok) {
|
|
344
|
+
return {
|
|
345
|
+
ok: false,
|
|
346
|
+
error: rulesDiscoverResult.error,
|
|
347
|
+
exitCode: 1,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
if (!rulesDiscoverResult.skipped && rulesDiscoverResult.manifestPath) {
|
|
351
|
+
actions.push({
|
|
352
|
+
action: "create",
|
|
353
|
+
path: ".spine/rules-manifest.json",
|
|
354
|
+
ruleCount: rulesDiscoverResult.ruleCount,
|
|
355
|
+
});
|
|
356
|
+
} else if (dryRun && fs.existsSync(path.join(projectRoot, ".cursor", "rules"))) {
|
|
357
|
+
actions.push({ action: "create", path: ".spine/rules-manifest.json" });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
ok: true,
|
|
362
|
+
dryRun,
|
|
363
|
+
tasksRoot,
|
|
364
|
+
config,
|
|
365
|
+
actions,
|
|
366
|
+
gitignoreResult,
|
|
367
|
+
rulesDiscoverResult,
|
|
368
|
+
exitCode: 0,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function cmdInit(args = []) {
|
|
373
|
+
const projectRoot = process.cwd();
|
|
374
|
+
const result = runInit(projectRoot, args);
|
|
375
|
+
|
|
376
|
+
if (!result.ok) {
|
|
377
|
+
console.error(`❌ ${result.error}`);
|
|
378
|
+
process.exit(result.exitCode ?? 1);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
console.log("\npi-spine Init\n");
|
|
382
|
+
if (result.dryRun) {
|
|
383
|
+
console.log(" Dry run — no files will be written.\n");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
for (const action of result.actions) {
|
|
387
|
+
if (action.action === "skip") {
|
|
388
|
+
console.log(` skip ${action.path} (already exists)`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const label = action.action === "update" ? "update" : action.action === "overwrite" ? "overwrite" : "create";
|
|
392
|
+
const detail = action.added?.length ? ` (${action.added.length} entries added)` : "";
|
|
393
|
+
console.log(` ${label} ${action.path}${detail}`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
console.log("\n✅ pi-spine initialized.\n");
|
|
397
|
+
console.log("Next: spine doctor\n");
|
|
398
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { integrateOrchToBase } from "../src/batch/integrate.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {object} result
|
|
5
|
+
* @param {boolean} json
|
|
6
|
+
*/
|
|
7
|
+
export function formatIntegrateHuman(result, json = false) {
|
|
8
|
+
if (json) return `${JSON.stringify(result, null, 2)}\n`;
|
|
9
|
+
|
|
10
|
+
const lines = ["", result.ok ? "Integrate" : "Integrate failed", "", ` ${result.headline}`];
|
|
11
|
+
|
|
12
|
+
if (result.error) {
|
|
13
|
+
lines.push("", ` Error: ${result.error}`);
|
|
14
|
+
}
|
|
15
|
+
if (result.batchId) {
|
|
16
|
+
lines.push("", ` Batch: ${result.batchId}`);
|
|
17
|
+
}
|
|
18
|
+
if (result.baseBranch && result.orchBranch) {
|
|
19
|
+
lines.push(` Branches: ${result.orchBranch} → ${result.baseBranch}`);
|
|
20
|
+
}
|
|
21
|
+
if (result.commitsAhead != null) {
|
|
22
|
+
lines.push(` Commits ahead: ${result.commitsAhead}`);
|
|
23
|
+
}
|
|
24
|
+
if (result.mergeCommit) {
|
|
25
|
+
lines.push(` Merge commit: ${result.mergeCommit}`);
|
|
26
|
+
}
|
|
27
|
+
if (result.mergePlan) {
|
|
28
|
+
lines.push(` Plan: ${result.mergePlan}`);
|
|
29
|
+
}
|
|
30
|
+
if (result.gateRequired) {
|
|
31
|
+
lines.push("", " Gate: approval required before integrate");
|
|
32
|
+
}
|
|
33
|
+
if (result.failureClass === "GateBlocked") {
|
|
34
|
+
lines.push("", " Gate: integrate blocked until approved");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
lines.push("", ` → ${result.suggestedCommand}`);
|
|
38
|
+
|
|
39
|
+
if (result.alternatives?.length) {
|
|
40
|
+
lines.push("", " Alternatives:");
|
|
41
|
+
for (const alt of result.alternatives) {
|
|
42
|
+
lines.push(` • ${alt}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
lines.push("");
|
|
47
|
+
return lines.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {object} options
|
|
52
|
+
* @param {string} options.projectRoot
|
|
53
|
+
* @param {string[]} options.args
|
|
54
|
+
*/
|
|
55
|
+
export function runSpineIntegrate(options) {
|
|
56
|
+
const { projectRoot, args } = options;
|
|
57
|
+
const flags = new Set(args.filter((a) => a.startsWith("--")));
|
|
58
|
+
|
|
59
|
+
let batchId = null;
|
|
60
|
+
const batchIdx = args.indexOf("--batch");
|
|
61
|
+
if (batchIdx >= 0 && args[batchIdx + 1]) {
|
|
62
|
+
batchId = args[batchIdx + 1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result = integrateOrchToBase({
|
|
66
|
+
projectRoot,
|
|
67
|
+
dryRun: flags.has("--dry-run"),
|
|
68
|
+
batchId,
|
|
69
|
+
forceIntegrate: flags.has("--force-integrate"),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
74
|
+
output: formatIntegrateHuman(result, flags.has("--json")),
|
|
75
|
+
result,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
exportJournalJsonl,
|
|
5
|
+
journalPath,
|
|
6
|
+
readJournalEvents,
|
|
7
|
+
summarizeJournalEvent,
|
|
8
|
+
} from "../src/batch/journal.mjs";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} timestamp
|
|
12
|
+
*/
|
|
13
|
+
function formatReplayTime(timestamp) {
|
|
14
|
+
const date = new Date(timestamp);
|
|
15
|
+
if (Number.isNaN(date.getTime())) return String(timestamp);
|
|
16
|
+
return date.toISOString().replace("T", " ").slice(0, 19);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} value
|
|
21
|
+
*/
|
|
22
|
+
function escapeMarkdownTableCell(value) {
|
|
23
|
+
return String(value).replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} batchId
|
|
28
|
+
* @param {object[]} events
|
|
29
|
+
*/
|
|
30
|
+
export function formatJournalMarkdownTimeline(batchId, events) {
|
|
31
|
+
const lines = [`# Batch journal timeline — ${batchId}`, ""];
|
|
32
|
+
lines.push("| Time (UTC) | Event | Lane | Task | Summary |");
|
|
33
|
+
lines.push("|------------|-------|------|------|---------|");
|
|
34
|
+
|
|
35
|
+
for (const event of events) {
|
|
36
|
+
const time = escapeMarkdownTableCell(formatReplayTime(event.timestamp));
|
|
37
|
+
const type = escapeMarkdownTableCell(event.type ?? "");
|
|
38
|
+
const lane = escapeMarkdownTableCell(event.laneId ?? "—");
|
|
39
|
+
const task = escapeMarkdownTableCell(event.taskId ?? "—");
|
|
40
|
+
const summary = escapeMarkdownTableCell(summarizeJournalEvent(event));
|
|
41
|
+
lines.push(`| ${time} | ${type} | ${lane} | ${task} | ${summary} |`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
lines.push("");
|
|
45
|
+
return lines.join("\n");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} projectRoot
|
|
50
|
+
* @param {string} batchId
|
|
51
|
+
* @returns {string|null}
|
|
52
|
+
*/
|
|
53
|
+
export function exportJournalMarkdown(projectRoot, batchId) {
|
|
54
|
+
const filePath = journalPath(projectRoot, batchId);
|
|
55
|
+
if (!fs.existsSync(filePath)) return null;
|
|
56
|
+
const events = readJournalEvents(projectRoot, batchId);
|
|
57
|
+
return formatJournalMarkdownTimeline(batchId, events);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {object[]} events
|
|
62
|
+
*/
|
|
63
|
+
export function formatJournalReplayTable(events) {
|
|
64
|
+
const lines = ["", "Journal replay", ""];
|
|
65
|
+
lines.push(" time | type | lane | task | summary");
|
|
66
|
+
lines.push(" --------------------+-----------------------+--------+----------+------------------");
|
|
67
|
+
|
|
68
|
+
for (const event of events) {
|
|
69
|
+
const time = formatReplayTime(event.timestamp).padEnd(19);
|
|
70
|
+
const type = String(event.type ?? "").padEnd(21);
|
|
71
|
+
const lane = String(event.laneId ?? "—").padEnd(6);
|
|
72
|
+
const task = String(event.taskId ?? "—").padEnd(8);
|
|
73
|
+
const summary = summarizeJournalEvent(event);
|
|
74
|
+
lines.push(` ${time} | ${type} | ${lane} | ${task} | ${summary}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
lines.push("");
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const JOURNAL_USAGE =
|
|
82
|
+
"Usage:\n" +
|
|
83
|
+
" spine journal replay --batch {id} [--json]\n" +
|
|
84
|
+
" spine journal export --batch {id} --format markdown|jsonl [--output path]\n";
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} projectRoot
|
|
88
|
+
* @param {string[]} args
|
|
89
|
+
*/
|
|
90
|
+
function runJournalReplay(projectRoot, args) {
|
|
91
|
+
const batchIdx = args.indexOf("--batch");
|
|
92
|
+
const batchId = batchIdx >= 0 ? args[batchIdx + 1] : null;
|
|
93
|
+
const json = args.includes("--json");
|
|
94
|
+
|
|
95
|
+
if (!batchId) {
|
|
96
|
+
return {
|
|
97
|
+
exitCode: 1,
|
|
98
|
+
output: `Missing required --batch {id}\n${JOURNAL_USAGE}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const filePath = journalPath(projectRoot, batchId);
|
|
103
|
+
if (!fs.existsSync(filePath)) {
|
|
104
|
+
return {
|
|
105
|
+
exitCode: 1,
|
|
106
|
+
output: `Journal not found for batch ${batchId}: ${filePath}\n`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const events = readJournalEvents(projectRoot, batchId);
|
|
111
|
+
if (json) {
|
|
112
|
+
return {
|
|
113
|
+
exitCode: 0,
|
|
114
|
+
output: `${JSON.stringify({ batchId, events }, null, 2)}\n`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
exitCode: 0,
|
|
120
|
+
output: formatJournalReplayTable(events),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {string} projectRoot
|
|
126
|
+
* @param {string[]} args
|
|
127
|
+
*/
|
|
128
|
+
function runJournalExport(projectRoot, args) {
|
|
129
|
+
const exportUsage =
|
|
130
|
+
"Usage: spine journal export --batch {id} --format markdown|jsonl [--output path]\n";
|
|
131
|
+
const batchIdx = args.indexOf("--batch");
|
|
132
|
+
const batchId = batchIdx >= 0 ? args[batchIdx + 1] : null;
|
|
133
|
+
const formatIdx = args.indexOf("--format");
|
|
134
|
+
const format = formatIdx >= 0 ? args[formatIdx + 1] : null;
|
|
135
|
+
const outputIdx = args.indexOf("--output");
|
|
136
|
+
const outputPath = outputIdx >= 0 ? args[outputIdx + 1] : null;
|
|
137
|
+
|
|
138
|
+
if (!batchId) {
|
|
139
|
+
return {
|
|
140
|
+
exitCode: 1,
|
|
141
|
+
output: `Missing required --batch {id}\n${exportUsage}`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (format !== "jsonl" && format !== "markdown") {
|
|
146
|
+
return {
|
|
147
|
+
exitCode: 1,
|
|
148
|
+
output: `Missing or unsupported --format (expected markdown or jsonl)\n${exportUsage}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const content =
|
|
153
|
+
format === "jsonl"
|
|
154
|
+
? exportJournalJsonl(projectRoot, batchId)
|
|
155
|
+
: exportJournalMarkdown(projectRoot, batchId);
|
|
156
|
+
if (content === null) {
|
|
157
|
+
const filePath = journalPath(projectRoot, batchId);
|
|
158
|
+
return {
|
|
159
|
+
exitCode: 1,
|
|
160
|
+
output: `Journal not found for batch ${batchId}: ${filePath}\n`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (outputPath) {
|
|
165
|
+
const dir = path.dirname(outputPath);
|
|
166
|
+
if (dir !== ".") {
|
|
167
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
168
|
+
}
|
|
169
|
+
fs.writeFileSync(outputPath, content, "utf-8");
|
|
170
|
+
return { exitCode: 0, output: "" };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return { exitCode: 0, output: content.endsWith("\n") ? content : `${content}\n` };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param {object} options
|
|
178
|
+
* @param {string} options.projectRoot
|
|
179
|
+
* @param {string[]} options.args
|
|
180
|
+
*/
|
|
181
|
+
export function runSpineJournal(options) {
|
|
182
|
+
const { projectRoot, args } = options;
|
|
183
|
+
const subcommand = args[0];
|
|
184
|
+
const subArgs = args.slice(1);
|
|
185
|
+
|
|
186
|
+
if (subcommand === "replay") {
|
|
187
|
+
return runJournalReplay(projectRoot, subArgs);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (subcommand === "export") {
|
|
191
|
+
return runJournalExport(projectRoot, subArgs);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
exitCode: 1,
|
|
196
|
+
output: JOURNAL_USAGE,
|
|
197
|
+
};
|
|
198
|
+
}
|