11import type { WorkspaceMetadata } from "@/common/types/workspace" ;
22import type { MCPServerMap } from "@/common/types/mcp" ;
3+ import type { RuntimeMode } from "@/common/types/runtime" ;
4+ import { RUNTIME_MODE } from "@/common/types/runtime" ;
35import {
46 readInstructionSet ,
57 readInstructionSetFromRuntime ,
@@ -13,6 +15,7 @@ import {
1315import type { Runtime } from "@/node/runtime/Runtime" ;
1416import { getMuxHome } from "@/common/constants/paths" ;
1517import { getAvailableTools } from "@/common/utils/tools/toolDefinitions" ;
18+ import { assertNever } from "@/common/utils/assertNever" ;
1619
1720// NOTE: keep this in sync with the docs/models.md file
1821
@@ -66,59 +69,59 @@ When the user asks you to remember something:
6669/**
6770 * Build environment context XML block describing the workspace.
6871 * @param workspacePath - Workspace directory path
69- * @param runtimeType - Runtime type: " local", " worktree", " ssh", or " docker"
72+ * @param runtimeType - Runtime type ( local, worktree, ssh, docker)
7073 */
71- function buildEnvironmentContext (
72- workspacePath : string ,
73- runtimeType : "local" | "worktree" | "ssh" | "docker"
74- ) : string {
75- if ( runtimeType === "local" ) {
76- // Local runtime works directly in project directory - may or may not be git
77- return `
78- <environment>
79- You are working in a directory at ${ workspacePath }
80-
81- - Tools run here automatically
82- - You are meant to do your work isolated from the user and other agents
83- </environment>
84- ` ;
85- }
86-
87- if ( runtimeType === "ssh" ) {
88- // SSH runtime clones the repository on a remote host
89- return `
90- <environment>
91- You are in a clone of a git repository at ${ workspacePath }
92-
93- - This IS a git repository - run git commands directly (no cd needed)
94- - Tools run here automatically
95- - You are meant to do your work isolated from the user and other agents
96- </environment>
97- ` ;
98- }
99-
100- if ( runtimeType === "docker" ) {
101- // Docker runtime runs in an isolated container
102- return `
103- <environment>
104- You are in a clone of a git repository at ${ workspacePath } inside a Docker container
105-
106- - This IS a git repository - run git commands directly (no cd needed)
107- - Tools run here automatically inside the container
108- - You are meant to do your work isolated from the user and other agents
109- </environment>
110- ` ;
74+ function buildEnvironmentContext ( workspacePath : string , runtimeType : RuntimeMode ) : string {
75+ // Common lines shared across git-based runtimes
76+ const gitCommonLines = [
77+ "- This IS a git repository - run git commands directly (no cd needed)" ,
78+ "- Tools run here automatically" ,
79+ "- You are meant to do your work isolated from the user and other agents" ,
80+ ] ;
81+
82+ let description : string ;
83+ let lines : string [ ] ;
84+
85+ switch ( runtimeType ) {
86+ case RUNTIME_MODE . LOCAL :
87+ // Local runtime works directly in project directory - may or may not be git
88+ description = `You are working in a directory at ${ workspacePath } ` ;
89+ lines = [
90+ "- Tools run here automatically" ,
91+ "- You are meant to do your work isolated from the user and other agents" ,
92+ ] ;
93+ break ;
94+
95+ case RUNTIME_MODE . WORKTREE :
96+ // Worktree runtime creates a git worktree locally
97+ description = `You are in a git worktree at ${ workspacePath } ` ;
98+ lines = [
99+ ...gitCommonLines ,
100+ "- Do not modify or visit other worktrees (especially the main project) without explicit user intent" ,
101+ ] ;
102+ break ;
103+
104+ case RUNTIME_MODE . SSH :
105+ // SSH runtime clones the repository on a remote host
106+ description = `You are in a clone of a git repository at ${ workspacePath } ` ;
107+ lines = gitCommonLines ;
108+ break ;
109+
110+ case RUNTIME_MODE . DOCKER :
111+ // Docker runtime runs in an isolated container
112+ description = `You are in a clone of a git repository at ${ workspacePath } inside a Docker container` ;
113+ lines = gitCommonLines ;
114+ break ;
115+
116+ default :
117+ assertNever ( runtimeType , `Unknown runtime type: ${ String ( runtimeType ) } ` ) ;
111118 }
112119
113- // Worktree runtime creates a git worktree locally
114120 return `
115121<environment>
116- You are in a git worktree at ${ workspacePath }
122+ ${ description }
117123
118- - This IS a git repository - run git commands directly (no cd needed)
119- - Tools run here automatically
120- - Do not modify or visit other worktrees (especially the main project) without explicit user intent
121- - You are meant to do your work isolated from the user and other agents
124+ ${ lines . join ( "\n" ) }
122125</environment>
123126` ;
124127}
0 commit comments