diff --git a/packages/core/src/tool/plugin/shell.ts b/packages/core/src/tool/plugin/shell.ts index 8a8ce3d707b0..16fe6a5f7749 100644 --- a/packages/core/src/tool/plugin/shell.ts +++ b/packages/core/src/tool/plugin/shell.ts @@ -176,7 +176,12 @@ export const Plugin = { agent: context.agent, source, }) - if ((yield* fsUtil.stat(target.canonical)).type !== "Directory") + const workdir = yield* fsUtil.stat(target.canonical).pipe( + Effect.catchReason("PlatformError", "NotFound", () => + Effect.fail(new Error(`Working directory does not exist: ${target.canonical}`)), + ), + ) + if (workdir.type !== "Directory") return yield* Effect.fail(new Error(`Working directory is not a directory: ${target.canonical}`)) }), ) diff --git a/packages/core/test/tool-shell.test.ts b/packages/core/test/tool-shell.test.ts index 64ea83996054..dfee4e12448d 100644 --- a/packages/core/test/tool-shell.test.ts +++ b/packages/core/test/tool-shell.test.ts @@ -257,6 +257,31 @@ describe("ShellTool", () => { ), ) + it.live("reports a missing workdir", () => + Effect.acquireUseRelease( + Effect.promise(() => tmpdir()), + (tmp) => { + reset() + return withSession(tmp.path, (registry) => + executeTool(registry, call({ command: cwdCommand, workdir: "missing" })), + ).pipe( + Effect.andThen((settled) => + Effect.sync(() => + expect(settled).toEqual({ + status: "error", + error: { + type: "unknown", + message: `Working directory does not exist: ${path.join(tmp.path, "missing")}`, + }, + }), + ), + ), + ) + }, + (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]().then(() => undefined)), + ), + ) + it.live("permissions compound commands separately", () => Effect.acquireUseRelease( Effect.promise(() => tmpdir()),