@@ -430,6 +430,22 @@ export type PluginHookBeforePromptBuildResult = {
430430 appendSystemContext ?: string ;
431431} ;
432432
433+ export const PLUGIN_PROMPT_MUTATION_RESULT_FIELDS = [
434+ "systemPrompt" ,
435+ "prependContext" ,
436+ "prependSystemContext" ,
437+ "appendSystemContext" ,
438+ ] as const satisfies readonly ( keyof PluginHookBeforePromptBuildResult ) [ ] ;
439+
440+ type MissingPluginPromptMutationResultFields = Exclude <
441+ keyof PluginHookBeforePromptBuildResult ,
442+ ( typeof PLUGIN_PROMPT_MUTATION_RESULT_FIELDS ) [ number ]
443+ > ;
444+ type AssertAllPluginPromptMutationResultFieldsListed =
445+ MissingPluginPromptMutationResultFields extends never ? true : never ;
446+ const assertAllPluginPromptMutationResultFieldsListed : AssertAllPluginPromptMutationResultFieldsListed = true ;
447+ void assertAllPluginPromptMutationResultFieldsListed ;
448+
433449// before_agent_start hook (legacy compatibility: combines both phases)
434450export type PluginHookBeforeAgentStartEvent = {
435451 prompt : string ;
@@ -440,6 +456,26 @@ export type PluginHookBeforeAgentStartEvent = {
440456export type PluginHookBeforeAgentStartResult = PluginHookBeforePromptBuildResult &
441457 PluginHookBeforeModelResolveResult ;
442458
459+ export type PluginHookBeforeAgentStartOverrideResult = Omit <
460+ PluginHookBeforeAgentStartResult ,
461+ keyof PluginHookBeforePromptBuildResult
462+ > ;
463+
464+ export const stripPromptMutationFieldsFromLegacyHookResult = (
465+ result : PluginHookBeforeAgentStartResult | void ,
466+ ) : PluginHookBeforeAgentStartOverrideResult | void => {
467+ if ( ! result || typeof result !== "object" ) {
468+ return result ;
469+ }
470+ const remaining : Partial < PluginHookBeforeAgentStartResult > = { ...result } ;
471+ for ( const field of PLUGIN_PROMPT_MUTATION_RESULT_FIELDS ) {
472+ delete remaining [ field ] ;
473+ }
474+ return Object . keys ( remaining ) . length > 0
475+ ? ( remaining as PluginHookBeforeAgentStartOverrideResult )
476+ : undefined ;
477+ } ;
478+
443479// llm_input hook
444480export type PluginHookLlmInputEvent = {
445481 runId : string ;
0 commit comments