gsd-pi 2.38.0-dev.add4f78 → 2.38.0-dev.d533afb

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 (117) hide show
  1. package/dist/resource-loader.js +34 -1
  2. package/dist/resources/extensions/github-sync/cli.js +284 -0
  3. package/dist/resources/extensions/github-sync/index.js +73 -0
  4. package/dist/resources/extensions/github-sync/mapping.js +67 -0
  5. package/dist/resources/extensions/github-sync/sync.js +424 -0
  6. package/dist/resources/extensions/github-sync/templates.js +118 -0
  7. package/dist/resources/extensions/github-sync/types.js +7 -0
  8. package/dist/resources/extensions/gsd/auto/session.js +3 -23
  9. package/dist/resources/extensions/gsd/auto-dispatch.js +1 -1
  10. package/dist/resources/extensions/gsd/auto-loop.js +292 -263
  11. package/dist/resources/extensions/gsd/auto-post-unit.js +28 -3
  12. package/dist/resources/extensions/gsd/auto-prompts.js +23 -43
  13. package/dist/resources/extensions/gsd/auto-start.js +7 -1
  14. package/dist/resources/extensions/gsd/auto-worktree.js +3 -3
  15. package/dist/resources/extensions/gsd/auto.js +143 -80
  16. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
  17. package/dist/resources/extensions/gsd/commands.js +2 -1
  18. package/dist/resources/extensions/gsd/context-budget.js +2 -10
  19. package/dist/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  20. package/dist/resources/extensions/gsd/doctor-providers.js +27 -11
  21. package/dist/resources/extensions/gsd/doctor.js +20 -1
  22. package/dist/resources/extensions/gsd/exit-command.js +2 -1
  23. package/dist/resources/extensions/gsd/files.js +4 -0
  24. package/dist/resources/extensions/gsd/git-service.js +15 -12
  25. package/dist/resources/extensions/gsd/guided-flow.js +82 -32
  26. package/dist/resources/extensions/gsd/index.js +22 -19
  27. package/dist/resources/extensions/gsd/native-git-bridge.js +37 -0
  28. package/dist/resources/extensions/gsd/preferences-models.js +0 -12
  29. package/dist/resources/extensions/gsd/preferences-types.js +1 -1
  30. package/dist/resources/extensions/gsd/preferences-validation.js +58 -10
  31. package/dist/resources/extensions/gsd/preferences.js +4 -2
  32. package/dist/resources/extensions/gsd/prompts/discuss.md +11 -14
  33. package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -2
  34. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
  35. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
  36. package/dist/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
  37. package/dist/resources/extensions/gsd/prompts/queue.md +4 -8
  38. package/dist/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
  39. package/dist/resources/extensions/gsd/prompts/run-uat.md +27 -10
  40. package/dist/resources/extensions/gsd/prompts/workflow-start.md +2 -2
  41. package/dist/resources/extensions/gsd/repo-identity.js +19 -3
  42. package/dist/resources/extensions/gsd/roadmap-mutations.js +24 -0
  43. package/dist/resources/extensions/mcp-client/index.js +14 -1
  44. package/package.json +1 -1
  45. package/packages/pi-ai/dist/utils/oauth/anthropic.js +2 -2
  46. package/packages/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
  47. package/packages/pi-ai/src/utils/oauth/anthropic.ts +2 -2
  48. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  49. package/packages/pi-coding-agent/dist/core/extensions/loader.js +205 -7
  50. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  51. package/packages/pi-coding-agent/src/core/extensions/loader.ts +223 -7
  52. package/src/resources/extensions/github-sync/cli.ts +364 -0
  53. package/src/resources/extensions/github-sync/index.ts +93 -0
  54. package/src/resources/extensions/github-sync/mapping.ts +81 -0
  55. package/src/resources/extensions/github-sync/sync.ts +556 -0
  56. package/src/resources/extensions/github-sync/templates.ts +183 -0
  57. package/src/resources/extensions/github-sync/tests/cli.test.ts +20 -0
  58. package/src/resources/extensions/github-sync/tests/commit-linking.test.ts +39 -0
  59. package/src/resources/extensions/github-sync/tests/mapping.test.ts +104 -0
  60. package/src/resources/extensions/github-sync/tests/templates.test.ts +110 -0
  61. package/src/resources/extensions/github-sync/types.ts +47 -0
  62. package/src/resources/extensions/gsd/auto/session.ts +3 -25
  63. package/src/resources/extensions/gsd/auto-dispatch.ts +1 -1
  64. package/src/resources/extensions/gsd/auto-loop.ts +382 -360
  65. package/src/resources/extensions/gsd/auto-post-unit.ts +29 -3
  66. package/src/resources/extensions/gsd/auto-prompts.ts +25 -45
  67. package/src/resources/extensions/gsd/auto-start.ts +11 -1
  68. package/src/resources/extensions/gsd/auto-worktree.ts +3 -3
  69. package/src/resources/extensions/gsd/auto.ts +139 -86
  70. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
  71. package/src/resources/extensions/gsd/commands.ts +2 -2
  72. package/src/resources/extensions/gsd/context-budget.ts +2 -12
  73. package/src/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  74. package/src/resources/extensions/gsd/doctor-providers.ts +26 -9
  75. package/src/resources/extensions/gsd/doctor.ts +22 -1
  76. package/src/resources/extensions/gsd/exit-command.ts +2 -2
  77. package/src/resources/extensions/gsd/files.ts +3 -1
  78. package/src/resources/extensions/gsd/git-service.ts +20 -10
  79. package/src/resources/extensions/gsd/guided-flow.ts +110 -38
  80. package/src/resources/extensions/gsd/index.ts +21 -16
  81. package/src/resources/extensions/gsd/native-git-bridge.ts +37 -0
  82. package/src/resources/extensions/gsd/preferences-models.ts +0 -12
  83. package/src/resources/extensions/gsd/preferences-types.ts +4 -4
  84. package/src/resources/extensions/gsd/preferences-validation.ts +50 -10
  85. package/src/resources/extensions/gsd/preferences.ts +3 -2
  86. package/src/resources/extensions/gsd/prompts/discuss.md +11 -14
  87. package/src/resources/extensions/gsd/prompts/execute-task.md +2 -2
  88. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
  89. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
  90. package/src/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
  91. package/src/resources/extensions/gsd/prompts/queue.md +4 -8
  92. package/src/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
  93. package/src/resources/extensions/gsd/prompts/run-uat.md +27 -10
  94. package/src/resources/extensions/gsd/prompts/workflow-start.md +2 -2
  95. package/src/resources/extensions/gsd/repo-identity.ts +20 -3
  96. package/src/resources/extensions/gsd/roadmap-mutations.ts +29 -0
  97. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +21 -18
  98. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +122 -68
  99. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +86 -3
  100. package/src/resources/extensions/gsd/tests/preferences.test.ts +2 -7
  101. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +59 -0
  102. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +21 -1
  103. package/src/resources/extensions/gsd/tests/run-uat.test.ts +11 -3
  104. package/src/resources/extensions/gsd/types.ts +0 -1
  105. package/src/resources/extensions/mcp-client/index.ts +17 -1
  106. package/dist/resources/extensions/gsd/prompt-compressor.js +0 -393
  107. package/dist/resources/extensions/gsd/semantic-chunker.js +0 -254
  108. package/dist/resources/extensions/gsd/summary-distiller.js +0 -212
  109. package/src/resources/extensions/gsd/prompt-compressor.ts +0 -508
  110. package/src/resources/extensions/gsd/semantic-chunker.ts +0 -336
  111. package/src/resources/extensions/gsd/summary-distiller.ts +0 -258
  112. package/src/resources/extensions/gsd/tests/context-compression.test.ts +0 -193
  113. package/src/resources/extensions/gsd/tests/prompt-compressor.test.ts +0 -529
  114. package/src/resources/extensions/gsd/tests/semantic-chunker.test.ts +0 -426
  115. package/src/resources/extensions/gsd/tests/summary-distiller.test.ts +0 -323
  116. package/src/resources/extensions/gsd/tests/token-optimization-benchmark.test.ts +0 -1272
  117. package/src/resources/extensions/gsd/tests/token-optimization-prefs.test.ts +0 -164
@@ -1,9 +1,9 @@
1
1
  /**
2
- * agent-end-retry.test.ts — Regression checks for the post-#1419 agent_end model.
2
+ * agent-end-retry.test.ts — Regression checks for the agent_end model.
3
3
  *
4
- * The old recursive handleAgentEnd retry path is gone. The loop now keeps
5
- * pendingResolve + pendingAgentEndQueue on AutoSession, and handleAgentEnd is
6
- * only a thin compatibility wrapper around resolveAgentEnd().
4
+ * The per-unit one-shot resolve function lives at module level in auto-loop.ts
5
+ * (_currentResolve). handleAgentEnd is a thin compatibility wrapper around
6
+ * resolveAgentEnd().
7
7
  */
8
8
 
9
9
  import test from "node:test";
@@ -14,40 +14,43 @@ import { fileURLToPath } from "node:url";
14
14
 
15
15
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
16
  const AUTO_TS_PATH = join(__dirname, "..", "auto.ts");
17
+ const AUTO_LOOP_TS_PATH = join(__dirname, "..", "auto-loop.ts");
17
18
  const SESSION_TS_PATH = join(__dirname, "..", "auto", "session.ts");
18
19
 
19
20
  function getAutoTsSource(): string {
20
21
  return readFileSync(AUTO_TS_PATH, "utf-8");
21
22
  }
22
23
 
24
+ function getAutoLoopTsSource(): string {
25
+ return readFileSync(AUTO_LOOP_TS_PATH, "utf-8");
26
+ }
27
+
23
28
  function getSessionTsSource(): string {
24
29
  return readFileSync(SESSION_TS_PATH, "utf-8");
25
30
  }
26
31
 
27
- test("AutoSession declares pending agent_end queue state", () => {
28
- const source = getSessionTsSource();
32
+ test("auto-loop.ts declares _currentResolve for per-unit one-shot promises", () => {
33
+ const source = getAutoLoopTsSource();
29
34
  assert.ok(
30
- source.includes("pendingResolve"),
31
- "AutoSession must declare pendingResolve for the in-flight unit promise",
35
+ source.includes("_currentResolve"),
36
+ "auto-loop.ts must declare _currentResolve for the per-unit resolve function",
32
37
  );
33
38
  assert.ok(
34
- source.includes("pendingAgentEndQueue"),
35
- "AutoSession must declare pendingAgentEndQueue for between-iteration agent_end events",
39
+ source.includes("_sessionSwitchInFlight"),
40
+ "auto-loop.ts must declare _sessionSwitchInFlight guard",
36
41
  );
37
42
  });
38
43
 
39
- test("AutoSession reset clears pending agent_end queue state", () => {
44
+ test("AutoSession no longer holds promise state (moved to auto-loop.ts module scope)", () => {
40
45
  const source = getSessionTsSource();
41
- const resetIdx = source.indexOf("reset(): void");
42
- assert.ok(resetIdx > -1, "AutoSession must have a reset() method");
43
- const resetBlock = source.slice(resetIdx, resetIdx + 4000);
46
+ // Properties should NOT exist as class fields
44
47
  assert.ok(
45
- resetBlock.includes("this.pendingResolve = null"),
46
- "reset() must clear pendingResolve",
48
+ !source.includes("pendingResolve:"),
49
+ "AutoSession must not declare pendingResolve (moved to auto-loop.ts)",
47
50
  );
48
51
  assert.ok(
49
- resetBlock.includes("this.pendingAgentEndQueue = []"),
50
- "reset() must clear pendingAgentEndQueue",
52
+ !source.includes("pendingAgentEndQueue:"),
53
+ "AutoSession must not declare pendingAgentEndQueue (removed — events are dropped)",
51
54
  );
52
55
  });
53
56
 
@@ -7,6 +7,7 @@ import {
7
7
  resolveAgentEnd,
8
8
  runUnit,
9
9
  autoLoop,
10
+ detectStuck,
10
11
  _resetPendingResolve,
11
12
  _setActiveSession,
12
13
  isSessionSwitchInFlight,
@@ -37,9 +38,6 @@ function makeMockSession(opts?: {
37
38
  const session = {
38
39
  active: true,
39
40
  verbose: false,
40
- sessionSwitchInFlight: false,
41
- pendingResolve: null,
42
- pendingAgentEndQueue: [],
43
41
  cmdCtx: {
44
42
  newSession: () => {
45
43
  opts?.onNewSessionStart?.(session);
@@ -96,7 +94,6 @@ test("resolveAgentEnd resolves a pending runUnit promise", async () => {
96
94
  const ctx = makeMockCtx();
97
95
  const pi = makeMockPi();
98
96
  const s = makeMockSession();
99
- _setActiveSession(s);
100
97
  const event = makeEvent();
101
98
 
102
99
  // Start runUnit — it will create the promise and send a message,
@@ -108,7 +105,6 @@ test("resolveAgentEnd resolves a pending runUnit promise", async () => {
108
105
  "task",
109
106
  "T01",
110
107
  "do stuff",
111
- undefined,
112
108
  );
113
109
 
114
110
  // Give the microtask queue a tick so runUnit reaches the await
@@ -122,44 +118,35 @@ test("resolveAgentEnd resolves a pending runUnit promise", async () => {
122
118
  assert.deepEqual(result.event, event);
123
119
  });
124
120
 
125
- test("resolveAgentEnd queues event when no promise is pending", () => {
121
+ test("resolveAgentEnd drops event when no promise is pending", () => {
126
122
  _resetPendingResolve();
127
- const s = makeMockSession();
128
- _setActiveSession(s);
129
123
 
130
- // Should not throw — queues the event for the next runUnit
124
+ // Should not throw — event is dropped (logged as warning)
131
125
  assert.doesNotThrow(() => {
132
126
  resolveAgentEnd(makeEvent());
133
127
  });
134
- assert.equal(s.pendingAgentEndQueue.length, 1, "event should be queued");
135
128
  });
136
129
 
137
- test("double resolveAgentEnd only resolves once (second is queued)", async () => {
130
+ test("double resolveAgentEnd only resolves once (second is dropped)", async () => {
138
131
  _resetPendingResolve();
139
132
 
140
133
  const ctx = makeMockCtx();
141
134
  const pi = makeMockPi();
142
135
  const s = makeMockSession();
143
- _setActiveSession(s);
144
136
  const event1 = makeEvent([{ id: 1 }]);
145
137
  const event2 = makeEvent([{ id: 2 }]);
146
138
 
147
- const resultPromise = runUnit(ctx, pi, s, "task", "T01", "prompt", undefined);
139
+ const resultPromise = runUnit(ctx, pi, s, "task", "T01", "prompt");
148
140
 
149
141
  await new Promise((r) => setTimeout(r, 10));
150
142
 
151
143
  // First resolve — should work
152
144
  resolveAgentEnd(event1);
153
145
 
154
- // Second resolve — should be queued (no pending promise)
146
+ // Second resolve — should be dropped (no pending resolver)
155
147
  assert.doesNotThrow(() => {
156
148
  resolveAgentEnd(event2);
157
149
  });
158
- assert.equal(
159
- s.pendingAgentEndQueue.length,
160
- 1,
161
- "second event should be queued",
162
- );
163
150
 
164
151
  const result = await resultPromise;
165
152
  assert.equal(result.status, "completed");
@@ -174,7 +161,7 @@ test("runUnit returns cancelled when session creation fails", async () => {
174
161
  const pi = makeMockPi();
175
162
  const s = makeMockSession({ newSessionThrows: "connection refused" });
176
163
 
177
- const result = await runUnit(ctx, pi, s, "task", "T01", "prompt", undefined);
164
+ const result = await runUnit(ctx, pi, s, "task", "T01", "prompt");
178
165
 
179
166
  assert.equal(result.status, "cancelled");
180
167
  assert.equal(result.event, undefined);
@@ -190,7 +177,7 @@ test("runUnit returns cancelled when session creation times out", async () => {
190
177
  // Session returns cancelled: true (simulates the timeout race outcome)
191
178
  const s = makeMockSession({ newSessionResult: { cancelled: true } });
192
179
 
193
- const result = await runUnit(ctx, pi, s, "task", "T01", "prompt", undefined);
180
+ const result = await runUnit(ctx, pi, s, "task", "T01", "prompt");
194
181
 
195
182
  assert.equal(result.status, "cancelled");
196
183
  assert.equal(result.event, undefined);
@@ -205,35 +192,31 @@ test("runUnit returns cancelled when s.active is false before sendMessage", asyn
205
192
  const s = makeMockSession();
206
193
  s.active = false;
207
194
 
208
- const result = await runUnit(ctx, pi, s, "task", "T01", "prompt", undefined);
195
+ const result = await runUnit(ctx, pi, s, "task", "T01", "prompt");
209
196
 
210
197
  assert.equal(result.status, "cancelled");
211
198
  assert.equal(pi.calls.length, 0);
212
199
  });
213
200
 
214
- test("runUnit only arms pendingResolve after newSession completes", async () => {
201
+ test("runUnit only arms resolve after newSession completes", async () => {
215
202
  _resetPendingResolve();
216
203
 
217
204
  let sawSwitchFlag = false;
218
- let sawPendingResolve: unknown = "unset";
219
205
 
220
206
  const ctx = makeMockCtx();
221
207
  const pi = makeMockPi();
222
208
  const s = makeMockSession({
223
209
  newSessionDelayMs: 20,
224
- onNewSessionStart: (session) => {
225
- sawSwitchFlag = session.sessionSwitchInFlight;
226
- sawPendingResolve = session.pendingResolve;
210
+ onNewSessionStart: () => {
211
+ sawSwitchFlag = isSessionSwitchInFlight();
227
212
  },
228
213
  });
229
- _setActiveSession(s);
230
214
 
231
- const resultPromise = runUnit(ctx, pi, s, "task", "T01", "prompt", undefined);
215
+ const resultPromise = runUnit(ctx, pi, s, "task", "T01", "prompt");
232
216
 
233
217
  await new Promise((r) => setTimeout(r, 30));
234
218
 
235
219
  assert.equal(sawSwitchFlag, true, "session switch guard should be active during newSession");
236
- assert.equal(sawPendingResolve, null, "pendingResolve should not be armed before newSession completes");
237
220
  assert.equal(isSessionSwitchInFlight(), false, "session switch guard should clear after newSession settles");
238
221
 
239
222
  resolveAgentEnd(makeEvent());
@@ -275,24 +258,23 @@ test("auto-loop.ts contains a while keyword", () => {
275
258
  );
276
259
  });
277
260
 
278
- test("auto-loop.ts one-shot pattern: pendingResolve is nulled before calling resolver", () => {
261
+ test("auto-loop.ts one-shot pattern: _currentResolve is nulled before calling resolver", () => {
279
262
  const src = readFileSync(
280
263
  resolve(import.meta.dirname, "..", "auto-loop.ts"),
281
264
  "utf-8",
282
265
  );
283
266
  // The one-shot pattern requires: save ref, null the variable, then call
284
- // Look for the pattern: s.pendingResolve = null appearing before r(
285
267
  const resolveBlock = src.slice(
286
268
  src.indexOf("export function resolveAgentEnd"),
287
269
  src.indexOf("export function resolveAgentEnd") + 600,
288
270
  );
289
- const nullIdx = resolveBlock.indexOf("pendingResolve = null");
271
+ const nullIdx = resolveBlock.indexOf("_currentResolve = null");
290
272
  const callIdx = resolveBlock.indexOf("r({");
291
- assert.ok(nullIdx > 0, "should null pendingResolve in resolveAgentEnd");
273
+ assert.ok(nullIdx > 0, "should null _currentResolve in resolveAgentEnd");
292
274
  assert.ok(callIdx > 0, "should call resolver in resolveAgentEnd");
293
275
  assert.ok(
294
276
  nullIdx < callIdx,
295
- "pendingResolve should be nulled before calling the resolver (one-shot)",
277
+ "_currentResolve should be nulled before calling the resolver (one-shot)",
296
278
  );
297
279
  });
298
280
 
@@ -462,8 +444,6 @@ function makeLoopSession(overrides?: Partial<Record<string, unknown>>) {
462
444
  pendingQuickTasks: [],
463
445
  sidecarQueue: [],
464
446
  autoModeStartModel: null,
465
- pendingResolve: null,
466
- pendingAgentEndQueue: [],
467
447
  unitDispatchCount: new Map<string, number>(),
468
448
  unitLifetimeDispatches: new Map<string, number>(),
469
449
  unitRecoveryCount: new Map<string, number>(),
@@ -1063,7 +1043,7 @@ test("handleAgentEnd in auto.ts is a thin wrapper calling resolveAgentEnd", () =
1063
1043
 
1064
1044
  // ── Stuck counter tests ──────────────────────────────────────────────────────
1065
1045
 
1066
- test("stuck counter: stops when deriveState returns same unit 5 consecutive times", async () => {
1046
+ test("stuck detection: stops when sliding window detects same unit 3 consecutive times", async () => {
1067
1047
  _resetPendingResolve();
1068
1048
 
1069
1049
  const ctx = makeMockCtx();
@@ -1098,20 +1078,15 @@ test("stuck counter: stops when deriveState returns same unit 5 consecutive time
1098
1078
 
1099
1079
  const loopPromise = autoLoop(ctx, pi, s, deps);
1100
1080
 
1101
- // The loop will dispatch the same unit each iteration. On iteration 1, sameUnitCount
1102
- // starts at 0 and the unit key is set. On iterations 2-5, sameUnitCount increments.
1103
- // At sameUnitCount=5 (iteration 6), stopAuto is called.
1104
- // Each iteration requires resolving an agent_end event.
1105
- // But the stuck counter fires BEFORE runUnit, so we only need to resolve 4 times
1106
- // (iterations 1-4 each run a unit, iteration 5 increments to 5 and stops).
1107
-
1108
- // Actually: iteration 1 sets lastDerivedUnit (sameUnitCount=0).
1109
- // Iteration 2: derivedKey === lastDerivedUnit → sameUnitCount=1.
1110
- // Iteration 3: sameUnitCount=2. Iteration 4: sameUnitCount=3.
1111
- // Iteration 5: sameUnitCount=4. Iteration 6: sameUnitCount=5 → stop.
1112
- // So we need to resolve 5 agent_end events (iterations 1-5 each run a unit).
1081
+ // Sliding window: iteration 1 pushes [A], iteration 2 pushes [A,A],
1082
+ // iteration 3 pushes [A,A,A] Rule 2 fires (3 consecutive) Level 1 recovery.
1083
+ // Level 1 invalidates caches and continues. Iteration 4 pushes [A,A,A,A] →
1084
+ // Rule 2 fires again Level 2 hard stop.
1085
+ // Iterations 1-3 each run a unit (3 resolves needed). Iteration 3 triggers
1086
+ // Level 1 (cache invalidation + continue). Iteration 4 triggers Level 2 (stop
1087
+ // before runUnit), so no 4th resolve needed.
1113
1088
 
1114
- for (let i = 0; i < 5; i++) {
1089
+ for (let i = 0; i < 3; i++) {
1115
1090
  await new Promise((r) => setTimeout(r, 30));
1116
1091
  resolveAgentEnd(makeEvent());
1117
1092
  }
@@ -1126,17 +1101,13 @@ test("stuck counter: stops when deriveState returns same unit 5 consecutive time
1126
1101
  stopReason.includes("Stuck"),
1127
1102
  `stop reason should mention 'Stuck', got: ${stopReason}`,
1128
1103
  );
1129
- assert.ok(
1130
- stopReason.includes("execute-task"),
1131
- "stop reason should include unitType",
1132
- );
1133
1104
  assert.ok(
1134
1105
  stopReason.includes("M001/S01/T01"),
1135
1106
  "stop reason should include unitId",
1136
1107
  );
1137
1108
  });
1138
1109
 
1139
- test("stuck counter: resets when deriveState returns a different unit", async () => {
1110
+ test("stuck detection: window resets recovery when deriveState returns a different unit", async () => {
1140
1111
  _resetPendingResolve();
1141
1112
 
1142
1113
  const ctx = makeMockCtx();
@@ -1197,10 +1168,11 @@ test("stuck counter: resets when deriveState returns a different unit", async ()
1197
1168
 
1198
1169
  await loopPromise;
1199
1170
 
1200
- // The counter should have reset when T02 was derived no stuck stop
1171
+ // Level 1 recovery fires on iteration 3 (cache invalidation + continue),
1172
+ // then iteration 4 derives T02 — no Level 2 hard stop.
1201
1173
  assert.ok(
1202
1174
  !stopCalled,
1203
- "stopAuto should NOT have been called — counter reset on unit change",
1175
+ "stopAuto should NOT have been called — different unit broke stuck pattern",
1204
1176
  );
1205
1177
  assert.ok(
1206
1178
  deriveCallCount >= 4,
@@ -1208,7 +1180,7 @@ test("stuck counter: resets when deriveState returns a different unit", async ()
1208
1180
  );
1209
1181
  });
1210
1182
 
1211
- test("stuck counter: does not increment during verification retry", async () => {
1183
+ test("stuck detection: does not push to window during verification retry", async () => {
1212
1184
  _resetPendingResolve();
1213
1185
 
1214
1186
  const ctx = makeMockCtx();
@@ -1270,10 +1242,10 @@ test("stuck counter: does not increment during verification retry", async () =>
1270
1242
  await loopPromise;
1271
1243
 
1272
1244
  // Even though same unit was derived 4 times, verification retries should
1273
- // not count, so stuck counter should not have fired
1245
+ // not push to the sliding window, so stuck detection should not have fired
1274
1246
  assert.ok(
1275
1247
  !stopReason.includes("Stuck"),
1276
- `stuck counter should not fire during verification retries, got: ${stopReason}`,
1248
+ `stuck detection should not fire during verification retries, got: ${stopReason}`,
1277
1249
  );
1278
1250
  assert.equal(
1279
1251
  verifyCallCount,
@@ -1282,24 +1254,106 @@ test("stuck counter: does not increment during verification retry", async () =>
1282
1254
  );
1283
1255
  });
1284
1256
 
1285
- test("stuck counter: logs debug output with stuck-detected phase", () => {
1286
- // Structural test: verify the auto-loop.ts source contains both
1287
- // stuck-detected and stuck-counter-reset debug log phases
1257
+ // ── detectStuck unit tests ────────────────────────────────────────────────────
1258
+
1259
+ test("detectStuck: returns null for fewer than 2 entries", () => {
1260
+ assert.equal(detectStuck([]), null);
1261
+ assert.equal(detectStuck([{ key: "A" }]), null);
1262
+ });
1263
+
1264
+ test("detectStuck: Rule 1 — same error twice in a row", () => {
1265
+ const result = detectStuck([
1266
+ { key: "A", error: "ENOENT: file not found" },
1267
+ { key: "A", error: "ENOENT: file not found" },
1268
+ ]);
1269
+ assert.ok(result?.stuck, "should detect same error repeated");
1270
+ assert.ok(result?.reason.includes("Same error repeated"));
1271
+ });
1272
+
1273
+ test("detectStuck: Rule 1 — different errors do not trigger", () => {
1274
+ const result = detectStuck([
1275
+ { key: "A", error: "ENOENT: file not found" },
1276
+ { key: "A", error: "EACCES: permission denied" },
1277
+ ]);
1278
+ assert.equal(result, null);
1279
+ });
1280
+
1281
+ test("detectStuck: Rule 2 — same unit 3 consecutive times", () => {
1282
+ const result = detectStuck([
1283
+ { key: "execute-task/M001/S01/T01" },
1284
+ { key: "execute-task/M001/S01/T01" },
1285
+ { key: "execute-task/M001/S01/T01" },
1286
+ ]);
1287
+ assert.ok(result?.stuck);
1288
+ assert.ok(result?.reason.includes("3 consecutive times"));
1289
+ });
1290
+
1291
+ test("detectStuck: Rule 2 — 2 consecutive does not trigger", () => {
1292
+ assert.equal(detectStuck([
1293
+ { key: "A" },
1294
+ { key: "A" },
1295
+ ]), null);
1296
+ });
1297
+
1298
+ test("detectStuck: Rule 3 — oscillation A→B→A→B", () => {
1299
+ const result = detectStuck([
1300
+ { key: "A" },
1301
+ { key: "B" },
1302
+ { key: "A" },
1303
+ { key: "B" },
1304
+ ]);
1305
+ assert.ok(result?.stuck);
1306
+ assert.ok(result?.reason.includes("Oscillation"));
1307
+ });
1308
+
1309
+ test("detectStuck: Rule 3 — non-oscillation pattern A→B→C→B", () => {
1310
+ assert.equal(detectStuck([
1311
+ { key: "A" },
1312
+ { key: "B" },
1313
+ { key: "C" },
1314
+ { key: "B" },
1315
+ ]), null);
1316
+ });
1317
+
1318
+ test("detectStuck: Rule 1 takes priority over Rule 2 when both match", () => {
1319
+ const result = detectStuck([
1320
+ { key: "A", error: "test error" },
1321
+ { key: "A", error: "test error" },
1322
+ { key: "A", error: "test error" },
1323
+ ]);
1324
+ assert.ok(result?.stuck);
1325
+ // Rule 1 fires first
1326
+ assert.ok(result?.reason.includes("Same error repeated"));
1327
+ });
1328
+
1329
+ test("detectStuck: truncates long error strings", () => {
1330
+ const longError = "x".repeat(500);
1331
+ const result = detectStuck([
1332
+ { key: "A", error: longError },
1333
+ { key: "A", error: longError },
1334
+ ]);
1335
+ assert.ok(result?.stuck);
1336
+ assert.ok(result!.reason.length < 300, "reason should be truncated");
1337
+ });
1338
+
1339
+ test("stuck detection: logs debug output with stuck-detected phase", () => {
1340
+ // Structural test: verify the auto-loop.ts source contains
1341
+ // stuck-detected and stuck-counter-reset debug log phases, plus detectStuck
1288
1342
  const src = readFileSync(
1289
1343
  resolve(import.meta.dirname, "..", "auto-loop.ts"),
1290
1344
  "utf-8",
1291
1345
  );
1292
1346
  assert.ok(
1293
1347
  src.includes('"stuck-detected"'),
1294
- "auto-loop.ts must log phase: 'stuck-detected' when stuck counter fires",
1348
+ "auto-loop.ts must log phase: 'stuck-detected' when stuck detection fires",
1295
1349
  );
1296
1350
  assert.ok(
1297
1351
  src.includes('"stuck-counter-reset"'),
1298
- "auto-loop.ts must log phase: 'stuck-counter-reset' when counter resets on new unit",
1352
+ "auto-loop.ts must log phase: 'stuck-counter-reset' when recovery resets on new unit",
1299
1353
  );
1300
1354
  assert.ok(
1301
- src.includes("sameUnitCount"),
1302
- "auto-loop.ts must track sameUnitCount for stuck detection",
1355
+ src.includes("detectStuck"),
1356
+ "auto-loop.ts must use detectStuck for sliding window analysis",
1303
1357
  );
1304
1358
  });
1305
1359
 
@@ -47,6 +47,18 @@ function withEnv(vars: Record<string, string | undefined>, fn: () => void): void
47
47
  }
48
48
  }
49
49
 
50
+ function withCwd(nextCwd: string, fn: () => void): void {
51
+ const saved = process.cwd();
52
+ process.chdir(nextCwd);
53
+ try {
54
+ fn();
55
+ } finally {
56
+ process.chdir(saved);
57
+ }
58
+ }
59
+
60
+ const PRESENT_TEST_VALUE = "configured";
61
+
50
62
  // ─── formatProviderReport ─────────────────────────────────────────────────────
51
63
 
52
64
  test("formatProviderReport returns fallback for empty results", () => {
@@ -312,7 +324,7 @@ test("runProviderChecks reports ok for Anthropic when GitHub Copilot env var is
312
324
  withEnv({
313
325
  ANTHROPIC_API_KEY: undefined,
314
326
  ANTHROPIC_OAUTH_TOKEN: undefined,
315
- COPILOT_GITHUB_TOKEN: "ghu_copilot-token",
327
+ COPILOT_GITHUB_TOKEN: PRESENT_TEST_VALUE,
316
328
  GH_TOKEN: undefined,
317
329
  GITHUB_TOKEN: undefined,
318
330
  HOME: tmpHome,
@@ -336,7 +348,7 @@ test("runProviderChecks reports ok for Anthropic via GITHUB_TOKEN cross-provider
336
348
  ANTHROPIC_OAUTH_TOKEN: undefined,
337
349
  COPILOT_GITHUB_TOKEN: undefined,
338
350
  GH_TOKEN: undefined,
339
- GITHUB_TOKEN: "ghp_github-token",
351
+ GITHUB_TOKEN: PRESENT_TEST_VALUE,
340
352
  HOME: tmpHome,
341
353
  }, () => {
342
354
  try {
@@ -354,7 +366,7 @@ test("runProviderChecks detects ANTHROPIC_OAUTH_TOKEN as valid Anthropic auth",
354
366
  const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-oauth-test-")));
355
367
  withEnv({
356
368
  ANTHROPIC_API_KEY: undefined,
357
- ANTHROPIC_OAUTH_TOKEN: "oauth-token-test",
369
+ ANTHROPIC_OAUTH_TOKEN: PRESENT_TEST_VALUE,
358
370
  COPILOT_GITHUB_TOKEN: undefined,
359
371
  GH_TOKEN: undefined,
360
372
  GITHUB_TOKEN: undefined,
@@ -401,3 +413,74 @@ test("runProviderChecks reports ok via Copilot auth.json for Anthropic", () => {
401
413
  rmSync(tmpHome, { recursive: true, force: true });
402
414
  });
403
415
  });
416
+
417
+ test("runProviderChecks uses provider-qualified anthropic-vertex model IDs", () => {
418
+ const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-vertex-prefix-home-")));
419
+ const repo = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-vertex-prefix-repo-")));
420
+ mkdirSync(join(repo, ".gsd"), { recursive: true });
421
+ writeFileSync(
422
+ join(repo, ".gsd", "preferences.md"),
423
+ [
424
+ "---",
425
+ "models:",
426
+ " execution: anthropic-vertex/claude-sonnet-4-6",
427
+ "---",
428
+ "",
429
+ ].join("\n"),
430
+ );
431
+
432
+ withEnv({
433
+ HOME: tmpHome,
434
+ ANTHROPIC_API_KEY: undefined,
435
+ ANTHROPIC_OAUTH_TOKEN: undefined,
436
+ ANTHROPIC_VERTEX_PROJECT_ID: "vertex-project",
437
+ }, () => {
438
+ withCwd(repo, () => {
439
+ const results = runProviderChecks();
440
+ const vertex = results.find(r => r.name === "anthropic-vertex");
441
+ const anthropic = results.find(r => r.name === "anthropic");
442
+ assert.ok(vertex, "anthropic-vertex result should exist");
443
+ assert.equal(vertex!.status, "ok", "should accept ANTHROPIC_VERTEX_PROJECT_ID as configured");
444
+ assert.ok(!anthropic || !anthropic.required, "plain anthropic should not be required for anthropic-vertex config");
445
+ });
446
+ });
447
+
448
+ rmSync(repo, { recursive: true, force: true });
449
+ rmSync(tmpHome, { recursive: true, force: true });
450
+ });
451
+
452
+ test("runProviderChecks uses object provider field for anthropic-vertex models", () => {
453
+ const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-vertex-provider-home-")));
454
+ const repo = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-vertex-provider-repo-")));
455
+ mkdirSync(join(repo, ".gsd"), { recursive: true });
456
+ writeFileSync(
457
+ join(repo, ".gsd", "preferences.md"),
458
+ [
459
+ "---",
460
+ "models:",
461
+ " execution:",
462
+ " model: claude-sonnet-4-6",
463
+ " provider: anthropic-vertex",
464
+ "---",
465
+ "",
466
+ ].join("\n"),
467
+ );
468
+
469
+ withEnv({
470
+ HOME: tmpHome,
471
+ ANTHROPIC_API_KEY: undefined,
472
+ ANTHROPIC_OAUTH_TOKEN: undefined,
473
+ ANTHROPIC_VERTEX_PROJECT_ID: undefined,
474
+ }, () => {
475
+ withCwd(repo, () => {
476
+ const results = runProviderChecks();
477
+ const vertex = results.find(r => r.name === "anthropic-vertex");
478
+ assert.ok(vertex, "anthropic-vertex result should exist");
479
+ assert.equal(vertex!.status, "error", "missing vertex config should be reported against anthropic-vertex");
480
+ assert.ok(vertex!.detail?.includes("ANTHROPIC_VERTEX_PROJECT_ID"), "should point to vertex setup");
481
+ });
482
+ });
483
+
484
+ rmSync(repo, { recursive: true, force: true });
485
+ rmSync(tmpHome, { recursive: true, force: true });
486
+ });
@@ -208,30 +208,25 @@ test("git fields comprehensive validation", () => {
208
208
  assert.equal(preferences.git?.isolation, "branch");
209
209
  });
210
210
 
211
- test("auto_visualize, auto_report, compression_strategy, context_selection validate correctly", () => {
211
+ test("auto_visualize, auto_report, context_selection validate correctly", () => {
212
212
  const { preferences, errors } = validatePreferences({
213
213
  auto_visualize: true,
214
214
  auto_report: false,
215
- compression_strategy: "compress",
216
215
  context_selection: "smart",
217
216
  });
218
217
  assert.equal(errors.length, 0);
219
218
  assert.equal(preferences.auto_visualize, true);
220
219
  assert.equal(preferences.auto_report, false);
221
- assert.equal(preferences.compression_strategy, "compress");
222
220
  assert.equal(preferences.context_selection, "smart");
223
221
  });
224
222
 
225
- test("auto_visualize, auto_report, compression_strategy, context_selection reject invalid values", () => {
223
+ test("auto_visualize, auto_report, context_selection reject invalid values", () => {
226
224
  const { errors: e1 } = validatePreferences({ auto_visualize: "yes" as never });
227
225
  assert.ok(e1.some(e => e.includes("auto_visualize")));
228
226
 
229
227
  const { errors: e2 } = validatePreferences({ auto_report: 1 as never });
230
228
  assert.ok(e2.some(e => e.includes("auto_report")));
231
229
 
232
- const { errors: e3 } = validatePreferences({ compression_strategy: "shrink" as never });
233
- assert.ok(e3.some(e => e.includes("compression_strategy")));
234
-
235
230
  const { errors: e4 } = validatePreferences({ context_selection: "partial" as never });
236
231
  assert.ok(e4.some(e => e.includes("context_selection")));
237
232
  });
@@ -0,0 +1,59 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+
6
+ const promptsDir = join(process.cwd(), "src/resources/extensions/gsd/prompts");
7
+
8
+ function readPrompt(name: string): string {
9
+ return readFileSync(join(promptsDir, `${name}.md`), "utf-8");
10
+ }
11
+
12
+ test("reactive-execute prompt keeps task summaries with subagents and avoids batch commits", () => {
13
+ const prompt = readPrompt("reactive-execute");
14
+ assert.match(prompt, /subagent-written summary as authoritative/i);
15
+ assert.match(prompt, /Do NOT create a batch commit/i);
16
+ assert.doesNotMatch(prompt, /\*\*Write task summaries\*\*/i);
17
+ assert.doesNotMatch(prompt, /\*\*Commit\*\* all changes/i);
18
+ });
19
+
20
+ test("run-uat prompt branches on dynamic UAT mode and supports runtime evidence", () => {
21
+ const prompt = readPrompt("run-uat");
22
+ assert.match(prompt, /\*\*Detected UAT mode:\*\*\s*`\{\{uatType\}\}`/);
23
+ assert.match(prompt, /uatType:\s*\{\{uatType\}\}/);
24
+ assert.match(prompt, /live-runtime/);
25
+ assert.match(prompt, /browser\/runtime\/network/i);
26
+ assert.match(prompt, /NEEDS-HUMAN/);
27
+ assert.doesNotMatch(prompt, /uatType:\s*artifact-driven/);
28
+ });
29
+
30
+ test("workflow-start prompt defaults to autonomy instead of per-phase confirmation", () => {
31
+ const prompt = readPrompt("workflow-start");
32
+ assert.match(prompt, /Keep moving by default/i);
33
+ assert.match(prompt, /Decision gates, not ceremony/i);
34
+ assert.doesNotMatch(prompt, /confirm with the user before proceeding/i);
35
+ assert.doesNotMatch(prompt, /Gate between phases/i);
36
+ });
37
+
38
+ test("discuss prompt allows implementation questions when they materially matter", () => {
39
+ const prompt = readPrompt("discuss");
40
+ assert.match(prompt, /Lead with experience, but ask implementation when it materially matters/i);
41
+ assert.match(prompt, /one gate, not two/i);
42
+ assert.doesNotMatch(prompt, /Questions must be about the experience, not the implementation/i);
43
+ });
44
+
45
+ test("guided discussion prompts avoid wrap-up prompts after every round", () => {
46
+ const milestonePrompt = readPrompt("guided-discuss-milestone");
47
+ const slicePrompt = readPrompt("guided-discuss-slice");
48
+ assert.match(milestonePrompt, /Do \*\*not\*\* ask a meta "ready to wrap up\?" question after every round/i);
49
+ assert.match(slicePrompt, /Do \*\*not\*\* ask a meta "ready to wrap up\?" question after every round/i);
50
+ assert.doesNotMatch(milestonePrompt, /I think I have a solid picture of this milestone\. Ready to wrap up/i);
51
+ assert.doesNotMatch(slicePrompt, /I think I have a solid picture of this slice\. Ready to wrap up/i);
52
+ });
53
+
54
+ test("guided-resume-task prompt preserves recovery state until work is superseded", () => {
55
+ const prompt = readPrompt("guided-resume-task");
56
+ assert.match(prompt, /Do \*\*not\*\* delete the continue file immediately/i);
57
+ assert.match(prompt, /successfully completed or you have written a newer summary\/continue artifact/i);
58
+ assert.doesNotMatch(prompt, /Delete the continue file after reading it/i);
59
+ });