@@ -103,6 +103,13 @@ function runDockerCommand(command: string, timeoutMs = 30000): Promise<DockerCom
103103export interface DockerRuntimeConfig {
104104 /** Docker image to use (e.g., ubuntu:22.04) */
105105 image : string ;
106+ /**
107+ * Container name for existing workspaces.
108+ * When creating a new workspace, this is computed during createWorkspace().
109+ * When recreating runtime for an existing workspace, this should be passed
110+ * to allow exec operations without calling createWorkspace again.
111+ */
112+ containerName ?: string ;
106113}
107114
108115/**
@@ -121,7 +128,7 @@ function sanitizeContainerName(name: string): string {
121128 * Generate container name from project path and workspace name.
122129 * Format: mux-{projectName}-{workspaceName}
123130 */
124- function getContainerName ( projectPath : string , workspaceName : string ) : string {
131+ export function getContainerName ( projectPath : string , workspaceName : string ) : string {
125132 const projectName = getProjectName ( projectPath ) ;
126133 return sanitizeContainerName ( `mux-${ projectName } -${ workspaceName } ` ) ;
127134}
@@ -131,9 +138,15 @@ function getContainerName(projectPath: string, workspaceName: string): string {
131138 */
132139export class DockerRuntime implements Runtime {
133140 private readonly config : DockerRuntimeConfig ;
141+ /** Container name - set during construction (for existing) or createWorkspace (for new) */
142+ private containerName ?: string ;
134143
135144 constructor ( config : DockerRuntimeConfig ) {
136145 this . config = config ;
146+ // If container name is provided (existing workspace), store it
147+ if ( config . containerName ) {
148+ this . containerName = config . containerName ;
149+ }
137150 }
138151
139152 /**
@@ -154,16 +167,17 @@ export class DockerRuntime implements Runtime {
154167 throw new RuntimeError ( "Operation aborted before execution" , "exec" ) ;
155168 }
156169
157- // Extract container name from cwd (assumes cwd is /src for workspace operations)
158- // For Docker, we need the container name which we get from the workspace context
159- // The container name is stored on the runtime instance during workspace creation
160- const containerName = ( this as DockerRuntimeWithContainer ) . containerName ;
161- if ( ! containerName ) {
170+ // Verify container name is available (set in constructor for existing workspaces,
171+ // or set in createWorkspace for new workspaces)
172+ if ( ! this . containerName ) {
162173 throw new RuntimeError (
163- "Docker runtime not initialized with container name. Use createWorkspace first." ,
174+ "Docker runtime not initialized with container name. " +
175+ "For existing workspaces, pass containerName in config. " +
176+ "For new workspaces, call createWorkspace first." ,
164177 "exec"
165178 ) ;
166179 }
180+ const containerName = this . containerName ;
167181
168182 // Build command parts
169183 const parts : string [ ] = [ ] ;
@@ -474,7 +488,7 @@ export class DockerRuntime implements Runtime {
474488 }
475489
476490 // Store container name on runtime instance for exec operations
477- ( this as DockerRuntimeWithContainer ) . containerName = containerName ;
491+ this . containerName = containerName ;
478492
479493 initLogger . logStep ( "Container created successfully" ) ;
480494
@@ -494,13 +508,13 @@ export class DockerRuntime implements Runtime {
494508 const { projectPath, branchName, trunkBranch, workspacePath, initLogger, abortSignal } = params ;
495509
496510 try {
497- const containerName = ( this as DockerRuntimeWithContainer ) . containerName ;
498- if ( ! containerName ) {
511+ if ( ! this . containerName ) {
499512 return {
500513 success : false ,
501514 error : "Container not initialized. Call createWorkspace first." ,
502515 } ;
503516 }
517+ const containerName = this . containerName ;
504518
505519 // 1. Sync project to container using git bundle + docker cp
506520 initLogger . logStep ( "Syncing project files to container..." ) ;
@@ -863,14 +877,6 @@ export class DockerRuntime implements Runtime {
863877 return Promise . resolve ( "/tmp" ) ;
864878 }
865879}
866-
867- /**
868- * Extended interface for runtime with container name set
869- */
870- interface DockerRuntimeWithContainer extends DockerRuntime {
871- containerName ?: string ;
872- }
873-
874880/**
875881 * Helper to convert a ReadableStream to a string
876882 */
0 commit comments