The ask id in the terminal's form: approval#12, /answer <n> as before, a cut ends in …

The terminal's round shipped `<kind>#<id> <keys> <text>` with a numeric id
(1-9 digits) and sends /approve <id>, /always <id>, /deny <id> when an id
was shown, /answer <n> without one. lembas_ask now says approval#12 yn …;
ids are a counter per display; /answer with one word is the option, with
two the id and the option. A lembas_ask value cut to state.max_bytes ends
in U+2026 (ask_id.ellipsis), the placed kind too.

Conformance: terminal.json ask_id cases redone (+7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-12-03 08:32:44 +00:00
1 parent cd4dab2a19
commit ff51eb5323
11 files changed
+76 -58

No files matched your search

+5 -4
View File
@@ -119,10 +119,11 @@ All notable changes to LLeMbas CLI. The format follows
- A folder named like `..cache` in the project is shown relative to the project in the prompt,
in approvals and in the editor, as any other folder.
- **In a LLeMbas terminal an answer is bound to the approval it was given for.** What the display
asks now carries a short id (`approval yn #k3f9 …`); `/approve #k3f9`, `/always`, `/deny` and
`/answer` with an id decide only that approval or question, and an answer meant for one that
has since closed is refused in words instead of approving the next. Without an id they work as
before. `lembas --version --json` lists `terminal_ask_id`.
asks now carries a number (`approval#12 yn …`); `/approve 12`, `/always 12` and `/deny 12`
decide only that approval, and an answer meant for one that has since closed is refused in
words instead of approving the next. Without a number they work as before, and so does
`/answer <n>`. A line too long for the terminal's ask line ends in "…". `lembas --version
--json` lists `terminal_ask_id`.
- **"Always" on a file outside the project now holds.** It remembered the file for its tool but
not that the file may be reached outside the project, so the next identical call asked again.
The outside path is now remembered too, for the session only — it is never written into the
+4 -3
View File
@@ -169,9 +169,10 @@ page *Harness-parity* in LLeMbas CLI's wiki.
CLI's alone.
- **Approvals bind to what was shown** (`acp.md`, `lembas_ask`; `loop.json`
`terminal.surface.ask_id`, `texts.wrong_id`; capability **`terminal_ask_id`**;
`conformance/terminal.json` `kind: ask_id`): `lembas_ask` is `approval yn #k3f9 …`, and
`/approve`, `/always`, `/deny`, `/answer` decide only for the id they name; without one, as
before. A released terminal's reader shows the id as the start of the text. The CLI's alone.
`conformance/terminal.json` `kind: ask_id`): `lembas_ask` is `approval#12 yn …` (the id 1–9
digits), `/approve 12`, `/always 12`, `/deny 12` decide only for the id they name; `/answer
<n>` as before (`/answer <id> <n>` bound too); no id, as before. A `lembas_ask` cut to fit ends
in `…`. The CLI's alone.
- **One answer to "inside a directory"** (`conformance/paths.json`, `op: within`): by whole names;
a child named `..cache` is a child.
- Conformance: every case of `conformance/terminal.json` is in the new names; cases of `env`,
+2 -2
View File
@@ -1182,7 +1182,7 @@ and by `lembas complete` (with `--debug`); `terminal_placed` — manual mode pla
the prompt, the `placed` kind of `lembas_ask`, the `ran` key of a status record and the input
mark; and from contract 4 `terminal_names_2` — the names of LLeMbas TERM are read (*The names
before the rename*); `terminal_ask_id` (spec 3.15.0) — `lembas_ask` carries the id of what is
asked, and `/approve`, `/always`, `/deny`, `/answer` take it. A CLI from before this
asked (`approval#12 …`), and `/approve`, `/always`, `/deny` (and `/answer` with two words) take it. A CLI from before this
section prints its bare version for the same arguments — one line that is not JSON — which is
how a terminal tells it is too old. `lembas --version` alone is unchanged.
@@ -1532,7 +1532,7 @@ The user vars of *Session state*, above, with two more (`terminal.state.surface_
| Var | Value |
|---|---|
| `lembas_surface` | `display` — the pane is the terminal's display, not the CLI's TUI |
| `lembas_ask` | empty; or what is asked now, one line: the kind (`approval` or `question`), the keys that answer it (`yn`, `yan`, `1-3n`), from spec 3.15.0 the **id** of what is asked (`terminal.surface.ask_id`: `#` and four characters, new for each approval and each question of a card), then the text — `approval yn #k3f9 terminal_run: make test`. **An answer is bound to what was shown**: `/approve #k3f9`, `/always #k3f9`, `/deny #k3f9`, `/answer #k3f9 2` decide only while that id is the one asked; another id decides nothing and is refused in words (`texts.wrong_id`); without an id they answer what is asked now, as before. A keypress cannot carry an id, so a terminal that can should send the command with the id rather than the key. A reader that takes kind, keys and text shows the id as the start of the text (`kind: ask_id`). A terminal shows it at its ask line, and sends the key the person presses there while the focus stays in their shell. Contract 3, a kind with **no keys**: **`placed <command>`** — a command stands at the person's prompt, placed by the agent and not run; nothing is to be sent for it: the terminal may hint at the person's cursor that Enter runs it and Ctrl+C dismisses it. A terminal takes a kind it does not know as nothing asked. |
| `lembas_ask` | empty; or what is asked now, one line: the kind (`approval` or `question`), from spec 3.15.0 with the **id** of what is asked after a `#` (`terminal.surface.ask_id`: a whole number of 1 to 9 digits, new for each approval and each question of a card), the keys that answer it (`yn`, `yan`, `1-3n`), then the text — `approval#12 yn terminal_run: make test`. **An answer is bound to what was shown**: `/approve 12`, `/always 12`, `/deny 12` decide only while 12 is the id asked; another id decides nothing and is refused in words (`texts.wrong_id`). `/answer <n>` takes the option alone, as before (`/answer 13 2`, the id first, is bound too). Without an id the commands answer what is asked now, as before. A keypress carries no id; a terminal that showed one sends the command with it. **A value cut to fit `state.max_bytes` ends in `…`** (`ask_id.ellipsis`): the rest is in the display (`kind: ask_id`). Contract 3, a kind with **no keys**: **`placed <command>`** — a command stands at the person's prompt, placed by the agent and not run; nothing is to be sent for it: the terminal may hint at the person's cursor that Enter runs it and Ctrl+C dismisses it. A terminal takes a kind it does not know as nothing asked. |
- **`lembas_state` is `idle` only while a question would be taken as a new turn** — the session
is up and nothing runs. `asking` while an approval or a question is open, **and while a call
+30 -19
View File
@@ -5042,50 +5042,61 @@
}
},
{
"about": "Spec 3.15.0: an answer command's first word, when it is an ask id, is the id.",
"about": "Spec 3.15.0: /approve, /always, /deny — a whole number first is the id.",
"kind": "ask_id",
"arg": "#k3f9",
"arg": "12",
"expect": {
"id": "#k3f9",
"id": "12",
"rest": ""
}
},
{
"about": "/answer takes the option alone, as before: one number is the option, not an id.",
"kind": "ask_id",
"arg": " #k3f9 2 ",
"expect": {
"id": "#k3f9",
"rest": "2"
}
},
{
"about": "No id: the argument as it was.",
"kind": "ask_id",
"answer": true,
"arg": "2",
"expect": {
"rest": "2"
}
},
{
"about": "Not an id: wrong length, a character not in the alphabet (0, o, l, 1 are left out), no prefix.",
"about": "…and two are the id and the option.",
"kind": "ask_id",
"arg": "#k3f 2",
"answer": true,
"arg": " 13 2 ",
"expect": {
"rest": "#k3f 2"
"id": "13",
"rest": "2"
}
},
{
"about": "Not an id: more than digits_max digits, not digits, a # before it.",
"kind": "ask_id",
"arg": "1234567890",
"expect": {
"rest": "1234567890"
}
},
{
"kind": "ask_id",
"arg": "#k3f0",
"arg": "#12",
"expect": {
"rest": "#k3f0"
"rest": "#12"
}
},
{
"kind": "ask_id",
"arg": "k3f9",
"arg": "x12",
"expect": {
"rest": "k3f9"
"rest": "x12"
}
},
{
"about": "No argument.",
"kind": "ask_id",
"arg": "",
"expect": {
"rest": ""
}
}
]
+3 -4
View File
@@ -1383,10 +1383,9 @@
},
"option_keys": "123456789",
"ask_id": {
"about": "Spec 3.15.0 (acp.md, *The display*, `lembas_ask`): each open approval and each question of a question card has a short id, written in `lembas_ask` after the keys — `approval yn #k3f9 terminal_run: make test`. `/approve`, `/always`, `/deny` and `/answer` take it as their first word; an answer naming another id than the one asked now decides nothing and is refused in words (`texts.wrong_id`); without an id they answer what is asked now, as before. A terminal that reads `lembas_ask` as kind, keys and text shows the id as the start of the text.",
"prefix": "#",
"length": 4,
"alphabet": "abcdefghijkmnpqrstuvwxyz23456789"
"about": "Spec 3.15.0 (acp.md, *The display*, `lembas_ask`): each open approval and each question of a question card has an id — a whole number of 1 to `digits_max` digits, new for each — written after the kind with `#`: `approval#12 yn terminal_run: make test`, `question#13 1-3n Which one?`. `/approve`, `/always` and `/deny` take it as their first word (`/approve 12`); `/answer` takes the option alone, as before (`/answer 2`), or the id first (`/answer 13 2`). An answer naming another id than the one asked now decides nothing and is refused in words (`texts.wrong_id`); without an id they answer what is asked now, as before. A value cut to fit `state.max_bytes` ends in `ellipsis`, so the terminal can say the rest is in the display.",
"digits_max": 9,
"ellipsis": "…"
},
"exit": {
"closed": 0,
+5 -10
View File
@@ -263,18 +263,13 @@ export function askKeys(e: Expecting): string {
}
const ID = S.ask_id
const ID_WORD = new RegExp(`^${ID.prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[${ID.alphabet}]{${ID.length}}$`)
const ID_WORD = new RegExp(`^\\d{1,${ID.digits_max}}$`)
/** A new id for what is asked (spec 3.15.0, loop.json `terminal.surface.ask_id`): `#k3f9`. */
export function newAskId(random: () => number = Math.random): string {
let id = ID.prefix
for (let i = 0; i < ID.length; i++) id += ID.alphabet[Math.floor(random() * ID.alphabet.length)]
return id
}
/** An answer command's argument (`kind: ask_id`): the id it names first, if any, and the rest. */
export function splitAskId(arg: string): { id?: string; rest: string } {
/** An answer command's argument (`kind: ask_id`): the id it names first, if any, and the rest.
* `/answer` takes the option alone as before: one word is the option, two are the id and it. */
export function splitAskId(arg: string, answer = false): { id?: string; rest: string } {
const words = arg.trim().split(/\s+/).filter(Boolean)
if (answer && words.length < 2) return { rest: words.join(" ") }
if (words[0] && ID_WORD.test(words[0])) return { id: words[0], rest: words.slice(1).join(" ") }
return { rest: words.join(" ") }
}
+9 -6
View File
@@ -9,7 +9,7 @@ import { clipEnd } from "../tui/layout.ts"
import type { Item, View } from "../tui/state.ts"
import { callAfter } from "../tui/transcript.ts"
import { receiveContext } from "./command.ts"
import { askKeys, newAskId, splitAskId, SurfaceInput, surfaceMode, type Action, type Expecting, type Scroll } from "./input.ts"
import { askKeys, splitAskId, SurfaceInput, surfaceMode, type Action, type Expecting, type Scroll } from "./input.ts"
import { plainValue } from "./uservars.ts"
import { setWindowSession } from "./windows.ts"
@@ -117,9 +117,11 @@ export function createSurface(app: App, view: View, hooks: SurfaceHooks) {
/** Each approval, and each question of a card, has an id of its own (spec 3.15.0): an answer
* that names one decides only that. Kept by the object asked, so a new one gets a new id. */
const ids = new WeakMap<object, string[]>()
let lastId = 0
const idFor = (o: object, at = 0): string => {
const list = ids.get(o) ?? []
list[at] ??= newAskId()
// A whole number, new for each (1 to digits_max digits, then round again).
list[at] ??= String((lastId = (lastId % (10 ** S.ask_id.digits_max - 1)) + 1))
ids.set(o, list)
return list[at]!
}
@@ -134,12 +136,13 @@ export function createSurface(app: App, view: View, hooks: SurfaceHooks) {
const ask = (): string => {
const e = expecting()
const p = view.state.pending
if (p) return plainValue(`approval ${askKeys(e)} ${idFor(p)} ${p.tool}: ${p.request.command ?? p.request.patterns.join(" ")}`)
const cut = (v: string) => plainValue(v, undefined, S.ask_id.ellipsis)
if (p) return cut(`approval#${idFor(p)} ${askKeys(e)} ${p.tool}: ${p.request.command ?? p.request.patterns.join(" ")}`)
const q = question()
if (q) return plainValue(`question ${askKeys(e)} ${idFor(q.req as object, q.at)} ${q.q.question}`)
if (q) return cut(`question#${idFor(q.req as object, q.at)} ${askKeys(e)} ${q.q.question}`)
// A command stands at the person's prompt: nothing to answer, a kind of its own.
const placed = app.terminal?.placed
if (placed) return plainValue(fillPrompt(PX.ask, { command: placed.command }))
if (placed) return plainValue(fillPrompt(PX.ask, { command: placed.command }), undefined, S.ask_id.ellipsis)
return ""
}
/** The command a call is waiting for the person to run or dismiss, if any. */
@@ -194,7 +197,7 @@ export function createSurface(app: App, view: View, hooks: SurfaceHooks) {
let arg = given
if (name === "approve" || name === "always" || name === "deny" || name === "answer") {
// An answer bound to what was shown: an id that is not the one asked now decides nothing.
const said = splitAskId(given)
const said = splitAskId(given, name === "answer")
const now = askedId()
if (said.id && said.id !== now) return view.info(fillPrompt(X.wrong_id, { said: said.id, now: now ? ` (${now})` : "" }), "warn")
arg = said.rest
+4 -3
View File
@@ -16,17 +16,18 @@ export type TerminalState = "idle" | "waiting" | "thinking" | "tools" | "writing
/** A value as it is published: control characters and line separators a space, white space run
* together, the ends trimmed, at most `max` UTF-8 bytes — cut at a character boundary. */
export function plainValue(v: unknown, max = S.max_bytes): string {
export function plainValue(v: unknown, max = S.max_bytes, ellipsis = ""): string {
const s = String(v ?? "")
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, " ")
.replace(/\s+/g, " ")
.trim()
const b = Buffer.from(s, "utf8")
if (b.length <= max) return s
let at = max
// A value that is cut may end in a mark saying so (lembas_ask: the rest is in the display).
let at = max - Buffer.byteLength(ellipsis, "utf8")
// Not into the middle of a character: its continuation bytes are 10xxxxxx.
while (at > 0 && (b[at]! & 0xc0) === 0x80) at--
return b.subarray(0, at).toString("utf8").trimEnd()
return b.subarray(0, at).toString("utf8").trimEnd() + ellipsis
}
/** The bytes that set one user var: `ESC ] 1337 ; SetUserVar=name=base64 ESC \`. */
+1 -1
View File
@@ -147,7 +147,7 @@ export const AREAS: Record<string, (c: Case) => unknown> = {
const input = new SurfaceInput()
return (c.reads as string[]).map((r) => input.feed(r, (c.expecting ?? {}) as Expecting))
}
if (c.kind === "ask_id") return splitAskId(c.arg as string)
if (c.kind === "ask_id") return splitAskId(c.arg as string, c.answer === true)
if (c.kind === "mode") return surfaceMode(c.asked as string)
if (c.kind === "status") return parseStatus(c.text as string) ?? null
if (c.kind === "ready") return ready({ record: c.record ? parseStatus(c.record as string) : undefined, paneText: (c.pane_text ?? "") as string, atPrompt: c.at_prompt === true })
+11 -4
View File
@@ -415,12 +415,11 @@ test("an approval's answer is bound to what was shown: lembas_ask carries its id
view.asker.ask({ tool: "terminal_run", args: { command }, request: { permission: "terminal_run", class: "execute", patterns: [command], command }, decision: { action: "ask", reason: "x", always: [] } } as never) as Promise<AskReply>
const first = card("make test")
await Bun.sleep(10)
const line = s.ask()
const m = /^approval yn (#[a-z0-9]{4}) terminal_run: make test$/.exec(line)
const m = /^approval#(\d{1,9}) yn terminal_run: make test$/.exec(s.ask())
expect(m).not.toBeNull()
const id = m![1]!
// The id of another card: refused in words, the card stays.
const other = id === "#aaaa" ? "#bbbb" : "#aaaa"
const other = String(Number(id) + 100)
s.feed(`/approve ${other}\r`)
expect(said().at(-1)).toBe(`${other} is not what is asked now (${id}) — nothing decided. Answer what the display shows.`)
expect(view.state.pending).toBeDefined()
@@ -430,10 +429,18 @@ test("an approval's answer is bound to what was shown: lembas_ask carries its id
// A new card has a new id; no id answers what is asked now, as before.
const second = card("make all")
await Bun.sleep(10)
expect(s.ask()).not.toContain(id)
expect(s.ask()).not.toStartWith(`approval#${id} `)
s.feed("/approve\r")
expect((await second).kind).toBe("once")
// Nothing asked: an id is refused as not what is asked.
s.feed(`/approve ${id}\r`)
expect(said().at(-1)).toBe(`${id} is not what is asked now — nothing decided. Answer what the display shows.`)
// A line too long for the ask line is cut and ends in an ellipsis.
const long = card("echo " + "x".repeat(400))
await Bun.sleep(10)
const line = s.ask()
expect(Buffer.byteLength(line, "utf8")).toBeLessThanOrEqual(LOOP.terminal.state.max_bytes)
expect(line.endsWith("\u2026")).toBe(true)
s.feed("/deny\r")
await long
})
+2 -2
View File
@@ -125,7 +125,7 @@ for (const width of [30, 45, 60]) {
shown.enter({ exit: 2 })
// Anything else that needs a yes is still a card, with its keys.
expect(await t.until("allow web_fetch?")).toBe(true)
expect(t.surface.ask()).toStartWith("approval y")
expect(t.surface.ask()).toMatch(/^approval#\d{1,9} y/)
expect(t.surface.ask()).toContain("web_fetch: ")
expect(t.frame()).toContain("y allow")
expect(t.frame()).toContain("n deny")
@@ -139,7 +139,7 @@ for (const width of [30, 45, 60]) {
expect(await t.until("3 Nothing")).toBe(true)
// (The recommended option is the first, as everywhere.)
expect(t.frame()).toContain("1 Run only that test")
expect(t.surface.ask()).toMatch(/^question 1-3n #[a-z2-9]{4} The oven test fails\. What should I do about it\?$/)
expect(t.surface.ask()).toMatch(/^question#\d{1,9} 1-3n The oven test fails\. What should I do about it\?$/)
// The command's row: the command and how it ended — never its output.
const row = lines().find((l) => l.startsWith("$ make test"))!
expect(row).toBeDefined()