gsd-pi 2.59.0-dev.3de3832 → 2.59.0-dev.d77b3dd

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 (90) hide show
  1. package/dist/resources/extensions/gsd/auto/phases.js +54 -1
  2. package/dist/resources/extensions/gsd/auto-model-selection.js +8 -3
  3. package/dist/resources/extensions/gsd/auto-post-unit.js +40 -1
  4. package/dist/resources/extensions/gsd/auto-prompts.js +13 -0
  5. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +70 -0
  6. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +51 -5
  7. package/dist/resources/extensions/gsd/captures.js +54 -1
  8. package/dist/resources/extensions/gsd/complexity-classifier.js +1 -1
  9. package/dist/resources/extensions/gsd/context-masker.js +68 -0
  10. package/dist/resources/extensions/gsd/docs/preferences-reference.md +7 -0
  11. package/dist/resources/extensions/gsd/gsd-db.js +2 -2
  12. package/dist/resources/extensions/gsd/model-router.js +123 -4
  13. package/dist/resources/extensions/gsd/phase-anchor.js +56 -0
  14. package/dist/resources/extensions/gsd/preferences-types.js +1 -0
  15. package/dist/resources/extensions/gsd/preferences-validation.js +46 -0
  16. package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -0
  17. package/dist/resources/extensions/gsd/prompts/rethink.md +7 -0
  18. package/dist/resources/extensions/gsd/prompts/triage-captures.md +6 -1
  19. package/dist/resources/extensions/gsd/rethink.js +5 -2
  20. package/dist/resources/extensions/gsd/state.js +1 -1
  21. package/dist/resources/extensions/gsd/status-guards.js +4 -3
  22. package/dist/resources/extensions/gsd/triage-resolution.js +128 -1
  23. package/dist/resources/extensions/gsd/triage-ui.js +12 -3
  24. package/dist/resources/skills/btw/SKILL.md +42 -0
  25. package/dist/web/standalone/.next/BUILD_ID +1 -1
  26. package/dist/web/standalone/.next/app-path-routes-manifest.json +20 -20
  27. package/dist/web/standalone/.next/build-manifest.json +2 -2
  28. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  29. package/dist/web/standalone/.next/required-server-files.json +1 -1
  30. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  31. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  39. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/index.html +1 -1
  47. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app-paths-manifest.json +20 -20
  54. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  55. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  56. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  57. package/dist/web/standalone/server.js +1 -1
  58. package/package.json +1 -1
  59. package/src/resources/extensions/gsd/auto/phases.ts +60 -1
  60. package/src/resources/extensions/gsd/auto-model-selection.ts +12 -3
  61. package/src/resources/extensions/gsd/auto-post-unit.ts +48 -1
  62. package/src/resources/extensions/gsd/auto-prompts.ts +17 -0
  63. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +78 -0
  64. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +53 -4
  65. package/src/resources/extensions/gsd/captures.ts +71 -2
  66. package/src/resources/extensions/gsd/complexity-classifier.ts +1 -1
  67. package/src/resources/extensions/gsd/context-masker.ts +74 -0
  68. package/src/resources/extensions/gsd/docs/preferences-reference.md +7 -0
  69. package/src/resources/extensions/gsd/gsd-db.ts +2 -2
  70. package/src/resources/extensions/gsd/model-router.ts +171 -8
  71. package/src/resources/extensions/gsd/phase-anchor.ts +71 -0
  72. package/src/resources/extensions/gsd/preferences-types.ts +9 -0
  73. package/src/resources/extensions/gsd/preferences-validation.ts +38 -0
  74. package/src/resources/extensions/gsd/prompts/execute-task.md +2 -0
  75. package/src/resources/extensions/gsd/prompts/rethink.md +7 -0
  76. package/src/resources/extensions/gsd/prompts/triage-captures.md +6 -1
  77. package/src/resources/extensions/gsd/rethink.ts +5 -2
  78. package/src/resources/extensions/gsd/state.ts +1 -1
  79. package/src/resources/extensions/gsd/status-guards.ts +4 -3
  80. package/src/resources/extensions/gsd/tests/context-masker.test.ts +122 -0
  81. package/src/resources/extensions/gsd/tests/model-router.test.ts +87 -1
  82. package/src/resources/extensions/gsd/tests/phase-anchor.test.ts +83 -0
  83. package/src/resources/extensions/gsd/tests/status-guards.test.ts +4 -0
  84. package/src/resources/extensions/gsd/tests/stop-backtrack.test.ts +216 -0
  85. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +1 -1
  86. package/src/resources/extensions/gsd/triage-resolution.ts +144 -1
  87. package/src/resources/extensions/gsd/triage-ui.ts +12 -3
  88. package/src/resources/skills/btw/SKILL.md +42 -0
  89. /package/dist/web/standalone/.next/static/{Y_HG7cJVptjBpkVSQQiFi → t_cBZAENjaOJIRST3dw08}/_buildManifest.js +0 -0
  90. /package/dist/web/standalone/.next/static/{Y_HG7cJVptjBpkVSQQiFi → t_cBZAENjaOJIRST3dw08}/_ssgManifest.js +0 -0
@@ -21,6 +21,13 @@ import type {
21
21
  GateEvaluationConfig,
22
22
  } from "./types.js";
23
23
  import type { DynamicRoutingConfig } from "./model-router.js";
24
+
25
+ export interface ContextManagementConfig {
26
+ observation_masking?: boolean; // default: true
27
+ observation_mask_turns?: number; // default: 8, range: 1-50
28
+ compaction_threshold_percent?: number; // default: 0.70, range: 0.5-0.95
29
+ tool_result_max_chars?: number; // default: 800, range: 200-10000
30
+ }
24
31
  import type { GitHubSyncConfig } from "../github-sync/types.js";
25
32
 
26
33
  // ─── Workflow Modes ──────────────────────────────────────────────────────────
@@ -94,6 +101,7 @@ export const KNOWN_PREFERENCE_KEYS = new Set<string>([
94
101
  "forensics_dedup",
95
102
  "show_token_cost",
96
103
  "stale_commit_threshold_minutes",
104
+ "context_management",
97
105
  "experimental",
98
106
  ]);
99
107
 
@@ -227,6 +235,7 @@ export interface GSDPreferences {
227
235
  post_unit_hooks?: PostUnitHookConfig[];
228
236
  pre_dispatch_hooks?: PreDispatchHookConfig[];
229
237
  dynamic_routing?: DynamicRoutingConfig;
238
+ context_management?: ContextManagementConfig;
230
239
  token_profile?: TokenProfile;
231
240
  phases?: PhaseSkipPreferences;
232
241
  auto_visualize?: boolean;
@@ -428,6 +428,10 @@ export function validatePreferences(preferences: GSDPreferences): {
428
428
  if (typeof dr.hooks === "boolean") validDr.hooks = dr.hooks;
429
429
  else errors.push("dynamic_routing.hooks must be a boolean");
430
430
  }
431
+ if (dr.capability_routing !== undefined) {
432
+ if (typeof dr.capability_routing === "boolean") validDr.capability_routing = dr.capability_routing;
433
+ else errors.push("dynamic_routing.capability_routing must be a boolean");
434
+ }
431
435
  if (dr.tier_models !== undefined) {
432
436
  if (typeof dr.tier_models === "object" && dr.tier_models !== null) {
433
437
  const tm = dr.tier_models as Record<string, unknown>;
@@ -452,6 +456,40 @@ export function validatePreferences(preferences: GSDPreferences): {
452
456
  }
453
457
  }
454
458
 
459
+ // ─── Context Management ──────────────────────────────────────────────
460
+ if (preferences.context_management !== undefined) {
461
+ if (typeof preferences.context_management === "object" && preferences.context_management !== null) {
462
+ const cm = preferences.context_management as unknown as Record<string, unknown>;
463
+ const validCm: Record<string, unknown> = {};
464
+
465
+ if (cm.observation_masking !== undefined) {
466
+ if (typeof cm.observation_masking === "boolean") validCm.observation_masking = cm.observation_masking;
467
+ else errors.push("context_management.observation_masking must be a boolean");
468
+ }
469
+ if (cm.observation_mask_turns !== undefined) {
470
+ const turns = cm.observation_mask_turns;
471
+ if (typeof turns === "number" && turns >= 1 && turns <= 50) validCm.observation_mask_turns = turns;
472
+ else errors.push("context_management.observation_mask_turns must be a number between 1 and 50");
473
+ }
474
+ if (cm.compaction_threshold_percent !== undefined) {
475
+ const pct = cm.compaction_threshold_percent;
476
+ if (typeof pct === "number" && pct >= 0.5 && pct <= 0.95) validCm.compaction_threshold_percent = pct;
477
+ else errors.push("context_management.compaction_threshold_percent must be a number between 0.5 and 0.95");
478
+ }
479
+ if (cm.tool_result_max_chars !== undefined) {
480
+ const chars = cm.tool_result_max_chars;
481
+ if (typeof chars === "number" && chars >= 200 && chars <= 10000) validCm.tool_result_max_chars = chars;
482
+ else errors.push("context_management.tool_result_max_chars must be a number between 200 and 10000");
483
+ }
484
+
485
+ if (Object.keys(validCm).length > 0) {
486
+ validated.context_management = validCm as any;
487
+ }
488
+ } else {
489
+ errors.push("context_management must be an object");
490
+ }
491
+ }
492
+
455
493
  // ─── Parallel Config ────────────────────────────────────────────────────
456
494
  if (preferences.parallel && typeof preferences.parallel === "object") {
457
495
  const p = preferences.parallel as unknown as Record<string, unknown>;
@@ -12,6 +12,8 @@ A researcher explored the codebase and a planner decomposed the work — you are
12
12
 
13
13
  {{runtimeContext}}
14
14
 
15
+ {{phaseAnchorSection}}
16
+
15
17
  {{resumeSection}}
16
18
 
17
19
  {{carryForwardSection}}
@@ -45,6 +45,13 @@ reason: "<reason>"
45
45
  ### Unpark a milestone
46
46
  Remove the `{ID}-PARKED.md` file from the milestone directory to reactivate it.
47
47
 
48
+ ### Skip a slice
49
+ Mark a slice as skipped so auto-mode advances past it without executing. Use the `gsd_skip_slice` tool:
50
+ ```
51
+ gsd_skip_slice({ milestone_id: "M003", slice_id: "S02", reason: "Descoped — feature moved to M005" })
52
+ ```
53
+ Skipped slices are treated as closed by the state machine (like "complete" but distinct). Use when a slice is no longer needed or has been superseded. The slice data is preserved for reference.
54
+
48
55
  ### Discard a milestone
49
56
  **Permanently** delete a milestone directory and prune it from QUEUE-ORDER.json. **Always confirm with the user before discarding.** Warn explicitly if the milestone has completed work.
50
57
 
@@ -20,6 +20,8 @@ The user captured thoughts during execution using `/gsd capture`. Your job is to
20
20
 
21
21
  For each capture, classify it as one of:
22
22
 
23
+ - **stop**: User directive to halt auto-mode immediately. Use when the user says "stop", "halt", "abort", "don't continue", "pause", or otherwise wants execution to cease. Auto-mode will pause after the current unit completes. Examples: "stop running", "halt execution", "don't continue".
24
+ - **backtrack**: User directive to abandon the current milestone and return to a previous one. The user believes earlier milestones missed critical features or need rework. Include the target milestone ID (e.g., M003) in the Resolution field. Auto-mode will pause and write a regression marker. Examples: "restart from M003", "go back to milestone 3", "M004 and M005 failed, restart from M003".
23
25
  - **quick-task**: Small, self-contained, no downstream impact. Can be done in minutes without modifying the plan. Examples: fix a typo, add a missing import, tweak a config value.
24
26
  - **inject**: Belongs in the current slice but wasn't planned. Needs a new task added to the slice plan. Examples: add error handling to a module being built, add a missing test case for current work.
25
27
  - **defer**: Belongs in a future slice or milestone. Not urgent for current work. Examples: performance optimization, feature that depends on unbuilt infrastructure, nice-to-have enhancement.
@@ -28,10 +30,12 @@ For each capture, classify it as one of:
28
30
 
29
31
  ## Decision Guidelines
30
32
 
33
+ - **ALWAYS classify as stop** when the user explicitly says "stop", "halt", "abort", or "don't continue". Never shoe-horn a stop directive into "replan" or "note".
34
+ - **ALWAYS classify as backtrack** when the user references returning to a previous milestone, restarting from an earlier point, or abandoning current milestone work. Include the target milestone ID in the Resolution field (e.g., "Backtrack to M003").
31
35
  - Prefer **quick-task** when the work is clearly small and self-contained.
32
36
  - Prefer **inject** over **replan** when only a new task is needed, not rewriting existing ones.
33
37
  - Prefer **defer** over **inject** when the work doesn't belong in the current slice's scope.
34
- - Use **replan** only when remaining incomplete tasks need to change — not just for adding work.
38
+ - Use **replan** only when remaining incomplete tasks in the *current slice* need to change — not for cross-milestone issues.
35
39
  - Use **note** for observations that don't require action.
36
40
  - When unsure between quick-task and inject, consider: will this take more than 10 minutes? If yes, inject.
37
41
 
@@ -46,6 +50,7 @@ For each capture, classify it as one of:
46
50
  - If applicable, which files would be affected
47
51
 
48
52
  For captures classified as **note** or **defer**, auto-confirm without asking — these are low-impact.
53
+ For captures classified as **stop** or **backtrack**, auto-confirm without asking — these are urgent user directives that must be honored immediately.
49
54
  For captures classified as **quick-task**, **inject**, or **replan**, ask the user to confirm or choose a different classification.
50
55
 
51
56
  3. **Update** `.gsd/CAPTURES.md` — for each capture, update its section with the confirmed classification:
@@ -112,8 +112,11 @@ function buildRethinkData(
112
112
  if (dbAvailable && status !== "complete") {
113
113
  const slices = getMilestoneSlices(mid);
114
114
  if (slices.length > 0) {
115
- const done = slices.filter(s => s.status === "complete").length;
116
- sliceInfo = `${done}/${slices.length} complete`;
115
+ const done = slices.filter(s => s.status === "complete" || s.status === "done").length;
116
+ const skipped = slices.filter(s => s.status === "skipped").length;
117
+ sliceInfo = skipped > 0
118
+ ? `${done}/${slices.length} complete, ${skipped} skipped`
119
+ : `${done}/${slices.length} complete`;
117
120
  }
118
121
  }
119
122
 
@@ -295,7 +295,7 @@ function extractContextTitle(content: string | null, fallback: string): string {
295
295
  * Helper: check if a DB status counts as "done" (handles K002 ambiguity).
296
296
  */
297
297
  function isStatusDone(status: string): boolean {
298
- return status === 'complete' || status === 'done';
298
+ return status === 'complete' || status === 'done' || status === 'skipped';
299
299
  }
300
300
 
301
301
  /**
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * Status predicates for GSD state-machine guards.
3
3
  *
4
- * The DB stores status as free-form strings. Two values indicate
5
- * "closed": "complete" (canonical) and "done" (legacy / alias).
4
+ * The DB stores status as free-form strings. Three values indicate
5
+ * "closed": "complete" (canonical), "done" (legacy / alias), and
6
+ * "skipped" (user-directed skip via rethink or backtrack).
6
7
  * Every inline `status === "complete" || status === "done"` should
7
8
  * use isClosedStatus() instead.
8
9
  */
9
10
 
10
11
  /** Returns true when a milestone, slice, or task status indicates closure. */
11
12
  export function isClosedStatus(status: string): boolean {
12
- return status === "complete" || status === "done";
13
+ return status === "complete" || status === "done" || status === "skipped";
13
14
  }
@@ -0,0 +1,122 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import { createObservationMask } from "../context-masker.js";
5
+
6
+ // These helpers produce messages in the pi-ai LLM payload format
7
+ // (post-convertToLlm, pre-provider), which is what before_provider_request sees.
8
+
9
+ function userMsg(content: string) {
10
+ return { role: "user", content: [{ type: "text", text: content }] };
11
+ }
12
+
13
+ function assistantMsg(content: string) {
14
+ return { role: "assistant", content: [{ type: "text", text: content }] };
15
+ }
16
+
17
+ /** toolResult in pi-ai format: role "toolResult", content as TextContent[] */
18
+ function toolResult(text: string) {
19
+ return { role: "toolResult", content: [{ type: "text", text }], toolCallId: "toolu_test", toolName: "Read", isError: false };
20
+ }
21
+
22
+ /** bashExecution after convertToLlm: becomes a user message with "Ran `cmd`" prefix */
23
+ function bashResult(text: string) {
24
+ return { role: "user", content: [{ type: "text", text: `Ran \`echo test\`\n\`\`\`\n${text}\n\`\`\`` }] };
25
+ }
26
+
27
+ const MASK_TEXT = "[result masked — within summarized history]";
28
+
29
+ test("masks nothing when message count is within keepRecentTurns", () => {
30
+ const mask = createObservationMask(8);
31
+ const messages = [
32
+ userMsg("hello"),
33
+ assistantMsg("hi"),
34
+ toolResult("file contents"),
35
+ ];
36
+ const result = mask(messages as any);
37
+ assert.equal(result.length, 3);
38
+ assert.deepEqual((result[2].content as any)[0].text, "file contents");
39
+ });
40
+
41
+ test("masks tool results older than keepRecentTurns", () => {
42
+ const mask = createObservationMask(2);
43
+ const messages = [
44
+ userMsg("turn 1"),
45
+ toolResult("old tool output"),
46
+ assistantMsg("response 1"),
47
+ userMsg("turn 2"),
48
+ toolResult("newer tool output"),
49
+ assistantMsg("response 2"),
50
+ userMsg("turn 3"),
51
+ toolResult("newest tool output"),
52
+ assistantMsg("response 3"),
53
+ ];
54
+ const result = mask(messages as any);
55
+ // Old tool result (before boundary) should be masked
56
+ assert.equal((result[1].content as any)[0].text, MASK_TEXT);
57
+ // Recent tool results (within keep window) should be preserved
58
+ assert.equal((result[4].content as any)[0].text, "newer tool output");
59
+ assert.equal((result[7].content as any)[0].text, "newest tool output");
60
+ });
61
+
62
+ test("never masks assistant messages", () => {
63
+ const mask = createObservationMask(1);
64
+ const messages = [
65
+ userMsg("turn 1"),
66
+ assistantMsg("old reasoning"),
67
+ userMsg("turn 2"),
68
+ assistantMsg("new reasoning"),
69
+ ];
70
+ const result = mask(messages as any);
71
+ assert.equal((result[1].content as any)[0].text, "old reasoning");
72
+ assert.equal((result[3].content as any)[0].text, "new reasoning");
73
+ });
74
+
75
+ test("never masks user messages", () => {
76
+ const mask = createObservationMask(1);
77
+ const messages = [
78
+ userMsg("old user message"),
79
+ assistantMsg("response"),
80
+ userMsg("new user message"),
81
+ assistantMsg("response"),
82
+ ];
83
+ const result = mask(messages as any);
84
+ assert.equal((result[0].content as any)[0].text, "old user message");
85
+ });
86
+
87
+ test("masks bash result user messages", () => {
88
+ const mask = createObservationMask(1);
89
+ const messages = [
90
+ userMsg("turn 1"),
91
+ bashResult("huge log output"),
92
+ assistantMsg("response 1"),
93
+ userMsg("turn 2"),
94
+ assistantMsg("response 2"),
95
+ ];
96
+ const result = mask(messages as any);
97
+ assert.equal((result[1].content as any)[0].text, MASK_TEXT);
98
+ });
99
+
100
+ test("returns same array length", () => {
101
+ const mask = createObservationMask(1);
102
+ const messages = [
103
+ userMsg("a"), toolResult("b"), assistantMsg("c"),
104
+ userMsg("d"), toolResult("e"), assistantMsg("f"),
105
+ ];
106
+ const result = mask(messages as any);
107
+ assert.equal(result.length, messages.length);
108
+ });
109
+
110
+ test("masks toolResult by role, not by type field", () => {
111
+ const mask = createObservationMask(1);
112
+ const messages = [
113
+ userMsg("turn 1"),
114
+ // This is the actual pi-ai format: role "toolResult", no type field
115
+ { role: "toolResult", content: [{ type: "text", text: "old result" }], toolCallId: "t1", toolName: "Read", isError: false },
116
+ assistantMsg("response 1"),
117
+ userMsg("turn 2"),
118
+ assistantMsg("response 2"),
119
+ ];
120
+ const result = mask(messages as any);
121
+ assert.equal((result[1].content as any)[0].text, MASK_TEXT);
122
+ });
@@ -5,8 +5,11 @@ import {
5
5
  resolveModelForComplexity,
6
6
  escalateTier,
7
7
  defaultRoutingConfig,
8
+ scoreModel,
9
+ computeTaskRequirements,
10
+ MODEL_CAPABILITY_PROFILES,
8
11
  } from "../model-router.js";
9
- import type { DynamicRoutingConfig, RoutingDecision } from "../model-router.js";
12
+ import type { DynamicRoutingConfig, RoutingDecision, ModelCapabilities } from "../model-router.js";
10
13
  import type { ClassificationResult } from "../complexity-classifier.js";
11
14
 
12
15
  // ─── Helpers ─────────────────────────────────────────────────────────────────
@@ -206,6 +209,89 @@ test("#2192: known model is still downgraded normally", () => {
206
209
  assert.notEqual(result.modelId, "claude-opus-4-6");
207
210
  });
208
211
 
212
+ // ─── Capability Scoring (ADR-004 Phase 2) ───────────────────────────────────
213
+
214
+ test("defaultRoutingConfig includes capability_routing: false", () => {
215
+ const config = defaultRoutingConfig();
216
+ assert.equal(config.capability_routing, false);
217
+ });
218
+
219
+ test("scoreModel computes weighted average of capability × requirement", () => {
220
+ const caps: ModelCapabilities = {
221
+ coding: 90, debugging: 80, research: 70,
222
+ reasoning: 85, speed: 50, longContext: 60, instruction: 75,
223
+ };
224
+ const reqs = { coding: 0.9, reasoning: 0.5 };
225
+ const score = scoreModel(caps, reqs);
226
+ // Expected: (0.9*90 + 0.5*85) / (0.9 + 0.5) = (81 + 42.5) / 1.4 = 88.21...
227
+ assert.ok(Math.abs(score - 88.21) < 0.1, `score ${score} should be ~88.21`);
228
+ });
229
+
230
+ test("scoreModel returns 50 for empty requirements", () => {
231
+ const caps: ModelCapabilities = {
232
+ coding: 90, debugging: 80, research: 70,
233
+ reasoning: 85, speed: 50, longContext: 60, instruction: 75,
234
+ };
235
+ const score = scoreModel(caps, {});
236
+ assert.equal(score, 50);
237
+ });
238
+
239
+ test("computeTaskRequirements returns base vector for known unit type", () => {
240
+ const reqs = computeTaskRequirements("execute-task");
241
+ assert.ok(reqs.coding !== undefined && reqs.coding > 0);
242
+ });
243
+
244
+ test("computeTaskRequirements boosts instruction for docs-tagged tasks", () => {
245
+ const reqs = computeTaskRequirements("execute-task", { tags: ["docs"] });
246
+ assert.ok((reqs.instruction ?? 0) >= 0.8);
247
+ assert.ok((reqs.coding ?? 1) <= 0.4);
248
+ });
249
+
250
+ test("computeTaskRequirements returns generic vector for unknown unit type", () => {
251
+ const reqs = computeTaskRequirements("unknown-unit");
252
+ assert.ok(reqs.reasoning !== undefined);
253
+ });
254
+
255
+ test("resolveModelForComplexity uses capability scoring when enabled", () => {
256
+ const config: DynamicRoutingConfig = {
257
+ ...defaultRoutingConfig(),
258
+ enabled: true,
259
+ capability_routing: true,
260
+ };
261
+ const result = resolveModelForComplexity(
262
+ makeClassification("light"),
263
+ { primary: "claude-opus-4-6", fallbacks: [] },
264
+ config,
265
+ ["claude-opus-4-6", "claude-haiku-4-5", "gpt-4o-mini"],
266
+ "execute-task",
267
+ );
268
+ assert.equal(result.wasDowngraded, true);
269
+ assert.equal(result.selectionMethod, "capability-scored");
270
+ });
271
+
272
+ test("resolveModelForComplexity falls back to tier-only when capability_routing is false", () => {
273
+ const config: DynamicRoutingConfig = {
274
+ ...defaultRoutingConfig(),
275
+ enabled: true,
276
+ capability_routing: false,
277
+ };
278
+ const result = resolveModelForComplexity(
279
+ makeClassification("light"),
280
+ { primary: "claude-opus-4-6", fallbacks: [] },
281
+ config,
282
+ ["claude-opus-4-6", "claude-haiku-4-5", "gpt-4o-mini"],
283
+ );
284
+ assert.equal(result.wasDowngraded, true);
285
+ assert.ok(!result.selectionMethod || result.selectionMethod === "tier-only");
286
+ });
287
+
288
+ test("MODEL_CAPABILITY_PROFILES has entries for core models", () => {
289
+ const profiledModels = Object.keys(MODEL_CAPABILITY_PROFILES);
290
+ assert.ok(profiledModels.length >= 9, `Expected ≥9 profiles, got ${profiledModels.length}`);
291
+ assert.ok(MODEL_CAPABILITY_PROFILES["claude-opus-4-6"]);
292
+ assert.ok(MODEL_CAPABILITY_PROFILES["claude-haiku-4-5"]);
293
+ });
294
+
209
295
  // ─── #2885: openai-codex and modern OpenAI models in tier map ────────────────
210
296
 
211
297
  test("#2885: openai-codex light-tier models are recognized", () => {
@@ -0,0 +1,83 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdtempSync, mkdirSync, rmSync, existsSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { tmpdir } from "node:os";
6
+
7
+ import { writePhaseAnchor, readPhaseAnchor, formatAnchorForPrompt } from "../phase-anchor.js";
8
+ import type { PhaseAnchor } from "../phase-anchor.js";
9
+
10
+ function makeTempBase(): string {
11
+ const tmp = mkdtempSync(join(tmpdir(), "gsd-anchor-test-"));
12
+ mkdirSync(join(tmp, ".gsd", "milestones", "M001", "anchors"), { recursive: true });
13
+ return tmp;
14
+ }
15
+
16
+ test("writePhaseAnchor creates anchor file in correct location", () => {
17
+ const base = makeTempBase();
18
+ try {
19
+ const anchor: PhaseAnchor = {
20
+ phase: "discuss",
21
+ milestoneId: "M001",
22
+ generatedAt: new Date().toISOString(),
23
+ intent: "Define authentication requirements",
24
+ decisions: ["Use JWT tokens", "Session expiry 24h"],
25
+ blockers: [],
26
+ nextSteps: ["Plan the implementation slices"],
27
+ };
28
+ writePhaseAnchor(base, "M001", anchor);
29
+ assert.ok(existsSync(join(base, ".gsd", "milestones", "M001", "anchors", "discuss.json")));
30
+ } finally {
31
+ rmSync(base, { recursive: true, force: true });
32
+ }
33
+ });
34
+
35
+ test("readPhaseAnchor returns written anchor", () => {
36
+ const base = makeTempBase();
37
+ try {
38
+ const anchor: PhaseAnchor = {
39
+ phase: "plan",
40
+ milestoneId: "M001",
41
+ generatedAt: new Date().toISOString(),
42
+ intent: "Break work into slices",
43
+ decisions: ["3 slices: auth, UI, tests"],
44
+ blockers: ["Need DB schema first"],
45
+ nextSteps: ["Execute S01"],
46
+ };
47
+ writePhaseAnchor(base, "M001", anchor);
48
+ const read = readPhaseAnchor(base, "M001", "plan");
49
+ assert.ok(read);
50
+ assert.equal(read!.intent, "Break work into slices");
51
+ assert.deepEqual(read!.decisions, ["3 slices: auth, UI, tests"]);
52
+ assert.deepEqual(read!.blockers, ["Need DB schema first"]);
53
+ } finally {
54
+ rmSync(base, { recursive: true, force: true });
55
+ }
56
+ });
57
+
58
+ test("readPhaseAnchor returns null when no anchor exists", () => {
59
+ const base = makeTempBase();
60
+ try {
61
+ const read = readPhaseAnchor(base, "M001", "discuss");
62
+ assert.equal(read, null);
63
+ } finally {
64
+ rmSync(base, { recursive: true, force: true });
65
+ }
66
+ });
67
+
68
+ test("formatAnchorForPrompt produces markdown block", () => {
69
+ const anchor: PhaseAnchor = {
70
+ phase: "discuss",
71
+ milestoneId: "M001",
72
+ generatedAt: "2026-04-03T00:00:00.000Z",
73
+ intent: "Define requirements",
74
+ decisions: ["Use JWT"],
75
+ blockers: [],
76
+ nextSteps: ["Plan slices"],
77
+ };
78
+ const md = formatAnchorForPrompt(anchor);
79
+ assert.ok(md.includes("## Handoff from discuss"));
80
+ assert.ok(md.includes("Define requirements"));
81
+ assert.ok(md.includes("Use JWT"));
82
+ assert.ok(md.includes("Plan slices"));
83
+ });
@@ -13,6 +13,10 @@ test('isClosedStatus: "done" returns true', () => {
13
13
  assert.equal(isClosedStatus('done'), true);
14
14
  });
15
15
 
16
+ test('isClosedStatus: "skipped" returns true', () => {
17
+ assert.equal(isClosedStatus('skipped'), true);
18
+ });
19
+
16
20
  test('isClosedStatus: "pending" returns false', () => {
17
21
  assert.equal(isClosedStatus('pending'), false);
18
22
  });