From 18ddf84e04b8854ec605738b8f842e7b3ed9be9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:50:15 +0000 Subject: [PATCH] module-kit 0.6.0: a production application offers its publications to agents (D1 decided) The Owner decided on 2026-11-22 that "Publikuj" is an agreement between the person and the agent, not a mechanism the App checks (LZD-0037, D1). A production application therefore offers tools with effect "publish" as a development version does. A publication stays a tool of its own with destructiveHint, passes the same writer gate as a draft, and every audit line now names the tool's effect beside the subject and the channel, so who published and which way is told. /tools/testing gains mcpTools to check the annotations. AGENT_PUBLICATION_IN_PRODUCTION is true and deprecated. Co-Authored-By: Claude Opus 5.5 --- README.md | 29 +++++++++++-------- package.json | 2 +- src/tools-testing.ts | 23 +++++++++++++++ src/tools.ts | 40 +++++++++++-------------- test/tools.test.ts | 69 +++++++++++++++++++++++++++++++++++--------- 5 files changed, 114 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 5c16ff2..b93b62e 100644 --- a/README.md +++ b/README.md @@ -221,17 +221,21 @@ interface. `write` is a draft: a reversible change that publishes nothing, which an agent makes on its own. `publish` is a publication: an irreversible step or one others see (an approval, a signature, a sending, a deletion, a movement of money, the publication of a draft or of data to everyone). An agent calls it -only after the person's explicit "Publikuj". A publication is a tool of its own, +on the person's "Publikuj". That word is an agreement between the person and +the agent, not a mechanism the App checks (the Owner, 2026-11-22), so **a +production application offers its publications to agents** as a development +version does, on `/mcp` and on the page. A publication is a tool of its own, never a mode of a draft tool, and the registry gives it `destructiveHint: true` itself. A draft and a publication are offered only while `dataWriter` allows writing (`LAZURIO_RUNTIME_DATA_WRITER=true`; unset, never in a runtime that states `LAZURIO_RUNTIME_DEPLOYMENT=production`, else only to a local or -Environment entry). **Until the Owner decides how the App knows that the person -said "Publikuj", a production application offers no publication**, on `/mcp` -or on the page, and a development version does -(`AGENT_PUBLICATION_IN_PRODUCTION`, the one place that decision changes). A -0.4 declaration of a publication (`effect: "write"` with `publishesData: -true`, or `publicationConsent`) is refused at registration. +Environment entry). The App records who published and which way with the +change itself: the person is `context.access.person.subject` and the way is +`context.channel` (`mcp` or `webmcp`), as the Standard's "Author and channel" +says; the registry's audit line names them too, with the effect. +`AGENT_PUBLICATION_IN_PRODUCTION` is `true` and deprecated. A 0.4 declaration +of a publication (`effect: "write"` with `publishesData: true`, or +`publicationConsent`) is refused at registration. **Answers and refusals.** A tool returns `{ ok: true, data, files? }` or `{ ok: false, reason, message, current_revision?, details? }` and never throws @@ -240,8 +244,8 @@ for an expected outcome. The common reasons are `identity_unavailable`, (with `current_revision`), `data_read_only`, `unavailable` and `internal_error`; a Module adds domain reasons of its own. On `/mcp` a refusal is a tool result with `isError` and `structuredContent`; a file is an embedded -resource. Every call writes one audit line (channel, tool, entry, subject, -role, outcome, duration), never the input or the answer. +resource. Every call writes one audit line (channel, tool, effect, entry, +subject, role, outcome, duration), never the input or the answer. **A data layer that decides by the method.** Every tool call is a `POST`. An App whose data layer chooses a read or a write path by the HTTP method asks @@ -252,9 +256,10 @@ readable. **Tests.** `@lazurio/module-kit/tools/testing` builds requests as the gateway states them (`gatewayRequest`, `hostedEnvironment`, `localEnvironment`) and -calls the registry (`mcpCall`, `mcpToolNames`, `mcpTool`, `pageTool`), so a -Module tests the list per role, the refusal without a role, writes in the -read-only mode and `record_changed` on both transports. +calls the registry (`mcpCall`, `mcpToolNames`, `mcpTools`, `mcpTool`, +`pageTool`), so a Module tests the list per role, the refusal without a role, +writes in the read-only mode, `record_changed` on both transports, and that +each publication is listed with `destructiveHint: true` (`mcpTools`). ## Bun.serve diff --git a/package.json b/package.json index 0702146..6dcdd6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lazurio/module-kit", - "version": "0.5.0", + "version": "0.6.0", "description": "Lazurio Module Standard runtime helpers: listener, health, shutdown, app access, tools for agents", "license": "MIT", "type": "module", diff --git a/src/tools-testing.ts b/src/tools-testing.ts index 79f2fc0..4aca2e6 100644 --- a/src/tools-testing.ts +++ b/src/tools-testing.ts @@ -138,6 +138,29 @@ export async function mcpToolNames( return (result?.tools ?? []).map((tool) => tool.name).sort(); } +/** The tools `tools/list` returns for a caller, with their annotations, so + * a Module checks that every publication carries `destructiveHint`. */ +export async function mcpTools( + registry: ToolRegistry, + caller: GatewayCaller, + appOrigin?: string, +): Promise }>> { + const { body } = await mcpCall( + registry, + "tools/list", + {}, + { caller, ...(appOrigin === undefined ? {} : { appOrigin }) }, + ); + const result = body.result as + | { + tools?: Array<{ name: string; annotations?: Record }>; + } + | undefined; + return (result?.tools ?? []) + .map((tool) => ({ name: tool.name, annotations: tool.annotations ?? {} })) + .sort((a, b) => a.name.localeCompare(b.name)); +} + /** Calls a tool through `/mcp` and returns its structured answer. */ export async function mcpTool( registry: ToolRegistry, diff --git a/src/tools.ts b/src/tools.ts index aa64eaa..09bbc15 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -54,16 +54,18 @@ export type RefusalCode = (typeof REFUSAL_CODES)[number]; * makes it on its own; * - `publish`: a publication, an irreversible step or one others see (an * approval, a signature, a sending, a deletion, a movement of money, the - * publication of a draft or of data to everyone). An agent calls it only - * after the person's explicit "Publikuj". It always carries - * `destructiveHint`, and until the Owner decides how the App knows that the - * person said "Publikuj", a production application does not offer it. */ + * publication of a draft or of data to everyone). An agent calls it on the + * person's "Publikuj", which is an agreement between the person and the + * agent, not a mechanism the App checks (the Owner, 2026-11-22). It is a + * tool of its own, always carries `destructiveHint`, and is offered in a + * production application as in a development version. */ export type ToolEffect = "read" | "prepare" | "write" | "publish"; -/** Whether an agent may publish in a production application. False until the - * Owner decides how the App knows the person's "Publikuj" (LZD-0037, D1); - * the one place that decision changes. */ -export const AGENT_PUBLICATION_IN_PRODUCTION = false; +/** Whether an agent may publish in a production application: yes, since the + * Owner decided on 2026-11-22 that "Publikuj" is an agreement between the + * person and the agent, not a mechanism the App checks (LZD-0037, D1). + * @deprecated Always true; kept so that 0.5 imports still compile. */ +export const AGENT_PUBLICATION_IN_PRODUCTION = true; /** The application role a tool needs at least. */ export type ToolRole = "user" | "admin"; @@ -224,6 +226,9 @@ export interface ToolAuditEvent { readonly entry: AppAccess["entry"]; readonly subject: string | null; readonly appRole: AppAccess["appRole"]; + /** The tool's effect; null for a tool this App does not have. With + * `subject` and `channel` it tells who published and which way. */ + readonly effect: ToolEffect | null; readonly outcome: "ok" | RefusalCode | (string & {}); readonly durationMs: number; } @@ -524,7 +529,6 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { tool: ToolDefinition, access: KnownAccess, canWrite: boolean, - where: Deployment, ): ToolRefusal | null => { if (tool.minRole === "admin" && access.appRole !== "admin") return refusal( @@ -538,15 +542,6 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { "data_read_only", "This App does not change data now (read-only mode).", ); - if ( - tool.effect === "publish" && - where === "production" && - !AGENT_PUBLICATION_IN_PRODUCTION - ) - return refusal( - "forbidden", - `${tool.name} publishes; a production application offers agents no publication until the Owner decides how it knows the person's "Publikuj" (LZD-0037, D1). A person publishes in the interface.`, - ); return null; }; @@ -556,9 +551,8 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { const list = (access: AppAccess): readonly ToolDescriptor[] => { if (!known(access)) return []; const canWrite = dataWriter(access, env); - const where = deployment(env); return [...tools.values()] - .filter((tool) => barrier(tool, access, canWrite, where) === null) + .filter((tool) => barrier(tool, access, canWrite) === null) .map(descriptor); }; @@ -575,6 +569,7 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { event: "agent-tool", channel, tool: tools.has(name) ? name : "(unknown)", + effect: tools.get(name)?.effect ?? null, entry: access.entry, subject: access.person?.subject ?? null, appRole: access.appRole, @@ -587,8 +582,7 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { if (tool === undefined) return finish(refusal("unknown_tool", "This App has no such tool.")); const canWrite = dataWriter(access, env); - const where = deployment(env); - const blocked = barrier(tool, access, canWrite, where); + const blocked = barrier(tool, access, canWrite); if (blocked !== null) return finish(blocked); let parsed: Awaited< ReturnType<(typeof tool.input)["~standard"]["validate"]> @@ -616,7 +610,7 @@ export function createToolRegistry(options: ToolRegistryOptions): ToolRegistry { const result = await tool.run(parsed.value, { access, channel, - deployment: where, + deployment: deployment(env), canWrite, request, }); diff --git a/test/tools.test.ts b/test/tools.test.ts index 1f9b425..caea4b2 100644 --- a/test/tools.test.ts +++ b/test/tools.test.ts @@ -16,6 +16,7 @@ import { mcpCall, mcpTool, mcpToolNames, + mcpTools, pageTool, TEST_ORIGIN, TEST_SUBJECT, @@ -334,6 +335,7 @@ describe("/mcp transport", () => { "export_record_pdf", "find_records", "get_app_context", + "publish_record", "save_record_draft", ]); expect(await mcpToolNames(writer, { role: "admin" })).toContain( @@ -366,15 +368,28 @@ describe("/mcp transport", () => { expect(call.structured.reason).toBe("data_read_only"); }); - test("a publication is not offered in production until D1, and is in a development version", async () => { - expect(await mcpToolNames(writer, { role: "admin" })).not.toContain( + test("a publication is offered in production and in a development version, always destructive (D1, 2026-11-22)", async () => { + // "Publikuj" is an agreement between the person and the agent: the App + // offers the publication and the agent calls it on the person's word. + expect(await mcpToolNames(writer, { role: "user" })).toContain( "publish_record", ); const call = await mcpTool(writer, "publish_record", { id: "r1" }); - expect(call.structured.reason).toBe("forbidden"); - expect(String(call.structured.message)).toContain("LZD-0037, D1"); + expect(call.isError).toBe(false); + expect(call.structured).toEqual({ id: "r1" }); const viaPage = await pageTool(writer, "publish_record", { id: "r1" }); - expect([viaPage.status, viaPage.body.reason]).toEqual([403, "forbidden"]); + expect(viaPage.status).toBe(200); + const destructive = { + readOnlyHint: false, + destructiveHint: true, + idempotentHint: false, + openWorldHint: false, + }; + const hosted = (await mcpTools(writer, { role: "user" })).find( + (tool) => tool.name === "publish_record", + ); + expect(hosted?.annotations).toEqual(destructive); + // A development version in an Environment offers it the same way. const local = registry(localEnvironment()); const response = await local.handleMcp( new Request("http://127.0.0.1:43100/mcp", { @@ -393,18 +408,44 @@ describe("/mcp transport", () => { }; } ).result.tools; - const published = listed.find((tool) => tool.name === "publish_record"); - expect(published?.annotations).toEqual({ - readOnlyHint: false, - destructiveHint: true, - idempotentHint: false, - openWorldHint: false, - }); + expect( + listed.find((tool) => tool.name === "publish_record")?.annotations, + ).toEqual(destructive); // The same writer gate as a draft: not in a read-only copy. expect(await mcpToolNames(reader, { role: "admin" })).not.toContain( "publish_record", ); - expect(AGENT_PUBLICATION_IN_PRODUCTION).toBe(false); + const refused = await mcpTool(reader, "publish_record", { id: "r1" }); + expect(refused.structured.reason).toBe("data_read_only"); + expect(AGENT_PUBLICATION_IN_PRODUCTION).toBe(true); + }); + + test("a publication is audited with who published, which way and its effect", async () => { + const audit: ToolAuditEvent[] = []; + const audited = registry(hostedEnvironment({ writer: true }), audit); + await mcpTool(audited, "publish_record", { id: "r1" }); + await pageTool(audited, "publish_record", { id: "r1" }); + expect( + audit.map(({ channel, subject, effect, outcome }) => ({ + channel, + subject, + effect, + outcome, + })), + ).toEqual([ + { + channel: "mcp", + subject: TEST_SUBJECT, + effect: "publish", + outcome: "ok", + }, + { + channel: "webmcp", + subject: TEST_SUBJECT, + effect: "publish", + outcome: "ok", + }, + ]); }); test("a publication declared the 0.4 way is refused at registration", () => { @@ -545,6 +586,7 @@ describe("/mcp transport", () => { event: "agent-tool", channel: "mcp", tool: "find_records", + effect: "read", entry: "app", subject: TEST_SUBJECT, appRole: "user", @@ -554,6 +596,7 @@ describe("/mcp transport", () => { event: "agent-tool", channel: "mcp", tool: "prepare_record_approval", + effect: "prepare", entry: "app", subject: TEST_SUBJECT, appRole: "user",