diff --git a/CHANGELOG.md b/CHANGELOG.md index a7de8c8..6e469b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ All notable changes to LLeMbas CLI. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/). +## [Unreleased] + +Harness spec 3.7.0: one display in every client. + +### Added + +- **Harness spec 3.7.0: one display everywhere** (`harness/display.md`). The spec now says how + every client — the web UI, Desktop, the CLI, Android — shows a tool call: one short title made + from the call's arguments (the same in the transcript, on the progress line and over the link), + the four states running, done, failed and denied, how long a finished call took, `+added + −removed` for an edit, and the kinds of block. A reply that was stopped or failed keeps the + spec's line (`Stopped: by you`, `Failed: …`) on it. The approval, question and plan cards offer + the same actions everywhere, and numbers are written in the client's locale format. + ## [2.0.0-beta.8] — 2026-11-10 ### Added diff --git a/harness/README.md b/harness/README.md index 76e816f..552cb1b 100644 --- a/harness/README.md +++ b/harness/README.md @@ -22,13 +22,14 @@ page *Harness-parity* in LLeMbas CLI's wiki. | `permission/defaults.json` | The rules every session starts from | | `permission/modes.json` | The four modes — manual, edit, auto, plan — as what each does with each risk class | | `models/schema.json` | Model metadata: context, output limit, efforts and the thinking switch, vision, tools, notes, capacity (`parallel`); `levels` — the effort levels a chat offers and what each sends | -| `loop.json` | How one prompt runs: the step backstop, budgets, wrap-up, nudges, parallel calls, capacity; `jobs` — background work, its marks and limits; `subagents` — the model refusals, what names a model, the setting's label; `team` — a team's size, names, marks, refusals and texts; `progress` — the phases' texts; `context` — result ids, stubs, the output cap, the compaction table, the environment lines, the session notes; `scheduled` (3.5.0) — scheduled work on a linked computer: the setting, the modes, the approval wait, the sentinel, the watch command's limits and the refusals; `phone` (3.6.0) — phone actions: the capability, each action's fields, what is required and checked, the wait and the texts | +| `loop.json` | How one prompt runs: the step backstop, budgets, wrap-up, nudges, parallel calls, capacity; `jobs` — background work, its marks and limits; `subagents` — the model refusals, what names a model, the setting's label; `team` — a team's size, names, marks, refusals and texts; `progress` — the phases' texts; `context` — result ids, stubs, the output cap, the compaction table, the environment lines, the session notes; `scheduled` (3.5.0) — scheduled work on a linked computer: the setting, the modes, the approval wait, the sentinel, the watch command's limits and the refusals; `phone` (3.6.0) — phone actions: the capability, each action's fields, what is required and checked, the wait and the texts; `display` (3.7.0) — a call's title keys, states and facts, the blocks, the cards' actions | | `filesystem.md` | The file system a session works in: paths, node kinds, the four access levels, errors, listings, search and indexing by tokens, stacked instruction files, skills, memory | | `context.md` | Context hygiene: what happens to a tool result when it is inserted, and never afterwards; the prefix that stays still; reasoning sent back during its turn; no absolute paths in the prompt | | `team.md` | Teams: a lead and the members it adds, the size setting, the room, who receives what, reports, a manager's refusals, capacity, stopping | | `subagents.md` | Subagents: the word, which model one runs on (the session's, or one the person named), the capacity refusals, and when the Subagents setting is offered; from 3.4.0 (§5–§13) the main agent and its tree — only it adds, permissions inherited and never widened, request options, a subagent's life and its findings, what clients show | | `phone.md` | Phone actions (3.6.0): `phone_action`, carried out by the LLeMbas app on the person's phone and confirmed there — who offers it, how a call is checked, the answer, navigation | | `progress.md` | Progress (3.4.0): the thirteen phases every client shows the same way, the data each carries, their texts, and where they are sent | +| `display.md` | Display (3.7.0): one display in every client — a tool call's title, its four states, the duration and the facts beside it, the kinds of block; how `stopped` and `failed` stay on a finished reply; what the approval, question and plan cards offer; numbers in the client's locale | | `quirks.json` | What real servers do, and how both harnesses cope | | `conformance/.json` | Cases with their expected results, run by both test suites | | `acp.md` | The link between them: ACP plus every `_lembas/*` method, field and capability | @@ -73,6 +74,36 @@ page *Harness-parity* in LLeMbas CLI's wiki. approval in plan mode and answers its `unavailable` text outside it. Their permission key is `plan` (`permission/defaults.json`), which a rule written for the former `todo` key still reaches. +## 3.7.0 + +Written ahead of the implementations; the CLI carries it in the same round (`display.md`, +`loop.json` `display`). + +- **One display in every client** (`display.md`). **A tool call has one short title**, made from + its arguments alone — `questions` and `patch` by what they name, else the first non-blank string + among `summary`, `command`, `code`, `pattern`, `query`, `url`, `path`, `file_path`, `from`, + `description`, `name`, `id`, `title`, `key`, `target`, `to`, `action`; first line, 80 characters + — and it is the same string in the transcript, as `running_tool`'s `what` and as the link's + `tool_call` title. **This fixes the order `what` is taken in**: before, both implementations + looked at `path` before `pattern` and `query`, so a `grep` was titled by its directory. +- **Four states** — `running`, `done`, `failed`, `denied` — told apart in every client; a finished + call shows **how long it took** (`0.4s`, `1m 05s`, `2h 03m`), a denied one never; an edit shows + **`+added −removed`**, counted from the diff **by its hunks** (a header without `a/` `b/` is + still a header; a removed line beginning `-- ` is still a line); a command its non-zero + `exit N`; a search its hits. +- **The blocks** every client distinguishes: `shell`, `edit`, `read`, `search`, `web`, `task`, + `tool`; `plan` and `hidden` are not drawn. +- **`stopped` and `failed` stay on the finished reply**: the progress text alone (`Stopped: by + you`, `Stopped: budget`, `Failed: …`) at the end of that reply, in every client, and again + wherever the reply is shown from what was stored. Nothing else says it twice. +- **The cards**: an approval offers Allow once / Always allow (where the request offers it) / + Deny / Deny, and say why; a question its options and always "Something else"; a plan Approve + with the mode to continue in, and Revise (`loop.json` `display.actions`). +- **Numbers in the client's locale format**; durations, ids, exit codes and line numbers never. + Conformance texts are in the plain format. +- Conformance area **`display`** (titles, durations, hunk counts, facts, the end line, drawn + blocks); `progress` gains the `budget` stop. + ## 3.6.0 - **Phone actions** (`phone.md`, `tools/phone_action.json`, `loop.json` `phone`): a chat's model @@ -86,6 +117,7 @@ page *Harness-parity* in LLeMbas CLI's wiki. `unavailable` when the message being answered did not. Conformance area **`phone`** (the checks and the result texts). +## 3.5.0 Written ahead of both implementations; the server vendors it as written, both carry it in the same round (`acp.md` *Scheduled work on a linked computer*, `loop.json` `scheduled`). diff --git a/harness/VERSION b/harness/VERSION index 40c341b..7c69a55 100644 --- a/harness/VERSION +++ b/harness/VERSION @@ -1 +1 @@ -3.6.0 +3.7.0 diff --git a/harness/acp.md b/harness/acp.md index 1e3b9b8..db06d57 100644 --- a/harness/acp.md +++ b/harness/acp.md @@ -219,7 +219,17 @@ Params: `{ sessionId }`. Stops the running turn. `{ sessionId, update }` with `sessionUpdate` one of `agent_message_chunk`, `agent_thought_chunk`, `tool_call`, `tool_call_update`, `plan` (below), `current_mode_update`, and -`available_commands_update` (capability `commands`): +`available_commands_update` (capability `commands`). + +From spec 3.7.0 a `tool_call`'s `title` is **the call's short title** (`display.md` §1) — the +tool's name where the call has none — and no `tool_call_update` changes it: `completed` is the +state `done`, `failed` is `failed`, and a call that was refused is `failed` with +`_meta.lembas.denied: true` and the reason as its content (the state `denied`). The same title is +`title` on the `tool_start` event of `_lembas/event` and `what` of `running_tool`; `tool_end` +carries `ms`, the call's duration, and `tool_denied` its `reason`. A client of `_lembas/event` +that is given no `title` (a device before 3.7.0) makes it from `args` by the same rule. + +`available_commands_update`: ```json { "sessionUpdate": "available_commands_update", diff --git a/harness/conformance/display.json b/harness/conformance/display.json new file mode 100644 index 0000000..371a03f --- /dev/null +++ b/harness/conformance/display.json @@ -0,0 +1,666 @@ +{ + "about": "Display (display.md, spec 3.7.0), in the plain number format. `show` says what is asked. `title`: a call's `args` (and its `tool`, for the reader) — expect `title`, the one short title (display.md §1), or null where the call has none. `duration`: a call's `state` and `ms` — expect `duration` as drawn beside the title (§2), or null. `change`: a unified `diff` — expect `added`, `removed` counted by its hunks, and `text` (loop.json display.change). `facts`: a finished call's `block` with its `diff`, `exit` or `hits` — expect `facts`, the texts after the title in order. `end`: a turn's last `progress` (or null) — expect `line`, the line that stays on the finished reply (§4), or null. `drawn`: a `block` — whether it is drawn as a call (§3). LLeMbas: services/display.py; CLI: session/display.ts.", + "cases": [ + { + "about": "A command is its own title.", + "show": "title", + "tool": "bash", + "args": { + "command": "bun test", + "description": "Run the tests" + }, + "expect": { + "title": "bun test" + } + }, + { + "about": "Only the first line of a command.", + "show": "title", + "tool": "bash", + "args": { + "command": " cd src &&\n make " + }, + "expect": { + "title": "cd src &&" + } + }, + { + "about": "A search is titled by its pattern, not where it looks.", + "show": "title", + "tool": "grep", + "args": { + "pattern": "TODO\\(", + "path": "src" + }, + "expect": { + "title": "TODO\\(" + } + }, + { + "about": "A file search likewise.", + "show": "title", + "tool": "glob", + "args": { + "pattern": "**/*.ts", + "path": "src/tui" + }, + "expect": { + "title": "**/*.ts" + } + }, + { + "about": "A read by its path.", + "show": "title", + "tool": "read", + "args": { + "path": "src/app.ts", + "offset": 120 + }, + "expect": { + "title": "src/app.ts" + } + }, + { + "about": "A listing with no path has no title.", + "show": "title", + "tool": "list", + "args": { + "depth": 2 + }, + "expect": { + "title": null + } + }, + { + "about": "An edit by its path.", + "show": "title", + "tool": "edit", + "args": { + "path": "README.md", + "old": "a", + "new": "b" + }, + "expect": { + "title": "README.md" + } + }, + { + "about": "A web search by its query.", + "show": "title", + "tool": "web_search", + "args": { + "query": "opentui extmarks", + "max_results": 5 + }, + "expect": { + "title": "opentui extmarks" + } + }, + { + "about": "A fetch by its address.", + "show": "title", + "tool": "web_fetch", + "args": { + "url": "https://example.org/docs" + }, + "expect": { + "title": "https://example.org/docs" + } + }, + { + "about": "A task by its description, not its prompt.", + "show": "title", + "tool": "task", + "args": { + "description": "Find the callers", + "prompt": "Look through src/ for every caller of load() and list them." + }, + "expect": { + "title": "Find the callers" + } + }, + { + "about": "A subagent by its name.", + "show": "title", + "tool": "team_add", + "args": { + "name": "Reviewer", + "role": "reviews the change", + "task": "Read the diff." + }, + "expect": { + "title": "Reviewer" + } + }, + { + "about": "A phone action by its summary, whatever else it carries.", + "show": "title", + "tool": "phone_action", + "args": { + "action": "open_url", + "summary": "Open the timetable", + "url": "https://example.org/t" + }, + "expect": { + "title": "Open the timetable" + } + }, + { + "about": "Python by the first line of its code.", + "show": "title", + "tool": "python", + "args": { + "code": "import math\nprint(math.pi)" + }, + "expect": { + "title": "import math" + } + }, + { + "about": "A question by its headers.", + "show": "title", + "tool": "ask_user", + "args": { + "why": "The schema is open.", + "questions": [ + { + "header": "Database", + "question": "Which one?", + "options": [] + }, + { + "header": "Cache", + "question": "Which cache?", + "options": [] + } + ] + }, + "expect": { + "title": "Database · Cache" + } + }, + { + "about": "A patch by the files it names.", + "show": "title", + "tool": "apply_patch", + "args": { + "patch": "*** Begin Patch\n*** Update File: src/a.ts\n@@\n-x\n+y\n*** Add File: docs/b.md\n+hello\n*** Delete File: old.txt\n*** End Patch" + }, + "expect": { + "title": "src/a.ts, docs/b.md, old.txt" + } + }, + { + "about": "A unified diff as a patch: the +++ paths, without b/ and without /dev/null.", + "show": "title", + "tool": "apply_patch", + "args": { + "patch": "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1 +1 @@\n-x\n+y\n--- a/gone.txt\n+++ /dev/null\n@@ -1 +0,0 @@\n-bye\n" + }, + "expect": { + "title": "src/a.ts" + } + }, + { + "about": "A patch that names nothing falls back to its path.", + "show": "title", + "tool": "apply_patch", + "args": { + "patch": "@@ -1 +1 @@\n-x\n+y\n", + "path": "src/a.ts" + }, + "expect": { + "title": "src/a.ts" + } + }, + { + "about": "Cut to 80 characters: 79 and an ellipsis.", + "show": "title", + "tool": "bash", + "args": { + "command": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "expect": { + "title": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx…" + } + }, + { + "about": "Exactly 80 is not cut.", + "show": "title", + "tool": "bash", + "args": { + "command": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + }, + "expect": { + "title": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + } + }, + { + "about": "Counted in code points, not UTF-16 units.", + "show": "title", + "tool": "bash", + "args": { + "command": "echo 🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂" + }, + "expect": { + "title": "echo 🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂…" + } + }, + { + "about": "A blank argument is passed over.", + "show": "title", + "tool": "grep", + "args": { + "pattern": " ", + "path": "src" + }, + "expect": { + "title": "src" + } + }, + { + "about": "An argument that is not a string is passed over.", + "show": "title", + "tool": "job_output", + "args": { + "id": "job3", + "wait": 30 + }, + "expect": { + "title": "job3" + } + }, + { + "about": "A setting by its key.", + "show": "title", + "tool": "settings", + "args": { + "action": "set", + "key": "theme", + "value": "moria" + }, + "expect": { + "title": "theme" + } + }, + { + "about": "Only an action.", + "show": "title", + "tool": "tasks", + "args": { + "action": "list" + }, + "expect": { + "title": "list" + } + }, + { + "about": "No arguments, no title.", + "show": "title", + "tool": "job_list", + "args": {}, + "expect": { + "title": null + } + }, + { + "about": "Arguments that are not an object, no title.", + "show": "title", + "tool": "read", + "args": "src/app.ts", + "expect": { + "title": null + } + }, + { + "about": "A finished call: tenths under a minute.", + "show": "duration", + "state": "done", + "ms": 412, + "expect": { + "duration": "0.4s" + } + }, + { + "about": "Seconds.", + "show": "duration", + "state": "done", + "ms": 8449, + "expect": { + "duration": "8.4s" + } + }, + { + "about": "Just under a minute.", + "show": "duration", + "state": "failed", + "ms": 59940, + "expect": { + "duration": "59.9s" + } + }, + { + "about": "From a minute: minutes and whole seconds.", + "show": "duration", + "state": "done", + "ms": 65000, + "expect": { + "duration": "1m 05s" + } + }, + { + "about": "From an hour: hours and minutes.", + "show": "duration", + "state": "done", + "ms": 7380000, + "expect": { + "duration": "2h 03m" + } + }, + { + "about": "A failed call shows how long it took.", + "show": "duration", + "state": "failed", + "ms": 1200, + "expect": { + "duration": "1.2s" + } + }, + { + "about": "A denied call shows none.", + "show": "duration", + "state": "denied", + "ms": 3, + "expect": { + "duration": null + } + }, + { + "about": "A running call shows none.", + "show": "duration", + "state": "running", + "ms": 5000, + "expect": { + "duration": null + } + }, + { + "about": "A stored call whose time was not kept shows none.", + "show": "duration", + "state": "done", + "expect": { + "duration": null + } + }, + { + "about": "One line changed.", + "show": "change", + "diff": "--- a/a.txt\n+++ b/a.txt\n@@ -1,3 +1,3 @@\n one\n-two\n+2\n three\n", + "expect": { + "added": 1, + "removed": 1, + "text": "+1 −1" + } + }, + { + "about": "Headers without a/ and b/ are still headers.", + "show": "change", + "diff": "Index: a.txt\n===================================================================\n--- a.txt\n+++ a.txt\n@@ -1,2 +1,3 @@\n one\n+one and a half\n two\n", + "expect": { + "added": 1, + "removed": 0, + "text": "+1 −0" + } + }, + { + "about": "A removed line that begins with `-- ` and an added one that begins with `++ ` are lines, not headers.", + "show": "change", + "diff": "--- a/q.sql\n+++ b/q.sql\n@@ -1,3 +1,3 @@\n select 1;\n--- the old comment\n+++ the new one\n select 2;\n", + "expect": { + "added": 1, + "removed": 1, + "text": "+1 −1" + } + }, + { + "about": "A new file.", + "show": "change", + "diff": "--- /dev/null\n+++ b/new.txt\n@@ -0,0 +1,2 @@\n+a\n+b\n", + "expect": { + "added": 2, + "removed": 0, + "text": "+2 −0" + } + }, + { + "about": "A hunk header without counts means one line each.", + "show": "change", + "diff": "--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n", + "expect": { + "added": 1, + "removed": 1, + "text": "+1 −1" + } + }, + { + "about": "No newline at end of file counts for nothing.", + "show": "change", + "diff": "--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n\\ No newline at end of file\n+b\n\\ No newline at end of file\n", + "expect": { + "added": 1, + "removed": 1, + "text": "+1 −1" + } + }, + { + "about": "Two files add up.", + "show": "change", + "diff": "diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1 +1,2 @@\n a\n+b\ndiff --git a/c b/c\n--- a/c\n+++ b/c\n@@ -1,2 +1 @@\n c\n-d\n", + "expect": { + "added": 1, + "removed": 1, + "text": "+1 −1" + } + }, + { + "about": "No diff, nothing changed.", + "show": "change", + "diff": "", + "expect": { + "added": 0, + "removed": 0, + "text": "+0 −0" + } + }, + { + "about": "An edit shows its change.", + "show": "facts", + "block": "edit", + "diff": "--- a/x\n+++ b/x\n@@ -1 +1,2 @@\n-a\n+b\n+c\n", + "expect": { + "facts": [ + "+2 −1" + ] + } + }, + { + "about": "A command that failed shows its exit code.", + "show": "facts", + "block": "shell", + "exit": 2, + "expect": { + "facts": [ + "exit 2" + ] + } + }, + { + "about": "A command that succeeded shows none.", + "show": "facts", + "block": "shell", + "exit": 0, + "expect": { + "facts": [] + } + }, + { + "about": "A search shows its hits.", + "show": "facts", + "block": "search", + "hits": 14, + "expect": { + "facts": [ + "14 hits" + ] + } + }, + { + "about": "One hit.", + "show": "facts", + "block": "search", + "hits": 1, + "expect": { + "facts": [ + "1 hit" + ] + } + }, + { + "about": "No hits is a fact too.", + "show": "facts", + "block": "search", + "hits": 0, + "expect": { + "facts": [ + "0 hits" + ] + } + }, + { + "about": "A read has none of these.", + "show": "facts", + "block": "read", + "hits": 3, + "exit": 1, + "expect": { + "facts": [] + } + }, + { + "about": "Stopped by the person: the line stays on the reply.", + "show": "end", + "progress": { + "phase": "stopped", + "since": 1762790400000, + "reason": "person" + }, + "now": 1762790460000, + "expect": { + "line": "Stopped: by you" + } + }, + { + "about": "The budget ran out.", + "show": "end", + "progress": { + "phase": "stopped", + "since": 1762790400000, + "reason": "budget" + }, + "now": 1762790460000, + "expect": { + "line": "Stopped: budget" + } + }, + { + "about": "The step limit.", + "show": "end", + "progress": { + "phase": "stopped", + "since": 1762790400000, + "reason": "steps" + }, + "now": 1762790460000, + "expect": { + "line": "Stopped: step limit" + } + }, + { + "about": "Stopped, no reason known.", + "show": "end", + "progress": { + "phase": "stopped", + "since": 1762790400000 + }, + "now": 1762790460000, + "expect": { + "line": "Stopped" + } + }, + { + "about": "Failed, with the error.", + "show": "end", + "progress": { + "phase": "failed", + "since": 1762790400000, + "reason": "502 Bad Gateway" + }, + "now": 1762790460000, + "expect": { + "line": "Failed: 502 Bad Gateway" + } + }, + { + "about": "A reply that finished shows nothing.", + "show": "end", + "progress": null, + "now": 1762790460000, + "expect": { + "line": null + } + }, + { + "about": "A phase that is not an end shows nothing on the reply.", + "show": "end", + "progress": { + "phase": "writing", + "since": 1762790400000 + }, + "now": 1762790460000, + "expect": { + "line": null + } + }, + { + "about": "A plan change is not drawn as a call.", + "show": "drawn", + "block": "plan", + "expect": { + "drawn": false + } + }, + { + "about": "Nor a hidden tool.", + "show": "drawn", + "block": "hidden", + "expect": { + "drawn": false + } + }, + { + "about": "A command is.", + "show": "drawn", + "block": "shell", + "expect": { + "drawn": true + } + }, + { + "about": "A tool nobody knows is the generic block.", + "show": "drawn", + "expect": { + "drawn": true + } + } + ] +} diff --git a/harness/conformance/progress.json b/harness/conformance/progress.json index 6096060..7a3ca66 100644 --- a/harness/conformance/progress.json +++ b/harness/conformance/progress.json @@ -316,6 +316,19 @@ "line": "Stopped: step limit" } }, + { + "about": "Stopped when the budget ran out.", + "progress": { + "phase": "stopped", + "since": 1762790400000, + "reason": "budget" + }, + "now": 1762790400000, + "expect": { + "text": "Stopped: budget", + "line": "Stopped: budget" + } + }, { "about": "Failed.", "progress": { diff --git a/harness/display.md b/harness/display.md new file mode 100644 index 0000000..2b0286c --- /dev/null +++ b/harness/display.md @@ -0,0 +1,165 @@ +# Display + +Spec 3.7.0. **One display in every client** — the web UI, Desktop, the CLI, Android — for the +things every one of them draws: a tool call, the end of a reply that did not finish, the card that +waits for the person, and a number. `progress.md` says what a session is doing *now*; this says +what stays on the screen afterwards. The data is `loop.json` `display`; the cases +`conformance/display.json`. + +Each client keeps its own look — a terminal row, a card, a chip — and its own translation of the +fixed words. What is the same is **what is said, from which data, in which state**. + +## 1. A tool call's title + +One rule, and one title per call: **the call's short title** — the same string in the transcript, +as `what` of `running_tool` (`progress.md` §2) and as `title` of the link's `tool_call` +(`acp.md`). It is made from the call's arguments alone, so it is known the moment the call starts +and never changes afterwards: + +1. `questions` (a list, `ask_user`): its `header`s, joined with ` · `. +2. `patch` (a string, `apply_patch`): the files it names — every `*** Add File: `, + `*** Update File: ` and `*** Delete File: ` line's path, else every `+++ ` line's path without + a leading `b/` (`/dev/null` left out) — joined with `, `. +3. Otherwise the first of these arguments that is a string with anything but white space in it, + in this order (`display.title.keys`): `summary`, `command`, `code`, `pattern`, `query`, `url`, + `path`, `file_path`, `from`, `description`, `name`, `id`, `title`, `key`, `target`, `to`, + `action`. +4. Then: trimmed, **its first line only**, trimmed again, and cut to **80 characters** + (`progress.what_max`) — 79 and `…` — counted in code points. + +A call with none of these has **no title**: the client draws the tool's name alone, and +`running_tool` goes without `what`. + +The order puts what a call *does* before where: a `grep` is titled by its pattern, not its +directory; a `bash` by its command, not its description; `phone_action` by its `summary`. The +tool's own name (or the client's label for it — `Bash`, `Search files`; a client's own table) is +drawn beside the title and is not part of it. + +A tool the spec marks `block: plan` or `block: hidden` is not drawn as a call at all (§3). + +## 2. A call's states + +A drawn call is in exactly one of four states (`display.states`), and every client tells the four +apart at a glance — by a mark, a colour or a word of its own; never by the title, which is the +same in all four: + +| State | When | What is shown beside the title | +|---|---|---| +| `running` | from the call's start until its result | a mark that it is running (a spinner, `…`); no duration is required — a client that shows one counts it from the call's start, as `progress.md` §3 writes elapsed time | +| `done` | its result came and is not an error | **how long it took** (below) | +| `failed` | its result is an error — the tool's own failure, a non-zero exit a tool reports as one, a timeout | how long it took, and the **first line of the error** where there is room | +| `denied` | it was not run: the person, a rule, the mode or the hardline refused it | **no duration**; the first line of the reason where there is room | + +A call that was `running` when its turn was stopped, or whose result never came (the session +ended, the device went away), is drawn `failed` once that is known — never left spinning. + +**The duration** of a finished call is the time from its start to its result, as the +implementation that ran it measured it, written the one way (`display.duration`): under a minute +in seconds with one decimal (`0.4s`, `8.4s`); from a minute `1m 05s`; from an hour `2h 03m` — +`progress.md`'s elapsed form with tenths under a minute. A duration is not a locale number (§6): +it is written with `.` everywhere. A stored call whose duration was not kept shows none. + +**Facts from the result** (`display.facts`) go after the title, never in its place: + +- **an edit** (`block: edit`) shows **`+{{added}} −{{removed}}`** (`display.change`; the minus is + U+2212) once its change is known: the lines its diff adds and removes. Counted from the unified + diff by its hunks — after each `@@ -a,b +c,d @@` header, the next lines that begin with `+`, `-` + or a space until `b` old lines and `d` new lines are used up (`\ No newline at end of file` counts + for nothing; a missing `,b` or `,d` is 1); a `+` there is one added, a `-` one removed. Nothing + outside a hunk is counted, so a file header never is and a removed line that itself begins with + `-- ` always is. Several files in one diff add up. +- **a command** (`block: shell`) shows **`exit {{code}}`** (`display.exit`) when its exit code is + known and not 0. +- **a search** (`block: search`) shows **`{{count}} hits`** (`display.hits`, `display.hit` for 1) + where the implementation knows the count. + +Anything else an implementation knows (the lines read, a job's id) it may add the same way. + +## 3. The kinds of block + +A tool's `block` (`tools/.json`; `display.blocks`) says how its call is read, and every +client distinguishes these — at least by what it shows collapsed and what it opens to: + +| `block` | Collapsed | Opened | +|---|---|---| +| `shell` | the command (the title), `exit N` | the output | +| `edit` | the path, `+N −M` | the change as a diff — a client may show the first of it without a click | +| `read` | the path (or the id) that was read | the text that came back, where the client keeps it | +| `search` | the pattern or the query, the hits | the hits | +| `web` | the query or the address | the results or the page's text | +| `task` | the task handed to a subagent | what the subagent did — its own calls, its progress (`subagents.md` §12) — and its report | +| `tool` | the tool's name and the title | the result | +| `plan` | **not drawn**: the plan card refreshes instead | | +| `hidden` | **not drawn** | | + +A tool the client does not know (an MCP tool, a custom tool) is `tool`. + +## 4. How `stopped` and `failed` end a reply + +A turn that did not finish ends with the progress `stopped` or `failed` (`progress.md` §4). That +progress is not only the last thing on the progress line: **its line stays on the finished +reply** — the text alone, no elapsed time (`progress.md` §3): + +- `Stopped: by you` · `Stopped: step limit` · `Stopped: budget` · `Stopped` (no reason known) +- `Failed: {{reason}}` — the error, one line + +Every client draws it **at the end of that reply**, in the transcript, where it remains when the +next turn begins and the progress line has moved on — `failed` in the client's error colour, +`stopped` in its muted one. Nothing else says the same thing beside it: a client does not also +print the raw error or a second "cancelled" notice of its own wording. A reply with no text at all +(stopped before the first token) still gets the line, on its own. + +Where the reply is shown again from what was stored — a reload, a resumed session, another client +— it is drawn again from the stored end; an implementation that stores a reply stores how it +ended (`stopped` with its reason, `failed` with its reason). A turn that finished normally shows +nothing. + +## 5. What the card offers + +When a session waits for the person (`waiting_for_person`), every client offers the same actions +(`display.actions`), under these words or their translation: + +**An approval** (`what: approval`; `acp.md` `session/request_permission`): + +| Action | Words | Answer | +|---|---|---| +| `once` | Allow once | the call runs; nothing is remembered | +| `always` | Always allow | the call runs and the offered pattern is allowed from now on — **offered only where the request offers it** (`always` absent: `permission/arity.json` `exact_only`, a `confirm: always` tool). A client with more than one place to remember it (this session, this project) may offer each | +| `deny` | Deny | the call is not run | +| `deny_reason` | Deny, and say why | the call is not run and the person's words go to the model as the reason (`feedback`) | + +A client may also let the person **correct a command before allowing it once** (the answer's +`command`); what is written is judged again. Closing the card without choosing is `deny`. +The card shows what is asked about itself — the command, or the change as a diff — and the call's +`purpose` where one was given. + +**A question** (`what: question`; `ask_user`, `acp.md` `_lembas/question`): the options as given, +the recommended one first and marked; several may be chosen where `multiple`; and **always a row +of the person's own — "Something else"** (`something_else`) — that takes free text and answers +`custom`. A client may offer asking back (`back`) and skipping one of several questions +(`skipped`). Closing the card is `dismissed`. + +**A plan** (`what: plan`; `plan_submit`, `acp.md` `_lembas/plan`): **Approve** — together with +**the mode the work continues in** (`approve_edit`: Approve, continue in Edit; `approve_manual`: +Approve, continue in Manual; never a mode beyond what the session may have) — and **Revise** +(`revise`), which takes the person's words as feedback. Closing the card is `dismissed`: nothing +is decided. + +A client that cannot offer one of these (a notification with two buttons) offers what fits and +opens the full card for the rest; it never answers for the person. + +## 6. Numbers + +A number a person reads is written **in the client's own locale format** — its grouping and its +decimal mark, from the platform's number formatter and the locale the client runs in (the +browser's, the phone's, a terminal's `LC_NUMERIC` / `LC_ALL` / `LANG`), not from a rule here. That is every count and +measure: tokens (`12,480` · `12 480` · `12.480`), the rate (`12.5` · `12,5`), `done` / `total` and +`percent`, hits, lines, `+added −removed`, costs and credits. + +Not numbers in this sense, and written as they are everywhere: durations (§2, `progress.md` §3), +ids (`s1`, `job7`, `#12`), an exit code, a line number in a path (`a.ts:120`), a version, a port. + +The texts in `conformance/` are written in the **plain format** — no grouping, `.` for the +decimal mark — which is what an implementation's text function produces when it is given no +locale; a client passes its locale's formatter to the same function. Nothing sent between +implementations is ever formatted: `progress` carries numbers, and each client formats its own. diff --git a/harness/loop.json b/harness/loop.json index 98d7b5c..af6e17f 100644 --- a/harness/loop.json +++ b/harness/loop.json @@ -686,5 +686,92 @@ "panel", "values" ] + }, + "display": { + "about": "Spec 3.7.0 (display.md): one display in every client. `title`: how a tool call's one short title is made from its arguments (the same string in the transcript, as running_tool's `what` and as the link's tool_call title) — `questions` and `patch` first, then the first non-blank string among `keys`; first line, cut to progress.what_max. `states`: the four states of a drawn call; `no_duration`: the states that show none. `duration`: a finished call's time (tenths under a minute). `change`, `exit`, `hits`/`hit`: the facts after the title. `blocks`: the kinds of block every client distinguishes; `not_drawn`: those that are no call in the transcript. `end`: the phases whose line stays on the finished reply. `actions`: what each card offers, with its English words (shared i18n keys display.actions..). `plain`: the number format of the conformance texts. conformance/display.json.", + "title": { + "questions_join": " · ", + "patch_files": [ + "*** Add File: ", + "*** Update File: ", + "*** Delete File: " + ], + "patch_join": ", ", + "keys": [ + "summary", + "command", + "code", + "pattern", + "query", + "url", + "path", + "file_path", + "from", + "description", + "name", + "id", + "title", + "key", + "target", + "to", + "action" + ] + }, + "states": [ + "running", + "done", + "failed", + "denied" + ], + "no_duration": [ + "running", + "denied" + ], + "duration": { + "tenths_under_seconds": 60 + }, + "change": "+{{added}} −{{removed}}", + "exit": "exit {{code}}", + "hits": "{{count}} hits", + "hit": "{{count}} hit", + "blocks": [ + "shell", + "edit", + "read", + "search", + "web", + "task", + "tool", + "plan", + "hidden" + ], + "not_drawn": [ + "plan", + "hidden" + ], + "end": [ + "stopped", + "failed" + ], + "actions": { + "approval": { + "once": "Allow once", + "always": "Always allow", + "deny": "Deny", + "deny_reason": "Deny, and say why" + }, + "question": { + "something_else": "Something else" + }, + "plan": { + "approve_edit": "Approve, continue in Edit", + "approve_manual": "Approve, continue in Manual", + "revise": "Revise" + } + }, + "plain": { + "group": "", + "decimal": "." + } } } diff --git a/harness/progress.md b/harness/progress.md index ba3c4ca..d688a7e 100644 --- a/harness/progress.md +++ b/harness/progress.md @@ -35,7 +35,7 @@ In the order a turn usually meets them. `{{x}}` in a text is the field `x`; the | `reading_prompt` | `done: int`, `total: int` — prompt tokens processed of all | `Reading the prompt: {{done}} / {{total}} tokens ({{percent}}%)` · without `total`: `Reading the prompt` | | `thinking` | — | `Thinking` | | `writing` | `rate?: number` — tokens a second, as measured over this reply | `Writing: {{rate}} tok/s` · without `rate`: `Writing` | -| `running_tool` | `tool: string` (the tool's name); `what?: string` — the call's short title (the command, the path, the query), one line, at most 80 characters | `Running {{tool}}: {{what}}` · without `what`: `Running {{tool}}` | +| `running_tool` | `tool: string` (the tool's name); `what?: string` — the call's short title (the command, the path, the query; from 3.7.0 exactly `display.md` §1), one line, at most 80 characters | `Running {{tool}}: {{what}}` · without `what`: `Running {{tool}}` | | `waiting_for_person` | `what: "approval" \| "question" \| "plan"`; `tool?: string` (approval: the tool asked about) | `Waiting for you: {{what}}` | | `waiting_for_subagents` | `running: int` — subagents working or waiting now | `Waiting for subagents: {{running}} running` | | `compacting` | — | `Compacting the conversation` | @@ -88,7 +88,8 @@ What decides the phase, so that two implementations agree on the same moment: - `compacting` — a compaction runs. `retrying` — a failed request will be sent again after a wait. - `stopped` / `failed` — the turn ended other than by finishing: stopped by the person, a step limit or a budget; failed with an error. They are the last progress of that turn and stay until the - next one begins; a turn that finished normally ends with `null`. + next one begins; a turn that finished normally ends with `null`. From 3.7.0 their line also stays on + the finished reply itself (`display.md` §4). ## 5. Where it is sent diff --git a/src/harness.ts b/src/harness.ts index d87c77e..6289140 100644 --- a/src/harness.ts +++ b/src/harness.ts @@ -186,6 +186,27 @@ export const LOOP: { monitor: { timeout_seconds: { default: number; min: number; max: number }; excerpt_chars: number; output_max_bytes: number } texts: Record<"off" | "plan" | "denied" | "monitor_asks" | "monitor_denied" | "no_reply", string> } + /** Display (spec 3.7.0, harness/display.md): a tool call's title, states and facts, the blocks, + * the phases that end a reply, what each card offers. */ + display: { + title: { questions_join: string; patch_files: string[]; patch_join: string; keys: string[] } + states: string[] + no_duration: string[] + duration: { tenths_under_seconds: number } + change: string + exit: string + hits: string + hit: string + blocks: string[] + not_drawn: string[] + end: string[] + actions: { + approval: Record<"once" | "always" | "deny" | "deny_reason", string> + question: Record<"something_else", string> + plan: Record<"approve_edit" | "approve_manual" | "revise", string> + } + plain: { group: string; decimal: string } + } /** Progress (spec 3.4.0, harness/progress.md): the phases, their texts, the line. */ progress: { phases: string[] diff --git a/src/session/display.ts b/src/session/display.ts new file mode 100644 index 0000000..3ffebbc --- /dev/null +++ b/src/session/display.ts @@ -0,0 +1,151 @@ +// Display (harness spec 3.7.0, harness/display.md): what every client says about a tool call, the +// end of a reply and a number — the title, the states, the facts after the title. Pure: the TUI, +// the progress tracker and the ACP agent all read these. +import { LOOP } from "../harness.ts" +import { fillPrompt } from "../prompt/fill.ts" +import { duration } from "../duration.ts" + +const D = LOOP.display + +/** How a number is written: the plain format (no grouping, `.`) unless a client passes its own. */ +export type NumberFormat = (n: number, decimals?: number) => string + +export const plainNumber: NumberFormat = (n, decimals) => (decimals === undefined ? String(n) : n.toFixed(decimals)) + +/** A formatter for a locale (display.md §6): the platform's grouping and decimal mark. An unknown + * locale is the plain format. */ +export function localeNumber(locale: string | undefined): NumberFormat { + if (!locale) return plainNumber + try { + const whole = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }) + const cache = new Map() + return (n, decimals) => { + if (decimals === undefined) return (Number.isInteger(n) ? whole : new Intl.NumberFormat(locale)).format(n) + let f = cache.get(decimals) + if (!f) cache.set(decimals, (f = new Intl.NumberFormat(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }))) + return f.format(n) + } + } catch { + return plainNumber + } +} + +/** The locale a terminal runs in, as a BCP 47 tag: LC_ALL, then LC_NUMERIC, then LANG + * (`sk_SK.UTF-8` → `sk-SK`). `C`, `POSIX` and nothing at all are no locale: the plain format. */ +export function terminalLocale(env: Record = process.env): string | undefined { + const raw = env.LC_ALL || env.LC_NUMERIC || env.LANG + if (!raw) return undefined + const name = raw.split(/[.@]/)[0]! + if (!name || name === "C" || name === "POSIX") return undefined + const tag = name.replace(/_/g, "-") + try { + return Intl.getCanonicalLocales(tag)[0] + } catch { + return undefined + } +} + +/** One line, cut to the title's length in code points (79 and an ellipsis). */ +export function shortTitle(s: string | undefined): string | undefined { + if (!s) return undefined + const line = s.trim().split("\n")[0]!.trim() + if (!line) return undefined + const max = LOOP.progress.what_max + const points = [...line] + return points.length > max ? `${points.slice(0, max - 1).join("")}…` : line +} + +/** The files a patch names: its `*** Add/Update/Delete File:` lines, else its `+++ ` lines. */ +function patchFiles(patch: string): string[] { + const lines = patch.split("\n") + const named = lines.flatMap((l) => { + const head = D.title.patch_files.find((h) => l.startsWith(h)) + return head ? [l.slice(head.length).trim()] : [] + }) + if (named.length) return named.filter(Boolean) + return lines + .filter((l) => l.startsWith("+++ ")) + .map((l) => l.slice(4).split("\t")[0]!.trim().replace(/^b\//, "")) + .filter((f) => f && f !== "/dev/null") +} + +/** A tool call's one short title (display.md §1), from its arguments alone: the same string in the + * transcript, as `what` of running_tool and as the link's tool_call title. */ +export function callTitle(args: unknown): string | undefined { + if (!args || typeof args !== "object") return undefined + const a = args as Record + if (Array.isArray(a.questions)) { + const headers = (a.questions as unknown[]).map((q) => (q && typeof q === "object" ? (q as { header?: unknown }).header : undefined)).filter((h): h is string => typeof h === "string" && h.trim() !== "") + const t = shortTitle(headers.map((h) => h.trim()).join(D.title.questions_join)) + if (t) return t + } + if (typeof a.patch === "string") { + const t = shortTitle(patchFiles(a.patch).join(D.title.patch_join)) + if (t) return t + } + for (const k of D.title.keys) { + const v = a[k] + if (typeof v === "string" && v.trim()) return shortTitle(v) + } + return undefined +} + +export type CallState = "running" | "done" | "failed" | "denied" + +/** A finished call's duration (display.md §2): tenths under a minute, then 1m 05s, 2h 03m. None + * for a call that is running or was denied, or whose time was not kept. */ +export function callDuration(state: CallState, ms: number | undefined): string | undefined { + if (D.no_duration.includes(state) || ms === undefined || !Number.isFinite(ms)) return undefined + return duration(ms) +} + +/** The lines a unified diff adds and removes, counted by its hunks (display.md §2): nothing + * outside a hunk counts, so a file header never does and a removed `-- x` line always does. */ +export function diffCounts(diff: string): { added: number; removed: number } { + let added = 0 + let removed = 0 + let old = 0 + let fresh = 0 + for (const l of diff.split("\n")) { + if (old <= 0 && fresh <= 0) { + const m = /^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@/.exec(l) + if (m) { + old = m[1] === undefined ? 1 : Number(m[1]) + fresh = m[2] === undefined ? 1 : Number(m[2]) + } + continue + } + if (l.startsWith("+")) { + added++ + fresh-- + } else if (l.startsWith("-")) { + removed++ + old-- + } else if (l.startsWith("\\")) continue + else { + old-- + fresh-- + } + } + return { added, removed } +} + +const fill = (t: string, v: Record) => fillPrompt(t, v) + +/** `+3 −1` for an edit. */ +export function changeText(c: { added: number; removed: number }, num: NumberFormat = plainNumber): string { + return fill(D.change, { added: num(c.added), removed: num(c.removed) }) +} + +/** The facts after a finished call's title (display.md §2): an edit's change, a command's exit + * code when it is not 0, a search's hits. */ +export function callFacts(f: { block?: string; diff?: string; exit?: number | null; hits?: number }, num: NumberFormat = plainNumber): string[] { + const out: string[] = [] + if (f.block === "edit" && f.diff) out.push(changeText(diffCounts(f.diff), num)) + if (f.block === "shell" && typeof f.exit === "number" && f.exit !== 0) out.push(fill(D.exit, { code: String(f.exit) })) + if (f.block === "search" && typeof f.hits === "number") out.push(fill(f.hits === 1 ? D.hit : D.hits, { count: num(f.hits) })) + return out +} + +/** Whether a tool's block is drawn as a call at all (display.md §3). */ +export const drawnBlock = (block: string | undefined) => !D.not_drawn.includes(block ?? "tool") diff --git a/src/session/progress.ts b/src/session/progress.ts index 46d02bd..ff6c2b8 100644 --- a/src/session/progress.ts +++ b/src/session/progress.ts @@ -93,6 +93,13 @@ export function progressLine(p: Progress, now = Date.now()): string { return fill(P.line, { text, elapsed: duration(now - p.since, true) }) } +/** The line that stays on a reply that did not finish (display.md §4): the text of `stopped` or + * `failed`, alone; nothing for a reply that finished, or a phase that is not an end. */ +export function endLine(p: Progress | null | undefined, now = Date.now()): string | undefined { + if (!p || !LOOP.display.end.includes(p.phase)) return undefined + return progressLine(p, now) +} + /** Whether two objects are the same phase for the same thing (so `since` is kept). */ export function samePhase(a: Progress | null | undefined, b: Omit): boolean { if (!a || a.phase !== b.phase) return false diff --git a/tests/conformance.ts b/tests/conformance.ts index 593efde..5230dff 100644 --- a/tests/conformance.ts +++ b/tests/conformance.ts @@ -31,7 +31,8 @@ import { LOOP, TOOL_SPECS } from "../src/harness.ts" import { LEAD_TOOLS, memberTools, Team, TEAM_TOOLS, type Capacity } from "../src/team/team.ts" import { noteBlock } from "../src/session/prefix.ts" import { offer, subagentModel, type ModelInfo } from "../src/team/subagents.ts" -import { progressLine, progressText, type Progress } from "../src/session/progress.ts" +import { endLine, progressLine, progressText, type Progress } from "../src/session/progress.ts" +import { callDuration, callFacts, callTitle, changeText, diffCounts, drawnBlock, type CallState } from "../src/session/display.ts" import { checkMode, requestRefusal, tighten, whoDecides, type Grant } from "../src/team/delegation.ts" import { fillPrompt as fillText } from "../src/prompt/fill.ts" import { isSilent, judgeCase, monitorHash, scheduledMode, stripSentinel } from "../src/acp/scheduled.ts" @@ -355,6 +356,27 @@ export const AREAS: Record unknown> = { throw new Error(`team: unknown op ${String(st.op)}`) }) }, + // Display (display.md, spec 3.7.0): a call's title, duration and facts; the line that ends a reply. + display: (c) => { + switch (c.show) { + case "title": + return { title: callTitle(c.args) ?? null } + case "duration": + return { duration: callDuration(c.state as CallState, c.ms as number | undefined) ?? null } + case "change": { + const n = diffCounts(c.diff as string) + return { ...n, text: changeText(n) } + } + case "facts": + return { facts: callFacts(c as { block?: string; diff?: string; exit?: number; hits?: number }) } + case "end": + return { line: endLine(c.progress as Progress | null, c.now as number) ?? null } + case "drawn": + return { drawn: drawnBlock(c.block as string | undefined) } + default: + throw new Error(`display: unknown show ${String(c.show)}`) + } + }, // Progress (progress.md, spec 3.4.0): the text and the line a client draws. progress: (c) => { const p = c.progress as Progress