Skip to content

feat(plugins): Add an afterToolExecute hook for checks on finished tool calls - #2646

Merged
dcramer merged 5 commits into
mainfrom
feat/after-tool-execute-hook
Nov 4, 2026
Merged

dcramer merged 5 commits into
mainfrom
feat/after-tool-execute-hook

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Adds a plugin hook that runs after a tool call finishes. It lets us add deterministic rules to tool calls, such as "when the agent edits an eval, check that the eval is not overfit."

beforeToolExecute sees only the tool input, so it can't tell what bash wrote (sed -i, heredocs, git apply). afterToolExecute runs after the call and gets:

  • ctx.sandbox: the Run's sandbox, so a rule can run git diff
  • ctx.workspace: the active Workspace's repos and checkout paths, so a rule runs only on the repos it covers
  • ctx.decider.decide(...): the decision model (Jev) for one narrow choice
  • ctx.model.completeObject(...): the structured model, for judgments that need reasoning
  • ctx.decision.nudge(message): adds a <plugin-note> after the tool result, which the agent reads
  • ctx.decision.deny(reason): replaces the result with a policy refusal. The message says the action already ran.

The hook runs in the shared tool pipeline, so direct calls, executeTool, and Code Mode script calls all get it. If a hook throws, Junior logs the error and keeps the tool result as it was. The tool already ran, so a broken check must not turn the result into an error that the agent retries.

basePluginContext, withPluginHookSpan, and createSandboxCapability move from agent-hooks.ts to plugins/hook-context.ts, so the new hook phase can live in its own file.

The first rule is the eval-overfit check. It goes in junior-prod as an inline plugin after this is released: it nudges the agent when a diff under packages/junior-evals/evals/ in getsentry/junior looks overfit.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 4, 2026 5:23pm UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@sentry-junior

sentry-junior Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

check / types and test / junior unit failed here because of a break on main, not this PR: web-batch-messages.test.ts imported webActorFromEmail, which #2630 removed (TS2305). #2643 fixed it on main as e35103a2d. Rebase onto main to clear those checks. ci / required failed only because those two did.

@dcramer

dcramer commented Nov 4, 2026

Copy link
Copy Markdown
Member

rebase this, main is probably fixed?

…ol calls

Plugins can now check a tool call after it runs, with the Run's sandbox,
the active Workspace repositories, the decision model, and the structured
model. A check can add a note to the tool result or reject the result.
A before-hook cannot see what bash wrote, so file-change rules need this.
An abort during afterToolExecute made the pipeline report the call as
preempted, so a resumed agent could retry work that already ran. Stop
the checks and keep the result instead.
Document how a check limits itself to named Workspaces.
A nudge was added to the tool result content. A Code Mode script got the
structured details, so it lost the nudge, or the content text with the
nudge joined in, which breaks JSON.parse. Return nudges next to the
result and show them under the call in the codemode result.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

4 screenshot changes — 4 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Page · Desktop
Automation Page · Desktop
Changed
Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automation Run Details Light · Desktop
Automation Run Details Light · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7181332. Configure here.

@dcramer dcramer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna get this out so i can experiment with some hardcoded hooks

@dcramer
dcramer merged commit 39eecdf into main Nov 4, 2026
47 checks passed
@dcramer
dcramer deleted the feat/after-tool-execute-hook branch November 4, 2026 17:54

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 71e5d97a Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant