@mosadd/mcp 3.0.0 → 3.0.1

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 (39) hide show
  1. package/CHANGELOG.md +415 -410
  2. package/LICENSE +21 -0
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-VMMJJYXF.js → chunk-J2S44U5R.js} +52 -27
  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-invite.test.ts +1 -1
  14. package/src/__tests__/mirc-voice.test.ts +82 -0
  15. package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
  16. package/src/__tests__/presence.test.ts +2 -2
  17. package/src/__tests__/server.test.ts +3 -3
  18. package/src/__tests__/tool-count-consistency.test.ts +4 -4
  19. package/src/crypto/channel-e2ee.ts +1 -1
  20. package/src/crypto/mdm-session.ts +14 -14
  21. package/src/providers/supabase-dm.ts +1 -1
  22. package/src/providers/supabase.ts +8 -8
  23. package/src/server.ts +4 -4
  24. package/src/tools/channel-payload.ts +3 -3
  25. package/src/tools/index.ts +13 -13
  26. package/src/tools/knowledge.ts +384 -351
  27. package/src/tools/mail-aliases.ts +1 -1
  28. package/src/tools/mail-provenance.ts +1 -1
  29. package/src/tools/mdm-as-agent.ts +3 -4
  30. package/src/tools/mdm.ts +15 -13
  31. package/src/tools/mirc-edge.ts +4 -4
  32. package/src/tools/mirc-members.ts +1 -1
  33. package/src/tools/mirc-messages.ts +36 -12
  34. package/src/tools/mirc.ts +1 -1
  35. package/src/tools/mroom-messages.ts +1 -1
  36. package/src/tools/presence.ts +10 -10
  37. package/src/tools/ptt-ingest.ts +1 -1
  38. package/src/tools/threat.ts +1 -1
  39. package/src/tools/voice-format.ts +30 -7
@@ -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.";');
@@ -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 since LINEAR-5596 (own agent → auto_joined, no code); the toolkit just never exposed it.
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 — arbitrowana w SQL (LINEAR-5879):
178
- // claim RPC-em, nie surowym upsertem.
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 (LINEAR-3498)
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 (LINEAR-3464)
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 (LINEAR-3498)
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 (LINEAR-4813): it already said 73 but nothing enforced it.
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, LINEAR-5057 E-17): six surfaces the gate did
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 (kanon 1.1 review, LINEAR-5870): three more public files hand-typed a total
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 (kanon 1.1 review, LINEAR-5870). Measured that day: examples/README.md had
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 / LINEAR-5934).
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