Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/shell/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ export function args(file: string, command: string, cwd: string) {
[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
[[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
cd -- "$1"
eval ${JSON.stringify(command)}
eval "$2"
`,
"opencode",
cwd,
command,
]
}
if (n === "bash") {
Expand All @@ -181,10 +182,11 @@ export function args(file: string, command: string, cwd: string) {
shopt -s expand_aliases
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
cd -- "$1"
eval ${JSON.stringify(command)}
eval "$2"
`,
"opencode",
cwd,
command,
]
}
if (n === "cmd") return ["/c", command]
Expand Down
31 changes: 31 additions & 0 deletions packages/opencode/test/session/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,37 @@ unix("shell commands can change directory after startup", () =>
),
)

unix(
"shell preserves newlines with configured bash",
() =>
withSh(() =>
provideTmpdirInstance(
(_dir) =>
Effect.gen(function* () {
if (!Bun.which("bash")) return

const { prompt, run, chat } = yield* boot()
const result = yield* prompt.shell({
sessionID: chat.id,
agent: "build",
command: "printf first\nprintf second",
})

expect(result.info.role).toBe("assistant")
const tool = completedTool(result.parts)
if (!tool) return

expect(tool.state.input.command).toBe("printf first\nprintf second")
expect(tool.state.output).toContain("firstsecond")
expect(tool.state.output).not.toContain("firstnprintf")
yield* run.assertNotBusy(chat.id)
}),
{ git: true, config: { ...cfg, shell: "bash" } },
),
),
30_000,
)

unix("shell lists files from the project directory", () =>
provideTmpdirInstance(
(dir) =>
Expand Down
Loading