Skip to content

Commit f8705a9

Browse files
baxenclaude
andauthored
fix(codex): default agent workspace to ~/.buzz (#831)
Signed-off-by: Bradley Axen <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 293c519 commit f8705a9

7 files changed

Lines changed: 140 additions & 14 deletions

File tree

‎src/bundled/codex/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ BUZZODZ_PROFILE=codex-agents2 BUZZ_DEV_VIEWER= bin/just desktop
2020
2. Open **Agents2 → New agent**, choose **Codex**, and create an agent. The Codex
2121
tab checks the installed CLI and existing account. If needed, install Codex
2222
and run `codex login` in a terminal, then click **Check again**.
23-
3. In the agent's **Settings** tab, set an absolute **Workspace** path. A
24-
disposable directory is useful for the first test. Choose model, thinking,
23+
3. The **Workspace** defaults to `~/.buzz`, like Claude Code. In the agent's
24+
**Settings** tab, you can set an absolute path instead; clearing it restores
25+
the default. A disposable directory is useful for the first test. Choose model, thinking,
2526
session scope, and instructions, then **Save**.
2627
4. Mentions and replies are automatic; **Attention** also lets you add event
2728
watches. In a channel you can write to, select the agent from the `@` picker

‎src/bundled/codex/config.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const defaults: Config = {
1717
model: "",
1818
effort: "",
1919
instructions: "",
20-
workspace: "",
20+
workspace: "~/.buzz",
2121
scope: "thread",
2222
};
2323
export function config(raw: unknown): Config {
@@ -41,3 +41,6 @@ export const effortName = (effort: string) =>
4141

4242
export const absoluteWorkspace = (path: string) =>
4343
path.trim().startsWith("/") || /^[A-Za-z]:[\\/]/.test(path.trim());
44+
45+
export const validWorkspace = (path: string) =>
46+
path.trim() === defaults.workspace || absoluteWorkspace(path);

‎src/bundled/codex/manifest.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"apiVersion": 1,
55
"host": {
66
"processes": [
7+
{
8+
"id": "workspace",
9+
"program": "pwd"
10+
},
711
{
812
"id": "app-server",
913
"program": "codex",

‎src/bundled/codex/runtime.test.ts‎

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ function fixture(
131131
let closed = false;
132132
const fileReads: { cwd?: string; path: string }[] = [];
133133
const spawn = vi.fn(async (_id: string, value?: HostProcessOptions) => {
134+
if (_id === "workspace") {
135+
value?.onStdout?.("/home/test/.buzz\n");
136+
return { ...process, exited: Promise.resolve(0) };
137+
}
134138
if (_id === "read") {
135139
fileReads.push({
136140
...(value?.cwd ? { cwd: value.cwd } : {}),
@@ -752,13 +756,83 @@ it("waits for terminal termination after asynchronous clean acknowledgement befo
752756

753757
it("publishes workspace errors without starting work", async () => {
754758
const f = fixture();
755-
await f.runtime.run({ ...f.delivery("hello"), config: {} });
759+
await f.runtime.run({
760+
...f.delivery("hello"),
761+
config: { workspace: "relative" },
762+
});
756763
expect(f.publish.mock.calls[0]?.[0]).toMatchObject({
757764
content: expect.stringContaining("absolute workspace"),
758765
});
759766
expect(f.spawn).not.toHaveBeenCalled();
760767
});
761768

769+
it.each([{}, { workspace: "" }, { workspace: " " }])(
770+
"runs blank workspace settings in the resolved default: %j",
771+
async (config) => {
772+
const f = fixture();
773+
await f.runtime.run({ ...f.delivery("hello"), config });
774+
await vi.waitFor(() => expect(f.starts()).toHaveLength(1));
775+
expect(f.spawn).toHaveBeenCalledWith(
776+
"app-server",
777+
expect.objectContaining({ cwd: "~/.buzz" }),
778+
);
779+
expect(f.spawn).toHaveBeenCalledWith(
780+
"workspace",
781+
expect.objectContaining({ cwd: "~/.buzz" }),
782+
);
783+
for (const method of ["config/read", "thread/start"])
784+
expect(
785+
f.sent.find((wire) => wire.method === method)?.params,
786+
).toMatchObject({ cwd: "/home/test/.buzz" });
787+
f.complete(0, "DONE");
788+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(1));
789+
await f.runtime.run({ ...f.delivery("again"), config });
790+
await vi.waitFor(() => expect(f.starts()).toHaveLength(2));
791+
expect(
792+
f.sent.find((wire) => wire.method === "thread/resume")?.params,
793+
).toMatchObject({ cwd: "/home/test/.buzz" });
794+
f.complete(1, "DONE AGAIN");
795+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(2));
796+
f.runtime.dispose();
797+
},
798+
);
799+
800+
it("reports a default workspace resolution failure without starting a turn", async () => {
801+
const f = fixture();
802+
const spawn = f.spawn.getMockImplementation();
803+
if (!spawn) throw new Error("Missing spawn fixture");
804+
f.spawn.mockImplementation(async (id, options) =>
805+
id === "workspace"
806+
? { ...f.process, exited: Promise.resolve(1) }
807+
: spawn(id, options),
808+
);
809+
await f.runtime.run({ ...f.delivery("hello"), config: {} });
810+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(1));
811+
expect(f.publish.mock.calls[0]?.[0]).toMatchObject({
812+
content: expect.stringContaining(
813+
"Could not resolve the default Codex workspace",
814+
),
815+
});
816+
expect(f.starts()).toHaveLength(0);
817+
});
818+
819+
it("uses the default after changing away from a custom workspace on an existing server", async () => {
820+
const f = fixture();
821+
await f.runtime.run(f.delivery("custom"));
822+
await vi.waitFor(() => expect(f.starts()).toHaveLength(1));
823+
f.complete(0, "CUSTOM");
824+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(1));
825+
await f.runtime.run({ ...f.delivery("default"), config: {} });
826+
await vi.waitFor(() => expect(f.starts()).toHaveLength(2));
827+
const threads = f.sent.filter((wire) => wire.method === "thread/start");
828+
expect(threads.map((wire) => (wire.params as { cwd: string }).cwd)).toEqual([
829+
"/tmp/codex-test",
830+
"/home/test/.buzz",
831+
]);
832+
f.complete(1, "DEFAULT");
833+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(2));
834+
});
835+
762836
it("posts tool-sent parts and never duplicates native assistant text", async () => {
763837
const f = fixture();
764838
await f.runtime.run(f.delivery("work"));

‎src/bundled/codex/runtime.ts‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import type { RelayData } from "../../features/relay/service";
77
import type { EventData } from "../../features/relay/events";
88
import { appClient } from "../../buzz-mcp/app-client";
99
import { TOOLS, callTool } from "../../buzz-mcp/tools";
10-
import { config, absoluteWorkspace, type Config } from "./config";
10+
import {
11+
config,
12+
absoluteWorkspace,
13+
validWorkspace,
14+
type Config,
15+
} from "./config";
1116
import { conversationHistory } from "./history";
1217
import {
1318
developerInstructions,
@@ -217,10 +222,10 @@ export class CodexRuntime {
217222
interest:
218223
trigger.type === "watch" ? (trigger.interest?.instructions ?? "") : "",
219224
};
220-
if (!absoluteWorkspace(settings.workspace)) {
225+
if (!validWorkspace(settings.workspace)) {
221226
await this.publish(
222227
request,
223-
"Choose an absolute workspace path in Codex settings first.",
228+
"Choose an absolute workspace path or ~/.buzz in Codex settings first.",
224229
);
225230
return;
226231
}
@@ -515,13 +520,31 @@ export class CodexRuntime {
515520
try {
516521
const rpc = await entry.opening;
517522
signal.throwIfAborted();
523+
// The process host expands ~/.buzz and creates it; Codex's RPC needs
524+
// an absolute path rather than shell-style home notation.
525+
let workspace = settings.workspace;
526+
if (!absoluteWorkspace(workspace)) {
527+
let directory = "";
528+
const process = await this.spawn("workspace", {
529+
cwd: workspace,
530+
onStdout: (data) => {
531+
directory += data;
532+
},
533+
});
534+
const code = await process.exited;
535+
workspace = directory.trim();
536+
if (code !== 0 || !absoluteWorkspace(workspace))
537+
throw new Error("Could not resolve the default Codex workspace.");
538+
signal.throwIfAborted();
539+
}
540+
active.workspace = workspace;
518541
const existing = entry.saved[key];
519542
const normalized = await rpc.request<{
520543
config: {
521544
model?: string | null;
522545
mcp_servers?: Record<string, Record<string, unknown>>;
523546
};
524-
}>("config/read", { cwd: settings.workspace });
547+
}>("config/read", { cwd: workspace });
525548
const models = await listModels(rpc);
526549
const model =
527550
settings.model ||
@@ -533,7 +556,6 @@ export class CodexRuntime {
533556
"The selected Codex model is unavailable. Choose an available model in Settings.",
534557
);
535558
const effort = settings.effort || selected.defaultReasoningEffort;
536-
const workspace = settings.workspace;
537559
const mcp = Object.fromEntries(
538560
Object.entries(normalized.config.mcp_servers ?? {}).map(
539561
([name, server]) => [

‎src/bundled/codex/tabs.test.tsx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,24 @@ it("preserves unavailable saved choices and closes a process returned after unmo
158158
late.resolve(process);
159159
await waitFor(() => expect(process.end).toHaveBeenCalled());
160160
});
161+
162+
it("shows the default workspace and restores it when the field is cleared", async () => {
163+
const f = fixture();
164+
const save = vi.fn(async () => {});
165+
render(<f.tabs.SettingsTab {...f.props(defaults, save)} />);
166+
expect(screen.getByLabelText("Workspace")).toHaveValue("~/.buzz");
167+
await screen.findByRole("option", { name: "Model A" });
168+
fireEvent.change(screen.getByLabelText("Instructions"), {
169+
target: { value: "Test instructions" },
170+
});
171+
const expected = { ...defaults, instructions: "Test instructions" };
172+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
173+
await waitFor(() => expect(save).toHaveBeenCalledWith(expected));
174+
await waitFor(() => expect(screen.getByLabelText("Workspace")).toBeEnabled());
175+
save.mockClear();
176+
fireEvent.change(screen.getByLabelText("Workspace"), {
177+
target: { value: " " },
178+
});
179+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
180+
await waitFor(() => expect(save).toHaveBeenCalledWith(expected));
181+
});

‎src/bundled/codex/tabs.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AgentViewProps } from "../../features/agents2/service";
44
import {
55
config,
66
effortName,
7-
absoluteWorkspace,
7+
validWorkspace,
88
type Config,
99
type Model,
1010
} from "./config";
@@ -218,9 +218,10 @@ export function createTabs(
218218
setSaving(true);
219219
setError("");
220220
try {
221-
if (!absoluteWorkspace(draft.workspace))
222-
throw new Error("Enter an absolute workspace path.");
223-
await save({ ...draft, workspace: draft.workspace.trim() });
221+
const settings = config(draft);
222+
if (!validWorkspace(settings.workspace))
223+
throw new Error("Enter an absolute workspace path or ~/.buzz.");
224+
await save(settings);
224225
} catch (reason) {
225226
setError(reason instanceof Error ? reason.message : String(reason));
226227
} finally {
@@ -329,7 +330,7 @@ export function createTabs(
329330
...control,
330331
id: "codex-workspace",
331332
value: draft.workspace,
332-
placeholder: "/absolute/path/to/project",
333+
placeholder: "~/.buzz",
333334
disabled: saving,
334335
onChange: (event: { target: { value: string } }) =>
335336
set({ workspace: event.target.value }),

0 commit comments

Comments
 (0)