@sleep2agi/commhub-server 0.9.0-preview.284 → 0.9.0-preview.285

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/build-info.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
- "commit": "b6ad87e519d17636bd112822b14debef1f4eea7e",
3
+ "commit": "cd13ac796c40ba24fcb2ebcb003c58fd9a5ef7e4",
4
4
  "dirty": false,
5
- "built_at": "2026-11-16T03:10:27.474Z",
5
+ "built_at": "2026-11-16T08:56:26.097Z",
6
6
  "source": "git"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.284",
3
+ "version": "0.9.0-preview.285",
4
4
  "description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -237,3 +237,49 @@ describe("任务看板 —— 授权让节点看得到 / 改得了", () => {
237
237
  expect(await cardIds(node.mgr.token)).not.toContain(cardA);
238
238
  });
239
239
  });
240
+
241
+ // admin 2026-11-16「节点新增权限可以编辑其他人的 AGENTS.md 的管理权限」:rules 能力。
242
+ describe("rules 授权 —— 节点写别的节点的规则文件", () => {
243
+ const write = (token: string, nodeId: string) => mcp(token, "write_node_rules_file", { node_id: nodeId, content: "# rules\n" });
244
+ const clearQueue = () => db.run("DELETE FROM node_rules_requests WHERE node_id IN (?1, ?2, ?3)", [node.mgr.id, node.a.id, node.b.id]);
245
+
246
+ test("写自己的不需要授权", async () => {
247
+ clearQueue();
248
+ await putGrants(user.boss.token, node.mgr.id, []);
249
+ const r = await write(node.mgr.token, node.mgr.id);
250
+ expect(r.ok).toBe(true);
251
+ });
252
+ test("没授权写别人的 ⇒ rules_write_not_granted", async () => {
253
+ clearQueue();
254
+ const r = await write(node.mgr.token, node.a.id);
255
+ expect(r.ok).toBe(false);
256
+ expect(r.error).toBe("rules_write_not_granted");
257
+ });
258
+ test("rules·node·edit ⇒ 只能写那一个节点", async () => {
259
+ clearQueue();
260
+ expect((await putGrants(user.boss.token, node.mgr.id, [{ capability: "rules", scope_kind: "node", scope_id: node.a.id, level: "edit" }])).status).toBe(200);
261
+ expect((await write(node.mgr.token, node.a.id)).ok).toBe(true);
262
+ expect((await write(node.mgr.token, node.b.id)).error).toBe("rules_write_not_granted");
263
+ });
264
+ test("rules·department·edit 覆盖子树;read 级别不能写", async () => {
265
+ clearQueue();
266
+ await putGrants(user.boss.token, node.mgr.id, [{ capability: "rules", scope_kind: "department", scope_id: deptB, level: "edit" }]);
267
+ expect((await write(node.mgr.token, node.b.id)).ok).toBe(true);
268
+ clearQueue();
269
+ await putGrants(user.boss.token, node.mgr.id, [{ capability: "rules", scope_kind: "network", level: "read" }]);
270
+ expect((await write(node.mgr.token, node.b.id)).error).toBe("rules_write_not_granted");
271
+ });
272
+ test("只读节点即使有 edit 授权也不能写别人的", async () => {
273
+ clearQueue();
274
+ await putGrants(user.boss.token, node.mgr.id, [{ capability: "rules", scope_kind: "network", level: "edit" }]);
275
+ db.run("UPDATE nodes SET permission_mode = 'readonly' WHERE node_id = ?1", [node.mgr.id]);
276
+ const r = await write(node.mgr.token, node.a.id);
277
+ db.run("UPDATE nodes SET permission_mode = 'normal' WHERE node_id = ?1", [node.mgr.id]);
278
+ expect(r.ok).toBe(false);
279
+ });
280
+ test("人(用户令牌)照旧能写", async () => {
281
+ clearQueue();
282
+ await putGrants(user.boss.token, node.mgr.id, []);
283
+ expect((await write(user.boss.token, node.a.id)).ok).toBe(true);
284
+ });
285
+ });
@@ -2,7 +2,7 @@
2
2
  // 也可以只管某个部门下的」)。
3
3
  //
4
4
  // 模型 = 能力 × 范围 × 级别,按行存在 node_grants:
5
- // capability schedules(第一期);board(第二期,随 requirements 读写判定一起上线)
5
+ // capability schedules(第一期);board(第二期,随 requirements 读写判定一起上线);rules(写别的节点的 AGENTS.md)
6
6
  // scope_kind network(整个网络,scope_id = "")| department(该部门及全部下级,scope_id = department_id)
7
7
  // | node(单个节点,scope_id = node_id)
8
8
  // level read(只看)| edit(看 + 改)
@@ -33,7 +33,10 @@ db.exec(`
33
33
  CREATE INDEX IF NOT EXISTS idx_node_grants_node ON node_grants(node_id);
34
34
  `);
35
35
 
36
- export const GRANT_CAPABILITIES = ["schedules", "board"] as const;
36
+ // rules(admin 2026-11-16「节点新增权限可以编辑其他人的 AGENTS.md 的管理权限」):
37
+ // 节点令牌写**别的节点**的规则文件(AGENTS.md / CLAUDE.md)必须有 rules·edit 覆盖目标;写自己的不需要。
38
+ // 读照旧(read 类工具),人(用户令牌)不受影响。
39
+ export const GRANT_CAPABILITIES = ["schedules", "board", "rules"] as const;
37
40
  // 第二期(board):能力与判定 + requirements 读写判定已在同一个 PR 里一起上 ⇒ 现在开闸。
38
41
  export const GRANT_CAPABILITIES_PLANNED = [] as const;
39
42
  export type GrantCapability = (typeof GRANT_CAPABILITIES)[number];
package/src/tools.ts CHANGED
@@ -58,6 +58,7 @@ import {
58
58
  validateOpenCodeV2ProviderModel,
59
59
  ValidationError,
60
60
  } from "./create-node-validate.js";
61
+ import { grantLevelForTarget } from "./node-grants.js";
61
62
  import {
62
63
  putPendingEnvBlob,
63
64
  takePendingEnvBlob,
@@ -4487,6 +4488,23 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
4487
4488
  }
4488
4489
  }
4489
4490
  const nodeId = node.node_id;
4491
+ // admin 2026-11-16 —— 节点令牌改**别的节点**的规则文件要有 rules·edit 授权(节点页「管理权限」里给)。
4492
+ // 改自己的照旧放行;人(用户令牌)不走这条。只读节点一律降为 read ⇒ 不能写。
4493
+ if (op === "write" && callerTokenIsNetwork) {
4494
+ const caller = resolveNodeCaller(callerTokenId);
4495
+ const self = caller.ok && (caller.kind === "node" ? caller.nodeId === nodeId : false)
4496
+ || caller.ok && node.alias === caller.alias;
4497
+ if (!self) {
4498
+ const callerNodeId = caller.ok && caller.kind === "node" ? caller.nodeId : null;
4499
+ const mode = callerNodeId ? db.get<{ permission_mode: string | null }>("SELECT permission_mode FROM nodes WHERE node_id = ?1", callerNodeId)?.permission_mode ?? null : null;
4500
+ const level = callerNodeId && !nodeId.startsWith("session:")
4501
+ ? grantLevelForTarget(node.network_id || "default", callerNodeId, "rules", nodeId, mode)
4502
+ : null;
4503
+ if (level !== "edit") {
4504
+ return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "rules_write_not_granted", target: node.alias, message: "a node may only edit its own rules file; editing another node's AGENTS.md needs a 'rules' edit grant covering that node (node page → 管理权限), or use a user login" }) }] };
4505
+ }
4506
+ }
4507
+ }
4490
4508
  if (isLogsOp(op) && !canReadNodeLogs(nodeId, node.network_id || "default")) {
4491
4509
  return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "logs_permission_denied", message: "only the node's owner or a network owner/admin can read its run log" }) }] };
4492
4510
  }