feat(local-model): pick the coding agent in the window, and install one that is missing

The installed screen gets one more block, "Start a session with": a chip
per coding agent the model in use can be run with, as a radio group, the
server's default selected. A chip that is not on the Mac says so.

The main button follows the selected chip:
- an agent that can be started: "Start a session", with that agent;
- an agent that is not on the Mac: its literal install command above the
  button, and "Install <agent>". The click is the consent; the server
  runs its own stock command, and the window shows "Installing" on the
  chip while the model stays ready and another agent can be started;
- an agent that needs a setup of its own (DeepSeek Harness without a
  terminal profile): one line that says where, nothing to press.

A failed install shows the server's sentence under the chip with the
installer's last words folded away; the model's own headline is
untouched. On a stopped model Start stays the one main button. The
choice is remembered on the device. A server that lists no agents gets
the screen it had.

Rendered in Chromium at 1440, 390 and 320 px on a dark and a light
skin: the chips wrap, nothing leaves the window.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-11 10:00:03 +01:00
1 parent d22bfaaaaf
commit 0442b4cdbf
4 files changed
+688 -14

No files matched your search

+353 -1
View File
@@ -51,6 +51,7 @@ import type {
HardwareFacts,
LocalModelConflict,
LocalModelErrorCode,
LocalModelHarnessRow,
LocalModelInstallView,
LocalModelLibraryRow,
LocalModelMessage,
@@ -77,7 +78,7 @@ interface App {
openLocalModelWindow(): void;
closeLocalModelWindow(): void;
isLocalModelWindowOpen(): boolean;
startLocalModelSession(): Promise<void>;
startLocalModelSession(cli?: string): Promise<void>;
loadAppSettingsFromServer?: () => Promise<void>;
loadCliListForSettings?: () => Promise<void>;
selectCustomModelEntry?: (cli: string, endpointId: string) => Promise<void>;
@@ -389,6 +390,7 @@ function install(over: Partial<LocalModelInstallView> = {}): LocalModelInstallVi
runtime: RUNTIME_MISSING,
folder: FOLDER,
library: [],
harnesses: [],
actions: ['install'],
...over,
};
@@ -2827,6 +2829,356 @@ describe('the models on this Mac', () => {
});
});
// ---------- The coding agents of an installed model ----------
/** The agents the server lists for the installed model: two that can be started, one to install, one that needs a setup. */
const AGENTS: LocalModelHarnessRow[] = [
{ cli: 'opencode', cliLabel: 'OpenCode', default: true, status: 'ready', readyMark: '┃', actions: ['start-session'] },
{
cli: 'claude',
cliLabel: 'Claude Code',
default: false,
status: 'ready',
slowFirstTurn: true,
actions: ['start-session'],
},
{
cli: 'pi',
cliLabel: 'Pi',
default: false,
status: 'installable',
installCommand: 'npm install -g --ignore-scripts @earendil-works/pi-coding-agent',
actions: ['install'],
},
{ cli: 'deepseek', cliLabel: 'DeepSeek', default: false, status: 'setup-needed', readyMark: '❯', actions: [] },
];
const withAgents = (rows: LocalModelHarnessRow[], over: Partial<LocalModelInstallView> = {}) =>
status(
{},
{ ...INSTALLED.install, harnesses: rows, actions: [...INSTALLED.install.actions, 'install-agent'], ...over }
);
const WITH_AGENTS = withAgents(AGENTS);
describe('the coding agents of an installed model', () => {
const chips = (page: Mounted) => texts(page.body, '.lm-agent').map((text) => text.trim());
const chosen = (page: Mounted) =>
page.body.querySelector('.lm-agent[aria-checked="true"] .lm-agent-name')?.textContent ?? null;
const pick = (page: Mounted, label: string) => {
const chip = [...page.body.querySelectorAll<HTMLButtonElement>('.lm-agent')].find(
(el) => el.querySelector('.lm-agent-name')!.textContent === label
);
expect(chip, `no agent "${label}"`).toBeTruthy();
chip!.click();
};
const launcher = (app: App) => {
app.loadAppSettingsFromServer = vi.fn(async () => undefined);
app.loadCliListForSettings = vi.fn(async () => undefined);
app.selectCustomModelEntry = vi.fn(async () => undefined);
return app.selectCustomModelEntry;
};
it('is one radio group: a chip per agent in the server order, the default selected, a tag on what is not there', async () => {
const page = mount();
await opened(page, WITH_AGENTS);
const group = page.body.querySelector('.lm-agent-list')!;
expect(group.getAttribute('role')).toBe('radiogroup');
expect(page.document.getElementById(group.getAttribute('aria-labelledby')!)!.textContent).toBe(
'Start a session with'
);
expect(texts(page.body, '.lm-agent-name')).toEqual(['OpenCode', 'Claude Code', 'Pi', 'DeepSeek']);
expect(chips(page)).toEqual(['OpenCode', 'Claude Code', 'PiNot installed', 'DeepSeekNeeds setup']);
expect(chosen(page)).toBe('OpenCode');
// One tab stop for the group.
expect([...page.body.querySelectorAll<HTMLElement>('.lm-agent')].map((el) => el.tabIndex)).toEqual([0, -1, -1, -1]);
// The chips say which agent, so the facts line no longer does.
expect(page.body.textContent).not.toContain('Runs with');
expect(buttons(page.body)).toEqual(['Remove', 'Stop', 'Start a session']);
expect(frameOf(page.body).querySelectorAll('.lm-buttons .wt-btn-primary')).toHaveLength(1);
});
it('starts the session with the selected agent, and this device remembers the choice', async () => {
const page = mount();
const { app } = await opened(page, WITH_AGENTS);
const launch = launcher(app);
pick(page, 'Claude Code');
expect(chosen(page)).toBe('Claude Code');
// What the catalogue says about its first answer.
expect(texts(page.body, '.lm-agent-about .lm-aside')).toEqual(['The first answer can take minutes.']);
expect(verbs(app)).toEqual([]);
press(page.body, 'Start a session');
await settle();
expect(launch).toHaveBeenCalledWith('claude', 'local-ollama');
// The window opened again later: the last choice stands, not the default.
expect(page.dom.window.localStorage.getItem('codeman-local-model-agent')).toBe('claude');
const again = page.newApp(ok(WITH_AGENTS));
await again.loadLocalModel();
again.openLocalModelWindow();
await settle();
expect(chosen(page)).toBe('Claude Code');
});
it('a remembered agent the server no longer lists falls back to the default', async () => {
const page = mount();
page.dom.window.localStorage.setItem('codeman-local-model-agent', 'gone');
const { app } = await opened(page, WITH_AGENTS);
expect(chosen(page)).toBe('OpenCode');
const launch = launcher(app);
press(page.body, 'Start a session');
await settle();
expect(launch).toHaveBeenCalledWith('opencode', 'local-ollama');
});
it('an agent that is not on this Mac: its literal command, and the main button installs it', async () => {
const page = mount();
const installing = AGENTS.map((row) =>
row.cli === 'pi' ? { ...row, status: 'installing' as const, actions: [] } : row
);
const { app, serve } = await opened(page, WITH_AGENTS, () =>
ok(withAgents(installing, { actions: INSTALLED.install.actions }).install)
);
pick(page, 'Pi');
expect(texts(page.body, '.lm-agent-about .lm-aside')).toEqual([
'Pi is not on this Mac yet. Codeman installs it with this command:',
]);
// The command the click consents to, as text, exactly as the server sent it.
expect(texts(page.body, '.lm-agent-about .lm-command')).toEqual([
'npm install -g --ignore-scripts @earendil-works/pi-coding-agent',
]);
expect(buttons(page.body)).toEqual(['Remove', 'Stop', 'Install Pi']);
expect(frameOf(page.body).querySelector('.lm-buttons .wt-btn-primary')!.textContent).toBe('Install Pi');
press(page.body, 'Install Pi');
await settle();
// The id goes out as data; the command is the server's own and is never sent.
expect(verbs(app)).toEqual([['POST', '/api/local-model/agent', { cli: 'pi' }]]);
expect(chips(page)).toContain('PiInstalling');
expect(texts(page.body, '.lm-agent-about .lm-aside')).toEqual([
'Installing Pi. You can start a session with another agent meanwhile.',
]);
const main = frameOf(page.body).querySelector<HTMLButtonElement>('.lm-buttons .wt-btn-primary')!;
expect([main.textContent, main.disabled]).toEqual(['Installing Pi', true]);
// The model is as it was: still installed, still running.
expect(page.body.dataset.screen).toBe('installed');
expect(texts(page.body, '.lm-state-text')).toEqual(['Running']);
// The installer landed: the next poll says so, and the same chip now starts a session.
serve(
withAgents(
AGENTS.map((row) =>
row.cli === 'pi'
? {
cli: 'pi',
cliLabel: 'Pi',
default: false,
status: 'ready' as const,
actions: ['start-session' as const],
}
: row
)
)
);
await page.tick();
expect(chips(page)).toContain('Pi');
expect(chosen(page)).toBe('Pi');
expect(buttons(page.body)).toEqual(['Remove', 'Stop', 'Start a session']);
const launch = launcher(app);
press(page.body, 'Start a session');
await settle();
expect(launch).toHaveBeenCalledWith('pi', 'local-ollama');
});
it('while an agent installs, a session with another agent can be started', async () => {
const page = mount();
const rows = AGENTS.map((row) => (row.cli === 'pi' ? { ...row, status: 'installing' as const, actions: [] } : row));
const { app } = await opened(page, withAgents(rows, { actions: INSTALLED.install.actions }));
expect(chosen(page)).toBe('OpenCode');
const launch = launcher(app);
press(page.body, 'Start a session');
await settle();
expect(launch).toHaveBeenCalledWith('opencode', 'local-ollama');
});
it('a failed install: the server sentence on the chip that failed, the installer words folded away, and try again', async () => {
const page = mount();
const rows = AGENTS.map((row) =>
row.cli === 'pi'
? {
...row,
error: {
message: { text: LOCAL_MODEL_INSTALL_LABELS.errHarnessFailed, vars: { cli: 'Pi' } },
detail: 'npm ERR! <b>network</b> request failed',
},
}
: row
);
await opened(page, withAgents(rows));
// Not shown under another agent.
expect(page.body.querySelector('.lm-agent-about .lm-notice')).toBeNull();
pick(page, 'Pi');
expect(texts(page.body, '.lm-agent-about .lm-notice-text')).toEqual(['Pi could not be installed.']);
const detail = page.body.querySelector('.lm-agent-about .lm-detail-text')!;
// Someone else's text: shown as text, never as markup.
expect(detail.textContent).toBe('npm ERR! <b>network</b> request failed');
expect(detail.querySelector('b')).toBeNull();
expect(buttons(page.body)).toEqual(['Remove', 'Stop', 'Install Pi']);
// The model itself has no error: the headline still says ready.
expect(texts(page.body, '.lm-title')).toEqual(['Qwen3.6 35B-A3B is ready on this Mac.']);
});
it('an agent that needs a setup of its own says where, and has nothing to press', async () => {
const page = mount();
const { app } = await opened(page, WITH_AGENTS);
pick(page, 'DeepSeek');
expect(texts(page.body, '.lm-agent-about .lm-aside')).toEqual([
'DeepSeek needs a setup of its own. Set it up from the Run menu, then start a session with it here.',
]);
expect(buttons(page.body)).toEqual(['Remove', 'Stop']);
expect(verbs(app)).toEqual([]);
});
it('with no agent that can be started the main button installs the default one', async () => {
const page = mount();
const rows: LocalModelHarnessRow[] = [
{
cli: 'opencode',
cliLabel: 'OpenCode',
default: true,
status: 'installable',
installCommand: 'curl -fsSL https://opencode.ai/install | bash',
actions: ['install'],
},
];
await opened(page, withAgents(rows, { actions: ['stop', 'install', 'install-agent', 'remove'] }));
expect(buttons(page.body)).toEqual(['Remove', 'Stop', 'Install OpenCode']);
expect(texts(page.body, '.lm-command')).toEqual(['curl -fsSL https://opencode.ai/install | bash']);
});
it('a stopped model: Start stays the one main button, and an agent can still be installed', async () => {
const page = mount();
const rows = AGENTS.map((row) => (row.status === 'ready' ? { ...row, actions: [] } : row));
const { app } = await opened(
page,
withAgents(rows, { running: false, actions: ['start', 'install', 'install-agent', 'remove'] }),
() => ok(withAgents(rows, { running: false, actions: ['start', 'install', 'remove'] }).install)
);
expect(buttons(page.body)).toEqual(['Remove', 'Start']);
pick(page, 'Pi');
expect(buttons(page.body)).toEqual(['Remove', 'Start', 'Install Pi']);
const primary = frameOf(page.body).querySelectorAll('.lm-buttons .wt-btn-primary');
expect([...primary].map((el) => el.textContent)).toEqual(['Start']);
press(page.body, 'Install Pi');
await settle();
expect(verbs(app)).toEqual([['POST', '/api/local-model/agent', { cli: 'pi' }]]);
});
it('moves the selection with the arrow keys, Home and End, and the focus follows', async () => {
const page = mount();
await opened(page, WITH_AGENTS);
page.body.querySelector<HTMLElement>('.lm-agent[aria-checked="true"]')!.focus();
const key = (name: string) => {
const event = new page.dom.window.KeyboardEvent('keydown', { key: name, bubbles: true, cancelable: true });
page.document.activeElement!.dispatchEvent(event);
return event;
};
const walk: Array<[string, string]> = [
['ArrowRight', 'Claude Code'],
['ArrowDown', 'Pi'],
['ArrowLeft', 'Claude Code'],
['ArrowUp', 'OpenCode'],
// The ends wrap.
['ArrowLeft', 'DeepSeek'],
['ArrowRight', 'OpenCode'],
['End', 'DeepSeek'],
['Home', 'OpenCode'],
];
for (const [name, agent] of walk) {
const event = key(name);
expect(event.defaultPrevented, name).toBe(true);
expect(chosen(page), name).toBe(agent);
const active = page.document.activeElement!;
expect(active.classList.contains('lm-agent'), name).toBe(true);
expect(active.getAttribute('aria-checked'), name).toBe('true');
}
// Any other key is left alone.
expect(key('a').defaultPrevented).toBe(false);
});
it('is not on the screen that ends an install, and not while something blocks every session', async () => {
const page = mount();
const { app, serve } = await opened(page, INSTALLING);
serve(WITH_AGENTS);
await page.tick();
// The install just finished in this window: one thing to do.
expect(page.body.querySelector('.lm-agents')).toBeNull();
expect(buttons(page.body)).toEqual(['Start a session']);
const launch = launcher(app);
press(page.body, 'Start a session');
await settle();
// The agent that was chosen for the install: the server's default.
expect(launch).toHaveBeenCalledWith('opencode', 'local-ollama');
const blocked = mount();
await opened(
blocked,
withAgents(
AGENTS.map((row) => ({ ...row, actions: row.actions.filter((action) => action !== 'start-session') })),
{
actions: ['stop', 'install', 'remove'],
error: {
code: 'model-changed',
message: { text: LOCAL_MODEL_INSTALL_LABELS.errModelChanged },
next: 'remove',
},
}
)
);
expect(blocked.body.querySelector('.lm-agents')).toBeNull();
expect(buttons(blocked.body)).not.toContain('Start a session');
});
it('an agent name is text of someone else: shown as text', async () => {
const page = mount();
const rows = AGENTS.map((row) =>
row.cli === 'pi'
? { ...row, cliLabel: '<img src=x onerror=alert(1)>', installCommand: '<script>x</script>' }
: row
);
await opened(page, withAgents(rows));
pick(page, '<img src=x onerror=alert(1)>');
expect(page.body.querySelector('.lm-agents img, .lm-agents script')).toBeNull();
expect(texts(page.body, '.lm-command')).toEqual(['<script>x</script>']);
expect(buttons(page.body)).toContain('Install <img src=x onerror=alert(1)>');
});
it('in Chinese: the label, the tags, the line and the button', async () => {
const page = mount({ i18n: true });
page.win.CodemanI18n.start();
page.win.CodemanI18n.configure({ language: 'zh-CN' });
await opened(page, WITH_AGENTS);
expect(texts(page.body, '.lm-agents-label')).toEqual(['开始会话时使用']);
expect(texts(page.body, '.lm-agent .lm-tag')).toEqual(['未安装', '需要设置']);
pick(page, 'Pi');
expect(texts(page.body, '.lm-agent-about .lm-aside')).toEqual([
'此 Mac 上尚未安装 Pi。Codeman 会用下面这条命令安装它:',
]);
expect(buttons(page.body)).toContain('安装 Pi');
});
it('a server that lists no agents (an older one): the one agent of the install, as before', async () => {
const page = mount();
const { app } = await opened(page, INSTALLED);
expect(page.body.querySelector('.lm-agents')).toBeNull();
expect(page.body.textContent).toContain('Runs with OpenCode.');
const launch = launcher(app);
press(page.body, 'Start a session');
await settle();
expect(launch).toHaveBeenCalledWith('opencode', 'local-ollama');
});
});
describe('what an earlier Remove left on disk', () => {
const LEFT = status({}, { store: STORE_ONE, actions: ['install', 'remove'] });