Skip to content

feat(context-guard): toast the operator once when zones.json is malformed - #12319

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-6156-41398171620-1
Nov 2, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-6156-41398171620-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #6156

Summary

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

The context-guard module now shows the person one ui.toast when zones.json fails to parse or a band shape fails validation. The toast names the file and the readBands notices (percent, token_bands) and fires once per distinct file content. Claude gets no line, and the shipped-default fallback is unchanged. This is box 1, the only box the 2026-10-13 recorded decision and the 2026-11-02 narrowing comment leave open: operator only, once per change to the file. Design choice: parseSettings now returns readBands' notices on Settings, and loadSettings, which already re-reads the file only when its mtime or size key changes, toasts there. A per-session Set of toasted texts makes the dedupe content-based, so re-saving the same text gives no second toast. The toast is gated on context_guard_toast and context_guard_hooks_enabled, like the crossing toast.

Not verified

  • context-guard.test.ts (the claude plugin test mods suite) was not executed here: the lane cannot run checked-tree code, and check-affected skipped 'validate-plugins: claude plugin test (mods)'. Left to the PR's CI.
  • TypeScript type check of register.tsx was not run in this lane; left to the PR's CI.
  • README generated options table was hand-edited to match plugin.json because scripts/sync-plugin-options-docs.py cannot run in this lane; CI's drift check confirms it.
  • tidy ai-slop pass ran as a rubric read only: detect.sh and the guarded fix flow are not among the wrappers this lane's Bash may run. README line 440 is in a generated region and was not audited.
  • Review note left as is: a zones.json holding only an unknown key (for example $schema) draws a 'percent' notice from readBands (zone.ts:53), so it would toast; this matches the resolver's documented behavior and the shell resolver's stderr notice.

Fix

  • plugins/context-guard/hooks/register.tsx: Settings carries readBands' notices; loadSettings toasts <path>: shipped defaults replace malformed <notices> · /context-guard:setup check once per distinct malformed text (new State fields zonesToast, zonesToasted)
  • plugins/context-guard/hooks/context-guard.test.ts: new 'Malformed zones.json' section with five tests: an unparsable file, a band shape that fails validation (each with the fallback to shipped edges), same text versus a new malformed edit, a valid file (no zones toast, its own edges apply), and cont
  • plugins/context-guard/README.md: Configuration notes the malformed-file toast beside the /context-guard:setup check report; the context_guard_toast rows in the options table and the generated options reference now cover it
  • plugins/context-guard/.claude-plugin/plugin.json: context_guard_toast description also covers the malformed zones.json toast (kept identical to the README's generated table)
  • .changes/context-guard/work-resolve-issue-issue-6156-41398171620-1-8f9b1cde.md: minor changelog fragment for the new toast

Verification

The runner ran each check from the base copy against 5912919:

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

The run reports:

  • .lane/checks/bin/check-changelog-fragments: all 4 fragments valid (run before and after tidy and review fixes)
  • .lane/checks/bin/check-changed-skills: no changed skills, nothing to gate
  • .lane/checks/bin/check-affected: 11 passed, 7 skipped (typos not installed; validate-plugins steps that run checked-tree code, including claude plugin test (mods), are left to CI), over 5 changed files
  • fresh-context review subagent over the whole diff: no confirmed bugs; every existing zonesFile call raises no readBands notice, so no existing w.toasts assertion changes; applied its wording suggestion (the toast says only the malformed shapes fall back) and its test-strength suggestion (the valid-f
  • code-tidying:tidy-diff over the 13 changed hunks: no code edits; README paragraph reworded by write-for-humans (split the long sentence; the shape, not the file, falls back); ai-slop rubric read found no tells
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41398171620

Left out: the items under Not verified.

Related

#6156

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

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #12319 (context-guard: one toast when zones.json is malformed)

I found no security issues.

I read every hunk of all 5 changed files. None of them matches a trusted-path glob.

What I checked:

  • The toast in register.tsx. plugins/context-guard/hooks/register.tsx now shows the person a $.ui.toast when the local ~/.claude/context-guard/zones.json is malformed.
    • The toast text is built only from the resolved file path and readBands' fixed notice names (percent, token_bands). None of the file's content is put into the toast.
    • Nothing new reaches Claude's context. The change adds no model-facing line.
    • The input is a file in the user's own home directory, so no outside party reaches this code. It also adds no token, secret, network or execution path.
  • The dedupe set. zonesToasted holds each malformed file text toasted this session. It only grows when the file's mtime or size key changes, and the user writes that file themselves, so it is not something an attacker can drive.
  • The zonesToast gate. It is cfg.enabled && cfg.toast, which is the same gate as the existing crossing toast.
  • Tests, README and changelog fragment. These carry no security surface.

Plugin manifest:

  • manifest userConfig.context_guard_toast.description: pass. Only the key's description text changed, which is in the inert set. The default: true is unchanged and the key's type is unchanged.

Instruction surface: the diff removes or softens no standing instruction.

PR context: it contains no embedded text that directs the lane.

Prior findings: none. This is round 1 of 3, and the cap did not apply.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no findings

All five changed files were read in full: the changelog fragment, plugin.json, README.md, context-guard.test.ts and register.tsx. Prior findings: none (round 0 of 3; the cap does not apply).

What changed. parseSettings now passes readBands' notices through on Settings. When the file's stat key changes, loadSettings toasts once per distinct malformed text, using a per-session Set. The toast is gated on context_guard_hooks_enabled && context_guard_toast.

Checks against the code:

  • Re-saves. Re-saving the same text moves the mtime, so loadSettings re-parses the file, but zonesToasted.has(text) stops a second toast. A new malformed text adds one toast (see register.tsx#L342-L351).
  • Concurrent refreshes. Two refreshes at once, such as the write timer and a tool.call, can both re-parse the file. Only one toasts, because the add runs synchronously before the toast.
  • Absent or unreadable file. text === null gives no notices and no toast.
  • Claude gets no line. The toast reaches only the person; nothing is added to context.
  • Fallback. The fallback to the shipped bands is unchanged, since readBands already returned DEFAULT_BANDS for each malformed shape.
  • Test expectations. These hold against zone.ts readBands as I read it; I did not run the tests:
    • { not json gives notices percent and token_bands.
    • An inverted percent pair gives percent only.
    • At 55% and 60%, the shipped 50% edge produces the acceptable crossing.
    • The valid file's 30% edge produces a crossing at 31%.
    • TOAST is defined later in the file but is already used earlier (line 643), so the new tests' use of it is safe.

Closing issue #6156 (the 2026-11-02 narrowed "Done when" list). Each item is met, and each has a test in this PR that could fail if it broke:

  • One toast naming the file and the readBands notices, with no line for Claude: met; tests at L576 and L583.
  • Once per distinct file content: met; test at L590.
  • A valid file gives no toast, and the shipped bands still apply on a malformed one: met; tests at L576, L583 and L602.
  • context_guard_toast: false suppresses the toast: met; test at L609.
  • The README notes the toast beside /context-guard:setup check: met.

Plugin manifest:

  • manifest userConfig.context_guard_toast.default: pass (unchanged; only the field's description text changed, and the README's options table matches it).
  • manifest version: pass (the repository releases from changelog fragments; the fragment's bump: minor fits a new user-visible toast).
  • manifest description: pass (no capability removed; the top-level description does not list notices at this level of detail).

Path-scoped rules. .claude/rules/mod-authoring.md matches plugins/*/hooks/**. It asks the author to follow a process and sets no criteria this diff breaks.

Not verified by this lane. I did not run the test suite, the type check or the README options-docs drift check (this lane has no shell). The PR's own claims about its checks are the author's and unconfirmed here.

Spend. None beyond normal module runs; the change touches no billing and creates no paid resource.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 5912919e2f2a39762c3359689de3858cd385b4a0.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit bcd36ec Nov 2, 2026
46 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-6156-41398171620-1 branch November 2, 2026 07:33
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

pr-merge's gate holds it on its risk score (evidence-unbound:claude-review: not bound: no-run;
  evidence-unbound:claude-security-review: not bound: no-run)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit bcd36ecb5e03a7a78a0c258bd797cd272c434d42; later checks count it verified from this comment.

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.

feat(context-guard): toast the operator once when zones.json is malformed

0 participants