1+ import type { AgentInstructionOverrides } from "@t3tools/contracts" ;
12import * as DocumentText from "../../provider/DocumentText.ts" ;
23import { makeProviderTextDeltaCoalescer } from "./ProviderTextDeltaCoalescer.ts" ;
34import { claudeTaskOutputRoot , tailClaudeTaskOutput } from "./ClaudeTaskOutputTail.ts" ;
@@ -170,10 +171,7 @@ import {
170171} from "../../provider/claudeUsageLimits.ts" ;
171172import type { ManagedServerProvider } from "@t3tools/provider-core/server/snapshot" ;
172173import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment" ;
173- import {
174- T3_CODE_DEVICE_TOOL_INSTRUCTIONS_WITH_TOOL_SEARCH ,
175- T3_CODE_ORCHESTRATION_INSTRUCTIONS ,
176- } from "@t3tools/provider-core/server/orchestrationInstructions" ;
174+ import { resolveAgentInstructions } from "@t3tools/provider-core/server/orchestrationInstructions" ;
177175import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions" ;
178176import {
179177 mcpToolPresentation ,
@@ -1438,13 +1436,15 @@ To wait for a background command or Monitor you started (tests, a build), call \
14381436` ;
14391437
14401438// Native subagents start from their task, not this session's system prompt.
1441- const subagentDeviceInstructions : HookCallback = ( ) =>
1442- Promise . resolve ( {
1443- hookSpecificOutput : {
1444- hookEventName : "SubagentStart" ,
1445- additionalContext : T3_CODE_DEVICE_TOOL_INSTRUCTIONS_WITH_TOOL_SEARCH ,
1446- } ,
1447- } ) ;
1439+ const subagentDeviceInstructions =
1440+ ( instructions : string ) : HookCallback =>
1441+ ( ) =>
1442+ Promise . resolve ( {
1443+ hookSpecificOutput : {
1444+ hookEventName : "SubagentStart" ,
1445+ additionalContext : instructions ,
1446+ } ,
1447+ } ) ;
14481448
14491449export function makeClaudeQueryOptions ( input : {
14501450 readonly modelSelection : ModelSelection ;
@@ -1459,6 +1459,7 @@ export function makeClaudeQueryOptions(input: {
14591459 readonly mcpServers ?: ClaudeQueryOptions [ "mcpServers" ] ;
14601460 /** The thread's T3 MCP session holds the `device` capability. */
14611461 readonly deviceToolsAvailable ?: boolean ;
1462+ readonly instructionOverrides ?: AgentInstructionOverrides | null ;
14621463 readonly tools ?: ClaudeAgentSdkQueryTools ;
14631464 readonly allowedTools ?: ReadonlyArray < string > ;
14641465 readonly disallowedTools ?: ReadonlyArray < string > ;
@@ -1523,6 +1524,7 @@ export function makeClaudeQueryOptions(input: {
15231524 ...compactQuerySettings ,
15241525 env : { ...compactQuerySettings ?. env , ENABLE_TOOL_SEARCH : input . toolSearchOverride } ,
15251526 } as ClaudeSdkSettings ) ;
1527+ const resolvedInstructions = resolveAgentInstructions ( input . instructionOverrides ) ;
15261528 const deviceInstructions = input . mcpServers !== undefined && input . deviceToolsAvailable === true ;
15271529 const options : ClaudeAgentSdkQueryOptions = {
15281530 model : compiledSelection . apiModelId ,
@@ -1576,16 +1578,20 @@ export function makeClaudeQueryOptions(input: {
15761578 buildRuntimeInstructions ( { harness : "Claude Code" } ) +
15771579 ( input . mcpServers === undefined
15781580 ? ""
1579- : T3_CODE_ORCHESTRATION_INSTRUCTIONS +
1581+ : resolvedInstructions . orchestration +
15801582 CLAUDE_BACKGROUND_WAIT_INSTRUCTIONS +
1581- ( deviceInstructions
1582- ? `\n${ T3_CODE_DEVICE_TOOL_INSTRUCTIONS_WITH_TOOL_SEARCH } \n`
1583- : "" ) ) ,
1583+ ( deviceInstructions ? `\n${ resolvedInstructions . devicesWithToolSearch } \n` : "" ) ) ,
15841584 ...launchAppendSystemPrompt ,
15851585 ] . join ( "\n\n" ) ,
15861586 } ,
15871587 ...( deviceInstructions
1588- ? { hooks : { SubagentStart : [ { hooks : [ subagentDeviceInstructions ] } ] } }
1588+ ? {
1589+ hooks : {
1590+ SubagentStart : [
1591+ { hooks : [ subagentDeviceInstructions ( resolvedInstructions . devicesWithToolSearch ) ] } ,
1592+ ] ,
1593+ } ,
1594+ }
15891595 : { } ) ,
15901596 ...( Object . keys ( extraArgs ) . length === 0 ? { } : { extraArgs } ) ,
15911597 } ;
@@ -4542,6 +4548,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
45424548 } ) ,
45434549 openSession : Effect . fn ( "ClaudeAdapterV2.openSession" ) (
45444550 function * ( input : ProviderAdapter . ProviderAdapterV2OpenSessionInput ) {
4551+ const instructionOverrides = Option . isSome ( serverSettings )
4552+ ? ( yield * serverSettings . value . getSettings ) . agentInstructionOverrides
4553+ : null ;
45454554 const sessionScope = yield * Effect . scope ;
45464555 const now = yield * DateTime . now ;
45474556 const session = providerSession ( {
@@ -9910,6 +9919,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
99109919 launchArgSettings ,
99119920 ) ;
99129921 const queryOptions = makeClaudeQueryOptions ( {
9922+ instructionOverrides,
99139923 modelSelection : turnInput . modelSelection ,
99149924 nativeThreadId,
99159925 resume : shouldResume ,
0 commit comments