gsd-pi 2.74.0-dev.2b524c3 → 2.74.0-dev.b741afb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/cli.js +85 -0
  2. package/dist/headless-query.js +4 -1
  3. package/dist/help-text.js +23 -0
  4. package/dist/resources/extensions/gsd/auto/detect-stuck.js +11 -4
  5. package/dist/resources/extensions/gsd/auto/phases.js +45 -1
  6. package/dist/resources/extensions/gsd/auto-post-unit.js +52 -56
  7. package/dist/resources/extensions/gsd/auto-prompts.js +12 -0
  8. package/dist/resources/extensions/gsd/auto.js +8 -2
  9. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +21 -8
  10. package/dist/resources/extensions/gsd/commands/catalog.js +26 -1
  11. package/dist/resources/extensions/gsd/commands/handlers/ops.js +20 -0
  12. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +68 -9
  13. package/dist/resources/extensions/gsd/commands-add-tests.js +111 -0
  14. package/dist/resources/extensions/gsd/commands-backlog.js +140 -0
  15. package/dist/resources/extensions/gsd/commands-do.js +79 -0
  16. package/dist/resources/extensions/gsd/commands-maintenance.js +6 -6
  17. package/dist/resources/extensions/gsd/commands-pr-branch.js +180 -0
  18. package/dist/resources/extensions/gsd/commands-session-report.js +82 -0
  19. package/dist/resources/extensions/gsd/commands-ship.js +187 -0
  20. package/dist/resources/extensions/gsd/db-writer.js +3 -5
  21. package/dist/resources/extensions/gsd/graph-context.js +66 -0
  22. package/dist/resources/extensions/gsd/gsd-db.js +321 -0
  23. package/dist/resources/extensions/gsd/index.js +15 -2
  24. package/dist/resources/extensions/gsd/md-importer.js +3 -4
  25. package/dist/resources/extensions/gsd/memory-store.js +19 -51
  26. package/dist/resources/extensions/gsd/milestone-validation-gates.js +13 -12
  27. package/dist/resources/extensions/gsd/native-git-bridge.js +7 -4
  28. package/dist/resources/extensions/gsd/prompts/add-tests.md +35 -0
  29. package/dist/resources/extensions/gsd/state.js +5 -1
  30. package/dist/resources/extensions/gsd/tools/complete-slice.js +15 -0
  31. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +3 -14
  32. package/dist/resources/extensions/gsd/triage-resolution.js +2 -5
  33. package/dist/resources/extensions/gsd/workflow-manifest.js +8 -69
  34. package/dist/resources/extensions/gsd/workflow-migration.js +21 -22
  35. package/dist/resources/extensions/gsd/workflow-projections.js +4 -1
  36. package/dist/resources/extensions/gsd/workflow-reconcile.js +14 -11
  37. package/dist/tsconfig.extensions.tsbuildinfo +1 -0
  38. package/dist/web/standalone/.next/BUILD_ID +1 -1
  39. package/dist/web/standalone/.next/app-path-routes-manifest.json +7 -7
  40. package/dist/web/standalone/.next/build-manifest.json +2 -2
  41. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  42. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  43. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  51. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/index.html +1 -1
  59. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  60. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  65. package/dist/web/standalone/.next/server/app-paths-manifest.json +7 -7
  66. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  67. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  68. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  69. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  70. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  71. package/package.json +3 -2
  72. package/packages/daemon/package.json +2 -2
  73. package/packages/mcp-server/dist/index.d.ts +3 -0
  74. package/packages/mcp-server/dist/index.d.ts.map +1 -1
  75. package/packages/mcp-server/dist/index.js +3 -0
  76. package/packages/mcp-server/dist/index.js.map +1 -1
  77. package/packages/mcp-server/dist/readers/graph.d.ts +87 -0
  78. package/packages/mcp-server/dist/readers/graph.d.ts.map +1 -0
  79. package/packages/mcp-server/dist/readers/graph.js +548 -0
  80. package/packages/mcp-server/dist/readers/graph.js.map +1 -0
  81. package/packages/mcp-server/dist/readers/index.d.ts +2 -0
  82. package/packages/mcp-server/dist/readers/index.d.ts.map +1 -1
  83. package/packages/mcp-server/dist/readers/index.js +1 -0
  84. package/packages/mcp-server/dist/readers/index.js.map +1 -1
  85. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  86. package/packages/mcp-server/dist/server.js +65 -0
  87. package/packages/mcp-server/dist/server.js.map +1 -1
  88. package/packages/mcp-server/package.json +2 -2
  89. package/packages/mcp-server/src/index.ts +15 -0
  90. package/packages/mcp-server/src/readers/graph.test.ts +426 -0
  91. package/packages/mcp-server/src/readers/graph.ts +708 -0
  92. package/packages/mcp-server/src/readers/index.ts +12 -0
  93. package/packages/mcp-server/src/server.ts +83 -0
  94. package/packages/mcp-server/tsconfig.json +1 -0
  95. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -0
  96. package/packages/native/package.json +2 -2
  97. package/packages/native/tsconfig.tsbuildinfo +1 -0
  98. package/packages/pi-agent-core/package.json +1 -1
  99. package/packages/pi-agent-core/tsconfig.json +1 -0
  100. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -0
  101. package/packages/pi-ai/package.json +1 -1
  102. package/packages/pi-ai/tsconfig.json +1 -0
  103. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -0
  104. package/packages/pi-coding-agent/tsconfig.json +1 -0
  105. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -0
  106. package/packages/pi-tui/package.json +1 -1
  107. package/packages/pi-tui/tsconfig.json +1 -0
  108. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -0
  109. package/packages/rpc-client/package.json +1 -1
  110. package/packages/rpc-client/tsconfig.json +1 -0
  111. package/packages/rpc-client/tsconfig.tsbuildinfo +1 -0
  112. package/src/resources/extensions/gsd/auto/detect-stuck.ts +12 -4
  113. package/src/resources/extensions/gsd/auto/loop-deps.ts +6 -0
  114. package/src/resources/extensions/gsd/auto/phases.ts +68 -1
  115. package/src/resources/extensions/gsd/auto-post-unit.ts +60 -57
  116. package/src/resources/extensions/gsd/auto-prompts.ts +13 -0
  117. package/src/resources/extensions/gsd/auto.ts +7 -0
  118. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +24 -8
  119. package/src/resources/extensions/gsd/commands/catalog.ts +26 -1
  120. package/src/resources/extensions/gsd/commands/handlers/ops.ts +20 -0
  121. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +74 -9
  122. package/src/resources/extensions/gsd/commands-add-tests.ts +137 -0
  123. package/src/resources/extensions/gsd/commands-backlog.ts +182 -0
  124. package/src/resources/extensions/gsd/commands-do.ts +109 -0
  125. package/src/resources/extensions/gsd/commands-maintenance.ts +6 -6
  126. package/src/resources/extensions/gsd/commands-pr-branch.ts +234 -0
  127. package/src/resources/extensions/gsd/commands-session-report.ts +101 -0
  128. package/src/resources/extensions/gsd/commands-ship.ts +219 -0
  129. package/src/resources/extensions/gsd/db-writer.ts +3 -5
  130. package/src/resources/extensions/gsd/graph-context.ts +85 -0
  131. package/src/resources/extensions/gsd/gsd-db.ts +467 -0
  132. package/src/resources/extensions/gsd/index.ts +18 -2
  133. package/src/resources/extensions/gsd/md-importer.ts +3 -5
  134. package/src/resources/extensions/gsd/memory-store.ts +31 -62
  135. package/src/resources/extensions/gsd/milestone-validation-gates.ts +13 -14
  136. package/src/resources/extensions/gsd/native-git-bridge.ts +11 -12
  137. package/src/resources/extensions/gsd/prompts/add-tests.md +35 -0
  138. package/src/resources/extensions/gsd/state.ts +9 -2
  139. package/src/resources/extensions/gsd/tests/commands-backlog.test.ts +158 -0
  140. package/src/resources/extensions/gsd/tests/commands-do.test.ts +127 -0
  141. package/src/resources/extensions/gsd/tests/commands-pr-branch.test.ts +68 -0
  142. package/src/resources/extensions/gsd/tests/commands-session-report.test.ts +82 -0
  143. package/src/resources/extensions/gsd/tests/commands-ship.test.ts +71 -0
  144. package/src/resources/extensions/gsd/tests/commands-workflow-custom.test.ts +14 -0
  145. package/src/resources/extensions/gsd/tests/extension-bootstrap-isolation.test.ts +154 -0
  146. package/src/resources/extensions/gsd/tests/graph-context.test.ts +337 -0
  147. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +68 -1
  148. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +140 -0
  149. package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +180 -0
  150. package/src/resources/extensions/gsd/tests/workflow-logger-wiring.test.ts +223 -0
  151. package/src/resources/extensions/gsd/tools/complete-slice.ts +19 -0
  152. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +3 -11
  153. package/src/resources/extensions/gsd/triage-resolution.ts +2 -7
  154. package/src/resources/extensions/gsd/workflow-manifest.ts +9 -104
  155. package/src/resources/extensions/gsd/workflow-migration.ts +21 -29
  156. package/src/resources/extensions/gsd/workflow-projections.ts +8 -1
  157. package/src/resources/extensions/gsd/workflow-reconcile.ts +15 -15
  158. /package/dist/web/standalone/.next/static/{YzIEI9sxJy4t5xgClF08g → XnHY5eXUsTCFmNodWHetD}/_buildManifest.js +0 -0
  159. /package/dist/web/standalone/.next/static/{YzIEI9sxJy4t5xgClF08g → XnHY5eXUsTCFmNodWHetD}/_ssgManifest.js +0 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * GSD Command — /gsd session-report
3
+ *
4
+ * Summarizes the current session: tasks completed, cost, tokens,
5
+ * duration, model usage breakdown.
6
+ */
7
+ import { mkdirSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { getLedger, getProjectTotals, aggregateByModel, formatCost, formatTokenCount, loadLedgerFromDisk } from "./metrics.js";
10
+ import { gsdRoot } from "./paths.js";
11
+ import { formatDuration } from "../shared/format-utils.js";
12
+ function formatSessionReport(units) {
13
+ const totals = getProjectTotals(units);
14
+ const byModel = aggregateByModel(units);
15
+ const lines = [];
16
+ lines.push("╭─ Session Report ──────────────────────────────────────╮");
17
+ if (totals.duration > 0) {
18
+ lines.push(`│ Duration: ${formatDuration(totals.duration).padEnd(40)}│`);
19
+ }
20
+ lines.push(`│ Units: ${String(units.length).padEnd(40)}│`);
21
+ lines.push(`│ Cost: ${formatCost(totals.cost).padEnd(40)}│`);
22
+ lines.push(`│ Tokens: ${`${formatTokenCount(totals.tokens.input)} in / ${formatTokenCount(totals.tokens.output)} out`.padEnd(40)}│`);
23
+ lines.push("│ │");
24
+ // Work completed
25
+ if (units.length > 0) {
26
+ lines.push("│ Work Completed: │");
27
+ for (const unit of units) {
28
+ const finished = unit.finishedAt > 0;
29
+ const status = finished ? "✓" : "•";
30
+ const label = ` ${status} ${unit.id ?? "unknown"}`;
31
+ lines.push(`│ ${label.padEnd(53)}│`);
32
+ }
33
+ lines.push("│ │");
34
+ }
35
+ // Model usage
36
+ if (byModel.length > 0) {
37
+ lines.push("│ Model Usage: │");
38
+ for (const m of byModel) {
39
+ const label = ` ${m.model}: ${m.units} units (${formatCost(m.cost)})`;
40
+ lines.push(`│ ${label.padEnd(53)}│`);
41
+ }
42
+ }
43
+ lines.push("╰───────────────────────────────────────────────────────╯");
44
+ return lines.join("\n");
45
+ }
46
+ export async function handleSessionReport(args, ctx) {
47
+ const basePath = process.cwd();
48
+ // Get units from in-memory ledger or disk
49
+ const ledger = getLedger();
50
+ let units;
51
+ if (ledger && ledger.units.length > 0) {
52
+ units = ledger.units;
53
+ }
54
+ else {
55
+ const diskLedger = loadLedgerFromDisk(basePath);
56
+ if (!diskLedger || diskLedger.units.length === 0) {
57
+ ctx.ui.notify("No session data — no units have been executed yet.", "info");
58
+ return;
59
+ }
60
+ units = diskLedger.units;
61
+ }
62
+ // JSON output
63
+ if (args.includes("--json")) {
64
+ const totals = getProjectTotals(units);
65
+ const byModel = aggregateByModel(units);
66
+ ctx.ui.notify(JSON.stringify({ units: units.length, totals, byModel }, null, 2), "info");
67
+ return;
68
+ }
69
+ // Save to file
70
+ if (args.includes("--save")) {
71
+ const report = formatSessionReport(units);
72
+ const reportsDir = join(gsdRoot(basePath), "reports");
73
+ mkdirSync(reportsDir, { recursive: true });
74
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
75
+ const outPath = join(reportsDir, `session-${timestamp}.md`);
76
+ writeFileSync(outPath, `\`\`\`\n${report}\n\`\`\`\n`, "utf-8");
77
+ ctx.ui.notify(`Report saved: ${outPath}`, "success");
78
+ return;
79
+ }
80
+ // Display
81
+ ctx.ui.notify(formatSessionReport(units), "info");
82
+ }
@@ -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
- const rollbackAdapter = db._getAdapter();
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
- adapter?.prepare('DELETE FROM decisions WHERE id = :id').run({ ':id': id });
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
- const rollbackAdapter = db._getAdapter();
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
  }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Graph-aware context injection for dispatch prompt builders.
3
+ *
4
+ * Reads the pre-built graph.json and returns a formatted context block
5
+ * for injection into prompts. Gracefully returns null when no graph exists
6
+ * or the query yields no results — callers must handle null.
7
+ */
8
+ import { logWarning } from "./workflow-logger.js";
9
+ /**
10
+ * Query the knowledge graph for nodes related to the given term and format
11
+ * the result as an inlined context block.
12
+ *
13
+ * Returns null when:
14
+ * - @gsd-build/mcp-server fails to import
15
+ * - graph.json does not exist (graphQuery already handles this gracefully)
16
+ * - query returns zero nodes
17
+ *
18
+ * Annotates the block header when the graph is stale (> 24 hours old).
19
+ */
20
+ export async function inlineGraphSubgraph(projectDir, term, opts) {
21
+ if (!term || !term.trim())
22
+ return null;
23
+ try {
24
+ const { graphQuery, graphStatus } = await import("@gsd-build/mcp-server");
25
+ const result = await graphQuery(projectDir, term, opts.budget);
26
+ if (result.nodes.length === 0)
27
+ return null;
28
+ // Check staleness for annotation
29
+ let staleAnnotation = "";
30
+ try {
31
+ const status = await graphStatus(projectDir);
32
+ if (status.exists && status.stale && status.ageHours !== undefined) {
33
+ const hours = Math.round(status.ageHours);
34
+ staleAnnotation = `\n> ⚠ Graph last built ${hours}h ago — context may be outdated`;
35
+ }
36
+ }
37
+ catch {
38
+ // Non-fatal — skip annotation on error
39
+ }
40
+ // Format nodes as a compact list
41
+ const nodeLines = result.nodes.map((n) => {
42
+ const desc = n.description ? ` — ${n.description}` : "";
43
+ return `- **${n.label}** (\`${n.type}\`, ${n.confidence})${desc}`;
44
+ });
45
+ // Format edges as relations (only if present)
46
+ const edgeLines = result.edges.length > 0
47
+ ? result.edges.map((e) => `- \`${e.from}\` →[${e.type}]→ \`${e.to}\``)
48
+ : [];
49
+ const sections = [
50
+ `### Knowledge Graph Context (term: "${term}")`,
51
+ `Source: \`.gsd/graphs/graph.json\``,
52
+ staleAnnotation,
53
+ "",
54
+ `**Nodes (${result.nodes.length}):**`,
55
+ ...nodeLines,
56
+ ];
57
+ if (edgeLines.length > 0) {
58
+ sections.push("", `**Relations (${result.edges.length}):**`, ...edgeLines);
59
+ }
60
+ return sections.filter((l) => l !== undefined).join("\n");
61
+ }
62
+ catch (err) {
63
+ logWarning("prompt", `inlineGraphSubgraph failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
64
+ return null;
65
+ }
66
+ }