aicrosschat 0.8.4 → 0.8.6
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/README.md +2 -2
- package/package.json +3 -2
- package/plugin/lib/tasks.js +13 -4
- package/relay/relay.mjs +2 -1
- package/test/run.mjs +122 -0
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ npm test # 6 组:identity / tasks / core / relay smoke / mcp / 包完
|
|
|
161
161
|
npm run smoke # relay 协议与安全,16 项断言
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
安装包里(`test/`
|
|
164
|
+
安装包里(`test/` 已随包发布,可直接跑完整 6 组):
|
|
165
165
|
|
|
166
166
|
```powershell
|
|
167
167
|
npm run smoke # 16 项,等价于 node relay/smoke.mjs
|
|
@@ -294,7 +294,7 @@ MCP 与 CLI 成员**没有 `inject`/`followup`**——那是 DSH 内部的 agent
|
|
|
294
294
|
- **任务板已实现**:认领按 seq 先到先得、支持 dependsOn 依赖门、done/release/重派;但它仍是从日志折叠出来的“软状态”,不是服务端 CAS。
|
|
295
295
|
- **有 relay 自带 Web 时间线**:`GET /ui`(无鉴权,token 存 localStorage);DSH 侧边栏面板仍未做。
|
|
296
296
|
- **TOFU 落盘条件**:只有配置了 `--data`(或 `--keys`)才会持久化 `keys.json`;默认启动命令不落盘,重启后同 nodeId 可换钥。
|
|
297
|
-
- **TLS
|
|
297
|
+
- **TLS 已实测(2026-11-22,双方独立复现)**:`--tls-cert/--tls-key` 在自签证书(SAN=localhost/127.0.0.1)下通过——https `/health`、签名 append、`/events` 均正常;不带信任时连接失败。客户端需信任证书(Node 用 `NODE_EXTRA_CA_CERTS`,浏览器手动导入);生产仍推荐 Tailscale 或 HTTPS 反代。
|
|
298
298
|
- **重连补投有上限**:`resync` 只拉 `/events?since=0&limit=500`,超过 500 条的历史不会重放。
|
|
299
299
|
- **身份文件权限 0600 仅 POSIX 有效**:Windows 上 Node 的 mode 不生效。
|
|
300
300
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicrosschat",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "跨机 DSH 协作插件:一台机器派活,其他机器各自干活,通过共享结构化事件时间线交换任务与结果;默认不打扰,可开圆桌模式。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"README.md",
|
|
26
26
|
"INSTALL.md",
|
|
27
27
|
"LICENSE",
|
|
28
|
-
"setup-member.ps1"
|
|
28
|
+
"setup-member.ps1",
|
|
29
|
+
"test"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
32
|
"test": "node test/run.mjs",
|
package/plugin/lib/tasks.js
CHANGED
|
@@ -130,16 +130,23 @@ export function findConflicts(tasks, options) {
|
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* 判断一个节点有没有资格关闭(done / release)这个任务。
|
|
133
|
-
*
|
|
133
|
+
* 正常关闭者:持有人、创建者、或被直接指派的人(`to` 是该节点)。
|
|
134
|
+
* 其他人关闭不算错,但要留下痕迹。
|
|
134
135
|
* @param {object|undefined} task - 关闭前的任务视图
|
|
135
136
|
* @param {string} from - 发起关闭的节点
|
|
136
|
-
* @returns {{allowed: boolean, owner: string|null, creator: string|null}}
|
|
137
|
+
* @returns {{allowed: boolean, owner: string|null, creator: string|null, assignee: string|null}}
|
|
137
138
|
*/
|
|
138
139
|
export function closeAuthority(task, from) {
|
|
139
|
-
if (!task) return { allowed: true, owner: null, creator: null }
|
|
140
|
+
if (!task) return { allowed: true, owner: null, creator: null, assignee: null }
|
|
140
141
|
const owner = task.owner ?? null
|
|
141
142
|
const creator = task.createdBy ?? null
|
|
142
|
-
|
|
143
|
+
const assignee = task.assignee ?? null
|
|
144
|
+
return {
|
|
145
|
+
allowed: owner === from || creator === from || assignee === from,
|
|
146
|
+
owner,
|
|
147
|
+
creator,
|
|
148
|
+
assignee,
|
|
149
|
+
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
/**
|
|
@@ -169,6 +176,7 @@ export function applyEvent(tasks, event) {
|
|
|
169
176
|
seq: event.seq ?? 0,
|
|
170
177
|
paths: normalizePaths(event.paths),
|
|
171
178
|
dependsOn: normalizeIds(event.dependsOn),
|
|
179
|
+
assignee: typeof event.to === 'string' && event.to !== '*' ? event.to : null,
|
|
172
180
|
title: String(event.text ?? '').slice(0, 200),
|
|
173
181
|
})
|
|
174
182
|
return tasks
|
|
@@ -186,6 +194,7 @@ export function applyEvent(tasks, event) {
|
|
|
186
194
|
seq: event.seq ?? existing.seq,
|
|
187
195
|
paths: normalizePaths(event.paths),
|
|
188
196
|
dependsOn: normalizeIds(event.dependsOn),
|
|
197
|
+
assignee: typeof event.to === 'string' && event.to !== '*' ? event.to : null,
|
|
189
198
|
title: event.text ? String(event.text).slice(0, 200) : existing.title,
|
|
190
199
|
})
|
|
191
200
|
}
|
package/relay/relay.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* 用法:
|
|
9
9
|
* node relay.mjs --port 7317 --token <secret> [--host 0.0.0.0] [--data events.jsonl]
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* 接口:/health 与 /ui 公开;其余(/events /peers /append /keys /register-key)要求 x-crosschat-token。
|
|
12
12
|
* POST /append 追加一个事件,返回 { seq, ts }
|
|
13
13
|
* GET /events?since=N&wait=MS&limit=K 读取 seq > N 的事件,可长轮询
|
|
14
14
|
* GET /peers 在线节点(120s 内有请求)
|
|
@@ -50,6 +50,7 @@ const requireSignature = !allowUnsigned
|
|
|
50
50
|
const tlsCert = argv.get('tls-cert')
|
|
51
51
|
const tlsKey = argv.get('tls-key')
|
|
52
52
|
|
|
53
|
+
if (allowUnsigned) console.warn('[crosschat-relay] WARNING: signature verification disabled (--allow-unsigned); any token holder can post as any nodeId');
|
|
53
54
|
if (!token) {
|
|
54
55
|
console.error('crosschat-relay: --token is required')
|
|
55
56
|
process.exit(2)
|
package/test/run.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// crosschat 发布自检:identity / tasks / core / relay smoke / mcp / 包完整性
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
10
|
+
const cases = [];
|
|
11
|
+
const check = (name, fn) => cases.push({ name, fn });
|
|
12
|
+
|
|
13
|
+
check('identity: sign/verify/tamper', async () => {
|
|
14
|
+
const id = await import('../plugin/lib/identity.js');
|
|
15
|
+
const a = id.generateIdentity();
|
|
16
|
+
const b = id.generateIdentity();
|
|
17
|
+
const ev = id.signedEvent({ from: 'node-a', kind: 'note', text: '你好', to: '*' }, a);
|
|
18
|
+
if (!id.verifyEvent(ev, a.publicKey)) throw new Error('self verify failed');
|
|
19
|
+
if (id.verifyEvent(ev, b.publicKey)) throw new Error('foreign key verified');
|
|
20
|
+
const bad = { ...ev, text: '被篡改' };
|
|
21
|
+
if (id.verifyEvent(bad, a.publicKey)) throw new Error('tamper accepted');
|
|
22
|
+
if (id.canonicalize({ b: 1, a: 2 }) !== id.canonicalize({ a: 2, b: 1 })) throw new Error('canonicalize unstable');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
check('tasks: claim/done/depends/overlap', async () => {
|
|
26
|
+
const t = await import('../plugin/lib/tasks.js');
|
|
27
|
+
const board = t.foldTasks([
|
|
28
|
+
{ seq: 1, from: 'lead', kind: 'task', taskId: 'T1', text: 'first' },
|
|
29
|
+
{ seq: 2, from: 'node-b', kind: 'claim', taskId: 'T1', text: 'mine' },
|
|
30
|
+
{ seq: 3, from: 'lead', kind: 'task', taskId: 'T2', text: 'second', dependsOn: ['T1'] },
|
|
31
|
+
]);
|
|
32
|
+
const t1 = board.get('T1');
|
|
33
|
+
const t2 = board.get('T2');
|
|
34
|
+
if (t1.state !== 'claimed' || t1.owner !== 'node-b') throw new Error('claim fold wrong: ' + JSON.stringify(t1));
|
|
35
|
+
if (t.canClaim(t1, board).ok) throw new Error('claimed task still claimable');
|
|
36
|
+
if (t.canClaim(t2, board).ok) throw new Error('dependency gate failed');
|
|
37
|
+
t.applyEvent(board, { seq: 4, from: 'node-b', kind: 'done', taskId: 'T1', text: 'ok' });
|
|
38
|
+
if (board.get('T1').state !== 'done') throw new Error('done fold wrong');
|
|
39
|
+
if (!t.canClaim(t2, board).ok) throw new Error('ready after dep done failed');
|
|
40
|
+
const assigned = t.foldTasks([
|
|
41
|
+
{ seq: 10, from: 'lead', kind: 'task', taskId: 'T9', to: 'node-b', text: 'direct assign' },
|
|
42
|
+
{ seq: 11, from: 'node-b', kind: 'done', taskId: 'T9', text: 'done without claim' },
|
|
43
|
+
]);
|
|
44
|
+
const verdict = t.closeAuthority(assigned.get('T9'), 'node-b');
|
|
45
|
+
if (!verdict.allowed) throw new Error('assignee cannot close: ' + JSON.stringify(verdict));
|
|
46
|
+
const stranger = t.closeAuthority(assigned.get('T9'), 'node-z');
|
|
47
|
+
if (stranger.allowed) throw new Error('stranger closed assigned task');
|
|
48
|
+
if (!t.pathsOverlap('src/', 'src/main.js')) throw new Error('overlap miss');
|
|
49
|
+
if (t.pathsOverlap('docs/', 'src/')) throw new Error('overlap false positive');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
check('core: render/reach', async () => {
|
|
53
|
+
const c = await import('../plugin/lib/core.js');
|
|
54
|
+
const text = c.render({ from: 'node-a', name: 'lead', kind: 'task', to: 'node-c', seq: 7, taskId: 'T1', text: 'x'.repeat(200) }, 40);
|
|
55
|
+
for (const needle of ['[crosschat]', 'from=lead', 'node=node-a', 'kind=task', 'taskId=T1', 'seq=7']) {
|
|
56
|
+
if (!text.includes(needle)) throw new Error('render missing ' + needle);
|
|
57
|
+
}
|
|
58
|
+
if (c.reachOf({ to: '*' }, 'node-c') !== 'broadcast') throw new Error('broadcast reach');
|
|
59
|
+
if (c.reachOf({ to: 'node-c' }, 'node-c') !== 'direct') throw new Error('direct reach');
|
|
60
|
+
if (c.reachOf({ to: 'node-a' }, 'node-c') !== null) throw new Error('unrelated reach');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
check('relay: protocol + security smoke', async () => {
|
|
64
|
+
const r = spawnSync(process.execPath, [path.join(root, 'relay/smoke.mjs')], { encoding: 'utf8', timeout: 60000 });
|
|
65
|
+
if (r.status !== 0) throw new Error('smoke exit=' + r.status + '\n' + (r.stderr || '').slice(-800));
|
|
66
|
+
if (!/PASS/.test(r.stdout)) throw new Error('smoke did not print PASS');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
check('mcp: initialize + tools/list', async () => {
|
|
70
|
+
const args = [path.join(root, 'mcp/server.mjs')];
|
|
71
|
+
const child = spawn(process.execPath, args, {
|
|
72
|
+
env: { ...process.env, CROSSCHAT_TOKEN: 'test-token', CROSSCHAT_NODE: 'test-node', CROSSCHAT_RELAY: 'http://127.0.0.1:9', DSH_HOME: fs.mkdtempSync(path.join(os.tmpdir(), 'crosschat-mcp-')) },
|
|
73
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
74
|
+
});
|
|
75
|
+
let buf = '';
|
|
76
|
+
const send = (obj) => child.stdin.write(JSON.stringify(obj) + '\n');
|
|
77
|
+
const reply = await new Promise((resolve, reject) => {
|
|
78
|
+
const timer = setTimeout(() => reject(new Error('mcp timeout; stderr=' + err)), 15000);
|
|
79
|
+
let err = '';
|
|
80
|
+
child.stderr.on('data', (d) => { err += String(d); });
|
|
81
|
+
child.stdout.on('data', (d) => {
|
|
82
|
+
buf += String(d);
|
|
83
|
+
let idx;
|
|
84
|
+
while ((idx = buf.indexOf('\n')) >= 0) {
|
|
85
|
+
const line = buf.slice(0, idx).trim();
|
|
86
|
+
buf = buf.slice(idx + 1);
|
|
87
|
+
if (!line) continue;
|
|
88
|
+
let msg;
|
|
89
|
+
try { msg = JSON.parse(line); } catch { continue; }
|
|
90
|
+
if (msg.id === 2) { clearTimeout(timer); resolve(msg); }
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
send({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 't', version: '1' } } });
|
|
94
|
+
send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} });
|
|
95
|
+
}).finally(() => { try { child.kill(); } catch {} });
|
|
96
|
+
const names = (reply.result?.tools ?? []).map((t) => t.name);
|
|
97
|
+
for (const n of ['team_say', 'team_inbox', 'team_claim', 'team_done']) {
|
|
98
|
+
if (!names.includes(n)) throw new Error('missing tool ' + n + ' got ' + names.join(','));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
check('package: metadata + patch wiring', async () => {
|
|
103
|
+
const patchFile = path.join(root, 'plugin/cordis.patch.yml');
|
|
104
|
+
if (!fs.existsSync(patchFile)) throw new Error('patch missing');
|
|
105
|
+
const patch = fs.readFileSync(patchFile, 'utf8');
|
|
106
|
+
if (!new RegExp('name:\\s*' + pkg.name + '\\s*$', 'm').test(patch)) throw new Error('patch name != package name');
|
|
107
|
+
const entry = path.join(root, pkg.main);
|
|
108
|
+
if (!fs.existsSync(entry)) throw new Error('main missing: ' + pkg.main);
|
|
109
|
+
for (const [bin, target] of Object.entries(pkg.bin)) {
|
|
110
|
+
if (!fs.existsSync(path.join(root, target))) throw new Error('bin ' + bin + ' -> ' + target + ' missing');
|
|
111
|
+
}
|
|
112
|
+
if (!fs.existsSync(path.join(root, pkg.dsh.bundle.patch))) throw new Error('dsh.bundle.patch missing');
|
|
113
|
+
if (!pkg.files.includes('LICENSE')) throw new Error('LICENSE not in files');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
let failed = 0;
|
|
117
|
+
for (const c of cases) {
|
|
118
|
+
try { await c.fn(); console.log('ok ' + c.name); }
|
|
119
|
+
catch (e) { failed += 1; console.error('FAIL ' + c.name + ': ' + (e?.message ?? e)); }
|
|
120
|
+
}
|
|
121
|
+
if (failed) { console.error(`\n${failed} case(s) failed`); process.exit(1); }
|
|
122
|
+
console.log(`\nPASS ${cases.length} cases`);
|