n2n-nexus 0.8.2 → 0.9.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/CHANGELOG.md +39 -0
- package/CONTRIBUTING.md +49 -0
- package/README.md +157 -77
- package/SECURITY.md +37 -0
- package/build/cli/client-command.js +58 -0
- package/build/cli/doctor.js +58 -8
- package/build/cli/entry.js +5 -0
- package/build/cli/hook.js +104 -16
- package/build/cli/install.js +37 -13
- package/build/cli/mcp-config.js +16 -12
- package/build/client/discovery.js +115 -0
- package/build/client/nexus-client.js +8 -2
- package/build/contract.js +69 -0
- package/build/index.js +12 -18
- package/build/server/nexus.js +63 -35
- package/contract/errors.json +52 -0
- package/contract/hook.json +156 -0
- package/contract/tools.json +2812 -0
- package/docs/ARCHITECTURE.md +142 -108
- package/docs/ARCHITECTURE_zh.md +144 -110
- package/docs/ASSISTANT_GUIDE.md +5 -4
- package/docs/ASSISTANT_GUIDE_zh.md +134 -0
- package/docs/MEETING_MINUTES_2025-12-29.md +166 -0
- package/docs/README_zh.md +159 -79
- package/docs/TOOLS_REFERENCE.md +404 -0
- package/docs/discussion_2025-12-29.md +727 -0
- package/llms.txt +16 -5
- package/package.json +12 -8
- package/build/cli/autostart.js +0 -64
- package/build/config/cli.js +0 -8
- package/build/config/paths.js +0 -38
- package/build/constants.js +0 -18
- package/build/daemon/hook-contract.js +0 -68
- package/build/daemon/index.js +0 -57
- package/build/daemon/rate-limit.js +0 -62
- package/build/daemon/server.js +0 -862
- package/build/daemon/tool-outputs.js +0 -180
- package/build/daemon/tools.js +0 -326
- package/build/storage/agents.js +0 -227
- package/build/storage/docs.js +0 -81
- package/build/storage/events.js +0 -31
- package/build/storage/fs-utils.js +0 -88
- package/build/storage/global-messages.js +0 -44
- package/build/storage/index.js +0 -141
- package/build/storage/migrations.js +0 -87
- package/build/storage/paths.js +0 -23
- package/build/storage/projects.js +0 -53
- package/build/storage/registry.js +0 -355
- package/build/storage/sqlite-meeting.js +0 -323
- package/build/storage/sqlite.js +0 -275
- package/build/storage/tasks.js +0 -138
- package/build/types.js +0 -1
- package/build/utils/async-rwlock.js +0 -64
package/build/storage/tasks.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TaskService - Phase 2: Async Task Management
|
|
3
|
-
*
|
|
4
|
-
* Manages long-running operations with progress tracking,
|
|
5
|
-
* meeting traceability, and MCP-compatible status reporting.
|
|
6
|
-
*/
|
|
7
|
-
import { getDatabase } from "./sqlite.js";
|
|
8
|
-
import { TASK_CLEANUP_MAX_AGE_MS } from "../constants.js";
|
|
9
|
-
export const TASK_STATUSES = ["pending", "running", "completed", "failed", "cancelled"];
|
|
10
|
-
// Generate unique task ID
|
|
11
|
-
function generateTaskId() {
|
|
12
|
-
const timestamp = new Date().toISOString().replace(/[-:T.Z]/g, "").slice(0, 14);
|
|
13
|
-
const random = Math.random().toString(36).substring(2, 6);
|
|
14
|
-
return `task_${timestamp}_${random}`;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create a new task
|
|
18
|
-
*/
|
|
19
|
-
export function createTask(input = {}) {
|
|
20
|
-
const db = getDatabase();
|
|
21
|
-
const id = input.id || generateTaskId();
|
|
22
|
-
const now = new Date().toISOString();
|
|
23
|
-
const stmt = db.prepare(`
|
|
24
|
-
INSERT INTO tasks (id, status, progress, source_meeting_id, metadata, created_at, updated_at, ttl)
|
|
25
|
-
VALUES (?, 'pending', 0.0, ?, ?, ?, ?, ?)
|
|
26
|
-
`);
|
|
27
|
-
stmt.run(id, input.source_meeting_id || null, input.metadata ? JSON.stringify(input.metadata) : null, now, now, input.ttl || null);
|
|
28
|
-
return getTask(id);
|
|
29
|
-
}
|
|
30
|
-
function rowToTask(row) {
|
|
31
|
-
return {
|
|
32
|
-
id: row.id,
|
|
33
|
-
status: row.status,
|
|
34
|
-
progress: row.progress,
|
|
35
|
-
source_meeting_id: row.source_meeting_id || null,
|
|
36
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : {},
|
|
37
|
-
result_uri: row.result_uri || null,
|
|
38
|
-
error_message: row.error_message || null,
|
|
39
|
-
created_at: row.created_at,
|
|
40
|
-
updated_at: row.updated_at,
|
|
41
|
-
ttl: row.ttl || null
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get a task by ID
|
|
46
|
-
*/
|
|
47
|
-
export function getTask(id) {
|
|
48
|
-
const row = getDatabase().prepare("SELECT * FROM tasks WHERE id = ?").get(id);
|
|
49
|
-
return row ? rowToTask(row) : null;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Update task status and progress
|
|
53
|
-
*/
|
|
54
|
-
export function updateTask(id, update) {
|
|
55
|
-
const db = getDatabase();
|
|
56
|
-
const now = new Date().toISOString();
|
|
57
|
-
const sets = ["updated_at = ?"];
|
|
58
|
-
const values = [now];
|
|
59
|
-
if (update.status !== undefined) {
|
|
60
|
-
sets.push("status = ?");
|
|
61
|
-
values.push(update.status);
|
|
62
|
-
}
|
|
63
|
-
if (update.progress !== undefined) {
|
|
64
|
-
sets.push("progress = ?");
|
|
65
|
-
values.push(Math.max(0, Math.min(1, update.progress)));
|
|
66
|
-
}
|
|
67
|
-
if (update.result_uri !== undefined) {
|
|
68
|
-
sets.push("result_uri = ?");
|
|
69
|
-
values.push(update.result_uri);
|
|
70
|
-
}
|
|
71
|
-
if (update.error_message !== undefined) {
|
|
72
|
-
sets.push("error_message = ?");
|
|
73
|
-
values.push(update.error_message);
|
|
74
|
-
}
|
|
75
|
-
if (update.metadata !== undefined) {
|
|
76
|
-
sets.push("metadata = ?");
|
|
77
|
-
values.push(JSON.stringify(update.metadata));
|
|
78
|
-
}
|
|
79
|
-
values.push(id);
|
|
80
|
-
const sql = `UPDATE tasks SET ${sets.join(", ")} WHERE id = ?`;
|
|
81
|
-
db.prepare(sql).run(...values);
|
|
82
|
-
return getTask(id);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* List tasks with optional status filter
|
|
86
|
-
*/
|
|
87
|
-
export function listTasks(status, limit = 50) {
|
|
88
|
-
const db = getDatabase();
|
|
89
|
-
let sql = "SELECT * FROM tasks";
|
|
90
|
-
const params = [];
|
|
91
|
-
if (status) {
|
|
92
|
-
sql += " WHERE status = ?";
|
|
93
|
-
params.push(status);
|
|
94
|
-
}
|
|
95
|
-
sql += " ORDER BY created_at DESC LIMIT ?";
|
|
96
|
-
params.push(limit);
|
|
97
|
-
const rows = db.prepare(sql).all(...params);
|
|
98
|
-
return rows.map(rowToTask);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Cancel a pending or running task
|
|
102
|
-
*/
|
|
103
|
-
export function cancelTask(id) {
|
|
104
|
-
const task = getTask(id);
|
|
105
|
-
if (!task)
|
|
106
|
-
return false;
|
|
107
|
-
if (task.status !== "pending" && task.status !== "running")
|
|
108
|
-
return false;
|
|
109
|
-
updateTask(id, { status: "cancelled" });
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Mark pending/running tasks whose TTL has elapsed as failed.
|
|
114
|
-
*/
|
|
115
|
-
export function expireTasks(now = Date.now()) {
|
|
116
|
-
return getDatabase().prepare(`
|
|
117
|
-
UPDATE tasks
|
|
118
|
-
SET status = 'failed', error_message = 'TTL expired', updated_at = ?
|
|
119
|
-
WHERE status IN ('pending', 'running')
|
|
120
|
-
AND ttl IS NOT NULL
|
|
121
|
-
AND ROUND(unixepoch(created_at, 'subsec') * 1000) + ttl < ?
|
|
122
|
-
`).run(new Date(now).toISOString(), now).changes;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Delete completed/failed/cancelled tasks older than specified age
|
|
126
|
-
*/
|
|
127
|
-
export function cleanupTasks(maxAgeMs = TASK_CLEANUP_MAX_AGE_MS, now = Date.now()) {
|
|
128
|
-
const cutoff = new Date(now - maxAgeMs).toISOString();
|
|
129
|
-
return getDatabase().prepare(`
|
|
130
|
-
DELETE FROM tasks
|
|
131
|
-
WHERE status IN ('completed', 'failed', 'cancelled')
|
|
132
|
-
AND updated_at < ?
|
|
133
|
-
`).run(cutoff).changes;
|
|
134
|
-
}
|
|
135
|
-
/** Expire overdue tasks, then purge finished ones past the retention window. */
|
|
136
|
-
export function runTaskMaintenance(now = Date.now()) {
|
|
137
|
-
return { expired: expireTasks(now), removed: cleanupTasks(TASK_CLEANUP_MAX_AGE_MS, now) };
|
|
138
|
-
}
|
package/build/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const MESSAGE_CATEGORIES = ["MEETING_START", "PROPOSAL", "DECISION", "UPDATE", "CHAT"];
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Readers-writer lock for async code. Any number of readers run together; a
|
|
3
|
-
* writer runs alone. Waiters are served in FIFO order and writers take
|
|
4
|
-
* priority: once a writer is queued, readers that arrive later queue behind
|
|
5
|
-
* it instead of joining the readers already running, so a steady stream of
|
|
6
|
-
* reads cannot starve a write.
|
|
7
|
-
*/
|
|
8
|
-
export class AsyncRWLock {
|
|
9
|
-
readers = 0;
|
|
10
|
-
writing = false;
|
|
11
|
-
queue = [];
|
|
12
|
-
acquire(write) {
|
|
13
|
-
// A reader may join running readers only while nothing is queued (a queued entry is either a writer or a reader behind one).
|
|
14
|
-
const free = write ? !this.writing && this.readers === 0 : !this.writing && this.queue.length === 0;
|
|
15
|
-
if (free) {
|
|
16
|
-
if (write)
|
|
17
|
-
this.writing = true;
|
|
18
|
-
else
|
|
19
|
-
this.readers++;
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
return new Promise((resolve) => this.queue.push({ write, resolve }));
|
|
23
|
-
}
|
|
24
|
-
release(write) {
|
|
25
|
-
if (write)
|
|
26
|
-
this.writing = false;
|
|
27
|
-
else
|
|
28
|
-
this.readers--;
|
|
29
|
-
if (this.writing || this.readers > 0)
|
|
30
|
-
return;
|
|
31
|
-
// Lock is free: wake the next writer alone, or every reader up to the next queued writer.
|
|
32
|
-
const next = this.queue[0];
|
|
33
|
-
if (!next)
|
|
34
|
-
return;
|
|
35
|
-
if (next.write) {
|
|
36
|
-
this.queue.shift();
|
|
37
|
-
this.writing = true;
|
|
38
|
-
next.resolve();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
while (this.queue.length > 0 && !this.queue[0].write) {
|
|
42
|
-
this.readers++;
|
|
43
|
-
this.queue.shift().resolve();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async withRead(fn) {
|
|
47
|
-
await this.acquire(false);
|
|
48
|
-
try {
|
|
49
|
-
return await fn();
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
this.release(false);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async withWrite(fn) {
|
|
56
|
-
await this.acquire(true);
|
|
57
|
-
try {
|
|
58
|
-
return await fn();
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
this.release(true);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|