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.
Files changed (53) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/CONTRIBUTING.md +49 -0
  3. package/README.md +157 -77
  4. package/SECURITY.md +37 -0
  5. package/build/cli/client-command.js +58 -0
  6. package/build/cli/doctor.js +58 -8
  7. package/build/cli/entry.js +5 -0
  8. package/build/cli/hook.js +104 -16
  9. package/build/cli/install.js +37 -13
  10. package/build/cli/mcp-config.js +16 -12
  11. package/build/client/discovery.js +115 -0
  12. package/build/client/nexus-client.js +8 -2
  13. package/build/contract.js +69 -0
  14. package/build/index.js +12 -18
  15. package/build/server/nexus.js +63 -35
  16. package/contract/errors.json +52 -0
  17. package/contract/hook.json +156 -0
  18. package/contract/tools.json +2812 -0
  19. package/docs/ARCHITECTURE.md +142 -108
  20. package/docs/ARCHITECTURE_zh.md +144 -110
  21. package/docs/ASSISTANT_GUIDE.md +5 -4
  22. package/docs/ASSISTANT_GUIDE_zh.md +134 -0
  23. package/docs/MEETING_MINUTES_2025-12-29.md +166 -0
  24. package/docs/README_zh.md +159 -79
  25. package/docs/TOOLS_REFERENCE.md +404 -0
  26. package/docs/discussion_2025-12-29.md +727 -0
  27. package/llms.txt +16 -5
  28. package/package.json +12 -8
  29. package/build/cli/autostart.js +0 -64
  30. package/build/config/cli.js +0 -8
  31. package/build/config/paths.js +0 -38
  32. package/build/constants.js +0 -18
  33. package/build/daemon/hook-contract.js +0 -68
  34. package/build/daemon/index.js +0 -57
  35. package/build/daemon/rate-limit.js +0 -62
  36. package/build/daemon/server.js +0 -862
  37. package/build/daemon/tool-outputs.js +0 -180
  38. package/build/daemon/tools.js +0 -326
  39. package/build/storage/agents.js +0 -227
  40. package/build/storage/docs.js +0 -81
  41. package/build/storage/events.js +0 -31
  42. package/build/storage/fs-utils.js +0 -88
  43. package/build/storage/global-messages.js +0 -44
  44. package/build/storage/index.js +0 -141
  45. package/build/storage/migrations.js +0 -87
  46. package/build/storage/paths.js +0 -23
  47. package/build/storage/projects.js +0 -53
  48. package/build/storage/registry.js +0 -355
  49. package/build/storage/sqlite-meeting.js +0 -323
  50. package/build/storage/sqlite.js +0 -275
  51. package/build/storage/tasks.js +0 -138
  52. package/build/types.js +0 -1
  53. package/build/utils/async-rwlock.js +0 -64
@@ -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
- }