gsd-pi 2.28.0-dev.853dfc5 → 2.28.0-dev.a8d3050

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 (73) hide show
  1. package/dist/resource-loader.js +80 -8
  2. package/dist/resources/extensions/gsd/auto-verification.ts +41 -7
  3. package/dist/resources/extensions/gsd/auto.ts +2 -2
  4. package/dist/resources/extensions/gsd/commands-handlers.ts +1 -9
  5. package/dist/resources/extensions/gsd/commands-prefs-wizard.ts +14 -22
  6. package/dist/resources/extensions/gsd/commands.ts +1 -7
  7. package/dist/resources/extensions/gsd/index.ts +2 -1
  8. package/dist/resources/extensions/gsd/json-persistence.ts +52 -0
  9. package/dist/resources/extensions/gsd/metrics.ts +17 -31
  10. package/dist/resources/extensions/gsd/paths.ts +0 -8
  11. package/dist/resources/extensions/gsd/routing-history.ts +13 -17
  12. package/dist/resources/extensions/gsd/tests/gsd-inspect.test.ts +1 -1
  13. package/dist/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
  14. package/dist/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
  15. package/dist/resources/extensions/gsd/types.ts +1 -0
  16. package/dist/resources/extensions/gsd/unit-runtime.ts +16 -13
  17. package/dist/resources/extensions/gsd/verification-evidence.ts +2 -0
  18. package/dist/resources/extensions/gsd/verification-gate.ts +13 -2
  19. package/dist/resources/extensions/remote-questions/discord-adapter.ts +2 -2
  20. package/dist/resources/extensions/remote-questions/notify.ts +1 -2
  21. package/dist/resources/extensions/remote-questions/slack-adapter.ts +1 -2
  22. package/dist/resources/extensions/remote-questions/telegram-adapter.ts +1 -2
  23. package/dist/resources/extensions/remote-questions/types.ts +3 -0
  24. package/dist/resources/extensions/shared/mod.ts +3 -0
  25. package/package.json +4 -1
  26. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +3 -0
  27. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  28. package/packages/pi-coding-agent/dist/core/settings-manager.js +8 -0
  29. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  30. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  31. package/packages/pi-coding-agent/dist/core/system-prompt.js +10 -0
  32. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  33. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  34. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -1
  35. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  36. package/packages/pi-coding-agent/scripts/copy-assets.cjs +39 -8
  37. package/packages/pi-coding-agent/src/core/settings-manager.ts +11 -0
  38. package/packages/pi-coding-agent/src/core/system-prompt.ts +11 -0
  39. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +4 -1
  40. package/packages/pi-tui/dist/autocomplete.d.ts +3 -0
  41. package/packages/pi-tui/dist/autocomplete.d.ts.map +1 -1
  42. package/packages/pi-tui/dist/autocomplete.js +14 -0
  43. package/packages/pi-tui/dist/autocomplete.js.map +1 -1
  44. package/packages/pi-tui/src/autocomplete.ts +19 -1
  45. package/src/resources/extensions/gsd/auto-verification.ts +41 -7
  46. package/src/resources/extensions/gsd/auto.ts +2 -2
  47. package/src/resources/extensions/gsd/commands-handlers.ts +1 -9
  48. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +14 -22
  49. package/src/resources/extensions/gsd/commands.ts +1 -7
  50. package/src/resources/extensions/gsd/index.ts +2 -1
  51. package/src/resources/extensions/gsd/json-persistence.ts +52 -0
  52. package/src/resources/extensions/gsd/metrics.ts +17 -31
  53. package/src/resources/extensions/gsd/paths.ts +0 -8
  54. package/src/resources/extensions/gsd/routing-history.ts +13 -17
  55. package/src/resources/extensions/gsd/tests/gsd-inspect.test.ts +1 -1
  56. package/src/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
  57. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
  58. package/src/resources/extensions/gsd/types.ts +1 -0
  59. package/src/resources/extensions/gsd/unit-runtime.ts +16 -13
  60. package/src/resources/extensions/gsd/verification-evidence.ts +2 -0
  61. package/src/resources/extensions/gsd/verification-gate.ts +13 -2
  62. package/src/resources/extensions/remote-questions/discord-adapter.ts +2 -2
  63. package/src/resources/extensions/remote-questions/notify.ts +1 -2
  64. package/src/resources/extensions/remote-questions/slack-adapter.ts +1 -2
  65. package/src/resources/extensions/remote-questions/telegram-adapter.ts +1 -2
  66. package/src/resources/extensions/remote-questions/types.ts +3 -0
  67. package/src/resources/extensions/shared/mod.ts +3 -0
  68. package/dist/resources/extensions/gsd/preferences-hooks.ts +0 -10
  69. package/dist/resources/extensions/shared/progress-widget.ts +0 -282
  70. package/dist/resources/extensions/shared/thinking-widget.ts +0 -107
  71. package/src/resources/extensions/gsd/preferences-hooks.ts +0 -10
  72. package/src/resources/extensions/shared/progress-widget.ts +0 -282
  73. package/src/resources/extensions/shared/thinking-widget.ts +0 -107
@@ -45,12 +45,6 @@ import { handleCleanupBranches, handleCleanupSnapshots, handleSkip, handleDryRun
45
45
  import { handleDoctor, handleSteer, handleCapture, handleTriage, handleKnowledge, handleRunHook, handleUpdate, handleSkillHealth } from "./commands-handlers.js";
46
46
  import { handleLogs } from "./commands-logs.js";
47
47
 
48
- // ─── Re-exports (preserve public API surface) ───────────────────────────────
49
- export { handlePrefs, handlePrefsMode, handlePrefsWizard, ensurePreferencesFile, handleImportClaude, buildCategorySummaries, serializePreferencesToFrontmatter, yamlSafeString, configureMode } from "./commands-prefs-wizard.js";
50
- export { TOOL_KEYS, loadToolApiKeys, getConfigAuthStorage, handleConfig } from "./commands-config.js";
51
- export { type InspectData, formatInspectOutput, handleInspect } from "./commands-inspect.js";
52
- export { handleCleanupBranches, handleCleanupSnapshots, handleSkip, handleDryRun } from "./commands-maintenance.js";
53
- export { handleDoctor, handleSteer, handleCapture, handleTriage, handleKnowledge, handleRunHook, handleUpdate, handleSkillHealth } from "./commands-handlers.js";
54
48
 
55
49
  export function dispatchDoctorHeal(pi: ExtensionAPI, scope: string | undefined, reportText: string, structuredIssues: string): void {
56
50
  const workflowPath = process.env.GSD_WORKFLOW_PATH ?? join(process.env.HOME ?? "~", ".pi", "GSD-WORKFLOW.md");
@@ -846,7 +840,7 @@ function showHelp(ctx: ExtensionCommandContext): void {
846
840
  " /gsd init Project init wizard — detect, configure, bootstrap .gsd/",
847
841
  " /gsd setup Global setup status [llm|search|remote|keys|prefs]",
848
842
  " /gsd mode Set workflow mode (solo/team) [global|project]",
849
- " /gsd prefs Manage preferences [global|project|status|wizard|setup]",
843
+ " /gsd prefs Manage preferences [global|project|status|wizard|setup|import-claude]",
850
844
  " /gsd config Set API keys for external tools",
851
845
  " /gsd keys API key manager [list|add|remove|test|rotate|doctor]",
852
846
  " /gsd hooks Show post-unit hook configuration",
@@ -27,7 +27,8 @@ import { createBashTool, createWriteTool, createReadTool, createEditTool, isTool
27
27
  import { Type } from "@sinclair/typebox";
28
28
 
29
29
  import { debugLog, debugTime } from "./debug-logger.js";
30
- import { registerGSDCommand, loadToolApiKeys } from "./commands.js";
30
+ import { registerGSDCommand } from "./commands.js";
31
+ import { loadToolApiKeys } from "./commands-config.js";
31
32
  import { registerExitCommand } from "./exit-command.js";
32
33
  import { registerWorktreeCommand, getWorktreeOriginalCwd, getActiveWorktreeName } from "./worktree-command.js";
33
34
  import { getActiveAutoWorktreeContext } from "./auto-worktree.js";
@@ -0,0 +1,52 @@
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+
4
+ /**
5
+ * Load a JSON file with validation, returning a default on failure.
6
+ * Handles missing files, corrupt JSON, and schema mismatches uniformly.
7
+ */
8
+ export function loadJsonFile<T>(
9
+ filePath: string,
10
+ validate: (data: unknown) => data is T,
11
+ defaultFactory: () => T,
12
+ ): T {
13
+ try {
14
+ if (!existsSync(filePath)) return defaultFactory();
15
+ const raw = readFileSync(filePath, "utf-8");
16
+ const parsed = JSON.parse(raw);
17
+ return validate(parsed) ? parsed : defaultFactory();
18
+ } catch {
19
+ return defaultFactory();
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Load a JSON file with validation, returning null on failure.
25
+ * For callers that distinguish "no data" from "default data".
26
+ */
27
+ export function loadJsonFileOrNull<T>(
28
+ filePath: string,
29
+ validate: (data: unknown) => data is T,
30
+ ): T | null {
31
+ try {
32
+ if (!existsSync(filePath)) return null;
33
+ const raw = readFileSync(filePath, "utf-8");
34
+ const parsed = JSON.parse(raw);
35
+ return validate(parsed) ? parsed : null;
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Save a JSON file, creating parent directories as needed.
43
+ * Non-fatal — swallows errors to prevent persistence from breaking operations.
44
+ */
45
+ export function saveJsonFile<T>(filePath: string, data: T): void {
46
+ try {
47
+ mkdirSync(dirname(filePath), { recursive: true });
48
+ writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n", "utf-8");
49
+ } catch {
50
+ // Non-fatal — don't let persistence failures break operation
51
+ }
52
+ }
@@ -13,11 +13,11 @@
13
13
  * 4. On crash recovery or fresh start, the ledger is loaded from disk
14
14
  */
15
15
 
16
- import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
17
16
  import { join } from "node:path";
18
17
  import type { ExtensionContext } from "@gsd/pi-coding-agent";
19
18
  import { gsdRoot } from "./paths.js";
20
19
  import { getAndClearSkills } from "./skill-telemetry.js";
20
+ import { loadJsonFile, loadJsonFileOrNull, saveJsonFile } from "./json-persistence.js";
21
21
 
22
22
  // Re-export from shared — canonical implementation lives in format-utils.
23
23
  export { formatTokenCount } from "../shared/mod.js";
@@ -502,45 +502,31 @@ function metricsPath(base: string): string {
502
502
  return join(gsdRoot(base), "metrics.json");
503
503
  }
504
504
 
505
+ function isMetricsLedger(data: unknown): data is MetricsLedger {
506
+ return (
507
+ typeof data === "object" &&
508
+ data !== null &&
509
+ (data as MetricsLedger).version === 1 &&
510
+ Array.isArray((data as MetricsLedger).units)
511
+ );
512
+ }
513
+
514
+ function defaultLedger(): MetricsLedger {
515
+ return { version: 1, projectStartedAt: Date.now(), units: [] };
516
+ }
517
+
505
518
  /**
506
519
  * Load ledger from disk without initializing in-memory state.
507
520
  * Used by history/export commands outside of auto-mode.
508
521
  */
509
522
  export function loadLedgerFromDisk(base: string): MetricsLedger | null {
510
- try {
511
- const raw = readFileSync(metricsPath(base), "utf-8");
512
- const parsed = JSON.parse(raw);
513
- if (parsed.version === 1 && Array.isArray(parsed.units)) {
514
- return parsed as MetricsLedger;
515
- }
516
- } catch {
517
- // File doesn't exist or is corrupt
518
- }
519
- return null;
523
+ return loadJsonFileOrNull(metricsPath(base), isMetricsLedger);
520
524
  }
521
525
 
522
526
  function loadLedger(base: string): MetricsLedger {
523
- try {
524
- const raw = readFileSync(metricsPath(base), "utf-8");
525
- const parsed = JSON.parse(raw);
526
- if (parsed.version === 1 && Array.isArray(parsed.units)) {
527
- return parsed as MetricsLedger;
528
- }
529
- } catch {
530
- // File doesn't exist or is corrupt — start fresh
531
- }
532
- return {
533
- version: 1,
534
- projectStartedAt: Date.now(),
535
- units: [],
536
- };
527
+ return loadJsonFile(metricsPath(base), isMetricsLedger, defaultLedger);
537
528
  }
538
529
 
539
530
  function saveLedger(base: string, data: MetricsLedger): void {
540
- try {
541
- mkdirSync(gsdRoot(base), { recursive: true });
542
- writeFileSync(metricsPath(base), JSON.stringify(data, null, 2) + "\n", "utf-8");
543
- } catch {
544
- // Don't let metrics failures break auto-mode
545
- }
531
+ saveJsonFile(metricsPath(base), data);
546
532
  }
@@ -137,14 +137,6 @@ export function clearPathCache(): void {
137
137
 
138
138
  // ─── Name Builders ─────────────────────────────────────────────────────────
139
139
 
140
- /**
141
- * Build a directory name from an ID.
142
- * ("M001") → "M001"
143
- */
144
- export function buildDirName(id: string): string {
145
- return id;
146
- }
147
-
148
140
  /**
149
141
  * Build a milestone-level file name.
150
142
  * ("M001", "CONTEXT") → "M001-CONTEXT.md"
@@ -2,10 +2,10 @@
2
2
  // Tracks success/failure per tier per unit-type pattern to improve
3
3
  // classification accuracy over time.
4
4
 
5
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
6
5
  import { join } from "node:path";
7
6
  import { gsdRoot } from "./paths.js";
8
7
  import type { ComplexityTier } from "./types.js";
8
+ import { loadJsonFile, saveJsonFile } from "./json-persistence.js";
9
9
 
10
10
  // ─── Types ───────────────────────────────────────────────────────────────────
11
11
 
@@ -267,24 +267,20 @@ function historyPath(base: string): string {
267
267
  return join(gsdRoot(base), HISTORY_FILE);
268
268
  }
269
269
 
270
+ function isRoutingHistoryData(data: unknown): data is RoutingHistoryData {
271
+ return (
272
+ typeof data === "object" &&
273
+ data !== null &&
274
+ (data as RoutingHistoryData).version === 1 &&
275
+ typeof (data as RoutingHistoryData).patterns === "object" &&
276
+ (data as RoutingHistoryData).patterns !== null
277
+ );
278
+ }
279
+
270
280
  function loadHistory(base: string): RoutingHistoryData {
271
- try {
272
- const raw = readFileSync(historyPath(base), "utf-8");
273
- const parsed = JSON.parse(raw);
274
- if (parsed.version === 1 && parsed.patterns) {
275
- return parsed as RoutingHistoryData;
276
- }
277
- } catch {
278
- // File doesn't exist or is corrupt — start fresh
279
- }
280
- return createEmptyHistory();
281
+ return loadJsonFile(historyPath(base), isRoutingHistoryData, createEmptyHistory);
281
282
  }
282
283
 
283
284
  function saveHistory(base: string, data: RoutingHistoryData): void {
284
- try {
285
- mkdirSync(gsdRoot(base), { recursive: true });
286
- writeFileSync(historyPath(base), JSON.stringify(data, null, 2) + "\n", "utf-8");
287
- } catch {
288
- // Non-fatal — don't let history failures break auto-mode
289
- }
285
+ saveJsonFile(historyPath(base), data);
290
286
  }
@@ -3,7 +3,7 @@
3
3
  // Tests the pure formatInspectOutput function with known data.
4
4
 
5
5
  import { createTestContext } from './test-helpers.ts';
6
- import { formatInspectOutput, type InspectData } from '../commands.ts';
6
+ import { formatInspectOutput, type InspectData } from '../commands-inspect.ts';
7
7
 
8
8
  const { assertEq, assertTrue, assertMatch, report } = createTestContext();
9
9
 
@@ -58,6 +58,7 @@ test("verification-evidence: writeVerificationJSON writes correct JSON shape", (
58
58
  stdout: "all good",
59
59
  stderr: "",
60
60
  durationMs: 2340,
61
+ blocking: true,
61
62
  },
62
63
  ],
63
64
  });
@@ -105,9 +106,9 @@ test("verification-evidence: writeVerificationJSON maps exitCode to verdict corr
105
106
  const result = makeResult({
106
107
  passed: false,
107
108
  checks: [
108
- { command: "lint", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
109
- { command: "test", exitCode: 1, stdout: "", stderr: "fail", durationMs: 200 },
110
- { command: "audit", exitCode: 2, stdout: "", stderr: "err", durationMs: 300 },
109
+ { command: "lint", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
110
+ { command: "test", exitCode: 1, stdout: "", stderr: "fail", durationMs: 200, blocking: true },
111
+ { command: "audit", exitCode: 2, stdout: "", stderr: "err", durationMs: 300, blocking: true },
111
112
  ],
112
113
  });
113
114
 
@@ -133,6 +134,7 @@ test("verification-evidence: writeVerificationJSON excludes stdout/stderr from o
133
134
  stdout: "hello\n",
134
135
  stderr: "some warning",
135
136
  durationMs: 50,
137
+ blocking: true,
136
138
  },
137
139
  ],
138
140
  });
@@ -181,8 +183,8 @@ test("verification-evidence: writeVerificationJSON uses optional unitId when pro
181
183
  test("verification-evidence: formatEvidenceTable returns markdown table with correct columns", () => {
182
184
  const result = makeResult({
183
185
  checks: [
184
- { command: "npm run typecheck", exitCode: 0, stdout: "", stderr: "", durationMs: 2340 },
185
- { command: "npm run lint", exitCode: 1, stdout: "", stderr: "err", durationMs: 1100 },
186
+ { command: "npm run typecheck", exitCode: 0, stdout: "", stderr: "", durationMs: 2340, blocking: true },
187
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "err", durationMs: 1100, blocking: true },
186
188
  ],
187
189
  });
188
190
 
@@ -214,9 +216,9 @@ test("verification-evidence: formatEvidenceTable returns no-checks message for e
214
216
  test("verification-evidence: formatEvidenceTable formats duration as seconds with 1 decimal", () => {
215
217
  const result = makeResult({
216
218
  checks: [
217
- { command: "fast", exitCode: 0, stdout: "", stderr: "", durationMs: 150 },
218
- { command: "slow", exitCode: 0, stdout: "", stderr: "", durationMs: 2340 },
219
- { command: "zero", exitCode: 0, stdout: "", stderr: "", durationMs: 0 },
219
+ { command: "fast", exitCode: 0, stdout: "", stderr: "", durationMs: 150, blocking: true },
220
+ { command: "slow", exitCode: 0, stdout: "", stderr: "", durationMs: 2340, blocking: true },
221
+ { command: "zero", exitCode: 0, stdout: "", stderr: "", durationMs: 0, blocking: true },
220
222
  ],
221
223
  });
222
224
 
@@ -230,8 +232,8 @@ test("verification-evidence: formatEvidenceTable uses ✅/❌ emoji for pass/fai
230
232
  const result = makeResult({
231
233
  passed: false,
232
234
  checks: [
233
- { command: "pass-cmd", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
234
- { command: "fail-cmd", exitCode: 1, stdout: "", stderr: "", durationMs: 200 },
235
+ { command: "pass-cmd", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
236
+ { command: "fail-cmd", exitCode: 1, stdout: "", stderr: "", durationMs: 200, blocking: true },
235
237
  ],
236
238
  });
237
239
 
@@ -335,8 +337,8 @@ test("verification-evidence: integration — VerificationResult → JSON → tab
335
337
  const result = makeResult({
336
338
  passed: false,
337
339
  checks: [
338
- { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500 },
339
- { command: "npm run test:unit", exitCode: 1, stdout: "", stderr: "1 failed", durationMs: 3200 },
340
+ { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500, blocking: true },
341
+ { command: "npm run test:unit", exitCode: 1, stdout: "", stderr: "1 failed", durationMs: 3200, blocking: true },
340
342
  ],
341
343
  discoverySource: "package-json",
342
344
  });
@@ -390,7 +392,7 @@ test("verification-evidence: writeVerificationJSON with retryAttempt and maxRetr
390
392
  const result = makeResult({
391
393
  passed: false,
392
394
  checks: [
393
- { command: "npm run lint", exitCode: 1, stdout: "", stderr: "error", durationMs: 300 },
395
+ { command: "npm run lint", exitCode: 1, stdout: "", stderr: "error", durationMs: 300, blocking: true },
394
396
  ],
395
397
  });
396
398
 
@@ -415,7 +417,7 @@ test("verification-evidence: writeVerificationJSON without retry params omits re
415
417
  const result = makeResult({
416
418
  passed: true,
417
419
  checks: [
418
- { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
420
+ { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
419
421
  ],
420
422
  });
421
423
 
@@ -441,7 +443,7 @@ test("verification-evidence: writeVerificationJSON includes runtimeErrors when p
441
443
  const result = makeResult({
442
444
  passed: false,
443
445
  checks: [
444
- { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
446
+ { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
445
447
  ],
446
448
  runtimeErrors: [
447
449
  { source: "bg-shell", severity: "crash", message: "Server crashed", blocking: true },
@@ -473,7 +475,7 @@ test("verification-evidence: writeVerificationJSON omits runtimeErrors when abse
473
475
  const result = makeResult({
474
476
  passed: true,
475
477
  checks: [
476
- { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50 },
478
+ { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50, blocking: true },
477
479
  ],
478
480
  });
479
481
 
@@ -512,7 +514,7 @@ test("verification-evidence: formatEvidenceTable appends runtime errors section"
512
514
  const result = makeResult({
513
515
  passed: false,
514
516
  checks: [
515
- { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
517
+ { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
516
518
  ],
517
519
  runtimeErrors: [
518
520
  { source: "bg-shell", severity: "crash", message: "Server crashed with SIGKILL", blocking: true },
@@ -537,7 +539,7 @@ test("verification-evidence: formatEvidenceTable omits runtime errors section wh
537
539
  const result = makeResult({
538
540
  passed: true,
539
541
  checks: [
540
- { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200 },
542
+ { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200, blocking: true },
541
543
  ],
542
544
  });
543
545
 
@@ -552,7 +554,7 @@ test("verification-evidence: formatEvidenceTable truncates runtime error message
552
554
  const result = makeResult({
553
555
  passed: false,
554
556
  checks: [
555
- { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
557
+ { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
556
558
  ],
557
559
  runtimeErrors: [
558
560
  { source: "bg-shell", severity: "error", message: longMessage, blocking: false },
@@ -598,7 +600,7 @@ test("verification-evidence: writeVerificationJSON includes auditWarnings when p
598
600
  const result = makeResult({
599
601
  passed: true,
600
602
  checks: [
601
- { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
603
+ { command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
602
604
  ],
603
605
  auditWarnings: SAMPLE_AUDIT_WARNINGS,
604
606
  });
@@ -627,7 +629,7 @@ test("verification-evidence: writeVerificationJSON omits auditWarnings when abse
627
629
  const result = makeResult({
628
630
  passed: true,
629
631
  checks: [
630
- { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50 },
632
+ { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50, blocking: true },
631
633
  ],
632
634
  });
633
635
 
@@ -666,7 +668,7 @@ test("verification-evidence: formatEvidenceTable appends audit warnings section"
666
668
  const result = makeResult({
667
669
  passed: true,
668
670
  checks: [
669
- { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
671
+ { command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
670
672
  ],
671
673
  auditWarnings: SAMPLE_AUDIT_WARNINGS,
672
674
  });
@@ -689,7 +691,7 @@ test("verification-evidence: formatEvidenceTable omits audit warnings section wh
689
691
  const result = makeResult({
690
692
  passed: true,
691
693
  checks: [
692
- { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200 },
694
+ { command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200, blocking: true },
693
695
  ],
694
696
  });
695
697
 
@@ -705,7 +707,7 @@ test("verification-evidence: integration — VerificationResult with auditWarnin
705
707
  const result = makeResult({
706
708
  passed: true,
707
709
  checks: [
708
- { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500 },
710
+ { command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500, blocking: true },
709
711
  ],
710
712
  auditWarnings: [
711
713
  {
@@ -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 */