@@ -64,6 +64,7 @@ import type { submitEmbeddedAttemptPrompt } from "./attempt-prompt-submit.js";
6464type PromptPhaseInput = Parameters < typeof runEmbeddedAttemptPromptPhase > [ 0 ] ;
6565type PromptPhaseState = ReturnType < PromptPhaseInput [ "lifecycle" ] [ "readState" ] > ;
6666type AssemblyCall = {
67+ applyPromptBuildToolsAllow : ( toolsAllow : string [ ] | undefined ) => string [ ] ;
6768 setLeasedSteering : ( lease : { leaseId : string ; runIds : string [ ] } ) => void ;
6869} ;
6970type PromptPreflightCall = Parameters < typeof prepareEmbeddedAttemptPromptPreflight > [ 0 ] ;
@@ -107,6 +108,7 @@ function createFixture() {
107108 prePromptMessageCount = count ;
108109 } ) ;
109110 const setPromptCacheChangesForTurn = vi . fn ( ) ;
111+ const setCodeModeReconciliationReadAuthorized = vi . fn ( ) ;
110112 const setFinalPromptText = vi . fn ( ) ;
111113 const markBeforeAgentRunBlocked = vi . fn ( ) ;
112114 const markYieldAborted = vi . fn ( ( ) => {
@@ -119,6 +121,7 @@ function createFixture() {
119121 mocks . preparePromptAssembly . mockImplementation ( async ( input : AssemblyCall ) => {
120122 order . push ( "assembly" ) ;
121123 const lease = { leaseId : "lease-1" , runIds : [ "run-1" ] } ;
124+ input . applyPromptBuildToolsAllow ( undefined ) ;
122125 input . setLeasedSteering ( lease ) ;
123126 return {
124127 hookCtx : { } ,
@@ -237,6 +240,14 @@ function createFixture() {
237240 transport : "sse" ,
238241 uncompactedEffectiveTools : [ ] ,
239242 } ,
243+ toolPolicy : {
244+ baseline : { activeToolNames : [ "read" ] , catalogEntries : [ ] } ,
245+ effectiveTools : [ { name : "read" } ] ,
246+ uncompactedEffectiveTools : [ { name : "read" } ] ,
247+ tools : [ { name : "read" } ] ,
248+ codeModeControlsEnabled : false ,
249+ coreReadAuthorized : true ,
250+ } ,
240251 preflight : {
241252 contextEngineAssemblySucceeded : false ,
242253 contextEnginePromptAuthority : "assembled" ,
@@ -258,6 +269,7 @@ function createFixture() {
258269 setPrePromptMessageCount,
259270 setCurrentUserTimestampOverride : vi . fn ( ) ,
260271 setPromptCacheChangesForTurn,
272+ setCodeModeReconciliationReadAuthorized,
261273 setFinalPromptText,
262274 markBeforeAgentRunBlocked,
263275 markYieldAborted,
@@ -275,13 +287,21 @@ function createFixture() {
275287 setFinalPromptText,
276288 setPrePromptMessageCount,
277289 setPromptCacheChangesForTurn,
290+ setCodeModeReconciliationReadAuthorized,
278291 state,
279292 yieldState,
280293 } ;
281294}
282295
283296beforeEach ( ( ) => {
284297 vi . clearAllMocks ( ) ;
298+ mocks . applyPromptToolsAllow . mockReturnValue ( {
299+ activeToolNames : [ "read" ] ,
300+ coreReadAuthorized : true ,
301+ effectiveTools : [ { name : "read" } ] ,
302+ uncompactedEffectiveTools : [ { name : "read" } ] ,
303+ tools : [ { name : "read" } ] ,
304+ } ) ;
285305} ) ;
286306
287307describe ( "runEmbeddedAttemptPromptPhase" , ( ) => {
@@ -308,6 +328,7 @@ describe("runEmbeddedAttemptPromptPhase", () => {
308328 ] ) ;
309329 expect ( fixture . setPrePromptMessageCount ) . toHaveBeenCalledWith ( 2 ) ;
310330 expect ( fixture . setPromptCacheChangesForTurn ) . toHaveBeenCalledWith ( [ ] ) ;
331+ expect ( fixture . setCodeModeReconciliationReadAuthorized ) . toHaveBeenCalledWith ( true ) ;
311332 expect ( fixture . setFinalPromptText ) . toHaveBeenCalledWith ( "hello" ) ;
312333 expect ( mocks . preparePromptExecution ) . toHaveBeenCalledWith (
313334 expect . objectContaining ( {
@@ -335,6 +356,21 @@ describe("runEmbeddedAttemptPromptPhase", () => {
335356 expect ( mocks . releasePendingSteering ) . not . toHaveBeenCalled ( ) ;
336357 } ) ;
337358
359+ it ( "records a final prompt policy that removes core read" , async ( ) => {
360+ const fixture = createFixture ( ) ;
361+ mocks . applyPromptToolsAllow . mockReturnValueOnce ( {
362+ activeToolNames : [ ] ,
363+ coreReadAuthorized : false ,
364+ effectiveTools : [ ] ,
365+ uncompactedEffectiveTools : [ ] ,
366+ tools : [ ] ,
367+ } ) ;
368+
369+ await runEmbeddedAttemptPromptPhase ( fixture . input ) ;
370+
371+ expect ( fixture . setCodeModeReconciliationReadAuthorized ) . toHaveBeenCalledWith ( false ) ;
372+ } ) ;
373+
338374 it ( "skips before_agent_run for settled-turn finalization" , async ( ) => {
339375 const fixture = createFixture ( ) ;
340376 fixture . input . attempt . operation = "settled-tool-finalization" ;
0 commit comments