Skip to content

Commit 4e3a0c4

Browse files
authored
✨ feat: add environment variable support in shell execution (#1369)
Expanded shell options to include env variables and isolateEnv settings.
1 parent de8ae44 commit 4e3a0c4

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/cli/src/nodehost.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ export class NodeHost extends EventTarget implements RuntimeHost {
552552
cancellationToken,
553553
stdin: input,
554554
ignoreError,
555+
env,
556+
isolateEnv,
555557
} = options || {}
556558
const trace = options?.trace?.startTraceDetails(label || command)
557559
try {
@@ -583,6 +585,8 @@ export class NodeHost extends EventTarget implements RuntimeHost {
583585
stdin: input ? undefined : "ignore",
584586
stdout: ["pipe"],
585587
stderr: ["pipe"],
588+
env,
589+
extendEnv: !isolateEnv,
586590
}
587591
)
588592
trace?.itemValue(`exit code`, `${exitCode}`)

packages/core/src/git.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ export class GitClient implements Git {
108108
args: string | string[],
109109
options?: { label?: string }
110110
): Promise<string> {
111-
const opts = {
111+
const opts: ShellOptions = {
112112
...(options || {}),
113113
cwd: this.cwd,
114+
env: {
115+
LC_ALL: "en_US",
116+
},
114117
}
115118
const eargs = Array.isArray(args) ? args : shellParse(args)
116119
dbg(`exec`, shellQuote(eargs))

packages/core/src/types/prompt_template.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,9 @@ interface SgHost {
42364236

42374237
interface ShellOptions {
42384238
cwd?: string
4239+
42394240
stdin?: string
4241+
42404242
/**
42414243
* Process timeout in milliseconds, default is 60s
42424244
*/
@@ -4250,6 +4252,16 @@ interface ShellOptions {
42504252
* Ignore exit code errors
42514253
*/
42524254
ignoreError?: boolean
4255+
4256+
/**
4257+
* Additional environment variables to set for the process.
4258+
*/
4259+
env?: Record<string, string>
4260+
4261+
/**
4262+
* Inject the content of 'env' exclusively
4263+
*/
4264+
isolateEnv?: boolean
42534265
}
42544266

42554267
interface ShellOutput {

0 commit comments

Comments
 (0)