aicrosschat 0.8.3 → 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/INSTALL.md CHANGED
@@ -35,16 +35,16 @@ relay **不需要**在每台机器上都跑——只要有一台机器(通常
35
35
  ```sh
36
36
  # macOS / Linux
37
37
  cd ~/.dsh/profiles/web # 或你使用的 profile 目录
38
- pnpm add file:$HOME/crosschat/plugin
38
+ pnpm add aicrosschat
39
39
  ```
40
40
 
41
41
  ```powershell
42
42
  # Windows(在 profile 目录里)
43
43
  cd C:\Users\<你>\.dsh\profiles\web
44
- pnpm add file:C:/tools/crosschat/plugin
44
+ pnpm add aicrosschat
45
45
  ```
46
46
 
47
- 然后把 `crosschat` 加进该 profile 的 `package.json`:
47
+ 然后把 `aicrosschat` 加进该 profile 的 `package.json`:
48
48
 
49
49
  ```jsonc
50
50
  {
@@ -52,7 +52,7 @@ pnpm add file:C:/tools/crosschat/plugin
52
52
  }
53
53
  ```
54
54
 
55
- > Desktop 应用的 `desktop` profile 由应用独占,CLI 拒绝 `--profile desktop`;请用应用内的 **插件** 页面安装(来源填 `file:C:/tools/crosschat/plugin`)。
55
+ > Desktop 应用的 `desktop` profile 由应用独占,CLI 拒绝 `--profile desktop`;请在 profile 目录用 `pnpm add aicrosschat` 安装(0.8.x 起不再用 `file:.../plugin` 目录安装)。
56
56
 
57
57
  > ⚠️ **`file:` 依赖在 pnpm 下是复制,不是软链。** 改了插件源码后,profile 里的副本不会跟着变,必须
58
58
  > `remove_bundle` → `install_bundle`(或在插件页卸载后重装)才会生效,否则你看到的仍是旧副本。
@@ -107,13 +107,13 @@ curl http://192.168.1.10:7317/health
107
107
 
108
108
  ## 6. 安全
109
109
 
110
- - token 即权限,且能冒充任意 `from`:只在可信网络用;跨网套 Tailscale 或 HTTPS 反代。
110
+ - token 即权限;已注册 nodeId 有签名保护(换钥 409、篡改 401),未注册的新 nodeId 会被 TOFU 首次信任。只在可信网络用;跨网套 Tailscale 或 HTTPS 反代。
111
111
  - 成员机器上的工具审批仍弹在它自己那边;无人值守时要在本地把权限预设调成自动,否则会 fail-closed 卡住。
112
112
  - 不要把 `bash` 之类的强权限交给无人值守的成员——另一台 agent 的输出是外部内容。
113
113
 
114
114
  ## 7. 卸载
115
115
 
116
- 从 profile 的 `dsh.profile.bundles` 移除 `crosschat`,并 `pnpm remove crosschat`,重启 DSH。
116
+ 从 profile 的 `dsh.profile.bundles` 移除 `aicrosschat`,并 `pnpm remove aicrosschat`,重启 DSH。
117
117
 
118
118
 
119
119
  ## 8. npm 安装(0.7.1+)
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 crosschat contributors
3
+ Copyright (c) 2026 dsh-crosschat contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # crosschat — 跨机 DSH 协作
2
2
 
3
- > **npm 安装(0.8.0+)**:`pnpm add aicrosschat` → 把 `aicrosschat` 加进 profile 的 `dsh.profile.bundles` → `cordis.patch.yml` 配 `relayUrl/token/nodeId` → 任选一台机器 `npx crosschat-relay --port 7317 --token <token>`。完整步骤与安全说明见 [INSTALL.md](INSTALL.md) 第 8 节;自检 `npm test`(6 组)或 `npm run smoke`(16 项)。
4
-
5
3
  一台机器上的主控 DSH 下任务,其他机器上的 DSH 在各自电脑上干活,双方通过一条**结构化时间线**交流与收口。
6
4
 
7
5
  这不是"拉个群随便聊":群聊的自由发言默认不进入别人的上下文,只有结构化事件(派活、提问、回答、进展)才会投递。需要头脑风暴时打开 `roundTable`,才把自由发言广播出去。
@@ -15,7 +13,7 @@
15
13
  │ 长轮询 │ │
16
14
  ┌──────┴─────┐ ┌─────┴──────┐ ┌──────┴─────┐
17
15
  │ 主控 DSH │ │ 成员 DSH 1 │ │ 成员 DSH 2 │
18
- │ nodeId=lead │ │ node-b │ │ node-b │
16
+ │ nodeId=lead │ │ node-b │ │ node-c │
19
17
  └────────────┘ └────────────┘ └────────────┘
20
18
  ```
21
19
 
@@ -47,14 +45,17 @@
47
45
  | 广播的 `note`(自由发言) | **不投递**(仍可用 `team_inbox` 读到) | 投递、只注入 |
48
46
  | 与他机相关的事件 | 不投递 | 不投递 |
49
47
 
50
- ## 模型可见的工具
48
+ ## 模型可见的工具(DSH 端共 11 个)
51
49
 
52
50
  | 工具 | 作用 |
53
51
  |---|---|
54
- | `team_join` | 加入时间线;从当前日志尾部开始接收 |
52
+ | `team_join` / `team_leave` | 入席 / 退席(MCP 端由环境变量固定身份,没有这两个) |
55
53
  | `team_say` | 发言/派活/汇报;`to`、`kind`、`taskId` 决定投给谁 |
56
54
  | `team_inbox` | 读取最近事件(包括没投递给你的),支持 `since` 续读 |
57
55
  | `team_peers` | 列出在线节点 |
56
+ | `team_claim` / `team_done` / `team_tasks` | 任务板:认领 / 完成 / 查看 |
57
+ | `team_profile` / `team_roster` | 能力自述 / 名册 |
58
+ | `team_wait` | 阻塞等一组任务完成(默认 60s,上限 300s) |
58
59
 
59
60
  ## 任务板
60
61
 
@@ -74,14 +75,13 @@ task ──▶ open ──claim──▶ claimed ──done──▶ done
74
75
  | 释放 | `release` 把 `claimed` 退回 `open`,可被别人重新认领 |
75
76
  | 关闭 | 只有 `done` 关闭任务;`answer` / `status` 只是汇报,不算完成 |
76
77
 
77
- 三端工具同名同义:
78
+ 三端工具的差异(以实际代码为准):
78
79
 
79
- | 工具 | 作用 |
80
- |---|---|
81
- | `team_claim(taskId)` | 认领,返回是否生效与当前持有人 |
82
- | `team_done(taskId, result)` | 标记完成并附摘要 |
83
- | `team_tasks(state?)` | 查看任务板(open / claimed / done) |
84
- | `team_say(kind=task, …)` | 派任务;未给 `taskId` 时自动生成 |
80
+ | 端 | 工具数 | 说明 |
81
+ |---|---|---|
82
+ | DSH 插件 | **11** | 含 `team_join` / `team_leave`,身份随会话自动恢复 |
83
+ | MCP 桥 | **9** | 无 join/leave(用 `CROSSCHAT_NODE` 固定身份),其余同名同义,含 `team_wait` |
84
+ | CLI | **9** | 子命令 `peers/say/inbox/claim/done/tasks/profile/roster/wait` |
85
85
 
86
86
  > 实践提醒:干完活一定要调 `team_done`,别只发 `answer`——`answer` 不关闭任务,板上会一直显示 `open`。
87
87
 
@@ -106,7 +106,7 @@ task ──▶ open ──claim──▶ claimed ──done──▶ done
106
106
  ### 1. 主控机器上启动 relay
107
107
 
108
108
  ```powershell
109
- node crosschat\relay\relay.mjs --port 7317 --host 0.0.0.0 --token <一个长随机串>
109
+ npx crosschat-relay --port 7317 --host 0.0.0.0 --token <一个长随机串>
110
110
  ```
111
111
 
112
112
  - 建议加 `--data events.jsonl` 持久化事件。
@@ -115,15 +115,14 @@ node crosschat\relay\relay.mjs --port 7317 --host 0.0.0.0 --token <一个长随
115
115
 
116
116
  ### 2. 每台机器装插件
117
117
 
118
- 插件目录:`crosschat/plugin`。它通过 `dsh.bundle.patch` 声明自己的行,安装后由 `dsh.profile.bundles` 组合。
119
-
120
- 用 `plugin_manager` 安装(目标 profile 会因此改动):
121
-
122
- ```
123
- plugin_manager.install_bundle({ action: 'install_bundle', target: 'file:C:\\path\\to\\crosschat\\plugin' })
118
+ ```powershell
119
+ cd %USERPROFILE%\.dsh\profiles\desktop
120
+ pnpm add aicrosschat
124
121
  ```
125
122
 
126
- > Desktop 的 `desktop` profile 由应用独占,CLI 的 `dsh plugin --profile desktop` 会被拒绝;因此走应用内的插件管理入口。
123
+ 然后把 `aicrosschat` 加进该 profile 的 `dsh.profile.bundles`,重启 DSH。根包通过 `dsh.bundle.patch` 指向 `plugin/cordis.patch.yml`。
124
+
125
+ > 0.8.x 起不再支持“把 `plugin` 子目录当包安装”(`file:...\plugin`);那是 0.7 的目录分发方式,patch 的模块名已改为 `aicrosschat`。
127
126
 
128
127
  ### 3. 每台机器配置
129
128
 
@@ -131,7 +130,7 @@ plugin_manager.install_bundle({ action: 'install_bundle', target: 'file:C:\\path
131
130
 
132
131
  ```yaml
133
132
  - id: crosschat
134
- name: crosschat
133
+ name: aicrosschat
135
134
  config:
136
135
  relayUrl: http://192.168.1.10:7317
137
136
  token: <和 relay 一致>
@@ -155,20 +154,20 @@ plugin_manager.install_bundle({ action: 'install_bundle', target: 'file:C:\\path
155
154
 
156
155
  ## 验证
157
156
 
157
+ 仓库内(含测试目录):
158
+
158
159
  ```powershell
159
- node crosschat\relay\smoke.mjs # relay 协议:发布/定向/广播/长轮询/鉴权
160
- node crosschat\plugin\test-core.mjs # 投递规则与渲染
161
- node crosschat\plugin\test-integration.mjs # 真实 relay + 假 agent 的端到端
162
- node crosschat\test-two-instances.mjs # 两个隔离 DSH 实例的端到端
160
+ npm test # 6 组:identity / tasks / core / relay smoke / mcp / 包完整性
161
+ npm run smoke # relay 协议与安全,16 项断言
163
162
  ```
164
163
 
165
- `test-integration.mjs` 用 `module.registerHooks` 把 DSH 的三个依赖桩掉,因此不需要安装插件、不需要启动 DSH 也能验证投递行为。
164
+ 安装包里(`test/` 已随包发布,可直接跑完整 6 组):
166
165
 
167
- ### 本机双实例结果(已跑通)
166
+ ```powershell
167
+ npm run smoke # 16 项,等价于 node relay/smoke.mjs
168
+ ```
168
169
 
169
- - 实例 A:桌面 DSH,`desktop` profile,`nodeId=node-a`(主控)。
170
- - 实例 B:隔离 `DSH_HOME=%USERPROFILE%\.crosschat-member`,`sdk` profile,`nodeId=node-b`,由 `test-two-instances.mjs` 通过 stdio JSON-RPC 驱动。
171
- - 证据链:B 运行 `team_join` 后出现在 `/peers`;A 发 `task`(seq=7);B 被 `followup` 唤醒、跑完一轮、用 `team_say` 回报(seq=8);该回报以 `[crosschat]` 信封注入 A 的上下文。
170
+ > 早先文档里提到的 `test-core.mjs`、`test-integration.mjs`、`test-two-instances.mjs` 已不存在;双实例结果属于历史记录,当前仓库不再提供该驱动脚本,**不作为可复现声明**。
172
171
 
173
172
 
174
173
  ## 其他客户端接入(非 DSH)
@@ -186,7 +185,7 @@ node crosschat\test-two-instances.mjs # 两个隔离 DSH 实例的端到端
186
185
  | `CROSSCHAT_NODE` | 本成员节点 id(必填,全网唯一) |
187
186
  | `CROSSCHAT_NAME` | 显示名,默认等于节点 id |
188
187
 
189
- 暴露三个工具:`team_say`、`team_inbox`、`team_peers`(与 DSH 插件同名同义)。
188
+ 暴露九个工具:`team_say`、`team_inbox`、`team_peers`、`team_claim`、`team_done`、`team_tasks`、`team_profile`、`team_roster`、`team_wait`(与 DSH 插件的对应工具同名同义;DSH 另有 `team_join` / `team_leave`,用于入席管理,MCP 端以环境变量固定身份,不需要这两个)。
190
189
 
191
190
  通用 `mcpServers` 配置(WorkBuddy 的 `~/.workbuddy/mcp.json`、Trae、扣子、Kimi、Qoder、Claude Code、Codex、Cursor、Gemini CLI 都吃这一套):
192
191
 
@@ -195,7 +194,7 @@ node crosschat\test-two-instances.mjs # 两个隔离 DSH 实例的端到端
195
194
  "mcpServers": {
196
195
  "crosschat": {
197
196
  "command": "node",
198
- "args": ["C:/tools/crosschat/mcp/server.mjs"],
197
+ "args": ["npx crosschat-mcp"],
199
198
  "env": {
200
199
  "CROSSCHAT_RELAY": "http://192.168.1.10:7317",
201
200
  "CROSSCHAT_TOKEN": "<relay token>",
@@ -210,9 +209,9 @@ node crosschat\test-two-instances.mjs # 两个隔离 DSH 实例的端到端
210
209
  ### 2) CLI shim(任何能跑命令的 agent)
211
210
 
212
211
  ```sh
213
- node crosschat/bin/crosschat.mjs peers
214
- node crosschat/bin/crosschat.mjs say "正文" --to node-a --kind answer --task T1
215
- node crosschat/bin/crosschat.mjs inbox --since 8 --limit 5
212
+ npx crosschat peers
213
+ npx crosschat say "正文" --to node-a --kind answer --task T1
214
+ npx crosschat inbox --since 8 --limit 5
216
215
  ```
217
216
 
218
217
  连接参数:`--relay` / `--token` / `--node` / `--name`,或对应的 `CROSSCHAT_*` 环境变量。
@@ -246,7 +245,37 @@ MCP 与 CLI 成员**没有 `inject`/`followup`**——那是 DSH 内部的 agent
246
245
 
247
246
  > 升级顺序:**先升客户端,再升 relay**。反过来的话,旧客户端发不出签名,所有消息都会被 400 拒绝。
248
247
 
249
- ## 可靠性
248
+ ## 依赖、能力自述与收口
249
+
250
+ 这三组能力是为「一句话派活 → 自动拆解 → 等齐 → 汇总」准备的。
251
+
252
+ ### 任务依赖(`dependsOn`)
253
+
254
+ ```json
255
+ { "kind": "task", "taskId": "T3", "to": "node-b", "dependsOn": ["T1", "T2"], "text": "跑测试" }
256
+ ```
257
+
258
+ - 前置任务**没有全部 `done`** 时,`team_claim` 会返回「依赖未完成:T1, T2」,不会生效;
259
+ - 任务板上该项显示 `deps=…`,未就绪时标「· 等待中」;
260
+ - 依赖是**认领门**,不是自动调度:前置完成后,需要主控或成员再次 `claim`(或由主控 `team_wait` 等到齐后再派下一批)。
261
+
262
+ ### 阻塞收口(`team_wait`)
263
+
264
+ `team_wait(taskIds, timeoutSec = 60)` 会轮询任务板直到这些任务全部 `done` 或超时(上限 300 秒),返回每个任务的最终状态。派完子任务后用它替代「反复查板子」。
265
+
266
+ ### 能力自述与名册(`team_profile` / `team_roster`)
267
+
268
+ ```json
269
+ { "skills": "写文档、跑测试", "paths": ["docs/"], "notes": "Windows 节点,模型 deepseek-flash" }
270
+ ```
271
+
272
+ `team_profile` 广播一条 `profile` 事件;`team_roster` 汇总在线节点与各自最近一次声明。主控据此分工,而不是靠猜。建议加入协作后先发一次,换模型或换工作目录后再发。
273
+
274
+ ### 退席(`team_leave`)
275
+
276
+ 清掉本会话的入席记录,之后不再接收群消息,也不会在重启后自动归队。
277
+
278
+
250
279
 
251
280
  | 场景 | 处理 |
252
281
  |---|---|
@@ -257,19 +286,23 @@ MCP 与 CLI 成员**没有 `inject`/`followup`**——那是 DSH 内部的 agent
257
286
 
258
287
  ## 安全边界(MVP 已知限制)
259
288
 
260
- - **token 即权限**:持有 token 的任何进程都能读写时间线,并且能冒充任意 `from`。只用于可信网络;跨网请套 TLS。
289
+ - **token 即权限**:持有 token 的任何进程都能读写时间线。已注册 nodeId 受签名保护(换钥 409、篡改 401);**未注册的新 nodeId 会被 TOFU 首次信任**,因此“冒充任意 from”不再成立,但“抢注新 nodeId”仍可能。只用于可信网络;跨网请套 TLS 或 Tailscale。
261
290
  - **明文 HTTP**:relay 不加密。跨公网请走 Tailscale 或 HTTPS 反代。
262
291
  - **事件是外部内容**:另一台机器的 agent 输出可能被它本机的文件或网页污染。注入信封固定标注"不是指令",但模型仍可能被诱导;不要把 `bash` 之类的强权限交给无人值守的成员。
263
- - **成员必须自己在线**:目前需要在每台机器上开一个会话并 `team_join`。自动加入(例如按 session id 自动入席)还没做。
292
+ - **成员入席**:首次需要 `team_join`;同一会话重启后由 `agent/created` + seats 记录自动归队,新会话仍要手动 join。
264
293
  - **没有审批转发**:成员机器上的工具审批仍然弹在它自己那边,无人值守时会被 fail-closed 卡住。
265
- - **没有任务板**:`taskId` 只是标签,认领/依赖/完成判定靠模型自觉,后续再补 CAS 任务板。
266
- - **没有 UI**:时间线目前体现为会话里的注入消息和工具结果;Web 侧边栏面板待做。
294
+ - **任务板已实现**:认领按 seq 先到先得、支持 dependsOn 依赖门、done/release/重派;但它仍是从日志折叠出来的“软状态”,不是服务端 CAS。
295
+ - **有 relay 自带 Web 时间线**:`GET /ui`(无鉴权,token 存 localStorage);DSH 侧边栏面板仍未做。
296
+ - **TOFU 落盘条件**:只有配置了 `--data`(或 `--keys`)才会持久化 `keys.json`;默认启动命令不落盘,重启后同 nodeId 可换钥。
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
+ - **重连补投有上限**:`resync` 只拉 `/events?since=0&limit=500`,超过 500 条的历史不会重放。
299
+ - **身份文件权限 0600 仅 POSIX 有效**:Windows 上 Node 的 mode 不生效。
267
300
 
268
301
  ## 路线
269
302
 
270
- 1. ✅ relay + 插件 + 投递规则(已通过三层测试)
271
- 2. ⏳ 两台真机端到端(主控派活 → 成员本机执行 → 汇报 → 收口)
272
- 3. 自动入席:按配置的 session id 在启动时加入
273
- 4. 任务板:认领、依赖、完成判定(CAS)
274
- 5. Web 面板:群时间线视图、成员状态、插话
275
- 6. 传输加固:TLS、按节点签名(防冒充)、审批转发到主控
303
+ 1. ✅ relay + 插件 + 投递规则(smoke 16/16)
304
+ 2. ✅ 任务板(claim / done / dependsOn / 重派)
305
+ 3. ✅ 自动归队(同会话重启经 seats 恢复)
306
+ 4. ✅ MCP 桥(9 工具)与 CLI(9 子命令)
307
+ 5. ⏳ 审批转发到主控;DSH 侧边栏面板
308
+ 6. ⏳ TLS 实测与证书信任链;>500 条历史补投
package/mcp/server.mjs CHANGED
@@ -98,6 +98,18 @@ const TOOLS = [
98
98
  description: '查看成员名册:在线节点与各自最近一次能力声明。',
99
99
  inputSchema: { type: 'object', properties: {} },
100
100
  },
101
+ {
102
+ name: 'team_wait',
103
+ description: '阻塞等待一组任务全部完成(done)或超时。派完子任务后用它收口,最多等 timeoutSec 秒。',
104
+ inputSchema: {
105
+ type: 'object',
106
+ properties: {
107
+ taskIds: { type: 'array', items: { type: 'string' }, description: '要等待的任务 id 列表。' },
108
+ timeoutSec: { type: 'integer', description: '最长等待秒数,默认 60,上限 300。' },
109
+ },
110
+ required: ['taskIds'],
111
+ },
112
+ },
101
113
  {
102
114
  name: 'team_peers',
103
115
  description: '列出当前在线的协作节点和日志尾部序号。',
@@ -215,6 +227,27 @@ async function callTool(name, args) {
215
227
  return [...nodes].map(node => `${node}${online.has(node) ? '' : '(离线)'}`
216
228
  + `${profiles.has(node) ? `: ${profiles.get(node)}` : '(未声明能力)'}`).join('\n')
217
229
  }
230
+ if (name === 'team_wait') {
231
+ const ids = normalizeIds(args?.taskIds)
232
+ if (ids.length === 0) throw new Error('taskIds 不能为空')
233
+ const timeoutSec = Math.min(300, Math.max(5, Number(args?.timeoutSec ?? 60)))
234
+ const deadline = Date.now() + timeoutSec * 1000
235
+ const snapshot = async () => {
236
+ const page = await client.events(0, 500)
237
+ const board = foldTasks(page.events ?? [])
238
+ return ids.map(id => ({ id, state: board.get(id)?.state ?? 'missing' }))
239
+ }
240
+ for (;;) {
241
+ const rows = await snapshot()
242
+ if (rows.every(row => row.state === 'done')) {
243
+ return `全部完成:${rows.map(row => `${row.id}=done`).join('、')}`
244
+ }
245
+ if (Date.now() >= deadline) {
246
+ return `超时(${timeoutSec}s),仍未全部完成:${rows.map(row => `${row.id}=${row.state}`).join('、')}`
247
+ }
248
+ await new Promise(resolve => setTimeout(resolve, 2000))
249
+ }
250
+ }
218
251
  if (name === 'team_peers') {
219
252
  const page = await client.peers()
220
253
  const nodes = (page.peers ?? []).map(p => p.node)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicrosschat",
3
- "version": "0.8.3",
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",
@@ -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
- return { allowed: owner === from || creator === from, owner, creator }
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
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "name": "crosschat",
2
+ "name": "aicrosschat-plugin",
3
3
  "description": "跨机 DSH 协作:共享结构化事件时间线 + 定向消息 + 可选圆桌模式",
4
- "version": "0.7.0",
4
+ "version": "0.8.4",
5
5
  "private": true,
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
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
- * 接口(全部要求 x-crosschat-token):
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/setup-member.ps1 CHANGED
@@ -60,27 +60,27 @@ if (-not (Test-Path $manifestFile)) {
60
60
  }
61
61
 
62
62
  # --- 3. plugin installed? --------------------------------------------------
63
- $pluginPkg = Join-Path $ProfileDir 'node_modules\crosschat\package.json'
63
+ $pluginPkg = Join-Path $ProfileDir 'node_modules\aicrosschat\package.json'
64
64
  if (Test-Path $pluginPkg) {
65
65
  $version = ([System.IO.File]::ReadAllText($pluginPkg, [System.Text.Encoding]::UTF8) | ConvertFrom-Json).version
66
- Write-Ok "plugin present: crosschat@$version"
66
+ Write-Ok "plugin present: aicrosschat@$version"
67
67
  } else {
68
68
  Write-Warn2 "plugin not installed yet - install it in the DSH Plugins UI (source: path to crosschat\plugin)"
69
69
  }
70
70
 
71
71
  $manifest = [System.IO.File]::ReadAllText($manifestFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json
72
72
  $bundles = @($manifest.dsh.profile.bundles)
73
- if ($bundles -contains 'crosschat') {
74
- Write-Ok "crosschat is already in dsh.profile.bundles"
73
+ if ($bundles -contains 'aicrosschat') {
74
+ Write-Ok "aicrosschat is already in dsh.profile.bundles"
75
75
  } else {
76
- Write-Warn2 "crosschat is missing from dsh.profile.bundles - add it or install via the Plugins UI"
76
+ Write-Warn2 "aicrosschat is missing from dsh.profile.bundles - add it or install via the Plugins UI"
77
77
  }
78
78
 
79
79
  # --- 4. config block -------------------------------------------------------
80
80
  $block = @"
81
81
  # crosschat (written by setup-member.ps1)
82
82
  - id: crosschat
83
- name: crosschat
83
+ name: aicrosschat
84
84
  config:
85
85
  relayUrl: $RelayUrl
86
86
  token: $Token
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`);