MCPcopy Create free account
hub / github.com/Noumena-Network/code / getEnvironmentOverrides

Function getEnvironmentOverrides

src/utils/shell/bashProvider.ts:209–254  ·  view source on GitHub ↗
(
      command: string,
    )

Source from the content-addressed store, hash-verified

207 },
208
209 async getEnvironmentOverrides(
210 command: string,
211 ): Promise<Record<string, string>> {
212 // TMUX SOCKET ISOLATION (DEFERRED):
213 // We initialize NCode's tmux socket ONLY AFTER the Tmux tool has been used
214 // at least once, OR if the current command appears to use tmux.
215 // This defers the startup cost until tmux is actually needed.
216 //
217 // Once the Tmux tool is used (or a tmux command runs), all subsequent Bash
218 // commands will use NCode's isolated socket via the TMUX env var override.
219 //
220 // See tmuxSocket.ts for the full isolation architecture documentation.
221 const commandUsesTmux = command.includes('tmux')
222 if (
223 isInternalBuild() &&
224 (hasTmuxToolBeenUsed() || commandUsesTmux)
225 ) {
226 await ensureSocketInitialized()
227 }
228 const ncodeTmuxEnv = getNcodeTmuxEnv()
229 const env: Record<string, string> = {}
230 // CRITICAL: Override TMUX to isolate ALL tmux commands to NCode's socket.
231 // This is NOT the user's TMUX value - it points to NCode's isolated socket.
232 // When null (before socket initializes), user's TMUX is preserved.
233 if (ncodeTmuxEnv) {
234 env.TMUX = ncodeTmuxEnv
235 }
236 if (currentSandboxTmpDir) {
237 let posixTmpDir = currentSandboxTmpDir
238 if (getPlatform() === 'windows') {
239 posixTmpDir = windowsPathToPosixPath(posixTmpDir)
240 }
241 env.TMPDIR = posixTmpDir
242 env.CLAUDE_CODE_TMPDIR = posixTmpDir
243 // Zsh uses TMPPREFIX (default /tmp/zsh) for heredoc temp files,
244 // not TMPDIR. Set it to a path inside the sandbox tmp dir so
245 // heredocs work in sandboxed zsh commands.
246 // Safe to set unconditionally — non-zsh shells ignore TMPPREFIX.
247 env.TMPPREFIX = posixJoin(posixTmpDir, 'zsh')
248 }
249 // Apply session env vars set via /env (child processes only, not the REPL)
250 for (const [key, value] of getSessionEnvVars()) {
251 env[key] = value
252 }
253 return env
254 },
255 }
256}

Callers

nothing calls this directly

Calls 6

isInternalBuildFunction · 0.85
hasTmuxToolBeenUsedFunction · 0.85
ensureSocketInitializedFunction · 0.85
getNcodeTmuxEnvFunction · 0.85
getPlatformFunction · 0.85
getSessionEnvVarsFunction · 0.85

Tested by

no test coverage detected