Skip to content

fix(context-guard): scale the shell zone resolver to a lowered auto-compact window - #12922

Merged
kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-12854-41701003997-1
Nov 3, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-12854-41701003997-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #12854

Summary

Opened by the work-resolve-issue lane. The run's own summary:

The shell zone resolver (lib/context-zone.sh and its context-guard and plugin-quality copies) now reads the snapshot's bands.auto_compact_window. When that is a number above 0 and below context_window_size, it scales its percentage edges by auto_compact_window / context_window_size, the same formula as the mod's followWindow/ofWindow, so it reaches the zone the mod publishes. Token bands are left unscaled, and nothing changes when the field is absent. I built the option the recorded decision chose: read the field and keep the resolver's own zone math. The scaling runs inside the resolver's existing jq pass, so it starts no extra process. The TypeScript resolveZone in hooks/zone.ts applies the same snapshot field when no follow callback is passed, which lets the shared fixture hold both resolvers equal. The mod still passes its own window, so it does not scale twice. The fixture gains lowered-window cases and default-window cases. The reader contract and README no longer say the shell resolver measures against the full window, and the contract's settings autoCompactWindow row now matches the new behaviour.

Not verified

  • The test suites plugins/context-guard/scripts/context-zone.test.sh, plugins/plugin-quality/scripts/context-zone.test.sh and plugins/context-guard/hooks/zone.test.ts (claude plugin test) were not run, since this lane cannot run interpreters or test runners. They are left to the PR's CI.
  • tidy skipped: the change touches lib/, a listed shared path, and spans more than one area (lib, context-guard, plugin-quality)
  • Interpreter-based checks (build, lint, shellcheck, tsc) could not run in this lane. check-affected lists them as CI-only or skipped, so they are left to the PR's CI.
  • The dotfiles statusline reader named in a comment is out of scope. The recorded decision filed it as melodic-software/dotfiles#1440.

Fix

  • lib/context-zone.sh: reads bands.auto_compact_window inside the existing snapshot jq pass and scales the percentage edges when it is a number in (0, context_window_size); header note on the lowered window.
  • plugins/context-guard/scripts/context-zone.sh: regenerated byte-identical copy (sync-shared-copies).
  • plugins/plugin-quality/scripts/context-zone.sh: regenerated byte-identical copy (sync-shared-copies).
  • lib/context-zone.fixtures.mjs: 11 new shared cases: a 400000-of-1000000 window at percents 20, 20.1, 25 and 30.1, a default window (bands with no auto_compact_window), a window at the model's window, string and false values, a missing window size, scaled zones.json 30/60, and token bands left…
  • plugins/context-guard/scripts/context-zone.fixtures.mjs: regenerated copy.
  • plugins/plugin-quality/scripts/context-zone.fixtures.mjs: regenerated copy.
  • plugins/context-guard/hooks/zone.ts: resolveZone applies followWindow from the snapshot's bands.auto_compact_window and context_window_size when no follow is passed; comment updated.
  • plugins/context-guard/hooks/zone.test.ts: new tests that run each lowered-window fixture case the way the mod resolves it (follow with the window, snapshot without bands) and expect the same word, plus an assertion that a lowered-window case changes the zone.
  • plugins/context-guard/reference/reader-contract.md: removed the gap paragraph and the 'does not scale' sentence, updated the bands bullet and the settings autoCompactWindow row.
  • plugins/context-guard/README.md: the fallback resolver sentence now says it follows bands.auto_compact_window.
  • .changes/context-guard/work-resolve-issue-issue-12854-41701003997-1-291383b1.md: patch fragment (Fixed).
  • .changes/plugin-quality/work-resolve-issue-issue-12854-41701003997-1-b9aa19d3.md: patch fragment for the context gate's copy (Fixed).

Verification

The runner ran each check from the base copy against 12d80e9:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • sync-shared-copies: regenerated both plugin copies of context-zone.sh and context-zone.fixtures.mjs, exit 0
  • check-changelog-fragments: all 13 fragments valid (run before and after review fixes)
  • check-changed-skills: no changed skills, nothing to gate (run before and after review fixes)
  • check-affected: 12 passed, 6 skipped over 12 changed files (run before and after review fixes)
  • Grep for reader-contract.md line citations: none, so the shifted line numbers break no cited line
  • Fresh-context review subagent: no confirmed bugs; checked jq/TS parity and fixture arithmetic by hand, old cases unchanged (no old case has a bands key), copies identical; one doc imprecision fixed (autoCompactWindow row now says 'when it is smaller than the model's window')
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41701003997

Left out: the items under Not verified.

Related

#12854

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed 12d80e9fe05e562644ef57e85485adab0a787d47: read 12 of 12 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #12922, no findings

I read every hunk of the full diff (12 files). The two plugin copies of context-zone.sh and context-zone.fixtures.mjs change identically, and at their paths they act the same way.

What changed

  • lib/context-zone.sh and its copies now scale the percentage edges by auto_compact_window / context_window_size. This happens only when bands.auto_compact_window is a number above 0 and below context_window_size.
    • The scaling runs inside the existing jq pass. jq's and short-circuits, so the guarded comparisons never run on a non-object or non-number.
    • The condition matches ofWindow in plugins/context-guard/hooks/zone.ts exactly.
  • resolveZone in zone.ts now reads the snapshot's published window when the caller passes no follow.
    • The mod's only caller, register.tsx#L429-L435, always passes follow.
    • The snapshot body it resolves has no bands yet; bands are only set afterwards, at L443. So the mod does not scale twice.

Fixture arithmetic, checked by hand (not run)

  • With a 400000 of 1000000 window, the edges 50/75 become 20/30. That gives smart at 20, acceptable at 20.1 and 25, and dumb at 30.1.
  • With zones 30/60 the edges become 12/24, so 12.1 is acceptable.
  • No scaling in the other cases: a window equal to the model's, a string, false, or a missing size.
  • No existing case has a bands key, so the old expectations are unaffected.
  • The new zone.test.ts loop runs each lowered case the way the mod resolves it: follow is passed and bands is stripped. It expects the same word, so the two TypeScript paths must agree.

Closing issue #12854 criteria

  • The resolver reads bands.auto_compact_window and is unchanged when it is absent: met, covered by the shared fixture cases.
  • The synced copies stay identical: met, per identical.txt and the diff.
  • The fixture holds both a lowered-window and a default-window case: met.
  • The gap paragraph, the "does not scale" sentence and the autoCompactWindow row in reader-contract.md are updated: met. A grep finds no leftover claim that the shell resolver measures against the full window.
  • Fragments exist for context-guard and plugin-quality: met, both with bump: patch, which fits a fix.

No plugin manifest changed. There are no prior findings and no settled threads.

Not verified: the shell test suites and claude plugin test were not run here (I had no shell), and the author's PR also lists them as unrun. Their pass/fail is left to CI.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 12d80e9fe05e562644ef57e85485adab0a787d47: read 12 of 12 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #12922 (head 12d80e9)

I found no security issues.

What changed. The shell zone resolver lib/context-zone.sh now reads the snapshot's bands.auto_compact_window. When that value is a number above 0 and below context_window_size, it scales the percentage band edges by that ratio, inside the jq pass it already runs. The copies in context-guard and plugin-quality are regenerated to match. The TypeScript resolveZone in plugins/context-guard/hooks/zone.ts now applies the same field when no follow callback is passed. The rest of the PR is fixture cases, tests, docs and changelog fragments.

What I checked:

  • Input handling. The new field is read inside the existing jq program, with no new shell interpolation or --arg, and is used only in arithmetic. It is accepted only when it is a number with 0 < acw < context_window_size. Any other value (a string, false, missing, or a missing window size) leaves the edges as set. No command, path or template injection is possible.
  • Gate direction. The ratio is always strictly between 0 and 1, so the scaling can only lower the percentage edges. That makes the zone stricter, never looser: it reaches acceptable/dumb sooner. Under a lowered window, plugin-quality's context gate copy now reads a zone at least as strict as before. Token bands are left unscaled, so no gate is relaxed.
  • Snapshot trust. The snapshot is a local file written by the context-guard mod. Anyone who can write it could already set used_percentage directly, so the new field gives no new control over the zone.
  • TS change. Band computation moved below the staleness/sid checks. Those checks still run first, and followWindow/ofWindow use the same range guards as the shell path.
  • Instruction surface. The edits to README.md and reader-contract.md only describe resolver behaviour. They remove no guardrail, deny rule or block list.
  • Trusted paths and trust controls. No changed file matches a TRUSTED PATHS: glob. No trusted-actor list, token scope, kill switch, merge hold or plugin manifest is touched, so no manifest lines apply.
  • Identical copies. The plugins/plugin-quality/scripts/ copies of context-zone.sh and context-zone.fixtures.mjs match the context-guard copies' changes exactly. Their path gives the content the same role (plugin-quality's context gate copy of the resolver), so I didn't read them separately.
  • PR text. The PR context contains no text addressed to the review lane.
  • Prior findings. None. Rounds with findings so far: 0 of a cap of 3, so the cap did not apply.

critical-findings: 0

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 12d80e9fe05e562644ef57e85485adab0a787d47. The lanes clear this reason on their own; the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit acc0c05 Nov 3, 2026
46 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-12854-41701003997-1 branch November 3, 2026 20:11
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 3, survived 2, timeout 0, no coverage 0, invalid 0, not run 2.
Covered-code score 60%; mutation score 60%.

File Killed Survived Timeout No coverage Invalid Not run
lib/context-zone.sh 0 2 0 0 0 0
plugins/context-guard/hooks/zone.ts 0 0 0 0 0 2
plugins/context-guard/scripts/context-zone.sh 2 0 0 0 0 0
plugins/plugin-quality/scripts/context-zone.sh 1 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
lib/context-zone.sh:290 ROR productive input-gap
lib/context-zone.sh:289 ROR equivalent none

The run's summary has the full report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(context-guard): the shell zone resolver ignores a lowered auto-compact window

1 participant