@mosadd/mcp 3.0.0-alpha.54 → 3.0.0-alpha.56
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 +29 -11
- package/LICENSE +21 -0
- package/README.md +12 -11
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-3PUOM4R5.js → chunk-T3KDVUAT.js} +66 -28
- package/dist/index.js +1 -1
- package/package.json +10 -10
- package/src/__tests__/flota-jawnie.test.ts +244 -0
- package/src/__tests__/integration.test.ts +34 -7
- package/src/__tests__/mdm-mcp-readable.test.ts +10 -6
- package/src/__tests__/presence.test.ts +199 -199
- package/src/__tests__/tool-count-consistency.test.ts +85 -29
- package/src/index.ts +1 -1
- package/src/providers/blob-upload.ts +162 -162
- package/src/server.ts +1 -1
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +1 -1
- package/src/tools/mdm-as-agent.ts +18 -6
- package/src/tools/mdm.ts +26 -11
- package/src/tools/mirc-edge.ts +1 -1
- package/src/tools/mirc-messages.ts +10 -14
- package/src/tools/mroom-messages.ts +4 -12
- package/src/tools/presence.ts +3 -3
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* comms_session_attach — the liveness contract.
|
|
3
|
-
*
|
|
4
|
-
* This tool decides WHO answers the owner: a live agent session, or the 24/7 cloud stand-in.
|
|
5
|
-
* Both answering, or the stand-in answering in a live session's name, is the exact failure that
|
|
6
|
-
* cost the founder his trust in the agent (see the file header in tools/presence.ts). So the
|
|
7
|
-
* things pinned here are the ones that would silently re-open it:
|
|
8
|
-
*
|
|
9
|
-
* 1. attaching writes the liveness row the stand-in reads, under the CALLER'S identity;
|
|
10
|
-
* 2. the hold renews itself on a timer — the model is not asked to remember a clock;
|
|
11
|
-
* 3. the timer is unref()ed, so a held line can never keep a dead session's process alive;
|
|
12
|
-
* 4. re-attaching replaces the beat instead of stacking a second one;
|
|
13
|
-
* 5. release DELETES the row (no backdated timestamp lying in a table other code reads).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
17
|
-
|
|
18
|
-
const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
19
|
-
const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
|
|
20
|
-
const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
|
|
21
|
-
const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
-
|
|
23
|
-
/** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
|
|
24
|
-
const calls = {
|
|
25
|
-
upserts: [] as Record<string, unknown>[],
|
|
26
|
-
deletes: [] as string[],
|
|
27
|
-
rpcs: [] as { name: string; args: Record<string, unknown> }[],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Minimal query-builder stand-in: every method returns the builder, `maybeSingle()` resolves the
|
|
32
|
-
* identity row, and the builder is thenable so `await delete().eq()` works like PostgREST's.
|
|
33
|
-
*/
|
|
34
|
-
function makeBuilder(table: string) {
|
|
35
|
-
const builder: Record<string, unknown> = {};
|
|
36
|
-
let pendingDelete = false;
|
|
37
|
-
const self = () => builder;
|
|
38
|
-
Object.assign(builder, {
|
|
39
|
-
select: self,
|
|
40
|
-
is: self,
|
|
41
|
-
or: self,
|
|
42
|
-
upsert: (row: Record<string, unknown>) => {
|
|
43
|
-
calls.upserts.push({ table, ...row });
|
|
44
|
-
return Promise.resolve({ error: null });
|
|
45
|
-
},
|
|
46
|
-
delete: () => {
|
|
47
|
-
pendingDelete = true;
|
|
48
|
-
return builder;
|
|
49
|
-
},
|
|
50
|
-
// ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
|
|
51
|
-
// `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
|
|
52
|
-
// obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
|
|
53
|
-
eq: (_col: string, val: string) => {
|
|
54
|
-
if (pendingDelete) {
|
|
55
|
-
calls.deletes.push(val);
|
|
56
|
-
return Object.assign(
|
|
57
|
-
{ eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
|
|
58
|
-
{ then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
return builder;
|
|
62
|
-
},
|
|
63
|
-
// resolveOwnedAgentLine path: .or(...).limit(2) → the caller's ONE owned agent.
|
|
64
|
-
limit: () =>
|
|
65
|
-
Promise.resolve({
|
|
66
|
-
data: [{ id: AGENT_ID, m0ssad_email: "
|
|
67
|
-
error: null,
|
|
68
|
-
}),
|
|
69
|
-
maybeSingle: () => Promise.resolve({ data: { id: IDENTITY_ID, display_name: "mosADD CTO" }, error: null }),
|
|
70
|
-
});
|
|
71
|
-
return builder;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
vi.mock("../providers/supabase.js", () => ({
|
|
75
|
-
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
76
|
-
// Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
|
|
77
|
-
// generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
|
|
78
|
-
sessionId: () => TEST_SESSION,
|
|
79
|
-
getSupabase: () => ({
|
|
80
|
-
auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
|
|
81
|
-
from: (table: string) => makeBuilder(table),
|
|
82
|
-
// release/as_agent path: presence.ts woła mosadd_gateway_binding_release/claim przez rpc —
|
|
83
|
-
// atrapa nagrywa wywołania, żeby asercje czytały się jak prawdziwy wire.
|
|
84
|
-
rpc: (name: string, args: Record<string, unknown>) => {
|
|
85
|
-
calls.rpcs.push({ name, args });
|
|
86
|
-
return Promise.resolve({ error: null, data: { took_over: false, previous_session_id: null } });
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
const ctx = { log: () => {} } as never;
|
|
92
|
-
|
|
93
|
-
/** Import after the mock is registered, so the module under test picks it up. */
|
|
94
|
-
const { presenceTools, __clearAttachmentsForTest } = await import("../tools/presence.js");
|
|
95
|
-
const attach = presenceTools[0];
|
|
96
|
-
|
|
97
|
-
async function call(input: Record<string, unknown>) {
|
|
98
|
-
return (await attach.handler(input, ctx)) as Record<string, unknown>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
describe("comms_session_attach", () => {
|
|
102
|
-
beforeEach(() => {
|
|
103
|
-
calls.upserts = [];
|
|
104
|
-
calls.deletes = [];
|
|
105
|
-
vi.useFakeTimers();
|
|
106
|
-
});
|
|
107
|
-
afterEach(() => {
|
|
108
|
-
__clearAttachmentsForTest();
|
|
109
|
-
vi.useRealTimers();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("is registered as a network tool under the comms_ capability group", () => {
|
|
113
|
-
expect(attach.name).toBe("comms_session_attach");
|
|
114
|
-
expect(attach.requires).toBe("network");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("claims the line for the CALLER'S identity, with a label the owner can read", async () => {
|
|
118
|
-
const out = await call({ label: "CTO — Claude Code" });
|
|
119
|
-
expect(out.attached).toBe(true);
|
|
120
|
-
expect(out.identity_id).toBe(IDENTITY_ID);
|
|
121
|
-
expect(calls.upserts).toHaveLength(1);
|
|
122
|
-
expect(calls.upserts[0]).toMatchObject({
|
|
123
|
-
table: "agent_bridge_heartbeat",
|
|
124
|
-
identity_id: IDENTITY_ID,
|
|
125
|
-
host: "CTO — Claude Code",
|
|
126
|
-
mode: "mcp-session",
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("renews the hold on its own — the model is never asked to keep time", async () => {
|
|
131
|
-
await call({});
|
|
132
|
-
expect(calls.upserts).toHaveLength(1);
|
|
133
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
134
|
-
expect(calls.upserts).toHaveLength(2);
|
|
135
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
136
|
-
expect(calls.upserts).toHaveLength(3);
|
|
137
|
-
// Every beat is a fresh timestamp, not a replay of the first one.
|
|
138
|
-
expect(calls.upserts[2].last_seen_at).not.toBe(calls.upserts[0].last_seen_at);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("never keeps a finished session's process alive (timer is unref'ed)", async () => {
|
|
142
|
-
const unref = vi.fn();
|
|
143
|
-
const spy = vi.spyOn(globalThis, "setInterval").mockReturnValue({ unref } as never);
|
|
144
|
-
await call({});
|
|
145
|
-
expect(unref).toHaveBeenCalledOnce();
|
|
146
|
-
spy.mockRestore();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("re-attaching replaces the beat instead of stacking a second one", async () => {
|
|
150
|
-
await call({ label: "first" });
|
|
151
|
-
await call({ label: "second" });
|
|
152
|
-
calls.upserts = [];
|
|
153
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
154
|
-
expect(calls.upserts).toHaveLength(1);
|
|
155
|
-
expect(calls.upserts[0].host).toBe("second");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("release DELETES the row and stops beating — the stand-in resumes at once", async () => {
|
|
159
|
-
await call({});
|
|
160
|
-
const out = await call({ release: true });
|
|
161
|
-
expect(out.attached).toBe(false);
|
|
162
|
-
// Zwolnienie kasuje puls linii (po identity) i puszcza deklarację TEJ sesji RPC-em
|
|
163
|
-
// (konto ORAZ sesja po stronie SQL — nie kasujemy po samym koncie, bo to zabierało
|
|
164
|
-
// linię wszystkim innym generałom na tym samym kluczu).
|
|
165
|
-
expect(calls.deletes).toEqual([IDENTITY_ID]);
|
|
166
|
-
expect(calls.rpcs).toEqual([{ name: "mosadd_gateway_binding_release", args: { p_session_id: TEST_SESSION } }]);
|
|
167
|
-
calls.upserts = [];
|
|
168
|
-
await vi.advanceTimersByTimeAsync(180_000);
|
|
169
|
-
expect(calls.upserts).toHaveLength(0);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("as_agent declares the line: binding upsert + beat on the AGENT's identity, not the key's", async () => {
|
|
173
|
-
const out = await call({ as_agent: "
|
|
174
|
-
expect(out.attached).toBe(true);
|
|
175
|
-
expect(out.identity_id).toBe(AGENT_ID);
|
|
176
|
-
expect((out.speaking_as as { address: string }).address).toBe("
|
|
177
|
-
// The signing declaration message-send reads — arbitrowana w SQL (LINEAR-5879):
|
|
178
|
-
// claim RPC-em, nie surowym upsertem.
|
|
179
|
-
expect(calls.rpcs).toContainEqual({
|
|
180
|
-
name: "mosadd_gateway_binding_claim",
|
|
181
|
-
args: {
|
|
182
|
-
p_session_id: TEST_SESSION,
|
|
183
|
-
p_agent_identity_id: AGENT_ID,
|
|
184
|
-
p_agent_address: "
|
|
185
|
-
p_host: "
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
// …and the AGENT's liveness row, so ITS cloud stand-in defers to this session.
|
|
189
|
-
expect(calls.upserts).toContainEqual(
|
|
190
|
-
expect.objectContaining({
|
|
191
|
-
table: "agent_bridge_heartbeat",
|
|
192
|
-
identity_id: AGENT_ID,
|
|
193
|
-
host: "
|
|
194
|
-
}),
|
|
195
|
-
);
|
|
196
|
-
// The key's own line is NOT claimed — attaching as an agent must not silence the owner's lane.
|
|
197
|
-
expect(calls.upserts.some((u) => u.table === "agent_bridge_heartbeat" && u.identity_id === IDENTITY_ID)).toBe(false);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* comms_session_attach — the liveness contract.
|
|
3
|
+
*
|
|
4
|
+
* This tool decides WHO answers the owner: a live agent session, or the 24/7 cloud stand-in.
|
|
5
|
+
* Both answering, or the stand-in answering in a live session's name, is the exact failure that
|
|
6
|
+
* cost the founder his trust in the agent (see the file header in tools/presence.ts). So the
|
|
7
|
+
* things pinned here are the ones that would silently re-open it:
|
|
8
|
+
*
|
|
9
|
+
* 1. attaching writes the liveness row the stand-in reads, under the CALLER'S identity;
|
|
10
|
+
* 2. the hold renews itself on a timer — the model is not asked to remember a clock;
|
|
11
|
+
* 3. the timer is unref()ed, so a held line can never keep a dead session's process alive;
|
|
12
|
+
* 4. re-attaching replaces the beat instead of stacking a second one;
|
|
13
|
+
* 5. release DELETES the row (no backdated timestamp lying in a table other code reads).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
17
|
+
|
|
18
|
+
const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
19
|
+
const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
|
|
20
|
+
const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
|
|
21
|
+
const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
+
|
|
23
|
+
/** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
|
|
24
|
+
const calls = {
|
|
25
|
+
upserts: [] as Record<string, unknown>[],
|
|
26
|
+
deletes: [] as string[],
|
|
27
|
+
rpcs: [] as { name: string; args: Record<string, unknown> }[],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal query-builder stand-in: every method returns the builder, `maybeSingle()` resolves the
|
|
32
|
+
* identity row, and the builder is thenable so `await delete().eq()` works like PostgREST's.
|
|
33
|
+
*/
|
|
34
|
+
function makeBuilder(table: string) {
|
|
35
|
+
const builder: Record<string, unknown> = {};
|
|
36
|
+
let pendingDelete = false;
|
|
37
|
+
const self = () => builder;
|
|
38
|
+
Object.assign(builder, {
|
|
39
|
+
select: self,
|
|
40
|
+
is: self,
|
|
41
|
+
or: self,
|
|
42
|
+
upsert: (row: Record<string, unknown>) => {
|
|
43
|
+
calls.upserts.push({ table, ...row });
|
|
44
|
+
return Promise.resolve({ error: null });
|
|
45
|
+
},
|
|
46
|
+
delete: () => {
|
|
47
|
+
pendingDelete = true;
|
|
48
|
+
return builder;
|
|
49
|
+
},
|
|
50
|
+
// ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
|
|
51
|
+
// `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
|
|
52
|
+
// obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
|
|
53
|
+
eq: (_col: string, val: string) => {
|
|
54
|
+
if (pendingDelete) {
|
|
55
|
+
calls.deletes.push(val);
|
|
56
|
+
return Object.assign(
|
|
57
|
+
{ eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
|
|
58
|
+
{ then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return builder;
|
|
62
|
+
},
|
|
63
|
+
// resolveOwnedAgentLine path: .or(...).limit(2) → the caller's ONE owned agent.
|
|
64
|
+
limit: () =>
|
|
65
|
+
Promise.resolve({
|
|
66
|
+
data: [{ id: AGENT_ID, m0ssad_email: "agent-one@mosadd.com", display_name: "AGENT ONE" }],
|
|
67
|
+
error: null,
|
|
68
|
+
}),
|
|
69
|
+
maybeSingle: () => Promise.resolve({ data: { id: IDENTITY_ID, display_name: "mosADD CTO" }, error: null }),
|
|
70
|
+
});
|
|
71
|
+
return builder;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
75
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
76
|
+
// Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
|
|
77
|
+
// generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
|
|
78
|
+
sessionId: () => TEST_SESSION,
|
|
79
|
+
getSupabase: () => ({
|
|
80
|
+
auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
|
|
81
|
+
from: (table: string) => makeBuilder(table),
|
|
82
|
+
// release/as_agent path: presence.ts woła mosadd_gateway_binding_release/claim przez rpc —
|
|
83
|
+
// atrapa nagrywa wywołania, żeby asercje czytały się jak prawdziwy wire.
|
|
84
|
+
rpc: (name: string, args: Record<string, unknown>) => {
|
|
85
|
+
calls.rpcs.push({ name, args });
|
|
86
|
+
return Promise.resolve({ error: null, data: { took_over: false, previous_session_id: null } });
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
const ctx = { log: () => {} } as never;
|
|
92
|
+
|
|
93
|
+
/** Import after the mock is registered, so the module under test picks it up. */
|
|
94
|
+
const { presenceTools, __clearAttachmentsForTest } = await import("../tools/presence.js");
|
|
95
|
+
const attach = presenceTools[0];
|
|
96
|
+
|
|
97
|
+
async function call(input: Record<string, unknown>) {
|
|
98
|
+
return (await attach.handler(input, ctx)) as Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
describe("comms_session_attach", () => {
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
calls.upserts = [];
|
|
104
|
+
calls.deletes = [];
|
|
105
|
+
vi.useFakeTimers();
|
|
106
|
+
});
|
|
107
|
+
afterEach(() => {
|
|
108
|
+
__clearAttachmentsForTest();
|
|
109
|
+
vi.useRealTimers();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("is registered as a network tool under the comms_ capability group", () => {
|
|
113
|
+
expect(attach.name).toBe("comms_session_attach");
|
|
114
|
+
expect(attach.requires).toBe("network");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("claims the line for the CALLER'S identity, with a label the owner can read", async () => {
|
|
118
|
+
const out = await call({ label: "CTO — Claude Code" });
|
|
119
|
+
expect(out.attached).toBe(true);
|
|
120
|
+
expect(out.identity_id).toBe(IDENTITY_ID);
|
|
121
|
+
expect(calls.upserts).toHaveLength(1);
|
|
122
|
+
expect(calls.upserts[0]).toMatchObject({
|
|
123
|
+
table: "agent_bridge_heartbeat",
|
|
124
|
+
identity_id: IDENTITY_ID,
|
|
125
|
+
host: "CTO — Claude Code",
|
|
126
|
+
mode: "mcp-session",
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("renews the hold on its own — the model is never asked to keep time", async () => {
|
|
131
|
+
await call({});
|
|
132
|
+
expect(calls.upserts).toHaveLength(1);
|
|
133
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
134
|
+
expect(calls.upserts).toHaveLength(2);
|
|
135
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
136
|
+
expect(calls.upserts).toHaveLength(3);
|
|
137
|
+
// Every beat is a fresh timestamp, not a replay of the first one.
|
|
138
|
+
expect(calls.upserts[2].last_seen_at).not.toBe(calls.upserts[0].last_seen_at);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("never keeps a finished session's process alive (timer is unref'ed)", async () => {
|
|
142
|
+
const unref = vi.fn();
|
|
143
|
+
const spy = vi.spyOn(globalThis, "setInterval").mockReturnValue({ unref } as never);
|
|
144
|
+
await call({});
|
|
145
|
+
expect(unref).toHaveBeenCalledOnce();
|
|
146
|
+
spy.mockRestore();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("re-attaching replaces the beat instead of stacking a second one", async () => {
|
|
150
|
+
await call({ label: "first" });
|
|
151
|
+
await call({ label: "second" });
|
|
152
|
+
calls.upserts = [];
|
|
153
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
154
|
+
expect(calls.upserts).toHaveLength(1);
|
|
155
|
+
expect(calls.upserts[0].host).toBe("second");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("release DELETES the row and stops beating — the stand-in resumes at once", async () => {
|
|
159
|
+
await call({});
|
|
160
|
+
const out = await call({ release: true });
|
|
161
|
+
expect(out.attached).toBe(false);
|
|
162
|
+
// Zwolnienie kasuje puls linii (po identity) i puszcza deklarację TEJ sesji RPC-em
|
|
163
|
+
// (konto ORAZ sesja po stronie SQL — nie kasujemy po samym koncie, bo to zabierało
|
|
164
|
+
// linię wszystkim innym generałom na tym samym kluczu).
|
|
165
|
+
expect(calls.deletes).toEqual([IDENTITY_ID]);
|
|
166
|
+
expect(calls.rpcs).toEqual([{ name: "mosadd_gateway_binding_release", args: { p_session_id: TEST_SESSION } }]);
|
|
167
|
+
calls.upserts = [];
|
|
168
|
+
await vi.advanceTimersByTimeAsync(180_000);
|
|
169
|
+
expect(calls.upserts).toHaveLength(0);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("as_agent declares the line: binding upsert + beat on the AGENT's identity, not the key's", async () => {
|
|
173
|
+
const out = await call({ as_agent: "agent-one@mosadd.com", label: "agent one — Cowork" });
|
|
174
|
+
expect(out.attached).toBe(true);
|
|
175
|
+
expect(out.identity_id).toBe(AGENT_ID);
|
|
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.
|
|
179
|
+
expect(calls.rpcs).toContainEqual({
|
|
180
|
+
name: "mosadd_gateway_binding_claim",
|
|
181
|
+
args: {
|
|
182
|
+
p_session_id: TEST_SESSION,
|
|
183
|
+
p_agent_identity_id: AGENT_ID,
|
|
184
|
+
p_agent_address: "agent-one@mosadd.com",
|
|
185
|
+
p_host: "agent one — Cowork",
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
// …and the AGENT's liveness row, so ITS cloud stand-in defers to this session.
|
|
189
|
+
expect(calls.upserts).toContainEqual(
|
|
190
|
+
expect.objectContaining({
|
|
191
|
+
table: "agent_bridge_heartbeat",
|
|
192
|
+
identity_id: AGENT_ID,
|
|
193
|
+
host: "agent one — Cowork",
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
// The key's own line is NOT claimed — attaching as an agent must not silence the owner's lane.
|
|
197
|
+
expect(calls.upserts.some((u) => u.table === "agent_bridge_heartbeat" && u.identity_id === IDENTITY_ID)).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -30,37 +30,64 @@ const SURFACES: { file: string; re: RegExp; what: string }[] = [
|
|
|
30
30
|
// 2026-07-29 — the gate guarded four internal surfaces and left the public face of the project
|
|
31
31
|
// unguarded, which is the wrong way round. The badge is checked because a wrong number in a
|
|
32
32
|
// green badge is the most confident-looking lie a repo can tell.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{ file: "README.md", re:
|
|
36
|
-
{ file: "README.md", re: /npx -y @mosadd\/mcp@alpha\s+#\s*(\d+) tools/, what: "README quickstart comment" },
|
|
33
|
+
// README rewritten 2026-09-29 (m.0S truth pass): the badge, the @alpha quickstart line and the long module
|
|
34
|
+
// table are gone; the two sentences that carry the total are pinned instead.
|
|
35
|
+
{ file: "README.md", re: /^(\d+) tools in `@mosadd\/mcp`/m, what: "README tools section" },
|
|
37
36
|
{ file: "packages/mcp/server.json", re: /(\d+)\s+MCP tools/, what: "MCP registry manifest description" },
|
|
38
37
|
// The npm-visible description — what `npm view @mosadd/mcp description` and the npmjs.com
|
|
39
38
|
// page show. Added 2026-07-30 (LINEAR-4813): it already said 73 but nothing enforced it.
|
|
40
39
|
{ file: "packages/mcp/package.json", re: /—\s*(\d+)\s+tools\s+—/, what: "package.json description" },
|
|
41
|
-
{ file: "apps/realm/index.html", re: /#\s*(\d+)\s+tools/, what: "mosadd.dev Realm hero" },
|
|
42
|
-
{ file: "apps/dev/app/docs/mcp/page.tsx", re: /Total surface today:[\s\S]*?(\d+)\s+tools/, what: "dev docs /docs/mcp" },
|
|
43
|
-
{ file: "apps/dev/app/opengraph-image.tsx", re: /(\d+)\s+MCP tools/, what: "dev OG image" },
|
|
44
40
|
// Added 2026-08-01 (content-truth audit, LINEAR-5057 E-17): six surfaces the gate did
|
|
45
41
|
// not pin had silently drifted to 69/66/71/22/4 while TOOL_COUNT was 73. Every public
|
|
46
42
|
// file that hand-types a total is now listed here — if you add a surface with a
|
|
47
43
|
// number, add it to this array in the same PR.
|
|
48
|
-
{ file: "docs/OWNER-GUIDE.md", re: /\*\*(\d+) mosADD tools\*\*/, what: "owner guide" },
|
|
49
44
|
{ file: "packages/ai/README.md", re: /the (\d+) mosADD toolkit tools/, what: "@mosadd/ai README" },
|
|
50
45
|
{ file: "docs/architecture/human-os.md", re: /exposing \*\*(\d+) tools\*\*/, what: "human-os architecture doc" },
|
|
51
46
|
{ file: "examples/README.md", re: /\*\*(\d+) live MCP tools across/, what: "examples README header" },
|
|
52
47
|
{ file: "packages/mcp/README.md", re: /One key, one server, (\d+) tools/, what: "@mosadd/mcp README intro" },
|
|
53
48
|
{ file: "packages/mcp/README.md", re: /\*\*(\d+) callable tools\*\* in total/, what: "@mosadd/mcp README breakdown" },
|
|
54
|
-
{ file: "apps/dev/public/llms.txt", re: /(\d+)\s+(?:MCP\s+)?tools/, what: "llms.txt (read by AI crawlers)" },
|
|
55
49
|
// Added 2026-09-04 (kanon 1.1 review, LINEAR-5870): three more public files hand-typed a total
|
|
56
50
|
// and had sat at 77 through two bumps (82, 84) because nothing pinned them. Both realm llms.txt
|
|
57
51
|
// lines are pinned separately — a single /(\d+) tools/ would only ever see the first.
|
|
58
|
-
|
|
59
|
-
{ file: "apps/realm/llms.txt", re: /## Toolkit \(@mosadd\/mcp — (\d+) tools\)/, what: "mosadd.dev Realm llms.txt toolkit heading" },
|
|
60
|
-
{ file: "docs/registry-submissions/smithery.md", re: /mAYL, (\d+) MCP tools, one server/, what: "Smithery listing tagline" },
|
|
61
|
-
{ file: "docs/registry-submissions/smithery.md", re: /\*\*(\d+) MCP tools — 4 modules/, what: "Smithery long description" },
|
|
52
|
+
// The package's own number, 85 on 2026-09-29, pinned where a text describes @mosadd/mcp itself.
|
|
62
53
|
];
|
|
63
54
|
|
|
55
|
+
// ── The HUB's number ────────────────────────────────────────────────────────
|
|
56
|
+
// 2026-09-29 (verifier of the m.0S distribution pass): the public texts said "85 tools" for
|
|
57
|
+
// https://mcp.mosadd.dev/mcp while the hub listed 88 — it serves every @mosadd/mcp tool plus tools of its
|
|
58
|
+
// own. 2026-09-30: the hub lists 86, because the phone-call tools (call_start, call_status) are held back until
|
|
59
|
+
// calls open (the price list marks them "soon"); the count moved 85 → 88 → 86 in two days. So texts about the
|
|
60
|
+
// ENDPOINT carry no number at all: they point at distribution/hub-tools.json (a snapshot of the live tools/list;
|
|
61
|
+
// `node scripts/check-hub-tools.mjs` compares it with the live hub, `--write` refreshes it), and this gate fails
|
|
62
|
+
// when one of them states "<N> tools" for the endpoint again. A number that describes @mosadd/mcp itself (a line
|
|
63
|
+
// that names `@mosadd/mcp`) stays and is pinned to TOOL_COUNT by SURFACES above.
|
|
64
|
+
const hubSnapshot = JSON.parse(readFileSync(resolve(repoRoot, "distribution/hub-tools.json"), "utf8")) as {
|
|
65
|
+
count: number;
|
|
66
|
+
names: string[];
|
|
67
|
+
server_version: string;
|
|
68
|
+
};
|
|
69
|
+
const packageNames = allTools.map((t) => t.name);
|
|
70
|
+
const HUB_ONLY = hubSnapshot.names.filter((n) => !packageNames.includes(n)).sort();
|
|
71
|
+
const HUB_COUNT = hubSnapshot.count;
|
|
72
|
+
const HELD_BACK = ["call_start", "call_status"]; // phone calls through the user's own Telnyx/Twilio account: "soon"
|
|
73
|
+
|
|
74
|
+
// Every public text that talks about the endpoint (not about the package).
|
|
75
|
+
const HUB_TEXTS = [
|
|
76
|
+
"README.md",
|
|
77
|
+
"docs/hosts.md",
|
|
78
|
+
"docs/roadmap.md",
|
|
79
|
+
"skills/m0s-quickstart/SKILL.md",
|
|
80
|
+
"distribution/clawhub/m0s/SKILL.md",
|
|
81
|
+
"distribution/pulsemcp.md",
|
|
82
|
+
"distribution/mcp-so.md",
|
|
83
|
+
"distribution/awesome-mcp-servers.md",
|
|
84
|
+
];
|
|
85
|
+
/** "88 tools", "88 MCP tools", "88 live tools" — a fixed count, in a line that is not about @mosadd/mcp. */
|
|
86
|
+
const FIXED_COUNT = /\b\d+\s+(?:MCP\s+|live\s+|callable\s+)?tools\b/i;
|
|
87
|
+
function fixedHubCounts(text: string): string[] {
|
|
88
|
+
return text.split(/\r?\n/).filter((l) => FIXED_COUNT.test(l) && !l.includes("@mosadd/mcp"));
|
|
89
|
+
}
|
|
90
|
+
|
|
64
91
|
describe("tool-count consistency (anti-drift gate)", () => {
|
|
65
92
|
it("TOOL_COUNT is a positive integer", () => {
|
|
66
93
|
expect(Number.isInteger(TOOL_COUNT)).toBe(true);
|
|
@@ -80,6 +107,47 @@ describe("tool-count consistency (anti-drift gate)", () => {
|
|
|
80
107
|
}
|
|
81
108
|
});
|
|
82
109
|
|
|
110
|
+
describe("hub tool count (texts about https://mcp.mosadd.dev/mcp)", () => {
|
|
111
|
+
it("the snapshot is the package plus the hub's own tools, nothing missing", () => {
|
|
112
|
+
expect(hubSnapshot.names).toHaveLength(hubSnapshot.count);
|
|
113
|
+
expect(packageNames.filter((n) => !hubSnapshot.names.includes(n)), "package tools the hub does not list").toEqual([]);
|
|
114
|
+
expect(HUB_COUNT).toBe(TOOL_COUNT + HUB_ONLY.length);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("the README tools section points at the snapshot, names every hub-only tool and says which are held back", () => {
|
|
118
|
+
const readme = readFileSync(resolve(repoRoot, "README.md"), "utf8");
|
|
119
|
+
const para = readme.match(/[^\n]*distribution\/hub-tools\.json[^\n]*(?:\n(?!\n)[^\n]*)*/)?.[0] ?? "";
|
|
120
|
+
expect(para, "README has no paragraph pointing at distribution/hub-tools.json").not.toBe("");
|
|
121
|
+
for (const n of HUB_ONLY) expect(para, `README hub paragraph does not name ${n}`).toContain(`\`${n}\``);
|
|
122
|
+
const listed = HELD_BACK.filter((n) => hubSnapshot.names.includes(n));
|
|
123
|
+
if (listed.length === 0) {
|
|
124
|
+
// calls are not open: the README must say so, and name the tools it holds back
|
|
125
|
+
expect(para).toMatch(/coming soon/);
|
|
126
|
+
expect(para).toMatch(/held back/);
|
|
127
|
+
for (const n of HELD_BACK) expect(para, `README does not name the held-back ${n}`).toContain(`\`${n}\``);
|
|
128
|
+
} else {
|
|
129
|
+
expect(para, `the hub lists ${listed.join(", ")} now — the README still says they are held back`).not.toMatch(/held back/);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
for (const file of HUB_TEXTS) {
|
|
134
|
+
it(`${file} states no fixed number of hub tools (it points at distribution/hub-tools.json)`, () => {
|
|
135
|
+
const lines = fixedHubCounts(readFileSync(resolve(repoRoot, file), "utf8"));
|
|
136
|
+
expect(
|
|
137
|
+
lines,
|
|
138
|
+
`${file} states a fixed tool count for the endpoint (the hub lists ${HUB_COUNT} today, and it changes): drop the number or point at distribution/hub-tools.json`,
|
|
139
|
+
).toEqual([]);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
it("the gate fires: a text that says '88 tools' for the endpoint is caught, one about @mosadd/mcp is not", () => {
|
|
144
|
+
expect(fixedHubCounts("m.0S is a hosted MCP endpoint with 88 tools.")).toHaveLength(1);
|
|
145
|
+
expect(fixedHubCounts("The hub lists **88 MCP tools** today.")).toHaveLength(1);
|
|
146
|
+
expect(fixedHubCounts("85 tools in `@mosadd/mcp` (`3.0.0-alpha.55`)")).toEqual([]);
|
|
147
|
+
expect(fixedHubCounts("The hub's tool list is whatever `tools/list` returns.")).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
83
151
|
// ── Per-MODULE anti-drift gate ───────────────────────────────────────────────
|
|
84
152
|
// WHY this exists (added 2026-08-11): the total-only gate above was GREEN while the
|
|
85
153
|
// prose around every pinned line was wrong. Each SURFACES entry pins ONE regex per
|
|
@@ -147,22 +215,10 @@ const MODULE_SURFACES: { file: string; what: string; re: (label: string) => RegE
|
|
|
147
215
|
re: (label) => new RegExp(`\\*\\*${label}\\*\\*\\s*\\((\\d+)\\)`),
|
|
148
216
|
},
|
|
149
217
|
{
|
|
150
|
-
file: "
|
|
151
|
-
what: "
|
|
152
|
-
// "
|
|
153
|
-
re: (label) => new RegExp(
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
file: "docs/registry-submissions/smithery.md",
|
|
157
|
-
what: "Smithery long-description per-module list",
|
|
158
|
-
// "- mDM (16 tools) — …"
|
|
159
|
-
re: (label) => new RegExp(`^- ${label} \\((\\d+) tools`, "m"),
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
file: "apps/dev/public/llms.txt",
|
|
163
|
-
what: "dev llms.txt per-module list",
|
|
164
|
-
// "- mDM — 1:1 direct messages … (16 tools)" / "mRAG — agent memory … (8 tools);"
|
|
165
|
-
re: (label) => new RegExp(`\\b${label} — [^\\n]*?\\((\\d+) tools\\)`),
|
|
218
|
+
file: "README.md",
|
|
219
|
+
what: "README tools line",
|
|
220
|
+
// "mDM 16 · mIRC 25 · mURL 7 · mAYL 16 · mTALK 6 · mRAG 8 · comms 5 · threat 2"
|
|
221
|
+
re: (label) => new RegExp(`\\b${label} (\\d+) ·`),
|
|
166
222
|
},
|
|
167
223
|
];
|
|
168
224
|
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Exposes mosadd OS modules (m*) as MCP tools to any agent runtime
|
|
5
5
|
* (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, etc.).
|
|
6
6
|
*
|
|
7
|
-
* License: Apache-2.0
|
|
7
|
+
* License: MIT (releases before 2026-09-29: Apache-2.0)
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export { createMosaddServer, defaultProviders } from "./server.js";
|