Skip to content

refactor(context-budget): simplify measure engine and hook code - #15176

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14434-42884705043-1
Nov 10, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14434

Summary

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

Simplified three of the five listed context-budget files without changing behavior. measure.mjs now runs the SDK snapshot through one local sdkRun helper instead of two copied import-and-snapshot blocks, reuses the existing splitCsv helper for --deny and --tools and the existing ENV_TOKEN_RE constant for --find-unstored, and folds a few redundant branches. settings-write-ask.mjs computes the live-settings decision in one short-circuit expression with the same evaluation order, so the git spawn still runs last and only for a local settings name. register.tsx resolves the draw elements once per band render. parts.tsx was reviewed and left unchanged because no simplification kept the rendered output identical, and types/index.d.ts is unchanged as the issue requires.

Not verified

  • measure.test.sh and settings-write-ask.test.sh were not run: the lane's Bash allows only the named wrappers, so no test runner or node could run here; left to the PR's CI
  • No build or lint of the touched .mjs/.tsx files beyond check-affected (which ran no JS linter for these files); left to the PR's CI
  • plugins/context-budget/hooks/parts.tsx left unchanged: the remaining candidates (for example, replacing the conditional color spread with color={undefined}) could change the props passed to the renderer
  • register.tsx: resolving draw once assumes $.ui.resolve(e) is a pure lookup; the claude-code engine types are not in the repo, so this was checked against how the Pane handler uses it rather than against the engine's source
  • tidy: passes 1-3 ran over the measure.mjs rows and found nothing more. The hooks/register.tsx and hooks/settings-write-ask.mjs rows were dropped because both are wired in hooks/hooks.json, which puts them on the GLOBAL HARD exclusion list under enforce. Pass 4 (write-for-humans) found nothing to…
  • cant-fail-scan not applicable: it scans test files and this change touches none

Fix

  • plugins/context-budget/skills/audit/scripts/measure.mjs: one local sdkRun closure replaces two copied SDK import+sdkSnapshot blocks in takeSnapshot; splitCsv reused for the deny and tools lists; ENV_TOKEN_RE reused for --find-unstored; collapsedSkillCount guards merged; sdkSnapshot destructures the…
  • plugins/context-budget/hooks/settings-write-ask.mjs: the let/if/else-if block deciding whether the target is a live settings file is now one const expression with the same short-circuit order
  • plugins/context-budget/hooks/register.tsx: the AbovePrompt band render calls $.ui.resolve(e) once and reuses the result
  • .changes/context-budget/work-resolve-issue-issue-14434-42884705043-1-999647d9.md: patch fragment created with scripts/new-changelog-fragment.sh, body '### Changed' and 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 7270bf6:

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

The run reports:

  • check-changelog-fragments: all 4 fragments under .changes/ valid (run before and after tidy)
  • check-changed-skills: plugins/context-budget/skills/audit PASS, 0 errors, 3 warnings that were already there (description length, body length, token size), none from this change
  • check-affected: 12 passed, 7 skipped, over 4 changed files
  • fresh-context review subagent over the whole diff: found no behavior change; it checked splitCsv equivalence at both call sites, that errors from import()/sdkVersionFromEntry still reach the same catch blocks with the same messages, the ternary/|| precedence and git-spawn short-circuit order in…
  • git-read diff --numstat HEAD: 25 added, 28 removed across 3 code files, plus a 7-line fragment
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42884705043

Left out: the items under Not verified.

Related

#14434

Merge-Risk: max=HIGH demote=true head=7270bf64166ed44108600ffe7a30393b17c03bce rubric=8.3.5 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 7270bf64166ed44108600ffe7a30393b17c03bce: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15176, refactor(context-budget): simplify measure engine and hook code

No security issues found. I read every hunk of all 4 changed files. None of them matches a trusted-path glob, and the diff touches no plugin manifest, workflow, trust control or standing instruction.

critical-findings: 0

What I checked

  • plugins/context-budget/hooks/settings-write-ask.mjs. This is the only security-relevant surface: a PreToolUse hook that asks for confirmation before a Write, Edit or NotebookEdit to a live settings file.
    • The new const live = userGlobal || (/^managed/i.test(name) ? MANAGED_DIRS.some(isDir) : atRoot(PROJECT_DIR) || atRoot(cwd) || (/local/i.test(name) && cwd !== '' && atRoot(localSettingsRoot(cwd)))) gives the same result as the old let/if/else if block. The ternary binds looser than ||, so the whole || chain stays the else branch.
    • The hoisted cwd and atRoot are side-effect-free: slash is a string normaliser and isDir is a comparison.
    • The git spawn in localSettingsRoot still runs last, and only for a local name.
    • No settings target the hook used to ask about is now let through (L94-L98).
    • The case-insensitive match and the opt-out env read are unchanged.
  • plugins/context-budget/skills/audit/scripts/measure.mjs.
    • splitCsv (L392-L395) matches the inline split it replaces for --deny and --tools.
    • ENV_TOKEN_RE (L68) is the same regex, and it carries the g flag that matchAll needs.
    • The sdkRun closure imports the same found.entry as the two blocks it replaces, and only when it is called, so nothing new is loaded or run.
    • The other edits (collapsedSkillCount, binaryScanPath, the destructure in sdkSnapshot) are equivalent rewrites.
  • plugins/context-budget/hooks/register.tsx. It now calls $.ui.resolve(e) once and reuses the result, so it renders the same thing; there is no security surface here.
  • .changes/...md. A changelog fragment with no executable content.

Other notes

  • The PR context has no embedded instructions aimed at the review lane.
  • No prior findings apply: this is the first review of this pull request.
  • There is no hold: nothing in this change can cause a charge.

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk in all 4 changed files. I found nothing that blocks the merge and no advisory findings. None of the changed files is on a trusted path. This is the lane's first review of this PR, so it was a full review, not blocking-only.

What I checked

  • plugins/context-budget/skills/audit/scripts/measure.mjs
    • splitCsv: it returns [] for an empty value (line 392), which matches the old args.deny ? … : [] guard. parseArgs always stores a string for a flag that takes a value, so String(value) changes nothing for --deny or --tools. The --tools call is still guarded by if (!args.tools) usageError(...) above it.
    • ENV_TOKEN_RE: the shared constant at line 68 is the same regex with the same /g flag. matchAll works on a copy of the regex, so sharing it can't leak lastIndex state between calls.
    • sdkRun: it is only defined before the found checks and is called only after found is confirmed truthy. The import() and sdkVersionFromEntry calls still run inside the same try blocks, so a failure still lands in the same degrade or fall-through path.
    • Small folds: merging the two collapsedSkillCount guards, the ternary in binaryScanPath, and destructuring the promise result directly are all equivalent to the old code.
  • plugins/context-budget/hooks/settings-write-ask.mjs: the conditional operator binds more loosely than ||, so the new expression reads userGlobal || (managed ? MANAGED_DIRS.some(isDir) : (projectDir || cwd || local-root)). That is the old branch order. The git spawn in localSettingsRoot still runs last and only for a local name. slash() (line 43) has no side effects, so computing cwd early changes nothing.
  • plugins/context-budget/hooks/register.tsx: $.ui.resolve(e) now runs once instead of twice in the same handler. The Pane handler at line 133 uses it the same way, as a lookup.
  • Changelog fragment: bump: patch, with the ### Changed body and the exact line the issue asks for.

Closing issue #14434, acceptance criteria

  • Behavior unchanged: met, based on the equivalence checks above. These are refactors, so the existing behavior tests still cover the same paths.
  • Only the listed files and a fragment were edited: met.
  • At most 400 changed lines and 15 files: met (about 50 lines, 3 code files).
  • types/index.d.ts unchanged: met.
  • Fragment shape: met.
  • ci-status green: not something I can check from here; it's for CI to show.

Verification: I read the code but ran nothing; this lane has no shell. The author's results for the test, lint and check scripts are their own claims, and I haven't verified them.

No .claude-plugin manifest changed, so the manifest checks don't apply. The PR context had no embedded instructions aimed at this lane.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 7270bf6

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-15176-7270bf64166ed44108600ffe7a30393b17c03bce, expires on 2026-12-10.

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 10, 2026
Merged via the queue into main with commit 8433090 Nov 10, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14434-42884705043-1 branch November 10, 2026 22:05
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 84330907eeae84be3fb4e18667a36ed6e071b5fd; 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, audit and types context-budget plugin code

0 participants