From af69e793e705a27168faf8e2493420c7ad5391f6 Mon Sep 17 00:00:00 2001 From: LouisLv Date: Thu, 17 Apr 2025 22:14:12 +0800 Subject: [PATCH] fix: check workdir before spawn (#221) The workdir used to spawn a agent command is provide by the agent tool, we need to ensure its existence and fallback to process.cwd when not. fix #212 --- codex-cli/src/utils/agent/handle-exec-command.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/codex-cli/src/utils/agent/handle-exec-command.ts b/codex-cli/src/utils/agent/handle-exec-command.ts index 41b7abbc..84dbbc9c 100644 --- a/codex-cli/src/utils/agent/handle-exec-command.ts +++ b/codex-cli/src/utils/agent/handle-exec-command.ts @@ -204,11 +204,20 @@ async function execCommand( runInSandbox: boolean, abortSignal?: AbortSignal, ): Promise { + let { workdir } = execInput; + if (workdir) { + try { + await access(workdir); + } catch (e) { + log(`EXEC workdir=${workdir} not found, use process.cwd() instead`); + workdir = process.cwd(); + } + } if (isLoggingEnabled()) { if (applyPatchCommand != null) { log("EXEC running apply_patch command"); } else { - const { cmd, workdir, timeoutInMillis } = execInput; + const { cmd, timeoutInMillis } = execInput; // Seconds are a bit easier to read in log messages and most timeouts // are specified as multiples of 1000, anyway. const timeout =