@mosadd/mcp 3.0.0-alpha.52 → 3.0.0-alpha.53

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +334 -309
  2. package/README.md +150 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-KVN7LZFW.js → chunk-AWKITPZQ.js} +384 -103
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +9 -9
  8. package/src/__tests__/golden-path.test.ts +139 -139
  9. package/src/__tests__/integration.test.ts +182 -182
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -114
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  12. package/src/__tests__/mdm-mcp-readable.test.ts +284 -0
  13. package/src/__tests__/mirc-invite.test.ts +112 -112
  14. package/src/__tests__/mtalk.test.ts +122 -122
  15. package/src/__tests__/server.test.ts +71 -71
  16. package/src/__tests__/serverJsonVersion.test.ts +45 -45
  17. package/src/__tests__/tool-count-consistency.test.ts +199 -199
  18. package/src/bin/login.ts +138 -138
  19. package/src/bin/mcp.ts +145 -145
  20. package/src/config.ts +66 -66
  21. package/src/crypto/mdm-session.ts +798 -502
  22. package/src/index.ts +19 -19
  23. package/src/observability/sentry.ts +79 -79
  24. package/src/providers/memory-voice.ts +79 -79
  25. package/src/providers/supabase-dm.ts +174 -122
  26. package/src/providers/supabase-voice.ts +91 -91
  27. package/src/providers/supabase.ts +231 -231
  28. package/src/server.ts +186 -162
  29. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
  30. package/src/tools/actions.ts +166 -166
  31. package/src/tools/attachments.ts +276 -276
  32. package/src/tools/capabilities.ts +70 -70
  33. package/src/tools/embed.ts +110 -110
  34. package/src/tools/index.ts +181 -181
  35. package/src/tools/knowledge-graph.ts +186 -186
  36. package/src/tools/knowledge.ts +344 -344
  37. package/src/tools/mail-agentbox.ts +155 -155
  38. package/src/tools/mail-aliases.ts +25 -25
  39. package/src/tools/mail-provenance.ts +137 -137
  40. package/src/tools/mail.ts +403 -403
  41. package/src/tools/mcall.ts +216 -216
  42. package/src/tools/mdm-as-agent.ts +126 -126
  43. package/src/tools/mdm-voice.ts +220 -220
  44. package/src/tools/mdm.ts +119 -17
  45. package/src/tools/mirc-edge.ts +196 -196
  46. package/src/tools/mirc-members.ts +287 -287
  47. package/src/tools/mirc.ts +308 -308
  48. package/src/tools/mroom-messages.ts +142 -142
  49. package/src/tools/mroom.ts +221 -221
  50. package/src/tools/mtalk.ts +131 -131
  51. package/src/tools/murl.ts +314 -314
  52. package/src/tools/presence.ts +442 -442
  53. package/src/tools/ptt-ingest.ts +99 -99
  54. package/src/tools/threat.ts +123 -123
  55. package/src/types.ts +121 -121
  56. package/src/version.ts +8 -8
  57. package/src/voice/floor.ts +132 -132
  58. package/LICENSE +0 -201
@@ -1,199 +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
- // 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
- });
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
+ });