mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Redesign Agents & models as a roster of cards with a side drawer and an Add agent chooser
AI Assisted
This commit is contained in:
1 parent
5136269ca7
commit
0fdb99f723
9 files changed
+1035
-351
No files matched your search
@@ -34,12 +34,12 @@ One row per file under `src/web-console/public/` (the games and their sound are
|
||||
| `public/screens/git-host.js` | hosts the git board: tabs, panels and what each click sends |
|
||||
| `public/screens/help-dialog.js` | the Help dialog and the first-run Welcome (named so it is never confused with the pure help.js). Help reads right in both modes: a phrase that differs under the desktop app carries its app wording in `data-app` (swapped in by `renderAppWording()`), and a paragraph that differs is a `.for-browser` / `.for-app` sibling pair, switched by `:root.in-app` (set in `core.js` from `page.inApp`, rule in `help.css`). The older `render*Help()` functions patch a few ids the same way. `scripts/test-web-console-page-help.mjs` sweeps every topic's visible text in each mode for the other mode's wording |
|
||||
| `public/screens/looks.js` | User Preferences: the look and sound controls, which save as they change |
|
||||
| `public/screens/agents-view.js` | the agents view's mount, state and server calls, serving both User Preferences' Agents & models tab and the setup page as a master-detail split: the pickable list on the left, the picked agent's form or state in the right pane. Picking a row is the navigation; a dirty form asks the dialog's unsaved prompt first. Each form edits a draft; Save sends the saved list with only that draft swapped in (`POST /models` or `POST /agents`), Discard drops it. `hasUnsaved`, `saveOpen` and `discardOpen` feed the dialog's unsaved prompt. `mountAgentsView(container, {mode, forCli, onStart})` hands its renderers one `ctx` (state plus callbacks); `mode: "prefs"` draws the agent rows with Found / Not found on PATH badges and a v3 orchestrator placeholder, `mode: "setup"` draws the pick list (found / outside-PATH / missing states, install lines, Use it from here, templates, Start) inside a caller-supplied container |
|
||||
| `public/screens/agents-view.js` | the agents view's mount, state and server calls, serving both User Preferences' Agents & models tab and the setup page. Preferences draws a roster of agent cards with the picked agent's form in a side drawer (`data-av="drawer"`, hidden while no form is open, the roster `inert` behind it) and the Add agent chooser (`data-av="chooser"`); the setup page keeps a master-detail split, the pickable list on the left and the picked entry's state (or the same form) in the right pane. Picking a card or row is the navigation; a dirty form asks the dialog's unsaved prompt first. Each form edits a draft; Save sends the saved list with only that draft swapped in (`POST /models` or `POST /agents`), Discard drops it. `hasUnsaved`, `saveOpen` and `discardOpen` feed the dialog's unsaved prompt. `mountAgentsView(container, {mode, forCli, onStart})` hands its renderers one `ctx` (state plus callbacks); `mode: "prefs"` draws the agent cards with Found / Not found on PATH badges and the model each strength uses, `openChooser` / `startNew(template)` (the starter templates are an opt-in there, not a list section) and `closeDrawer` (Esc, the scrim and Close go through it, so a dirty draft asks first), `mode: "setup"` draws the pick list (found / outside-PATH / missing states, install lines, Use it from here, templates, Start) inside a caller-supplied container |
|
||||
| `public/screens/agents/agents-data.js` | PURE, no imports, `node --test` importable: the agents view's data helpers. `MODEL_CLIS`/`BUILT_IN` (the built-in rows, pinned to `src/launcher/agents.json` by a test), `emptyLists`, `newAgent`, `normalizeAgent`, `cliOf`/`agentId` draft keys, `savedEntry`, `canonical`/`isDirty`, `nameOf`, `modelNames`, `summaryRows`, `serverStateFor`, `cleanAgent` and `templateDraft` |
|
||||
| `public/screens/agents/agents-list-editor.js` | the one row-list editor behind the three argument lists and the models list: `listEditor({list, kind, field, placeholder, addLabel, optionalName, aria, onChange})` draws `div.agent-rows` (a Remove per row, an Add that appends and focuses the new row, edits written into the live list) |
|
||||
| `public/screens/agents/agents-summary.js` | the agents view's collection side: `renderSummary(ctx)` draws the left column for both modes (prefs rows with found badges, the shipped templates under "Or start from a template" and the orchestrator placeholder; setup pick rows, badges and templates), `drawSummaryPane(ctx)` draws the right pane while nothing is open (empty text, a picked template's note and Use this template, or the picked setup entry's state area: Start, Use it from here, install lines), plus `BADGES`/`drawBadge` |
|
||||
| `public/screens/agents/agents-form.js` | the agents view's per-agent form: `drawForm(ctx)` draws the detail pane (the built-in's Models fold, or an added agent's identity fields plus folded Models and Command-line arguments sections), `renderDirty(ctx)` toggles the Unsaved badge and Save/Discard; the foot (Save, Discard, Save anyway on 409, Delete with inline confirm), `input.invalid[data-field]` marking and the `FORM_FOCUSABLE` focus save/restore |
|
||||
| `public/screens/agents/agents-strengths.js` | the "Strengths in the loop" fold under Models in an agent's form: `strengthsFold(ctx, agentId, draft, { models, hasEffort })` maps Thrifty, Balanced and Best to one of the agent's own models (and an effort for Claude and Codex), shows untouched rows as shipped with a "default" tag and changed rows with Reset, and keeps only changed rows in `ctx.strengthDrafts` for the form's Save |
|
||||
| `public/screens/agents/agents-summary.js` | the agents view's collection side: `renderSummary(ctx)` draws the list for both modes (prefs cards with found badges and a ghost Add card; setup pick rows, badges and templates), `drawChooser(ctx)` / `markTemplateState` the Add agent sheet (a tile per shipped template, with whether its command is installed, plus Custom agent), `drawSummaryPane(ctx)` draws the setup pane while nothing is open (a picked template's note and Use this template, or the picked setup entry's state area: Start, Use it from here, install lines), plus `BADGES`/`drawBadge` |
|
||||
| `public/screens/agents/agents-form.js` | the agents view's per-agent form, the drawer's content: `drawForm(ctx)` draws the head (name, a template tag, Close), the two tabs (Models & strengths, and Launch, which a new agent opens on; `ctx.tab`), then the tab: models (the In the loop box, a model row with strength pills for each shipped model, the person's own models with Remove, an add row that moves an id and name into the draft so it never holds a half-typed model) or Launch (a built-in only reads; an added agent's name, command with Test, start prompt and the Command-line arguments fold). `renderDirty(ctx)` toggles the Unsaved badge and Save/Discard; the foot (Save, Discard, Save anyway on 409, Delete with inline confirm), `input.invalid[data-field]` marking and the `FORM_FOCUSABLE` focus save/restore |
|
||||
| `public/screens/agents/agents-strengths.js` | the strengths panel of an agent's form: `strengthsPanel(ctx, agentId, draft, { models, hasEffort })` returns the In the loop box (the model each of Thrifty, Balanced and Best resolves to, an effort select for Claude and Codex, Reset or a "default" tag) and `pills(id, label)`, the three toggle buttons each model row carries (one pressed per word; tapping the pick again clears it only where nothing ships for the word). Changed rows only are kept in `ctx.strengthDrafts` for the form's Save; `wordChip` is the colored word the cards use too |
|
||||
| `public/strengths.js` | the loop's strength rule, shared by the page and the server: `resolveStrengths` and `nextStrength`, held to `scripts/fixtures/strength-cases.json` (the Rust twin is in `models.rs`) |
|
||||
| `public/screens/setup.js` | the agent-less setup screen (`workflow === "setup"`, opened by `plan2code` or the app when no agent can run): the "No agent yet" headline, Planny's setup pose, the agent list from `mountAgentsView` in setup mode, Check again, and the "Starting <Label>..." pane after a Start send (`{i:"__start"}` via `/submit`). `setupMoved(url)` disarms the 2-minute no-page notice once the `move` event lands |
|
||||
| `public/screens/prefs-dialog.js` | User Preferences as a dialog: its four tabs (wired by `tabs.js` from `PREFS_TABS`), `openPrefs(tab)` (the one way in, loading Agents & models each time), the fading Saved mark beside a fieldset (`markSaved`), Back to default for the tab on screen, and `confirmUnsaved()`, the in-dialog Save / Discard / Keep editing prompt before Close, Esc, a backdrop click, a tab switch or picking another agent leaves an unsaved agent edit. Other screens reach it through `hooks` |
|
||||
@@ -53,7 +53,7 @@ One row per file under `src/web-console/public/` (the games and their sound are
|
||||
| `public/styles/help.css` | The help dialog, its diagrams and its tabs |
|
||||
| `public/styles/looks.css` | The looks button and the highlight swatches |
|
||||
| `public/styles/prefs.css` | User Preferences' side list of tabs, the strip below 720 px, the Saved mark, the setup screen's own chrome, and the in-dialog unsaved prompt (new classes only: the Subagents dialog shares `.looks`) |
|
||||
| `public/styles/agents.css` | the Agents & models view: the master-detail `.split` (list column, pickable `.split-row`s with `aria-current`, the `.split-pane`), badges, the form's fields, folds and foot, the models lists, the setup pane's state area, and the under-720 px single-column treatment |
|
||||
| `public/styles/agents.css` | the Agents & models view: the Preferences roster (`.roster`, `.agent-card`), the drawer (`.drawer`, `.agent-tabs`, `.agent-body`), the Add agent chooser, the strength words and pills (`.tier`, `.strength-pill`), the setup page's master-detail `.split` (list column, pickable `.split-row`s with `aria-current`, the `.split-pane`), badges, the form's fields, folds and foot, the models lists, the setup pane's state area, and the under-720 px single-column treatment |
|
||||
| `public/styles/pieces.css` | Shared pieces: cards, options, settled answers, pager, forms, checklist, markdown and the modal |
|
||||
| `public/styles/planny.css` | Planny the mascot: the flight, his moods and variants, and the wake-up |
|
||||
| `public/styles/poses.css` | The start-screen poses, one per skill. After the dashboard on purpose: its narrow-window rules override the dashboard's |
|
||||
|
||||
@@ -1758,17 +1758,17 @@ On Appearance and Sounds & activities each change saves the moment you make it,
|
||||
|
||||
### Agents & models
|
||||
|
||||
Most people never need this tab: Plan2Code finds the agents installed on the machine and ships an up-to-date model list with every release. It opens on a list of agents on the left, one row per agent with its models and whether its command was found on this machine. Picking a row opens that agent's form in the pane beside it, and **Add agent** a blank one. Under the list, **Or start from a template** offers the same starter templates the setup page has (GitHub Copilot CLI, OpenCode, Gemini CLI, Pi): picking one shows its note and **Use this template**, which opens the new-agent form prefilled rather than saving anything behind your back. Nothing on this tab saves as you type: each form has its own **Save** and **Discard**, and shows an **Unsaved** badge while it holds a change. Leaving a form with an unsaved change (another tab, picking another agent, **Close**, `Esc`) asks first: save it, discard it, or keep editing. Saving one agent never sends another's half-typed edit.
|
||||
Most people never need this tab: Plan2Code finds the agents installed on the machine and ships an up-to-date model list with every release. It opens on a roster of cards, one per agent, each showing whether its command was found on this machine, the model Thrifty, Balanced and Best use, and how many models it has. Opening a card puts that agent's form in a drawer over the roster, with two tabs: **Models & strengths** and **Launch** (a built-in's Launch tab only reads, because Plan2Code ships and updates its command). **Add agent** opens a chooser: the same starter templates the setup page has (GitHub Copilot CLI, OpenCode, Gemini CLI, Pi), each saying whether its command is installed here, or a **Custom agent**. Picking a template opens the new-agent form prefilled rather than saving anything behind your back; a template whose command an agent already uses is shown as *Already added*. Nothing on this tab saves as you type: each form has its own **Save** and **Discard**, and shows an **Unsaved** badge while it holds a change. Leaving a form with an unsaved change (another tab, **Close** on the drawer or a click outside it, **Close** on the dialog, `Esc`) asks first: save it, discard it, or keep editing. `Esc` backs out of the chooser, then the drawer, before it closes Preferences. Saving one agent never sends another's half-typed edit.
|
||||
|
||||
**Models.** The `plan2code` launcher's model menu comes from `models.json`, which every install overwrites with the authors' curated list. Each built-in agent's form (Claude, Devin, Codex) shows that list under *Comes with Plan2Code*, and below it **Models you added**, each a model id and the name shown in the menu, for a model that came out before Plan2Code was updated. Additions are kept in `~/.plan2code/models.json` and survive updates, unless the curated list now includes them; **Remove** takes one out. Restart `plan2code` to see a change. You can always run `plan2code --model <id>`, or switch model inside your agent before running a skill. Devin ids ending `-xhigh` or `-max` are refused. Maintainers refresh the curated list, and the shipped agent list's install data, with the repo-local `/plan2code-launcher-update` skill, which shows a diff and changes only what they approve.
|
||||
|
||||
**Strengths in the loop.** Under *Models*, a fold of the same name maps **Thrifty**, **Balanced** and **Best** to one of that agent's own models (and an effort, for agents that take one). Rows you have not changed show as shipped, tagged *default*; a changed row has **Reset**. The Implementation Loop's **Strength per phase** setting reads these three words to start each phase, its retry and its helpers on the model you chose (see the Implementation Loop in the desktop app's guide). Saved with the agent's form in `~/.plan2code/models.json`.
|
||||
**Strengths in the loop.** On the *Models & strengths* tab, an **In the loop** box shows the model **Thrifty**, **Balanced** and **Best** use for that agent (and an effort, for agents that take one), and tapping a word on a model in the list below it makes that model the pick, one per word. Rows you have not changed show as shipped, tagged *default*; a changed row has **Reset**. The Implementation Loop's **Strength per phase** setting reads these three words to start each phase, its retry and its helpers on the model you chose (see the Implementation Loop in the desktop app's guide). Saved with the agent's form in `~/.plan2code/models.json`.
|
||||
|
||||
**Agents.** An agent you add is an agent CLI Plan2Code did not find on its own, which the `plan2code` command and the desktop app can then start. Each one has a name, the command to run (a bare name looked up on `PATH`, or a full path), and optional fields:
|
||||
|
||||
- **Start prompt**: `/plan2code` by default. Leave it blank to start the agent with nothing typed.
|
||||
- **Models**: a list to offer, each an id and an optional label.
|
||||
- Under the **Command-line arguments** fold:
|
||||
- On the **Launch** tab, under the **Command-line arguments** fold:
|
||||
- **Arguments**: one per row. `{prompt}` is replaced by the start prompt (for example `--message={prompt}`); with no `{prompt}` anywhere, the prompt is added last.
|
||||
- **Bypass arguments**: added when permission checks are off.
|
||||
- **Model arguments**: added when a model is chosen, with `{model}` replaced (`--model` and `{model}` by default).
|
||||
|
||||
@@ -85,27 +85,50 @@ test("the violet highlight and dark theme chosen in preferences stick across a r
|
||||
assert.deepEqual(await firstPaintAttrs(s), { theme: null, accent: null }, "the first paint still carries the old looks");
|
||||
});
|
||||
|
||||
// The Agents & models tab: the split's row list, its rows and the pane the
|
||||
// pick opens the form in (the list stays on screen; there is no back page).
|
||||
// The Agents & models tab: a roster of agent cards, the picked agent's form in
|
||||
// a drawer over it (Models & strengths and Launch tabs), and the Add agent
|
||||
// chooser, where the starter templates are an opt-in.
|
||||
const AGENTS_FILE = path.join(MODELS_DIR, "agents.json");
|
||||
const agentsTable = (s) => s.page.locator("#agents-table");
|
||||
const agentRow = (s, key) => agentsTable(s).locator(`.split-row[data-key="${key}"]`);
|
||||
const agentCard = (s, key) => agentsTable(s).locator(`.agent-card[data-key="${key}"]`);
|
||||
const agentForm = (s) => s.page.locator("#agents-form");
|
||||
const chooser = (s) => s.page.locator("#agents-chooser");
|
||||
const formField = (s, name) => agentForm(s).getByRole("textbox", { name, exact: true });
|
||||
const formButton = (s, name) => agentForm(s).getByRole("button", { name, exact: true });
|
||||
const formPane = (s) => agentForm(s).locator(".prefs-agents-fields");
|
||||
const drawerTab = (s, name) => agentForm(s).getByRole("tab", { name, exact: true });
|
||||
const unsavedPrompt = (s) => s.page.locator("#prefs-unsaved");
|
||||
|
||||
async function openAgentsTab(s) {
|
||||
// The dialog's DOM survives a close, so the row, a stale form and even a
|
||||
// stale empty pane can match before load() resolves. Wait on the fetch
|
||||
// itself first; the empty pane only draws once it has.
|
||||
// The dialog's DOM survives a close, so the card and a stale drawer can match
|
||||
// before load() resolves. Wait on the fetch itself first.
|
||||
const loaded = s.page.waitForResponse((r) => r.url().endsWith("/agents"));
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-agents");
|
||||
await loaded;
|
||||
await agentRow(s, "cli:claude").waitFor();
|
||||
await agentForm(s).locator(".split-empty").waitFor();
|
||||
await agentCard(s, "cli:claude").waitFor();
|
||||
await s.page.locator("#agents-drawer").waitFor({ state: "hidden" });
|
||||
}
|
||||
|
||||
// Add agent, then a chooser tile: a template by name, or the Custom agent tile.
|
||||
async function addAgent(s, template) {
|
||||
await s.page.click("#agents-add");
|
||||
await chooser(s).waitFor();
|
||||
await chooser(s).locator(template ? `.chooser-tile[data-template="${template}"]` : ".chooser-tile.wide").click();
|
||||
await formPane(s).waitFor();
|
||||
}
|
||||
|
||||
// A saved or new agent's Launch tab, where its fields are.
|
||||
async function openLaunch(s) {
|
||||
await drawerTab(s, "Launch").click();
|
||||
await formField(s, "Command").waitFor();
|
||||
}
|
||||
|
||||
// The Models tab's add row: an id (and a name), then the button.
|
||||
async function addModel(s, id, label) {
|
||||
await formField(s, "Model id").fill(id);
|
||||
if (label) await formField(s, "Name shown in the menu").fill(label);
|
||||
await formButton(s, "Add a model").click();
|
||||
}
|
||||
|
||||
// agents.json as the test starts it: none, or the entries given. Removed after.
|
||||
@@ -118,30 +141,30 @@ function seedAgents(t, agents) {
|
||||
t.after(() => fs.rmSync(AGENTS_FILE, { force: true }));
|
||||
}
|
||||
|
||||
test("Agents & models: the table lists Claude, Devin and Codex, and a model id typed in Codex's form is saved only on Save", async (t) => {
|
||||
test("Agents & models: the roster lists Claude, Devin and Codex, and a model id typed in Codex's form is saved only on Save", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
// The file the launcher reads: put back as the suite had it (no file).
|
||||
t.after(() => fs.rmSync(path.join(MODELS_DIR, "models.json"), { force: true }));
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const keys = await agentsTable(s).locator(".split-row[data-key]").evaluateAll((rows) => rows.map((r) => r.dataset.key));
|
||||
const keys = await agentsTable(s).locator(".agent-card[data-key]").evaluateAll((cards) => cards.map((c) => c.dataset.key));
|
||||
assert.deepEqual(keys, ["cli:claude", "cli:devin", "cli:codex"]);
|
||||
assert.equal(await textOf(agentRow(s, "cli:codex").locator(".row-name")), "Codex");
|
||||
assert.equal(await textOf(agentCard(s, "cli:codex").locator(".row-name")), "Codex");
|
||||
|
||||
await s.page.getByRole("button", { name: "Edit Codex" }).click();
|
||||
await formPane(s).waitFor();
|
||||
assert.equal(await agentRow(s, "cli:codex").getAttribute("aria-current"), "true", "the picked row is marked; the list stays beside the form");
|
||||
assert.equal(await agentCard(s, "cli:codex").getAttribute("aria-current"), "true", "the picked card is marked");
|
||||
await agentForm(s).locator(".prefs-agents-none").filter({ hasText: /^No models ship for Codex yet/ }).waitFor();
|
||||
assert.equal(await agentForm(s).locator(".models-row.locked").count(), 0, "nothing comes with Plan2Code for Codex");
|
||||
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").fill("gpt-test-codex-1");
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").nth(1).fill("gpt-test-codex-2");
|
||||
await addModel(s, "gpt-test-codex-1");
|
||||
await addModel(s, "gpt-test-codex-2");
|
||||
const mine = agentForm(s).locator(".models-row:not(.locked)");
|
||||
assert.equal(await mine.count(), 2);
|
||||
// Remove drops the row from the draft; it still reaches the file only on Save.
|
||||
await agentForm(s).locator(".agent-row.model").first().getByRole("button", { name: "Remove" }).click();
|
||||
assert.equal(await agentForm(s).locator(".agent-row.model").count(), 1, "the removed row is gone");
|
||||
await mine.first().getByRole("button", { name: /^Remove/ }).click();
|
||||
assert.equal(await mine.count(), 1, "the removed row is gone");
|
||||
await agentForm(s).locator(".prefs-unsaved-badge").waitFor();
|
||||
const before = await s.page.evaluate(async () => (await (await fetch("/models")).json()).user);
|
||||
assert.deepEqual(before.codex, [], "nothing is saved before Save");
|
||||
@@ -153,20 +176,22 @@ test("Agents & models: the table lists Claude, Devin and Codex, and a model id t
|
||||
assert.deepEqual([saved.claude, saved.devin], [[], []], "the id leaked into another agent's menu");
|
||||
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), false, "saved, nothing is unsaved");
|
||||
|
||||
// The summary counts it on Codex's row, and so does a fresh page.
|
||||
assert.match(await textOf(agentRow(s, "cli:codex").locator(".row-models")), /^1: gpt-test-codex-2$/);
|
||||
// Close the drawer: the card counts it, and so does a fresh page.
|
||||
await formButton(s, "Close").click();
|
||||
await s.page.locator("#agents-drawer").waitFor({ state: "hidden" });
|
||||
assert.match(await textOf(agentCard(s, "cli:codex").locator(".row-models")), /^1 model$/);
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Codex" }).click();
|
||||
assert.equal(await formField(s, "Model id").inputValue(), "gpt-test-codex-2");
|
||||
assert.equal(await textOf(agentForm(s).locator(".models-row .model-name")), "gpt-test-codex-2");
|
||||
});
|
||||
|
||||
// The "Strengths in the loop" fold: Thrifty, Balanced and Best mapped to the
|
||||
// agent's own models. models.json under PLAN2CODE_MODELS_DIR is what Save writes.
|
||||
// "In the loop": Thrifty, Balanced and Best mapped to the agent's own models,
|
||||
// by tapping a word on a model. models.json under PLAN2CODE_MODELS_DIR is what Save writes.
|
||||
const MODELS_FILE = path.join(MODELS_DIR, "models.json");
|
||||
const strengthsFold = (s) => agentForm(s).locator("details.prefs-agents-strengths");
|
||||
const strengthRow = (s, word) => strengthsFold(s).locator(`.strength-row[data-word="${word}"]`);
|
||||
const loopRow = (s, word) => agentForm(s).locator(`.strength-row[data-word="${word}"]`);
|
||||
const wordPill = (s, word, model) => agentForm(s).locator(`.strength-pill[data-word="${word}"][data-model="${model}"]`);
|
||||
const savedStrengths = () => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(MODELS_FILE, "utf8")).strengths ?? null;
|
||||
@@ -175,7 +200,7 @@ const savedStrengths = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// The shipped list the tests start with has no models at all; the fold needs some
|
||||
// The shipped list the tests start with has no models at all; the panel needs some
|
||||
// (and Claude and Devin's shipped strengths), so a test writes them and puts the file back.
|
||||
const SHIPPED_FILE = path.join(MODELS_DIR, "bin", "models.json");
|
||||
function seedShippedModels(t) {
|
||||
@@ -204,13 +229,12 @@ async function savedStrengthsAre(expected) {
|
||||
assert.deepEqual(savedStrengths(), expected);
|
||||
}
|
||||
|
||||
async function openStrengths(s, name) {
|
||||
async function openAgent(s, name) {
|
||||
await s.page.getByRole("button", { name: `Edit ${name}` }).click();
|
||||
await formPane(s).waitFor();
|
||||
await strengthsFold(s).locator("summary").click();
|
||||
}
|
||||
|
||||
test("Agents & models: Claude's fold shows the shipped rows as default, and only a changed row is saved, until Reset", async (t) => {
|
||||
test("Agents & models: Claude's panel shows the shipped rows as default, and only a changed row is saved, until Reset", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
t.after(() => fs.rmSync(MODELS_FILE, { force: true }));
|
||||
@@ -218,29 +242,34 @@ test("Agents & models: Claude's fold shows the shipped rows as default, and only
|
||||
fs.rmSync(MODELS_FILE, { force: true });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await openStrengths(s, "Claude");
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="model"]').inputValue(), "sonnet");
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="effort"]').inputValue(), "low");
|
||||
assert.equal(await strengthRow(s, "best").locator('select[data-field="model"]').inputValue(), "opus");
|
||||
assert.equal(await strengthsFold(s).locator(".strength-default").count(), 3, "all three rows are untouched defaults");
|
||||
assert.equal(await textOf(strengthRow(s, "balanced").locator(".strength-default")), "default");
|
||||
assert.equal(await strengthsFold(s).locator(".strength-reset").count(), 0, "nothing to reset yet");
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-offer")), "The loop will offer: Thrifty, Balanced, Best");
|
||||
// The card already shows what each strength uses.
|
||||
assert.match(await textOf(agentCard(s, "cli:claude").locator(".card-tiers")), /Thrifty\s+Sonnet · low[\s\S]*Best\s+Opus · medium/);
|
||||
await openAgent(s, "Claude");
|
||||
assert.equal(await textOf(loopRow(s, "thrifty").locator(".strength-model")), "Sonnet");
|
||||
assert.equal(await loopRow(s, "thrifty").locator('select[data-field="effort"]').inputValue(), "low");
|
||||
assert.equal(await wordPill(s, "best", "opus").getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await wordPill(s, "best", "sonnet").getAttribute("aria-pressed"), "false");
|
||||
assert.equal(await agentForm(s).locator(".strength-default").count(), 3, "all three rows are untouched defaults");
|
||||
assert.equal(await textOf(loopRow(s, "balanced").locator(".strength-default")), "default");
|
||||
assert.equal(await agentForm(s).locator(".strength-reset").count(), 0, "nothing to reset yet");
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-offer")), "The loop will offer: Thrifty, Balanced, Best");
|
||||
|
||||
await strengthRow(s, "thrifty").locator('select[data-field="model"]').selectOption("opus");
|
||||
await wordPill(s, "thrifty", "opus").click();
|
||||
await agentForm(s).locator(".prefs-unsaved-badge").waitFor();
|
||||
assert.equal(await strengthRow(s, "thrifty").locator(".strength-reset").count(), 1, "a changed row has Reset");
|
||||
assert.equal(await strengthRow(s, "thrifty").locator(".strength-default").count(), 0);
|
||||
assert.equal(await strengthRow(s, "balanced").locator(".strength-reset").count(), 0, "the other rows stay default");
|
||||
assert.equal(await wordPill(s, "thrifty", "opus").getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await wordPill(s, "thrifty", "sonnet").getAttribute("aria-pressed"), "false", "one pick per strength");
|
||||
assert.equal(await loopRow(s, "thrifty").locator(".strength-reset").count(), 1, "a changed row has Reset");
|
||||
assert.equal(await loopRow(s, "thrifty").locator(".strength-default").count(), 0);
|
||||
assert.equal(await loopRow(s, "balanced").locator(".strength-reset").count(), 0, "the other rows stay default");
|
||||
assert.equal(fs.existsSync(MODELS_FILE), false, "nothing is saved before Save");
|
||||
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved. Restart plan2code/ }).waitFor();
|
||||
assert.deepEqual(savedStrengths(), { claude: { thrifty: { model: "opus", effort: "low" } } }, "only the changed row is written");
|
||||
|
||||
await strengthRow(s, "thrifty").locator(".strength-reset").click();
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="model"]').inputValue(), "sonnet", "Reset restores the shipped row");
|
||||
assert.equal(await textOf(strengthRow(s, "thrifty").locator(".strength-default")), "default");
|
||||
await loopRow(s, "thrifty").locator(".strength-reset").click();
|
||||
assert.equal(await textOf(loopRow(s, "thrifty").locator(".strength-model")), "Sonnet", "Reset restores the shipped row");
|
||||
assert.equal(await textOf(loopRow(s, "thrifty").locator(".strength-default")), "default");
|
||||
await agentForm(s).locator(".prefs-unsaved-badge").waitFor();
|
||||
await formButton(s, "Save").click();
|
||||
await savedStrengthsAre(null); // with every row back at its default, no strengths are stored
|
||||
@@ -253,18 +282,18 @@ test("Agents & models: Codex has an effort select on each row and Devin does not
|
||||
seedShippedModels(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await openStrengths(s, "Codex");
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-empty")), "Add a model under Models first", "no models ship for Codex");
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").fill("gpt-test-codex-1");
|
||||
assert.equal(await strengthsFold(s).locator('select[data-field="effort"]').count(), 3);
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="model"]').inputValue(), "", "nothing ships for Codex, so the row is not mapped");
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-offer")), "The loop will not offer a strength for this agent until one is mapped.");
|
||||
await openAgent(s, "Codex");
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-empty")), "Add a model first, then choose which one the loop uses for each strength.", "no models ship for Codex");
|
||||
await addModel(s, "gpt-test-codex-1");
|
||||
assert.equal(await agentForm(s).locator('select[data-field="effort"]').count(), 3);
|
||||
assert.equal(await textOf(loopRow(s, "thrifty").locator(".strength-model")), "not mapped", "nothing ships for Codex, so the row is not mapped");
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-offer")), "The loop will not offer a strength for this agent until one is mapped.");
|
||||
await formButton(s, "Discard").click(); // the added model is unsaved: leaving would ask first
|
||||
await s.page.getByRole("button", { name: "Edit Devin" }).click();
|
||||
await strengthsFold(s).locator("summary").click();
|
||||
assert.equal(await strengthsFold(s).locator('select[data-field="model"]').count(), 3);
|
||||
assert.equal(await strengthsFold(s).locator('select[data-field="effort"]').count(), 0, "Devin takes no separate effort");
|
||||
await formButton(s, "Close").click();
|
||||
await s.page.locator("#agents-drawer").waitFor({ state: "hidden" });
|
||||
await openAgent(s, "Devin");
|
||||
assert.equal(await agentForm(s).locator(".strength-row").count(), 3);
|
||||
assert.equal(await agentForm(s).locator('select[data-field="effort"]').count(), 0, "Devin takes no separate effort");
|
||||
});
|
||||
|
||||
test("Agents & models: a strength-only edit is unsaved until Save, Discard puts the shipped rows back, and Reset keeps focus on its row", async (t) => {
|
||||
@@ -274,18 +303,18 @@ test("Agents & models: a strength-only edit is unsaved until Save, Discard puts
|
||||
seedShippedModels(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await openStrengths(s, "Claude");
|
||||
await openAgent(s, "Claude");
|
||||
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), false);
|
||||
await strengthRow(s, "best").locator('select[data-field="model"]').selectOption("sonnet");
|
||||
await wordPill(s, "best", "sonnet").click();
|
||||
await agentForm(s).locator(".prefs-unsaved-badge").waitFor();
|
||||
await formButton(s, "Discard").click();
|
||||
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), false, "Discard clears the strength-only change");
|
||||
assert.equal(await strengthRow(s, "best").locator('select[data-field="model"]').inputValue(), "opus", "the shipped row is back");
|
||||
assert.equal(await wordPill(s, "best", "opus").getAttribute("aria-pressed"), "true", "the shipped row is back");
|
||||
assert.equal(fs.existsSync(MODELS_FILE), false, "nothing was written");
|
||||
|
||||
await strengthRow(s, "best").locator('select[data-field="model"]').selectOption("sonnet");
|
||||
await strengthRow(s, "best").locator(".strength-reset").focus();
|
||||
await strengthRow(s, "best").locator(".strength-reset").click();
|
||||
await wordPill(s, "best", "sonnet").click();
|
||||
await loopRow(s, "best").locator(".strength-reset").focus();
|
||||
await loopRow(s, "best").locator(".strength-reset").click();
|
||||
assert.equal(
|
||||
await s.page.evaluate(() => document.activeElement?.closest("[data-word]")?.dataset.word),
|
||||
"best",
|
||||
@@ -301,24 +330,20 @@ test("Agents & models: a saved row whose model was removed reads not mapped whil
|
||||
fs.rmSync(MODELS_FILE, { force: true });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await formPane(s).waitFor();
|
||||
await addAgent(s);
|
||||
await formField(s, "Name").fill("Gemini");
|
||||
await formField(s, "Command").fill("node");
|
||||
await agentForm(s).locator("details.agent-fold > summary", { hasText: /^Models$/ }).click();
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").fill("model-a");
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").nth(1).fill("model-b");
|
||||
await strengthsFold(s).locator("summary").click();
|
||||
await strengthRow(s, "thrifty").locator('select[data-field="model"]').selectOption("model-a");
|
||||
await strengthRow(s, "best").locator('select[data-field="model"]').selectOption("model-b");
|
||||
await drawerTab(s, "Models & strengths").click();
|
||||
await addModel(s, "model-a");
|
||||
await addModel(s, "model-b");
|
||||
await wordPill(s, "thrifty", "model-a").click();
|
||||
await wordPill(s, "best", "model-b").click();
|
||||
await formButton(s, "Save").click();
|
||||
await savedStrengthsAre({ gemini: { thrifty: { model: "model-a" }, best: { model: "model-b" } } });
|
||||
|
||||
await agentForm(s).locator(".agent-row.model").first().getByRole("button", { name: "Remove" }).click();
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="model"]').inputValue(), "", "the removed model reads not mapped");
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-offer")), "The loop will offer: Best");
|
||||
await agentForm(s).locator(".models-row").first().getByRole("button", { name: /^Remove/ }).click();
|
||||
assert.equal(await textOf(loopRow(s, "thrifty").locator(".strength-model")), "not mapped", "the removed model reads not mapped");
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-offer")), "The loop will offer: Best");
|
||||
await formButton(s, "Save").click();
|
||||
await savedStrengthsAre({ gemini: { best: { model: "model-b" } } });
|
||||
});
|
||||
@@ -331,26 +356,24 @@ test("Agents & models: an added agent maps strengths only from its own Models, a
|
||||
fs.rmSync(MODELS_FILE, { force: true });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await formPane(s).waitFor();
|
||||
await addAgent(s);
|
||||
await formField(s, "Name").fill("Copilot");
|
||||
await formField(s, "Command").fill("node");
|
||||
await strengthsFold(s).locator("summary").click();
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-empty")), "Add a model under Models first");
|
||||
assert.equal(await strengthsFold(s).locator("select").count(), 0, "no selects without a model");
|
||||
await drawerTab(s, "Models & strengths").click();
|
||||
const empty = "Add a model first, then choose which one the loop uses for each strength.";
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-empty")), empty);
|
||||
assert.equal(await agentForm(s).locator(".strength-body select").count(), 0, "no selects without a model");
|
||||
|
||||
await agentForm(s).locator("details.agent-fold > summary", { hasText: /^Models$/ }).click();
|
||||
await formButton(s, "Add a model").click();
|
||||
await formField(s, "Model id").fill("gpt-test-1");
|
||||
assert.equal(await strengthsFold(s).locator(".strength-empty").count(), 0, "the fold follows the Models list as it changes");
|
||||
await strengthRow(s, "thrifty").locator('select[data-field="model"]').selectOption("gpt-test-1");
|
||||
assert.equal(await strengthRow(s, "thrifty").locator('select[data-field="effort"]').count(), 0, "an added agent has no effort select");
|
||||
await addModel(s, "gpt-test-1");
|
||||
assert.equal(await agentForm(s).locator(".strength-empty").count(), 0, "the panel follows the Models list as it changes");
|
||||
await wordPill(s, "thrifty", "gpt-test-1").click();
|
||||
assert.equal(await agentForm(s).locator('select[data-field="effort"]').count(), 0, "an added agent has no effort select");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").waitFor();
|
||||
assert.deepEqual(savedStrengths(), { copilot: { thrifty: { model: "gpt-test-1" } } }, "saved under the new agent's id");
|
||||
|
||||
await agentForm(s).locator(".agent-row.model").first().getByRole("button", { name: "Remove" }).click();
|
||||
assert.equal(await textOf(strengthsFold(s).locator(".strength-empty")), "Add a model under Models first");
|
||||
await agentForm(s).locator(".models-row").first().getByRole("button", { name: /^Remove/ }).click();
|
||||
assert.equal(await textOf(agentForm(s).locator(".strength-empty")), empty);
|
||||
await formButton(s, "Save").click();
|
||||
await savedStrengthsAre(null);
|
||||
});
|
||||
@@ -360,10 +383,10 @@ test("Agents & models: a person adds an agent, tests its command, sees it after
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
assert.equal(await agentsTable(s).locator('.split-row[data-key^="agent:"]').count(), 0, "no agents before one is added");
|
||||
assert.equal(await agentsTable(s).locator('.agent-card[data-key^="agent:"]').count(), 0, "no agents before one is added");
|
||||
|
||||
await s.page.click("#agents-add");
|
||||
await formPane(s).waitFor();
|
||||
await addAgent(s);
|
||||
assert.equal(await drawerTab(s, "Launch").getAttribute("aria-selected"), "true", "a new agent opens on Launch, where its fields are");
|
||||
assert.equal(await agentForm(s).locator("details.prefs-agents-args").evaluate((d) => d.open), true, "the arguments are open on a new agent");
|
||||
await formField(s, "Name").fill("Test Agent");
|
||||
await formField(s, "Command").fill("node");
|
||||
@@ -381,22 +404,24 @@ test("Agents & models: a person adds an agent, tests its command, sees it after
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await openAgentsTab(s);
|
||||
const row = agentRow(s, "agent:test-agent");
|
||||
await row.locator(".prefs-badge.ok").waitFor();
|
||||
assert.equal(await textOf(row.locator(".prefs-badge")), "Found");
|
||||
const card = agentCard(s, "agent:test-agent");
|
||||
await card.locator(".prefs-badge.ok").waitFor();
|
||||
assert.equal(await textOf(card.locator(".prefs-badge")), "Found");
|
||||
assert.equal(await textOf(card.locator(".tag")), "Custom");
|
||||
await s.page.getByRole("button", { name: "Edit Test Agent" }).click();
|
||||
assert.equal(await drawerTab(s, "Models & strengths").getAttribute("aria-selected"), "true", "a saved agent opens on its models");
|
||||
await openLaunch(s);
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Test Agent");
|
||||
assert.equal(await agentForm(s).locator("details.prefs-agents-args").evaluate((d) => d.open), false, "the arguments are folded on a saved agent");
|
||||
|
||||
await formButton(s, "Delete agent").click();
|
||||
await formButton(s, "Yes, delete").click();
|
||||
await row.waitFor({ state: "detached" });
|
||||
assert.equal(await agentsTable(s).locator('.split-row[data-key^="agent:"]').count(), 0);
|
||||
await card.waitFor({ state: "detached" });
|
||||
assert.equal(await agentsTable(s).locator('.agent-card[data-key^="agent:"]').count(), 0);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents, []);
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "agents-add", "with its row gone, focus goes to Add agent");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "agents-add", "with its card gone, focus goes to Add agent");
|
||||
assert.equal(await textOf(s.page.locator("#agents-status")), "Deleted.");
|
||||
await s.page.click("#agents-add");
|
||||
await formPane(s).waitFor();
|
||||
await addAgent(s);
|
||||
assert.equal(await s.page.locator("#agents-status").innerText(), "", "opening a form clears Deleted.");
|
||||
});
|
||||
|
||||
@@ -405,7 +430,7 @@ test("Agents & models: a new agent with only a name is not sent, its command is
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await addAgent(s);
|
||||
await formField(s, "Name").fill("Focus Agent");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".agent-error").filter({ hasText: "Give it a name and a command first." }).waitFor();
|
||||
@@ -414,7 +439,7 @@ test("Agents & models: a new agent with only a name is not sent, its command is
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Focus Agent", "the typed name survives the redraw");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.textContent), "Save", "focus stays on Save");
|
||||
|
||||
// The first good save assigns an id; the form stays open on it.
|
||||
// The first good save assigns an id; the drawer stays open on it.
|
||||
await formField(s, "Command").fill("node");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
@@ -441,8 +466,7 @@ test("Agents & models: a file holding entries the page could not read is only re
|
||||
await openAgentsTab(s);
|
||||
await s.page.locator("#agents-status").filter({ hasText: /schema 2/ }).waitFor();
|
||||
|
||||
await s.page.click("#agents-add");
|
||||
await formPane(s).waitFor();
|
||||
await addAgent(s);
|
||||
assert.equal(await formButton(s, "Save anyway").count(), 0, "no Save anyway before a save is tried");
|
||||
await formField(s, "Name").fill("Mine");
|
||||
await formField(s, "Command").fill("node");
|
||||
@@ -467,7 +491,8 @@ test("Agents & models: nothing reaches agents.json before Save", async (t) => {
|
||||
const before = fs.readFileSync(AGENTS_FILE, "utf8");
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await openAgent(s, "Alpha");
|
||||
await openLaunch(s);
|
||||
await formField(s, "Command").fill("alpha-cli --edited");
|
||||
await formField(s, "Command").press("Tab");
|
||||
await s.page.waitForTimeout(500);
|
||||
@@ -482,19 +507,22 @@ test("Agents & models: a discarded edit never rides along with another agent's S
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await openAgent(s, "Alpha");
|
||||
await openLaunch(s);
|
||||
await formField(s, "Command").fill("alpha-cli --dropped");
|
||||
// Picking another row is the way out of a form; a dirty draft asks first.
|
||||
await s.page.getByRole("button", { name: "Edit Beta" }).click();
|
||||
// Closing the drawer is the way out of a form; a dirty draft asks first.
|
||||
await formButton(s, "Close").click();
|
||||
await unsavedPrompt(s).waitFor();
|
||||
assert.equal(await textOf(s.page.locator("#prefs-unsaved-name")), "Alpha");
|
||||
assert.equal(await s.page.locator("#looks-modal .prefs-body").evaluate((b) => b.inert), true, "the dialog behind the prompt is out of reach");
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Discard", exact: true }).click();
|
||||
await unsavedPrompt(s).waitFor({ state: "hidden" });
|
||||
await formPane(s).waitFor();
|
||||
await s.page.locator("#agents-drawer").waitFor({ state: "hidden" });
|
||||
assert.equal(await s.page.locator("#looks-modal .prefs-body").evaluate((b) => b.inert), false);
|
||||
assert.equal(await textOf(agentForm(s).locator(".prefs-agents-title")), "Beta", "the pick the prompt asked about carries on");
|
||||
|
||||
await openAgent(s, "Beta");
|
||||
assert.equal(await textOf(agentForm(s).locator(".prefs-agents-title")), "Beta");
|
||||
await openLaunch(s);
|
||||
await formField(s, "Command").fill("beta-cli --kept");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
@@ -502,24 +530,26 @@ test("Agents & models: a discarded edit never rides along with another agent's S
|
||||
assert.deepEqual(agents.map((a) => [a.id, a.command]), [["alpha", "alpha-cli"], ["beta", "beta-cli --kept"]]);
|
||||
});
|
||||
|
||||
test("Agents & models: an unsaved edit asks first on a row pick, Close, Esc, a backdrop click and a tab switch", async (t) => {
|
||||
test("Agents & models: an unsaved edit asks first on Close, a scrim click, Esc, a backdrop click, a tab switch and Close dialog", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const modal = s.page.locator("#looks-modal");
|
||||
const edit = async (command) => {
|
||||
if (!(await agentForm(s).locator(".prefs-agents-title").filter({ hasText: "Alpha" }).count())) {
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
if (!(await agentForm(s).locator(".prefs-agents-title").filter({ hasText: "Alpha" }).isVisible())) {
|
||||
await openAgent(s, "Alpha");
|
||||
await openLaunch(s);
|
||||
}
|
||||
await formField(s, "Command").fill(command);
|
||||
};
|
||||
const triggers = {
|
||||
row: () => s.page.getByRole("button", { name: "Edit Beta" }).click(),
|
||||
close: () => s.page.click("#looks-done"),
|
||||
drawerClose: () => formButton(s, "Close").click(),
|
||||
scrim: () => s.page.locator(".drawer-scrim").click({ position: { x: 5, y: 5 } }),
|
||||
esc: () => formField(s, "Command").press("Escape"),
|
||||
backdrop: () => s.page.mouse.click(4, 4),
|
||||
tab: () => s.page.click("#prefs-tab-appearance"),
|
||||
dialog: () => s.page.click("#looks-done"),
|
||||
};
|
||||
for (const [name, leave] of Object.entries(triggers)) {
|
||||
// Keep editing: the form and the draft stay.
|
||||
@@ -535,8 +565,8 @@ test("Agents & models: an unsaved edit asks first on a row pick, Close, Esc, a b
|
||||
}
|
||||
const before = fs.readFileSync(AGENTS_FILE, "utf8");
|
||||
|
||||
// Discard drops the edit and goes on (here, Close).
|
||||
await triggers.close();
|
||||
// Discard drops the edit and goes on (here, closing the dialog).
|
||||
await triggers.dialog();
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Discard", exact: true }).click();
|
||||
await modal.waitFor({ state: "hidden" });
|
||||
assert.equal(fs.readFileSync(AGENTS_FILE, "utf8"), before, "Discard writes nothing");
|
||||
@@ -550,12 +580,30 @@ test("Agents & models: an unsaved edit asks first on a row pick, Close, Esc, a b
|
||||
assert.equal(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents[0].command, "alpha-saved");
|
||||
});
|
||||
|
||||
test("Agents & models: Esc closes the chooser, then a clean drawer, before it closes Preferences", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const modal = s.page.locator("#looks-modal");
|
||||
await s.page.click("#agents-add");
|
||||
await chooser(s).waitFor();
|
||||
await s.page.keyboard.press("Escape");
|
||||
await chooser(s).waitFor({ state: "hidden" });
|
||||
assert.equal(await modal.evaluate((d) => d.open), true, "Esc in the chooser leaves the dialog open");
|
||||
await openAgent(s, "Alpha");
|
||||
await s.page.keyboard.press("Escape");
|
||||
await s.page.locator("#agents-drawer").waitFor({ state: "hidden" });
|
||||
assert.equal(await modal.evaluate((d) => d.open), true, "Esc in a clean drawer leaves the dialog open");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Edit Alpha", "focus goes back to the card");
|
||||
});
|
||||
|
||||
test("Agents & models: Esc in the unsaved prompt keeps editing, and a Save that fails there stays and marks the field", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await addAgent(s);
|
||||
await formField(s, "Name").fill("Half Agent");
|
||||
|
||||
await s.page.click("#looks-done");
|
||||
@@ -574,29 +622,27 @@ test("Agents & models: Esc in the unsaved prompt keeps editing, and a Save that
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.matches('input.invalid[data-field="command"]')), true, "focus is on the marked field");
|
||||
});
|
||||
|
||||
test("Agents & models: a command not on PATH is marked, and the orchestrator row has no Edit", async (t) => {
|
||||
test("Agents & models: a command not on PATH is marked on its card", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, [{ id: "ghost", name: "Ghost", command: "plan2code-no-such-command-xyz" }]);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const badge = agentRow(s, "agent:ghost").locator(".prefs-badge");
|
||||
const badge = agentCard(s, "agent:ghost").locator(".prefs-badge");
|
||||
await badge.filter({ hasText: "Not found on PATH" }).waitFor();
|
||||
assert.equal(await badge.evaluate((b) => b.classList.contains("missing")), true);
|
||||
const soon = agentsTable(s).locator(".split-row.soon");
|
||||
assert.match(await textOf(soon), /v3 orchestrator\s+Nothing to set yet\./);
|
||||
assert.equal(await soon.getByRole("button").count(), 0);
|
||||
assert.equal(await agentsTable(s).getByText("v3 orchestrator").count(), 0, "no placeholder card");
|
||||
});
|
||||
|
||||
test("Agents & models: below 720 px the split stacks and the form is one column", async (t) => {
|
||||
test("Agents & models: at 600 px the drawer fits the dialog and its form is one column", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.setViewportSize({ width: 600, height: 800 });
|
||||
await openAgentsTab(s);
|
||||
const cols = await styleOf(s.page.locator("#agents-split"), "grid-template-columns");
|
||||
assert.equal(cols.trim().split(/\s+/).length, 1, `the split stacks: ${cols}`);
|
||||
assert.equal(await styleOf(s.page.locator("#agents-table"), "overflow-y"), "auto", "the row list scrolls");
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await openAgent(s, "Alpha");
|
||||
await openLaunch(s);
|
||||
const box = await agentForm(s).boundingBox();
|
||||
assert.ok(box && box.x >= 0 && box.x + box.width <= 600, `the drawer sits inside the window: ${JSON.stringify(box)}`);
|
||||
const fields = await styleOf(agentForm(s).locator(".prefs-agents-fields"), "grid-template-columns");
|
||||
assert.equal(fields.trim().split(/\s+/).length, 1, `one column: ${fields}`);
|
||||
});
|
||||
@@ -610,25 +656,32 @@ function seedShipped(t, agents) {
|
||||
t.after(() => fs.rmSync(SHIPPED_AGENTS_FILE, { force: true }));
|
||||
}
|
||||
|
||||
test("Agents & models: shipped templates offer a prefilled new-agent form", async (t) => {
|
||||
test("Agents & models: starter templates are an opt-in on Add agent, each with whether it is installed, and a pick opens a prefilled form", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
seedShipped(t, [
|
||||
{ id: "templar", name: "Templar", kind: "template", command: "templar", prompt: "/plan2code", args: ["{prompt}"], note: "A starter agent." },
|
||||
{ id: "templar", name: "Templar", kind: "template", command: "plan2code-no-such-command-xyz", prompt: "/plan2code", args: ["{prompt}"], note: "A starter agent." },
|
||||
{ id: "nodey", name: "Nodey", kind: "template", command: "node", prompt: "/plan2code" },
|
||||
]);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await agentsTable(s).locator(".split-list-head", { hasText: "Or start from a template" }).waitFor();
|
||||
const row = agentRow(s, "setup:Templar");
|
||||
assert.match(await textOf(row), /Templar\s+templar/);
|
||||
await row.click();
|
||||
const use = agentForm(s).getByRole("button", { name: "Use this template", exact: true });
|
||||
await use.waitFor();
|
||||
assert.match(await textOf(agentForm(s)), /A starter agent\./);
|
||||
await use.click();
|
||||
assert.equal(await agentsTable(s).getByText("Templar").count(), 0, "templates are not part of the roster");
|
||||
await s.page.click("#agents-add");
|
||||
await chooser(s).waitFor();
|
||||
const tile = chooser(s).locator('.chooser-tile[data-template="Templar"]');
|
||||
assert.match(await textOf(tile), /Templar\s+plan2code-no-such-command-xyz/);
|
||||
assert.match(await textOf(tile), /A starter agent\./);
|
||||
await tile.locator(".chooser-state").filter({ hasText: "Not installed yet" }).waitFor();
|
||||
await chooser(s).locator('.chooser-tile[data-template="Nodey"] .chooser-state').filter({ hasText: "Installed on this computer" }).waitFor();
|
||||
assert.equal(await chooser(s).locator(".chooser-tile.wide").count(), 1, "a custom agent is always on offer");
|
||||
|
||||
await tile.click();
|
||||
await formPane(s).waitFor();
|
||||
assert.equal(await chooser(s).isHidden(), true, "a pick closes the chooser");
|
||||
assert.equal(await textOf(agentForm(s).locator(".prefs-agents-title .tag")), "From the Templar template");
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Templar");
|
||||
assert.equal(await formField(s, "Command").inputValue(), "templar");
|
||||
assert.equal(await formField(s, "Command").inputValue(), "plan2code-no-such-command-xyz");
|
||||
assert.equal(await agentForm(s).locator('.agent-rows[data-field="args"] input').first().inputValue(), "{prompt}", "its arguments come along");
|
||||
});
|
||||
|
||||
test("Cleanup scans the console home and lists an old session folder with its size", async (t) => {
|
||||
@@ -777,10 +830,10 @@ test("Set up preferences on the dashboard opens on Appearance with agents and mo
|
||||
await s.page.locator("#looks-modal[open]").waitFor();
|
||||
assert.equal(await selectedTab(s), "prefs-tab-appearance");
|
||||
await s.page.click("#prefs-tab-agents");
|
||||
const goose = s.page.locator('#agents-table .split-row[data-key="agent:goose"]');
|
||||
const goose = s.page.locator('#agents-table .agent-card[data-key="agent:goose"]');
|
||||
await goose.waitFor();
|
||||
assert.match(await textOf(goose.locator(".row-name")), /^Goose/);
|
||||
assert.equal(await s.page.locator('#agents-table .split-row[data-key="cli:claude"]').count(), 1, "the built-ins are listed");
|
||||
assert.equal(await s.page.locator('#agents-table .agent-card[data-key="cli:claude"]').count(), 1, "the built-ins are listed");
|
||||
assert.doesNotMatch(await s.page.locator("#agents-status").innerText(), /could not be loaded/);
|
||||
});
|
||||
|
||||
|
||||
@@ -3280,7 +3280,8 @@
|
||||
</li>
|
||||
<li>
|
||||
<strong>Agents & models</strong>: the agents you can start and
|
||||
the models each one offers.
|
||||
the models each one offers. Each agent is a card; open one to edit
|
||||
it in a side drawer.
|
||||
</li>
|
||||
<li>
|
||||
<strong>System</strong>: Cleanup<span class="for-app">, and Desktop
|
||||
@@ -3334,9 +3335,11 @@
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>Strengths in the loop</strong>: under Models, map Thrifty,
|
||||
Balanced and Best to one of the agent's own models. The Implementation
|
||||
Loop's per-phase strength reads them. Untouched rows stay as shipped.
|
||||
<strong>Strengths in the loop</strong>: each agent's
|
||||
<strong>In the loop</strong> box shows the model Thrifty, Balanced
|
||||
and Best use, and you change one by tapping that word on a model in
|
||||
the list below it. The Implementation Loop's per-phase strength
|
||||
reads them. Untouched rows stay as shipped.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Models</strong>: each built-in agent (Claude, Devin, Codex)
|
||||
@@ -3349,8 +3352,11 @@
|
||||
<li>
|
||||
<strong>Agents</strong>: an agent you add is another command-line
|
||||
tool the <code>plan2code</code> launcher can start, beside the
|
||||
built-in ones. Give it a name, the command to run and, if you like,
|
||||
a start prompt and models. <strong>Test</strong> checks the command
|
||||
built-in ones. <strong>Add agent</strong> offers the starter
|
||||
templates (each says whether its command is installed) or a custom
|
||||
command. Give it a name, the command to run and, if you like, a
|
||||
start prompt and models, on the drawer's <strong>Launch</strong>
|
||||
tab. <strong>Test</strong> checks the command
|
||||
is on your PATH. The <strong>Command-line arguments</strong> fold
|
||||
holds the arguments it is started with, the ones that skip its
|
||||
permission prompts, and the ones that pick a model, where
|
||||
@@ -3629,14 +3635,17 @@
|
||||
</section>
|
||||
<section class="prefs-panel" data-tab="agents">
|
||||
<div class="prefs-agents" data-section="agents">
|
||||
<p class="help" id="agents-intro" data-av="intro">Most people never need to change this. Plan2Code finds the agents installed on this machine and ships an up-to-date model list with every release.</p>
|
||||
<div class="split" id="agents-split">
|
||||
<div class="split-list" id="agents-table" data-av="table">
|
||||
<button type="button" class="btn small ghost split-add" id="agents-add" data-av="add">Add agent</button>
|
||||
</div>
|
||||
<div class="split-pane" id="agents-form" data-av="form"></div>
|
||||
<div class="roster-head">
|
||||
<p class="help" id="agents-intro" data-av="intro">Most people never need to change this. Plan2Code finds the agents installed on this machine and ships an up-to-date model list with every release. Open an agent to choose the models the loop uses for each strength.</p>
|
||||
<button type="button" class="btn small primary" id="agents-add" data-av="add">Add agent</button>
|
||||
</div>
|
||||
<div class="roster" id="agents-table" data-av="table"></div>
|
||||
<span class="help" id="agents-status" data-av="status" role="status"></span>
|
||||
<div class="agents-drawer" id="agents-drawer" data-av="drawer" hidden>
|
||||
<div class="drawer-scrim" data-av="scrim"></div>
|
||||
<aside class="drawer" id="agents-form" data-av="form" aria-label="Agent"></aside>
|
||||
</div>
|
||||
<div class="agents-chooser" id="agents-chooser" data-av="chooser" hidden></div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="prefs-panel" data-tab="system">
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// Plan2Code Web Console - the agents view's mount, state and server calls.
|
||||
//
|
||||
// One mount serves the User Preferences Agents & models tab and the
|
||||
// agent-less setup page, drawn as a master-detail split: the list on the
|
||||
// left (agents-summary.js), the picked agent's form or state in the right
|
||||
// pane (agents-form.js / agents-summary.js), the row-list editor shared by
|
||||
// every list field (agents-list-editor.js) and the pure helpers underneath
|
||||
// (agents-data.js). Picking a row is the navigation; there is no back page.
|
||||
// agent-less setup page. Preferences draws a roster of agent cards
|
||||
// (agents-summary.js) with the picked agent's form in a side drawer
|
||||
// (agents-form.js) and an Add agent chooser where the starter templates are an
|
||||
// opt-in; the setup page keeps a master-detail split, its list on the left and
|
||||
// the picked entry's state (or the same form) in the right pane. The row-list
|
||||
// editor shared by every list field is agents-list-editor.js and the pure
|
||||
// helpers underneath are agents-data.js. Picking a card or row is the
|
||||
// navigation; there is no back page.
|
||||
// Nothing saves as it changes: a form edits a draft, and its Save sends the
|
||||
// saved list with only that draft swapped in, so a half-typed command line
|
||||
// never reaches agents.json or models.json.
|
||||
@@ -24,8 +27,9 @@ import {
|
||||
isDirty,
|
||||
nameOf,
|
||||
cleanAgent,
|
||||
templateDraft,
|
||||
} from "./agents/agents-data.js";
|
||||
import { renderSummary, drawSummaryPane, drawBadge } from "./agents/agents-summary.js";
|
||||
import { renderSummary, drawSummaryPane, drawBadge, drawChooser, markTemplateState } from "./agents/agents-summary.js";
|
||||
import { drawForm, renderDirty } from "./agents/agents-form.js";
|
||||
|
||||
/**
|
||||
@@ -113,6 +117,13 @@ export function mountAgentsView(container, opts = {}) {
|
||||
// warnings while Save anyway is on offer.
|
||||
formError: null,
|
||||
formReplace: null,
|
||||
// The drawer's tab ("models" or "launch"), the template a new agent was
|
||||
// started from (its name, for the form's head), and whether the Add agent
|
||||
// chooser is up; templateState remembers each template command's check.
|
||||
tab: "models",
|
||||
draftFrom: null,
|
||||
chooserOpen: false,
|
||||
templateState: new Map(),
|
||||
// Delete agent waiting for its second click; the folds' open state, kept
|
||||
// across redraws.
|
||||
confirming: false,
|
||||
@@ -125,6 +136,10 @@ export function mountAgentsView(container, opts = {}) {
|
||||
confirmUnsaved,
|
||||
pick,
|
||||
pickSetup,
|
||||
openChooser,
|
||||
closeChooser,
|
||||
startNew,
|
||||
closeDrawer,
|
||||
save: (key, options) => saveForm(key, options),
|
||||
discard: () => discardOpen(),
|
||||
deleteAgent,
|
||||
@@ -157,6 +172,24 @@ export function mountAgentsView(container, opts = {}) {
|
||||
else drawSummaryPane(ctx);
|
||||
}
|
||||
|
||||
// Preferences only: the drawer shows while a form is open, and the roster
|
||||
// behind it is out of reach (it also sits behind a scrim).
|
||||
function syncDrawer() {
|
||||
const drawer = $("drawer");
|
||||
if (!drawer) return;
|
||||
drawer.hidden = !ctx.openKey;
|
||||
const behind = Boolean(ctx.openKey || ctx.chooserOpen);
|
||||
$("table").inert = behind;
|
||||
if ($("add")) $("add").inert = behind;
|
||||
}
|
||||
|
||||
function syncChooser() {
|
||||
const box = $("chooser");
|
||||
if (!box) return;
|
||||
box.hidden = !ctx.chooserOpen;
|
||||
syncDrawer();
|
||||
}
|
||||
|
||||
function edited() {
|
||||
if (ctx.openKey) {
|
||||
// A model added or removed changes what the strengths fold may pick.
|
||||
@@ -173,6 +206,7 @@ export function mountAgentsView(container, opts = {}) {
|
||||
ctx.drafts.delete(ctx.openKey);
|
||||
ctx.strengthDrafts.delete(ctx.openKey);
|
||||
ctx.openKey = null;
|
||||
ctx.draftFrom = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -199,14 +233,18 @@ export function mountAgentsView(container, opts = {}) {
|
||||
ctx.formReplace = null;
|
||||
ctx.confirming = false;
|
||||
ctx.strengthsOpen = false;
|
||||
ctx.tab = key === "agent:new" ? "launch" : "models";
|
||||
ctx.argsOpen = key === "agent:new";
|
||||
// A built-in's only section is its models: folded it would show nothing.
|
||||
ctx.modelsOpen = key.startsWith("cli:");
|
||||
if (mode === "setup") ctx.setupSel = key.startsWith("agent:") && key !== "agent:new" ? "setup:" + agentId(key) : null;
|
||||
if (!ctx.drafts.has(key)) ctx.drafts.set(key, structuredClone(key === "agent:new" ? newAgent() : savedEntry(ctx.saved, key)));
|
||||
renderSummary(ctx);
|
||||
syncDrawer();
|
||||
drawForm(ctx);
|
||||
$("form").querySelector("input")?.focus();
|
||||
// A form of fields starts in its first one; the models list would scroll to its add row, so it starts on its tab.
|
||||
const first = ctx.tab === "launch" ? $("form").querySelector(".prefs-agents-fields input") : null;
|
||||
(first || $("form").querySelector('.agent-tab[aria-selected="true"]'))?.focus();
|
||||
}
|
||||
|
||||
// The form goes back to the empty or picked pane; focus goes to the row
|
||||
@@ -219,16 +257,77 @@ export function mountAgentsView(container, opts = {}) {
|
||||
ctx.strengthDrafts.delete(ctx.openKey);
|
||||
}
|
||||
ctx.openKey = null;
|
||||
ctx.draftFrom = null;
|
||||
ctx.formError = null;
|
||||
ctx.formReplace = null;
|
||||
ctx.confirming = false;
|
||||
renderSummary(ctx);
|
||||
drawPane();
|
||||
syncDrawer();
|
||||
const rowKey = left && mode === "setup" && left.startsWith("agent:") ? "setup:" + agentId(left) : left;
|
||||
const row = rowKey && $("table").querySelector(`[data-key="${CSS.escape(rowKey)}"]`);
|
||||
(row || $("add")).focus();
|
||||
}
|
||||
|
||||
const agentCardFor = (key) => $("table").querySelector(`[data-key="${CSS.escape(key)}"]`);
|
||||
|
||||
// The drawer's way out (Close, its scrim, Esc): a dirty draft asks first.
|
||||
async function closeDrawer() {
|
||||
const left = ctx.openKey;
|
||||
if (!left) return;
|
||||
if (!(await leaveForm())) return focusOpen();
|
||||
ctx.formError = null;
|
||||
ctx.formReplace = null;
|
||||
ctx.confirming = false;
|
||||
renderSummary(ctx);
|
||||
drawPane();
|
||||
syncDrawer();
|
||||
(agentCardFor(left) || $("add"))?.focus();
|
||||
}
|
||||
|
||||
// Add agent: the chooser, with the templates as an opt-in. Picking a tile is
|
||||
// what starts the draft (and asks about an unsaved one first).
|
||||
function openChooser() {
|
||||
ctx.chooserOpen = true;
|
||||
drawChooser(ctx);
|
||||
syncChooser();
|
||||
$("chooser").querySelector(".chooser-tile:not(:disabled)")?.focus();
|
||||
for (const t of ctx.saved.templates) checkTemplate(t.command);
|
||||
}
|
||||
|
||||
function closeChooser() {
|
||||
ctx.chooserOpen = false;
|
||||
syncChooser();
|
||||
$("add")?.focus();
|
||||
}
|
||||
|
||||
// Whether a template's command is on this computer, asked once per load.
|
||||
async function checkTemplate(command) {
|
||||
let state = ctx.templateState.get(command) || "unknown";
|
||||
if (state === "unknown") {
|
||||
try {
|
||||
const res = await fetch("/agents/test", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ command }),
|
||||
});
|
||||
if (res.ok) state = (await res.json()).found ? "ok" : "missing";
|
||||
} catch {}
|
||||
ctx.templateState.set(command, state);
|
||||
}
|
||||
if (ctx.chooserOpen) markTemplateState(ctx, command, state);
|
||||
}
|
||||
|
||||
async function startNew(template) {
|
||||
if (!(await leaveForm())) return;
|
||||
ctx.chooserOpen = false;
|
||||
syncChooser();
|
||||
ctx.drafts.set("agent:new", structuredClone(template ? templateDraft(template) : newAgent()));
|
||||
openForm("agent:new");
|
||||
ctx.draftFrom = template ? template.name : null;
|
||||
drawForm(ctx);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- badges */
|
||||
|
||||
// Whether each row's command is on PATH, all at once. /agents/test only
|
||||
@@ -308,6 +407,7 @@ export function mountAgentsView(container, opts = {}) {
|
||||
ctx.strengthDrafts.delete(ctx.openKey);
|
||||
ctx.openKey = key;
|
||||
ctx.drafts.set(key, structuredClone(savedEntry(ctx.saved, key)));
|
||||
ctx.draftFrom = null;
|
||||
ctx.formError = null;
|
||||
ctx.formReplace = null;
|
||||
renderSummary(ctx);
|
||||
@@ -357,6 +457,7 @@ export function mountAgentsView(container, opts = {}) {
|
||||
const isNew = key === "agent:new";
|
||||
if (isNew && (!String(draft.name || "").trim() || !String(draft.command || "").trim())) {
|
||||
ctx.formError = { field: String(draft.name || "").trim() ? "command" : "name", error: "Give it a name and a command first." };
|
||||
ctx.tab = "launch";
|
||||
drawForm(ctx);
|
||||
return false;
|
||||
}
|
||||
@@ -373,6 +474,7 @@ export function mountAgentsView(container, opts = {}) {
|
||||
}
|
||||
if (!res.ok) {
|
||||
ctx.formError = { field: body.index === at ? body.field : null, error: body.error || "Could not save." };
|
||||
if (ctx.formError.field) ctx.tab = ctx.formError.field === "models" ? "models" : "launch";
|
||||
ctx.formReplace = null;
|
||||
drawForm(ctx);
|
||||
return false;
|
||||
@@ -471,7 +573,7 @@ export function mountAgentsView(container, opts = {}) {
|
||||
// Back into the form after Keep editing or a failed Save: the marked field, else the first.
|
||||
function focusOpen() {
|
||||
const form = $("form");
|
||||
(form.querySelector("input.invalid") || form.querySelector("input"))?.focus();
|
||||
(form.querySelector("input.invalid") || form.querySelector('.agent-tab[aria-selected="true"]'))?.focus();
|
||||
}
|
||||
|
||||
// Each time the dialog opens: the list, from the server. The setup mount
|
||||
@@ -480,6 +582,9 @@ export function mountAgentsView(container, opts = {}) {
|
||||
async function load() {
|
||||
const seq = ++loadSeq;
|
||||
ctx.openKey = null;
|
||||
ctx.draftFrom = null;
|
||||
ctx.chooserOpen = false;
|
||||
ctx.templateState.clear();
|
||||
ctx.drafts.clear();
|
||||
ctx.strengthDrafts.clear();
|
||||
ctx.found.clear();
|
||||
@@ -530,10 +635,28 @@ export function mountAgentsView(container, opts = {}) {
|
||||
setAgentsStatus(problems.join(" "), problems.length > 0);
|
||||
renderSummary(ctx);
|
||||
drawPane();
|
||||
syncChooser();
|
||||
}
|
||||
|
||||
function wire() {
|
||||
$("add")?.addEventListener("click", () => pick("agent:new"));
|
||||
$("add")?.addEventListener("click", () => (mode === "setup" ? pick("agent:new") : openChooser()));
|
||||
$("scrim")?.addEventListener("click", () => closeDrawer());
|
||||
// Esc backs out of the topmost layer first: the chooser, then the drawer
|
||||
// (a dirty draft asks), before the dialog's own Esc closes Preferences.
|
||||
if (mode === "prefs") {
|
||||
container.addEventListener("keydown", (e) => {
|
||||
if (e.key !== "Escape" || e.defaultPrevented) return;
|
||||
if (ctx.chooserOpen) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
closeChooser();
|
||||
} else if (ctx.openKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
closeDrawer();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { load, wire, hasUnsaved, unsavedName, saveOpen, discardOpen, focusOpen };
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
// Plan2Code Web Console - the agents view's per-agent form, the detail pane.
|
||||
// Plan2Code Web Console - the agents view's per-agent form, the drawer's content.
|
||||
//
|
||||
// What the right pane draws while a draft is being edited: the built-in's
|
||||
// models fold or an added agent's fields (identity inline, Models and
|
||||
// Command-line arguments folded), the foot (Save, Discard, the Unsaved
|
||||
// badge, Save anyway after a 409, Delete with its inline confirm), error
|
||||
// marking, and the focus save/restore that keeps a redraw from stealing
|
||||
// where the person was. It only draws and listens: state and fetches live
|
||||
// in the mount, reached through `ctx`.
|
||||
// What the drawer (or, on the setup page, the split's right pane) draws while a
|
||||
// draft is being edited: the head (name, command, a close button), two tabs,
|
||||
// Models & strengths and Launch, the foot (Save, Discard, the Unsaved badge,
|
||||
// Save anyway after a 409, Delete with its inline confirm), error marking, and
|
||||
// the focus save/restore that keeps a redraw from stealing where the person
|
||||
// was. A built-in's Launch tab only reads (Plan2Code owns its command); an
|
||||
// added agent's holds the fields. It only draws and listens: state and fetches
|
||||
// live in the mount, reached through `ctx`.
|
||||
|
||||
import { el } from "../../render.js";
|
||||
import { listEditor } from "./agents-list-editor.js";
|
||||
import { BUILT_IN, HAS_EFFORT, cliOf, savedEntry, isDirty } from "./agents-data.js";
|
||||
import { strengthsFold } from "./agents-strengths.js";
|
||||
import { strengthsPanel } from "./agents-strengths.js";
|
||||
import { drawBadge } from "./agents-summary.js";
|
||||
|
||||
function agentField(label, field, child) {
|
||||
const wrap = el("div", "agent-field");
|
||||
@@ -63,50 +65,152 @@ function fold(ctx, which, title, cls, kids) {
|
||||
return d;
|
||||
}
|
||||
|
||||
// A built-in's whole form is its models, so the one fold holds the note, the
|
||||
// locked shipped list and the editor for the person's own additions.
|
||||
function builtInFields(ctx, cli, draft) {
|
||||
const shipped = el("div", "models-list prefs-agents-shipped");
|
||||
shipped.setAttribute("aria-label", "Comes with Plan2Code");
|
||||
for (const m of ctx.saved.shipped[cli]) {
|
||||
const row = el("div", "models-row locked");
|
||||
row.append(el("span", null, m.id), el("span", null, m.label || ""));
|
||||
shipped.appendChild(row);
|
||||
/* ------------------------------------------------------------ models tab */
|
||||
|
||||
// One model: its name and id, the pill set (when the strengths loaded), and a
|
||||
// Remove for the ones the person added.
|
||||
function modelRow(ctx, m, panel, onRemove) {
|
||||
const row = el("div", onRemove ? "models-row" : "models-row locked");
|
||||
const name = el("span", "model-name");
|
||||
const named = m.label && m.label !== m.id;
|
||||
name.append(named ? m.label : m.id);
|
||||
if (named) name.append(el("code", null, m.id));
|
||||
row.appendChild(name);
|
||||
row.appendChild(panel ? panel.pills(m.id, m.label || m.id) : el("span"));
|
||||
if (onRemove) {
|
||||
const remove = el("button", "btn small ghost", "Remove");
|
||||
remove.type = "button";
|
||||
remove.setAttribute("aria-label", "Remove " + (m.label || m.id));
|
||||
remove.addEventListener("click", onRemove);
|
||||
row.appendChild(remove);
|
||||
} else {
|
||||
row.appendChild(el("span"));
|
||||
}
|
||||
const note = el("div", "models-note");
|
||||
note.innerHTML =
|
||||
"<ul>" +
|
||||
"<li>Restart <code>plan2code</code> to see a change in its model menu.</li>" +
|
||||
"<li>At any time, run <code>plan2code --model <id></code>, or pick your model inside your agent before running a skill.</li>" +
|
||||
"<li>Updating Plan2Code refreshes the built-in list. Models you added stay, unless the built-in list now includes them.</li>" +
|
||||
"<li>Devin models are limited to Low, Medium and High effort.</li>" +
|
||||
"</ul>";
|
||||
const comes = el("div", "agent-field");
|
||||
comes.append(el("span", null, "Comes with Plan2Code"));
|
||||
if (ctx.saved.shipped[cli].length) comes.append(shipped);
|
||||
else comes.append(el("p", "help prefs-agents-none", `No models ship for ${BUILT_IN[cli]} yet; add your own below.`));
|
||||
const yours = agentField(
|
||||
"Models you added",
|
||||
"models",
|
||||
listEditor({ list: draft, kind: "models", field: "models", optionalName: false, addLabel: "Add a model", onChange: ctx.edited })
|
||||
);
|
||||
const models = () => [...ctx.saved.shipped[cli], ...draft];
|
||||
return [
|
||||
fold(ctx, "modelsOpen", "Models", "agent-fold", [note, comes, yours]),
|
||||
...(ctx.modelsLoaded ? [strengthsFold(ctx, cli, draft, { models, hasEffort: HAS_EFFORT.includes(cli) })] : []),
|
||||
];
|
||||
return row;
|
||||
}
|
||||
|
||||
function addedFields(ctx, draft) {
|
||||
// The add-a-model row: an id, a name for the menu, and the button that moves
|
||||
// them into the draft, so the draft never holds a half-typed model.
|
||||
function addModelRow(ctx, list, { nameRequired, taken }) {
|
||||
const wrap = el("div", "agent-row model model-add");
|
||||
const id = el("input");
|
||||
id.placeholder = "Model id, for {model}";
|
||||
id.setAttribute("aria-label", "Model id");
|
||||
id.dataset.field = "models";
|
||||
const label = el("input");
|
||||
label.placeholder = nameRequired ? "Name shown in the menu" : "Name shown in the menu (optional)";
|
||||
label.setAttribute("aria-label", "Name shown in the menu");
|
||||
label.dataset.field = "models";
|
||||
const add = el("button", "btn small", "Add a model");
|
||||
add.type = "button";
|
||||
const submit = () => {
|
||||
const value = id.value.trim();
|
||||
const text = label.value.trim();
|
||||
id.classList.toggle("invalid", !value || taken(value));
|
||||
if (!value || taken(value)) {
|
||||
id.focus();
|
||||
return;
|
||||
}
|
||||
list.push(nameRequired ? { id: value, label: text || value } : text ? { id: value, label: text } : { id: value });
|
||||
ctx.edited();
|
||||
ctx.drawForm();
|
||||
ctx.$("form").querySelector(".model-add input")?.focus();
|
||||
};
|
||||
add.addEventListener("click", submit);
|
||||
for (const input of [id, label]) {
|
||||
input.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
wrap.append(id, label, add);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function modelsTab(ctx, key, draft) {
|
||||
const isCli = key.startsWith("cli:");
|
||||
const cli = isCli ? cliOf(key) : null;
|
||||
const mine = isCli ? draft : draft.models;
|
||||
const shipped = isCli ? ctx.saved.shipped[cli] : [];
|
||||
const all = () => [...shipped, ...mine.filter((m) => m.id)];
|
||||
const owner = isCli ? cli : key === "agent:new" ? "" : savedEntry(ctx.saved, key).id;
|
||||
const panel = ctx.modelsLoaded ? strengthsPanel(ctx, owner, draft, { models: all, hasEffort: isCli && HAS_EFFORT.includes(cli) }) : null;
|
||||
const kids = [];
|
||||
if (panel) {
|
||||
const lead = agentField("In the loop", "strengths", panel.box);
|
||||
lead.classList.add("prefs-agents-strengths-field");
|
||||
kids.push(lead);
|
||||
kids.push(el("p", "help models-tip", "Tap Thrifty, Balanced or Best on a model below to make it that strength's pick."));
|
||||
}
|
||||
if (isCli) {
|
||||
const comes = el("div", "agent-field");
|
||||
comes.append(el("span", null, "Comes with Plan2Code"));
|
||||
if (shipped.length) {
|
||||
const list = el("div", "models-list prefs-agents-shipped");
|
||||
list.setAttribute("aria-label", "Comes with Plan2Code");
|
||||
for (const m of shipped) list.appendChild(modelRow(ctx, m, panel, null));
|
||||
comes.append(list);
|
||||
} else {
|
||||
comes.append(el("p", "help prefs-agents-none", `No models ship for ${BUILT_IN[cli]} yet; add your own below.`));
|
||||
}
|
||||
kids.push(comes);
|
||||
}
|
||||
const yours = agentField(isCli ? "Models you added" : "Models", "models", el("div", "models-list prefs-agents-mine"));
|
||||
const rows = yours.querySelector(".models-list");
|
||||
mine.forEach((m, i) =>
|
||||
rows.appendChild(
|
||||
modelRow(ctx, m, panel, () => {
|
||||
mine.splice(i, 1);
|
||||
ctx.edited();
|
||||
ctx.drawForm();
|
||||
})
|
||||
)
|
||||
);
|
||||
const taken = (id) => all().some((m) => m.id === id);
|
||||
yours.appendChild(addModelRow(ctx, mine, { nameRequired: isCli, taken }));
|
||||
kids.push(yours);
|
||||
if (isCli) {
|
||||
const note = el("div", "models-note");
|
||||
note.innerHTML =
|
||||
"<ul>" +
|
||||
"<li>Restart <code>plan2code</code> to see a change in its model menu.</li>" +
|
||||
"<li>At any time, run <code>plan2code --model <id></code>, or pick your model inside your agent before running a skill.</li>" +
|
||||
"<li>Updating Plan2Code refreshes the built-in list. Models you added stay, unless the built-in list now includes them.</li>" +
|
||||
"<li>Devin models are limited to Low, Medium and High effort.</li>" +
|
||||
"</ul>";
|
||||
kids.push(fold(ctx, "modelsOpen", "About this list", "agent-fold", [note]));
|
||||
}
|
||||
return kids;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ launch tab */
|
||||
|
||||
// A built-in's Launch tab only reads: Plan2Code ships and updates its command.
|
||||
function builtInLaunch(ctx, key) {
|
||||
const cli = cliOf(key);
|
||||
const entry = ctx.saved.builtins.find((b) => b.id === cli);
|
||||
const note = el("div", "note");
|
||||
note.append(el("b", null, "Managed by Plan2Code. "), `The command and arguments for ${BUILT_IN[cli]} ship with the app and update with it. Only its models are yours to change.`);
|
||||
const list = el("dl", "kv");
|
||||
const state = el("span", "prefs-badge");
|
||||
const known = ctx.found.get(key);
|
||||
drawBadge(state, known ? known.state : "unknown");
|
||||
const command = el("dd");
|
||||
command.append(el("code", null, (entry && entry.command) || cli), " ", state);
|
||||
list.append(el("dt", null, "Command"), command);
|
||||
if (entry && entry.prompt) {
|
||||
const prompt = el("dd");
|
||||
prompt.appendChild(el("code", null, entry.prompt));
|
||||
list.append(el("dt", null, "Start prompt"), prompt);
|
||||
}
|
||||
return [note, list];
|
||||
}
|
||||
|
||||
function addedLaunch(ctx, draft) {
|
||||
const command = agentField("Command", "command", agentInput(ctx, draft, "command", "Command", "Program to run, such as myagent", true));
|
||||
command.append(agentTest(ctx, draft));
|
||||
const models = fold(ctx, "modelsOpen", "Models", "agent-fold", [
|
||||
agentField(
|
||||
"Models",
|
||||
"models",
|
||||
listEditor({ list: draft.models, kind: "models", field: "models", addLabel: "Add a model", onChange: ctx.edited })
|
||||
),
|
||||
]);
|
||||
const args = fold(ctx, "argsOpen", "Command-line arguments", "agent-fold prefs-agents-args", [
|
||||
agentField("Arguments", "args", listEditor({ list: draft.args, field: "args", placeholder: "--message={prompt}", addLabel: "Add an argument", aria: "Arguments", onChange: ctx.edited })),
|
||||
agentField("Bypass arguments", "bypassArgs", listEditor({ list: draft.bypassArgs, field: "bypassArgs", placeholder: "--yes-always", addLabel: "Add an argument", aria: "Bypass arguments", onChange: ctx.edited })),
|
||||
@@ -116,14 +220,12 @@ function addedFields(ctx, draft) {
|
||||
agentField("Name", "name", agentInput(ctx, draft, "name", "Name", "Name shown in the menu", true)),
|
||||
command,
|
||||
agentField("Start prompt", "prompt", agentInput(ctx, draft, "prompt", "Start prompt", "/plan2code (blank starts with nothing typed)", false)),
|
||||
models,
|
||||
...(ctx.modelsLoaded
|
||||
? [strengthsFold(ctx, ctx.openKey === "agent:new" ? "" : savedEntry(ctx.saved, ctx.openKey).id, draft, { models: () => draft.models, hasEffort: false })]
|
||||
: []),
|
||||
args,
|
||||
];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ foot */
|
||||
|
||||
// Save, Discard and the Unsaved badge (shown only while the draft differs),
|
||||
// the Saved mark's spot, Save anyway after a 409, and Delete agent with its
|
||||
// confirm on the form itself (never the browser's confirm()).
|
||||
@@ -180,7 +282,7 @@ export function renderDirty(ctx, key) {
|
||||
// Which field or button has focus, so a redraw (an id assigned, an error
|
||||
// marked) puts the person back where they were: { nth, start, end }. What
|
||||
// they typed is already in the draft the redraw reads.
|
||||
const FORM_FOCUSABLE = "input, button, summary";
|
||||
const FORM_FOCUSABLE = "input, button, summary, select";
|
||||
|
||||
function formFocus(form) {
|
||||
const active = document.activeElement;
|
||||
@@ -203,29 +305,68 @@ function restoreFormFocus(form, at) {
|
||||
}
|
||||
}
|
||||
|
||||
const TABS = [
|
||||
["models", "Models & strengths"],
|
||||
["launch", "Launch"],
|
||||
];
|
||||
|
||||
export function drawForm(ctx) {
|
||||
const pane = ctx.$("form");
|
||||
const key = ctx.openKey;
|
||||
const draft = ctx.drafts.get(key);
|
||||
const focus = formFocus(pane);
|
||||
pane.replaceChildren();
|
||||
const isCli = key.startsWith("cli:");
|
||||
const head = el("div", "form-head");
|
||||
const title = el("h3", "prefs-agents-title");
|
||||
title.tabIndex = -1;
|
||||
if (key.startsWith("cli:")) title.append(el("span", null, BUILT_IN[cliOf(key)]), el("code", null, cliOf(key)));
|
||||
else title.append(el("span", null, key === "agent:new" ? "New agent" : savedEntry(ctx.saved, key).name));
|
||||
if (isCli) title.append(el("span", null, BUILT_IN[cliOf(key)]), el("code", null, cliOf(key)));
|
||||
else {
|
||||
title.append(el("span", null, key === "agent:new" ? "New agent" : savedEntry(ctx.saved, key).name));
|
||||
if (key === "agent:new" && ctx.draftFrom) title.append(el("span", "tag", `From the ${ctx.draftFrom} template`));
|
||||
}
|
||||
head.appendChild(title);
|
||||
if (ctx.$("drawer")) {
|
||||
const close = el("button", "btn small ghost drawer-close", "Close");
|
||||
close.type = "button";
|
||||
close.setAttribute("aria-label", "Close");
|
||||
close.addEventListener("click", () => ctx.closeDrawer());
|
||||
head.appendChild(close);
|
||||
}
|
||||
pane.appendChild(head);
|
||||
|
||||
const tabs = el("div", "agent-tabs");
|
||||
tabs.setAttribute("role", "tablist");
|
||||
const order = key === "agent:new" ? [...TABS].reverse() : TABS;
|
||||
for (const [id, label] of order) {
|
||||
const tab = el("button", "agent-tab", label);
|
||||
tab.type = "button";
|
||||
tab.setAttribute("role", "tab");
|
||||
tab.dataset.tab = id;
|
||||
tab.setAttribute("aria-selected", String(ctx.tab === id));
|
||||
tab.addEventListener("click", () => {
|
||||
if (ctx.tab === id) return;
|
||||
ctx.tab = id;
|
||||
ctx.drawForm();
|
||||
});
|
||||
tabs.appendChild(tab);
|
||||
}
|
||||
pane.appendChild(tabs);
|
||||
|
||||
const body = el("div", "agent-body");
|
||||
const fields = el("div", "prefs-agents-fields");
|
||||
fields.append(...(key.startsWith("cli:") ? builtInFields(ctx, cliOf(key), draft) : addedFields(ctx, draft)));
|
||||
pane.appendChild(fields);
|
||||
fields.setAttribute("role", "tabpanel");
|
||||
if (ctx.tab === "models") fields.append(...modelsTab(ctx, key, draft));
|
||||
else fields.append(...(isCli ? builtInLaunch(ctx, key) : addedLaunch(ctx, draft)));
|
||||
body.appendChild(fields);
|
||||
if (ctx.formError) {
|
||||
for (const input of pane.querySelectorAll("input")) {
|
||||
for (const input of body.querySelectorAll("input")) {
|
||||
if (input.dataset.field === ctx.formError.field) input.classList.add("invalid");
|
||||
}
|
||||
pane.appendChild(el("p", "agent-error", ctx.formError.error));
|
||||
body.appendChild(el("p", "agent-error", ctx.formError.error));
|
||||
}
|
||||
if (ctx.formReplace && ctx.formReplace.length) pane.appendChild(el("p", "agent-error", ctx.formReplace.join(" ")));
|
||||
if (ctx.formReplace && ctx.formReplace.length) body.appendChild(el("p", "agent-error", ctx.formReplace.join(" ")));
|
||||
pane.appendChild(body);
|
||||
pane.appendChild(formFoot(ctx, key));
|
||||
renderDirty(ctx, key);
|
||||
restoreFormFocus(pane, focus);
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
// Plan2Code Web Console - the "Strengths in the loop" fold of an agent's form.
|
||||
// Plan2Code Web Console - the "In the loop" panel of an agent's form.
|
||||
//
|
||||
// Maps the loop's three words (Thrifty, Balanced, Best) to one of the agent's
|
||||
// own models, and to an effort where the agent takes one. Choices are
|
||||
// select-only from the agent's Models list. An untouched row follows what
|
||||
// ships; only a row the person changed is kept in the form's strength draft
|
||||
// (ctx.strengthDrafts, by form key), which the form's Save sends. The rule that
|
||||
// reads a row is resolveStrengths, the same module the server uses.
|
||||
// own models, and to an effort where the agent takes one. The panel is two
|
||||
// halves that stay in step: a summary box (one row per word: the model it
|
||||
// resolves to, an effort select, and Reset or "default") and a pill set each
|
||||
// model row carries, where tapping a word on a model makes it that word's pick.
|
||||
// An untouched row follows what ships; only a row the person changed is kept in
|
||||
// the form's strength draft (ctx.strengthDrafts, by form key), which the form's
|
||||
// Save sends. The rule that reads a row is resolveStrengths, the same module the
|
||||
// server uses.
|
||||
|
||||
import { el } from "../../render.js";
|
||||
import { STRENGTH_ORDER, resolveStrengths } from "../../strengths.js";
|
||||
import { canonical, strengthOwner } from "./agents-data.js";
|
||||
|
||||
const WORDS = { thrifty: "Thrifty", balanced: "Balanced", best: "Best" };
|
||||
export const WORDS = { thrifty: "Thrifty", balanced: "Balanced", best: "Best" };
|
||||
const HINTS = { thrifty: "Quick, cheap steps", balanced: "The everyday pick", best: "The hardest steps" };
|
||||
const EFFORTS = ["low", "medium", "high"];
|
||||
|
||||
function option(value, text) {
|
||||
@@ -20,12 +24,19 @@ function option(value, text) {
|
||||
return o;
|
||||
}
|
||||
|
||||
// A word as a colored chip: Thrifty, Balanced and Best get the rank colors.
|
||||
export function wordChip(word) {
|
||||
return el("span", "tier t-" + word, WORDS[word]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The fold for the open form. `models` is the agent's Models list ({ id, label }
|
||||
* The panel for the open form. `models` is the agent's Models list ({ id, label }
|
||||
* rows) or a function returning it, read at every redraw so a model added in the
|
||||
* same form shows up. `hasEffort` adds the effort select.
|
||||
* same form shows up. `hasEffort` adds the effort select. Returns
|
||||
* { box, pills(id, label), refresh }: the summary box, a builder for one model's
|
||||
* pill set, and the redraw the form's edits call through ctx.strengthsRefresh.
|
||||
*/
|
||||
export function strengthsFold(ctx, agentId, draft, { models, hasEffort }) {
|
||||
export function strengthsPanel(ctx, agentId, draft, { models, hasEffort }) {
|
||||
const key = ctx.openKey;
|
||||
const owner = agentId || strengthOwner(key);
|
||||
const shipped = (ctx.saved.strengths.shipped && ctx.saved.strengths.shipped[owner]) || {};
|
||||
@@ -39,13 +50,18 @@ export function strengthsFold(ctx, agentId, draft, { models, hasEffort }) {
|
||||
const rows = ctx.strengthDrafts.has(key) ? ctx.strengthDrafts.get(key) : ctx.saved.strengths.user && ctx.saved.strengths.user[owner];
|
||||
return rows && typeof rows === "object" ? rows : {};
|
||||
};
|
||||
const state = () => {
|
||||
const list = modelList();
|
||||
const base = { shipped, models: list.map((m) => m.id), hasEffort };
|
||||
return { list, user: userRows(), resolved: resolveStrengths({ ...base, user: userRows() }), dflt: resolveStrengths({ ...base, user: {} }) };
|
||||
};
|
||||
const labelOf = (id) => {
|
||||
const m = modelList().find((x) => x.id === id);
|
||||
return m ? m.label || m.id : id;
|
||||
};
|
||||
|
||||
const details = el("details", "agent-fold prefs-agents-strengths");
|
||||
details.open = ctx.strengthsOpen;
|
||||
details.addEventListener("toggle", () => (ctx.strengthsOpen = details.open));
|
||||
details.appendChild(el("summary", null, "Strengths in the loop"));
|
||||
const body = el("div", "strength-body");
|
||||
details.appendChild(body);
|
||||
const box = el("div", "strength-body prefs-agents-strengths");
|
||||
const pillSets = [];
|
||||
|
||||
function setRow(word, row) {
|
||||
const next = { ...userRows() };
|
||||
@@ -55,86 +71,107 @@ export function strengthsFold(ctx, agentId, draft, { models, hasEffort }) {
|
||||
ctx.edited();
|
||||
}
|
||||
|
||||
function draw() {
|
||||
const active = document.activeElement;
|
||||
const back = active && body.contains(active) ? { word: active.closest("[data-word]")?.dataset.word, field: active.dataset.field } : null;
|
||||
body.replaceChildren();
|
||||
const list = modelList();
|
||||
if (!list.length) {
|
||||
body.appendChild(el("p", "help strength-empty", "Add a model under Models first"));
|
||||
function choose(word, id) {
|
||||
const { resolved, dflt } = state();
|
||||
const now = resolved[word];
|
||||
if (now && now.model === id) {
|
||||
// Tapping the pick again clears it only where nothing ships for the word;
|
||||
// with a default, putting it back is Reset's job.
|
||||
if (!dflt[word]) setRow(word, null);
|
||||
return;
|
||||
}
|
||||
const base = { shipped, models: list.map((m) => m.id), hasEffort };
|
||||
const user = userRows();
|
||||
const resolved = resolveStrengths({ ...base, user });
|
||||
const dflt = resolveStrengths({ ...base, user: {} });
|
||||
const next = { model: id };
|
||||
if (hasEffort && now && now.effort) next.effort = now.effort;
|
||||
setRow(word, canonical(next) === canonical(dflt[word]) ? null : next);
|
||||
}
|
||||
|
||||
for (const word of STRENGTH_ORDER) {
|
||||
const row = el("div", "strength-row");
|
||||
row.dataset.word = word;
|
||||
row.appendChild(el("span", "strength-word", WORDS[word]));
|
||||
|
||||
const model = el("select");
|
||||
model.dataset.field = "model";
|
||||
model.setAttribute("aria-label", `${WORDS[word]} model`);
|
||||
// Nothing ships for this word: "not mapped" is a real choice. With a default,
|
||||
// clearing a row is Reset's job.
|
||||
if (!dflt[word]) model.appendChild(option("", "not mapped"));
|
||||
for (const m of list) model.appendChild(option(m.id, m.label && m.label !== m.id ? `${m.label} (${m.id})` : m.id));
|
||||
model.value = resolved[word] ? resolved[word].model : "";
|
||||
model.addEventListener("change", () => {
|
||||
if (!model.value) return setRow(word, null);
|
||||
const next = { model: model.value };
|
||||
if (hasEffort && resolved[word] && resolved[word].effort) next.effort = resolved[word].effort;
|
||||
setRow(word, canonical(next) === canonical(dflt[word]) ? null : next);
|
||||
});
|
||||
row.appendChild(model);
|
||||
|
||||
if (hasEffort) {
|
||||
const effort = el("select");
|
||||
effort.dataset.field = "effort";
|
||||
effort.setAttribute("aria-label", `${WORDS[word]} effort`);
|
||||
effort.disabled = !resolved[word];
|
||||
effort.appendChild(option("", "no effort"));
|
||||
for (const e of EFFORTS) effort.appendChild(option(e, e));
|
||||
effort.value = (resolved[word] && resolved[word].effort) || "";
|
||||
effort.addEventListener("change", () => {
|
||||
const next = { model: resolved[word].model };
|
||||
if (effort.value) next.effort = effort.value;
|
||||
setRow(word, canonical(next) === canonical(dflt[word]) ? null : next);
|
||||
});
|
||||
row.appendChild(effort);
|
||||
function refresh() {
|
||||
const active = document.activeElement;
|
||||
const back = active && box.contains(active) ? active.closest("[data-word]")?.dataset.word : null;
|
||||
box.replaceChildren();
|
||||
const { list, user, resolved, dflt } = state();
|
||||
if (!list.length) {
|
||||
box.appendChild(el("p", "help strength-empty", "Add a model first, then choose which one the loop uses for each strength."));
|
||||
} else {
|
||||
for (const word of STRENGTH_ORDER) {
|
||||
const row = el("div", "strength-row");
|
||||
row.dataset.word = word;
|
||||
const label = el("span", "strength-word");
|
||||
label.append(wordChip(word), el("small", "help", HINTS[word]));
|
||||
row.appendChild(label);
|
||||
const pick = resolved[word];
|
||||
row.appendChild(el("span", pick ? "strength-model" : "strength-model none", pick ? labelOf(pick.model) : "not mapped"));
|
||||
if (hasEffort) {
|
||||
const effort = el("select");
|
||||
effort.dataset.field = "effort";
|
||||
effort.setAttribute("aria-label", `${WORDS[word]} effort`);
|
||||
effort.disabled = !pick;
|
||||
effort.appendChild(option("", "no effort"));
|
||||
for (const e of EFFORTS) effort.appendChild(option(e, e));
|
||||
effort.value = (pick && pick.effort) || "";
|
||||
effort.addEventListener("change", () => {
|
||||
const next = { model: pick.model };
|
||||
if (effort.value) next.effort = effort.value;
|
||||
setRow(word, canonical(next) === canonical(dflt[word]) ? null : next);
|
||||
});
|
||||
row.appendChild(effort);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(user, word)) {
|
||||
const reset = el("button", "btn small ghost strength-reset", "Reset");
|
||||
reset.type = "button";
|
||||
reset.dataset.field = "reset";
|
||||
reset.setAttribute("aria-label", `Reset ${WORDS[word]}`);
|
||||
reset.addEventListener("click", () => setRow(word, null));
|
||||
row.appendChild(reset);
|
||||
} else if (pick) {
|
||||
row.appendChild(el("span", "help strength-default", "default"));
|
||||
}
|
||||
box.appendChild(row);
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(user, word)) {
|
||||
const reset = el("button", "btn small ghost strength-reset", "Reset");
|
||||
reset.type = "button";
|
||||
reset.dataset.field = "reset";
|
||||
reset.setAttribute("aria-label", `Reset ${WORDS[word]}`);
|
||||
reset.addEventListener("click", () => setRow(word, null));
|
||||
row.appendChild(reset);
|
||||
} else if (resolved[word]) {
|
||||
row.appendChild(el("span", "help strength-default", "default"));
|
||||
}
|
||||
body.appendChild(row);
|
||||
const offered = STRENGTH_ORDER.filter((w) => resolved[w]).map((w) => WORDS[w]);
|
||||
box.appendChild(
|
||||
el(
|
||||
"p",
|
||||
"help strength-offer",
|
||||
offered.length ? `The loop will offer: ${offered.join(", ")}` : "The loop will not offer a strength for this agent until one is mapped."
|
||||
)
|
||||
);
|
||||
}
|
||||
for (const set of pillSets) {
|
||||
const now = state().resolved;
|
||||
for (const p of set.pills) p.btn.setAttribute("aria-pressed", String(Boolean(now[p.word] && now[p.word].model === set.id)));
|
||||
}
|
||||
|
||||
const offered = STRENGTH_ORDER.filter((w) => resolved[w]).map((w) => WORDS[w]);
|
||||
body.appendChild(
|
||||
el(
|
||||
"p",
|
||||
"help strength-offer",
|
||||
offered.length ? `The loop will offer: ${offered.join(", ")}` : "The loop will not offer a strength for this agent until one is mapped."
|
||||
)
|
||||
);
|
||||
if (back) {
|
||||
// A Reset that was pressed is gone with its row's change: the model select takes the focus.
|
||||
const row = body.querySelector(`[data-word="${back.word}"]`);
|
||||
(row?.querySelector(`[data-field="${back.field}"]`) || row?.querySelector('[data-field="model"]'))?.focus();
|
||||
// A Reset that was pressed is gone with its change: the row's effort select, else its pick, takes the focus.
|
||||
const row = box.querySelector(`[data-word="${back}"]`);
|
||||
const target = row?.querySelector("select") || document.querySelector(`.strength-pill[data-word="${back}"][aria-pressed="true"]`);
|
||||
target?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.strengthsRefresh = draw;
|
||||
draw();
|
||||
return details;
|
||||
// One model's pill set: the three words as toggle buttons, one pressed per word.
|
||||
function pills(id, label) {
|
||||
const wrap = el("span", "strength-pills");
|
||||
wrap.setAttribute("role", "group");
|
||||
wrap.setAttribute("aria-label", `Use ${label} as`);
|
||||
const set = { id, pills: [] };
|
||||
const now = state().resolved;
|
||||
for (const word of STRENGTH_ORDER) {
|
||||
const btn = el("button", "strength-pill t-" + word, WORDS[word]);
|
||||
btn.type = "button";
|
||||
btn.dataset.word = word;
|
||||
btn.dataset.model = id;
|
||||
btn.setAttribute("aria-pressed", String(Boolean(now[word] && now[word].model === id)));
|
||||
btn.setAttribute("aria-label", `Use ${label} as ${WORDS[word]}`);
|
||||
btn.addEventListener("click", () => choose(word, id));
|
||||
set.pills.push({ btn, word });
|
||||
wrap.appendChild(btn);
|
||||
}
|
||||
pillSets.push(set);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
ctx.strengthsRefresh = refresh;
|
||||
refresh();
|
||||
return { box, pills, refresh };
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
// Plan2Code Web Console - the agents view's collection side.
|
||||
//
|
||||
// The master-detail's left column for both mounts: Preferences draws one
|
||||
// pickable row per agent (name, command, found badge, its models) plus the
|
||||
// v3 orchestrator placeholder; the setup page draws the same rows with their
|
||||
// found/outside/missing badges and the starter templates. While no form is
|
||||
// open the right pane is this module's too: the empty text, or the picked
|
||||
// entry's state and way forward (Start, Use it from here, the install lines).
|
||||
// The collection side for both mounts. Preferences draws a roster of cards,
|
||||
// one per agent (name, command, found badge, the model each strength uses),
|
||||
// and the Add agent chooser, where the starter templates are an opt-in. The
|
||||
// setup page keeps its master-detail list: the same agents with their
|
||||
// found/outside/missing badges and the starter templates, and a right pane that
|
||||
// shows the picked entry's state and way forward (Start, Use it from here, the
|
||||
// install lines).
|
||||
// It only draws and listens: every fetch and every piece of state lives in
|
||||
// the mount, reached through `ctx`.
|
||||
|
||||
import { el, copyButton } from "../../render.js";
|
||||
import { summaryRows, serverStateFor, modelNames, agentId, templateDraft } from "./agents-data.js";
|
||||
import { summaryRows, serverStateFor, agentId, templateDraft, HAS_EFFORT } from "./agents-data.js";
|
||||
import { STRENGTH_ORDER, resolveStrengths } from "../../strengths.js";
|
||||
import { wordChip } from "./agents-strengths.js";
|
||||
|
||||
/* ------------------------------------------------------------- badges */
|
||||
|
||||
@@ -26,22 +29,46 @@ export function drawBadge(badge, state) {
|
||||
if (state !== "unknown") badge.classList.add(state);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- the prefs rows */
|
||||
/* -------------------------------------------------------- the prefs cards */
|
||||
|
||||
// One pickable row: the whole row is the Edit button, so it carries the
|
||||
// data-key and the "Edit <name>" aria-label the flows rely on.
|
||||
function prefsRow(ctx, row, check) {
|
||||
const r = el("button", "split-row");
|
||||
// A model's name without its gloss ("Sonnet, latest Sonnet" or "Opus plan: Opus in plan mode" is cut at the first separator), so a card line stays one line.
|
||||
const GLOSS = new RegExp(" " + String.fromCharCode(8212) + " |, |: ");
|
||||
const shortLabel = (label) => label.split(GLOSS)[0];
|
||||
|
||||
// The model each strength resolves to for one row, as [word, label, effort]
|
||||
// triples; empty while the strengths did not load.
|
||||
function strengthLines(ctx, row) {
|
||||
if (!ctx.modelsLoaded) return [];
|
||||
const isCli = row.key.startsWith("cli:");
|
||||
const owner = isCli ? row.command : agentId(row.key);
|
||||
const resolved = resolveStrengths({
|
||||
shipped: (ctx.saved.strengths.shipped && ctx.saved.strengths.shipped[owner]) || {},
|
||||
user: (ctx.saved.strengths.user && ctx.saved.strengths.user[owner]) || {},
|
||||
models: row.models.map((m) => m.id),
|
||||
hasEffort: isCli && HAS_EFFORT.includes(owner),
|
||||
});
|
||||
return STRENGTH_ORDER.map((word) => {
|
||||
const pick = resolved[word];
|
||||
const model = pick && row.models.find((m) => m.id === pick.model);
|
||||
return [word, model ? shortLabel(model.label || model.id) : null, pick && pick.effort];
|
||||
});
|
||||
}
|
||||
|
||||
// One card: the whole card is the Edit button, so it carries the data-key and
|
||||
// the "Edit <name>" aria-label the flows rely on.
|
||||
function agentCard(ctx, row, check) {
|
||||
const r = el("button", "agent-card");
|
||||
r.type = "button";
|
||||
r.dataset.key = row.key;
|
||||
r.setAttribute("aria-label", "Edit " + row.name);
|
||||
r.setAttribute("aria-current", ctx.openKey === row.key ? "true" : "false");
|
||||
r.addEventListener("click", () => ctx.pick(row.key));
|
||||
r.appendChild(el("span", "row-name", row.name));
|
||||
const sub = el("span", "row-sub");
|
||||
sub.id = "row-sub-" + row.key;
|
||||
r.setAttribute("aria-describedby", sub.id);
|
||||
sub.appendChild(el("code", null, row.command));
|
||||
const top = el("span", "card-top");
|
||||
const who = el("span", "card-who");
|
||||
const name = el("span", "row-name", row.name);
|
||||
if (row.key.startsWith("agent:")) name.append(" ", el("span", "tag", "Custom"));
|
||||
who.append(name, el("code", null, row.command));
|
||||
top.appendChild(who);
|
||||
const badge = el("span", "prefs-badge");
|
||||
const known = serverStateFor(ctx.saved, row);
|
||||
if (known) {
|
||||
@@ -55,11 +82,22 @@ function prefsRow(ctx, row, check) {
|
||||
check.push(row);
|
||||
}
|
||||
}
|
||||
sub.appendChild(badge);
|
||||
const names = modelNames(row.models);
|
||||
sub.appendChild(el("span", "row-models", names.length ? `${names.length}: ${names.join(", ")}` : "None"));
|
||||
r.appendChild(sub);
|
||||
if (row.noneShip) r.appendChild(el("span", "help row-note", `No models ship for ${row.name} yet; open this row to add your own.`));
|
||||
top.appendChild(badge);
|
||||
r.appendChild(top);
|
||||
const lines = strengthLines(ctx, row);
|
||||
if (lines.length) {
|
||||
const tiers = el("span", "card-tiers");
|
||||
for (const [word, label, effort] of lines) {
|
||||
const line = el("span", "card-tier");
|
||||
line.append(wordChip(word), label ? el("span", null, effort ? `${label} · ${effort}` : label) : el("span", "muted", "not mapped"));
|
||||
tiers.appendChild(line);
|
||||
}
|
||||
r.appendChild(tiers);
|
||||
}
|
||||
const foot = el("span", "card-foot");
|
||||
foot.append(el("span", "row-models", `${row.models.length} ${row.models.length === 1 ? "model" : "models"}`), el("span", "card-edit", "Edit ›"));
|
||||
r.appendChild(foot);
|
||||
if (row.noneShip && !row.models.length) r.appendChild(el("span", "help row-note", `No models ship for ${row.name} yet; open this card to add your own.`));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -120,15 +158,14 @@ export function renderSummary(ctx) {
|
||||
}
|
||||
} else {
|
||||
const check = [];
|
||||
for (const row of summaryRows(ctx.saved)) list.appendChild(prefsRow(ctx, row, check));
|
||||
if (ctx.saved.templates.length) {
|
||||
list.appendChild(el("div", "split-list-head", "Or start from a template"));
|
||||
for (const t of ctx.saved.templates) list.appendChild(setupRow(ctx, t, "setup:" + t.name));
|
||||
}
|
||||
const soon = el("div", "split-row soon");
|
||||
soon.append(el("span", "row-name", "v3 orchestrator"), el("span", "row-sub", "Nothing to set yet."));
|
||||
list.appendChild(soon);
|
||||
for (const row of summaryRows(ctx.saved)) list.appendChild(agentCard(ctx, row, check));
|
||||
const ghost = el("button", "agent-card ghost");
|
||||
ghost.type = "button";
|
||||
ghost.append(el("span", "plus", "+"), el("b", null, "Add an agent"), el("span", "muted", "From a starter template or your own command"));
|
||||
ghost.addEventListener("click", () => ctx.openChooser());
|
||||
list.appendChild(ghost);
|
||||
if (check.length) ctx.checkFound(check);
|
||||
return;
|
||||
}
|
||||
if (add) list.appendChild(add);
|
||||
}
|
||||
@@ -227,10 +264,8 @@ export function drawSummaryPane(ctx) {
|
||||
const all = [...ctx.saved.builtins, ...ctx.saved.agents];
|
||||
const entry = sel && all.find((e) => "setup:" + e.id === sel);
|
||||
const template = sel && !entry && ctx.saved.templates.find((t) => "setup:" + t.name === sel);
|
||||
if (ctx.mode !== "setup") {
|
||||
pane.appendChild(template ? templatePane(ctx, template) : el("div", "split-empty", "Pick an agent on the left to edit it here."));
|
||||
return;
|
||||
}
|
||||
// Preferences' drawer holds nothing while no form is open.
|
||||
if (ctx.mode !== "setup") return;
|
||||
if (entry) {
|
||||
const box = el("div", "setup-detail");
|
||||
const head = el("div", "form-head");
|
||||
@@ -254,3 +289,71 @@ export function drawSummaryPane(ctx) {
|
||||
}
|
||||
pane.appendChild(el("div", "split-empty", "Pick an agent on the left to see its state and the way forward."));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------ the Add agent chooser */
|
||||
|
||||
const TEMPLATE_STATE = { ok: "Installed on this computer", missing: "Not installed yet", unknown: "" };
|
||||
|
||||
// The Add agent sheet: the starter templates as an opt-in, each with whether
|
||||
// its command is on this computer, and a Custom agent tile for any other tool.
|
||||
// A template whose command an agent already uses is shown, not offered.
|
||||
export function drawChooser(ctx) {
|
||||
const box = ctx.$("chooser");
|
||||
box.replaceChildren();
|
||||
const scrim = el("div", "chooser-scrim");
|
||||
scrim.addEventListener("click", () => ctx.closeChooser());
|
||||
const sheet = el("div", "chooser-sheet");
|
||||
sheet.setAttribute("role", "dialog");
|
||||
sheet.setAttribute("aria-labelledby", "agents-chooser-title");
|
||||
const head = el("div", "chooser-head");
|
||||
const title = el("h3", null, "Add an agent");
|
||||
title.id = "agents-chooser-title";
|
||||
const close = el("button", "btn small ghost", "Cancel");
|
||||
close.type = "button";
|
||||
close.addEventListener("click", () => ctx.closeChooser());
|
||||
head.append(title, close);
|
||||
sheet.appendChild(head);
|
||||
const have = new Set([...ctx.saved.builtins, ...ctx.saved.agents].map((a) => a.command));
|
||||
if (ctx.saved.templates.length) {
|
||||
sheet.appendChild(el("p", "help", "Start from a ready-made setup. You can change everything afterwards."));
|
||||
const tiles = el("div", "chooser-tiles");
|
||||
for (const t of ctx.saved.templates) {
|
||||
const done = have.has(t.command);
|
||||
const tile = el("button", "chooser-tile");
|
||||
tile.type = "button";
|
||||
tile.dataset.template = t.name;
|
||||
tile.disabled = done;
|
||||
const state = el("span", "chooser-state");
|
||||
state.dataset.command = t.command;
|
||||
const known = ctx.templateState.get(t.command);
|
||||
state.textContent = done ? "Already added" : TEMPLATE_STATE[known || "unknown"];
|
||||
if (known) state.classList.add(known);
|
||||
tile.append(el("b", null, t.name), el("code", null, t.command));
|
||||
if (t.note) tile.appendChild(el("span", "muted", t.note));
|
||||
tile.appendChild(state);
|
||||
tile.addEventListener("click", () => ctx.startNew(t));
|
||||
tiles.appendChild(tile);
|
||||
}
|
||||
sheet.appendChild(tiles);
|
||||
sheet.appendChild(el("div", "chooser-or", "or"));
|
||||
} else {
|
||||
sheet.appendChild(el("p", "help", "Add any command-line agent: give it a name and a command, then its models."));
|
||||
}
|
||||
const custom = el("button", "chooser-tile wide");
|
||||
custom.type = "button";
|
||||
custom.dataset.template = "";
|
||||
custom.append(el("b", null, "Custom agent"), el("span", "muted", "Any command-line tool. You give it a name and a command, and add its models."));
|
||||
custom.addEventListener("click", () => ctx.startNew(null));
|
||||
sheet.appendChild(custom);
|
||||
box.append(scrim, sheet);
|
||||
}
|
||||
|
||||
// Fills each tile's "installed" line once /agents/test has answered for its command.
|
||||
export function markTemplateState(ctx, command, state) {
|
||||
for (const node of ctx.$("chooser").querySelectorAll(".chooser-state")) {
|
||||
if (node.dataset.command !== command || node.textContent === "Already added") continue;
|
||||
node.textContent = TEMPLATE_STATE[state];
|
||||
node.classList.remove("ok", "missing");
|
||||
if (state !== "unknown") node.classList.add(state);
|
||||
}
|
||||
}
|
||||
@@ -165,3 +165,221 @@
|
||||
.strength-word { font-size: 0.9em; }
|
||||
.strength-default { margin: 0; font-size: 0.8em; color: var(--ink-3); }
|
||||
.strength-empty, .strength-offer { margin: 0; }
|
||||
|
||||
/* ------------------------------------------------- Preferences: the roster */
|
||||
|
||||
/* The Agents & models tab in User Preferences: a roster of cards, the picked
|
||||
agent's form in a drawer over it, and the Add agent chooser over both. The
|
||||
drawer and chooser sit in the tab's own box (absolute) and stick to the top
|
||||
of the dialog's scroll, so they stay in view on a long roster. */
|
||||
.prefs-agents { position: relative; min-height: 520px; align-content: start; }
|
||||
.roster-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
|
||||
.roster-head > .help { max-width: 62ch; }
|
||||
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
|
||||
|
||||
.agent-card {
|
||||
appearance: none;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
color: var(--ink);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: var(--radius);
|
||||
padding: 12px 14px;
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
align-content: start;
|
||||
min-width: 0;
|
||||
}
|
||||
.agent-card:hover { border-color: var(--accent-line); box-shadow: var(--shadow); }
|
||||
.agent-card[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
||||
.agent-card .card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
|
||||
.agent-card .card-who { display: grid; gap: 2px; min-width: 0; }
|
||||
.agent-card .row-name { font-weight: 700; font-size: 14.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
||||
.agent-card .card-who code { color: var(--ink-3); font-size: 12px; }
|
||||
.agent-card .card-tiers { display: grid; gap: 5px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
|
||||
.agent-card .card-tier { display: grid; grid-template-columns: 5.2em minmax(0, 1fr); gap: 8px; align-items: center; font-size: 13px; }
|
||||
.agent-card .card-tier .muted, .strength-model.none { color: var(--ink-3); font-style: italic; }
|
||||
.agent-card .card-foot { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 12px; }
|
||||
.agent-card .card-edit { color: var(--accent); font-weight: 600; }
|
||||
.agent-card .row-note { margin: 0; }
|
||||
.agent-card.ghost {
|
||||
border-style: dashed;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
place-content: center;
|
||||
justify-items: center;
|
||||
text-align: center;
|
||||
min-height: 150px;
|
||||
color: var(--ink-2);
|
||||
}
|
||||
.agent-card.ghost .plus { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 20px; }
|
||||
.agent-card.ghost .muted { font-size: 12.5px; color: var(--ink-3); }
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
font-size: 11.5px;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
padding: 0 7px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--rule-2);
|
||||
background: var(--panel-2);
|
||||
color: var(--ink-3);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Thrifty, Balanced and Best take the rank colors (see tokens.css). */
|
||||
.tier {
|
||||
display: inline-block;
|
||||
justify-self: start;
|
||||
font-size: 11.5px;
|
||||
font-weight: 600;
|
||||
line-height: 1.5;
|
||||
padding: 0 8px;
|
||||
border-radius: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tier.t-thrifty { color: var(--lvl-1); background: var(--lvl-1-soft); }
|
||||
.tier.t-balanced { color: var(--lvl-2); background: var(--lvl-2-soft); }
|
||||
.tier.t-best { color: var(--lvl-3); background: var(--lvl-3-soft); }
|
||||
|
||||
/* ---------------------------------------------------------------- the drawer */
|
||||
|
||||
.agents-drawer, .agents-chooser { position: absolute; inset: 0; z-index: 5; }
|
||||
.agents-drawer[hidden], .agents-chooser[hidden] { display: none; }
|
||||
.drawer-scrim, .chooser-scrim { position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(1px); }
|
||||
.drawer {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
margin-left: auto;
|
||||
width: min(500px, 100%);
|
||||
height: min(100%, calc(100vh - 270px));
|
||||
min-height: 380px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
overflow: hidden;
|
||||
}
|
||||
.drawer .form-head { padding: 14px 16px 6px; justify-content: space-between; align-items: center; flex-wrap: nowrap; }
|
||||
.drawer .prefs-agents-title { font-size: 16px; flex-wrap: wrap; }
|
||||
.agent-tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--rule); }
|
||||
.agent-tab {
|
||||
appearance: none;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-bottom: 2px solid transparent;
|
||||
color: var(--ink-3);
|
||||
padding: 8px 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.agent-tab:hover { color: var(--ink); }
|
||||
.agent-tab[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
|
||||
.agent-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px 16px; display: grid; gap: 12px; align-content: start; }
|
||||
.drawer .prefs-agents-foot { border-top: 1px solid var(--rule); padding: 10px 16px; background: var(--panel); }
|
||||
/* Nothing to offer on a clean built-in: no empty bar. */
|
||||
.drawer .prefs-agents-foot:not(:has(> :not([hidden]))) { display: none; }
|
||||
/* The same form on the setup page's split pane is not a drawer: let it flow. */
|
||||
.split-pane .agent-body { overflow: visible; padding: 12px 0 0; }
|
||||
.split-pane .agent-tabs { padding: 0; }
|
||||
|
||||
.note { background: var(--accent-soft); color: var(--ink); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
|
||||
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13px; }
|
||||
.kv dt { color: var(--ink-3); }
|
||||
.kv dd { margin: 0; }
|
||||
|
||||
/* In the loop: the three words, what each resolves to, and the model pills. */
|
||||
.strength-body .strength-row { grid-template-columns: minmax(0, 11em) minmax(0, 1fr) auto auto; }
|
||||
.strength-body .strength-row:not(:has(select)) { grid-template-columns: minmax(0, 11em) minmax(0, 1fr) auto; }
|
||||
.strength-word { display: grid; gap: 1px; font-size: inherit; }
|
||||
.strength-word small { font-size: 11.5px; }
|
||||
.strength-model { overflow-wrap: anywhere; font-size: 13px; }
|
||||
.models-tip { margin: 0; }
|
||||
.models-list { max-height: none; }
|
||||
.models-row { grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; padding: 4px 6px; border-radius: 6px; font-size: 13px; }
|
||||
.models-row.locked { grid-template-columns: minmax(0, 1fr) auto auto; font-size: 13px; opacity: 1; }
|
||||
.models-row:hover { background: var(--panel-2); }
|
||||
.model-name { display: grid; min-width: 0; overflow-wrap: anywhere; }
|
||||
.model-name code { font-size: 11.5px; color: var(--ink-3); }
|
||||
.strength-pills { display: inline-flex; gap: 4px; }
|
||||
.strength-pill {
|
||||
appearance: none;
|
||||
font: inherit;
|
||||
font-size: 11.5px;
|
||||
padding: 1px 9px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--rule-2);
|
||||
background: transparent;
|
||||
color: var(--ink-3);
|
||||
cursor: pointer;
|
||||
opacity: 0.65;
|
||||
}
|
||||
.strength-pill:hover { opacity: 1; }
|
||||
.strength-pill[aria-pressed="true"] { opacity: 1; font-weight: 600; border-color: transparent; }
|
||||
.strength-pill.t-thrifty[aria-pressed="true"] { color: var(--lvl-1); background: var(--lvl-1-soft); }
|
||||
.strength-pill.t-balanced[aria-pressed="true"] { color: var(--lvl-2); background: var(--lvl-2-soft); }
|
||||
.strength-pill.t-best[aria-pressed="true"] { color: var(--lvl-3); background: var(--lvl-3-soft); }
|
||||
.model-add { margin-top: 6px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
|
||||
|
||||
/* ------------------------------------------------------------- the chooser */
|
||||
|
||||
.chooser-sheet {
|
||||
position: sticky;
|
||||
top: 24px;
|
||||
margin: 24px auto 0;
|
||||
width: min(620px, calc(100% - 24px));
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 16px 18px 18px;
|
||||
}
|
||||
.chooser-head { display: flex; justify-content: space-between; align-items: center; }
|
||||
.chooser-head h3 { margin: 0; font-size: 16px; }
|
||||
.chooser-sheet > .help { margin: 0; }
|
||||
.chooser-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
||||
.chooser-tile {
|
||||
appearance: none;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
color: var(--ink);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.chooser-tile:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
|
||||
.chooser-tile:disabled { opacity: 0.55; cursor: default; }
|
||||
.chooser-tile b { font-size: 14px; }
|
||||
.chooser-tile code { color: var(--ink-3); font-size: 12px; }
|
||||
.chooser-tile .muted { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink-3); }
|
||||
.chooser-tile.wide { border-style: dashed; }
|
||||
.chooser-state { font-size: 12px; color: var(--ink-3); }
|
||||
.chooser-state.ok { color: var(--ok); }
|
||||
.chooser-state.missing { color: var(--warn); }
|
||||
.chooser-or { text-align: center; color: var(--ink-3); font-size: 12px; display: flex; align-items: center; gap: 10px; }
|
||||
.chooser-or::before, .chooser-or::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.roster-head { flex-direction: column; }
|
||||
.chooser-tiles { grid-template-columns: 1fr; }
|
||||
.strength-body .strength-row, .strength-body .strength-row:not(:has(select)) { grid-template-columns: minmax(0, 1fr) auto; }
|
||||
.strength-body .strength-word { grid-column: 1 / -1; }
|
||||
.models-row, .models-row.locked { grid-template-columns: minmax(0, 1fr) auto; }
|
||||
.models-row .strength-pills { grid-column: 1 / -1; order: 3; }
|
||||
.model-add { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.drawer .help, .chooser-sheet .help, .strength-offer { font-size: 12.5px; color: var(--ink-3); }
|
||||
Reference in new issue
Block a user