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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.41",
3
+ "version": "3.0.0-alpha.42",
4
4
  "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
5
  "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 84 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
6
  "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
@@ -17,6 +17,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
17
17
 
18
18
  const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
19
19
  const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
20
+ const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
20
21
  const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
21
22
 
22
23
  /** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
@@ -45,10 +46,16 @@ function makeBuilder(table: string) {
45
46
  pendingDelete = true;
46
47
  return builder;
47
48
  },
49
+ // ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
50
+ // `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
51
+ // obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
48
52
  eq: (_col: string, val: string) => {
49
53
  if (pendingDelete) {
50
54
  calls.deletes.push(val);
51
- return Promise.resolve({ error: null });
55
+ return Object.assign(
56
+ { eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
57
+ { then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
58
+ );
52
59
  }
53
60
  return builder;
54
61
  },
@@ -65,6 +72,9 @@ function makeBuilder(table: string) {
65
72
 
66
73
  vi.mock("../providers/supabase.js", () => ({
67
74
  readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
75
+ // Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
76
+ // generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
77
+ sessionId: () => TEST_SESSION,
68
78
  getSupabase: () => ({
69
79
  auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
70
80
  from: (table: string) => makeBuilder(table),
@@ -145,7 +155,9 @@ describe("comms_session_attach", () => {
145
155
  // Two deletes since 2026-08-26: the heartbeat row (by identity) AND the as_agent
146
156
  // declaration in mosadd_gateway_agent_binding (by user) — a finishing session hands
147
157
  // back EVERYTHING it could hold, so no stale declaration keeps signing later posts.
148
- expect(calls.deletes).toEqual([IDENTITY_ID, USER_ID]);
158
+ // Zwolnienie kasuje: puls linii + deklarację TEJ sesji (konto ORAZ sesja). Trzeci element to
159
+ // dowód, że nie kasujemy po samym koncie — bo to zabierało linię wszystkim innym generałom.
160
+ expect(calls.deletes).toEqual([IDENTITY_ID, USER_ID, TEST_SESSION]);
149
161
  calls.upserts = [];
150
162
  await vi.advanceTimersByTimeAsync(180_000);
151
163
  expect(calls.upserts).toHaveLength(0);
@@ -10,9 +10,28 @@
10
10
  */
11
11
 
12
12
  import { AsyncLocalStorage } from "node:async_hooks";
13
+ import { randomUUID } from "node:crypto";
14
+ import { hostname } from "node:os";
13
15
  import { createClient, type SupabaseClient } from "@supabase/supabase-js";
14
16
  import { loadSession, isSessionExpired } from "../config.js";
15
17
 
18
+ /**
19
+ * Tożsamość TEGO procesu — stała przez całe życie sesji, nowa przy każdym starcie.
20
+ *
21
+ * ⛔ NIE MOŻE być pochodną konta ani hosta. Dwie sesje generałów potrafią stać na tej samej
22
+ * maszynie i pod tym samym kontem (box floty), więc identyfikator z hosta zlepiłby je z powrotem
23
+ * w jedną — czyli odtworzył dokładnie ten błąd, który to naprawia. Nazwa hosta zostaje tylko jako
24
+ * czytelny przedrostek do diagnostyki; o rozróżnieniu decyduje losowy ogon.
25
+ */
26
+ let cachedSessionId: string | null = null;
27
+ export function sessionId(): string {
28
+ if (cachedSessionId) return cachedSessionId;
29
+ let host = "mcp";
30
+ try { host = (hostname() || "mcp").slice(0, 24); } catch { /* bez nazwy hosta też działa */ }
31
+ cachedSessionId = `${host}:${randomUUID()}`;
32
+ return cachedSessionId;
33
+ }
34
+
16
35
  export interface SupabaseEnv {
17
36
  url: string;
18
37
  anonKey: string;
@@ -95,6 +114,13 @@ export function getSupabase(env: SupabaseEnv = readSupabaseEnv()): SupabaseClien
95
114
  headers: {
96
115
  ...(env.userJwt ? { Authorization: `Bearer ${env.userJwt}` } : {}),
97
116
  "x-mosadd-origin": "hub-gateway",
117
+ // ⛔ KTÓRA TO SESJA (2026-08-27, „każdy generał co chwilę gubi mózg"). Wszyscy generałowie
118
+ // wpinają się kluczem hub TEGO SAMEGO właściciela, więc dla serwera ich wywołania były
119
+ // nieodróżnialne — a deklaracja linii (`comms_session_attach as_agent`) trzymała JEDEN
120
+ // wiersz na konto. Skutek: kto wpiął się ostatni, odbierał linię wszystkim pozostałym, a
121
+ // ich posty na kanałach zaczynały wracać z 403. Ten nagłówek daje każdemu PROCESOWI własną
122
+ // tożsamość sesji, dzięki czemu dziewięć linii na jednym koncie nie depcze sobie po piętach.
123
+ "x-mosadd-session": sessionId(),
98
124
  },
99
125
  },
100
126
  });
@@ -54,7 +54,7 @@
54
54
  import { hostname } from "node:os";
55
55
  import { z } from "zod";
56
56
  import type { MosaddTool, MosaddToolContext } from "../types.js";
57
- import { getSupabase, readSupabaseEnv, type SupabaseEnv } from "../providers/supabase.js";
57
+ import { getSupabase, readSupabaseEnv, sessionId, type SupabaseEnv } from "../providers/supabase.js";
58
58
 
59
59
  /**
60
60
  * How often we re-stamp the row. The consumer (`agent-dm-responder`, BRIDGE_FRESH_MS) trusts a beat
@@ -240,7 +240,10 @@ async function comms_session_attach(
240
240
  const { error } = await sb.from("agent_bridge_heartbeat").delete().eq("identity_id", id);
241
241
  if (error) throw new Error(`Could not release the line: ${error.message}`);
242
242
  }
243
- await sb.from("mosadd_gateway_agent_binding").delete().eq("user_id", self.user_id);
243
+ // Zwalniamy WYŁĄCZNIE deklarację TEJ sesji — kasowanie po samym koncie zabierało linię
244
+ // wszystkim pozostałym generałom wpiętym tym samym kluczem.
245
+ await sb.from("mosadd_gateway_agent_binding").delete()
246
+ .eq("user_id", self.user_id).eq("session_id", sessionId());
244
247
  processBindings.delete(self.user_id);
245
248
  ctx.log("info", "comms_session_attach: released", { identity_ids: [...toRelease] });
246
249
  return {
@@ -274,12 +277,17 @@ async function comms_session_attach(
274
277
  const { error: bindError } = await sb.from("mosadd_gateway_agent_binding").upsert(
275
278
  {
276
279
  user_id: self.user_id,
280
+ // ⛔ DEKLARACJA NALEŻY DO SESJI, NIE DO KONTA (2026-08-27). Wszyscy generałowie wpinają się
281
+ // kluczem tego samego właściciela, więc klucz na samym `user_id` znaczył „kto ostatni, ten
282
+ // zabiera linię wszystkim" — i realnie zabierał: Dyspozytor tracił prawo głosu na kanałach
283
+ // w chwili, gdy wpinał się kolejny generał, a jego posty wracały z 403.
284
+ session_id: sessionId(),
277
285
  agent_identity_id: agent.id,
278
286
  agent_address: agent.m0ssad_email,
279
287
  bound_at: new Date().toISOString(),
280
288
  bound_by_host: host,
281
289
  },
282
- { onConflict: "user_id" },
290
+ { onConflict: "user_id,session_id" },
283
291
  );
284
292
  if (bindError) throw new Error(`Could not declare the agent line: ${bindError.message}`);
285
293
  processBindings.set(self.user_id, agent.id);
@@ -368,10 +376,15 @@ export async function autoBeatFromActivity(ctx: MosaddToolContext): Promise<void
368
376
  const now = Date.now();
369
377
  if (now - (lastBindingCheck.get(self.user_id) ?? 0) >= BEAT_MS) {
370
378
  lastBindingCheck.set(self.user_id, now);
379
+ // ⛔ ZAWĘŻONE DO TEJ SESJI. Po 2026-08-27 na jedno konto przypada tyle wierszy, ilu
380
+ // generałów jest wpiętych — zapytanie o sam `user_id` z `maybeSingle()` nie tylko
381
+ // zwróciłoby BŁĄD przy dwóch sesjach, ale przy jednej trafiłoby w CUDZĄ deklarację i
382
+ // biło pulsem w nie swoją linię.
371
383
  const { data } = await getSupabase(env)
372
384
  .from("mosadd_gateway_agent_binding")
373
385
  .select("agent_identity_id, bound_at")
374
386
  .eq("user_id", self.user_id)
387
+ .eq("session_id", sessionId())
375
388
  .maybeSingle();
376
389
  if (data && Date.now() - new Date(data.bound_at as string).getTime() <= 24 * 60 * 60 * 1000) {
377
390
  lineId = data.agent_identity_id as string;