File tree Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 1+ import { NON_INTERACTIVE_ENV_VARS } from "./env" ;
2+
3+ describe ( "NON_INTERACTIVE_ENV_VARS" , ( ) => {
4+ it ( "should include MUX_AGENT=1" , ( ) => {
5+ expect ( NON_INTERACTIVE_ENV_VARS . MUX_AGENT ) . toBe ( "1" ) ;
6+ } ) ;
7+
8+ it ( "should include all expected env vars" , ( ) => {
9+ expect ( NON_INTERACTIVE_ENV_VARS ) . toMatchObject ( {
10+ MUX_AGENT : "1" ,
11+ GIT_EDITOR : "true" ,
12+ GIT_SEQUENCE_EDITOR : "true" ,
13+ EDITOR : "true" ,
14+ VISUAL : "true" ,
15+ GIT_TERMINAL_PROMPT : "0" ,
16+ } ) ;
17+ } ) ;
18+ } ) ;
Original file line number Diff line number Diff line change 33 * These prevent tools from blocking on editor/credential prompts.
44 */
55export const NON_INTERACTIVE_ENV_VARS = {
6+ // Sentinel variable to indicate commands are running under Mux AI agent
7+ MUX_AGENT : "1" ,
68 // Prevent interactive editors from blocking execution
79 // Critical for git operations like rebase/commit that try to open editors
810 GIT_EDITOR : "true" , // Git-specific editor (highest priority)
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import type {
1616} from "./Runtime" ;
1717import { RuntimeError as RuntimeErrorClass } from "./Runtime" ;
1818import { EXIT_CODE_ABORTED , EXIT_CODE_TIMEOUT } from "@/common/constants/exitCodes" ;
19+ import { NON_INTERACTIVE_ENV_VARS } from "@/common/constants/env" ;
1920import { log } from "@/node/services/log" ;
2021import { checkInitHookExists , createLineBufferedLoggers , getInitHookEnv } from "./initHook" ;
2122import { streamProcessToLogger } from "./streamProcess" ;
@@ -106,11 +107,10 @@ export class SSHRuntime implements Runtime {
106107 // Add cd command if cwd is specified
107108 parts . push ( cdCommandForSSH ( options . cwd ) ) ;
108109
109- // Add environment variable exports
110- if ( options . env ) {
111- for ( const [ key , value ] of Object . entries ( options . env ) ) {
112- parts . push ( `export ${ key } =${ shescape . quote ( value ) } ` ) ;
113- }
110+ // Add environment variable exports (NON_INTERACTIVE_ENV_VARS + user-provided env)
111+ const allEnv = { ...NON_INTERACTIVE_ENV_VARS , ...( options . env ?? { } ) } ;
112+ for ( const [ key , value ] of Object . entries ( allEnv ) ) {
113+ parts . push ( `export ${ key } =${ shescape . quote ( value ) } ` ) ;
114114 }
115115
116116 // Add the actual command
Original file line number Diff line number Diff line change @@ -100,6 +100,18 @@ describeIntegration("Runtime integration tests", () => {
100100 expect ( result . exitCode ) . toBe ( 0 ) ;
101101 } ) ;
102102
103+ test . concurrent ( "automatically sets MUX_AGENT=1 environment variable" , async ( ) => {
104+ const runtime = createRuntime ( ) ;
105+ await using workspace = await TestWorkspace . create ( runtime , type ) ;
106+
107+ const result = await execBuffered ( runtime , 'echo "$MUX_AGENT"' , {
108+ cwd : workspace . path ,
109+ timeout : 30 ,
110+ } ) ;
111+
112+ expect ( result . stdout . trim ( ) ) . toBe ( "1" ) ;
113+ } ) ;
114+
103115 test . concurrent ( "passes environment variables" , async ( ) => {
104116 const runtime = createRuntime ( ) ;
105117 await using workspace = await TestWorkspace . create ( runtime , type ) ;
You can’t perform that action at this time.
0 commit comments