diff --git a/CHANGELOG.md b/CHANGELOG.md index 4adbcc298..9c8497b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,9 +43,10 @@ What is renamed: or `~/.llembas-term.lua`), data, cache and the runtime directory. - **What a pane sees:** `LLEMBAS_TERM` (the version), `LLEMBAS_TERM_PANE`, `LLEMBAS_TERM_EXECUTABLE`, `LLEMBAS_TERM_EXECUTABLE_DIR`, `LLEMBAS_TERM_STATUS_DIR`, - `LLEMBAS_TERM_UNIX_SOCKET`, `LLEMBAS_TERM_CONFIG_FILE`, `LLEMBAS_TERM_CONFIG_DIR`, - `LLEMBAS_TERM_AUTOCOMPLETE`, `LLEMBAS_TERM_CLI`. No `LLEMBAS_TTY…` is set any more, and one - inherited from an old terminal that started this one is dropped. + `LLEMBAS_TERM_UNIX_SOCKET`, `LLEMBAS_TERM_CONFIG_FILE`, `LLEMBAS_TERM_CONFIG_DIR`. No + `LLEMBAS_TTY…` is set any more, and one inherited from an old terminal that started this + one is dropped. (`LLEMBAS_TTY_AUTOCOMPLETE` and `LLEMBAS_TTY_CLI` have no new name: the + shell's own autocomplete they were for is gone, below.) - **Between the terminal and the engine:** the status directory `/llembas-term/status-/`, the status record's first line `llembas-term-status=1`, the input mark's `llembas-term-input=1`, and the user variable @@ -95,6 +96,54 @@ What is carried over, once, at the first start of the renamed terminal: screen that looks so is left out too. The README lists exactly what is recognised and what cannot be (*Secrets on a command line*). +- **What a pane says of its shell no longer decides anything that matters.** A shell + reports where it stands both in a file and by a variable of the pane, and the variable can + be printed by anything. It could put a command of its choice into your history — to be + suggested back to you as if you had run it — and replace the record your own shell keeps. + Now the file your shell writes itself, while that shell runs, is the authority: the + variable never replaces it, and only it puts a command into the history, lets LLeMbas know + your prompt is empty, or says how a command ended. Commands run on another machine over + `ssh` are therefore no longer kept in the terminal's history. + +- **Suggestions and the AI's autocomplete only at your shell's prompt.** What you type into + a program a command started — a database client, a remote session — was coloured, offered + suggestions and, with AI autocomplete on, sent for a completion. Now nothing is offered + while your shell says a command runs, and the AI is asked only while the program in front + of the pane is a shell. + +- **Taking a suggestion takes exactly what you saw.** A suggestion too long for the row is + taken up to where it was cut, characters that are drawn as nothing (zero-width, the ones + that turn text around) are never in a suggestion or the history, and no suggestion is + taken while a key you pressed is not on the screen yet. + +- **The shell's own autocomplete is gone** (`autocomplete = 'shell'`). It could not know + that a pane was made private or that AI was switched off, and went on sending what you + typed. The terminal draws the AI's suggestion itself; `'shell'` now turns nothing on, and + the log says so. + +- **An answer goes to what you were shown.** The keys that allow or deny answered whatever + LLeMbas asked at the moment the key arrived. Now a request that changed a moment before + is not answered (you are told to read it again), and with a LLeMbas CLI that numbers what + it asks the number goes with the answer, so that it cannot be taken for another. A + request too long to show says that the rest is in the display. + +- **With AI off, the LLeMbas CLI is not started.** It still was, to read your settings and + to keep a choice. Now the one thing that starts it with AI off is the AI switch itself; + every other choice made then holds until the terminal closes. The README says exactly what + still works. + +- **A terminal started from a pane of another keeps its own status records.** It used to + take over the first terminal's directory, so that each could read the other's shells and + input marks. Each terminal now always uses its own. + +- **The set-up program refuses to run as root, and refuses a signed release of another + version.** A release whose signed `SHA256SUMS` names its product and version must name the + one that was asked for, so that an older signed release cannot be passed off as the newest. + +- **The packages are built with the least the build needs.** Only the step that publishes a + release may write to the repository, and only for a tag, after the build passed; every + step of the build is pinned to the exact code it was checked with. + ### Added - **`Ctrl+Tab` on the ask line switches the mode**, manual ↔ auto. What stands before your @@ -119,6 +168,40 @@ What is carried over, once, at the first start of the renamed terminal: `kitty_keyboard = false` leaves it off). A program that does not ask gets its keys exactly as before. +### Fixed + +- **Asking from a full-screen program lost the question.** In an editor or a pager, with + nothing of the screen asked about, the terminal handed LLeMbas an empty context, which it + refuses: the display did not start and the question was dropped. Now the question goes + alone. And when a display cannot start or ends before it took a question, the ask line + opens again with your question on it and what LLeMbas said. +- **The ask line opens at once.** It waited for the LLeMbas CLI to say what model and + settings apply, and what you typed meanwhile went to your shell. Now it opens first and + the model in front of the question follows. +- **A question LLeMbas asks you is answered on the ask line** — a number, `n` to skip, or + your words. The notice named the allow and deny keys, which do not answer a question. +- **Each pane follows its own directory's settings.** With two windows in two directories + the terminal switched back and forth between their settings every second and asked the AI + again each time. +- **A question asked while the display starts keeps its context**, and context files that + were never handed over are removed, at once where the terminal knows of them, else within + ten minutes — not only when the next question is asked. +- **After `lembas update` the terminal sees the new CLI** within a minute, and at once when + it had found the old one lacking — no restart needed. +- **A shell reached with `ssh` inside a pane is named as that machine's** in what goes with + a question (with a LLeMbas CLI that reads it), and the display opens in a directory of + this machine. The context also says how each command ended, where the shell said so. +- **Typing is not slowed by slow disks.** Whether a command exists is looked up in a listing + of each `PATH` directory, read once a minute, not by a look at the disk for every + character; nothing on a network or automounted file system is looked at; the history and + the input mark are written by a thread of their own. +- **A notice of a display that was closed is taken away at once.** +- Texts: the chat model is called that everywhere (*LLeMbas: choose chat model*); "the + LLeMbas CLI's own choice" where it said "the engine's own choice"; a CLI too old to say + what it can do is told so with the key that still works (it named a version that was not + enough); the message for a part only the window has says that; `--help` names the + terminal's own configuration file. + ### Changed - **The terminal needs the engine's terminal contract 4.** A CLI from before it is not used diff --git a/README.md b/README.md index 875c35134..7131a45f7 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,10 @@ prompt, the answer shows beside your shell, and what the agent does in a shell i your pane, at your prompt, where you see it. It is not a terminal that starts another program in a split. -With AI switched off, or until you press one of the keys below, it is an ordinary terminal: -nothing is started, nothing of a pane is read and nothing leaves the machine. +Until you press one of the keys below it is an ordinary terminal: nothing of LLeMbas is +started, nothing of a pane is read and nothing leaves the machine. With AI switched off that +stays so — the LLeMbas CLI is not started at all, but to keep the switch itself when you press +it (*AI on and off*, below, says exactly what still works). The engine is the [LLeMbas CLI](https://github.com/LLeMbas/LLeMbas-CLI) (`lembas`), installed beside the terminal as its own thing, and the editor is @@ -45,19 +47,30 @@ older one the terminal says so in words, with how to update. Version in `VERSION placed at your prompt and not entered: `Enter` runs it, you may change it first, and `Ctrl+C` (or clearing the line) dismisses it — a dimmed hint beside it says so, and no approval card stands in the way. In *auto* mode the commands the CLI's rules allow are - typed and entered without asking. Whatever else LLeMbas asks — a question, a permission for - a tool that is not the shell — stands at your cursor's row with the keys that answer it - (`Ctrl+Shift+Y` allows, `Ctrl+Shift+J` denies, from your own pane), until it is answered. + typed and entered without asking. A permission for a tool that is not the shell stands at + your cursor's row with the keys that answer it (`Ctrl+Shift+Y` allows, `Ctrl+Shift+J` + denies, from your own pane), until it is answered; the answer is for what you read there + (a request that changed a moment before is not answered, and the terminal says so). A + question LLeMbas asks you stands there too, and is answered on the ask line: a number of + its options, `n` to skip it, or your own words. There are no file-edit tools here: this is for terminal work, and the CLI or the IDE are a key away. - **The CLI itself, whole.** `Ctrl+Shift+S` opens `lembas` in a new tab, in the pane's directory, exactly as if you had typed it. - **AI on and off.** `Ctrl+Shift+I` switches all of it at any moment; the option `ai` says - how the terminal starts. Off: every key below but the switch does nothing (and says so - once), no process is started, nothing of a pane is read and nothing leaves the machine. + how the terminal starts. Off: nothing of a pane is read, nothing leaves the machine, and the + LLeMbas CLI is not started — not to ask, not to complete, not to read or keep a setting. The + one exception is the switch itself: pressing it has the CLI keep that choice (and, switching + on, read the settings). What still works with AI off is the terminal's own: suggestions from + your own history, the colours, private panes, clearing the history, the display's width and + the drawing switches (a choice made then holds until the terminal closes), and the two + entries that open another program in a tab when you ask — *set up* and *open LLeMbas IDE*. + Every other LLeMbas key says once that AI is off, then nothing. - **A shell line with comforts, in any shell.** Drawn by the terminal itself, so they work in bash as in zsh, and inside `ssh` where the other machine's shell has the shell - integration: + integration. They are drawn only while the shell is at its prompt (by its status record): + what you type into a program a command started — a database client, a password prompt — is + never offered anything: - *suggestions*: the rest of the line, dimmed after the cursor, from the commands this terminal has seen you run. `Right` or `End` takes it, `Alt+Right` one word, anything else just goes on typing; @@ -66,7 +79,9 @@ older one the terminal says so in words, with how to update. Version in `VERSION - *AI autocomplete*, off unless you turn it on (*LLeMbas: AI autocomplete on/off* in the command palette; choose its model with *LLeMbas: choose autocomplete model*): when your history has nothing for the line, LLeMbas is asked after a pause and its answer shows in - the same place, in italics. *LLeMbas: autocomplete status* says in words whether it is + the same place, in italics. What a key takes is exactly what is drawn: a suggestion too + long for the row is taken up to where it was cut, and nothing invisible (zero-width or + direction-changing characters) is ever in one. *LLeMbas: autocomplete status* says in words whether it is on, which engine and model it uses, and what the last attempts gave — a suggestion, nothing, a timeout, or the engine's own error sentence. - **Your choices are remembered** — for this machine, and for a working directory where you @@ -84,7 +99,7 @@ older one the terminal says so in words, with how to update. Version in `VERSION | `Ctrl+Shift+G` | LLeMbas: stop the turn | | | | LLeMbas: new conversation | A tab has one conversation, which goes on until you start a new one. | | `Ctrl+Shift+D` | LLeMbas: show/hide the display | Hidden, it runs on behind your pane. | -| `Ctrl+Shift+M` | LLeMbas: choose model — here / — everywhere | The terminal's own chat model, from your server's list. Also from the ask line. | +| `Ctrl+Shift+M` | LLeMbas: choose chat model — here / — everywhere | The terminal's own chat model, from your server's list. Also from the ask line. | | `Ctrl+Alt+M` | LLeMbas: choose autocomplete model — here / — everywhere | The terminal's own autocomplete model. | | `Ctrl+Tab` *on the ask line* | LLeMbas: choose mode — here / — everywhere | *manual* or *auto*. The key switches to the other one; anywhere but the ask line `Ctrl+Tab` is the next tab, as always. | | `Ctrl+Shift+Alt+P` | | The terminal's command palette, like `Ctrl+Shift+P` — the one of the two that is never handed to LLeMbas IDE (below). | @@ -132,7 +147,9 @@ older one the terminal says so in words, with how to update. Version in `VERSION nothing with it: its commands are `llembas-term`, `llembas-term-gui` and `llembas-term-mux-server`, its configuration is `~/.config/llembas-term/llembas-term.lua` (or `~/.llembas-term.lua`), and it - neither reads WezTerm's files nor talks to a running WezTerm. + neither reads WezTerm's files nor talks to a running WezTerm. One thing it keeps on + purpose: a pane's `TERM_PROGRAM` is `WezTerm`, because programs decide by it which of the + terminal's features they may use, and this terminal has all of WezTerm's. ## Set-up: the CLI and LLeMbas IDE @@ -145,8 +162,10 @@ your `PATH` and then in `~/.local/bin`. When one is missing, the palette entry **LLeMbas: set up (CLI and IDE)** — or `llembas-term-setup` in a shell — says which, and asks before installing each. It runs that product's own installer from that product's own release, after checking it: the release's `SHA256SUMS` must -be signed with the LLeMbas release key and the installer must match it. Nothing runs as root -and nothing already installed is touched. A beta terminal installs the newest betas, a stable +be signed with the LLeMbas release key, must name that release where it names one (a first +line `# `: an older signed release served under a newer tag is refused), +and the installer must match it. It refuses to run as root — everything goes into your own +home — and nothing already installed is touched. A beta terminal installs the newest betas, a stable one the newest stable releases (`--channel stable|beta` to say otherwise; `--dry-run` to see what it would do; `--no-cli`, `--no-ide`). @@ -157,17 +176,28 @@ what it would do; `--no-cli`, `--no-ide`). **When you send a question** (the two *ask* entries), LLeMbas is given, with it: - the last 5 commands of that pane with the end of each one's output (200 - lines or 16 KiB at most), and the pane's directory and shell. This needs the - shell integration (below), which marks where a command and its output begin; + lines or 16 KiB at most), how each ended where the shell said so, and the pane's + directory and shell. This needs the shell integration (below), which marks where a + command and its output begin; - without shell integration: the last screenful instead; -- from a full-screen program (an editor, a pager): only the directory, unless - you chose *ask about this screen*. +- from a full-screen program (an editor, a pager): nothing but the question, unless + you chose *ask about this screen*; +- from a shell reached with `ssh` inside the pane: the same, named as that machine's (its + host, with a LLeMbas CLI that reads it), and the display opens in a directory of this + machine. -Never: a pane you marked private, a pane that is asking for a password, a pane -that runs on another machine, the scrollback as a whole, or anything at all -while you have not asked. The context is written to a file only you can read, -in the terminal's runtime directory; LLeMbas deletes it after reading it and -the terminal removes any that are left after ten minutes. +Never: a pane you marked private, a pane that is asking for a password (as far as the +terminal can tell: a program that turns echo off and reads a line, as `sudo` and `ssh` do — +not a password a program on another machine asks for), a pane of another of the terminal's +domains, the scrollback as a whole, or anything at all while you have not asked. The context +is written to a file only you can read, in the terminal's runtime directory; LLeMbas deletes +it after reading it. One that was never handed over (a question that was not sent, a display +that ended first) is removed at once where the terminal knows of it, and otherwise once it +is ten minutes old: the terminal looks at its first status update and then once a minute +while it has written any. + +A question is never lost without a word: when the display could not start or ended before it +took the question, the ask line opens again with the question on it and what the display said. **What the terminal trusts: only what it started.** The display of a tab is the pane the terminal itself opened and started `lembas terminal` in, remembered by that pane's id. A @@ -196,8 +226,10 @@ input line — never what. **AI autocomplete**, when you turned it on: the line you are typing is sent to `lembas complete` after a pause, when your own history has no suggestion for it — never an empty line, a line of fewer than three characters, a line that starts with a space, a -private pane, a shell on another machine, **or a line that looks as if it holds a secret** -(*Secrets on a command line*, below). What comes back is shown as text; nothing runs +private pane, a line typed while the shell is not at its prompt (a command runs), a line +typed into anything but a shell (`ssh`, a database client), a shell whose directory is on +another machine, **or a line that looks as if it holds a secret** (*Secrets on a command +line*, below). What comes back is shown as text; nothing runs until you take it and press Enter. The engine is given eight seconds for an answer (`autocomplete_timeout_ms`), and twenty for the first one after you switch autocomplete on or change its model: a model on your own machine may have to be loaded. The last few attempts — the start of the line, how long it took, what came back — are @@ -262,9 +294,9 @@ width. Each is in the command palette twice: A directory's own value wins over the machine's there. A key (`Ctrl+Shift+I`, `Ctrl+Shift+M`, `Ctrl+Alt+M`, `Ctrl+Tab` on the ask line) keeps the choice *here* when this directory already has settings of its own, and *everywhere* otherwise; the word shown at your cursor says which. The settings -of the directory of the pane you are in apply: change directory, or pane, and the +of each pane's own directory apply in that pane: change directory, or pane, and the suggestions, the colours, the autocomplete, the model and mode on the ask line and what the -next display starts with follow. +next display starts with follow — two windows in two directories each keep their own. **LLeMbas: settings** lists what applies now and where each value comes from — *here* (with the directory), *everywhere*, or the configuration — and has a line that forgets this @@ -274,12 +306,16 @@ They are kept by the LLeMbas CLI in its own directory on this machine (its READM path and the commands: `lembas terminal settings`), not in the working directory, and are sent nowhere. Nothing is read until your first LLeMbas key or palette entry; once you have chosen something through the terminal, they are read at the first prompt, so that they hold -from the start. The options in your configuration file are the starting values only: a value +from the start. Reading them starts the CLI, so with AI off they are not read (what you chose +for the whole machine, as last read, still applies) and a choice you make then holds until +the terminal closes; switching AI on reads them again. The options in your configuration file are the starting values only: a value you set through the terminal wins over the file, until you remove it (*LLeMbas: settings*, or `lembas terminal settings set … =default`). With a LLeMbas CLI that is too old for this terminal a choice holds until the terminal -closes, and the terminal says once that remembering it needs a newer CLI. +closes, and the terminal says once that remembering it needs a newer CLI. What the CLI can do +is asked again after a minute, and at once when it lacked something you just asked for, so +after `lembas update` the terminal need not be restarted. **Kept on this machine, sent nowhere:** @@ -294,7 +330,12 @@ closes, and the terminal says once that remembering it needs a newer CLI. - *The pane's status record*, which the shell integration writes at every prompt: whether the shell is at its prompt or running a command, the last exit status, the time, the directory — not what the command was. It is how LLeMbas knows that a command it typed has - ended. In the terminal's runtime directory, readable by you alone. + ended. In the terminal's runtime directory, readable by you alone, in a directory of this + run of the terminal (a terminal started from a pane of another keeps its own). The shell + also says it by a user variable, which reaches the terminal from another machine too; but + anything printed to a pane can say the same, so it decides nothing that matters: a command + enters the history, and the *input mark* is written, only by the record the pane's own + shell on this machine wrote itself. The session bar reads what LLeMbas itself tells the terminal about its session. It does not read the pane. The colours and the suggestion are drawn when a pane is painted: @@ -349,11 +390,12 @@ require('llembas').apply(config, { blocks = 5, -- commands passed on (at most 20) output_lines = 200, -- of each command's output, from its end output_bytes = 16384, + screen_lines = 200, -- of the screen, when it is passed on alt_screen = false, -- true: also the screen of a full-screen program }, suggestions = true, -- the rest of the line from your own command history highlight = true, -- the command line in colours - autocomplete = false, -- AI: true, drawn by the terminal; 'shell', by the shell integration + autocomplete = false, -- AI: the rest of the line from LLeMbas, drawn by the terminal autocomplete_timeout_ms = 8000, -- how long LLeMbas is given for the rest of a line history = { enabled = true, max = 5000 }, colors = { -- a number of your colour scheme's palette, '#rrggbb', or false @@ -396,10 +438,13 @@ is how the terminal knows which cells are your command line. there and source the first from that shell's rc file with `LLEMBAS_TERM` set (for instance `[ -n "$SSH_CONNECTION" ] && LLEMBAS_TERM=remote . ~/.llembas-term.sh`). Suggestions and colours then work there too, drawn by your terminal; whether a command or a path exists is -not marked, since that is the other machine's to know. +not marked, since that is the other machine's to know. The commands you run there are not +kept in the terminal's history (what that shell says of them is only what it says), and the +AI's autocomplete is not asked about them. -The older autocomplete drawn by the shell itself (zsh shows it, bash completes on -`Ctrl+X Ctrl+A`) is still there as `autocomplete = 'shell'`. +The autocomplete the shell integration used to draw itself (`autocomplete = 'shell'`) is gone: +it could not know that a pane was made private or that AI was switched off. The terminal +draws the AI's suggestion itself; `'shell'` now turns nothing on, and says so in the log. ## Coming from LLeMbas TTY diff --git a/llembas/README.md b/llembas/README.md index 59f0a04bd..a4435de8b 100644 --- a/llembas/README.md +++ b/llembas/README.md @@ -3,7 +3,8 @@ Everything LLeMbas TERM adds to WezTerm lives in this directory, in `scripts/` and in one workflow file. WezTerm's own files are changed as little as possible, and each changed block carries a `LLeMbas TERM:` comment, so that -merging upstream stays cheap (`git grep -n 'LLeMbas TERM:'` lists them all). +merging upstream stays cheap (`git grep -n 'LLeMbas TERM:'` lists them all; a changed line of +help text, which a comment inside it would show, has the comment on the line above). ``` llembas/ @@ -38,8 +39,12 @@ scripts/ | The drawing | `wezterm-gui/src/llembas/` (Rust) | fetches cells, places the result, takes keys. As thin as it can be, because only a person at a screen can check it. | The layer asks for the drawing through `wezterm.llembas` (`wezterm-gui/src/llembas/lua.rs`): -`ask_line(window, pane, { prefix, event })`, `ask_active(pane_id)`, -`ask_prefix(window, pane, prefix)`, `configure { … }`, `notice(pane, text)`, +`ask_line(window, pane, { prefix, event, text })`, `ask_active(pane_id)`, +`ask_prefix(window, pane, prefix)`, `configure { … }` (for every pane), +`configure_pane(pane_id, { … })` (what is on in one pane, by its own directory's settings), +`notice(pane, text)`, `hint(pane_id, text, gentle, source)`, +`status(pane_id, id, seq, state, dir)`, `complete_status()`, `data_dir()`, `real_path(path)`, +`local_dir(pane)` (the one answer to "is this pane's shell on this machine, and where"), `set_private(pane_id, on)`, `command_ended(pane, exit, cwd)`, `clear_history()`. The layer looks for each before calling it, so it also runs where they are missing (the mux server, the tests). @@ -88,7 +93,7 @@ A new Lua module must be added to `MODULES` in `config/src/llembas.rs`. ## The contract with the LLeMbas CLI The engine is the LLeMbas CLI; its specification (`harness/acp.md` in the CLI's repository, -*A terminal as the client*) is the authority. The terminal needs **contract 4**, the one in +*A terminal as the client*, contracts 1 to 4) is the authority. The terminal needs **contract 4**, the one in which the engine knows the terminal by the name LLeMbas TERM (`core.CONTRACT`): with an engine of an older contract nothing of it is used, and the person is told in words to run `lembas update` (`messages.contract_old`). What the terminal does of it, and @@ -96,56 +101,75 @@ where each point is in the code (one function or constant each, in `lua/llembas/ | The terminal | Where | The CLI | |---|---|---| -| asks what the CLI can do: `lembas --version --json`; needs `terminal_contract` ≥ 4 and the part it is about to use (`terminal_surface`, `terminal_models`) | `cli_info`, `cli_has`, `CAP`, `CONTRACT` | prints one JSON object | +| asks what the CLI can do: `lembas --version --json`; needs `terminal_contract` ≥ 4 and the part it is about to use (`terminal_surface`, `terminal_models`, `terminal_settings`, `terminal_placed`, `terminal_context_2`); asked again after a minute, and at once when what was needed was missing | `cli_info`, `cli_has`, `CAP`, `CONTRACT` | prints one JSON object | | starts the display: `lembas terminal --window --pane [--terminal-context ] [--mode manual\|auto] [--new]`, to the right of the pane; the id is this run of the terminal and the tab | `display_args`, `window_id`, `held` | one conversation per id | | writes a question, in one write: `/terminal-context ` + Enter when there is a context, then the question as a bracketed paste + Enter; at once when the display reports a state, else when it first says `idle` | `ask_bytes` | a new turn, or words added to the running one | -| writes a line for the display, each one write: `/approve`, `/always`, `/deny`, `/stop`, `/new`, `/model `, `/mode ` | `DISPLAY_KEYS`, `display_line` | | -| reads user variables `lembas_session`, `_title`, `_model`, `_mode`, `_effort`, `_state` (`idle`, `waiting`, `thinking`, `tools`, `writing`, `asking`), `_context`, `_tokens`, `_spend`, and of the display `lembas_surface` (`display`) and `lembas_ask` (` `) | `session_from_vars`, `parse_ask` | sets them with OSC 1337 `SetUserVar` | +| writes a line for the display, each one write: `/approve`, `/always`, `/deny` — with the number of what is asked when `lembas_ask` carries one (`/approve 7`), else only for an ask that has stood unchanged for two seconds — `/answer ` (a question card: a number or `n` typed on the ask line; words are pasted as a question is, which the display takes as the answer), `/stop`, `/new`, `/model `, `/mode ` | `DISPLAY_KEYS`, `answer_line`, `question_answer`, `display_line` | | +| reads user variables `lembas_session`, `_title`, `_model`, `_mode`, `_effort`, `_state` (`idle`, `waiting`, `thinking`, `tools`, `writing`, `asking`), `_context`, `_tokens`, `_spend`, and of the display `lembas_surface` (`display`) and `lembas_ask` (`[#] `, the id a number of up to 9 digits; a text that ends in `…` was cut by the engine) — only of the display the layer started, or of a pane whose program in front is the CLI itself; of any other pane they are not looked at | `session_from_vars`, `parse_ask` | sets them with OSC 1337 `SetUserVar` | | lists and sets the terminal's two models: `lembas terminal models --json`, `lembas terminal models set --main\|--autocomplete ` | `models_args`, `models_set_args`, `terminal_models` | keeps them | | exports `LLEMBAS_TERM` (version), `LLEMBAS_TERM_PANE`, `LLEMBAS_TERM_EXECUTABLE`, `LLEMBAS_TERM_STATUS_DIR` to every pane | Rust (identity), `apply` | types into a pane with `$LLEMBAS_TERM_EXECUTABLE cli send-text --pane-id N --no-paste`, reads it with `cli get-text` | -| the shell integration writes the pane's status record at every prompt and when a command starts: `$LLEMBAS_TERM_STATUS_DIR/pane-.status` and the user variable `llembas_term_status`; the layer writes the file from the variable for a shell that could not (`via=uservar`) | `shell/llembas-term.sh`, `parse_status`, `status_text`, `status_dir`, `status_dir_of` | waits for it after typing a command | -| asks for the rest of a line: the line on standard input (then closed) of `lembas complete --shell --cwd --timeout-ms [--model ] [--debug]`, with `LLEMBAS_TERM` set; `` is 8000 (the option), and 20000 at least for the first request after a change; `--debug` only once the CLI said it has contract 3 or later; `--cwd` is always given (the engine requires it): the pane's directory, else the home directory | `llembas_line::complete` (`args`, `run`, `decide`), `wezterm-gui/src/llembas/complete.rs` | prints only the rest; nothing means no suggestion; what it writes to standard error is the sentence shown by *autocomplete status* | +| the shell integration writes the pane's status record at every prompt and when a command starts: `$LLEMBAS_TERM_STATUS_DIR/pane-.status` (with `pid=`) and the user variable `llembas_term_status`; a file a local shell wrote and still keeps is the authority, never replaced by a variable (`status_authority`); the layer writes the file from the variable only where no such file is (`via=uservar`, a shell on another machine) | `shell/llembas-term.sh`, `parse_status`, `status_authority`, `status_text`, `status_dir`, `status_dir_of` | waits for it after typing a command | +| asks for the rest of a line: the line on standard input (then closed) of `lembas complete --shell --cwd --timeout-ms [--model ] [--debug]`, with `LLEMBAS_TERM` set; `` is 8000 (the option), and 20000 at least for the first request after a change; `--debug` only once the CLI said it has contract 3 or later; `--cwd` is given (contract 3 lets it be left out; the terminal always knows one): the pane's directory, else the home directory | `llembas_line::complete` (`args`, `run`, `decide`), `wezterm-gui/src/llembas/complete.rs` | prints only the rest; nothing means no suggestion; what it writes to standard error is the sentence shown by *autocomplete status* | | reads and writes what the person chose (contract 3, `terminal_settings`): `lembas terminal settings --cwd --json` → `{ effective = { = }, from = { = "default" \| "global" \| "" }, directory = { path } \| null }`; `lembas terminal settings set (--global \| --cwd ) --json =` (`default` removes it); `lembas terminal settings forget --cwd --json` (the entry's own path, which may be a directory above the pane's: the nearest entry applies). Keys: `ai`, `autocomplete`, `suggestions`, `highlight` (`true`/`false`), `mode`, `main_model`, `autocomplete_model`, `display_width` (a part of the pane, `0.2` to `0.6`, written `0.40`; percent is read too) | `SETTINGS`, `settings_args`, `settings_set_args`, `settings_forget_args`, `settings_entry`, `setting_value`, `setting_text` | keeps them, for the machine and by directory | -| writes the input mark `pane-.input` beside the status record (mode 0600, written whole): `llembas-term-input=1`, `id=`, `seq=` (the status record's), `typed=0\|1` | `llembas_line::mark`, `state::mark_input`, `decorate::compute`; the layer hands the record over with `wezterm.llembas.status` | places a command only at an empty prompt; the mark counts while its id and seq are the record's and the record is at `prompt` | +| writes the input mark `pane-.input` beside the status record (mode 0600, written whole): `llembas-term-input=1`, `id=`, `seq=` (the status record's), `typed=0\|1` — only for a record the pane's own shell keeps (never for one that came by variable alone) | `llembas_line::mark`, `state::mark_input`, `decorate::compute`; the layer hands the record over with `wezterm.llembas.status` | places a command only at an empty prompt; the mark counts while its id and seq are the record's and the record is at `prompt` | | shows a hint while a command placed at the prompt waits for the person (contract 3, `terminal_placed`): `lembas_ask` = `placed ` | `PLACED_KIND`, `parse_ask`, `messages.placed` | places the command without Enter and watches the status record: a new prompt with `ran=1` is "ran", one without is "dismissed" | The status directory is `/llembas-term/status-`: -two terminals number their panes alike, so each keeps its records apart. Directories of -terminals that are gone are removed when a display starts. +two terminals number their panes alike, so each keeps its records apart. A +`LLEMBAS_TERM_STATUS_DIR` in the terminal's own environment (a terminal started from a pane of +another) or in the configuration is not used: every pane is given this terminal's own. +Directories of terminals that are gone are removed when a display starts. The context file is JSON, mode 0600, in the terminal's runtime directory, named `context--.json`: ```json -{ "version": 1, "pane": 3, "cwd": "/home/me/project", "shell": "zsh", - "blocks": [ { "command": "make test", "exit": null, "output": "…tail…" } ], +{ "version": 2, "pane": 3, "cwd": "/home/me/project", "shell": "zsh", "host": "buildhost", + "blocks": [ { "seq": 17, "command": "make test", "exit": 2, "output": "…tail…" } ], "screen": "…only when the shell marks no commands…" } ``` -It is still version 1 (which the CLI reads): `exit` is `null`, and the blocks carry no -`seq`. Files older than ten minutes are removed the next time one is written. +Version 2 (contract 2's *context that continues*) goes to an engine that says it reads it +(`terminal_context_2`); any other gets version 1, without `host` and `seq`. `host` is there +when the pane's shell reported a directory of another machine (`ssh` inside the pane). A +block's `seq` is that of the status record when the command started, and its `exit` what the +next prompt's record said — both from the record the pane's own shell keeps (`note_block`, +`block_known`); without them `seq` is left out and `exit` is `null`. A context with no block +and no screen is not written at all (the engine refuses an empty one): the question goes +alone. Files that were never handed over are removed at once where the layer knows of them +(a question replaced while the display starts, a display that ended first), and otherwise +once they are ten minutes old: looked for at the first status update and then once a minute +while any was written. ### Settings: when the engine is asked -`init.lua` (*What the person chose, remembered*). `M.value(key)` is the one place a setting -is read: the store's value for the directory that applies (`directory`, then `global`), else -what was chosen in this run (`session`: a CLI without the store, or a write it refused), -else the options (`config`). A store value whose source is `default` is not used: the +`init.lua` (*What the person chose, remembered*). `M.value(key, pane)` is the one place a +setting is read: the store's value for that pane's directory (`directory`, then `global`), +else what was chosen in this run (`session`: AI off, a CLI without the store, or a write it +refused), else, for a directory not read yet, the machine's values as last seen +(`global`), else the options (`config`). Without a pane it is the directory followed last. A store value whose source is `default` is not used: the options are the defaults. - Nothing is read at start-up. `settings_awake`: from the first key or palette entry of LLeMbas in this run — or from the first prompt, when the empty file `settings-chosen` in the terminal's data directory says the person chose something through the terminal before (written at the first successful `set`). -- `follow(pane)` makes the settings of the active pane's directory the ones that apply: at a - new prompt of the active pane (the status record), at `update-status` (the active pane - changed) and at every key of LLeMbas. What the store said of a directory is kept for a - minute (`wezterm.GLOBAL`, at most 64 directories); the whole of it is dropped after one of - our own writes. A directory whose shell reports another host is not asked about. +- `follow(pane)` reads the settings of the pane's directory and tells the terminal's own + part what is on in that pane (`configure_pane`): at a new prompt of the active pane (the + status record), at `update-status` (each window's active pane) and at every key of + LLeMbas — after the ask line has opened, and not before an answer is sent. What the store + said of a directory is kept for a minute (`wezterm.GLOBAL`, at most 64 directories); the + whole of it is dropped after one of our own writes. A directory whose shell reports + another host is not asked about. +- **With AI off in a pane nothing is read for it** (reading starts the engine), and a choice + is kept for the session (`messages.kept_session`), except the AI switch itself, which the + store keeps and after which the settings are read (`follow(pane, true, true)`). - Every call of the engine is `wezterm.run_child_process` inside an event handler, which is asynchronous: the window's thread is never held. -- A change of the applying settings goes to the terminal's own part (`configure`), to the - ask line's prefix and to the next display's arguments (`-m`, `--mode`, the split's size). +- A change of the applying settings goes to the terminal's own part (`configure_pane` for + the pane; `configure` for every pane only when something that is the same everywhere + changed), to the ask line's prefix and to the next display's arguments (`-m`, `--mode`, + the split's size). A display that runs is not changed by a change of directory. ### A word that stands @@ -164,11 +188,13 @@ typed (it runs before the line is edited); the terminal can, because the shell i marks the input cells. So the terminal writes the *input mark* of the engine's specification. - The layer hands each status record to the terminal's own part (`wezterm.llembas.status`: - pane, id, seq, state, the status directory) — with AI on, for a local pane; otherwise it - says the pane is no longer followed, and the mark is removed. + pane, id, seq, state, and the status directory — only with AI on, for a local pane, and + for the record the pane's own shell keeps; without the directory no mark is written and + the record says only whether the shell is at its prompt). - When a pane whose shell is at a prompt is painted (`decorate::compute`), `typed` is: an - input cell that shows something on the cursor's row; else an input zone that nothing - follows and that shows something (a line carried on over rows). The mark is written when + input cell that shows something on the cursor's row; else one on the rows above that the + cursor's row carries on from (a line wrapped over rows) — the rows already fetched, never + the whole scrollback. The mark is written by the terminal's own writer thread, in order. The mark is written when the record or the answer changed (`state::mark_input`), beside the record, whole. - What it cannot be: ahead of the screen. It is as old as the last painting of the pane — a frame behind the typing, and not kept up for a pane that is not shown. A mark of an @@ -190,12 +216,19 @@ pane's content, the cursor and what is on stay the same. Off for a pane: while a full-screen program has it, without the shell integration, when the input line is longer than three rows, under an overlay (search, copy mode, the ask line), and when the options are off. The suggestion is drawn only in the pane that has the -keyboard, over blank cells only. Whether a command or a path exists is looked up only for a -local pane whose shell reports this machine as its host. +keyboard, over blank cells only, and only while the pane's status record says the shell is +at its prompt (or there is none). A key takes exactly what was drawn (`suggest::drawn_part`: +a cut suggestion up to the cut), and none is taken while a key sent to the pane is not on +its screen yet (`state::key_sent`, from the key hook). Whether a command or a path exists is +looked up only for a local pane whose shell reports this machine as its host, never on a +network or automounted file system (`/proc/self/mounts`), and a command by the listings of +the `PATH` directories, read at most once a minute — never a `stat` per word typed. The +command history is appended to by the same writer thread as the marks. The AI's suggestion: `llembas_line::complete::decide` says whether the line is asked about -and, when not, why (`Skip`); `Tracker` allows one request at a time and remembers the answer -for a line; `run` starts the engine (standard library only, so `cargo test -p llembas-line` +and, when not, why (`Skip`: also `NotAtPrompt`, and `NotAShell` when the program in front +is no shell); `Tracker` allows one request at a time and remembers the answer +for a line; `run_said` starts the engine (standard library only, so `cargo test -p llembas-line` runs it against a stand-in script); `Log` keeps the last eight attempts in memory for `wezterm.llembas.complete_status()`. The pane's directory is decoded from the path of the address its shell reported (`dir_of_url_path`): the URL library's own conversion to a file @@ -270,7 +303,7 @@ scripts/hygiene.sh rustfmt --check --edition 2018 # for a Rust file you touched rustfmt --check --edition 2021 llembas/line/src/*.rs llembas/tests/shell-test.sh # the status record, in bash and zsh -shellcheck llembas/shell/*.sh llembas/shell/autocomplete.bash; zsh -n llembas/shell/autocomplete.zsh +shellcheck llembas/shell/*.sh; zsh -n llembas/shell/llembas-term.sh ``` The terminal itself is built by CI only, and so are the tests of `llembas/line` diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 76f3e16e5..4f1f53bb9 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -75,7 +75,8 @@ pub use termwindow::{set_window_class, set_window_position, TermWindow, ICON_DAT version = config::llembas_term_long_version() )] struct Opt { - /// Skip loading wezterm.lua + // LLeMbas TERM: the file it skips is its own + /// Skip loading llembas-term.lua (the LLeMbas layer's own defaults are not applied either) #[arg(long, short = 'n')] skip_config: bool, diff --git a/wezterm/src/cli/activate_pane.rs b/wezterm/src/cli/activate_pane.rs index 00b9ff5a5..2b6243d86 100644 --- a/wezterm/src/cli/activate_pane.rs +++ b/wezterm/src/cli/activate_pane.rs @@ -6,6 +6,7 @@ use wezterm_client::client::Client; pub struct ActivatePane { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/activate_pane_direction.rs b/wezterm/src/cli/activate_pane_direction.rs index 377970779..6aa42c3a0 100644 --- a/wezterm/src/cli/activate_pane_direction.rs +++ b/wezterm/src/cli/activate_pane_direction.rs @@ -8,6 +8,7 @@ use wezterm_client::client::Client; pub struct ActivatePaneDirection { /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/activate_tab.rs b/wezterm/src/cli/activate_tab.rs index 559b3d954..42e985c91 100644 --- a/wezterm/src/cli/activate_tab.rs +++ b/wezterm/src/cli/activate_tab.rs @@ -36,6 +36,7 @@ pub struct ActivateTab { /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. /// /// The pane is used to figure out which window diff --git a/wezterm/src/cli/adjust_pane_size.rs b/wezterm/src/cli/adjust_pane_size.rs index 57eae9986..139161bbd 100644 --- a/wezterm/src/cli/adjust_pane_size.rs +++ b/wezterm/src/cli/adjust_pane_size.rs @@ -9,6 +9,7 @@ use wezterm_client::client::Client; pub struct CliAdjustPaneSize { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/get_pane_direction.rs b/wezterm/src/cli/get_pane_direction.rs index 9896a7348..4a28690af 100644 --- a/wezterm/src/cli/get_pane_direction.rs +++ b/wezterm/src/cli/get_pane_direction.rs @@ -8,6 +8,7 @@ use wezterm_client::client::Client; pub struct GetPaneDirection { /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/get_text.rs b/wezterm/src/cli/get_text.rs index 0629cc8cb..e95831f4a 100644 --- a/wezterm/src/cli/get_text.rs +++ b/wezterm/src/cli/get_text.rs @@ -8,6 +8,7 @@ use wezterm_term::{ScrollbackOrVisibleRowIndex, StableRowIndex}; pub struct GetText { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/kill_pane.rs b/wezterm/src/cli/kill_pane.rs index 41104a9a8..f72af0ccc 100644 --- a/wezterm/src/cli/kill_pane.rs +++ b/wezterm/src/cli/kill_pane.rs @@ -6,6 +6,7 @@ use wezterm_client::client::Client; pub struct KillPane { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/move_pane_to_new_tab.rs b/wezterm/src/cli/move_pane_to_new_tab.rs index 331aaa4ed..09ccd20bd 100644 --- a/wezterm/src/cli/move_pane_to_new_tab.rs +++ b/wezterm/src/cli/move_pane_to_new_tab.rs @@ -7,6 +7,7 @@ use wezterm_client::client::Client; pub struct MovePaneToNewTab { /// Specify the pane that should be moved. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/rename_workspace.rs b/wezterm/src/cli/rename_workspace.rs index 47bc94786..dbce75f1d 100644 --- a/wezterm/src/cli/rename_workspace.rs +++ b/wezterm/src/cli/rename_workspace.rs @@ -11,6 +11,7 @@ pub struct RenameWorkspace { /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. /// /// The pane is used to figure out which workspace diff --git a/wezterm/src/cli/send_text.rs b/wezterm/src/cli/send_text.rs index d5072a87e..255bdb82c 100644 --- a/wezterm/src/cli/send_text.rs +++ b/wezterm/src/cli/send_text.rs @@ -8,6 +8,7 @@ use wezterm_client::client::Client; pub struct SendText { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/set_tab_title.rs b/wezterm/src/cli/set_tab_title.rs index 15ac2191f..a9b0f34c3 100644 --- a/wezterm/src/cli/set_tab_title.rs +++ b/wezterm/src/cli/set_tab_title.rs @@ -11,6 +11,7 @@ pub struct SetTabTitle { tab_id: Option, /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. /// /// The pane is used to figure out which tab should be renamed. diff --git a/wezterm/src/cli/set_window_title.rs b/wezterm/src/cli/set_window_title.rs index 16c6a5220..5d11da98c 100644 --- a/wezterm/src/cli/set_window_title.rs +++ b/wezterm/src/cli/set_window_title.rs @@ -11,6 +11,7 @@ pub struct SetWindowTitle { window_id: Option, /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. /// /// The pane is used to figure out which window diff --git a/wezterm/src/cli/spawn_command.rs b/wezterm/src/cli/spawn_command.rs index 97ce9be63..c21798341 100644 --- a/wezterm/src/cli/spawn_command.rs +++ b/wezterm/src/cli/spawn_command.rs @@ -12,6 +12,7 @@ use wezterm_client::client::Client; pub struct SpawnCommand { /// Specify the current pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. /// The pane is used to determine the current domain /// and window. diff --git a/wezterm/src/cli/split_pane.rs b/wezterm/src/cli/split_pane.rs index 5dad757da..0cca2c543 100644 --- a/wezterm/src/cli/split_pane.rs +++ b/wezterm/src/cli/split_pane.rs @@ -10,6 +10,7 @@ use wezterm_client::client::Client; pub struct SplitPane { /// Specify the pane that should be split. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/cli/zoom_pane.rs b/wezterm/src/cli/zoom_pane.rs index 9d31752a5..a60ec0e0f 100644 --- a/wezterm/src/cli/zoom_pane.rs +++ b/wezterm/src/cli/zoom_pane.rs @@ -9,6 +9,7 @@ use wezterm_client::client::Client; pub struct ZoomPane { /// Specify the target pane. /// The default is to use the current pane based on the + // LLeMbas TERM: the pane variable by its own name (upstream: WEZTERM_PANE) /// environment variable LLEMBAS_TERM_PANE. #[arg(long)] pane_id: Option, diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index e6b1ce932..f53e2c863 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -30,7 +30,8 @@ mod cli; version = llembas_term_long_version() )] pub struct Opt { - /// Skip loading wezterm.lua + // LLeMbas TERM: the file it skips is its own + /// Skip loading llembas-term.lua (the LLeMbas layer's own defaults are not applied either) #[arg(long, short = 'n')] skip_config: bool,