@mosadd/mcp 3.0.0-alpha.44 → 3.0.0-alpha.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ /**
2
+ * mIRC_invite — the wrapper that lets a channel created from the toolkit STOP being mute.
3
+ *
4
+ * mIRC_join adds the KEY's identity (the account, usually a human) to a channel, while
5
+ * message-send signs channel posts with the AGENT — so until the agent itself is a member
6
+ * every post 403s `agent_not_in_channel`. channel-members-manage `invite` has done the right
7
+ * thing since LINEAR-5596 (own agent → auto_joined, no code); the toolkit just never exposed it.
8
+ *
9
+ * Pinned here, because each would silently regress:
10
+ * 1. the tool exists, is a network tool, and its description names BOTH outcomes;
11
+ * 2. the field-name normalizer does NOT rename `role` → `new_role` for invite — the EF's
12
+ * invite branch reads `body.role`, so the rename would drop every requested role to
13
+ * "member" without an error (set-role keeps the rename: that branch reads `new_role`);
14
+ * 3. mIRC_create's `invite_agents` fan-out never forwards the field to channel-manage,
15
+ * reports per-agent failures in `invites[]`, and never throws the created channel away.
16
+ */
17
+ import { describe, it, expect, vi, beforeEach } from "vitest";
18
+ import type { MosaddTool } from "../types.js";
19
+
20
+ const CHANNEL_ID = "6d0f1c1e-1111-4a2b-9c3d-000000000001";
21
+ const AGENT_A = "0489d4c6-8727-442f-bf83-68747a469492";
22
+ const AGENT_B = "b228b6ae-dda6-4823-9882-40ea91ed1530";
23
+
24
+ const calls: { fn: string; body: Record<string, unknown> }[] = [];
25
+ let inviteReply: (body: Record<string, unknown>) => unknown = () => ({ auto_joined: true, member: {} });
26
+
27
+ vi.mock("../providers/supabase.js", () => ({
28
+ readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
29
+ invokeFunction: async (fn: string, body: Record<string, unknown>) => {
30
+ calls.push({ fn, body });
31
+ if (fn === "channel-manage") return { channel: { id: CHANNEL_ID, name: body.name } };
32
+ if (fn === "channel-members-manage") return inviteReply(body);
33
+ throw new Error(`unexpected edge function ${fn}`);
34
+ },
35
+ }));
36
+
37
+ const ctx = { log: () => {} } as never;
38
+ /** Import after the mock is registered, so the modules under test pick it up. */
39
+ const { mircMembersTools } = await import("../tools/mirc-members.js");
40
+ const { mircTools } = await import("../tools/mirc.js");
41
+
42
+ function tool(list: readonly MosaddTool[], name: string): MosaddTool {
43
+ const t = list.find((x) => x.name === name);
44
+ if (!t) throw new Error(`${name} is not registered`);
45
+ return t;
46
+ }
47
+
48
+ describe("mIRC_invite", () => {
49
+ beforeEach(() => {
50
+ calls.length = 0;
51
+ inviteReply = () => ({ auto_joined: true, member: {} });
52
+ });
53
+
54
+ it("is registered as a network tool whose description names both outcomes", () => {
55
+ const invite = tool(mircMembersTools, "mIRC_invite");
56
+ expect(invite.requires).toBe("network");
57
+ expect(invite.description).toContain("auto_joined");
58
+ expect(invite.description).toContain("invite code");
59
+ });
60
+
61
+ it("sends `role` under its own name — the EF's invite branch reads body.role, not new_role", async () => {
62
+ const invite = tool(mircMembersTools, "mIRC_invite");
63
+ await invite.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "moderator" }, ctx);
64
+ expect(calls).toHaveLength(1);
65
+ expect(calls[0].fn).toBe("channel-members-manage");
66
+ expect(calls[0].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A, role: "moderator" });
67
+ expect(calls[0].body).not.toHaveProperty("new_role");
68
+ expect(calls[0].body).not.toHaveProperty("identity_id");
69
+ });
70
+
71
+ it("keeps the role → new_role rename for set-role (the exemption is invite-only)", async () => {
72
+ const setRole = tool(mircMembersTools, "mIRC_set_role");
73
+ await setRole.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "admin" }, ctx);
74
+ expect(calls[0].body).toMatchObject({ action: "set-role", new_role: "admin" });
75
+ expect(calls[0].body).not.toHaveProperty("role");
76
+ });
77
+ });
78
+
79
+ describe("mIRC_create invite_agents fan-out", () => {
80
+ beforeEach(() => {
81
+ calls.length = 0;
82
+ inviteReply = () => ({ auto_joined: true, member: {} });
83
+ });
84
+
85
+ it("creates first, then invites each agent; a per-agent failure lands in invites[] and never undoes the channel", async () => {
86
+ inviteReply = (body) => {
87
+ if (body.target_identity_id === AGENT_B) throw new Error("channel-members-manage (400): Already a member of this channel");
88
+ return { auto_joined: true, member: { identity_id: body.target_identity_id } };
89
+ };
90
+ const create = tool(mircTools, "mIRC_create");
91
+ const out = (await create.handler({ name: "ops", access_mode: "open", invite_agents: [AGENT_A, AGENT_B] }, ctx)) as {
92
+ channel: { id: string };
93
+ invites: Array<{ identity_id: string; ok: boolean; auto_joined?: boolean; error?: string }>;
94
+ };
95
+ expect(out.channel.id).toBe(CHANNEL_ID);
96
+ expect(calls.map((c) => c.fn)).toEqual(["channel-manage", "channel-members-manage", "channel-members-manage"]);
97
+ // invite_agents is toolkit-side composition — channel-manage must never see it.
98
+ expect(calls[0].body).not.toHaveProperty("invite_agents");
99
+ expect(calls[1].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A });
100
+ expect(out.invites).toHaveLength(2);
101
+ expect(out.invites[0]).toMatchObject({ identity_id: AGENT_A, ok: true, auto_joined: true });
102
+ expect(out.invites[1]).toMatchObject({ identity_id: AGENT_B, ok: false });
103
+ expect(out.invites[1].error).toContain("Already a member");
104
+ });
105
+
106
+ it("without invite_agents behaves exactly as before — one call, no invites key", async () => {
107
+ const create = tool(mircTools, "mIRC_create");
108
+ const out = (await create.handler({ name: "ops", access_mode: "open" }, ctx)) as Record<string, unknown>;
109
+ expect(calls).toHaveLength(1);
110
+ expect(out).not.toHaveProperty("invites");
111
+ });
112
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * server.json MUSI ZGADZAĆ SIĘ Z package.json — inaczej oficjalny rejestr MCP rozdaje starą wersję.
3
+ *
4
+ * ⛔ POWÓD JEST ZMIERZONY, NIE TEORETYCZNY (2026-08-28). `packages/mcp/server.json` stał na
5
+ * `3.0.0-alpha.33`, podczas gdy pakiet był już na `3.0.0-alpha.44` — **jedenaście wersji wstecz**.
6
+ * `server.json` to karta, którą czyta oficjalny rejestr MCP, więc każdy, kto znalazłby mosADD tam,
7
+ * a nie u nas, instalowałby alpha.33: wersję sprzed poprawki modelu-widma, sprzed stabilnej
8
+ * tożsamości sesji i sprzed dwóch wycofanych wydań (alpha.39 zdeprecowana, alpha.42 cofnięta).
9
+ * Pierwsze wrażenie z produktu brałoby się z kodu, o którym my sami wiemy, że jest zepsuty.
10
+ *
11
+ * Rozjechało się dlatego, że NIC tego nie pilnowało: publikacja bumpuje `package.json`, a karta
12
+ * rejestru jest osobnym plikiem, którego nikt nie tyka. Klasyczne „dwie kopie prawdy" — ta sama
13
+ * klasa, która trzy razy przywracała model-widmo na czoło łańcucha. Opis w dokumentacji niczego
14
+ * nie broni; test broni przy każdym przebiegu.
15
+ *
16
+ * Sprawdzamy OBA miejsca w server.json: `version` na wierzchu i `packages[].version`.
17
+ */
18
+ import { describe, it, expect } from "vitest";
19
+ import { readFileSync } from "node:fs";
20
+ import { dirname, join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+
23
+ // Zakotwiczone w import.meta.url, nigdy w cwd — pułapka build-cwd kosztowała nas już raz.
24
+ const HERE = dirname(fileURLToPath(import.meta.url));
25
+ const PKG_DIR = join(HERE, "..", "..");
26
+
27
+ const pkg = JSON.parse(readFileSync(join(PKG_DIR, "package.json"), "utf8")) as { version: string };
28
+ const card = JSON.parse(readFileSync(join(PKG_DIR, "server.json"), "utf8")) as {
29
+ version: string;
30
+ packages?: Array<{ identifier?: string; version?: string }>;
31
+ };
32
+
33
+ describe("server.json (karta rejestru MCP)", () => {
34
+ it("ma tę samą wersję co package.json", () => {
35
+ expect(card.version, `server.json.version rozjechało się z package.json (${pkg.version}). ` +
36
+ "Karta rejestru rozdawałaby innym ludziom INNĄ wersję niż publikujemy.").toBe(pkg.version);
37
+ });
38
+
39
+ it("ma tę samą wersję w bloku packages[]", () => {
40
+ const npmEntry = (card.packages ?? []).find((p) => p.identifier === "@mosadd/mcp");
41
+ expect(npmEntry, "brak wpisu @mosadd/mcp w server.json → packages[]").toBeTruthy();
42
+ expect(npmEntry?.version, `server.json → packages[].version rozjechało się z package.json ` +
43
+ `(${pkg.version}). To jest wersja, którą rejestr KAŻE ZAINSTALOWAĆ.`).toBe(pkg.version);
44
+ });
45
+ });
@@ -1,164 +1,199 @@
1
- import { describe, it, expect } from "vitest";
2
- import { readFileSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
- import { dirname, resolve } from "node:path";
5
- import { TOOL_COUNT, allTools } from "../tools/index.js";
6
-
7
- // ── Anti-drift gate ──────────────────────────────────────────────────────────
8
- // The advertised tool count has drifted across surfaces repeatedly (68/69/65/61/
9
- // "70+"), which the founder rightly hates. TOOL_COUNT (= allTools.length) is the ONE
10
- // source of truth; every hardcoded doc surface must equal it. If you add/remove a
11
- // tool, this test fails until you update the surfaces below (or vice-versa).
12
- //
13
- // NOT checked here: the mosADD app's LP `McpToolReference` computes its total
14
- // dynamically from the rendered list, so it cannot drift; and the mosadd-agent README
15
- // lives in a separate repo. Both are noted in the migration handoff.
16
- //
17
- // ⚠ CROSS-REPO SURFACE THIS TEST CANNOT REACH: the public MCP server card at
18
- // apps/web/public/.well-known/mcp/server-card.json lives in the m0ssad-3 repo
19
- // (served at mosadd.com/.well-known/mcp/server-card.json). Found 2026-07-30
20
- // advertising 69 AND 64 at once while TOOL_COUNT was 73. It is pinned by its own
21
- // static gate THERE: m0ssad-3 scripts/check-mcp-server-card.mjs (wired into
22
- // scripts/gates-local.mjs), whose EXPECTED_TOOL_COUNT constant must be bumped in
23
- // the same change whenever TOOL_COUNT moves.
24
-
25
- const here = dirname(fileURLToPath(import.meta.url));
26
- const repoRoot = resolve(here, "../../../.."); // packages/mcp/src/__tests__ -> repo root
27
-
28
- const SURFACES: { file: string; re: RegExp; what: string }[] = [
29
- // README FIRST, because it is the one people actually read. It was NOT in this list until
30
- // 2026-07-29 — the gate guarded four internal surfaces and left the public face of the project
31
- // unguarded, which is the wrong way round. The badge is checked because a wrong number in a
32
- // green badge is the most confident-looking lie a repo can tell.
33
- { file: "README.md", re: /badge\/tools-(\d+)%20live/, what: "README badge" },
34
- { file: "README.md", re: /starts an MCP server with \*\*(\d+) tools\*\*/, what: "README intro line" },
35
- { file: "README.md", re: /\*\*(\d+) callable tools across/, what: "README module breakdown" },
36
- { file: "README.md", re: /npx -y @mosadd\/mcp@alpha\s+#\s*(\d+) tools/, what: "README quickstart comment" },
37
- { file: "packages/mcp/server.json", re: /(\d+)\s+MCP tools/, what: "MCP registry manifest description" },
38
- // The npm-visible description — what `npm view @mosadd/mcp description` and the npmjs.com
39
- // page show. Added 2026-07-30 (LINEAR-4813): it already said 73 but nothing enforced it.
40
- { file: "packages/mcp/package.json", re: /—\s*(\d+)\s+tools\s+—/, what: "package.json description" },
41
- { file: "apps/realm/index.html", re: /#\s*(\d+)\s+tools/, what: "mosadd.dev Realm hero" },
42
- { file: "apps/dev/app/docs/mcp/page.tsx", re: /Total surface today:[\s\S]*?(\d+)\s+tools/, what: "dev docs /docs/mcp" },
43
- { file: "apps/dev/app/opengraph-image.tsx", re: /(\d+)\s+MCP tools/, what: "dev OG image" },
44
- // Added 2026-08-01 (content-truth audit, LINEAR-5057 E-17): six surfaces the gate did
45
- // not pin had silently drifted to 69/66/71/22/4 while TOOL_COUNT was 73. Every public
46
- // file that hand-types a total is now listed here — if you add a surface with a
47
- // number, add it to this array in the same PR.
48
- { file: "docs/OWNER-GUIDE.md", re: /\*\*(\d+) mosADD tools\*\*/, what: "owner guide" },
49
- { file: "packages/ai/README.md", re: /the (\d+) mosADD toolkit tools/, what: "@mosadd/ai README" },
50
- { file: "docs/architecture/human-os.md", re: /exposing \*\*(\d+) tools\*\*/, what: "human-os architecture doc" },
51
- { file: "examples/README.md", re: /\*\*(\d+) live MCP tools across/, what: "examples README header" },
52
- { file: "packages/mcp/README.md", re: /One key, one server, (\d+) tools/, what: "@mosadd/mcp README intro" },
53
- { file: "packages/mcp/README.md", re: /\*\*(\d+) callable tools\*\* in total/, what: "@mosadd/mcp README breakdown" },
54
- { file: "apps/dev/public/llms.txt", re: /(\d+)\s+(?:MCP\s+)?tools/, what: "llms.txt (read by AI crawlers)" },
55
- ];
56
-
57
- describe("tool-count consistency (anti-drift gate)", () => {
58
- it("TOOL_COUNT is a positive integer", () => {
59
- expect(Number.isInteger(TOOL_COUNT)).toBe(true);
60
- expect(TOOL_COUNT).toBeGreaterThan(0);
61
- });
62
-
63
- for (const s of SURFACES) {
64
- it(`${s.what} (${s.file}) advertises exactly TOOL_COUNT (${TOOL_COUNT})`, () => {
65
- const txt = readFileSync(resolve(repoRoot, s.file), "utf8");
66
- const m = txt.match(s.re);
67
- expect(m, `no tool-count number found in ${s.file} — did the surface change shape?`).toBeTruthy();
68
- expect(
69
- Number(m![1]),
70
- `${s.file} says ${m![1]} tools but TOOL_COUNT is ${TOOL_COUNT} — sync the surface or the registry`,
71
- ).toBe(TOOL_COUNT);
72
- });
73
- }
74
- });
75
-
76
- // ── Per-MODULE anti-drift gate ───────────────────────────────────────────────
77
- // WHY this exists (added 2026-08-11): the total-only gate above was GREEN while the
78
- // prose around every pinned line was wrong. Each SURFACES entry pins ONE regex per
79
- // file, so somebody could correct the single matched number and leave its own sentence
80
- // contradicting it. Measured that day, with TOOL_COUNT = 77:
81
- // - packages/mcp/README.md ended a sentence "**77 callable tools** in total" (pinned,
82
- // green) whose own terms — mDM 14 + mIRC 24 + mURL 7 + mAYL 12 = 57, +16 — summed
83
- // to 73, because mAYL had grown by the four mAYL_agentbox_* tools and nobody
84
- // re-added the addends.
85
- // - src/tools/index.ts said the same thing in its header comment.
86
- // A breakdown that contradicts its own total is worse than no breakdown: it looks
87
- // audited. So the addends are now derived from allTools and pinned too.
88
- const liveByModule: Record<string, number> = (() => {
89
- const by: Record<string, number> = {};
90
- for (const t of allTools) {
91
- // Prefix = everything before the first "_", except comms_*/threat_* which are
92
- // capability groups rather than m* modules and are labelled as such in the docs.
93
- const prefix = t.name.startsWith("comms_")
94
- ? "comms"
95
- : t.name.startsWith("threat_")
96
- ? "threat"
97
- : t.name.split("_")[0];
98
- by[prefix] = (by[prefix] ?? 0) + 1;
99
- }
100
- return by;
101
- })();
102
-
103
- /** Doc label → the registry prefix it describes. "Irondome" is the brand name for threat_*. */
104
- const MODULE_LABELS: { label: string; prefix: string }[] = [
105
- { label: "mDM", prefix: "mDM" },
106
- { label: "mIRC", prefix: "mIRC" },
107
- { label: "mURL", prefix: "mURL" },
108
- { label: "mAYL", prefix: "mAYL" },
109
- { label: "mTALK", prefix: "mTALK" },
110
- { label: "mRAG", prefix: "mRAG" },
111
- ];
112
-
113
- const MODULE_SURFACES: { file: string; what: string; re: (label: string) => RegExp }[] = [
114
- {
115
- file: "packages/mcp/src/tools/index.ts",
116
- what: "registry header breakdown",
117
- // "modules mDM 14 · mIRC 24 · mURL 7 · mAYL 16 = 61; capabilities mTALK 6 · mRAG 4 …"
118
- re: (label) => new RegExp(`\\b${label}\\s+(\\d+)\\s*[·=]`),
119
- },
120
- {
121
- file: "packages/mcp/README.md",
122
- what: "README module table row",
123
- // "| **mDM** (14) | `mDM_list_contacts`, …"
124
- re: (label) => new RegExp(`\\|\\s*\\*\\*${label}\\*\\*\\s*\\((\\d+)\\)`),
125
- },
126
- {
127
- file: "packages/mcp/README.md",
128
- what: "README breakdown addends",
129
- // "mDM (14) + mIRC (24) + … ; capabilities: mTALK (6) + mRAG (4) + …"
130
- re: (label) => new RegExp(`\\b${label}_?\\s*\\((\\d+)\\)\\s*[+=;]`),
131
- },
132
- ];
133
-
134
- describe("per-module tool-count consistency", () => {
135
- it("every registered tool falls into a known module/capability prefix", () => {
136
- const known = new Set([...MODULE_LABELS.map((m) => m.prefix), "comms", "threat"]);
137
- const strays = Object.keys(liveByModule).filter((p) => !known.has(p));
138
- expect(
139
- strays,
140
- `unknown tool prefix(es) ${strays.join(", ")} — a new module shipped without a doc breakdown; ` +
141
- `add it to MODULE_LABELS and to every surface listed in MODULE_SURFACES`,
142
- ).toEqual([]);
143
- });
144
-
145
- it("the per-module numbers add up to TOOL_COUNT", () => {
146
- const sum = Object.values(liveByModule).reduce((a, b) => a + b, 0);
147
- expect(sum).toBe(TOOL_COUNT);
148
- });
149
-
150
- for (const s of MODULE_SURFACES) {
151
- for (const { label, prefix } of MODULE_LABELS) {
152
- it(`${s.what} (${s.file}) says ${label} = ${liveByModule[prefix]}`, () => {
153
- const txt = readFileSync(resolve(repoRoot, s.file), "utf8");
154
- const m = txt.match(s.re(label));
155
- expect(m, `no "${label} <n>" breakdown found in ${s.file} — did the surface change shape?`).toBeTruthy();
156
- expect(
157
- Number(m![1]),
158
- `${s.file} says ${label} has ${m![1]} tools but the registry has ${liveByModule[prefix]} — ` +
159
- `sync the surface or the registry`,
160
- ).toBe(liveByModule[prefix]);
161
- });
162
- }
163
- }
164
- });
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, resolve } from "node:path";
5
+ import { TOOL_COUNT, allTools } from "../tools/index.js";
6
+
7
+ // ── Anti-drift gate ──────────────────────────────────────────────────────────
8
+ // The advertised tool count has drifted across surfaces repeatedly (68/69/65/61/
9
+ // "70+"), which the founder rightly hates. TOOL_COUNT (= allTools.length) is the ONE
10
+ // source of truth; every hardcoded doc surface must equal it. If you add/remove a
11
+ // tool, this test fails until you update the surfaces below (or vice-versa).
12
+ //
13
+ // NOT checked here: the mosADD app's LP `McpToolReference` computes its total
14
+ // dynamically from the rendered list, so it cannot drift; and the mosadd-agent README
15
+ // lives in a separate repo. Both are noted in the migration handoff.
16
+ //
17
+ // ⚠ CROSS-REPO SURFACE THIS TEST CANNOT REACH: the public MCP server card at
18
+ // apps/web/public/.well-known/mcp/server-card.json lives in the m0ssad-3 repo
19
+ // (served at mosadd.com/.well-known/mcp/server-card.json). Found 2026-07-30
20
+ // advertising 69 AND 64 at once while TOOL_COUNT was 73. It is pinned by its own
21
+ // static gate THERE: m0ssad-3 scripts/check-mcp-server-card.mjs (wired into
22
+ // scripts/gates-local.mjs), whose EXPECTED_TOOL_COUNT constant must be bumped in
23
+ // the same change whenever TOOL_COUNT moves.
24
+
25
+ const here = dirname(fileURLToPath(import.meta.url));
26
+ const repoRoot = resolve(here, "../../../.."); // packages/mcp/src/__tests__ -> repo root
27
+
28
+ const SURFACES: { file: string; re: RegExp; what: string }[] = [
29
+ // README FIRST, because it is the one people actually read. It was NOT in this list until
30
+ // 2026-07-29 — the gate guarded four internal surfaces and left the public face of the project
31
+ // unguarded, which is the wrong way round. The badge is checked because a wrong number in a
32
+ // green badge is the most confident-looking lie a repo can tell.
33
+ { file: "README.md", re: /badge\/tools-(\d+)%20live/, what: "README badge" },
34
+ { file: "README.md", re: /starts an MCP server with \*\*(\d+) tools\*\*/, what: "README intro line" },
35
+ { file: "README.md", re: /\*\*(\d+) callable tools across/, what: "README module breakdown" },
36
+ { file: "README.md", re: /npx -y @mosadd\/mcp@alpha\s+#\s*(\d+) tools/, what: "README quickstart comment" },
37
+ { file: "packages/mcp/server.json", re: /(\d+)\s+MCP tools/, what: "MCP registry manifest description" },
38
+ // The npm-visible description — what `npm view @mosadd/mcp description` and the npmjs.com
39
+ // page show. Added 2026-07-30 (LINEAR-4813): it already said 73 but nothing enforced it.
40
+ { file: "packages/mcp/package.json", re: /—\s*(\d+)\s+tools\s+—/, what: "package.json description" },
41
+ { file: "apps/realm/index.html", re: /#\s*(\d+)\s+tools/, what: "mosadd.dev Realm hero" },
42
+ { file: "apps/dev/app/docs/mcp/page.tsx", re: /Total surface today:[\s\S]*?(\d+)\s+tools/, what: "dev docs /docs/mcp" },
43
+ { file: "apps/dev/app/opengraph-image.tsx", re: /(\d+)\s+MCP tools/, what: "dev OG image" },
44
+ // Added 2026-08-01 (content-truth audit, LINEAR-5057 E-17): six surfaces the gate did
45
+ // not pin had silently drifted to 69/66/71/22/4 while TOOL_COUNT was 73. Every public
46
+ // file that hand-types a total is now listed here — if you add a surface with a
47
+ // number, add it to this array in the same PR.
48
+ { file: "docs/OWNER-GUIDE.md", re: /\*\*(\d+) mosADD tools\*\*/, what: "owner guide" },
49
+ { file: "packages/ai/README.md", re: /the (\d+) mosADD toolkit tools/, what: "@mosadd/ai README" },
50
+ { file: "docs/architecture/human-os.md", re: /exposing \*\*(\d+) tools\*\*/, what: "human-os architecture doc" },
51
+ { file: "examples/README.md", re: /\*\*(\d+) live MCP tools across/, what: "examples README header" },
52
+ { file: "packages/mcp/README.md", re: /One key, one server, (\d+) tools/, what: "@mosadd/mcp README intro" },
53
+ { file: "packages/mcp/README.md", re: /\*\*(\d+) callable tools\*\* in total/, what: "@mosadd/mcp README breakdown" },
54
+ { file: "apps/dev/public/llms.txt", re: /(\d+)\s+(?:MCP\s+)?tools/, what: "llms.txt (read by AI crawlers)" },
55
+ // Added 2026-09-04 (kanon 1.1 review, LINEAR-5870): three more public files hand-typed a total
56
+ // and had sat at 77 through two bumps (82, 84) because nothing pinned them. Both realm llms.txt
57
+ // lines are pinned separately — a single /(\d+) tools/ would only ever see the first.
58
+ { file: "apps/realm/llms.txt", re: /@mosadd\/mcp — (\d+) tools, Apache-2\.0/, what: "mosadd.dev Realm llms.txt intro" },
59
+ { file: "apps/realm/llms.txt", re: /## Toolkit \(@mosadd\/mcp — (\d+) tools\)/, what: "mosadd.dev Realm llms.txt toolkit heading" },
60
+ { file: "docs/registry-submissions/smithery.md", re: /mAYL, (\d+) MCP tools, one server/, what: "Smithery listing tagline" },
61
+ { file: "docs/registry-submissions/smithery.md", re: /\*\*(\d+) MCP tools — 4 modules/, what: "Smithery long description" },
62
+ ];
63
+
64
+ describe("tool-count consistency (anti-drift gate)", () => {
65
+ it("TOOL_COUNT is a positive integer", () => {
66
+ expect(Number.isInteger(TOOL_COUNT)).toBe(true);
67
+ expect(TOOL_COUNT).toBeGreaterThan(0);
68
+ });
69
+
70
+ for (const s of SURFACES) {
71
+ it(`${s.what} (${s.file}) advertises exactly TOOL_COUNT (${TOOL_COUNT})`, () => {
72
+ const txt = readFileSync(resolve(repoRoot, s.file), "utf8");
73
+ const m = txt.match(s.re);
74
+ expect(m, `no tool-count number found in ${s.file} — did the surface change shape?`).toBeTruthy();
75
+ expect(
76
+ Number(m![1]),
77
+ `${s.file} says ${m![1]} tools but TOOL_COUNT is ${TOOL_COUNT} — sync the surface or the registry`,
78
+ ).toBe(TOOL_COUNT);
79
+ });
80
+ }
81
+ });
82
+
83
+ // ── Per-MODULE anti-drift gate ───────────────────────────────────────────────
84
+ // WHY this exists (added 2026-08-11): the total-only gate above was GREEN while the
85
+ // prose around every pinned line was wrong. Each SURFACES entry pins ONE regex per
86
+ // file, so somebody could correct the single matched number and leave its own sentence
87
+ // contradicting it. Measured that day, with TOOL_COUNT = 77:
88
+ // - packages/mcp/README.md ended a sentence "**77 callable tools** in total" (pinned,
89
+ // green) whose own terms — mDM 14 + mIRC 24 + mURL 7 + mAYL 12 = 57, +16 — summed
90
+ // to 73, because mAYL had grown by the four mAYL_agentbox_* tools and nobody
91
+ // re-added the addends.
92
+ // - src/tools/index.ts said the same thing in its header comment.
93
+ // A breakdown that contradicts its own total is worse than no breakdown: it looks
94
+ // audited. So the addends are now derived from allTools and pinned too.
95
+ const liveByModule: Record<string, number> = (() => {
96
+ const by: Record<string, number> = {};
97
+ for (const t of allTools) {
98
+ // Prefix = everything before the first "_", except comms_*/threat_* which are
99
+ // capability groups rather than m* modules and are labelled as such in the docs.
100
+ const prefix = t.name.startsWith("comms_")
101
+ ? "comms"
102
+ : t.name.startsWith("threat_")
103
+ ? "threat"
104
+ : t.name.split("_")[0];
105
+ by[prefix] = (by[prefix] ?? 0) + 1;
106
+ }
107
+ return by;
108
+ })();
109
+
110
+ /** Doc label → the registry prefix it describes. "Irondome" is the brand name for threat_*. */
111
+ const MODULE_LABELS: { label: string; prefix: string }[] = [
112
+ { label: "mDM", prefix: "mDM" },
113
+ { label: "mIRC", prefix: "mIRC" },
114
+ { label: "mURL", prefix: "mURL" },
115
+ { label: "mAYL", prefix: "mAYL" },
116
+ { label: "mTALK", prefix: "mTALK" },
117
+ { label: "mRAG", prefix: "mRAG" },
118
+ ];
119
+
120
+ const MODULE_SURFACES: { file: string; what: string; re: (label: string) => RegExp }[] = [
121
+ {
122
+ file: "packages/mcp/src/tools/index.ts",
123
+ what: "registry header breakdown",
124
+ // "modules mDM 14 · mIRC 24 · mURL 7 · mAYL 16 = 61; capabilities mTALK 6 · mRAG 4 …"
125
+ re: (label) => new RegExp(`\\b${label}\\s+(\\d+)\\s*[·=]`),
126
+ },
127
+ {
128
+ file: "packages/mcp/README.md",
129
+ what: "README module table row",
130
+ // "| **mDM** (14) | `mDM_list_contacts`, …"
131
+ re: (label) => new RegExp(`\\|\\s*\\*\\*${label}\\*\\*\\s*\\((\\d+)\\)`),
132
+ },
133
+ {
134
+ file: "packages/mcp/README.md",
135
+ what: "README breakdown addends",
136
+ // "mDM (14) + mIRC (24) + … ; capabilities: mTALK (6) + mRAG (4) + …"
137
+ re: (label) => new RegExp(`\\b${label}_?\\s*\\((\\d+)\\)\\s*[+=;]`),
138
+ },
139
+ // Added 2026-09-04 (kanon 1.1 review, LINEAR-5870). Measured that day: examples/README.md had
140
+ // its header bumped to 85 while its own addends still read mDM (14) / mRAG (4) / comms (4) — a
141
+ // breakdown summing to 78 under a headline of 85, the exact shape this gate exists for. The
142
+ // realm llms.txt and the Smithery copy carried mDM 14 / mIRC 24 / mRAG 4 from alpha.33.
143
+ {
144
+ file: "examples/README.md",
145
+ what: "examples README per-module list",
146
+ // "- **mDM** (16): list_contacts, …"
147
+ re: (label) => new RegExp(`\\*\\*${label}\\*\\*\\s*\\((\\d+)\\)`),
148
+ },
149
+ {
150
+ file: "apps/realm/llms.txt",
151
+ what: "mosadd.dev Realm llms.txt per-module list",
152
+ // "- mDM (16): E2EE 1:1 messaging …" — one bullet per module, mTALK and mRAG included.
153
+ re: (label) => new RegExp(`^- ${label} \\((\\d+)\\):`, "m"),
154
+ },
155
+ {
156
+ file: "docs/registry-submissions/smithery.md",
157
+ what: "Smithery long-description per-module list",
158
+ // "- mDM (16 tools) — …"
159
+ re: (label) => new RegExp(`^- ${label} \\((\\d+) tools`, "m"),
160
+ },
161
+ {
162
+ file: "apps/dev/public/llms.txt",
163
+ what: "dev llms.txt per-module list",
164
+ // "- mDM — 1:1 direct messages … (16 tools)" / "mRAG — agent memory … (8 tools);"
165
+ re: (label) => new RegExp(`\\b${label} — [^\\n]*?\\((\\d+) tools\\)`),
166
+ },
167
+ ];
168
+
169
+ describe("per-module tool-count consistency", () => {
170
+ it("every registered tool falls into a known module/capability prefix", () => {
171
+ const known = new Set([...MODULE_LABELS.map((m) => m.prefix), "comms", "threat"]);
172
+ const strays = Object.keys(liveByModule).filter((p) => !known.has(p));
173
+ expect(
174
+ strays,
175
+ `unknown tool prefix(es) ${strays.join(", ")} — a new module shipped without a doc breakdown; ` +
176
+ `add it to MODULE_LABELS and to every surface listed in MODULE_SURFACES`,
177
+ ).toEqual([]);
178
+ });
179
+
180
+ it("the per-module numbers add up to TOOL_COUNT", () => {
181
+ const sum = Object.values(liveByModule).reduce((a, b) => a + b, 0);
182
+ expect(sum).toBe(TOOL_COUNT);
183
+ });
184
+
185
+ for (const s of MODULE_SURFACES) {
186
+ for (const { label, prefix } of MODULE_LABELS) {
187
+ it(`${s.what} (${s.file}) says ${label} = ${liveByModule[prefix]}`, () => {
188
+ const txt = readFileSync(resolve(repoRoot, s.file), "utf8");
189
+ const m = txt.match(s.re(label));
190
+ expect(m, `no "${label} <n>" breakdown found in ${s.file} — did the surface change shape?`).toBeTruthy();
191
+ expect(
192
+ Number(m![1]),
193
+ `${s.file} says ${label} has ${m![1]} tools but the registry has ${liveByModule[prefix]} — ` +
194
+ `sync the surface or the registry`,
195
+ ).toBe(liveByModule[prefix]);
196
+ });
197
+ }
198
+ }
199
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * mRAG_delete MUSI foldować source_id dokładnie tak, jak robi to mRAG_ingest.
3
+ *
4
+ * ⛔ ZMIERZONA AWARIA (2026-08-28). `mRAG_ingest` przepuszczał nie-UUID przez `uuidV5`, a
5
+ * `mRAG_delete` wysyłał SUROWY napis prosto do kolumny UUID. Efekt na żywo:
6
+ *
7
+ * mRAG_ingest { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → { indexed: 1 } ✅
8
+ * mRAG_delete { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → 500
9
+ * "invalid input syntax for type uuid" ❌
10
+ *
11
+ * Czyli: dokument zaindeksowany pod NATURALNYM kluczem (numer sprawy, ścieżka pliku, threadId
12
+ * Gmaila) dawało się dodać, ale **nigdy nie dawało się go usunąć tym samym identyfikatorem**.
13
+ * Dwie połowy tej samej rury nie zgadzały się ze sobą.
14
+ *
15
+ * I to nie było niedopatrzenie w cieniu — obietnica stała w DWÓCH miejscach, a implementacja
16
+ * w jednym: komentarz przy foldowaniu mówi „so grouping and mRAG_delete keep working on natural
17
+ * keys", a opis narzędzia obiecuje userowi „can later be removed with mRAG_delete".
18
+ *
19
+ * Boli najbardziej przy korpusie, bo tam naturalne klucze są jedynym sposobem na dedup przy
20
+ * ponownym wczytaniu — a właśnie tak mielone są akta.
21
+ *
22
+ * Ten test pilnuje INWARIANTU, nie implementacji: cokolwiek robi ingest ze swoim `source_id`,
23
+ * delete ma zrobić to samo. Gdyby ktoś kiedyś zmienił namespace albo wersję UUID, obie strony
24
+ * muszą pojechać razem — i to złapie każdy rozjazd.
25
+ */
26
+ import { describe, it, expect } from "vitest";
27
+ import { readFileSync } from "node:fs";
28
+ import { dirname, join } from "node:path";
29
+ import { fileURLToPath } from "node:url";
30
+
31
+ const HERE = dirname(fileURLToPath(import.meta.url));
32
+ const SRC = readFileSync(join(HERE, "..", "knowledge.ts"), "utf8");
33
+
34
+ /** Ciało funkcji o danej nazwie — od jej deklaracji do następnej deklaracji `async function`. */
35
+ function bodyOf(name: string): string {
36
+ const start = SRC.indexOf(`async function ${name}(`);
37
+ expect(start, `nie znaleziono funkcji ${name} w knowledge.ts`).toBeGreaterThan(-1);
38
+ const next = SRC.indexOf("\nasync function ", start + 1);
39
+ return SRC.slice(start, next === -1 ? SRC.length : next);
40
+ }
41
+
42
+ describe("mRAG_delete — zgodność foldowania z mRAG_ingest", () => {
43
+ it("delete folduje source_id przez uuidV5, tak samo jak ingest", () => {
44
+ const del = bodyOf("mRAG_delete");
45
+ expect(del, "mRAG_delete musi wołać uuidV5 — inaczej naturalny klucz da 500 na kolumnie uuid")
46
+ .toContain("uuidV5(");
47
+ expect(del, "mRAG_delete musi używać TEGO SAMEGO namespace co ingest")
48
+ .toContain("SOURCE_ID_NAMESPACE");
49
+ expect(del, "mRAG_delete musi rozpoznawać gotowy UUID i go NIE przerabiać")
50
+ .toContain("UUID_RE");
51
+ });
52
+
53
+ it("delete NIE wysyła surowego input.source_id do rag-sources", () => {
54
+ const del = bodyOf("mRAG_delete");
55
+ expect(
56
+ /source_id:\s*input\.source_id\s*\?\?\s*null/.test(del),
57
+ "regresja: surowy input.source_id znowu leci do rag-sources — to jest dokładnie ten błąd 500",
58
+ ).toBe(false);
59
+ });
60
+
61
+ it("obie strony dzielą jedną definicję namespace i jedną funkcję uuidV5", () => {
62
+ // Po jednej definicji każdej — dwie kopie to dwie prawdy, a na tym już się przejechaliśmy
63
+ // przy trasach modeli (FALLBACK_ROUTES vs ai_routes).
64
+ expect(SRC.match(/const SOURCE_ID_NAMESPACE\s*=/g)?.length ?? 0).toBe(1);
65
+ expect(SRC.match(/function uuidV5\(/g)?.length ?? 0).toBe(1);
66
+ });
67
+ });
@@ -12,12 +12,16 @@
12
12
  * defensive classification over the threat taxonomy — the surveillance-era
13
13
  * *marketing* was killed, the classification engine is real and wanted.
14
14
  *
15
- * 84 callable tools registered — the exact live count is exported as TOOL_COUNT
15
+ * 85 callable tools registered — the exact live count is exported as TOOL_COUNT
16
16
  * (= allTools.length) below; ALWAYS reference that, never re-hard-code a number that drifts.
17
- * Breakdown (2026-08-17, measured from a live tools/list on the built server):
18
- * modules mDM 16 · mIRC 24 · mURL 7 · mAYL 16 = 63; capabilities mTALK 6 · mRAG 8 ·
17
+ * Breakdown (2026-09-03, from allTools in this tree; the live tools/list on mcp.mosadd.com catches up
18
+ * when the alpha carrying mIRC_invite is published and the gateway redeployed):
19
+ * modules mDM 16 · mIRC 25 · mURL 7 · mAYL 16 = 64; capabilities mTALK 6 · mRAG 8 ·
19
20
  * comms 5 (action_create/action_frame_get/embed_create/capabilities/session_attach) · Irondome/threat 2
20
- * = 21. 63 + 21 = 84. (mDM 16 = 14 + mDM_send_as_agent/mDM_list_my_agents added 2026-08-17: an MCP key
21
+ * = 21. 64 + 21 = 85. (mIRC 25 = 24 + mIRC_invite added 2026-09-03 (LINEAR-5870): mIRC_join adds the KEY's
22
+ * identity while channel posts are signed by the AGENT, so every channel created from the toolkit was mute
23
+ * until its agent was added from the app — mIRC_invite wraps channel-members-manage `invite`: own agent →
24
+ * auto_joined, anyone else → invite code. mDM 16 = 14 + mDM_send_as_agent/mDM_list_my_agents added 2026-08-17: an MCP key
21
25
  * is bound to a USER, so an agent runtime wired up with its owner's key spoke AS THE OWNER — these
22
26
  * let it speak as an agent it OWNS instead, checked server-side. mRAG 8 = 4 search/ingest + 4 mRAG_graph_* traversal tools added 2026-08-11.
23
27
  * comms_session_attach added 2026-08-14: a live agent session claims the account's reply lane so