diff --git a/CHANGELOG.md b/CHANGELOG.md index 621b025d1..885c14334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,62 @@ What changed in each release of LLeMbas TTY. WezTerm's own changes are in `docs/changelog.md`, as upstream keeps them. +## Unreleased + +### Fixed + +- **AI autocomplete never asked.** The terminal started the engine without the pane's + directory, which the engine requires: the directory was taken from what the shell + integration reports (`file://`) in a way that fails for every address + that names a host — which is every one the integration writes. The engine ended with a + usage error, its error output was discarded, and nothing was shown: no suggestion, no + request to the server, no word about it. The directory is now read correctly (so are the + paths that the highlighting marks as existing, which had the same fault for relative + paths), and when there is none the person's home is given. +- **What an attempt gave is never silent.** The engine's own sentence — not logged in, no + model chosen, a timeout — is kept and shown by *LLeMbas: autocomplete status*, and written + to the terminal's log. +- **The engine is given time.** It was stopped after 2.5 seconds, before a model on the + person's own machine could be loaded for its first answer; and a request that is closed + stops the loading. Now ten seconds by default, and an option: `autocomplete_timeout_ms`. +- The autocomplete model chosen in the terminal is passed to the engine with each request. +- **What LLeMbas asks stands until it is answered.** The word at the cursor's row that says + an approval or a question waits, with its keys, was gone after four seconds; it now stays + for as long as the display asks, moves with you to another pane of the tab, and goes when + it is answered or the display closes. + +### Added + +- **Settings are remembered, for this machine and for a working directory.** Every switch + and choice — AI, AI autocomplete, suggestions, highlighting, mode, chat model, + autocomplete model, display width — is in the command palette twice: *— here* for the + pane's directory, *— everywhere* for the machine; the directory's own wins. A key keeps + the choice where this directory's settings already are. The settings of the active pane's + directory apply, and follow you from directory to directory. Kept by the LLeMbas CLI + (`lembas terminal settings`, CLI 2.0.0-beta.20 or newer) in its own directory on this + machine; with an older CLI a choice holds until the terminal closes, said once. The + options in the configuration file are the starting values: a value set through the + terminal wins. +- **LLeMbas: settings** — what applies in this pane and where each value comes from, with a + line that forgets the directory's own. +- **LLeMbas: autocomplete status** — whether the AI's autocomplete is on and by whose + choice, the engine and model it would use, and the last attempts: when, for which line, + how long, and what came back. +- **LLeMbas: display width** — the display's part of the pane. +- **Manual mode without an approval card** (with a CLI that places commands, 2.0.0-beta.20 + or newer): the command is put at your prompt and not entered; a dimmed hint — *Enter runs + · edit freely · Ctrl+C dismisses* — is drawn beside it, or on the empty row below, never + over it, and goes when you have decided. Nothing of the hint is written to the pane. + +### For developers + +- `llembas-line` gains `complete`: whether a line is asked about and why not, the directory + in a reported address, one request at a time, the engine's command line and its run, and + the attempts in words — tested in CI with a stand-in engine that records its arguments, + its input and its environment. +- `wezterm.llembas.hint`, `.complete_status`, `.data_dir`; `configure` takes `ac_model` and + `ac_timeout_ms`. + ## 1.0.0-beta.4 — 2026-12-02 ### Changed diff --git a/README.md b/README.md index 808e4a013..db0d4d39a 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,16 @@ WezTerm — see `LICENSE.md`. its own: it shows what LLeMbas says, the tools it uses that are not the shell, and what it asks you. `Ctrl+Shift+D` hides and shows it. - **Commands happen in your pane.** When LLeMbas runs a command it is typed at your prompt - as if you typed it, and its output is in your scrollback. In *manual* mode every command - is asked first; `Ctrl+Shift+Y` allows, `Ctrl+Shift+J` denies, from your own pane. In *auto* - mode the commands the CLI's rules allow are typed without asking. There are no file-edit - tools here: this is for terminal work, and the CLI or the IDE are a key away. + as if you typed it, and its output is in your scrollback. In *manual* mode the command is + 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. (With a LLeMbas CLI older than 2.0.0-beta.20, manual mode + asks in the display before typing: `Ctrl+Shift+Y` allows, `Ctrl+Shift+J` denies, from your + own pane.) 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, until it is answered. + 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 @@ -52,28 +58,37 @@ WezTerm — see `LICENSE.md`. else just goes on typing; - *colours*: the command (when it exists), options, strings, variables, the signs between commands, comments, and paths that exist; - - *AI autocomplete*, off unless you turn it on: when your history has nothing for the - line, LLeMbas is asked after a pause and its answer shows in the same place, in italics. + - *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 + 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 + want it different there. See *Settings* below. | Key | Command palette (`Ctrl+Shift+P`) | What it does | |---|---|---| | `Ctrl+Shift+A` | LLeMbas: ask the model | The ask line. The question goes with the *terminal context* of your pane (below). | | | LLeMbas: ask about this screen | The same, with what is visible on the screen instead of the last commands — also from a full-screen program. | | `Ctrl+Shift+S` | LLeMbas: open the CLI | `lembas`, whole, in a new tab. | -| `Ctrl+Shift+I` | LLeMbas: AI on/off | The switch. | +| `Ctrl+Shift+I` | LLeMbas: AI on/off — here / — everywhere | The switch. | | `Ctrl+Shift+Y` | LLeMbas: approve (allow once) | Answers what LLeMbas asks, from your pane. | | | LLeMbas: approve always | Where the question offers it (never for a command typed into your pane). | | `Ctrl+Shift+J` | LLeMbas: deny | | | `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. | -| | LLeMbas: choose model | The terminal's own chat model, from your server's list. | -| | LLeMbas: choose autocomplete model | The terminal's own autocomplete model. | -| | LLeMbas: choose mode | *manual* or *auto*. | +| | LLeMbas: choose model — here / — everywhere | The terminal's own chat model, from your server's list. | +| | LLeMbas: choose autocomplete model — here / — everywhere | The terminal's own autocomplete model. | +| | LLeMbas: choose mode — here / — everywhere | *manual* or *auto*. | +| | LLeMbas: display width — here / — everywhere | The display's part of the pane, from the next time it opens. | | `Ctrl+Shift+H` | LLeMbas: private pane on/off | Nothing of the pane is passed on, and its commands are not remembered. | -| | LLeMbas: suggestions on/off | | -| | LLeMbas: syntax highlighting on/off | | -| | LLeMbas: AI autocomplete on/off | | +| | LLeMbas: suggestions on/off — here / — everywhere | | +| | LLeMbas: syntax highlighting on/off — here / — everywhere | | +| | LLeMbas: AI autocomplete on/off — here / — everywhere | | +| | LLeMbas: settings | What applies in this pane and where each value comes from; forgets this directory's own. | +| | LLeMbas: autocomplete status | The AI's autocomplete in words: on or off, engine, model, the last attempts. | | | LLeMbas: clear command history | | | | LLeMbas: log in | `lembas login`, in a new tab. | | `Ctrl+Shift+E` | LLeMbas: open LLeMbas IDE here | LLeMbas IDE in a new tab, in the pane's directory. | @@ -136,8 +151,44 @@ CLI's business; it never types at a password prompt. **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 that starts with a space, a private pane, or a shell on another machine. -What comes back is shown as text; nothing runs until you take it and press Enter. +empty line, a line of fewer than three characters, a line that starts with a space, a +private pane, or a shell on another machine. What comes back is shown as text; nothing runs +until you take it and press Enter. The engine is given ten seconds for an answer +(`autocomplete_timeout_ms`): a model on your own machine may have to be loaded for the first +one. The last few attempts — the start of the line, how long it took, what came back — are +kept in memory for *LLeMbas: autocomplete status* and go when the terminal closes. + +## Settings + +What you switch and choose in the terminal is remembered: AI on or off, AI autocomplete, +suggestions, highlighting, the mode, the chat model, the autocomplete model and the display's +width. Each is in the command palette twice: + +- **… — here** keeps it for the working directory of the pane you are in; +- **… — everywhere** keeps it for this machine. + +A directory's own value wins over the machine's there. A key (`Ctrl+Shift+I`, or one you gave +to `model` or `mode`) 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 +suggestions, the colours, the autocomplete, the model and mode on the ask line and what the +next display starts with follow. + +**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 +directory's own settings. + +They are kept by the LLeMbas CLI in its own directory on this machine (its README has the +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 +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 has no such store (before 2.0.0-beta.20) everything works as before: +a choice holds until the terminal closes, and the terminal says once that remembering it +needs a newer CLI. **Kept on this machine, sent nowhere:** @@ -191,6 +242,8 @@ require('llembas').apply(config, { ide = { key = 'E', mods = 'CTRL|SHIFT' }, ask_screen = false, always = false, new = false, model = false, mode = false, }, + -- (ai, mode, display.width, suggestions, highlight and autocomplete are starting values: + -- what you choose in the terminal is remembered and wins - see Settings) display = { width = 0.33 }, -- of the pane it opens beside mode = 'manual', -- the mode a display starts in; or 'auto' context = { @@ -203,6 +256,7 @@ require('llembas').apply(config, { 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_timeout_ms = 10000, -- 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 prefix = 6, ghost = 8, notice = 3, diff --git a/llembas/README.md b/llembas/README.md index 668038480..ff0fd25a7 100644 --- a/llembas/README.md +++ b/llembas/README.md @@ -99,7 +99,9 @@ where each point is in the code (one function or constant each, in `lua/llembas/ | 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_TTY` (version), `LLEMBAS_TTY_PANE`, `LLEMBAS_TTY_EXECUTABLE`, `LLEMBAS_TTY_STATUS_DIR` to every pane | Rust (identity), `apply` | types into a pane with `$LLEMBAS_TTY_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_TTY_STATUS_DIR/pane-.status` and the user variable `llembas_tty_status`; the layer writes the file from the variable for a shell that could not (`via=uservar`) | `shell/llembas-tty.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 of `lembas complete --shell [--cwd ] --timeout-ms 2500` | `wezterm-gui/src/llembas/complete.rs` | prints only the rest; nothing means no suggestion | +| asks for the rest of a line: the line on standard input (then closed) of `lembas complete --shell --cwd --timeout-ms [--model ]`, with `LLEMBAS_TTY` set; `--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* | +| 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 ) =` (`default` removes it); `lembas terminal settings forget --cwd `. Keys: `ai`, `autocomplete`, `suggestions`, `highlight` (`true`/`false`), `mode`, `main_model`, `autocomplete_model`, `display_width` (a part of the pane, 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 | +| 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-tty/status-`: two terminals number their panes alike, so each keeps its records apart. Directories of @@ -117,6 +119,46 @@ named `context--.json`: 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. +### 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 +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. +- 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 display that runs is not changed by a change of directory. + +### A word that stands + +`wezterm.llembas.hint(pane id, text | nil, gentle, source pane id)` keeps a word at the +cursor's row of a pane until it is taken away, or until the source pane (the display) is +gone. `sync_hint` in `init.lua` makes it what the display says now (`lembas_ask`): at the +display's user variables and at `update-status`. An approval or a question may be drawn +reversed over the end of the row, as a notice is; a *gentle* hint (a placed command) is +drawn only beside what the row shows or on the empty row below, and not at all otherwise. + +### Whether the input at the prompt is empty + +The engine places a command only at an empty prompt. The shell's hook cannot say how much is +typed (it runs before the line is edited), so the status record carries no such field. What +is typed is known at one place only: the terminal's screen, where the shell integration +marks the input cells. The engine reads it there, as it reads everything of a pane: +`cli get-text` of the cursor's row (with `cli list --format json` for the cursor). + ## What the terminal draws on the input line `wezterm-gui/src/llembas/decorate.rs`, at the moment a pane is painted: the rows near the @@ -133,6 +175,14 @@ and when the options are off. The suggestion is drawn only in the pane that has 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. +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` +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 +path refuses every address that names a host, and the shell integration always names one. + ## Checking a change without building ``` diff --git a/llembas/line/src/complete.rs b/llembas/line/src/complete.rs index dc97850e2..9b9c8e393 100644 --- a/llembas/line/src/complete.rs +++ b/llembas/line/src/complete.rs @@ -762,7 +762,7 @@ mod tests { #[test] fn the_engine_as_it_is_run() { use std::os::unix::fs::PermissionsExt; - use std::path::{Path, PathBuf}; + use std::path::PathBuf; let dir = std::env::temp_dir().join(format!( "llembas-line-complete-{}-{}", @@ -781,7 +781,7 @@ mod tests { }; let read = |name: &str| -> String { std::fs::read_to_string(dir.join(name)).unwrap_or_default() }; - let cli = |path: &Path| path.to_str().unwrap().to_string(); + let cli = |path: &PathBuf| path.to_str().unwrap().to_string(); let always = || true; // 1. What the engine is given: its arguments one by one, the line on diff --git a/llembas/tests/smoke.sh b/llembas/tests/smoke.sh index 24cba2f8e..92f134f28 100755 --- a/llembas/tests/smoke.sh +++ b/llembas/tests/smoke.sh @@ -110,16 +110,32 @@ local config = wezterm.config_builder() local n = wezterm.llembas local out = { 'module=' .. type(n) } if type(n) == 'table' then - for _, name in ipairs { 'ask_line', 'configure', 'notice', 'set_private', 'command_ended', 'clear_history' } do + for _, name in ipairs { 'ask_line', 'configure', 'notice', 'hint', 'complete_status', 'data_dir', 'set_private', 'command_ended', 'clear_history' } do out[#out + 1] = name .. '=' .. type(n[name]) end local ok, err = pcall(n.configure, { - suggestions = true, highlight = true, ai_complete = false, cli = '', history = true, history_max = 10, + suggestions = true, highlight = true, ai_complete = false, cli = '/opt/x/lembas', ac_model = 'local/fast', + ac_timeout_ms = 4000, history = true, history_max = 10, colors = { ghost = 8, command = '#00ff00', unknown = false }, }) out[#out + 1] = 'configure=' .. tostring(ok) .. (ok and '' or (' ' .. tostring(err))) local ok2 = pcall(n.set_private, 3, true) out[#out + 1] = 'set_private=' .. tostring(ok2) + -- a word that stands, set and taken away again; the autocomplete in words + local ok3, err3 = pcall(function() + n.hint(3, 'Enter runs', true, 4) + n.hint(3, nil) + end) + out[#out + 1] = 'hint=' .. tostring(ok3) .. (ok3 and '' or (' ' .. tostring(err3))) + local ok4, status = pcall(n.complete_status) + status = ok4 and tostring(status) or '' + out[#out + 1] = 'status=' .. tostring(status:find('engine: /opt/x/lembas', 1, true) ~= nil + and status:find('model: local/fast', 1, true) ~= nil + and status:find('given 4000 ms', 1, true) ~= nil + and status:find('AI autocomplete (or AI) is off', 1, true) ~= nil + and status:find('not yet', 1, true) ~= nil) + local ok5, dir = pcall(n.data_dir) + out[#out + 1] = 'data_dir=' .. tostring(ok5 and type(dir) == 'string' and dir:sub(1, 1) == '/') end require('llembas').apply(config, { autocomplete = true }) local f = io.open(wezterm.home_dir .. '/native.txt', 'w') @@ -129,7 +145,7 @@ return config LUA native_keys="$(clean "$TTY" show-keys --lua 2>"$work/keys-err.txt")" native="$(cat "$work/home/native.txt" 2>/dev/null)" - expect "wezterm.llembas is there, with every function the layer uses" "$native" '^module=table ask_line=function configure=function notice=function set_private=function command_ended=function clear_history=function configure=true set_private=true$' + expect "wezterm.llembas is there, with every function the layer uses" "$native" '^module=table ask_line=function configure=function notice=function hint=function complete_status=function data_dir=function set_private=function command_ended=function clear_history=function configure=true set_private=true hint=true status=true data_dir=true$' expect "the layer applies over it" "$native_keys" "llembas-ask" if [ -e "$work/home/.local/share/llembas-tty/command-history" ]; then bad "a command history was written though no command ran"; else ok "no command history is written before a command ran"; fi else diff --git a/wezterm-gui/src/llembas/lua.rs b/wezterm-gui/src/llembas/lua.rs index ed6dacc86..c631840a8 100644 --- a/wezterm-gui/src/llembas/lua.rs +++ b/wezterm-gui/src/llembas/lua.rs @@ -169,7 +169,9 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> { }) }; state::set_hint(pane_id, hint); - Mux::notify_from_any_thread(MuxNotification::PaneOutput(pane_id)); + if Mux::try_get().is_some() { + Mux::notify_from_any_thread(MuxNotification::PaneOutput(pane_id)); + } Ok(true) }, )?,