wezard 2.8.6 → 2.8.8

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.
Files changed (69) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +2 -0
  3. package/cli/wezard.sh +7 -0
  4. package/dist/cli/codex-hook.js +6 -1
  5. package/dist/cli/codex-hook.js.map +1 -1
  6. package/dist/cli/sync.js +37 -7
  7. package/dist/cli/sync.js.map +1 -1
  8. package/dist/daemon/approval.js +97 -79
  9. package/dist/daemon/approval.js.map +1 -1
  10. package/dist/daemon/danger.js +219 -11
  11. package/dist/daemon/danger.js.map +1 -1
  12. package/dist/daemon/http.js +5 -1
  13. package/dist/daemon/http.js.map +1 -1
  14. package/dist/daemon/inbound.js +33 -0
  15. package/dist/daemon/inbound.js.map +1 -1
  16. package/dist/daemon/index.js +27 -15
  17. package/dist/daemon/index.js.map +1 -1
  18. package/dist/daemon/mcp-http.js +77 -0
  19. package/dist/daemon/mcp-http.js.map +1 -0
  20. package/dist/daemon/message-events.js +3 -1
  21. package/dist/daemon/message-events.js.map +1 -1
  22. package/dist/daemon/mirror-bridge.js +53 -19
  23. package/dist/daemon/mirror-bridge.js.map +1 -1
  24. package/dist/daemon/peers.js +9 -8
  25. package/dist/daemon/peers.js.map +1 -1
  26. package/dist/daemon/pending.js.map +1 -1
  27. package/dist/daemon/picker-policy.js +16 -6
  28. package/dist/daemon/picker-policy.js.map +1 -1
  29. package/dist/daemon/router.js +15 -6
  30. package/dist/daemon/router.js.map +1 -1
  31. package/dist/daemon/session-cache.js.map +1 -1
  32. package/dist/daemon/spawn-tmux.js +5 -1
  33. package/dist/daemon/spawn-tmux.js.map +1 -1
  34. package/dist/daemon/steward-guard.js +2 -13
  35. package/dist/daemon/steward-guard.js.map +1 -1
  36. package/dist/daemon/wizard-names.js +64 -37
  37. package/dist/daemon/wizard-names.js.map +1 -1
  38. package/dist/daemon/wizard.js +13 -4
  39. package/dist/daemon/wizard.js.map +1 -1
  40. package/dist/mcp/server.js +5 -667
  41. package/dist/mcp/server.js.map +1 -1
  42. package/dist/mcp/tools.js +688 -0
  43. package/dist/mcp/tools.js.map +1 -0
  44. package/dist/shared/allow-rules.js +171 -25
  45. package/dist/shared/allow-rules.js.map +1 -1
  46. package/dist/shared/chat-view.js +1 -1
  47. package/dist/shared/chat-view.js.map +1 -1
  48. package/dist/shared/config.js +16 -2
  49. package/dist/shared/config.js.map +1 -1
  50. package/dist/shared/detail-render.js +101 -11
  51. package/dist/shared/detail-render.js.map +1 -1
  52. package/dist/shared/hook-mode.js +31 -0
  53. package/dist/shared/hook-mode.js.map +1 -0
  54. package/dist/shared/modal-pane.js +79 -9
  55. package/dist/shared/modal-pane.js.map +1 -1
  56. package/dist/shared/plan.js +4 -0
  57. package/dist/shared/plan.js.map +1 -1
  58. package/dist/shared/repl-script.js +118 -0
  59. package/dist/shared/repl-script.js.map +1 -0
  60. package/dist/shared/tool-hints.js +28 -4
  61. package/dist/shared/tool-hints.js.map +1 -1
  62. package/dist/shared/turn-state.js +1 -1
  63. package/dist/shared/turn-state.js.map +1 -1
  64. package/dist/shared/world.js +3 -2
  65. package/dist/shared/world.js.map +1 -1
  66. package/hooks/pre-tool-use.sh +48 -5
  67. package/package.json +1 -1
  68. package/web/chat.css +88 -20
  69. package/web/chat.js +136 -18
@@ -5,12 +5,13 @@ import { createPending, getPending, getResolvedSnapshot, resolvePending, resolve
5
5
  import { cacheGet, cachePut, cacheKey, isAutoWindowActive, autoWindowRemainingMs, setAutoWindow, clearAutoWindow, getWindowMeta, } from "./session-cache.js";
6
6
  import { evaluateAllow, ruleMatchesAny, alwaysAllowRulesFor, splitSegments, NEVER_RULE_ALLOW } from "../shared/allow-rules.js";
7
7
  import { redact } from "./redact.js";
8
+ import { readHookMode } from "../shared/hook-mode.js";
8
9
  import { dangerOf, dangerEarlyExit, selfConfigWriteOf } from "./danger.js";
9
10
  import { appendUnique } from "../shared/config-writer.js";
10
11
  import { claudeConfigWrite } from "../shared/claude-config-path.js";
11
12
  import { recordApproval, recordApprovalDecision, buildDetailUrl, getDetail, openTurnsOf, targetOfSession } from "./detail.js";
12
13
  import { json, readBody } from "./http.js";
13
- import { botOfKey, tagBadge, tagOfKey, withTagHeader, withBot } from "../shared/session-label.js";
14
+ import { botOfKey, displayName, tagBadge, tagOfKey, withTagHeader, withBot } from "../shared/session-label.js";
14
15
  import { chatPolicyOf } from "./chat-name.js";
15
16
  import { makeStewardGuard } from "./steward-guard.js";
16
17
  import { sessionNameFor } from "./session-name.js";
@@ -63,15 +64,21 @@ const takeFirstLines = (s, lines, maxChars) => TRUNC(s.split("\n").slice(0, line
63
64
  const EDIT_SNIPPET_LEN = 160;
64
65
  const WRITE_PREVIEW_LINES = 4;
65
66
  const WRITE_PREVIEW_CHARS = 200;
66
- const SOURCE_ICON = "https://wwcdn.weixin.qq.com/node/wework/images/3d-claude-ai-logo.bce0ddae70.jpg";
67
- // Source 行 = 会话身份位: 放会话名 (谁在请求), 让 main_title 整块 13×2 字腾给
68
- // "想干什么"。危险卡只把这行文字变红 (desc_color: 2), 不换文案不加图标 ——
69
- // 红色本身就是信号。会话名缺失时回落品牌名, 不留空行。
70
- const buildSource = (danger, sessionName) => ({
71
- icon_url: SOURCE_ICON,
72
- desc: TRUNC(sessionName || "wezard", 13),
73
- desc_color: danger ? 2 : 0,
74
- });
67
+ const SOURCE_MAX = 13;
68
+ // Source 行 = wizard 的身份位: 🧙 + `.name` (名册里的全局名), 让 main_title 整块
69
+ // 13×2 字腾给"想干什么"。WeCom 的 icon_url 只吃图片 URL, 所以 emoji 写在 desc 里,
70
+ // 不再挂一张 logo 图。危险卡只把这行文字变红 (desc_color: 2), 不换文案 —— 红色本身
71
+ // 就是信号。名字缺失时回落品牌名, 不留空行。
72
+ const buildSource = (danger, who) => {
73
+ const name = (who ?? "").trim().replace(/^[#.]/, "");
74
+ return {
75
+ desc: TRUNC(name ? `🧙 .${name}` : "🧙 wezard", SOURCE_MAX),
76
+ desc_color: danger ? 2 : 0,
77
+ };
78
+ };
79
+ /** 卡片身份位上写谁: wizard 的全局名 (名册里的名字, 也是它唯一的地址); 名册还没
80
+ * 落定才退回会话名 (#tag / CC 会话名 / transcript 首条 / 短 id) —— 那是临时口径。 */
81
+ const cardName = (chatKey, transcriptPath, sessionId) => (chatKey ? displayName(chatKey) : "") || sessionNameFor(chatKey, transcriptPath, sessionId);
75
82
  const prefixLines = (s, prefix) => s.split("\n").map((l) => `${prefix} ${l}`).join("\n");
76
83
  // Flat key:val summary for unknown tools — never dump raw JSON.
77
84
  const UNKNOWN_VAL_LEN = 140;
@@ -189,15 +196,15 @@ const detailJumpList = (url) => url ? [{ type: 1, title: "🔍 完整命令 ·
189
196
  // prefix that outbound mirror bubbles carry — one visual per tag, regardless
190
197
  // of how many times `/clear` rotates the underlying sessionId.
191
198
  const emojiFor = tagBadge;
192
- // ── v3 布局 (2026-07-31 两轮真机反馈后定稿) ──────────────────────────
193
- // 信息优先级: 谁在问(会话名) > 想干什么(desc) > 具体命令 > 上下文。
194
- // source 品牌位; 危险卡文字变红 (仅变色, 不换文案)
195
- // main_title <会话名> · <工具> — 无锁/无 emoji, 纯文字
199
+ // ── 布局 (v3 2026-07-31, source 行 2026-10-27 换成 🧙 + .name) ──────────
200
+ // 信息优先级: 谁在问(wizard 名) > 想干什么(desc) > 具体命令 > 为什么问。
201
+ // source 🧙 .name; 危险卡文字变红 (仅变色, 不换文案)
202
+ // main_title <工具/意图> · <目录>/ — 无锁/无 emoji, 纯文字
196
203
  // quote_area 命令主体 — 无标题, 整块可点跳详情页 (PC); 3 行截断由
197
204
  // 右上⋯展开与详情页兜底
198
- // horizontal 上文 (最近用户消息); 危险卡多一行规则名
205
+ // horizontal 危险 (名单真命中) / 审核 (为什么这次没白名单放行)。
206
+ // 不带「上文」: 人正在干的事在 CLI 里看得见, 卡上只留判断依据。
199
207
  // jump_list 「🔍 完整命令·详情」
200
- // 会话名: #tag (企微发起) > CC 会话名 (本地发起, sessions 注册表) > 首条消息。
201
208
  const HMETA_VAL_MAX = 26;
202
209
  // 一级标题 = Claude 自己写的意图 (tool_input.description), 回答"想干什么" ——
203
210
  // 13×2 字里最值钱的内容。没有 description 的工具 (Read/Write/Edit…) 回落
@@ -214,6 +221,7 @@ const denyReasonText = (d) => {
214
221
  case "substitution": return "含 $() 动态构造,无法白名单";
215
222
  case "unparsable": return "引号未闭合或含后台符 &";
216
223
  case "tool_not_listed": return `${shortTool(d.tool)} 未在白名单`;
224
+ case "repl_opaque": return "内层调用无法识别(动态构造或纯计算)";
217
225
  case "never_allow": return "交互工具,永不免审";
218
226
  // 没配白名单规则 = 用户没在用这套机制, 每张卡都挂这行纯噪声。
219
227
  case "no_rules": return undefined;
@@ -223,18 +231,17 @@ const denyReasonText = (d) => {
223
231
  const shortTool = (toolName) => TRUNC(toolName.replace(/^mcp__/, "").replace(/__/g, ":"), 16);
224
232
  const metaRows = (a) => {
225
233
  const rows = [];
226
- const tail = oneLine(a.transcriptTail).trim();
227
- if (tail)
228
- rows.push({ keyname: "上文", value: TRUNC(tail, HMETA_VAL_MAX) });
229
- // 为什么要人来点这一下 —— 优先级 危险 > 未白名单。danger 命中时命令很可能
230
- // 本来就在白名单里, 再报"未放行"是误导。
234
+ // 为什么要人来点这一下 —— 优先级 危险 > 未白名单 > 必发卡说明。danger 命中时命令很
235
+ // 可能本来就在白名单里, 再报"未放行"是误导; 反过来「屏面看不懂」「askRules 命中」
236
+ // 都不是危险, 只进「审核」行 —— 「危险」行只写名单真命中的那类操作 (rm / DROP / 强推)。
231
237
  if (a.danger) {
232
238
  rows.push({ keyname: "危险", value: TRUNC(`命中「${a.danger}」`, HMETA_VAL_MAX) });
233
239
  }
234
- else if (a.denyReason) {
235
- const why = denyReasonText(a.denyReason);
236
- if (why)
237
- rows.push({ keyname: "审核", value: TRUNC(why, HMETA_VAL_MAX) });
240
+ else if (a.denyReason && denyReasonText(a.denyReason)) {
241
+ rows.push({ keyname: "审核", value: TRUNC(denyReasonText(a.denyReason), HMETA_VAL_MAX) });
242
+ }
243
+ else if (a.singleNote) {
244
+ rows.push({ keyname: "审核", value: TRUNC(a.singleNote, HMETA_VAL_MAX) });
238
245
  }
239
246
  return rows.length > 0 ? rows : undefined;
240
247
  };
@@ -413,13 +420,10 @@ const renderBatchBody = (batch) => {
413
420
  lines.push(`…还有 ${overflow} 项`);
414
421
  return TRUNC(lines.join("\n"), QUOTE_MAX);
415
422
  };
416
- // 批量卡的标题/中段与单卡同构 (会话名 + 工具×N / 成员列表进引用区)。
423
+ // 批量卡的标题/中段与单卡同构 (身份位 + 工具×N / 成员列表进引用区)。
417
424
  const batchTitle = (batch) => `${batch.sessionName || batch.sessionId.slice(-8)} · ${shortTool(batch.toolName)} ×${batch.members.length}`;
418
- const batchBlocks = (batch, transcriptTail) => {
425
+ const batchBlocks = (batch) => {
419
426
  const rows = [];
420
- const tail = oneLine(transcriptTail).trim();
421
- if (tail)
422
- rows.push({ keyname: "上文", value: TRUNC(tail, HMETA_VAL_MAX) });
423
427
  if (batch.danger)
424
428
  rows.push({ keyname: "危险", value: TRUNC(`命中「${batch.danger}」`, HMETA_VAL_MAX) });
425
429
  return {
@@ -427,11 +431,11 @@ const batchBlocks = (batch, transcriptTail) => {
427
431
  ...(rows.length > 0 ? { horizontal_content_list: rows } : {}),
428
432
  };
429
433
  };
430
- const buildBatchCard = (batch, transcriptTail) => ({
434
+ const buildBatchCard = (batch) => ({
431
435
  card_type: "button_interaction",
432
436
  source: buildSource(batch.danger, batch.sessionName),
433
437
  main_title: { title: batchTitle(batch) },
434
- ...batchBlocks(batch, transcriptTail),
438
+ ...batchBlocks(batch),
435
439
  task_id: batch.batchId,
436
440
  button_list: [
437
441
  { text: "❌", style: 4, key: encodeBatchKey(batch.batchId, "deny") },
@@ -442,7 +446,7 @@ const buildBatchCard = (batch, transcriptTail) => ({
442
446
  { text: `✅ ×${batch.members.length}`, style: 4, key: encodeBatchKey(batch.batchId, "allow") },
443
447
  ],
444
448
  });
445
- const buildBatchResolvedCard = (batch, decision, transcriptTail) => {
449
+ const buildBatchResolvedCard = (batch, decision) => {
446
450
  const button = decision === "allow_window"
447
451
  ? {
448
452
  text: `${verbOf(decision, batch.windowMinutes)} · 点击取消`,
@@ -458,16 +462,16 @@ const buildBatchResolvedCard = (batch, decision, transcriptTail) => {
458
462
  card_type: "button_interaction",
459
463
  source: buildSource(batch.danger, batch.sessionName),
460
464
  main_title: { title: batchTitle(batch) },
461
- ...batchBlocks(batch, transcriptTail),
465
+ ...batchBlocks(batch),
462
466
  task_id: batch.batchId,
463
467
  button_list: [button],
464
468
  };
465
469
  };
466
- const buildBatchAlreadyResolvedCard = (batch, transcriptTail) => ({
470
+ const buildBatchAlreadyResolvedCard = (batch) => ({
467
471
  card_type: "button_interaction",
468
472
  source: buildSource(batch.danger, batch.sessionName),
469
473
  main_title: { title: batchTitle(batch) },
470
- ...batchBlocks(batch, transcriptTail),
474
+ ...batchBlocks(batch),
471
475
  task_id: batch.batchId,
472
476
  button_list: [{ text: "已经放行", style: 4, key: encodeBatchNoopKey(batch.batchId) }],
473
477
  });
@@ -570,11 +574,10 @@ export const buildAskqMarkdown = (q, prefix = "") => {
570
574
  });
571
575
  return [head, "", ...opts].join("\n");
572
576
  };
573
- export const buildAskqCard = (reqId, q, transcriptTail, approver) => {
574
- const tail = oneLine(transcriptTail).trim();
577
+ export const buildAskqCard = (reqId, q, approver) => {
575
578
  return {
576
579
  card_type: "vote_interaction",
577
- source: buildSource(undefined, tail),
580
+ source: buildSource(undefined, cardName(approver)),
578
581
  main_title: { title: TRUNC(`🤔 ${emojiFor(approver)}${q.header || "请选择"}`, ASKQ_TITLE_MAX) },
579
582
  task_id: reqId,
580
583
  checkbox: {
@@ -596,7 +599,7 @@ export const buildAskqCard = (reqId, q, transcriptTail, approver) => {
596
599
  };
597
600
  // 投票卡 submit 后那张卡再被点 (askq_noop:<id>) → 终态 identity, 直接 return,
598
601
  // 不再 stash 任何 outcome / question 副本。
599
- const buildAskqResolvedCard = (reqId, q, outcome, transcriptTail, approver) => {
602
+ const buildAskqResolvedCard = (reqId, q, outcome, approver) => {
600
603
  const summary = outcome.kind === "cli"
601
604
  ? "🖥️ 已转 CLI 中处理"
602
605
  : outcome.kind === "chat"
@@ -604,10 +607,9 @@ const buildAskqResolvedCard = (reqId, q, outcome, transcriptTail, approver) => {
604
607
  : outcome.kind === "empty"
605
608
  ? "⚠️ 未选择"
606
609
  : `✅ ${outcome.picked.map((i) => q.options[i]?.label ?? `#${i}`).join(", ")}`;
607
- const tail = oneLine(transcriptTail).trim();
608
610
  return {
609
611
  card_type: "button_interaction",
610
- source: buildSource(undefined, tail),
612
+ source: buildSource(undefined, cardName(approver)),
611
613
  main_title: { title: TRUNC(`🤔 ${emojiFor(approver)}${q.header || "已回答"}`, ASKQ_TITLE_MAX) },
612
614
  sub_title_text: TRUNC(q.question, ASKQ_SUB_MAX),
613
615
  task_id: reqId,
@@ -748,13 +750,12 @@ const buildPlanMarkdown = (plan) => {
748
750
  }
749
751
  return `**📋 计划待审批**\n\n${body}`;
750
752
  };
751
- const buildPlanCard = (reqId, _sessionId, cwd, transcriptTail, approver, hasPlan) => {
752
- const tail = oneLine(transcriptTail).trim();
753
+ const buildPlanCard = (reqId, cwd, approver, hasPlan) => {
753
754
  const tag = emojiFor(approver);
754
755
  const dir = dirName(cwd);
755
756
  return {
756
757
  card_type: "button_interaction",
757
- source: buildSource(undefined, tail),
758
+ source: buildSource(undefined, cardName(approver)),
758
759
  main_title: { title: TRUNC(`📋 计划审批 · ${tag}${dir}/`, PLAN_TITLE_MAX + 12) },
759
760
  sub_title_text: hasPlan
760
761
  ? "审阅上方计划后选择:同意开始执行,或让 Agent 继续完善。"
@@ -766,13 +767,12 @@ const buildPlanCard = (reqId, _sessionId, cwd, transcriptTail, approver, hasPlan
766
767
  ],
767
768
  };
768
769
  };
769
- const buildPlanResolvedCard = (reqId, action, cwd, transcriptTail, approver) => {
770
- const tail = oneLine(transcriptTail).trim();
770
+ const buildPlanResolvedCard = (reqId, action, cwd, approver) => {
771
771
  const dir = dirName(cwd);
772
772
  const summary = action === "approve" ? "✅ 已同意 · 开始执行" : "✏️ 继续完善计划";
773
773
  return {
774
774
  card_type: "button_interaction",
775
- source: buildSource(undefined, tail),
775
+ source: buildSource(undefined, cardName(approver)),
776
776
  main_title: { title: TRUNC(`📋 计划 · ${emojiFor(approver)}${dir}/`, PLAN_TITLE_MAX + 12) },
777
777
  task_id: reqId,
778
778
  button_list: [{ text: summary, style: 4, key: encodePlanNoopKey(reqId) }],
@@ -829,7 +829,7 @@ const handleExitPlanMode = async ({ cfg, log, client, body, getMirrorTarget, flu
829
829
  }
830
830
  await client.sendMessage(target, {
831
831
  msgtype: "template_card",
832
- template_card: buildPlanCard(reqId, body.session_id, body.cwd ?? "", body.transcript_tail ?? "", approver, true),
832
+ template_card: buildPlanCard(reqId, body.cwd ?? "", approver, true),
833
833
  });
834
834
  log.info({ reqId, approver }, "plan card sent");
835
835
  }
@@ -985,7 +985,7 @@ export const runMirrorAskqFlow = async ({ cfg, log, client, sessionId, chatKey,
985
985
  }
986
986
  await client.sendMessage(target, {
987
987
  msgtype: "template_card",
988
- template_card: buildAskqCard(reqId, q, "", chatKey),
988
+ template_card: buildAskqCard(reqId, q, chatKey),
989
989
  });
990
990
  log.info({ reqId, chatKey, idx: i, total }, "mirror askq card sent");
991
991
  }
@@ -1124,7 +1124,7 @@ export const runMirrorPlanFlow = async ({ cfg, log, client, sessionId, chatKey,
1124
1124
  }
1125
1125
  await client.sendMessage(target, {
1126
1126
  msgtype: "template_card",
1127
- template_card: buildPlanCard(reqId, sessionId, cwd, "", chatKey, Boolean(plan)),
1127
+ template_card: buildPlanCard(reqId, cwd, chatKey, Boolean(plan)),
1128
1128
  });
1129
1129
  log.info({ reqId, chatKey }, "mirror plan card sent");
1130
1130
  }
@@ -1157,8 +1157,8 @@ export const runMirrorPlanFlow = async ({ cfg, log, client, sessionId, chatKey,
1157
1157
  await note("⚠️ 已记录选择,但本地对话框按键注入失败,请回到 CLI 手动处理。");
1158
1158
  return;
1159
1159
  }
1160
+ // 计划卡同款: 结论已在卡片终态, 不再发跟帖。
1160
1161
  log.info({ reqId, sessionId, approve }, "mirror plan resolved via send-keys");
1161
- await note(approve ? "✅ 已同意,退出 plan mode 开始执行…" : "✏️ 已选择继续完善计划。");
1162
1162
  };
1163
1163
  const mirrorPickerSlots = new Map();
1164
1164
  const MIRROR_PICKER_SLOT_TTL_MS = 12 * 3600_000; // 与 approval.longPollSec 对齐
@@ -1200,7 +1200,7 @@ const consumePickerAllow = (sessionId, toolName) => {
1200
1200
  return Date.now() - at <= RECENT_PICKER_TTL_MS;
1201
1201
  };
1202
1202
  /** 返回「卡是否真的发出去了」— false (WS 断 / 发送失败) 时调用方应允许对同屏重试。 */
1203
- export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey, cwd, jsonlPath, toolName, toolInput, agent, danger, voteTimeoutMs, press }) => {
1203
+ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey, cwd, jsonlPath, toolName, toolInput, agent, danger, singleNote, voteTimeoutMs, press }) => {
1204
1204
  if (!canReach(client, chatKey))
1205
1205
  return false;
1206
1206
  const target = targetChatId(chatKey);
@@ -1211,7 +1211,7 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1211
1211
  catch { /* best-effort */ }
1212
1212
  };
1213
1213
  const tail = agent ? `子代理 ${agent} 的原生权限确认` : "CLI 原生权限确认";
1214
- const sessionName = sessionNameFor(chatKey, jsonlPath, sessionId);
1214
+ const sessionName = cardName(chatKey, jsonlPath, sessionId);
1215
1215
  const { reqId, promise } = createPending({
1216
1216
  meta: {
1217
1217
  kind: "generic",
@@ -1223,7 +1223,8 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1223
1223
  chatKey,
1224
1224
  transcriptTail: tail,
1225
1225
  danger,
1226
- forceSingle: Boolean(danger),
1226
+ singleNote,
1227
+ forceSingle: Boolean(danger || singleNote),
1227
1228
  sessionName,
1228
1229
  },
1229
1230
  timeoutMs: voteTimeoutMs,
@@ -1241,10 +1242,10 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1241
1242
  sessionShort: sessionId.slice(-8),
1242
1243
  sessionId,
1243
1244
  chatKey,
1244
- transcriptTail: tail,
1245
1245
  windowMinutes: cfg.approval.windowMinutes,
1246
1246
  danger,
1247
- forceSingle: Boolean(danger),
1247
+ singleNote,
1248
+ forceSingle: Boolean(danger || singleNote),
1248
1249
  sessionName,
1249
1250
  }),
1250
1251
  });
@@ -1275,13 +1276,16 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1275
1276
  const d = raw;
1276
1277
  if (d === "deny") {
1277
1278
  const r = await press("no");
1278
- await note(r.ok
1279
- ? `🚫 已替你拒绝 CLI 权限确认(${toolName})→ ${r.label ?? "Escape"}`
1280
- : `⚠️ 已记录拒绝,但代按失败(${r.reason ?? "未知"}),请回 CLI 处理。`);
1279
+ // 代按成功不补发消息: 卡片已被 updateTemplateCard 收成「❌ 已拒绝」终态,
1280
+ // 群里再贴一条纯属噪音。只有按失败才需要人回 CLI 接手。
1281
+ if (!r.ok)
1282
+ await note(`⚠️ 已记录拒绝,但代按失败(${r.reason ?? "未知"}),请回 CLI 处理。`);
1281
1283
  return true;
1282
1284
  }
1283
1285
  if (d === "allow_window" && cfg.approval.windowMinutes > 0) {
1284
- setAutoWindow(chatKey, cfg.approval.windowMinutes * 60_000, { toolName, toolInput, cwd, transcriptTail: tail });
1286
+ setAutoWindow(chatKey, cfg.approval.windowMinutes * 60_000, {
1287
+ toolName, toolInput, cwd, transcriptTail: tail, danger, singleNote, sessionName,
1288
+ });
1285
1289
  // 与 handler 的 allow_window 同款 sweep: 同 chat 其它 pending 卡一并放行。
1286
1290
  const swept = resolvePendingsByChat(chatKey, "allow_window", reqId);
1287
1291
  log.info({ chatKey, minutes: cfg.approval.windowMinutes, swept: swept.length }, "auto-window opened via picker card");
@@ -1297,9 +1301,8 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1297
1301
  // 代按成功 → CLI 才真正派发工具 → hook 此刻才会上报同一调用; 预先记账让
1298
1302
  // handler 直接放行, 不再发第二张卡 (consumePickerAllow)。
1299
1303
  recordPickerAllow(sessionId, toolName);
1300
- await note(wantSession
1301
- ? `🔓 已代按「本会话不再询问」(${toolName})→ ${r.label ?? ""}\n原生确认框不过 hook,「总是」规则帮不上它,已翻译成 CLI 的会话级免问。`
1302
- : `🔓 已代按 CLI 权限确认(${toolName})→ ${r.label ?? "Yes"}${d === "allow_window" ? `,并开启 ${cfg.approval.windowMinutes} 分钟自动放行窗口` : ""}`);
1304
+ // 代按成功同样不补发消息 —— 结果 (含「本会话通过」/「N 分钟会话内全过」)
1305
+ // 已经落在卡片终态按钮上, 那是人真正会回头核对的地方。失败才发一条。
1303
1306
  log.info({ reqId, sessionId, decision: d, pressed: r.label }, "mirror picker resolved via send-keys");
1304
1307
  return true;
1305
1308
  }
@@ -1388,7 +1391,7 @@ const handleAskUserQuestion = async ({ cfg, log, client, body, getMirrorTarget,
1388
1391
  }
1389
1392
  await client.sendMessage(target, {
1390
1393
  msgtype: "template_card",
1391
- template_card: buildAskqCard(reqId, q, body.transcript_tail ?? "", approver),
1394
+ template_card: buildAskqCard(reqId, q, approver),
1392
1395
  });
1393
1396
  log.info({ reqId, approver, idx: i, total }, "askq card sent");
1394
1397
  }
@@ -1571,8 +1574,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1571
1574
  return;
1572
1575
  const r = await nm.answer(sessionId, { waitMs: cfg.approval.claudeConfigModalWaitMs });
1573
1576
  if (r.status === "answered") {
1574
- log.info({ sessionId, path: hit.path, pressed: `${r.index}. ${r.label}` }, "claude-config modal answered");
1575
- await notify(approver, `🔓 已代按 CLI 原生确认框「${r.title ?? "确认"}」→ 选项 ${r.index}. ${r.label}(${hit.path})`);
1577
+ // 只在日志里留痕: 这张卡 (人点的那张) 已是「✅ 已通过」终态, 代按原生框是
1578
+ // 它的完成动作, 不必再往群里贴一条。按不掉时下面的告警照发。
1579
+ log.info({ sessionId, path: hit.path, pressed: `${r.index}. ${r.label}`, title: r.title }, "claude-config modal answered");
1576
1580
  return;
1577
1581
  }
1578
1582
  if (r.status === "no_modal") {
@@ -1620,7 +1624,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1620
1624
  activeBatches.delete(batchKeyOf(batch.sessionId, batch.toolName, batch.chatId));
1621
1625
  const isMulti = batch.members.length > 1;
1622
1626
  const card = isMulti
1623
- ? buildBatchCard(batch, batch.members[0]?.transcriptTail ?? "")
1627
+ ? buildBatchCard(batch)
1624
1628
  : (() => {
1625
1629
  const m = batch.members[0];
1626
1630
  return buildCard({
@@ -1635,7 +1639,6 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1635
1639
  // the emoji (only tagged sessions get it now). Also flows through
1636
1640
  // to the resolved card's cancel key path.
1637
1641
  chatKey: batch.approver,
1638
- transcriptTail: m.transcriptTail,
1639
1642
  windowMinutes: batch.windowMinutes,
1640
1643
  danger: batch.danger,
1641
1644
  forceSingle: batch.forceSingle,
@@ -1694,6 +1697,12 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1694
1697
  json(res, 200, { decision: "ask", reason: "approval_disabled" });
1695
1698
  return;
1696
1699
  }
1700
+ // `wezard use cli`: 审批权已经交回本地 CLI, 这里再造一张卡就是「两处都能点」。
1701
+ // 回 ask 让 hook / codex 的 PermissionRequest 都走 CLI 自己的权限流程。
1702
+ if (readHookMode(cfg.daemon.stateDir) === "cli") {
1703
+ json(res, 200, { decision: "ask", reason: "hook_mode_cli" });
1704
+ return;
1705
+ }
1697
1706
  const body = (await readBody(req));
1698
1707
  const nativePermission = body.cli_backend === "codex" && body.hook_event_name === "PermissionRequest";
1699
1708
  let sessionId = body.session_id ?? "";
@@ -1795,6 +1804,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1795
1804
  // 必发卡 = 危险名单 或 askRules 命中。这两者的语义是「每次都要人单独看一眼」,
1796
1805
  // 所以压过放行/窗口/缓存。守卫不在其列 —— 见上面 settleGuard 的注释。
1797
1806
  const mustCard = nativePermission || Boolean(danger) || Boolean(askHit);
1807
+ // 必发卡但不是危险的理由 — 卡片「审核」行 (askRules = 人自己要求每次问;
1808
+ // 危险名单命中由 danger 自己走「危险」行, 不在这里重复)。
1809
+ const singleNote = askHit ? `命中 askRules「${askHit}」` : undefined;
1798
1810
  // allowRules: matcher 拦下的工具里再挖细粒度豁免 (Bash 可按命令前缀区分)。
1799
1811
  // 交互卡工具 (AskUserQuestion 等) 在引擎内部硬保护, 规则写了也不放行。
1800
1812
  // 用 evaluateAllow 而非 ruleAllows: 未命中时要把"因为哪一段"带到卡上,
@@ -1966,7 +1978,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1966
1978
  const longPollMs = cfg.approval.longPollSec * 1000;
1967
1979
  // 卡片标题上的会话身份 — 发卡前算一次, 存进 meta 供 resolved 卡复用
1968
1980
  // (#tag 直接取; 否则读 transcript 首条用户消息, 带缓存)。
1969
- const sessionName = sessionNameFor(approver, body.transcript_path, sessionId);
1981
+ const sessionName = cardName(approver, body.transcript_path, sessionId);
1970
1982
  // Reload 续接: hook 带着上一轮的 req_id 回来, 复用同一个 id 重新挂起 ——
1971
1983
  // WeCom 上那张卡的按钮编的就是它, 于是旧卡的点击照样能 resolve 这次长轮询。
1972
1984
  const resumeId = (body.resume_req_id ?? "").trim();
@@ -1981,6 +1993,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1981
1993
  chatKey: approver,
1982
1994
  transcriptTail,
1983
1995
  danger: danger?.rule,
1996
+ singleNote,
1984
1997
  forceSingle: mustCard,
1985
1998
  sessionName,
1986
1999
  denyReason,
@@ -2001,7 +2014,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
2001
2014
  // 创建 batch + 计时器, 后续到达者只追加成员, 不发卡。flush 时依据成员数
2002
2015
  // 选择普通 buildCard 或 buildBatchCard。0 = 关闭聚合, 立即 flush。
2003
2016
  // 续接的请求不再进 batch: 卡已经在群里, 重发就是重复轰炸。
2004
- const member = { reqId, toolInput: display, originalToolInput: toolInput, toolInputStr, cwd, transcriptTail };
2017
+ const member = { reqId, toolInput: display, originalToolInput: toolInput, toolInputStr, cwd };
2005
2018
  const bk = batchKeyOf(sessionId, toolName, chatId);
2006
2019
  // 必发卡请求既不 join 也不被 join — 一次这样的操作 = 一张卡 = 一次点击。
2007
2020
  // 合流会把它塞进带「⏱全过 / ✅总是」的批量卡, 一次点击就连它一起放行了。
@@ -2122,6 +2135,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
2122
2135
  toolInput: display,
2123
2136
  cwd,
2124
2137
  transcriptTail,
2138
+ danger: danger?.rule,
2139
+ sessionName,
2140
+ singleNote,
2125
2141
  });
2126
2142
  // 同一个 chat 里其它 pending 卡 (可能来自并发同 turn, 也可能来自绑到
2127
2143
  // 同一个 chat 的别的 session) — 一并放行,免得用户逐个点。
@@ -2263,7 +2279,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2263
2279
  log.info({ reqId: askq.reqId, outcome, ok }, "askq event resolved");
2264
2280
  if (q) {
2265
2281
  try {
2266
- await client.updateTemplateCard(frame, buildAskqResolvedCard(cbTaskId || askq.reqId, q, outcome, meta?.transcriptTail ?? "", meta?.chatKey));
2282
+ await client.updateTemplateCard(frame, buildAskqResolvedCard(cbTaskId || askq.reqId, q, outcome, meta?.chatKey));
2267
2283
  }
2268
2284
  catch (e) {
2269
2285
  log.warn({ err: e.message, reqId: askq.reqId }, "askq updateTemplateCard failed");
@@ -2311,7 +2327,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2311
2327
  const ok = resolvePending(planClick.reqId, `${PLAN_PICKED_PREFIX}${planClick.action}`);
2312
2328
  log.info({ reqId: planClick.reqId, action: planClick.action, ok }, "plan event resolved");
2313
2329
  try {
2314
- await client.updateTemplateCard(frame, buildPlanResolvedCard(cbTaskId || planClick.reqId, planClick.action, meta?.cwd ?? "", meta?.transcriptTail ?? "", meta?.chatKey));
2330
+ await client.updateTemplateCard(frame, buildPlanResolvedCard(cbTaskId || planClick.reqId, planClick.action, meta?.cwd ?? "", meta?.chatKey));
2315
2331
  }
2316
2332
  catch (e) {
2317
2333
  log.warn({ err: e.message, reqId: planClick.reqId }, "plan updateTemplateCard failed");
@@ -2347,10 +2363,9 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2347
2363
  if (resolved > 0)
2348
2364
  onApproved?.(batch.sessionId);
2349
2365
  try {
2350
- const tail = batch.members[0]?.transcriptTail ?? "";
2351
2366
  const card = allSwept
2352
- ? buildBatchAlreadyResolvedCard(batch, tail)
2353
- : buildBatchResolvedCard(batch, batchDec.decision, tail);
2367
+ ? buildBatchAlreadyResolvedCard(batch)
2368
+ : buildBatchResolvedCard(batch, batchDec.decision);
2354
2369
  await client.updateTemplateCard(frame, card);
2355
2370
  log.info({ batchId: batch.batchId, decision: batchDec.decision, allSwept }, "batch card updated in place");
2356
2371
  }
@@ -2388,8 +2403,10 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2388
2403
  cwd: wmeta?.cwd ?? "",
2389
2404
  sessionShort: "?",
2390
2405
  chatKey: decoded.cancelChatKey,
2391
- transcriptTail: wmeta?.transcriptTail ?? "",
2392
2406
  windowMinutes: cfg.approval.windowMinutes,
2407
+ danger: wmeta?.danger,
2408
+ sessionName: wmeta?.sessionName,
2409
+ singleNote: wmeta?.singleNote,
2393
2410
  detailUrl: cbTaskId ? detailUrlFor(cbTaskId, decoded.cancelChatKey) : undefined,
2394
2411
  }));
2395
2412
  log.info({ chatKey: decoded.cancelChatKey, cbTaskId }, "cancel card updated in place");
@@ -2462,10 +2479,11 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2462
2479
  sessionShort,
2463
2480
  sessionId: meta?.sessionId ?? "",
2464
2481
  chatKey: meta?.chatKey ?? "",
2465
- transcriptTail: meta?.transcriptTail ?? "",
2466
2482
  windowMinutes: cfg.approval.windowMinutes,
2483
+ danger: meta?.danger,
2467
2484
  sessionName: meta?.sessionName,
2468
2485
  denyReason: meta?.denyReason,
2486
+ singleNote: meta?.singleNote,
2469
2487
  detailUrl: detailUrlFor(reqId, meta?.chatKey),
2470
2488
  })
2471
2489
  : buildResolvedCard({
@@ -2475,7 +2493,6 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2475
2493
  toolInputStr,
2476
2494
  cwd: meta?.cwd ?? "",
2477
2495
  sessionShort,
2478
- transcriptTail: meta?.transcriptTail ?? "",
2479
2496
  windowMinutes: cfg.approval.windowMinutes,
2480
2497
  decision: effectiveDecision,
2481
2498
  by,
@@ -2484,6 +2501,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2484
2501
  danger: meta?.danger,
2485
2502
  sessionName: meta?.sessionName,
2486
2503
  denyReason: meta?.denyReason,
2504
+ singleNote: meta?.singleNote,
2487
2505
  detailUrl: detailUrlFor(reqId, meta?.chatKey),
2488
2506
  });
2489
2507
  await client.updateTemplateCard(frame, card);