n2n-nexus 0.7.0 → 0.8.0

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/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # n2n-nexus
2
2
 
3
- n2n-nexus is a local-first Model Context Protocol (MCP) coordination hub from N2NS Lab for multi-AI assistant collaboration. It uses a long-running local daemon as the source of truth and lightweight MCP adapters for IDEs and AI coding assistants. Each MCP connection has a discoverable session identity and a pull-based direct inbox with explicit receipts and reply links; messages do not automatically wake models.
3
+ n2n-nexus is a local-first Model Context Protocol (MCP) coordination hub from N2NS Lab for multi-AI assistant collaboration. It uses a long-running local daemon as the source of truth and lightweight MCP adapters for IDEs and AI coding assistants. Each Claude Code and Codex conversation has its own identity, taken from the client: `n2n-nexus install <claude|codex>` adds hooks that announce new direct messages to the recipient (on prompt, after tool calls, before the turn ends, or while listening), and the model reads them with a tool.
4
4
 
5
5
  ## Search intent coverage
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n2n-nexus",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Local-first MCP coordination hub from N2NS Lab for multi-AI assistant collaboration.",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -1,89 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { SessionStore } from "./sessions.js";
3
- import { getDatabase } from "./sqlite.js";
4
- export const DEFAULT_MESSAGE_TTL_MS = 24 * 60 * 60 * 1000;
5
- function toMessage(row) {
6
- return {
7
- messageId: row.message_id, from: row.from_session_id, to: row.to_session_id,
8
- text: row.text, category: row.category ?? undefined, replyTo: row.reply_to, status: row.status,
9
- createdAt: row.created_at, expiresAt: row.expires_at, fetchedAt: row.fetched_at,
10
- acknowledgedAt: row.acknowledged_at, repliedAt: row.replied_at, reason: row.reason
11
- };
12
- }
13
- function expire(now) {
14
- getDatabase().prepare("UPDATE direct_messages SET status = 'expired', reason = 'Message TTL elapsed' WHERE status IN ('accepted', 'fetched') AND expires_at <= ?")
15
- .run(new Date(now).toISOString());
16
- }
17
- export class DirectMessageStore {
18
- static send(fromSessionId, input, now = Date.now()) {
19
- SessionStore.require(fromSessionId);
20
- const ttlMs = input.ttlMs ?? DEFAULT_MESSAGE_TTL_MS;
21
- if (!Number.isSafeInteger(ttlMs) || ttlMs <= 0)
22
- throw new Error("ttlMs must be a positive integer");
23
- const db = getDatabase();
24
- expire(now);
25
- return db.transaction(() => {
26
- const recipient = SessionStore.require(input.to);
27
- if (input.replyTo) {
28
- const original = this.get(input.replyTo, fromSessionId, now);
29
- if (original.to !== fromSessionId || original.from !== input.to)
30
- throw new Error("Reply must target the original sender");
31
- if (!["fetched", "acknowledged", "replied"].includes(original.status))
32
- throw new Error(`Cannot reply to a message with status ${original.status}`);
33
- }
34
- const messageId = randomUUID();
35
- const timestamp = new Date(now).toISOString();
36
- const status = recipient.inbound === "refuse" ? "refused" : "accepted";
37
- db.prepare("INSERT INTO direct_messages (message_id, from_session_id, to_session_id, text, category, reply_to, status, created_at, expires_at, reason) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
38
- .run(messageId, fromSessionId, input.to, input.message, input.category ?? null, input.replyTo ?? null, status, timestamp, new Date(now + ttlMs).toISOString(), status === "refused" ? "Recipient refuses incoming messages" : null);
39
- if (input.replyTo && status === "accepted") {
40
- db.prepare("UPDATE direct_messages SET status = 'replied', replied_at = COALESCE(replied_at, ?) WHERE message_id = ?")
41
- .run(timestamp, input.replyTo);
42
- }
43
- return this.get(messageId, fromSessionId, now);
44
- })();
45
- }
46
- static readInbox(sessionId, count, now = Date.now()) {
47
- SessionStore.require(sessionId);
48
- const db = getDatabase();
49
- return db.transaction(() => {
50
- expire(now);
51
- const rows = db.prepare("SELECT * FROM direct_messages WHERE to_session_id = ? AND status IN ('accepted', 'fetched') ORDER BY created_at ASC, rowid ASC LIMIT ?")
52
- .all(sessionId, count);
53
- const timestamp = new Date(now).toISOString();
54
- const update = db.prepare("UPDATE direct_messages SET status = 'fetched', fetched_at = ? WHERE message_id = ? AND status = 'accepted'");
55
- return rows.map(row => {
56
- if (row.status === "accepted") {
57
- update.run(timestamp, row.message_id);
58
- row.status = "fetched";
59
- row.fetched_at = timestamp;
60
- }
61
- return toMessage(row);
62
- });
63
- })();
64
- }
65
- static get(messageId, actorSessionId, now = Date.now()) {
66
- expire(now);
67
- const row = getDatabase().prepare("SELECT * FROM direct_messages WHERE message_id = ? AND (from_session_id = ? OR to_session_id = ?)")
68
- .get(messageId, actorSessionId, actorSessionId);
69
- if (!row)
70
- throw new Error("Message not found for this session");
71
- return toMessage(row);
72
- }
73
- static acknowledge(messageId, recipientSessionId, outcome, now = Date.now()) {
74
- const db = getDatabase();
75
- expire(now);
76
- return db.transaction(() => {
77
- const message = this.get(messageId, recipientSessionId, now);
78
- if (message.to !== recipientSessionId)
79
- throw new Error("Only the recipient can acknowledge a message");
80
- if (message.status === outcome)
81
- return message;
82
- if (message.status !== "fetched")
83
- throw new Error(`Cannot ${outcome === "acknowledged" ? "acknowledge" : "refuse"} a message with status ${message.status}`);
84
- db.prepare("UPDATE direct_messages SET status = ?, acknowledged_at = ?, reason = ? WHERE message_id = ?")
85
- .run(outcome, outcome === "acknowledged" ? new Date(now).toISOString() : null, outcome === "refused" ? "Recipient refused message" : null, messageId);
86
- return this.get(messageId, recipientSessionId, now);
87
- })();
88
- }
89
- }
@@ -1,77 +0,0 @@
1
- import { getDatabase } from "./sqlite.js";
2
- export const SESSION_LEASE_MS = 60_000;
3
- function toSession(row, now) {
4
- return {
5
- sessionId: row.session_id, instanceId: row.instance_id, name: row.name,
6
- clientName: row.client_name, workspace: row.workspace, projectId: row.project_id,
7
- inbound: row.inbound, reception: "pull",
8
- online: row.connected === 1 && now - Date.parse(row.last_seen_at) < SESSION_LEASE_MS,
9
- createdAt: row.created_at, lastSeenAt: row.last_seen_at
10
- };
11
- }
12
- export class SessionStore {
13
- static register(input, now = Date.now()) {
14
- const db = getDatabase();
15
- return db.transaction(() => {
16
- const existing = this.get(input.sessionId, now);
17
- if (existing && existing.instanceId !== input.instanceId)
18
- throw new Error("Session belongs to another instance");
19
- const timestamp = new Date(now).toISOString();
20
- if (existing) {
21
- db.prepare("UPDATE sessions SET client_name = ?, workspace = ?, connected = 1, last_seen_at = ? WHERE session_id = ?")
22
- .run(input.clientName ?? existing.clientName, input.workspace ?? existing.workspace, timestamp, input.sessionId);
23
- }
24
- else {
25
- db.prepare("INSERT INTO sessions (session_id, instance_id, name, client_name, workspace, created_at, last_seen_at) VALUES (?, ?, ?, ?, ?, ?, ?)")
26
- .run(input.sessionId, input.instanceId, `session-${input.sessionId.slice(0, 8)}`, input.clientName ?? "", input.workspace ?? "", timestamp, timestamp);
27
- }
28
- return this.get(input.sessionId, now);
29
- })();
30
- }
31
- static get(sessionId, now = Date.now()) {
32
- const row = getDatabase().prepare("SELECT * FROM sessions WHERE session_id = ?").get(sessionId);
33
- return row ? toSession(row, now) : null;
34
- }
35
- static require(sessionId, instanceId) {
36
- const session = this.get(sessionId);
37
- if (!session)
38
- throw new Error(`Unknown session: ${sessionId}`);
39
- if (instanceId !== undefined && session.instanceId !== instanceId)
40
- throw new Error("Session belongs to another instance");
41
- return session;
42
- }
43
- static list(options = {}, now = Date.now()) {
44
- const clauses = [];
45
- const params = [];
46
- if (options.projectId !== undefined) {
47
- clauses.push("project_id = ?");
48
- params.push(options.projectId);
49
- }
50
- if (options.onlineOnly) {
51
- clauses.push("connected = 1 AND last_seen_at > ?");
52
- params.push(new Date(now - SESSION_LEASE_MS).toISOString());
53
- }
54
- const rows = getDatabase().prepare(`SELECT * FROM sessions ${clauses.length ? `WHERE ${clauses.join(" AND ")}` : ""} ORDER BY last_seen_at DESC, rowid DESC LIMIT ?`)
55
- .all(...params, options.limit ?? 100);
56
- return rows.map(row => toSession(row, now));
57
- }
58
- static update(sessionId, changes, now = Date.now()) {
59
- const db = getDatabase();
60
- return db.transaction(() => {
61
- const existing = this.require(sessionId);
62
- db.prepare("UPDATE sessions SET name = ?, project_id = ?, inbound = ? WHERE session_id = ?")
63
- .run(changes.name ?? existing.name, changes.projectId === undefined ? existing.projectId : changes.projectId, changes.inbound ?? existing.inbound, sessionId);
64
- if (changes.inbound === "refuse") {
65
- db.prepare("UPDATE direct_messages SET status = 'expired', reason = 'Message TTL elapsed' WHERE to_session_id = ? AND status IN ('accepted', 'fetched') AND expires_at <= ?")
66
- .run(sessionId, new Date(now).toISOString());
67
- db.prepare("UPDATE direct_messages SET status = 'refused', reason = 'recipient_refused' WHERE to_session_id = ? AND status IN ('accepted', 'fetched')")
68
- .run(sessionId);
69
- }
70
- return this.get(sessionId, now);
71
- })();
72
- }
73
- static disconnect(sessionId, instanceId) {
74
- this.require(sessionId, instanceId);
75
- getDatabase().prepare("UPDATE sessions SET connected = 0 WHERE session_id = ?").run(sessionId);
76
- }
77
- }