Merge #806: pick the coding agent per session, with Pi and DeepSeek Harness, and install a missing one

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-11 20:15:38 +01:00
commit f7fccc5dfc
26 files changed
+2013 -113

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L
**Opened outside Codeman** (`foreign-sessions.js`, both home screens): the tmux sessions a human started, listed from `GET /api/mux/foreign` (root CLAUDE.md, Adopted tmux sessions). ONE renderer, `renderForeignSessions(container)`, fills the welcome block and the phone overview's, and every row goes through `textContent`, since a session name and a command line come from someone else's process. ⚠️ It polls only while a home screen is up (`startForeignPolling`/`stopForeignPolling` from `showWelcome()`/`hideWelcome()`) and the tab is visible (`_foreignPollTick()` is the one gate, and `visibilitychange` catches up; the cache TTL sits under the poll interval, so one tab's every tick is a full socket sweep), and the poll is local only: the docker and ssh scan costs one connection per target, so it runs once on the toggle and again on Rescan, and its rows and notes are kept apart (`_foreignWideSessions`, `_foreignWideNotes`) or the next local poll would wipe them. ⚠️ A 403 is a non-admin in multi-user mode, an answer and not a failed poll: `_foreignRefused` stops the polling and shows no block. ⚠️ `closeSession()` re-reads the list after an adopted tab's DELETE, since the home screen's own load races it and the row would say `Go to tab` until the next poll. ⚠️ An adopted tab has no kill outcome to offer, so the close dialog hides the red button and always tears the wrapper down. ⚠️ `session.remote` and `session.docker` are undefined on an adopted session, so a check that hides a row for those two usually needs `session.adopt` as well. Tests: `test/foreign-sessions-ui.test.ts`, `test/foreign-sessions-i18n.test.ts` (harvests every string from the real module).
**Run a model on this Mac** (`local-model-ui.js`; welcome button `#welcomeLocalModelBtn`, chooser window `#localModelModal`, App Settings > Models row `#localModelSettings`; server rules in the root CLAUDE.md, Local model): ONE window does everything (choose, confirm, progress, paused, failed, installed, no recommendation); the button and the Settings row only open it. ⚠️ The models on this Mac (`install.library`) are ONE list builder, `_localModelLibraryEl()`: on the installed screen always (the model in use first, in the chooser's selected look, each row with the context it was checked with, a state tag and its size on disk), on a paused or failed screen only when a row offers something (the way back to an earlier model), never on the screen that ends an install. A row has "Use" and "Delete" only for what the server lists for THAT row (`row.actions`); Use is a switch with no confirm screen (nothing is downloaded), Delete asks once in place under its row (`.lm-lib-ask`, the one red button, the focus on Cancel), and the asked row keeps its buttons unseen (`.lm-lib-actions-away`) so the sizes do not jump sideways. Under the list: what all downloads take (`install.store`) and "Add a model", which opens the chooser from an installed model; there a row with `candidate.library` says "In use" or "On this Mac" and the main button becomes a disabled "In use" or "Use this model". With nothing installed and a store an earlier Remove kept, the chooser and the nothing-fits screen say what it takes and offer "Delete them" (`_localModelStoreEl()`). ⚠️ A screen that carries the list sets `data-long` on the body, which switches it from the centred short-screen layout (bottom-aligned on a phone) to top-aligned: a centred flex column that overflows cuts off its first lines. ⚠️ The row buttons live in `.lm-lib-actions`, not `.lm-buttons` (the screen's own buttons in the foot), and are a size smaller (`.lm-btn-row`). ⚠️ A job whose steps hold no `model` step is a switch (`localModelIsSwitch()`) and is named one ("Switching to", no download bar). Which screen shows follows `install.state` of `GET /api/local-model`; the page itself holds only the selection and whether the person is on the chooser or the confirm screen. ⚠️ The window is ONE frame for the whole flow: a fixed height on desktop (`.modal-content.local-model-window`), App Settings' boxed close button, the body scrolling between the header and a foot of its own (`#localModelWindowFoot`): every screen's last part (`.lm-foot`, or the `.lm-remove` question) is moved there by `_renderLocalModelWindow()`, so a button never moves away from under the pointer and is never clipped; a test that looks for a button looks in the frame, not the body. The short screens are centred in that frame on desktop and sit above the buttons on a phone (`data-screen` on the body). ⚠️ The memory bar (`.lm-bar`, `role="meter"`) is the one strong element: filled to the selected row's `budgetShare`, the model at its PEAK (the legend says so, and the installed line uses the same words beside what the model takes now, so the two figures are never read as a contradiction), the memory map (`Candidate.memory`: the model, its context and the brief peaks side by side, each named in the legend, on a track of `--text-muted` at about a third) in the feature's own colours (`--lm-*`: white for the feature, turned over to dark ink on the light skins, blue the context, green good, amber tight, orange slow, rose the brief peaks, deeper on the light skins), never `--accent`, which the owner rejected as too much blue (about 3:1 against the window, so the free part can be seen; a border token is 1.5:1 and the inputs' `--bg-input` is the window's own surface on the dark skins), 10px, no gradient or glow, and its width transition is the only motion (off under `prefers-reduced-motion`); a repaint starts each bar at the last width of its kind, so keep `_settleLocalModelBars()` after every body write. The figure beside it is an estimate and says "about" in whole GB (`localModelWholeGb()` on the server's text); only the download figure keeps tabular figures. ⚠️ The rows are the server's pick first, then the other models by download size, largest first (`localModelCandidates()`): the server's alternatives are its ranking, which no column shows. ⚠️ The download bar means ONE thing, the model download: at the start while the runtime is fetched, gone once the model is in (the step list carries verify, agent and connect); the first paint after an install finished shows "Start a session" alone (`justInstalled`), an error on an installed model is the headline with a grey dot, and Remove is quiet everywhere but red in its own question, never the accent. ⚠️ The window polls the GET once a second WHILE OPEN and never otherwise (no SSE event): `closeLocalModelWindow()` clears the timer, a background tab asks nothing, an unchanged answer repaints nothing, and a tick that moved only the download reLine truncated
**Run a model on this Mac** (`local-model-ui.js`; welcome button `#welcomeLocalModelBtn`, chooser window `#localModelModal`, App Settings > Models row `#localModelSettings`; server rules in the root CLAUDE.md, Local model): ONE window does everything (choose, confirm, progress, paused, failed, installed, no recommendation); the button and the Settings row only open it. ⚠️ The models on this Mac (`install.library`) are ONE list builder, `_localModelLibraryEl()`: on the installed screen always (the model in use first, in the chooser's selected look, each row with the context it was checked with, a state tag and its size on disk), on a paused or failed screen only when a row offers something (the way back to an earlier model), never on the screen that ends an install. A row has "Use" and "Delete" only for what the server lists for THAT row (`row.actions`); Use is a switch with no confirm screen (nothing is downloaded), Delete asks once in place under its row (`.lm-lib-ask`, the one red button, the focus on Cancel), and the asked row keeps its buttons unseen (`.lm-lib-actions-away`) so the sizes do not jump sideways. Under the list: what all downloads take (`install.store`) and "Add a model", which opens the chooser from an installed model; there a row with `candidate.library` says "In use" or "On this Mac" and the main button becomes a disabled "In use" or "Use this model". With nothing installed and a store an earlier Remove kept, the chooser and the nothing-fits screen say what it takes and offer "Delete them" (`_localModelStoreEl()`). ⚠️ A screen that carries the list sets `data-long` on the body, which switches it from the centred short-screen layout (bottom-aligned on a phone) to top-aligned: a centred flex column that overflows cuts off its first lines. ⚠️ The row buttons live in `.lm-lib-actions`, not `.lm-buttons` (the screen's own buttons in the foot), and are a size smaller (`.lm-btn-row`). ⚠️ A job whose steps hold no `model` step is a switch (`localModelIsSwitch()`) and is named one ("Switching to", no download bar). Which screen shows follows `install.state` of `GET /api/local-model`; the page itself holds only the selection and whether the person is on the chooser or the confirm screen. ⚠️ The window is ONE frame for the whole flow: a fixed height on desktop (`.modal-content.local-model-window`), App Settings' boxed close button, the body scrolling between the header and a foot of its own (`#localModelWindowFoot`): every screen's last part (`.lm-foot`, or the `.lm-remove` question) is moved there by `_renderLocalModelWindow()`, so a button never moves away from under the pointer and is never clipped; a test that looks for a button looks in the frame, not the body. The short screens are centred in that frame on desktop and sit above the buttons on a phone (`data-screen` on the body). ⚠️ The memory bar (`.lm-bar`, `role="meter"`) is the one strong element: filled to the selected row's `budgetShare`, the model at its PEAK (the legend says so, and the installed line uses the same words beside what the model takes now, so the two figures are never read as a contradiction), the memory map (`Candidate.memory`: the model, its context and the brief peaks side by side, each named in the legend, on a track of `--text-muted` at about a third) in the feature's own colours (`--lm-*`: white for the feature, turned over to dark ink on the light skins, blue the context, green good, amber tight, orange slow, rose the brief peaks, deeper on the light skins), never `--accent`, which the owner rejected as too much blue (about 3:1 against the window, so the free part can be seen; a border token is 1.5:1 and the inputs' `--bg-input` is the window's own surface on the dark skins), 10px, no gradient or glow, and its width transition is the only motion (off under `prefers-reduced-motion`); a repaint starts each bar at the last width of its kind, so keep `_settleLocalModelBars()` after every body write. The figure beside it is an estimate and says "about" in whole GB (`localModelWholeGb()` on the server's text); only the download figure keeps tabular figures. ⚠️ The rows are the server's pick first, then the other models by download size, largest first (`localModelCandidates()`): the server's alternatives are its ranking, which no column shows. ⚠️ The download bar means ONE thing, the model download: at the start while the runtime is fetched, gone once the model is in (the step list carries verify, agent and connect); the first paint after an install finished shows "Start a session" alone (`justInstalled`), an error on an installed model is the headline with a grey dot, and Remove is quiet everywhere but red in its own question, never the accent. ⚠️ The window polls the GET once a second WHILE OPEN and never otherwise (no SSE event): `closeLocalModelWindow()` clears the timer, a background tab asks nothing, an unchanged answer repaints nothing, and a tick that moved only the download reLine truncated
**Home-screen session order** (`CodemanSessionOrder` in constants.js, pure): BOTH home screens (phone overview, desktop rail) must order rows through this ONE comparator. Rank `needs` → `error` → `waiting` → `working` → `idle` → `done`. ⚠️ The tiebreak flips: states a session is still IN sort oldest-first, states it has STOPPED sort newest-first. ⚠️ The running group keys off `lastSubmitAt`, never `lastActivityAt` (a working pane repaints constantly). ⚠️ A 0 stamp means unknown and sorts last within its state. Final tiebreak is `orderIndex`, so the list never shuffles. The tab strip itself is NOT sorted by this. Test: `test/session-overview-order.test.ts`. → [architecture-invariants#home-screen-session-order](../../docs/architecture-invariants.md#home-screen-session-order)
+14 -2
View File
@@ -1540,6 +1540,18 @@
'Takes {memory} GB of memory now.': '目前占用 {memory} GB 内存。',
'All of it is on the GPU.': '全部位于 GPU 上。',
'Start a session': '开始会话',
// The coding agents of an installed model: one chip each, and the line under the selected one.
'Start a session with': '开始会话时使用',
Installing: '正在安装',
'Not installed': '未安装',
'Needs setup': '需要设置',
'Install {cli}': '安装 {cli}',
'Installing {cli}. You can start a session with another agent meanwhile.':
'正在安装 {cli}。在此期间,你可以用其他智能体开始会话。',
'{cli} is not on this Mac yet. Codeman installs it with this command:':
'此 Mac 上尚未安装 {cli}。{name} 会用下面这条命令安装它:',
'{cli} needs a setup of its own. Set it up from the Run menu, then start a session with it here.':
'{cli} 需要单独设置。请先在"运行"菜单中完成设置,然后就可以在这里用它开始会话。',
'Remove the local model from this Mac?': '要从此 Mac 移除本地模型吗?',
'Also delete the downloaded model': '同时删除已下载的模型',
'The coding agent stays installed.': '编程智能体会保留,不会被卸载。',
@@ -1628,8 +1640,8 @@
'此 Mac 目前只使用 {model}。请先在本地模型窗口中切换模型。',
'This model is not one of the checked models on this Mac.': '该模型不在此 Mac 上已检查的模型之列。',
'This model is not on this Mac.': '此 Mac 上没有这个模型。',
'{cli} is not installed on this Mac. Install this model again to choose a coding agent.':
'此 Mac 上没有安装 {cli}。请重新安装此模型,以便选择编程智能体。',
'{cli} is not installed on this Mac. Install a coding agent in the local model window first.':
'此 Mac 上没有安装 {cli}。请先在本地模型窗口中安装一个编程智能体。',
'{model} could not be deleted from this Mac.': '无法从此 Mac 删除 {model}。',
// What the endpoint routes answer for the record of the model on this Mac (shown as a toast).
'This endpoint belongs to the model Codeman runs on this Mac. Change or remove it in the local model window.':
+252 -12
View File
@@ -13,6 +13,7 @@
* POST /api/local-model/runtime { action: 'start' | 'stop', newPort? }
* DELETE /api/local-model { removeModel }
* DELETE /api/local-model/models { modelId }
* POST /api/local-model/agent { cli }
*
* ## Three surfaces, one window
*
@@ -35,9 +36,11 @@
* | `progress` | installing: the download bar, the steps, Cancel |
* | `paused` | paused (Cancel or a server restart): Continue or Remove |
* | `failed` | failed: the server's sentence and the ONE action that helps |
* | `installed` | installed: running or stopped, the models on this Mac with their |
* | | size on disk (Use, Delete), Add a model, Start a session, |
* | | Stop/Start, Remove (right after an install: Start a session alone) |
* | `installed` | installed: running or stopped, the coding agents a session can be |
* | | started with, the models on this Mac with their size on disk |
* | | (Use, Delete), Add a model, Start a session (or "Install <agent>" |
* | | for one that is not on this Mac), Stop/Start, Remove (right after |
* | | an install: Start a session alone) |
* | `none` | idle and nothing fits: the hardware line, the reason, Close |
*
* The memory bar is the one strong element: the memory this Mac can give a model, filled to
@@ -61,6 +64,16 @@
* models (`install.store`) and "Add a model". A row has a button only for an action the server
* lists for THAT row (`row.actions`).
*
* The coding agent is chosen per session (`install.harnesses`): on the installed screen every
* agent the model can be run with is a chip of one radio group, the server's default first.
* The main button follows the selected chip: "Start a session" for one that can be started,
* "Install <agent>" for one that is not on this Mac (its literal install command is on screen
* above the button, so the click is the consent), and nothing to press for one that needs a
* setup of its own. An install of an agent runs beside the model: the state stays `installed`,
* and another agent can be started meanwhile. The device remembers the agent a session was
* last STARTED with, and each opening of the window selects it while it can be started (a
* chip that was only looked at is not a choice, or the window would reopen on "Install").
*
* ## Polling
*
* The window asks the GET once a second WHILE IT IS OPEN, and never otherwise (there is no SSE
@@ -115,6 +128,9 @@ const LOCAL_MODEL_POLL_MS = 1000;
/** What `confirmDelete` holds while the question is about everything an earlier Remove kept. No model id has a space. */
const LOCAL_MODEL_STORE_KEY = 'the store';
/** Where this device remembers the coding agent last chosen for a session (a CLI id, as data). */
const LOCAL_MODEL_AGENT_STORAGE_KEY = 'codeman-local-model-agent';
/** The tag kinds of the server's pick (`CandidateTagKind`): the ones drawn in the accent colour. */
const LOCAL_MODEL_ACCENT_TAGS = ['tested', 'best', 'best-tight'];
@@ -240,6 +256,39 @@ function localModelLibraryTag(row) {
return { text: localModelT('Not checked'), kind: 'unverified' };
}
/** The rows of `install.harnesses`: the coding agents the model in use can be run with. A payload without the list has none. */
function localModelAgents(install) {
return (Array.isArray(install.harnesses) ? install.harnesses : []).filter(
(row) => row && typeof row.cli === 'string' && row.cli
);
}
/** What an agent chip says beside the name, and the tag class that colours it. Nothing for one that can be started. */
function localModelAgentTag(row) {
if (row.status === 'installing') return { text: localModelT('Installing'), kind: 'tight' };
if (row.status === 'installable') return { text: localModelT('Not installed'), kind: 'unverified' };
if (row.status === 'setup-needed') return { text: localModelT('Needs setup'), kind: 'unverified' };
return null;
}
/** The coding agent this device chose last, or '' (storage can be empty or refused: the default agent stands then). */
function localModelStoredAgent() {
try {
const value = window.localStorage.getItem(LOCAL_MODEL_AGENT_STORAGE_KEY);
return typeof value === 'string' ? value : '';
} catch {
return '';
}
}
function localModelStoreAgent(cli) {
try {
window.localStorage.setItem(LOCAL_MODEL_AGENT_STORAGE_KEY, String(cli));
} catch {
/* a convenience only */
}
}
/**
* The coding agents a row can run with. A payload without the list means the one agent of the
* row's flat fields.
@@ -545,6 +594,11 @@ Object.assign(CodemanApp.prototype, {
modelId: null,
/** The selected coding agent (a CLI id, as data), or null for the row's first. */
cli: null,
/**
* The coding agent chosen for a session on the installed model (a CLI id, as data), or
* null: what this device chose last, else the server's default.
*/
agent: null,
/** A verb is in flight: every button waits. */
busy: false,
/** What the last verb answered when it was refused. */
@@ -580,6 +634,26 @@ Object.assign(CodemanApp.prototype, {
return { candidates, candidate, harnesses, harness };
},
/**
* The coding agents of the installed model and the one a session would start with: the chip
* selected in this opening of the window, else the agent this device last STARTED a session
* with while it can still be started, else the server's default (its first row). A
* remembered agent that is not startable now never wins: the window would open on "Install"
* or on nothing to press, with "Start a session" out of sight. `row` is null when the server
* lists none.
*/
_localModelAgent() {
const ui = this._localModelWindowState();
const rows = localModelAgents(localModelInstall(this._localModelStatus));
const stored = ui.agent ? '' : localModelStoredAgent();
const row =
rows.find((entry) => entry.cli === ui.agent) ||
rows.find((entry) => entry.cli === stored && entry.status === 'ready') ||
rows.find((entry) => entry.default === true) ||
rows[0];
return { rows, row: row || null };
},
/** Which screen the window shows, see the table in @fileoverview. */
_localModelScreen() {
const ui = this._localModelWindowState();
@@ -615,6 +689,9 @@ Object.assign(CodemanApp.prototype, {
busy: false,
notice: null,
expected: null,
// A chip that was only looked at in an earlier opening is not a choice: each opening
// starts from the agent last STARTED on this device, else the server's default.
agent: null,
confirmRemove: false,
confirmDelete: null,
justInstalled: false,
@@ -845,6 +922,28 @@ Object.assign(CodemanApp.prototype, {
if (asked) this._focusLocalModelWindow(asked === LOCAL_MODEL_STORE_KEY ? 'store-delete' : `delete:${asked}`);
},
/**
* Select a coding agent for the next session. Nothing is sent, and nothing is remembered
* yet: a chip can be selected just to see what installing it would run. The device
* remembers an agent once a session was started with it.
*/
selectLocalModelAgent(cli) {
const ui = this._localModelWindowState();
if (ui.busy || typeof cli !== 'string' || !cli) return;
ui.agent = cli;
ui.notice = null;
this.renderLocalModel();
},
/**
* "Install <agent>": the consent click for the command shown above the button. The server
* runs its own stock command for that agent, never text from here, and answers at once: the
* install goes on beside the model and the next polls say how it stands.
*/
installLocalModelAgent(cli) {
return this._localModelVerb('POST', '/api/local-model/agent', { cli });
},
cancelLocalModelInstall() {
return this._localModelVerb('POST', '/api/local-model/cancel');
},
@@ -873,20 +972,24 @@ Object.assign(CodemanApp.prototype, {
},
/**
* "Start a session": a session on the saved connection with the coding agent of the install.
* "Start a session": a session on the saved connection with a coding agent: `cli` (the
* chip that is selected), or without one the server's default agent (`install.cli`).
* The page's own copies are stale right after an install (the settings flag was switched on
* by the server and the agent may have been installed a moment ago), so both are read again
* before the existing launcher runs. Both values are the payload's; no id is compared.
*/
async startLocalModelSession() {
async startLocalModelSession(cli) {
const install = localModelInstall(this._localModelStatus);
if (typeof install.cli !== 'string' || typeof install.endpointId !== 'string') return;
const agent = typeof cli === 'string' && cli ? cli : install.cli;
if (typeof agent !== 'string' || typeof install.endpointId !== 'string') return;
// The agent a session was started with is the one the next opening selects.
if (typeof cli === 'string' && cli) localModelStoreAgent(cli);
const settingsOpen = document.getElementById('appSettingsModal')?.classList.contains('active');
this.closeLocalModelWindow();
if (settingsOpen) this.closeAppSettings?.();
await this.loadAppSettingsFromServer?.();
await this.loadCliListForSettings?.();
await this.selectCustomModelEntry?.(install.cli, install.endpointId);
await this.selectCustomModelEntry?.(agent, install.endpointId);
},
// ═══════════════════════════════════════════════════════════════
@@ -1495,6 +1598,107 @@ Object.assign(CodemanApp.prototype, {
return box;
},
/**
* The coding agents a session on the installed model can be started with
* (`install.harnesses`): one chip per agent, a radio group, and under it one line about the
* selected one. For an agent that is not on this Mac that line is the literal install command
* (the main button then reads "Install <agent>"), and after a failed install the server's
* sentence with the installer's last words folded away. `null` when the server lists none.
*/
_localModelAgentsEl() {
const ui = this._localModelWindowState();
const { rows, row: chosen } = this._localModelAgent();
if (!rows.length || !chosen) return null;
const section = localModelEl('div', 'lm-agents');
const label = localModelEl('p', 'lm-agents-label', localModelT('Start a session with'));
label.id = 'localModelAgentsLabel';
section.appendChild(label);
const group = localModelEl('div', 'lm-agent-list');
group.setAttribute('role', 'radiogroup');
group.setAttribute('aria-labelledby', 'localModelAgentsLabel');
for (const row of rows) {
const on = row === chosen;
const chip = localModelEl('button', on ? 'lm-agent lm-agent-on' : 'lm-agent');
chip.type = 'button';
chip.setAttribute('role', 'radio');
chip.setAttribute('aria-checked', on ? 'true' : 'false');
// One tab stop for the group: the selected chip.
chip.tabIndex = on ? 0 : -1;
chip.dataset.lmKey = `agent:${row.cli}`;
chip.disabled = ui.busy;
const radio = localModelEl('span', 'lm-radio');
radio.setAttribute('aria-hidden', 'true');
chip.appendChild(radio);
chip.appendChild(localModelEl('span', 'lm-agent-name', String(row.cliLabel || row.cli)));
const tag = localModelAgentTag(row);
if (tag) chip.appendChild(localModelEl('span', `lm-tag lm-tag-${tag.kind}`, tag.text));
chip.addEventListener('click', () => this.selectLocalModelAgent(row.cli));
group.appendChild(chip);
}
group.addEventListener('keydown', (event) => this._onLocalModelAgentKey(event));
section.appendChild(group);
const name = String(chosen.cliLabel || chosen.cli);
const about = localModelEl('div', 'lm-agent-about');
if (chosen.status === 'installable' || chosen.status === 'installing') {
const lead =
chosen.status === 'installing'
? localModelT('Installing {cli}. You can start a session with another agent meanwhile.', { cli: name })
: localModelT('{cli} is not on this Mac yet. Codeman installs it with this command:', { cli: name });
about.appendChild(localModelEl('p', 'lm-aside', lead));
if (chosen.installCommand) about.appendChild(localModelEl('code', 'lm-command', String(chosen.installCommand)));
} else if (chosen.status === 'setup-needed') {
about.appendChild(
localModelEl(
'p',
'lm-aside',
localModelT(
'{cli} needs a setup of its own. Set it up from the Run menu, then start a session with it here.',
{
cli: name,
}
)
)
);
} else if (chosen.slowFirstTurn === true) {
about.appendChild(localModelEl('p', 'lm-aside', localModelT('The first answer can take minutes.')));
}
// The last install of this agent failed: the server's sentence, and what the installer said.
const error = chosen.status === 'installable' ? chosen.error : null;
if (error && error.message) {
const failed = localModelEl('div', 'lm-notice');
failed.setAttribute('role', 'alert');
failed.appendChild(localModelEl('p', 'lm-notice-text', localModelMessage(error.message)));
if (typeof error.detail === 'string' && error.detail) {
const details = localModelEl('details', 'lm-details');
details.appendChild(localModelEl('summary', '', localModelT('Details')));
details.appendChild(localModelEl('pre', 'lm-detail-text', error.detail));
failed.appendChild(details);
}
about.appendChild(failed);
}
if (about.childElementCount) section.appendChild(about);
return section;
},
/** Arrow keys, Home and End move the selection of the agent chips, and the focus with it. */
_onLocalModelAgentKey(event) {
const { rows, row } = this._localModelAgent();
if (!rows.length || !row) return;
const index = rows.indexOf(row);
let next = -1;
if (event.key === 'ArrowDown' || event.key === 'ArrowRight') next = (index + 1) % rows.length;
else if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') next = (index - 1 + rows.length) % rows.length;
else if (event.key === 'Home') next = 0;
else if (event.key === 'End') next = rows.length - 1;
if (next < 0 || next === index) return;
event.preventDefault();
this.selectLocalModelAgent(rows[next].cli);
this._focusLocalModelWindow(`agent:${rows[next].cli}`);
},
/** Arrow keys, Home and End move the selection of the radio group, and the focus with it. */
_onLocalModelListKey(event) {
const selection = this._localModelSelection();
@@ -1962,7 +2166,9 @@ Object.assign(CodemanApp.prototype, {
state.appendChild(localModelEl('span', 'lm-state-text', error ? `${model}, ${running}` : running));
parts.push(state);
const about = [];
if (install.cliLabel) about.push(localModelT('Runs with {cli}.', { cli: String(install.cliLabel) }));
// The agents have their own block below when the server lists them; without the list, the one of the install.
const agent = this._localModelAgent().row;
if (!agent && install.cliLabel) about.push(localModelT('Runs with {cli}.', { cli: String(install.cliLabel) }));
const line = this._localModelFactsLine(install);
if (line) about.push(line);
if (about.length) parts.push(localModelEl('p', 'lm-aside', about.join(' ')));
@@ -1980,6 +2186,11 @@ Object.assign(CodemanApp.prototype, {
// The screen that ends an install has one button. Stop and Remove are for the window
// opened later (or for this one once anything else was said in it).
const ending = ui.justInstalled === true && can('start-session') && !error && !notice;
// Which coding agent the next session runs with. Not on the screen that ends an install
// (that one says one thing: the session starts with the agent that was just chosen), and
// not while something blocks every session.
const agents = ending || error ? null : this._localModelAgentsEl();
if (agents) parts.push(agents);
// Everything that is on this Mac, what it takes on disk, and the way to another model.
// Not on the screen that ends an install: that one says one thing.
const library = ending ? null : this._localModelLibraryEl(install);
@@ -2006,24 +2217,53 @@ Object.assign(CodemanApp.prototype, {
);
}
// Start is the main action of a stopped model, unless the error's own button says so already.
const startIsMain =
can('start') &&
!(error && (error.next === 'start' || error.next === 'other-port')) &&
!can('start-session') &&
!next;
if (can('start') && !(error && (error.next === 'start' || error.next === 'other-port'))) {
buttons.appendChild(
localModelButton(localModelT('Start'), {
key: can('start-session') || next ? 'start' : 'primary',
primary: !can('start-session') && !next,
key: startIsMain ? 'primary' : 'start',
primary: startIsMain,
disabled: ui.busy,
onClick: () => void this.setLocalModelRuntime('start'),
})
);
}
if (next) buttons.appendChild(next);
if (can('start-session')) {
// The main button follows the selected coding agent, by what the server offers for it.
const offers = (action) => !!agents && Array.isArray(agent?.actions) && agent.actions.includes(action);
if (agents && agent && agent.status !== 'ready') {
const name = String(agent.cliLabel || agent.cli);
if (offers('install')) {
buttons.appendChild(
localModelButton(localModelT('Install {cli}', { cli: name }), {
// A stopped model's main action is Start: installing an agent is the quiet one then.
key: startIsMain ? 'agent-install' : 'primary',
primary: !next && !startIsMain,
disabled: ui.busy,
onClick: () => void this.installLocalModelAgent(agent.cli),
})
);
} else if (agent.status === 'installing') {
buttons.appendChild(
localModelButton(localModelT('Installing {cli}', { cli: name }), {
key: startIsMain ? 'agent-install' : 'primary',
primary: !next && !startIsMain,
disabled: true,
})
);
}
// An agent that needs a setup of its own has nothing to press: the line above says where.
} else if (agents ? offers('start-session') : can('start-session')) {
buttons.appendChild(
localModelButton(localModelT('Start a session'), {
key: 'primary',
primary: !next,
disabled: ui.busy,
onClick: () => void this.startLocalModelSession(),
onClick: () => void this.startLocalModelSession(agents && agent ? agent.cli : undefined),
})
);
}
+88 -1
View File
@@ -23318,6 +23318,88 @@ html[data-skin='rose-pine-dawn'] {
accent-color: var(--lm-brand);
}
/* ── the coding agents of an installed model ─────────────────────── */
/* One chip per agent a session can be started with, as a radio group: the
selected one in the look of the selected model row, a tag on the ones that
are not on this Mac. Under them, one line about the selected one. */
.lm-agents {
display: flex;
flex-direction: column;
gap: 0.45rem;
}
.lm-agents-label {
font-size: 0.7rem;
color: var(--text-dim);
}
.lm-agent-list {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
}
.lm-agent {
display: inline-flex;
align-items: center;
gap: 0.45rem;
min-height: 2.1rem;
padding: 0 0.7rem 0 0.6rem;
border: 1px solid var(--border);
border-radius: 9px;
background: transparent;
color: var(--text);
font: inherit;
font-size: 0.8rem;
cursor: pointer;
transition:
background var(--transition-smooth),
border-color var(--transition-smooth);
}
.lm-agent:hover:not(:disabled) {
background: var(--control-bg);
}
.lm-agent:focus-visible {
outline: 2px solid var(--lm-brand);
outline-offset: 1px;
}
.lm-agent:disabled {
cursor: default;
}
.lm-agent-on,
.lm-agent-on:hover:not(:disabled) {
border-color: color-mix(in srgb, var(--lm-brand) 55%, var(--border));
background: linear-gradient(
90deg,
color-mix(in srgb, var(--lm-brand) 17%, transparent),
color-mix(in srgb, var(--lm-brand) 5%, transparent)
);
}
.lm-agent .lm-radio {
flex: none;
}
.lm-agent-on .lm-radio {
border-color: var(--lm-brand);
background: radial-gradient(circle, var(--lm-brand) 0 3px, transparent 3.5px);
}
.lm-agent-name {
font-weight: 600;
white-space: nowrap;
}
.lm-agent-about {
display: flex;
flex-direction: column;
gap: 0.3rem;
}
/* ── the models on this Mac ───────────────────────────────────────── */
/* Name with its context, state, size on disk, and what can be done with the
row. One grid like the chooser's, so the sizes line up down the list. The
@@ -23552,7 +23634,8 @@ html[data-skin='rose-pine-dawn'] {
@media (prefers-reduced-motion: reduce) {
.lm-bar-fill,
.lm-model {
.lm-model,
.lm-agent {
transition: none;
}
}
@@ -23563,6 +23646,10 @@ html[data-skin='rose-pine-dawn'] {
min-height: 2.9rem;
}
.lm-agent {
min-height: 2.6rem;
}
.local-model-window .wt-btn.lm-btn.lm-btn-row {
min-height: 36px;
}
+14 -1
View File
@@ -12,6 +12,7 @@
* | `POST /api/local-model/runtime` | `LocalModelRuntimeRequest` | the install view; 409 |
* | `DELETE /api/local-model` | `LocalModelRemoveRequest` | the install view; 409 |
* | `DELETE /api/local-model/models` | `LocalModelDeleteRequest` | the install view; 400, 409, 500 |
* | `POST /api/local-model/agent` | `LocalModelAgentRequest` | the install view; 400, 409 |
*
* The GET is built from the hardware probe, the catalogue, the harness facts and the pure
* `recommend()`, plus the `install` object of the install service
@@ -55,6 +56,10 @@
* - `DELETE /api/local-model/models` takes a model NAME in its body, never a path: the schema
* admits only `name:tag`, and the service deletes only a name of its own listing, through
* the runtime.
* - `POST /api/local-model/agent` installs one more coding agent beside an installed model.
* Its body names a CLI id only: the service takes it only when it is a row of the view's
* `harnesses` that offers `install`, and runs the compiled stock command, never text from
* the request. It looks at no session: nothing about the model in use changes.
* - Every dependency is injected (`LocalModelRouteDeps`), so a route test spawns nothing and
* does not need a Mac: it passes its own hardware, harness facts and service.
*/
@@ -97,6 +102,7 @@ import {
} from '../../local-model/install-job.js';
import { recommend } from '../../local-model/recommend.js';
import {
LocalModelAgentSchema,
LocalModelDeleteSchema,
LocalModelInstallSchema,
LocalModelRemoveSchema,
@@ -261,7 +267,7 @@ export function registerLocalModelRoutes(
// The measured budget once the runtime reported it, and the runtime download that an
// install would still add: what turns the estimate into the figures of the consent.
const options = await service.recommendOptions();
const install = await service.view();
const install = await service.view({ harnessFacts });
// A row that is already a checked model on this Mac says so: choosing it is a switch.
const recommendation = markLibraryCandidates(
resolved.recommend(hardware, catalog, harnessFacts, options),
@@ -334,4 +340,11 @@ export function registerLocalModelRoutes(
const body = parseBody(LocalModelDeleteSchema, req.body);
return runVerb(reply, () => resolved.service().deleteLibraryModel(body, actorOf(req)));
});
app.post('/api/local-model/agent', async (req, reply): Promise<LocalModelVerbResponse> => {
const denied = adminOnly(req, reply);
if (denied) return denied;
const body = parseBody(LocalModelAgentSchema, req.body);
return runVerb(reply, () => resolved.service().installAgent(body, actorOf(req)));
});
}
+13 -4
View File
@@ -2495,14 +2495,20 @@ const localModelId = z
.max(200)
.regex(/^[a-z0-9][a-z0-9._-]*:[a-z0-9][a-z0-9._-]*$/, 'Invalid model id');
/**
* A coding agent as a CLI registry id. A request-shape check only: the real gate is the
* service's own lookup of the id among the catalogue harnesses it offers right now.
*/
const localModelCli = z
.string()
.max(64)
.regex(/^[a-z0-9][a-z0-9_-]*$/, 'Invalid coding agent id');
/** POST /api/local-model/install: the row the person chose and the size they confirmed. */
export const LocalModelInstallSchema = z
.object({
modelId: localModelId,
cli: z
.string()
.max(64)
.regex(/^[a-z0-9][a-z0-9_-]*$/, 'Invalid coding agent id'),
cli: localModelCli,
context: z.number().int().positive().max(MAX_DISCOVERED_CONTEXT_TOKENS),
acknowledgedBytes: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
})
@@ -2525,6 +2531,9 @@ export const LocalModelUseSchema = z.object({ modelId: localModelId }).strict();
/** DELETE /api/local-model/models: one model of the store, by its name. Never a path. */
export const LocalModelDeleteSchema = z.object({ modelId: localModelId }).strict();
/** POST /api/local-model/agent: one more coding agent to install beside an installed model. */
export const LocalModelAgentSchema = z.object({ cli: localModelCli }).strict();
/**
* A shell-safe bare word, mirroring `config/cli-registry/schema.ts`'s own `shellToken` —
* duplicated rather than imported, since the REAL safety boundary for anything built from