diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a08e48..cdf8cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,9 +28,15 @@ and `/context` shows where the window goes the way the side panel of the other a server that is not on its one-model server. When the session's model cannot serve its own subagents, the agent is told so in its first note, and `/effort`, `/team size` and `/team` say it beside the setting. -- **"Subagents" is the word** for the setting (fewest and most agents at work, the lead included): - the row beside the effort in `/effort`, `/team size`, `/settings`. "Helper" is gone. The status - bar reads `agents 3/4 · 2 subagents working` while there is a team. +- **"Subagents" is the word** for the setting, with **Min** and **Max**: the row beside the effort + in `/effort`, `/team size`, `/settings`. "Helper" is gone. The status bar reads + `agents 3/4 · 2 subagents working` while there is a team. +- **The numbers count this agent**: `Subagents: Min 1, Max 4 — 1 is this agent alone`. Max 1 is + the agent alone, with no subagents; Max 4 is the agent and up to three subagents. +- **The setting is one range with two handles.** In `/effort` and `/team size` the Subagents row + shows `Min 1`, a track from 1 to the cap with a handle for each, and `Max 4`: ←→ move the handle in focus, tab switches to the other, enter + sets both for the session (Min never passes Max; Max goes up to `agents.cap`). `/team size` also + keeps the usual pairs and ` ` typed. - **`/context`** shows the window as used tokens of the window and a percentage, one bar split by category, every category with its tokens and its share of the window, what is free, and how far it is to automatic compaction (`N until auto-compact`, with `/compact` to do it now). diff --git a/schema/config.schema.json b/schema/config.schema.json index 8e26977..28d40e7 100644 --- a/schema/config.schema.json +++ b/schema/config.schema.json @@ -894,17 +894,17 @@ ] }, "agents": { - "description": "Subagents (harness team.md, subagents.md): how many agents a session may have at work. Offered where subagents are on and a model could serve one: the session's, when it serves two requests at once, or another model off its one-model server. /team size and /effort change it for the session.", + "description": "Subagents (harness team.md, subagents.md): how many agents a session may have at work, counting the session's own agent — Subagents: Min 1, Max 4 by default; 1 is this agent alone. Offered where subagents are on and a model could serve one: the session's, when it serves two requests at once, or another model off its one-model server. /team size and /effort (one range, Min and Max) change it for the session.", "type": "object", "properties": { "min": { - "description": "Subagents, fewest: the fewest agents at work, the lead included (default 1). 2 or more: the lead works through subagents from the start.", + "description": "Subagents, Min: the agents at work at least, this agent included (default 1 — 1 is this agent alone). 2 or more: it works through subagents from the start.", "type": "integer", "minimum": 1, "maximum": 9007199254740991 }, "max": { - "description": "Subagents, most: the most agents at work, the lead included (default 4). 1: one agent, no subagents.", + "description": "Subagents, Max: the agents at work at most, this agent included (default 4 — this agent and up to 3 subagents). 1: this agent alone, no subagents.", "type": "integer", "minimum": 1, "maximum": 9007199254740991 diff --git a/src/config/schema.ts b/src/config/schema.ts index 4118320..acb7999 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -298,12 +298,12 @@ export const Config = z.strictObject({ effort: z.union([z.enum(EFFORTS), z.literal("off"), z.literal("default")]).optional().describe("The effort level a session starts with, when the model offers it: an effort, off (thinking switched off, on a model with the switch) or default; otherwise the model's own start level."), agents: z .strictObject({ - min: z.number().int().min(1).optional().describe("Subagents, fewest: the fewest agents at work, the lead included (default 1). 2 or more: the lead works through subagents from the start."), - max: z.number().int().min(1).optional().describe("Subagents, most: the most agents at work, the lead included (default 4). 1: one agent, no subagents."), + min: z.number().int().min(1).optional().describe("Subagents, Min: the agents at work at least, this agent included (default 1 — 1 is this agent alone). 2 or more: it works through subagents from the start."), + max: z.number().int().min(1).optional().describe("Subagents, Max: the agents at work at most, this agent included (default 4 — this agent and up to 3 subagents). 1: this agent alone, no subagents."), cap: z.number().int().min(1).optional().describe("Global config only. The highest max a session may set (default 32)."), }) .optional() - .describe("Subagents (harness team.md, subagents.md): how many agents a session may have at work. Offered where subagents are on and a model could serve one: the session's, when it serves two requests at once, or another model off its one-model server. /team size and /effort change it for the session."), + .describe("Subagents (harness team.md, subagents.md): how many agents a session may have at work, counting the session's own agent — Subagents: Min 1, Max 4 by default; 1 is this agent alone. Offered where subagents are on and a model could serve one: the session's, when it serves two requests at once, or another model off its one-model server. /team size and /effort (one range, Min and Max) change it for the session."), subagents: z.boolean().optional().describe("false: no subagents — no task tool and no team."), settings_tool: z.enum(["ask", "allow", "off"]).optional().describe("Global config only. The agent's settings tool: ask (default) — each change is approved like any tool call; allow — changes go through without asking (a less strict mode still asks); off — no settings tool."), update: Update.optional().describe("Global config only. Updating LLeMbas CLI itself."), diff --git a/src/config/settings.ts b/src/config/settings.ts index 1c33a10..d692a50 100644 --- a/src/config/settings.ts +++ b/src/config/settings.ts @@ -9,6 +9,7 @@ import { existsSync, readFileSync } from "node:fs" import { join } from "node:path" import { parse, parseDocument } from "yaml" import { z } from "zod" +import LOOP_JSON from "../../harness/loop.json" import { paths } from "./paths.ts" import { asMode, Config, EFFORTS, MODES, PERSONALITIES, UPDATE_CHANNELS } from "./schema.ts" @@ -29,8 +30,13 @@ export interface SettingDef { reload?: boolean /** What it is when nothing sets it. */ fallback?: string + /** What a person reads beside the key in /settings. */ + hint?: string } +// The Subagents setting's names and what its numbers count (harness loop.json subagents.setting). +const SUB = LOOP_JSON.subagents.setting + const ALL: Scope[] = ["session", "global", "project"] const USER: Scope[] = ["session", "global"] @@ -38,8 +44,8 @@ export const SETTINGS: SettingDef[] = [ { key: "model", kind: "model", agent: true, scopes: ALL }, { key: "effort", kind: "effort", agent: true, scopes: ALL, fallback: "the model's start level" }, // The team's size is the person's: the agent never sets how many agents it may have. - { key: "agents.min", kind: "number", agent: false, scopes: ALL, fallback: "1" }, - { key: "agents.max", kind: "number", agent: false, scopes: ALL, fallback: "4" }, + { key: "agents.min", kind: "number", agent: false, scopes: ALL, fallback: "1", hint: `${SUB.label}: ${SUB.min} — ${SUB.short}` }, + { key: "agents.max", kind: "number", agent: false, scopes: ALL, fallback: "4", hint: `${SUB.label}: ${SUB.max} — this agent included; 4 is this agent and up to 3 subagents` }, { key: "mode", kind: "enum", values: MODES, agent: true, scopes: ALL, fallback: "manual" }, { key: "small_model", kind: "model", agent: true, scopes: ALL, fallback: "the session's model" }, { key: "knowledge", kind: "list", agent: true, scopes: ALL, fallback: "every base" }, diff --git a/src/harness.ts b/src/harness.ts index 170f521..c103ae1 100644 --- a/src/harness.ts +++ b/src/harness.ts @@ -123,7 +123,7 @@ export const LOOP: { subagents: { texts: { not_named: string; same_group: string; one_request: string } named: { before: string; after: string } - setting: { label: string; min: string; max: string; own: string } + setting: { label: string; min: string; max: string; hint: string; short: string; own: string } } /** Teams (spec 3.2.0, harness/team.md): the size setting, names, marks, texts. */ team: { diff --git a/src/session/commands.ts b/src/session/commands.ts index c7ee9f5..f817b2b 100644 --- a/src/session/commands.ts +++ b/src/session/commands.ts @@ -49,7 +49,7 @@ export const SHARED_BUILTINS: { name: string; description: string; hint?: string { name: "init", description: "make or update the project's AGENTS.md from what the repository says", hint: "what to focus on" }, { name: "continue", description: "carry on — after esc stopped it, or when it should keep going (ctrl+g)" }, { name: "agents", description: "subagents: list them, make one, or hand one a task", hint: "name" }, - { name: "team", description: "subagents: the team and the room; how many; stop one", hint: "size | stop " }, + { name: "team", description: "subagents: the team and the room; how many; stop one", hint: "size | stop " }, ] /** The status bar's word for a team with members: its size of the most it may have, and how many @@ -66,10 +66,11 @@ export function teamLabel(team: Team): string { export function teamText(app: App, arg: string): string { const rt = app.team const t = rt.team + const S = SUBAGENTS.setting const [verb, ...rest] = arg.trim().split(/\s+/).filter(Boolean) if (verb === "size") { const [min, max] = rest.map(Number) - if (min === undefined || max === undefined || Number.isNaN(min) || Number.isNaN(max)) return `/team size — now ${t.min} to ${t.max} (at most ${t.cap})` + if (min === undefined || max === undefined || Number.isNaN(min) || Number.isNaN(max)) return `/team size — now ${S.label}: ${S.min} ${t.min}, ${S.max} ${t.max} (Max at most ${t.cap}). ${S.hint}` // Checked whole before anything is set: a refused pair changes nothing (team.md §2). const no = Team.check(min, max, t.cap) if (no) return no @@ -80,7 +81,7 @@ export function teamText(app: App, arg: string): string { } catch (e) { return (e as Error).message } - return `Subagents: ${t.min} to ${t.max} agents at work for this session, the lead included; it is told with your next message.` + return `${S.label}: ${S.min} ${t.min}, ${S.max} ${t.max} — ${S.short}. Set for this session; the agent is told with your next message.` } if (verb === "stop") { const name = rest[0] @@ -93,8 +94,8 @@ export function teamText(app: App, arg: string): string { ? `No subagents in this session: ${app.engine.model.ref} serves one request at a time, and every other model is on its one-model server.` : "No subagents in this session: they are switched off (subagents: false)." const since = Math.max(0, t.room.length - TEAM.read_max) - const own = t.couldServe().own ? "" : `\n${SUBAGENTS.setting.own}` - return `${t.read("lead", since)}\n\nSubagents: ${SUBAGENTS.setting.min} ${t.min}, ${SUBAGENTS.setting.max} ${t.max} agents, the lead included (/team size ); /team stop stops a member.${own}` + const own = t.couldServe().own ? "" : `\n${S.own}` + return `${t.read("lead", since)}\n\n${S.label}: ${S.min} ${t.min}, ${S.max} ${t.max} — ${S.short} (/team size ); /team stop stops a member.${own}` } /** `/agents [name]`: the subagents the task tool offers, or one of them — the text both the TUI and diff --git a/src/team/team.ts b/src/team/team.ts index 8ca90a1..dfc5cb4 100644 --- a/src/team/team.ts +++ b/src/team/team.ts @@ -155,7 +155,7 @@ export class Team { /** Where it is set: a value outside 1 ≤ min ≤ max ≤ cap is refused with the bounds. */ static check(min: number, max: number, cap: number): string | undefined { - if (!Number.isInteger(min) || !Number.isInteger(max) || min < 1 || min > max || max > cap) return `agents: 1 ≤ min ≤ max ≤ ${cap} (the cap) — whole numbers; min ${min}, max ${max} is outside` + if (!Number.isInteger(min) || !Number.isInteger(max) || min < 1 || min > max || max > cap) return `Subagents: 1 ≤ Min ≤ Max ≤ ${cap} (the cap), whole numbers, this agent included; Min ${min}, Max ${max} is outside` return undefined } diff --git a/src/tui/commands.ts b/src/tui/commands.ts index c19cf7c..50d08cd 100644 --- a/src/tui/commands.ts +++ b/src/tui/commands.ts @@ -16,7 +16,7 @@ import { changelogPrompt, initPrompt, reviewPrompt, teamText } from "../session/ import { git } from "../git/run.ts" import { branches, deleteBranch, switchBranch } from "../git/branch.ts" import type { Ctx } from "./context.ts" -import type { DialogSpec } from "./components/dialog.tsx" +import type { DialogSpec, Option } from "./components/dialog.tsx" import { deleteEverywhere } from "../acp/share.ts" import { themeNames } from "./theme.ts" import { render } from "../plan/plan.ts" @@ -96,26 +96,44 @@ report is all the session's model sees of your work. const TEAM_ROW = "\u0000team" -/** The team's size for this session: a few usual pairs, or any typed as ` `. */ +/** The Subagents setting as one range from 1 to the cap with two handles, Min and Max (harness + * team.md §2): the numbers count this agent, so 1 is this agent alone. */ +function teamRange(c: CommandCtx): Option { + const t = c.app.team.team + const S = SUBAGENTS.setting + return { + label: S.label, + value: TEAM_ROW, + // The session's model cannot serve subagents itself: said where the size is set (subagents.md §4). + description: t.couldServe().own ? S.short : S.own, + range: { from: 1, to: t.cap, lo: t.min, hi: t.max, names: [S.min, S.max], onSubmit: (lo, hi) => applyTeamSize(c, `${lo} ${hi}`) }, + } +} + +const applyTeamSize = (c: CommandCtx, v: string) => (c.view.info(teamText(c.app, `size ${v}`)), c.refresh()) + +/** The team's size for this session: the range, a few usual pairs, or any typed as ` `. */ function openTeamSize(c: CommandCtx) { const t = c.app.team.team const pairs = [ - [1, 1, "one agent: no subagents"], - [1, 4, "the agent decides; up to three subagents"], + [1, 1, "this agent alone: no subagents"], + [1, 4, "this agent decides; up to three subagents"], [2, 4, "subagents from the start"], - [1, 8, "the agent decides; up to seven subagents"], + [1, 8, "this agent decides; up to seven subagents"], [3, 8, "at least two subagents"], [1, Math.min(16, t.cap), "many subagents, with sub-managers"], ] as const + const S = SUBAGENTS.setting const seen = new Set() const options = pairs .filter(([min, max]) => max <= t.cap && !seen.has(`${min} ${max}`) && seen.add(`${min} ${max}`)) - .map(([min, max, what]) => ({ label: `${min} to ${max}`, value: `${min} ${max}`, description: what, current: t.min === min && t.max === max })) - const apply = (v: string) => (c.view.info(teamText(c.app, `size ${v}`)), c.refresh()) - const S = SUBAGENTS.setting - // The session's model cannot serve subagents itself: said where the size is set (subagents.md §4). - const own = t.couldServe().own ? "" : ` — ${S.own}` - c.openDialog({ title: `${S.label} — now ${S.min} ${t.min}, ${S.max} ${t.max} (agents at work, this one included; at most ${t.cap})${own}`, options, onSelect: apply, custom: { label: "set to ", onSubmit: apply } }) + .map(([min, max, what]) => ({ label: `${S.min} ${min}, ${S.max} ${max}`, value: `${min} ${max}`, description: what, current: t.min === min && t.max === max })) + c.openDialog({ + title: `${S.label} — ${S.min} ${t.min}, ${S.max} ${t.max} (1 to ${t.cap}, this agent included)`, + options: [teamRange(c), ...options], + onSelect: (v) => applyTeamSize(c, v), + custom: { label: "set to ", onSubmit: (v) => applyTeamSize(c, v) }, + }) } export const COMMANDS: Command[] = [ @@ -220,12 +238,8 @@ export const COMMANDS: Command[] = [ } // The Subagents setting sits beside the effort (team.md §2, subagents.md §4: shown only where // subagents are offered). - const team = c.app.team.team - const S = SUBAGENTS.setting - const agentsRow = team.offered - ? [{ label: `${S.label}: ${S.min} ${team.min}, ${S.max} ${team.max}`, value: TEAM_ROW, description: team.couldServe().own ? "agents at work, this one included" : S.own }] - : [] - const choose = (v: string) => (v === TEAM_ROW ? openTeamSize(c) : set(v)) + const agentsRow = c.app.team.team.offered ? [teamRange(c)] : [] + const choose = (v: string) => set(v) if (control === "none" && (arg || !agentsRow.length)) return c.view.info(`${m.ref} has one level (${levels[0]}): there is nothing to choose`) if (arg) return set(arg) if (control === "none") return c.openDialog({ title: `Chat settings — ${m.ref}`, options: agentsRow, onSelect: choose }) @@ -248,7 +262,7 @@ export const COMMANDS: Command[] = [ }, { name: "team", - args: "[size [ ] | stop []]", + args: "[size [ ] | stop []]", description: "subagents: the team and the room; how many; stop one", run(c, arg) { // The tree and the room as the lead sees them — the person sees everything (team.md §5). @@ -1013,7 +1027,7 @@ export const COMMANDS: Command[] = [ ? [...(e.def.values ?? [])] : [] c.openDialog({ - title: `${key} — now ${show(e.value) || e.def.fallback || "unset"}${e.source === "default" ? "" : ` (${e.source})`}`, + title: `${key} — now ${show(e.value) || e.def.fallback || "unset"}${e.source === "default" ? "" : ` (${e.source})`}${e.def.hint ? ` · ${e.def.hint}` : ""}`, options: values.map((v) => ({ label: v, value: v, current: v === show(e.value) })), onSelect: (v) => askScope(key, v), custom: e.def.kind === "enum" || e.def.kind === "boolean" || e.def.kind === "effort" ? undefined : { label: "set to", onSubmit: (v) => askScope(key, v) }, @@ -1029,7 +1043,7 @@ export const COMMANDS: Command[] = [ options: S.list().map((e) => ({ label: e.def.key, value: e.def.key, - description: `${show(e.value) || e.def.fallback || "unset"}${e.source === "default" ? "" : ` · ${e.source}`}${e.def.reload ? " · after restart" : ""}`, + description: `${show(e.value) || e.def.fallback || "unset"}${e.source === "default" ? "" : ` · ${e.source}`}${e.def.reload ? " · after restart" : ""}${e.def.hint ? ` · ${e.def.hint}` : ""}`, })), onSelect: askValue, }) diff --git a/src/tui/components/dialog.tsx b/src/tui/components/dialog.tsx index b4ddbae..0507cca 100644 --- a/src/tui/components/dialog.tsx +++ b/src/tui/components/dialog.tsx @@ -8,6 +8,31 @@ export interface Option { value: string description?: string current?: boolean + /** A two-handle range on this row (the Subagents setting, harness team.md §2: one range from 1 + * to the cap, Min and Max). While the row is highlighted ←→ move the handle in focus and tab + * moves the focus; Min never passes Max. Enter calls `onSubmit` with both, not `onSelect`. */ + range?: Range +} + +export interface Range { + /** The bounds of the track. */ + from: number + to: number + /** The handles' values. */ + lo: number + hi: number + /** The handles' names (Min, Max). */ + names: [string, string] + onSubmit: (lo: number, hi: number) => void +} + +/** The track as text: `─` outside the range, `━` inside it, `●` for a handle. */ +export function rangeTrack(r: Pick, lo: number, hi: number, width = 16): { before: string; lo: string; between: string; hi: string; after: string } { + const span = Math.max(1, r.to - r.from) + const at = (v: number) => Math.round(((v - r.from) / span) * (width - 1)) + const a = at(lo) + const b = Math.max(at(hi), a + (hi > lo ? 1 : 0)) + return { before: "─".repeat(a), lo: "●", between: "━".repeat(Math.max(0, b - a - 1)), hi: b > a ? "●" : "", after: "─".repeat(Math.max(0, width - 1 - b)) } } export interface DialogSpec { @@ -45,6 +70,16 @@ export function Dialog(p: { spec: DialogSpec; close: () => void }) { const hits = q ? p.spec.options.filter((o) => (o.label + " " + (o.description ?? "")).toLowerCase().includes(q)) : p.spec.options return p.spec.custom && query().trim() ? [{ label: `${p.spec.custom.label} "${query().trim()}"`, value: CUSTOM }, ...hits] : hits }) + // A range row's handles, moved while the dialog is open and handed over on enter; esc drops them. + const [ranges, setRanges] = createSignal>({}) + const [focus, setFocus] = createSignal<0 | 1>(1) + const valuesOf = (o: Option): [number, number] => ranges()[o.value] ?? [o.range!.lo, o.range!.hi] + const move = (o: Option, by: number) => { + const r = o.range! + const [lo, hi] = valuesOf(o) + const next: [number, number] = focus() === 0 ? [Math.min(hi, Math.max(r.from, lo + by)), hi] : [lo, Math.min(r.to, Math.max(lo, hi + by))] + setRanges((m) => ({ ...m, [o.value]: next })) + } const start = Math.max(0, p.spec.options.findIndex((o) => o.current)) const [sel, setSel] = createSignal(start) // The spec is live: a list that redraws itself with fewer rows keeps the cursor on a row. @@ -70,6 +105,8 @@ export function Dialog(p: { spec: DialogSpec; close: () => void }) { run(o.value) } } else if (key.name === "escape") p.close() + else if (shown()[sel()]?.range && (key.name === "left" || key.name === "right")) move(shown()[sel()]!, key.name === "left" ? -1 : 1) + else if (shown()[sel()]?.range && key.name === "tab") setFocus((f) => (f === 0 ? 1 : 0)) else if (key.name === "up" || (key.ctrl && key.name === "p")) setSel((i) => (i + n - 1) % Math.max(n, 1)) else if (key.name === "down" || (key.ctrl && key.name === "n")) setSel((i) => (i + 1) % Math.max(n, 1)) else if (key.name === "return") { @@ -79,8 +116,10 @@ export function Dialog(p: { spec: DialogSpec; close: () => void }) { const onSelect = p.spec.onSelect const custom = p.spec.custom const typed = query().trim() + const range = o.range && { submit: o.range.onSubmit, values: valuesOf(o) } p.close() if (o.value === CUSTOM) custom?.onSubmit(typed) + else if (range) range.submit(...range.values) else onSelect(o.value) } } else if (filterable() && key.name === "backspace") { @@ -104,6 +143,30 @@ export function Dialog(p: { spec: DialogSpec; close: () => void }) { {(o, i) => { const active = () => i() + offset() === sel() + if (o.range) { + const values = () => valuesOf(o) + const track = () => rangeTrack(o.range!, values()[0], values()[1]) + const handle = (n: 0 | 1) => (active() && focus() === n ? c().accent : active() ? c().title : c().text) + return ( + + + {" "} + {o.label} + {" "} + {`${o.range.names[0]} ${values()[0]}`} + {" "} + {track().before} + {track().lo} + {track().between} + {track().hi} + {track().after} + {" "} + {`${o.range.names[1]} ${values()[1]}`} + {o.description ? ` ${o.description}` : ""} + + + ) + } return ( @@ -118,7 +181,11 @@ export function Dialog(p: { spec: DialogSpec; close: () => void }) { nothing matches - {p.spec.hint ?? "↑↓ move · enter choose · esc close"} + + {shown()[sel()]?.range + ? `←→ move ${shown()[sel()]!.range!.names[focus()]} · tab ${shown()[sel()]!.range!.names[focus() === 0 ? 1 : 0]} · enter set · esc close` + : (p.spec.hint ?? "↑↓ move · enter choose · esc close")} + ) diff --git a/tests/team.test.ts b/tests/team.test.ts index f0d293f..a57ecf6 100644 --- a/tests/team.test.ts +++ b/tests/team.test.ts @@ -135,10 +135,10 @@ describe("a team at work (team.md)", () => { const dir = setup(() => say(`ok ${n++}`)) app = createApp({ cwd: dir, mode: "edit", asker: yes, store: false }) await app.engine.prompt("one") - expect(teamText(app, "size 3 2")).toContain("1 ≤ min ≤ max ≤ 32") - expect(teamText(app, "size 1 40")).toContain("1 ≤ min ≤ max ≤ 32") + expect(teamText(app, "size 3 2")).toContain("1 ≤ Min ≤ Max ≤ 32") + expect(teamText(app, "size 1 40")).toContain("1 ≤ Min ≤ Max ≤ 32") expect([app.team.team.min, app.team.team.max]).toEqual([1, 4]) - expect(teamText(app, "size 2 6")).toContain("2 to 6") + expect(teamText(app, "size 2 6")).toContain("Min 2, Max 6") expect(app.settings.get("agents.max").value).toBe(6) await app.engine.prompt("two") expect(lastUser(fake!.requests[1])).toContain("The team may have 2 to 6 agents, you included.") diff --git a/tests/tui/dialog.test.tsx b/tests/tui/dialog.test.tsx index 315ffe4..323ad23 100644 --- a/tests/tui/dialog.test.tsx +++ b/tests/tui/dialog.test.tsx @@ -36,3 +36,50 @@ test("dialog: arrow down + enter picks the second option — with a spec that cl expect(picked).toEqual(["b"]) expect(closed).toBe(1) }) + +test("dialog: a range row is one track with two handles — ←→ move the one in focus, tab the other, enter hands both over", async () => { + const set: [number, number][] = [] + const picked: string[] = [] + const ctx = { theme: () => DEFAULT_THEME, dims: () => ({ width: 72, height: 16 }) } as never + const [spec, setSpec] = createSignal({ + title: "Effort", + options: [ + { label: "high", value: "high", current: true }, + { label: "Subagents", value: "team", description: "1 is this agent alone", range: { from: 1, to: 32, lo: 1, hi: 4, names: ["Min", "Max"], onSubmit: (lo, hi) => set.push([lo, hi]) } }, + ], + onSelect: (v) => picked.push(v), + }) + setup = await testRender( + () => ( + + + setSpec(undefined)} /> + + + ), + { width: 72, height: 16 }, + ) + await setup.renderOnce() + expect(setup.captureCharFrame()).toContain("Subagents Min 1 ●") + setup.mockInput.pressArrow("down") + await setup.renderOnce() + expect(setup.captureCharFrame()).toContain("←→ move Max · tab Min") + setup.mockInput.pressArrow("right") + setup.mockInput.pressArrow("right") + await setup.renderOnce() + expect(setup.captureCharFrame()).toContain("Max 6") + setup.mockInput.pressTab() + setup.mockInput.pressArrow("right") + setup.mockInput.pressArrow("right") + setup.mockInput.pressArrow("left") + await setup.renderOnce() + expect(setup.captureCharFrame()).toContain("Min 2") + // Min never passes Max, and Min never goes under 1. + for (let i = 0; i < 10; i++) setup.mockInput.pressArrow("right") + await setup.renderOnce() + expect(setup.captureCharFrame()).toContain("Min 6") + setup.mockInput.pressEnter() + await setup.renderOnce() + expect(set).toEqual([[6, 6]]) + expect(picked).toEqual([]) +})