fix(chat): preserve custom CLI preference during catalog load (#149)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -77,6 +77,14 @@ const ptyProfile: AgentProfile = {
|
|||||||
cwdTemplate: "{projectRoot}",
|
cwdTemplate: "{projectRoot}",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function deferred<T>() {
|
||||||
|
let resolve!: (value: T | PromiseLike<T>) => void;
|
||||||
|
const promise = new Promise<T>((res) => {
|
||||||
|
resolve = res;
|
||||||
|
});
|
||||||
|
return { promise, resolve };
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
});
|
});
|
||||||
@ -191,4 +199,58 @@ describe("LayoutGrid custom agent CLI (#147)", () => {
|
|||||||
expect(screen.getByTestId("custom-agent-chat-view")).toBeTruthy(),
|
expect(screen.getByTestId("custom-agent-chat-view")).toBeTruthy(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps a restored custom CLI mode while the agent/profile catalog is still loading (#149)", async () => {
|
||||||
|
const layout = new MockLayoutGateway();
|
||||||
|
const agent = new MockAgentGateway();
|
||||||
|
const profileGateway = new MockProfileGateway();
|
||||||
|
const terminal = new MockTerminalGateway();
|
||||||
|
const system = new MockSystemGateway();
|
||||||
|
await profileGateway.configureProfiles([structuredProfile]);
|
||||||
|
const created = await agent.createAgent("p1", {
|
||||||
|
name: "Worker",
|
||||||
|
profileId: structuredProfile.id,
|
||||||
|
});
|
||||||
|
const tree = await layout.loadLayout("p1");
|
||||||
|
const leafId = leaves(tree)[0].id;
|
||||||
|
await layout.mutateLayout("p1", {
|
||||||
|
type: "setCellAgent",
|
||||||
|
target: leafId,
|
||||||
|
agent: created.id,
|
||||||
|
});
|
||||||
|
window.localStorage.setItem(`idea.agent-cell-mode.p1.${leafId}`, "custom");
|
||||||
|
|
||||||
|
const agentsLoaded = deferred<void>();
|
||||||
|
const profilesLoaded = deferred<void>();
|
||||||
|
const originalListAgents = agent.listAgents.bind(agent);
|
||||||
|
const originalListProfiles = profileGateway.listProfiles.bind(profileGateway);
|
||||||
|
vi.spyOn(agent, "listAgents").mockImplementation(async (projectId) => {
|
||||||
|
await agentsLoaded.promise;
|
||||||
|
return originalListAgents(projectId);
|
||||||
|
});
|
||||||
|
vi.spyOn(profileGateway, "listProfiles").mockImplementation(async () => {
|
||||||
|
await profilesLoaded.promise;
|
||||||
|
return originalListProfiles();
|
||||||
|
});
|
||||||
|
|
||||||
|
renderGrid({
|
||||||
|
layout,
|
||||||
|
agent,
|
||||||
|
profile: profileGateway,
|
||||||
|
terminal,
|
||||||
|
system,
|
||||||
|
} as unknown as Gateways);
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByTestId("layout-leaf")).toBeTruthy());
|
||||||
|
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("custom");
|
||||||
|
expect(screen.queryByTestId("custom-agent-chat-view")).toBeNull();
|
||||||
|
|
||||||
|
agentsLoaded.resolve();
|
||||||
|
profilesLoaded.resolve();
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(screen.getByTestId("custom-agent-chat-view")).toBeTruthy(),
|
||||||
|
);
|
||||||
|
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("custom");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -362,25 +362,48 @@ function LeafView({
|
|||||||
|
|
||||||
// Load the project's agents for the dropdown.
|
// Load the project's agents for the dropdown.
|
||||||
const [agents, setAgents] = useState<Agent[]>([]);
|
const [agents, setAgents] = useState<Agent[]>([]);
|
||||||
|
const [agentsLoaded, setAgentsLoaded] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!agentGateway) return;
|
setAgentsLoaded(false);
|
||||||
|
if (!agentGateway) {
|
||||||
|
setAgentsLoaded(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
agentGateway.listAgents(projectId).then((list) => {
|
agentGateway.listAgents(projectId).then((list) => {
|
||||||
if (!cancelled) setAgents(list);
|
if (!cancelled) {
|
||||||
}).catch(() => {/* ignore — dropdown stays empty */});
|
setAgents(list);
|
||||||
|
setAgentsLoaded(true);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
if (!cancelled) setAgentsLoaded(true);
|
||||||
|
/* ignore — dropdown stays empty */
|
||||||
|
});
|
||||||
return () => { cancelled = true; };
|
return () => { cancelled = true; };
|
||||||
}, [agentGateway, projectId]);
|
}, [agentGateway, projectId]);
|
||||||
|
|
||||||
const [profiles, setProfiles] = useState<AgentProfile[]>([]);
|
const [profiles, setProfiles] = useState<AgentProfile[]>([]);
|
||||||
|
const [profilesLoaded, setProfilesLoaded] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setProfilesLoaded(false);
|
||||||
|
if (!profileGateway) {
|
||||||
|
setProfilesLoaded(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
profileGateway
|
profileGateway
|
||||||
?.listProfiles()
|
.listProfiles()
|
||||||
.then((list) => {
|
.then((list) => {
|
||||||
if (!cancelled) setProfiles(list);
|
if (!cancelled) {
|
||||||
|
setProfiles(list);
|
||||||
|
setProfilesLoaded(true);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
if (!cancelled) setProfiles([]);
|
if (!cancelled) {
|
||||||
|
setProfiles([]);
|
||||||
|
setProfilesLoaded(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
@ -486,8 +509,9 @@ function LeafView({
|
|||||||
agentGateway?.closeAgentChat,
|
agentGateway?.closeAgentChat,
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!agentsLoaded || !profilesLoaded) return;
|
||||||
if (!customCliAvailable && cellMode !== "tui") setCellMode("tui");
|
if (!customCliAvailable && cellMode !== "tui") setCellMode("tui");
|
||||||
}, [cellMode, customCliAvailable]);
|
}, [agentsLoaded, cellMode, customCliAvailable, profilesLoaded, setCellMode]);
|
||||||
const modelServerStatus = statusForAgent(pinnedAgent);
|
const modelServerStatus = statusForAgent(pinnedAgent);
|
||||||
const modelServerOverlay = modelServerOverlayText(modelServerStatus);
|
const modelServerOverlay = modelServerOverlayText(modelServerStatus);
|
||||||
// F2 — download progress (bar/%/bytes/source) when the status carries it; null
|
// F2 — download progress (bar/%/bytes/source) when the status carries it; null
|
||||||
|
|||||||
Reference in New Issue
Block a user