weacpx 0.4.0-beta.1 → 0.4.0-beta.2

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.
@@ -428,26 +428,32 @@ function formatToolCallEvent(update, sessionUpdate) {
428
428
  if (title.length === 0)
429
429
  return null;
430
430
  const emoji = KIND_EMOJI[kind] ?? "\uD83D\uDD27";
431
- const command = getToolDisplayCommand(update);
432
- if (command) {
433
- return `${emoji} ${truncateToolDisplay(command)}`;
434
- }
435
- if (sessionUpdate === "tool_call_update" || isGenericToolTitle(kind, title))
431
+ const inputSummary = summarizeToolInput(update.rawInput);
432
+ const status = readString(update, "status");
433
+ if (!inputSummary && isGenericToolTitle(kind, title))
436
434
  return null;
437
- return `${emoji} ${title}`;
435
+ const summaryText = inputSummary ? `: ${truncateToolDisplay(inputSummary)}` : "";
436
+ const statusText = status ? ` (${status})` : "";
437
+ return `${emoji} ${title}${statusText}${summaryText}`;
438
438
  }
439
- function getToolDisplayCommand(update) {
440
- if (!update)
441
- return null;
442
- const command = update.rawInput?.command;
443
- if (typeof command === "string" && command.length > 0) {
444
- return command;
439
+ function summarizeToolInput(rawInput) {
440
+ if (rawInput == null)
441
+ return;
442
+ if (typeof rawInput === "string" || typeof rawInput === "number" || typeof rawInput === "boolean") {
443
+ return String(rawInput);
445
444
  }
446
- const parsedCmd = update.rawInput?.parsed_cmd;
447
- if (parsedCmd && parsedCmd.length > 0) {
445
+ if (!isRecord(rawInput))
446
+ return;
447
+ const command = readFirstString(rawInput, ["command", "cmd", "program"]);
448
+ const args = readFirstStringArray(rawInput, ["args", "arguments"]);
449
+ if (command) {
450
+ return [command, ...args ?? []].join(" ");
451
+ }
452
+ const parsedCmd = rawInput.parsed_cmd;
453
+ if (Array.isArray(parsedCmd) && parsedCmd.length > 0) {
448
454
  const parts = [];
449
455
  for (const entry of parsedCmd) {
450
- if (entry && typeof entry.cmd === "string" && entry.cmd.length > 0) {
456
+ if (isRecord(entry) && typeof entry.cmd === "string" && entry.cmd.length > 0) {
451
457
  parts.push(entry.cmd);
452
458
  }
453
459
  }
@@ -455,7 +461,51 @@ function getToolDisplayCommand(update) {
455
461
  return parts.join(" ");
456
462
  }
457
463
  }
458
- return null;
464
+ return readFirstString(rawInput, [
465
+ "path",
466
+ "file",
467
+ "filePath",
468
+ "filepath",
469
+ "target",
470
+ "uri",
471
+ "url",
472
+ "query",
473
+ "pattern",
474
+ "text",
475
+ "search",
476
+ "name",
477
+ "description"
478
+ ]);
479
+ }
480
+ function readFirstString(record, keys) {
481
+ for (const key of keys) {
482
+ const value = record[key];
483
+ if (typeof value === "string" && value.trim().length > 0) {
484
+ return value.trim();
485
+ }
486
+ }
487
+ return;
488
+ }
489
+ function readFirstStringArray(record, keys) {
490
+ for (const key of keys) {
491
+ const value = record[key];
492
+ if (!Array.isArray(value))
493
+ continue;
494
+ const entries = value.map((entry) => typeof entry === "string" && entry.trim().length > 0 ? entry.trim() : undefined).filter((entry) => entry !== undefined);
495
+ if (entries.length > 0) {
496
+ return entries;
497
+ }
498
+ }
499
+ return;
500
+ }
501
+ function isRecord(value) {
502
+ return typeof value === "object" && value !== null && !Array.isArray(value);
503
+ }
504
+ function readString(rawInput, key) {
505
+ if (!isRecord(rawInput))
506
+ return;
507
+ const value = rawInput[key];
508
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
459
509
  }
460
510
  function truncateToolDisplay(text) {
461
511
  return text.length > 60 ? `${text.slice(0, 57)}...` : text;
@@ -1072,7 +1122,7 @@ class BridgeRuntime {
1072
1122
  input.name,
1073
1123
  ...structuredPrompt ? ["--file", structuredPrompt.filePath] : [input.text]
1074
1124
  ]));
1075
- const formatToolCalls = input.replyMode === "verbose";
1125
+ const formatToolCalls = (input.replyMode ?? "verbose") === "verbose";
1076
1126
  try {
1077
1127
  const result = onEvent ? await this.runPromptCommand(spawnSpec.command, spawnSpec.args, onEvent, { formatToolCalls }) : await this.run(spawnSpec.command, spawnSpec.args);
1078
1128
  return { text: getPromptText(result) };
package/dist/cli.js CHANGED
@@ -9477,211 +9477,6 @@ function readVersion(moduleUrl = import.meta.url) {
9477
9477
  var PACKAGE_NAME = "weacpx";
9478
9478
  var init_version = () => {};
9479
9479
 
9480
- // src/formatting/render-text.ts
9481
- function renderAgents(config2) {
9482
- const names = Object.keys(config2.agents);
9483
- if (names.length === 0) {
9484
- return "还没有注册任何 Agent。";
9485
- }
9486
- return ["已注册的 Agent:", ...names.map((name) => `- ${name}`)].join(`
9487
- `);
9488
- }
9489
- function renderWorkspaces(config2) {
9490
- const names = Object.entries(config2.workspaces);
9491
- if (names.length === 0) {
9492
- return "还没有注册任何工作区。";
9493
- }
9494
- return ["已注册的工作区:", ...names.map(([name, workspace]) => `- ${name}: ${workspace.cwd}`)].join(`
9495
- `);
9496
- }
9497
- function renderOrchestrationUnavailable() {
9498
- return "当前未启用任务编排服务。";
9499
- }
9500
- function renderDelegateSuccess(taskId, workerSession) {
9501
- return [`已创建委派任务「${taskId}」`, `worker 会话:${workerSession}`].join(`
9502
- `);
9503
- }
9504
- function renderGroupCreated(group) {
9505
- return [`已创建任务组「${group.groupId}」`, `- 标题:${group.title}`].join(`
9506
- `);
9507
- }
9508
- function renderGroupList(groups) {
9509
- if (groups.length === 0) {
9510
- return "当前协调会话下还没有任务组。";
9511
- }
9512
- return ["当前协调会话的任务组:", ...groups.map((group) => renderGroupListItem(group))].join(`
9513
- `);
9514
- }
9515
- function renderGroupSummary(summary) {
9516
- const { group, tasks } = summary;
9517
- const lines = [
9518
- `任务组「${group.groupId}」`,
9519
- `- 标题:${group.title}`,
9520
- `- 协调会话:${group.coordinatorSession}`,
9521
- `- 总任务数:${summary.totalTasks}`,
9522
- `- 待确认:${summary.pendingApprovalTasks}`,
9523
- `- 运行中:${summary.runningTasks}`,
9524
- `- 已完成:${summary.completedTasks}`,
9525
- `- 已失败:${summary.failedTasks}`,
9526
- `- 已取消:${summary.cancelledTasks}`,
9527
- `- 是否终态:${summary.terminal ? "是" : "否"}`
9528
- ];
9529
- if (group.injectionPending !== undefined) {
9530
- lines.push(`- 注入待处理:${group.injectionPending ? "是" : "否"}`);
9531
- }
9532
- if (group.injectionAppliedAt) {
9533
- lines.push(`- 注入完成时间:${group.injectionAppliedAt}`);
9534
- }
9535
- if (group.lastInjectionError) {
9536
- lines.push(`- 最近注入错误:${group.lastInjectionError}`);
9537
- }
9538
- if (tasks.length > 0) {
9539
- lines.push("- 成员:");
9540
- for (const task of tasks) {
9541
- lines.push(` - ${task.taskId} [${task.status}] ${task.targetAgent}`);
9542
- }
9543
- }
9544
- return lines.join(`
9545
- `);
9546
- }
9547
- function renderGroupCancelSuccess(input) {
9548
- return [
9549
- `任务组「${input.summary.group.groupId}」已发起取消`,
9550
- `- 已请求取消:${input.cancelledTaskIds.length}`,
9551
- `- 已跳过终态任务:${input.skippedTaskIds.length}`
9552
- ].join(`
9553
- `);
9554
- }
9555
- function renderTaskList(tasks) {
9556
- if (tasks.length === 0) {
9557
- return "当前协调会话下还没有任务。";
9558
- }
9559
- return ["当前协调会话的任务:", ...tasks.map((task) => renderTaskListItem(task))].join(`
9560
- `);
9561
- }
9562
- function renderTaskSummary(task) {
9563
- const header = [
9564
- `任务「${task.taskId}」`,
9565
- `- 状态:${task.status}`,
9566
- `- 协调会话:${task.coordinatorSession}`,
9567
- `- worker 会话:${task.workerSession ?? "未分配"}`,
9568
- `- 目标 Agent:${task.targetAgent}`
9569
- ];
9570
- if (task.role)
9571
- header.push(`- 角色:${task.role}`);
9572
- if (task.groupId)
9573
- header.push(`- 任务组:${task.groupId}`);
9574
- if (task.status === "needs_confirmation") {
9575
- header.push(`- 来源:${task.sourceKind} / ${task.sourceHandle}${task.role ? ` / ${task.role}` : ""}`);
9576
- }
9577
- header.push(`- 任务:${task.task}`);
9578
- if (task.summary.trim().length > 0)
9579
- header.push(`- 摘要:${task.summary}`);
9580
- if (task.resultText.trim().length > 0)
9581
- header.push(`- 结果:${task.resultText}`);
9582
- const events = [];
9583
- events.push({ at: task.createdAt, event: "created" });
9584
- if (task.workerSession && task.status !== "needs_confirmation") {
9585
- events.push({ at: task.createdAt, event: "dispatched", detail: task.workerSession });
9586
- }
9587
- if (task.lastProgressAt)
9588
- events.push({ at: task.lastProgressAt, event: "last_progress" });
9589
- if (task.cancelRequestedAt)
9590
- events.push({ at: task.cancelRequestedAt, event: "cancel_requested" });
9591
- if (task.cancelCompletedAt)
9592
- events.push({ at: task.cancelCompletedAt, event: "cancel_completed" });
9593
- if (task.lastCancelError)
9594
- events.push({ at: task.updatedAt, event: "cancel_failed", detail: task.lastCancelError });
9595
- if (task.status === "completed")
9596
- events.push({ at: task.updatedAt, event: "completed" });
9597
- if (task.status === "failed")
9598
- events.push({ at: task.updatedAt, event: "failed" });
9599
- if (task.noticeSentAt)
9600
- events.push({ at: task.noticeSentAt, event: "notice_sent", detail: task.deliveryAccountId });
9601
- if (task.lastNoticeError)
9602
- events.push({ at: task.updatedAt, event: "notice_failed", detail: task.lastNoticeError });
9603
- if (task.injectionAppliedAt)
9604
- events.push({ at: task.injectionAppliedAt, event: "injection_applied" });
9605
- if (task.lastInjectionError)
9606
- events.push({ at: task.updatedAt, event: "injection_failed", detail: task.lastInjectionError });
9607
- events.sort((a, b) => a.at.localeCompare(b.at));
9608
- const timeline = events.length > 0 ? ["- 时间线:", ...events.map((e) => ` - [${e.at}] ${e.event}${e.detail ? `: ${e.detail}` : ""}`)] : [];
9609
- return [...header, ...timeline].join(`
9610
- `);
9611
- }
9612
- function renderTaskCancelSuccess(task) {
9613
- if (task.status === "completed" || task.status === "failed" || task.status === "cancelled") {
9614
- return [`任务「${task.taskId}」已结束。`, `- 当前状态:${task.status}`].join(`
9615
- `);
9616
- }
9617
- if (task.cancelRequestedAt) {
9618
- return [`已请求取消任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
9619
- `);
9620
- }
9621
- return [`任务「${task.taskId}」已取消。`, `- 当前状态:${task.status}`].join(`
9622
- `);
9623
- }
9624
- function renderTaskApprovalSuccess(task) {
9625
- return [`已批准任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
9626
- `);
9627
- }
9628
- function renderTaskRejectionSuccess(task) {
9629
- return [`已拒绝任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
9630
- `);
9631
- }
9632
- function renderTaskConfirmationUnavailable(task) {
9633
- return [`任务「${task.taskId}」当前不是待确认状态。`, `- 当前状态:${task.status}`].join(`
9634
- `);
9635
- }
9636
- function renderTasksCleanResult(removedTasks, removedBindings) {
9637
- if (removedTasks === 0 && removedBindings === 0) {
9638
- return "当前协调会话下没有可清理的任务。";
9639
- }
9640
- const lines = [];
9641
- if (removedTasks > 0) {
9642
- lines.push(`已清理 ${removedTasks} 个已结束的任务。`);
9643
- }
9644
- if (removedBindings > 0) {
9645
- lines.push(`已释放 ${removedBindings} 个无效的 worker 绑定。`);
9646
- }
9647
- return lines.join(`
9648
- `);
9649
- }
9650
- function renderTaskListItem(task) {
9651
- const role = task.role ? ` / ${task.role}` : "";
9652
- const group = task.groupId ? `;组:${task.groupId}` : "";
9653
- const summary = task.summary.trim().length > 0 ? `:${task.summary}` : "";
9654
- const source = task.status === "needs_confirmation" ? `;来源:${task.sourceKind} / ${task.sourceHandle}${task.role ? ` / ${task.role}` : ""}` : "";
9655
- const reliability = [
9656
- task.noticePending ? "通知待重试" : "",
9657
- task.injectionPending ? "注入待重试" : "",
9658
- task.cancelRequestedAt && !task.cancelCompletedAt && task.status === "running" ? "取消中" : ""
9659
- ].filter(Boolean).map((item) => `;${item}`).join("");
9660
- return `- ${task.taskId} [${task.status}] ${task.targetAgent}${role} -> ${task.workerSession ?? "未分配"}${group}${source}${summary}${reliability}`;
9661
- }
9662
- function renderGroupListItem(group) {
9663
- const reliability = [
9664
- group.group.injectionPending ? "注入待重试" : ""
9665
- ].filter(Boolean).map((item) => `;${item}`).join("");
9666
- return [
9667
- `- ${group.group.groupId}`,
9668
- group.group.title,
9669
- `总计 ${group.totalTasks}`,
9670
- `待确认 ${group.pendingApprovalTasks}`,
9671
- `运行中 ${group.runningTasks}`,
9672
- `完成 ${group.completedTasks}`,
9673
- `失败 ${group.failedTasks}`,
9674
- `取消 ${group.cancelledTasks}${reliability}`
9675
- ].join(" | ");
9676
- }
9677
- function renderTaskProgress(task, summary) {
9678
- return `⏳ 任务「${task.taskId}」(${task.targetAgent}):${summary}`;
9679
- }
9680
- function renderTaskHeartbeat(task, elapsedSeconds) {
9681
- const minutes = Math.floor(elapsedSeconds / 60);
9682
- return `⏳ 任务「${task.taskId}」已运行 ${minutes} 分钟,等待中...`;
9683
- }
9684
-
9685
9480
  // src/orchestration/task-wait-timeouts.ts
9686
9481
  var DEFAULT_TASK_WAIT_TIMEOUT_MS, MAX_TASK_WAIT_TIMEOUT_MS, DEFAULT_TASK_WAIT_POLL_INTERVAL_MS = 1000, MAX_TASK_WAIT_POLL_INTERVAL_MS = 1e4, TASK_WAIT_RPC_TIMEOUT_PADDING_MS = 5000;
9687
9482
  var init_task_wait_timeouts = __esm(() => {
@@ -16776,6 +16571,8 @@ async function handleSessionRemove(context, chatKey, alias) {
16776
16571
  }
16777
16572
  async function promptWithSession(context, session, chatKey, text, reply, replyContextToken, accountId, media, abortSignal) {
16778
16573
  const effectiveReplyMode = session.replyMode ?? context.config?.channel.replyMode ?? "verbose";
16574
+ if (!session.replyMode)
16575
+ session.replyMode = effectiveReplyMode;
16779
16576
  const transportReply = effectiveReplyMode !== "final" ? reply : undefined;
16780
16577
  if (context.orchestration) {
16781
16578
  try {
@@ -16796,7 +16593,7 @@ async function promptWithSession(context, session, chatKey, text, reply, replyCo
16796
16593
  }
16797
16594
  const { promptText, taskIds, groupIds, claimHumanReply } = await preparePromptWithFallback(context, session, chatKey, text, replyContextToken, accountId);
16798
16595
  try {
16799
- const replyContext = transportReply && context.quota ? { chatKey, quota: context.quota } : undefined;
16596
+ const replyContext = transportReply && context.quota && getChannelIdFromChatKey(chatKey) === "weixin" ? { chatKey, quota: context.quota } : undefined;
16800
16597
  const result = await context.interaction.promptTransportSession(session, promptText, transportReply, replyContext, media, abortSignal);
16801
16598
  if (claimHumanReply) {
16802
16599
  try {
@@ -16874,88 +16671,293 @@ async function markCoordinatorResultsInjected(context, taskIds, groupIds) {
16874
16671
  });
16875
16672
  }
16876
16673
  }
16877
- async function markCoordinatorResultsInjectionFailed(context, taskIds, groupIds, error2) {
16878
- if (taskIds.length === 0 && groupIds.length === 0 || !context.orchestration) {
16879
- return;
16674
+ async function markCoordinatorResultsInjectionFailed(context, taskIds, groupIds, error2) {
16675
+ if (taskIds.length === 0 && groupIds.length === 0 || !context.orchestration) {
16676
+ return;
16677
+ }
16678
+ const errorMessage = error2 instanceof Error ? error2.message : String(error2);
16679
+ try {
16680
+ if (groupIds.length > 0) {
16681
+ await context.orchestration.markCoordinatorGroupsInjectionFailed?.(groupIds, errorMessage);
16682
+ }
16683
+ if (taskIds.length > 0) {
16684
+ await context.orchestration.markTaskInjectionFailed(taskIds, errorMessage);
16685
+ }
16686
+ } catch (markError) {
16687
+ await context.logger.error("orchestration.coordinator_results.mark_failed", "failed to mark coordinator results injection failure", {
16688
+ taskIds: taskIds.join(","),
16689
+ groupIds: groupIds.join(","),
16690
+ error: markError instanceof Error ? markError.message : String(markError)
16691
+ });
16692
+ }
16693
+ }
16694
+ var NO_CURRENT_SESSION_TEXT = "当前还没有选中的会话。请先执行 /session new ... 或 /use <alias>。", sessionHelp, modeHelp, replyModeHelp, statusHelp, cancelHelp;
16695
+ var init_session_handler = __esm(() => {
16696
+ init_build_coordinator_prompt();
16697
+ init_channel_scope();
16698
+ sessionHelp = {
16699
+ topic: "session",
16700
+ aliases: ["ss", "sessions"],
16701
+ summary: "创建、恢复、切换和重置逻辑会话。",
16702
+ commands: [
16703
+ { usage: "/sessions", description: "查看当前会话列表" },
16704
+ { usage: "/session 或 /ss", description: "查看会话列表" },
16705
+ { usage: "/ss <agent> (-d <path> | --ws <name>)", description: "快速新建或复用一个会话" },
16706
+ { usage: "/ss new <agent> (-d <path> | --ws <name>)", description: "强制新建会话" },
16707
+ { usage: "/ss new <alias> -a <name> --ws <name>", description: "按指定配置新建会话" },
16708
+ { usage: "/ss attach <alias> -a <name> --ws <name> --name <transport-session>", description: "绑定已有会话" },
16709
+ { usage: "/session rm <alias>", description: "删除逻辑会话" },
16710
+ { usage: "/use <alias>", description: "切换当前会话" },
16711
+ { usage: "/session reset 或 /clear", description: "重置当前会话上下文" }
16712
+ ],
16713
+ examples: ["/ss codex -d /absolute/path/to/repo", "/use backend-fix", "/session rm old-session", "/session reset"]
16714
+ };
16715
+ modeHelp = {
16716
+ topic: "mode",
16717
+ aliases: [],
16718
+ summary: "查看或设置当前会话 mode。",
16719
+ commands: [
16720
+ { usage: "/mode", description: "查看当前会话已保存的 mode" },
16721
+ { usage: "/mode <id>", description: "设置当前会话 mode" }
16722
+ ],
16723
+ examples: ["/mode", "/mode plan"]
16724
+ };
16725
+ replyModeHelp = {
16726
+ topic: "replymode",
16727
+ aliases: [],
16728
+ summary: "查看或设置当前逻辑会话的回复输出模式。",
16729
+ commands: [
16730
+ { usage: "/replymode", description: "查看全局默认、当前覆盖和实际生效值" },
16731
+ { usage: "/replymode stream", description: "当前会话使用流式回复" },
16732
+ { usage: "/replymode verbose", description: "当前会话流式回复并显示工具调用" },
16733
+ { usage: "/replymode final", description: "当前会话只发送最终文本" },
16734
+ { usage: "/replymode reset", description: "清除当前会话覆盖并回退到全局默认" }
16735
+ ],
16736
+ examples: ["/replymode", "/replymode final", "/replymode verbose"]
16737
+ };
16738
+ statusHelp = {
16739
+ topic: "status",
16740
+ aliases: [],
16741
+ summary: "查看当前选中会话的状态。",
16742
+ commands: [{ usage: "/status", description: "查看当前会话状态" }],
16743
+ examples: ["/status"]
16744
+ };
16745
+ cancelHelp = {
16746
+ topic: "cancel",
16747
+ aliases: ["stop"],
16748
+ summary: "取消当前会话里正在执行的任务。",
16749
+ commands: [
16750
+ { usage: "/cancel", description: "取消当前任务" },
16751
+ { usage: "/stop", description: "取消当前任务(/cancel 别名)" }
16752
+ ],
16753
+ examples: ["/cancel"]
16754
+ };
16755
+ });
16756
+
16757
+ // src/formatting/render-text.ts
16758
+ function renderAgents(config2) {
16759
+ const names = Object.keys(config2.agents);
16760
+ if (names.length === 0) {
16761
+ return "还没有注册任何 Agent。";
16762
+ }
16763
+ return ["已注册的 Agent:", ...names.map((name) => `- ${name}`)].join(`
16764
+ `);
16765
+ }
16766
+ function renderWorkspaces(config2) {
16767
+ const names = Object.entries(config2.workspaces);
16768
+ if (names.length === 0) {
16769
+ return "还没有注册任何工作区。";
16770
+ }
16771
+ return ["已注册的工作区:", ...names.map(([name, workspace]) => `- ${name}: ${workspace.cwd}`)].join(`
16772
+ `);
16773
+ }
16774
+ function renderOrchestrationUnavailable() {
16775
+ return "当前未启用任务编排服务。";
16776
+ }
16777
+ function renderDelegateSuccess2(taskId, workerSession) {
16778
+ return [`已创建委派任务「${taskId}」`, `worker 会话:${workerSession}`].join(`
16779
+ `);
16780
+ }
16781
+ function renderGroupCreated2(group) {
16782
+ return [`已创建任务组「${group.groupId}」`, `- 标题:${group.title}`].join(`
16783
+ `);
16784
+ }
16785
+ function renderGroupList2(groups) {
16786
+ if (groups.length === 0) {
16787
+ return "当前协调会话下还没有任务组。";
16788
+ }
16789
+ return ["当前协调会话的任务组:", ...groups.map((group) => renderGroupListItem2(group))].join(`
16790
+ `);
16791
+ }
16792
+ function renderGroupSummary2(summary) {
16793
+ const { group, tasks } = summary;
16794
+ const lines = [
16795
+ `任务组「${group.groupId}」`,
16796
+ `- 标题:${group.title}`,
16797
+ `- 协调会话:${group.coordinatorSession}`,
16798
+ `- 总任务数:${summary.totalTasks}`,
16799
+ `- 待确认:${summary.pendingApprovalTasks}`,
16800
+ `- 运行中:${summary.runningTasks}`,
16801
+ `- 已完成:${summary.completedTasks}`,
16802
+ `- 已失败:${summary.failedTasks}`,
16803
+ `- 已取消:${summary.cancelledTasks}`,
16804
+ `- 是否终态:${summary.terminal ? "是" : "否"}`
16805
+ ];
16806
+ if (group.injectionPending !== undefined) {
16807
+ lines.push(`- 注入待处理:${group.injectionPending ? "是" : "否"}`);
16808
+ }
16809
+ if (group.injectionAppliedAt) {
16810
+ lines.push(`- 注入完成时间:${group.injectionAppliedAt}`);
16811
+ }
16812
+ if (group.lastInjectionError) {
16813
+ lines.push(`- 最近注入错误:${group.lastInjectionError}`);
16814
+ }
16815
+ if (tasks.length > 0) {
16816
+ lines.push("- 成员:");
16817
+ for (const task of tasks) {
16818
+ lines.push(` - ${task.taskId} [${task.status}] ${task.targetAgent}`);
16819
+ }
16820
+ }
16821
+ return lines.join(`
16822
+ `);
16823
+ }
16824
+ function renderGroupCancelSuccess2(input) {
16825
+ return [
16826
+ `任务组「${input.summary.group.groupId}」已发起取消`,
16827
+ `- 已请求取消:${input.cancelledTaskIds.length}`,
16828
+ `- 已跳过终态任务:${input.skippedTaskIds.length}`
16829
+ ].join(`
16830
+ `);
16831
+ }
16832
+ function renderTaskList2(tasks) {
16833
+ if (tasks.length === 0) {
16834
+ return "当前协调会话下还没有任务。";
16835
+ }
16836
+ return ["当前协调会话的任务:", ...tasks.map((task) => renderTaskListItem2(task))].join(`
16837
+ `);
16838
+ }
16839
+ function renderTaskSummary2(task) {
16840
+ const header = [
16841
+ `任务「${task.taskId}」`,
16842
+ `- 状态:${task.status}`,
16843
+ `- 协调会话:${task.coordinatorSession}`,
16844
+ `- worker 会话:${task.workerSession ?? "未分配"}`,
16845
+ `- 目标 Agent:${task.targetAgent}`
16846
+ ];
16847
+ if (task.role)
16848
+ header.push(`- 角色:${task.role}`);
16849
+ if (task.groupId)
16850
+ header.push(`- 任务组:${task.groupId}`);
16851
+ if (task.status === "needs_confirmation") {
16852
+ header.push(`- 来源:${task.sourceKind} / ${task.sourceHandle}${task.role ? ` / ${task.role}` : ""}`);
16853
+ }
16854
+ header.push(`- 任务:${task.task}`);
16855
+ if (task.summary.trim().length > 0)
16856
+ header.push(`- 摘要:${task.summary}`);
16857
+ if (task.resultText.trim().length > 0)
16858
+ header.push(`- 结果:${task.resultText}`);
16859
+ const events = [];
16860
+ events.push({ at: task.createdAt, event: "created" });
16861
+ if (task.workerSession && task.status !== "needs_confirmation") {
16862
+ events.push({ at: task.createdAt, event: "dispatched", detail: task.workerSession });
16863
+ }
16864
+ if (task.lastProgressAt)
16865
+ events.push({ at: task.lastProgressAt, event: "last_progress" });
16866
+ if (task.cancelRequestedAt)
16867
+ events.push({ at: task.cancelRequestedAt, event: "cancel_requested" });
16868
+ if (task.cancelCompletedAt)
16869
+ events.push({ at: task.cancelCompletedAt, event: "cancel_completed" });
16870
+ if (task.lastCancelError)
16871
+ events.push({ at: task.updatedAt, event: "cancel_failed", detail: task.lastCancelError });
16872
+ if (task.status === "completed")
16873
+ events.push({ at: task.updatedAt, event: "completed" });
16874
+ if (task.status === "failed")
16875
+ events.push({ at: task.updatedAt, event: "failed" });
16876
+ if (task.noticeSentAt)
16877
+ events.push({ at: task.noticeSentAt, event: "notice_sent", detail: task.deliveryAccountId });
16878
+ if (task.lastNoticeError)
16879
+ events.push({ at: task.updatedAt, event: "notice_failed", detail: task.lastNoticeError });
16880
+ if (task.injectionAppliedAt)
16881
+ events.push({ at: task.injectionAppliedAt, event: "injection_applied" });
16882
+ if (task.lastInjectionError)
16883
+ events.push({ at: task.updatedAt, event: "injection_failed", detail: task.lastInjectionError });
16884
+ events.sort((a, b) => a.at.localeCompare(b.at));
16885
+ const timeline = events.length > 0 ? ["- 时间线:", ...events.map((e) => ` - [${e.at}] ${e.event}${e.detail ? `: ${e.detail}` : ""}`)] : [];
16886
+ return [...header, ...timeline].join(`
16887
+ `);
16888
+ }
16889
+ function renderTaskCancelSuccess(task) {
16890
+ if (task.status === "completed" || task.status === "failed" || task.status === "cancelled") {
16891
+ return [`任务「${task.taskId}」已结束。`, `- 当前状态:${task.status}`].join(`
16892
+ `);
16893
+ }
16894
+ if (task.cancelRequestedAt) {
16895
+ return [`已请求取消任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
16896
+ `);
16897
+ }
16898
+ return [`任务「${task.taskId}」已取消。`, `- 当前状态:${task.status}`].join(`
16899
+ `);
16900
+ }
16901
+ function renderTaskApprovalSuccess2(task) {
16902
+ return [`已批准任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
16903
+ `);
16904
+ }
16905
+ function renderTaskRejectionSuccess2(task) {
16906
+ return [`已拒绝任务「${task.taskId}」。`, `- 当前状态:${task.status}`].join(`
16907
+ `);
16908
+ }
16909
+ function renderTaskConfirmationUnavailable(task) {
16910
+ return [`任务「${task.taskId}」当前不是待确认状态。`, `- 当前状态:${task.status}`].join(`
16911
+ `);
16912
+ }
16913
+ function renderTasksCleanResult(removedTasks, removedBindings) {
16914
+ if (removedTasks === 0 && removedBindings === 0) {
16915
+ return "当前协调会话下没有可清理的任务。";
16880
16916
  }
16881
- const errorMessage = error2 instanceof Error ? error2.message : String(error2);
16882
- try {
16883
- if (groupIds.length > 0) {
16884
- await context.orchestration.markCoordinatorGroupsInjectionFailed?.(groupIds, errorMessage);
16885
- }
16886
- if (taskIds.length > 0) {
16887
- await context.orchestration.markTaskInjectionFailed(taskIds, errorMessage);
16888
- }
16889
- } catch (markError) {
16890
- await context.logger.error("orchestration.coordinator_results.mark_failed", "failed to mark coordinator results injection failure", {
16891
- taskIds: taskIds.join(","),
16892
- groupIds: groupIds.join(","),
16893
- error: markError instanceof Error ? markError.message : String(markError)
16894
- });
16917
+ const lines = [];
16918
+ if (removedTasks > 0) {
16919
+ lines.push(`已清理 ${removedTasks} 个已结束的任务。`);
16920
+ }
16921
+ if (removedBindings > 0) {
16922
+ lines.push(`已释放 ${removedBindings} 个无效的 worker 绑定。`);
16895
16923
  }
16924
+ return lines.join(`
16925
+ `);
16926
+ }
16927
+ function renderTaskListItem2(task) {
16928
+ const role = task.role ? ` / ${task.role}` : "";
16929
+ const group = task.groupId ? `;组:${task.groupId}` : "";
16930
+ const summary = task.summary.trim().length > 0 ? `:${task.summary}` : "";
16931
+ const source = task.status === "needs_confirmation" ? `;来源:${task.sourceKind} / ${task.sourceHandle}${task.role ? ` / ${task.role}` : ""}` : "";
16932
+ const reliability = [
16933
+ task.noticePending ? "通知待重试" : "",
16934
+ task.injectionPending ? "注入待重试" : "",
16935
+ task.cancelRequestedAt && !task.cancelCompletedAt && task.status === "running" ? "取消中" : ""
16936
+ ].filter(Boolean).map((item) => `;${item}`).join("");
16937
+ return `- ${task.taskId} [${task.status}] ${task.targetAgent}${role} -> ${task.workerSession ?? "未分配"}${group}${source}${summary}${reliability}`;
16938
+ }
16939
+ function renderGroupListItem2(group) {
16940
+ const reliability = [
16941
+ group.group.injectionPending ? "注入待重试" : ""
16942
+ ].filter(Boolean).map((item) => `;${item}`).join("");
16943
+ return [
16944
+ `- ${group.group.groupId}`,
16945
+ group.group.title,
16946
+ `总计 ${group.totalTasks}`,
16947
+ `待确认 ${group.pendingApprovalTasks}`,
16948
+ `运行中 ${group.runningTasks}`,
16949
+ `完成 ${group.completedTasks}`,
16950
+ `失败 ${group.failedTasks}`,
16951
+ `取消 ${group.cancelledTasks}${reliability}`
16952
+ ].join(" | ");
16953
+ }
16954
+ function renderTaskProgress(task, summary) {
16955
+ return `⏳ 任务「${task.taskId}」(${task.targetAgent}):${summary}`;
16956
+ }
16957
+ function renderTaskHeartbeat(task, elapsedSeconds) {
16958
+ const minutes = Math.floor(elapsedSeconds / 60);
16959
+ return `⏳ 任务「${task.taskId}」已运行 ${minutes} 分钟,等待中...`;
16896
16960
  }
16897
- var NO_CURRENT_SESSION_TEXT = "当前还没有选中的会话。请先执行 /session new ... 或 /use <alias>。", sessionHelp, modeHelp, replyModeHelp, statusHelp, cancelHelp;
16898
- var init_session_handler = __esm(() => {
16899
- init_build_coordinator_prompt();
16900
- init_channel_scope();
16901
- sessionHelp = {
16902
- topic: "session",
16903
- aliases: ["ss", "sessions"],
16904
- summary: "创建、恢复、切换和重置逻辑会话。",
16905
- commands: [
16906
- { usage: "/sessions", description: "查看当前会话列表" },
16907
- { usage: "/session 或 /ss", description: "查看会话列表" },
16908
- { usage: "/ss <agent> (-d <path> | --ws <name>)", description: "快速新建或复用一个会话" },
16909
- { usage: "/ss new <agent> (-d <path> | --ws <name>)", description: "强制新建会话" },
16910
- { usage: "/ss new <alias> -a <name> --ws <name>", description: "按指定配置新建会话" },
16911
- { usage: "/ss attach <alias> -a <name> --ws <name> --name <transport-session>", description: "绑定已有会话" },
16912
- { usage: "/session rm <alias>", description: "删除逻辑会话" },
16913
- { usage: "/use <alias>", description: "切换当前会话" },
16914
- { usage: "/session reset 或 /clear", description: "重置当前会话上下文" }
16915
- ],
16916
- examples: ["/ss codex -d /absolute/path/to/repo", "/use backend-fix", "/session rm old-session", "/session reset"]
16917
- };
16918
- modeHelp = {
16919
- topic: "mode",
16920
- aliases: [],
16921
- summary: "查看或设置当前会话 mode。",
16922
- commands: [
16923
- { usage: "/mode", description: "查看当前会话已保存的 mode" },
16924
- { usage: "/mode <id>", description: "设置当前会话 mode" }
16925
- ],
16926
- examples: ["/mode", "/mode plan"]
16927
- };
16928
- replyModeHelp = {
16929
- topic: "replymode",
16930
- aliases: [],
16931
- summary: "查看或设置当前逻辑会话的回复输出模式。",
16932
- commands: [
16933
- { usage: "/replymode", description: "查看全局默认、当前覆盖和实际生效值" },
16934
- { usage: "/replymode stream", description: "当前会话使用流式回复" },
16935
- { usage: "/replymode verbose", description: "当前会话流式回复并显示工具调用" },
16936
- { usage: "/replymode final", description: "当前会话只发送最终文本" },
16937
- { usage: "/replymode reset", description: "清除当前会话覆盖并回退到全局默认" }
16938
- ],
16939
- examples: ["/replymode", "/replymode final", "/replymode verbose"]
16940
- };
16941
- statusHelp = {
16942
- topic: "status",
16943
- aliases: [],
16944
- summary: "查看当前选中会话的状态。",
16945
- commands: [{ usage: "/status", description: "查看当前会话状态" }],
16946
- examples: ["/status"]
16947
- };
16948
- cancelHelp = {
16949
- topic: "cancel",
16950
- aliases: ["stop"],
16951
- summary: "取消当前会话里正在执行的任务。",
16952
- commands: [
16953
- { usage: "/cancel", description: "取消当前任务" },
16954
- { usage: "/stop", description: "取消当前任务(/cancel 别名)" }
16955
- ],
16956
- examples: ["/cancel"]
16957
- };
16958
- });
16959
16961
 
16960
16962
  // src/commands/handlers/orchestration-handler.ts
16961
16963
  async function handleDelegateRequest(context, chatKey, targetAgent, task, role, groupId, replyContextToken, accountId) {
@@ -16980,7 +16982,7 @@ async function handleDelegateRequest(context, chatKey, targetAgent, task, role,
16980
16982
  ...replyContextToken ? { replyContextToken } : {},
16981
16983
  ...accountId ? { accountId } : {}
16982
16984
  });
16983
- return { text: renderDelegateSuccess(result.taskId, result.workerSession) };
16985
+ return { text: renderDelegateSuccess2(result.taskId, result.workerSession) };
16984
16986
  }
16985
16987
  async function handleGroupCreate(context, chatKey, title) {
16986
16988
  const session = await getCurrentSession(context, chatKey);
@@ -16995,7 +16997,7 @@ async function handleGroupCreate(context, chatKey, title) {
16995
16997
  coordinatorSession: session.transportSession,
16996
16998
  title
16997
16999
  });
16998
- return { text: renderGroupCreated(group) };
17000
+ return { text: renderGroupCreated2(group) };
16999
17001
  }
17000
17002
  async function handleGroupList(context, chatKey, filter) {
17001
17003
  const session = await getCurrentSession(context, chatKey);
@@ -17010,7 +17012,7 @@ async function handleGroupList(context, chatKey, filter) {
17010
17012
  coordinatorSession: session.transportSession,
17011
17013
  ...filter ?? {}
17012
17014
  });
17013
- return { text: renderGroupList(groups) };
17015
+ return { text: renderGroupList2(groups) };
17014
17016
  }
17015
17017
  async function handleGroupGet(context, chatKey, groupId) {
17016
17018
  const session = await getCurrentSession(context, chatKey);
@@ -17028,7 +17030,7 @@ async function handleGroupGet(context, chatKey, groupId) {
17028
17030
  if (!group) {
17029
17031
  return { text: GROUP_NOT_FOUND_TEXT };
17030
17032
  }
17031
- return { text: renderGroupSummary(group) };
17033
+ return { text: renderGroupSummary2(group) };
17032
17034
  }
17033
17035
  async function handleGroupCancel(context, chatKey, groupId) {
17034
17036
  const session = await getCurrentSession(context, chatKey);
@@ -17050,7 +17052,7 @@ async function handleGroupCancel(context, chatKey, groupId) {
17050
17052
  groupId,
17051
17053
  coordinatorSession: session.transportSession
17052
17054
  });
17053
- return { text: renderGroupCancelSuccess(cancelled) };
17055
+ return { text: renderGroupCancelSuccess2(cancelled) };
17054
17056
  }
17055
17057
  async function handleGroupDelegate(context, chatKey, groupId, targetAgent, task, role, replyContextToken, accountId) {
17056
17058
  const session = await getCurrentSession(context, chatKey);
@@ -17083,7 +17085,7 @@ async function handleTaskList(context, chatKey, filter) {
17083
17085
  coordinatorSession: session.transportSession,
17084
17086
  ...filter ?? {}
17085
17087
  });
17086
- return { text: renderTaskList(tasks) };
17088
+ return { text: renderTaskList2(tasks) };
17087
17089
  }
17088
17090
  async function handleTaskGet(context, chatKey, taskId) {
17089
17091
  const session = await getCurrentSession(context, chatKey);
@@ -17098,7 +17100,7 @@ async function handleTaskGet(context, chatKey, taskId) {
17098
17100
  if (!task || task.coordinatorSession !== session.transportSession) {
17099
17101
  return { text: TASK_NOT_FOUND_TEXT };
17100
17102
  }
17101
- return { text: renderTaskSummary(task) };
17103
+ return { text: renderTaskSummary2(task) };
17102
17104
  }
17103
17105
  async function handleTaskApprove(context, chatKey, taskId) {
17104
17106
  const session = await getCurrentSession(context, chatKey);
@@ -17120,7 +17122,7 @@ async function handleTaskApprove(context, chatKey, taskId) {
17120
17122
  taskId,
17121
17123
  coordinatorSession: session.transportSession
17122
17124
  });
17123
- return { text: renderTaskApprovalSuccess(approved) };
17125
+ return { text: renderTaskApprovalSuccess2(approved) };
17124
17126
  }
17125
17127
  async function handleTaskReject(context, chatKey, taskId) {
17126
17128
  const session = await getCurrentSession(context, chatKey);
@@ -17142,7 +17144,7 @@ async function handleTaskReject(context, chatKey, taskId) {
17142
17144
  taskId,
17143
17145
  coordinatorSession: session.transportSession
17144
17146
  });
17145
- return { text: renderTaskRejectionSuccess(rejected) };
17147
+ return { text: renderTaskRejectionSuccess2(rejected) };
17146
17148
  }
17147
17149
  async function handleTaskCancel(context, chatKey, taskId) {
17148
17150
  const session = await getCurrentSession(context, chatKey);
@@ -23244,7 +23246,7 @@ ${result.text}` : "" };
23244
23246
  name: session.transportSession,
23245
23247
  mcpCoordinatorSession: session.mcpCoordinatorSession,
23246
23248
  mcpSourceHandle: session.mcpSourceHandle,
23247
- ...session.replyMode ? { replyMode: session.replyMode } : {}
23249
+ replyMode: session.replyMode ?? "verbose"
23248
23250
  };
23249
23251
  }
23250
23252
  }
@@ -23483,26 +23485,32 @@ function formatToolCallEvent(update, sessionUpdate) {
23483
23485
  if (title.length === 0)
23484
23486
  return null;
23485
23487
  const emoji2 = KIND_EMOJI[kind] ?? "\uD83D\uDD27";
23486
- const command = getToolDisplayCommand(update);
23487
- if (command) {
23488
- return `${emoji2} ${truncateToolDisplay(command)}`;
23489
- }
23490
- if (sessionUpdate === "tool_call_update" || isGenericToolTitle(kind, title))
23488
+ const inputSummary = summarizeToolInput(update.rawInput);
23489
+ const status = readString(update, "status");
23490
+ if (!inputSummary && isGenericToolTitle(kind, title))
23491
23491
  return null;
23492
- return `${emoji2} ${title}`;
23492
+ const summaryText = inputSummary ? `: ${truncateToolDisplay(inputSummary)}` : "";
23493
+ const statusText = status ? ` (${status})` : "";
23494
+ return `${emoji2} ${title}${statusText}${summaryText}`;
23493
23495
  }
23494
- function getToolDisplayCommand(update) {
23495
- if (!update)
23496
- return null;
23497
- const command = update.rawInput?.command;
23498
- if (typeof command === "string" && command.length > 0) {
23499
- return command;
23496
+ function summarizeToolInput(rawInput) {
23497
+ if (rawInput == null)
23498
+ return;
23499
+ if (typeof rawInput === "string" || typeof rawInput === "number" || typeof rawInput === "boolean") {
23500
+ return String(rawInput);
23501
+ }
23502
+ if (!isRecord3(rawInput))
23503
+ return;
23504
+ const command = readFirstString(rawInput, ["command", "cmd", "program"]);
23505
+ const args = readFirstStringArray(rawInput, ["args", "arguments"]);
23506
+ if (command) {
23507
+ return [command, ...args ?? []].join(" ");
23500
23508
  }
23501
- const parsedCmd = update.rawInput?.parsed_cmd;
23502
- if (parsedCmd && parsedCmd.length > 0) {
23509
+ const parsedCmd = rawInput.parsed_cmd;
23510
+ if (Array.isArray(parsedCmd) && parsedCmd.length > 0) {
23503
23511
  const parts = [];
23504
23512
  for (const entry of parsedCmd) {
23505
- if (entry && typeof entry.cmd === "string" && entry.cmd.length > 0) {
23513
+ if (isRecord3(entry) && typeof entry.cmd === "string" && entry.cmd.length > 0) {
23506
23514
  parts.push(entry.cmd);
23507
23515
  }
23508
23516
  }
@@ -23510,7 +23518,51 @@ function getToolDisplayCommand(update) {
23510
23518
  return parts.join(" ");
23511
23519
  }
23512
23520
  }
23513
- return null;
23521
+ return readFirstString(rawInput, [
23522
+ "path",
23523
+ "file",
23524
+ "filePath",
23525
+ "filepath",
23526
+ "target",
23527
+ "uri",
23528
+ "url",
23529
+ "query",
23530
+ "pattern",
23531
+ "text",
23532
+ "search",
23533
+ "name",
23534
+ "description"
23535
+ ]);
23536
+ }
23537
+ function readFirstString(record3, keys) {
23538
+ for (const key of keys) {
23539
+ const value = record3[key];
23540
+ if (typeof value === "string" && value.trim().length > 0) {
23541
+ return value.trim();
23542
+ }
23543
+ }
23544
+ return;
23545
+ }
23546
+ function readFirstStringArray(record3, keys) {
23547
+ for (const key of keys) {
23548
+ const value = record3[key];
23549
+ if (!Array.isArray(value))
23550
+ continue;
23551
+ const entries = value.map((entry) => typeof entry === "string" && entry.trim().length > 0 ? entry.trim() : undefined).filter((entry) => entry !== undefined);
23552
+ if (entries.length > 0) {
23553
+ return entries;
23554
+ }
23555
+ }
23556
+ return;
23557
+ }
23558
+ function isRecord3(value) {
23559
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23560
+ }
23561
+ function readString(rawInput, key) {
23562
+ if (!isRecord3(rawInput))
23563
+ return;
23564
+ const value = rawInput[key];
23565
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
23514
23566
  }
23515
23567
  function truncateToolDisplay(text) {
23516
23568
  return text.length > 60 ? `${text.slice(0, 57)}...` : text;
@@ -23874,7 +23926,7 @@ class AcpxCliTransport {
23874
23926
  const args = this.buildPromptArgs(session, text, structuredPrompt?.filePath);
23875
23927
  try {
23876
23928
  if (reply || options?.onSegment) {
23877
- const formatToolCalls = session.replyMode === "verbose";
23929
+ const formatToolCalls = (session.replyMode ?? "verbose") === "verbose";
23878
23930
  const { result: result2, overflowCount } = await this.runStreamingPrompt(this.command, args, reply, 30000, formatToolCalls, replyContext, options?.onSegment);
23879
23931
  const baseText = getPromptText(result2);
23880
23932
  if (!reply) {
@@ -38385,7 +38437,7 @@ function buildWeacpxMcpToolRegistry(input) {
38385
38437
  return [
38386
38438
  {
38387
38439
  name: "delegate_request",
38388
- description: `Delegate a subtask to another agent under the current coordinator.${availableAgents && availableAgents.length > 0 ? ` Available agents: ${availableAgents.join(", ")}.` : ""}`,
38440
+ description: `Delegate a subtask to another agent under the current coordinator. Pass an absolute workingDirectory for the worker.${availableAgents && availableAgents.length > 0 ? ` Available agents: ${availableAgents.join(", ")}.` : ""}`,
38389
38441
  inputSchema: exports_external.object({
38390
38442
  targetAgent: exports_external.string().min(1),
38391
38443
  task: exports_external.string().min(1),
@@ -38400,12 +38452,12 @@ function buildWeacpxMcpToolRegistry(input) {
38400
38452
  ...sourceHandle ? { sourceHandle } : {},
38401
38453
  ...input2
38402
38454
  });
38403
- return createSuccessResult(`Delegation task ${result.taskId} is ${result.status}.`, result);
38455
+ return createSuccessResult(renderDelegateSuccess(result), result);
38404
38456
  })
38405
38457
  },
38406
38458
  {
38407
38459
  name: "group_new",
38408
- description: "Create a new task group for the current coordinator.",
38460
+ description: "Create a new task group under the current coordinator.",
38409
38461
  inputSchema: exports_external.object({
38410
38462
  title: exports_external.string().min(1)
38411
38463
  }).strict(),
@@ -38414,12 +38466,12 @@ function buildWeacpxMcpToolRegistry(input) {
38414
38466
  coordinatorSession,
38415
38467
  title: args.title
38416
38468
  });
38417
- return createSuccessResult(`Group ${group.groupId} created (title: ${group.title}).`, group);
38469
+ return createSuccessResult(renderGroupCreated(group), group);
38418
38470
  })
38419
38471
  },
38420
38472
  {
38421
38473
  name: "group_get",
38422
- description: "Fetch a single task group summary for the current coordinator.",
38474
+ description: "Fetch a single task-group summary under the current coordinator.",
38423
38475
  inputSchema: exports_external.object({
38424
38476
  groupId: exports_external.string().min(1)
38425
38477
  }).strict(),
@@ -38433,7 +38485,7 @@ function buildWeacpxMcpToolRegistry(input) {
38433
38485
  },
38434
38486
  {
38435
38487
  name: "group_list",
38436
- description: "List task groups for the current coordinator.",
38488
+ description: "List task groups under the current coordinator.",
38437
38489
  inputSchema: exports_external.object({
38438
38490
  status: groupStatusSchema.optional(),
38439
38491
  stuck: exports_external.boolean().optional(),
@@ -38454,7 +38506,7 @@ function buildWeacpxMcpToolRegistry(input) {
38454
38506
  },
38455
38507
  {
38456
38508
  name: "group_cancel",
38457
- description: "Cancel all unfinished tasks in a task group for the current coordinator.",
38509
+ description: "Cancel all unfinished tasks in a task group under the current coordinator.",
38458
38510
  inputSchema: exports_external.object({
38459
38511
  groupId: exports_external.string().min(1)
38460
38512
  }).strict(),
@@ -38468,7 +38520,7 @@ function buildWeacpxMcpToolRegistry(input) {
38468
38520
  },
38469
38521
  {
38470
38522
  name: "task_get",
38471
- description: "Fetch a single orchestration task for the current coordinator.",
38523
+ description: "Fetch a single task under the current coordinator.",
38472
38524
  inputSchema: exports_external.object({
38473
38525
  taskId: exports_external.string().min(1)
38474
38526
  }).strict(),
@@ -38482,7 +38534,7 @@ function buildWeacpxMcpToolRegistry(input) {
38482
38534
  },
38483
38535
  {
38484
38536
  name: "task_list",
38485
- description: "List orchestration tasks for the current coordinator.",
38537
+ description: "List tasks under the current coordinator.",
38486
38538
  inputSchema: exports_external.object({
38487
38539
  status: taskStatusSchema.optional(),
38488
38540
  stuck: exports_external.boolean().optional(),
@@ -38503,7 +38555,7 @@ function buildWeacpxMcpToolRegistry(input) {
38503
38555
  },
38504
38556
  {
38505
38557
  name: "task_approve",
38506
- description: "Approve a pending orchestration task for the current coordinator.",
38558
+ description: "Approve a pending task under the current coordinator.",
38507
38559
  inputSchema: exports_external.object({
38508
38560
  taskId: exports_external.string().min(1)
38509
38561
  }).strict(),
@@ -38517,7 +38569,7 @@ function buildWeacpxMcpToolRegistry(input) {
38517
38569
  },
38518
38570
  {
38519
38571
  name: "task_reject",
38520
- description: "Reject a pending orchestration task for the current coordinator.",
38572
+ description: "Reject a pending task under the current coordinator.",
38521
38573
  inputSchema: exports_external.object({
38522
38574
  taskId: exports_external.string().min(1)
38523
38575
  }).strict(),
@@ -38531,7 +38583,7 @@ function buildWeacpxMcpToolRegistry(input) {
38531
38583
  },
38532
38584
  {
38533
38585
  name: "task_cancel",
38534
- description: "Request cancellation for an orchestration task under the current coordinator.",
38586
+ description: "Request cancellation for a task under the current coordinator.",
38535
38587
  inputSchema: exports_external.object({
38536
38588
  taskId: exports_external.string().min(1)
38537
38589
  }).strict(),
@@ -38540,12 +38592,12 @@ function buildWeacpxMcpToolRegistry(input) {
38540
38592
  coordinatorSession,
38541
38593
  taskId: args.taskId
38542
38594
  });
38543
- return createSuccessResult(`任务「${task.taskId}」已请求取消。`, task);
38595
+ return createSuccessResult(renderTaskCancelRequest(task), task);
38544
38596
  })
38545
38597
  },
38546
38598
  {
38547
38599
  name: "task_wait",
38548
- description: "Wait for an orchestration task to finish or require attention using a bounded timeout.",
38600
+ description: `Wait for a task to finish or require attention. Defaults: timeout ${DEFAULT_TASK_WAIT_TIMEOUT_MS} ms, poll interval ${DEFAULT_TASK_WAIT_POLL_INTERVAL_MS} ms. Maximums: timeout ${MAX_TASK_WAIT_TIMEOUT_MS} ms, poll interval ${MAX_TASK_WAIT_POLL_INTERVAL_MS} ms.`,
38549
38601
  inputSchema: exports_external.object({
38550
38602
  taskId: exports_external.string().min(1),
38551
38603
  timeoutMs: exports_external.number().int().min(0).max(MAX_TASK_WAIT_TIMEOUT_MS).optional(),
@@ -38561,7 +38613,7 @@ function buildWeacpxMcpToolRegistry(input) {
38561
38613
  },
38562
38614
  {
38563
38615
  name: "worker_raise_question",
38564
- description: "Raise a blocker question for the current bound session.",
38616
+ description: "Raise a blocker question for the current bound worker session.",
38565
38617
  inputSchema: exports_external.object({
38566
38618
  taskId: exports_external.string().min(1),
38567
38619
  question: exports_external.string().min(1),
@@ -38576,8 +38628,7 @@ function buildWeacpxMcpToolRegistry(input) {
38576
38628
  sourceHandle,
38577
38629
  ...args
38578
38630
  });
38579
- return createSuccessResult([`任务「${result.taskId}」已提交 blocker 问题。`, `- questionId:${result.questionId}`].join(`
38580
- `), result);
38631
+ return createSuccessResult(renderWorkerRaiseQuestionSuccess(result), result);
38581
38632
  })
38582
38633
  },
38583
38634
  {
@@ -38593,8 +38644,7 @@ function buildWeacpxMcpToolRegistry(input) {
38593
38644
  coordinatorSession,
38594
38645
  ...args
38595
38646
  });
38596
- return createSuccessResult([`已回答任务「${task.taskId}」的 blocker 问题。`, `- 当前状态:${task.status}`].join(`
38597
- `), task);
38647
+ return createSuccessResult(renderCoordinatorAnswerQuestionSuccess(task), task);
38598
38648
  })
38599
38649
  },
38600
38650
  {
@@ -38610,10 +38660,7 @@ function buildWeacpxMcpToolRegistry(input) {
38610
38660
  coordinatorSession,
38611
38661
  ...args
38612
38662
  });
38613
- const text = result.packageId ? [`已创建 human question package「${result.packageId}」。`, `- 已排队任务:${result.queuedTaskIds.length}`].join(`
38614
- `) : [`问题已加入当前 human question queue。`, `- 已排队任务:${result.queuedTaskIds.length}`].join(`
38615
- `);
38616
- return createSuccessResult(text, result);
38663
+ return createSuccessResult(renderCoordinatorRequestHumanInputSuccess(result), result);
38617
38664
  })
38618
38665
  },
38619
38666
  {
@@ -38630,13 +38677,12 @@ function buildWeacpxMcpToolRegistry(input) {
38630
38677
  coordinatorSession,
38631
38678
  ...args
38632
38679
  });
38633
- return createSuccessResult([`已追加 human package「${result.packageId}」跟进消息。`, `- messageId:${result.messageId}`].join(`
38634
- `), result);
38680
+ return createSuccessResult(renderCoordinatorFollowUpHumanPackageSuccess(result), result);
38635
38681
  })
38636
38682
  },
38637
38683
  {
38638
38684
  name: "coordinator_review_contested_result",
38639
- description: "Review a contested coordinator result under the current coordinator.",
38685
+ description: "Review a contested result under the current coordinator.",
38640
38686
  inputSchema: exports_external.object({
38641
38687
  taskId: exports_external.string().min(1),
38642
38688
  reviewId: exports_external.string().min(1),
@@ -38649,9 +38695,7 @@ function buildWeacpxMcpToolRegistry(input) {
38649
38695
  decision,
38650
38696
  ...rest
38651
38697
  });
38652
- const actionText = decision === "accept" ? "已接受" : "已丢弃";
38653
- return createSuccessResult([`${actionText}任务「${task.taskId}」的 contested result。`, `- 当前状态:${task.status}`].join(`
38654
- `), task);
38698
+ return createSuccessResult(renderCoordinatorReviewContestedResultSuccess(task, decision), task);
38655
38699
  })
38656
38700
  }
38657
38701
  ];
@@ -38702,10 +38746,185 @@ function createErrorResult(message) {
38702
38746
  isError: true
38703
38747
  };
38704
38748
  }
38749
+ function renderDelegateSuccess(result) {
38750
+ return [`Delegation task "${result.taskId}" created.`, `- Status: ${result.status}`].join(`
38751
+ `);
38752
+ }
38753
+ function renderGroupCreated(group) {
38754
+ return [`Task group "${group.groupId}" created.`, `- Title: ${group.title}`].join(`
38755
+ `);
38756
+ }
38757
+ function renderGroupSummary(summary) {
38758
+ const { group, tasks } = summary;
38759
+ const lines = [
38760
+ `Task group "${group.groupId}"`,
38761
+ `- Title: ${group.title}`,
38762
+ `- Coordinator session: ${group.coordinatorSession}`,
38763
+ `- Total tasks: ${summary.totalTasks}`,
38764
+ `- Pending approval: ${summary.pendingApprovalTasks}`,
38765
+ `- Running: ${summary.runningTasks}`,
38766
+ `- Completed: ${summary.completedTasks}`,
38767
+ `- Failed: ${summary.failedTasks}`,
38768
+ `- Cancelled: ${summary.cancelledTasks}`,
38769
+ `- Terminal: ${summary.terminal ? "yes" : "no"}`
38770
+ ];
38771
+ if (group.injectionPending !== undefined) {
38772
+ lines.push(`- Injection pending: ${group.injectionPending ? "yes" : "no"}`);
38773
+ }
38774
+ if (group.injectionAppliedAt) {
38775
+ lines.push(`- Injection completed at: ${group.injectionAppliedAt}`);
38776
+ }
38777
+ if (group.lastInjectionError) {
38778
+ lines.push(`- Last injection error: ${group.lastInjectionError}`);
38779
+ }
38780
+ if (tasks.length > 0) {
38781
+ lines.push("- Members:");
38782
+ for (const task of tasks) {
38783
+ lines.push(` - ${task.taskId} [${task.status}] ${task.targetAgent}`);
38784
+ }
38785
+ }
38786
+ return lines.join(`
38787
+ `);
38788
+ }
38789
+ function renderGroupList(groups) {
38790
+ if (groups.length === 0) {
38791
+ return "There are no task groups under the current coordinator.";
38792
+ }
38793
+ return ["Task groups for the current coordinator:", ...groups.map((group) => renderGroupListItem(group))].join(`
38794
+ `);
38795
+ }
38796
+ function renderGroupListItem(group) {
38797
+ const reliability = group.group.injectionPending ? " | injection pending" : "";
38798
+ return [
38799
+ `- ${group.group.groupId}`,
38800
+ group.group.title,
38801
+ `total ${group.totalTasks}`,
38802
+ `pending ${group.pendingApprovalTasks}`,
38803
+ `running ${group.runningTasks}`,
38804
+ `completed ${group.completedTasks}`,
38805
+ `failed ${group.failedTasks}`,
38806
+ `cancelled ${group.cancelledTasks}${reliability}`
38807
+ ].join(" | ");
38808
+ }
38809
+ function renderGroupCancelSuccess(input) {
38810
+ return [
38811
+ `Task group "${input.summary.group.groupId}" cancellation requested.`,
38812
+ `- Cancel requested: ${input.cancelledTaskIds.length}`,
38813
+ `- Skipped terminal tasks: ${input.skippedTaskIds.length}`
38814
+ ].join(`
38815
+ `);
38816
+ }
38817
+ function renderTaskList(tasks) {
38818
+ if (tasks.length === 0) {
38819
+ return "There are no tasks under the current coordinator.";
38820
+ }
38821
+ return ["Tasks for the current coordinator:", ...tasks.map((task) => renderTaskListItem(task))].join(`
38822
+ `);
38823
+ }
38824
+ function renderTaskListItem(task) {
38825
+ const role = task.role ? ` / ${task.role}` : "";
38826
+ const group = task.groupId ? `; group: ${task.groupId}` : "";
38827
+ const summary = task.summary.trim().length > 0 ? `: ${task.summary}` : "";
38828
+ const source = task.status === "needs_confirmation" ? `; source: ${task.targetAgent}${task.role ? ` / ${task.role}` : ""}` : "";
38829
+ const reliability = [
38830
+ task.noticePending ? "notice pending retry" : "",
38831
+ task.injectionPending ? "injection pending retry" : "",
38832
+ task.cancelRequestedAt && !task.cancelCompletedAt && task.status === "running" ? "cancelling" : ""
38833
+ ].filter(Boolean).map((item) => `; ${item}`).join("");
38834
+ return `- ${task.taskId} [${task.status}] ${task.targetAgent}${role} -> ${task.workerSession ?? "unassigned"}${group}${source}${summary}${reliability}`;
38835
+ }
38836
+ function renderTaskSummary(task) {
38837
+ const header = [
38838
+ `Task "${task.taskId}"`,
38839
+ `- Status: ${task.status}`,
38840
+ `- Coordinator session: ${task.coordinatorSession}`,
38841
+ `- Worker session: ${task.workerSession ?? "unassigned"}`,
38842
+ `- Target agent: ${task.targetAgent}`
38843
+ ];
38844
+ if (task.role)
38845
+ header.push(`- Role: ${task.role}`);
38846
+ if (task.groupId)
38847
+ header.push(`- Group: ${task.groupId}`);
38848
+ if (task.status === "needs_confirmation") {
38849
+ header.push(`- Source: ${task.sourceKind} / ${task.sourceHandle}${task.role ? ` / ${task.role}` : ""}`);
38850
+ }
38851
+ header.push(`- Task: ${task.task}`);
38852
+ if (task.summary.trim().length > 0)
38853
+ header.push(`- Summary: ${task.summary}`);
38854
+ if (task.resultText.trim().length > 0)
38855
+ header.push(`- Result: ${task.resultText}`);
38856
+ const events = [];
38857
+ events.push({ at: task.createdAt, event: "created" });
38858
+ if (task.workerSession && task.status !== "needs_confirmation") {
38859
+ events.push({ at: task.createdAt, event: "dispatched", detail: task.workerSession });
38860
+ }
38861
+ if (task.lastProgressAt)
38862
+ events.push({ at: task.lastProgressAt, event: "last progress" });
38863
+ if (task.cancelRequestedAt)
38864
+ events.push({ at: task.cancelRequestedAt, event: "cancel requested" });
38865
+ if (task.cancelCompletedAt)
38866
+ events.push({ at: task.cancelCompletedAt, event: "cancel completed" });
38867
+ if (task.lastCancelError)
38868
+ events.push({ at: task.updatedAt, event: "cancel failed", detail: task.lastCancelError });
38869
+ if (task.status === "completed")
38870
+ events.push({ at: task.updatedAt, event: "completed" });
38871
+ if (task.status === "failed")
38872
+ events.push({ at: task.updatedAt, event: "failed" });
38873
+ if (task.noticeSentAt)
38874
+ events.push({ at: task.noticeSentAt, event: "notice sent", detail: task.deliveryAccountId });
38875
+ if (task.lastNoticeError)
38876
+ events.push({ at: task.updatedAt, event: "notice failed", detail: task.lastNoticeError });
38877
+ if (task.injectionAppliedAt)
38878
+ events.push({ at: task.injectionAppliedAt, event: "injection applied" });
38879
+ if (task.lastInjectionError)
38880
+ events.push({ at: task.updatedAt, event: "injection failed", detail: task.lastInjectionError });
38881
+ events.sort((a, b) => a.at.localeCompare(b.at));
38882
+ const timeline = events.length > 0 ? ["- Timeline:", ...events.map((e) => ` - [${e.at}] ${e.event}${e.detail ? `: ${e.detail}` : ""}`)] : [];
38883
+ return [...header, ...timeline].join(`
38884
+ `);
38885
+ }
38886
+ function renderTaskCancelRequest(task) {
38887
+ if (task.status === "completed" || task.status === "failed" || task.status === "cancelled") {
38888
+ return [`Task "${task.taskId}" has already finished.`, `- Current status: ${task.status}`].join(`
38889
+ `);
38890
+ }
38891
+ return [`Cancellation requested for task "${task.taskId}".`, `- Current status: ${task.status}`].join(`
38892
+ `);
38893
+ }
38894
+ function renderTaskApprovalSuccess(task) {
38895
+ return [`Task "${task.taskId}" approved.`, `- Current status: ${task.status}`].join(`
38896
+ `);
38897
+ }
38898
+ function renderTaskRejectionSuccess(task) {
38899
+ return [`Task "${task.taskId}" rejected.`, `- Current status: ${task.status}`].join(`
38900
+ `);
38901
+ }
38902
+ function renderWorkerRaiseQuestionSuccess(task) {
38903
+ return [`Blocker question submitted for task "${task.taskId}".`, `- questionId: ${task.questionId}`].join(`
38904
+ `);
38905
+ }
38906
+ function renderCoordinatorAnswerQuestionSuccess(task) {
38907
+ return [`Answered the blocker question for task "${task.taskId}".`, `- Current status: ${task.status}`].join(`
38908
+ `);
38909
+ }
38910
+ function renderCoordinatorRequestHumanInputSuccess(result) {
38911
+ return result.packageId ? [`Created human question package "${result.packageId}".`, `- Queued tasks: ${result.queuedTaskIds.length}`].join(`
38912
+ `) : [`Queued the question in the current human question queue.`, `- Queued tasks: ${result.queuedTaskIds.length}`].join(`
38913
+ `);
38914
+ }
38915
+ function renderCoordinatorFollowUpHumanPackageSuccess(result) {
38916
+ return [`Appended follow-up to human package "${result.packageId}".`, `- messageId: ${result.messageId}`].join(`
38917
+ `);
38918
+ }
38919
+ function renderCoordinatorReviewContestedResultSuccess(task, decision) {
38920
+ const actionText = decision === "accept" ? "Accepted" : "Discarded";
38921
+ return [`${actionText} contested result for task "${task.taskId}".`, `- Current status: ${task.status}`].join(`
38922
+ `);
38923
+ }
38705
38924
  function formatToolError(error2) {
38706
38925
  const message = error2 instanceof Error ? error2.message : String(error2);
38707
38926
  if (/ECONNREFUSED|ENOENT|server closed without a response|socket hang up|connect /i.test(message)) {
38708
- return `无法连接到 orchestration daemon:${message}`;
38927
+ return `Failed to connect to the orchestration daemon: ${message}`;
38709
38928
  }
38710
38929
  return message;
38711
38930
  }
@@ -38925,6 +39144,9 @@ function createWeacpxMcpServer(options) {
38925
39144
  return await toolStatePromise;
38926
39145
  }
38927
39146
  toolStatePromise = resolveMcpIdentity(server, options).then((identity) => {
39147
+ if (!options.transport) {
39148
+ throw new Error("weacpx MCP transport is not configured");
39149
+ }
38928
39150
  toolState = buildToolState({
38929
39151
  transport: options.transport,
38930
39152
  coordinatorSession: identity.coordinatorSession,
@@ -38984,7 +39206,7 @@ async function resolveMcpIdentity(server, options) {
38984
39206
  throw new McpError(ErrorCode.InvalidRequest, "weacpx MCP identity is not configured; run through `weacpx mcp-stdio` or provide --coordinator-session");
38985
39207
  }
38986
39208
  async function runWeacpxMcpServer(options) {
38987
- const transport = createOrchestrationTransport(options.endpoint ?? resolveDefaultOrchestrationEndpoint(process.env, process.platform));
39209
+ const transport = options.transport ?? createOrchestrationTransport(options.endpoint ?? resolveDefaultOrchestrationEndpoint(process.env, process.platform));
38988
39210
  const server = createWeacpxMcpServer({
38989
39211
  transport,
38990
39212
  ...options.coordinatorSession ? { coordinatorSession: options.coordinatorSession } : {},
@@ -40765,6 +40987,7 @@ async function defaultMcpStdio(args, deps = {}) {
40765
40987
  let coordinatorSession;
40766
40988
  let sourceHandle;
40767
40989
  let endpoint;
40990
+ let transport;
40768
40991
  let identityResolver;
40769
40992
  let availableAgents;
40770
40993
  try {
@@ -40773,6 +40996,7 @@ async function defaultMcpStdio(args, deps = {}) {
40773
40996
  const workspace = parseCoordinatorWorkspace(args, process.env);
40774
40997
  endpoint = resolveDefaultOrchestrationEndpoint(process.env, process.platform);
40775
40998
  const client = new OrchestrationClient(endpoint);
40999
+ transport = createOrchestrationTransport(endpoint, { client });
40776
41000
  const runtimePaths = (await init_main().then(() => exports_main)).resolveRuntimePaths();
40777
41001
  await ensureConfigExists(runtimePaths.configPath);
40778
41002
  const config2 = await loadConfig(runtimePaths.configPath);
@@ -40786,7 +41010,7 @@ async function defaultMcpStdio(args, deps = {}) {
40786
41010
  state,
40787
41011
  client
40788
41012
  });
40789
- const eagerIdentity = parsedCoordinatorSession && workspace ? await resolveIdentity({ clientName: undefined, listRoots: async () => [] }) : null;
41013
+ const eagerIdentity = parsedCoordinatorSession ? await resolveIdentity({ clientName: undefined, listRoots: async () => [] }) : null;
40790
41014
  coordinatorSession = eagerIdentity?.coordinatorSession ?? "";
40791
41015
  identityResolver = eagerIdentity ? undefined : resolveIdentity;
40792
41016
  } catch (error2) {
@@ -40795,7 +41019,7 @@ async function defaultMcpStdio(args, deps = {}) {
40795
41019
  return 2;
40796
41020
  }
40797
41021
  await runWeacpxMcpServer({
40798
- endpoint,
41022
+ transport,
40799
41023
  ...coordinatorSession ? { coordinatorSession } : {},
40800
41024
  ...sourceHandle ? { sourceHandle } : {},
40801
41025
  ...identityResolver ? { resolveIdentity: identityResolver } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weacpx",
3
- "version": "0.4.0-beta.1",
3
+ "version": "0.4.0-beta.2",
4
4
  "description": "使用微信 ClawBot 随时随地通过 `acpx` 控制 Claude Code、Codex 等 Agents。",
5
5
  "keywords": [
6
6
  "acpx",