Repository navigation
fix(agent): enforce PreToolUse on parsed inputs and UserPromptSubmit on structured user messages - #179
Open
alexb-openrouter wants to merge 1 commit into
Open
fix(agent): enforce PreToolUse on parsed inputs and UserPromptSubmit on structured user messages#179alexb-openrouter wants to merge 1 commit into
alexb-openrouter wants to merge 1 commit into
Conversation
…on structured user messages
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two lifecycle-hook enforcement gaps in
ModelResult(packages/agent/src/lib/model-result.ts):PreToolUse(andPermissionRequest/PostToolUse/PostToolUseFailure) now inspectinputSchema-parsed tool arguments:runToolWithHooksandprepareToolCallForApprovalemittedPreToolUsewith rawtoolCall.arguments(e.g.{}), whileexecuteToolparsed arguments throughtool.function.inputSchema(which applies.default(),.coerce, and.transform()). APreToolUsedeny hook checking a defaulted or transformed field missed the effective value thatexecutereceived.resolveHookToolInput(tool, rawArguments)which runsz4.safeParse(tool.function.inputSchema, rawArguments)and passesparsed.datawhen it succeeds as a record, falling back torawArguments ?? {}when validation fails so hooks can still inspect or repair invalid input.effectiveToolCall.arguments(includingnull), and mutated inputs continue to be re-parsed throughinputSchemabyexecuteToolandvalidatePreparedMutation.UserPromptSubmitnow supports structured content-array user messages:extractPromptAndApplieronly matched{ role: 'user', content: string }. Structured user messages such as{ role: 'user', content: [{ type: 'input_text', text: '...' }] }were skipped, allowing blockingUserPromptSubmithooks to be bypassed (or evaluated against an earlier string-content user message instead of the latest structured user message).findLatestUserMessageIndexandextractPromptAndApplierto target the latest user message regardless of whethercontentis a string or a content array, extracting allinput_text/textblocks joined with'\n'(or''for non-text-only arrays so blocking hooks still fire).promptCacheBreakpoint), drop subsequent text blocks so unmutated text does not remain, preserve non-text blocks (input_image,input_file, etc.), or append aninput_textblock when none existed.Verification
packages/agent/tests/unit/model-result-hooks.test.tscoveringinputSchemadefaults/transforms/mutations on both direct and approval-gate paths, and structured content-array rejection, latest-message targeting, multimodal mutation, and non-text-only arrays forUserPromptSubmit.pnpm lint,pnpm typecheck, andpnpm testacross all packages.