*llembas.txt*    LLeMbas in Neovim

The agent is the LLeMbas CLI. This plugin starts `lembas serve --stdio` and is its
client; the sign-in, the models, the tools and the permissions are the CLI's.

It needs LLeMbas CLI 2.0.0-beta.16 or newer; an older one is said once, with how
to update it. A `lembas` that is not on Neovim's PATH is also looked for in
~/.local/bin; anywhere else, set `cmd` (|llembas-setup|).

The CLI keeps ONE sign-in for the whole computer: the terminal and the linked
service use it too. |:LLeMbasLogin| is that same sign-in, made from here.

==============================================================================
COMMANDS                                                    *llembas-commands*

:LLeMbas                                                            *:LLeMbas*
    Open or close the chat panel: the transcript, and the prompt under it.
    In the prompt, <CR> in normal mode or <C-s> sends (or steers while busy),
    <C-c> stops the turn, <C-x><C-f> inserts @file, <C-x><C-o> inserts a
    /command, q closes the panel, g? opens help.
    The prompt's first line begins with what <CR> will do: `ask ›`,
    `rewrite ›` or `add ›` (|llembas-intent|). <Tab> in an empty prompt
    switches between them; with text in the prompt it is Neovim's own <Tab>.
    <C-j> is a new line. With the bars (|llembas-bars|) <CR> sends from
    insert mode too and <Esc> goes back to the code.
    In the transcript, <CR> or gf opens file:line under the cursor, K inspects
    tool output in a float, y yanks the fenced code block under the cursor, i
    jumps into the prompt, q closes.

:[range]LLeMbasAsk [question]                                    *:LLeMbasAsk*
    Ask about the lines of [range]. They are sent as the buffer has them,
    saved or not, with the file, the line numbers and the diagnostics on them.
    Without a question the lines are attached to the next message you type.

:[range]LLeMbasExplain                                       *:LLeMbasExplain*
    Ask the agent to explain the selected lines concisely.

:LLeMbasFix                                                      *:LLeMbasFix*
    Send the current buffer's reported diagnostics to the agent to fix.

:[range]LLeMbasEdit [instruction]                               *:LLeMbasEdit*
    Have the lines of [range] rewritten. The result is shown in place as
    changes: old lines marked, new lines beside them. Nothing is written
    until you accept. ga accepts the change under the cursor, gr rejects it,
    gA and gR do all, ]h and [h jump between changes.

:LLeMbasGenerate [instruction]                             *:LLeMbasGenerate*
    Generate code at the cursor line and show it as inline proposed hunks.

:[range]LLeMbasPrompt [ask|rewrite|add]                       *:LLeMbasPrompt*
    To the prompt, with the lines of [range] — without one, the cursor's
    line — as the attachment: its name stands above the prompt
    (`main.rs:12-18`). The argument sets what <CR> will do.    *llembas-intent*
        ask      the question goes to the chat, the lines with it as context
        rewrite  the lines are rewritten; the result is shown in the file as
                 changes to accept or reject (as |:LLeMbasEdit|)
        add      new code is written at the point, shown the same way
                 (as |:LLeMbasGenerate|)
    After a rewrite or an add the prompt says `ask ›` again.

:LLeMbasEffort [level]                                        *:LLeMbasEffort*
    The effort of the conversation: off, minimal, low, medium, high, xhigh,
    max or default. Without a level, pick one. A level the model does not
    offer is said, with the level it runs on.

:LLeMbasAI [on|off]                                              *:LLeMbasAI*
    Everything of LLeMbas on or off. Off is a plain editor: the agent is
    stopped, no suggestion is asked for, nothing is sent, and it stays off in
    this directory until it is switched on.

:LLeMbasMenu                                                    *:LLeMbasMenu*
    Every command and every setting — the model, the mode, the effort,
    suggestions, the bars — in one list to pick from.

:LLeMbasBars [on|off|top|bottom|tree|chat [on|off]]             *:LLeMbasBars*
    The four bars (|llembas-bars|) on or off, or one of them.

:LLeMbasTree                                                    *:LLeMbasTree*
    The file tree, show and hide (|llembas-tree|).

:LLeMbasCancelEdit                                       *:LLeMbasCancelEdit*
    Cancel an in-flight rewrite or generation in the current buffer.

:LLeMbasAccept[!]  :LLeMbasReject[!]            *:LLeMbasAccept* *:LLeMbasReject*
    Accept or reject the change under the cursor; with ! all of them.

:LLeMbasNextHunk  :LLeMbasPrevHunk            *:LLeMbasNextHunk* *:LLeMbasPrevHunk*
    Jump to the next or previous proposed change in the current buffer.

:LLeMbasAutocomplete [on|off]                           *:LLeMbasAutocomplete*
    Suggestions as you type. While typing, <Tab> accepts a shown suggestion,
    <M-Right> accepts the next word, and <M-\> asks for one now.

:LLeMbasAutocompleteTokens [N|auto|words|line|block|file] *:LLeMbasAutocompleteTokens*
    Configure how much autocomplete predicts (max tokens up to 4096 and/or a
    length preset: auto, words, line, block, file). Without an argument, opens
    a picker with presets and a custom token count input.

:LLeMbasAutocompleteInstructions [text|-]         *:LLeMbasAutocompleteInstructions*
    Your own instructions for suggestions ("-" clears them).

:LLeMbasAutocompleteModel[!] [model]               *:LLeMbasAutocompleteModel*
    The model that writes suggestions, saved in your account; without a name,
    pick from the list. With ! it is switched for this editor only. "-" goes
    back to the default.

:LLeMbasMainModel [model]                                  *:LLeMbasMainModel*
    The model for chat and rewriting, saved in your account. "?" shows both
    settings.

:LLeMbasFiles[!] [name]                                        *:LLeMbasFiles*
    Find a file or folder of the project by part of its name and insert @path
    into the prompt (! opens the chosen file in the editing window). Without
    a name it asks for one. Needs no session and no sign-in.

:LLeMbasOpenFile [name]                                     *:LLeMbasOpenFile*
    Open a file of the project, found the same way.

:LLeMbasCommands                                            *:LLeMbasCommands*
    Pick an available /command or skill and insert it into the prompt.

:LLeMbasSessions                                            *:LLeMbasSessions*
    List previous sessions in this directory and resume one with its history.

:LLeMbasCompact                                              *:LLeMbasCompact*
    Compact the active session's conversation context.

:LLeMbasToggleThoughts                                *:LLeMbasToggleThoughts*
    Toggle showing model thinking in the transcript.

:LLeMbasOpen                                                    *:LLeMbasOpen*
    Open the file the agent showed last. Only a picture, a PDF, sound, video
    or plain text, and only when the file's first bytes are what its name
    says: plain text opens here (read-only), the rest in the system's
    viewer. Anything else is named and left alone.

:LLeMbasStop                                                    *:LLeMbasStop*
    Stop the running turn.

:LLeMbasNew[!]                                                   *:LLeMbasNew*
    Start a new session (! also ends the agent when a turn hangs). Old
    sessions stay in the CLI.

:LLeMbasMode [mode]                                             *:LLeMbasMode*
    Change the session's mode (works live mid-turn); without an arg, pick.

:LLeMbasModel [model]                                          *:LLeMbasModel*
    Pick or change the session's model.

:LLeMbasStatus  :LLeMbasHelp                     *:LLeMbasStatus* *:LLeMbasHelp*
    Open floating status overview or commands & keymaps reference. The status
    says the CLI's version, the folder the agent works in, and why no
    suggestion came when none did.

:LLeMbasLogin [address] [--ca {file}]                         *:LLeMbasLogin*
    Sign this computer in to a LLeMbas server (the address is asked for when
    not given; nothing is predefined). The CLI's own sign-in is run
    (`lembas login --json`): the code to approve is shown in the chat and the
    approval page is opened in your browser. When it is approved the agent is
    started anew, so the open panel works at once.
    When the computer is signed in to another server already, the plugin says
    which and asks first: the new sign-in replaces it, for the terminal and
    the linked service too. --ca names the certificate authority of a server
    that has a private one (also `login.ca` in |llembas-setup|); with it the
    CLI always makes a new sign-in.

:LLeMbasLoginCancel                                     *:LLeMbasLoginCancel*
    Stop a sign-in that waits to be approved.

:LLeMbasLogout                                               *:LLeMbasLogout*
    Sign this computer out, after asking: the terminal and the linked service
    are signed out with it.

:LLeMbasRestart                                             *:LLeMbasRestart*
    Stop the agent. The transcript stays; the next message, suggestion or
    rewrite starts a new agent and a new session.

:LLeMbasLog                                                     *:LLeMbasLog*
    Show what the agent wrote on stderr: the running one's, or the last
    one's — where to look when it stopped.

==============================================================================
THE BARS                                                        *llembas-bars*

`bars = true` in |llembas-setup| lays the editor out in four bars, each of
which can be switched off (`bars = { top = false }`, |:LLeMbasBars|):

    top      what LLeMbas is doing, the conversation's title, model · mode ·
             effort, the context in percent, suggestions on or off, and the
             git branch and the file's problems when there is room. It is the
             'tabline'.
    bottom   the keys for the bar that has the focus (|llembas-keys|), and
             Neovim's own state: mode, modified, macro, search count, line
             and column, pending operator. It is the 'statusline' (with
             'laststatus' 3). From 120 columns the search count and the
             pending operator have cells in it ('showcmdloc' statusline);
             narrower, the keys need the room and both are where stock Neovim
             shows them, in the command line's row.
             With several tab pages the top bar says which one this is.
    tree     the file tree on the left (|llembas-tree|).
    chat     the right bar: the settings lines (model, mode, effort,
             autocomplete — <CR> on a line opens its choices under it, <CR>
             on a choice takes it, <Esc> closes), the transcript, and the
             prompt with the attachment's name above it.

Every row is made of cells of a known width; one cell takes what is left and
is cut with an ellipsis. Nothing wraps. When the code would have fewer than
`min_code` columns the chat folds away, then the tree; a bar opened by key at
that width is shown all the same. Under 18 rows the settings lines are left
out. Switched off, the top and bottom bars give 'tabline' and 'statusline'
back as they were (`User LLeMbasBars` is fired, for a distribution that puts
its own there).
>lua
    require("llembas").setup({ bars = {
      top = true, bottom = true, tree = true, chat = true,
      tree_width = 26,     -- 16 to 60
      chat_width = 42,     -- 34 to 50
      prompt_height = 3,
      min_code = 60,
    } })
<
The tree                                                        *llembas-tree*
    The working directory as lines. <CR> or l opens a file, and opens or
    closes a directory; <Right> opens, <Left> or h closes or goes to the
    directory above. a makes a file (a directory when the name ends in /),
    r renames or moves, d deletes after asking — into the trash where the
    system has one (`gio trash`, `trash-put`, `trash`), and for good, said so
    in the question, where it has none. / filters by name as you type, .
    shows hidden files, R reads the directory again. The file you are in is
    followed. The first column of a row is its git state: M changed, A added,
    ? new, D deleted, ! conflict, • a directory with changes inside.

==============================================================================
KEYS                                                            *llembas-keys*

`keys = true` (or `bars`) maps LLeMbas's keys from one table,
`require("llembas.keys").table`. An action has two forms, and both are
mapped:

    the chord     the LLeMbas terminal's: <C-S-A> and so on. It reaches
                  Neovim only from a terminal that reports such keys (the
                  kitty keyboard protocol).
    the other     a key after the prefix (<Leader>l), or a plain key in one of
                  the bars. It always arrives.

    <C-S-A>    <Leader>la  to the prompt; the selection or the cursor's line
                           comes along (|:LLeMbasPrompt|)
               <Leader>le  the same, to rewrite        <Leader>lg  to add
    <C-Tab>    <Leader>lm  switch the mode
    <C-S-M>    <Leader>lM  choose the model            <Leader>lE  the effort
    <C-M-m>    <Leader>lC  choose the autocomplete model
    <C-M-a>    <Leader>lt  suggestions as you type, on and off
    <C-S-I>    <Leader>lI  LLeMbas on and off (|:LLeMbasAI|)
    <C-S-G>    <Leader>l.  stop the running turn
    <C-S-Y>    ga          accept the proposed change under the cursor
    <C-S-J>    gr          reject it       <M-C-S-Y>  gA  accept all
    <C-S-E>    <Leader>lb  the tree, show and hide
    <C-S-D>    <Leader>ll  the chat, show and hide
    <M-Left> <M-Right>     to the bar on the left, on the right
    <C-S-P>    <Leader>lp  the menu (|:LLeMbasMenu|)
    <Leader>ls sessions, ln new, lc commands, lx explain, lf fix, lS status,
    li sign in, l? help.

The bottom bar shows the form that works: the chords once one has arrived
from this terminal (remembered) or when the terminal is one known to report
them, the other form otherwise. `keys = { chords = true }` or `false` says it
by hand; `keys = { prefix = "<Leader>a" }` moves the other form.
To change a key, change its entry and set up again:
>lua
    local keys = require("llembas.keys")
    keys.by_id.ask.chord = "<F2>"
    require("llembas").setup({ keys = true })
<
<Tab> has three jobs that never meet: while typing code it accepts a shown
suggestion and is Neovim's own otherwise (the mapping exists only while a
suggestion is shown); in an empty prompt it switches ask, rewrite, add; and
it is never a completion menu's.

Inside the LLeMbas terminal (`$LLEMBAS_TERM` or `$LLEMBAS_TTY`) the plugin
sets the terminal's user var `llembas_ide` to 1 when the keys are mapped and
clears it on exit, so that the terminal hands its own chords through. Nothing
is written in any other terminal.

==============================================================================
FOR A STATUSLINE, A BAR, A SCRIPT                                *llembas-api*

require("llembas").settings()                               *llembas.settings()*
    What holds now: `state` ("idle", "thinking", "tools", "writing",
    "waiting", "starting", "signed_out", "no_cli", "off"), `title`,
    `session` (boolean), `model`, `mode`, `effort`, `context` (percent of the
    model's window, or nil), `autocomplete`, `ai`, `intent`, `attachment`,
    `busy`, `changes` (proposed changes in this buffer).

User LLeMbasChanged                                            *LLeMbasChanged*
    Fired when any of that changes. `User LLeMbasBars`: the top or bottom bar
    was switched; `User LLeMbasLayout`: the side bars were laid out.

require("llembas").setting_lines()                     *llembas.setting_lines()*
    The settings as lines: `{ id, label, value, off }` for model, mode,
    effort, autocomplete.
require("llembas").choices({id}, {cb})                        *llembas.choices()*
    What a setting can be set to: `cb(list)` of `{ value, label, current }`,
    or `cb(nil, why)`. The models and modes are asked of the CLI.
require("llembas").set({id}, {value})                             *llembas.set()*
    Set it.
require("llembas").prompt({opts})                              *llembas.prompt()*
    |:LLeMbasPrompt|: `intent`, `first`, `last`, `attach = false`.
require("llembas").intent([{name}])                            *llembas.intent()*
    Set, and return, what <CR> in the prompt will do.
require("llembas").cli()                                          *llembas.cli()*
    The command that starts the agent, as a list, or nil and why: `cmd` as
    set, and a bare `lembas` that is not on this editor's PATH where the
    CLI's installer puts it (~/.local/bin). The one place that decides
    whether the LLeMbas CLI is installed.
require("llembas").effort([{level}])   .ai([{on}])   .autocomplete([{on}])
require("llembas").cycle_mode()        .menu()
    As the commands of those names.
require("llembas.layout").toggle({bar} [, {on}])   .focus("tree"|"code"|"chat")
    .go(-1|1)   .where()   .options()   .top_text([{width}])
    .bottom_text([{where} [, {width} [, {chords}]]])
    The bars: show and hide, move the focus, where it is, and the two rows as
    plain text of exactly the width asked for.
require("llembas.keys").table   .by_id   .for_bar({where})   .rows()
    .written({lhs})   .chords()
    The key table, the keys a bar shows, the rows of a cheat sheet, a key as
    the bar writes it, and whether the chords arrive.

What is remembered                                          *llembas-remembered*
    The mode, the effort, suggestions and LLeMbas on or off, which bars are
    shown and how wide the side bars are: per working directory, with a
    machine-wide level under it, in `stdpath("state")/llembas/settings.json`.
    A change is the directory's own. *Make these settings the default* in
    the menu copies what holds here to the machine-wide level; *Forget what
    this directory chose* removes the directory's own. `remember = false`
    keeps nothing. The models are not kept here: the session's model is the
    LLeMbas CLI's to remember (the model last used in a directory), and the
    autocomplete and main model are your account's
    (|:LLeMbasAutocompleteModel|, |:LLeMbasMainModel|).

    After |:cd| the new directory's own hold: the mode and the effort a
    session starts with, LLeMbas and suggestions on or off.

==============================================================================
WHAT IS SENT                                                *llembas-privacy*

Everything goes to the LLeMbas CLI on this computer, and from there to your
LLeMbas server: nowhere else.

What you send        the message you type; lines you ask about, have
                     explained or rewritten; a file you name with @.
With a message       the name of the file you are in, the cursor's line, the
                     lines that came along, the diagnostics on them, and the
                     NAMES (not the text) of the other open files
                     (`send_open_file = false`: none of this).
With a suggestion    the text around the cursor (up to 400 lines before it
                     and 100 after), the file's name and type, and the TEXT
                     of up to six other open files (the first 400 lines of
                     each), of which the CLI puts pieces beside it.

What goes along without your pointing at it — the other files' names and
text — is held to three rules:

1. Only files inside the working directory (|:pwd|).
2. Never a file that looks like it holds secrets, by its name or its place:
   `.env` and `.env.*` (but not `.env.example`, `.env.sample`,
   `.env.template`), `*.env`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `*.jks`,
   `*.keystore`, `*.ppk`, `*.kdbx`, `id_rsa*`, `id_ed25519*`, `id_ecdsa*`,
   `id_dsa*`, `.netrc`, `.npmrc`, `.pypirc`, `.pgpass`, `.htpasswd`,
   `.git-credentials`, `credentials*`, `secrets.*`, `secret.*`, and
   anything under `.ssh/`, `.gnupg/`, `.aws/`, `.kube/`, `.docker/` or
   `.azure/`.
3. Never a file the project's .gitignore leaves out (git is asked, once a
   file; a file git has not answered for yet is left out).

In a file that looks like it holds secrets no suggestion is asked for at
all, so nothing of it is sent; that is said once. A file the project
ignores, or one outside the working directory, still gets suggestions while
you type in it: its own text around the cursor is what a suggestion is made
from.

The agent itself reads and writes files as a turn needs them, under the
CLI's permissions; that is the CLI's to allow or ask about, and is not
limited by the rules above. |:LLeMbasAI| off sends nothing at all.

==============================================================================
WHEN SOMETHING IS WRONG                                     *llembas-trouble*

The CLI is not found       the chat says so; install it or set `cmd`.
The CLI is too old         said once, with both versions: `lembas update`.
Not signed in              every way in says so: |:LLeMbasLogin|.
The agent stopped          the chat says why (its last words); the next
                           message starts it again. |:LLeMbasLog| has more.
The agent does not answer  the start is given up after 10 seconds and said;
                           a turn has no limit (<C-c> or |:LLeMbasStop| stops
                           it, |:LLeMbasNew|! ends the agent).
A turn failed              the reason is in the transcript, in red.
The plugin is too old      a server may ask for a newer plugin: said once.

==============================================================================
SETUP                                                          *llembas-setup*
>lua
    require("llembas").setup({
      cmd = { "lembas", "serve", "--stdio" },  -- the agent
      position = "right",      -- "right" | "left" | "bottom" | "float"
      width = 64,              -- the panel's columns
      prompt_height = 5,       -- the prompt window's rows
      border = "rounded",      -- border style for floating windows
      mode = nil,              -- the mode a session starts in
      model = nil,             -- the model a session starts on
      show_thoughts = false,   -- the model's thinking in the transcript
      send_open_file = true,   -- a typed message names the file you are in
      login = {
        ca = nil,              -- the CA file of a server with a private one
      },
      complete = {
        auto = true,           -- suggest as you type
        debounce_ms = 250,     -- the pause before a suggestion is asked for
        model = nil,           -- a model for this editor only
        max_tokens = nil,      -- max tokens to predict (nil: server default)
        length = "auto",       -- "auto" | "words" | "line" | "block" | "file"
        instructions = "",     -- custom autocomplete instructions
        accept = "<Tab>",      -- accepts a shown suggestion
        accept_word = "<M-Right>", -- accepts next word of suggestion
        trigger = "<M-\\>",    -- asks for a suggestion now
      },
      keys = false,            -- true or { prefix, chords }: |llembas-keys|
      bars = false,            -- true or a table: |llembas-bars|
      remember = true,         -- |llembas-remembered|
    })
<
Statusline component: `require("llembas").statusline()`.
Highlights: `LLeMbasBrand`, `LLeMbasUserHeader`, `LLeMbasAgentHeader`,
`LLeMbasThought`, `LLeMbasToolPending`, `LLeMbasToolDone`, `LLeMbasToolFail`,
`LLeMbasToolDenied`, `LLeMbasPlanHeader`, `LLeMbasDiffAdd`, `LLeMbasDiffDelete`,
`LLeMbasDiffHint`, `LLeMbasGhost`, `LLeMbasSeparator`; the bars' `LLeMbasBar`,
`LLeMbasBarKey`, `LLeMbasBarTitle`, `LLeMbasBarSeparator`, `LLeMbasBarFact`,
`LLeMbasBarIdle`, `LLeMbasBarBusy`, `LLeMbasBarWaiting`, `LLeMbasBarOff`,
`LLeMbasBarVim`; `LLeMbasPromptPrefix`, `LLeMbasChip`, `LLeMbasLineLabel`,
`LLeMbasLineValue`, `LLeMbasLineOff`, `LLeMbasLineCurrent`; the tree's
`LLeMbasTreeDirectory`, `LLeMbasTreeCurrent`, `LLeMbasTreeChanged`,
`LLeMbasTreeAdded`, `LLeMbasTreeNew`, `LLeMbasTreeDeleted`,
`LLeMbasTreeConflict` (all `default = true`).

What the model writes is shown as text. It is never run, and the panel's
buffers read no modeline.

 vim:tw=78:ts=8:ft=help:norl:
