diff --git a/README.md b/README.md index 52d69cb..4491a4a 100644 --- a/README.md +++ b/README.md @@ -213,8 +213,14 @@ bündelt **dieselben** Funktionen: `unraid_docker` (`action: list|logs|restart|u - Es enthält nur freigegebene Aktionen. Die `action`-Liste wird pro Anfrage aus den Tool-Freigaben erzeugt; es entsteht keine neue Berechtigung. -- Schema-Größe gemessen: „Nur Lesen“ ≈ 1,6k statt 2,9k Tokens, Vollzugriff - ≈ 3,3k statt 6,9k Tokens. +- Schema-Größe gemessen: „Nur Lesen“ ≈ 1,7k statt 2,9k Tokens, Vollzugriff + ≈ 3,8k statt 6,9k Tokens. +- Die Verhaltensregeln des vollen Profils (z.B. „update nur auf ausdrücklichen + Wunsch“, „Programme nur in der Toolbox installieren“, „_apply nur für die + bestätigte Vorschau“) stehen als kurze `Rules:` in der Gruppenbeschreibung – + jeweils nur, wenn die betreffende Aktion freigegeben ist. +- Gleichbedeutende Werte werden je Ziel-Tool übersetzt (`detail: summary` bei + `list` → `compact`, `state: active` → `running`, `severity: errors` → `error`). - Typische Verwechslungen werden toleriert (`name` statt `container`, `cmd` statt `command`, `Update-Status` statt `update_status`); unbekannte Parameter werden ignoriert und im Ergebnis genannt. diff --git a/dist/mua-2026.11.21.r037-x86_64-1.txz.sha256 b/dist/mua-2026.11.21.r037-x86_64-1.txz.sha256 deleted file mode 100644 index f929e5d..0000000 --- a/dist/mua-2026.11.21.r037-x86_64-1.txz.sha256 +++ /dev/null @@ -1 +0,0 @@ -3ead78bbccbe9f3e8d629c2abfb7878bf3780ffbd815cef2c38cb56b5cfeb828 mua-2026.11.21.r037-x86_64-1.txz diff --git a/dist/mua-2026.11.21.r037-x86_64-1.txz b/dist/mua-2026.11.21.r038-x86_64-1.txz similarity index 71% rename from dist/mua-2026.11.21.r037-x86_64-1.txz rename to dist/mua-2026.11.21.r038-x86_64-1.txz index 7e0da72..214fe2d 100644 Binary files a/dist/mua-2026.11.21.r037-x86_64-1.txz and b/dist/mua-2026.11.21.r038-x86_64-1.txz differ diff --git a/dist/mua-2026.11.21.r038-x86_64-1.txz.sha256 b/dist/mua-2026.11.21.r038-x86_64-1.txz.sha256 new file mode 100644 index 0000000..7fd8612 --- /dev/null +++ b/dist/mua-2026.11.21.r038-x86_64-1.txz.sha256 @@ -0,0 +1 @@ +bdef4eaf4faf61e43c32b557f653fc55e9bfb93770d8956891e6807036d350e5 mua-2026.11.21.r038-x86_64-1.txz diff --git a/package.json b/package.json index 84ddc87..0c28e3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mua", - "version": "2026.11.21.r037", + "version": "2026.11.21.r038", "description": "Mikes Unraid Agent - MCP over HTTP(S) (Streamable HTTP) for Unraid", "type": "module", "main": "src/index.ts", diff --git a/plugin/mua.plg b/plugin/mua.plg index a9ab9e6..104980e 100644 --- a/plugin/mua.plg +++ b/plugin/mua.plg @@ -2,13 +2,13 @@ - + - - + + ]> +### 2026.11.21.r038 +- Lite-Profil übernimmt die Verhaltensregeln des vollen Profils als kurze „Rules“: Updates nur auf ausdrücklichen Wunsch, exakte Containernamen für Änderungen, *_apply nur für die bestätigte Vorschau, Root-Shell nur für ausdrücklich verlangte Aufgaben, Programme nur in der Toolbox installieren, Jobs nicht doppelt starten u.a. Eine Regel erscheint nur, wenn ihre Aktion freigegeben ist. +- Gleichbedeutende Werte werden je Ziel-Tool übersetzt (detail summary/compact, state active → running, severity errors → error). +- Schema-Größe Lite: „Nur Lesen“ ca. 1,7k, Vollzugriff ca. 3,8k Tokens (volles Profil 2,9k bzw. 6,9k). + ### 2026.11.21.r037 - Neues kompaktes Profil für kleine Modelle unter `/mcp/lite` (oder `?profile=lite`, Standard per `MUA_PROFILE`): dieselben Funktionen in 9 Gruppen-Tools mit `action` statt 49 Einzeltools. Bei „Nur Lesen“ ca. 1,6k statt 2,9k Tokens Schema, bei Vollzugriff ca. 3,3k statt 6,9k. - Lite-Schemas enthalten nur freigegebene Aktionen; Berechtigungen werden immer am zugrunde liegenden Tool geprüft. Typische Verwechslungen (name/container, cmd/command, Schreibweise der Aktion) werden toleriert, fehlende Pflichtparameter klar benannt. @@ -230,7 +235,7 @@ Das .txz enthält: install/doinst.sh (läuft nach Installation) =========================================== --> - + &txzURL; &txzSHA256; diff --git a/plugin/plugin.json b/plugin/plugin.json index c21cda9..724ec08 100644 --- a/plugin/plugin.json +++ b/plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "mua", "author": "Michael", - "version": "2026.11.21.r037", + "version": "2026.11.21.r038", "minver": "7.0.0", "pluginDirectory": "/usr/local/emhttp/plugins/mua", "configDirectory": "/boot/config/plugins/mua", diff --git a/src/helpers.ts b/src/helpers.ts index 1cf00e7..4caa472 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -19,7 +19,7 @@ import { redactKnownSecrets } from "./redact"; // ── Konstanten ────────────────────────────────────────────────────────── export const MUA_SERVER_NAME = "mua"; -export const MUA_VERSION = "2026.11.21.r037"; +export const MUA_VERSION = "2026.11.21.r038"; export const MUA_PROTOCOL_VERSION = "2025-03-26"; export const PHP_HELPER = "/usr/local/bin/unraid-docker-mcp-helper.php"; export const STATUS_HELPER = "/usr/local/bin/unraid-mcp-status-helper.php"; diff --git a/src/lite.test.ts b/src/lite.test.ts index d231ba8..3ea9905 100644 --- a/src/lite.test.ts +++ b/src/lite.test.ts @@ -21,7 +21,7 @@ describe("lite profile: tools/list", () => { "unraid_overview", "unraid_shell_readonly", "unraid_docker", "unraid_storage", "unraid_network", "unraid_system", "unraid_apps", "unraid_shell", "unraid_toolbox", ]); - expect(schemaSize(lite)).toBeLessThan(schemaSize(full) * 0.55); + expect(schemaSize(lite)).toBeLessThan(schemaSize(full) * 0.6); }); test("every full-profile tool is reachable through a listed lite tool/action", async () => { @@ -323,3 +323,45 @@ describe("unraid_overview", () => { expect(o.summary.storage.parity).toBe("check P running 25%"); }); }); + +describe("r038: behavioural rules and enum synonyms", () => { + const group = (name: string, isAvailable: (n: string) => boolean) => + listTools({ profile: "lite", isAvailable }).find((t) => t.name === name)!; + + test("rules from the full descriptions are carried over", () => { + const docker = group("unraid_docker", ALL).description; + expect(docker).toContain("update only when the user explicitly asked"); + expect(docker).toContain("exact container name"); + const shell = group("unraid_shell", ALL).description; + expect(shell).toContain("run only for what the user explicitly asked"); + expect(shell).toContain("never start a duplicate"); + expect(group("unraid_toolbox", ALL).description).toContain("never in the MCP client"); + expect(group("unraid_apps", ALL).description).toContain("explicit approval"); + expect(group("unraid_storage", ALL).description).toContain("denies every user not listed"); + }); + + test("a rule only appears when its action is enabled, and only once", () => { + const readOnly = group("unraid_docker", only("unraid_docker_list", "unraid_docker_logs")).description; + expect(readOnly).toContain("state=running"); + expect(readOnly).not.toContain("update only when"); + expect(readOnly).not.toContain("exact container name"); + const operator = group("unraid_docker", only("unraid_docker_list", "unraid_docker_start", "unraid_docker_stop")).description; + expect(operator.match(/exact container name/g)?.length).toBe(1); + }); + + test("equivalent enum values are translated per target tool", async () => { + expect((await prepareCall("unraid_docker", { action: "list", detail: "summary" }, ctx(ALL))).args).toEqual({ detail: "compact" }); + expect((await prepareCall("unraid_docker", { action: "inspect", container: "Sonarr", detail: "compact" }, ctx(ALL))).args) + .toEqual({ container: "Sonarr", detail: "summary" }); + expect((await prepareCall("unraid_docker", { action: "list", state: "active" }, ctx(ALL))).args).toEqual({ state: "running" }); + expect((await prepareCall("unraid_docker", { action: "analyze_logs", severity: "errors" }, ctx(ALL))).args).toEqual({ severity: "error" }); + // Unbekannte Werte bleiben unverändert, damit das Tool selbst klar ablehnt. + expect((await prepareCall("unraid_docker", { action: "list", state: "bogus" }, ctx(ALL))).args).toEqual({ state: "bogus" }); + }); + + test("lite stays clearly smaller than full, also with rules", () => { + const full = listTools({ profile: "full", isAvailable: ALL }); + const lite = listTools({ profile: "lite", isAvailable: ALL }); + expect(schemaSize(lite)).toBeLessThan(schemaSize(full) * 0.6); + }); +}); diff --git a/src/profiles.ts b/src/profiles.ts index e1d79a3..cda7340 100644 --- a/src/profiles.ts +++ b/src/profiles.ts @@ -23,6 +23,11 @@ interface LiteAction { tool: string; /** Ein Satz für die Gruppenbeschreibung. */ summary: string; + /** + * Verhaltensregel aus der ausführlichen Beschreibung des vollen Profils. + * Erscheint nur, wenn die Aktion freigegeben ist. + */ + rule?: string; /** Lite-Parametername → Parametername des Ziel-Tools. */ rename?: Record; /** Ausweich-Ziel, falls `tool` nicht freigegeben ist. */ @@ -40,6 +45,7 @@ interface LiteGroup { } const OPERATION = { operation: "action" }; +const EXACT_NAME = "Changes (start/stop/restart/modify/update/rebuild) need the exact container name from list."; /** ["a","b"] / "a, b" / "a|b" / "a" → "a|b", wie unraid_docker_update_verified_batch es erwartet. */ export function joinContainers(args: Record): Record { @@ -88,26 +94,27 @@ export const LITE_GROUPS: LiteGroup[] = [ intro: "Docker containers on Unraid.", aliases: { name: "container", id: "container", lines: "tail" }, actions: { - list: { tool: "unraid_docker_list", summary: "containers with state (filter by state)" }, + list: { tool: "unraid_docker_list", summary: "containers with state (filter by state)", rule: "For \"what is running\" use state=running; include_stats only when CPU/RAM is asked." }, inspect: { tool: "unraid_docker_inspect", summary: "config, ports, mounts (env values redacted)" }, logs: { tool: "unraid_docker_logs", summary: "last log lines" }, - analyze_logs: { tool: "unraid_docker_analyze_logs", summary: "find errors/warnings in logs, one or all containers" }, + analyze_logs: { tool: "unraid_docker_analyze_logs", summary: "find errors/warnings in logs, one or all containers", rule: "Prefer one analyze_logs call with focus_terms over many logs calls." }, processes: { tool: "unraid_docker_processes", summary: "processes inside a container" }, stats: { tool: "unraid_docker_stats", summary: "CPU/RAM/IO of running containers" }, info: { tool: "unraid_docker_info", summary: "Docker engine info" }, - update_status: { tool: "unraid_docker_update_status", summary: "which containers have updates" }, - start: { tool: "unraid_docker_start", summary: "start" }, - stop: { tool: "unraid_docker_stop", summary: "stop" }, - restart: { tool: "unraid_docker_restart", summary: "restart" }, + update_status: { tool: "unraid_docker_update_status", summary: "which containers have updates", rule: "If status_complete is false, updates_available is only a minimum: name the unknown containers." }, + start: { tool: "unraid_docker_start", summary: "start", rule: EXACT_NAME }, + stop: { tool: "unraid_docker_stop", summary: "stop", rule: EXACT_NAME }, + restart: { tool: "unraid_docker_restart", summary: "restart", rule: EXACT_NAME }, update: { tool: "unraid_docker_update_verified_batch", fallback: "unraid_docker_update", summary: "pull new image and recreate (one or comma-separated list)", prepare: joinContainers, + rule: "update only when the user explicitly asked for it. Already current containers are skipped; running/stopped state is kept.", }, create: { tool: "unraid_docker_create", summary: "create from a saved Unraid template" }, - modify: { tool: "unraid_docker_modify", summary: "change port/env/volume/network/privileged" }, - rebuild: { tool: "unraid_docker_rebuild", summary: "recreate from its template" }, + modify: { tool: "unraid_docker_modify", summary: "change port/env/volume/network/privileged", rule: EXACT_NAME }, + rebuild: { tool: "unraid_docker_rebuild", summary: "recreate from its template", rule: EXACT_NAME }, template_preview: { tool: "unraid_docker_template_preview", rename: OPERATION, summary: "preview creating/removing a template; returns approval_ticket" }, - template_apply: { tool: "unraid_docker_template_apply", summary: "apply a previewed template change" }, + template_apply: { tool: "unraid_docker_template_apply", summary: "apply a previewed template change", rule: "*_apply: only the exact preview the user approved; never invent an approval_ticket." }, }, }, { @@ -116,15 +123,15 @@ export const LITE_GROUPS: LiteGroup[] = [ aliases: { share_name: "share", disk_name: "disk", path: "relative_path" }, actions: { status: { tool: "unraid_storage_status", summary: "array, parity, pools, disk alerts" }, - disks: { tool: "unraid_disk_health", summary: "SMART/errors/temperature, one or all disks" }, + disks: { tool: "unraid_disk_health", summary: "SMART/errors/temperature, one or all disks", rule: "disks uses cached SMART data and never spins disks up; diagnose smart for full detail." }, diagnose: { tool: "unraid_storage_diagnostics", rename: OPERATION, summary: "zfs_pool|zfs_dataset|zfs_snapshots|smart|parity_history" }, shares: { tool: "unraid_shares_list", summary: "all shares with usage" }, share: { tool: "unraid_share_inspect", summary: "one share in detail" }, - files: { tool: "unraid_files_inventory", summary: "list folders/files inside a share (metadata only)" }, + files: { tool: "unraid_files_inventory", summary: "list folders/files inside a share (metadata only)", rule: "files: find a folder with name_contains first, then call again with it as relative_path. Never reads file contents." }, share_users: { tool: "unraid_share_users", summary: "SMB users" }, share_permissions: { tool: "unraid_share_permissions", summary: "who can access a share" }, - share_preview: { tool: "unraid_share_preview", rename: OPERATION, summary: "preview create/permissions/remove; returns approval_ticket" }, - share_apply: { tool: "unraid_share_apply", summary: "apply a previewed share change" }, + share_preview: { tool: "unraid_share_preview", rename: OPERATION, summary: "preview create/permissions/remove; returns approval_ticket", rule: "Check share_users first: a permissions change denies every user not listed. Only empty shares can be removed." }, + share_apply: { tool: "unraid_share_apply", summary: "apply a previewed share change", rule: "share_apply: only the exact preview the user approved." }, }, }, { @@ -154,9 +161,9 @@ export const LITE_GROUPS: LiteGroup[] = [ intro: "Community Applications (app store).", aliases: { name: "container_name", app: "app_id", search: "query", q: "query" }, actions: { - search: { tool: "unraid_ca_search", summary: "find apps" }, + search: { tool: "unraid_ca_search", summary: "find apps", rule: "Put up to 5 name variants into one query separated by | instead of repeated searches." }, install_preview: { tool: "unraid_ca_install_preview", summary: "preview an install; returns approval_ticket" }, - install: { tool: "unraid_ca_install", summary: "install after preview" }, + install: { tool: "unraid_ca_install", summary: "install after preview", rule: "install only after install_preview and the user's explicit approval (confirm=true + approval_ticket)." }, }, }, { @@ -164,8 +171,8 @@ export const LITE_GROUPS: LiteGroup[] = [ intro: "Root shell on the Unraid host (critical). For read-only diagnosis prefer unraid_shell_readonly.", aliases: { cmd: "command", script: "command", id: "job_id", timeout: "timeout_seconds" }, actions: { - run: { tool: "unraid_system_shell", summary: "run a command/script as root (≤30 min)" }, - job_start: { tool: "unraid_system_job_start", summary: "start a long job in background, returns job_id" }, + run: { tool: "unraid_system_shell", summary: "run a command/script as root (≤30 min)", rule: "run only for what the user explicitly asked (edit files, docker commands, install, admin). Prefer unraid_docker/unraid_storage actions when they cover it. Do not inspect MUA itself or route commands through the client's own terminal." }, + job_start: { tool: "unraid_system_job_start", summary: "start a long job in background, returns job_id", rule: "job_start only for work over 30 min; poll job_status and never start a duplicate while one is running." }, job_status: { tool: "unraid_system_job_status", summary: "state and output tail of a job" }, job_cancel: { tool: "unraid_system_job_cancel", summary: "stop a running job" }, job_cleanup: { tool: "unraid_system_job_cleanup", summary: "delete logs of a finished job" }, @@ -176,8 +183,8 @@ export const LITE_GROUPS: LiteGroup[] = [ intro: "Optional agent toolbox container (ffmpeg, yt-dlp, …).", aliases: { cmd: "command", timeout: "timeout_seconds" }, actions: { - status: { tool: "unraid_toolbox_status", summary: "which programs are installed" }, - exec: { tool: "unraid_toolbox_exec", summary: "run a command inside the toolbox" }, + status: { tool: "unraid_toolbox_status", summary: "which programs are installed", rule: "Check status first when a CLI program (ffmpeg, yt-dlp, …) may be missing." }, + exec: { tool: "unraid_toolbox_exec", summary: "run a command inside the toolbox", rule: "Install missing programs only inside this toolbox, never in the MCP client or agent container." }, }, }, ]; @@ -230,6 +237,7 @@ export function buildLiteTools( action: { type: "string", enum: enabled.map(([n]) => n), description: "What to do (see tool description)" }, }; const lines: string[] = []; + const rules: string[] = []; for (const [actionName, action, tool] of enabled) { const schema = tool.inputSchema as Schema; const required = new Set(schema.required ?? []); @@ -251,10 +259,12 @@ export function buildLiteTools( const level = riskOf(tool.name); const risk = level === "critical" ? " [critical]" : level === "write" ? " [changes state]" : ""; lines.push(`- ${actionName}${params.length ? `(${params.join(", ")})` : ""}: ${action.summary}${risk}`); + if (action.rule && !rules.includes(action.rule)) rules.push(action.rule); } out.push({ name: group.name, - description: `${group.intro} Pick an action; * = required.\n${lines.join("\n")}`, + description: `${group.intro} Pick an action; * = required.\n${lines.join("\n")}` + + (rules.length ? `\nRules:\n${rules.map((r) => `- ${r}`).join("\n")}` : ""), inputSchema: { type: "object", properties, required: ["action"], additionalProperties: false }, handler: async () => { throw new Error("lite group tools are dispatched, not called directly"); }, }); @@ -262,6 +272,13 @@ export function buildLiteTools( return out; } +const ENUM_SYNONYMS: Record = { + summary: ["compact"], compact: ["summary"], short: ["compact", "summary"], brief: ["compact", "summary"], + detailed: ["full"], details: ["full"], all: ["full"], + active: ["running"], up: ["running"], down: ["stopped"], inactive: ["stopped"], exited: ["stopped"], + warning: ["warn"], warnings: ["warn"], errors: ["error"], err: ["error"], +}; + export interface ResolvedCall { tool: string; args: Record; @@ -336,6 +353,15 @@ export function resolveLiteCall( if (!known.has("name") && known.has("share") && args["name"] !== undefined && args["share"] === undefined) { args["share"] = args["name"]; delete args["name"]; } + // Gemischte Enums im Gruppenschema (z.B. detail: list kennt compact|full, + // inspect kennt summary|full): gleichbedeutende Werte still übersetzen. + for (const [key, value] of Object.entries(args)) { + const allowed: unknown[] | undefined = (schema.properties?.[key] as any)?.enum; + if (typeof value === "string" && allowed && !allowed.includes(value)) { + const synonym = ENUM_SYNONYMS[value.toLowerCase()]?.find((v) => allowed.includes(v)); + if (synonym) args[key] = synonym; + } + } const ignored = Object.keys(args).filter((k) => !known.has(k)); for (const k of ignored) delete args[k]; const missing = (schema.required ?? []).filter((r) => args[r] === undefined || args[r] === "");