wezard 2.8.7 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +0 -6
- package/CLAUDE.md +3 -2
- package/README.md +5 -5
- package/config.example.jsonc +4 -0
- package/dist/cli/codex-hook.js +20 -4
- package/dist/cli/codex-hook.js.map +1 -1
- package/dist/cli/init.js +10 -8
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/sync.js +32 -112
- package/dist/cli/sync.js.map +1 -1
- package/dist/daemon/approval.js +67 -24
- package/dist/daemon/approval.js.map +1 -1
- package/dist/daemon/channel-context.js +62 -0
- package/dist/daemon/channel-context.js.map +1 -0
- package/dist/daemon/channel-store.js +96 -0
- package/dist/daemon/channel-store.js.map +1 -0
- package/dist/daemon/channel.js +693 -0
- package/dist/daemon/channel.js.map +1 -0
- package/dist/daemon/config-api.js +10 -2
- package/dist/daemon/config-api.js.map +1 -1
- package/dist/daemon/danger.js +49 -39
- package/dist/daemon/danger.js.map +1 -1
- package/dist/daemon/handoff.js +243 -28
- package/dist/daemon/handoff.js.map +1 -1
- package/dist/daemon/idle-nudge.js +29 -8
- package/dist/daemon/idle-nudge.js.map +1 -1
- package/dist/daemon/inbound.js +6 -1
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +151 -23
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/message-events.js +84 -10
- package/dist/daemon/message-events.js.map +1 -1
- package/dist/daemon/mirror-bridge.js +203 -18
- package/dist/daemon/mirror-bridge.js.map +1 -1
- package/dist/daemon/pending.js +7 -5
- package/dist/daemon/pending.js.map +1 -1
- package/dist/daemon/picker-policy.js +27 -12
- package/dist/daemon/picker-policy.js.map +1 -1
- package/dist/daemon/spawn-tmux.js +124 -20
- package/dist/daemon/spawn-tmux.js.map +1 -1
- package/dist/daemon/steward-guard.js +1 -1
- package/dist/daemon/steward-guard.js.map +1 -1
- package/dist/daemon/wezard-session.js +1 -0
- package/dist/daemon/wezard-session.js.map +1 -1
- package/dist/daemon/wizard-names.js +64 -37
- package/dist/daemon/wizard-names.js.map +1 -1
- package/dist/daemon/wizard.js +13 -4
- package/dist/daemon/wizard.js.map +1 -1
- package/dist/mcp/tools.js +18 -1
- package/dist/mcp/tools.js.map +1 -1
- package/dist/shared/allow-rules.js +202 -26
- package/dist/shared/allow-rules.js.map +1 -1
- package/dist/shared/cli-backends.js +14 -0
- package/dist/shared/cli-backends.js.map +1 -1
- package/dist/shared/config.js +74 -14
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/detail-render.js +105 -10
- package/dist/shared/detail-render.js.map +1 -1
- package/dist/shared/detail-store.js.map +1 -1
- package/dist/shared/json-map-store.js +23 -6
- package/dist/shared/json-map-store.js.map +1 -1
- package/dist/shared/repl-script.js +206 -0
- package/dist/shared/repl-script.js.map +1 -0
- package/dist/shared/session-hooks.js +46 -0
- package/dist/shared/session-hooks.js.map +1 -0
- package/dist/shared/session-mcp.js +59 -0
- package/dist/shared/session-mcp.js.map +1 -0
- package/dist/shared/session-skills.js +55 -0
- package/dist/shared/session-skills.js.map +1 -0
- package/dist/shared/tool-hints.js +76 -11
- package/dist/shared/tool-hints.js.map +1 -1
- package/hooks/pre-tool-use.sh +18 -0
- package/package.json +1 -2
- package/dist/daemon/repl-script.js +0 -22
- package/dist/daemon/repl-script.js.map +0 -1
- package/hooks/hooks.json +0 -16
package/dist/daemon/approval.js
CHANGED
|
@@ -221,6 +221,7 @@ const denyReasonText = (d) => {
|
|
|
221
221
|
case "substitution": return "含 $() 动态构造,无法白名单";
|
|
222
222
|
case "unparsable": return "引号未闭合或含后台符 &";
|
|
223
223
|
case "tool_not_listed": return `${shortTool(d.tool)} 未在白名单`;
|
|
224
|
+
case "repl_opaque": return "内层调用无法识别(动态构造或纯计算)";
|
|
224
225
|
case "never_allow": return "交互工具,永不免审";
|
|
225
226
|
// 没配白名单规则 = 用户没在用这套机制, 每张卡都挂这行纯噪声。
|
|
226
227
|
case "no_rules": return undefined;
|
|
@@ -892,6 +893,19 @@ const freshSlot = (sessionId) => {
|
|
|
892
893
|
return s;
|
|
893
894
|
};
|
|
894
895
|
export const hasMirrorAskq = (sessionId) => freshSlot(sessionId) !== undefined;
|
|
896
|
+
/** 提问的结果落盘 = 面板已经不在屏上 (本地作答 / 我们自己驱动完) → 作废挂着的卡。
|
|
897
|
+
* 只认提问那次调用的 callId: PTC 脚本里在提问之前落地的别的工具结果不是它。
|
|
898
|
+
* 原生路径没有这个信号 (hook 迟到时自己清槽), callId 为 undefined 时按任意 result 处理。 */
|
|
899
|
+
export const mootMirrorAskq = (sessionId, callId) => {
|
|
900
|
+
const s = freshSlot(sessionId);
|
|
901
|
+
if (!s)
|
|
902
|
+
return;
|
|
903
|
+
if (callId && s.callId && callId !== s.callId)
|
|
904
|
+
return;
|
|
905
|
+
if (s.reqId)
|
|
906
|
+
resolvePending(s.reqId, "moot");
|
|
907
|
+
mirrorAskqSlots.delete(sessionId);
|
|
908
|
+
};
|
|
895
909
|
export const buildAskqDriveActions = (questions, picks) => {
|
|
896
910
|
const maxOpts = questions.reduce((m, q) => Math.max(m, q.options.length), 0);
|
|
897
911
|
const acts = [{ kind: "keys", keys: Array(maxOpts + 3).fill("Up") }];
|
|
@@ -928,7 +942,7 @@ export const buildAskqChatDriveActions = (q) => [
|
|
|
928
942
|
{ kind: "text", text: "聊聊这个" },
|
|
929
943
|
{ kind: "confirm_submit" },
|
|
930
944
|
];
|
|
931
|
-
export const runMirrorAskqFlow = async ({ cfg, log, client, sessionId, chatKey, toolInput, voteTimeoutMs, drive }) => {
|
|
945
|
+
export const runMirrorAskqFlow = async ({ cfg, log, client, sessionId, chatKey, toolInput, voteTimeoutMs, callId, drive }) => {
|
|
932
946
|
const questions = parseAskqInput(toolInput);
|
|
933
947
|
if (!questions || questions.length === 0)
|
|
934
948
|
return;
|
|
@@ -970,7 +984,7 @@ export const runMirrorAskqFlow = async ({ cfg, log, client, sessionId, chatKey,
|
|
|
970
984
|
},
|
|
971
985
|
timeoutMs: remainMs,
|
|
972
986
|
});
|
|
973
|
-
mirrorAskqSlots.set(sessionId, { reqId, at: Date.now() });
|
|
987
|
+
mirrorAskqSlots.set(sessionId, { reqId, at: Date.now(), callId });
|
|
974
988
|
const prefix = total > 1 ? `(${i + 1}/${total}) ` : "";
|
|
975
989
|
try {
|
|
976
990
|
try {
|
|
@@ -1156,8 +1170,8 @@ export const runMirrorPlanFlow = async ({ cfg, log, client, sessionId, chatKey,
|
|
|
1156
1170
|
await note("⚠️ 已记录选择,但本地对话框按键注入失败,请回到 CLI 手动处理。");
|
|
1157
1171
|
return;
|
|
1158
1172
|
}
|
|
1173
|
+
// 计划卡同款: 结论已在卡片终态, 不再发跟帖。
|
|
1159
1174
|
log.info({ reqId, sessionId, approve }, "mirror plan resolved via send-keys");
|
|
1160
|
-
await note(approve ? "✅ 已同意,退出 plan mode 开始执行…" : "✏️ 已选择继续完善计划。");
|
|
1161
1175
|
};
|
|
1162
1176
|
const mirrorPickerSlots = new Map();
|
|
1163
1177
|
const MIRROR_PICKER_SLOT_TTL_MS = 12 * 3600_000; // 与 approval.longPollSec 对齐
|
|
@@ -1275,13 +1289,16 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
|
|
|
1275
1289
|
const d = raw;
|
|
1276
1290
|
if (d === "deny") {
|
|
1277
1291
|
const r = await press("no");
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1292
|
+
// 代按成功不补发消息: 卡片已被 updateTemplateCard 收成「❌ 已拒绝」终态,
|
|
1293
|
+
// 群里再贴一条纯属噪音。只有按失败才需要人回 CLI 接手。
|
|
1294
|
+
if (!r.ok)
|
|
1295
|
+
await note(`⚠️ 已记录拒绝,但代按失败(${r.reason ?? "未知"}),请回 CLI 处理。`);
|
|
1281
1296
|
return true;
|
|
1282
1297
|
}
|
|
1283
1298
|
if (d === "allow_window" && cfg.approval.windowMinutes > 0) {
|
|
1284
|
-
setAutoWindow(chatKey, cfg.approval.windowMinutes * 60_000, {
|
|
1299
|
+
setAutoWindow(chatKey, cfg.approval.windowMinutes * 60_000, {
|
|
1300
|
+
toolName, toolInput, cwd, transcriptTail: tail, danger, singleNote, sessionName,
|
|
1301
|
+
});
|
|
1285
1302
|
// 与 handler 的 allow_window 同款 sweep: 同 chat 其它 pending 卡一并放行。
|
|
1286
1303
|
const swept = resolvePendingsByChat(chatKey, "allow_window", reqId);
|
|
1287
1304
|
log.info({ chatKey, minutes: cfg.approval.windowMinutes, swept: swept.length }, "auto-window opened via picker card");
|
|
@@ -1297,9 +1314,8 @@ export const runMirrorPickerFlow = async ({ log, client, cfg, sessionId, chatKey
|
|
|
1297
1314
|
// 代按成功 → CLI 才真正派发工具 → hook 此刻才会上报同一调用; 预先记账让
|
|
1298
1315
|
// handler 直接放行, 不再发第二张卡 (consumePickerAllow)。
|
|
1299
1316
|
recordPickerAllow(sessionId, toolName);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
: `🔓 已代按 CLI 权限确认(${toolName})→ ${r.label ?? "Yes"}${d === "allow_window" ? `,并开启 ${cfg.approval.windowMinutes} 分钟自动放行窗口` : ""}`);
|
|
1317
|
+
// 代按成功同样不补发消息 —— 结果 (含「本会话通过」/「N 分钟会话内全过」)
|
|
1318
|
+
// 已经落在卡片终态按钮上, 那是人真正会回头核对的地方。失败才发一条。
|
|
1303
1319
|
log.info({ reqId, sessionId, decision: d, pressed: r.label }, "mirror picker resolved via send-keys");
|
|
1304
1320
|
return true;
|
|
1305
1321
|
}
|
|
@@ -1571,8 +1587,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
|
|
|
1571
1587
|
return;
|
|
1572
1588
|
const r = await nm.answer(sessionId, { waitMs: cfg.approval.claudeConfigModalWaitMs });
|
|
1573
1589
|
if (r.status === "answered") {
|
|
1574
|
-
|
|
1575
|
-
|
|
1590
|
+
// 只在日志里留痕: 这张卡 (人点的那张) 已是「✅ 已通过」终态, 代按原生框是
|
|
1591
|
+
// 它的完成动作, 不必再往群里贴一条。按不掉时下面的告警照发。
|
|
1592
|
+
log.info({ sessionId, path: hit.path, pressed: `${r.index}. ${r.label}`, title: r.title }, "claude-config modal answered");
|
|
1576
1593
|
return;
|
|
1577
1594
|
}
|
|
1578
1595
|
if (r.status === "no_modal") {
|
|
@@ -1887,13 +1904,13 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
|
|
|
1887
1904
|
settleGuard();
|
|
1888
1905
|
return;
|
|
1889
1906
|
}
|
|
1890
|
-
//
|
|
1891
|
-
// 名单 / askRules / ⏱窗口 / 会话缓存 (
|
|
1892
|
-
//
|
|
1893
|
-
//
|
|
1894
|
-
if (!nativePermission && cfg.approval.
|
|
1895
|
-
log.info({ toolName, sessionId }, "
|
|
1896
|
-
json(res, 200, { decision: "allow", reason: "
|
|
1907
|
+
// mode=skip_all: 跳过所有审批 —— 命中 matcher 的调用一律静默放行, 压过危险
|
|
1908
|
+
// 名单 / askRules / ⏱窗口 / 会话缓存 (原 danger.skipAll, 2026-10-28 并入 mode)。
|
|
1909
|
+
// denyRules / EnterPlanMode 拦截在前面已生效 (拒绝不是审批);
|
|
1910
|
+
// AskUserQuestion / ExitPlanMode 交互卡在上方分支已返回, 不受影响。
|
|
1911
|
+
if (!nativePermission && cfg.approval.mode === "skip_all") {
|
|
1912
|
+
log.info({ toolName, sessionId }, "skip_all auto allow");
|
|
1913
|
+
json(res, 200, { decision: "allow", reason: "skip_all" });
|
|
1897
1914
|
settleGuard();
|
|
1898
1915
|
return;
|
|
1899
1916
|
}
|
|
@@ -1911,6 +1928,27 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
|
|
|
1911
1928
|
// 早退照样能给 (settleGuard), 拿它挡早退等于把 danger 的开关废掉。
|
|
1912
1929
|
const earlyExit = dangerEarlyExit(cfg, danger, nativePermission || Boolean(askHit) || Boolean(selfWrite));
|
|
1913
1930
|
if (earlyExit) {
|
|
1931
|
+
// danger-only 模式 (mode=danger, 默认) 的自动放行按 ⏱ 窗口记账/续期 (人
|
|
1932
|
+
// 2026-10-28: 普通卡不再发, 非 danger 一律放行, 但要能看出是 10h 窗口放的,
|
|
1933
|
+
// 不是永久无痕)。窗口只做记账不参与门控 —— danger_mode_skip 本身不看窗口状态。
|
|
1934
|
+
if (earlyExit === "danger_mode_skip" && approver && cfg.approval.windowMinutes > 0) {
|
|
1935
|
+
setAutoWindow(approver, cfg.approval.windowMinutes * 60_000, {
|
|
1936
|
+
toolName,
|
|
1937
|
+
toolInput,
|
|
1938
|
+
cwd,
|
|
1939
|
+
transcriptTail,
|
|
1940
|
+
danger: danger?.rule,
|
|
1941
|
+
singleNote,
|
|
1942
|
+
});
|
|
1943
|
+
const remainSec = Math.ceil(autoWindowRemainingMs(approver) / 1000);
|
|
1944
|
+
log.info({ toolName, sessionId, chatKey: approver, remainSec }, "danger-only auto-window allow");
|
|
1945
|
+
json(res, 200, {
|
|
1946
|
+
decision: "allow",
|
|
1947
|
+
reason: `auto_window:${remainSec}s (danger-only)`,
|
|
1948
|
+
});
|
|
1949
|
+
settleGuard();
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1914
1952
|
log.info({ toolName, sessionId, reason: earlyExit }, "danger switch early exit");
|
|
1915
1953
|
json(res, 200, { decision: "allow", reason: earlyExit });
|
|
1916
1954
|
settleGuard();
|
|
@@ -2004,6 +2042,9 @@ export const makeApproveHandler = ({ cfg, log, client, sourcePath, getMirrorTarg
|
|
|
2004
2042
|
toolInput: display,
|
|
2005
2043
|
cwd,
|
|
2006
2044
|
sessionId,
|
|
2045
|
+
// 卡片身份随 detail 记录留 24h: 「展开完整命令」在 pending / 快照都过期后
|
|
2046
|
+
// 仍凭它回到卡片所在的 chat, 而不是 defaultChat。
|
|
2047
|
+
chatKey: approver,
|
|
2007
2048
|
transcriptTail,
|
|
2008
2049
|
});
|
|
2009
2050
|
// Batch coalesce: 同 session 同 tool 的并发请求合流为一张卡。窗口内首位
|
|
@@ -2193,13 +2234,15 @@ export const installApprovalEventListener = (client, log, cfg, onApproved) => {
|
|
|
2193
2234
|
if (key.startsWith(FULLCMD_PREFIX)) {
|
|
2194
2235
|
const reqId = key.slice(FULLCMD_PREFIX.length);
|
|
2195
2236
|
const rec = getDetail(reqId);
|
|
2196
|
-
//
|
|
2197
|
-
//
|
|
2198
|
-
//
|
|
2199
|
-
//
|
|
2200
|
-
//
|
|
2237
|
+
// 回复目标 = 卡片自己的会话身份, 逐级回收: 待决时在 pending 里; 已决时
|
|
2238
|
+
// pending 已删, 回落到 resolvePending 留下的 5min resolved 暂存; 再往后
|
|
2239
|
+
// (含 daemon 重启) 由 24h 的 detail 记录兜着 —— recordApproval 落卡时就
|
|
2240
|
+
// 把 chatKey 一起存了。全部 miss (记录过期的真鬼卡) 才按点击帧是哪个
|
|
2241
|
+
// 机器人收的兑到它自己的默认聊天 (副机器人没配 = 不回), 不回落主机器人
|
|
2242
|
+
// 的全局 defaultChat; 单机器人时 botTagOf 恒 "", 就是 cfg.defaultChat。
|
|
2201
2243
|
const target = getPending(reqId)?.chatKey
|
|
2202
2244
|
?? getResolvedSnapshot(reqId)?.meta.chatKey
|
|
2245
|
+
?? (rec?.kind === "approval" ? rec.chatKey : undefined)
|
|
2203
2246
|
?? defaultChatOfBot(cfg, botTagOf(frame));
|
|
2204
2247
|
if (!target) {
|
|
2205
2248
|
log.info({ reqId, bot: botTagOf(frame) }, "full command: 记录已过期且该机器人没有默认聊天, 不回");
|