wezard 2.8.6 → 2.8.7

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 (65) 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 +83 -69
  9. package/dist/daemon/approval.js.map +1 -1
  10. package/dist/daemon/danger.js +20 -3
  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 +11 -7
  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 +1 -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/repl-script.js +22 -0
  30. package/dist/daemon/repl-script.js.map +1 -0
  31. package/dist/daemon/router.js +15 -6
  32. package/dist/daemon/router.js.map +1 -1
  33. package/dist/daemon/session-cache.js.map +1 -1
  34. package/dist/daemon/spawn-tmux.js +5 -1
  35. package/dist/daemon/spawn-tmux.js.map +1 -1
  36. package/dist/daemon/steward-guard.js +2 -13
  37. package/dist/daemon/steward-guard.js.map +1 -1
  38. package/dist/daemon/wizard.js +1 -1
  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/chat-view.js +1 -1
  45. package/dist/shared/chat-view.js.map +1 -1
  46. package/dist/shared/config.js +16 -2
  47. package/dist/shared/config.js.map +1 -1
  48. package/dist/shared/detail-render.js +2 -1
  49. package/dist/shared/detail-render.js.map +1 -1
  50. package/dist/shared/hook-mode.js +31 -0
  51. package/dist/shared/hook-mode.js.map +1 -0
  52. package/dist/shared/modal-pane.js +79 -9
  53. package/dist/shared/modal-pane.js.map +1 -1
  54. package/dist/shared/plan.js +4 -0
  55. package/dist/shared/plan.js.map +1 -1
  56. package/dist/shared/tool-hints.js +13 -4
  57. package/dist/shared/tool-hints.js.map +1 -1
  58. package/dist/shared/turn-state.js +1 -1
  59. package/dist/shared/turn-state.js.map +1 -1
  60. package/dist/shared/world.js +3 -2
  61. package/dist/shared/world.js.map +1 -1
  62. package/hooks/pre-tool-use.sh +48 -5
  63. package/package.json +1 -1
  64. package/web/chat.css +88 -20
  65. 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…) 回落
@@ -223,18 +230,17 @@ const denyReasonText = (d) => {
223
230
  const shortTool = (toolName) => TRUNC(toolName.replace(/^mcp__/, "").replace(/__/g, ":"), 16);
224
231
  const metaRows = (a) => {
225
232
  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
- // 本来就在白名单里, 再报"未放行"是误导。
233
+ // 为什么要人来点这一下 —— 优先级 危险 > 未白名单 > 必发卡说明。danger 命中时命令很
234
+ // 可能本来就在白名单里, 再报"未放行"是误导; 反过来「屏面看不懂」「askRules 命中」
235
+ // 都不是危险, 只进「审核」行 —— 「危险」行只写名单真命中的那类操作 (rm / DROP / 强推)。
231
236
  if (a.danger) {
232
237
  rows.push({ keyname: "危险", value: TRUNC(`命中「${a.danger}」`, HMETA_VAL_MAX) });
233
238
  }
234
- else if (a.denyReason) {
235
- const why = denyReasonText(a.denyReason);
236
- if (why)
237
- rows.push({ keyname: "审核", value: TRUNC(why, HMETA_VAL_MAX) });
239
+ else if (a.denyReason && denyReasonText(a.denyReason)) {
240
+ rows.push({ keyname: "审核", value: TRUNC(denyReasonText(a.denyReason), HMETA_VAL_MAX) });
241
+ }
242
+ else if (a.singleNote) {
243
+ rows.push({ keyname: "审核", value: TRUNC(a.singleNote, HMETA_VAL_MAX) });
238
244
  }
239
245
  return rows.length > 0 ? rows : undefined;
240
246
  };
@@ -413,13 +419,10 @@ const renderBatchBody = (batch) => {
413
419
  lines.push(`…还有 ${overflow} 项`);
414
420
  return TRUNC(lines.join("\n"), QUOTE_MAX);
415
421
  };
416
- // 批量卡的标题/中段与单卡同构 (会话名 + 工具×N / 成员列表进引用区)。
422
+ // 批量卡的标题/中段与单卡同构 (身份位 + 工具×N / 成员列表进引用区)。
417
423
  const batchTitle = (batch) => `${batch.sessionName || batch.sessionId.slice(-8)} · ${shortTool(batch.toolName)} ×${batch.members.length}`;
418
- const batchBlocks = (batch, transcriptTail) => {
424
+ const batchBlocks = (batch) => {
419
425
  const rows = [];
420
- const tail = oneLine(transcriptTail).trim();
421
- if (tail)
422
- rows.push({ keyname: "上文", value: TRUNC(tail, HMETA_VAL_MAX) });
423
426
  if (batch.danger)
424
427
  rows.push({ keyname: "危险", value: TRUNC(`命中「${batch.danger}」`, HMETA_VAL_MAX) });
425
428
  return {
@@ -427,11 +430,11 @@ const batchBlocks = (batch, transcriptTail) => {
427
430
  ...(rows.length > 0 ? { horizontal_content_list: rows } : {}),
428
431
  };
429
432
  };
430
- const buildBatchCard = (batch, transcriptTail) => ({
433
+ const buildBatchCard = (batch) => ({
431
434
  card_type: "button_interaction",
432
435
  source: buildSource(batch.danger, batch.sessionName),
433
436
  main_title: { title: batchTitle(batch) },
434
- ...batchBlocks(batch, transcriptTail),
437
+ ...batchBlocks(batch),
435
438
  task_id: batch.batchId,
436
439
  button_list: [
437
440
  { text: "❌", style: 4, key: encodeBatchKey(batch.batchId, "deny") },
@@ -442,7 +445,7 @@ const buildBatchCard = (batch, transcriptTail) => ({
442
445
  { text: `✅ ×${batch.members.length}`, style: 4, key: encodeBatchKey(batch.batchId, "allow") },
443
446
  ],
444
447
  });
445
- const buildBatchResolvedCard = (batch, decision, transcriptTail) => {
448
+ const buildBatchResolvedCard = (batch, decision) => {
446
449
  const button = decision === "allow_window"
447
450
  ? {
448
451
  text: `${verbOf(decision, batch.windowMinutes)} · 点击取消`,
@@ -458,16 +461,16 @@ const buildBatchResolvedCard = (batch, decision, transcriptTail) => {
458
461
  card_type: "button_interaction",
459
462
  source: buildSource(batch.danger, batch.sessionName),
460
463
  main_title: { title: batchTitle(batch) },
461
- ...batchBlocks(batch, transcriptTail),
464
+ ...batchBlocks(batch),
462
465
  task_id: batch.batchId,
463
466
  button_list: [button],
464
467
  };
465
468
  };
466
- const buildBatchAlreadyResolvedCard = (batch, transcriptTail) => ({
469
+ const buildBatchAlreadyResolvedCard = (batch) => ({
467
470
  card_type: "button_interaction",
468
471
  source: buildSource(batch.danger, batch.sessionName),
469
472
  main_title: { title: batchTitle(batch) },
470
- ...batchBlocks(batch, transcriptTail),
473
+ ...batchBlocks(batch),
471
474
  task_id: batch.batchId,
472
475
  button_list: [{ text: "已经放行", style: 4, key: encodeBatchNoopKey(batch.batchId) }],
473
476
  });
@@ -570,11 +573,10 @@ export const buildAskqMarkdown = (q, prefix = "") => {
570
573
  });
571
574
  return [head, "", ...opts].join("\n");
572
575
  };
573
- export const buildAskqCard = (reqId, q, transcriptTail, approver) => {
574
- const tail = oneLine(transcriptTail).trim();
576
+ export const buildAskqCard = (reqId, q, approver) => {
575
577
  return {
576
578
  card_type: "vote_interaction",
577
- source: buildSource(undefined, tail),
579
+ source: buildSource(undefined, cardName(approver)),
578
580
  main_title: { title: TRUNC(`🤔 ${emojiFor(approver)}${q.header || "请选择"}`, ASKQ_TITLE_MAX) },
579
581
  task_id: reqId,
580
582
  checkbox: {
@@ -596,7 +598,7 @@ export const buildAskqCard = (reqId, q, transcriptTail, approver) => {
596
598
  };
597
599
  // 投票卡 submit 后那张卡再被点 (askq_noop:<id>) → 终态 identity, 直接 return,
598
600
  // 不再 stash 任何 outcome / question 副本。
599
- const buildAskqResolvedCard = (reqId, q, outcome, transcriptTail, approver) => {
601
+ const buildAskqResolvedCard = (reqId, q, outcome, approver) => {
600
602
  const summary = outcome.kind === "cli"
601
603
  ? "🖥️ 已转 CLI 中处理"
602
604
  : outcome.kind === "chat"
@@ -604,10 +606,9 @@ const buildAskqResolvedCard = (reqId, q, outcome, transcriptTail, approver) => {
604
606
  : outcome.kind === "empty"
605
607
  ? "⚠️ 未选择"
606
608
  : `✅ ${outcome.picked.map((i) => q.options[i]?.label ?? `#${i}`).join(", ")}`;
607
- const tail = oneLine(transcriptTail).trim();
608
609
  return {
609
610
  card_type: "button_interaction",
610
- source: buildSource(undefined, tail),
611
+ source: buildSource(undefined, cardName(approver)),
611
612
  main_title: { title: TRUNC(`🤔 ${emojiFor(approver)}${q.header || "已回答"}`, ASKQ_TITLE_MAX) },
612
613
  sub_title_text: TRUNC(q.question, ASKQ_SUB_MAX),
613
614
  task_id: reqId,
@@ -748,13 +749,12 @@ const buildPlanMarkdown = (plan) => {
748
749
  }
749
750
  return `**📋 计划待审批**\n\n${body}`;
750
751
  };
751
- const buildPlanCard = (reqId, _sessionId, cwd, transcriptTail, approver, hasPlan) => {
752
- const tail = oneLine(transcriptTail).trim();
752
+ const buildPlanCard = (reqId, cwd, approver, hasPlan) => {
753
753
  const tag = emojiFor(approver);
754
754
  const dir = dirName(cwd);
755
755
  return {
756
756
  card_type: "button_interaction",
757
- source: buildSource(undefined, tail),
757
+ source: buildSource(undefined, cardName(approver)),
758
758
  main_title: { title: TRUNC(`📋 计划审批 · ${tag}${dir}/`, PLAN_TITLE_MAX + 12) },
759
759
  sub_title_text: hasPlan
760
760
  ? "审阅上方计划后选择:同意开始执行,或让 Agent 继续完善。"
@@ -766,13 +766,12 @@ const buildPlanCard = (reqId, _sessionId, cwd, transcriptTail, approver, hasPlan
766
766
  ],
767
767
  };
768
768
  };
769
- const buildPlanResolvedCard = (reqId, action, cwd, transcriptTail, approver) => {
770
- const tail = oneLine(transcriptTail).trim();
769
+ const buildPlanResolvedCard = (reqId, action, cwd, approver) => {
771
770
  const dir = dirName(cwd);
772
771
  const summary = action === "approve" ? "✅ 已同意 · 开始执行" : "✏️ 继续完善计划";
773
772
  return {
774
773
  card_type: "button_interaction",
775
- source: buildSource(undefined, tail),
774
+ source: buildSource(undefined, cardName(approver)),
776
775
  main_title: { title: TRUNC(`📋 计划 · ${emojiFor(approver)}${dir}/`, PLAN_TITLE_MAX + 12) },
777
776
  task_id: reqId,
778
777
  button_list: [{ text: summary, style: 4, key: encodePlanNoopKey(reqId) }],
@@ -829,7 +828,7 @@ const handleExitPlanMode = async ({ cfg, log, client, body, getMirrorTarget, flu
829
828
  }
830
829
  await client.sendMessage(target, {
831
830
  msgtype: "template_card",
832
- template_card: buildPlanCard(reqId, body.session_id, body.cwd ?? "", body.transcript_tail ?? "", approver, true),
831
+ template_card: buildPlanCard(reqId, body.cwd ?? "", approver, true),
833
832
  });
834
833
  log.info({ reqId, approver }, "plan card sent");
835
834
  }
@@ -985,7 +984,7 @@ export const runMirrorAskqFlow = async ({ cfg, log, client, sessionId, chatKey,
985
984
  }
986
985
  await client.sendMessage(target, {
987
986
  msgtype: "template_card",
988
- template_card: buildAskqCard(reqId, q, "", chatKey),
987
+ template_card: buildAskqCard(reqId, q, chatKey),
989
988
  });
990
989
  log.info({ reqId, chatKey, idx: i, total }, "mirror askq card sent");
991
990
  }
@@ -1124,7 +1123,7 @@ export const runMirrorPlanFlow = async ({ cfg, log, client, sessionId, chatKey,
1124
1123
  }
1125
1124
  await client.sendMessage(target, {
1126
1125
  msgtype: "template_card",
1127
- template_card: buildPlanCard(reqId, sessionId, cwd, "", chatKey, Boolean(plan)),
1126
+ template_card: buildPlanCard(reqId, cwd, chatKey, Boolean(plan)),
1128
1127
  });
1129
1128
  log.info({ reqId, chatKey }, "mirror plan card sent");
1130
1129
  }
@@ -1200,7 +1199,7 @@ const consumePickerAllow = (sessionId, toolName) => {
1200
1199
  return Date.now() - at <= RECENT_PICKER_TTL_MS;
1201
1200
  };
1202
1201
  /** 返回「卡是否真的发出去了」— false (WS 断 / 发送失败) 时调用方应允许对同屏重试。 */
1203
- export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey, cwd, jsonlPath, toolName, toolInput, agent, danger, voteTimeoutMs, press }) => {
1202
+ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey, cwd, jsonlPath, toolName, toolInput, agent, danger, singleNote, voteTimeoutMs, press }) => {
1204
1203
  if (!canReach(client, chatKey))
1205
1204
  return false;
1206
1205
  const target = targetChatId(chatKey);
@@ -1211,7 +1210,7 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1211
1210
  catch { /* best-effort */ }
1212
1211
  };
1213
1212
  const tail = agent ? `子代理 ${agent} 的原生权限确认` : "CLI 原生权限确认";
1214
- const sessionName = sessionNameFor(chatKey, jsonlPath, sessionId);
1213
+ const sessionName = cardName(chatKey, jsonlPath, sessionId);
1215
1214
  const { reqId, promise } = createPending({
1216
1215
  meta: {
1217
1216
  kind: "generic",
@@ -1223,7 +1222,8 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1223
1222
  chatKey,
1224
1223
  transcriptTail: tail,
1225
1224
  danger,
1226
- forceSingle: Boolean(danger),
1225
+ singleNote,
1226
+ forceSingle: Boolean(danger || singleNote),
1227
1227
  sessionName,
1228
1228
  },
1229
1229
  timeoutMs: voteTimeoutMs,
@@ -1241,10 +1241,10 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
1241
1241
  sessionShort: sessionId.slice(-8),
1242
1242
  sessionId,
1243
1243
  chatKey,
1244
- transcriptTail: tail,
1245
1244
  windowMinutes: cfg.approval.windowMinutes,
1246
1245
  danger,
1247
- forceSingle: Boolean(danger),
1246
+ singleNote,
1247
+ forceSingle: Boolean(danger || singleNote),
1248
1248
  sessionName,
1249
1249
  }),
1250
1250
  });
@@ -1388,7 +1388,7 @@ const handleAskUserQuestion = async ({ cfg, log, client, body, getMirrorTarget,
1388
1388
  }
1389
1389
  await client.sendMessage(target, {
1390
1390
  msgtype: "template_card",
1391
- template_card: buildAskqCard(reqId, q, body.transcript_tail ?? "", approver),
1391
+ template_card: buildAskqCard(reqId, q, approver),
1392
1392
  });
1393
1393
  log.info({ reqId, approver, idx: i, total }, "askq card sent");
1394
1394
  }
@@ -1620,7 +1620,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1620
1620
  activeBatches.delete(batchKeyOf(batch.sessionId, batch.toolName, batch.chatId));
1621
1621
  const isMulti = batch.members.length > 1;
1622
1622
  const card = isMulti
1623
- ? buildBatchCard(batch, batch.members[0]?.transcriptTail ?? "")
1623
+ ? buildBatchCard(batch)
1624
1624
  : (() => {
1625
1625
  const m = batch.members[0];
1626
1626
  return buildCard({
@@ -1635,7 +1635,6 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1635
1635
  // the emoji (only tagged sessions get it now). Also flows through
1636
1636
  // to the resolved card's cancel key path.
1637
1637
  chatKey: batch.approver,
1638
- transcriptTail: m.transcriptTail,
1639
1638
  windowMinutes: batch.windowMinutes,
1640
1639
  danger: batch.danger,
1641
1640
  forceSingle: batch.forceSingle,
@@ -1694,6 +1693,12 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1694
1693
  json(res, 200, { decision: "ask", reason: "approval_disabled" });
1695
1694
  return;
1696
1695
  }
1696
+ // `wezard use cli`: 审批权已经交回本地 CLI, 这里再造一张卡就是「两处都能点」。
1697
+ // 回 ask 让 hook / codex 的 PermissionRequest 都走 CLI 自己的权限流程。
1698
+ if (readHookMode(cfg.daemon.stateDir) === "cli") {
1699
+ json(res, 200, { decision: "ask", reason: "hook_mode_cli" });
1700
+ return;
1701
+ }
1697
1702
  const body = (await readBody(req));
1698
1703
  const nativePermission = body.cli_backend === "codex" && body.hook_event_name === "PermissionRequest";
1699
1704
  let sessionId = body.session_id ?? "";
@@ -1795,6 +1800,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1795
1800
  // 必发卡 = 危险名单 或 askRules 命中。这两者的语义是「每次都要人单独看一眼」,
1796
1801
  // 所以压过放行/窗口/缓存。守卫不在其列 —— 见上面 settleGuard 的注释。
1797
1802
  const mustCard = nativePermission || Boolean(danger) || Boolean(askHit);
1803
+ // 必发卡但不是危险的理由 — 卡片「审核」行 (askRules = 人自己要求每次问;
1804
+ // 危险名单命中由 danger 自己走「危险」行, 不在这里重复)。
1805
+ const singleNote = askHit ? `命中 askRules「${askHit}」` : undefined;
1798
1806
  // allowRules: matcher 拦下的工具里再挖细粒度豁免 (Bash 可按命令前缀区分)。
1799
1807
  // 交互卡工具 (AskUserQuestion 等) 在引擎内部硬保护, 规则写了也不放行。
1800
1808
  // 用 evaluateAllow 而非 ruleAllows: 未命中时要把"因为哪一段"带到卡上,
@@ -1966,7 +1974,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1966
1974
  const longPollMs = cfg.approval.longPollSec * 1000;
1967
1975
  // 卡片标题上的会话身份 — 发卡前算一次, 存进 meta 供 resolved 卡复用
1968
1976
  // (#tag 直接取; 否则读 transcript 首条用户消息, 带缓存)。
1969
- const sessionName = sessionNameFor(approver, body.transcript_path, sessionId);
1977
+ const sessionName = cardName(approver, body.transcript_path, sessionId);
1970
1978
  // Reload 续接: hook 带着上一轮的 req_id 回来, 复用同一个 id 重新挂起 ——
1971
1979
  // WeCom 上那张卡的按钮编的就是它, 于是旧卡的点击照样能 resolve 这次长轮询。
1972
1980
  const resumeId = (body.resume_req_id ?? "").trim();
@@ -1981,6 +1989,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
1981
1989
  chatKey: approver,
1982
1990
  transcriptTail,
1983
1991
  danger: danger?.rule,
1992
+ singleNote,
1984
1993
  forceSingle: mustCard,
1985
1994
  sessionName,
1986
1995
  denyReason,
@@ -2001,7 +2010,7 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
2001
2010
  // 创建 batch + 计时器, 后续到达者只追加成员, 不发卡。flush 时依据成员数
2002
2011
  // 选择普通 buildCard 或 buildBatchCard。0 = 关闭聚合, 立即 flush。
2003
2012
  // 续接的请求不再进 batch: 卡已经在群里, 重发就是重复轰炸。
2004
- const member = { reqId, toolInput: display, originalToolInput: toolInput, toolInputStr, cwd, transcriptTail };
2013
+ const member = { reqId, toolInput: display, originalToolInput: toolInput, toolInputStr, cwd };
2005
2014
  const bk = batchKeyOf(sessionId, toolName, chatId);
2006
2015
  // 必发卡请求既不 join 也不被 join — 一次这样的操作 = 一张卡 = 一次点击。
2007
2016
  // 合流会把它塞进带「⏱全过 / ✅总是」的批量卡, 一次点击就连它一起放行了。
@@ -2122,6 +2131,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
2122
2131
  toolInput: display,
2123
2132
  cwd,
2124
2133
  transcriptTail,
2134
+ danger: danger?.rule,
2135
+ sessionName,
2136
+ singleNote,
2125
2137
  });
2126
2138
  // 同一个 chat 里其它 pending 卡 (可能来自并发同 turn, 也可能来自绑到
2127
2139
  // 同一个 chat 的别的 session) — 一并放行,免得用户逐个点。
@@ -2263,7 +2275,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2263
2275
  log.info({ reqId: askq.reqId, outcome, ok }, "askq event resolved");
2264
2276
  if (q) {
2265
2277
  try {
2266
- await client.updateTemplateCard(frame, buildAskqResolvedCard(cbTaskId || askq.reqId, q, outcome, meta?.transcriptTail ?? "", meta?.chatKey));
2278
+ await client.updateTemplateCard(frame, buildAskqResolvedCard(cbTaskId || askq.reqId, q, outcome, meta?.chatKey));
2267
2279
  }
2268
2280
  catch (e) {
2269
2281
  log.warn({ err: e.message, reqId: askq.reqId }, "askq updateTemplateCard failed");
@@ -2311,7 +2323,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2311
2323
  const ok = resolvePending(planClick.reqId, `${PLAN_PICKED_PREFIX}${planClick.action}`);
2312
2324
  log.info({ reqId: planClick.reqId, action: planClick.action, ok }, "plan event resolved");
2313
2325
  try {
2314
- await client.updateTemplateCard(frame, buildPlanResolvedCard(cbTaskId || planClick.reqId, planClick.action, meta?.cwd ?? "", meta?.transcriptTail ?? "", meta?.chatKey));
2326
+ await client.updateTemplateCard(frame, buildPlanResolvedCard(cbTaskId || planClick.reqId, planClick.action, meta?.cwd ?? "", meta?.chatKey));
2315
2327
  }
2316
2328
  catch (e) {
2317
2329
  log.warn({ err: e.message, reqId: planClick.reqId }, "plan updateTemplateCard failed");
@@ -2347,10 +2359,9 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2347
2359
  if (resolved > 0)
2348
2360
  onApproved?.(batch.sessionId);
2349
2361
  try {
2350
- const tail = batch.members[0]?.transcriptTail ?? "";
2351
2362
  const card = allSwept
2352
- ? buildBatchAlreadyResolvedCard(batch, tail)
2353
- : buildBatchResolvedCard(batch, batchDec.decision, tail);
2363
+ ? buildBatchAlreadyResolvedCard(batch)
2364
+ : buildBatchResolvedCard(batch, batchDec.decision);
2354
2365
  await client.updateTemplateCard(frame, card);
2355
2366
  log.info({ batchId: batch.batchId, decision: batchDec.decision, allSwept }, "batch card updated in place");
2356
2367
  }
@@ -2388,8 +2399,10 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2388
2399
  cwd: wmeta?.cwd ?? "",
2389
2400
  sessionShort: "?",
2390
2401
  chatKey: decoded.cancelChatKey,
2391
- transcriptTail: wmeta?.transcriptTail ?? "",
2392
2402
  windowMinutes: cfg.approval.windowMinutes,
2403
+ danger: wmeta?.danger,
2404
+ sessionName: wmeta?.sessionName,
2405
+ singleNote: wmeta?.singleNote,
2393
2406
  detailUrl: cbTaskId ? detailUrlFor(cbTaskId, decoded.cancelChatKey) : undefined,
2394
2407
  }));
2395
2408
  log.info({ chatKey: decoded.cancelChatKey, cbTaskId }, "cancel card updated in place");
@@ -2462,10 +2475,11 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2462
2475
  sessionShort,
2463
2476
  sessionId: meta?.sessionId ?? "",
2464
2477
  chatKey: meta?.chatKey ?? "",
2465
- transcriptTail: meta?.transcriptTail ?? "",
2466
2478
  windowMinutes: cfg.approval.windowMinutes,
2479
+ danger: meta?.danger,
2467
2480
  sessionName: meta?.sessionName,
2468
2481
  denyReason: meta?.denyReason,
2482
+ singleNote: meta?.singleNote,
2469
2483
  detailUrl: detailUrlFor(reqId, meta?.chatKey),
2470
2484
  })
2471
2485
  : buildResolvedCard({
@@ -2475,7 +2489,6 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2475
2489
  toolInputStr,
2476
2490
  cwd: meta?.cwd ?? "",
2477
2491
  sessionShort,
2478
- transcriptTail: meta?.transcriptTail ?? "",
2479
2492
  windowMinutes: cfg.approval.windowMinutes,
2480
2493
  decision: effectiveDecision,
2481
2494
  by,
@@ -2484,6 +2497,7 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
2484
2497
  danger: meta?.danger,
2485
2498
  sessionName: meta?.sessionName,
2486
2499
  denyReason: meta?.denyReason,
2500
+ singleNote: meta?.singleNote,
2487
2501
  detailUrl: detailUrlFor(reqId, meta?.chatKey),
2488
2502
  });
2489
2503
  await client.updateTemplateCard(frame, card);