@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +420 -410
  2. package/LICENSE +21 -0
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-VMMJJYXF.js → chunk-I3FSPQ4G.js} +78 -30
  5. package/dist/index.d.ts +6 -6
  6. package/dist/index.js +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/blob-upload.test.ts +1 -1
  9. package/src/__tests__/{flota-jawnie.test.ts → fleet-plaintext.test.ts} +59 -60
  10. package/src/__tests__/integration.test.ts +1 -1
  11. package/src/__tests__/mdm-e2ee.test.ts +3 -3
  12. package/src/__tests__/mdm-mcp-readable.test.ts +95 -95
  13. package/src/__tests__/mirc-files.test.ts +80 -0
  14. package/src/__tests__/mirc-invite.test.ts +1 -1
  15. package/src/__tests__/mirc-voice.test.ts +82 -0
  16. package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
  17. package/src/__tests__/presence.test.ts +2 -2
  18. package/src/__tests__/server.test.ts +3 -3
  19. package/src/__tests__/tool-count-consistency.test.ts +4 -4
  20. package/src/crypto/channel-e2ee.ts +1 -1
  21. package/src/crypto/mdm-session.ts +14 -14
  22. package/src/providers/supabase-dm.ts +6 -1
  23. package/src/providers/supabase.ts +8 -8
  24. package/src/server.ts +4 -4
  25. package/src/tools/channel-payload.ts +3 -3
  26. package/src/tools/index.ts +13 -13
  27. package/src/tools/knowledge.ts +384 -351
  28. package/src/tools/mail-aliases.ts +1 -1
  29. package/src/tools/mail-provenance.ts +1 -1
  30. package/src/tools/mdm-as-agent.ts +3 -4
  31. package/src/tools/mdm.ts +19 -14
  32. package/src/tools/mirc-edge.ts +4 -4
  33. package/src/tools/mirc-members.ts +1 -1
  34. package/src/tools/mirc-messages.ts +41 -12
  35. package/src/tools/mirc.ts +1 -1
  36. package/src/tools/mroom-messages.ts +1 -1
  37. package/src/tools/presence.ts +10 -10
  38. package/src/tools/ptt-ingest.ts +1 -1
  39. package/src/tools/threat.ts +1 -1
  40. package/src/tools/voice-format.ts +53 -7
@@ -1,22 +1,21 @@
1
1
  /**
2
- * ZAMEK „ZERO SZYFROWANIA Z FLOTA" (29.09.2026, owner decision 28.09: no encryption on agent-line
2
+ * LOCK "NO ENCRYPTION WITH THE FLEET" (29.09.2026, owner decision 28.09: no encryption on agent-line
3
3
  * conversations, in any channel or identity).
4
4
  *
5
- * Dwie reguly bramy MCP, obie zmierzone jako zepsute 28–29.09 (Public\ZERO-SZYFROWANIA-29-09,
6
- * D1 §3 i S1 §1b):
5
+ * Two rules of the MCP gateway, both measured as broken on 28–29.09:
7
6
  *
8
- * c1 — DEKODER KANALU. #adm i #command sa otwarte, bez klucza grupowego. Aplikacja zapisuje
9
- * tekst kanalu jako goly UTF-8 w base64 (apps/web ircApi.ts `encodePayload`). Stary dekoder
10
- * (`mirc-messages.ts` / `mroom-messages.ts` `unpackPayload`) znal tylko koperte JSON, wiec
11
- * KAZDY wpis Krola czytal sie liniom jako "<ciphertext>" (f159c8d7, 776b3e9a na #adm).
12
- * Teraz: jawny tekst = tekst. "<ciphertext>" zostaje tylko dla prawdziwej koperty klucza
13
- * grupowego {iv,ciphertext,hmac}, do ktorej linia nie ma klucza (i dla bajtow nie-UTF-8).
7
+ * c1 — CHANNEL DECODER. Open channels have no group key. The app stores channel text
8
+ * as bare UTF-8 in base64 (apps/web ircApi.ts `encodePayload`). The old decoder
9
+ * (`mirc-messages.ts` / `mroom-messages.ts` `unpackPayload`) knew only the JSON envelope, so
10
+ * EVERY post of the owner read as "<ciphertext>" for the agent lines.
11
+ * Now: plain text = text. "<ciphertext>" stays only for a real group-key envelope
12
+ * {iv,ciphertext,hmac} the line holds no key for (and for bytes that are not UTF-8).
14
13
  *
15
- * b1 — mDM_send DO FLOTY JAWNIE. Gdy ktoras strona to linia agenta ALBO to wiadomosc do siebie
16
- * (to === selfId), wysylka idzie sciezka jawna: encrypted:false, reason:"fleet_plaintext".
17
- * Czlowiek↔czlowiek zostaje E2EE bez zmian (koperta X3DH + Double Ratchet).
14
+ * b1 — mDM_send TO THE FLEET IN THE CLEAR. When either side is an agent line OR it is a note to self
15
+ * (to === selfId), the send takes the plain path: encrypted:false, reason:"fleet_plaintext".
16
+ * Person↔person stays E2EE, unchanged (X3DH + Double Ratchet envelope).
18
17
  *
19
- * Kazdy zamek sprawdzony na czerwono przed naprawa (kod alpha.54) i pod sabotazem po naprawie.
18
+ * Every lock was checked red before the fix (alpha.54 code) and under sabotage after the fix.
20
19
  */
21
20
  import { describe, expect, it, vi, beforeEach } from "vitest";
22
21
  import type { DmProvider, DmListArgs, DmListResult, DmSendResult } from "@mosadd/providers";
@@ -66,82 +65,82 @@ const listCtx = { log: noopLog } as unknown as MosaddToolContext;
66
65
  const appEncode = (text: string) => Buffer.from(new TextEncoder().encode(text)).toString("base64");
67
66
  const b64json = (obj: unknown) => Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
68
67
 
69
- const ADM = "6c251ebf-acb4-4f49-bd9a-7fc28e5cfee6";
70
- const KING = "king-identity";
71
- const LINE = "general-line-identity";
68
+ const CHANNEL = "00000000-0000-4000-8000-000000000001";
69
+ const OWNER = "owner-identity";
70
+ const LINE = "agent-line-identity";
72
71
  const PEER = "peer-human-identity";
73
- // Synthetic (the repo is public — no real message of the King goes into a fixture): Polish
74
- // diacritics, an em dash, an @mention, a newline and an emoji, like the King writes.
75
- const KING_TEXT = "Kto dowodzi flotą? Zgłoście się na #adm — żółć, źdźbło 🦞\n@all baczność";
72
+ // Synthetic (the repo is public — no real message goes into a fixture): Polish
73
+ // diacritics, an em dash, an @mention, a newline and an emoji, like a real owner post.
74
+ const OWNER_TEXT = "Zażółć gęślą jaźń — spotkanie o 9:00 🦞\n@all proszę o potwierdzenie";
76
75
 
77
76
  type ListOut = { messages: Array<{ id: string; text: string }> };
78
77
 
79
78
  async function readChannel(rows: Array<[string, string]>): Promise<string[]> {
80
79
  storedRows = rows.map(([id, payload], i) => ({
81
80
  id,
82
- sender_identity_id: KING,
81
+ sender_identity_id: OWNER,
83
82
  encrypted_payload: payload,
84
83
  created_at: new Date(i * 1000).toISOString(),
85
84
  }));
86
85
  const out = (await handler(mircMessagesTools, "mIRC_list_messages")(
87
- { channel_id: ADM, space_id: "space-adm", limit: 50 },
86
+ { channel_id: CHANNEL, space_id: "space-1", limit: 50 },
88
87
  listCtx,
89
88
  )) as ListOut;
90
89
  return out.messages.map((m) => m.text);
91
90
  }
92
91
 
93
- describe("c1 — dekoder kanalu: tekst Krola czyta sie jako tekst, <ciphertext> tylko dla zamknietej koperty", () => {
92
+ describe("c1 — channel decoder: the owner's text reads as text, <ciphertext> only for a sealed envelope", () => {
94
93
  beforeEach(() => {
95
94
  storedRows = [];
96
95
  groupKeyOpens = () => null;
97
96
  });
98
97
 
99
- it("wpis Krola z aplikacji (goly UTF-8 w base64) na otwartym #adm → czytelny tekst, nie <ciphertext>", async () => {
98
+ it("an owner post from the app (bare UTF-8 in base64) on an open channel → readable text, not <ciphertext>", async () => {
100
99
  const texts = await readChannel([
101
- ["f159c8d7", appEncode(KING_TEXT)],
102
- ["776b3e9a", appEncode("@all bacznosc")],
100
+ ["msg-1", appEncode(OWNER_TEXT)],
101
+ ["msg-2", appEncode("@all please confirm")],
103
102
  ]);
104
- expect(texts).toEqual([KING_TEXT, "@all bacznosc"]);
103
+ expect(texts).toEqual([OWNER_TEXT, "@all please confirm"]);
105
104
  expect(texts).not.toContain("<ciphertext>");
106
105
  });
107
106
 
108
- it("koperta mosadd.chat.v1 z narzedzia (linie) → jej tekst, jak dotad", async () => {
107
+ it("a mosadd.chat.v1 envelope from the tool (agent lines) → its text, as before", async () => {
109
108
  const texts = await readChannel([
110
- ["line-1", b64json({ v: "mosadd.chat.v1", type: "text", text: "meldunek linii", reply_to: null })],
109
+ ["line-1", b64json({ v: "mosadd.chat.v1", type: "text", text: "line report", reply_to: null })],
111
110
  ]);
112
- expect(texts).toEqual(["meldunek linii"]);
111
+ expect(texts).toEqual(["line report"]);
113
112
  });
114
113
 
115
- it("koperta klucza grupowego {iv,ciphertext,hmac} BEZ klucza → <ciphertext> zostaje", async () => {
114
+ it("a group-key envelope {iv,ciphertext,hmac} WITHOUT the key → <ciphertext> stays", async () => {
116
115
  const texts = await readChannel([["sealed", b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" })]]);
117
116
  expect(texts).toEqual(["<ciphertext>"]);
118
117
  });
119
118
 
120
- it("koperta klucza grupowego, linia MA klucz → odszyfrowany tekst (sciezka bez zmian)", async () => {
119
+ it("a group-key envelope, the line HAS the key → decrypted text (path unchanged)", async () => {
121
120
  const sealed = b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" });
122
- groupKeyOpens = (_c, p) => (p === sealed ? JSON.stringify({ v: "mosadd.chat.v1", type: "text", text: "z klucza" }) : null);
123
- expect(await readChannel([["sealed", sealed]])).toEqual(["z klucza"]);
121
+ groupKeyOpens = (_c, p) => (p === sealed ? JSON.stringify({ v: "mosadd.chat.v1", type: "text", text: "from the key" }) : null);
122
+ expect(await readChannel([["sealed", sealed]])).toEqual(["from the key"]);
124
123
  });
125
124
 
126
- it("koperta ratchetu mDM (v: mosadd.e2ee.*) wklejona w kanal → <ciphertext>", async () => {
125
+ it("an mDM ratchet envelope (v: mosadd.e2ee.*) pasted into a channel → <ciphertext>", async () => {
127
126
  const texts = await readChannel([["e2ee", b64json({ v: "mosadd.e2ee.v2", dh: "x", n: 0, ct: "y" })]]);
128
127
  expect(texts).toEqual(["<ciphertext>"]);
129
128
  });
130
129
 
131
- it("bajty nie-UTF-8 → <ciphertext> (to nie slowa)", async () => {
130
+ it("non-UTF-8 bytes → <ciphertext> (these are not words)", async () => {
132
131
  const texts = await readChannel([["bin", Buffer.from([0xff, 0xfe, 0x00, 0x81, 0xc3]).toString("base64")]]);
133
132
  expect(texts).toEqual(["<ciphertext>"]);
134
133
  });
135
134
 
136
- it("glos {audio, mime, dur} → znacznik notatki glosowej (formatVoiceIfAny bez zmian)", async () => {
135
+ it("voice {audio, mime, dur} → voice note marker (formatVoiceIfAny unchanged)", async () => {
137
136
  const texts = await readChannel([["voice", b64json({ audio: "A".repeat(2000), mime: "audio/webm", dur: 4200 })]]);
138
137
  expect(texts).toEqual(["[voice note — 4s]"]);
139
138
  });
140
139
 
141
- it("mROOM: ta sama regula — tekst z aplikacji czyta sie jako tekst", async () => {
142
- storedRows = [{ id: "r1", sender_identity_id: KING, encrypted_payload: appEncode(KING_TEXT), created_at: new Date(0).toISOString() }];
140
+ it("mROOM: the same rule — text from the app reads as text", async () => {
141
+ storedRows = [{ id: "r1", sender_identity_id: OWNER, encrypted_payload: appEncode(OWNER_TEXT), created_at: new Date(0).toISOString() }];
143
142
  const out = (await handler(mroomMessagesTools, "mROOM_list_messages")({ room_id: "room-1" }, listCtx)) as ListOut;
144
- expect(out.messages.map((m) => m.text)).toEqual([KING_TEXT]);
143
+ expect(out.messages.map((m) => m.text)).toEqual([OWNER_TEXT]);
145
144
  });
146
145
  });
147
146
 
@@ -189,56 +188,56 @@ const send = (b: Backend, from: string, to: string, text: string) =>
189
188
  handler(mdmTools, "mDM_send")({ to, text }, gatewayRequest(b, from)) as Promise<SendOut>;
190
189
  const plain = (row: Row) => new TextDecoder().decode(row.payload);
191
190
 
192
- describe("b1 — mDM_send: z liniami floty i z Krolem zawsze jawnie, czlowiek↔czlowiek E2EE", () => {
193
- it("linia agenta → Krol: encrypted:false, reason fleet_plaintext, Krol czyta goly tekst", async () => {
191
+ describe("b1 — mDM_send: with fleet lines and with the owner always in the clear, person↔person E2EE", () => {
192
+ it("agent line → owner: encrypted:false, reason fleet_plaintext, the owner reads bare text", async () => {
194
193
  const b = new Backend();
195
194
  b.kinds.set(LINE, "agent");
196
- await person(b, KING, 7);
197
- const s = await send(b, LINE, KING, "meldunek");
195
+ await person(b, OWNER, 7);
196
+ const s = await send(b, LINE, OWNER, "report");
198
197
  expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
199
198
  expect(b.rows.at(-1)!.messageType).toBe("txt");
200
- expect(plain(b.rows.at(-1)!)).toBe("meldunek");
199
+ expect(plain(b.rows.at(-1)!)).toBe("report");
201
200
  });
202
201
 
203
- it("Krol (klucz czlowieka) → linia agenta: jawnie, mimo ze linia ma stary pek", async () => {
202
+ it("owner (a person's key) → agent line: in the clear, even though the line has an old bundle", async () => {
204
203
  const b = new Backend();
205
204
  b.kinds.set(LINE, "agent");
206
- await person(b, KING, 7);
205
+ await person(b, OWNER, 7);
207
206
  b.bundles.set(LINE, serializePublicBundle(await new SeededMdmKeyStore(new Uint8Array(32).fill(9)).getOwnMaterial()));
208
- const s = await send(b, KING, LINE, "rozkaz");
207
+ const s = await send(b, OWNER, LINE, "instruction");
209
208
  expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
210
- expect(plain(b.rows.at(-1)!)).toBe("rozkaz");
209
+ expect(plain(b.rows.at(-1)!)).toBe("instruction");
211
210
  });
212
211
 
213
- it("Krol pisze do SIEBIE (to === selfId) przez MCP: jawnie — zero kopert we wlasnym watku", async () => {
212
+ it("the owner writes to SELF (to === selfId) through MCP: in the clear — zero envelopes in the own thread", async () => {
214
213
  const b = new Backend();
215
- await person(b, KING, 7);
216
- const s = await send(b, KING, KING, "notatka do siebie");
214
+ await person(b, OWNER, 7);
215
+ const s = await send(b, OWNER, OWNER, "note to self");
217
216
  expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
218
217
  const row = b.rows.at(-1)!;
219
- expect(row.threadId).toBe(`dm:${KING}:${KING}`);
218
+ expect(row.threadId).toBe(`dm:${OWNER}:${OWNER}`);
220
219
  expect(isE2eeEnvelope(row.payload)).toBe(false);
221
- expect(plain(row)).toBe("notatka do siebie");
220
+ expect(plain(row)).toBe("note to self");
222
221
  });
223
222
 
224
- it("czlowiek → czlowiek: E2EE zostaje — koperta ratchetu, tekstu nie widac, odbiorca otwiera", async () => {
223
+ it("person → person: E2EE stays — ratchet envelope, text not visible, the recipient opens it", async () => {
225
224
  const b = new Backend();
226
- await person(b, KING, 7);
225
+ await person(b, OWNER, 7);
227
226
  const peerKeys = await person(b, PEER, 5);
228
- const s = await send(b, KING, PEER, "tajne");
227
+ const s = await send(b, OWNER, PEER, "secret");
229
228
  expect(s).toMatchObject({ encrypted: true, mode: "e2ee" });
230
229
  expect(s.reason).not.toBe("fleet_plaintext");
231
230
  const row = b.rows.at(-1)!;
232
231
  expect(isE2eeEnvelope(row.payload)).toBe(true);
233
- expect(plain(row)).not.toContain("tajne");
234
- expect(new TextDecoder().decode(await decryptFromPeer(peerKeys, KING, row.payload))).toBe("tajne");
232
+ expect(plain(row)).not.toContain("secret");
233
+ expect(new TextDecoder().decode(await decryptFromPeer(peerKeys, OWNER, row.payload))).toBe("secret");
235
234
  });
236
235
 
237
- it("opisy narzedzi: mDM_send_unencrypted nie jest 'DEPRECATED / prefer mDM_send', obie mowia: floty zawsze jawnie", () => {
236
+ it("tool descriptions: mDM_send_unencrypted is not 'DEPRECATED / prefer mDM_send', both say: fleet always in the clear", () => {
238
237
  const d = (n: string) => mdmTools.find((t) => t.name === n)!.description;
239
238
  expect(d("mDM_send_unencrypted")).not.toMatch(/DEPRECATED|Prefer mDM_send|Will be removed/i);
240
239
  for (const n of ["mDM_send", "mDM_send_unencrypted"]) {
241
- expect(d(n)).toMatch(/fleet lines and with the King: ALWAYS in the clear/);
240
+ expect(d(n)).toMatch(/Conversations with fleet lines and with the [A-Za-z ]+: ALWAYS in the clear/);
242
241
  }
243
242
  });
244
243
  });
@@ -176,7 +176,7 @@ describe("@mosadd/mcp — integration (real stdio)", () => {
176
176
  expect(names).toContain("mDM_send");
177
177
  expect(names).toContain("mIRC_create");
178
178
  expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
179
- expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
179
+ expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered
180
180
  expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
181
181
  expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
182
182
  expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
@@ -1,5 +1,5 @@
1
1
  /**
2
- * mDM E2EE golden path (LINEAR-2357) — the "done" bar.
2
+ * mDM E2EE golden path — the "done" bar.
3
3
  *
4
4
  * Two parties (alice, bob) sharing ONE backend that acts as both the message
5
5
  * store AND the key directory (decision "1a": prekey bundles ride the same
@@ -105,7 +105,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
105
105
  const wire = backend.messages[0]!.payload;
106
106
  const wireStr = Buffer.from(wire).toString("utf8");
107
107
  expect(wireStr).not.toContain("first contact");
108
- expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS — LINEAR-3409)
108
+ expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS)
109
109
 
110
110
  // 4. Bob lists the thread and decrypts Alice's message.
111
111
  const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
@@ -178,7 +178,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
178
178
  });
179
179
  });
180
180
 
181
- describe("auto-publish prekeys on startup (LINEAR-3104 cold-start fix)", () => {
181
+ describe("auto-publish prekeys on startup (cold-start fix)", () => {
182
182
  it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
183
183
  const backend = new SharedBackend();
184
184
  createMosaddServer({
@@ -1,28 +1,28 @@
1
1
  /**
2
- * ZAMEK (27.09.2026, nastepstwo LINEAR-6089, POPRAWKA po niezaleznej weryfikacji toru mdm-brama):
3
- * wiadomosc wyslana przez mDM_send z MCP ma byc CZYTELNA u nadawcy i u odbiorcy — na KAZDYM
4
- * kluczu tej samej tozsamosci, nie tylko na tym, ktory ja wyslal — a aplikacja ma mowic PRAWDE,
5
- * gdy czegos pokazac nie moze.
2
+ * LOCK (27.09.2026, follow-up fix after independent verification of the mDM gateway path):
3
+ * a message sent by mDM_send from MCP must be READABLE for the sender and for the recipient — on EVERY
4
+ * key of the same identity, not only on the one that sent it — and the app must tell the TRUTH
5
+ * when it cannot show something.
6
6
  *
7
- * Co zmierzono 27.09:
8
- * 1. mDM_send przez brame rodzil NOWA tozsamosc co wywolanie (keystore w pamieci na zadanie HTTP).
9
- * 2. Pierwsza poprawka (alpha.53) dala tozsamosc stala per KLUCZ API i pozwolila linii agenta
10
- * podmieniac pek w katalogu. Tozsamosc ma WIELE aktywnych kluczy (general@: 8, wszystkie
11
- * uzywane w 3 dni; 7 z 17 agentow ma po kilka), wiec pek przeskakiwal miedzy tozsamosciami:
12
- * kopia s1. otwierala sie tylko pod kluczem, ktory ja zapisal, a kopie r1. przestawaly sie
13
- * otwierac u odbiorcy po nastepnej wysylce innym kluczem.
14
- * 3. alpha.53 pisala tez `txt` + s1. pod ziarnem z klucza API na kluczu CZLOWIEKA — aplikacja
15
- * (mdmE2ee.ts readOwnMdmMessage) nie otwiera takiej kopii i podawala FALSZYWY powod
16
- * („wyslane z innego urzadzenia" / „odblokuj tozsamosc") zamiast „wyslane przez MCP".
7
+ * What was measured on 27.09:
8
+ * 1. mDM_send through the gateway created a NEW identity on every call (in-memory keystore per HTTP request).
9
+ * 2. The first fix (alpha.53) gave a stable identity per API KEY and let an agent line
10
+ * replace its bundle in the directory. An identity has MANY active keys (one agent identity: 8, all
11
+ * used within 3 days; 7 of 17 agents have several), so the bundle jumped between identities:
12
+ * the s1. copy opened only under the key that wrote it, and the r1. copies stopped
13
+ * opening for the recipient after the next send with another key.
14
+ * 3. alpha.53 also wrote `txt` + s1. under the API-key seed on a PERSON's key — the app
15
+ * (mdmE2ee.ts readOwnMdmMessage) does not open such a copy and gave a FALSE reason
16
+ * ("sent from another device" / "unlock your identity") instead of "sent by MCP".
17
17
  *
18
- * Naprawa u zrodla = regula Krola (DECYZJE-KROLA 20.09 12:56Z „E2EE wewnetrzne = zero"): gdy
19
- * strona rozmowy jest linia agenta, DM idzie JAWNIE — tak samo robi aplikacja (peerIsAgent).
20
- * Jawny tekst czyta kazdy klucz linii i aplikacja odbiorcy na kazdym urzadzeniu; pek nie jest
21
- * potrzebny, wiec nie ma czego podmieniac. Czlowiek↔czlowiek zostaje E2EE, a MCP na kluczu
22
- * czlowieka NIE rusza jego peku z aplikacji, nie pisze kopii s1. i znakuje koperte `text`.
18
+ * Fix at the source = the owner's rule (20.09: no E2EE on internal conversations): when one
19
+ * side of the conversation is an agent line, the DM goes IN THE CLEAR — the app does the same (peerIsAgent).
20
+ * Plain text is readable by every key of the line and by the recipient's app on every device; no bundle is
21
+ * needed, so there is nothing to replace. Person↔person stays E2EE, and MCP on a person's
22
+ * key does NOT touch the bundle from their app, writes no s1. copy and marks the envelope `text`.
23
23
  *
24
- * Prawdziwa kryptografia (X3DH + Double Ratchet + AES-GCM + HKDF z @mosadd/crypto), zero atrap
25
- * szyfru. Kazde "zadanie" bramy = SWIEZY serwer z danym kluczem API — jak handler bramy.
24
+ * Real cryptography (X3DH + Double Ratchet + AES-GCM + HKDF from @mosadd/crypto), no fake
25
+ * ciphers. Every gateway "request" = a FRESH server with the given API key — like the gateway handler.
26
26
  */
27
27
 
28
28
  import { execFileSync } from "node:child_process";
@@ -179,9 +179,9 @@ async function appReadOwn(
179
179
  }
180
180
 
181
181
  const KEY_A = "mosadd_sk_live_0123456789abcdef0123456789abcdef";
182
- const KEY_B = "mosadd_sk_live_fedcba9876543210fedcba9876543210"; // druga, rownolegle aktywna, ta sama linia
183
- const LINE = "general-line-identity";
184
- const KING = "king-identity";
182
+ const KEY_B = "mosadd_sk_live_fedcba9876543210fedcba9876543210"; // a second key, active in parallel, same line
183
+ const LINE = "agent-line-identity";
184
+ const OWNER = "owner-identity";
185
185
  const PEER = "peer-human-identity";
186
186
 
187
187
  type SendOut = {
@@ -194,11 +194,11 @@ type SendOut = {
194
194
  };
195
195
  type ListOut = { messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }> };
196
196
 
197
- describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplikacji (zamek 27.09)", () => {
198
- it("KAT: tozsamosc z ziarna jest bit w bit ta, ktora wylicza aplikacja", async () => {
197
+ describe("mDM_send from MCP — readable on every key, true reasons in the app (lock 27.09)", () => {
198
+ it("KAT: the identity derived from the seed is bit for bit the one the app derives", async () => {
199
199
  const seed = new Uint8Array(32).map((_, i) => i + 1);
200
200
  const m = await deriveOwnMaterialFromSeed(seed);
201
- // policzone @noble/curves+hashes 2.0.1 z drzewa mosADD (tych samych, na ktorych stoi web)
201
+ // computed with @noble/curves+hashes 2.0.1 from the mosADD tree (the same ones the web client uses)
202
202
  expect(toBase64(m.identity.publicKey)).toBe("kGJhDa1OHhlUYRQ0ZgztQfIucOPLxkdOK2iBJpNEWEU=");
203
203
  expect(toBase64(m.signingIdentity.publicKey)).toBe("4XxF9XwcOS25C+G8oS/NGXor6ahKsOklnpq3JUQHfVY=");
204
204
  expect(toBase64(m.signedPrekey.pair.publicKey)).toBe("0/QU9p52caXSkyjLx/PH4C/9A/UzOZaPRecMtVBQj0Y=");
@@ -209,7 +209,7 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
209
209
  );
210
210
  });
211
211
 
212
- it("dwa zadania bramy z tym samym kluczem = JEDNA tozsamosc (nie nowa co wywolanie)", async () => {
212
+ it("two gateway requests with the same key = ONE identity (not a new one per call)", async () => {
213
213
  const b = new Backend();
214
214
  const a = await gatewayRequest(b, LINE, KEY_A).providers.keys.getOwnMaterial();
215
215
  const c = await gatewayRequest(b, LINE, KEY_A).providers.keys.getOwnMaterial();
@@ -217,19 +217,19 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
217
217
  expect(toBase64(a.signedPrekey.pair.publicKey)).toBe(toBase64(c.signedPrekey.pair.publicKey));
218
218
  });
219
219
 
220
- it("linia agenta, DWA klucze naprzemiennie: jawny txt, kazdy klucz czyta wszystko, Krol czyta w aplikacji, katalog nietkniety", async () => {
220
+ it("agent line, TWO keys alternating: plain txt, every key reads everything, the owner reads in the app, directory untouched", async () => {
221
221
  const b = new Backend();
222
222
  b.kinds.set(LINE, "agent");
223
- await appOf(b, KING, 7);
223
+ await appOf(b, OWNER, 7);
224
224
 
225
- const s1 = (await tool("mDM_send")({ to: KING, text: "meldunek z klucza A" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
226
- const s2 = (await tool("mDM_send")({ to: KING, text: "meldunek z klucza B" }, gatewayRequest(b, LINE, KEY_B))) as SendOut;
227
- const s3 = (await tool("mDM_send")({ to: KING, text: "znow klucz A" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
225
+ const s1 = (await tool("mDM_send")({ to: OWNER, text: "report from key A" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
226
+ const s2 = (await tool("mDM_send")({ to: OWNER, text: "report from key B" }, gatewayRequest(b, LINE, KEY_B))) as SendOut;
227
+ const s3 = (await tool("mDM_send")({ to: OWNER, text: "key A again" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
228
228
  for (const s of [s1, s2, s3]) {
229
229
  expect(s).toMatchObject({ encrypted: false, mode: "plaintext_agent_lane", sender_copy: true, recipient_copy: true, identity: "untouched" });
230
230
  }
231
231
 
232
- // Katalog kluczy: ZERO zapisow — pek linii nie istnieje, wiec nie ma czego przestawiac.
232
+ // Key directory: ZERO writes — the line has no bundle, so there is nothing to switch.
233
233
  expect(b.publishes).toBe(0);
234
234
  expect(b.bundles.has(LINE)).toBe(false);
235
235
 
@@ -238,104 +238,104 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
238
238
  expect(row.selfPayload).toBeNull();
239
239
  expect(row.recipientSelfPayload).toBeNull();
240
240
  }
241
- // Krol w aplikacji, na DOWOLNYM urzadzeniu: jawny tekst, bez kluczy i bez ratchetu.
242
- expect(b.rows.map(appPlaintext)).toEqual(["meldunek z klucza A", "meldunek z klucza B", "znow klucz A"]);
241
+ // The owner in the app, on ANY device: plain text, no keys and no ratchet.
242
+ expect(b.rows.map(appPlaintext)).toEqual(["report from key A", "report from key B", "key A again"]);
243
243
 
244
- // Nadawca: KAZDY klucz linii, swieze zadanie (pusta pamiec wyslanych), czyta WSZYSTKIE trzy.
244
+ // Sender: EVERY key of the line, fresh request (empty sent memory), reads ALL three.
245
245
  for (const k of [KEY_A, KEY_B]) {
246
- const read = (await tool("mDM_list")({ contact_id: KING }, gatewayRequest(b, LINE, k))) as ListOut;
247
- expect(read.messages.map((m) => m.text)).toEqual(["meldunek z klucza A", "meldunek z klucza B", "znow klucz A"]);
246
+ const read = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, k))) as ListOut;
247
+ expect(read.messages.map((m) => m.text)).toEqual(["report from key A", "report from key B", "key A again"]);
248
248
  }
249
249
  });
250
250
 
251
- it("watek wlasny linii (dm:ja:ja): zapis kluczem A, odczyt kluczem B", async () => {
251
+ it("the line's own thread (dm:me:me): written with key A, read with key B", async () => {
252
252
  const b = new Backend();
253
253
  b.kinds.set(LINE, "agent");
254
- await tool("mDM_send")({ to: LINE, text: "notatka do siebie" }, gatewayRequest(b, LINE, KEY_A));
254
+ await tool("mDM_send")({ to: LINE, text: "note to self" }, gatewayRequest(b, LINE, KEY_A));
255
255
  const row = b.rows.at(-1)!;
256
256
  expect(row.threadId).toBe(`dm:${LINE}:${LINE}`);
257
257
  expect(row.messageType).toBe("txt");
258
258
  const read = (await tool("mDM_list")({ contact_id: LINE }, gatewayRequest(b, LINE, KEY_B))) as ListOut;
259
- expect(read.messages.map((m) => m.text)).toEqual(["notatka do siebie"]);
259
+ expect(read.messages.map((m) => m.text)).toEqual(["note to self"]);
260
260
  expect(b.publishes).toBe(0);
261
261
  });
262
262
 
263
- it("czlowiek pisze przez MCP DO linii agenta: jawnie (jak peerIsAgent w aplikacji)", async () => {
263
+ it("a person writes through MCP TO an agent line: in the clear (like peerIsAgent in the app)", async () => {
264
264
  const b = new Backend();
265
265
  b.kinds.set(LINE, "agent");
266
- await appOf(b, KING, 7);
267
- const s = (await tool("mDM_send")({ to: LINE, text: "rozkaz" }, gatewayRequest(b, KING, KEY_A))) as SendOut;
266
+ await appOf(b, OWNER, 7);
267
+ const s = (await tool("mDM_send")({ to: LINE, text: "instruction" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
268
268
  expect(s.mode).toBe("plaintext_agent_lane");
269
- expect(appPlaintext(b.rows.at(-1)!)).toBe("rozkaz");
270
- const lineRead = (await tool("mDM_list")({ contact_id: KING }, gatewayRequest(b, LINE, KEY_B))) as ListOut;
271
- expect(lineRead.messages.map((m) => m.text)).toEqual(["rozkaz"]);
269
+ expect(appPlaintext(b.rows.at(-1)!)).toBe("instruction");
270
+ const lineRead = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, KEY_B))) as ListOut;
271
+ expect(lineRead.messages.map((m) => m.text)).toEqual(["instruction"]);
272
272
  });
273
273
 
274
- it("klucz CZLOWIEKA do czlowieka: E2EE, pek z aplikacji nietkniety, bez s1., typ `text` — aplikacja mowi PRAWDZIWY powod", async () => {
274
+ it("a PERSON's key to a person: E2EE, app bundle untouched, no s1., type `text` — the app gives the TRUE reason", async () => {
275
275
  const b = new Backend();
276
- const kingSeed = new Uint8Array(32).fill(7);
277
- const kingApp = await appOf(b, KING, 7);
278
- const kingBundle = toBase64(b.bundles.get(KING)!);
276
+ const ownerSeed = new Uint8Array(32).fill(7);
277
+ const ownerApp = await appOf(b, OWNER, 7);
278
+ const ownerBundle = toBase64(b.bundles.get(OWNER)!);
279
279
  const peerApp = await appOf(b, PEER, 5);
280
280
 
281
- const s = (await tool("mDM_send")({ to: PEER, text: "tajne" }, gatewayRequest(b, KING, KEY_A))) as SendOut;
281
+ const s = (await tool("mDM_send")({ to: PEER, text: "secret" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
282
282
  expect(s).toMatchObject({ encrypted: true, mode: "e2ee", identity: "foreign", sender_copy: false, recipient_copy: false });
283
283
  const row = b.rows.at(-1)!;
284
284
  expect(row.messageType).toBe("text");
285
285
  expect(row.selfPayload).toBeNull();
286
- expect(appPlaintext(row)).not.toContain("tajne");
286
+ expect(appPlaintext(row)).not.toContain("secret");
287
287
  expect(b.publishes).toBe(0);
288
- expect(toBase64(b.bundles.get(KING)!)).toBe(kingBundle);
288
+ expect(toBase64(b.bundles.get(OWNER)!)).toBe(ownerBundle);
289
289
 
290
- // Odbiorca czyta przez ratchet (koperta niesie naglowek X3DH do JEGO peku z aplikacji).
291
- expect(new TextDecoder().decode(await decryptFromPeer(peerApp, KING, row.payload))).toBe("tajne");
292
- // Wlasciciel w aplikacji: tresci nie ma (MCP nie zna ziarna aplikacji) i powod jest PRAWDZIWY.
293
- expect(await appReadOwn(kingSeed, kingApp, KING, row)).toEqual({ text: null, reason: "agent" });
290
+ // The recipient reads through the ratchet (the envelope carries an X3DH header to THEIR app bundle).
291
+ expect(new TextDecoder().decode(await decryptFromPeer(peerApp, OWNER, row.payload))).toBe("secret");
292
+ // The owner in the app: no content (MCP does not know the app seed) and the reason is TRUE.
293
+ expect(await appReadOwn(ownerSeed, ownerApp, OWNER, row)).toEqual({ text: null, reason: "agent" });
294
294
  });
295
295
 
296
- // 29.09 (ZERO SZYFROWANIA, rozkaz Krola 28.09): notatka do siebie z MCP idzie JAWNIE — do 28.09
297
- // byla koperta E2EE, ktora aplikacja otwierala kluczami z ziarna; teraz nie ma czego otwierac.
298
- it("klucz czlowieka, notatka do siebie: jawny txt — aplikacja czyta goly tekst na kazdym urzadzeniu", async () => {
296
+ // 29.09 (owner decision 28.09: no encryption on agent-line conversations): a note to self from MCP goes IN THE CLEAR —
297
+ // until 28.09 it was an E2EE envelope the app opened with seed keys; now there is nothing to open.
298
+ it("a person's key, note to self: plain txt — the app reads bare text on every device", async () => {
299
299
  const b = new Backend();
300
- await appOf(b, KING, 7);
301
- const s = (await tool("mDM_send")({ to: KING, text: "do siebie z MCP" }, gatewayRequest(b, KING, KEY_A))) as SendOut;
300
+ await appOf(b, OWNER, 7);
301
+ const s = (await tool("mDM_send")({ to: OWNER, text: "note to self from MCP" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
302
302
  expect(s).toMatchObject({ encrypted: false, mode: "plaintext_agent_lane", identity: "untouched" });
303
303
  const row = b.rows.at(-1)!;
304
304
  expect(row.messageType).toBe("txt");
305
305
  expect(row.selfPayload).toBeNull();
306
- expect(appPlaintext(row)).toBe("do siebie z MCP");
306
+ expect(appPlaintext(row)).toBe("note to self from MCP");
307
307
  expect(b.publishes).toBe(0);
308
308
  });
309
309
 
310
- it("czlowiek BEZ peku: MCP nie publikuje sam (ani mDM_send, ani autoPublishKeys); jawne mDM_publish_keys moze", async () => {
310
+ it("a person WITHOUT a bundle: MCP does not publish on its own (neither mDM_send nor autoPublishKeys); an explicit mDM_publish_keys may", async () => {
311
311
  const b = new Backend();
312
- b.kinds.set(KING, "human");
312
+ b.kinds.set(OWNER, "human");
313
313
  await appOf(b, PEER, 5);
314
- const s = (await tool("mDM_send")({ to: PEER, text: "x" }, gatewayRequest(b, KING, KEY_A))) as SendOut;
314
+ const s = (await tool("mDM_send")({ to: PEER, text: "x" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
315
315
  expect(s.identity).toBe("absent");
316
- expect(b.bundles.has(KING)).toBe(false);
316
+ expect(b.bundles.has(OWNER)).toBe(false);
317
317
 
318
- createMosaddServer({ apiKey: KEY_A, autoPublishKeys: true, providers: { dm: new Lane(b, KING), voice: new InMemoryVoiceProvider(KING) } });
318
+ createMosaddServer({ apiKey: KEY_A, autoPublishKeys: true, providers: { dm: new Lane(b, OWNER), voice: new InMemoryVoiceProvider(OWNER) } });
319
319
  await new Promise((r) => setTimeout(r, 50));
320
- expect(b.bundles.has(KING)).toBe(false);
320
+ expect(b.bundles.has(OWNER)).toBe(false);
321
321
  expect(b.publishes).toBe(0);
322
322
 
323
- const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, KING, KEY_A))) as { published: boolean; identity: string };
323
+ const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, OWNER, KEY_A))) as { published: boolean; identity: string };
324
324
  expect(p).toMatchObject({ published: true, identity: "published" });
325
325
  });
326
326
 
327
- it("jawne mDM_publish_keys na kluczu czlowieka NIE nadpisuje peku z aplikacji", async () => {
327
+ it("an explicit mDM_publish_keys on a person's key does NOT overwrite the app bundle", async () => {
328
328
  const b = new Backend();
329
- await appOf(b, KING, 7);
330
- const before = toBase64(b.bundles.get(KING)!);
331
- const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, KING, KEY_A))) as { published: boolean; identity: string; note?: string };
329
+ await appOf(b, OWNER, 7);
330
+ const before = toBase64(b.bundles.get(OWNER)!);
331
+ const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, OWNER, KEY_A))) as { published: boolean; identity: string; note?: string };
332
332
  expect(p).toMatchObject({ published: false, identity: "foreign" });
333
333
  expect(p.note).toBeTruthy();
334
- expect(toBase64(b.bundles.get(KING)!)).toBe(before);
334
+ expect(toBase64(b.bundles.get(OWNER)!)).toBe(before);
335
335
  expect(b.publishes).toBe(0);
336
336
  });
337
337
 
338
- it("autoPublishKeys na linii agenta: zero zapisow w katalogu (zaden z jej kluczy nie przestawia peku)", async () => {
338
+ it("autoPublishKeys on an agent line: zero directory writes (none of its keys switches the bundle)", async () => {
339
339
  const b = new Backend();
340
340
  b.kinds.set(LINE, "agent");
341
341
  for (const k of [KEY_A, KEY_B]) {
@@ -346,31 +346,31 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
346
346
  expect(b.bundles.has(LINE)).toBe(false);
347
347
  });
348
348
 
349
- it("stara koperta E2EE od Krola z kopia r1. (pek linii sprzed poprawki) dalej czytelna w bramie", async () => {
349
+ it("an old E2EE envelope from the owner with an r1. copy (line bundle from before the fix) is still readable in the gateway", async () => {
350
350
  const b = new Backend();
351
351
  b.kinds.set(LINE, "agent");
352
- const king = await appOf(b, KING, 7);
353
- // pek linii opublikowany przez alpha.53 z ziarna klucza A
352
+ const owner = await appOf(b, OWNER, 7);
353
+ // the line bundle published by alpha.53 from the seed of key A
354
354
  b.bundles.set(LINE, serializePublicBundle(await new SeededMdmKeyStore(await deriveMdmSeedFromSecret(KEY_A)).getOwnMaterial()));
355
- const kingLane = new Lane(b, KING);
356
- const lineBundle = (await fetchVerifiedBundle(kingLane, LINE))!;
357
- const inner = new TextEncoder().encode("rozkaz od Krola");
358
- await encryptForPeer(king, kingLane, LINE, new TextEncoder().encode("pierwsza"));
359
- const env = await encryptForPeer(king, kingLane, LINE, inner);
360
- await kingLane.send({
355
+ const ownerLane = new Lane(b, OWNER);
356
+ const lineBundle = (await fetchVerifiedBundle(ownerLane, LINE))!;
357
+ const inner = new TextEncoder().encode("instruction from the owner");
358
+ await encryptForPeer(owner, ownerLane, LINE, new TextEncoder().encode("first"));
359
+ const env = await encryptForPeer(owner, ownerLane, LINE, inner);
360
+ await ownerLane.send({
361
361
  to: LINE,
362
- threadId: `dm:${[KING, LINE].sort().join(":")}`,
362
+ threadId: `dm:${[OWNER, LINE].sort().join(":")}`,
363
363
  payload: env,
364
364
  messageType: "txt",
365
- recipientSelfPayload: await sealForPeerRecoverable(king, lineBundle, inner),
365
+ recipientSelfPayload: await sealForPeerRecoverable(owner, lineBundle, inner),
366
366
  });
367
- const read = (await tool("mDM_list")({ contact_id: KING }, gatewayRequest(b, LINE, KEY_A))) as ListOut;
368
- expect(read.messages.find((m) => m.sender_identity_id === KING)?.text).toBe("rozkaz od Krola");
367
+ const read = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, KEY_A))) as ListOut;
368
+ expect(read.messages.find((m) => m.sender_identity_id === OWNER)?.text).toBe("instruction from the owner");
369
369
  });
370
370
 
371
- // Straznik rozjazdu z aplikacja: dwie reguly, na ktorych stoi ta poprawka, czytane ze zrodla
372
- // aplikacji na origin/main repo mosADD (MOSADD_WEB_REPO albo C:/Projects/mosADD). Bez repo obok
373
- // (np. CI bez siostrzanego drzewa) — pominiety, nie zielony na slepo.
371
+ // Drift guard against the app: the two rules this fix stands on, read from the app source
372
+ // on origin/main of the mosADD repo (MOSADD_WEB_REPO, else the default path below). Without that repo
373
+ // next to this one (e.g. CI without the sibling tree) the test is skipped, not blindly green.
374
374
  const webRepo = process.env.MOSADD_WEB_REPO ?? "C:/Projects/mosADD";
375
375
  const appSource = (path: string): string | null => {
376
376
  try {
@@ -381,7 +381,7 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
381
381
  };
382
382
  const mdmE2ee = appSource("apps/web/src/lib/mdmE2ee.ts");
383
383
  const ircApi = appSource("apps/web/src/lib/ircApi.ts");
384
- it.skipIf(!mdmE2ee || !ircApi)("kontrakt aplikacji: `text` = powod agent, s1. = kopia dla mnie, agent = jawnie", () => {
384
+ it.skipIf(!mdmE2ee || !ircApi)("app contract: `text` = reason agent, s1. = my own copy, agent = in the clear", () => {
385
385
  expect(mdmE2ee).toContain('reason: msg.message_type === "text" ? "agent" : "device"');
386
386
  expect(mdmE2ee).toContain("const kopiaDlaMnie = doSiebie || (!!msg.self_payload && msg.self_payload.startsWith(SELF_TAG));");
387
387
  expect(mdmE2ee).toContain('const SELF_TAG = "s1.";');