Skip to content

refactor(discovery): simplify the webfetch-truncation hook - #14544

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14443-42595449176-1
Nov 9, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14443

Summary

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

Simplified plugins/discovery/hooks/webfetch-truncation.mjs without changing its behavior. decide() now uses optional chaining in place of the x && x.y guards, takes the last line with pop(), and builds the context line once from two parts, so the shared start and end of the two messages appear once (the text is unchanged character for character). readStdin() restarts its idle timer with timer.refresh() instead of clearing and recreating it, and main()'s JSON.parse try/catch is on one line. Exports (decide, pageName, MAX_STDIN_BYTES, MAX_URL_CHARS), stdout and exit behavior are unchanged.

Not verified

  • node --test plugins/discovery/hooks/webfetch-truncation.test.mjs (run via webfetch-truncation.test.sh) was not executed here, since this lane runs no interpreter; left to the PR's CI
  • tidy recorded as skipped: passes 4 and 5 (the markdown passes) did not run on the changelog fragment, because the issue's acceptance criterion fixes its body text word for word
  • review nits not applied, both outside the change's scope: if (!raw) return in main() could go (JSON.parse('') throws and is caught), and the header comment's line wrap at lines 13-14 reads oddly
  • ci-status green is a PR check, left to the PR's CI

Fix

  • plugins/discovery/hooks/webfetch-truncation.mjs: optional chaining in decide(), last line via pop(), the two context messages built from one template with the differing parts picked by readOn, the stdin idle timer restarted with timer.refresh(), and a one-line try/catch around JSON.parse
  • .changes/discovery/work-resolve-issue-issue-14443-42595449176-1-80b11f40.md: new patch fragment, body ### Changed with "Internal simplification, no behavior change."

Verification

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

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

The run reports:

  • check-changelog-fragments: all 2 fragments under .changes/ valid (run after the edit and again after tidy)
  • check-changed-skills: no changed skills, nothing to gate (run twice)
  • check-affected: 12 passed, 7 skipped, none failed over the 2 changed files (run twice)
  • fresh-context review subagent: traced decide() over falsy and odd payload, tool_response and tool_input values, rebuilt both context messages character by character, and checked the timer.refresh() and post-finish timer behavior; reported no bugs and the same output for every input
  • tidy-diff over the changed hunks: pass 1 found nothing more to simplify; pass 2 found no comments in the listed lines; pass 3 kept main()'s catch { return } because fail-open is the hook's documented contract
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42595449176

Left out: the items under Not verified.

Related

#14443

Merge-Risk: max=LOW demote=false head=cb6f79e3b00f39ad1c416a28aedaeb77723ceb8d rubric=8.1.4 rater=claude-opus-5-5 checker=claude-opus-5-5

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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #14544, no security issues found

I read every hunk of both changed files. Neither matches a trusted-path glob.

plugins/discovery/hooks/webfetch-truncation.mjs. This is a behavior-preserving refactor of a PostToolUse hook that fails open.

  • decide(): payload?.tool_name !== 'WebFetch' still returns null for a null or undefined payload, the same as the old !payload || guard. response?.result and payload.tool_input?.url match the old && guards for every falsy value, and the new typeof result !== 'string' check still rejects anything that isn't a string.
  • .pop() on the result of split('\n') always gets at least one element, so it can't throw.
  • The URL in the message still goes through pageName(), which this PR doesn't change. The fetched placeholder line is still never echoed back into the model's context. Nothing new from the fetched (untrusted) text reaches the emitted additionalContext.
  • readStdin(): timer.refresh() replaces clearing and re-creating the idle timer. The MAX_STDIN_BYTES cap and its finish(null) path are unchanged.
  • main(): the JSON.parse try/catch was collapsed onto one line. It is semantically identical.
  • No hook registration, block list, permission or trust control is touched. Nothing is deleted or narrowed in any instruction surface.

.changes/discovery/...-80b11f40.md is a new changelog fragment. It contains only data and has no security surface.

No plugin manifest changed. Neither the PR context nor the prior findings contain any embedded instructions aimed at this lane. This is the lane's first review of the PR, not a blocking-only review.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of both changed files. I also read the head copy of plugins/discovery/hooks/webfetch-truncation.mjs and the part of its test file that checks this change. I ran nothing: this lane has no interpreter. The author's runs (check-changelog-fragments, check-affected, the review subagent) are the author's claims and I have not checked them.

Behavior is the same (traced by hand):

  • payload?.tool_name !== 'WebFetch' returns null for every value the old !payload || … guard returned null for. Falsy values that are not null or undefined (0, '', false) read tool_name as undefined.
  • response?.result: when response is a falsy non-string, the old code gave the value itself and the new code gives undefined. Neither is a string, so both return null.
  • split('\n').pop(): split always returns at least one element, so this is the same as lines[lines.length - 1].
  • payload.tool_input?.url: for a falsy tool_input, the old code passed 0, false or '' to pageName and the new code passes undefined. All of these fail new URL(String(raw)), so both give 'this page'.
  • I rebuilt both context messages from the template, character by character. Each matches the old string literal exactly: the read-on note branch and the truncation placeholder branch.
  • timer.refresh() in place of clear-then-recreate: the idle restart works the same way. Calling refresh after finish has run clearTimeout does nothing in Node, and a late finish(null) returns early through the finished guard, so stdout and the exit code don't change.
  • The one-line try/catch is only a formatting change.

Closing issue #14443, criterion by criterion:

  • Behavior unchanged; exports and file names kept: met, as traced above. Tests check the read-on guidance, the /discovery:read-docs mention, the this page fallback and the stdout/exit behavior (plugins/discovery/hooks/webfetch-truncation.test.mjs L91-L130). They match patterns, not the full text, so a small wording change would get past them. The template keeps the text identical, so this is noted here, not flagged.
  • Diff edits only the listed file and changelog fragments: met.
  • Within 400 lines and 15 files: met.
  • ci-status green: not checked here; that is left to the PR's CI.
  • Fragment whose body is ### Changed plus "Internal simplification, no behavior change.": met, and the bump is patch.

No plugin manifest, .claude/rules file or trusted path is touched. The prior-findings file lists nothing: this is the first review of this pull request. I found no embedded instructions in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for cb6f79e

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-14544-cb6f79e3b00f39ad1c416a28aedaeb77723ceb8d, expires on 2026-12-09.

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 9, 2026
Merged via the queue into main with commit 93ef606 Nov 9, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14443-42595449176-1 branch November 9, 2026 11:57
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

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

File Killed Survived Timeout No coverage Invalid Not run
plugins/discovery/hooks/webfetch-truncation.mjs 5 2 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/discovery/hooks/webfetch-truncation.mjs:64 UOI productive no-assertion
plugins/discovery/hooks/webfetch-truncation.mjs:87 SBR productive input-gap

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.

Simplify the webfetch-truncation.mjs discovery plugin code

0 participants