@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.
- package/CHANGELOG.md +415 -410
- package/LICENSE +21 -0
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-VMMJJYXF.js → chunk-J2S44U5R.js} +52 -27
- 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-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 +1 -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 +15 -13
- package/src/tools/mirc-edge.ts +4 -4
- package/src/tools/mirc-members.ts +1 -1
- package/src/tools/mirc-messages.ts +36 -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 +30 -7
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
*
|
|
8
|
-
* 1. mDM_send
|
|
9
|
-
* 2.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 3. alpha.53
|
|
15
|
-
* (mdmE2ee.ts readOwnMdmMessage)
|
|
16
|
-
* (
|
|
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
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
-
*
|
|
25
|
-
*
|
|
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"; //
|
|
183
|
-
const LINE = "
|
|
184
|
-
const
|
|
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
|
|
198
|
-
it("KAT:
|
|
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
|
-
//
|
|
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("
|
|
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("
|
|
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,
|
|
223
|
+
await appOf(b, OWNER, 7);
|
|
224
224
|
|
|
225
|
-
const s1 = (await tool("mDM_send")({ to:
|
|
226
|
-
const s2 = (await tool("mDM_send")({ to:
|
|
227
|
-
const s3 = (await tool("mDM_send")({ to:
|
|
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
|
-
//
|
|
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
|
-
//
|
|
242
|
-
expect(b.rows.map(appPlaintext)).toEqual(["
|
|
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
|
-
//
|
|
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:
|
|
247
|
-
expect(read.messages.map((m) => m.text)).toEqual(["
|
|
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("
|
|
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: "
|
|
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(["
|
|
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("
|
|
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,
|
|
267
|
-
const s = (await tool("mDM_send")({ to: LINE, text: "
|
|
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("
|
|
270
|
-
const lineRead = (await tool("mDM_list")({ contact_id:
|
|
271
|
-
expect(lineRead.messages.map((m) => m.text)).toEqual(["
|
|
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("
|
|
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
|
|
277
|
-
const
|
|
278
|
-
const
|
|
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: "
|
|
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("
|
|
286
|
+
expect(appPlaintext(row)).not.toContain("secret");
|
|
287
287
|
expect(b.publishes).toBe(0);
|
|
288
|
-
expect(toBase64(b.bundles.get(
|
|
288
|
+
expect(toBase64(b.bundles.get(OWNER)!)).toBe(ownerBundle);
|
|
289
289
|
|
|
290
|
-
//
|
|
291
|
-
expect(new TextDecoder().decode(await decryptFromPeer(peerApp,
|
|
292
|
-
//
|
|
293
|
-
expect(await appReadOwn(
|
|
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 (
|
|
297
|
-
//
|
|
298
|
-
it("
|
|
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,
|
|
301
|
-
const s = (await tool("mDM_send")({ to:
|
|
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("
|
|
306
|
+
expect(appPlaintext(row)).toBe("note to self from MCP");
|
|
307
307
|
expect(b.publishes).toBe(0);
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
-
it("
|
|
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(
|
|
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,
|
|
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(
|
|
316
|
+
expect(b.bundles.has(OWNER)).toBe(false);
|
|
317
317
|
|
|
318
|
-
createMosaddServer({ apiKey: KEY_A, autoPublishKeys: true, providers: { dm: new Lane(b,
|
|
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(
|
|
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,
|
|
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("
|
|
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,
|
|
330
|
-
const before = toBase64(b.bundles.get(
|
|
331
|
-
const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b,
|
|
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(
|
|
334
|
+
expect(toBase64(b.bundles.get(OWNER)!)).toBe(before);
|
|
335
335
|
expect(b.publishes).toBe(0);
|
|
336
336
|
});
|
|
337
337
|
|
|
338
|
-
it("autoPublishKeys
|
|
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("
|
|
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
|
|
353
|
-
//
|
|
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
|
|
356
|
-
const lineBundle = (await fetchVerifiedBundle(
|
|
357
|
-
const inner = new TextEncoder().encode("
|
|
358
|
-
await encryptForPeer(
|
|
359
|
-
const env = await encryptForPeer(
|
|
360
|
-
await
|
|
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:${[
|
|
362
|
+
threadId: `dm:${[OWNER, LINE].sort().join(":")}`,
|
|
363
363
|
payload: env,
|
|
364
364
|
messageType: "txt",
|
|
365
|
-
recipientSelfPayload: await sealForPeerRecoverable(
|
|
365
|
+
recipientSelfPayload: await sealForPeerRecoverable(owner, lineBundle, inner),
|
|
366
366
|
});
|
|
367
|
-
const read = (await tool("mDM_list")({ contact_id:
|
|
368
|
-
expect(read.messages.find((m) => m.sender_identity_id ===
|
|
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
|
-
//
|
|
372
|
-
//
|
|
373
|
-
// (
|
|
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)("
|
|
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
|
|
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
|