gsd-pi 2.80.0-dev.c5c38454b → 2.80.0-dev.f55d16d13

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 (77) hide show
  1. package/dist/resources/.managed-resources-content-hash +1 -1
  2. package/dist/resources/GSD-WORKFLOW.md +2 -2
  3. package/dist/resources/extensions/gsd/auto/phases.js +37 -30
  4. package/dist/resources/extensions/gsd/auto-post-unit.js +10 -10
  5. package/dist/resources/extensions/gsd/auto-prompts.js +111 -1
  6. package/dist/resources/extensions/gsd/auto.js +9 -1
  7. package/dist/resources/extensions/gsd/clean-root-preflight.js +42 -4
  8. package/dist/resources/extensions/gsd/detection.js +106 -0
  9. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +7 -8
  10. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
  11. package/dist/resources/extensions/gsd/safety/evidence-collector.js +10 -2
  12. package/dist/resources/extensions/gsd/worktree-manager.js +16 -14
  13. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  14. package/dist/web/standalone/.next/BUILD_ID +1 -1
  15. package/dist/web/standalone/.next/app-path-routes-manifest.json +14 -14
  16. package/dist/web/standalone/.next/build-manifest.json +2 -2
  17. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  18. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  19. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  27. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/index.html +1 -1
  35. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app-paths-manifest.json +14 -14
  42. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  43. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  44. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  45. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  46. package/package.json +1 -1
  47. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +30 -0
  48. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  49. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  50. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +2 -0
  51. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  52. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +36 -0
  53. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +2 -0
  54. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  55. package/src/resources/GSD-WORKFLOW.md +2 -2
  56. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
  57. package/src/resources/extensions/gsd/auto/phases.ts +42 -28
  58. package/src/resources/extensions/gsd/auto-post-unit.ts +10 -10
  59. package/src/resources/extensions/gsd/auto-prompts.ts +116 -1
  60. package/src/resources/extensions/gsd/auto.ts +12 -1
  61. package/src/resources/extensions/gsd/clean-root-preflight.ts +41 -3
  62. package/src/resources/extensions/gsd/detection.ts +128 -0
  63. package/src/resources/extensions/gsd/prompts/complete-milestone.md +7 -8
  64. package/src/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
  65. package/src/resources/extensions/gsd/safety/evidence-collector.ts +11 -2
  66. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +1 -1
  67. package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +88 -2
  68. package/src/resources/extensions/gsd/tests/detection.test.ts +140 -0
  69. package/src/resources/extensions/gsd/tests/right-sized-workflow-prompts.test.ts +192 -0
  70. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +29 -0
  71. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +46 -2
  72. package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +37 -6
  73. package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +7 -0
  74. package/src/resources/extensions/gsd/tests/worktree-nested-git-safety.test.ts +9 -2
  75. package/src/resources/extensions/gsd/worktree-manager.ts +15 -4
  76. /package/dist/web/standalone/.next/static/{TCSim36ZpcPu2WgeoC45g → mPZbi5BH9dwokaPZlrYuQ}/_buildManifest.js +0 -0
  77. /package/dist/web/standalone/.next/static/{TCSim36ZpcPu2WgeoC45g → mPZbi5BH9dwokaPZlrYuQ}/_ssgManifest.js +0 -0
@@ -28,7 +28,7 @@ Then do the thing `STATE.md` says to do next.
28
28
  ## The Hierarchy
29
29
 
30
30
  ```
31
- Milestone → a shippable version (4-10 slices)
31
+ Milestone → a shippable version (1-10 slices, sized to the work)
32
32
  Slice → one demoable vertical capability (1-7 tasks)
33
33
  Task → one context-window-sized unit of work (fits in one session)
34
34
  ```
@@ -331,7 +331,7 @@ The **Don't Hand-Roll** and **Common Pitfalls** sections prevent the most expens
331
331
 
332
332
  **For a milestone (roadmap):**
333
333
  1. Read `M###-CONTEXT.md`, `M###-RESEARCH.md`, and `.gsd/DECISIONS.md` if they exist.
334
- 2. Decompose the vision into 4-10 demoable vertical slices.
334
+ 2. Decompose the vision into 1-10 demoable vertical slices. Prefer one slice for tiny, single-file, or static work unless the request clearly spans independent capabilities.
335
335
  3. Order by risk (high-risk first to validate feasibility early).
336
336
  4. Write `M###-ROADMAP.md` with checkboxes, risk levels, dependencies, demo sentences.
337
337
  5. **Write the boundary map** — for each slice, specify what it produces (functions, types, interfaces, endpoints) and what it consumes from upstream slices. This forces interface thinking before implementation and enables deterministic verification that slices actually connect.
@@ -139,6 +139,7 @@ export interface LoopDeps {
139
139
  postflightPopStash: (
140
140
  basePath: string,
141
141
  milestoneId: string,
142
+ stashMarker: string | undefined,
142
143
  notify: (message: string, level: "info" | "warning" | "error") => void,
143
144
  ) => void;
144
145
 
@@ -32,13 +32,13 @@ import { detectStuck } from "./detect-stuck.js";
32
32
  import { runUnit } from "./run-unit.js";
33
33
  import { debugLog } from "../debug-logger.js";
34
34
  import { resolveWorktreeProjectRoot, normalizeWorktreePathForCompare } from "../worktree-root.js";
35
- import { PROJECT_FILES, hasProjectFileInAncestor } from "../detection.js";
35
+ import { classifyProject } from "../detection.js";
36
36
  import { MergeConflictError } from "../git-service.js";
37
37
  import { setCurrentPhase, clearCurrentPhase } from "../../shared/gsd-phase-state.js";
38
38
  import { pauseAutoForProviderError } from "../provider-error-pause.js";
39
39
  import { resumeAutoAfterProviderDelay } from "../bootstrap/provider-error-resume.js";
40
40
  import { join, basename } from "node:path";
41
- import { existsSync, cpSync, readdirSync } from "node:fs";
41
+ import { existsSync, cpSync } from "node:fs";
42
42
  import {
43
43
  logWarning,
44
44
  logError,
@@ -684,6 +684,7 @@ export async function runPreDispatch(
684
684
  deps.postflightPopStash(
685
685
  s.originalBasePath || s.basePath,
686
686
  s.currentMilestoneId!,
687
+ preflightTransition.stashMarker,
687
688
  ctx.ui.notify.bind(ctx.ui),
688
689
  );
689
690
  }
@@ -797,6 +798,7 @@ export async function runPreDispatch(
797
798
  deps.postflightPopStash(
798
799
  s.originalBasePath || s.basePath,
799
800
  s.currentMilestoneId,
801
+ preflightAllComplete.stashMarker,
800
802
  ctx.ui.notify.bind(ctx.ui),
801
803
  );
802
804
  }
@@ -925,6 +927,7 @@ export async function runPreDispatch(
925
927
  deps.postflightPopStash(
926
928
  s.originalBasePath || s.basePath,
927
929
  s.currentMilestoneId,
930
+ preflightComplete.stashMarker,
928
931
  ctx.ui.notify.bind(ctx.ui),
929
932
  );
930
933
  }
@@ -1484,8 +1487,9 @@ export async function runUnitPhase(
1484
1487
  // Verify the working directory is a valid git checkout with project
1485
1488
  // files before dispatching work. A broken worktree causes agents to
1486
1489
  // hallucinate summaries since they cannot read or write any files.
1487
- // Uses the shared PROJECT_FILES list from detection.ts to support all
1488
- // ecosystems (Rust, Go, Python, Java, etc.), not just JS.
1490
+ // Uses project classification so project presence is not conflated with
1491
+ // ecosystem marker detection. Static/minimal repos become untyped-existing.
1492
+ let projectClassification: ReturnType<typeof classifyProject> | null = null;
1489
1493
  if (s.basePath && unitType === "execute-task") {
1490
1494
  const gitMarker = join(s.basePath, ".git");
1491
1495
  const hasGit = deps.existsSync(gitMarker);
@@ -1496,30 +1500,29 @@ export async function runUnitPhase(
1496
1500
  await deps.stopAuto(ctx, pi, msg);
1497
1501
  return { action: "break", reason: "worktree-invalid" };
1498
1502
  }
1499
- const hasProjectFile = PROJECT_FILES.some((f) => deps.existsSync(join(s.basePath, f)));
1500
- const hasSrcDir = deps.existsSync(join(s.basePath, "src"));
1501
- // Xcode bundles have project-specific names (*.xcodeproj, *.xcworkspace)
1502
- // that cannot be matched by exact filename — scan the directory by suffix.
1503
- let hasXcodeBundle = false;
1504
- try {
1505
- const entries = deps.existsSync(s.basePath) ? readdirSync(s.basePath) : [];
1506
- hasXcodeBundle = entries.some((e: string) => e.endsWith(".xcodeproj") || e.endsWith(".xcworkspace"));
1507
- } catch (err) {
1508
- debugLog("runUnitPhase", { phase: "xcode-bundle-scan-failed", basePath: s.basePath, error: String(err) });
1509
- }
1510
- // Monorepo support (#2347): if no project files in the worktree directory,
1511
- // walk parent directories up to the filesystem root. In monorepos,
1512
- // package.json / Cargo.toml etc. live in a parent directory.
1513
- const hasProjectFileInParent =
1514
- !hasProjectFile && !hasSrcDir && !hasXcodeBundle
1515
- ? hasProjectFileInAncestor(s.basePath, deps.existsSync)
1516
- : false;
1517
- if (!hasProjectFile && !hasSrcDir && !hasXcodeBundle && !hasProjectFileInParent) {
1518
- // Greenfield projects won't have project files yet — the first task creates them.
1519
- // Log a warning but allow execution to proceed. The .git check above is sufficient
1520
- // to ensure we're in a valid working directory.
1521
- debugLog("runUnitPhase", { phase: "worktree-health-warn-greenfield", basePath: s.basePath, hasProjectFile, hasSrcDir, hasXcodeBundle });
1522
- ctx.ui.notify(`Warning: ${s.basePath} has no recognized project files — proceeding as greenfield project`, "warning");
1503
+ projectClassification = classifyProject(s.basePath);
1504
+ if (projectClassification.kind === "invalid-repo") {
1505
+ const msg = `Worktree health check failed: ${s.basePath} classified as invalid-repo (${projectClassification.reason}) — refusing to dispatch ${unitType} ${unitId}`;
1506
+ debugLog("runUnitPhase", { phase: "worktree-health-invalid-repo", basePath: s.basePath, classification: projectClassification });
1507
+ if (projectClassification.reason === "missing .git" && hasGit) {
1508
+ ctx.ui.notify(
1509
+ `Warning: ${s.basePath} project classification could not confirm .git; assuming it has no project content yet — proceeding as greenfield project because worktree health reported .git present`,
1510
+ "warning",
1511
+ );
1512
+ } else {
1513
+ ctx.ui.notify(msg, "error");
1514
+ await deps.stopAuto(ctx, pi, msg);
1515
+ return { action: "break", reason: "worktree-invalid" };
1516
+ }
1517
+ } else if (projectClassification.kind === "greenfield") {
1518
+ debugLog("runUnitPhase", { phase: "worktree-health-greenfield", basePath: s.basePath, classification: projectClassification });
1519
+ ctx.ui.notify(`Warning: ${s.basePath} has no project content yet — proceeding as greenfield project`, "warning");
1520
+ } else if (projectClassification.kind === "untyped-existing") {
1521
+ debugLog("runUnitPhase", { phase: "worktree-health-untyped-existing", basePath: s.basePath, classification: projectClassification });
1522
+ ctx.ui.notify(
1523
+ `Notice: ${s.basePath} has existing project content but no recognized tooling markers using generic file-level workflow guidance`,
1524
+ "info",
1525
+ );
1523
1526
  }
1524
1527
  }
1525
1528
 
@@ -1598,6 +1601,17 @@ export async function runUnitPhase(
1598
1601
  // Prompt injection
1599
1602
  let finalPrompt = prompt;
1600
1603
 
1604
+ if (unitType === "execute-task") {
1605
+ projectClassification ??= classifyProject(s.basePath);
1606
+ if (projectClassification.kind === "untyped-existing") {
1607
+ const samples = projectClassification.contentFiles.slice(0, 8).join(", ") || "project files";
1608
+ finalPrompt +=
1609
+ "\n\n**Project classification:** Existing untyped project. No recognized build/tooling markers were detected, " +
1610
+ "so use generic file-level workflow guidance. Task plans and completion summaries must list every concrete " +
1611
+ `project file changed in \`files\` or \`expected_output\`. Detected content sample: ${samples}.`;
1612
+ }
1613
+ }
1614
+
1601
1615
  if (s.pendingVerificationRetry) {
1602
1616
  const retryCtx = s.pendingVerificationRetry;
1603
1617
  s.pendingVerificationRetry = null;
@@ -43,7 +43,7 @@ import {
43
43
  import { regenerateIfMissing } from "./workflow-projections.js";
44
44
  import { syncStateToProjectRoot } from "./auto-worktree.js";
45
45
  import { normalizeWorktreePathForCompare } from "./worktree-root.js";
46
- import { isDbAvailable, getTask, getSlice, getMilestone, updateTaskStatus, _getAdapter } from "./gsd-db.js";
46
+ import { isDbAvailable, getTask, getSlice, getMilestone, updateTaskStatus, _getAdapter, getVerificationEvidence } from "./gsd-db.js";
47
47
  import { renderPlanCheckboxes } from "./markdown-renderer.js";
48
48
  import { consumeSignal } from "./session-status-io.js";
49
49
  import {
@@ -852,22 +852,22 @@ export async function postUnitPreVerification(pctx: PostUnitContext, opts?: PreV
852
852
  }
853
853
 
854
854
  // Evidence cross-reference (execute-task only)
855
- // Verification evidence is passed via the complete-task tool call and
856
- // stored in the SUMMARY.md on disk not available as structured data
857
- // in the DB. The evidence collector tracks actual bash tool calls, so
858
- // we can still detect units that claimed success but ran no commands.
855
+ // Only compare against concrete command evidence persisted by the task
856
+ // completion tool. A prose Verify field can be satisfied later by the
857
+ // host verification gate, so it is not enough to accuse the unit.
859
858
  if (safetyConfig.evidence_cross_reference && s.currentUnit.type === "execute-task") {
860
859
  try {
861
860
  const actual = getEvidence();
862
861
  const bashCalls = actual.filter(e => e.kind === "bash");
863
- // If the task is marked complete but zero bash commands were run,
864
- // it's suspicious — the LLM may have fabricated results.
865
862
  if (sMid && sSid && sTid && isDbAvailable()) {
866
863
  const taskRow = getTask(sMid, sSid, sTid);
867
- if (taskRow?.status === "complete" && taskRow.verify && bashCalls.length === 0) {
868
- logWarning("safety", "task marked complete with verification commands but no bash calls were executed");
864
+ const claimedCommands = getVerificationEvidence(sMid, sSid, sTid)
865
+ .map((row) => row.command)
866
+ .filter((command): command is string => typeof command === "string" && command.trim().length > 0);
867
+ if (taskRow?.status === "complete" && claimedCommands.length > 0 && bashCalls.length === 0) {
868
+ logWarning("safety", "task claimed verification command evidence but no execution tool calls were recorded");
869
869
  ctx.ui.notify(
870
- `Safety: task ${sTid} has verification commands but no bash calls were recorded`,
870
+ `Safety: task ${sTid} claimed command evidence but no execution tool calls were recorded`,
871
871
  "warning",
872
872
  );
873
873
  }
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { loadFile, parseContinue, parseSummary, loadActiveOverrides, formatOverridesSection, parseTaskPlanFile } from "./files.js";
10
10
  import type { Override, UatType } from "./files.js";
11
- import { hasVerdict, getUatType } from "./verdict-parser.js";
11
+ import { hasVerdict, getUatType, extractVerdict } from "./verdict-parser.js";
12
12
  import { loadPrompt, inlineTemplate } from "./prompt-loader.js";
13
13
  import {
14
14
  resolveMilestoneFile, resolveSliceFile, resolveSlicePath,
@@ -39,6 +39,7 @@ import { logWarning } from "./workflow-logger.js";
39
39
  import { inlineGraphSubgraph } from "./graph-context.js";
40
40
  import { buildExtractionStepsBlock } from "./commands-extract-learnings.js";
41
41
  import { resolveSkillManifest, warnIfManifestHasMissingSkills } from "./skill-manifest.js";
42
+ import { classifyProject, type ProjectClassification } from "./detection.js";
42
43
 
43
44
  // ─── Preamble Cap ─────────────────────────────────────────────────────────────
44
45
 
@@ -80,6 +81,108 @@ function resolveSummaryBudgetChars(): number {
80
81
  return resolvePromptBudgets().summaryBudgetChars;
81
82
  }
82
83
 
84
+ function formatProjectClassificationForPlanning(classification: ProjectClassification): string {
85
+ const sampleFiles = classification.contentFiles.slice(0, 8);
86
+ const sample = sampleFiles.length > 0 ? sampleFiles.map((file) => `\`${file}\``).join(", ") : "(none)";
87
+ const lines = [
88
+ "### Project Classification",
89
+ "",
90
+ `- **Kind:** ${classification.kind}`,
91
+ `- **Content files:** ${classification.contentFiles.length}`,
92
+ `- **Sample files:** ${sample}`,
93
+ `- **Reason:** ${classification.reason}`,
94
+ "",
95
+ ];
96
+
97
+ if (classification.kind === "untyped-existing") {
98
+ if (classification.contentFiles.length <= 2) {
99
+ lines.push(
100
+ "**Workflow sizing:** This is a tiny existing untyped project. Prefer exactly one slice unless the milestone request clearly spans multiple independent user-visible capabilities.",
101
+ );
102
+ } else if (classification.contentFiles.length <= 5) {
103
+ lines.push(
104
+ "**Workflow sizing:** This is a small existing untyped project. Prefer 1-2 slices unless the milestone request clearly spans multiple independent user-visible capabilities.",
105
+ );
106
+ } else {
107
+ lines.push(
108
+ "**Workflow sizing:** Existing untyped project. Use generic file-level workflow guidance and size slices by real capability boundaries, not by missing tooling markers.",
109
+ );
110
+ }
111
+ } else if (classification.kind === "greenfield") {
112
+ lines.push("**Workflow sizing:** No project content exists yet. Use normal greenfield sizing for the requested scope.");
113
+ } else if (classification.kind === "typed-existing") {
114
+ lines.push("**Workflow sizing:** Known project markers exist. Use normal ecosystem-aware planning guidance.");
115
+ } else {
116
+ lines.push("**Workflow sizing:** Invalid repository state. Planning should surface this as a blocker rather than inventing project structure.");
117
+ }
118
+
119
+ return lines.join("\n");
120
+ }
121
+
122
+ function normalizeArtifactRef(value: string): string {
123
+ return value.trim().replace(/^[-\s]+/, "").replace(/^["'`]+|["'`]+$/g, "").replaceAll("\\", "/").replace(/^\.\//, "");
124
+ }
125
+
126
+ function parseCoveredArtifacts(validationContent: string): Set<string> {
127
+ const covered = new Set<string>();
128
+ const lines = validationContent.split(/\r?\n/);
129
+ let inCoveredArtifacts = false;
130
+ for (const line of lines) {
131
+ if (/^\s*covered[-_]?artifacts\s*:/i.test(line)) {
132
+ inCoveredArtifacts = true;
133
+ const inline = line.split(/covered[-_]?artifacts\s*:/i)[1]?.trim();
134
+ if (inline && inline !== "[]") {
135
+ inline.replace(/^\[|\]$/g, "").split(",").map(normalizeArtifactRef).filter(Boolean).forEach((item) => covered.add(item));
136
+ }
137
+ continue;
138
+ }
139
+ if (!inCoveredArtifacts) continue;
140
+ if (/^\S/.test(line) && !/^\s*-/.test(line)) break;
141
+ const item = line.match(/^\s*-\s*(.+)$/)?.[1];
142
+ if (item) covered.add(normalizeArtifactRef(item));
143
+ }
144
+ return covered;
145
+ }
146
+
147
+ function isValidationFreshOrApplicable(validationContent: string | null, currentArtifacts: string[]): boolean {
148
+ if (!validationContent) return false;
149
+ if (!/validation_metadata:/i.test(validationContent)) return false;
150
+ const coveredArtifacts = parseCoveredArtifacts(validationContent);
151
+ if (coveredArtifacts.size === 0) return false;
152
+ return currentArtifacts
153
+ .map(normalizeArtifactRef)
154
+ .filter(Boolean)
155
+ .every((artifact) => coveredArtifacts.has(artifact));
156
+ }
157
+
158
+ function formatCloseoutReviewInstructions(validationContent: string | null, validationRel: string, currentArtifacts: string[]): string {
159
+ const verdict = validationContent ? extractVerdict(validationContent) : null;
160
+ const validationFresh = isValidationFreshOrApplicable(validationContent, currentArtifacts);
161
+ if (verdict === "pass" && validationFresh) {
162
+ return [
163
+ "### Passing Validation Artifact",
164
+ "",
165
+ `A passing validation artifact is present at \`${validationRel}\`. Treat it as authoritative for success criteria, requirement coverage, verification classes, and cross-slice integration.`,
166
+ "",
167
+ "Do not delegate fresh reviewer/security/tester audits and do not redo the validation evidence review unless the artifact is internally inconsistent with the inlined summaries. Focus this unit on final milestone narrative, learnings, PROJECT/requirements updates, and `gsd_complete_milestone`.",
168
+ ].join("\n");
169
+ }
170
+
171
+ if (verdict) {
172
+ return [
173
+ "### Validation Requires Attention",
174
+ "",
175
+ `A validation artifact is present at \`${validationRel}\` with verdict \`${verdict}\`, but it is missing freshness metadata or does not cover current milestone artifacts. Do not treat the milestone as complete unless the issues are resolved and evidence supports completion.`,
176
+ ].join("\n");
177
+ }
178
+
179
+ return [
180
+ "### No Passing Validation Artifact",
181
+ "",
182
+ `No passing validation artifact was found at \`${validationRel}\`. Use the full closeout review path before completion.`,
183
+ ].join("\n");
184
+ }
185
+
83
186
  function capPreamble(preamble: string): string {
84
187
  // Cap inlined context at min(historical 30K ceiling, scaled inline budget).
85
188
  // The ceiling preserves pre-fix behavior for large-window users; the scaled
@@ -1658,6 +1761,8 @@ export async function buildPlanMilestonePrompt(mid: string, midTitle: string, ba
1658
1761
  const researchAnchor = readPhaseAnchor(base, mid, "research-milestone");
1659
1762
  if (researchAnchor) inlined.push(formatAnchorForPrompt(researchAnchor));
1660
1763
 
1764
+ inlined.push(formatProjectClassificationForPlanning(classifyProject(base)));
1765
+
1661
1766
  inlined.push(await inlineFile(contextPath, contextRel, "Milestone Context"));
1662
1767
  const researchInline = await inlineFileOptional(researchPath, researchRel, "Milestone Research");
1663
1768
  if (researchInline) inlined.push(researchInline);
@@ -2348,6 +2453,9 @@ export async function buildCompleteMilestonePrompt(
2348
2453
  const inlineLevel = level ?? resolveInlineLevel();
2349
2454
  const roadmapPath = resolveMilestoneFile(base, mid, "ROADMAP");
2350
2455
  const roadmapRel = relMilestoneFile(base, mid, "ROADMAP");
2456
+ const validationPath = resolveMilestoneFile(base, mid, "VALIDATION");
2457
+ const validationRel = relMilestoneFile(base, mid, "VALIDATION");
2458
+ const validationContent = validationPath ? await loadFile(validationPath) : null;
2351
2459
 
2352
2460
  const inlined: string[] = [];
2353
2461
  inlined.push(await inlineFile(roadmapPath, roadmapRel, "Milestone Roadmap"));
@@ -2389,6 +2497,13 @@ export async function buildCompleteMilestonePrompt(
2389
2497
  `### On-demand Slice Summaries\n\nExcerpted above. Read the full file for any slice when the excerpt's section heads don't carry enough narrative for the milestone summary you're drafting:\n\n${pathList}`,
2390
2498
  );
2391
2499
  }
2500
+ const validationContext = [
2501
+ formatCloseoutReviewInstructions(validationContent, validationRel, [validationRel, roadmapRel, ...summaryRelPaths]),
2502
+ ];
2503
+ if (validationContent) {
2504
+ validationContext.push(`### Milestone Validation\nSource: \`${validationRel}\`\n\n${validationContent.trim()}`);
2505
+ }
2506
+ inlined.unshift(...validationContext);
2392
2507
 
2393
2508
  // Inline root GSD files (skip for minimal — completion can read these if needed)
2394
2509
  if (inlineLevel !== "minimal") {
@@ -420,6 +420,17 @@ export function _synthesizePausedSessionRecoveryForTest(
420
420
  return synthesizePausedSessionRecovery(basePath, unitType, unitId, sessionFile);
421
421
  }
422
422
 
423
+ const DETACHED_AUTO_KEEPALIVE_INTERVAL_MS = 30_000;
424
+
425
+ function withDetachedAutoKeepalive<T>(run: Promise<T>): Promise<T> {
426
+ const keepAlive = setInterval(() => {}, DETACHED_AUTO_KEEPALIVE_INTERVAL_MS);
427
+ return run.finally(() => {
428
+ clearInterval(keepAlive);
429
+ });
430
+ }
431
+
432
+ export const _withDetachedAutoKeepaliveForTest = withDetachedAutoKeepalive;
433
+
423
434
  export function startAutoDetached(
424
435
  ctx: ExtensionCommandContext,
425
436
  pi: ExtensionAPI,
@@ -431,7 +442,7 @@ export function startAutoDetached(
431
442
  milestoneLock?: string | null;
432
443
  },
433
444
  ): void {
434
- void startAuto(ctx, pi, base, verboseMode, options).catch((err) => {
445
+ void withDetachedAutoKeepalive(startAuto(ctx, pi, base, verboseMode, options)).catch((err) => {
435
446
  const message = getErrorMessage(err);
436
447
  ctx.ui.notify(`Auto-start failed: ${message}`, "error");
437
448
  logWarning("engine", `auto start error: ${message}`, { file: "auto.ts" });
@@ -21,10 +21,34 @@ import { nativeHasChanges } from "./native-git-bridge.js";
21
21
  export interface PreflightResult {
22
22
  /** true when a stash was pushed and postflightPopStash should be called */
23
23
  stashPushed: boolean;
24
+ /** Unique marker embedded in the stash message for targeted restoration */
25
+ stashMarker?: string;
24
26
  /** human-readable summary of what happened (empty string for clean trees) */
25
27
  summary: string;
26
28
  }
27
29
 
30
+ function findPreflightStashRef(basePath: string, milestoneId: string, stashMarker?: string): string | null {
31
+ const markerPrefix = `gsd-preflight-stash:${milestoneId}:`;
32
+ let fallbackRef: string | null = null;
33
+ try {
34
+ const list = execFileSync("git", ["stash", "list", "--format=%gd%x00%s"], {
35
+ cwd: basePath,
36
+ stdio: ["ignore", "pipe", "pipe"],
37
+ encoding: "utf-8",
38
+ env: GIT_NO_PROMPT_ENV,
39
+ });
40
+ for (const line of list.split("\n")) {
41
+ const [ref, subject] = line.split("\x00");
42
+ if (!ref || !subject) continue;
43
+ if (stashMarker && subject.includes(stashMarker)) return ref;
44
+ if (!fallbackRef && subject.includes(markerPrefix)) fallbackRef = ref;
45
+ }
46
+ } catch (err) {
47
+ logWarning("preflight", `stash list failed before restore: ${err instanceof Error ? err.message : String(err)}`);
48
+ }
49
+ return fallbackRef;
50
+ }
51
+
28
52
  /**
29
53
  * Check the working tree for dirty files before a milestone merge.
30
54
  *
@@ -62,7 +86,8 @@ export function preflightCleanRoot(
62
86
 
63
87
  // Push the stash
64
88
  try {
65
- execFileSync("git", ["stash", "push", "--include-untracked", "-m", "gsd-preflight-stash"], {
89
+ const stashMarker = `gsd-preflight-stash:${milestoneId}:${process.pid}:${Date.now()}:${process.hrtime.bigint().toString(36)}`;
90
+ execFileSync("git", ["stash", "push", "--include-untracked", "-m", `gsd-preflight-stash [${stashMarker}]`], {
66
91
  cwd: basePath,
67
92
  stdio: ["ignore", "pipe", "pipe"],
68
93
  encoding: "utf-8",
@@ -70,6 +95,7 @@ export function preflightCleanRoot(
70
95
  });
71
96
  return {
72
97
  stashPushed: true,
98
+ stashMarker,
73
99
  summary: `Stashed uncommitted changes before merge (milestone ${milestoneId}).`,
74
100
  };
75
101
  } catch (err) {
@@ -91,10 +117,19 @@ export function preflightCleanRoot(
91
117
  export function postflightPopStash(
92
118
  basePath: string,
93
119
  milestoneId: string,
120
+ stashMarker: string | undefined,
94
121
  notify: (message: string, level: "info" | "warning" | "error") => void,
95
122
  ): void {
123
+ let stashRef: string | null = null;
96
124
  try {
97
- execFileSync("git", ["stash", "pop"], {
125
+ stashRef = findPreflightStashRef(basePath, milestoneId, stashMarker);
126
+ if (!stashRef) {
127
+ const msg = `No matching GSD preflight stash found for milestone ${milestoneId}; leaving stash list untouched.`;
128
+ logWarning("preflight", msg);
129
+ notify(msg, "warning");
130
+ return;
131
+ }
132
+ execFileSync("git", ["stash", "pop", stashRef], {
98
133
  cwd: basePath,
99
134
  stdio: ["ignore", "pipe", "pipe"],
100
135
  encoding: "utf-8",
@@ -104,7 +139,10 @@ export function postflightPopStash(
104
139
  } catch (err) {
105
140
  // Pop conflicts mean the merged code collides with the stashed changes.
106
141
  // Log a warning — the user needs to resolve manually, but the merge succeeded.
107
- const msg = `git stash pop failed after merge of milestone ${milestoneId}: ${err instanceof Error ? err.message : String(err)}. Run "git stash pop" manually to restore your changes.`;
142
+ const restoreHint = stashRef
143
+ ? `Run "git stash pop ${stashRef}" or "git stash apply ${stashRef}" manually to restore the correct stash.`
144
+ : `Run "git stash list" to find the matching GSD preflight stash before restoring manually.`;
145
+ const msg = `git stash pop ${stashRef ?? ""}`.trim() + ` failed after merge of milestone ${milestoneId}: ${err instanceof Error ? err.message : String(err)}. ${restoreHint}`;
108
146
  logWarning("preflight", msg);
109
147
  notify(msg, "warning");
110
148
  }
@@ -6,6 +6,7 @@
6
6
  * flow to show when entering a project directory.
7
7
  */
8
8
 
9
+ import { execFileSync } from "node:child_process";
9
10
  import { existsSync, openSync, readSync, closeSync, readdirSync, readFileSync, statSync } from "node:fs";
10
11
  import { dirname, join, parse as parsePath } from "node:path";
11
12
  import { homedir } from "node:os";
@@ -72,6 +73,22 @@ export interface ProjectSignals {
72
73
  verificationCommands: string[];
73
74
  }
74
75
 
76
+ export type ProjectClassificationKind =
77
+ | "invalid-repo"
78
+ | "greenfield"
79
+ | "untyped-existing"
80
+ | "typed-existing";
81
+
82
+ export interface ProjectClassification {
83
+ kind: ProjectClassificationKind;
84
+ signals: ProjectSignals;
85
+ trackedFiles: string[];
86
+ untrackedFiles: string[];
87
+ contentFiles: string[];
88
+ markers: string[];
89
+ reason: string;
90
+ }
91
+
75
92
  // ─── Project File Markers ───────────────────────────────────────────────────────
76
93
 
77
94
  export const PROJECT_FILES = [
@@ -243,6 +260,7 @@ const TEST_MARKERS = [
243
260
  const RECURSIVE_SCAN_IGNORED_DIRS = new Set([
244
261
  ".git",
245
262
  ".gsd",
263
+ ".bg-shell",
246
264
  ".planning",
247
265
  ".plans",
248
266
  ".claude",
@@ -267,6 +285,8 @@ const RECURSIVE_SCAN_IGNORED_DIRS = new Set([
267
285
  "out",
268
286
  ]) as ReadonlySet<string>;
269
287
 
288
+ const PROJECT_CONTENT_EXCLUDE_DIRS = RECURSIVE_SCAN_IGNORED_DIRS;
289
+
270
290
  /** Project file markers safe to detect recursively via suffix matching. */
271
291
  const ROOT_ONLY_PROJECT_FILES = new Set<string>([
272
292
  ".github/workflows",
@@ -536,6 +556,114 @@ export function detectProjectSignals(basePath: string): ProjectSignals {
536
556
  };
537
557
  }
538
558
 
559
+ function normalizeGitPath(file: string): string {
560
+ return file.replaceAll("\\", "/").replace(/^\.\//, "");
561
+ }
562
+
563
+ function isProjectContentFile(file: string): boolean {
564
+ const normalized = normalizeGitPath(file);
565
+ if (!normalized || normalized.endsWith("/")) return false;
566
+ if (normalized === ".gitignore" || normalized === ".gitattributes") return false;
567
+ const parts = normalized.split("/");
568
+ if (parts.some((part) => PROJECT_CONTENT_EXCLUDE_DIRS.has(part))) return false;
569
+ if (normalized.endsWith(".DS_Store")) return false;
570
+ return true;
571
+ }
572
+
573
+ function runGitLines(basePath: string, args: string[]): string[] {
574
+ try {
575
+ const output = execFileSync("git", args, {
576
+ cwd: basePath,
577
+ stdio: ["ignore", "pipe", "ignore"],
578
+ encoding: "utf-8",
579
+ }).trim();
580
+ return output ? output.split("\n").map((line) => line.trim()).filter(Boolean) : [];
581
+ } catch {
582
+ return [];
583
+ }
584
+ }
585
+
586
+ function listTrackedProjectFiles(basePath: string): string[] {
587
+ return runGitLines(basePath, ["ls-files"])
588
+ .map(normalizeGitPath)
589
+ .filter(isProjectContentFile);
590
+ }
591
+
592
+ function listUntrackedProjectFiles(basePath: string): string[] {
593
+ return runGitLines(basePath, ["ls-files", "--others", "--exclude-standard"])
594
+ .map(normalizeGitPath)
595
+ .filter(isProjectContentFile);
596
+ }
597
+
598
+ function hasKnownProjectMarkers(basePath: string, signals: ProjectSignals): boolean {
599
+ if (signals.detectedFiles.length > 0) return true;
600
+ if (signals.xcodePlatforms.length > 0) return true;
601
+ return false;
602
+ }
603
+
604
+ /**
605
+ * Classify repo presence separately from ecosystem/tooling markers.
606
+ *
607
+ * Known project files identify tooling. Git-tracked/non-ignored content
608
+ * identifies whether this is an existing project at all. This keeps small
609
+ * static or documentation repos from being mislabeled as greenfield.
610
+ */
611
+ export function classifyProject(basePath: string): ProjectClassification {
612
+ const signals = detectProjectSignals(basePath);
613
+ const markers = [...signals.detectedFiles];
614
+
615
+ if (!signals.isGitRepo) {
616
+ return {
617
+ kind: "invalid-repo",
618
+ signals,
619
+ trackedFiles: [],
620
+ untrackedFiles: [],
621
+ contentFiles: [],
622
+ markers,
623
+ reason: "missing .git",
624
+ };
625
+ }
626
+
627
+ const trackedFiles = listTrackedProjectFiles(basePath);
628
+ const untrackedFiles = listUntrackedProjectFiles(basePath);
629
+ const contentFiles = [...new Set([...trackedFiles, ...untrackedFiles])];
630
+ const hasMarkers = hasKnownProjectMarkers(basePath, signals);
631
+
632
+ if (hasMarkers) {
633
+ return {
634
+ kind: "typed-existing",
635
+ signals,
636
+ trackedFiles,
637
+ untrackedFiles,
638
+ contentFiles,
639
+ markers,
640
+ reason: markers.length > 0 ? `detected markers: ${markers.join(", ")}` : "detected project structure",
641
+ };
642
+ }
643
+
644
+ if (contentFiles.length > 0) {
645
+ return {
646
+ kind: "untyped-existing",
647
+ signals,
648
+ trackedFiles,
649
+ untrackedFiles,
650
+ contentFiles,
651
+ markers,
652
+ reason: "project content exists but no recognized tooling markers were found",
653
+ };
654
+ }
655
+
656
+ return {
657
+ kind: "greenfield",
658
+ signals,
659
+ trackedFiles,
660
+ untrackedFiles,
661
+ contentFiles,
662
+ markers,
663
+ reason: "no tracked or non-ignored project content",
664
+ };
665
+ }
666
+
539
667
  // ─── Xcode Platform Detection ───────────────────────────────────────────────────
540
668
 
541
669
  /** Known SDKROOT values → canonical platform names. */