-
Notifications
You must be signed in to change notification settings - Fork 15.8k
refactor: replace Bun shell execution with portable Process utilities #18318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,6 @@ import { Flag } from "../flag/flag" | |
| import { ulid } from "ulid" | ||
| import { spawn } from "child_process" | ||
| import { Command } from "../command" | ||
| import { $ } from "bun" | ||
| import { pathToFileURL, fileURLToPath } from "url" | ||
| import { ConfigMarkdown } from "../config/markdown" | ||
| import { SessionSummary } from "./summary" | ||
|
|
@@ -48,6 +47,7 @@ import { iife } from "@/util/iife" | |
| import { Shell } from "@/shell/shell" | ||
| import { Truncate } from "@/tool/truncate" | ||
| import { decodeDataUrl } from "@/util/data-url" | ||
| import { Process } from "@/util/process" | ||
|
|
||
| // @ts-ignore | ||
| globalThis.AI_SDK_LOG_WARNINGS = false | ||
|
|
@@ -1812,15 +1812,13 @@ NOTE: At any point in time through this workflow you should feel free to ask the | |
| template = template + "\n\n" + input.arguments | ||
| } | ||
|
|
||
| const shell = ConfigMarkdown.shell(template) | ||
| if (shell.length > 0) { | ||
| const shellMatches = ConfigMarkdown.shell(template) | ||
| if (shellMatches.length > 0) { | ||
| const sh = Shell.preferred() | ||
| const results = await Promise.all( | ||
| shell.map(async ([, cmd]) => { | ||
| try { | ||
| return await $`${{ raw: cmd }}`.quiet().nothrow().text() | ||
| } catch (error) { | ||
| return `Error executing command: ${error instanceof Error ? error.message : String(error)}` | ||
| } | ||
| shellMatches.map(async ([, cmd]) => { | ||
| const out = await Process.text([cmd], { shell: sh, nothrow: true }) | ||
| return out.text | ||
|
Comment on lines
+1819
to
+1821
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The old code had an explicit Consider returning a fallback string on failure to preserve debuggability: shellMatches.map(async ([, cmd]) => {
const out = await Process.text([cmd], { shell: sh, nothrow: true })
return out.text || (out.code !== 0 ? `Error executing command (exit ${out.code})` : "")
}), |
||
| }), | ||
| ) | ||
| let index = 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shell.preferred()may return incompatible shell for POSIX commandsThe template shell commands (matched by
!cmd`` syntax) are expected to be POSIX shell code. UsingShell.preferred()can return `fish` or `nu` — both of which are explicitly blacklisted in `Shell.acceptable()` because they are incompatible with POSIX syntax. When a user's `$SHELL` is set to fish or nu, the spawned process will receive POSIX shell syntax it cannot parse, and the failure will be silently swallowed by `nothrow: true`, leaving the template substitution as an empty string with no feedback.bash.tsusesShell.acceptable()for exactly this reason. This call should too.