@sleep2agi/commhub-server 0.9.0-preview.231 → 0.9.0-preview.232

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.231",
3
+ "version": "0.9.0-preview.232",
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",
@@ -34,7 +34,7 @@ export const PUBLIC_HEALTH_KEY_READERS: Readonly<Record<string, AnonReaderEntry>
34
34
  status: { reader: "cli", why: "客户端展示 Hub 的细分状态(ok / degraded)" },
35
35
  status_reasons: { reader: "cli", why: "anet status 把 status_reasons 拼成一行原因给用户看(bin/cli.ts)" },
36
36
  version: { reader: "cli", why: "版本不一致提示(anet 与 hub 的版本对齐)" },
37
- version_source: { reader: "operator", why: "运维判断「版本没变」是没发出去还是被 env 覆盖;仓内无代码读" },
37
+ version_source: { reader: "operator", why: "运维判断「版本没变」是没发出去、被 env 覆盖,还是读不到/读到空;仓内无代码读" },
38
38
  version_role: { reader: "external", why: "docs/release-hub-runbook.md 描述的仓外 dashboard 读它区分构建;仓内无消费者,未验" },
39
39
  api_version: { reader: "cli", why: "客户端与 Hub 协商协议版本,不匹配时给出升级提示" },
40
40
  transport: { reader: "cli", why: "协议协商(streamable-http)" },
@@ -1121,23 +1121,23 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
1121
1121
  // 2026-10-31 —— **有覆盖、零仲裁**(外部复核 (d)):version 有两个来源
1122
1122
  // (standalone 二进制注入的 env / 磁盘 package.json),此前只报结果、不报谁赢了。
1123
1123
  // version_source 就是那个仲裁位;下面四例钉住它的语义。
1124
- test("version_source names which override won (embedded_env / package_json / unknown)", async () => {
1124
+ test("version_source names which override won (and splits the two failure causes)", async () => {
1125
1125
  const { resolveServerVersion } = await import("./server.js");
1126
1126
  expect(resolveServerVersion("0.9.0-preview.999", () => "0.9.0-preview.1"))
1127
1127
  .toEqual({ version: "0.9.0-preview.999", source: "embedded_env" });
1128
1128
  // env 形状不对 ⇒ 落到磁盘,而不是把非法值当版本号
1129
1129
  expect(resolveServerVersion("latest", () => "0.9.0-preview.1"))
1130
1130
  .toEqual({ version: "0.9.0-preview.1", source: "package_json" });
1131
- // 磁盘读失败 ⇒ unknown,而不是伪装成某个来源
1131
+ // 磁盘读失败 ⇒ read_failed;读到空 ⇒ empty_value(**两个成因两个值**,不是一个 unknown)
1132
1132
  expect(resolveServerVersion(undefined, () => { throw new Error("ENOENT"); }))
1133
- .toEqual({ version: "?", source: "unknown" });
1133
+ .toEqual({ version: "?", source: "read_failed" });
1134
1134
  expect(resolveServerVersion(" ", () => "?"))
1135
- .toEqual({ version: "?", source: "unknown" });
1135
+ .toEqual({ version: "?", source: "empty_value" });
1136
1136
 
1137
1137
  // 线上读数与语义自洽:unknown ⇔ version 是 "?"
1138
1138
  const body = await (await fetch(`${BASE}/health`)).json() as any;
1139
- expect(["embedded_env", "package_json", "unknown"]).toContain(body.version_source);
1140
- if (body.version_source === "unknown") expect(body.version).toBe("?");
1139
+ expect(["embedded_env", "package_json", "read_failed", "empty_value"]).toContain(body.version_source);
1140
+ if (body.version_source === "read_failed" || body.version_source === "empty_value") expect(body.version).toBe("?");
1141
1141
  else expect(body.version).not.toBe("?");
1142
1142
  });
1143
1143
 
package/src/server.ts CHANGED
@@ -176,7 +176,11 @@ const MCP_LABEL_MAX_BYTES = 1024 * 1024;
176
176
  * · 或以为在用二进制内嵌版本,其实是磁盘那个
177
177
  * 两个方向都只能靠猜。⇒ 现在把来源作为字段一起给出。
178
178
  */
179
- export type VersionSource = "embedded_env" | "package_json" | "unknown";
179
+ // 2026-10-31 —— 外部复核:「diagnosticIdValid 失败时**静默丢键** ⇒ id_absent 与 id_malformed
180
+ // 不可区分。」同一形状在本字段上:原来 unknown 同时表示「读失败」与「读到空」,
181
+ // 而两者的下一步完全不同(查文件权限 vs 修 package.json)。
182
+ // ⇒ 拆成两个值,不新增字段:**两个成因就不是一个取值**。
183
+ export type VersionSource = "embedded_env" | "package_json" | "read_failed" | "empty_value";
180
184
  export function resolveServerVersion(
181
185
  embeddedRaw: string | undefined,
182
186
  readPackageVersion: () => string,
@@ -188,9 +192,9 @@ export function resolveServerVersion(
188
192
  try {
189
193
  const v = readPackageVersion();
190
194
  if (v && v !== "?") return { version: v, source: "package_json" };
191
- return { version: "?", source: "unknown" };
195
+ return { version: "?", source: "empty_value" };
192
196
  } catch {
193
- return { version: "?", source: "unknown" };
197
+ return { version: "?", source: "read_failed" };
194
198
  }
195
199
  }
196
200
  const RESOLVED_VERSION = resolveServerVersion(process.env.ANET_EMBEDDED_COMMHUB_VERSION, () => {
@@ -3928,7 +3932,14 @@ return Bun.serve({
3928
3932
  "SELECT node_id, network_id FROM nodes WHERE node_id = ?1", nodeRef);
3929
3933
  const role = node?.network_id ? getUserNetworkRole(restAuth.userId, node.network_id) : null;
3930
3934
  if (!node || !node.network_id || (!role && !isAdmin)) {
3931
- return withCors(req, Response.json({ ok: false, error: "node_not_found" }, { status: 404 }));
3935
+ // 2026-10-31 —— 外部复核:「当一个选项对应两种修法相反的成因时,它不是选项,是问题的前半句。」
3936
+ // 这里 404 同时表示「不存在」与「不在你的可见范围」,两者修法相反(找对节点 vs 申请权限)。
3937
+ // 合并是**故意的**(否则可以枚举网络里有哪些节点),所以不能靠 hint 猜一个成因 ——
3938
+ // 只能把「这是有意合并的」写进载荷,让前端不臆断。
3939
+ return withCors(req, Response.json({
3940
+ ok: false, error: "node_not_found",
3941
+ note: "不存在,或不在你的可见范围内(两者故意同码,避免枚举)",
3942
+ }, { status: 404 }));
3932
3943
  }
3933
3944
  const row = db.get<{ request_id: string; status: string; observed_at: number | null; snapshot_json: string | null; error: string | null }>(
3934
3945
  `SELECT request_id, status, observed_at, snapshot_json, error FROM daemon_provider_snapshots
@@ -3966,7 +3977,11 @@ return Bun.serve({
3966
3977
  "SELECT node_id, network_id FROM nodes WHERE node_id = ?1", nodeRef);
3967
3978
  const role = node?.network_id ? getUserNetworkRole(restAuth.userId, node.network_id) : null;
3968
3979
  if (!node || !node.network_id || (!role && !isAdmin)) {
3969
- return withCors(req, Response.json({ ok: false, error: "node_not_found" }, { status: 404 }));
3980
+ // 同 GET:404 同时表示「不存在」与「不可见」,两者修法相反,合并是故意的 ⇒ 只说明「有意合并」
3981
+ return withCors(req, Response.json({
3982
+ ok: false, error: "node_not_found",
3983
+ note: "不存在,或不在你的可见范围内(两者故意同码,避免枚举)",
3984
+ }, { status: 404 }));
3970
3985
  }
3971
3986
  let body: any = null;
3972
3987
  try { body = await req.json(); } catch { return withCors(req, Response.json({ ok: false, error: "invalid_json" }, { status: 400 })); }