pi-spine 1.0.2 → 1.2.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/README.md +61 -489
- package/bin/get-version.mjs +1 -13
- package/bin/spine-batch.mjs +162 -51
- package/bin/spine-cli/batch.mjs +3 -3
- package/bin/spine-cli/lane-logs.mjs +24 -0
- package/bin/spine-cli/scenarios.mjs +298 -0
- package/bin/spine-cli/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-config.mjs +1 -212
- package/bin/spine-doctor.mjs +2 -418
- package/bin/spine-init.mjs +1 -398
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-preflight.mjs +1 -700
- package/bin/spine-review-step.mjs +6 -4
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +112 -13
- package/bin/spine-worker-runner.mjs +24 -14
- package/bin/spine.mjs +52 -2
- package/extensions/spine/worker-tools.ts +14 -12
- package/package.json +5 -2
- package/skills/create-spine-tasks/SKILL.md +135 -6
- package/skills/create-spine-tasks/references/clarify-template.md +73 -0
- package/skills/create-spine-tasks/references/contract-template.md +19 -0
- package/skills/create-spine-tasks/references/prompt-template.md +2 -0
- package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
- package/src/batch/abort.mjs +3 -12
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +312 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-verify.mjs +140 -2
- package/src/batch/detached-start.mjs +105 -7
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -0
- package/src/batch/diagnosis-task-done.mjs +110 -0
- package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
- package/src/batch/diagnosis.mjs +174 -62
- package/src/batch/engine-lanes/merge.mjs +168 -77
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +32 -74
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +42 -5
- package/src/batch/engine.mjs +115 -68
- package/src/batch/evidence.mjs +81 -17
- package/src/batch/gate.mjs +46 -17
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +73 -7
- package/src/batch/integrate.mjs +3 -5
- package/src/batch/journal.mjs +25 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lifecycle.mjs +131 -4
- package/src/batch/macro-phase.mjs +226 -0
- package/src/batch/merge/adoption-doc-merge.mjs +243 -0
- package/src/batch/merge/wave-merge-state.mjs +108 -0
- package/src/batch/metrics.mjs +74 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +223 -0
- package/src/batch/post-merge-limbo.mjs +345 -17
- package/src/batch/reconcile.mjs +473 -50
- package/src/batch/resume-common.mjs +6 -2
- package/src/batch/resume-engine.mjs +58 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +56 -1
- package/src/batch/resume-multi-validate.mjs +148 -8
- package/src/batch/resume-multi.mjs +45 -44
- package/src/batch/resume.mjs +64 -47
- package/src/batch/retry.mjs +56 -5
- package/src/batch/review-shared.mjs +196 -0
- package/src/batch/review-spawn.mjs +326 -0
- package/src/batch/review.mjs +178 -212
- package/src/batch/rules-manifest-drift.mjs +157 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence.mjs +454 -0
- package/src/batch/state.mjs +18 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +94 -10
- package/src/batch/worker-host.mjs +185 -37
- package/src/batch/worker-output.mjs +196 -3
- package/src/batch/worktree.mjs +10 -0
- package/src/cli/handoff.mjs +1 -1
- package/src/cli/issue-draft.mjs +180 -0
- package/src/cli/journal-follow.mjs +239 -0
- package/src/cli/lane-logs.mjs +291 -0
- package/src/cli/rules.mjs +1 -1
- package/src/cli/sequence.mjs +108 -0
- package/src/cli/settings-set.mjs +3 -22
- package/src/cli/settings-slash.mjs +27 -5
- package/src/cli/wait.mjs +187 -0
- package/src/cli/watch.mjs +160 -0
- package/src/config/agent-model-resolve.mjs +48 -0
- package/src/config/cursor-rules/discover.mjs +3 -21
- package/src/config/defaults.mjs +7 -1
- package/src/config/settings-fields.mjs +48 -0
- package/src/config/spine-config-load.mjs +221 -0
- package/src/config/spine-init-constants.mjs +424 -0
- package/src/config/spine-preflight-lib.mjs +1180 -0
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +224 -40
- package/src/dashboard/public/index.html +15 -9
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +387 -6
- package/src/dashboard/view.mjs +170 -15
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/run-doctor-checks.mjs +483 -0
- package/src/doctor/sequence-safety.mjs +57 -0
- package/src/doctor/stale-path.mjs +22 -0
- package/src/doctor/stale-worktrees.mjs +102 -0
- package/src/fixtures/scenario-registry.mjs +194 -0
- package/src/fs/atomic-write.mjs +49 -0
- package/src/migrate/taskplane-config.mjs +1 -1
- package/src/planner/file-scope.mjs +246 -0
- package/src/planner/format-plan.mjs +9 -7
- package/src/planner/index.mjs +6 -2
- package/src/planner/pending.mjs +92 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/analyze/index.mjs +453 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +42 -1
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/src/util/command-exists.mjs +19 -0
- package/templates/docs/constitution.md +61 -0
- package/templates/spine-config.json +9 -2
package/bin/spine-init.mjs
CHANGED
|
@@ -1,398 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
export * from "../src/config/spine-init-constants.mjs";
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* GitHub issue draft CLI (issue #60 Tier 1c).
|
|
4
|
+
* Usage: spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
|
|
11
|
+
import { buildIssueDraftBody } from "../src/cli/issue-draft.mjs";
|
|
12
|
+
import { commandExists } from "../src/util/command-exists.mjs";
|
|
13
|
+
import { c, die, isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_OUT_PATH = ".spine/issue-draft.md";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string[]} argv
|
|
19
|
+
*/
|
|
20
|
+
export function parseIssueDraftArgs(argv) {
|
|
21
|
+
/** @type {{ issueType: "bug"|"enhancement"|"question", title: string|null, json: boolean, outPath: string, create: boolean }} */
|
|
22
|
+
const args = {
|
|
23
|
+
issueType: "bug",
|
|
24
|
+
title: null,
|
|
25
|
+
json: false,
|
|
26
|
+
outPath: DEFAULT_OUT_PATH,
|
|
27
|
+
create: false,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const arg = argv[i];
|
|
32
|
+
if (arg === "--type") {
|
|
33
|
+
const value = argv[++i];
|
|
34
|
+
if (value !== "bug" && value !== "enhancement" && value !== "question") {
|
|
35
|
+
die(`Invalid --type value: ${value ?? "(missing)"}\nExpected bug, enhancement, or question.`);
|
|
36
|
+
}
|
|
37
|
+
args.issueType = value;
|
|
38
|
+
} else if (arg === "--title") {
|
|
39
|
+
args.title = argv[++i] ?? null;
|
|
40
|
+
} else if (arg === "--json") {
|
|
41
|
+
args.json = true;
|
|
42
|
+
} else if (arg === "--out") {
|
|
43
|
+
args.outPath = argv[++i] ?? DEFAULT_OUT_PATH;
|
|
44
|
+
} else if (arg === "--create") {
|
|
45
|
+
args.create = true;
|
|
46
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
47
|
+
return { ...args, help: true };
|
|
48
|
+
} else {
|
|
49
|
+
die(`Unknown argument: ${arg}\nRun ${c.cyan}spine issue draft --help${c.reset} for usage.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function printIssueDraftHelp() {
|
|
57
|
+
console.log(`
|
|
58
|
+
${c.bold}spine issue draft${c.reset} — build a GitHub issue draft from project state
|
|
59
|
+
|
|
60
|
+
${c.bold}Usage:${c.reset}
|
|
61
|
+
spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]
|
|
62
|
+
|
|
63
|
+
${c.bold}Options:${c.reset}
|
|
64
|
+
--type TYPE Issue type label: bug (default), enhancement, or question
|
|
65
|
+
--title TITLE Override issue title (default: diagnosis headline)
|
|
66
|
+
--json Print { title, body, labels, draftPath? } as JSON
|
|
67
|
+
--out PATH Write markdown body to PATH (default: ${DEFAULT_OUT_PATH})
|
|
68
|
+
--create Create GitHub issue via gh CLI (requires gh on PATH)
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {object} options
|
|
74
|
+
* @param {string} options.projectRoot
|
|
75
|
+
* @param {string[]} [options.args]
|
|
76
|
+
*/
|
|
77
|
+
export function runSpineIssueDraft(options) {
|
|
78
|
+
const { projectRoot, args: argv = [] } = options;
|
|
79
|
+
const parsed = parseIssueDraftArgs(argv);
|
|
80
|
+
if ("help" in parsed && parsed.help) {
|
|
81
|
+
printIssueDraftHelp();
|
|
82
|
+
return { exitCode: 0, output: "" };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let draft;
|
|
86
|
+
try {
|
|
87
|
+
draft = buildIssueDraftBody({
|
|
88
|
+
projectRoot,
|
|
89
|
+
issueType: parsed.issueType,
|
|
90
|
+
title: parsed.title ?? undefined,
|
|
91
|
+
});
|
|
92
|
+
} catch (err) {
|
|
93
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
94
|
+
return { exitCode: 1, output: `ERROR: ${message}\n` };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const draftPath = path.resolve(projectRoot, parsed.outPath);
|
|
98
|
+
let wroteDraft = false;
|
|
99
|
+
if (!parsed.json) {
|
|
100
|
+
fs.mkdirSync(path.dirname(draftPath), { recursive: true });
|
|
101
|
+
fs.writeFileSync(draftPath, draft.body, "utf-8");
|
|
102
|
+
wroteDraft = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (parsed.create) {
|
|
106
|
+
if (!commandExists("gh")) {
|
|
107
|
+
return {
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
output:
|
|
110
|
+
"ERROR: gh CLI not found on PATH. Install GitHub CLI or omit --create.\n",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const bodyFilePath = wroteDraft ? draftPath : path.join(projectRoot, ".spine", ".issue-draft-body.tmp.md");
|
|
115
|
+
if (!wroteDraft) {
|
|
116
|
+
fs.mkdirSync(path.dirname(bodyFilePath), { recursive: true });
|
|
117
|
+
fs.writeFileSync(bodyFilePath, draft.body, "utf-8");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const ghArgs = [
|
|
121
|
+
"issue",
|
|
122
|
+
"create",
|
|
123
|
+
"--title",
|
|
124
|
+
draft.title,
|
|
125
|
+
"--body-file",
|
|
126
|
+
bodyFilePath,
|
|
127
|
+
];
|
|
128
|
+
for (const label of draft.labels) {
|
|
129
|
+
ghArgs.push("--label", label);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const ghResult = spawnSync("gh", ghArgs, {
|
|
133
|
+
cwd: projectRoot,
|
|
134
|
+
encoding: "utf-8",
|
|
135
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!wroteDraft && bodyFilePath.endsWith(".issue-draft-body.tmp.md")) {
|
|
139
|
+
try {
|
|
140
|
+
fs.unlinkSync(bodyFilePath);
|
|
141
|
+
} catch {
|
|
142
|
+
// Best-effort cleanup of temp body file.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (ghResult.status !== 0) {
|
|
147
|
+
const stderr = (ghResult.stderr ?? "").trim();
|
|
148
|
+
return {
|
|
149
|
+
exitCode: ghResult.status ?? 1,
|
|
150
|
+
output: stderr ? `ERROR: ${stderr}\n` : "ERROR: gh issue create failed\n",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (parsed.json) {
|
|
156
|
+
const payload = {
|
|
157
|
+
title: draft.title,
|
|
158
|
+
body: draft.body,
|
|
159
|
+
labels: draft.labels,
|
|
160
|
+
};
|
|
161
|
+
if (wroteDraft) {
|
|
162
|
+
payload.draftPath = path.relative(projectRoot, draftPath);
|
|
163
|
+
}
|
|
164
|
+
return { exitCode: 0, output: `${JSON.stringify(payload, null, 2)}\n` };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const humanOutput = [`# ${draft.title}`, "", draft.body, ""].join("\n");
|
|
168
|
+
return { exitCode: 0, output: humanOutput };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {object} options
|
|
173
|
+
* @param {string} options.projectRoot
|
|
174
|
+
* @param {string[]} [options.args]
|
|
175
|
+
*/
|
|
176
|
+
export function runSpineIssue(options) {
|
|
177
|
+
const { projectRoot, args: argv = [] } = options;
|
|
178
|
+
const sub = argv[0];
|
|
179
|
+
if (sub !== "draft") {
|
|
180
|
+
return {
|
|
181
|
+
exitCode: 1,
|
|
182
|
+
output:
|
|
183
|
+
`Usage: spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]\n`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return runSpineIssueDraft({ projectRoot, args: argv.slice(1) });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
190
|
+
const { exitCode, output } = runSpineIssue({
|
|
191
|
+
projectRoot: process.cwd(),
|
|
192
|
+
args: process.argv.slice(2),
|
|
193
|
+
});
|
|
194
|
+
process.stdout.write(output ?? "");
|
|
195
|
+
process.exit(exitCode);
|
|
196
|
+
}
|
package/bin/spine-journal.mjs
CHANGED
|
@@ -81,6 +81,7 @@ export function formatJournalReplayTable(events) {
|
|
|
81
81
|
const JOURNAL_USAGE =
|
|
82
82
|
"Usage:\n" +
|
|
83
83
|
" spine journal replay --batch {id} [--json]\n" +
|
|
84
|
+
" spine journal follow [--batch {id}] [--lane lane-N] [--json]\n" +
|
|
84
85
|
" spine journal export --batch {id} --format markdown|jsonl [--output path]\n";
|
|
85
86
|
|
|
86
87
|
/**
|