MCPcopy Create free account
hub / github.com/21st-dev/1code / buildEnvironment

Function buildEnvironment

src/main/lib/platform/base.ts:93–133  ·  view source on GitHub ↗
(baseEnv?: Record<string, string>)

Source from the content-addressed store, hash-verified

91 }
92
93 buildEnvironment(baseEnv?: Record<string, string>): Record<string, string> {
94 const envConfig = this.getEnvironmentConfig()
95 const pathConfig = this.getPathConfig()
96 const home = this.getHome()
97 const user = this.getUsername()
98
99 const env: Record<string, string> = { ...baseEnv }
100
101 // Set home directory
102 env[envConfig.homeVar] = home
103 if (!env.HOME) env.HOME = home
104
105 // Set user
106 env[envConfig.userVar] = user
107 if (!env.USER) env.USER = user
108
109 // Set additional platform-specific vars
110 for (const [key, value] of Object.entries(envConfig.additionalVars)) {
111 if (!env[key]) {
112 // Resolve special placeholders
113 env[key] = value
114 .replace("${HOME}", home)
115 .replace("${USER}", user)
116 }
117 }
118
119 // Build extended PATH
120 env.PATH = this.buildExtendedPath(env.PATH || process.env.PATH)
121
122 // Set TERM if not present
123 if (!env.TERM) {
124 env.TERM = "xterm-256color"
125 }
126
127 // Set SHELL
128 if (!env.SHELL) {
129 env.SHELL = this.getDefaultShell()
130 }
131
132 return env
133 }
134
135 /**
136 * Execute a command safely using execFile (no shell interpolation).

Callers

nothing calls this directly

Calls 4

buildExtendedPathMethod · 0.80
getEnvironmentConfigMethod · 0.65
getPathConfigMethod · 0.65
getDefaultShellMethod · 0.65

Tested by

no test coverage detected