Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3409a41d85 | |||
| e8c18f1e3b | |||
| 611a047bef | |||
| e44b35b0e0 | |||
| 8196f6fb8e | |||
| 08e0075d14 | |||
| 250f3d38f0 | |||
| 2bb7b94a66 | |||
| 80fb60c60f |
@@ -29,6 +29,8 @@ local PROBE_TTL_UP = tonumber(os.getenv("LMCP_HUB_PROBE_TTL_UP") or "30")
|
||||
local PROBE_TTL_DOWN_MIN = tonumber(os.getenv("LMCP_HUB_PROBE_TTL_DOWN_MIN") or "60")
|
||||
local PROBE_TTL_DOWN_MAX = tonumber(os.getenv("LMCP_HUB_PROBE_TTL_DOWN_MAX") or "900")
|
||||
local PROBE_BUDGET = tonumber(os.getenv("LMCP_HUB_PROBE_BUDGET") or "3")
|
||||
-- TCP port that answers "is this host there" for ssh-only backends.
|
||||
local SSH_PROBE_PORT = os.getenv("LMCP_HUB_SSH_PORT") or "22"
|
||||
local LMCP_TIMEOUT = tonumber(os.getenv("LMCP_HUB_LMCP_TIMEOUT") or "6")
|
||||
local SSH_TIMEOUT = tonumber(os.getenv("LMCP_HUB_SSH_TIMEOUT") or "10")
|
||||
local SSH_HARD_TIMEOUT = tonumber(os.getenv("LMCP_HUB_SSH_HARD_TIMEOUT") or "30")
|
||||
@@ -272,13 +274,19 @@ end
|
||||
-- bash fan-out of curl calls. Total wall clock ≈ PROBE_BUDGET.
|
||||
local function probe_all_parallel(force)
|
||||
local now = os.time()
|
||||
local need = {}
|
||||
local need, need_ssh = {}, {}
|
||||
for name, b in pairs(backends) do
|
||||
if b.lmcp_url and (force or not cache_fresh(status[name], now)) then
|
||||
need[#need+1] = b
|
||||
if force or not cache_fresh(status[name], now) then
|
||||
if b.lmcp_url then
|
||||
need[#need+1] = b
|
||||
elseif b.ssh_host then
|
||||
-- ssh-only: no lmcp endpoint to ask, but "is the box there" is still
|
||||
-- answerable cheaply. See the SSH probe note below.
|
||||
need_ssh[#need_ssh+1] = b
|
||||
end
|
||||
end
|
||||
end
|
||||
if #need == 0 then return end
|
||||
if #need == 0 and #need_ssh == 0 then return end
|
||||
|
||||
local script_parts = {}
|
||||
for _, b in ipairs(need) do
|
||||
@@ -289,6 +297,21 @@ local function probe_all_parallel(force)
|
||||
PROBE_BUDGET, b.name, auth, url, b.name
|
||||
)
|
||||
end
|
||||
-- SSH probe. The design note above rejects checking ssh because a session costs
|
||||
-- 3-6s per offline host — true for a SESSION. A bare TCP connect to 22 answers the
|
||||
-- only question a host card asks ("is it there") with no handshake and no auth:
|
||||
-- measured on this host, a dead target costs 1.05s and a live one milliseconds, and
|
||||
-- it rides the same parallel fan-out, so wall clock stays one budget window.
|
||||
-- Without nc we report nothing rather than guessing DOWN — a wrong claim is worse
|
||||
-- than the "no probe result" the dashboard already renders as unknown.
|
||||
for _, b in ipairs(need_ssh) do
|
||||
local host = b.ssh_host:gsub("'", "'\\''")
|
||||
script_parts[#script_parts+1] = string.format(
|
||||
"(if command -v nc >/dev/null 2>&1; then " ..
|
||||
"nc -z -w%d '%s' %s >/dev/null 2>&1 && echo '%s SSHUP 0' || echo '%s SSHDOWN 0'; " ..
|
||||
"else echo '%s SSHSKIP 0'; fi) &",
|
||||
PROBE_BUDGET, host, SSH_PROBE_PORT, b.name, b.name, b.name)
|
||||
end
|
||||
script_parts[#script_parts+1] = "wait"
|
||||
|
||||
local t0 = monotonic()
|
||||
@@ -302,8 +325,14 @@ local function probe_all_parallel(force)
|
||||
local name, code, t = line:match("^(%S+)%s+(%S+)%s+([%d%.]+)")
|
||||
if name then
|
||||
seen[name] = true
|
||||
local is_up = (code == "200")
|
||||
if is_up then
|
||||
if code == "SSHUP" then
|
||||
apply_probe_result(name, true, nil, "ssh", nil)
|
||||
elseif code == "SSHDOWN" then
|
||||
apply_probe_result(name, false, "ssh port unreachable", nil, nil)
|
||||
elseif code == "SSHSKIP" then
|
||||
-- nc missing: leave it unprobed rather than assert a state.
|
||||
seen[name] = nil
|
||||
elseif code == "200" then
|
||||
apply_probe_result(name, true, nil, "lmcp", nil)
|
||||
else
|
||||
apply_probe_result(name, false, "lmcp code=" .. code, nil, nil)
|
||||
@@ -316,7 +345,7 @@ local function probe_all_parallel(force)
|
||||
apply_probe_result(b.name, false, "probe fan-out missing", nil, nil)
|
||||
end
|
||||
end
|
||||
logreq("probe_all_parallel n=%d elapsed=%.2fs", #need, dt)
|
||||
logreq("probe_all_parallel lmcp=%d ssh=%d elapsed=%.2fs", #need, #need_ssh, dt)
|
||||
end
|
||||
|
||||
-- ---- Call-tool dispatcher ----------------------------------------------
|
||||
@@ -631,6 +660,62 @@ server:tool("remote_search_files", "find-by-pattern on a fleet host.",
|
||||
} }
|
||||
)
|
||||
|
||||
-- ---- Fleet-central local tools (migrated from tools.d/hertz.lua, 2026-07-18) ----
|
||||
-- These run LOCALLY on hertz (where the hub process also lives), so no ssh
|
||||
-- backend hop. Consolidated here so the hub is the single fleet-management
|
||||
-- endpoint. Still also served by hertz-tools (:8080) for now — remove there
|
||||
-- once every client (pi-agents etc.) has a @hub session.
|
||||
local function run_local(cmd, timeout)
|
||||
local full = timeout and ("timeout " .. tostring(timeout) .. " " .. cmd) or cmd
|
||||
local p = io.popen(full .. " 2>&1")
|
||||
if not p then return "Error: popen failed" end
|
||||
local out = p:read("*a")
|
||||
p:close()
|
||||
return out or ""
|
||||
end
|
||||
|
||||
server:tool("apropos",
|
||||
"Search shared fleet memory (stash) for facts about the fleet, projects, decisions, and preferences. query = 2-6 words on the topic; limit = max results (default 3). Read-only.",
|
||||
{ type = "object", properties = {
|
||||
query = { type = "string", description = "2-6 words describing what to recall" },
|
||||
limit = { type = "integer", description = "max results, default 3" },
|
||||
}, required = { "query" } },
|
||||
function(a)
|
||||
local q = tostring(a.query or ""):gsub("[^%w%s%-%.]", " "):gsub("%s+", " ")
|
||||
if q:gsub("%s", "") == "" then return "Error: query required" end
|
||||
local lim = tonumber(a.limit) or 3
|
||||
return run_local("python3 /opt/lmcp/helpers/stash_recall.py '" .. q .. "' " .. lim, 30)
|
||||
end,
|
||||
{ annotations = {
|
||||
title = "Apropos (fleet memory)",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("wake_fleet",
|
||||
"Wake a fleet NUC (pve1..pve4) via Fritz!Box Wake-on-LAN. Powers a node ON only; it cannot power anything off. Node boots in ~30-60s.",
|
||||
{ type = "object", properties = {
|
||||
node = { type = "string", description = "Node to wake: '1'..'4' or 'pve1'..'pve4'" },
|
||||
}, required = { "node" } },
|
||||
function(a)
|
||||
local node = tostring(a.node or ""):gsub("[^%w]", "")
|
||||
if not node:match("^p?v?e?[1-4]$") then
|
||||
return "Error: node must be 1-4 or pve1-pve4 (got: " .. tostring(a.node) .. ")"
|
||||
end
|
||||
return run_local("sudo /root/.local/bin/wake-pve " .. node, 15)
|
||||
end,
|
||||
{ annotations = {
|
||||
title = "Wake fleet NUC",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
io.stderr:write(string.format("lmcp-hub starting on port %d with %d backends from %s\n",
|
||||
server.port, (function() local n = 0; for _ in pairs(backends) do n = n + 1 end; return n end)(), CONF_PATH))
|
||||
server:run()
|
||||
|
||||
@@ -48,6 +48,19 @@ function lmcp.new(name, opts)
|
||||
self.host = opts.host or "0.0.0.0"
|
||||
self.port = opts.port or 8080
|
||||
self.tools = {}
|
||||
-- Erlaubnisliste je Instanz (LMCP_TOOL_ALLOW, kommagetrennt). Ist sie
|
||||
-- gesetzt, registriert `tool()` NUR diese Namen -- Built-ins wie Plugins.
|
||||
-- Nicht gesetzt: alles wie bisher. Das ist die einzige Stelle, an der ein
|
||||
-- Werkzeug entsteht, also die einzige, an der man es verhindern kann;
|
||||
-- nachtraeglich loeschen muss jeden kuenftigen Eintrag kennen und veraltet.
|
||||
self.tool_allow = nil
|
||||
do
|
||||
local roh = os.getenv("LMCP_TOOL_ALLOW")
|
||||
if roh and roh:match("%S") then
|
||||
self.tool_allow = {}
|
||||
for n in roh:gmatch("[^,%s]+") do self.tool_allow[n] = true end
|
||||
end
|
||||
end
|
||||
-- Resources primitive (MCP 2025-06-18 §Server/Resources). Storage is
|
||||
-- always present; capability is advertised iff `opts.resources` is
|
||||
-- truthy OR at least one resource/template has been registered by
|
||||
@@ -182,6 +195,13 @@ function lmcp:tool(name, description, params_schema, handler, opts)
|
||||
end
|
||||
schema = clean
|
||||
end
|
||||
-- Erlaubnisliste: stumm verweigern, damit ein Plugin, das ein nicht
|
||||
-- erlaubtes Werkzeug anbietet, nicht abstuerzt -- es existiert einfach
|
||||
-- nicht. `tools/list` und `tools/call` lesen beide dasselbe Register,
|
||||
-- ein nicht registriertes Werkzeug ist also weder sichtbar noch rufbar.
|
||||
if self.tool_allow and not self.tool_allow[name] then
|
||||
return self
|
||||
end
|
||||
self.tools[name] = {
|
||||
name = name,
|
||||
description = description,
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
-- Abnahmetest fuer lmcp Phase A (nur beobachten, nie ablehnen).
|
||||
--
|
||||
-- Vom Vertrag geschrieben, NICHT von der Implementierung: der Autor dieses
|
||||
-- Tests hat den zu pruefenden Code nicht gesehen. Genau daran sind die
|
||||
-- letzten vier Runden gescheitert - der Implementierer hat seine eigenen
|
||||
-- Hausaufgaben korrigiert, und der Test prueft dann verlaesslich das, was
|
||||
-- der Code ohnehin tut.
|
||||
--
|
||||
-- VERTRAG
|
||||
-- Eine einzelne, in sich geschlossene Lua-5.4-Datei stellt eine Tabelle M
|
||||
-- bereit mit:
|
||||
-- M.report(version, peer, ua) -- Produktionseinstieg
|
||||
-- M.sink(version, peer, ua) -- ueberschreibbar, wird beim ERSTEN
|
||||
-- -- Auftreten eines Tripels gerufen
|
||||
-- * jedes verschiedene Tripel (version, peer, ua) genau EINMAL
|
||||
-- * version nil oder "" -> nichts
|
||||
-- * der Entprellungszustand ist ein privates Upvalue: KEINE globale
|
||||
-- Variable, KEIN Parameter, den der Aufrufer mitgeben muss
|
||||
-- * gedeckelt bei 50 verschiedenen Tripeln; danach nichts mehr
|
||||
-- * M.report lehnt NIE etwas ab und liefert immer nil
|
||||
--
|
||||
-- Aufruf: lua5.4 phase_a_acceptance.lua <zu-pruefende-datei.lua>
|
||||
|
||||
local pfad = arg and arg[1]
|
||||
if not pfad then
|
||||
io.stderr:write("usage: lua5.4 phase_a_acceptance.lua <impl.lua>\n")
|
||||
os.exit(2)
|
||||
end
|
||||
|
||||
local vorher_global = {}
|
||||
for k in pairs(_G) do vorher_global[k] = true end
|
||||
|
||||
local lade = assert(loadfile(pfad))
|
||||
local M = lade()
|
||||
if type(M) ~= "table" then
|
||||
io.stderr:write("FAIL: die Datei liefert keine Tabelle zurueck\n")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local fehler = 0
|
||||
local function pruefe(name, bedingung, zusatz)
|
||||
if bedingung then
|
||||
print((" [ok ] %s"):format(name))
|
||||
else
|
||||
fehler = fehler + 1
|
||||
print((" [FAIL ] %s%s"):format(name, zusatz and (" — " .. zusatz) or ""))
|
||||
end
|
||||
end
|
||||
|
||||
-- Faenger einhaengen
|
||||
local gesehen = {}
|
||||
M.sink = function(v, p, u)
|
||||
gesehen[#gesehen + 1] = { v = v, p = p, u = u }
|
||||
end
|
||||
local function zuruecksetzen() gesehen = {} end
|
||||
|
||||
pruefe("M.report existiert und ist aufrufbar", type(M.report) == "function")
|
||||
if type(M.report) ~= "function" then os.exit(1) end
|
||||
|
||||
-- 1. nil und Leerstring melden nichts
|
||||
zuruecksetzen()
|
||||
M.report(nil, "peerA", "uaA")
|
||||
M.report("", "peerA", "uaA")
|
||||
pruefe("nil und \"\" melden nichts", #gesehen == 0,
|
||||
("es kamen %d Meldungen"):format(#gesehen))
|
||||
|
||||
-- 2. erstes Tripel meldet genau einmal
|
||||
zuruecksetzen()
|
||||
M.report("2025-06-18", "peerA", "uaA")
|
||||
pruefe("erstes Tripel meldet einmal", #gesehen == 1)
|
||||
|
||||
-- 3. DER FALL, DER DREI RUNDEN LANG DURCHRUTSCHTE:
|
||||
-- Entprellung am ECHTEN Einstieg, ohne dass der Aufrufer Zustand mitgibt.
|
||||
zuruecksetzen()
|
||||
for _ = 1, 5 do M.report("2025-06-18", "peerA", "uaA") end
|
||||
pruefe("fuenf gleiche Tripel -> keine weitere Meldung", #gesehen == 0,
|
||||
("es kamen %d Meldungen; Zustand ueberlebt den Aufruf nicht")
|
||||
:format(#gesehen))
|
||||
|
||||
-- 4. gleiche Fassung, andere Gegenstelle -> meldet wieder
|
||||
zuruecksetzen()
|
||||
M.report("2025-06-18", "peerB", "uaA")
|
||||
pruefe("gleiche Fassung, andere Gegenstelle -> Meldung", #gesehen == 1,
|
||||
"Entprellung nur auf die Fassung wuerde andere Klienten maskieren")
|
||||
|
||||
-- 5. gleiche Fassung und Gegenstelle, anderer User-Agent -> meldet wieder
|
||||
zuruecksetzen()
|
||||
M.report("2025-06-18", "peerB", "uaZ")
|
||||
pruefe("anderer User-Agent -> Meldung", #gesehen == 1)
|
||||
|
||||
-- 6. liefert immer nil, lehnt nie ab
|
||||
local r1 = M.report("2026-07-28", "peerC", "uaC")
|
||||
local r2 = M.report("2026-07-28", "peerC", "uaC")
|
||||
pruefe("M.report liefert nil (lehnt nie ab)", r1 == nil and r2 == nil)
|
||||
|
||||
-- 7. Deckel bei 50
|
||||
zuruecksetzen()
|
||||
for i = 1, 80 do M.report("v" .. i, "peerD", "uaD") end
|
||||
pruefe("Deckel greift bei 50", #gesehen <= 50,
|
||||
("es kamen %d Meldungen"):format(#gesehen))
|
||||
pruefe("Deckel wirft nicht zu frueh", #gesehen >= 40,
|
||||
("nur %d Meldungen vor dem Deckel"):format(#gesehen))
|
||||
|
||||
-- 8. kein globaler Zustand
|
||||
local neue = {}
|
||||
for k in pairs(_G) do
|
||||
if not vorher_global[k] then neue[#neue + 1] = k end
|
||||
end
|
||||
pruefe("keine neuen globalen Variablen", #neue == 0,
|
||||
"hinzugekommen: " .. table.concat(neue, ", "))
|
||||
|
||||
print((" %d Pruefungen fehlgeschlagen"):format(fehler))
|
||||
os.exit(fehler == 0 and 0 or 1)
|
||||
@@ -0,0 +1,195 @@
|
||||
-- Abnahmetest fuer Phase B der Angleichung an MCP 2026-07-28.
|
||||
--
|
||||
-- Phase A war beobachtend: feststellen, welche Fassungen ueberhaupt verlangt
|
||||
-- werden. Phase B setzt durch. Gemessen am 2026-08-08 an hertz-tools:8080
|
||||
-- antwortet lmcp mit HTTP 200 auf JEDE Fassungsangabe - auch auf 1999-01-01,
|
||||
-- eine Fassung, die es nie gab. Es liest den Kopf schlicht nicht.
|
||||
--
|
||||
-- VERTRAG. Eine in sich geschlossene Lua-5.4-Datei, Tabelle M:
|
||||
--
|
||||
-- M.SUPPORTED Liste der Fassungen, die dieser Server spricht.
|
||||
-- M.check(version) -> true, nil wenn zulaessig
|
||||
-- -> false, <fehlertabelle> sonst
|
||||
--
|
||||
-- 1. version == nil oder "" -> zulaessig. Ein fehlender Kopf ist erlaubt;
|
||||
-- der Server nimmt dann seine Grundfassung an. Das ist kein Sonderfall
|
||||
-- aus Bequemlichkeit: die sitzungslose Abkuerzung schickt ihn oft nicht,
|
||||
-- und sie traegt den meisten Verkehr.
|
||||
-- 2. Genaue Uebereinstimmung mit einem Eintrag in M.SUPPORTED -> zulaessig.
|
||||
-- 3. Alles andere -> false plus Fehlertabelle mit code == -32022 und einer
|
||||
-- data.supported-Liste, die GENAU M.SUPPORTED entspricht. Ohne die Liste
|
||||
-- kann die Gegenstelle nicht nachverhandeln, sie kann nur aufgeben.
|
||||
-- 4. Wirft nie. Zahl, Tabelle, Wahrheitswert, Funktion - alles beantwortet
|
||||
-- sie mit false, nicht mit einem Laufzeitfehler. Ein Server, der an
|
||||
-- einem fremden Kopf stirbt, ist schlechter als einer, der ihn ignoriert.
|
||||
-- 5. Aendert M.SUPPORTED nicht. Ein Aufruf darf die Liste des naechsten
|
||||
-- nicht verschieben.
|
||||
-- 6. Keine neue globale Variable.
|
||||
--
|
||||
-- Aufruf: lua5.4 phase_b_acceptance.lua <impl.lua>
|
||||
|
||||
local impl_path = arg and arg[1]
|
||||
if not impl_path then
|
||||
io.stderr:write("usage: lua5.4 phase_b_acceptance.lua <impl.lua>\n")
|
||||
os.exit(2)
|
||||
end
|
||||
|
||||
-- Globale Variablen VOR dem Laden festhalten, damit Regel 6 pruefbar ist.
|
||||
local vorher = {}
|
||||
for k in pairs(_G) do vorher[k] = true end
|
||||
|
||||
local chunk, lerr = loadfile(impl_path)
|
||||
if not chunk then
|
||||
io.stderr:write("kann " .. impl_path .. " nicht laden: " .. tostring(lerr) .. "\n")
|
||||
os.exit(2)
|
||||
end
|
||||
local ok_load, M = pcall(chunk)
|
||||
if not ok_load then
|
||||
io.stderr:write("Laden warf: " .. tostring(M) .. "\n")
|
||||
os.exit(2)
|
||||
end
|
||||
|
||||
local fehler = 0
|
||||
local function pruefe(name, bedingung, detail)
|
||||
if bedingung then
|
||||
print(string.format("[ok ] %s", name))
|
||||
else
|
||||
fehler = fehler + 1
|
||||
print(string.format("[FEHLER] %s%s", name, detail and (" -> " .. tostring(detail)) or ""))
|
||||
end
|
||||
end
|
||||
|
||||
-- 0. Form
|
||||
pruefe("M ist eine Tabelle", type(M) == "table", type(M))
|
||||
if type(M) ~= "table" then print(fehler .. " Pruefungen fehlgeschlagen"); os.exit(1) end
|
||||
pruefe("M.check ist aufrufbar", type(M.check) == "function", type(M.check))
|
||||
pruefe("M.SUPPORTED ist eine nicht-leere Liste",
|
||||
type(M.SUPPORTED) == "table" and #M.SUPPORTED >= 1, type(M.SUPPORTED))
|
||||
if type(M.check) ~= "function" or type(M.SUPPORTED) ~= "table" then
|
||||
print(fehler .. " Pruefungen fehlgeschlagen"); os.exit(1)
|
||||
end
|
||||
|
||||
local function ruf(v)
|
||||
local ok, a, b = pcall(M.check, v)
|
||||
return ok, a, b
|
||||
end
|
||||
|
||||
-- 1. fehlender Kopf
|
||||
local ok, zulaessig = ruf(nil)
|
||||
pruefe("nil ist zulaessig", ok and zulaessig == true, ok and tostring(zulaessig) or "warf")
|
||||
ok, zulaessig = ruf("")
|
||||
pruefe("leerer String ist zulaessig", ok and zulaessig == true, ok and tostring(zulaessig) or "warf")
|
||||
|
||||
-- 2. bekannte Fassung
|
||||
local bekannt = M.SUPPORTED[1]
|
||||
ok, zulaessig = ruf(bekannt)
|
||||
pruefe("bekannte Fassung " .. tostring(bekannt) .. " ist zulaessig",
|
||||
ok and zulaessig == true, ok and tostring(zulaessig) or "warf")
|
||||
|
||||
-- 3. unbekannte Fassung -> -32022 samt Liste
|
||||
local ok3, zul3, err3 = ruf("1999-01-01")
|
||||
pruefe("unbekannte Fassung wird abgelehnt", ok3 and zul3 == false,
|
||||
ok3 and tostring(zul3) or "warf")
|
||||
pruefe("Ablehnung traegt code -32022",
|
||||
ok3 and type(err3) == "table" and err3.code == -32022,
|
||||
ok3 and type(err3) == "table" and tostring(err3.code) or type(err3))
|
||||
local liste_ok = false
|
||||
if ok3 and type(err3) == "table" and type(err3.data) == "table"
|
||||
and type(err3.data.supported) == "table" then
|
||||
liste_ok = (#err3.data.supported == #M.SUPPORTED)
|
||||
for i = 1, #M.SUPPORTED do
|
||||
if err3.data.supported[i] ~= M.SUPPORTED[i] then liste_ok = false end
|
||||
end
|
||||
end
|
||||
pruefe("Ablehnung nennt genau M.SUPPORTED", liste_ok)
|
||||
|
||||
-- 3b. die Fassung, auf die wir zuwandern, ist noch NICHT zulaessig.
|
||||
-- Wer 2026-07-28 durchwinkt, bevor er sie spricht, hat den Fehler nur verschoben.
|
||||
local ok3b, zul3b, err3b = ruf("2026-07-28")
|
||||
local spricht_neu = false
|
||||
for i = 1, #M.SUPPORTED do if M.SUPPORTED[i] == "2026-07-28" then spricht_neu = true end end
|
||||
if spricht_neu then
|
||||
pruefe("2026-07-28 steht in SUPPORTED und wird angenommen", ok3b and zul3b == true)
|
||||
else
|
||||
pruefe("2026-07-28 wird abgelehnt, solange sie nicht in SUPPORTED steht",
|
||||
ok3b and zul3b == false and type(err3b) == "table" and err3b.code == -32022,
|
||||
ok3b and tostring(zul3b) or "warf")
|
||||
end
|
||||
|
||||
-- 3c. VERANKERUNG: M.SUPPORTED gegen den LAUFENDEN Server.
|
||||
--
|
||||
-- Ohne diese Pruefung misst der Test die Liste nur an sich selbst -- und ein
|
||||
-- Modul, das eine Fassung beansprucht, die der Server nicht spricht, besteht
|
||||
-- ihn glatt. Genau das ist am 2026-08-08 passiert: {"2025-06-18","2025-11-25"}
|
||||
-- ergab 14/14, obwohl lmcp nur 2025-06-18 meldet.
|
||||
--
|
||||
-- Gefragt wird per `initialize`; die Antwort nennt genau EINE protocolVersion,
|
||||
-- naemlich die, die dieser Server spricht. M.SUPPORTED muss exakt daraus
|
||||
-- bestehen.
|
||||
--
|
||||
-- Kein Uebersprung, wenn der Server fehlt: eine Abnahme, die ihre zentrale
|
||||
-- Eigenschaft nicht pruefen kann, ist keine Abnahme.
|
||||
local probe_url = os.getenv("LMCP_PROBE_URL")
|
||||
local probe_token = os.getenv("LMCP_PROBE_TOKEN")
|
||||
pruefe("LMCP_PROBE_URL ist gesetzt (ohne Server keine Verankerung)",
|
||||
probe_url ~= nil and probe_url ~= "", tostring(probe_url))
|
||||
|
||||
if probe_url and probe_url ~= "" then
|
||||
local rumpf = '{"jsonrpc":"2.0","id":1,"method":"initialize","params":' ..
|
||||
'{"protocolVersion":"2025-06-18","capabilities":{},' ..
|
||||
'"clientInfo":{"name":"phase-b-acceptance","version":"1"}}}'
|
||||
local befehl = "curl -s -m 15 -X POST"
|
||||
.. " -H 'Content-Type: application/json'"
|
||||
.. " -H 'Accept: application/json, text/event-stream'"
|
||||
if probe_token and probe_token ~= "" then
|
||||
befehl = befehl .. " -H 'Authorization: Bearer " .. probe_token .. "'"
|
||||
end
|
||||
befehl = befehl .. " -d '" .. rumpf .. "' '" .. probe_url .. "' 2>/dev/null"
|
||||
|
||||
local p = io.popen(befehl)
|
||||
local antwort = p and p:read("*a") or ""
|
||||
if p then p:close() end
|
||||
|
||||
local gemessen = antwort:match('"protocolVersion"%s*:%s*"([^"]+)"')
|
||||
pruefe("Server nennt eine protocolVersion", gemessen ~= nil,
|
||||
(#antwort > 0) and antwort:sub(1, 70) or "keine Antwort")
|
||||
|
||||
if gemessen then
|
||||
local passt = (#M.SUPPORTED == 1) and (M.SUPPORTED[1] == gemessen)
|
||||
pruefe("M.SUPPORTED entspricht GENAU dem, was der Server spricht ("
|
||||
.. gemessen .. ")", passt, table.concat(M.SUPPORTED, ","))
|
||||
end
|
||||
end
|
||||
|
||||
-- 4. wirft nie
|
||||
local fremde = { 42, true, false, {}, print, 0/0 }
|
||||
local alle_still, welcher = true, nil
|
||||
for _, v in ipairs({42, true, {}, print}) do
|
||||
local okx, zulx = pcall(M.check, v)
|
||||
if not okx or zulx ~= false then alle_still = false; welcher = tostring(v) end
|
||||
end
|
||||
pruefe("fremde Typen ergeben false statt Laufzeitfehler", alle_still, welcher)
|
||||
|
||||
-- 5. SUPPORTED bleibt unangetastet
|
||||
local kopie = {}
|
||||
for i, v in ipairs(M.SUPPORTED) do kopie[i] = v end
|
||||
ruf("1999-01-01"); ruf(bekannt); ruf(nil)
|
||||
local unveraendert = (#kopie == #M.SUPPORTED)
|
||||
for i = 1, #kopie do if kopie[i] ~= M.SUPPORTED[i] then unveraendert = false end end
|
||||
pruefe("M.SUPPORTED wird durch Aufrufe nicht veraendert", unveraendert)
|
||||
|
||||
-- 5b. wiederholte Ablehnung bleibt gleich (kein verbrauchbarer Zustand)
|
||||
local _, _, e1 = ruf("1999-01-01")
|
||||
local _, _, e2 = ruf("1999-01-01")
|
||||
pruefe("zweite Ablehnung ist so vollstaendig wie die erste",
|
||||
type(e1) == "table" and type(e2) == "table"
|
||||
and e1.code == e2.code
|
||||
and type(e2.data) == "table" and type(e2.data.supported) == "table")
|
||||
|
||||
-- 6. keine neuen Globalen
|
||||
local neu = {}
|
||||
for k in pairs(_G) do if not vorher[k] then neu[#neu + 1] = tostring(k) end end
|
||||
pruefe("keine neuen globalen Variablen", #neu == 0, table.concat(neu, ","))
|
||||
|
||||
print(fehler .. " Pruefungen fehlgeschlagen")
|
||||
os.exit(fehler == 0 and 0 or 1)
|
||||
@@ -0,0 +1,124 @@
|
||||
-- Ausfuehrbare Zusicherung fuer LMCP_TOOL_ALLOW.
|
||||
--
|
||||
-- Hintergrund: eine lmcp-Instanz konnte ihren Werkzeugsatz nur ERWEITERN.
|
||||
-- tools.d-Dateien fuegen hinzu; der Grundstock aus server.lua bringt shell,
|
||||
-- write_file und Verwandte mit, und eine Plugin-Datei kann nichts wegnehmen.
|
||||
-- Am 2026-08-08 hatte damit jeder Agent mit dem Raum-Token eine Wurzelschale
|
||||
-- im Raum-Container -- nachgewiesen: uid=0(root), Schreibzugriff auf
|
||||
-- room.jsonl. Das ist keine Einbruchsluecke (eine Sicherheitsdomaene), aber
|
||||
-- es macht jede Aussage ueber Rollentrennung unbelegbar.
|
||||
--
|
||||
-- Geprueft wird an der REGISTRIERUNG, nicht nachtraeglich loeschend: was nicht
|
||||
-- auf der Liste steht, entsteht gar nicht -- fuer Built-ins wie fuer Plugins,
|
||||
-- heute wie fuer alles, was spaeter dazukommt.
|
||||
--
|
||||
-- Aufruf: lua5.4 tests/test_tool_allow.lua
|
||||
|
||||
local hier = arg[0]:match('(.*/)') or './'
|
||||
-- VORNE anhaengen, nicht hinten. Sonst gewinnt die INSTALLIERTE Fassung unter
|
||||
-- /usr/share/lua/5.4/lmcp.lua, und der Test prueft nicht den Baum, in dem er
|
||||
-- liegt -- gemessen am 2026-08-08: der Test gab rot, obwohl der Code stimmte.
|
||||
package.path = hier .. '../?.lua;' .. package.path
|
||||
|
||||
local fehler = 0
|
||||
local function pruefe(name, bedingung, detail)
|
||||
if bedingung then
|
||||
print(string.format("[ok ] %s", name))
|
||||
else
|
||||
fehler = fehler + 1
|
||||
print(string.format("[FEHLER] %s%s", name, detail and (" -> " .. tostring(detail)) or ""))
|
||||
end
|
||||
end
|
||||
|
||||
local function namen(server)
|
||||
local t = {}
|
||||
for n in pairs(server.tools) do t[#t + 1] = n end
|
||||
table.sort(t)
|
||||
return t
|
||||
end
|
||||
|
||||
local function enthaelt(liste, wert)
|
||||
for _, v in ipairs(liste) do if v == wert then return true end end
|
||||
return false
|
||||
end
|
||||
|
||||
-- lmcp frisch laden, damit die Umgebungsvariable beim Anlegen gilt.
|
||||
local function frisch()
|
||||
package.loaded['lmcp'] = nil
|
||||
return require('lmcp')
|
||||
end
|
||||
|
||||
local leer = { type = "object" }
|
||||
local function nichts() return "x" end
|
||||
|
||||
-- 1. Ohne die Variable aendert sich nichts (Rueckwaertsvertraeglichkeit).
|
||||
-- Nur im ELTERNLAUF: im Kind ist die Liste gesetzt, dort waere die Aussage
|
||||
-- falsch und der Test wuerde sich selbst widerlegen.
|
||||
if os.getenv("LMCP_TOOL_ALLOW") == nil then
|
||||
local lmcp = frisch()
|
||||
local s = lmcp.new("probe-offen", { port = 0 })
|
||||
s:tool("room_say", "d", leer, nichts)
|
||||
s:tool("shell", "d", leer, nichts)
|
||||
local n = namen(s)
|
||||
pruefe("ohne LMCP_TOOL_ALLOW bleibt alles registriert",
|
||||
enthaelt(n, "room_say") and enthaelt(n, "shell"), table.concat(n, ","))
|
||||
end
|
||||
|
||||
-- Ab hier mit Liste. lmcp liest sie beim Anlegen der Instanz, also muss sie
|
||||
-- VOR lmcp.new() in der Umgebung stehen -- in Lua nur ueber einen Kindprozess
|
||||
-- setzbar, deshalb startet der Test sich selbst neu.
|
||||
if os.getenv("LMCP_TOOL_ALLOW") == nil then
|
||||
local eigen = arg[0]
|
||||
local rc = os.execute(
|
||||
'LMCP_TOOL_ALLOW="room_say,room_read,lease_acquire" lua5.4 "' .. eigen .. '" --kind')
|
||||
local ok = (rc == true or rc == 0)
|
||||
pruefe("Teillauf mit gesetzter Liste besteht", ok, tostring(rc))
|
||||
print(fehler .. " Pruefungen fehlgeschlagen")
|
||||
os.exit(fehler == 0 and 0 or 1)
|
||||
end
|
||||
|
||||
-- --- Kindlauf: LMCP_TOOL_ALLOW ist gesetzt -----------------------------------
|
||||
do
|
||||
local lmcp = frisch()
|
||||
local s = lmcp.new("probe-eng", { port = 0 })
|
||||
|
||||
-- erlaubt
|
||||
s:tool("room_say", "d", leer, nichts)
|
||||
s:tool("room_read", "d", leer, nichts)
|
||||
s:tool("lease_acquire", "d", leer, nichts)
|
||||
-- nicht erlaubt: genau die, die die Wurzelschale ausmachten
|
||||
s:tool("shell", "d", leer, nichts)
|
||||
s:tool("shell_bg", "d", leer, nichts)
|
||||
s:tool("write_file", "d", leer, nichts)
|
||||
s:tool("edit_file", "d", leer, nichts)
|
||||
s:tool("read_file", "d", leer, nichts)
|
||||
|
||||
local n = namen(s)
|
||||
pruefe("erlaubte Werkzeuge sind da",
|
||||
enthaelt(n, "room_say") and enthaelt(n, "room_read") and enthaelt(n, "lease_acquire"),
|
||||
table.concat(n, ","))
|
||||
pruefe("shell ist NICHT registriert", not enthaelt(n, "shell"))
|
||||
pruefe("shell_bg ist NICHT registriert", not enthaelt(n, "shell_bg"))
|
||||
pruefe("write_file ist NICHT registriert", not enthaelt(n, "write_file"))
|
||||
pruefe("edit_file ist NICHT registriert", not enthaelt(n, "edit_file"))
|
||||
pruefe("read_file ist NICHT registriert", not enthaelt(n, "read_file"))
|
||||
pruefe("genau drei Werkzeuge uebrig", #n == 3, table.concat(n, ","))
|
||||
|
||||
-- Der Kern: `tools/list` und `tools/call` lesen DASSELBE Register. Ein
|
||||
-- nicht registriertes Werkzeug ist also nicht bloss unsichtbar, es ist
|
||||
-- nicht rufbar. Waere es nur aus der Liste gefiltert, bliebe es erreichbar.
|
||||
pruefe("verweigertes Werkzeug ist auch nicht aufrufbar",
|
||||
s.tools["shell"] == nil)
|
||||
|
||||
-- Die Registrierung darf nicht werfen: ein Plugin, das ein gesperrtes
|
||||
-- Werkzeug anbietet, soll weiterlaufen, nicht abstuerzen.
|
||||
local ok = pcall(function() s:tool("shell", "d", leer, nichts) end)
|
||||
pruefe("Registrierung eines gesperrten Werkzeugs wirft nicht", ok)
|
||||
|
||||
-- Verkettung muss erhalten bleiben (tool() gibt self zurueck).
|
||||
local zurueck = s:tool("shell", "d", leer, nichts)
|
||||
pruefe("tool() liefert weiterhin self (verkettbar)", zurueck == s)
|
||||
end
|
||||
|
||||
print(fehler .. " Pruefungen fehlgeschlagen")
|
||||
os.exit(fehler == 0 and 0 or 1)
|
||||
@@ -0,0 +1,30 @@
|
||||
-- boltzmann-tools plugin: `stash` — fleet persistent-memory CLI wrapper.
|
||||
-- Receives (server, run). Runs the stash CLI inside the memory Incus container's
|
||||
-- stash-stash-1 docker container (which has NO shell — /stash is invoked directly
|
||||
-- as argv; docker exec handles that, no `sh -c` inside the container).
|
||||
local server, run = ...
|
||||
|
||||
server:tool("stash",
|
||||
"Fleet persistent memory (stash knowledge graph on the memory container). "
|
||||
.. "`command` = a stash subcommand + its args as ONE string. "
|
||||
.. "Examples: command:=\"recall escher plug AIN\" | command:=\"facts\" | "
|
||||
.. "command:=\"remember 'the NAS is at 192.168.88.10'\" | command:=\"namespace list\". "
|
||||
.. "Wrap multi-word text in single quotes. Read subcommands: recall, facts, namespace list, "
|
||||
.. "goal list, context show. Write: remember, forget, consolidate run.",
|
||||
{ type = "object", properties = {
|
||||
command = { type = "string",
|
||||
description = "stash subcommand + args, e.g. \"recall <query>\" or \"remember '<text>'\"" },
|
||||
}, required = { "command" } },
|
||||
function(a)
|
||||
local c = tostring(a.command or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
||||
if c == "" then return "Error: command required (e.g. command:=\"recall <query>\")" end
|
||||
return run("incus exec memory -- docker exec stash-stash-1 /stash " .. c, 60)
|
||||
end,
|
||||
{ annotations = {
|
||||
title = "Stash fleet memory",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = false,
|
||||
idempotentHint = false,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
@@ -1,103 +0,0 @@
|
||||
-- /opt/lmcp/tools.d/nash.lua -- nash shared memory tools
|
||||
--
|
||||
-- Provides add/search/list/delete tools for the nash memory service.
|
||||
-- Requires NASH_URL env var (e.g. http://192.168.88.143:8000).
|
||||
-- When unset, tools return an error guiding the user to set it.
|
||||
--
|
||||
-- SPDX-License-Identifier: MIT
|
||||
|
||||
local server, run = ...
|
||||
|
||||
local function nash_url()
|
||||
local url = os.getenv("NASH_URL")
|
||||
if not url or url == "" then return nil end
|
||||
return url:gsub("/+$", "")
|
||||
end
|
||||
|
||||
local function curl_json(url, method, body, timeout)
|
||||
timeout = timeout or 10
|
||||
local out = "/tmp/lmcp-nash-" .. os.time() .. "-" .. math.random(10000, 99999) .. ".json"
|
||||
local fmt = "http_code=%{http_code}"
|
||||
local cmd
|
||||
if body then
|
||||
local tmp = out .. ".req"
|
||||
local f = io.open(tmp, "w")
|
||||
if f then f:write(body); f:close() end
|
||||
cmd = string.format(
|
||||
"curl -sS -X %s --max-time %d -H 'Content-Type: application/json' --data-binary '@%s' -o '%s' -w '%s' '%s'",
|
||||
method, timeout, tmp, out, fmt, url
|
||||
)
|
||||
os.execute("rm -f '" .. tmp .. "' 2>/dev/null")
|
||||
else
|
||||
cmd = string.format(
|
||||
"curl -sS -X %s --max-time %d -o '%s' -w '%s' '%s'",
|
||||
method, timeout, out, fmt, url
|
||||
)
|
||||
end
|
||||
local raw = run(cmd, timeout + 5) or ""
|
||||
local http_code = tonumber(raw:match("(%d+)$")) or 0
|
||||
local body_out = ""
|
||||
local f = io.open(out, "r")
|
||||
if f then body_out = f:read("*a") or ""; f:close() end
|
||||
os.execute("rm -f '" .. out .. "' 2>/dev/null")
|
||||
return body_out, http_code
|
||||
end
|
||||
|
||||
server:tool("nash_add", "Store a text entry in shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
text = { type = "string", description = "Text content to remember" },
|
||||
},
|
||||
required = { "text" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local json, code = curl_json(base .. "/add", "POST", '{"text":' .. require("json").encode(a.text) .. '}')
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_search", "Semantic search across shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
query = { type = "string", description = "Search query" },
|
||||
limit = { type = "integer", description = "Max results (default 5)", default = 5 },
|
||||
},
|
||||
required = { "query" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"query":' .. require("json").encode(a.query) .. ',"limit":' .. (a.limit or 5) .. '}'
|
||||
local json, code = curl_json(base .. "/search", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_list", "List all entries in shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
limit = { type = "integer", description = "Max results (default 100)", default = 100 },
|
||||
},
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"limit":' .. (a.limit or 100) .. '}'
|
||||
local json, code = curl_json(base .. "/scroll", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_delete", "Delete an entry from shared nash memory by ID.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
id = { type = "string", description = "Entry ID to delete" },
|
||||
},
|
||||
required = { "id" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"id":' .. require("json").encode(a.id) .. '}'
|
||||
local json, code = curl_json(base .. "/delete", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
@@ -0,0 +1,36 @@
|
||||
-- versions.lua
|
||||
-- Modul zur Versionspruefung gemaess LMCP-Vertrag
|
||||
|
||||
local M = {}
|
||||
|
||||
M.SUPPORTED = {"2025-06-18"}
|
||||
|
||||
--- Prueft, ob eine Version unterstuetzt wird.
|
||||
-- @param version Die zu pruefende Version (String oder nil)
|
||||
-- @return boolean true wenn unterstuetzt, sonst false
|
||||
-- @return table|nil Fehlerdetails bei Nichtunterstuetzung
|
||||
function M.check(version)
|
||||
-- (a) version == nil oder "" -> true, nil
|
||||
if version == nil or version == "" then
|
||||
return true, nil
|
||||
end
|
||||
|
||||
-- (b) exakter Treffer in M.SUPPORTED -> true, nil
|
||||
for _, supported_version in ipairs(M.SUPPORTED) do
|
||||
if version == supported_version then
|
||||
return true, nil
|
||||
end
|
||||
end
|
||||
|
||||
-- (c) alles andere -> false, { code = -32022, data = { supported = M.SUPPORTED } }
|
||||
return false, {
|
||||
code = -32022,
|
||||
data = {
|
||||
supported = M.SUPPORTED
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
-- Keine neuen Globalen, keine Seiteneffekte, M.SUPPORTED wird nicht geaendert
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user