2.0 on dev: one server, context hygiene, stacked instructions, protocol 3

Working notes, Architecture, Harness parity and Home describe dev (2.0):
the CLI is LLeMbas-server-specific with one client (openai-chat to the
server's /v1), no custom connections or key_cmd; tool results are kept short
at insert time and never rewritten (session/results.ts, recall), so
compaction.prune is gone; instruction files stack from the project root down;
link protocol 3; memory from the server (lembas://memory); show. Each notes
where 1.x on main still differs. Spec 3.0.0 section: CLI side done for
instructions, context, show, memory and protocol 3; LLeMbas pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HomerandClaude Opus 5.5 committed 2026-10-27 21:59:38 +00:00
1 parent 5241eff7e0
commit fb36c22b95
4 files changed
+190 -94

No files matched your search

+95 -39
@@ -1,5 +1,8 @@
# Architecture
This page describes `dev` (2.0); where 1.x on `main` differs in a way that
matters, it says so.
One process per front end, one event bus per session. `createApp` (in
`src/app.ts`) wires configuration, the project, the model and an `Engine`; the
TUI, `lembas run`, the ACP agent and the tests all start there and subscribe to
@@ -26,12 +29,12 @@ version.ts replaced at compile time
bus/ the typed event bus, and the Asker interface (who answers approvals,
questions and plans)
config/ XDG paths (LEMBAS_HOME for tests), YAML loading and layering, {env:}/{file:}
substitution and key_cmd, the zod schema, the settings list, JSON Schemas
provider/ types.ts (Message, StreamEvent), common.ts (retry rule, part builder, stream
recorder), sse.ts, think.ts (inline <think> splitter), effort.ts, learned.ts,
discover.ts (context windows), http.ts (TLS, auth), tokens.ts, refs.ts (how a
model is named); one client per dialect: openai-chat.ts, responses.ts,
anthropic.ts, gemini.ts, ollama.ts
substitution, the zod schema, the settings list, JSON Schemas
provider/ index.ts (the login's model by its served id; NOT_LOGGED_IN), types.ts
(Message, StreamEvent), common.ts (retry rule, part builder, stream recorder),
sse.ts, think.ts (inline <think> splitter), effort.ts, learned.ts, http.ts (TLS,
auth), tokens.ts, refs.ts (a model's served id, and the older forms that still
resolve); the one client: openai-chat.ts
permission/ wildcard.ts, arity.ts (OpenCode), bash.ts (the small shell reader),
hardline.ts (the floor), evaluate.ts (rules, modes, paths)
tool/ tool.ts (the framework), registry.ts, names.ts (former names; `todo` becomes a
@@ -40,7 +43,8 @@ tool/ tool.ts (the framework), registry.ts, names.ts (former names;
glob, grep), bash (a command still running at its timeout becomes a job),
job_tools.ts (job_list, job_output, job_stop, job_send, report), web, ask_user,
plan_write, plan_update, plan_submit, task, memory, skills, library,
session_search, settings, view_image, project_tools (tasks, decisions)
session_search, settings, view_image, project_tools (tasks, decisions),
recall (any stored result again), show (a file in the client's viewer)
jobs/ registry.ts (one JobRegistry per process: commands and subagents as jobs, owned
by a session, persisted in the store, woken through the attached front end),
note.ts (the marked notes — conformance `jobs`)
@@ -49,10 +53,11 @@ plan/ plan.ts: the structured plan (harness/conformance/plan.json)
prototype/ fence.ts (a prototype fence's header and title), store.ts (saved under the
state directory, one file per prototype, named in the transcript)
session/ engine.ts (the loop), store.ts (SQLite + FTS5), turns.ts (undo/redo),
results.ts (context hygiene: result ids, stubs, the cap, recall),
title.ts, context.ts (/context), capacity.ts (the capacity rule),
commands.ts (slash commands shared by the TUI and ACP)
prompt/ assemble.ts (the system prompt), fill.ts (a spec text's variables; a bullet
whose variable is empty disappears), personality.ts
prompt/ assemble.ts (the system prompt, instructionChain), fill.ts (a spec text's
variables; a bullet whose variable is empty disappears), personality.ts
project/ root.ts (.agent, or .lembas), init.ts (first open: trust, git, skeleton),
safe.ts (no writes through a committed symlink), attach.ts (@ references),
files.ts (the @ index), commands.ts, agents.ts, board.ts, image.ts
@@ -65,8 +70,9 @@ library/ store.ts (notes, bases, documents, chunks; FTS5 + vectors), c
mcp/ index.ts (McpManager: stdio and HTTP servers), oauth.ts
search/ webui (a LLeMbas instance's), searxng, firecrawl, ddg; fetch.ts (pages)
voice/ audio.ts (recorders and players), speech.ts, text.ts, index.ts
lembas/ a LLeMbas instance: client.ts (discovery, device login), login.ts, webui.ts
(the `webui` connection), personal.ts (personalization, library, usage)
lembas/ the LLeMbas server: client.ts (discovery, device login, the protocol check),
login.ts, webui.ts (the login, expanded into the server's /v1 and its
models), personal.ts (personalization, usage)
acp/ agent.ts, rpc.ts, link.ts, hub.ts, share.ts, prompt.ts, turns.ts,
pending.ts, shellrc.ts — see below
update/ index.ts, source.ts, sshsig.ts, version.ts — see below
@@ -89,7 +95,8 @@ licences, harness), `install.sh` and `get.sh`, `third_party/`.
3. Run what was allowed: consecutive ordinary calls together, up to four; an
`exclusive` tool (such as `ask_user`) alone; two calls on the same file in
order. Errors become tool results, never exceptions.
4. Append the results and go round again.
4. Append the results — each made into what the model sees as it is inserted
(`session/results.ts`, below) — and go round again.
The numbers — the step backstop, how many calls run together, how often a
silent reply is nudged, and the wrap-up message — are `harness/loop.json`'s
@@ -104,11 +111,32 @@ after the step's tool results as one user message marked `STEER_MARK`
streamed, so `/continue` picks up there. **Budgets** (`harness/loop.json`: wall
time, tool output bytes, written tokens) and the **step ceiling** withdraw the
tools and ask for an answer from what the model has. **Context**: before each
step, past `compaction.auto_at` of the window, old tool outputs are pruned, then
— if still over — the history is summarised and the turn's prompt put back
verbatim. **Capacity** (`session/capacity.ts`) refuses a subagent on a model its
step, past `compaction.auto_at` of the window, the history is summarised, the
table of reads appended, and the turn's prompt put back verbatim — at most twice
a turn. Nothing is pruned in place any more (1.x cut old outputs first; that
threw the prompt cache away). **Capacity** (`session/capacity.ts`) refuses a
subagent on a model its
server cannot hold beside the session's own, or beside a running subagent's.
## Context hygiene (`src/session/results.ts`)
Harness spec 3.0.0 (`harness/context.md`, `loop.json` `context`): every measure
acts when a result is inserted, and **nothing already sent is ever rewritten**,
so the server's prompt cache holds. `ResultContext` gives every result an id
(`#` and hex, at least four digits, never reused — `[#0001]`); a read is headed
by its path, lines, length and the first 8 hex digits of the content's SHA-256.
A read of an unchanged file inside an earlier full read, or a `list`/`glob`/`grep`
repeated with the same result, is a stub naming the earlier id. Output over 400
lines or 40,000 characters keeps its head and tail with an
`[N lines elided, full output #id]` line. `edit`, `multiedit`, `write` and
`apply_patch` answer with their hunks under the new content's hash. Full results
live in the session store's `results` table, so **`recall`** (`tool/recall.ts`)
shows any of them, or a range, also after a resume or a compaction. A stub only
points at a result still in the conversation (`presentIds`): after a compaction,
an `/undo` or a rewind the file is read in full. Compaction appends
`compactionTable()` — the reads still in the conversation — to the summary.
`blocks/context.md` tells the model, wherever `recall` is offered.
## Background work: jobs (`src/jobs/`)
A **job** is a command in the background (`bash` with `background: true`, or a foreground
@@ -129,7 +157,7 @@ process exit every command's group gets TERM, then KILL, synchronously.
## Subagents (`src/app.ts` spawn, `src/tool/task.ts`)
`spawn()` builds a child `Engine` — its own `Bus`, the parent's tools minus `NOT_FOR_SUBAGENTS`
plus `report`, `stricterMode`, `limits.subagent_steps`, the parent's fallback — with a session
plus `report`, `stricterMode`, `limits.subagent_steps` — with a session
row of its own (`sessions.parent_id`; children are left out of `/sessions` and
`session_search`, and deleted with the parent), and registers it as a subagent job: the
registry follows the child's bus (its text and tool lines become the job's transcript for
@@ -168,14 +196,20 @@ one runs others offers no "always".
## Providers (`src/provider/`)
Every dialect turns the provider-neutral `Message[]` into its request and its
stream into the same `StreamEvent`s (`text`, `reasoning`, `tool_call_delta`,
`usage`, `progress`, `notice`, `finish`). What a provider needs back next turn
travels on the parts: Anthropic thinking signatures, a Responses reasoning item,
Gemini's thought signature. A part another provider cannot take is dropped on
conversion, never sent malformed. `common.retrying()` owns the retry rule: only
while nothing of the reply has been passed on, plus one attempt for a server
error. `effort.ts` and `learned.ts` remember an effort a server refused.
There is one: the server the CLI is logged in to, spoken to as OpenAI chat at
its `/v1` (`openai-chat.ts`). `index.ts` `resolveModel` finds a model by its
served id (`deepseek/deepseek-flash`; `refs.ts` still resolves the older
`<login>/<id>` forms), else `config.yaml`'s `model`, else the server's default
for the account; without a login it throws `NOT_LOGGED_IN`, which says
`lembas login <address>`. The context window, efforts, vision and capacity are
what `/v1/models` says — no discovery. The client turns the provider-neutral
`Message[]` into its request and its stream into `StreamEvent`s (`text`,
`reasoning`, `tool_call_delta`, `usage`, `progress`, `notice`, `finish`).
`common.retrying()` owns the retry rule: only while nothing of the reply has
been passed on, plus one attempt for a server error. `effort.ts` and
`learned.ts` remember an effort a server refused. *1.x on `main`* has five
dialects (`openai-chat`, `responses`, `anthropic`, `gemini`, `ollama`), custom
connections, context discovery and a model `fallback`.
## The session store and turns
@@ -196,11 +230,11 @@ Identity → the shared text (`system/default.md`, its variables filled by
`prompt/fill.ts`: the terminal as the surface, the file tools, background
commands, the git section, the current plan) and the family overlay → the
instance's instructions, when a LLeMbas client sent them over the link →
environment, model roster, git state, task board → `AGENTS.md` / `CLAUDE.md` and
`instruction_files` → MCP server instructions (scanned) → memory guidance and the
memory snapshot → the skills block → the library block (when knowledge tools are
offered; the knowledge scope names the bases an instance limited the chat to) →
the prototypes block (when offered: by the instance, or `prototypes: true` for a
environment, model roster, git state, task board → the instruction files →
MCP server instructions (scanned) → memory guidance and the memory snapshot (the
server's `lembas://memory` when memory is the server's) → the skills block → the
library block (when knowledge tools are offered; this machine's bases only) →
the context block (where `recall` is offered) → the prototypes block (when offered: by the instance, or `prototypes: true` for a
local session) → the mode → the person's custom instructions → the personality
(an instance's, when it sent them). The last two use the same headings and order
as the LLeMbas web UI. Memory and skills are
@@ -208,6 +242,12 @@ as the LLeMbas web UI. Memory and skills are
the session does not change the prompt under it and the provider's prompt cache
stays valid.
**Instruction files stack** (`instructionChain`, harness `filesystem.md`): the
global `AGENTS.md`, then every directory from the project root down to the
working directory, outermost first, each giving its `AGENTS.md`, else its
`CLAUDE.md` — only a real file inside the project (a link out is passed over) —
then the configured `instructions`. 1.x took only the nearest file.
## The TUI (`src/tui/`)
A subscriber like any other. `state.ts` turns bus events into a list of items,
@@ -237,12 +277,23 @@ asks first.
`roots`, `max_mode`, trust and approval timeout. **Context is the client's**:
`_meta.lembas` on `session/new` and every `session/prompt` may carry the
instance's system prompt, the account's personalization, the chat's knowledge
bases (then sent back as `_meta.lembas.scope` on every library call to the
instance) and whether prototypes are offered — the five 1.1.0 capabilities
`context`, `library`, `prototypes`, `plan_state` (the plan as a structure on
the `plan` update, on `_lembas/plan` and in `status`) and `rewind`
(`_lembas/session/rewind`: a turn and everything after it leave the
conversation as `/undo` does, files untouched).
bases (no longer read: the knowledge bases are this machine's) and whether
prototypes are offered — the 1.1.0 capabilities `context`, `library`,
`prototypes`, `plan_state` (the plan as a structure on the `plan` update, on
`_lembas/plan` and in `status`) and `rewind` (`_lembas/session/rewind`: a
turn and everything after it leave the conversation as `/undo` does, files
untouched). A session the client opened sends its id as
`_meta.lembas.scope` on every memory call and on the memory read. **`show`**
(spec 3.0.0): offered only in a session a client opened that said it can show
files; the device reads the file (at most 1 MB) and sends it with
`_lembas/show` to the web UI's or Desktop's viewer. A bare terminal never
offers it.
- **Link protocol 3** (`LEMBAS_PROTOCOL`): spoken alone. A server listing only 1
and 2 is refused at login and before every dial, saying to update the server
or use LLeMbas CLI 1.x; a newer one is told to update the CLI; a 4400 close
stops the link with the same advice. `session/new`'s result says `instance`,
and a session the client opens runs on the chat's model or is refused (-32602
with the reason) — never answered on the device's own model.
- **`rpc.ts`** — JSON-RPC 2.0, one message a line on stdio and one per WebSocket
frame on the link; written here so its few rules are what LLeMbas implements in
Python too.
@@ -298,14 +349,19 @@ running while nobody is logged in.
## Library, memory, skills, MCP, voice
- **Memory** is two small files (`MEMORY.md`, `USER.md`) under the config
directory, written by the `memory` tool and scanned by `memory/threats.ts`.
- **Memory** is the server's when the login's token has the `memory` scope
(`library: lembas`, the default then): the `memory` tool is the server's
`/mcp` tool, and the prompt's snapshot is the resource `lembas://memory`, read
as a session starts and kept for it. Otherwise it is two small files
(`MEMORY.md`, `USER.md`) under the config directory, written by the `memory`
tool and scanned by `memory/threats.ts`.
**Skills** are `SKILL.md` directories; only names and first lines enter the
prompt, and `skill_manage` is all-or-nothing across the files it touches.
- **The library** is one SQLite file: notes, knowledge bases, documents and
chunks (LLeMbas's chunker, shared by conformance), bm25 plus optional vectors,
fused by reciprocal rank. Logged in with `library: lembas`, the account's
library on the instance is used over `/mcp` instead.
fused by reciprocal rank. It is always this machine's: with `library: lembas`
only memory comes from the server's `/mcp` (1.x took notes and knowledge from
there too).
- **MCP**: `McpManager` connects every server at once without blocking the TUI;
a server that connects mid-session is usable from the next prompt. Stdio
servers get a minimal environment; HTTP servers try streamable HTTP, then SSE;
+32 -22
@@ -14,7 +14,8 @@ This page maps every shared concept to its file in both, and says where they
still differ. **Read it before touching either harness, and keep it true** — a
wrong row is how one side silently stops matching the other. Paths: CLI under
`src/` unless they start with `harness/`, `scripts/` or `tests/`; LLeMbas under
`src/lembas/` unless they start with `scripts/` or `tests/`.
`src/lembas/` unless they start with `scripts/` or `tests/`. The CLI column
describes `dev` (2.0); where 1.x on `main` differs, the row says so.
## The rule
@@ -61,6 +62,8 @@ wrong row is how one side silently stops matching the other. Paths: CLI under
| `prototype` | `prototype/fence.ts` `parseInfo`, `titleFor` | `services/prototypes.py` `info` (`parse_info`, `title_for`) |
| `library_scope` | `library/store.ts` `resolveBase` | `services/library/documents.py` `resolve_base` |
| `toolcall_index` | `provider/openai-chat.ts` `ToolCallAccumulator` | `services/llm/openai_client.py` (the accumulator) |
| `instructions` | `prompt/assemble.ts` `instructionChain` | **pending** (spec 3.0.0) |
| `context` | `session/results.ts` `ResultContext` | **pending** (spec 3.0.0) |
## Tools
@@ -79,7 +82,7 @@ a linked CLI — so the execution tools are `cli`.
| `plan_submit` | shared | `tool/plan_submit.ts`; card `tui/components/plancard.tsx` | `services/tools.py`, `services/interaction.py` `plan_card` (the same card a device's `_lembas/plan` draws) | offered in Plan mode only, on both; the CLI also writes the plan to a file under `.agent/plans/` for the record |
| `web_search` | shared | `tool/web.ts`, `search/` | `web_search` in `services/tools.py`, `services/search/` | — (the spec's text since LLeMbas 1.4.0) |
| `web_fetch` | shared | `tool/web.ts`, `search/fetch.ts` | `web_fetch` in `services/tools.py`, `services/fetch.py` `html_to_markdown` | — since LLeMbas 1.4.0: markdown (turndown's settings, `<main>`/`<article>` first), 20,000-character parts with `offset`; `fetch` a former name. LLeMbas has no Firecrawl scrape route (the CLI's `search.fetch: firecrawl`) |
| `memory` | shared | `tool/memory.ts`, `memory/store.ts` `applyOps` | `memory` in `services/tools.py`, `services/library/memories.py` `apply_ops` / `apply` | — since spec 1.2.0 / LLeMbas 1.5.0: one target there (`user`, `narrow.llembas`), limit 4,000; the CLI also refuses entries that look like prompt injection (`memory/threats.ts`), LLeMbas does not (Open items) |
| `memory` | shared | `tool/memory.ts`, `memory/store.ts` `applyOps` | `memory` in `services/tools.py`, `services/library/memories.py` `apply_ops` / `apply` | — since spec 1.2.0 / LLeMbas 1.5.0: one target there (`user`, `narrow.llembas`), limit 4,000; the CLI also refuses entries that look like prompt injection (`memory/threats.ts`), LLeMbas does not (Open items). On `dev`, with the login's `memory` scope the CLI's `memory` *is* the server's `/mcp` tool |
| `notes_search` · `note_view` · `note_manage` | shared | `tool/library.ts`, `library/store.ts` | the same names in `services/tools.py`, `services/library/notes.py` | — since spec 1.2.0: no `scope` there (`narrow.llembas`); ids are strings on both |
| `skills_list` · `skill_view` · `skill_manage` | shared | `tool/skills.ts`, `skill/index.ts` | the same names in `services/tools.py` (`compose_skill`, `parse_skill`), `services/library/skills.py`; the index is in the prompt as well | — since spec 1.2.0: create, patch, delete, revert only there (no supporting files, categories or project skills — `narrow.llembas`); a patch is exact-match there, where the CLI's `replace` also matches loosely; names are slugs with hyphens there |
| `knowledge_search` · `knowledge_get` | shared | `tool/library.ts`, `library/store.ts` | `services/tools.py`, `services/library/documents.py`, `retrieval.py` | — the spec's text and `base` on both; ids are strings in the spec since 1.2.0 (a number is taken by the CLI) |
@@ -90,6 +93,8 @@ a linked CLI — so the execution tools are `cli`.
| `bash` | cli | `tool/bash.ts`, `jobs/registry.ts` (a command still running at `timeout` is adopted as a job; `background: true` starts as one) | — | by design |
| `tasks` · `decisions` | cli | `tool/project_tools.ts`, `project/board.ts` | — | by design |
| `session_search` · `settings` · `view_image` | cli | `tool/session_search.ts`, `tool/settings.ts`, `tool/view_image.ts` | — | by design |
| `recall` | shared (spec 3.0.0) | `tool/recall.ts`, answered by the engine from `session/results.ts` | **pending** | — |
| `show` | shared, `requires: display` (spec 3.0.0) | `tool/show.ts`: offered only in a session a client opened that says `show`; sends `_lembas/show` | **pending** (the viewer, and relaying a device's) | — |
| Former names | | `tool/names.ts` reads `aliases.cli` and `argument_aliases`; `todo` converts its list into a plan | `services/tools.py` `resolve_alias`: `todo` → `plan_write`, `subagent_run` → `task`, and since 1.5.0 `memory_add`/`memory_forget` → `memory`, `notes_get` → `note_view`, `notes_create`/`_edit`/`_delete` → `note_manage`, `skill_get` → `skill_view`, `skill_create`/`skill_edit` → `skill_manage` (in the chat loop and on `/mcp`) | — |
| A project offering less (`narrow`) | | `harness.ts` `narrowParameters` (conformance only: the CLI offers every shared tool whole) | `services/harness_spec.py` `narrow`, `offered_parameters` | — |
| Variables in descriptions | | `harness.ts` `fillDescription` / `fillParameters` = `prompt/fill.ts`; the library's values in `tool/spec-vars.ts` | `services/harness_spec.py` `fill` / `fill_parameters`; values in `services/tools.py` `LLEMBAS_VARS` | LLeMbas's `fill` also drops a line a variable left empty and collapses blank lines, beyond the spec's bullet rule (Open items) |
@@ -115,7 +120,7 @@ a linked CLI — so the execution tools are `cli`.
| The loop: step backstop, budgets, wrap-up, parallel calls | `harness/loop.json`; `session/engine.ts` | `services/generation.py` (`_run`, `_wrap_up`), `services/settings_store.py` | budgets unset by default in the CLI |
| Capacity rule | `session/capacity.ts` (against the parent's model and every running subagent job's) | `services/subagent.py`, the connection's flags (`db/models/connection.py`) | — |
| Jobs: marks, caps, the note (`loop.json` `jobs`, `conformance/jobs.json`) | `jobs/note.ts` `jobNote`, `jobs/registry.ts`; `LOOP.jobs` in `harness.ts` | `services/jobs.py` `note`; `harness_spec.loop()["jobs"]` | the CLI owns commands; LLeMbas's jobs are its own helpers, and a device's are shown from the link |
| Dialects | `provider/openai-chat.ts`, `responses.ts`, `anthropic.ts`, `gemini.ts`, `ollama.ts` | `services/llm/openai_client.py`, `anthropic_client.py` | LLeMbas: OpenAI chat and Anthropic, by design |
| Dialects | `provider/openai-chat.ts` alone, to the server's `/v1` (1.x: also `responses`, `anthropic`, `gemini`, `ollama`) | `services/llm/openai_client.py`, `anthropic_client.py` | by design: the server speaks to providers, the CLI to the server |
| Quirks of real servers | `harness/quirks.json`; `provider/common.ts`, `sse.ts`, `openai-chat.ts` | `services/llm/openai_client.py`, `services/generation.py` | — |
| Reasoning effort | `provider/effort.ts`, `provider/learned.ts` | `services/chat.py`, `services/generation.py` | — |
| Model metadata | `harness/models/schema.json`; `config/schema.ts`, `lembas/webui.ts` reads it from `/v1/models` | served at `/v1/models` (`api/v1/openai.py`) from the model rows | — |
@@ -124,7 +129,9 @@ a linked CLI — so the execution tools are `cli`.
| The plan in the prompt | `{{plan_context}}` filled from the session's plan | `{{plan_context}}` filled from `chat.plan` | identical |
| `tasks/continue.md` | `session/commands.ts`, `session/engine.ts` | `harness_spec.prompt("tasks/continue.md")` in `api/chats.py`, `services/generation.py`, `web/templating.py` | identical |
| Personality presets | `harness/prompts/personality/`; `prompt/personality.ts` | `services/personalization.py` (reads the vendored presets) | identical |
| Compaction | prune, then summarise, prompt put back (`session/engine.ts`) | summary as a user + assistant turn, turns kept collapsed (`services/compaction.py`) | shape |
| Context hygiene (`context.md`) | at insert time, nothing sent rewritten: ids, read stubs, the cap, edit diffs, `recall` (`session/results.ts`) | **pending** | spec 3.0.0 |
| Compaction | summarise, append the table of reads, prompt put back (`session/engine.ts`); no prune (1.x pruned old outputs first) | summary as a user + assistant turn, turns kept collapsed (`services/compaction.py`) | shape |
| Instruction files | stacked: every `AGENTS.md` (else `CLAUDE.md`) from the project root down to the working directory, outermost first (`prompt/assemble.ts` `instructionChain`; 1.x: the nearest only) | **pending** (over the server's tree) | spec 3.0.0 |
| Library: chunking, search, fusion | `library/chunks.ts`, `library/store.ts` | `services/library/chunks.py`, `retrieval.py` | — |
**Prompt texts.** `harness/prompts/index.json` records, for each shared text,
@@ -148,14 +155,14 @@ Shared but still differing in LLeMbas: `family/*.md`, `blocks/memory.md`,
| ACP role | agent — `acp/agent.ts` | client — `services/device_link.py` |
| JSON-RPC framing | `acp/rpc.ts` | `device_link.Link` |
| The link | `acp/link.ts` (dials out), `service.ts` | `api/devices.py` `device_link_socket` (`/api/devices/link`) |
| `_lembas` protocol versions | `acp/agent.ts` `LEMBAS_PROTOCOL` = 2; says 2 only to an instance whose discovery lists it | `device_link.PROTOCOL` = 2, `PROTOCOLS` = (1, 2), `ACP_VERSION` = 1 |
| Discovery | `lembas/client.ts` reads `protocols`, at login and every dial | `/.well-known/lembas.json`: `protocol: 1`, `protocols: [1, 2]` |
| Capabilities (`files`, `commands`, `attachments`, `ask`, `plan`, `model`, `turns`, `shell`, since 1.1.0 `context`, `library`, `prototypes`, `plan_state`, `rewind`, since 2.0.0 `jobs`) | offered in `initialize`'s `_meta.lembas.capabilities` | used only when listed |
| `_lembas` protocol versions | `acp/agent.ts` `LEMBAS_PROTOCOL` = 3, alone (1.x: 2, falling back to 1) | `device_link.PROTOCOL` = 2, `PROTOCOLS` = (1, 2), `ACP_VERSION` = 1 — protocol 3 **pending** |
| Discovery | `lembas/client.ts` reads `protocols` at login and every dial; a server without 3 is refused with "update the server, or use LLeMbas CLI 1.x" (`protocolMismatch`) | `/.well-known/lembas.json`: `protocol: 1`, `protocols: [1, 2]` (3.0.0 raises `protocol` to 3 on purpose) |
| Capabilities (`files`, `commands`, `attachments`, `ask`, `plan`, `model`, `turns`, `shell`, since 1.1.0 `context`, `library`, `prototypes`, `plan_state`, `rewind`, since 2.0.0 `jobs`, since 3.0.0 `show`) | offered in `initialize`'s `_meta.lembas.capabilities` | used only when listed |
| Jobs on the link (`jobs`) | `job` / `job_note` events and `sub_tool` with `jobId` forwarded as `_lembas/event`; `_lembas/jobs`, `_lembas/job/output`, `_lembas/job/stop`, `_lembas/job/send`, `_lembas/job/transcript` in `acp/agent.ts`; `jobs` in `status`; `job` on `session/request_permission`; `machine: true` on a note's `prompt` | `services/device_link.py` `apply_event` → the Jobs strip above the composer and the subagent panel; the routes `POST /api/chats/{id}/jobs/{job}/stop` and `/send` call the device; the strip is refilled from `status.jobs` on reattach and polls while it has rows; a `machine` prompt is mirrored as the harness's turn | — |
| What only the client knows (`context`, `library`, `prototypes`) | read from `_meta.lembas` on `session/new` and every `session/prompt` into the session's context (`acp/agent.ts` `contextOf`), consumed by `prompt/assemble.ts`: the instance's instructions, its personalization in place of the device's, the knowledge scope, the prototype offer | sent by `services/device_link.py` on every prompt: `chat.effective_system_prompt`, the owner's personalization, the chat's knowledge bases, `prototypes.offered` |
| What only the client knows (`context`, `library`, `prototypes`) | read from `_meta.lembas` on `session/new` and every `session/prompt` into the session's context (`acp/agent.ts` `contextOf`), consumed by `prompt/assemble.ts`: the instance's instructions, its personalization in place of the device's, the prototype offer; the knowledge scope is no longer read (spec 3.0.0: the device's bases are its own) | sent by `services/device_link.py` on every prompt: `chat.effective_system_prompt`, the owner's personalization, the chat's knowledge bases, `prototypes.offered` |
| The plan on the link (`plan_state`) | the `plan` session update carries `_meta.lembas.plan`; `_lembas/plan` carries `plan`; `status` answers `plan` | `generation.plan` set from the update, drawn as the same panel and card an ordinary chat has; the structured `plan_card` on `_lembas/plan` |
| Rewind (`rewind`) | `_lembas/session/rewind` re-kinds the turn's rows as `/undo` does; files untouched | Edit and Regenerate on a device chat call it first; the controls say files are not undone |
| Library scope (`library`) | `mcp/index.ts` sends `_meta.lembas.scope: <sessionId>` on the instance library's `tools/call` | `api/mcp_server.py` resolves the chat by `(device token, session id)` and answers within its knowledge bases and data group |
| Library scope (`library`) | `mcp/index.ts` sends `_meta.lembas.scope: <sessionId>` on every `memory` call and on the `lembas://memory` read, for a session the client opened | `api/mcp_server.py` resolves the chat by `(device token, session id)` and answers within its knowledge bases and data group |
| Prototypes | a fence the model writes is saved under the state directory and named in the transcript (`prototype/`); `/prototype` lists them | rendered live in a sealed frame (`services/prototypes.py`, `api/prototypes.py`), for agent chats too |
| One session, both sides | `acp/hub.ts`, `acp/share.ts` | announced sessions become chats; `Chat.device_session_id` |
| Turn ids | `acp/turns.ts` | messages keep the turn id; reattach asks `_lembas/session/status` |
@@ -163,29 +170,31 @@ Shared but still differing in LLeMbas: `family/*.md`, `blocks/memory.md`,
| Deletes not yet acknowledged | `acp/pending.ts` | kept and resent until answered |
| Terminal shell marks | `acp/shellrc.ts` (bash, zsh, fish) | `services/agent/terminal.py`, `services/agent/shell_marks.py` (OSC 133 / OSC 7) |
| Device login (RFC 8628) | `lembas/client.ts`, `lembas/login.ts` | `services/devices.py`, `api/devices.py` (`/device`) |
| The account's models | `lembas/webui.ts`, `provider/refs.ts` (`<provider>/<model>`) | `api/v1/openai.py` |
| The account's models | `lembas/webui.ts`, `provider/refs.ts` (the served id; the older `<login>/…` forms still resolve) | `api/v1/openai.py` |
| Personalization and usage | `lembas/personal.ts` | `api/v1/me.py` (`/v1/me/personalization`, `/v1/usage`) |
| Library over MCP | `library: lembas` → `mcp/index.ts` `LIBRARY_SERVER` | `api/mcp_server.py` (`/mcp`) |
| Memory over MCP | `library: lembas` → `mcp/index.ts` `LIBRARY_SERVER`, its `memory` tool alone, and the resource `lembas://memory` for the prompt (`app.ts`); notes, knowledge and skills stay local (1.x: the whole library) | `api/mcp_server.py` (`/mcp`) |
| Search, fetch and speech through the instance | `search/webui.ts`, `voice/speech.ts` | `api/v1/services.py` |
## Spec 3.0.0 (draft) — not implemented on either side yet
## Spec 3.0.0 (draft) — CLI side in progress on `dev`, LLeMbas pending
`harness/VERSION` is `3.0.0-draft`. Every row below is a concept the spec now has and neither
project implements; the file named is where it is expected to go, not where it is.
`harness/VERSION` is `3.0.0-draft`, and becomes `3.0.0` when both projects implement it. The CLI
on `dev` loads it and implements the rows that apply to an agent session; LLeMbas implements none
yet. A file in a **pending** cell is where it is expected to go, not where it is.
| Concept | Spec | LLeMbas CLI | LLeMbas |
|---|---|---|---|
| Where a tool is offered (`sessions`, `requires`, `unavailable`, `confirm`) | `harness/tools/*.json`, `harness/README.md` | `harness.ts` `ToolSpecDef` | `services/harness_spec.py` |
| Where a tool is offered (`sessions`, `requires`, `unavailable`, `confirm`) | `harness/tools/*.json`, `harness/README.md` | `harness.ts` `ToolSpecDef` (read for `show`'s `unavailable`) | `services/harness_spec.py` |
| The file system as a contract: paths, kinds, levels, errors (`fs_access`) | `harness/filesystem.md` | — (an agent's disk: one level for the working directory) | the new tree's view (to be written) |
| Stacked instruction files (`instructions`) | `harness/filesystem.md` | `prompt/assemble.ts` `instructionFiles` (still the nearest file only) | to be written |
| Stacked instruction files (`instructions`) | `harness/filesystem.md` | **done**: `prompt/assemble.ts` `instructionChain` (conformance passes) | to be written |
| Chunking by tokens (`chunk_tokens`) | `harness/filesystem.md` | `library/chunks.ts` (still characters) | `services/library/chunks.py` (still characters) |
| Context hygiene: ids, stubs, cap, `recall`, diffs, compaction table (`context`) | `harness/context.md`, `loop.json` `context`, `prompts/blocks/context.md` | to be written | to be written |
| Context hygiene: ids, stubs, cap, `recall`, diffs, compaction table (`context`) | `harness/context.md`, `loop.json` `context`, `prompts/blocks/context.md` | **done**: `session/results.ts`, `tool/recall.ts`; `compaction.prune` removed (conformance passes) | to be written |
| Chat file tools `read` `write` `edit` `glob` `grep` `list` `mkdir` `mv` `rm` `search` | `harness/tools/` | (`read` … `list` as today) | to be written, over the tree |
| `show` | `harness/tools/show.json`, `acp.md` `_lembas/show` | to be written (offered when the client says `show`) | to be written (web UI viewer; relays a device's) |
| `show` | `harness/tools/show.json`, `acp.md` `_lembas/show` | **done**: `tool/show.ts`, capability `show` (offered when the client says `show`) | to be written (web UI viewer; relays a device's) |
| `python` (browser Pyodide) | `harness/tools/python.json` | — | to be written |
| Forge verbs `commit` `branch` `pr` `merge` `tag` `release` | `harness/tools/`, `permission/modes.json` `confirm` | — | to be written |
| Memory served by the instance for the device | `filesystem.md` *Memory*, `acp.md` *The HTTP API* | `memory/store.ts` (still local) | `/mcp` `memory` (to be written) |
| `instance` on `session/new`; the chat's model, no own-model answer | `acp.md` `session/new` | `acp/agent.ts` | `services/device_link.py` (the notice path to be removed) |
| Memory served by the instance for the device | `filesystem.md` *Memory*, `acp.md` *The HTTP API* | **done**: the `/mcp` `memory` tool and `lembas://memory` (`app.ts`); local `memory/store.ts` only without the scope | `/mcp` `memory` and the resource (to be written) |
| Link protocol 3; `instance` on `session/new`; the chat's model, no own-model answer | `acp.md` *Versions*, `session/new` | **done**: `acp/agent.ts`, `acp/link.ts`, `lembas/client.ts` | `services/device_link.py` (the notice path to be removed) |
| Neither `library` nor `prototypes` sent by a 3.0.0 instance | `acp.md` | **done** for `library` (no longer read) | to be written |
| `blocks/workspace.md` (a chat's view, told to the model) | `harness/prompts/` | — | to be written |
## Open items
@@ -221,8 +230,9 @@ project implements; the file named is where it is expected to go, not where it i
## Known gaps, kept deliberately
- **Dialects in LLeMbas.** OpenAI chat and Anthropic cover its endpoints; the
other three are not required for parity.
- **Dialects.** LLeMbas speaks OpenAI chat and Anthropic to its providers; the
CLI (2.0) speaks only OpenAI chat, to the server. 1.x's other three are not
required for parity.
- **Background commands, snapshots and undo** are the CLI's: they happen on the
machine where the work is. Since spec 2.0.0 a *job* is a shared concept — LLeMbas runs its own
helpers as jobs and shows a device's jobs over the link — but a command is never one of LLeMbas's.
+12 -6
@@ -2,12 +2,18 @@
LLeMbas CLI is a terminal coding agent and project manager: the `lembas`
command. TypeScript on Bun, rendered with OpenTUI and Solid, shipped as one
compiled, signed binary for Linux (x64, x64 without AVX2, arm64). It talks to any
LLM API through a native client per dialect, works in a project under four
permission modes with a git snapshot of every turn, keeps memory, skills and
knowledge bases, speaks MCP, and can sign in to a
[LLeMbas](https://github.com/LLeMbas/LLeMbas) server to use its models, library and
search — and let its web UI work the same sessions.
compiled, signed binary for Linux (x64, x64 without AVX2, arm64). It is the
agent of a [LLeMbas](https://github.com/LLeMbas/LLeMbas) server: it signs in to
one, uses that server's models through its `/v1`, its memory and search, and
lets its web UI (and LLeMbas Desktop) work the same sessions. It works in a
project under four permission modes with a git snapshot of every turn, keeps
tool results short without ever rewriting what the model has read, keeps skills
and knowledge bases on the machine, and speaks MCP.
This describes 2.0 on `dev`. **1.x on `main`** also talks to any LLM API of its
own — OpenAI-compatible, Responses, Anthropic, Gemini, Ollama — through custom
connections, and works with a 1.x server only (link protocol 2); 2.0 drops
those connections and speaks link protocol 3 to a 2.0 server alone.
**This wiki is for people changing the code.** User documentation lives on the
website:
+51 -27
@@ -6,19 +6,22 @@ first thing somebody "simplifies".
## Rules — breaking one is a redesign, not a tweak
1. **Nothing is predefined.** No connection, model, endpoint or key ships in the
binary. Every connection is one the user wrote into
`~/.config/lembas/connections.yaml`, or one a `/login` to a LLeMbas instance
wrote there. A model a server does not describe gets its context from the
config or from discovery, never from a table in the code.
2. **Connections are global only.** A project's `.agent/config.yaml` can never
define or override one — otherwise a cloned repository could point
`base_url` somewhere else and collect keys and prompts. Keys are
`{env:NAME}`, `{file:path}` or `key_cmd`, never pasted. The same holds for
every key in `config/load.ts:GLOBAL_ONLY` (`hardline_extra`,
`hardline_disable`, `voice`, `update`, `settings_tool`, `embedding`,
`remote`, `library`, `instructions`, `personality_custom`): a project that
sets one is warned and ignored.
1. **Nothing is predefined.** No server, model, endpoint or key ships in the
binary. The models are the ones the server the CLI is logged in to serves,
and what the CLI knows about one — its context window, efforts, capacity —
is that server's word, never a table in the code.
2. **The CLI is LLeMbas-server-specific.** It talks to the one LLeMbas server it
is logged in to (`lembas login <address>`) and nothing else: there are no
custom connections. `~/.config/lembas/connections.yaml` holds that login and
is global only — a project's `.agent/config.yaml` can never define or
override it, otherwise a cloned repository could point it somewhere else and
collect the key and the prompts. The same holds for every key in
`config/load.ts:GLOBAL_ONLY` (`hardline_extra`, `hardline_disable`, `voice`,
`update`, `settings_tool`, `embedding`, `remote`, `library`, `prototypes`,
`instructions`, `personality_custom`): a project that sets one is warned and
ignored. *1.x on `main` differs:* any number of connections the user wrote
into `connections.yaml`, keys as `{env:NAME}`, `{file:path}` or `key_cmd`,
and context from the config or discovery.
3. **The hardline is a floor.** `src/permission/hardline.ts` (data:
`harness/permission/hardline.json`) is refused in every mode, `auto`
included. Only the global config may add (`hardline_extra`) or disable
@@ -28,11 +31,12 @@ first thing somebody "simplifies".
the directory is trusted. Text from a third party — an MCP prompt, a skill, a
server's instructions — goes through none of the user's conveniences: `@path`
is expanded only in what the user typed.
5. **One thin native client per dialect, no AI SDK.** `openai-chat`,
`responses`, `anthropic`, `gemini`, `ollama` — one file each in
`src/provider/`, all producing the same `StreamEvent`s. The quirks of
llama.cpp, vLLM and friends are the point, and a generic SDK hides exactly
them.
5. **One thin native client, no AI SDK.** `openai-chat`
(`src/provider/openai-chat.ts`) to the server's `/v1`, producing the
`StreamEvent`s the engine reads. The quirks of llama.cpp, vLLM and friends
reach the CLI through the server, and a generic SDK hides exactly them.
*1.x on `main`* has one client per dialect: `openai-chat`, `responses`,
`anthropic`, `gemini`, `ollama`.
6. **One process, one bus.** The engine emits events and knows nothing about who
listens. The TUI, `lembas run`, the ACP agent and the tests are subscribers.
7. **No colour outside the theme.** Every colour comes from `src/tui/palette.ts`
@@ -67,9 +71,12 @@ first thing somebody "simplifies".
tool's name, description and parameters as the model sees them, and
`tests/harness.test.ts` keeps the zod schemas equal to it and `harness/acp.md`
naming every `_lembas` method and capability the code handles or sends.
- **A version field a released client compares exactly is frozen.** Discovery
says `protocol: 1` beside `protocols: [1, 2]` because older clients compared
`protocol` for equality. Add a list beside it; never raise it.
- **A version field a released client compares exactly is frozen** within a
major. Discovery said `protocol: 1` beside `protocols: [1, 2]` because older
clients compared `protocol` for equality: add a list beside it, never raise
it. Across a major the refusal is the point — link protocol 3 (server and CLI
2.0) raises it on purpose, so a 1.x peer and a 2.0 one refuse each other and
each says what to update.
- Nothing in `harness/` names a host, a path on a server or anybody's setup —
both projects are public.
@@ -184,9 +191,21 @@ when `tail` succeeds. Take the run's status on its own:
global only, so a cloned repository cannot point speech and its key elsewhere.
- **The step ceiling is a runaway backstop, not a budget.** Budgets
(`harness/loop.json`) are unset by default.
- **Gemini and Ollama are untested against real servers.** Both were written from
the API references and checked against how Hermes Agent and OpenCode handle the
same APIs; `tests/gemini-ollama.test.ts` proves the shapes, not acceptance.
- **Nothing already sent to the model is rewritten.** Tool results are kept
short when they are inserted (`session/results.ts`, harness `context.md`): an
id on each, a stub for an unchanged re-read or a repeated listing, head and
tail of a long output, a diff for an edit — and `recall` shows any of them in
full. Changing earlier context throws the server's prompt cache away from that
point, which is why `compaction.prune` (cutting old outputs in place) is gone;
compaction is the one deliberate break. An old config's `prune` is dropped with
a warning.
- **Memory is the server's** when the login's token may reach it: the `memory`
tool goes to the server's `/mcp`, and the memory in the prompt is the resource
`lembas://memory`, read once as a session starts. Notes, knowledge bases and
skills stay on this machine.
- *1.x on `main`:* **Gemini and Ollama are untested against real servers** —
written from the API references, `tests/gemini-ollama.test.ts` proves the
shapes, not acceptance. 2.0 has neither client.
## Lessons that are rules
@@ -236,7 +255,7 @@ when `tail` succeeds. Take the run's status on its own:
gets the usual retry (a proxy unloading the model mid-reply says so this way).
- **A broken tool call must not end the session.** Arguments that are not a JSON
object go back into the history as `{}`; a call cut off at the output limit
(`finish: length`, kept by every dialect) is not run, and the model is told to
(`finish: length`, kept by the client) is not run, and the model is told to
split it. Otherwise the server re-parses the broken arguments on every request.
- **The context meter leaves out thinking the dialect does not send back.**
- **Reasoning arrives as `reasoning_content`, `reasoning` or inline `<think>`
@@ -248,7 +267,12 @@ when `tail` succeeds. Take the run's status on its own:
the project) and **search code text as a regex** (`grep` offers
`literal: true`).
- **Compaction puts the prompt that started the turn back verbatim** after an
automatic summary, at most twice a turn; a summary alone loses the task.
automatic summary, at most twice a turn; a summary alone loses the task. The
summary also carries a table of the files read, so the model knows what to
`recall` or read again.
- **A stub only ever points at a result still in the conversation.** After a
compaction, an `/undo` or a rewind the earlier read is gone, so the file is
read in full again.
- **Bun's fetch does not use the OS certificate store** unless run with
`--use-system-ca`; the build passes it, and `tls.ca` covers the rest.
- **`Bun.spawn` without `env` passes the environment as it was at startup.** Pass
@@ -293,7 +317,7 @@ when `tail` succeeds. Take the run's status on its own:
— grep for the reader before shipping it, and test the stored row, not a screen
with a fallback.
- **Validate after substitution.** Files are validated before `{env:}`/`{file:}`
are filled (so one connection's missing variable cannot stop the others); a URL
are filled (so one entry's missing variable cannot stop the others); a URL
field therefore accepts a placeholder, and what it becomes is checked after,
turning off only the entry that is still wrong.
- **`String.replaceAll` reads `$&`, `$$`, `` $` `` and `$'` in the replacement.**