gsd-pi 2.28.0-dev.b23c118 → 2.28.0-dev.b28e67a

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 (30) hide show
  1. package/dist/cli.js +15 -9
  2. package/dist/resource-loader.js +26 -2
  3. package/dist/resources/extensions/gsd/auto-recovery.ts +17 -1
  4. package/dist/resources/extensions/gsd/auto-start.ts +1 -1
  5. package/dist/resources/extensions/gsd/auto-verification.ts +41 -7
  6. package/dist/resources/extensions/gsd/auto-worktree-sync.ts +14 -0
  7. package/dist/resources/extensions/gsd/auto.ts +22 -5
  8. package/dist/resources/extensions/gsd/tests/validate-milestone.test.ts +55 -0
  9. package/dist/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
  10. package/dist/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
  11. package/dist/resources/extensions/gsd/types.ts +1 -0
  12. package/dist/resources/extensions/gsd/verification-evidence.ts +2 -0
  13. package/dist/resources/extensions/gsd/verification-gate.ts +13 -2
  14. package/package.json +1 -1
  15. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  16. package/packages/pi-coding-agent/dist/core/system-prompt.js +10 -0
  17. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  18. package/packages/pi-coding-agent/scripts/copy-assets.cjs +39 -8
  19. package/packages/pi-coding-agent/src/core/system-prompt.ts +11 -0
  20. package/src/resources/extensions/gsd/auto-recovery.ts +17 -1
  21. package/src/resources/extensions/gsd/auto-start.ts +1 -1
  22. package/src/resources/extensions/gsd/auto-verification.ts +41 -7
  23. package/src/resources/extensions/gsd/auto-worktree-sync.ts +14 -0
  24. package/src/resources/extensions/gsd/auto.ts +22 -5
  25. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +55 -0
  26. package/src/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
  27. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
  28. package/src/resources/extensions/gsd/types.ts +1 -0
  29. package/src/resources/extensions/gsd/verification-evidence.ts +2 -0
  30. package/src/resources/extensions/gsd/verification-gate.ts +13 -2
@@ -581,7 +581,7 @@ test("formatFailureContext: formats a single failure with command, exit code, st
581
581
  const result: import("../types.ts").VerificationResult = {
582
582
  passed: false,
583
583
  checks: [
584
- { command: "npm run lint", exitCode: 1, stdout: "", stderr: "error: unused var", durationMs: 500 },
584
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "error: unused var", durationMs: 500, blocking: true },
585
585
  ],
586
586
  discoverySource: "preference",
587
587
  timestamp: Date.now(),
@@ -598,9 +598,9 @@ test("formatFailureContext: formats multiple failures", () => {
598
598
  const result: import("../types.ts").VerificationResult = {
599
599
  passed: false,
600
600
  checks: [
601
- { command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint error", durationMs: 100 },
602
- { command: "npm run test", exitCode: 2, stdout: "", stderr: "test failure", durationMs: 200 },
603
- { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 50 },
601
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint error", durationMs: 100, blocking: true },
602
+ { command: "npm run test", exitCode: 2, stdout: "", stderr: "test failure", durationMs: 200, blocking: true },
603
+ { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 50, blocking: true },
604
604
  ],
605
605
  discoverySource: "preference",
606
606
  timestamp: Date.now(),
@@ -619,7 +619,7 @@ test("formatFailureContext: truncates stderr longer than 2000 chars", () => {
619
619
  const result: import("../types.ts").VerificationResult = {
620
620
  passed: false,
621
621
  checks: [
622
- { command: "big-err", exitCode: 1, stdout: "", stderr: longStderr, durationMs: 100 },
622
+ { command: "big-err", exitCode: 1, stdout: "", stderr: longStderr, durationMs: 100, blocking: true },
623
623
  ],
624
624
  discoverySource: "preference",
625
625
  timestamp: Date.now(),
@@ -634,8 +634,8 @@ test("formatFailureContext: returns empty string when all checks pass", () => {
634
634
  const result: import("../types.ts").VerificationResult = {
635
635
  passed: true,
636
636
  checks: [
637
- { command: "npm run lint", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
638
- { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 200 },
637
+ { command: "npm run lint", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
638
+ { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 200, blocking: true },
639
639
  ],
640
640
  discoverySource: "preference",
641
641
  timestamp: Date.now(),
@@ -663,6 +663,7 @@ test("formatFailureContext: caps total output at 10,000 chars", () => {
663
663
  stdout: "",
664
664
  stderr: "e".repeat(1000), // 1000 chars each, 20 * ~1050 (with formatting) > 10,000
665
665
  durationMs: 100,
666
+ blocking: true,
666
667
  });
667
668
  }
668
669
  const result: import("../types.ts").VerificationResult = {
@@ -1077,3 +1078,131 @@ test("dependency-audit: subdirectory package.json does not trigger audit", () =>
1077
1078
  assert.equal(npmAuditCalled, false, "subdirectory dependency files should not trigger audit");
1078
1079
  assert.deepStrictEqual(result, []);
1079
1080
  });
1081
+
1082
+ // ─── Non-Blocking Discovery Tests ────────────────────────────────────────────
1083
+
1084
+ test("non-blocking: package-json discovered commands failing → result.passed is still true", () => {
1085
+ const tmp = makeTempDir("vg-nb-pkg-fail");
1086
+ try {
1087
+ writeFileSync(
1088
+ join(tmp, "package.json"),
1089
+ JSON.stringify({ scripts: { lint: "eslint .", test: "vitest" } }),
1090
+ );
1091
+ // These commands will fail because eslint/vitest don't exist in the temp dir
1092
+ const result = runVerificationGate({
1093
+ basePath: tmp,
1094
+ unitId: "T01",
1095
+ cwd: tmp,
1096
+ // No preference commands — discovery falls through to package.json
1097
+ });
1098
+ assert.equal(result.discoverySource, "package-json");
1099
+ assert.ok(result.checks.length > 0, "should have discovered package.json checks");
1100
+ assert.equal(result.passed, true, "package-json failures should not block the gate");
1101
+ for (const check of result.checks) {
1102
+ assert.equal(check.blocking, false, "package-json checks should be non-blocking");
1103
+ }
1104
+ } finally {
1105
+ rmSync(tmp, { recursive: true, force: true });
1106
+ }
1107
+ });
1108
+
1109
+ test("non-blocking: preference commands failing → result.passed is false", () => {
1110
+ const tmp = makeTempDir("vg-nb-pref-fail");
1111
+ try {
1112
+ const result = runVerificationGate({
1113
+ basePath: tmp,
1114
+ unitId: "T01",
1115
+ cwd: tmp,
1116
+ preferenceCommands: ["sh -c 'exit 1'"],
1117
+ });
1118
+ assert.equal(result.discoverySource, "preference");
1119
+ assert.equal(result.passed, false, "preference failures should block the gate");
1120
+ assert.equal(result.checks[0].blocking, true, "preference checks should be blocking");
1121
+ } finally {
1122
+ rmSync(tmp, { recursive: true, force: true });
1123
+ }
1124
+ });
1125
+
1126
+ test("non-blocking: task-plan commands failing → result.passed is false", () => {
1127
+ const tmp = makeTempDir("vg-nb-tp-fail");
1128
+ try {
1129
+ const result = runVerificationGate({
1130
+ basePath: tmp,
1131
+ unitId: "T01",
1132
+ cwd: tmp,
1133
+ taskPlanVerify: "sh -c 'exit 1'",
1134
+ });
1135
+ assert.equal(result.discoverySource, "task-plan");
1136
+ assert.equal(result.passed, false, "task-plan failures should block the gate");
1137
+ assert.equal(result.checks[0].blocking, true, "task-plan checks should be blocking");
1138
+ } finally {
1139
+ rmSync(tmp, { recursive: true, force: true });
1140
+ }
1141
+ });
1142
+
1143
+ test("non-blocking: blocking field is set correctly based on discovery source", () => {
1144
+ const tmp = makeTempDir("vg-nb-field");
1145
+ try {
1146
+ // preference → blocking
1147
+ const prefResult = runVerificationGate({
1148
+ basePath: tmp,
1149
+ unitId: "T01",
1150
+ cwd: tmp,
1151
+ preferenceCommands: ["echo ok"],
1152
+ });
1153
+ assert.equal(prefResult.checks[0].blocking, true);
1154
+
1155
+ // task-plan → blocking
1156
+ const tpResult = runVerificationGate({
1157
+ basePath: tmp,
1158
+ unitId: "T01",
1159
+ cwd: tmp,
1160
+ taskPlanVerify: "echo ok",
1161
+ });
1162
+ assert.equal(tpResult.checks[0].blocking, true);
1163
+
1164
+ // package-json → non-blocking
1165
+ writeFileSync(
1166
+ join(tmp, "package.json"),
1167
+ JSON.stringify({ scripts: { test: "echo ok" } }),
1168
+ );
1169
+ const pkgResult = runVerificationGate({
1170
+ basePath: tmp,
1171
+ unitId: "T01",
1172
+ cwd: tmp,
1173
+ });
1174
+ assert.equal(pkgResult.checks[0].blocking, false);
1175
+ } finally {
1176
+ rmSync(tmp, { recursive: true, force: true });
1177
+ }
1178
+ });
1179
+
1180
+ test("non-blocking: formatFailureContext only includes blocking failures", () => {
1181
+ const result: import("../types.ts").VerificationResult = {
1182
+ passed: true,
1183
+ checks: [
1184
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint warning", durationMs: 100, blocking: false },
1185
+ { command: "npm run test", exitCode: 1, stdout: "", stderr: "test error", durationMs: 200, blocking: true },
1186
+ { command: "npm run typecheck", exitCode: 1, stdout: "", stderr: "type error", durationMs: 50, blocking: false },
1187
+ ],
1188
+ discoverySource: "preference",
1189
+ timestamp: Date.now(),
1190
+ };
1191
+ const output = formatFailureContext(result);
1192
+ assert.ok(output.includes("`npm run test`"), "should include blocking failure");
1193
+ assert.ok(!output.includes("npm run lint"), "should not include non-blocking failure");
1194
+ assert.ok(!output.includes("npm run typecheck"), "should not include non-blocking failure");
1195
+ });
1196
+
1197
+ test("non-blocking: formatFailureContext returns empty when only non-blocking failures exist", () => {
1198
+ const result: import("../types.ts").VerificationResult = {
1199
+ passed: true,
1200
+ checks: [
1201
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint warning", durationMs: 100, blocking: false },
1202
+ { command: "npm run test", exitCode: 1, stdout: "", stderr: "test warning", durationMs: 200, blocking: false },
1203
+ ],
1204
+ discoverySource: "package-json",
1205
+ timestamp: Date.now(),
1206
+ };
1207
+ assert.equal(formatFailureContext(result), "", "should return empty when only non-blocking failures");
1208
+ });
@@ -55,6 +55,7 @@ export interface VerificationCheck {
55
55
  stdout: string;
56
56
  stderr: string;
57
57
  durationMs: number;
58
+ blocking: boolean; // true for preference/task-plan sources, false for package-json (advisory only)
58
59
  }
59
60
 
60
61
  /** A runtime error captured from bg-shell processes or browser console */
@@ -20,6 +20,7 @@ export interface EvidenceCheckJSON {
20
20
  exitCode: number;
21
21
  durationMs: number;
22
22
  verdict: "pass" | "fail";
23
+ blocking: boolean;
23
24
  }
24
25
 
25
26
  export interface RuntimeErrorJSON {
@@ -80,6 +81,7 @@ export function writeVerificationJSON(
80
81
  exitCode: check.exitCode,
81
82
  durationMs: check.durationMs,
82
83
  verdict: check.exitCode === 0 ? "pass" : "fail",
84
+ blocking: check.blocking,
83
85
  })),
84
86
  ...(retryAttempt !== undefined ? { retryAttempt } : {}),
85
87
  ...(maxRetries !== undefined ? { maxRetries } : {}),
@@ -112,7 +112,9 @@ const MAX_FAILURE_CONTEXT_CHARS = 10_000;
112
112
  * Returns an empty string when all checks pass or the checks array is empty.
113
113
  */
114
114
  export function formatFailureContext(result: VerificationResult): string {
115
- const failures = result.checks.filter((c) => c.exitCode !== 0);
115
+ // Only include blocking failures in retry context non-blocking (advisory) failures
116
+ // should not be injected into retry prompts to avoid noise pollution.
117
+ const failures = result.checks.filter((c) => c.exitCode !== 0 && c.blocking);
116
118
  if (failures.length === 0) return "";
117
119
 
118
120
  const blocks: string[] = [];
@@ -256,6 +258,10 @@ export function runVerificationGate(options: RunVerificationGateOptions): Verifi
256
258
  };
257
259
  }
258
260
 
261
+ // Commands from preference and task-plan sources are blocking;
262
+ // package-json discovered commands are advisory (non-blocking).
263
+ const blocking = source === "preference" || source === "task-plan";
264
+
259
265
  const checks: VerificationCheck[] = [];
260
266
 
261
267
  for (const command of commands) {
@@ -291,11 +297,16 @@ export function runVerificationGate(options: RunVerificationGateOptions): Verifi
291
297
  stdout: truncate(result.stdout, MAX_OUTPUT_BYTES),
292
298
  stderr,
293
299
  durationMs,
300
+ blocking,
294
301
  });
295
302
  }
296
303
 
304
+ // Gate passes if all blocking checks pass (non-blocking failures are advisory)
305
+ const blockingChecks = checks.filter(c => c.blocking);
306
+ const passed = blockingChecks.length === 0 || blockingChecks.every(c => c.exitCode === 0);
307
+
297
308
  return {
298
- passed: checks.every(c => c.exitCode === 0),
309
+ passed,
299
310
  checks,
300
311
  discoverySource: source,
301
312
  timestamp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gsd-pi",
3
- "version": "2.28.0-dev.b23c118",
3
+ "version": "2.28.0-dev.b28e67a",
4
4
  "description": "GSD — Get Shit Done coding agent",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAiMhF"}
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CA4MhF"}
@@ -54,6 +54,16 @@ export function buildSystemPrompt(options = {}) {
54
54
  // Add date/time and working directory last
55
55
  prompt += `\nCurrent date and time: ${dateTime}`;
56
56
  prompt += `\nCurrent working directory: ${resolvedCwd}`;
57
+ // Append promptGuidelines from extension-registered tools.
58
+ // Without this, tools registered via pi.registerTool() with promptGuidelines
59
+ // have their definitions reach the API but the model has no guidance on when
60
+ // to use them (#1184).
61
+ if (promptGuidelines && promptGuidelines.length > 0) {
62
+ prompt += "\n\n";
63
+ for (const guideline of promptGuidelines) {
64
+ prompt += guideline + "\n";
65
+ }
66
+ }
57
67
  return prompt;
58
68
  }
59
69
  // Get absolute paths to documentation and examples
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW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1G,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,aAAa,CAAC;IACzB,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,4DAA4D;IAClE,KAAK,EAAE,2BAA2B;IAClC,IAAI,EAAE,yDAAyD;IAC/D,IAAI,EAAE,kDAAkD;I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A+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -1,24 +1,55 @@
1
1
  #!/usr/bin/env node
2
- const { mkdirSync, cpSync } = require('fs');
2
+ const { mkdirSync, cpSync, copyFileSync, readdirSync } = require('fs');
3
+ const { join } = require('path');
4
+
5
+ /**
6
+ * Recursive directory copy using copyFileSync — workaround for cpSync failures
7
+ * on Windows paths containing non-ASCII characters (#1178).
8
+ */
9
+ function safeCpSync(src, dest, options) {
10
+ try {
11
+ cpSync(src, dest, options);
12
+ } catch {
13
+ if (options && options.recursive) {
14
+ copyDirRecursive(src, dest, options && options.filter);
15
+ } else {
16
+ copyFileSync(src, dest);
17
+ }
18
+ }
19
+ }
20
+
21
+ function copyDirRecursive(src, dest, filter) {
22
+ mkdirSync(dest, { recursive: true });
23
+ for (const entry of readdirSync(src, { withFileTypes: true })) {
24
+ const srcPath = join(src, entry.name);
25
+ const destPath = join(dest, entry.name);
26
+ if (filter && !filter(srcPath)) continue;
27
+ if (entry.isDirectory()) {
28
+ copyDirRecursive(srcPath, destPath, filter);
29
+ } else {
30
+ copyFileSync(srcPath, destPath);
31
+ }
32
+ }
33
+ }
3
34
 
4
35
  // Theme assets
5
36
  mkdirSync('dist/modes/interactive/theme', { recursive: true });
6
- cpSync('src/modes/interactive/theme', 'dist/modes/interactive/theme', {
37
+ safeCpSync('src/modes/interactive/theme', 'dist/modes/interactive/theme', {
7
38
  recursive: true,
8
39
  filter: (s) => !s.endsWith('.ts'),
9
40
  });
10
41
 
11
42
  // Export HTML templates and vendor files
12
43
  mkdirSync('dist/core/export-html/vendor', { recursive: true });
13
- cpSync('src/core/export-html/template.html', 'dist/core/export-html/template.html');
14
- cpSync('src/core/export-html/template.css', 'dist/core/export-html/template.css');
15
- cpSync('src/core/export-html/template.js', 'dist/core/export-html/template.js');
16
- cpSync('src/core/export-html/vendor', 'dist/core/export-html/vendor', {
44
+ safeCpSync('src/core/export-html/template.html', 'dist/core/export-html/template.html');
45
+ safeCpSync('src/core/export-html/template.css', 'dist/core/export-html/template.css');
46
+ safeCpSync('src/core/export-html/template.js', 'dist/core/export-html/template.js');
47
+ safeCpSync('src/core/export-html/vendor', 'dist/core/export-html/vendor', {
17
48
  recursive: true,
18
49
  filter: (s) => !s.endsWith('.ts'),
19
50
  });
20
51
 
21
52
  // LSP defaults
22
53
  mkdirSync('dist/core/lsp', { recursive: true });
23
- cpSync('src/core/lsp/defaults.json', 'dist/core/lsp/defaults.json');
24
- cpSync('src/core/lsp/lsp.md', 'dist/core/lsp/lsp.md');
54
+ safeCpSync('src/core/lsp/defaults.json', 'dist/core/lsp/defaults.json');
55
+ safeCpSync('src/core/lsp/lsp.md', 'dist/core/lsp/lsp.md');
@@ -94,6 +94,17 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
94
94
  prompt += `\nCurrent date and time: ${dateTime}`;
95
95
  prompt += `\nCurrent working directory: ${resolvedCwd}`;
96
96
 
97
+ // Append promptGuidelines from extension-registered tools.
98
+ // Without this, tools registered via pi.registerTool() with promptGuidelines
99
+ // have their definitions reach the API but the model has no guidance on when
100
+ // to use them (#1184).
101
+ if (promptGuidelines && promptGuidelines.length > 0) {
102
+ prompt += "\n\n";
103
+ for (const guideline of promptGuidelines) {
104
+ prompt += guideline + "\n";
105
+ }
106
+ }
107
+
97
108
  return prompt;
98
109
  }
99
110
 
@@ -36,6 +36,7 @@ import {
36
36
  clearPathCache,
37
37
  resolveGsdRootFile,
38
38
  } from "./paths.js";
39
+ import { isValidationTerminal } from "./state.js";
39
40
  import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
40
41
  import { atomicWriteSync } from "./atomic-write.js";
41
42
  import { dirname, join } from "node:path";
@@ -137,6 +138,21 @@ export function verifyExpectedArtifact(unitType: string, unitId: string, base: s
137
138
  if (!absPath) return false;
138
139
  if (!existsSync(absPath)) return false;
139
140
 
141
+ // validate-milestone must have a VALIDATION file with a terminal verdict
142
+ // (pass, needs-attention, or needs-remediation). Without this check, a
143
+ // VALIDATION file with missing/malformed frontmatter or an unrecognized
144
+ // verdict is treated as "complete" by the artifact check but deriveState
145
+ // still returns phase:"validating-milestone" (because isValidationTerminal
146
+ // returns false), creating an infinite skip loop that hits the lifetime cap.
147
+ if (unitType === "validate-milestone") {
148
+ try {
149
+ const validationContent = readFileSync(absPath, "utf-8");
150
+ if (!isValidationTerminal(validationContent)) return false;
151
+ } catch {
152
+ return false;
153
+ }
154
+ }
155
+
140
156
  // plan-slice must produce a plan with actual task entries, not just a scaffold.
141
157
  // The plan file may exist from a prior discussion/context step with only headings
142
158
  // but no tasks. Without this check the artifact is considered "complete" and the
@@ -211,7 +227,7 @@ export function verifyExpectedArtifact(unitType: string, unitId: string, base: s
211
227
  try {
212
228
  const roadmapContent = readFileSync(roadmapFile, "utf-8");
213
229
  const roadmap = parseRoadmap(roadmapContent);
214
- const slice = roadmap.slices.find(s => s.id === sid);
230
+ const slice = (roadmap.slices ?? []).find(s => s.id === sid);
215
231
  if (slice && !slice.done) return false;
216
232
  } catch {
217
233
  // Corrupt/unparseable roadmap — fail verification so the unit
@@ -415,7 +415,7 @@ export async function bootstrapAutoSession(
415
415
  ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
416
416
  ctx.ui.setFooter(hideFooter);
417
417
  const modeLabel = s.stepMode ? "Step-mode" : "Auto-mode";
418
- const pendingCount = state.registry.filter(m => m.status !== 'complete' && m.status !== 'parked').length;
418
+ const pendingCount = (state.registry ?? []).filter(m => m.status !== 'complete' && m.status !== 'parked').length;
419
419
  const scopeMsg = pendingCount > 1
420
420
  ? `Will loop through ${pendingCount} milestones.`
421
421
  : "Will loop until milestone complete.";
@@ -105,19 +105,39 @@ export async function runPostUnitVerification(
105
105
  const completionKey = `${s.currentUnit.type}/${s.currentUnit.id}`;
106
106
 
107
107
  if (result.checks.length > 0) {
108
- const passCount = result.checks.filter(c => c.exitCode === 0).length;
109
- const total = result.checks.length;
108
+ const blockingChecks = result.checks.filter(c => c.blocking);
109
+ const advisoryChecks = result.checks.filter(c => !c.blocking);
110
+ const blockingPassCount = blockingChecks.filter(c => c.exitCode === 0).length;
111
+ const advisoryFailCount = advisoryChecks.filter(c => c.exitCode !== 0).length;
112
+
110
113
  if (result.passed) {
111
- ctx.ui.notify(`Verification gate: ${passCount}/${total} checks passed`);
114
+ let msg = blockingChecks.length > 0
115
+ ? `Verification gate: ${blockingPassCount}/${blockingChecks.length} blocking checks passed`
116
+ : `Verification gate: passed (no blocking checks)`;
117
+ if (advisoryFailCount > 0) {
118
+ msg += ` (${advisoryFailCount} advisory warning${advisoryFailCount > 1 ? "s" : ""})`;
119
+ }
120
+ ctx.ui.notify(msg);
121
+ // Log advisory warnings to stderr for visibility
122
+ if (advisoryFailCount > 0) {
123
+ const advisoryFailures = advisoryChecks.filter(c => c.exitCode !== 0);
124
+ process.stderr.write(`verification-gate: ${advisoryFailCount} advisory (non-blocking) failure(s)\n`);
125
+ for (const f of advisoryFailures) {
126
+ process.stderr.write(` [advisory] ${f.command} exited ${f.exitCode}\n`);
127
+ }
128
+ }
112
129
  } else {
113
- const failures = result.checks.filter(c => c.exitCode !== 0);
114
- const failNames = failures.map(f => f.command).join(", ");
130
+ const blockingFailures = blockingChecks.filter(c => c.exitCode !== 0);
131
+ const failNames = blockingFailures.map(f => f.command).join(", ");
115
132
  ctx.ui.notify(`Verification gate: FAILED — ${failNames}`);
116
- process.stderr.write(`verification-gate: ${total - passCount}/${total} checks failed\n`);
117
- for (const f of failures) {
133
+ process.stderr.write(`verification-gate: ${blockingFailures.length}/${blockingChecks.length} blocking checks failed\n`);
134
+ for (const f of blockingFailures) {
118
135
  process.stderr.write(` ${f.command} exited ${f.exitCode}\n`);
119
136
  if (f.stderr) process.stderr.write(` stderr: ${f.stderr.slice(0, 500)}\n`);
120
137
  }
138
+ if (advisoryFailCount > 0) {
139
+ process.stderr.write(`verification-gate: ${advisoryFailCount} additional advisory (non-blocking) failure(s)\n`);
140
+ }
121
141
  }
122
142
  }
123
143
 
@@ -155,6 +175,20 @@ export async function runPostUnitVerification(
155
175
  s.verificationRetryCount.delete(s.currentUnit.id);
156
176
  s.pendingVerificationRetry = null;
157
177
  return "continue";
178
+ } else if (result.discoverySource === "package-json") {
179
+ // Auto-discovered checks from package.json may fail on pre-existing errors
180
+ // that the current task didn't introduce. Don't trigger the retry loop —
181
+ // log a warning and let the task proceed (#1186).
182
+ process.stderr.write(
183
+ `verification-gate: auto-discovered checks failed (source: package-json) — treating as advisory, not blocking\n`,
184
+ );
185
+ ctx.ui.notify(
186
+ `Verification: auto-discovered checks failed (pre-existing errors likely). Continuing without retry.`,
187
+ "warning",
188
+ );
189
+ s.verificationRetryCount.delete(s.currentUnit.id);
190
+ s.pendingVerificationRetry = null;
191
+ return "continue";
158
192
  } else if (autoFixEnabled && attempt + 1 <= maxRetries) {
159
193
  const nextAttempt = attempt + 1;
160
194
  s.verificationRetryCount.set(s.currentUnit.id, nextAttempt);
@@ -36,6 +36,12 @@ export function syncProjectRootToWorktree(projectRoot: string, worktreePath: str
36
36
  // has newer artifacts (e.g. slices that don't exist in the worktree yet)
37
37
  safeCopyRecursive(join(prGsd, "milestones", milestoneId), join(wtGsd, "milestones", milestoneId))
38
38
 
39
+ // Copy living documents from project root to worktree so agents have the
40
+ // latest decisions, requirements, project state, and knowledge.
41
+ for (const doc of ["DECISIONS.md", "REQUIREMENTS.md", "PROJECT.md", "KNOWLEDGE.md"]) {
42
+ safeCopy(join(prGsd, doc), join(wtGsd, doc), { force: true });
43
+ }
44
+
39
45
  // Delete worktree gsd.db so it rebuilds from the freshly synced files.
40
46
  // Stale DB rows are the root cause of the infinite skip loop (#853).
41
47
  try {
@@ -89,6 +95,14 @@ export function syncStateToProjectRoot(worktreePath: string, projectRoot: string
89
95
  // worktree. If the next session resolves basePath before worktree re-entry,
90
96
  // selfHeal can't find or clear the stale record (#769).
91
97
  safeCopyRecursive(join(wtGsd, "runtime", "units"), join(prGsd, "runtime", "units"), { force: true })
98
+
99
+ // 5. Living documents — decisions, requirements, project description, knowledge.
100
+ // Agents update these during slice execution. Without syncing, a new session
101
+ // reads stale copies from the project root, losing architectural decisions,
102
+ // requirement status updates, and accumulated knowledge (#1168).
103
+ for (const doc of ["DECISIONS.md", "REQUIREMENTS.md", "PROJECT.md", "KNOWLEDGE.md"]) {
104
+ safeCopy(join(wtGsd, doc), join(prGsd, doc), { force: true });
105
+ }
92
106
  }
93
107
 
94
108
  // ─── Resource Staleness ───────────────────────────────────────────────────