@tekyzinc/gsd-t 3.29.11 → 4.0.14

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 (114) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/bin/gsd-t-parallel.cjs +64 -13
  3. package/bin/gsd-t.js +48 -376
  4. package/bin/journey-coverage.cjs +6 -3
  5. package/bin/parallel-cli.cjs +13 -1
  6. package/commands/gsd-t-complete-milestone.md +6 -12
  7. package/commands/gsd-t-debug.md +47 -533
  8. package/commands/gsd-t-design-decompose.md +24 -497
  9. package/commands/gsd-t-doc-ripple.md +23 -139
  10. package/commands/gsd-t-execute.md +41 -958
  11. package/commands/gsd-t-feature.md +2 -6
  12. package/commands/gsd-t-gap-analysis.md +3 -6
  13. package/commands/gsd-t-help.md +2 -4
  14. package/commands/gsd-t-impact.md +26 -295
  15. package/commands/gsd-t-init-scan-setup.md +7 -7
  16. package/commands/gsd-t-integrate.md +44 -369
  17. package/commands/gsd-t-milestone.md +25 -124
  18. package/commands/gsd-t-partition.md +28 -539
  19. package/commands/gsd-t-plan.md +26 -472
  20. package/commands/gsd-t-prd.md +25 -311
  21. package/commands/gsd-t-quick.md +1 -1
  22. package/commands/gsd-t-resume.md +0 -33
  23. package/commands/gsd-t-scan.md +45 -652
  24. package/commands/gsd-t-verify.md +52 -569
  25. package/commands/gsd-t-wave.md +41 -430
  26. package/package.json +1 -1
  27. package/scripts/gsd-t-calibration-hook.js +3 -1
  28. package/scripts/hooks/pre-commit-journey-coverage +0 -2
  29. package/scripts/hooks/pre-commit-playwright-gate +0 -2
  30. package/templates/CLAUDE-global.md +44 -173
  31. package/templates/CLAUDE-project.md +118 -104
  32. package/templates/prompts/design-verify-subagent.md +3 -0
  33. package/templates/prompts/qa-subagent.md +3 -0
  34. package/templates/prompts/red-team-subagent.md +5 -2
  35. package/templates/workflows/_lib.js +176 -0
  36. package/templates/workflows/gsd-t-debug.workflow.js +86 -0
  37. package/templates/workflows/gsd-t-execute.workflow.js +206 -0
  38. package/templates/workflows/gsd-t-integrate.workflow.js +71 -0
  39. package/templates/workflows/gsd-t-phase.workflow.js +94 -0
  40. package/templates/workflows/gsd-t-quick.workflow.js +72 -0
  41. package/templates/workflows/gsd-t-scan.workflow.js +711 -0
  42. package/templates/workflows/gsd-t-verify.workflow.js +348 -0
  43. package/templates/workflows/gsd-t-wave.workflow.js +43 -0
  44. package/bin/check-headless-sessions.js +0 -140
  45. package/bin/context-budget-audit.cjs +0 -447
  46. package/bin/context-meter-config.cjs +0 -101
  47. package/bin/context-meter-config.test.cjs +0 -101
  48. package/bin/event-stream.cjs +0 -205
  49. package/bin/gsd-t-benchmark-orchestrator.js +0 -437
  50. package/bin/gsd-t-capture-lint.cjs +0 -440
  51. package/bin/gsd-t-economics.cjs +0 -315
  52. package/bin/gsd-t-in-session-usage.cjs +0 -213
  53. package/bin/gsd-t-orchestrator-config.cjs +0 -161
  54. package/bin/gsd-t-orchestrator-queue.cjs +0 -180
  55. package/bin/gsd-t-orchestrator-recover.cjs +0 -231
  56. package/bin/gsd-t-orchestrator-worker.cjs +0 -219
  57. package/bin/gsd-t-orchestrator.js +0 -535
  58. package/bin/gsd-t-parallel-probe.cjs +0 -132
  59. package/bin/gsd-t-ratelimit-probe-worker.cjs +0 -237
  60. package/bin/gsd-t-ratelimit-probe.cjs +0 -648
  61. package/bin/gsd-t-report-tokens.cjs +0 -549
  62. package/bin/gsd-t-stream-feed-client.cjs +0 -151
  63. package/bin/gsd-t-token-backfill.cjs +0 -366
  64. package/bin/gsd-t-token-capture.cjs +0 -321
  65. package/bin/gsd-t-token-dashboard.cjs +0 -353
  66. package/bin/gsd-t-token-regenerate-log.cjs +0 -129
  67. package/bin/gsd-t-tool-attribution.cjs +0 -377
  68. package/bin/gsd-t-tool-cost.cjs +0 -195
  69. package/bin/gsd-t-transcript-tee.cjs +0 -246
  70. package/bin/gsd-t-unattended-heartbeat.cjs +0 -188
  71. package/bin/gsd-t-unattended-platform.cjs +0 -551
  72. package/bin/gsd-t-unattended-platform.js +0 -381
  73. package/bin/gsd-t-unattended-safety.cjs +0 -773
  74. package/bin/gsd-t-unattended-safety.js +0 -788
  75. package/bin/gsd-t-unattended.cjs +0 -2109
  76. package/bin/gsd-t-unattended.js +0 -1367
  77. package/bin/gsd-t-worker-dispatch.cjs +0 -211
  78. package/bin/handoff-lock.cjs +0 -249
  79. package/bin/handoff-lock.js +0 -249
  80. package/bin/headless-auto-spawn.cjs +0 -711
  81. package/bin/headless-auto-spawn.js +0 -373
  82. package/bin/headless-exit-codes.cjs +0 -67
  83. package/bin/live-activity-report.cjs +0 -615
  84. package/bin/log-tail.cjs +0 -81
  85. package/bin/m44-proof-measure.cjs +0 -285
  86. package/bin/m46-iter-proof.cjs +0 -149
  87. package/bin/m46-worker-proof.cjs +0 -201
  88. package/bin/m55-substrate-proof.cjs +0 -134
  89. package/bin/metrics-rollup.js +0 -200
  90. package/bin/model-windows.cjs +0 -99
  91. package/bin/model-windows.test.cjs +0 -75
  92. package/bin/parallelism-report.cjs +0 -535
  93. package/bin/runway-estimator.cjs +0 -242
  94. package/bin/spawn-plan-derive.cjs +0 -163
  95. package/bin/spawn-plan-status-updater.cjs +0 -292
  96. package/bin/spawn-plan-writer.cjs +0 -204
  97. package/bin/supervisor-pid-fingerprint.cjs +0 -126
  98. package/bin/token-budget.cjs +0 -265
  99. package/bin/unattended-watch-format.cjs +0 -178
  100. package/bin/watch-progress.js +0 -155
  101. package/commands/gsd-t-unattended-stop.md +0 -85
  102. package/commands/gsd-t-unattended-watch.md +0 -465
  103. package/commands/gsd-t-unattended.md +0 -476
  104. package/commands/gsd-t-visualize.md +0 -116
  105. package/scripts/gsd-t-context-meter.e2e.test.js +0 -364
  106. package/scripts/gsd-t-context-meter.js +0 -341
  107. package/scripts/gsd-t-context-meter.test.js +0 -471
  108. package/scripts/gsd-t-dashboard-server.js +0 -1203
  109. package/scripts/gsd-t-post-commit-spawn-plan.sh +0 -86
  110. package/scripts/gsd-t-transcript.html +0 -1821
  111. package/scripts/hooks/gsd-t-conversation-capture.js +0 -439
  112. package/scripts/hooks/gsd-t-in-session-usage-hook.js +0 -84
  113. package/scripts/spawn-plan-fmt-tokens.cjs +0 -80
  114. package/templates/hooks/post-commit-spawn-plan.sh +0 -85
@@ -1,471 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Unit tests for scripts/gsd-t-context-meter.js
5
- *
6
- * v3.12 (M38 meter reduction): single-band (normal/threshold) — rewritten
7
- * from the M34 three-band / dead-meter era. The hook uses local token
8
- * estimation (no API key, no network) since v3.12, so the old countTokens
9
- * seam and missing-key tests are retired. The 7 previously stranded TD-102
10
- * tests are now rewritten against the v1.3.0 invariants.
11
- *
12
- * All dependencies are injected via runMeter's test seams — no real file
13
- * or transcript reads are needed.
14
- */
15
-
16
- const { test, beforeEach, afterEach } = require("node:test");
17
- const assert = require("node:assert/strict");
18
- const fs = require("fs");
19
- const path = require("path");
20
- const os = require("os");
21
-
22
- const { runMeter, defaultState } = require("./gsd-t-context-meter");
23
-
24
- /* ─────────────────────────── test harness ─────────────────────────── */
25
-
26
- let tmpRoot;
27
-
28
- beforeEach(() => {
29
- tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "gsd-t-cm-hook-"));
30
- });
31
-
32
- afterEach(() => {
33
- try {
34
- fs.rmSync(tmpRoot, { recursive: true, force: true });
35
- } catch (_) {
36
- /* ignore */
37
- }
38
- });
39
-
40
- function makeConfig(overrides = {}) {
41
- return {
42
- version: 1,
43
- thresholdPct: 75,
44
- modelWindowSize: 200000,
45
- checkFrequency: 5,
46
- statePath: ".gsd-t/.context-meter-state.json",
47
- logPath: ".gsd-t/context-meter.log",
48
- timeoutMs: 2000,
49
- ...overrides,
50
- };
51
- }
52
-
53
- function stateFile(root) {
54
- return path.join(root, ".gsd-t", ".context-meter-state.json");
55
- }
56
-
57
- function logFile(root) {
58
- return path.join(root, ".gsd-t", "context-meter.log");
59
- }
60
-
61
- function seedState(root, partial) {
62
- const statePath = stateFile(root);
63
- fs.mkdirSync(path.dirname(statePath), { recursive: true });
64
- fs.writeFileSync(
65
- statePath,
66
- JSON.stringify({ ...defaultState(), ...partial }, null, 2)
67
- );
68
- }
69
-
70
- function makePayload() {
71
- return {
72
- session_id: "test-session",
73
- transcript_path: path.join(tmpRoot, "fake-transcript.jsonl"),
74
- tool_name: "Bash",
75
- tool_input: {},
76
- tool_response: {},
77
- };
78
- }
79
-
80
- const FAKE_PARSED = {
81
- system: "",
82
- messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
83
- };
84
-
85
- /* ───────────────────────────── tests ───────────────────────────── */
86
-
87
- test("1. check-frequency skip — estimator NOT called, counter incremented, stdout {}", async () => {
88
- seedState(tmpRoot, { checkCount: 3 });
89
-
90
- const estimateCalls = [];
91
- const out = await runMeter({
92
- payload: makePayload(),
93
- projectRoot: tmpRoot,
94
- _loadConfig: () => makeConfig({ checkFrequency: 5 }),
95
- _parseTranscript: async () => {
96
- throw new Error("parseTranscript should not be called on skip");
97
- },
98
- _estimateTokens: () => {
99
- estimateCalls.push("called");
100
- throw new Error("estimateTokens should not be called on skip");
101
- },
102
- });
103
-
104
- assert.deepEqual(out, {});
105
- assert.equal(estimateCalls.length, 0);
106
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
107
- assert.equal(state.checkCount, 4);
108
- assert.equal(state.lastError, null);
109
- });
110
-
111
- test("2. check-frequency hit — under threshold → {} + state updated (single-band normal)", async () => {
112
- seedState(tmpRoot, { checkCount: 4 });
113
-
114
- const out = await runMeter({
115
- payload: makePayload(),
116
- projectRoot: tmpRoot,
117
- _loadConfig: () => makeConfig(),
118
- _parseTranscript: async () => FAKE_PARSED,
119
- _estimateTokens: () => ({ inputTokens: 10000 }),
120
- });
121
-
122
- assert.deepEqual(out, {});
123
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
124
- assert.equal(state.checkCount, 5);
125
- assert.equal(state.inputTokens, 10000);
126
- assert.equal(state.pct, 5);
127
- assert.equal(state.threshold, "normal");
128
- assert.equal(state.lastError, null);
129
- assert.equal(state.modelWindowSize, 200000);
130
- });
131
-
132
- test("3. check-frequency hit — at/over threshold → silent marker emitted, band='threshold'", async () => {
133
- seedState(tmpRoot, { checkCount: 4 });
134
-
135
- const out = await runMeter({
136
- payload: makePayload(),
137
- projectRoot: tmpRoot,
138
- _loadConfig: () => makeConfig(),
139
- _parseTranscript: async () => FAKE_PARSED,
140
- _estimateTokens: () => ({ inputTokens: 160000 }), // 80% > 75%
141
- });
142
-
143
- // v3.12: additionalContext is a SHORT machine-readable marker, not a STOP banner.
144
- assert.equal(typeof out.additionalContext, "string");
145
- assert.equal(out.additionalContext, "next-spawn-headless:true");
146
- // No user-facing banner strings.
147
- assert.ok(!/MANDATORY STOP/.test(out.additionalContext));
148
- assert.ok(!/\/gsd-t-pause/.test(out.additionalContext));
149
-
150
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
151
- assert.equal(state.checkCount, 5);
152
- assert.equal(state.pct, 80);
153
- assert.equal(state.threshold, "threshold");
154
- assert.equal(state.inputTokens, 160000);
155
- });
156
-
157
- test("4. no API key required — local estimator runs without any env setup", async () => {
158
- // v3.12: estimation is local (no API), so absence of any API key must not
159
- // affect behavior. This is the inverse of the old "missing_key" test.
160
- seedState(tmpRoot, { checkCount: 4 });
161
-
162
- const out = await runMeter({
163
- payload: makePayload(),
164
- projectRoot: tmpRoot,
165
- env: {}, // empty env — no keys of any kind
166
- _loadConfig: () => makeConfig(),
167
- _parseTranscript: async () => FAKE_PARSED,
168
- _estimateTokens: () => ({ inputTokens: 1000 }),
169
- });
170
-
171
- assert.deepEqual(out, {});
172
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
173
- assert.equal(state.checkCount, 5);
174
- assert.equal(state.lastError, null);
175
- assert.equal(state.inputTokens, 1000);
176
- // Log must never reference missing_key or API keys.
177
- if (fs.existsSync(logFile(tmpRoot))) {
178
- const log = fs.readFileSync(logFile(tmpRoot), "utf8");
179
- assert.ok(!/missing_key/.test(log));
180
- assert.ok(!/ANTHROPIC_API_KEY/.test(log));
181
- }
182
- });
183
-
184
- test("5. transcript parse failure — returns null → lastError 'parse_failure'", async () => {
185
- seedState(tmpRoot, { checkCount: 4 });
186
-
187
- const out = await runMeter({
188
- payload: makePayload(),
189
- projectRoot: tmpRoot,
190
- _loadConfig: () => makeConfig(),
191
- _parseTranscript: async () => null,
192
- _estimateTokens: () => {
193
- throw new Error("should not estimate when parse fails");
194
- },
195
- });
196
-
197
- assert.deepEqual(out, {});
198
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
199
- assert.equal(state.checkCount, 5);
200
- assert.equal(state.lastError.code, "parse_failure");
201
- });
202
-
203
- test("6. estimator failure — returns null → lastError 'estimate_error', inputTokens reset", async () => {
204
- seedState(tmpRoot, { checkCount: 4, inputTokens: 99999 });
205
-
206
- const out = await runMeter({
207
- payload: makePayload(),
208
- projectRoot: tmpRoot,
209
- _loadConfig: () => makeConfig(),
210
- _parseTranscript: async () => FAKE_PARSED,
211
- _estimateTokens: () => null,
212
- });
213
-
214
- assert.deepEqual(out, {});
215
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
216
- assert.equal(state.lastError.code, "estimate_error");
217
- // Reset inputTokens to 0 on failure to avoid stale readings tripping threshold false-positives.
218
- assert.equal(state.inputTokens, 0);
219
- assert.equal(state.pct, 0);
220
- assert.equal(state.threshold, "normal");
221
- });
222
-
223
- test("7. state file corruption — overwritten with valid defaults + fresh count", async () => {
224
- const sp = stateFile(tmpRoot);
225
- fs.mkdirSync(path.dirname(sp), { recursive: true });
226
- fs.writeFileSync(sp, "not json{");
227
-
228
- const out = await runMeter({
229
- payload: makePayload(),
230
- projectRoot: tmpRoot,
231
- _loadConfig: () => makeConfig({ checkFrequency: 5 }),
232
- _parseTranscript: async () => FAKE_PARSED,
233
- _estimateTokens: () => ({ inputTokens: 100 }),
234
- });
235
-
236
- assert.deepEqual(out, {});
237
- const state = JSON.parse(fs.readFileSync(sp, "utf8"));
238
- assert.equal(state.version, 1);
239
- assert.equal(state.checkCount, 1);
240
- });
241
-
242
- test("7b. state file corruption + frequency hit — estimator called once, state valid", async () => {
243
- const sp = stateFile(tmpRoot);
244
- fs.mkdirSync(path.dirname(sp), { recursive: true });
245
- fs.writeFileSync(sp, "not json{");
246
-
247
- const out = await runMeter({
248
- payload: makePayload(),
249
- projectRoot: tmpRoot,
250
- _loadConfig: () => makeConfig({ checkFrequency: 1 }),
251
- _parseTranscript: async () => FAKE_PARSED,
252
- _estimateTokens: () => ({ inputTokens: 500 }),
253
- });
254
-
255
- assert.deepEqual(out, {});
256
- const state = JSON.parse(fs.readFileSync(sp, "utf8"));
257
- assert.equal(state.version, 1);
258
- assert.equal(state.checkCount, 1);
259
- assert.equal(state.inputTokens, 500);
260
- assert.equal(state.lastError, null);
261
- });
262
-
263
- test("8. missing transcript_path in payload — lastError 'no_transcript', counter increments", async () => {
264
- seedState(tmpRoot, { checkCount: 4 });
265
-
266
- const out = await runMeter({
267
- payload: { session_id: "x" },
268
- projectRoot: tmpRoot,
269
- _loadConfig: () => makeConfig(),
270
- _parseTranscript: async () => {
271
- throw new Error("should not parse when transcript_path missing");
272
- },
273
- _estimateTokens: () => {
274
- throw new Error("should not estimate when transcript_path missing");
275
- },
276
- });
277
-
278
- assert.deepEqual(out, {});
279
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
280
- assert.equal(state.checkCount, 5);
281
- assert.equal(state.lastError.code, "no_transcript");
282
- });
283
-
284
- test("9. atomic write — no .tmp file on disk after successful run", async () => {
285
- seedState(tmpRoot, { checkCount: 4 });
286
-
287
- await runMeter({
288
- payload: makePayload(),
289
- projectRoot: tmpRoot,
290
- _loadConfig: () => makeConfig(),
291
- _parseTranscript: async () => FAKE_PARSED,
292
- _estimateTokens: () => ({ inputTokens: 1000 }),
293
- });
294
-
295
- const tmp = stateFile(tmpRoot) + ".tmp";
296
- assert.equal(fs.existsSync(tmp), false, ".tmp file should not exist after rename");
297
- assert.equal(fs.existsSync(stateFile(tmpRoot)), true, "state file should exist");
298
- });
299
-
300
- test("10. fail-open on unexpected throw — loadConfig throws → runMeter returns {}", async () => {
301
- const out = await runMeter({
302
- payload: makePayload(),
303
- projectRoot: tmpRoot,
304
- _loadConfig: () => {
305
- throw new Error("boom");
306
- },
307
- _parseTranscript: async () => FAKE_PARSED,
308
- _estimateTokens: () => ({ inputTokens: 1 }),
309
- });
310
-
311
- assert.deepEqual(out, {});
312
- });
313
-
314
- test("10b. fail-open — parseTranscript throws synchronously → {}", async () => {
315
- seedState(tmpRoot, { checkCount: 4 });
316
- const out = await runMeter({
317
- payload: makePayload(),
318
- projectRoot: tmpRoot,
319
- _loadConfig: () => makeConfig(),
320
- _parseTranscript: () => {
321
- throw new Error("sync boom");
322
- },
323
- _estimateTokens: () => ({ inputTokens: 1 }),
324
- });
325
-
326
- assert.deepEqual(out, {});
327
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
328
- assert.equal(state.lastError.code, "parse_failure");
329
- });
330
-
331
- test("10c. fail-open — estimateTokens throws → {} + lastError='estimate_error'", async () => {
332
- seedState(tmpRoot, { checkCount: 4 });
333
- const out = await runMeter({
334
- payload: makePayload(),
335
- projectRoot: tmpRoot,
336
- _loadConfig: () => makeConfig(),
337
- _parseTranscript: async () => FAKE_PARSED,
338
- _estimateTokens: () => {
339
- throw new Error("sync boom");
340
- },
341
- });
342
-
343
- assert.deepEqual(out, {});
344
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
345
- assert.equal(state.lastError.code, "estimate_error");
346
- });
347
-
348
- test("11. log never contains message content — only categories/counts", async () => {
349
- seedState(tmpRoot, { checkCount: 4 });
350
- const secretText = "SECRET_MESSAGE_CONTENT_XYZ";
351
-
352
- await runMeter({
353
- payload: makePayload(),
354
- projectRoot: tmpRoot,
355
- _loadConfig: () => makeConfig(),
356
- _parseTranscript: async () => ({
357
- system: "",
358
- messages: [
359
- { role: "user", content: [{ type: "text", text: secretText }] },
360
- ],
361
- }),
362
- _estimateTokens: () => ({ inputTokens: 42 }),
363
- });
364
-
365
- const log = fs.readFileSync(logFile(tmpRoot), "utf8");
366
- assert.ok(!log.includes(secretText), "log must not contain message content");
367
- assert.match(log, /measure/);
368
- assert.match(log, /tokens=42/);
369
- });
370
-
371
- test("12. clock injection — timestamp uses injected clock", async () => {
372
- seedState(tmpRoot, { checkCount: 4 });
373
- const fixed = new Date("2026-04-16T18:00:00.000Z");
374
-
375
- await runMeter({
376
- payload: makePayload(),
377
- projectRoot: tmpRoot,
378
- clock: () => fixed,
379
- _loadConfig: () => makeConfig(),
380
- _parseTranscript: async () => FAKE_PARSED,
381
- _estimateTokens: () => ({ inputTokens: 1000 }),
382
- });
383
-
384
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
385
- assert.equal(state.timestamp, fixed.toISOString());
386
- });
387
-
388
- /* ── M-fix: model-aware context window (the reported regression) ───────── */
389
-
390
- test("13. Opus 4.7 @ ~36% of a 1M window stays 'normal' (regression repro)", async () => {
391
- // The exact reported symptom: ~360k tokens used on an Opus 4.7 session.
392
- // With the old hardcoded 200k window this computed 180% → premature
393
- // headless handoff at ~64% of context REMAINING. With model-aware sizing
394
- // the window is 1M, so 360k = 36% = normal, no handoff.
395
- seedState(tmpRoot, { checkCount: 4 });
396
-
397
- const out = await runMeter({
398
- payload: makePayload(),
399
- projectRoot: tmpRoot,
400
- _loadConfig: () => makeConfig(), // config still says 200k — must be overridden
401
- _parseTranscript: async () => ({ ...FAKE_PARSED, model: "claude-opus-4-7" }),
402
- _estimateTokens: () => ({ inputTokens: 360000 }),
403
- });
404
-
405
- // No handoff marker — this is the whole point of the fix.
406
- assert.deepEqual(out, {});
407
-
408
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
409
- assert.equal(state.modelWindowSize, 1_000_000, "window resolved from model, not config");
410
- assert.equal(state.pct, 36, "360k / 1M = 36%");
411
- assert.equal(state.threshold, "normal");
412
- });
413
-
414
- test("14. Opus 4.7 @ 80% of the true 1M window DOES hand off", async () => {
415
- // The handoff must still fire at the real 75% threshold against the
416
- // corrected window — we keep the guard, we just size it correctly.
417
- seedState(tmpRoot, { checkCount: 4 });
418
-
419
- const out = await runMeter({
420
- payload: makePayload(),
421
- projectRoot: tmpRoot,
422
- _loadConfig: () => makeConfig(),
423
- _parseTranscript: async () => ({ ...FAKE_PARSED, model: "claude-opus-4-7-20260115" }),
424
- _estimateTokens: () => ({ inputTokens: 800000 }), // 80% of 1M > 75%
425
- });
426
-
427
- assert.equal(out.additionalContext, "next-spawn-headless:true");
428
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
429
- assert.equal(state.modelWindowSize, 1_000_000);
430
- assert.equal(state.pct, 80);
431
- assert.equal(state.threshold, "threshold");
432
- });
433
-
434
- test("15. no model in transcript → falls back to config window (back-compat)", async () => {
435
- // Existing transcripts / stubs without a model field must behave exactly
436
- // as before: config's modelWindowSize governs.
437
- seedState(tmpRoot, { checkCount: 4 });
438
-
439
- const out = await runMeter({
440
- payload: makePayload(),
441
- projectRoot: tmpRoot,
442
- _loadConfig: () => makeConfig({ modelWindowSize: 200000 }),
443
- _parseTranscript: async () => FAKE_PARSED, // no `model` key
444
- _estimateTokens: () => ({ inputTokens: 160000 }), // 80% of 200k
445
- });
446
-
447
- assert.equal(out.additionalContext, "next-spawn-headless:true");
448
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
449
- assert.equal(state.modelWindowSize, 200000);
450
- assert.equal(state.pct, 80);
451
- });
452
-
453
- test("16. Haiku session correctly sized at 200k (not over-large 1M)", async () => {
454
- seedState(tmpRoot, { checkCount: 4 });
455
-
456
- const out = await runMeter({
457
- payload: makePayload(),
458
- projectRoot: tmpRoot,
459
- _loadConfig: () => makeConfig(),
460
- _parseTranscript: async () => ({
461
- ...FAKE_PARSED,
462
- model: "claude-haiku-4-5-20251001",
463
- }),
464
- _estimateTokens: () => ({ inputTokens: 170000 }), // 85% of 200k
465
- });
466
-
467
- assert.equal(out.additionalContext, "next-spawn-headless:true");
468
- const state = JSON.parse(fs.readFileSync(stateFile(tmpRoot), "utf8"));
469
- assert.equal(state.modelWindowSize, 200000);
470
- assert.equal(state.pct, 85);
471
- });