Files
HomerandClaude Opus 5.5 24464aa48e
llembas-term / linux (push) Failing after 38s
Security (M3 and should-fix): a question is never lost, an answer goes to what was shown, a record is the shell's own
M3. Asked from a full-screen program with nothing of its screen asked
about, the context had nothing in it; the engine refuses such a file and a
display started with one never started. Now no file is written and the
question goes alone. A display that ends before it took a question gives
it back: the ask line opens again with the question on it and what the
display said last before it ended.

S1. What a pane says of its shell by user variable is only what it said.
A record the shell of this machine wrote itself (its process id, no via)
and whose shell still runs is the authority: a user variable never
replaces that file, and only it puts a command into the history, has the
input mark written, and numbers the blocks of a context.
S2. A suggestion is drawn and taken, and the AI asked, only while the
shell's record says it is at its prompt (or there is none); the AI only
while the program in front is a shell.
S3. The ask line opens at once from what is known; the settings and the
model are asked of the engine after, and the prefix follows. Answers and
stop no longer wait for the settings either.
S4. The settings that apply are the pane's own directory's: the layer says
them per pane (wezterm.llembas.configure_pane), so two windows in two
directories each keep theirs.
S5. With AI off nothing of the engine is started to read or keep a
setting, but the AI switch itself; a choice made then holds until the
terminal closes. The store's machine-wide values apply in a directory not
read yet.
S6. What the CLI can do is asked again after a minute, and at once when
it lacked what was needed (it may have been updated).
S7. A question card is answered on the ask line: a number, n, or words;
the notice says so, and the approve key says where the answer goes.
S8. A question that waits for a starting display keeps its context file
and sends it; an older waiting one's file goes at once; left-over files
are swept once a minute while any was written.
S10. A suggestion holds nothing invisible (format characters, bidi,
zero-width, variation selectors, tags, separators: filtered in the crate,
for history too); a key takes exactly what was drawn (a cut suggestion its
drawn part); and none is taken while a key sent to the shell is not on
its screen yet.
S12. No stat per word typed: the directories of PATH are listed at most
once a minute; nothing on a network or automounted file system is looked
at; whether an input line stands is read from the rows already fetched;
input marks and history lines are written by one thread of their own.
S13. The status directory is always this terminal's own: one inherited
from a terminal that started it, or set in the configuration, is not used.
S15. An answer is bound to what was asked: a number the engine gives what
it asks (approval#7 …) goes with the answer (/approve 7); without one, an
ask that changed a moment ago is not answered ("read it, then answer
again"). A cut value says that the rest is in the display.
S17. A context of a shell reached over SSH names its host (context file
version 2, with each block's seq and the exit status the shell said, for
an engine that reads it); the display starts in a directory of this machine.
S18. A notice whose display is gone is taken away at once.

Also: one answer for "is this pane's shell on this machine"
(wezterm.llembas.local_dir); dead complete::run and Log::clear only in
tests; the minimum-version check for a CLI that does not say what it can
do is gone (any such CLI is too old, said with the key that still works).

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

276 lines
6.9 KiB
Lua

-- LLeMbas TERM: a stand-in for the terminal's `wezterm` module, for the tests.
-- It records what the layer asks the terminal to do and does none of it,
-- except chmod, which is run for real so that the file mode can be checked.
local F = {}
function F.new(env)
env = env or {}
local w = {
GLOBAL = {},
target_triple = env.target_triple or 'x86_64-unknown-linux-gnu',
executable_dir = env.executable_dir or '/nonexistent/bin',
home_dir = env.home_dir or '/nonexistent/home',
config_file = env.config_file,
handlers = {},
logs = {},
spawned = {},
child_results = env.child_results or {},
-- the terminal's own drawing part, when a test gives one (see F.native)
llembas = env.native,
}
-- wezterm.action.Name(args) and wezterm.action.Name { … } give a table
-- that names the action; nothing more is needed to check what was bound.
w.action = setmetatable({}, {
__index = function(_, name)
return function(args)
return { action = name, args = args }
end
end,
})
function w.on(name, fn)
w.handlers[name] = w.handlers[name] or {}
table.insert(w.handlers[name], fn)
end
function w.emit(name, ...)
local result
for _, fn in ipairs(w.handlers[name] or {}) do
result = fn(...)
end
return result
end
function w.log_warn(...)
w.logs[#w.logs + 1] = table.concat({ ... }, ' ')
end
w.log_info = w.log_warn
w.log_error = w.log_warn
function w.config_builder()
return {}
end
function w.format(items)
local out = {}
for _, item in ipairs(items) do
if type(item) == 'table' and item.Text then
out[#out + 1] = item.Text
end
end
return table.concat(out)
end
function w.run_child_process(args)
w.spawned[#w.spawned + 1] = args
if args[1] == 'chmod' then
local ok = os.execute(string.format("chmod %s '%s'", args[2], args[3]))
return ok == true or ok == 0, '', ''
end
local key = table.concat(args, ' ', 2)
local r = w.child_results[key]
if r then
return r[1], r[2], ''
end
return false, '', 'not found'
end
function w.read_dir(dir)
local list = {}
local p = io.popen(string.format("ls -1 '%s' 2>/dev/null", dir))
if p then
for name in p:lines() do
list[#list + 1] = dir .. '/' .. name
end
p:close()
end
return list
end
function w.json_parse(text)
if env.json_parse then
return env.json_parse(text)
end
error 'not json'
end
return w
end
-- The terminal's own part (`wezterm.llembas`), recording what it is asked.
function F.native()
local n = { calls = {} }
for _, name in ipairs { 'ask_line', 'ask_prefix', 'configure', 'notice', 'hint', 'status', 'set_private', 'command_ended', 'clear_history', 'configure_pane' } do
n[name] = function(...)
n.calls[#n.calls + 1] = { name, ... }
return true
end
end
-- the terminal's side of the autocomplete in words, and its data directory
-- (a test sets n.status_text and n.dir)
function n.complete_status()
return n.status_text or 'engine: none'
end
-- is the pane's line the ask line (a test sets n.asking)
function n.ask_active()
return n.asking == true
end
function n.data_dir()
return n.dir or ''
end
-- a path with its links followed (a test sets n.real[path])
function n.real_path(path)
return n.real and n.real[path] or path
end
function n.last(name)
for i = #n.calls, 1, -1 do
if n.calls[i][1] == name then
return n.calls[i]
end
end
return nil
end
function n.count(name)
local c = 0
for _, call in ipairs(n.calls) do
if call[1] == name then
c = c + 1
end
end
return c
end
return n
end
-- A pane that records what is sent to it.
function F.pane(spec)
local p = {
id = spec.id or 1,
vars = spec.vars or {},
sent = {},
splits = {},
spec = spec,
}
function p:pane_id()
return self.id
end
function p:get_user_vars()
return self.vars
end
function p:get_metadata()
return spec.metadata
end
function p:is_alt_screen_active()
return spec.alt == true
end
function p:get_semantic_zones()
self.read_zones = true
return spec.zones or {}
end
function p:get_text_from_semantic_zone(zone)
self.read_text = true
return zone.text
end
function p:get_lines_as_text()
self.read_screen = true
return spec.screen or ''
end
function p:get_current_working_dir()
return spec.cwd
end
function p:get_foreground_process_name()
if self.program ~= nil then
return self.program or nil
end
return spec.program
end
-- What the terminal says of the process in front of the pane. A test sets
-- p.process: a table, or false for "it cannot say".
function p:get_foreground_process_info()
if self.process ~= nil then
return self.process or nil
end
return spec.process
end
function p:get_domain_name()
return spec.domain or 'local'
end
function p:tab()
return spec.tab
end
function p:activate()
self.activated = (self.activated or 0) + 1
end
function p:send_text(text)
self.sent[#self.sent + 1] = { 'text', text }
end
function p:send_paste(text)
self.sent[#self.sent + 1] = { 'paste', text }
end
function p:split(args)
self.splits[#self.splits + 1] = args
-- the command the layer started runs in the new pane: the shell that
-- holds it, with the engine under it (or the engine itself)
local words = {}
for i, a in ipairs(args.args or {}) do
words[i] = a
end
local process = { pid = 4000, executable = words[1], argv = words, children = {} }
if words[1] == '/bin/sh' then
process.executable = '/usr/bin/dash'
local engine = {}
for i = 5, #words do
engine[#engine + 1] = words[i]
end
process.children = { [4001] = { pid = 4001, executable = engine[1], argv = engine, children = {} } }
end
local new = F.pane { id = (spec.next_id or 100) + #self.splits, process = process }
self.last_split = new
if spec.tab then
table.insert(spec.tab.list, new)
new.spec.tab = spec.tab
end
return new
end
return p
end
function F.tab(panes, id)
local t = { list = panes, id = id or 1 }
function t:panes()
return self.list
end
function t:tab_id()
return self.id
end
for _, p in ipairs(panes) do
p.spec.tab = t
end
return t
end
function F.window(id)
local win = { id = id or 1, actions = {}, status = nil }
function win:window_id()
return self.id
end
function win:perform_action(action, pane)
-- an action that takes nothing is given by its name alone (act.TogglePaneZoomState)
if type(action) == 'function' then
action = action()
end
self.actions[#self.actions + 1] = { action = action, pane = pane }
end
function win:active_pane()
return self.active
end
function win:set_right_status(text)
self.status = text
end
return win
end
return F