@mosadd/mcp 3.0.0-alpha.4 → 3.0.0-alpha.41

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 (57) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +70 -36
  3. package/dist/bin/mcp.js +42 -3
  4. package/dist/chunk-SS6UVKSB.js +3513 -0
  5. package/dist/index.d.ts +115 -6
  6. package/dist/index.js +7 -3
  7. package/package.json +8 -5
  8. package/src/__tests__/golden-path.test.ts +139 -137
  9. package/src/__tests__/integration.test.ts +179 -178
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -178
  12. package/src/__tests__/mtalk.test.ts +122 -122
  13. package/src/__tests__/presence.test.ts +178 -0
  14. package/src/__tests__/server.test.ts +71 -67
  15. package/src/__tests__/tool-count-consistency.test.ts +164 -0
  16. package/src/bin/login.ts +138 -138
  17. package/src/bin/mcp.ts +145 -97
  18. package/src/config.ts +66 -66
  19. package/src/crypto/mdm-session.ts +502 -403
  20. package/src/index.ts +19 -17
  21. package/src/observability/sentry.ts +79 -79
  22. package/src/providers/blob-upload.ts +116 -0
  23. package/src/providers/memory-voice.ts +79 -79
  24. package/src/providers/supabase-dm.ts +122 -117
  25. package/src/providers/supabase-voice.ts +91 -91
  26. package/src/providers/supabase.ts +155 -96
  27. package/src/server.ts +66 -9
  28. package/src/tools/actions.ts +166 -0
  29. package/src/tools/attachments.ts +276 -0
  30. package/src/tools/capabilities.ts +70 -68
  31. package/src/tools/embed.ts +110 -0
  32. package/src/tools/index.ts +177 -43
  33. package/src/tools/knowledge-graph.ts +186 -0
  34. package/src/tools/knowledge.ts +327 -91
  35. package/src/tools/mail-agentbox.ts +155 -0
  36. package/src/tools/mail-aliases.ts +25 -0
  37. package/src/tools/mail-provenance.ts +137 -0
  38. package/src/tools/mail.ts +403 -89
  39. package/src/tools/mcall.ts +216 -0
  40. package/src/tools/mdm-as-agent.ts +126 -0
  41. package/src/tools/mdm-voice.ts +220 -0
  42. package/src/tools/mdm.ts +494 -392
  43. package/src/tools/mirc-edge.ts +196 -0
  44. package/src/tools/mirc-members.ts +61 -20
  45. package/src/tools/mirc-messages.ts +185 -151
  46. package/src/tools/mirc.ts +104 -10
  47. package/src/tools/mroom-messages.ts +142 -142
  48. package/src/tools/mroom.ts +221 -189
  49. package/src/tools/mtalk.ts +131 -121
  50. package/src/tools/murl.ts +314 -0
  51. package/src/tools/presence.ts +399 -0
  52. package/src/tools/ptt-ingest.ts +99 -0
  53. package/src/tools/threat.ts +123 -0
  54. package/src/types.ts +121 -85
  55. package/src/version.ts +8 -0
  56. package/src/voice/floor.ts +132 -132
  57. package/dist/chunk-YDFU6S5E.js +0 -1471
@@ -0,0 +1,178 @@
1
+ /**
2
+ * comms_session_attach — the liveness contract.
3
+ *
4
+ * This tool decides WHO answers the owner: a live agent session, or the 24/7 cloud stand-in.
5
+ * Both answering, or the stand-in answering in a live session's name, is the exact failure that
6
+ * cost the founder his trust in the agent (see the file header in tools/presence.ts). So the
7
+ * things pinned here are the ones that would silently re-open it:
8
+ *
9
+ * 1. attaching writes the liveness row the stand-in reads, under the CALLER'S identity;
10
+ * 2. the hold renews itself on a timer — the model is not asked to remember a clock;
11
+ * 3. the timer is unref()ed, so a held line can never keep a dead session's process alive;
12
+ * 4. re-attaching replaces the beat instead of stacking a second one;
13
+ * 5. release DELETES the row (no backdated timestamp lying in a table other code reads).
14
+ */
15
+
16
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
17
+
18
+ const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
19
+ const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
20
+ const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
21
+
22
+ /** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
23
+ const calls = {
24
+ upserts: [] as Record<string, unknown>[],
25
+ deletes: [] as string[],
26
+ };
27
+
28
+ /**
29
+ * Minimal query-builder stand-in: every method returns the builder, `maybeSingle()` resolves the
30
+ * identity row, and the builder is thenable so `await delete().eq()` works like PostgREST's.
31
+ */
32
+ function makeBuilder(table: string) {
33
+ const builder: Record<string, unknown> = {};
34
+ let pendingDelete = false;
35
+ const self = () => builder;
36
+ Object.assign(builder, {
37
+ select: self,
38
+ is: self,
39
+ or: self,
40
+ upsert: (row: Record<string, unknown>) => {
41
+ calls.upserts.push({ table, ...row });
42
+ return Promise.resolve({ error: null });
43
+ },
44
+ delete: () => {
45
+ pendingDelete = true;
46
+ return builder;
47
+ },
48
+ eq: (_col: string, val: string) => {
49
+ if (pendingDelete) {
50
+ calls.deletes.push(val);
51
+ return Promise.resolve({ error: null });
52
+ }
53
+ return builder;
54
+ },
55
+ // resolveOwnedAgentLine path: .or(...).limit(2) → the caller's ONE owned agent.
56
+ limit: () =>
57
+ Promise.resolve({
58
+ data: [{ id: AGENT_ID, m0ssad_email: "dispatcher@mosadd.com", display_name: "DYSPOZYTOR" }],
59
+ error: null,
60
+ }),
61
+ maybeSingle: () => Promise.resolve({ data: { id: IDENTITY_ID, display_name: "mosADD CTO" }, error: null }),
62
+ });
63
+ return builder;
64
+ }
65
+
66
+ vi.mock("../providers/supabase.js", () => ({
67
+ readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
68
+ getSupabase: () => ({
69
+ auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
70
+ from: (table: string) => makeBuilder(table),
71
+ }),
72
+ }));
73
+
74
+ const ctx = { log: () => {} } as never;
75
+
76
+ /** Import after the mock is registered, so the module under test picks it up. */
77
+ const { presenceTools, __clearAttachmentsForTest } = await import("../tools/presence.js");
78
+ const attach = presenceTools[0];
79
+
80
+ async function call(input: Record<string, unknown>) {
81
+ return (await attach.handler(input, ctx)) as Record<string, unknown>;
82
+ }
83
+
84
+ describe("comms_session_attach", () => {
85
+ beforeEach(() => {
86
+ calls.upserts = [];
87
+ calls.deletes = [];
88
+ vi.useFakeTimers();
89
+ });
90
+ afterEach(() => {
91
+ __clearAttachmentsForTest();
92
+ vi.useRealTimers();
93
+ });
94
+
95
+ it("is registered as a network tool under the comms_ capability group", () => {
96
+ expect(attach.name).toBe("comms_session_attach");
97
+ expect(attach.requires).toBe("network");
98
+ });
99
+
100
+ it("claims the line for the CALLER'S identity, with a label the owner can read", async () => {
101
+ const out = await call({ label: "CTO — Claude Code" });
102
+ expect(out.attached).toBe(true);
103
+ expect(out.identity_id).toBe(IDENTITY_ID);
104
+ expect(calls.upserts).toHaveLength(1);
105
+ expect(calls.upserts[0]).toMatchObject({
106
+ table: "agent_bridge_heartbeat",
107
+ identity_id: IDENTITY_ID,
108
+ host: "CTO — Claude Code",
109
+ mode: "mcp-session",
110
+ });
111
+ });
112
+
113
+ it("renews the hold on its own — the model is never asked to keep time", async () => {
114
+ await call({});
115
+ expect(calls.upserts).toHaveLength(1);
116
+ await vi.advanceTimersByTimeAsync(60_000);
117
+ expect(calls.upserts).toHaveLength(2);
118
+ await vi.advanceTimersByTimeAsync(60_000);
119
+ expect(calls.upserts).toHaveLength(3);
120
+ // Every beat is a fresh timestamp, not a replay of the first one.
121
+ expect(calls.upserts[2].last_seen_at).not.toBe(calls.upserts[0].last_seen_at);
122
+ });
123
+
124
+ it("never keeps a finished session's process alive (timer is unref'ed)", async () => {
125
+ const unref = vi.fn();
126
+ const spy = vi.spyOn(globalThis, "setInterval").mockReturnValue({ unref } as never);
127
+ await call({});
128
+ expect(unref).toHaveBeenCalledOnce();
129
+ spy.mockRestore();
130
+ });
131
+
132
+ it("re-attaching replaces the beat instead of stacking a second one", async () => {
133
+ await call({ label: "first" });
134
+ await call({ label: "second" });
135
+ calls.upserts = [];
136
+ await vi.advanceTimersByTimeAsync(60_000);
137
+ expect(calls.upserts).toHaveLength(1);
138
+ expect(calls.upserts[0].host).toBe("second");
139
+ });
140
+
141
+ it("release DELETES the row and stops beating — the stand-in resumes at once", async () => {
142
+ await call({});
143
+ const out = await call({ release: true });
144
+ expect(out.attached).toBe(false);
145
+ // Two deletes since 2026-08-26: the heartbeat row (by identity) AND the as_agent
146
+ // declaration in mosadd_gateway_agent_binding (by user) — a finishing session hands
147
+ // back EVERYTHING it could hold, so no stale declaration keeps signing later posts.
148
+ expect(calls.deletes).toEqual([IDENTITY_ID, USER_ID]);
149
+ calls.upserts = [];
150
+ await vi.advanceTimersByTimeAsync(180_000);
151
+ expect(calls.upserts).toHaveLength(0);
152
+ });
153
+
154
+ it("as_agent declares the line: binding upsert + beat on the AGENT's identity, not the key's", async () => {
155
+ const out = await call({ as_agent: "dispatcher@mosadd.com", label: "dispatcher — Cowork" });
156
+ expect(out.attached).toBe(true);
157
+ expect(out.identity_id).toBe(AGENT_ID);
158
+ expect((out.speaking_as as { address: string }).address).toBe("dispatcher@mosadd.com");
159
+ // The signing declaration message-send reads (migration 20260826210000)…
160
+ expect(calls.upserts).toContainEqual(
161
+ expect.objectContaining({
162
+ table: "mosadd_gateway_agent_binding",
163
+ user_id: USER_ID,
164
+ agent_identity_id: AGENT_ID,
165
+ }),
166
+ );
167
+ // …and the AGENT's liveness row, so ITS cloud stand-in defers to this session.
168
+ expect(calls.upserts).toContainEqual(
169
+ expect.objectContaining({
170
+ table: "agent_bridge_heartbeat",
171
+ identity_id: AGENT_ID,
172
+ host: "dispatcher — Cowork",
173
+ }),
174
+ );
175
+ // The key's own line is NOT claimed — attaching as an agent must not silence the owner's lane.
176
+ expect(calls.upserts.some((u) => u.table === "agent_bridge_heartbeat" && u.identity_id === IDENTITY_ID)).toBe(false);
177
+ });
178
+ });
@@ -1,67 +1,71 @@
1
- import { describe, expect, it } from "vitest";
2
- import { allTools, createMosaddServer } from "../index.js";
3
-
4
- describe("@mosadd/mcp", () => {
5
- describe("allTools registry", () => {
6
- it("exposes at least the 4 alpha channels", () => {
7
- const names = allTools.map((t) => t.name);
8
- // mDM (6 tools)
9
- expect(names).toContain("mDM_list_contacts");
10
- expect(names).toContain("mDM_publish_keys");
11
- expect(names).toContain("mDM_send");
12
- expect(names).toContain("mDM_send_unencrypted");
13
- expect(names).toContain("mDM_list");
14
- expect(names).toContain("mDM_respond_request");
15
- // mIRC (5 tools)
16
- expect(names).toContain("mIRC_create");
17
- expect(names).toContain("mIRC_delete");
18
- // mROOM (6 tools, including the USP guest-link)
19
- expect(names).toContain("mROOM_create");
20
- expect(names).toContain("mROOM_create_guest_link");
21
- // mAIL (2 tools)
22
- expect(names).toContain("mAIL_send");
23
- expect(names).toContain("mAIL_view");
24
- });
25
-
26
- it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
27
- const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
28
- const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
29
- for (const tool of allTools) {
30
- expect(tool.name).toMatch(new RegExp(`${channelName.source}|${metaName.source}`));
31
- }
32
- });
33
-
34
- it("every tool declares a transport requirement (any | radio | network)", () => {
35
- for (const tool of allTools) {
36
- expect(["any", "radio", "network"]).toContain(tool.requires);
37
- }
38
- });
39
-
40
- it("every tool ships a description and a Zod schema", () => {
41
- for (const tool of allTools) {
42
- expect(typeof tool.description).toBe("string");
43
- expect(tool.description.length).toBeGreaterThan(20);
44
- expect(tool.inputSchema).toBeDefined();
45
- // Zod schemas have _def
46
- expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
47
- }
48
- });
49
- });
50
-
51
- describe("createMosaddServer", () => {
52
- it("constructs without throwing in local mode", () => {
53
- const server = createMosaddServer({ mode: "local", logLevel: "error" });
54
- expect(server).toBeDefined();
55
- });
56
-
57
- it("defaults to local mode when no apiKey", () => {
58
- const server = createMosaddServer({ logLevel: "error" });
59
- expect(server).toBeDefined();
60
- });
61
-
62
- it("accepts cloud mode with apiKey", () => {
63
- const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
64
- expect(server).toBeDefined();
65
- });
66
- });
67
- });
1
+ import { describe, expect, it } from "vitest";
2
+ import { allTools, createMosaddServer } from "../index.js";
3
+
4
+ describe("@mosadd/mcp", () => {
5
+ describe("allTools registry", () => {
6
+ it("exposes at least the 4 alpha channels", () => {
7
+ const names = allTools.map((t) => t.name);
8
+ // mDM (6 tools)
9
+ expect(names).toContain("mDM_list_contacts");
10
+ expect(names).toContain("mDM_publish_keys");
11
+ expect(names).toContain("mDM_send");
12
+ expect(names).toContain("mDM_send_unencrypted");
13
+ expect(names).toContain("mDM_list");
14
+ expect(names).toContain("mDM_respond_request");
15
+ // mIRC (5 tools)
16
+ expect(names).toContain("mIRC_create");
17
+ expect(names).toContain("mIRC_delete");
18
+ // mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered (LINEAR-3498)
19
+ // (surveillance-era direction killed 2026-06-27; on-device security pillar, not an MCP tool)
20
+ expect(names).toContain("mURL_post");
21
+ expect(names).toContain("mAYL_send");
22
+ // mp0st_* aliases RETIRED 2026-07-15 — mAYL is the one name (mp0st is backend-internal only)
23
+ expect(names.some((n) => n.startsWith("mp0st_"))).toBe(false);
24
+ });
25
+
26
+ it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
27
+ const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
28
+ const mailName = /^mp0st_[a-z][a-z0-9_]*$/; // mail module codename (LINEAR-3464)
29
+ const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
30
+ const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine (LINEAR-3498)
31
+ for (const tool of allTools) {
32
+ expect(tool.name).toMatch(
33
+ new RegExp(`${channelName.source}|${mailName.source}|${metaName.source}|${threatName.source}`),
34
+ );
35
+ }
36
+ });
37
+
38
+ it("every tool declares a transport requirement (any | radio | network)", () => {
39
+ for (const tool of allTools) {
40
+ expect(["any", "radio", "network"]).toContain(tool.requires);
41
+ }
42
+ });
43
+
44
+ it("every tool ships a description and a Zod schema", () => {
45
+ for (const tool of allTools) {
46
+ expect(typeof tool.description).toBe("string");
47
+ expect(tool.description.length).toBeGreaterThan(20);
48
+ expect(tool.inputSchema).toBeDefined();
49
+ // Zod schemas have _def
50
+ expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
51
+ }
52
+ });
53
+ });
54
+
55
+ describe("createMosaddServer", () => {
56
+ it("constructs without throwing in local mode", () => {
57
+ const server = createMosaddServer({ mode: "local", logLevel: "error" });
58
+ expect(server).toBeDefined();
59
+ });
60
+
61
+ it("defaults to local mode when no apiKey", () => {
62
+ const server = createMosaddServer({ logLevel: "error" });
63
+ expect(server).toBeDefined();
64
+ });
65
+
66
+ it("accepts cloud mode with apiKey", () => {
67
+ const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
68
+ expect(server).toBeDefined();
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,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
+ ];
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
+ });