gsd-pi 2.73.1-dev.1040fb0 → 2.73.1-dev.49397e5
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/dist/cli-web-branch.d.ts +4 -3
- package/dist/cli-web-branch.js +10 -7
- package/dist/cli.js +99 -206
- package/dist/headless-query.js +4 -1
- package/dist/logo.d.ts +1 -1
- package/dist/logo.js +1 -1
- package/dist/onboarding.js +59 -53
- package/dist/resource-loader.js +2 -2
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +59 -1
- package/dist/resources/extensions/gsd/auto/detect-stuck.js +11 -4
- package/dist/resources/extensions/gsd/auto/phases.js +60 -10
- package/dist/resources/extensions/gsd/auto-dispatch.js +11 -3
- package/dist/resources/extensions/gsd/auto-post-unit.js +93 -57
- package/dist/resources/extensions/gsd/auto-start.js +3 -0
- package/dist/resources/extensions/gsd/auto-timeout-recovery.js +13 -0
- package/dist/resources/extensions/gsd/auto-verification.js +88 -3
- package/dist/resources/extensions/gsd/auto.js +37 -10
- package/dist/resources/extensions/gsd/bootstrap/register-extension.js +21 -8
- package/dist/resources/extensions/gsd/commands/catalog.js +26 -1
- package/dist/resources/extensions/gsd/commands/handlers/ops.js +20 -0
- package/dist/resources/extensions/gsd/commands/handlers/workflow.js +68 -9
- package/dist/resources/extensions/gsd/commands-add-tests.js +111 -0
- package/dist/resources/extensions/gsd/commands-backlog.js +140 -0
- package/dist/resources/extensions/gsd/commands-do.js +79 -0
- package/dist/resources/extensions/gsd/commands-maintenance.js +6 -6
- package/dist/resources/extensions/gsd/commands-pr-branch.js +180 -0
- package/dist/resources/extensions/gsd/commands-session-report.js +82 -0
- package/dist/resources/extensions/gsd/commands-ship.js +187 -0
- package/dist/resources/extensions/gsd/db-writer.js +3 -5
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +1 -1
- package/dist/resources/extensions/gsd/gsd-db.js +321 -0
- package/dist/resources/extensions/gsd/index.js +15 -2
- package/dist/resources/extensions/gsd/md-importer.js +3 -4
- package/dist/resources/extensions/gsd/memory-store.js +19 -51
- package/dist/resources/extensions/gsd/milestone-validation-gates.js +13 -12
- package/dist/resources/extensions/gsd/native-git-bridge.js +7 -4
- package/dist/resources/extensions/gsd/notification-widget.js +2 -2
- package/dist/resources/extensions/gsd/prompts/add-tests.md +35 -0
- package/dist/resources/extensions/gsd/state.js +66 -15
- package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +3 -14
- package/dist/resources/extensions/gsd/triage-resolution.js +2 -5
- package/dist/resources/extensions/gsd/workflow-manifest.js +8 -69
- package/dist/resources/extensions/gsd/workflow-migration.js +21 -22
- package/dist/resources/extensions/gsd/workflow-projections.js +4 -1
- package/dist/resources/extensions/gsd/workflow-reconcile.js +14 -11
- package/dist/tsconfig.extensions.tsbuildinfo +1 -0
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +14 -14
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +14 -14
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +3 -3
- package/packages/mcp-server/tsconfig.json +1 -0
- package/packages/mcp-server/tsconfig.tsbuildinfo +1 -0
- package/packages/native/tsconfig.tsbuildinfo +1 -0
- package/packages/pi-agent-core/tsconfig.json +1 -0
- package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -0
- package/packages/pi-ai/tsconfig.json +1 -0
- package/packages/pi-ai/tsconfig.tsbuildinfo +1 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +138 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +10 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts +2 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +9 -3
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js +52 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +21 -4
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +11 -3
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +157 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +12 -6
- package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.test.ts +73 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.ts +9 -3
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +21 -4
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +11 -3
- package/packages/pi-coding-agent/tsconfig.json +1 -0
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -0
- package/packages/pi-tui/dist/__tests__/tui.test.js +60 -1
- package/packages/pi-tui/dist/__tests__/tui.test.js.map +1 -1
- package/packages/pi-tui/dist/tui.d.ts +8 -0
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +32 -3
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/src/__tests__/tui.test.ts +76 -1
- package/packages/pi-tui/src/tui.ts +31 -3
- package/packages/pi-tui/tsconfig.json +1 -0
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -0
- package/packages/rpc-client/tsconfig.json +1 -0
- package/packages/rpc-client/tsconfig.tsbuildinfo +1 -0
- package/pkg/package.json +1 -1
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +95 -1
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +88 -0
- package/src/resources/extensions/gsd/auto/detect-stuck.ts +12 -4
- package/src/resources/extensions/gsd/auto/loop-deps.ts +6 -0
- package/src/resources/extensions/gsd/auto/phases.ts +90 -10
- package/src/resources/extensions/gsd/auto-dispatch.ts +10 -4
- package/src/resources/extensions/gsd/auto-post-unit.ts +107 -58
- package/src/resources/extensions/gsd/auto-start.ts +3 -0
- package/src/resources/extensions/gsd/auto-timeout-recovery.ts +17 -0
- package/src/resources/extensions/gsd/auto-verification.ts +98 -3
- package/src/resources/extensions/gsd/auto.ts +38 -14
- package/src/resources/extensions/gsd/bootstrap/register-extension.ts +24 -8
- package/src/resources/extensions/gsd/commands/catalog.ts +26 -1
- package/src/resources/extensions/gsd/commands/handlers/ops.ts +20 -0
- package/src/resources/extensions/gsd/commands/handlers/workflow.ts +74 -9
- package/src/resources/extensions/gsd/commands-add-tests.ts +137 -0
- package/src/resources/extensions/gsd/commands-backlog.ts +182 -0
- package/src/resources/extensions/gsd/commands-do.ts +109 -0
- package/src/resources/extensions/gsd/commands-maintenance.ts +6 -6
- package/src/resources/extensions/gsd/commands-pr-branch.ts +234 -0
- package/src/resources/extensions/gsd/commands-session-report.ts +101 -0
- package/src/resources/extensions/gsd/commands-ship.ts +219 -0
- package/src/resources/extensions/gsd/db-writer.ts +3 -5
- package/src/resources/extensions/gsd/docs/preferences-reference.md +1 -1
- package/src/resources/extensions/gsd/gsd-db.ts +467 -0
- package/src/resources/extensions/gsd/index.ts +18 -2
- package/src/resources/extensions/gsd/md-importer.ts +3 -5
- package/src/resources/extensions/gsd/memory-store.ts +31 -62
- package/src/resources/extensions/gsd/milestone-validation-gates.ts +13 -14
- package/src/resources/extensions/gsd/native-git-bridge.ts +11 -12
- package/src/resources/extensions/gsd/notification-widget.ts +2 -2
- package/src/resources/extensions/gsd/prompts/add-tests.md +35 -0
- package/src/resources/extensions/gsd/state.ts +80 -17
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/auto-post-unit-step-message.test.ts +53 -0
- package/src/resources/extensions/gsd/tests/commands-backlog.test.ts +158 -0
- package/src/resources/extensions/gsd/tests/commands-do.test.ts +127 -0
- package/src/resources/extensions/gsd/tests/commands-pr-branch.test.ts +68 -0
- package/src/resources/extensions/gsd/tests/commands-session-report.test.ts +82 -0
- package/src/resources/extensions/gsd/tests/commands-ship.test.ts +71 -0
- package/src/resources/extensions/gsd/tests/commands-workflow-custom.test.ts +14 -0
- package/src/resources/extensions/gsd/tests/complete-milestone-false-merge.test.ts +142 -0
- package/src/resources/extensions/gsd/tests/completed-at-reconcile.test.ts +42 -0
- package/src/resources/extensions/gsd/tests/derive-state-crossval.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +68 -8
- package/src/resources/extensions/gsd/tests/derive-state.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/extension-bootstrap-isolation.test.ts +154 -0
- package/src/resources/extensions/gsd/tests/integration/state-machine-edge-cases.test.ts +4 -2
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +68 -1
- package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +140 -0
- package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +180 -0
- package/src/resources/extensions/gsd/tests/state-machine-full-walkthrough.test.ts +5 -7
- package/src/resources/extensions/gsd/tests/token-profile.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/validate-milestone-stuck-guard.test.ts +179 -0
- package/src/resources/extensions/gsd/tests/workflow-logger-wiring.test.ts +223 -0
- package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +3 -11
- package/src/resources/extensions/gsd/triage-resolution.ts +2 -7
- package/src/resources/extensions/gsd/workflow-manifest.ts +9 -104
- package/src/resources/extensions/gsd/workflow-migration.ts +21 -29
- package/src/resources/extensions/gsd/workflow-projections.ts +8 -1
- package/src/resources/extensions/gsd/workflow-reconcile.ts +15 -15
- /package/dist/web/standalone/.next/static/{5dzOW4v8Vz23I5xRsiNSk → tAsSblRKK1lG7MVOwsO92}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{5dzOW4v8Vz23I5xRsiNSk → tAsSblRKK1lG7MVOwsO92}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GSD Command — /gsd ship
|
|
3
|
+
*
|
|
4
|
+
* Creates a PR from milestone artifacts: generates title + body from
|
|
5
|
+
* roadmap, slice summaries, and metrics, then opens via `gh pr create`.
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
9
|
+
import { deriveState } from "./state.js";
|
|
10
|
+
import { resolveMilestoneFile, resolveSlicePath, resolveSliceFile } from "./paths.js";
|
|
11
|
+
import { getLedger, getProjectTotals, aggregateByModel, formatCost, formatTokenCount, loadLedgerFromDisk } from "./metrics.js";
|
|
12
|
+
import { nativeGetCurrentBranch, nativeDetectMainBranch } from "./native-git-bridge.js";
|
|
13
|
+
import { formatDuration } from "../shared/format-utils.js";
|
|
14
|
+
function git(basePath, args) {
|
|
15
|
+
return execFileSync("git", args, { cwd: basePath, encoding: "utf-8" }).trim();
|
|
16
|
+
}
|
|
17
|
+
function isValidRefName(name) {
|
|
18
|
+
try {
|
|
19
|
+
execFileSync("git", ["check-ref-format", "--branch", name], { stdio: "pipe" });
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function listSliceIds(basePath, milestoneId) {
|
|
27
|
+
// Slices live at <milestoneDir>/slices/<sliceId>/ with canonical S\d+ IDs.
|
|
28
|
+
// Use resolveSlicePath with a probe to find the real slices directory root.
|
|
29
|
+
const probe = resolveSlicePath(basePath, milestoneId, "S01");
|
|
30
|
+
let slicesDir = null;
|
|
31
|
+
if (probe) {
|
|
32
|
+
// probe looks like <milestoneDir>/slices/S01 — parent is slices dir.
|
|
33
|
+
slicesDir = probe.replace(/[\\/][^\\/]+$/, "");
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Fall back to scanning the milestones roadmap file's sibling slices dir.
|
|
37
|
+
const roadmap = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
|
|
38
|
+
if (roadmap) {
|
|
39
|
+
slicesDir = roadmap.replace(/[\\/][^\\/]+$/, "") + "/slices";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!slicesDir || !existsSync(slicesDir))
|
|
43
|
+
return [];
|
|
44
|
+
try {
|
|
45
|
+
return readdirSync(slicesDir, { withFileTypes: true })
|
|
46
|
+
.filter((e) => e.isDirectory() && /^S\d+$/.test(e.name))
|
|
47
|
+
.map((e) => e.name)
|
|
48
|
+
.sort();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function collectSliceSummaries(basePath, milestoneId) {
|
|
55
|
+
const summaries = [];
|
|
56
|
+
for (const sliceId of listSliceIds(basePath, milestoneId)) {
|
|
57
|
+
const summaryPath = resolveSliceFile(basePath, milestoneId, sliceId, "SUMMARY");
|
|
58
|
+
if (!summaryPath || !existsSync(summaryPath))
|
|
59
|
+
continue;
|
|
60
|
+
try {
|
|
61
|
+
const content = readFileSync(summaryPath, "utf-8").trim();
|
|
62
|
+
if (content)
|
|
63
|
+
summaries.push(`### ${sliceId}\n${content}`);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// non-fatal
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return summaries;
|
|
70
|
+
}
|
|
71
|
+
function generatePRContent(basePath, milestoneId, milestoneTitle) {
|
|
72
|
+
const title = `feat: ${milestoneTitle || milestoneId}`;
|
|
73
|
+
const sections = [];
|
|
74
|
+
// TL;DR
|
|
75
|
+
sections.push("## TL;DR\n");
|
|
76
|
+
sections.push(`**What:** Ship milestone ${milestoneId} — ${milestoneTitle || "(untitled)"}`);
|
|
77
|
+
sections.push(`**Why:** Milestone work complete, ready for review.`);
|
|
78
|
+
sections.push(`**How:** See slice summaries below.\n`);
|
|
79
|
+
// What — slice summaries
|
|
80
|
+
const summaries = collectSliceSummaries(basePath, milestoneId);
|
|
81
|
+
if (summaries.length > 0) {
|
|
82
|
+
sections.push("## What\n");
|
|
83
|
+
sections.push(summaries.join("\n\n"));
|
|
84
|
+
sections.push("");
|
|
85
|
+
}
|
|
86
|
+
// Roadmap status
|
|
87
|
+
const roadmapPath = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
|
|
88
|
+
if (roadmapPath && existsSync(roadmapPath)) {
|
|
89
|
+
try {
|
|
90
|
+
const roadmap = readFileSync(roadmapPath, "utf-8");
|
|
91
|
+
const checkboxLines = roadmap.split("\n").filter((l) => /^\s*-\s*\[[ x]\]/.test(l));
|
|
92
|
+
if (checkboxLines.length > 0) {
|
|
93
|
+
sections.push("## Roadmap\n");
|
|
94
|
+
sections.push(checkboxLines.join("\n"));
|
|
95
|
+
sections.push("");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// non-fatal
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Metrics
|
|
103
|
+
const ledger = getLedger();
|
|
104
|
+
const units = ledger?.units ?? loadLedgerFromDisk(basePath)?.units ?? [];
|
|
105
|
+
if (units.length > 0) {
|
|
106
|
+
const totals = getProjectTotals(units);
|
|
107
|
+
const byModel = aggregateByModel(units);
|
|
108
|
+
sections.push("## Metrics\n");
|
|
109
|
+
sections.push(`- **Units executed:** ${units.length}`);
|
|
110
|
+
sections.push(`- **Total cost:** ${formatCost(totals.cost)}`);
|
|
111
|
+
sections.push(`- **Tokens:** ${formatTokenCount(totals.tokens.input)} input / ${formatTokenCount(totals.tokens.output)} output`);
|
|
112
|
+
if (totals.duration > 0) {
|
|
113
|
+
sections.push(`- **Duration:** ${formatDuration(totals.duration)}`);
|
|
114
|
+
}
|
|
115
|
+
if (byModel.length > 0) {
|
|
116
|
+
sections.push(`- **Models:** ${byModel.map((m) => `${m.model} (${m.units} units)`).join(", ")}`);
|
|
117
|
+
}
|
|
118
|
+
sections.push("");
|
|
119
|
+
}
|
|
120
|
+
// Change type checklist
|
|
121
|
+
sections.push("## Change type\n");
|
|
122
|
+
sections.push("- [x] `feat` — New feature or capability");
|
|
123
|
+
sections.push("- [ ] `fix` — Bug fix");
|
|
124
|
+
sections.push("- [ ] `refactor` — Code restructuring");
|
|
125
|
+
sections.push("- [ ] `test` — Adding or updating tests");
|
|
126
|
+
sections.push("- [ ] `docs` — Documentation only");
|
|
127
|
+
sections.push("- [ ] `chore` — Build, CI, or tooling changes\n");
|
|
128
|
+
// AI disclosure
|
|
129
|
+
sections.push("---\n");
|
|
130
|
+
sections.push("*This PR was prepared with AI assistance (GSD auto-mode).*");
|
|
131
|
+
return { title, body: sections.join("\n") };
|
|
132
|
+
}
|
|
133
|
+
export async function handleShip(args, ctx, _pi) {
|
|
134
|
+
const basePath = process.cwd();
|
|
135
|
+
const dryRun = args.includes("--dry-run");
|
|
136
|
+
const draft = args.includes("--draft");
|
|
137
|
+
const force = args.includes("--force");
|
|
138
|
+
const baseMatch = args.match(/--base\s+(\S+)/);
|
|
139
|
+
const base = baseMatch?.[1] ?? nativeDetectMainBranch(basePath);
|
|
140
|
+
if (!isValidRefName(base)) {
|
|
141
|
+
ctx.ui.notify(`Invalid base branch name: ${base}`, "error");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// 1. Validate milestone state
|
|
145
|
+
const state = await deriveState(basePath);
|
|
146
|
+
if (!state.activeMilestone) {
|
|
147
|
+
ctx.ui.notify("No active milestone to ship. Complete milestone work first.", "warning");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const milestoneId = state.activeMilestone.id;
|
|
151
|
+
const milestoneTitle = state.activeMilestone.title ?? "";
|
|
152
|
+
// 2. Check for incomplete work (use GSD phase as proxy — no phase field on ActiveRef)
|
|
153
|
+
if (state.phase !== "complete" && !force) {
|
|
154
|
+
ctx.ui.notify(`Milestone ${milestoneId} may not be complete (phase: ${state.phase}). Use --force to ship anyway.`, "warning");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// 3. Generate PR content
|
|
158
|
+
const { title, body } = generatePRContent(basePath, milestoneId, milestoneTitle);
|
|
159
|
+
// 4. Dry-run — just show the PR content
|
|
160
|
+
if (dryRun) {
|
|
161
|
+
ctx.ui.notify(`--- PR Preview ---\n\nTitle: ${title}\n\n${body}`, "info");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// 5. Check git state
|
|
165
|
+
const currentBranch = nativeGetCurrentBranch(basePath);
|
|
166
|
+
if (!isValidRefName(currentBranch)) {
|
|
167
|
+
ctx.ui.notify(`Current branch name is invalid for git: ${currentBranch}`, "error");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (currentBranch === base) {
|
|
171
|
+
ctx.ui.notify(`You're on ${base} — create a feature branch first.`, "warning");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// 6. Push and create PR (all argv-safe, no shell interpolation)
|
|
175
|
+
try {
|
|
176
|
+
git(basePath, ["push", "-u", "origin", currentBranch]);
|
|
177
|
+
const ghArgs = ["pr", "create", "--base", base, "--title", title, "--body", body];
|
|
178
|
+
if (draft)
|
|
179
|
+
ghArgs.push("--draft");
|
|
180
|
+
const prUrl = execFileSync("gh", ghArgs, { cwd: basePath, encoding: "utf-8" }).trim();
|
|
181
|
+
ctx.ui.notify(`PR created: ${prUrl}`, "success");
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
185
|
+
ctx.ui.notify(`Failed to create PR: ${msg}`, "error");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -301,8 +301,7 @@ export async function saveRequirementToDb(fields, basePath) {
|
|
|
301
301
|
catch (diskErr) {
|
|
302
302
|
logError('manifest', 'disk write failed, rolling back DB row', { fn: 'saveRequirementToDb', error: String(diskErr.message) });
|
|
303
303
|
try {
|
|
304
|
-
|
|
305
|
-
rollbackAdapter?.prepare('DELETE FROM requirements WHERE id = :id').run({ ':id': id });
|
|
304
|
+
db.deleteRequirementById(id);
|
|
306
305
|
}
|
|
307
306
|
catch (rollbackErr) {
|
|
308
307
|
logError('manifest', 'SPLIT BRAIN: disk write failed AND DB rollback failed — DB has orphaned row', { fn: 'saveRequirementToDb', id, error: String(rollbackErr.message) });
|
|
@@ -405,7 +404,7 @@ export async function saveDecisionToDb(fields, basePath) {
|
|
|
405
404
|
catch (diskErr) {
|
|
406
405
|
logError('manifest', 'disk write failed, rolling back DB row', { fn: 'saveDecisionToDb', error: String(diskErr.message) });
|
|
407
406
|
try {
|
|
408
|
-
|
|
407
|
+
db.deleteDecisionById(id);
|
|
409
408
|
}
|
|
410
409
|
catch (rollbackErr) {
|
|
411
410
|
logError('manifest', 'SPLIT BRAIN: disk write failed AND DB rollback failed — DB has orphaned row', { fn: 'saveDecisionToDb', id, error: String(rollbackErr.message) });
|
|
@@ -614,8 +613,7 @@ export async function saveArtifactToDb(opts, basePath) {
|
|
|
614
613
|
}
|
|
615
614
|
catch (diskErr) {
|
|
616
615
|
logError('manifest', 'disk write failed, rolling back DB row', { fn: 'saveArtifactToDb', error: String(diskErr.message) });
|
|
617
|
-
|
|
618
|
-
rollbackAdapter?.prepare('DELETE FROM artifacts WHERE path = :path').run({ ':path': opts.path });
|
|
616
|
+
db.deleteArtifactByPath(opts.path);
|
|
619
617
|
throw diskErr;
|
|
620
618
|
}
|
|
621
619
|
}
|
|
@@ -157,7 +157,7 @@ Setting `prefer_skills: []` does **not** disable skill discovery — it just mea
|
|
|
157
157
|
|
|
158
158
|
- `phases`: fine-grained control over which phases run. Usually set by `token_profile`, but can be overridden. Keys:
|
|
159
159
|
- `skip_research`: boolean — skip milestone-level research. Default: `false`.
|
|
160
|
-
- `reassess_after_slice`: boolean — run roadmap reassessment after each completed slice. Default: `
|
|
160
|
+
- `reassess_after_slice`: boolean — run roadmap reassessment after each completed slice. Default: `true`.
|
|
161
161
|
- `skip_reassess`: boolean — force-disable roadmap reassessment even if `reassess_after_slice` is enabled. Default: `false`.
|
|
162
162
|
- `skip_slice_research`: boolean — skip per-slice research. Default: `false`.
|
|
163
163
|
|
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Exposes a unified sync API for decisions and requirements storage.
|
|
6
6
|
// Schema is initialized on first open with WAL mode for file-backed DBs.
|
|
7
|
+
//
|
|
8
|
+
// ─── Single-writer invariant ─────────────────────────────────────────────
|
|
9
|
+
// This file is the ONLY place in the codebase that issues write SQL
|
|
10
|
+
// (INSERT / UPDATE / DELETE / REPLACE / BEGIN-COMMIT transactions) against
|
|
11
|
+
// the engine database at `.gsd/gsd.db`. All other modules must call the
|
|
12
|
+
// typed wrappers exported here. The structural test
|
|
13
|
+
// `tests/single-writer-invariant.test.ts` fails CI if a new bypass appears.
|
|
14
|
+
//
|
|
15
|
+
// `_getAdapter()` is retained for read-only SELECTs in query modules
|
|
16
|
+
// (context-store, memory-store queries, doctor checks, projections).
|
|
17
|
+
// Do NOT use it for writes — add a wrapper here instead.
|
|
18
|
+
//
|
|
19
|
+
// The separate `.gsd/unit-claims.db` managed by `unit-ownership.ts` is an
|
|
20
|
+
// intentionally independent store for cross-worktree claim races and is
|
|
21
|
+
// excluded from this invariant.
|
|
7
22
|
import { createRequire } from "node:module";
|
|
8
23
|
import { existsSync, copyFileSync, mkdirSync, realpathSync } from "node:fs";
|
|
9
24
|
import { dirname } from "node:path";
|
|
@@ -863,6 +878,50 @@ export function transaction(fn) {
|
|
|
863
878
|
_txDepth--;
|
|
864
879
|
}
|
|
865
880
|
}
|
|
881
|
+
/**
|
|
882
|
+
* Wrap a block of reads in a DEFERRED transaction so that all SELECTs observe
|
|
883
|
+
* a consistent snapshot of the DB even if a concurrent writer commits between
|
|
884
|
+
* them. Use this for multi-query read flows (e.g. tool executors that query
|
|
885
|
+
* milestone + slices + counts and want one snapshot). Re-entrant — if already
|
|
886
|
+
* inside a transaction, runs fn() without starting a nested one.
|
|
887
|
+
*/
|
|
888
|
+
export function readTransaction(fn) {
|
|
889
|
+
if (!currentDb)
|
|
890
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
891
|
+
if (_txDepth > 0) {
|
|
892
|
+
_txDepth++;
|
|
893
|
+
try {
|
|
894
|
+
return fn();
|
|
895
|
+
}
|
|
896
|
+
finally {
|
|
897
|
+
_txDepth--;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
_txDepth++;
|
|
901
|
+
currentDb.exec("BEGIN DEFERRED");
|
|
902
|
+
try {
|
|
903
|
+
const result = fn();
|
|
904
|
+
currentDb.exec("COMMIT");
|
|
905
|
+
return result;
|
|
906
|
+
}
|
|
907
|
+
catch (err) {
|
|
908
|
+
try {
|
|
909
|
+
currentDb.exec("ROLLBACK");
|
|
910
|
+
}
|
|
911
|
+
catch (rollbackErr) {
|
|
912
|
+
// A failed ROLLBACK after a failed read is a split-brain signal —
|
|
913
|
+
// the transaction is in an indeterminate state. Surface it via the
|
|
914
|
+
// logger instead of swallowing it.
|
|
915
|
+
logError("db", "snapshotState ROLLBACK failed", {
|
|
916
|
+
error: rollbackErr.message,
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
throw err;
|
|
920
|
+
}
|
|
921
|
+
finally {
|
|
922
|
+
_txDepth--;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
866
925
|
export function insertDecision(d) {
|
|
867
926
|
if (!currentDb)
|
|
868
927
|
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
@@ -2045,3 +2104,265 @@ export function getPendingGatesForTurn(milestoneId, sliceId, turn, taskId) {
|
|
|
2045
2104
|
export function getPendingGateCountForTurn(milestoneId, sliceId, turn) {
|
|
2046
2105
|
return getPendingGatesForTurn(milestoneId, sliceId, turn).length;
|
|
2047
2106
|
}
|
|
2107
|
+
// ─── Single-writer bypass wrappers ───────────────────────────────────────
|
|
2108
|
+
// These wrappers exist so modules outside this file never need to call
|
|
2109
|
+
// `_getAdapter()` for writes. Each one is a byte-equivalent replacement for
|
|
2110
|
+
// a raw prepare/run previously issued from another module. Keep them
|
|
2111
|
+
// minimal and direct — they exist to hold SQL text in one place, not to
|
|
2112
|
+
// add new behavior.
|
|
2113
|
+
/** Delete a decision row by id. Used by db-writer.ts rollback on disk-write failure. */
|
|
2114
|
+
export function deleteDecisionById(id) {
|
|
2115
|
+
if (!currentDb)
|
|
2116
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2117
|
+
currentDb.prepare("DELETE FROM decisions WHERE id = :id").run({ ":id": id });
|
|
2118
|
+
}
|
|
2119
|
+
/** Delete a requirement row by id. Used by db-writer.ts rollback on disk-write failure. */
|
|
2120
|
+
export function deleteRequirementById(id) {
|
|
2121
|
+
if (!currentDb)
|
|
2122
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2123
|
+
currentDb.prepare("DELETE FROM requirements WHERE id = :id").run({ ":id": id });
|
|
2124
|
+
}
|
|
2125
|
+
/** Delete an artifact row by path. Used by db-writer.ts rollback on disk-write failure. */
|
|
2126
|
+
export function deleteArtifactByPath(path) {
|
|
2127
|
+
if (!currentDb)
|
|
2128
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2129
|
+
currentDb.prepare("DELETE FROM artifacts WHERE path = :path").run({ ":path": path });
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Drop all rows from tasks/slices/milestones in dependency order inside a
|
|
2133
|
+
* transaction. Used by `gsd recover` to rebuild engine state from markdown.
|
|
2134
|
+
*/
|
|
2135
|
+
export function clearEngineHierarchy() {
|
|
2136
|
+
if (!currentDb)
|
|
2137
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2138
|
+
transaction(() => {
|
|
2139
|
+
currentDb.exec("DELETE FROM tasks");
|
|
2140
|
+
currentDb.exec("DELETE FROM slices");
|
|
2141
|
+
currentDb.exec("DELETE FROM milestones");
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* INSERT OR IGNORE a slice during event replay (workflow-reconcile.ts).
|
|
2146
|
+
* Strict insert-or-ignore semantics are required here to avoid the
|
|
2147
|
+
* `insertSlice` ON CONFLICT path that could downgrade an already-completed
|
|
2148
|
+
* slice back to 'pending'.
|
|
2149
|
+
*/
|
|
2150
|
+
export function insertOrIgnoreSlice(args) {
|
|
2151
|
+
if (!currentDb)
|
|
2152
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2153
|
+
currentDb.prepare(`INSERT OR IGNORE INTO slices (milestone_id, id, title, status, created_at)
|
|
2154
|
+
VALUES (:mid, :sid, :title, 'pending', :ts)`).run({
|
|
2155
|
+
":mid": args.milestoneId,
|
|
2156
|
+
":sid": args.sliceId,
|
|
2157
|
+
":title": args.title,
|
|
2158
|
+
":ts": args.createdAt,
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* INSERT OR IGNORE a task during event replay (workflow-reconcile.ts).
|
|
2163
|
+
* Same rationale as `insertOrIgnoreSlice`.
|
|
2164
|
+
*/
|
|
2165
|
+
export function insertOrIgnoreTask(args) {
|
|
2166
|
+
if (!currentDb)
|
|
2167
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2168
|
+
currentDb.prepare(`INSERT OR IGNORE INTO tasks (milestone_id, slice_id, id, title, status, created_at)
|
|
2169
|
+
VALUES (:mid, :sid, :tid, :title, 'pending', :ts)`).run({
|
|
2170
|
+
":mid": args.milestoneId,
|
|
2171
|
+
":sid": args.sliceId,
|
|
2172
|
+
":tid": args.taskId,
|
|
2173
|
+
":title": args.title,
|
|
2174
|
+
":ts": args.createdAt,
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Stamp the `replan_triggered_at` column on a slice. Used by triage-resolution
|
|
2179
|
+
* when a user capture requests a replan so the dispatcher can detect the
|
|
2180
|
+
* trigger via DB in addition to the on-disk REPLAN-TRIGGER.md marker.
|
|
2181
|
+
*/
|
|
2182
|
+
export function setSliceReplanTriggeredAt(milestoneId, sliceId, ts) {
|
|
2183
|
+
if (!currentDb)
|
|
2184
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2185
|
+
currentDb.prepare("UPDATE slices SET replan_triggered_at = :ts WHERE milestone_id = :mid AND id = :sid").run({ ":ts": ts, ":mid": milestoneId, ":sid": sliceId });
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* INSERT OR REPLACE a quality_gates row. Used by milestone-validation-gates.ts
|
|
2189
|
+
* to persist milestone-level (MV*) gate outcomes after validate-milestone runs.
|
|
2190
|
+
*/
|
|
2191
|
+
export function upsertQualityGate(g) {
|
|
2192
|
+
if (!currentDb)
|
|
2193
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2194
|
+
currentDb.prepare(`INSERT OR REPLACE INTO quality_gates
|
|
2195
|
+
(milestone_id, slice_id, gate_id, scope, task_id, status, verdict, rationale, findings, evaluated_at)
|
|
2196
|
+
VALUES (:mid, :sid, :gid, :scope, :tid, :status, :verdict, :rationale, :findings, :evaluated_at)`).run({
|
|
2197
|
+
":mid": g.milestoneId,
|
|
2198
|
+
":sid": g.sliceId,
|
|
2199
|
+
":gid": g.gateId,
|
|
2200
|
+
":scope": g.scope,
|
|
2201
|
+
":tid": g.taskId,
|
|
2202
|
+
":status": g.status,
|
|
2203
|
+
":verdict": g.verdict,
|
|
2204
|
+
":rationale": g.rationale,
|
|
2205
|
+
":findings": g.findings,
|
|
2206
|
+
":evaluated_at": g.evaluatedAt,
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Atomically replace all workflow state from a manifest. Lifted verbatim from
|
|
2211
|
+
* workflow-manifest.ts so the single-writer invariant holds. Only touches
|
|
2212
|
+
* engine tables + decisions. Does NOT modify artifacts or memories.
|
|
2213
|
+
*/
|
|
2214
|
+
export function restoreManifest(manifest) {
|
|
2215
|
+
if (!currentDb)
|
|
2216
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2217
|
+
const db = currentDb;
|
|
2218
|
+
transaction(() => {
|
|
2219
|
+
// Clear engine tables (order matters for foreign-key-like consistency)
|
|
2220
|
+
db.exec("DELETE FROM verification_evidence");
|
|
2221
|
+
db.exec("DELETE FROM tasks");
|
|
2222
|
+
db.exec("DELETE FROM slices");
|
|
2223
|
+
db.exec("DELETE FROM milestones");
|
|
2224
|
+
db.exec("DELETE FROM decisions WHERE 1=1");
|
|
2225
|
+
// Restore milestones
|
|
2226
|
+
const msStmt = db.prepare(`INSERT INTO milestones (id, title, status, depends_on, created_at, completed_at,
|
|
2227
|
+
vision, success_criteria, key_risks, proof_strategy,
|
|
2228
|
+
verification_contract, verification_integration, verification_operational, verification_uat,
|
|
2229
|
+
definition_of_done, requirement_coverage, boundary_map_markdown)
|
|
2230
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
2231
|
+
for (const m of manifest.milestones) {
|
|
2232
|
+
msStmt.run(m.id, m.title, m.status, JSON.stringify(m.depends_on), m.created_at, m.completed_at, m.vision, JSON.stringify(m.success_criteria), JSON.stringify(m.key_risks), JSON.stringify(m.proof_strategy), m.verification_contract, m.verification_integration, m.verification_operational, m.verification_uat, JSON.stringify(m.definition_of_done), m.requirement_coverage, m.boundary_map_markdown);
|
|
2233
|
+
}
|
|
2234
|
+
// Restore slices
|
|
2235
|
+
const slStmt = db.prepare(`INSERT INTO slices (milestone_id, id, title, status, risk, depends, demo,
|
|
2236
|
+
created_at, completed_at, full_summary_md, full_uat_md,
|
|
2237
|
+
goal, success_criteria, proof_level, integration_closure, observability_impact,
|
|
2238
|
+
sequence, replan_triggered_at)
|
|
2239
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
2240
|
+
for (const s of manifest.slices) {
|
|
2241
|
+
slStmt.run(s.milestone_id, s.id, s.title, s.status, s.risk, JSON.stringify(s.depends), s.demo, s.created_at, s.completed_at, s.full_summary_md, s.full_uat_md, s.goal, s.success_criteria, s.proof_level, s.integration_closure, s.observability_impact, s.sequence, s.replan_triggered_at);
|
|
2242
|
+
}
|
|
2243
|
+
// Restore tasks
|
|
2244
|
+
const tkStmt = db.prepare(`INSERT INTO tasks (milestone_id, slice_id, id, title, status,
|
|
2245
|
+
one_liner, narrative, verification_result, duration, completed_at,
|
|
2246
|
+
blocker_discovered, deviations, known_issues, key_files, key_decisions,
|
|
2247
|
+
full_summary_md, description, estimate, files, verify,
|
|
2248
|
+
inputs, expected_output, observability_impact, sequence)
|
|
2249
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
2250
|
+
for (const t of manifest.tasks) {
|
|
2251
|
+
tkStmt.run(t.milestone_id, t.slice_id, t.id, t.title, t.status, t.one_liner, t.narrative, t.verification_result, t.duration, t.completed_at, t.blocker_discovered ? 1 : 0, t.deviations, t.known_issues, JSON.stringify(t.key_files), JSON.stringify(t.key_decisions), t.full_summary_md, t.description, t.estimate, JSON.stringify(t.files), t.verify, JSON.stringify(t.inputs), JSON.stringify(t.expected_output), t.observability_impact, t.sequence);
|
|
2252
|
+
}
|
|
2253
|
+
// Restore decisions
|
|
2254
|
+
const dcStmt = db.prepare(`INSERT INTO decisions (seq, id, when_context, scope, decision, choice, rationale, revisable, made_by, superseded_by)
|
|
2255
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
2256
|
+
for (const d of manifest.decisions) {
|
|
2257
|
+
dcStmt.run(d.seq, d.id, d.when_context, d.scope, d.decision, d.choice, d.rationale, d.revisable, d.made_by, d.superseded_by);
|
|
2258
|
+
}
|
|
2259
|
+
// Restore verification evidence
|
|
2260
|
+
const evStmt = db.prepare(`INSERT INTO verification_evidence (task_id, slice_id, milestone_id, command, exit_code, verdict, duration_ms, created_at)
|
|
2261
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
2262
|
+
for (const e of manifest.verification_evidence) {
|
|
2263
|
+
evStmt.run(e.task_id, e.slice_id, e.milestone_id, e.command, e.exit_code, e.verdict, e.duration_ms, e.created_at);
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Bulk delete + insert a legacy milestone hierarchy for markdown → DB migration.
|
|
2269
|
+
* Used by workflow-migration.ts to populate engine tables from parsed ROADMAP/PLAN
|
|
2270
|
+
* files. All operations run inside a single transaction.
|
|
2271
|
+
*/
|
|
2272
|
+
export function bulkInsertLegacyHierarchy(payload) {
|
|
2273
|
+
if (!currentDb)
|
|
2274
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2275
|
+
const db = currentDb;
|
|
2276
|
+
const { milestones, slices, tasks, clearMilestoneIds, createdAt } = payload;
|
|
2277
|
+
if (clearMilestoneIds.length === 0)
|
|
2278
|
+
return;
|
|
2279
|
+
const placeholders = clearMilestoneIds.map(() => "?").join(",");
|
|
2280
|
+
transaction(() => {
|
|
2281
|
+
db.prepare(`DELETE FROM tasks WHERE milestone_id IN (${placeholders})`).run(...clearMilestoneIds);
|
|
2282
|
+
db.prepare(`DELETE FROM slices WHERE milestone_id IN (${placeholders})`).run(...clearMilestoneIds);
|
|
2283
|
+
db.prepare(`DELETE FROM milestones WHERE id IN (${placeholders})`).run(...clearMilestoneIds);
|
|
2284
|
+
const insertMilestone = db.prepare("INSERT INTO milestones (id, title, status, created_at) VALUES (?, ?, ?, ?)");
|
|
2285
|
+
for (const m of milestones) {
|
|
2286
|
+
insertMilestone.run(m.id, m.title, m.status, createdAt);
|
|
2287
|
+
}
|
|
2288
|
+
const insertSliceStmt = db.prepare("INSERT INTO slices (id, milestone_id, title, status, risk, depends, sequence, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
|
2289
|
+
for (const s of slices) {
|
|
2290
|
+
insertSliceStmt.run(s.id, s.milestoneId, s.title, s.status, s.risk, "[]", s.sequence, createdAt);
|
|
2291
|
+
}
|
|
2292
|
+
const insertTaskStmt = db.prepare("INSERT INTO tasks (id, slice_id, milestone_id, title, description, status, estimate, files, sequence) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
2293
|
+
for (const t of tasks) {
|
|
2294
|
+
insertTaskStmt.run(t.id, t.sliceId, t.milestoneId, t.title, "", t.status, "", "[]", t.sequence);
|
|
2295
|
+
}
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
// ─── Memory store writers ────────────────────────────────────────────────
|
|
2299
|
+
// All memory writes go through gsd-db.ts so the single-writer invariant
|
|
2300
|
+
// holds. These are direct pass-throughs to the SQL previously in
|
|
2301
|
+
// memory-store.ts — same bindings, same behavior.
|
|
2302
|
+
export function insertMemoryRow(args) {
|
|
2303
|
+
if (!currentDb)
|
|
2304
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2305
|
+
currentDb.prepare(`INSERT INTO memories (id, category, content, confidence, source_unit_type, source_unit_id, created_at, updated_at)
|
|
2306
|
+
VALUES (:id, :category, :content, :confidence, :source_unit_type, :source_unit_id, :created_at, :updated_at)`).run({
|
|
2307
|
+
":id": args.id,
|
|
2308
|
+
":category": args.category,
|
|
2309
|
+
":content": args.content,
|
|
2310
|
+
":confidence": args.confidence,
|
|
2311
|
+
":source_unit_type": args.sourceUnitType,
|
|
2312
|
+
":source_unit_id": args.sourceUnitId,
|
|
2313
|
+
":created_at": args.createdAt,
|
|
2314
|
+
":updated_at": args.updatedAt,
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
export function rewriteMemoryId(placeholderId, realId) {
|
|
2318
|
+
if (!currentDb)
|
|
2319
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2320
|
+
currentDb.prepare("UPDATE memories SET id = :real_id WHERE id = :placeholder").run({
|
|
2321
|
+
":real_id": realId,
|
|
2322
|
+
":placeholder": placeholderId,
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
export function updateMemoryContentRow(id, content, confidence, updatedAt) {
|
|
2326
|
+
if (!currentDb)
|
|
2327
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2328
|
+
if (confidence != null) {
|
|
2329
|
+
currentDb.prepare("UPDATE memories SET content = :content, confidence = :confidence, updated_at = :updated_at WHERE id = :id").run({ ":content": content, ":confidence": confidence, ":updated_at": updatedAt, ":id": id });
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
currentDb.prepare("UPDATE memories SET content = :content, updated_at = :updated_at WHERE id = :id").run({ ":content": content, ":updated_at": updatedAt, ":id": id });
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
export function incrementMemoryHitCount(id, updatedAt) {
|
|
2336
|
+
if (!currentDb)
|
|
2337
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2338
|
+
currentDb.prepare("UPDATE memories SET hit_count = hit_count + 1, updated_at = :updated_at WHERE id = :id").run({ ":updated_at": updatedAt, ":id": id });
|
|
2339
|
+
}
|
|
2340
|
+
export function supersedeMemoryRow(oldId, newId, updatedAt) {
|
|
2341
|
+
if (!currentDb)
|
|
2342
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2343
|
+
currentDb.prepare("UPDATE memories SET superseded_by = :new_id, updated_at = :updated_at WHERE id = :old_id").run({ ":new_id": newId, ":updated_at": updatedAt, ":old_id": oldId });
|
|
2344
|
+
}
|
|
2345
|
+
export function markMemoryUnitProcessed(unitKey, activityFile, processedAt) {
|
|
2346
|
+
if (!currentDb)
|
|
2347
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2348
|
+
currentDb.prepare(`INSERT OR IGNORE INTO memory_processed_units (unit_key, activity_file, processed_at)
|
|
2349
|
+
VALUES (:key, :file, :at)`).run({ ":key": unitKey, ":file": activityFile, ":at": processedAt });
|
|
2350
|
+
}
|
|
2351
|
+
export function decayMemoriesBefore(cutoffTs, now) {
|
|
2352
|
+
if (!currentDb)
|
|
2353
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2354
|
+
currentDb.prepare(`UPDATE memories
|
|
2355
|
+
SET confidence = MAX(0.1, confidence - 0.1), updated_at = :now
|
|
2356
|
+
WHERE superseded_by IS NULL AND updated_at < :cutoff AND confidence > 0.1`).run({ ":now": now, ":cutoff": cutoffTs });
|
|
2357
|
+
}
|
|
2358
|
+
export function supersedeLowestRankedMemories(limit, now) {
|
|
2359
|
+
if (!currentDb)
|
|
2360
|
+
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2361
|
+
currentDb.prepare(`UPDATE memories SET superseded_by = 'CAP_EXCEEDED', updated_at = :now
|
|
2362
|
+
WHERE id IN (
|
|
2363
|
+
SELECT id FROM memories
|
|
2364
|
+
WHERE superseded_by IS NULL
|
|
2365
|
+
ORDER BY (confidence * (1.0 + hit_count * 0.1)) ASC
|
|
2366
|
+
LIMIT :limit
|
|
2367
|
+
)`).run({ ":now": now, ":limit": limit });
|
|
2368
|
+
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
export { isDepthConfirmationAnswer, isDepthVerified, isGateQuestionId, isQueuePhaseActive, setQueuePhaseActive, shouldBlockContextWrite, shouldBlockPendingGate, shouldBlockPendingGateBash, shouldBlockQueueExecution, setPendingGate, clearPendingGate, getPendingGate, } from "./bootstrap/write-gate.js";
|
|
2
2
|
export default async function registerExtension(pi) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// Always register the core /gsd command first, in isolation.
|
|
4
|
+
// This ensures /gsd is available even if the full bootstrap (shortcuts,
|
|
5
|
+
// tools, hooks) fails — e.g. due to a Windows-specific import error.
|
|
6
|
+
const { registerGSDCommand } = await import("./commands/index.js");
|
|
7
|
+
registerGSDCommand(pi);
|
|
8
|
+
// Full setup (shortcuts, tools, hooks) in a separate try/catch so that
|
|
9
|
+
// any platform-specific load failure doesn't take out the core command.
|
|
10
|
+
try {
|
|
11
|
+
const { registerGsdExtension } = await import("./bootstrap/register-extension.js");
|
|
12
|
+
registerGsdExtension(pi);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
const { logWarning } = await import("./workflow-logger.js");
|
|
16
|
+
logWarning("bootstrap", `Extension setup partially failed — /gsd commands are available but shortcuts/tools may be missing: ${err instanceof Error ? err.message : String(err)}`);
|
|
17
|
+
}
|
|
5
18
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Exports: parseDecisionsTable, parseRequirementsSections, migrateFromMarkdown
|
|
6
6
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import { upsertDecision, upsertRequirement, insertArtifact, insertMilestone, insertSlice, insertTask, openDatabase, transaction, _getAdapter, } from './gsd-db.js';
|
|
8
|
+
import { upsertDecision, upsertRequirement, insertArtifact, insertMilestone, insertSlice, insertTask, openDatabase, transaction, updateSliceStatus, _getAdapter, } from './gsd-db.js';
|
|
9
9
|
import { resolveGsdRootFile, resolveMilestoneFile, resolveSliceFile, resolveTasksDir, milestonesDir, gsdRoot, resolveTaskFiles, } from './paths.js';
|
|
10
10
|
import { findMilestoneIds } from './guided-flow.js';
|
|
11
11
|
import { parseRoadmap, parsePlan } from './parsers-legacy.js';
|
|
@@ -571,9 +571,8 @@ export function migrateHierarchyToDb(basePath) {
|
|
|
571
571
|
return t.done && existsSync(summaryFile);
|
|
572
572
|
});
|
|
573
573
|
if (allTasksDone && hasSliceSummary) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
adapter.prepare(`UPDATE slices SET status = 'complete' WHERE id = :sid AND milestone_id = :mid`).run({ ':sid': sliceEntry.id, ':mid': milestoneId });
|
|
574
|
+
if (_getAdapter()) {
|
|
575
|
+
updateSliceStatus(milestoneId, sliceEntry.id, 'complete');
|
|
577
576
|
process.stderr.write(`gsd-migrate: ${milestoneId}/${sliceEntry.id} all tasks + slice summary complete — upgrading slice to complete\n`);
|
|
578
577
|
}
|
|
579
578
|
}
|