@@ -61,7 +61,15 @@ import { resolveSkillWorkshopToolApproval } from "../skills/workshop/policy.js";
6161import { isPlainObject , truncateUtf16Safe } from "../utils.js" ;
6262import {
6363 adjustedParamsByToolCallId ,
64+ buildAdjustedParamsKey ,
6465 preExecutionBlockedToolCallIds ,
66+ recordStructuredReplaySafeToolCall ,
67+ structuredReplaySafeToolCallIds ,
68+ } from "./agent-tools.before-tool-call.state.js" ;
69+ export {
70+ consumeAdjustedParamsForToolCall ,
71+ consumePreExecutionBlockedToolCall ,
72+ peekAdjustedParamsForToolCall ,
6573} from "./agent-tools.before-tool-call.state.js" ;
6674import { copyChannelAgentToolMeta , getChannelAgentToolMeta } from "./channel-tools.js" ;
6775import {
@@ -352,6 +360,25 @@ export function recordAdjustedParamsForToolCall(
352360 }
353361}
354362
363+ /** Record that one concrete core-owned tool call may use structured replay classification. */
364+ export function recordStructuredReplayTrustForToolCall (
365+ toolCallId : string | undefined ,
366+ tool : AnyAgentTool ,
367+ runId ?: string ,
368+ ) : void {
369+ if ( ! toolCallId || getPluginToolMeta ( tool ) || getChannelAgentToolMeta ( tool as never ) ) {
370+ return ;
371+ }
372+ recordStructuredReplaySafeToolCall ( toolCallId , runId ) ;
373+ while ( structuredReplaySafeToolCallIds . size > MAX_TRACKED_ADJUSTED_PARAMS ) {
374+ const oldest = structuredReplaySafeToolCallIds . values ( ) . next ( ) . value ;
375+ if ( ! oldest ) {
376+ break ;
377+ }
378+ structuredReplaySafeToolCallIds . delete ( oldest ) ;
379+ }
380+ }
381+
355382/**
356383 * Returns true when an error represents an intentional before_tool_call veto.
357384 */
@@ -364,13 +391,6 @@ const loadBeforeToolCallRuntime = createLazyRuntimeSurface(
364391 ( { beforeToolCallRuntime } ) => beforeToolCallRuntime ,
365392) ;
366393
367- function buildAdjustedParamsKey ( params : { runId ?: string ; toolCallId : string } ) : string {
368- if ( params . runId && params . runId . trim ( ) ) {
369- return `${ params . runId } :${ params . toolCallId } ` ;
370- }
371- return params . toolCallId ;
372- }
373-
374394function mergeParamsWithApprovalOverrides (
375395 originalParams : unknown ,
376396 approvalParams ?: unknown ,
@@ -1538,29 +1558,6 @@ export function copyBeforeToolCallHookMarker(source: AnyAgentTool, target: AnyAg
15381558 } ) ;
15391559}
15401560
1541- /** Consume and remove hook-adjusted params for a completed tool call. */
1542- export function consumeAdjustedParamsForToolCall ( toolCallId : string , runId ?: string ) : unknown {
1543- const adjustedParamsKey = buildAdjustedParamsKey ( { runId, toolCallId } ) ;
1544- const params = adjustedParamsByToolCallId . get ( adjustedParamsKey ) ;
1545- adjustedParamsByToolCallId . delete ( adjustedParamsKey ) ;
1546- return params ;
1547- }
1548-
1549- /** Snapshot hook-adjusted params without consuming later outcome bookkeeping. */
1550- export function peekAdjustedParamsForToolCall ( toolCallId : string , runId ?: string ) : unknown {
1551- const adjustedParamsKey = buildAdjustedParamsKey ( { runId, toolCallId } ) ;
1552- const params = adjustedParamsByToolCallId . get ( adjustedParamsKey ) ;
1553- return params === undefined ? undefined : structuredClone ( params ) ;
1554- }
1555-
1556- /** Consume whether policy prevented the target tool from starting. */
1557- export function consumePreExecutionBlockedToolCall ( toolCallId : string , runId ?: string ) : boolean {
1558- const key = buildAdjustedParamsKey ( { runId, toolCallId } ) ;
1559- const blocked = preExecutionBlockedToolCallIds . has ( key ) ;
1560- preExecutionBlockedToolCallIds . delete ( key ) ;
1561- return blocked ;
1562- }
1563-
15641561function recordPreExecutionBlockedToolCall ( toolCallId ?: string , runId ?: string ) : void {
15651562 if ( ! toolCallId ) {
15661563 return ;
@@ -1584,6 +1581,7 @@ export const testing = {
15841581 buildAdjustedParamsKey,
15851582 adjustedParamsByToolCallId,
15861583 preExecutionBlockedToolCallIds,
1584+ structuredReplaySafeToolCallIds,
15871585 runBeforeToolCallHook,
15881586 mergeParamsWithApprovalOverrides,
15891587 isPlainObject,
0 commit comments