@sleep2agi/commhub-server 0.9.0-preview.253 → 0.9.0-preview.254
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 +4 -3
- package/package.json +1 -1
- package/src/health-anon-readers.ts +5 -0
- package/src/health-redaction.test.ts +19 -0
- package/src/server.ts +27 -2
- package/src/tool-audience-http.test.ts +18 -0
- package/src/tools.ts +1 -1
package/build-info.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "8955cf5352f9d50467c5c16a84f384fc60ce3b40",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"built_at": "2026-10-
|
|
6
|
-
"source": "git"
|
|
5
|
+
"built_at": "2026-10-31T22:31:27.402Z",
|
|
6
|
+
"source": "git",
|
|
7
|
+
"event_sha": "3cd0931c7c1d45d5a1050613ea13fd68c622f162"
|
|
7
8
|
}
|
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.254",
|
|
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",
|
|
@@ -45,6 +45,11 @@ export const PUBLIC_HEALTH_KEY_READERS: Readonly<Record<string, AnonReaderEntry>
|
|
|
45
45
|
mcp_inflight: { reader: "operator", why: "运维手工 curl 看实时在途数;仓内无代码读,仅注释引用过生产数值" },
|
|
46
46
|
mcp_inflight_peak: { reader: "operator", why: "运维手工看**峰值**,用于判断重连风暴是否发生过;无程序读者" },
|
|
47
47
|
event_loop: { reader: "operator", why: "停顿指标只出现在历史发布报告里,仓内无代码读;靠人看" },
|
|
48
|
+
// #3271 —— 我原来把「观察这条闸有没有 fire」写成了 /health.counters.…,
|
|
49
|
+
// 而 counters 不在匿名投影里 ⇒ 没有 token 的读者(包括当时的我)看不到它。
|
|
50
|
+
// ⇒ 聚合走匿名投影;by_node 仍是拓扑,不给。
|
|
51
|
+
task_expiries_never_consumed_total: { reader: "operator", why: "运维/agent 判断「派单硬闸有没有真的 fire 过」;只有总数,不含节点名" },
|
|
52
|
+
counters_since: { reader: "operator", why: "上一条的窗口起点:计数器随重启归零,只有总数时「刚重启」与「一次都没发生」同值" },
|
|
48
53
|
auth: { reader: "cli", why: "客户端据此决定登录方式" },
|
|
49
54
|
security: { reader: "cli", why: "客户端据此提示是否需要 TLS/密钥配置" },
|
|
50
55
|
tmux: { reader: "cli", why: "共存 TUI 的前置检查" },
|
|
@@ -247,6 +247,25 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
247
247
|
expect(after.counters.task_rejections.total).toBe(before.counters.task_rejections.total);
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
+
// #3271 —— 「派单硬闸有没有真的 fire 过」必须是**匿名可读的聚合**。
|
|
251
|
+
// 我第一版把它只放在鉴权投影里(counters.task_expiries_never_consumed),
|
|
252
|
+
// 于是没有 token 的读者——包括当时的我——看不到它,也就无法验证它有没有 fire。
|
|
253
|
+
// 这两条断言把「公开的那一半」钉住:**给总数与窗口,不给 by_node**(节点名是拓扑)。
|
|
254
|
+
test("#3271 派单硬闸的读数:匿名给总数+窗口,by_node 留在鉴权投影", async () => {
|
|
255
|
+
const { PUBLIC_HEALTH_KEYS } = await import("./server.js");
|
|
256
|
+
expect(PUBLIC_HEALTH_KEYS.has("task_expiries_never_consumed_total")).toBe(true);
|
|
257
|
+
expect(PUBLIC_HEALTH_KEYS.has("counters_since")).toBe(true);
|
|
258
|
+
// by_node / last_at 不在公开白名单里 —— 拓扑不外泄(这条是**否定断言**,所以要配上面两条肯定断言)
|
|
259
|
+
expect(PUBLIC_HEALTH_KEYS.has("task_expiries_never_consumed")).toBe(false);
|
|
260
|
+
expect(PUBLIC_HEALTH_KEYS.has("by_node")).toBe(false);
|
|
261
|
+
const { neverConsumedExpiryCounters, noteNeverConsumedExpiry } = await import("./expiry-counters.js");
|
|
262
|
+
noteNeverConsumedExpiry("unread-probe-node");
|
|
263
|
+
const agg = neverConsumedExpiryCounters();
|
|
264
|
+
expect(agg.total).toBeGreaterThan(0);
|
|
265
|
+
expect(typeof agg.since).toBe("string");
|
|
266
|
+
expect(Object.keys(agg.by_node)).toContain("unread-probe-node");
|
|
267
|
+
});
|
|
268
|
+
|
|
250
269
|
// 2026-10-31 —— 出口清单里「before_route_table」那一行原本 pinned_by 为空(= 缺口)。
|
|
251
270
|
// 补上它的钉:未匹配的 /api/* 在路由表之前就 404,**不经过 handler,也不计数**。
|
|
252
271
|
// 这一条同时是「清单要能被一次坏输入打出来」的实例(对方那句)。
|
package/src/server.ts
CHANGED
|
@@ -1054,6 +1054,9 @@ export const PUBLIC_HEALTH_KEYS: ReadonlySet<string> = new Set([
|
|
|
1054
1054
|
"ok", "status", "status_reasons", "version", "version_source", "version_role", "api_version", "transport", "uptime", "startedAt",
|
|
1055
1055
|
// 规模与健康度聚合(不含拓扑明细)
|
|
1056
1056
|
"sessions_count", "sse_connections", "mcp_inflight", "mcp_inflight_peak",
|
|
1057
|
+
// #3271 —— 「到死没被取走」的**总数**(聚合,不含 by_node:节点名是拓扑)。
|
|
1058
|
+
// 配 counters_since 一起读:只有总数时,「进程刚重启」与「一次都没发生」同值。
|
|
1059
|
+
"task_expiries_never_consumed_total", "counters_since",
|
|
1057
1060
|
// 事件循环停顿是**一个对象**(event_loop: {max_gap_ms, recent_stalls,…}),
|
|
1058
1061
|
// 不是我原先以为的三个顶层键 —— 死条目测试当场抓到了这一点。
|
|
1059
1062
|
"event_loop",
|
|
@@ -1270,6 +1273,9 @@ export const HEALTH_FIELD_META: Readonly<Record<string, HealthFieldMeta>> = {
|
|
|
1270
1273
|
mcp_inflight: { class: "gauge", granularity: "level" },
|
|
1271
1274
|
mcp_inflight_peak: { class: "gauge", granularity: "cumulative" },
|
|
1272
1275
|
event_loop: { class: "gauge", granularity: "cumulative" },
|
|
1276
|
+
// #3271 —— 聚合计数:规模/强度,不含拓扑(by_node 留在鉴权投影里)。
|
|
1277
|
+
task_expiries_never_consumed_total: { class: "gauge", granularity: "cumulative" },
|
|
1278
|
+
counters_since: { class: "gauge", granularity: "label" },
|
|
1273
1279
|
auth: { class: "gauge", granularity: "label" },
|
|
1274
1280
|
security: { class: "gauge", granularity: "label" },
|
|
1275
1281
|
tmux: { class: "gauge", granularity: "label" },
|
|
@@ -3835,6 +3841,14 @@ return Bun.serve({
|
|
|
3835
3841
|
// #3271 —— 「到死都没被取走」按节点分桶。窗口用同一个 since。
|
|
3836
3842
|
task_expiries_never_consumed: neverConsumedExpiryCounters(),
|
|
3837
3843
|
},
|
|
3844
|
+
// 🔴 2026-10-31 —— 上面那个 counters 对象**不在匿名投影里**(PUBLIC_HEALTH_KEYS)。
|
|
3845
|
+
// 而 #3271 交付时我把「观察它有没有 fire」写成了 `/health.counters.…` ——
|
|
3846
|
+
// 没有 token 的读者看不到它 ⇒ 那条 must-fire 判据**我自己也没法验**。
|
|
3847
|
+
// ⇒ 聚合值走匿名投影:**只给总数与窗口,不给 by_node**(节点名是拓扑,计数不是)。
|
|
3848
|
+
// 这也与 sessions_count 同一条取舍:规模可以公开,明细不行。
|
|
3849
|
+
task_expiries_never_consumed_total: neverConsumedExpiryCounters().total,
|
|
3850
|
+
// 窗口的另一端:计数器随进程重启归零,而「归零」与「没有发生」同值 ⇒ 必须配起点。
|
|
3851
|
+
counters_since: startedAtIso,
|
|
3838
3852
|
// #496 — public, stable capability data. Dashboard upload proxies
|
|
3839
3853
|
// need the Hub's real limits before opening a streaming request;
|
|
3840
3854
|
// duplicating these constants client-side creates a silent
|
|
@@ -4088,7 +4102,16 @@ return Bun.serve({
|
|
|
4088
4102
|
state,
|
|
4089
4103
|
selection,
|
|
4090
4104
|
revision: (selection as any)?.expected_revision ?? null,
|
|
4091
|
-
|
|
4105
|
+
// #1650 —— 这一列是 **INTEGER(ms epoch)**,不是 hub 那种「不带时区标记的 TEXT」。
|
|
4106
|
+
// 棘轮看见「把这一列直接塞进 Date 构造器」会拦下它(形状相同、类型不同),
|
|
4107
|
+
// 而**照它的建议改成 parseHubTimestamp 就是错的**:那函数只吃字符串,数字一律返回 null,
|
|
4108
|
+
// 于是「有观测时间」会静默变成「从没观测过」。
|
|
4109
|
+
// ⇒ 正解是把单位写进名字,让形状自己说清它是 ms。
|
|
4110
|
+
observed_at: (() => {
|
|
4111
|
+
const observedAtMs = row?.observed_at ?? null;
|
|
4112
|
+
// 与原意一致:0 / 缺失都当「没有」。
|
|
4113
|
+
return observedAtMs ? new Date(observedAtMs).toISOString() : null;
|
|
4114
|
+
})(),
|
|
4092
4115
|
...(state === "failed" ? { error: row?.error ?? null } : {}),
|
|
4093
4116
|
...(state === "never_switched"
|
|
4094
4117
|
// 2026-10-31 —— **hint 必须自带动作**(外部复核:互斥选项若需要不同动作才能区分,
|
|
@@ -4154,7 +4177,9 @@ return Bun.serve({
|
|
|
4154
4177
|
request_id: applied.request_id,
|
|
4155
4178
|
state: "pending",
|
|
4156
4179
|
before, // 切换前(可能为 null = 从未切换过)
|
|
4157
|
-
expires_at
|
|
4180
|
+
// #1650 —— 同上:`expires_at` 这里是 **number(ms epoch)**,不是 TEXT 列。
|
|
4181
|
+
// 放进 `expiresAtMs` 而不是直接塞进 new Date(...):名字说明单位,棘轮也就不会误拦。
|
|
4182
|
+
expires_at: (() => { const expiresAtMs = applied.expires_at; return new Date(expiresAtMs).toISOString(); })(),
|
|
4158
4183
|
hint: "已排队;用 GET 同一路由回读 state=applied 才算生效(pending 不等于生效)",
|
|
4159
4184
|
}, { status: 202 }));
|
|
4160
4185
|
}
|
|
@@ -217,7 +217,16 @@ describe("bytes per role (#476 ceilings stay meaningful per role)", () => {
|
|
|
217
217
|
// ② 砍掉一批冗长描述里重复的解释性从句(每条约 20–100 B,信息点全部保留)。
|
|
218
218
|
// 实测(含新工具):all 97 / 86,020 B;node 64 / 64,464 B;user 64 / 59,680 B —— 三个上限**一个都没动**。
|
|
219
219
|
// 下次再加工具,请先合并动作或砍描述,不要直接改这三个数。
|
|
220
|
+
//
|
|
221
|
+
// #3294(2026-10-31):report_status 新增 `build_commit`(节点侧的字节标识)。
|
|
222
|
+
// 第一次跑就撞上限:node 64,540 > 64,500(+40 B,全部来自那一句 describe)。
|
|
223
|
+
// 按上面那条规矩**不抬上限**,把描述从
|
|
224
|
+
// "Build commit (hex, 7–40), from the packaged build-info.json"(63 字符)
|
|
225
|
+
// 压到 "Build commit (hex)"(19 字符)⇒ node 64,497 B,余量 **3 B**。
|
|
226
|
+
// ⚠️ 3 B 不是「刚好」,是**陷阱**:下一个人加一个字段名就会撞墙,而这条测试的失败会
|
|
227
|
+
// 读成「谁又把描述写长了」。所以下面把余量打出来,余量低于 100 B 时大声说一句。
|
|
220
228
|
const CEILINGS = { node: 64_500, user: 60_500, all: 86_500 } as const;
|
|
229
|
+
const MARGIN_FLOOR = 100;
|
|
221
230
|
test("node / user / all", async () => {
|
|
222
231
|
const node = await listTools(T.node_normal);
|
|
223
232
|
const user = await listTools(T.owner);
|
|
@@ -226,5 +235,14 @@ describe("bytes per role (#476 ceilings stay meaningful per role)", () => {
|
|
|
226
235
|
expect(node.bytes).toBeLessThanOrEqual(CEILINGS.node);
|
|
227
236
|
expect(user.bytes).toBeLessThanOrEqual(CEILINGS.user);
|
|
228
237
|
expect(all.bytes).toBeLessThanOrEqual(CEILINGS.all);
|
|
238
|
+
// 余量也是读数:只报「没超」时,余量从 400 B 掉到 3 B 这件事是看不见的,
|
|
239
|
+
// 下一个人撞墙时才知道上限早就被吃干了。
|
|
240
|
+
const margins = { node: CEILINGS.node - node.bytes, user: CEILINGS.user - user.bytes, all: CEILINGS.all - all.bytes };
|
|
241
|
+
console.log(`margin B — node ${margins.node}; user ${margins.user}; all ${margins.all}`);
|
|
242
|
+
for (const [role, m] of Object.entries(margins)) {
|
|
243
|
+
if (m < MARGIN_FLOOR) {
|
|
244
|
+
console.log(`::warning::${role} 的 tools/list 余量只剩 ${m} B(< ${MARGIN_FLOOR})—— 下一次加字段会先撞这里,请先砍描述或合并动作`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
229
247
|
});
|
|
230
248
|
});
|
package/src/tools.ts
CHANGED
|
@@ -886,7 +886,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
886
886
|
version: z.string().max(100).optional().describe("Agent version"),
|
|
887
887
|
// 2026-10-31 —— #3294:**字节标识**。40 位 hex;也接受 12 位前缀(CI 里截过的那种)。
|
|
888
888
|
// 与 version 分开:version 是标签,build_commit 是「哪一份字节」。
|
|
889
|
-
build_commit: z.string().regex(/^[0-9a-f]{7,40}$/).optional().describe("Build commit (hex
|
|
889
|
+
build_commit: z.string().regex(/^[0-9a-f]{7,40}$/).optional().describe("Build commit (hex)"),
|
|
890
890
|
tmux_name: z.string().max(200).optional().describe("tmux session name"),
|
|
891
891
|
// V2 fields
|
|
892
892
|
node_id: z.string().max(200).optional().describe("Stable node identifier"),
|