Table of Contents
Working notes
The project's rules, how it is built, tested and released, and the lessons that became rules. Each rule carries its reason, because a rule without one is the first thing somebody "simplifies".
Rules — breaking one is a redesign, not a tweak
- 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.
- 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.yamlholds that login and is global only — a project's.agent/config.yamlcan 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 inconfig/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.x onmaindiffers: any number of connections the user wrote intoconnections.yaml, keys as{env:NAME},{file:path}orkey_cmd, and context from the config or discovery. - The hardline is a floor.
src/permission/hardline.ts(data:harness/permission/hardline.json) is refused in every mode,autoincluded. Only the global config may add (hardline_extra) or disable (hardline_disable, by id) a rule. - Model output is untrusted. Tool results are data, not instructions. A
project's own config, commands, agents, skills and MCP servers count only once
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:
@pathis expanded only in what the user typed. - One thin native client, no AI SDK.
openai-chat(src/provider/openai-chat.ts) to the server's/v1, producing theStreamEvents 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 onmainhas one client per dialect:openai-chat,responses,anthropic,gemini,ollama. - 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. - No colour outside the theme. Every colour comes from
src/tui/palette.ts(the palettes) andtheme.ts; no hex literal anywhere else undersrc/tui/. - Lifted code keeps its header, naming the upstream file and licence.
src/tool/replace.tsis kept byte-for-byte with OpenCode (hence its@ts-nocheck) so it can be re-synced; a fix it needs lives beside it (replace-text.ts). - The binary is the product.
bun testcannot see whatbun build --compilebreaks, so every tag is preceded bybun run smoke, which drives the compiled binary — including the TUI in a real PTY at 120×40 and 80×24. - The harness design is shared with LLeMbas. Tools, permissions, prompt
texts, quirks, model metadata and the device link are one design, written as
data in
harness/and implemented natively by both projects; LLeMbas vendors a pinned copy. A change goes into the spec first, then into both. A bug found here is searched for in LLeMbas, and the other way round. The two connect (login,/v1,/mcp, the outbound link) but never depend on each other. See Harness parity.
The shared harness, in practice
harness/README.mdis the spec's own description. Bumpharness/VERSIONwith the change: patch for a text or a new conformance case, minor for a new tool, rule or field, major for a rename or a removed tool.- A fix comes with a conformance case that fails without it.
bun run harness recordfills in theexpectof a new case from this implementation;bun run harness record --allshows every case whose answer would change.tests/conformance.tsmaps each area to the function that answers it; LLeMbas runs the same files through its Python. - A test keeps the tool definitions honest: the spec is the source of every
tool's name, description and parameters as the model sees them, and
tests/harness.test.tskeeps the zod schemas equal to it andharness/acp.mdnaming every_lembasmethod and capability the code handles or sends. - A version field a released client compares exactly is frozen within a
major. Discovery said
protocol: 1besideprotocols: [1, 2]because older clients comparedprotocolfor 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.
Versions, channels and LTS
X.Y.Z, and each number means one thing:
- X — major. Big changes to the data structure, the design or core functionality. A major may break what came before; it says so and offers a way across.
- Y — feature. New, changed or removed features with a smaller blast radius.
- Z — patch. Bug and security fixes, and nothing else. Never a new, changed or removed feature: those always go up to the next Y or X.
LTS. A designated X.Y line keeps getting Z patches after a newer line
ships. Its patches are made on a branch named after the line (1.7), because
main has moved on. One exception, and only one: an LTS patch may also carry
export tooling for the upgrade to the next major — nothing else that is new.
Channels. main is stable, tagged vX.Y.Z. dev is the edge, tagged
vX.Y.Z-beta.N. A beta is installed by its tag, by hand; it is never offered
by any update feed, so a stable installation cannot step onto one by itself.
Server and CLI move together across a major: CLI 2.x speaks to server 2.x, and each refuses the other's older major with a clear message.
Build, test, release
bun install # bunfig.toml's minimumReleaseAge refuses packages under 3 days old
bun test
bunx tsc --noEmit
bun run smoke # build dist/lembas, drive it
bun run licenses --check # the licences of everything the binary contains
bun run schema # regenerate schema/*.json from the zod schemas
scripts/ci.sh # all of it, plus shellcheck and gitleaks
scripts/ci.sh is the gate, here and on CI (.github/workflows/ci.yml runs it
with CI=1, so a missing shellcheck or gitleaks fails instead of being
skipped). .gitleaksignore holds the one false positive: the made-up
credential the memory threat scanner's test must catch.
Versioning. package.json is the single source; src/version.ts is
replaced at compile time. main is the stable channel, tagged
vX.Y.Z, and pre-releases are vX.Y.Z-beta.N. The updater compares versions as
SemVer (src/update/version.ts): git's own version sort would put
v1.1.0-beta.1 above v1.1.0 and hand a stable install a pre-release.
A release, in order:
CHANGELOG.md's[Unreleased]becomes[X.Y.Z] — date;package.jsonis bumped; one commit, files added by name.scripts/ci.shpasses.- A signed annotated tag whose message is that changelog section:
git tag -s vX.Y.Z --cleanup=verbatim -F notes.md. Without--cleanup=verbatimgit deletes every line starting with#— every### Fixedheading. - Push, then from the tag:
bun install --frozen-lockfile --os=linux --cpu=arm64(OpenTUI's arm64 library), thenbun run dist -- --sign <the release key>.distbuilds the three binaries, writesSHA256SUMS— its first line# lembas X.Y.Z, signed with the rest so an old release's files cannot be served under a newer tag — signs it withssh-keygen -Y signin thelembas-releasenamespace, verifies its own signature, and says whether the key is the one built into the binary. - The Release is made from the tag with the notes passed explicitly and
every file
SHA256SUMSlists — the three binaries,install.sh,get.sh,LICENSES.txt— plusSHA256SUMS.sig.get.shand the updater refuse a release without a valid signature, so a Release missing its assets or its signature breaks every install and every update from then on. - The public GitHub repository's Release is made by
.github/workflows/release.yml: it waits for the canonical release's files, checks them exactly asget.shwould (signature, version line, every checksum), and publishes the same files and notes; a-beta.Ntag becomes a prerelease. Nothing is built there.
Never gate a commit on a pipeline. bun test | tail -3 && git commit commits
when tail succeeds. Take the run's status on its own:
bun test > log; rc=$?.
Defaults, and why
- MCP tools ask, whatever the server says about them, unless a
permission:rule allows them. A read-only hint only changes the class (plan mode then asks instead of refusing). - A local MCP server gets a minimal environment, not the shell's. A server
that needs a token names it under
env:. - A server's instructions enter the system prompt only if the threat scan finds nothing. MCP prompts are commands the user runs, not tools.
memoryis allowed without asking;skill_manageasks. Memory is capped, scanned and small; a skill is instructions later sessions will follow, so it is approved like an edit.- A long skill description is warned about, not refused — small models loop on a refusal.
- Subagents get the skills list, not memory, custom instructions or the personality: those are the main agent's business.
- Background work is one registry. A command in the background and a subagent in the
background are both jobs of the session that started them (
src/jobs/): one id space, one list, one wake. A job never belongs to the process:job_listin one session must not see another's, and a finished job's note goes to the session that owns it — stored for it when that session is not open. The lifecycle isharness/loop.jsonjobs. - A note from the harness always carries its mark (
LOOP.jobs.marks), said rather than hidden, and starts a turn throughTurns.promptwithmachine: truewhen nothing runs — neverengine.promptdirectly, which would skip thetaskevents the web UI tracks turns by. The idle wake once sent a bare user message to whatever session was open; the model took it as the person's words, and a/newin between sent it to the wrong session. - A command's
timeoutis when it stops blocking, not when it dies. At the timeout the running child is handed to the job registry with its buffer; only Esc,job_stopand the session's end kill it. A!cmdfrom the prompt passestimeline: false: it has no owner to tell. - What you say is a draft by default (
voice.submit: draft), andvoiceis 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. - Nothing already sent to the model is rewritten. Tool results are kept
short when they are inserted (
session/results.ts, harnesscontext.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 — andrecallshows any of them in full. Changing earlier context throws the server's prompt cache away from that point, which is whycompaction.prune(cutting old outputs in place) is gone; compaction is the one deliberate break. An old config'spruneis dropped with a warning. - Memory is the server's when the login's token may reach it: the
memorytool goes to the server's/mcp, and the memory in the prompt is the resourcelembas://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.tsproves the shapes, not acceptance. 2.0 has neither client.
Lessons that are rules
Permissions: judge the thing that happens
- A permission is about what the call does; when the program cannot see that,
it asks. Every check that failed in review looked at a description of the
action: the command's arguments but not its input redirection (
cat < .env); a link's name but not its target; a URL's host but not its redirects or what the name resolved to; the mode as typed, not as applied; a release's tag, not the version inside its signed list. - Paths are judged as real paths.
resolvedoes not follow symlinks; a repository shippingdocs -> ~/.sshwould get reads there as in-project.realPath(the longest existing prefix, links followed — dangling ones by hand) is used for every path; protected paths are checked on both spellings. - A written deny is matched against the plain spelling too.
sudo -u x git push,env A=1 git push,timeout 5 …,sh -c "…",/usr/bin/git pushall walked pastgit push *: denyuntil each simple command was also looked up with wrappers, quotes and program paths taken off. Only the deny is taken from the plain spelling — an allow there would loosen (sudo git statusis notgit status). - A rule right per command can be wrong per line. "Always" on
curl x | shstoredcurl *andsh, so the nextcurl anything | shran unasked. No "always" is offered for a line where one command runs others (exact_onlyinharness/permission/arity.json; conformancealways.json). - Read an allowed command's options, not its purpose.
rg --preruns a program,git diff --outputwrites anywhere,git branch -v -Ddeletes,tree -owrites. Ask rules follow the allows for those. - Edit mode's waiver needs
paths. Awrite-class call that names no file (skill_manage, a read-only MCP tool) is not a file edit. - The project's rules come after the user's, and a project cannot loosen a global rule (last match would otherwise let a cloned repository do it).
- Fail closed where a check cannot be done — including
get.sh, which never falls back to an unsigned build.
Providers and streams
- An SSE stream's last line may have no newline, and an error may be a bare
{"error":…}line inside a 200.sse.tsprocesses an unterminated last line like any other and surfaces every error shape seen in the wild. - Never re-serialise a recorded stream. Fixtures are sanitised by in-place substitution only, byte-exact otherwise — a re-serialiser once added the very newline whose absence was the bug. Streamed strings are reassembled across frames before paths are replaced, then spread back over the same frames.
- Only non-whitespace counts as output for the retry-before-output rule.
- A frame with
type: "server_error"or aninternal…code is a 500 and 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 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,reasoningor inline<think>tags; all are read. A thinking model that ends with everything in the reasoning channel and no content is asked once for the reply. - A model told "carry on" retries a refused edit indefinitely. Tell it up front that nobody can approve, and withdraw the tool on a final refusal.
- Small models drop the leading
/of absolute paths (recovered only inside the project) and search code text as a regex (grepoffersliteral: 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. The
summary also carries a table of the files read, so the model knows what to
recallor read again. - A stub only ever points at a result still in the conversation. After a
compaction, an
/undoor 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, andtls.cacovers the rest. Bun.spawnwithoutenvpasses the environment as it was at startup. Pass the live environment explicitly.- Bun decodes text dropping a UTF-8 BOM. Files are read with
ignoreBOM: trueso an edit does not strip one. Lifted code carries its runtime's assumptions: Bun is not Node.
The TUI
- Solid props are live getters. A dialog that cleared its own spec and then
called
spec.onSelectthrew inside OpenTUI's key handler, which logs and carries on — a picker that closed without choosing. Take the callback before closing; test dialogs inside the realRoot. - One terminal-size subscription, in
Root, passed through context — one per component leaked listeners until Node printed a warning across the screen. - Test the state a program leaves behind, not only what it shows. A throw
after OpenTUI turned on mouse reporting left the shell receiving every mouse
move as input.
runTuidestroys the renderer before printing any fatal error, and the smoke test reads the terminal's modes after it quits. - No model, or an unreadable config, is a screen with a retry, never an exception.
- Markdown inside a
<scrollbox>needsscrollX={false}, and is parsed off the main thread — wait for its text, not its box. - OpenTUI's
truncateelides the middle — right for a path, wrong for a sentence. - Emoji with a variation selector are one or two columns depending on the
terminal; plain emoji are two everywhere.
icons: plainexists for fonts without emoji. - Streamed text is flushed at about 30 fps; re-parsing markdown per token stutters on a small machine.
- A markdown box eats
[t1] [ ]as link syntax. The plan card draws its lines as plain coloured text (plancard.tsxplanLines), not through the markdown renderer, or the ids and marks vanish. - Offsets in the textarea are columns, not string indices (a CJK character or an emoji is
two). Never slice
plainTextbycursorOffset: take text withgetTextRange(from, to). setTextdrops every extmark. A paste placeholder is an extmark, so anything that changes part of the box inserts or replaces a selection (setSelection+insertText); what must put the whole box back usesPlaceholders.snapshot/restore(tui/paste.ts).- Where an insert went is read off the cursor after it, never before: with a selection the text goes in at the selection's start, wherever the cursor was. An extmark placed from the cursor-before landed on the wrong range and the placeholder's content was lost.
- OpenTUI's input parser hands an unfinished escape sequence on as typed keys after about 20 ms. A long terminal reply that stalls (kitty's clipboard over SSH) loses that packet and would type it into the box: hold the box's input while such a reply is read, and treat any input during it as a lost packet.
- A tool call has one title (
session/display.tscallTitle, harnessdisplay.md), made when the call starts and carried on thetool_startevent. Nothing else derives one: a second function is how the transcript, the progress line and the link came to say three things. - The default theme is Moria (since 1.3.0), the look the web UI, the desktop
app and the website share;
lembas,shireand the rest stay selectable.
Code and data
- A field nothing reads is a promise. A store method with no caller, a config key accepted by the schema and read by nothing, a status-bar slot never filled — 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 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.replaceAllreads$&,$$,$`and$'in the replacement. Escape$, or pass a function.\wis ASCII in JavaScript. Patterns ported from Python use\p{L}with theuflag, or one accented word hides an injection.- A spec text's variables go through
prompt/fill.ts, which drops a bullet whose variable is empty and throws on one that was never filled;fill()inassemble.tsis only for the CLI's own task texts. The harness test asserts no{{and no empty bullet in the assembled prompt in every mode. - The plan is the engine's, not the tool's.
plan_writeandplan_updatego throughToolContext.plan; the engine persists it in the session store's meta on every change and loads it on resume. A tool that kept its own copy would lose it on/newand on a restart, which is exactly what the todo list did. - A permission key may cover several tools:
planisplan_writeandplan_updatetogether, and a rule written for the formertodokey is read asplan(PERMISSION_ALIASES, applied to the spec's defaults too). bun run harness recordpretty-prints every conformance file it touches. On a compact file that is a whole-file diff; checkgit diff --statafter a record and restore what did not change in substance.- zod 4's
z.record(z.enum(…))is exhaustive; a partial map isz.partialRecord. - Messages stored in one millisecond tie on time; order by id as well.
- An rc wrapper replaces the shell's own startup order. The shell
integration (
src/acp/shellrc.ts) is tested by running real bash, zsh and fish against the startup files people really have. In bash,PS0can set a variable in the shell itself only through an arithmetic array subscript.
Testing conventions
bun testruns unit tests and end-to-end tests againsttests/fake-provider.ts, a scripted endpoint. Recorded real streams replay through the same path.tests/tui/drives the realRoot.- Bun's
toMatchObjectwith asymmetric matchers writes the matchers into the object — use plaintoMatch/toContainon an object that is looked at again. - The smoke test (
scripts/smoke.ts,scripts/drive.ts) starts the compiled binary on a fresh home: first run, prompt, approval, answer and quit in a PTY at both sizes, nothing wider than the terminal, the status bar on the last row, and the terminal's modes restored. - MCP and OAuth are tested against the SDK's own servers, including its example OAuth server, so the whole sign-in runs without a public service.
- Several suites may share a small machine. The per-test timeout is 20 s — passed as
bun test --timeout 20000bypackage.jsonandscripts/ci.sh, because Bun 1.4 does not readbunfig.toml's[test] timeout(found 2026-10-20: every test ran at Bun's 5 s default, and under load the ones near that edge timed out while their bodies kept running against the next test's fixtures). A test that must wait longer says so with its own timeout argument.