@sleep2agi/commhub-server 0.9.0-preview.280 → 0.9.0-preview.281
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 +2 -2
- package/package.json +1 -1
- package/src/anet-variant-real-daemon-http.test.ts +3 -2
- package/src/build-commit-report-http.test.ts +3 -2
- package/src/health-redaction.test.ts +8 -4
- package/src/launched-by-cli-report-http.test.ts +155 -0
- package/src/node-inbox-allowlist-http.test.ts +320 -0
- package/src/node-lifecycle-read.ts +1 -1
- package/src/node-permissions.ts +133 -2
- package/src/requirements-comment-http.test.ts +1 -1
- package/src/requirements-status-participants-http.test.ts +3 -3
- package/src/scheduled-tasks.ts +19 -3
- package/src/server.ts +76 -6
- package/src/session-project-attach-migration.test.ts +2 -1
- package/src/session-project-attach-native.test.ts +3 -1
- package/src/session-project-create-http.test.ts +3 -2
- package/src/session-project-create-native.test.ts +3 -1
- package/src/session-source-delivery.ts +5 -0
- package/src/session-source-directory-http.test.ts +5 -1
- package/src/session-source-evidence.test.ts +11 -4
- package/src/session-source-transport.ts +7 -1
- package/src/test-work-root.ts +18 -0
- package/src/tools.ts +43 -17
package/src/tools.ts
CHANGED
|
@@ -37,7 +37,7 @@ import { addAgentNetworkScope, addAgentTimelineScope, addNetworkScope, canRestWr
|
|
|
37
37
|
import { canMessageAgent, restrictedNetworkIds, RESTRICTED_MEMBER_TOOLS, type AgentRef } from "./agent-access.js";
|
|
38
38
|
import { listedToolFilter, scopeToolsList, type ToolCaller } from "./tool-audience.js";
|
|
39
39
|
import { agentBatchScheduleInterval, agentCancelSchedule, agentCreateSchedule, agentGetSchedule, agentListSchedules, agentRunScheduleNow, agentScheduleRuns, agentUpdateSchedule } from "./schedule-agent.js";
|
|
40
|
-
import { broadcastVerdict, dispatchVerdict, humanOnlyVerdict, NODE_TOOL_CLASS, nodeDecide, nodeIdentity, nodePermissionDeniedBody, recordNodeToolCall, writeVerdict, type NodeIdentity, type Verdict, toolAllowlistVerdict } from "./node-permissions.js";
|
|
40
|
+
import { broadcastVerdict, dispatchVerdict, filterBroadcastByInbox, humanOnlyVerdict, inboxDenied, inboxSenderFromAuth, NODE_TOOL_CLASS, nodeDecide, nodeIdentity, nodePermissionDeniedBody, recordNodeToolCall, writeVerdict, type InboxSender, type NodeIdentity, type Verdict, toolAllowlistVerdict } from "./node-permissions.js";
|
|
41
41
|
import { countInFlightTasks } from "./node-in-flight-tasks.js";
|
|
42
42
|
import { restrictedMemberAttachmentsDenied } from "./restricted-files.js";
|
|
43
43
|
import { errorBody } from "./requirements-errors.js";
|
|
@@ -412,6 +412,18 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
412
412
|
return singleNetworkId({ networkId: null, networkIds: getUserNetworkIds(enforceUserId) });
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
+
// 收件白名单(目标节点愿不愿意收这个发件人)。放在各工具自己的权限检查**之后**判,
|
|
416
|
+
// 这样没权限 / 没授权的调用方仍然拿到原来那条统一的错误,不能拿它探测别人设没设名单。
|
|
417
|
+
let inboxSenderCache: InboxSender | null = null;
|
|
418
|
+
const inboxSender = (): InboxSender => inboxSenderCache ??= inboxSenderFromAuth({
|
|
419
|
+
isNodeToken: callerTokenIsNetwork, tokenId: callerTokenId ?? null, boundNetworkId: enforceNetworkId ?? null,
|
|
420
|
+
userId: enforceUserId ?? null, username: callerAlias ?? null,
|
|
421
|
+
});
|
|
422
|
+
const inboxDeniedReply = (netId: string | null, target: AgentRef, tool: string) => {
|
|
423
|
+
const denial = inboxDenied(netId, target, inboxSender(), `mcp:${tool}`);
|
|
424
|
+
return denial ? { content: [{ type: "text" as const, text: JSON.stringify(denial) }] } : null;
|
|
425
|
+
};
|
|
426
|
+
|
|
415
427
|
// Check write access — delegates to the shared canRestWriteNetwork so MCP
|
|
416
428
|
// and REST cannot drift again (#517). isAdmin=false: MCP has no admin
|
|
417
429
|
// bypass today; keep behavior identical to before the extraction.
|
|
@@ -1010,6 +1022,14 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
1010
1022
|
// #2293 —— 这台机器上 OpenCode serve 的 loopback 端点(`http://127.0.0.1:PORT`)。
|
|
1011
1023
|
// 客户端「OpenCode Server」行此前只能写「端口未上报」。只收 loopback URL,不收密码。
|
|
1012
1024
|
opencode_server: z.string().max(200).optional().catch(undefined),
|
|
1025
|
+
// 2026-11-10 —— 起这份 agent-node 的 **anet CLI 版本**(`2.3.0-preview.226` 这种形态)。
|
|
1026
|
+
// 🔴 这一格必须写进 schema:zod 的 object 默认**丢掉未知键** ⇒ 不写在这里,节点
|
|
1027
|
+
// 报上来也会被静默剥掉,而 /api/nodes 的投影读到的永远是 null。这个坑在本仓库
|
|
1028
|
+
// 已经吃过两次(#3294 的 build_commit、#2293 的 opencode_catalog),都是
|
|
1029
|
+
// 「字段明明发了、hub 上永远是 null」。`.catch(undefined)` 与邻居一致:
|
|
1030
|
+
// 形状不对只丢这一格,绝不拒掉整份心跳。
|
|
1031
|
+
// ⚠️ 不要复用 `anet_version`:那是节点自身配置里的静态占位值,含义不同、还有别的代码在读。
|
|
1032
|
+
launched_by_cli_version: z.string().max(64).optional().catch(undefined),
|
|
1013
1033
|
config_update_capable: z.boolean().optional(),
|
|
1014
1034
|
peer_reply_inbox_capable: z.literal(true).optional(),
|
|
1015
1035
|
side_thread_capability: z.object({
|
|
@@ -2250,6 +2270,8 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2250
2270
|
const targetAlias = canonical.alias;
|
|
2251
2271
|
const target = resolveDeliveryTarget(targetAlias, effectiveNetId);
|
|
2252
2272
|
if (target.state === "not_found") return deliveryTargetReply(target)!;
|
|
2273
|
+
const inboxRefused = inboxDeniedReply(effectiveNetId, { alias: targetAlias, nodeId: target.session?.node_id ?? null }, "send_task");
|
|
2274
|
+
if (inboxRefused) return inboxRefused;
|
|
2253
2275
|
|
|
2254
2276
|
// Dashboard sends carry a random client_request_id inside meta. Derive
|
|
2255
2277
|
// the task primary key from authenticated scope + that request id so a
|
|
@@ -2456,6 +2478,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2456
2478
|
const targetAlias = canonical.alias;
|
|
2457
2479
|
const target = resolveDeliveryTarget(targetAlias, effectiveNetId);
|
|
2458
2480
|
if (target.state === "not_found") return deliveryTargetReply(target)!;
|
|
2481
|
+
{ const inboxRefused = inboxDeniedReply(effectiveNetId, { alias: targetAlias, nodeId: target.session?.node_id ?? null }, "send_message"); if (inboxRefused) return inboxRefused; }
|
|
2459
2482
|
// RFC-027 §2.3 inbox-enqueue lifecycle guard (PR1.1 site 2/6).
|
|
2460
2483
|
{
|
|
2461
2484
|
const lc = assertNodeActive(targetAlias, effectiveNetId ?? null);
|
|
@@ -3065,6 +3088,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
3065
3088
|
if (!["failed", "expired", "cancelled"].includes(task.status)) {
|
|
3066
3089
|
return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: `task status is ${task.status}, not retryable` }) }] };
|
|
3067
3090
|
}
|
|
3091
|
+
{ const inboxRefused = inboxDeniedReply(effectiveNetId ?? task.network_id ?? null, { alias: task.to_name, nodeId: task.to_node_id ?? null }, "retry_task"); if (inboxRefused) return inboxRefused; }
|
|
3068
3092
|
// RFC-027 §2.3 inbox-enqueue lifecycle guard (PR1.1 site 4/6).
|
|
3069
3093
|
{
|
|
3070
3094
|
const lc = assertNodeActive(task.to_name, effectiveNetId ?? task.network_id ?? null);
|
|
@@ -3154,17 +3178,17 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
3154
3178
|
// 是最大的一格:每次轮询都拉全量再自己筛。给它一个「只要这之后创建的」,
|
|
3155
3179
|
// 空窗口就回极短体,比任何提示词都省(提示词只能劝,改不了接口成本)。
|
|
3156
3180
|
created_since: z.string().max(64).optional()
|
|
3157
|
-
.describe("Only tasks created after this (ISO 8601
|
|
3181
|
+
.describe("Only tasks created after this (ISO 8601 / 'YYYY-MM-DD HH:MM:SS'), e.g. previous server_time."),
|
|
3158
3182
|
// #3119 —— stats 是全表 GROUP BY:轮询时它比任务列表本身还贵。
|
|
3159
3183
|
// #3119 —— 不给 `.default(false)`:要能区分「没传」与「显式传 false」。
|
|
3160
3184
|
// 节点令牌没传时默认省略 stats(它是给「看图的人」用的计数,轮询的节点不读它);
|
|
3161
3185
|
// 显式传 false 仍然可以要回来。用户令牌保持旧行为(默认返回 stats)。
|
|
3162
3186
|
omit_stats: z.boolean().optional()
|
|
3163
|
-
.describe("Skip per-status counts (
|
|
3187
|
+
.describe("Skip per-status counts (full scan). Default true for node tokens."),
|
|
3164
3188
|
// #3943 —— 服务端水位。调用方不传时间,Hub 用「上次给这个调用者返回的时刻」当下界,
|
|
3165
3189
|
// 返回后把水位推到本次的 server_time。客户端连时钟都不用记(也就不会因两边差几秒漏活)。
|
|
3166
3190
|
since_last: z.boolean().optional().default(false)
|
|
3167
|
-
.describe("Only tasks created since this caller's previous list_tasks (
|
|
3191
|
+
.describe("Only tasks created since this caller's previous list_tasks (server-side watermark)."),
|
|
3168
3192
|
},
|
|
3169
3193
|
async ({ alias, status, from_name, from_node_id, network_id: netId, before_created_at, before_task_id, durable_cursor, durable_terminal_cursor, after_terminal_seq, limit, created_since, omit_stats, since_last }) => {
|
|
3170
3194
|
const readScope = resolveReadScope(netId);
|
|
@@ -3421,6 +3445,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
3421
3445
|
const reassignedAlias = canonical.alias;
|
|
3422
3446
|
const target = resolveDeliveryTarget(reassignedAlias, effectiveNetId ?? task.network_id ?? null);
|
|
3423
3447
|
const newNodeId = target.state === "not_found" ? null : (target.session?.node_id ?? null);
|
|
3448
|
+
{ const inboxRefused = inboxDeniedReply(effectiveNetId ?? task.network_id ?? null, { alias: reassignedAlias, nodeId: newNodeId }, "reassign_task"); if (inboxRefused) return inboxRefused; }
|
|
3424
3449
|
// RFC-027 §2.3 inbox-enqueue lifecycle guard (PR1.1 site 5/6).
|
|
3425
3450
|
{
|
|
3426
3451
|
const lc = assertNodeActive(reassignedAlias, effectiveNetId ?? task.network_id ?? null);
|
|
@@ -3636,7 +3661,8 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
3636
3661
|
if (filter_server) { sql += " AND server = ?"; params.push(filter_server); }
|
|
3637
3662
|
if (filter_status) { sql += " AND status = ?"; params.push(filter_status); }
|
|
3638
3663
|
|
|
3639
|
-
const
|
|
3664
|
+
const allTargets = db.all<{ alias: string; node_id: string | null; network_id: string | null }>(sql, ...params);
|
|
3665
|
+
const { allowed: targets, skipped: inboxSkipped } = filterBroadcastByInbox(allTargets, effectiveNetId, inboxSender(), "mcp:broadcast");
|
|
3640
3666
|
// #2721 —— 分批入库 + 批间让出(见 broadcast-fanout.ts 顶部:一条广播 384 行曾把 Hub
|
|
3641
3667
|
// 打成 143.9 秒的 timer 饥饿)。语义不变:仍然逐个收件人一行、仍然 best-effort 跳过非 active。
|
|
3642
3668
|
const { ids } = await enqueueBroadcast(targets, message, "hub", effectiveNetId, {
|
|
@@ -3649,7 +3675,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
3649
3675
|
content: [
|
|
3650
3676
|
{
|
|
3651
3677
|
type: "text" as const,
|
|
3652
|
-
text: JSON.stringify({ ok: true, recipients: ids.length, message_ids: ids }),
|
|
3678
|
+
text: JSON.stringify({ ok: true, recipients: ids.length, message_ids: ids, ...(inboxSkipped.length ? { inbox_skipped: inboxSkipped } : {}) }),
|
|
3653
3679
|
},
|
|
3654
3680
|
],
|
|
3655
3681
|
};
|
|
@@ -7116,7 +7142,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7116
7142
|
server.registerTool(
|
|
7117
7143
|
"read_opencode_catalog",
|
|
7118
7144
|
{
|
|
7119
|
-
description: "Queue an owned child’s
|
|
7145
|
+
description: "Queue an owned child’s V2 catalog read. pending = authorized and held in memory, not a snapshot or daemon receipt. Starts no server. URL/auth/directory/settings/headers/body rejected.",
|
|
7120
7146
|
inputSchema: z.object({
|
|
7121
7147
|
daemon_node_id: z.string().min(1).max(200),
|
|
7122
7148
|
node_id: z.string().min(1).max(200),
|
|
@@ -7174,7 +7200,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7174
7200
|
server.registerTool(
|
|
7175
7201
|
"ack_opencode_catalog",
|
|
7176
7202
|
{
|
|
7177
|
-
description: "Daemon stores a whitelisted V2 catalog snapshot or error code. Extra fields
|
|
7203
|
+
description: "Daemon stores a whitelisted V2 catalog snapshot or error code. Extra fields rejected; a stored failure is status failed, not a transport error.",
|
|
7178
7204
|
inputSchema: opencodeCatalogAckSchema as any,
|
|
7179
7205
|
},
|
|
7180
7206
|
async (args: unknown) => {
|
|
@@ -7262,19 +7288,19 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7262
7288
|
parent_id: z.string().max(200).optional().describe("children of this requirement ('none' = top level)"),
|
|
7263
7289
|
department_id: z.string().max(64).optional().describe("owner (or its Agent's owner) in this department or below"),
|
|
7264
7290
|
top_level: z.boolean().optional(), q: z.string().max(200).optional(),
|
|
7265
|
-
overdue: z.boolean().optional().describe("true = open
|
|
7266
|
-
due_within_days: z.number().int().min(0).max(365).optional().describe("open
|
|
7291
|
+
overdue: z.boolean().optional().describe("true = open and past due (before today, Asia/Shanghai); false = the rest"),
|
|
7292
|
+
due_within_days: z.number().int().min(0).max(365).optional().describe("open, not overdue, due by end of today + N days (0 = today)"),
|
|
7267
7293
|
limit: z.number().int().min(1).max(1000).optional().describe(`page size, default ${REQ_LIST_MCP_DEFAULT_LIMIT}`),
|
|
7268
7294
|
cursor: z.string().max(600).optional().describe("next_cursor from the previous page"),
|
|
7269
|
-
view: z.enum(["full", "summary"]).optional().describe("
|
|
7270
|
-
changes: z.boolean().optional().describe("with updated_since:
|
|
7271
|
-
include_last_event: z.boolean().optional().describe("
|
|
7295
|
+
view: z.enum(["full", "summary"]).optional().describe("summary (default; no bodies) or full"),
|
|
7296
|
+
changes: z.boolean().optional().describe("with updated_since: tasks changed since then, +deleted ids, +server_time (+newer events with include_last_event)"),
|
|
7297
|
+
include_last_event: z.boolean().optional().describe("true adds last_event per row (~150 B: type/field/actor/at/summary; null if none)"),
|
|
7272
7298
|
};
|
|
7273
7299
|
const reqListKeys = Object.keys(reqListShape);
|
|
7274
7300
|
server.registerTool(
|
|
7275
7301
|
"requirements_list",
|
|
7276
7302
|
{
|
|
7277
|
-
description: `
|
|
7303
|
+
description: `Tasks, newest first. Default ${REQ_LIST_MCP_DEFAULT_LIMIT}/page, view=summary (no bodies; has_description, checklist_count; ~0.5 KB/task); has_more ⇒ cursor=next_cursor. Full text: requirements_get or view=full (limit ≤1000). Filters: seq (#N), status, project_id ('none'), owner/agent_owner ('user:<id>'/'node:<id>'/'none'), tag, ISO updated_since, overdue/due_within_days (open), external_ref, parent_id/top_level, department_id (incl. sub-depts), include_archived. q: AND over title/description/people/project/tags. Rows have children {total,done}; include_last_event adds the newest event. changes=true + updated_since: changed tasks incl. archived, deleted ids, server_time. Unknown params → -32602.`,
|
|
7278
7304
|
// Strict: registerTool honours a constructed object's unknownKeys (server.tool() would strip them silently).
|
|
7279
7305
|
inputSchema: z.strictObject(reqListShape, {
|
|
7280
7306
|
error: (iss: any) => iss.code === "unrecognized_keys"
|
|
@@ -7301,7 +7327,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7301
7327
|
// #473 —— Agent 查人:紧凑通讯录(requirements-people.ts)。严格参数,同 requirements_list(#471)。
|
|
7302
7328
|
const reqPeopleShape = {
|
|
7303
7329
|
network_id: z.string().max(200).optional(),
|
|
7304
|
-
q: z.string().min(1).max(100).optional().describe("case-insensitive substring
|
|
7330
|
+
q: z.string().min(1).max(100).optional().describe("case-insensitive substring: username, display name, department, alias"),
|
|
7305
7331
|
limit: z.number().int().min(1).max(200).optional().describe("people per page, default 50"),
|
|
7306
7332
|
offset: z.number().int().min(0).optional().describe("next_offset from the previous page"),
|
|
7307
7333
|
};
|
|
@@ -7309,7 +7335,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7309
7335
|
server.registerTool(
|
|
7310
7336
|
"requirements_people",
|
|
7311
7337
|
{
|
|
7312
|
-
description: "
|
|
7338
|
+
description: "People and their Agents, for task fields. Rows: user_id, username, display_name (\"\" if unset), role, department {id,name}|null, agents [{node_id,alias}]; agents_without_owner on the first page only. q: case-insensitive substring of username/display name/department/alias. 50/page, limit ≤200; has_more ⇒ next_offset. Ungranted Agents omitted. Person fields take these IDs or {kind:'user',username}/{kind:'node',alias}.",
|
|
7313
7339
|
inputSchema: z.strictObject(reqPeopleShape, {
|
|
7314
7340
|
error: (iss: any) => iss.code === "unrecognized_keys"
|
|
7315
7341
|
? `unknown parameter(s): ${(iss.keys ?? []).join(", ")}; valid parameters: ${reqPeopleKeys.join(", ")}`
|
|
@@ -7436,7 +7462,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
7436
7462
|
server.registerTool(
|
|
7437
7463
|
"requirements_events",
|
|
7438
7464
|
{
|
|
7439
|
-
description: `Task activity (动态), newest first: field changes (who, when, old → new) and comments (kind=comment, new.text; add via requirements_comment).
|
|
7465
|
+
description: `Task activity (动态), newest first: field changes (who, when, old → new) and comments (kind=comment, new.text; add via requirements_comment). requirement_id (req_… or #N): default 200; network-wide: default ${REQ_EVENTS_NETWORK_DEFAULT_LIMIT}. limit ≤500; older: cursor=next_cursor; next since=server_time. Visibility as requirements_list. Unknown params → -32602.`,
|
|
7440
7466
|
inputSchema: z.strictObject(reqEventsShape, {
|
|
7441
7467
|
error: (iss: any) => iss.code === "unrecognized_keys"
|
|
7442
7468
|
? `unknown parameter(s): ${(iss.keys ?? []).join(", ")}; valid parameters: ${reqEventsKeys.join(", ")}`
|