@@ -155,6 +155,8 @@ it("does not commit running state when inherited background routing cannot be re
155155
156156function makeLocalCommandHarness ( input : {
157157 readonly text : string ;
158+ readonly workspace ?: OrchestrationV2ThreadProjection [ "thread" ] [ "workspace" ] ;
159+ readonly successfulNativeTurn ?: boolean ;
158160 readonly previousNativeSession ?: boolean ;
159161 readonly previousMessages ?: ReadonlyArray < string > ;
160162 readonly logoutFailure ?: string ;
@@ -238,6 +240,7 @@ function makeLocalCommandHarness(input: {
238240 activeProviderThreadId : providerThreadId ,
239241 branch : null ,
240242 worktreePath : null ,
243+ workspace : input . workspace ,
241244 } as OrchestrationV2ThreadProjection [ "thread" ] ,
242245 runs : [
243246 ...( input . previousNativeSession
@@ -393,6 +396,17 @@ function makeLocalCommandHarness(input: {
393396 ) ,
394397 ensureThread : ( ) => Effect . succeed ( providerThread ) ,
395398 } ;
399+ const startTurn = vi . fn < ProviderAdapter . ProviderAdapterV2SessionRuntime [ "startTurn" ] > (
400+ ( ) => Effect . void ,
401+ ) ;
402+ const getTurnStartHistory = vi . fn ( ( ) =>
403+ Effect . fail (
404+ new ProjectionStore . ProjectionStoreReadError ( {
405+ threadId,
406+ cause : input . historyReadFailureAfterFallback ,
407+ } ) ,
408+ ) ,
409+ ) ;
396410 const open = vi . fn ( ( ) =>
397411 input . interruptOpen === true
398412 ? Effect . interrupt
@@ -414,7 +428,7 @@ function makeLocalCommandHarness(input: {
414428 ) ,
415429 ) ,
416430 )
417- : input . failReadsAfterRunning === true
431+ : input . failReadsAfterRunning === true || input . successfulNativeTurn === true
418432 ? Effect . succeed ( {
419433 driver : providerThread . driver ,
420434 providerSession : {
@@ -430,15 +444,30 @@ function makeLocalCommandHarness(input: {
430444 lastError : null ,
431445 } ,
432446 ensureThread : ( ) => Effect . succeed ( providerThread ) ,
447+ startTurn,
433448 } as never )
434449 : Effect . die ( "A local command must not open a native session." ) ,
435450 ) ;
436451 const startRootRun = vi . fn <
437452 ( input : RunExecutionService . RunExecutionServiceV2StartRootRunInput ) => Effect . Effect < void >
438- > ( ( ) =>
439- input . failReadsAfterRunning === true
440- ? Effect . void
441- : Effect . die ( "A local command must not start a native turn." ) ,
453+ > ( ( controls ) =>
454+ input . successfulNativeTurn === true
455+ ? controls . session . startTurn ( {
456+ appThread : controls . appThread ,
457+ threadId : controls . appThread . id ,
458+ runId : controls . run . id ,
459+ runOrdinal : controls . run . ordinal ,
460+ providerTurnOrdinal : controls . providerTurnOrdinal ,
461+ attemptId : controls . attemptId ,
462+ rootNodeId : controls . rootNode . id ,
463+ providerThread : controls . providerThread ,
464+ message : controls . message ,
465+ modelSelection : controls . modelSelection ,
466+ runtimePolicy : controls . runtimePolicy ,
467+ } )
468+ : input . failReadsAfterRunning === true
469+ ? Effect . void
470+ : Effect . die ( "A local command must not start a native turn." ) ,
442471 ) ;
443472 const failReadIfRunning = Effect . suspend ( ( ) =>
444473 input . failReadsAfterRunning === true &&
@@ -513,13 +542,7 @@ function makeLocalCommandHarness(input: {
513542 ( m . text . trim ( ) . toLowerCase ( ) !== "/compact" || m . attachments . length > 0 ) ,
514543 ) ,
515544 } ) ,
516- getTurnStartHistory : ( ) =>
517- Effect . fail (
518- new ProjectionStore . ProjectionStoreReadError ( {
519- threadId,
520- cause : input . historyReadFailureAfterFallback ,
521- } ) ,
522- ) ,
545+ getTurnStartHistory,
523546 } ) ,
524547 Layer . mock ( ProviderSessionManager . ProviderSessionManagerV2 ) ( { open } ) ,
525548 Layer . mock ( ProviderAuthService . ProviderAuthService ) ( { tryHandlePromptCommand } ) ,
@@ -531,6 +554,8 @@ function makeLocalCommandHarness(input: {
531554 ) ,
532555 ) ;
533556 return {
557+ startTurn,
558+ getTurnStartHistory,
534559 open,
535560 writeIfRunCurrent,
536561 startRootRun,
@@ -855,3 +880,50 @@ for (const previousMessages of [[], ["/compact", " /COMPACT "]]) {
855880 } ) ,
856881 ) ;
857882}
883+
884+ for ( const workspace of [ undefined , null ] ) {
885+ effectIt . effect ( `keeps ordinary project prompts raw with workspace ${ workspace } ` , ( ) =>
886+ Effect . gen ( function * ( ) {
887+ const text = "Inspect the repository" ;
888+ const harness = makeLocalCommandHarness ( { text, workspace, successfulNativeTurn : true } ) ;
889+ yield * harness . start ;
890+ expect ( harness . startTurn ) . toHaveBeenCalledOnce ( ) ;
891+ expect ( harness . startTurn . mock . calls [ 0 ] ?. [ 0 ] . message . text ) . toBe ( text ) ;
892+ expect ( harness . getTurnStartHistory ) . not . toHaveBeenCalled ( ) ;
893+ } ) ,
894+ ) ;
895+ }
896+
897+ effectIt . effect ( "delivers frozen workspace context in an ordinary native provider prompt" , ( ) =>
898+ Effect . gen ( function * ( ) {
899+ const workspace = {
900+ filePath : "/meta/all.code-workspace" ,
901+ workspaceRoot : "/meta" ,
902+ folders : [
903+ { id : "first" , name : 'Quotes " and \\ newline\n你好' , path : "/meta/é\\folder\n🚀" } ,
904+ { id : "second" , name : "Second" , path : "/external" } ,
905+ ] ,
906+ repositories : [ ] ,
907+ } ;
908+ const text = 'Inspect both repositories\n"你好"' ;
909+ const harness = makeLocalCommandHarness ( { text, workspace, successfulNativeTurn : true } ) ;
910+ yield * harness . start ;
911+ expect ( harness . startTurn ) . toHaveBeenCalledOnce ( ) ;
912+ const message = harness . startTurn . mock . calls [ 0 ] ?. [ 0 ] . message ;
913+ expect ( message ?. text ) . toContain (
914+ JSON . stringify ( workspace . folders . map ( ( { name, path } ) => ( { name, path } ) ) ) ,
915+ ) ;
916+ expect ( message ?. text ) . toContain (
917+ "Use these existing checkouts. Workspace worktrees and filesystem restore are not supported." ,
918+ ) ;
919+ expect ( message ?. text ) . toContain ( `User message:\n${ text } ` ) ;
920+ expect ( message ?. text . split ( text ) ) . toHaveLength ( 2 ) ;
921+ expect ( message ) . toEqual ( {
922+ ...harness . startRootRun . mock . calls [ 0 ] ?. [ 0 ] . message ,
923+ text : message ?. text ,
924+ } ) ;
925+ expect ( harness . projection ( ) . runs . at ( - 1 ) ?. status ) . toBe ( "running" ) ;
926+ expect ( harness . getTurnStartHistory ) . not . toHaveBeenCalled ( ) ;
927+ expect ( harness . events . some ( ( event ) => event . type === "context-handoff.updated" ) ) . toBe ( false ) ;
928+ } ) ,
929+ ) ;
0 commit comments