Files
HomerandClaude Opus 5.5 97d3f8bbba LLeMbas IDE: one rule for where the CLI is, its installer checked, honest doctor and start screen
- The CLI is found where the plugin finds it (require("llembas").cli(): PATH, then
  ~/.local/bin); the installer and the launcher keep the same find_cli in shell, and
  scripts/test-ide.sh fails when the two shell copies differ or disagree with the plugin. A CLI
  in ~/.local/bin that is not on PATH (right after a first install) is no longer "not installed".
- The CLI's get.sh is taken from a CLI release (the newest of the channel, or
  LLEMBAS_IDE_CLI_VERSION) and run only after that release's SHA256SUMS is verified with the
  release key and get.sh matches it; LEMBAS_REF names that release.
- curl … | bash -s -- --help prints the help (it is a here-document now); it names ssh-keygen.
- The start screen says a sign-in is needed only when there is none.
- doctor and an update see files added to a plugin, not only changed ones; doctor accepts the
  start as the installer does, says when plugins.lock is missing, checks ssh-keygen, and counts
  "1 check failed" / "N checks failed".
- A release archive that holds a link is refused; newest_tag keeps redirects on https.
- The README key table says where a chord also works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 07:52:31 +00:00

138 lines
5.3 KiB
Lua

-- LLeMbas, built in. The plugin is the one in this repository's nvim/ directory, used through
-- its documented commands and setup; the agent is the LLeMbas CLI. Nothing about a server, a
-- model or a key is set here: they come from the CLI's sign-in.
local M = {}
M.loaded = false
--- The agent's program, or nil: `lembas` on PATH or where its installer puts it, or whatever
--- `cmd` was set to. The plugin decides (`require("llembas").cli()`): there is one rule for
--- "is the LLeMbas CLI installed", and the launcher's `doctor` keeps the same one in shell.
function M.cli()
local ok, llembas = pcall(require, "llembas")
if not ok or type(llembas.cli) ~= "function" then return nil end
local cmd = llembas.cli()
return cmd and cmd[1] or nil
end
function M.has_cli() return M.cli() ~= nil end
local signed = nil -- true | false once it was looked up; nil before, and when it cannot be told
--- Whether the CLI is signed in to a server: true, false, or nil when that is not known (yet).
--- Looked up once, on this machine only — where the CLI keeps its sign-ins (`lembas __paths`),
--- as `llembas-ide doctor` does; no server is asked. `cb()` is called when the answer is in.
function M.signed_in(cb)
if signed ~= nil or M.looking then return signed end
local exe = M.cli()
if not exe then return nil end
M.looking = true
local ok = pcall(vim.system, { exe, "__paths" }, { text = true, timeout = 5000 }, function(res)
local dir = res.code == 0 and (res.stdout or ""):match("config=([^\r\n]+)") or nil
vim.schedule(function()
M.looking = false
if dir then
local f = io.open(dir .. "/lembas.json", "r")
local text = f and f:read("*a") or ""
if f then f:close() end
signed = text:find('"base_url"', 1, true) ~= nil
end
if cb then cb() end
end)
end)
if not ok then M.looking = false end
return nil
end
--- The layout LLeMbas IDE starts with: all four bars. `lua/user/init.lua` changes it with
--- require("llembas").setup({ bars = { … } }); see |llembas-bars|.
M.bars = { top = true, bottom = true, tree = true, chat = true, tree_width = 26, chat_width = 42 }
function M.setup()
local ok, llembas = pcall(require, "llembas")
if not ok then
table.insert(require("llembas_ide").problems, "llembas: the LLeMbas plugin is not installed")
return
end
llembas.setup({
-- Without the CLI the IDE is an editor and stays quiet: no suggestions are asked for.
complete = { auto = M.has_cli() },
-- The keys are the plugin's own table, mapped in both forms; an action that needs the agent
-- says what is missing instead of failing when there is no CLI.
keys = {
prefix = "<Leader>l",
guard = function()
if M.has_cli() then return true end
M.sign_in()
return false
end,
},
bars = vim.deepcopy(M.bars),
})
M.loaded = true
end
--- The plugin's version, or nil.
function M.version()
local ok, llembas = pcall(require, "llembas")
return ok and llembas.version or nil
end
--- Whether suggestions as you type are on.
function M.autocomplete_on()
local ok, llembas = pcall(require, "llembas")
return ok and type(llembas.config) == "table" and type(llembas.config.complete) == "table" and llembas.config.complete.auto == true
end
--- For the statusline: what LLeMbas is doing, in a few characters.
function M.status()
if not M.loaded then return "", false end
if not M.has_cli() then return "◈ no CLI", false end
local ok, text = pcall(function() return require("llembas").statusline() end)
text = (ok and type(text) == "string" and text ~= "") and text or "◈ LLeMbas"
return text .. (M.autocomplete_on() and " · suggest on" or " · suggest off"), true
end
--- Signing in is the CLI's. With a plugin that offers :LLeMbasLogin that is used; otherwise the
--- one command to type is shown.
function M.sign_in()
if vim.fn.exists(":LLeMbasLogin") == 2 then return vim.cmd("LLeMbasLogin") end
local lines
if M.has_cli() then
lines = {
"LLeMbas needs two things: a LLeMbas server, and a sign-in to it.",
"",
"In a terminal (<Space>tt opens one here), with your server's address:",
"",
" lembas login https://your-server.example.org",
"",
"It shows a code to confirm in the browser. After that the chat (<Space>ll),",
"asking about code and suggestions as you type work in this editor.",
"The models and the permissions are your account's; nothing is set here.",
}
else
lines = {
"The LLeMbas CLI (the `lembas` command) is not installed.",
"",
"It is the agent this editor talks to. Everything else in the IDE works without it.",
"To get it, run the installer again and answer yes to the CLI, or see",
"",
" https://github.com/LLeMbas/LLeMbas-CLI",
"",
"Then sign in to your LLeMbas server: lembas login https://your-server.example.org",
}
end
require("llembas_ide.ui").page("Sign in to LLeMbas", lines)
end
--- Run a plugin command only when the plugin and the CLI are there; otherwise say what is missing.
function M.cmd(command)
return function()
if not M.loaded then return vim.notify("LLeMbas: the plugin is not installed", vim.log.levels.WARN) end
if not M.has_cli() then return M.sign_in() end
vim.cmd(command)
end
end
return M