@sleep2agi/commhub-server 0.9.0-preview.245 → 0.9.0-preview.246
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/package.json +1 -1
- package/src/requirement-events-http.test.ts +16 -0
- package/src/requirements.ts +33 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.246",
|
|
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",
|
|
@@ -240,6 +240,22 @@ describe("requirement events", () => {
|
|
|
240
240
|
expect((await events(scoped.token, `&requirement_id=${theirs.id}`)).body.events).toEqual([]);
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
+
test("the CARD payload hides a hidden node's alias too (assignee is a string, not a ref)", async () => {
|
|
244
|
+
// 2026-10-31 —— #3285 的另一半,比事件列表**常用得多**的那一面。
|
|
245
|
+
// assignee 是派生展示字段(自由文本),写侧在设 agent_owner 时回填别名;
|
|
246
|
+
// 它没有 {kind,id} 形状 ⇒ isHiddenRef 判不了 ⇒ 只抹引用的话,卡列表上照样看得到别名。
|
|
247
|
+
const card = await create(admin.token, { name: "动态示例十之半" });
|
|
248
|
+
await patch(admin.token, card.id, { agent_owner: { kind: "node", id: NODE } });
|
|
249
|
+
const mine = (await send(admin.token, "GET", `/api/requirements?network_id=${NET}&limit=500`)).body.requirements
|
|
250
|
+
.find((c: any) => c.id === card.id);
|
|
251
|
+
expect(mine.assignee).toBe("ev-node"); // 无限制的读者:看得到(这是如实回显)
|
|
252
|
+
const theirs = (await send(restricted.token, "GET", `/api/requirements?network_id=${NET}&limit=500`)).body.requirements
|
|
253
|
+
.find((c: any) => c.id === card.id);
|
|
254
|
+
expect(theirs).toBeDefined(); // 卡本身他看得见(不是「看不见的卡」那条规则)
|
|
255
|
+
expect(theirs.assignee).toBeNull(); // 但执行人那一栏不能借别名漏出去
|
|
256
|
+
expect(JSON.stringify(theirs)).not.toContain("ev-node");
|
|
257
|
+
});
|
|
258
|
+
|
|
243
259
|
test("an agent-restricted member: hidden nodes are masked, and an event that only differs by a hidden node is dropped", async () => {
|
|
244
260
|
const card = await create(admin.token, { name: "动态示例十" });
|
|
245
261
|
await patch(nodeToken, card.id, { priority: "high" });
|
package/src/requirements.ts
CHANGED
|
@@ -829,6 +829,34 @@ function hiddenNodeFilter(ctx: RequirementsRequestContext, networkId: string): H
|
|
|
829
829
|
const visible = new Set(visibleAgents(ctx.auth.userId, networkId).nodeIds);
|
|
830
830
|
return (nodeId: string) => !visible.has(nodeId);
|
|
831
831
|
}
|
|
832
|
+
/**
|
|
833
|
+
* 2026-10-31 —— **派生展示字段绕过了引用抹除**(#3285 的另一半)。
|
|
834
|
+
*
|
|
835
|
+
* `owner` / `agent_owner` / `participants` 都是 `{kind:"node", id}` 引用,所以能被
|
|
836
|
+
* `isHiddenRef` 判定并抹掉。而 `assignee` 与事件里的同名字段存的是**别名字符串** ——
|
|
837
|
+
* 没有任何 {kind,id} 可判 ⇒ 受限成员在**卡片列表**上(比事件列表常用得多)直接读到
|
|
838
|
+
* 一个他看不见的 Agent 的名字。
|
|
839
|
+
*
|
|
840
|
+
* 只能在「别名集合」这一层判:把该网络里受限成员看不见的节点的别名收成一个集合。
|
|
841
|
+
* 方向写死:**命中就抹**(宁可少显示一个名字,也不多露一个)。
|
|
842
|
+
*/
|
|
843
|
+
const aliasSetByCtx = new WeakMap<RequirementsRequestContext, Map<string, Set<string>>>();
|
|
844
|
+
export function hiddenNodeAliases(ctx: RequirementsRequestContext, networkId: string): Set<string> {
|
|
845
|
+
const hidden = hiddenNodeFilter(ctx, networkId);
|
|
846
|
+
if (!hidden) return EMPTY_ALIAS_SET;
|
|
847
|
+
let perNet = aliasSetByCtx.get(ctx);
|
|
848
|
+
if (!perNet) aliasSetByCtx.set(ctx, perNet = new Map());
|
|
849
|
+
let set = perNet.get(networkId);
|
|
850
|
+
if (!set) {
|
|
851
|
+
const rows = db.all<{ node_id: string; alias: string | null }>(
|
|
852
|
+
"SELECT node_id, alias FROM nodes WHERE network_id = ?1", networkId);
|
|
853
|
+
set = new Set(rows.filter(r => r.alias && hidden(r.node_id)).map(r => r.alias as string));
|
|
854
|
+
perNet.set(networkId, set);
|
|
855
|
+
}
|
|
856
|
+
return set;
|
|
857
|
+
}
|
|
858
|
+
const EMPTY_ALIAS_SET: Set<string> = new Set();
|
|
859
|
+
|
|
832
860
|
function isHiddenRef(ref: unknown, hidden: HiddenNode): boolean {
|
|
833
861
|
if (!hidden || !ref || typeof ref !== "object") return false;
|
|
834
862
|
const r = ref as { kind?: unknown; id?: unknown };
|
|
@@ -851,8 +879,11 @@ function toPublicFor(ctx: RequirementsRequestContext, row: Row) {
|
|
|
851
879
|
const pub = can ? { ...base, viewer_can: can } : base;
|
|
852
880
|
const hidden = hiddenNodeFilter(ctx, row.network_id);
|
|
853
881
|
if (!hidden) return pub;
|
|
882
|
+
const hiddenAliases = hiddenNodeAliases(ctx, row.network_id);
|
|
854
883
|
return {
|
|
855
884
|
...pub,
|
|
885
|
+
// 别名不是引用 ⇒ 单列一条(见 hiddenNodeAliases 的长注释)
|
|
886
|
+
assignee: hiddenAliases.has(pub.assignee) ? null : pub.assignee,
|
|
856
887
|
owner: isHiddenRef(pub.owner, hidden) ? null : pub.owner,
|
|
857
888
|
agent_owner: isHiddenRef(pub.agent_owner, hidden) ? null : pub.agent_owner,
|
|
858
889
|
participants: Array.isArray(pub.participants) ? pub.participants.filter((ref: unknown) => !isHiddenRef(ref, hidden)) : pub.participants,
|
|
@@ -1779,16 +1810,8 @@ function listEvents(ctx: RequirementsRequestContext): Response {
|
|
|
1779
1810
|
// 而同一张卡的 agent_owner 事件已被正确抹掉 ⇒ 名字从旁边漏了出去。
|
|
1780
1811
|
// 修法:按「隐藏节点的别名集合」判,命中就抹成 null;随后「抹后 old==new」的规则会把整条丢弃。
|
|
1781
1812
|
// 方向选择:宁可多抹(隐藏)也不多露 —— 别名与人名冲突时,少显示一个名字的代价小于多露一个。
|
|
1782
|
-
|
|
1783
|
-
const hiddenAlias = (v: unknown): boolean =>
|
|
1784
|
-
if (!hidden || typeof v !== "string" || !v) return false;
|
|
1785
|
-
if (hiddenAliases === null) {
|
|
1786
|
-
const rows = db.all<{ node_id: string; alias: string | null }>(
|
|
1787
|
-
"SELECT node_id, alias FROM nodes WHERE network_id = ?1", networkId);
|
|
1788
|
-
hiddenAliases = new Set(rows.filter(r => r.alias && hidden(r.node_id)).map(r => r.alias as string));
|
|
1789
|
-
}
|
|
1790
|
-
return hiddenAliases.has(v);
|
|
1791
|
-
};
|
|
1813
|
+
const aliasSet = hiddenNodeAliases(ctx, networkId);
|
|
1814
|
+
const hiddenAlias = (v: unknown): boolean => !!hidden && typeof v === "string" && v !== "" && aliasSet.has(v);
|
|
1792
1815
|
const aware = knowsAbandoned(ctx);
|
|
1793
1816
|
const seen = new Map<string, boolean>();
|
|
1794
1817
|
const canSee = (id: string): boolean => {
|