Repository navigation
feat(bin): trigger the 70% compaction doctrine from Claude's host-computed context telemetry - #11
Merged
Merged
Conversation
sbracewell64
force-pushed
the
fm/gsd-p4-fleet-telemetry
branch
2 times, most recently
from
July 31, 2026 03:50
2360e78 to
b9fd7fc
Compare
…, truncate percentages
… verification evidence
…ptional telemetry fields
sbracewell64
force-pushed
the
fm/gsd-p4-fleet-telemetry
branch
from
July 31, 2026 15:43
b9fd7fc to
0435c09
Compare
sbracewell64
added a commit
that referenced
this pull request
Aug 9, 2026
…puted context telemetry (#11) * feat: add real context pressure telemetry * no-mistakes(review): decouple statusline display from snapshot writes, truncate percentages * no-mistakes(document): cover secondmate charter compaction trigger in fm-brief header * no-mistakes(document): record dated Claude 2.1.219 statusLine payload verification evidence * no-mistakes(review): require only trigger percentages, name missing optional telemetry fields
sbracewell64
added a commit
that referenced
this pull request
Aug 10, 2026
…puted context telemetry (#11) * feat: add real context pressure telemetry * no-mistakes(review): decouple statusline display from snapshot writes, truncate percentages * no-mistakes(document): cover secondmate charter compaction trigger in fm-brief header * no-mistakes(document): record dated Claude 2.1.219 statusLine payload verification evidence * no-mistakes(review): require only trigger percentages, name missing optional telemetry fields
sbracewell64
added a commit
that referenced
this pull request
Aug 11, 2026
…puted context telemetry (#11) * feat: add real context pressure telemetry * no-mistakes(review): decouple statusline display from snapshot writes, truncate percentages * no-mistakes(document): cover secondmate charter compaction trigger in fm-brief header * no-mistakes(document): record dated Claude 2.1.219 statusLine payload verification evidence * no-mistakes(review): require only trigger percentages, name missing optional telemetry fields
sbracewell64
added a commit
that referenced
this pull request
Aug 11, 2026
…puted context telemetry (#11) * feat: add real context pressure telemetry * no-mistakes(review): decouple statusline display from snapshot writes, truncate percentages * no-mistakes(document): cover secondmate charter compaction trigger in fm-brief header * no-mistakes(document): record dated Claude 2.1.219 statusLine payload verification evidence * no-mistakes(review): require only trigger percentages, name missing optional telemetry fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
The developer (operating through a "firstmate" supervisor) tasked an autonomous agent with GSD Phase 4 fleet telemetry: wiring Claude Code's statusline JSON context_window payload (remaining_percentage, used_percentage, total_tokens, current_usage) into the firstmate repo so the existing "compact at ~70% context pressure" doctrine can be triggered from a real host-computed instrument rather than a worker's self-estimate. Requirements included making the compact-at-70% trigger fireable from that reading (with design latitude over whether it surfaces in the statusline display, a hook, or a crew brief advisory), plus tests and docs per repo conventions. A hard boundary was set: the change must not alter firstmate's routing, supervision, worker lifecycle, state integrity, isolation, or completion detection. The work had to be done on branch fm/gsd-p4-fleet-telemetry in an isolated worktree and validated through the no-mistakes pipeline before shipping a PR, including an in-fork mirror PR to work around CI not running on cross-fork PRs. During validation, the developer ruled that dated verification evidence be added to the docs (verified 2026-07-24 against Claude Code 2.1.219, confirming the context_window object), and after repairing a GitHub credential missing workflow scope, directed the agent to resume from pipeline head 92e7c2e and complete the push, PR, and mirror.
What Changed
bin/fm-context-statusline.sh, wired as the Claude Code statusLine command in tracked.claude/settings.json: it renders the real host-computedused/remainingcontext percentages from thecontext_windowpayload and appends aCOMPACT NOW: /compactadvisory at 70% used or higher. Only the two trigger percentages are required — missing optional fields (total_tokens,current_usage) are named in the display instead of silently darkening the instrument, and invalid payloads produce no display and clear any stale snapshot.bin/fm-spawn.shnow gives spawned Claude crewmates a git-excludedsettings.local.jsonthat runs the same script with--record, atomically writing acontext-pressure.jsonsnapshot (present fields,missing_optional_fields, derivedcompact_recommended) under the existing per-task/tmp/fm-<id>root;bin/fm-brief.shadds a "Context pressure" section to ship/scout briefs telling workers to read that snapshot at phase boundaries and/compactwhen recommended, and secondmate charters carry the same CTX-row trigger. Routing, supervision, lifecycle, and completion detection are untouched.tests/fm-context-statusline.test.sh,tests/fm-brief.test.shadditions, spawn-dispatch assertions) covering the exact-70% trigger, truncation, snapshot resilience, and the per-agent-kind brief contract, plus docs indocs/configuration.md(including dated verification of the payload contract against Claude Code 2.1.219) anddocs/scripts.md.Risk Assessment
✅ Low: The round-2 commit faithfully implements the user's ruled contract (hard-require only the two trigger percentages, visibly name missing optional fields, preserve-only-present snapshot fields) with matching docs and exact-assertion tests, and leaves all previously verified invariants — atomic writes, fail-silent handling, spawn/brief wiring, and the no-lifecycle-change boundary — intact.
Testing
Ran the four touched behavior-test files through the repo's runner (all pass), then demonstrated the feature end-to-end: real statusLine payloads through the tracked settings command produced the CTX display, the exact-70% COMPACT NOW advisory, the atomic worker snapshot JSON, and silent cleanup on malformed input; generated briefs show the compaction contract on every agent kind, and the payload field contract was independently re-confirmed in the Claude Code 2.1.219 binary.
Evidence: Statusline E2E transcript (display, 70% trigger, snapshot, malformed-input cleanup)
$ echo '{"context_window":{..."used_percentage":72.4...}}' | fm-context-statusline.sh --record /tmp/fm-evidence-demo/context-pressure.json CTX 72.4% used / 27.6% left (200k) | COMPACT NOW: /compact $ cat /tmp/fm-evidence-demo/context-pressure.json { "context_window": { "remaining_percentage": 27.6, "used_percentage": 72.4, "total_tokens": 200000, "current_usage": {...} }, "compact_at_used_percentage": 70, "compact_recommended": true } (69.99% renders 'CTX 69.9% used / 30% left (200k)' with no advisory; malformed payload prints nothing, exits 0, removes the stale snapshot)Evidence: Worker-facing brief and charter context-pressure sections
Evidence: Independent context_window contract verification against Claude Code 2.1.219 binary
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed ✅
bin/fm-context-statusline.sh:53- In clearStaleRecord, the catch branchif (error.code !== "ENOENT") return;is a no-op: both the ENOENT and non-ENOENT paths fall out of the function identically since nothing follows the if. It reads as if a non-ENOENT unlink failure is handled differently when it isn't. Simplify to an empty catch (or a comment) so the intent — best-effort unlink — is explicit.bin/fm-context-statusline.sh:85- The trigger's availability is coupled tocurrent_usage(line 85) even though onlyused_percentage/remaining_percentagedrive the display and the 70% advisory. If a future Claude Code release renames or drops that unused-for-display field, the entire telemetry line and compaction trigger silently go dark fleet-wide, and briefs forbid workers from falling back to self-estimates. The docs state this fail-dark contract deliberately and it was verified against 2.1.219, so this may be intentional — but confirm whether the display/trigger should degrade gracefully when only the two percentages are present, keeping the snapshot strict.bin/fm-context-statusline.sh:92- The snapshot writer mkdirSync-recreates the predictable world-readable path /tmp/fm-<id> and writes a temp file with a guessable name (.context-pressure.json.<pid>.tmp) via fs.writeFileSync, which follows symlinks. On a multi-user host, a local attacker who pre-creates /tmp/fm-<id> could plant a symlink at the temp path to make the user clobber an arbitrary file. This matches the repo's existing /tmp/fm-<id> convention (fm-spawn's gotmp) and content is non-sensitive telemetry written 0600, so it does not worsen the established threat model — noting the tradeoff only.🔧 Fix: require only trigger percentages, name missing optional telemetry fields
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-context-statusline.test.sh tests/fm-brief.test.sh— all 27 behavior tests pass, including exact-70% trigger, truncation, snapshot resilience, and per-agent-kind brief contractbin/fm-test-run.sh tests/fm-spawn-dispatch-profile.test.sh tests/fm-subagent-pretool-check.test.sh— all pass, including the new assertion that a spawned Claude worker's git-excluded settings.local.json wires fm-context-statusline.sh with a task-scoped --record pathManual E2E: piped realistic Claude Code statusLine payloads (42.3%, 69.99%, 72.4% used, and a malformed self-estimate shape) through the tracked.claude/settings.jsoncommand, verifying the CTX display line, the /compact advisory firing at ≥70%, the recorded context-pressure.json snapshot with compact_recommended=true, and silent stale-snapshot cleanup on invalid inputManual E2E: generated a ship brief and a secondmate charter viabin/fm-brief.shand extracted the worker-facing '# Context pressure' section and CTX-row compaction instructionRead-only re-verification of the context_window payload contract by grepping the installed Claude Code 2.1.219 binary for all four documented fields and its embedded statusline usage examples✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.