@mosadd/mcp 3.0.0 → 3.0.2
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.
- package/CHANGELOG.md +420 -410
- package/LICENSE +21 -0
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-VMMJJYXF.js → chunk-I3FSPQ4G.js} +78 -30
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/blob-upload.test.ts +1 -1
- package/src/__tests__/{flota-jawnie.test.ts → fleet-plaintext.test.ts} +59 -60
- package/src/__tests__/integration.test.ts +1 -1
- package/src/__tests__/mdm-e2ee.test.ts +3 -3
- package/src/__tests__/mdm-mcp-readable.test.ts +95 -95
- package/src/__tests__/mirc-files.test.ts +80 -0
- package/src/__tests__/mirc-invite.test.ts +1 -1
- package/src/__tests__/mirc-voice.test.ts +82 -0
- package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
- package/src/__tests__/presence.test.ts +2 -2
- package/src/__tests__/server.test.ts +3 -3
- package/src/__tests__/tool-count-consistency.test.ts +4 -4
- package/src/crypto/channel-e2ee.ts +1 -1
- package/src/crypto/mdm-session.ts +14 -14
- package/src/providers/supabase-dm.ts +6 -1
- package/src/providers/supabase.ts +8 -8
- package/src/server.ts +4 -4
- package/src/tools/channel-payload.ts +3 -3
- package/src/tools/index.ts +13 -13
- package/src/tools/knowledge.ts +384 -351
- package/src/tools/mail-aliases.ts +1 -1
- package/src/tools/mail-provenance.ts +1 -1
- package/src/tools/mdm-as-agent.ts +3 -4
- package/src/tools/mdm.ts +19 -14
- package/src/tools/mirc-edge.ts +4 -4
- package/src/tools/mirc-members.ts +1 -1
- package/src/tools/mirc-messages.ts +41 -12
- package/src/tools/mirc.ts +1 -1
- package/src/tools/mroom-messages.ts +1 -1
- package/src/tools/presence.ts +10 -10
- package/src/tools/ptt-ingest.ts +1 -1
- package/src/tools/threat.ts +1 -1
- package/src/tools/voice-format.ts +53 -7
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 30.11.2026 — agenci nie widzieli plików od człowieka: zrzut wrzucony do kanału razem z wiadomością tekstową leży
|
|
3
|
+
* w metadanych wiadomości, message-list (mosADD) oddaje go jako `files` z podpisanym adresem (prawa czytającego),
|
|
4
|
+
* a mIRC_list_messages / mDM_list nie przenosiły tego pola — agent widział sam tekst.
|
|
5
|
+
*
|
|
6
|
+
* Pilnowane:
|
|
7
|
+
* 1. zrzut przy wiadomości tekstowej → attachments [{name, mime, size, url}] obok tekstu;
|
|
8
|
+
* 2. plik szyfrowany → encrypted:true, url null; adres nie-https odrzucony;
|
|
9
|
+
* 3. wiadomość bez plików → bez pola attachments;
|
|
10
|
+
* 4. mDM_list i dostawca mDM przenoszą to samo pole.
|
|
11
|
+
*
|
|
12
|
+
* SABOTAŻ (30.11): `...(pliki ? { attachments: pliki } : {})` wycięte z mirc-messages.ts → czerwone 1 i 2.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { describe, expect, it, vi } from "vitest";
|
|
16
|
+
import type { MosaddTool } from "../types.js";
|
|
17
|
+
|
|
18
|
+
const CHANNEL_ID = "6d0f1c1e-1111-4a2b-9c3d-000000000002";
|
|
19
|
+
const b64 = (s: string) => Buffer.from(s, "utf8").toString("base64");
|
|
20
|
+
const URL1 = "https://api.example/storage/v1/object/sign/chat-files/u1/c1/screenshot.png?token=t";
|
|
21
|
+
|
|
22
|
+
vi.mock("../crypto/channel-e2ee.js", () => ({
|
|
23
|
+
decryptChannelPayload: async () => null,
|
|
24
|
+
encryptChannelPayload: async () => null,
|
|
25
|
+
unwrapEnvelopeText: (s: string) => s,
|
|
26
|
+
}));
|
|
27
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
28
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
29
|
+
invokeFunction: async (fn: string) => {
|
|
30
|
+
if (fn === "channel-manage") return { linked_space_id: "space-1" };
|
|
31
|
+
if (fn === "message-list") {
|
|
32
|
+
return {
|
|
33
|
+
messages: [
|
|
34
|
+
{ id: "m-zrzut", sender_identity_id: "czlowiek", encrypted_payload: b64("zobacz, tu jest źle"), created_at: "2026-11-30T03:30:41Z",
|
|
35
|
+
message_type: "txt", files: [{ name: "screenshot.png", mime: "image/png", size: 182044, url: URL1 }] },
|
|
36
|
+
{ id: "m-tajny", sender_identity_id: "czlowiek", encrypted_payload: b64("plik"), created_at: "2026-11-30T03:31:00Z",
|
|
37
|
+
message_type: "file", files: [{ name: "a.pdf", mime: "application/pdf", size: 10, url: null, encrypted: true },
|
|
38
|
+
{ name: "b.png", mime: "image/png", size: 1, url: "http://bez-tls.example/b.png" }] },
|
|
39
|
+
{ id: "m-txt", sender_identity_id: "czlowiek", encrypted_payload: b64("sam tekst"), created_at: "2026-11-30T03:32:00Z", message_type: "txt" },
|
|
40
|
+
],
|
|
41
|
+
next_before: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`unexpected edge function ${fn}`);
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
const ctx = { log: () => {} } as never;
|
|
49
|
+
const { mircMessagesTools } = await import("../tools/mirc-messages.js");
|
|
50
|
+
const lista = mircMessagesTools.find((t) => t.name === "mIRC_list_messages") as MosaddTool;
|
|
51
|
+
const czytaj = async () => ((await lista.handler({ channel_id: CHANNEL_ID }, ctx)) as { messages: Array<Record<string, unknown>> }).messages;
|
|
52
|
+
|
|
53
|
+
describe("pliki w kanale docierają do agenta", () => {
|
|
54
|
+
it("1: zrzut przy wiadomości tekstowej → attachments z podpisanym adresem obok tekstu", async () => {
|
|
55
|
+
const m = (await czytaj()).find((x) => x.id === "m-zrzut")!;
|
|
56
|
+
expect(m.text).toBe("zobacz, tu jest źle");
|
|
57
|
+
expect(m.attachments).toEqual([{ name: "screenshot.png", mime: "image/png", size: 182044, url: URL1 }]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("2: plik szyfrowany → encrypted:true bez url; adres nie-https odrzucony", async () => {
|
|
61
|
+
const m = (await czytaj()).find((x) => x.id === "m-tajny")!;
|
|
62
|
+
expect(m.attachments).toEqual([
|
|
63
|
+
{ name: "a.pdf", mime: "application/pdf", size: 10, url: null, encrypted: true },
|
|
64
|
+
{ name: "b.png", mime: "image/png", size: 1, url: null },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("3: wiadomość bez plików → bez pola attachments", async () => {
|
|
69
|
+
const m = (await czytaj()).find((x) => x.id === "m-txt")!;
|
|
70
|
+
expect(m).not.toHaveProperty("attachments");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("4: mDM_list i dostawca mDM przenoszą to samo pole", () => {
|
|
74
|
+
const prov = readFileSync(new URL("../providers/supabase-dm.ts", import.meta.url), "utf8");
|
|
75
|
+
const tool = readFileSync(new URL("../tools/mdm.ts", import.meta.url), "utf8");
|
|
76
|
+
expect(prov).toContain("files: attachmentsFrom(m.files)");
|
|
77
|
+
expect(tool).toContain("...(m.files?.length ? { attachments: m.files } : {})");
|
|
78
|
+
expect(lista.description).toContain("attachments: [{name, mime, size, url}]");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* mIRC_join adds the KEY's identity (the account, usually a human) to a channel, while
|
|
5
5
|
* message-send signs channel posts with the AGENT — so until the agent itself is a member
|
|
6
6
|
* every post 403s `agent_not_in_channel`. channel-members-manage `invite` has done the right
|
|
7
|
-
* thing
|
|
7
|
+
* thing for a while (own agent → auto_joined, no code); the toolkit just never exposed it.
|
|
8
8
|
*
|
|
9
9
|
* Pinned here, because each would silently regress:
|
|
10
10
|
* 1. the tool exists, is a network tool, and its description names BOTH outcomes;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 30.11.2026 — agenci nie słyszeli PTT w kanałach mIRC. message-list (mosADD) oddaje przy notatce ptt/voice
|
|
3
|
+
* `transcript` uprawnieniami czytającego (RLS ptt_transcripts: członek kanału), a mIRC_list_messages wyrzucał to pole:
|
|
4
|
+
* agent dostawał sam „[voice note — 25s]”, choć transkrypt leżał w bazie.
|
|
5
|
+
*
|
|
6
|
+
* Pilnowane:
|
|
7
|
+
* 1. notatka z transkryptem → text „[voice note — 25s] <transkrypcja>” + pole voice;
|
|
8
|
+
* 2. notatka bez transkryptu (jeszcze się robi) → sam znacznik, voice.transcript = null;
|
|
9
|
+
* 3. zwykły tekst bez zmian i bez pola voice;
|
|
10
|
+
* 4. mDM_list składa text tą samą formułą (druga strona rozmowy słyszy).
|
|
11
|
+
*
|
|
12
|
+
* SABOTAŻ (30.11): `text: voiceText(…, glos.voice)` → `text: formatVoiceIfAny(…)` w mirc-messages.ts → czerwone 1.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { describe, expect, it, vi } from "vitest";
|
|
16
|
+
import type { MosaddTool } from "../types.js";
|
|
17
|
+
import { voiceText } from "../tools/voice-format.js";
|
|
18
|
+
|
|
19
|
+
const CHANNEL_ID = "d0193de5-7a77-45d0-82e6-673effcc0077";
|
|
20
|
+
const b64 = (s: string) => Buffer.from(s, "utf8").toString("base64");
|
|
21
|
+
const notatka = b64(JSON.stringify({ audio: "A".repeat(4000), mime: "audio/webm", dur: 25_000 }));
|
|
22
|
+
|
|
23
|
+
vi.mock("../crypto/channel-e2ee.js", () => ({
|
|
24
|
+
decryptChannelPayload: async () => null,
|
|
25
|
+
encryptChannelPayload: async () => null,
|
|
26
|
+
unwrapEnvelopeText: (s: string) => s,
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
29
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
30
|
+
invokeFunction: async (fn: string) => {
|
|
31
|
+
if (fn === "channel-manage") return { linked_space_id: "space-1" };
|
|
32
|
+
if (fn === "message-list") {
|
|
33
|
+
return {
|
|
34
|
+
messages: [
|
|
35
|
+
{ id: "m-ptt", sender_identity_id: "czlowiek", encrypted_payload: notatka, created_at: "2026-11-30T01:45:43Z",
|
|
36
|
+
message_type: "ptt", transcript: "Szuflady mają się zamykać płynnie.", audio_url: null, duration_ms: null },
|
|
37
|
+
{ id: "m-ptt-w-drodze", sender_identity_id: "czlowiek", encrypted_payload: notatka, created_at: "2026-11-30T01:46:00Z",
|
|
38
|
+
message_type: "ptt", transcript: null, audio_url: null, duration_ms: null },
|
|
39
|
+
{ id: "m-txt", sender_identity_id: "czlowiek", encrypted_payload: b64("zwykły tekst"), created_at: "2026-11-30T01:47:00Z",
|
|
40
|
+
message_type: "txt" },
|
|
41
|
+
],
|
|
42
|
+
next_before: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`unexpected edge function ${fn}`);
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const ctx = { log: () => {} } as never;
|
|
50
|
+
const { mircMessagesTools } = await import("../tools/mirc-messages.js");
|
|
51
|
+
const lista = mircMessagesTools.find((t) => t.name === "mIRC_list_messages") as MosaddTool;
|
|
52
|
+
|
|
53
|
+
describe("PTT w kanale dociera do agenta jako tekst", () => {
|
|
54
|
+
it("1: notatka z transkryptem → „[voice note — 25s] <transkrypcja>” + pole voice", async () => {
|
|
55
|
+
const r = (await lista.handler({ channel_id: CHANNEL_ID }, ctx)) as { messages: Array<Record<string, unknown>> };
|
|
56
|
+
const m = r.messages.find((x) => x.id === "m-ptt")!;
|
|
57
|
+
expect(m.text).toBe("[voice note — 25s] Szuflady mają się zamykać płynnie.");
|
|
58
|
+
expect(m.voice).toEqual({ transcript: "Szuflady mają się zamykać płynnie.", audio_url: null, duration_ms: null });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("2: notatka bez transkryptu → sam znacznik, transcript null", async () => {
|
|
62
|
+
const r = (await lista.handler({ channel_id: CHANNEL_ID }, ctx)) as { messages: Array<Record<string, unknown>> };
|
|
63
|
+
const m = r.messages.find((x) => x.id === "m-ptt-w-drodze")!;
|
|
64
|
+
expect(m.text).toBe("[voice note — 25s]");
|
|
65
|
+
expect((m.voice as { transcript: unknown }).transcript).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("3: zwykły tekst bez zmian i bez pola voice", async () => {
|
|
69
|
+
const r = (await lista.handler({ channel_id: CHANNEL_ID }, ctx)) as { messages: Array<Record<string, unknown>> };
|
|
70
|
+
const m = r.messages.find((x) => x.id === "m-txt")!;
|
|
71
|
+
expect(m.text).toBe("zwykły tekst");
|
|
72
|
+
expect(m).not.toHaveProperty("voice");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("4: voiceText — znacznik z czasu trwania, gdy payload nie niesie znacznika; mDM_list używa tej formuły", () => {
|
|
76
|
+
expect(voiceText("<undecryptable>", { transcript: "raz dwa", duration_ms: 4_400 })).toBe("[voice note — 4s] raz dwa");
|
|
77
|
+
expect(voiceText("", { transcript: " ", duration_ms: null })).toBe("[voice note]");
|
|
78
|
+
expect(voiceText("tekst", undefined)).toBe("tekst");
|
|
79
|
+
const mdm = readFileSync(new URL("../tools/mdm.ts", import.meta.url), "utf8");
|
|
80
|
+
expect(mdm).toContain("m.voice ? { ...m, text: voiceText(m.text, m.voice) } : m");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mRAG_search diagnostics — what rag-query reports about HOW it found the sources (partial / keyword fallback / per-stage timing)
|
|
3
|
+
* must reach the agent. Before this the handler kept only answer/sources/chunks_found, so a keyword-only fallback after a vector
|
|
4
|
+
* timeout (2026-11-22 incident: 0 sources, "przekroczyło limit czasu") looked identical to an empty memory and no stage time was visible.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
7
|
+
|
|
8
|
+
let backend: Record<string, unknown> = {};
|
|
9
|
+
|
|
10
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
11
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
12
|
+
invokeFunction: () => Promise.resolve(backend),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const { knowledgeTools } = await import("../tools/knowledge.js");
|
|
16
|
+
const search = knowledgeTools.find((t) => t.name === "mRAG_search")!;
|
|
17
|
+
const ctx = { log: () => {} } as never;
|
|
18
|
+
|
|
19
|
+
const source = { source_type: "file", source_id: "u", thread_id: null, similarity: 0, snippet: "punkt startu", created_at: "2026-11-21T00:00:00Z" };
|
|
20
|
+
|
|
21
|
+
describe("mRAG_search diagnostics", () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
backend = {};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("keyword fallback after a vector timeout: partial, reason, mode and per-stage timing reach the agent", async () => {
|
|
27
|
+
backend = {
|
|
28
|
+
answer: "[mRAG · wynik częściowy] Etap wektorowy nie zdążył w limicie (3500 ms) — pokazuję wyszukiwanie po słowach: 1 źr.",
|
|
29
|
+
sources: [source],
|
|
30
|
+
chunks_found: 1,
|
|
31
|
+
partial: true,
|
|
32
|
+
partial_reason: "search_timeout",
|
|
33
|
+
search_mode: "keyword",
|
|
34
|
+
timing: { embed_ms: 21, wektor_ms: 3495, slowa_ms: 40, total_ms: 3517 },
|
|
35
|
+
stages: { embed_ms: 21, wektor_ms: 3495, slowa_ms: 40, rerank_ms: null, synteza_ms: null, total_ms: 3517, status: { embed: "ok", wektor: "limit", slowa: "ok" } },
|
|
36
|
+
etapy_tekst: "must not leak into the tool result",
|
|
37
|
+
fresh_chunks: 0,
|
|
38
|
+
};
|
|
39
|
+
const r = (await search.handler({ query: "marocain-punkt-startu" }, ctx)) as Record<string, unknown>;
|
|
40
|
+
expect(r.partial).toBe(true);
|
|
41
|
+
expect(r.partial_reason).toBe("search_timeout");
|
|
42
|
+
expect(r.search_mode).toBe("keyword");
|
|
43
|
+
expect((r.timing as Record<string, number>).wektor_ms).toBe(3495);
|
|
44
|
+
expect(((r.stages as { status: Record<string, string> }).status).wektor).toBe("limit");
|
|
45
|
+
expect(r.chunks_found).toBe(1);
|
|
46
|
+
expect(r.answer).toMatch(/^\[mRAG/);
|
|
47
|
+
// only the documented fields are forwarded, not whatever else the backend happens to send
|
|
48
|
+
expect(Object.keys(r).sort()).toEqual(["answer", "chunks_found", "partial", "partial_reason", "search_mode", "sources", "stages", "timing"]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("a named empty synthesis (degraded) is forwarded together with the sources", async () => {
|
|
52
|
+
backend = { answer: "[mRAG · bez syntezy] Model nie zwrócił odpowiedzi.", sources: [source], chunks_found: 1, degraded: "ai_unavailable", search_mode: "hybrid" };
|
|
53
|
+
const r = (await search.handler({ query: "x", answer: true }, ctx)) as Record<string, unknown>;
|
|
54
|
+
expect(r.degraded).toBe("ai_unavailable");
|
|
55
|
+
expect(r.sources).toHaveLength(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("an older backend (no diagnostics) yields exactly the old three-field result", async () => {
|
|
59
|
+
backend = { answer: "", sources: [source], chunks_found: 1 };
|
|
60
|
+
const r = (await search.handler({ query: "x" }, ctx)) as Record<string, unknown>;
|
|
61
|
+
expect(Object.keys(r).sort()).toEqual(["answer", "chunks_found", "sources"]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("null diagnostics are dropped, partial:false is kept (it is information)", async () => {
|
|
65
|
+
backend = { answer: "", sources: [], chunks_found: 0, partial: false, degraded: null, timing: null };
|
|
66
|
+
const r = (await search.handler({ query: "x" }, ctx)) as Record<string, unknown>;
|
|
67
|
+
expect(r.partial).toBe(false);
|
|
68
|
+
expect("degraded" in r).toBe(false);
|
|
69
|
+
expect("timing" in r).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("the tool description promises exactly what the handler now delivers", () => {
|
|
73
|
+
expect(search.description).toMatch(/partial:true/);
|
|
74
|
+
expect(search.description).toMatch(/partial_reason/);
|
|
75
|
+
expect(search.description).toMatch(/keyword fallback/);
|
|
76
|
+
expect(search.description).toMatch(/timing/);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -174,8 +174,8 @@ describe("comms_session_attach", () => {
|
|
|
174
174
|
expect(out.attached).toBe(true);
|
|
175
175
|
expect(out.identity_id).toBe(AGENT_ID);
|
|
176
176
|
expect((out.speaking_as as { address: string }).address).toBe("agent-one@mosadd.com");
|
|
177
|
-
// The signing declaration message-send reads —
|
|
178
|
-
//
|
|
177
|
+
// The signing declaration message-send reads — arbitrated in SQL:
|
|
178
|
+
// claimed through the RPC, not a raw upsert.
|
|
179
179
|
expect(calls.rpcs).toContainEqual({
|
|
180
180
|
name: "mosadd_gateway_binding_claim",
|
|
181
181
|
args: {
|
|
@@ -15,7 +15,7 @@ describe("@mosadd/mcp", () => {
|
|
|
15
15
|
// mIRC (5 tools)
|
|
16
16
|
expect(names).toContain("mIRC_create");
|
|
17
17
|
expect(names).toContain("mIRC_delete");
|
|
18
|
-
// mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered
|
|
18
|
+
// mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered
|
|
19
19
|
// (surveillance-era direction killed 2026-06-27; on-device security pillar, not an MCP tool)
|
|
20
20
|
expect(names).toContain("mURL_post");
|
|
21
21
|
expect(names).toContain("mAYL_send");
|
|
@@ -25,9 +25,9 @@ describe("@mosadd/mcp", () => {
|
|
|
25
25
|
|
|
26
26
|
it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
|
|
27
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
|
|
28
|
+
const mailName = /^mp0st_[a-z][a-z0-9_]*$/; // mail module codename
|
|
29
29
|
const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
|
|
30
|
-
const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine
|
|
30
|
+
const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine
|
|
31
31
|
for (const tool of allTools) {
|
|
32
32
|
expect(tool.name).toMatch(
|
|
33
33
|
new RegExp(`${channelName.source}|${mailName.source}|${metaName.source}|${threatName.source}`),
|
|
@@ -35,9 +35,9 @@ const SURFACES: { file: string; re: RegExp; what: string }[] = [
|
|
|
35
35
|
{ file: "README.md", re: /^(\d+) tools in `@mosadd\/mcp`/m, what: "README tools section" },
|
|
36
36
|
{ file: "packages/mcp/server.json", re: /(\d+)\s+MCP tools/, what: "MCP registry manifest description" },
|
|
37
37
|
// The npm-visible description — what `npm view @mosadd/mcp description` and the npmjs.com
|
|
38
|
-
// page show. Added 2026-07-30
|
|
38
|
+
// page show. Added 2026-07-30: it already said 73 but nothing enforced it.
|
|
39
39
|
{ file: "packages/mcp/package.json", re: /—\s*(\d+)\s+tools\s+—/, what: "package.json description" },
|
|
40
|
-
// Added 2026-08-01 (content-truth audit
|
|
40
|
+
// Added 2026-08-01 (content-truth audit): six surfaces the gate did
|
|
41
41
|
// not pin had silently drifted to 69/66/71/22/4 while TOOL_COUNT was 73. Every public
|
|
42
42
|
// file that hand-types a total is now listed here — if you add a surface with a
|
|
43
43
|
// number, add it to this array in the same PR.
|
|
@@ -46,7 +46,7 @@ const SURFACES: { file: string; re: RegExp; what: string }[] = [
|
|
|
46
46
|
{ file: "examples/README.md", re: /\*\*(\d+) live MCP tools across/, what: "examples README header" },
|
|
47
47
|
{ file: "packages/mcp/README.md", re: /One key, one server, (\d+) tools/, what: "@mosadd/mcp README intro" },
|
|
48
48
|
{ file: "packages/mcp/README.md", re: /\*\*(\d+) callable tools\*\* in total/, what: "@mosadd/mcp README breakdown" },
|
|
49
|
-
// Added 2026-09-04 (
|
|
49
|
+
// Added 2026-09-04 (docs review): three more public files hand-typed a total
|
|
50
50
|
// and had sat at 77 through two bumps (82, 84) because nothing pinned them. Both realm llms.txt
|
|
51
51
|
// lines are pinned separately — a single /(\d+) tools/ would only ever see the first.
|
|
52
52
|
// The package's own number, 85 on 2026-09-29, pinned where a text describes @mosadd/mcp itself.
|
|
@@ -208,7 +208,7 @@ const MODULE_SURFACES: { file: string; what: string; re: (label: string) => RegE
|
|
|
208
208
|
// "mDM (14) + mIRC (24) + … ; capabilities: mTALK (6) + mRAG (4) + …"
|
|
209
209
|
re: (label) => new RegExp(`\\b${label}_?\\s*\\((\\d+)\\)\\s*[+=;]`),
|
|
210
210
|
},
|
|
211
|
-
// Added 2026-09-04 (
|
|
211
|
+
// Added 2026-09-04 (docs review). Measured that day: examples/README.md had
|
|
212
212
|
// its header bumped to 85 while its own addends still read mDM (14) / mRAG (4) / comms (4) — a
|
|
213
213
|
// breakdown summing to 78 under a headline of 85, the exact shape this gate exists for. The
|
|
214
214
|
// realm llms.txt and the Smithery copy carried mDM 14 / mIRC 24 / mRAG 4 from alpha.33.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Channel E2EE for MCP toolkit LINES (F4
|
|
2
|
+
* Channel E2EE for MCP toolkit LINES (F4).
|
|
3
3
|
*
|
|
4
4
|
* The mosadd.com app encrypts text on password/private channels with a per-channel
|
|
5
5
|
* group key (AES-256-GCM + HMAC-SHA256), wrapped for each member to the member's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mDM end-to-end encryption — session layer
|
|
2
|
+
* mDM end-to-end encryption — session layer.
|
|
3
3
|
*
|
|
4
4
|
* Sits ABOVE the DmProvider. The provider moves opaque bytes; THIS module
|
|
5
5
|
* decides what those bytes are: an X3DH handshake + Double Ratchet ciphertext
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* run X3DH (responder) and derive the SAME root key.
|
|
14
14
|
* - Subsequent messages reuse the stored ratchet session (no header).
|
|
15
15
|
*
|
|
16
|
-
* SCOPE / known follow-ups (tracked
|
|
16
|
+
* SCOPE / known follow-ups (tracked, NOT silently hidden):
|
|
17
17
|
* - Ratchet is strict in-order (no skipped-message keys) — fine for a single
|
|
18
18
|
* ordered thread; out-of-order/lossy transports need skipped-key handling.
|
|
19
19
|
* - Signed-prekey signature is carried but NOT yet verified (auth follow-up).
|
|
@@ -52,7 +52,7 @@ import type { DmProvider } from "@mosadd/providers";
|
|
|
52
52
|
export const PREKEY_BUNDLE_VERSION = "mosadd.prekeys.v1" as const;
|
|
53
53
|
/** Legacy symmetric-ratchet envelope (no PCS). Still DECODED for back-compat. */
|
|
54
54
|
export const E2EE_ENVELOPE_VERSION = "mosadd.e2ee.v1" as const;
|
|
55
|
-
/** Double-Ratchet-with-DH envelope — post-compromise security
|
|
55
|
+
/** Double-Ratchet-with-DH envelope — post-compromise security. New sends use this. */
|
|
56
56
|
export const E2EE_ENVELOPE_VERSION_V2 = "mosadd.e2ee.v2" as const;
|
|
57
57
|
|
|
58
58
|
const DEFAULT_ONE_TIME_PREKEYS = 8;
|
|
@@ -96,7 +96,7 @@ export interface PublicPrekeyBundle {
|
|
|
96
96
|
*/
|
|
97
97
|
export interface MdmSessionRecord {
|
|
98
98
|
ratchet?: RatchetState; // v1 (legacy symmetric)
|
|
99
|
-
ratchet2?: DhRatchetState; // v2 (DH ratchet, PCS
|
|
99
|
+
ratchet2?: DhRatchetState; // v2 (DH ratchet, PCS)
|
|
100
100
|
role: SessionRole;
|
|
101
101
|
/** Handshake header still owed to the peer (initiator only, until first send). */
|
|
102
102
|
pendingHandshake?: { ik: Uint8Array; ek: Uint8Array; opkId?: number };
|
|
@@ -194,7 +194,7 @@ function randomId(): number {
|
|
|
194
194
|
|
|
195
195
|
// ---- Seed-backed keystore: ONE stable identity, not a new one per call ----
|
|
196
196
|
//
|
|
197
|
-
// ⛔ WHY (measured 27.09.2026,
|
|
197
|
+
// ⛔ WHY (measured 27.09.2026, follow-up fix): the hosted gateway builds a fresh
|
|
198
198
|
// McpServer per HTTP request, so the default InMemoryMdmKeyStore minted a BRAND-NEW random
|
|
199
199
|
// identity for every single mDM_send. Every envelope carried an X3DH header from an identity
|
|
200
200
|
// that existed for one request and was never published — the sender could never read its own
|
|
@@ -202,7 +202,7 @@ function randomId(): number {
|
|
|
202
202
|
// written (it needs the sender's PUBLISHED identity). The app (mosADD f95557f) now says WHY such
|
|
203
203
|
// a bubble is unreadable; this is the source fix, so new messages are born readable.
|
|
204
204
|
//
|
|
205
|
-
// The fix mirrors the web client exactly (apps/web/src/lib/mdmKeyStore.ts
|
|
205
|
+
// The fix mirrors the web client exactly (apps/web/src/lib/mdmKeyStore.ts): the
|
|
206
206
|
// whole identity is derived by HKDF from ONE recoverable 32-byte seed, with the SAME labels, zero
|
|
207
207
|
// one-time prekeys and signed-prekey id 1 — so the bundle is byte-identical on every process that
|
|
208
208
|
// knows the seed. The web takes its seed from the login secret; an MCP runtime has no password,
|
|
@@ -451,20 +451,20 @@ export interface BundlePolicy {
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
|
-
* ⛔ WHO MAY WRITE THE KEY DIRECTORY FROM MCP (27.09.2026,
|
|
454
|
+
* ⛔ WHO MAY WRITE THE KEY DIRECTORY FROM MCP (27.09.2026, fix after independent verification of the mDM gateway path).
|
|
455
455
|
*
|
|
456
456
|
* The MCP identity is seeded from ONE API key. A mosADD identity has MANY active keys (every OAuth
|
|
457
|
-
* connector mints its own — measured 27.09: 7 of 17 agent identities hold several,
|
|
457
|
+
* connector mints its own — measured 27.09: 7 of 17 agent identities hold several, one of them
|
|
458
458
|
* 8, all used within 3 days). A per-key identity that is allowed to (re)publish therefore makes the
|
|
459
459
|
* directory FLAP between up to 8 identities: copies sealed under key A stop opening once key B
|
|
460
460
|
* published, and envelopes sealed to "the" bundle open on one key only. So:
|
|
461
461
|
*
|
|
462
|
-
* - kind "agent": an agent LINE sends
|
|
463
|
-
*
|
|
462
|
+
* - kind "agent": an agent LINE sends IN THE CLEAR (plaintext) — owner decision 20.09 "no internal
|
|
463
|
+
* E2EE": line↔line, line↔owner and person→line all without E2EE; the app does the same
|
|
464
464
|
* (ircApi.ts peerIsAgent). An agent never needs a bundle for mDM_send, so the AUTOMATIC paths
|
|
465
465
|
* write nothing. Only an explicit mDM_publish_keys still publishes (the caller asked for it).
|
|
466
466
|
* - kind "human": the person's bundle is anchored to their login secret IN THE APP
|
|
467
|
-
* (mdmKeyStore.setIdentitySeed;
|
|
467
|
+
* (mdmKeyStore.setIdentitySeed; rule in hub-key-exchange: only the identity's own client
|
|
468
468
|
* publishes). MCP never replaces it and never pre-empts it on an empty directory automatically
|
|
469
469
|
* — a bundle published from an API-key seed would be overwritten by the app later and strand
|
|
470
470
|
* everything sealed to it meanwhile. Explicit mDM_publish_keys may fill an EMPTY directory.
|
|
@@ -701,7 +701,7 @@ export async function encryptForPeer(
|
|
|
701
701
|
oneTimePreKeyPublicKey: opk?.publicKey,
|
|
702
702
|
});
|
|
703
703
|
// New sessions use the DH ratchet (v2 / PCS). The initial remote ratchet key
|
|
704
|
-
// is the peer's signed prekey (the X3DH→DR handoff).
|
|
704
|
+
// is the peer's signed prekey (the X3DH→DR handoff).
|
|
705
705
|
const ratchet2 = await initRatchetInitiator(rootKey, peer.signedPrekey.publicKey);
|
|
706
706
|
session = {
|
|
707
707
|
ratchet2,
|
|
@@ -787,7 +787,7 @@ export async function decryptFromPeer(
|
|
|
787
787
|
peerId: string,
|
|
788
788
|
envelopeBytes: Uint8Array,
|
|
789
789
|
): Promise<Uint8Array> {
|
|
790
|
-
// v2 (DH ratchet / PCS)
|
|
790
|
+
// v2 (DH ratchet / PCS).
|
|
791
791
|
if (peekEnvelopeVersion(envelopeBytes) === E2EE_ENVELOPE_VERSION_V2) {
|
|
792
792
|
const env = parseEnvelopeV2(envelopeBytes);
|
|
793
793
|
let session = await keystore.getSession(peerId);
|
|
@@ -833,7 +833,7 @@ export async function decryptFromPeer(
|
|
|
833
833
|
if (step.messageIndex !== env.i) {
|
|
834
834
|
throw new Error(
|
|
835
835
|
`Out-of-order mDM message (expected ratchet index ${step.messageIndex}, got ${env.i}). ` +
|
|
836
|
-
`Skipped-key handling is a tracked follow-up
|
|
836
|
+
`Skipped-key handling is a tracked follow-up.`,
|
|
837
837
|
);
|
|
838
838
|
}
|
|
839
839
|
const plaintext = await decryptBytes(step.messageKey, env.ct);
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
DmMessage,
|
|
21
21
|
} from "@mosadd/providers";
|
|
22
22
|
import { getSupabase, invokeFunction, readSupabaseEnv } from "./supabase.js";
|
|
23
|
+
import { attachmentsFrom, type MessageAttachment } from "../tools/voice-format.js";
|
|
23
24
|
|
|
24
25
|
const PROTOCOL_VERSION = "mosadd.chat.v1";
|
|
25
26
|
|
|
@@ -66,6 +67,8 @@ export interface DmMessageExt extends DmMessage {
|
|
|
66
67
|
transcript?: string | null;
|
|
67
68
|
audioUrl?: string | null;
|
|
68
69
|
durationMs?: number | null;
|
|
70
|
+
/** 30.11: pliki wiadomości z message-list (fileEnrich.ts w mosADD) — podpisany adres, prawa czytającego. */
|
|
71
|
+
files?: MessageAttachment[];
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
export class SupabaseDmProvider implements DmProvider {
|
|
@@ -86,7 +89,7 @@ export class SupabaseDmProvider implements DmProvider {
|
|
|
86
89
|
* `identities.kind` of a PEER, or null when it cannot be read (RLS can_see_identity scopes rows
|
|
87
90
|
* to contacts / thread co-members; a miss is not an error). mDM_send uses it exactly like the
|
|
88
91
|
* app's ChatPanel `peerIsAgent` (theirIdent.kind === 'agent' || iAmAgent): a DM to an agent
|
|
89
|
-
* line is sent in the clear, because the line must read it (
|
|
92
|
+
* line is sent in the clear, because the line must read it (owner decision 20.09).
|
|
90
93
|
*/
|
|
91
94
|
async peerKind(peerId: string): Promise<string | null> {
|
|
92
95
|
try {
|
|
@@ -178,6 +181,7 @@ export class SupabaseDmProvider implements DmProvider {
|
|
|
178
181
|
transcript?: string | null;
|
|
179
182
|
audio_url?: string | null;
|
|
180
183
|
duration_ms?: number | null;
|
|
184
|
+
files?: unknown;
|
|
181
185
|
}>;
|
|
182
186
|
cursor?: string | null;
|
|
183
187
|
has_more?: boolean;
|
|
@@ -204,6 +208,7 @@ export class SupabaseDmProvider implements DmProvider {
|
|
|
204
208
|
transcript: m.transcript ?? null,
|
|
205
209
|
audioUrl: m.audio_url ?? null,
|
|
206
210
|
durationMs: m.duration_ms ?? null,
|
|
211
|
+
files: attachmentsFrom(m.files),
|
|
207
212
|
})),
|
|
208
213
|
// history mode (`before`) returns `next_before`; incremental (`since`) returns `cursor`+`has_more`.
|
|
209
214
|
nextCursor: data?.next_before ?? (data?.has_more ? (data?.cursor ?? null) : null),
|
|
@@ -114,18 +114,18 @@ export function getSupabase(env: SupabaseEnv = readSupabaseEnv()): SupabaseClien
|
|
|
114
114
|
autoRefreshToken: false,
|
|
115
115
|
detectSessionInUrl: false,
|
|
116
116
|
},
|
|
117
|
-
// ⛔ x-mosadd-origin:
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// hub-key-exchange
|
|
121
|
-
//
|
|
122
|
-
//
|
|
117
|
+
// ⛔ x-mosadd-origin: EVERY call from the toolkit / MCP gateway carries this marker (2026-08-25,
|
|
118
|
+
// after agent sessions were found speaking as their owner). Agent sessions plugged in the OWNER's
|
|
119
|
+
// key and posted on channels from the owner's own bubble — the server had NO WAY to tell the gateway
|
|
120
|
+
// from the app, because hub-key-exchange returns an ordinary user JWT. This header tells them apart:
|
|
121
|
+
// message-send refuses a channel post from a PERSON's identity when it came through the gateway, with
|
|
122
|
+
// a message telling the caller to plug in its OWN line's key. The mosadd.com app never sends this header.
|
|
123
123
|
global: {
|
|
124
124
|
headers: {
|
|
125
125
|
...(env.userJwt ? { Authorization: `Bearer ${env.userJwt}` } : {}),
|
|
126
126
|
"x-mosadd-origin": "hub-gateway",
|
|
127
|
-
//
|
|
128
|
-
//
|
|
127
|
+
// The header only when the session HAS an identity — an empty "" (gateway without sessionKey) sends
|
|
128
|
+
// nothing, so the server-side 409 guard sees no false claims.
|
|
129
129
|
...(sessionId() ? { "x-mosadd-session": sessionId() } : {}),
|
|
130
130
|
// ⛔ KTÓRA TO SESJA (2026-08-27, „każdy generał co chwilę gubi mózg"). Wszyscy generałowie
|
|
131
131
|
// wpinają się kluczem hub TEGO SAMEGO właściciela, więc dla serwera ich wywołania były
|
package/src/server.ts
CHANGED
|
@@ -78,9 +78,9 @@ export function createMosaddServer(options: MosaddServerOptions = {}) {
|
|
|
78
78
|
// etc.) and never blocks startup. Uses the SAME keystore the tools use, so the
|
|
79
79
|
// published identity matches what mDM_send/encryptForPeer will use this process.
|
|
80
80
|
//
|
|
81
|
-
// ⛔ ENSURE, NOT BLIND PUBLISH (27.09.2026,
|
|
81
|
+
// ⛔ ENSURE, NOT BLIND PUBLISH (27.09.2026, fix after verification): the policy is
|
|
82
82
|
// bundlePolicyForKind — the SAME one mDM_send uses. Agent line: writes NOTHING (it sends in the
|
|
83
|
-
// clear,
|
|
83
|
+
// clear, owner decision 20.09; a per-key bundle from each of its keys only made the directory flap).
|
|
84
84
|
// Human: writes NOTHING (the app owns that bundle). Unknown kind (e.g. radio): empty -> publish.
|
|
85
85
|
if (options.autoPublishKeys) {
|
|
86
86
|
void (async () => {
|
|
@@ -98,7 +98,7 @@ export function createMosaddServer(options: MosaddServerOptions = {}) {
|
|
|
98
98
|
// Human-facing identity of the server itself (initialize result). The icon URLs
|
|
99
99
|
// point at the LIVE gateway origin on purpose: clients that honour serverInfo.icons
|
|
100
100
|
// get the brand mark without scraping the favicon, and the files ship with
|
|
101
|
-
// the gateway's public/ folder (
|
|
101
|
+
// the gateway's public/ folder (brand rule of 2026-08-26 — generated by m0ssad-3 scripts/
|
|
102
102
|
// generate-brand-icons.py, never hand-edited).
|
|
103
103
|
title: "mosADD — omnichannel messenger for agents",
|
|
104
104
|
websiteUrl: "https://mosadd.com",
|
|
@@ -137,7 +137,7 @@ export function createMosaddServer(options: MosaddServerOptions = {}) {
|
|
|
137
137
|
const parsed = tool.inputSchema.parse(input);
|
|
138
138
|
try {
|
|
139
139
|
const result = await tool.handler(parsed as never, ctx);
|
|
140
|
-
// AUTO-
|
|
140
|
+
// AUTO-PAIRING (08-26): a LIVE session that is actually WORKING holds its line —
|
|
141
141
|
// the founder spent a week talking to cloud stand-ins because models never
|
|
142
142
|
// remembered the attach handshake. Fire-and-forget, throttled inside, never blocks
|
|
143
143
|
// the tool's own response; see autoBeatFromActivity for which line gets the beat.
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* channel-payload — stored channel/room payload (base64) → the text a reader should see.
|
|
3
3
|
*
|
|
4
4
|
* Plaintext for agent lines since 29.09 (owner decision 28.09: no encryption on agent-line conversations,
|
|
5
|
-
* in any channel or identity).
|
|
6
|
-
* yet every line reading them through this gateway saw the
|
|
5
|
+
* in any channel or identity). The fleet's ops channels are OPEN channels with no group key,
|
|
6
|
+
* yet every line reading them through this gateway saw the owner's posts as "<ciphertext>". Nothing
|
|
7
7
|
* was encrypted: the app stores channel text as plain UTF-8 in base64 (apps/web ircApi.ts
|
|
8
8
|
* `encodePayload`), while the old decoder here understood ONLY a JSON `mosadd.chat.v1` envelope
|
|
9
|
-
* and stamped everything else "<ciphertext>". Measured 28.09–29.09 on
|
|
9
|
+
* and stamped everything else "<ciphertext>". Measured 28.09–29.09 on an open ops channel.
|
|
10
10
|
*
|
|
11
11
|
* Rule now (same as mdm.ts `unpackPayload` and the mKEEPER bridge `decodePayload.mjs`):
|
|
12
12
|
* - JSON envelope with `text` → that text (toolkit posts, unchanged)
|