-- pmacs-mcp-prompts/init.lua --- T M9.7 prompts-as-result-buffers. -- -- Public API: -- -- local mcp_prompts = require("pmacs-mcp-prompts") -- mcp_prompts.register(server) -- fetch prompts/list, define each as a command -- mcp_prompts.unregister(server) -- drop the server's commands -- mcp_prompts.commands_for(server) -- list of registered command names -- mcp_prompts.command_name(label, prompt) -- compute the normalized command name -- -- Spec interpretation (T M9.7): -- -- Invoking a prompt with arguments produces a *result buffer*; the -- buffer's view interprets the result format (text / code / markdown). -- Format determination is *explicit* via `_meta.format` on the -- `prompts/get` response — the package does not infer format from -- content. Recognized values: `"text"`, `"code"`, `"markdown"`. -- Anything else (or absent) falls back to text rendering with a -- logged warning. Servers that want their prompts rendered as code -- or markdown set the field; servers that don't get plain text. -- -- `_meta.language` accompanies `format = "code"` and names the -- tree-sitter language to attach. `markdown` always uses the -- `markdown` grammar. -- -- =========================================================================== -- IMPORTANT — `_meta.format` is a pmacs convention, not standard MCP. -- =========================================================================== -- -- The MCP spec (2025-11-25) defines `_meta` as a free-form metadata -- bag for prompts/resources/tools but does not standardize a -- `format` field. Pmacs's choice to key off `_meta.format` is -- deliberate (explicit beats inferred) and documented here so that -- the M9.10 deliverable (TRANSITION-M9.md and the -- MCP-for-package-authors guide) can spread the rule: -- -- * Existing real-world MCP servers (Anthropic's filesystem, -- github, slack, etc., as of 2026-Q1) do NOT set `_meta.format`. -- Every prompt from those servers therefore renders as -- plain text. This is correct behavior, not a bug — it's the -- "servers that don't, get plain text" branch above. -- * Authors of *new* MCP servers that want their prompts to -- render with code or markdown highlighting MUST set -- `_meta.format = "code"` (with a `_meta.language`) or -- `_meta.format = "markdown"` on each `prompts/get` response. -- * If/when the upstream MCP spec adopts a format-hint field, -- this package will switch to whatever the spec defines and -- keep `_meta.format` as a backwards-compatibility fallback -- until v2.0. -- -- M9.10 owners: surface this rule in TRANSITION-M9.md and the -- MCP-for-package-authors guide so package authors know the -- contract before they ship a server. -- =========================================================================== -- -- The package consumes M9.5's notifications dispatcher with zero new -- pmacs.mcp.* APIs — that's the M9.5 framing's structural property. -- M9.7 ships exactly like M9.6: fixture-package + fake-server -- extensions, no Rust API growth. The one v0.1 surface expansion is -- the markdown grammar registered in `BUILTIN_LANGUAGES` (M11 -- measurement counts public Lua/Rust API; grammars and Cargo deps -- are different dimensions). -- -- Implementation notes: -- -- * Command names follow `-` with both -- halves passed through the same `[a-zA-Z0-9_.-]` allow-list (M9.6 -- finding 11). A label like `"my server!"` and a prompt named -- `code/review` together produce `my-server--code-review`. -- * Cross-source collisions (a builtin or another package owning -- the normalized name) → set_status warn, route through -- pmacs.error, skip the prompt; rest of the server's prompts -- register cleanly. M9.6 finding 6 + 10 carry-forward. -- * Required-arg flow: pmacs.minibuffer.read with chained on_accept -- callbacks. Optional args are not prompted in v0.1. Prompt-arg -- coercion does NOT apply (M9.6 finding 12 doesn't carry forward -- to M9.7) — MCP's `prompts/list` returns arguments as -- `{name, description?, required?}` triples with NO per-arg -- schema, so all wire values are strings; coercion would have -- nothing to coerce against. -- * Result buffer named `*mcp: