Compare commits

..
4 changed files with 51 additions and 24 deletions
+2 -2
View File
@@ -38,8 +38,8 @@ ACP handle instead of a tmux pane).
## The adapter ## The adapter
The resolved structured command selects a provider adapter. Its binary is The resolved structured command selects a provider adapter. Its binary is
resolved by walking the session's `PATH` (when set on the spawn request), then resolved by walking the session's `PATH` when the spawn request sets one, or
the daemon's `PATH`, and taking the first executable with that name. the daemon's `PATH` otherwise, and taking the first executable with that name.
| Command | Adapter binary | Install command | Provider detail | | Command | Adapter binary | Install command | Provider detail |
| --- | --- | --- | --- | | --- | --- | --- | --- |
+15 -9
View File
@@ -26,15 +26,21 @@ describe("buildSpawnRequest", () => {
expect(res).toEqual({ req: { cwd: base.cwd, command: base.command, metadata: {} } }); expect(res).toEqual({ req: { cwd: base.cwd, command: base.command, metadata: {} } });
}); });
it("requests structured view only for Claude Code", () => { it.each(["claude", "FOO=1 /usr/local/bin/codex", "env -i codex"])(
expect(buildSpawnRequest({ ...base, structuredView: true }, null)).toEqual({ "requests structured view for resolved %s commands",
req: { (command) => {
cwd: base.cwd, expect(buildSpawnRequest({ ...base, command, structuredView: true }, null)).toEqual({
command: "claude", req: {
metadata: { name: "amber-fox" }, cwd: base.cwd,
view: "Structured", command,
}, metadata: { name: "amber-fox" },
}); view: "Structured",
},
});
},
);
it("does not request structured view for unsupported commands", () => {
expect( expect(
buildSpawnRequest({ ...base, command: "opencode", structuredView: true }, null), buildSpawnRequest({ ...base, command: "opencode", structuredView: true }, null),
).toEqual({ ).toEqual({
+9 -2
View File
@@ -15,6 +15,13 @@ import { splitCommand } from "./toolIcon.js";
import { abbreviateCwd } from "./types.js"; import { abbreviateCwd } from "./types.js";
import type { BranchInfo, CreateSessionRequest, Project, Session, SpawnPreset } from "./types.js"; import type { BranchInfo, CreateSessionRequest, Project, Session, SpawnPreset } from "./types.js";
const STRUCTURED_VIEW_TOOLS = new Set(["claude", "codex"]);
function supportsStructuredView(command: string): boolean {
const tool = splitCommand(command).tool;
return tool !== null && STRUCTURED_VIEW_TOOLS.has(tool);
}
/** Where a worktree's branch comes from: freshly created (default) or picked /** Where a worktree's branch comes from: freshly created (default) or picked
* from the repository's existing branches (#61). */ * from the repository's existing branches (#61). */
export type WorktreeBranchMode = "new" | "existing"; export type WorktreeBranchMode = "new" | "existing";
@@ -68,7 +75,7 @@ export function buildSpawnRequest(
metadata, metadata,
}; };
if (values.structuredView && splitCommand(values.command).tool === "claude") { if (values.structuredView && supportsStructuredView(values.command)) {
req.view = "Structured"; req.view = "Structured";
} }
@@ -369,7 +376,7 @@ export function createSpawnForm(opts: SpawnFormOptions): SpawnFormHandle {
let commandTouched = false; let commandTouched = false;
function updateStructuredAvailability(): void { function updateStructuredAvailability(): void {
const supported = splitCommand(command).tool === "claude"; const supported = supportsStructuredView(command);
structuredWrap.hidden = !supported; structuredWrap.hidden = !supported;
if (!supported) structuredView.checked = false; if (!supported) structuredView.checked = false;
} }
+25 -11
View File
@@ -44,7 +44,7 @@ describe("spawn form structured view", () => {
vi.unstubAllGlobals(); vi.unstubAllGlobals();
}); });
it("is default-off and shown only for the resolved Claude Code command", async () => { it("is default-off and shown for resolved Claude Code and Codex commands", async () => {
stubApi(); stubApi();
handle = createSpawnForm({ onSuccess() {} }); handle = createSpawnForm({ onSuccess() {} });
document.body.appendChild(handle.el); document.body.appendChild(handle.el);
@@ -59,26 +59,33 @@ describe("spawn form structured view", () => {
expect(wrap.hidden).toBe(false); expect(wrap.hidden).toBe(false);
expect(checkbox.checked).toBe(false); expect(checkbox.checked).toBe(false);
handle.el.querySelector<HTMLButtonElement>('[data-id="opencode"]')!.click(); const custom = handle.el.querySelector<HTMLButtonElement>('[data-id="custom"]')!;
expect(wrap.hidden).toBe(true); custom.click();
const command = handle.el.querySelector<HTMLInputElement>(".cmd-raw")!;
handle.el.querySelector<HTMLButtonElement>('[data-id="claude"]')!.click(); command.value = "FOO=1 /usr/local/bin/codex";
command.dispatchEvent(new Event("input"));
expect(wrap.hidden).toBe(false); expect(wrap.hidden).toBe(false);
command.value = "opencode";
command.dispatchEvent(new Event("input"));
expect(wrap.hidden).toBe(true);
}); });
it("clears a checked value when the command changes away from Claude Code", async () => { it("clears a checked value when Codex changes to an unsupported command", async () => {
stubApi(); stubApi();
handle = createSpawnForm({ onSuccess() {} }); handle = createSpawnForm({ onSuccess() {} });
document.body.appendChild(handle.el); document.body.appendChild(handle.el);
await drain(); await drain();
handle.el.querySelector<HTMLButtonElement>('[data-id="custom"]')!.click();
const command = handle.el.querySelector<HTMLInputElement>(".cmd-raw")!;
command.value = "env -i codex";
command.dispatchEvent(new Event("input"));
const checkbox = handle.el.querySelector<HTMLInputElement>("input[name=structured_view]")!; const checkbox = handle.el.querySelector<HTMLInputElement>("input[name=structured_view]")!;
checkbox.click(); checkbox.click();
expect(checkbox.checked).toBe(true); expect(checkbox.checked).toBe(true);
const custom = handle.el.querySelector<HTMLButtonElement>('[data-id="custom"]')!;
custom.click();
const command = handle.el.querySelector<HTMLInputElement>(".cmd-raw")!;
command.value = "opencode"; command.value = "opencode";
command.dispatchEvent(new Event("input")); command.dispatchEvent(new Event("input"));
@@ -86,7 +93,7 @@ describe("spawn form structured view", () => {
expect(checkbox.checked).toBe(false); expect(checkbox.checked).toBe(false);
}); });
it("emits Structured in the submitted request when selected", async () => { it.each(["claude", "codex"])("emits Structured for a selected %s command", async (tool) => {
const requests = stubApi(); const requests = stubApi();
handle = createSpawnForm({ handle = createSpawnForm({
seed: { cwd: "/srv/work", cwdRawVisible: true, worktreeEnabled: false }, seed: { cwd: "/srv/work", cwdRawVisible: true, worktreeEnabled: false },
@@ -95,13 +102,20 @@ describe("spawn form structured view", () => {
document.body.appendChild(handle.el); document.body.appendChild(handle.el);
await drain(); await drain();
if (tool === "codex") {
handle.el.querySelector<HTMLButtonElement>('[data-id="custom"]')!.click();
const command = handle.el.querySelector<HTMLInputElement>(".cmd-raw")!;
command.value = "codex";
command.dispatchEvent(new Event("input"));
}
handle.el.querySelector<HTMLInputElement>("input[name=structured_view]")!.click(); handle.el.querySelector<HTMLInputElement>("input[name=structured_view]")!.click();
handle.el.requestSubmit(); handle.el.requestSubmit();
await drain(); await drain();
expect(requests).toHaveLength(1); expect(requests).toHaveLength(1);
expect(JSON.parse(String(requests[0].body))).toMatchObject({ expect(JSON.parse(String(requests[0].body))).toMatchObject({
command: "claude", command: tool,
view: "Structured", view: "Structured",
}); });
}); });