Skip to content

refactor(context-guard): simplify hooks and scripts without behavior change - #15349

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14435-43011735567-1
Nov 11, 2026
Merged

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

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14435

Summary

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

Applied behavior-preserving simplifications to the context-guard hooks and scripts: post-compact-mark.sh tracks its telemetry status directly instead of a separate marker_ok flag; the status tool's JSON reuses the bands object refresh() already publishes instead of rebuilding it from a second tokenShape call; resolveZone destructures readBands once; cache-line.mjs replaces hand-rolled object guards with optional chaining; payload.sh's header comment is rewrapped where a line broke mid-sentence. hook-test-sink.sh and check-mod-load.sh are unchanged: hook-test-sink.sh is a byte-identical copy of the canonical lib/hook-test-sink.sh (a shared path outside this issue's file list), and check-mod-load.sh had no simplification that kept its output identical. A fresh-context review found that switching post-compact-mark.sh to the in-process cg::read_payload_to reader would keep trailing newlines in INPUT, which hook::emit_telemetry reads for correlation keys, so that change was reverted to keep behavior exact.

Not verified

  • Test suites (hooks/post-compact-mark.test.sh, hooks/context-guard.test.ts, hooks/zone.test.ts, scripts/cache-line.test.sh) not run here: this lane runs no interpreter or test runner; left to the PR's CI
  • ci-status green: a PR check, left to the PR's CI
  • hook-test-sink.sh not simplified: it must stay byte-identical to the canonical lib/hook-test-sink.sh, which is outside this issue's file list and under a shared path
  • check-mod-load.sh not changed: no simplification found that keeps its rows and exit codes identical
  • tidy pass 5 (ai-slop:audit fix) on the changelog fragment did not run its detector or digest guard: this lane's Bash runs only the named wrappers; the fragment's one line is the issue-mandated text, and a manual rubric read found no AI-writing tells
  • build and lint of the touched TS, MJS and shell files (tsc, biome, shellcheck) not run here beyond check-affected; left to the PR's CI
  • Untracked dotfiles at the checkout root (.bashrc, .bash_profile, .profile, .zshrc, .zprofile, .gitconfig, .ripgreprc, .mcp.json, .idea, .vscode) are sandbox artifacts, not part of this change

Fix

  • plugins/context-guard/hooks/post-compact-mark.sh: marker_ok flag removed; telemetry_status starts as "error" and is set to "ok" on a successful write and rename; comments updated to match
  • plugins/context-guard/hooks/payload.sh: header comment rewrapped where two sentences broke mid-line; no code change
  • plugins/context-guard/hooks/register.tsx: statusJson returns body.bands from refresh() instead of recomputing tokenShape and rebuilding the same object; the takeLines doc comment moved from above the Fire type to above takeLines
  • plugins/context-guard/hooks/zone.ts: resolveZone destructures readBands' bands and notices in one statement
  • plugins/context-guard/scripts/cache-line.mjs: cacheLine reads payload?.prompt_cache; wire() computes current and existing with optional chaining
  • .changes/context-guard/work-resolve-issue-issue-14435-43011735567-1-b7f70796.md: patch fragment, ### Changed, "Internal simplification, no behavior change."

Verification

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

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

The run reports:

  • check-changelog-fragments: all 11 fragments valid
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (typos not installed; validate-plugins steps that run code from the checked tree; ruff and changed-skills not applicable), the rest CI-only
  • fresh-context review subagent over the whole diff: register.tsx (byte-identical JSON, same key order and auto_compact_window condition), zone.ts, cache-line.mjs (every JSON.parse result type) and the telemetry_status change confirmed equivalent; one finding (read_payload_to keeps trailing newlines…
  • code-tidying:tidy-diff ran over the changed lines: no further edits; post-compact-mark.sh rows dropped because the file is wired as a hook command in hooks.json
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43011735567

Left out: the items under Not verified.

Related

#14435

Merge-Risk: max=MEDIUM demote=false head=abbf0a9fb94059e741d99a19cc4218eda0c52a63 rubric=8.4.2 rater=claude-opus-5-5 checker=claude-opus-5-5

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

Copy link
Copy Markdown
Contributor

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

No security issues found in this pull request.

I read every hunk of all 6 changed files. None of them matches a trusted-path glob, and none is a plugin manifest, hook registration (hooks.json), workflow or trust control. The diff deletes or softens no standing instruction.

  • plugins/context-guard/hooks/post-compact-mark.sh: the marker_ok flag is replaced by setting telemetry_status directly. The marker write, the refusal to rename onto a directory, and the exit 0 all work as before. Nothing new reaches a shell or a file path.
  • plugins/context-guard/hooks/payload.sh: the header comment is rewrapped. No code changed.
  • plugins/context-guard/hooks/register.tsx: statusJson now returns body.bands. refresh() builds that object from the mod's own settings (register.tsx L452-L457). It does not come from outside input, and it is only written into the status tool's JSON. The other hunk moves a comment.
  • plugins/context-guard/hooks/zone.ts: readBands is destructured in one statement. The session-id check ^[A-Za-z0-9_-]+$ is unchanged.
  • plugins/context-guard/scripts/cache-line.mjs: the hand-written object checks become optional chaining. For every type JSON.parse can return, including null, it produces the same pc, current and existing values as before.
  • .changes/...md: a changelog fragment only.

The PR context file has no embedded text telling the lane to pass the PR, skip a check, drop a finding or post elsewhere.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15349 (context-guard simplification, closes #14435)

No findings. I read every hunk of all 6 changed files and checked each change against the unchanged code it relies on.

Is behavior unchanged? Each change was checked for equivalence:

  • plugins/context-guard/hooks/post-compact-mark.sh: telemetry_status starts as "error" and becomes "ok" only once the write and the mv both succeed. That gives the same result as the old marker_ok path. Nothing else sets the variable before the hook::emit_telemetry call. post-compact-mark.test.sh:136 still checks the error path.
  • plugins/context-guard/hooks/register.tsx: statusJson now returns body.bands. refresh() (register.tsx#L452-L461) builds that object from the same settings.bands and the same tokenShape(body.context_window, body.cli_version, settings.bands) call, with the same key order. The old code added auto_compact_window only when body.bands.auto_compact_window was defined; refresh adds it only when follows is true. Either way the key is missing from the JSON when it has no value, because JSON.stringify drops undefined values. Moving the takeLines doc comment puts it back on its own function.
  • plugins/context-guard/hooks/zone.ts: the destructure is a rename only. read was read.bands before, and notices is unchanged.
  • plugins/context-guard/scripts/cache-line.mjs: for every value JSON.parse can return (null, primitive, array, object), payload?.prompt_cache and typeof settings?.statusLine === "object" / typeof current?.command give the same results as the old guards. typeof null === "object" still sends a null statusLine to null, and an array is still accepted as before.
  • plugins/context-guard/hooks/payload.sh: only comments changed. A few lines still wrap short, which is cosmetic.

Closing issue #14435 acceptance criteria:

  • Behavior unchanged: met (see above). Existing tests cover the touched paths: context-guard.test.ts checks the bands shape, including auto_compact_window, and post-compact-mark.test.sh checks the telemetry status.
  • Only listed files plus a fragment edited: met.
  • Within 400 lines / 15 files: met.
  • Fragment for context-guard with bump: patch, ### Changed, and the exact required line: met.
  • ci-status green: the author says CI will check this. I could not confirm it here.

The test runs, tsc/biome/shellcheck, and the lane's own fresh-context review described in the PR body are the author's claims; I did not verify them. I ran no tests myself, since this lane has no shell.

No plugin manifest changed. No embedded instructions were found in the PR context or prior-findings files.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head abbf0a9fb94059e741d99a19cc4218eda0c52a63, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for abbf0a9

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15349-abbf0a9fb94059e741d99a19cc4218eda0c52a63, expires on 2026-12-11.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit 3755edb Nov 11, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14435-43011735567-1 branch November 11, 2026 11:55
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

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

File Killed Survived Timeout No coverage Invalid Not run
plugins/context-guard/hooks/post-compact-mark.sh 1 1 0 0 0 0
plugins/context-guard/hooks/zone.ts 0 2 0 0 0 0
plugins/context-guard/scripts/cache-line.mjs 3 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/context-guard/hooks/post-compact-mark.sh:111 SBR productive no-assertion
plugins/context-guard/hooks/zone.ts:185 other unclassified none
plugins/context-guard/hooks/zone.ts:197 other unclassified none

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 3755edb9c6cf91c649aa1383228424aa11b7c8dd; 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.

Simplify the hooks and scripts context-guard plugin code

0 participants