@@ -21,6 +21,7 @@ import type { WorktreeCreationPhase, WorktreeMeta } from "../domain/model";
2121import { allocateServicePorts , isValidBranchName , isValidEnvKey } from "../domain/policies" ;
2222import type { AutoNameGenerator } from "./auto-name-service" ;
2323import {
24+ type AgentLaunchMode ,
2425 buildAgentPaneCommand ,
2526 buildDockerAgentPaneCommand ,
2627 buildDockerShellCommand ,
@@ -184,6 +185,7 @@ export class LifecycleService {
184185 initialized,
185186 worktreePath,
186187 prompt : input . prompt ,
188+ launchMode : "fresh" ,
187189 } ) ;
188190
189191 await this . reportCreateProgress ( {
@@ -218,6 +220,7 @@ export class LifecycleService {
218220 } > {
219221 try {
220222 const resolved = await this . resolveExistingWorktree ( branch ) ;
223+ const launchMode : AgentLaunchMode = resolved . meta ? "resume" : "fresh" ;
221224 const initialized = resolved . meta
222225 ? await this . refreshManagedArtifacts ( resolved )
223226 : await this . initializeUnmanagedWorktree ( resolved ) ;
@@ -233,6 +236,7 @@ export class LifecycleService {
233236 agent : initialized . meta . agent ,
234237 initialized,
235238 worktreePath : resolved . entry . path ,
239+ launchMode,
236240 } ) ;
237241
238242 await this . deps . reconciliation . reconcile ( this . deps . projectRoot ) ;
@@ -467,6 +471,7 @@ export class LifecycleService {
467471 initialized : InitializeManagedWorktreeResult ;
468472 worktreePath : string ;
469473 prompt ?: string ;
474+ launchMode : AgentLaunchMode ;
470475 } ) : Promise < void > {
471476 if ( input . profile . runtime === "docker" ) {
472477 const dockerProfile = this . requireDockerProfile ( input . profile ) ;
@@ -485,6 +490,7 @@ export class LifecycleService {
485490 initialized : input . initialized ,
486491 worktreePath : input . worktreePath ,
487492 prompt : input . prompt ,
493+ launchMode : input . launchMode ,
488494 containerName,
489495 } ) ) ;
490496 return ;
@@ -497,6 +503,7 @@ export class LifecycleService {
497503 initialized : input . initialized ,
498504 worktreePath : input . worktreePath ,
499505 prompt : input . prompt ,
506+ launchMode : input . launchMode ,
500507 } ) ) ;
501508 }
502509
@@ -507,9 +514,10 @@ export class LifecycleService {
507514 initialized : InitializeManagedWorktreeResult ;
508515 worktreePath : string ;
509516 prompt ?: string ;
517+ launchMode : AgentLaunchMode ;
510518 containerName ?: string ;
511519 } ) {
512- const systemPrompt = input . profile . systemPrompt
520+ const systemPrompt = input . launchMode === "fresh" && input . profile . systemPrompt
513521 ? expandTemplate ( input . profile . systemPrompt , input . initialized . runtimeEnv )
514522 : undefined ;
515523 const containerName = input . containerName ;
@@ -530,7 +538,8 @@ export class LifecycleService {
530538 runtimeEnvPath : input . initialized . paths . runtimeEnvPath ,
531539 yolo : input . profile . yolo === true ,
532540 systemPrompt,
533- prompt : input . prompt ,
541+ prompt : input . launchMode === "fresh" ? input . prompt : undefined ,
542+ launchMode : input . launchMode ,
534543 } ) ,
535544 shell : buildDockerShellCommand (
536545 containerName ,
@@ -544,7 +553,8 @@ export class LifecycleService {
544553 runtimeEnvPath : input . initialized . paths . runtimeEnvPath ,
545554 yolo : input . profile . yolo === true ,
546555 systemPrompt,
547- prompt : input . prompt ,
556+ prompt : input . launchMode === "fresh" ? input . prompt : undefined ,
557+ launchMode : input . launchMode ,
548558 } ) ,
549559 shell : buildManagedShellCommand ( input . initialized . paths . runtimeEnvPath ) ,
550560 } ,
0 commit comments