@tekyzinc/gsd-t 2.74.12 → 2.76.10
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.
- package/CHANGELOG.md +130 -0
- package/README.md +71 -1
- package/bin/advisor-integration.js +93 -0
- package/bin/check-headless-sessions.js +140 -0
- package/bin/context-meter-config.cjs +101 -0
- package/bin/context-meter-config.test.cjs +101 -0
- package/bin/gsd-t.js +710 -16
- package/bin/headless-auto-spawn.js +290 -0
- package/bin/model-selector.js +224 -0
- package/bin/runway-estimator.js +242 -0
- package/bin/token-budget.js +96 -89
- package/bin/token-optimizer.js +471 -0
- package/bin/token-telemetry.js +246 -0
- package/commands/gsd-t-audit.md +3 -3
- package/commands/gsd-t-backlog-list.md +38 -0
- package/commands/gsd-t-brainstorm.md +3 -3
- package/commands/gsd-t-complete-milestone.md +24 -0
- package/commands/gsd-t-debug.md +124 -7
- package/commands/gsd-t-discuss.md +10 -3
- package/commands/gsd-t-doc-ripple.md +32 -4
- package/commands/gsd-t-execute.md +107 -52
- package/commands/gsd-t-help.md +19 -0
- package/commands/gsd-t-integrate.md +67 -4
- package/commands/gsd-t-optimization-apply.md +91 -0
- package/commands/gsd-t-optimization-reject.md +94 -0
- package/commands/gsd-t-partition.md +7 -0
- package/commands/gsd-t-pause.md +3 -0
- package/commands/gsd-t-plan.md +10 -3
- package/commands/gsd-t-prd.md +3 -3
- package/commands/gsd-t-quick.md +71 -9
- package/commands/gsd-t-reflect.md +3 -7
- package/commands/gsd-t-resume.md +36 -0
- package/commands/gsd-t-status.md +31 -0
- package/commands/gsd-t-test-sync.md +7 -0
- package/commands/gsd-t-verify.md +12 -5
- package/commands/gsd-t-visualize.md +3 -7
- package/commands/gsd-t-wave.md +82 -18
- package/docs/GSD-T-README.md +52 -0
- package/docs/architecture.md +95 -0
- package/docs/infrastructure.md +117 -0
- package/docs/methodology.md +36 -0
- package/docs/prd-harness-evolution.md +51 -37
- package/docs/requirements.md +66 -0
- package/package.json +1 -1
- package/scripts/context-meter/count-tokens-client.js +221 -0
- package/scripts/context-meter/count-tokens-client.test.js +308 -0
- package/scripts/context-meter/test-injector.js +55 -0
- package/scripts/context-meter/threshold.js +88 -0
- package/scripts/context-meter/threshold.test.js +255 -0
- package/scripts/context-meter/transcript-parser.js +252 -0
- package/scripts/context-meter/transcript-parser.test.js +320 -0
- package/scripts/gsd-t-context-meter.e2e.test.js +415 -0
- package/scripts/gsd-t-context-meter.js +350 -0
- package/scripts/gsd-t-context-meter.test.js +417 -0
- package/scripts/gsd-t-heartbeat.js +2 -2
- package/scripts/gsd-t-statusline.js +23 -8
- package/templates/CLAUDE-global.md +5 -1
- package/templates/CLAUDE-project.md +26 -6
- package/templates/context-meter-config.json +10 -0
- package/templates/prompts/README.md +1 -1
- package/bin/task-counter.cjs +0 -161
package/docs/architecture.md
CHANGED
|
@@ -368,6 +368,101 @@ During partition, UI/frontend projects automatically receive `.gsd-t/contracts/d
|
|
|
368
368
|
|
|
369
369
|
When Playwright MCP is registered in Claude Code settings, QA agents get 3 minutes of interactive exploration and Red Team gets 5 minutes after all scripted tests pass. Findings are tagged `[EXPLORATORY]` in qa-issues.md and red-team-report.md, and tracked separately in QA calibration (category key: `exploratory` — does NOT count against scripted pass/fail ratio). Silent skip when Playwright MCP absent. Wired into: execute, quick, integrate, debug.
|
|
370
370
|
|
|
371
|
+
## Context Meter Architecture (M34, v2.75.10+)
|
|
372
|
+
|
|
373
|
+
The Context Meter is the authoritative source for session context-burn measurement in GSD-T. It replaces the v2.74.12 `bin/task-counter.cjs` proxy (and the pre-v2.74.12 `CLAUDE_CONTEXT_TOKENS_USED` env-var approach, which never worked because Claude Code does not export those vars).
|
|
374
|
+
|
|
375
|
+
**Data flow:**
|
|
376
|
+
|
|
377
|
+
```
|
|
378
|
+
Claude Code tool call finishes
|
|
379
|
+
│
|
|
380
|
+
▼
|
|
381
|
+
PostToolUse hook (~/.claude/settings.json registered)
|
|
382
|
+
│
|
|
383
|
+
▼
|
|
384
|
+
scripts/gsd-t-context-meter.js (runMeter)
|
|
385
|
+
│
|
|
386
|
+
├── 1. loadConfig(.gsd-t/context-meter-config.json)
|
|
387
|
+
├── 2. check-frequency gate — short-circuits if tool-call % freq != 0
|
|
388
|
+
├── 3. parseTranscript(hook.transcript_path)
|
|
389
|
+
│ → { system, messages } shaped for count_tokens
|
|
390
|
+
├── 4. countTokens({apiKey, model, system, messages, timeoutMs:200})
|
|
391
|
+
│ → POST https://api.anthropic.com/v1/messages/count_tokens
|
|
392
|
+
│ → 200 { input_tokens } | failure → null
|
|
393
|
+
├── 5. computePct(inputTokens, modelWindowSize)
|
|
394
|
+
├── 6. bandFor(pct) → "normal" | "warn" | "stop" (v3.0.0 three-band model)
|
|
395
|
+
└── 7. atomic write .gsd-t/.context-meter-state.json
|
|
396
|
+
{ version, timestamp, inputTokens, modelWindowSize, pct, threshold, checkCount, lastError? }
|
|
397
|
+
│
|
|
398
|
+
▼
|
|
399
|
+
bin/token-budget.js getSessionStatus(projectDir) ── v3.0.0: normal/warn/stop only
|
|
400
|
+
│
|
|
401
|
+
├── readContextMeterState(dir)
|
|
402
|
+
│ if fresh (timestamp within 5 min):
|
|
403
|
+
│ return { consumed, estimated_remaining, pct, threshold }
|
|
404
|
+
│ else: null
|
|
405
|
+
│
|
|
406
|
+
└── fallback: readSessionConsumed(dir) from .gsd-t/token-log.md (heuristic)
|
|
407
|
+
│
|
|
408
|
+
▼
|
|
409
|
+
bin/runway-estimator.js estimateRunway({command, domain_type, remaining_tasks})
|
|
410
|
+
│ reads current_pct from .context-meter-state.json
|
|
411
|
+
│ queries .gsd-t/token-metrics.jsonl for historical pct-delta per spawn
|
|
412
|
+
│ projects current_pct + pct_per_task × remaining_tasks × skew
|
|
413
|
+
│ confidence: high ≥50 records, medium ≥10, low <10 (+1.25× skew)
|
|
414
|
+
│ returns {can_start, projected_end_pct, confidence, recommendation}
|
|
415
|
+
▼
|
|
416
|
+
Command file Step 0 — runway gate (execute/wave/quick/integrate/debug):
|
|
417
|
+
if (!decision.can_start) {
|
|
418
|
+
print ⛔ banner
|
|
419
|
+
autoSpawnHeadless({command, continue_from: '.'}) ── bin/headless-auto-spawn.js
|
|
420
|
+
process.exit(0) ── never prompts user
|
|
421
|
+
} else {
|
|
422
|
+
proceed to Step 0.1 (Verify Context Gate Readiness) and Step 1
|
|
423
|
+
}
|
|
424
|
+
│
|
|
425
|
+
▼
|
|
426
|
+
bin/headless-auto-spawn.js (when refused)
|
|
427
|
+
│ detached child: node bin/gsd-t.js headless {command} --log
|
|
428
|
+
│ child.unref(); interactive session returns immediately
|
|
429
|
+
│ writes .gsd-t/headless-sessions/{id}.json (status: "running")
|
|
430
|
+
│ 2s poll watcher: process.kill(pid, 0) → mac osascript notification on exit
|
|
431
|
+
│
|
|
432
|
+
▼
|
|
433
|
+
Orchestrator Context Gate — v3.0.0 semantics:
|
|
434
|
+
normal → proceed
|
|
435
|
+
warn → log to .gsd-t/token-log.md, proceed at full quality (informational only)
|
|
436
|
+
stop → halt cleanly, runway estimator hands off to headless-auto-spawn
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Key constraints:**
|
|
440
|
+
- **Fail-open**: every stage catches errors and writes a partial state file. Never crashes Claude Code.
|
|
441
|
+
- **No message content in state or log files** — only token counts, band names, error codes.
|
|
442
|
+
- **Never logs or writes the API key** anywhere.
|
|
443
|
+
- **State staleness window**: 5 minutes — after that, heuristic fallback takes over.
|
|
444
|
+
- **Hook latency budget**: 200ms (timeoutMs on the HTTP call), enforced by `req.setTimeout` + `req.destroy()`.
|
|
445
|
+
|
|
446
|
+
**Contracts:**
|
|
447
|
+
- `.gsd-t/contracts/context-meter-contract.md` — schema, state file format, hook I/O
|
|
448
|
+
- `.gsd-t/contracts/context-observability-contract.md` v2.0.0 — Ctx% as the real session-wide signal (replaces Tasks-Since-Reset)
|
|
449
|
+
- `.gsd-t/contracts/token-budget-contract.md` v3.0.0 — three-band stop-at-85 (M35 clean break from v2.0.0)
|
|
450
|
+
- `.gsd-t/contracts/token-telemetry-contract.md` v1.0.0 — per-spawn 18-field JSONL at `.gsd-t/token-metrics.jsonl`
|
|
451
|
+
- `.gsd-t/contracts/runway-estimator-contract.md` v1.0.0 — pre-flight projection, confidence grading, refusal/headless handoff
|
|
452
|
+
- `.gsd-t/contracts/headless-auto-spawn-contract.md` v1.0.0 — detached continuation, session schema, macOS notification channel
|
|
453
|
+
- `.gsd-t/contracts/model-selection-contract.md` v1.0.0 — per-phase tier mapping + complexity-signal escalation, consumed by `bin/model-selector.js`
|
|
454
|
+
|
|
455
|
+
**M35 supporting components** (outside the context-meter dataflow):
|
|
456
|
+
- `bin/model-selector.js` — declarative rules table mapping phases to haiku/sonnet/opus; consulted at plan time, never at runtime under pressure
|
|
457
|
+
- `bin/token-optimizer.js` — at `complete-milestone`, scans the last 3 milestones of `.gsd-t/token-metrics.jsonl` and appends recalibration recommendations to `.gsd-t/optimization-backlog.md` (never auto-applied; user promotes via `/user:gsd-t-optimization-apply` or rejects via `/user:gsd-t-optimization-reject` with 5-milestone cooldown)
|
|
458
|
+
- `bin/check-headless-sessions.js` — renders the read-back banner on `/user:gsd-t-resume` and `/user:gsd-t-status` for completed-but-not-yet-surfaced headless sessions
|
|
459
|
+
|
|
460
|
+
**Installer integration** (`bin/gsd-t.js`):
|
|
461
|
+
- `install` / `init` — copy hook runtime, merge PostToolUse entry into `~/.claude/settings.json`, copy config template, prompt for API key (skippable, TTY-only)
|
|
462
|
+
- `doctor` — RED on missing API key, missing hook, missing script, invalid config, failed count_tokens dry-run
|
|
463
|
+
- `status` — displays `Context: {pct}% of {window} tokens ({band}) — last check {rel}` line
|
|
464
|
+
- `update-all` — one-shot task-counter retirement migration (deletes legacy files, writes `.gsd-t/.task-counter-retired-v1` marker)
|
|
465
|
+
|
|
371
466
|
## Planned Architecture Changes (M23-M24)
|
|
372
467
|
|
|
373
468
|
**M23: Headless Mode**
|
package/docs/infrastructure.md
CHANGED
|
@@ -195,6 +195,123 @@ gsd-t-verify:
|
|
|
195
195
|
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
+
## Context Meter Setup (M34, v2.75.10+)
|
|
199
|
+
|
|
200
|
+
The Context Meter is a PostToolUse hook that measures real context consumption via the Anthropic `count_tokens` API. It is **required** for the `gsd-t-execute`, `gsd-t-wave`, `gsd-t-quick`, `gsd-t-integrate`, and `gsd-t-debug` session-stop gates to work.
|
|
201
|
+
|
|
202
|
+
**API key — required**
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Shell profile (~/.zshrc, ~/.bashrc, ~/.config/fish/config.fish)
|
|
206
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
207
|
+
|
|
208
|
+
# Verify
|
|
209
|
+
echo $ANTHROPIC_API_KEY | head -c 10
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Get a key at [https://console.anthropic.com](https://console.anthropic.com). Free tier is sufficient — `count_tokens` is billed per call at negligible cost.
|
|
213
|
+
|
|
214
|
+
**CI/CD**: set `ANTHROPIC_API_KEY` as a secret (`secrets.ANTHROPIC_API_KEY` in GitHub Actions, masked variables in GitLab CI). The existing verify workflow example above already threads the secret through.
|
|
215
|
+
|
|
216
|
+
**Per-project `.env.local` (optional)**: drop `ANTHROPIC_API_KEY=sk-ant-...` into the project's ignored env file and source it in your shell profile if you need per-project keys.
|
|
217
|
+
|
|
218
|
+
**Verify with doctor**:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npx @tekyzinc/gsd-t doctor
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Expected GREEN output:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
Context Meter
|
|
228
|
+
✅ API key set (ANTHROPIC_API_KEY)
|
|
229
|
+
✅ PostToolUse hook registered in ~/.claude/settings.json
|
|
230
|
+
✅ scripts/gsd-t-context-meter.js exists
|
|
231
|
+
✅ .gsd-t/context-meter-config.json loads cleanly
|
|
232
|
+
✅ count_tokens dry-run: 7 tokens
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
If any check is RED, doctor exits with code 1.
|
|
236
|
+
|
|
237
|
+
**Config file** — `.gsd-t/context-meter-config.json`:
|
|
238
|
+
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"enabled": true,
|
|
242
|
+
"apiKeyEnvVar": "ANTHROPIC_API_KEY",
|
|
243
|
+
"modelWindowSize": 200000,
|
|
244
|
+
"thresholdPct": 85,
|
|
245
|
+
"checkFrequency": 1
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Threshold bands** (M35 v3.0.0 — three bands, lower-bound inclusive):
|
|
250
|
+
|
|
251
|
+
| Band | Range | Orchestrator action |
|
|
252
|
+
|--------|----------|----------------------------------------------------------------------------------|
|
|
253
|
+
| normal | 0–69% | Proceed |
|
|
254
|
+
| warn | 70–84% | Log warning; cue for explicit pause/resume at the next clean boundary |
|
|
255
|
+
| stop | ≥85% | Halt cleanly with resume instruction; command refuses to start if runway crosses |
|
|
256
|
+
|
|
257
|
+
**Zero silent quality degradation.** There is no `downgrade` band and no `conserve` band. Models are **never** swapped at runtime under context pressure — model choice is a plan-time decision made by `bin/model-selector.js`, and quality-critical phases (Red Team, doc-ripple, Design Verify) always run at their designated tier. See `.gsd-t/contracts/token-budget-contract.md` v3.0.0.
|
|
258
|
+
|
|
259
|
+
**Structural guarantee**: because the runway estimator refuses runs that project past 85% and the stop band fires at 85%, the runtime's 95% native compact is structurally unreachable under healthy operation. `halt_type: native-compact` in `.gsd-t/token-metrics.jsonl` is a defect signal.
|
|
260
|
+
|
|
261
|
+
**Upgrading from pre-M34**: `gsd-t update-all` runs a one-time task-counter retirement migration in every registered project (deletes `bin/task-counter.cjs`, `.gsd-t/task-counter-config.json`, `.gsd-t/.task-counter-state.json`, and the `.gsd-t/.task-counter` file; writes `.gsd-t/.task-counter-retired-v1` marker). After upgrade you **must** set `ANTHROPIC_API_KEY` — doctor will fail otherwise.
|
|
262
|
+
|
|
263
|
+
## Runway-Protected Execution (M35)
|
|
264
|
+
|
|
265
|
+
M35 adds four components on top of the Context Meter. Together they replace graduated degradation with a pre-flight gate + pause/resume model.
|
|
266
|
+
|
|
267
|
+
### Per-phase model selection — `bin/model-selector.js`
|
|
268
|
+
|
|
269
|
+
Declarative rules table mapping each phase (`plan`, `execute`, `red-team`, `doc-ripple`, `design-verify`, `qa`, `integrate`, ...) to a default tier (`haiku`|`sonnet`|`opus`). Complexity signals promoted from the task plan (`cross_module_refactor`, `security_boundary`, `data_loss_risk`, `contract_design`) escalate sonnet→opus. Each command file documents its assignments in a `## Model Assignment` block.
|
|
270
|
+
|
|
271
|
+
Contract: `.gsd-t/contracts/model-selection-contract.md` v1.0.0
|
|
272
|
+
|
|
273
|
+
### Pre-flight runway estimator — `bin/runway-estimator.js`
|
|
274
|
+
|
|
275
|
+
Reads historical per-spawn consumption from `.gsd-t/token-metrics.jsonl` via a three-tier query fallback (exact match on `{command, phase, domain}` → command+phase → command) and produces a confidence-weighted projection of end-of-run `pct`. If the projection would cross `STOP_THRESHOLD_PCT = 85`, the command refuses to start — the interactive session exits cleanly and an autonomous headless continuation is auto-spawned. The user never types `/clear`.
|
|
276
|
+
|
|
277
|
+
### Headless auto-spawn — `bin/headless-auto-spawn.js`
|
|
278
|
+
|
|
279
|
+
Detached child-process spawn (`child_process.spawn` with `detached:true`, `stdio:['ignore', fd, fd]`, `child.unref()`). Writes `.gsd-t/headless-sessions/{session-id}.json` with session metadata, polls with `process.kill(pid, 0)` liveness probe (timer `.unref()`-ed), marks `status: completed`, and posts a macOS `osascript` notification when done (graceful no-op on non-darwin). `bin/check-headless-sessions.js` renders the read-back banner on the next `gsd-t-resume` / `gsd-t-status`.
|
|
280
|
+
|
|
281
|
+
Directory: `.gsd-t/headless-sessions/` — one JSON per session, plus optional `{id}-context.json` and log files.
|
|
282
|
+
|
|
283
|
+
### Per-spawn token telemetry — `.gsd-t/token-metrics.jsonl`
|
|
284
|
+
|
|
285
|
+
Frozen 18-field JSONL schema, one record per subagent spawn. Written by the orchestrator, consumed by the runway estimator and the token optimizer.
|
|
286
|
+
|
|
287
|
+
Contract: `.gsd-t/contracts/token-telemetry-contract.md` v1.0.0
|
|
288
|
+
|
|
289
|
+
Key fields: `timestamp`, `session_id`, `command`, `phase`, `domain`, `task_id`, `model`, `complexity_signals[]`, `input_tokens`, `output_tokens`, `duration_seconds`, `start_pct`, `end_pct`, `halt_type`, `halt_reason`, `exit_code`, `run_type` (`interactive`|`headless`), `projection_variance`.
|
|
290
|
+
|
|
291
|
+
`halt_type` values: `clean`, `stop-band`, `runway-refuse`, `native-compact` (defect), `crash`.
|
|
292
|
+
|
|
293
|
+
### Optimization backlog — `.gsd-t/optimization-backlog.md`
|
|
294
|
+
|
|
295
|
+
Append-only markdown file of recalibration recommendations. `bin/token-optimizer.js` scans the last 3 milestones of telemetry at `complete-milestone` time and appends detected recommendations. Recommendations are **never** auto-applied — the user promotes via `/user:gsd-t-optimization-apply {ID}` or rejects via `/user:gsd-t-optimization-reject {ID} [--reason "..."]`. Rejected items are fingerprinted and cooled down for 5 milestones before re-surfacing.
|
|
296
|
+
|
|
297
|
+
Detection rules: `demote` (opus phase with ≥90% success, ≥3 volume), `escalate` (sonnet phase with ≥30% failure, ≥5 volume), `runway-tune` (projection vs. actual divergence >15%), `investigate` (per-phase p95 > 2× median, ≥10 volume).
|
|
298
|
+
|
|
299
|
+
## Metrics CLI — `gsd-t metrics`
|
|
300
|
+
|
|
301
|
+
Read-only surface onto the token telemetry stream. Backward-compatible with pre-M35 `metrics` output; new flags surface M35 data.
|
|
302
|
+
|
|
303
|
+
| Flag | Output |
|
|
304
|
+
|-----------------------|----------------------------------------------------------------------------------------|
|
|
305
|
+
| (no flag) | Task telemetry, process ELO, domain health (pre-M35 behavior) |
|
|
306
|
+
| `--tokens` | Per-command / per-phase token usage summary from `.gsd-t/token-metrics.jsonl` |
|
|
307
|
+
| `--halts` | Count + breakdown of `halt_type` values — flags any `native-compact` as a defect |
|
|
308
|
+
| `--context-window` | Trailing 20-run window of `end_pct` with runway headroom |
|
|
309
|
+
| `--cross-project` | Cross-project ranking (pre-M35, unchanged) |
|
|
310
|
+
|
|
311
|
+
## `/advisor` escalation convention
|
|
312
|
+
|
|
313
|
+
When a sonnet-default phase hits a complexity signal that warrants opus (e.g., cross-module refactor detected mid-execution), the command may emit an `/advisor` hook line in its output — a structured suggestion for the orchestrator to escalate the **next** spawn of that phase to opus. This is a plan-time signal, not a runtime swap: the current spawn completes at its assigned tier, and the escalation applies to subsequent work. See `.gsd-t/contracts/model-selection-contract.md` for the hook schema.
|
|
314
|
+
|
|
198
315
|
## Security Notes
|
|
199
316
|
|
|
200
317
|
- Zero npm dependencies — no supply chain risk
|
package/docs/methodology.md
CHANGED
|
@@ -83,3 +83,39 @@ Teams burn tokens fast. Use them strategically:
|
|
|
83
83
|
- Planning (always — need full cross-domain context)
|
|
84
84
|
- Integration (always — need to see all seams)
|
|
85
85
|
- The task is straightforward
|
|
86
|
+
|
|
87
|
+
## Context Awareness: From Proxy to Real Measurement (M34)
|
|
88
|
+
|
|
89
|
+
GSD-T has always needed a reliable signal for "how much of the context window is consumed right now" so the orchestrator can decide whether to continue, pause, or hand off to a headless continuation. The journey to real measurement is instructive:
|
|
90
|
+
|
|
91
|
+
1. **v1.0 era — env var check.** Early GSD-T read `CLAUDE_CONTEXT_TOKENS_USED` / `CLAUDE_CONTEXT_TOKENS_MAX` environment variables, assuming Claude Code exported them. It does not. The check was always inert — `pct` was effectively zero forever, and the stop gate never fired. The first symptom was not a crash, it was silent context exhaustion leading to mid-session compaction.
|
|
92
|
+
|
|
93
|
+
2. **v2.74.12 — task-counter proxy.** To patch the regression, `bin/task-counter.cjs` tracked the number of tasks completed since the last `/clear` and assumed a linear correspondence between task count and context percentage (e.g., 5 tasks ≈ 80%). This was better than nothing but fundamentally a proxy — it could not distinguish a task that read three files from a task that ran a full-project grep and a Playwright suite.
|
|
94
|
+
|
|
95
|
+
3. **v2.75.10 (M34) — real measurement.** The Context Meter PostToolUse hook streams the current transcript to the Anthropic `count_tokens` API after every tool call and writes the exact `input_tokens` count to `.gsd-t/.context-meter-state.json`. `bin/token-budget.js` `getSessionStatus()` reads that state file as the authoritative signal. Proxies are retired.
|
|
96
|
+
|
|
97
|
+
**Why this matters**: Opus-primary sessions compound context risk (larger system prompts, deeper reasoning, longer tool outputs). A proxy with ±20% error is fine for an undercommitted Sonnet session but causes silent compaction on a busy Opus session. Real measurement is the only durable fix.
|
|
98
|
+
|
|
99
|
+
**Fail-open principle**: the meter hook never blocks tool calls or crashes Claude Code. Every failure mode (missing API key, network error, malformed transcript, rate limit) catches and writes a partial state file with `lastError.code` set. The orchestrator treats a missing or stale state file as "fall back to heuristic" rather than "stop immediately" — the user never loses work to a meter hiccup.
|
|
100
|
+
|
|
101
|
+
## From Silent Degradation to Aggressive Pause-Resume (M35)
|
|
102
|
+
|
|
103
|
+
Between v2.74 and v2.75, GSD-T attempted to cope with context pressure through **graduated degradation** — downgrading subagent models (opus→sonnet, sonnet→haiku), checkpointing early, skipping "non-essential" phases (Red Team, doc-ripple, Design Verify). The idea was well-intentioned: burn less context, finish more work before hitting the runtime's native compact at 95%.
|
|
104
|
+
|
|
105
|
+
**It was the wrong framing.** Degradation is invisible to the user: a task that silently dropped from opus to haiku still reports "completed," and a skipped Red Team pass still looks like a green wave. Several regressions showed up where bugs made it through QA because Red Team had been silently skipped under context pressure, and where cross-module refactors made on haiku introduced subtle type errors that opus would have caught. The quality floor had become conditional on context pressure — a load-bearing invariant that the user could not see or control.
|
|
106
|
+
|
|
107
|
+
**M35 (v2.76.10) replaces graduated degradation with aggressive pause-resume.** The core principles:
|
|
108
|
+
|
|
109
|
+
1. **Quality is non-negotiable.** No phase is "non-essential." No model is downgraded under pressure. Red Team, doc-ripple, and Design Verify always run at their designated tier. If a task can't fit, the task pauses — it does not degrade.
|
|
110
|
+
|
|
111
|
+
2. **Explicit per-phase model selection.** `bin/model-selector.js` carries a declarative rules table with ≥13 phase mappings. Complexity signals (`cross_module_refactor`, `security_boundary`, `data_loss_risk`, `contract_design`) escalate sonnet→opus at plan time. Each command file carries a `## Model Assignment` block documenting its assignments. Model choice is now a plan-time decision, not a runtime pressure response.
|
|
112
|
+
|
|
113
|
+
3. **User never types `/clear`.** When the runway estimator (`bin/runway-estimator.js`) projects a run would cross 85% context, the command refuses to start — then auto-spawns a detached headless continuation via `bin/headless-auto-spawn.js`. The interactive session sees a single ⛔ banner and exits cleanly. The user gets a macOS notification when the headless run finishes and a read-back banner on the next `gsd-t-resume` or `gsd-t-status` call.
|
|
114
|
+
|
|
115
|
+
4. **Data before optimization.** Per-spawn token telemetry (`.gsd-t/token-metrics.jsonl`, 18-field frozen schema) is the raw material. The runway estimator reads historical consumption to project future runs. The token optimizer (`bin/token-optimizer.js`) runs at `complete-milestone` and appends retrospective recalibration recommendations to `.gsd-t/optimization-backlog.md`. Recommendations are **never auto-applied** — the user promotes or rejects deliberately. Tier calibration is a data-driven human decision, not a runtime heuristic.
|
|
116
|
+
|
|
117
|
+
5. **Clean break, no compat shim.** The v2.0.0 `token-budget-contract.md` defined `downgrade` and `conserve` bands with `modelOverrides` and `skipPhases` fields. v3.0.0 drops all of it. The contract is a clean three-band model (`normal` < 70%, `warn` 70–85%, `stop` ≥ 85%) and the response object is just `{band, pct, message}`. No backwards-compat translation layer — the old API is gone.
|
|
118
|
+
|
|
119
|
+
**Structural guarantee.** Because `STOP_THRESHOLD_PCT = 85` and the runway estimator refuses runs that would project past 85%, the runtime's 95% native compact is now structurally unreachable under healthy operation. `halt_type: native-compact` in `.gsd-t/token-metrics.jsonl` is a defect signal — if it appears, the estimator needs re-tuning.
|
|
120
|
+
|
|
121
|
+
**Message content is never logged**: the meter writes only token counts, band names, and error category codes. Never transcript text, never API response bodies, never the API key itself. See `docs/architecture.md` for the full data-flow diagram and `.gsd-t/contracts/context-meter-contract.md` for the schema.
|
|
@@ -299,49 +299,63 @@ Evolve GSD-T from a static methodology framework into a self-calibrating quality
|
|
|
299
299
|
|
|
300
300
|
---
|
|
301
301
|
|
|
302
|
-
### 3.7
|
|
302
|
+
### 3.7 Context Gate + Surgical Model Escalation (REWRITTEN IN M35 — v2.76.10)
|
|
303
303
|
|
|
304
|
-
**
|
|
304
|
+
**Status**: The original v2 design for this section described graduated degradation with `downgrade` and `conserve` bands that silently demoted models and skipped Red Team / doc-ripple phases under context pressure. **M35 removed that behavior entirely** (see `token-budget-contract.md` v3.0.0 and `.gsd-t/M35-definition.md`). The historical text is preserved in git history; this section documents the replacement.
|
|
305
305
|
|
|
306
|
-
|
|
306
|
+
**Problem**: Silent quality degradation is the wrong answer to context pressure. If the orchestrator is allowed to swap opus for sonnet, sonnet for haiku, or skip Red Team / doc-ripple / Design Verification when context is tight, the user silently receives lower-quality work than they asked for. GSD-T's core principle is excellent, deeply-tested results — not "best effort under pressure."
|
|
307
307
|
|
|
308
|
-
**Solution**:
|
|
308
|
+
**Solution**: Three strict components that replace the old graduated-degradation model.
|
|
309
309
|
|
|
310
310
|
**Mechanism**:
|
|
311
|
-
1. **Session budget tracking** — The orchestrator tracks cumulative tokens consumed across all subagent spawns within a session. Uses the existing observability logging data (token-log.md) plus `CLAUDE_CONTEXT_TOKENS_USED` environment variable.
|
|
312
|
-
2. **Budget estimation before spawn** — Before spawning a subagent, estimate the token cost based on: model tier (Opus ~5x Sonnet, Sonnet ~5x Haiku), task complexity (from plan-time scoring if available), and historical average from token-log.md for similar tasks.
|
|
313
|
-
3. **Graduated degradation thresholds**:
|
|
314
|
-
|
|
315
|
-
| Session Budget Consumed | Action |
|
|
316
|
-
|------------------------|--------|
|
|
317
|
-
| < 60% | Normal operation — all models at assigned tiers |
|
|
318
|
-
| 60-70% | **WARN**: Display budget alert to user. Reduce iteration budgets to minimum (2). |
|
|
319
|
-
| 70-85% | **DOWNGRADE**: Non-critical Sonnet tasks demoted to Haiku. Skip exploratory testing (3.5). Disable shadow-mode audit (3.1). |
|
|
320
|
-
| 85-95% | **CONSERVE**: Pause non-essential phases (doc-ripple, design brief generation). Checkpoint all progress to disk. |
|
|
321
|
-
| > 95% | **STOP**: Hard stop. Save all progress. Display: "Token budget nearly exhausted. Progress saved. Resume with `/gsd-t-resume` after limit resets." |
|
|
322
|
-
|
|
323
|
-
4. **Model-tier-aware budgeting** — The budget tracker understands that one Opus call ≈ 5 Sonnet calls ≈ 25 Haiku calls in token terms. Degradation actions (downgrading Sonnet → Haiku) are chosen to maximize remaining capacity for high-value tasks.
|
|
324
|
-
5. **Milestone pre-flight check** — Before starting a wave or execute run, estimate total token cost for the remaining work. If estimated cost exceeds available budget, warn the user: "This milestone has ~{N} tasks remaining, estimated at ~{X}% of daily budget. Proceed or split across sessions?"
|
|
325
|
-
6. **Integration with iteration budget (3.6)** — When budget is constrained (>60%), iteration budgets are automatically reduced. At >70%, the system prefers model escalation (Haiku → Sonnet) over additional iterations at the same tier, since one Sonnet attempt is more likely to converge than three Haiku attempts.
|
|
326
311
|
|
|
327
|
-
**
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
312
|
+
1. **Three-band context gate** (`bin/token-budget.js` v3.0.0, `token-budget-contract.md` v3.0.0):
|
|
313
|
+
|
|
314
|
+
| Session Context Consumed | Band | Action |
|
|
315
|
+
|--------------------------|------|--------|
|
|
316
|
+
| < 70% | `normal` | Proceed at full quality. |
|
|
317
|
+
| 70–85% | `warn` | Log to `.gsd-t/token-log.md` and proceed at **full quality**. **Never** downgrade models, skip Red Team, skip doc-ripple, or skip Design Verification. |
|
|
318
|
+
| ≥ 85% | `stop` | Halt cleanly. Checkpoint progress. Hand off to runway estimator / headless auto-spawn (see below). |
|
|
319
|
+
|
|
320
|
+
The bands `downgrade` and `conserve` that existed in v2.x are deleted. `applyModelOverride`, `skipPhases`, and all related machinery are deleted.
|
|
321
|
+
|
|
322
|
+
2. **Surgical per-phase model selection** (`bin/model-selector.js`, `model-selection-contract.md` v1.0.0 — m35-model-selector-advisor):
|
|
323
|
+
- Declarative phase→tier mapping: `haiku` for strictly mechanical work (test runners, file-existence checks, JSON validation, branch guards), `sonnet` for routine code work (execute step 2, test-sync, doc-ripple wiring), `opus` for high-stakes reasoning (partition, discuss, Red Team, verify judgment, debug root-cause, architecture/contract design).
|
|
324
|
+
- Sonnet is the **routine default** — opus is applied surgically at declared escalation points, not as a fallback for "important-looking" work.
|
|
325
|
+
- Dual-layer: `ANTHROPIC_MODEL=opus` for the interactive session, `model:` directive overrides per-spawn.
|
|
326
|
+
- Optional `/advisor` escalation hook at declared points; convention-based fallback if the native tool is not programmable.
|
|
327
|
+
|
|
328
|
+
3. **Runway estimator + headless auto-spawn** (`bin/runway-estimator.js`, `bin/headless-auto-spawn.js` — m35-runway-estimator, m35-headless-auto-spawn):
|
|
329
|
+
- Pre-flight: before spawning a phase or task subagent, estimate the token cost of the remaining work from `.gsd-t/token-metrics.jsonl` history. If the projected runway crosses the `stop` threshold, **refuse the run and auto-spawn a headless session** to continue the work.
|
|
330
|
+
- The user never types `/clear` under normal operation. The interactive session stays idle; the headless run consumes the fresh context window and reports results back via `.gsd-t/M35-headless-results-*.md`.
|
|
331
|
+
- The only time a user sees a `/clear` prompt is when headless auto-spawn itself fails — an explicit degradation path, not a silent one.
|
|
332
|
+
|
|
333
|
+
4. **Per-spawn telemetry** (`bin/token-telemetry.js`, `token-telemetry-contract.md` v1.0.0 — m35-token-telemetry):
|
|
334
|
+
- Every Task subagent spawn is wrapped in a token bracket that records `{timestamp, milestone, command, phase, step, domain, task, model, duration_s, input_tokens_before, input_tokens_after, tokens_consumed, context_window_pct_before, context_window_pct_after, outcome, halt_type, escalated_via_advisor}` to `.gsd-t/token-metrics.jsonl`.
|
|
335
|
+
- `gsd-t metrics --tokens [--by model,command,phase,milestone]`, `gsd-t metrics --halts`, `gsd-t metrics --context-window` surface the history.
|
|
336
|
+
- Telemetry feeds the runway estimator (historical cost-per-phase) and the optimization backlog (`bin/token-optimizer.js` → `.gsd-t/optimization-backlog.md`, detect-only — user selectively promotes via `/user:gsd-t-optimization-apply|reject`).
|
|
337
|
+
|
|
338
|
+
**Files affected (M35 active set)**:
|
|
339
|
+
- MODIFY: `bin/token-budget.js` — three-band `getDegradationActions`, `WARN_THRESHOLD_PCT = 70`, `STOP_THRESHOLD_PCT = 85`
|
|
340
|
+
- MODIFY: `.gsd-t/contracts/token-budget-contract.md` — v3.0.0 rewrite (Option X clean break, no compat shim)
|
|
341
|
+
- NEW: `bin/model-selector.js`, `bin/advisor-integration.js`, `bin/runway-estimator.js`, `bin/headless-auto-spawn.js`, `bin/token-telemetry.js`, `bin/token-optimizer.js`
|
|
342
|
+
- NEW: `.gsd-t/contracts/model-selection-contract.md`, `runway-estimator-contract.md`, `token-telemetry-contract.md`, `headless-auto-spawn-contract.md` (all v1.0.0)
|
|
343
|
+
- MODIFY: `commands/gsd-t-execute.md`, `gsd-t-wave.md`, `gsd-t-quick.md`, `gsd-t-integrate.md`, `gsd-t-debug.md`, `gsd-t-doc-ripple.md` — three-band handlers, Model Assignment blocks, per-spawn token brackets, runway estimator wires
|
|
344
|
+
- MODIFY: `templates/CLAUDE-global.md`, `templates/CLAUDE-project.md` — rewrite Token-Aware Orchestration section
|
|
334
345
|
|
|
335
346
|
**Success criteria**:
|
|
336
|
-
- [ ]
|
|
337
|
-
- [ ]
|
|
338
|
-
- [ ]
|
|
339
|
-
- [ ]
|
|
340
|
-
- [ ]
|
|
341
|
-
- [ ]
|
|
342
|
-
- [ ]
|
|
347
|
+
- [ ] Zero `downgrade`, `conserve`, `modelOverride`, `skipPhases` references in live code under `bin/`, `scripts/`, `commands/`, `templates/` (prose discussing the removal is acceptable)
|
|
348
|
+
- [ ] `bin/model-selector.js` contains ≥ 8 declarative phase mappings
|
|
349
|
+
- [ ] Runway estimator wired into ≥ 5 command files
|
|
350
|
+
- [ ] Per-spawn token telemetry captures the full 18-field schema
|
|
351
|
+
- [ ] Headless auto-spawn tested end-to-end
|
|
352
|
+
- [ ] ~1030/1030 tests green (954 baseline at M35 Wave 1 exit)
|
|
353
|
+
- [ ] M35 dogfooded itself from Wave 3 onward
|
|
354
|
+
- [ ] `v2.76.10` tagged
|
|
355
|
+
|
|
356
|
+
**Non-goals**: cost modeling (M35 tracks tokens, not dollars), auto-optimization (backlog is detect-only), model marketplace (Claude models only), runtime Claude Code patches (convention-based `/advisor` fallback if no programmable API).
|
|
343
357
|
|
|
344
|
-
**Acceptance test**: Start a wave
|
|
358
|
+
**Acceptance test**: Start a multi-wave milestone. Drive session context above 70% mid-wave. Verify: (a) the orchestrator logs a `warn` entry and proceeds at full quality with no model swaps and no phase skips; (b) when the runway estimator projects a `stop` crossing before the next phase completes, it halts cleanly and auto-spawns a headless session to continue; (c) the user never sees a `/clear` prompt unless the headless handoff itself fails; (d) `.gsd-t/token-metrics.jsonl` contains one record per spawn with the full schema.
|
|
345
359
|
|
|
346
360
|
---
|
|
347
361
|
|
|
@@ -498,7 +512,7 @@ All new code (`bin/qa-calibrator.js`, component registry logic) uses Node.js bui
|
|
|
498
512
|
| Playwright MCP not widely available | Medium | Low | Graceful degradation — feature skips if MCP absent. |
|
|
499
513
|
| Higher iteration budgets waste context tokens | Low | Medium | Budget governance (M26) caps aggregate rework. Telemetry tracks. |
|
|
500
514
|
| Command file sizes grow beyond readability | Medium | High | Each injection is max 5-10 lines. Total overhead auditable via 3.1. |
|
|
501
|
-
| **Token exhaustion mid-milestone** | **High** | **High** | **
|
|
515
|
+
| **Token exhaustion mid-milestone** | **High** | **High** | **Runway-protected execution (3.7) with pre-flight estimator + headless auto-spawn. No graduated degradation; quality never lowered under pressure. Clean stop at 85% with automatic headless continuation.** |
|
|
502
516
|
| **QA promotion to Sonnet exceeds token budget** | Low | Medium | QA calls are small relative to execute. Net impact ~10-15% more tokens. Token orchestrator manages ceiling. |
|
|
503
517
|
| **Budget estimation inaccuracy** | Medium | Medium | Estimates improve over time using historical data from token-log.md. Conservative defaults (overestimate). |
|
|
504
518
|
|
|
@@ -566,10 +580,10 @@ There are two distinct token budget concerns:
|
|
|
566
580
|
- QA model promotion (Haiku → Sonnet): +10-15% tokens per milestone
|
|
567
581
|
- Red Team model promotion (Sonnet → Opus): +3-5% tokens per milestone (only 1 call)
|
|
568
582
|
- Exploratory testing: +5-10% tokens per milestone (when MCP available)
|
|
569
|
-
- Higher iteration budgets: variable,
|
|
583
|
+
- Higher iteration budgets: variable, bounded by the M35 runway estimator (3.7) which refuses runs projected to cross 85%
|
|
570
584
|
- Harness audit: opt-in only, not counted in normal milestone budgets
|
|
571
585
|
|
|
572
|
-
**Maximum additional session cost**: ~25-30% more tokens per milestone vs. current. The
|
|
586
|
+
**Maximum additional session cost**: ~25-30% more tokens per milestone vs. current. The M35 runway estimator + headless auto-spawn (3.7) ensures this stays within daily limits through pre-flight refusal + fresh-context headless continuation — **not** through graduated degradation. When a run would exceed the budget, the interactive session hands off cleanly to a headless continuation with a fresh context window; quality is never reduced.
|
|
573
587
|
|
|
574
588
|
### Command file discipline
|
|
575
589
|
|
package/docs/requirements.md
CHANGED
|
@@ -210,6 +210,72 @@
|
|
|
210
210
|
**Orphaned requirements**: None — all M32 REQs mapped to tasks.
|
|
211
211
|
**Unanchored tasks**: None — all 3 domain tasks map directly to functional requirements.
|
|
212
212
|
|
|
213
|
+
## Requirements Traceability (updated by plan phase — M34)
|
|
214
|
+
|
|
215
|
+
| REQ-ID | Requirement Summary | Domain | Task(s) | Status |
|
|
216
|
+
|---------|------------------------------------------------------------------------------------------|-----------------------------|----------|----------|
|
|
217
|
+
| REQ-063 | Context Meter PostToolUse hook — count_tokens API call, state file, fail-open | context-meter-hook | Tasks 1–5 | complete |
|
|
218
|
+
| REQ-064 | Context Meter config schema — apiKeyEnvVar, modelWindowSize, thresholdPct, checkFrequency | context-meter-config | Tasks 1–4 | complete |
|
|
219
|
+
| REQ-065 | Installer integration — install/init hook, doctor gate, status line, update-all migration | installer-integration | Tasks 1–6 | complete |
|
|
220
|
+
| REQ-066 | bin/token-budget.js v2.0.0 — real-source `getSessionStatus()` reading the meter state file | token-budget-replacement | Tasks 1–10 | complete |
|
|
221
|
+
| REQ-067 | Command file migration — execute/wave/quick/integrate/debug use CTX_PCT, no task-counter | token-budget-replacement | Tasks 6–10 | complete |
|
|
222
|
+
| REQ-068 | Docs + tests — README/GSD-T-README/templates/docs/CHANGELOG updated, integration tests added | m34-docs-and-tests | Tasks 1–9 | in_progress |
|
|
223
|
+
|
|
224
|
+
**M34 Functional Requirements:**
|
|
225
|
+
- **REQ-063**: The PostToolUse hook must measure the real transcript token count after every tool call (subject to `checkFrequency`), write the result atomically to `.gsd-t/.context-meter-state.json`, and never crash Claude Code on error.
|
|
226
|
+
- **REQ-064**: The config loader must validate `apiKeyEnvVar` is a string, `modelWindowSize` > 0, `thresholdPct` in (0, 100), `checkFrequency` ≥ 1. Missing config = use defaults.
|
|
227
|
+
- **REQ-065**: `gsd-t doctor` must hard-gate on: API key set, hook registered, script present, config valid, live `count_tokens` dry-run succeeds. Exit code 1 if any RED.
|
|
228
|
+
- **REQ-066**: `bin/token-budget.js` `getSessionStatus()` must read `.gsd-t/.context-meter-state.json` when fresh (within 5 minutes of timestamp) and fall back to a historical heuristic otherwise. Public API shape unchanged from v1.x — callers see no breakage.
|
|
229
|
+
- **REQ-067**: No command file may reference `task-counter.cjs` or `CLAUDE_CONTEXT_TOKENS_*` env vars. All session-stop gates must call `token-budget.getSessionStatus()`.
|
|
230
|
+
- **REQ-068**: All downstream docs (README.md, docs/GSD-T-README.md, templates/CLAUDE-*, docs/*.md, CHANGELOG.md, package.json) must describe M34 by the time the milestone is marked complete.
|
|
231
|
+
|
|
232
|
+
**M34 Non-Functional Requirements:**
|
|
233
|
+
- Hook latency ≤ 200ms P99 (enforced by `req.setTimeout` + `req.destroy()` in the HTTPS client)
|
|
234
|
+
- Zero external npm dependencies (same as the rest of GSD-T)
|
|
235
|
+
- Zero message content in state files, log files, or diagnostics — only token counts, band names, error category codes
|
|
236
|
+
- Zero API-key material written to disk — env var read only, never persisted
|
|
237
|
+
|
|
238
|
+
**Orphaned requirements**: None — all M34 REQs mapped to tasks.
|
|
239
|
+
**Unanchored tasks**: None — all 34 M34 tasks map directly to functional or non-functional requirements.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Requirements Traceability (updated by plan phase — M35)
|
|
244
|
+
|
|
245
|
+
| REQ-ID | Requirement Summary | Domain | Task(s) | Status |
|
|
246
|
+
|---------|-----------------------------------------------------------------------------------------|-----------------------------|-----------|----------|
|
|
247
|
+
| REQ-069 | Silent degradation bands removed — `getDegradationActions()` returns only `{band: 'normal'\|'warn'\|'stop'}` | degradation-rip-out | T1 | complete (Wave 1) |
|
|
248
|
+
| REQ-070 | Three-band model only — `WARN_THRESHOLD_PCT=70`, `STOP_THRESHOLD_PCT=85`, no model overrides or phase skips | degradation-rip-out | T1, T2 | complete (Waves 1–2) |
|
|
249
|
+
| REQ-071 | Surgical per-phase model selection via `bin/model-selector.js` — ≥8 phase mappings, declarative rules table | model-selector-advisor | T2 | complete (Wave 2) |
|
|
250
|
+
| REQ-072 | `/advisor` escalation with graceful fallback — convention-based if API not programmable | model-selector-advisor | T1, T3 | complete (Wave 2) |
|
|
251
|
+
| REQ-073 | Pre-flight runway estimator refuses runs projected to cross 85% stop threshold | runway-estimator | T1–T5 | complete (Wave 3) |
|
|
252
|
+
| REQ-074 | Per-spawn token telemetry to `.gsd-t/token-metrics.jsonl` with frozen 18-field schema | token-telemetry | T1–T3 | complete (Waves 1–2) |
|
|
253
|
+
| REQ-075 | `gsd-t metrics` CLI: `--tokens [--by ...]`, `--halts`, `--tokens --context-window` | token-telemetry | T4–T6 | complete (Wave 2) |
|
|
254
|
+
| REQ-076 | Optimization backlog — detect only, never auto-apply, user promotes or rejects | optimization-backlog | T1–T4 | complete (Wave 4) |
|
|
255
|
+
| REQ-077 | Headless auto-spawn on runway refusal — user never sees a `/clear` prompt | headless-auto-spawn | T1–T5 | complete (Waves 3–4) |
|
|
256
|
+
| REQ-078 | Structural elimination of native compact messages — `halt_type: native-compact` count is 0 during M35 execution | runway-estimator + headless-auto-spawn | T1–T5 (RE), T1–T5 (HAS) | complete (Wave 5) |
|
|
257
|
+
|
|
258
|
+
**M35 Functional Requirements:**
|
|
259
|
+
- **REQ-069**: `bin/token-budget.js` `getDegradationActions()` must return `{band: 'normal'|'warn'|'stop', pct: number, message: string}` only. No `modelOverride`, no `skipPhases`, no `checkpoint` side-channel.
|
|
260
|
+
- **REQ-070**: `WARN_THRESHOLD_PCT = 70`, `STOP_THRESHOLD_PCT = 85`. `grep -r "downgrade\|conserve\|modelOverride\|skipPhases" bin/ commands/ docs/ templates/` returns zero hits in live code.
|
|
261
|
+
- **REQ-071**: `bin/model-selector.js` exists with a declarative rules table, at least 8 phase mappings across all three tiers (haiku/sonnet/opus), and unit tests for each mapping.
|
|
262
|
+
- **REQ-072**: `bin/advisor-integration.js` exists. If `/advisor` is programmable: calls it. If not: convention-based fallback block injection. Graceful degradation: missed escalations logged, caller never blocked.
|
|
263
|
+
- **REQ-073**: Every long-running command (execute, wave, integrate, debug, quick) invokes `estimateRunway()` at Step 0. On refusal: prints ⛔ block, calls `autoSpawnHeadless()`, exits cleanly. User never sees "run /clear."
|
|
264
|
+
- **REQ-074**: Every Task subagent spawn in execute/wave/quick/integrate/debug/doc-ripple is wrapped in a token bracket. Records appended to `.gsd-t/token-metrics.jsonl` with all 18 schema fields.
|
|
265
|
+
- **REQ-075**: `gsd-t metrics --tokens [--by <field>...]` prints an aggregated table. `gsd-t metrics --halts` shows halt_type breakdown with native-compact warning. `gsd-t metrics --tokens --context-window` buckets by pct_before.
|
|
266
|
+
- **REQ-076**: `bin/token-optimizer.js` runs at `complete-milestone`, appends to `.gsd-t/optimization-backlog.md`. Recommendations never auto-applied. User promotes via `gsd-t-optimization-apply {ID}` or rejects via `gsd-t-optimization-reject {ID}`.
|
|
267
|
+
- **REQ-077**: `bin/headless-auto-spawn.js` `autoSpawnHeadless()` spawns a detached child process, writes `.gsd-t/headless-sessions/{id}.json`, fires macOS notification on completion, and surfaces results banner on next interactive command.
|
|
268
|
+
- **REQ-078**: The combination of `STOP_THRESHOLD_PCT=85` and runway estimator refusing runs that project past 85% means the runtime's 95% native compact is structurally unreachable. `halt_type: native-compact` in `token-metrics.jsonl` is a defect signal.
|
|
269
|
+
|
|
270
|
+
**M35 Non-Functional Requirements:**
|
|
271
|
+
- Zero external npm dependencies (GSD-T mandate — token-telemetry.js, runway-estimator.js, headless-auto-spawn.js must use Node.js built-ins only)
|
|
272
|
+
- `autoSpawnHeadless()` must return control to the interactive session in < 500ms (detached spawn is immediate)
|
|
273
|
+
- `estimateRunway()` must complete in < 100ms (reads two local files, no network)
|
|
274
|
+
- Full test suite: target ~1030 tests total after M35; quality over count
|
|
275
|
+
|
|
276
|
+
**Orphaned requirements**: None — all M35 REQs mapped to tasks.
|
|
277
|
+
**Unanchored tasks**: None — all 38 M35 tasks trace to REQ-069–REQ-078 or REQ-063–068 (existing requirements that M35 code continues to satisfy).
|
|
278
|
+
|
|
213
279
|
---
|
|
214
280
|
|
|
215
281
|
## M17: Scan Visual Output — Feature Specification
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekyzinc/gsd-t",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.76.10",
|
|
4
4
|
"description": "GSD-T: Contract-Driven Development for Claude Code — 56 slash commands with headless CI/CD mode, graph-powered code analysis, real-time agent dashboard, execution intelligence, task telemetry, doc-ripple enforcement, backlog management, impact analysis, test sync, milestone archival, and PRD generation",
|
|
5
5
|
"author": "Tekyz, Inc.",
|
|
6
6
|
"license": "MIT",
|