wezard 3.0.1 → 3.0.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.
- package/CLAUDE.md +14 -11
- package/README.md +2 -2
- package/cli/wezard.sh +56 -20
- package/config.example.jsonc +3 -0
- package/dist/cli/audit.js +11 -13
- package/dist/cli/audit.js.map +1 -1
- package/dist/cli/codex-hook.js +20 -17
- package/dist/cli/codex-hook.js.map +1 -1
- package/dist/cli/ext.js +271 -0
- package/dist/cli/ext.js.map +1 -0
- package/dist/cli/init.js +9 -13
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/sync.js +3 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/wx.js +7 -6
- package/dist/cli/wx.js.map +1 -1
- package/dist/daemon/aibot-media.js +28 -20
- package/dist/daemon/aibot-media.js.map +1 -1
- package/dist/daemon/approval.js +60 -37
- package/dist/daemon/approval.js.map +1 -1
- package/dist/daemon/channel-onboarding.js +61 -0
- package/dist/daemon/channel-onboarding.js.map +1 -0
- package/dist/daemon/channel-posts.js +56 -16
- package/dist/daemon/channel-posts.js.map +1 -1
- package/dist/daemon/channel-rebind.js +100 -0
- package/dist/daemon/channel-rebind.js.map +1 -0
- package/dist/daemon/channel-store.js.map +1 -1
- package/dist/daemon/channel.js +218 -466
- package/dist/daemon/channel.js.map +1 -1
- package/dist/daemon/claim.js +1 -45
- package/dist/daemon/claim.js.map +1 -1
- package/dist/daemon/classes.js +11 -13
- package/dist/daemon/classes.js.map +1 -1
- package/dist/daemon/config-api.js +5 -29
- package/dist/daemon/config-api.js.map +1 -1
- package/dist/daemon/control-socket.js +93 -0
- package/dist/daemon/control-socket.js.map +1 -0
- package/dist/daemon/danger-scrub.js +315 -0
- package/dist/daemon/danger-scrub.js.map +1 -0
- package/dist/daemon/danger.js +146 -16
- package/dist/daemon/danger.js.map +1 -1
- package/dist/daemon/detail.js +37 -15
- package/dist/daemon/detail.js.map +1 -1
- package/dist/daemon/exec-surface.js +108 -0
- package/dist/daemon/exec-surface.js.map +1 -0
- package/dist/daemon/external.js +595 -0
- package/dist/daemon/external.js.map +1 -0
- package/dist/daemon/http.js +97 -16
- package/dist/daemon/http.js.map +1 -1
- package/dist/daemon/inbound.js +91 -80
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +1268 -171
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/last-response.js +8 -17
- package/dist/daemon/last-response.js.map +1 -1
- package/dist/daemon/legacy-panes.js +67 -0
- package/dist/daemon/legacy-panes.js.map +1 -0
- package/dist/daemon/mcp-http.js.map +1 -1
- package/dist/daemon/me-room.js +137 -0
- package/dist/daemon/me-room.js.map +1 -0
- package/dist/daemon/media.js +14 -0
- package/dist/daemon/media.js.map +1 -1
- package/dist/daemon/message-format.js +5 -0
- package/dist/daemon/message-format.js.map +1 -1
- package/dist/daemon/mirror-bridge.js +77 -26
- package/dist/daemon/mirror-bridge.js.map +1 -1
- package/dist/daemon/notices.js +4 -5
- package/dist/daemon/notices.js.map +1 -1
- package/dist/daemon/onboarding.js +120 -45
- package/dist/daemon/onboarding.js.map +1 -1
- package/dist/daemon/peers.js +2 -2
- package/dist/daemon/peers.js.map +1 -1
- package/dist/daemon/plan-http.js +2 -3
- package/dist/daemon/plan-http.js.map +1 -1
- package/dist/daemon/reach.js +1 -5
- package/dist/daemon/reach.js.map +1 -1
- package/dist/daemon/room-bind.js +297 -0
- package/dist/daemon/room-bind.js.map +1 -0
- package/dist/daemon/room-facts.js +1 -1
- package/dist/daemon/room-facts.js.map +1 -1
- package/dist/daemon/room-hub.js +158 -19
- package/dist/daemon/room-hub.js.map +1 -1
- package/dist/daemon/room-overdue.js +90 -28
- package/dist/daemon/room-overdue.js.map +1 -1
- package/dist/daemon/room-watchdog.js +44 -22
- package/dist/daemon/room-watchdog.js.map +1 -1
- package/dist/daemon/rooms.js +101 -4
- package/dist/daemon/rooms.js.map +1 -1
- package/dist/daemon/session-scan.js +1 -1
- package/dist/daemon/session-scan.js.map +1 -1
- package/dist/daemon/short-id-log.js +43 -0
- package/dist/daemon/short-id-log.js.map +1 -0
- package/dist/daemon/spawn-tmux.js +12 -9
- 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/steward-model.js +17 -3
- package/dist/daemon/steward-model.js.map +1 -1
- package/dist/daemon/steward-repair.js +171 -0
- package/dist/daemon/steward-repair.js.map +1 -0
- package/dist/daemon/steward.js +48 -9
- package/dist/daemon/steward.js.map +1 -1
- package/dist/daemon/tool-face.js +31 -0
- package/dist/daemon/tool-face.js.map +1 -0
- package/dist/daemon/turn-opening.js +8 -3
- package/dist/daemon/turn-opening.js.map +1 -1
- package/dist/daemon/wizard-memory.js +4 -10
- package/dist/daemon/wizard-memory.js.map +1 -1
- package/dist/daemon/wizard.js +153 -73
- package/dist/daemon/wizard.js.map +1 -1
- package/dist/daemon/ws.js +1 -1
- package/dist/daemon/ws.js.map +1 -1
- package/dist/mcp/output.js +27 -5
- package/dist/mcp/output.js.map +1 -1
- package/dist/mcp/relay.js +152 -0
- package/dist/mcp/relay.js.map +1 -0
- package/dist/mcp/tools.js +87 -39
- package/dist/mcp/tools.js.map +1 -1
- package/dist/shared/chat-http.js +65 -48
- package/dist/shared/chat-http.js.map +1 -1
- package/dist/shared/cli-local-status.js +28 -0
- package/dist/shared/cli-local-status.js.map +1 -0
- package/dist/shared/cli-socket.js +14 -0
- package/dist/shared/cli-socket.js.map +1 -0
- package/dist/shared/codex-hooks.js +5 -2
- package/dist/shared/codex-hooks.js.map +1 -1
- package/dist/shared/config.js +45 -45
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/daemon-addr.js +23 -0
- package/dist/shared/daemon-addr.js.map +1 -0
- package/dist/shared/daemon-client.js +41 -0
- package/dist/shared/daemon-client.js.map +1 -0
- package/dist/shared/daemon-token.js +2 -2
- package/dist/shared/daemon-token.js.map +1 -1
- package/dist/shared/external.js +402 -0
- package/dist/shared/external.js.map +1 -0
- package/dist/shared/inject-view.js +48 -10
- package/dist/shared/inject-view.js.map +1 -1
- package/dist/shared/instance-id.js +21 -0
- package/dist/shared/instance-id.js.map +1 -0
- package/dist/shared/message-footer.js +8 -1
- package/dist/shared/message-footer.js.map +1 -1
- package/dist/shared/model-tiers.js +39 -1
- package/dist/shared/model-tiers.js.map +1 -1
- package/dist/shared/ports.js +56 -0
- package/dist/shared/ports.js.map +1 -0
- package/dist/shared/pricing.js +0 -5
- package/dist/shared/pricing.js.map +1 -1
- package/dist/shared/role-render.js +8 -7
- package/dist/shared/role-render.js.map +1 -1
- package/dist/shared/role-view.js +5 -2
- package/dist/shared/role-view.js.map +1 -1
- package/dist/shared/room-overdue.js +84 -12
- package/dist/shared/room-overdue.js.map +1 -1
- package/dist/shared/room-view.js +18 -4
- package/dist/shared/room-view.js.map +1 -1
- package/dist/shared/room.js +245 -28
- package/dist/shared/room.js.map +1 -1
- package/dist/shared/session-label.js +29 -51
- package/dist/shared/session-label.js.map +1 -1
- package/dist/shared/session-mcp.js +35 -57
- package/dist/shared/session-mcp.js.map +1 -1
- package/dist/shared/smarts.js +15 -30
- package/dist/shared/smarts.js.map +1 -1
- package/dist/shared/world.js +1 -1
- package/dist/shared/world.js.map +1 -1
- package/dist/svr/facts-store.js.map +1 -1
- package/dist/svr/index.js +57 -15
- package/dist/svr/index.js.map +1 -1
- package/hooks/pre-tool-use.sh +14 -10
- package/hooks/stop.sh +5 -3
- package/launchd/com.wezard.svr.plist.template +2 -0
- package/package.json +3 -1
- package/scripts/install.sh +12 -0
- package/systemd/wezard-svr.service.template +2 -0
- package/web/chat.js +81 -40
- package/dist/daemon/bot-mux.js +0 -161
- package/dist/daemon/bot-mux.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { envelopeFor, parseEnvelope, renderTail } from "../shared/reminder.js";
|
|
2
|
+
import { isCliRetryNotice, isCliStateReceipt } from "../shared/cli-local-status.js";
|
|
2
3
|
import { turnOpening } from "./turn-opening.js";
|
|
3
4
|
import { charterInContext, charterPreamble, charterToRearm } from "../shared/charter-rearm.js";
|
|
4
5
|
import { codexSessions, codexSessionForPane, recordCodexPaneSession } from "../shared/codex.js";
|
|
@@ -24,6 +25,7 @@ import { pasteTmuxBuffer } from "./tmux-buffer.js";
|
|
|
24
25
|
import { existsSync, readdirSync, readFileSync, statSync, watch, openSync, readSync, closeSync } from "node:fs";
|
|
25
26
|
import { basename, join, dirname } from "node:path";
|
|
26
27
|
import { newStewardSpec, resumedStewardSpec } from "./steward-model.js";
|
|
28
|
+
import { daemonSocketPath } from "../shared/daemon-addr.js";
|
|
27
29
|
import { expandHome, sanitizeId } from "../shared/paths.js";
|
|
28
30
|
import { augmentedPath } from "../shared/exec-path.js";
|
|
29
31
|
import { sleep, truncateWithCount, mapLimit, clipLine } from "../shared/std.js";
|
|
@@ -51,7 +53,7 @@ import { manifestationOf, wizardStore } from "./wizard.js";
|
|
|
51
53
|
import { startSubagentWatch } from "./subagent-tail.js";
|
|
52
54
|
import { getDetail, knowsToolUse, recordTool, recordToolResult, recordMark, recordTurnStart, recordTurnQuery, recordTurnInject, recordTurnItem, recordTurnUsage, recordTurnClose, recordCloseOpenTurns, lastChannelOf, openTurnsOf, buildDetailUrl, buildChatUrl, roleUniq, markTurnTextFinal } from "./detail.js";
|
|
53
55
|
import { errText } from "./last-response.js";
|
|
54
|
-
import { labelFor, tagOfKey, baseOfKey, stripSigil, displayName, createdAck, windowLabel, withTagHeader, withLinkedTagHeader, chatHead, headed, tagBadge, parseTagHeader, MAX_BODY_LINKS, isInternalKey
|
|
56
|
+
import { labelFor, tagOfKey, baseOfKey, stripSigil, displayName, createdAck, windowLabel, withTagHeader, withLinkedTagHeader, chatHead, headed, tagBadge, parseTagHeader, MAX_BODY_LINKS, isInternalKey } from "../shared/session-label.js";
|
|
55
57
|
import { splitMarkdown } from "../shared/md-chunk.js";
|
|
56
58
|
import { readHookMode } from "../shared/hook-mode.js";
|
|
57
59
|
import { isWxFrame } from "../shared/wx-text.js";
|
|
@@ -173,9 +175,8 @@ const findJsonlBySid = (sid, only) => {
|
|
|
173
175
|
// codebuddy persists message/function_call records instead, so route every
|
|
174
176
|
// parsed line through the owning backend's adapter first (identity for claude).
|
|
175
177
|
const normalizeForPath = (path, raw) => backendForPath(path).normalizeTranscriptLine(raw);
|
|
176
|
-
// /model、/effort
|
|
177
|
-
//
|
|
178
|
-
const MODEL_RECEIPT_RE = /^(?:Set model to|Kept model as|Set effort level to|Kept effort|Switch model)\b/;
|
|
178
|
+
// /model、/effort、/login 的本地回执是 CLI 自己的操作痕迹, 不是聊天内容 —— 不镜像、
|
|
179
|
+
// 不进详情页。原文按后端/版本变 (见 shared/cli-local-status.ts), 判据在那里一处维护。
|
|
179
180
|
// Local-command noise on user lines: Claude marks the caveat / command-stdout
|
|
180
181
|
// records isMeta; codebuddy persists them as PLAIN user messages (no isMeta
|
|
181
182
|
// field at all). Predicates looking for the first REAL user line must skip
|
|
@@ -549,7 +550,7 @@ const renderLine = (raw, deps) => {
|
|
|
549
550
|
const stdoutMatch = c.match(/<local-command-stdout>([\s\S]*?)<\/local-command-stdout>/);
|
|
550
551
|
if (stdoutMatch && stdoutMatch[1]) {
|
|
551
552
|
const skillOutput = stdoutMatch[1].replace(/\[[0-9;]*m/g, "").trim();
|
|
552
|
-
if (
|
|
553
|
+
if (isCliStateReceipt(skillOutput))
|
|
553
554
|
return out;
|
|
554
555
|
if (skillOutput) {
|
|
555
556
|
out.push({ kind: "skill_output", body: `⚙️ ${skillOutput}` });
|
|
@@ -684,7 +685,8 @@ const renderLine = (raw, deps) => {
|
|
|
684
685
|
if (b?.type === "text" && typeof b.text === "string") {
|
|
685
686
|
flushPending();
|
|
686
687
|
const t = b.text.trim();
|
|
687
|
-
|
|
688
|
+
// CLI 自己的自动重试提示不是模型发言: 重试成功时它是噪声, 失败时 CLI 会再写一句真失败。
|
|
689
|
+
if (t && !isCliRetryNotice(t) && !deps.isOwnAssistantSend?.(t))
|
|
688
690
|
out.push({ kind: "text", body: t, final: textFinal });
|
|
689
691
|
}
|
|
690
692
|
else if (b?.type === "tool_use" && deps.includeTools) {
|
|
@@ -777,6 +779,9 @@ const renderLine = (raw, deps) => {
|
|
|
777
779
|
if (!stdout.trim())
|
|
778
780
|
return []; // pure invocation record or empty stdout
|
|
779
781
|
const cleaned = stripAnsi(stdout);
|
|
782
|
+
// 同一种回执也走这条记录 (别的 CLI 版本把 /model 落在 system/local_command 下)。
|
|
783
|
+
if (isCliStateReceipt(cleaned))
|
|
784
|
+
return [];
|
|
780
785
|
const anchored = anchorSkillOutput(cleaned);
|
|
781
786
|
if (!anchored)
|
|
782
787
|
return [];
|
|
@@ -788,10 +793,10 @@ const renderLine = (raw, deps) => {
|
|
|
788
793
|
};
|
|
789
794
|
// Block-wise packing (shared/md-chunk): never cuts mid-line, and never cuts a
|
|
790
795
|
// fenced block or table in a way that breaks rendering — see splitMarkdown.
|
|
791
|
-
// Room reserved in every chunk for the signed
|
|
796
|
+
// Room reserved in every chunk for the signed `🧙 name` / `2/5` header line and
|
|
792
797
|
// the chat-detail links linkTags hangs on it and on up to MAX_BODY_LINKS body
|
|
793
798
|
// mentions — each `(url)` runs ~200-250 bytes. 头里最多两条: 自己的, 以及公开 peer 轮
|
|
794
|
-
// 的 `→
|
|
799
|
+
// 的 `→ 🧙 对方`。v3 起头从 `.name` 换成 `🧙 name` (每条约 +13 字节, ZWJ 序列 12
|
|
795
800
|
// 字节 + 空格), 预算加 64 字帖余量; md-chunk 按行块切, 不会把序列切成两半。
|
|
796
801
|
const TAG_HEADER_BUDGET = 256 * (2 + MAX_BODY_LINKS) + 64;
|
|
797
802
|
export const startMirrorTail = (deps) => {
|
|
@@ -1421,6 +1426,10 @@ const paneRunsShell = async (target) => {
|
|
|
1421
1426
|
const r = await runTmux(["display-message", "-p", "-t", target, "#{pane_current_command}"]);
|
|
1422
1427
|
return r.ok && SHELL_RE.test(r.stdout.trim());
|
|
1423
1428
|
};
|
|
1429
|
+
/** 没有绑定时 injectText 的判词。gone = 「重试也贴不进去」(会话真没了): 只有既没有绑定、
|
|
1430
|
+
* 也不在出生窗口时才算。出生窗口 (newSession / cloneSession 还没 attach) 里稍后就有绑定,
|
|
1431
|
+
* 报 gone 会让 room 泵给提问者写一条假的「没有会话 (已被结束)」—— 新群引导现场踩过。 */
|
|
1432
|
+
export const unattachedVerdict = (hasBinding, birthing) => ({ ok: false, retryable: true, reason: "no mirror attached for target", ...(hasBinding || birthing ? {} : { gone: true }) });
|
|
1424
1433
|
const paneLiveness = async (paneId) => {
|
|
1425
1434
|
if (!paneId)
|
|
1426
1435
|
return "gone";
|
|
@@ -2158,7 +2167,7 @@ const injectViaSpawn = async (args) => {
|
|
|
2158
2167
|
cwd = meta.cwd;
|
|
2159
2168
|
const hookEntry = fileURLToPath(new URL("../cli/codex-hook.js", import.meta.url));
|
|
2160
2169
|
const { loadConfig } = await import("../shared/config.js");
|
|
2161
|
-
const command = codexHookCommand(loadConfig().sourcePath,
|
|
2170
|
+
const command = codexHookCommand(loadConfig().sourcePath, daemonSocketPath(cfg), hookEntry);
|
|
2162
2171
|
codexArgs = await codexHookLaunchArgs(bin, cwd, command, cfg.approval.hookTimeoutSec + 10, cfg.approval.enabled);
|
|
2163
2172
|
}
|
|
2164
2173
|
catch (e) {
|
|
@@ -2220,8 +2229,7 @@ const injectViaSpawn = async (args) => {
|
|
|
2220
2229
|
// 审批 (缺了它 hook 会当成别人的会话交回本地 CLI —— 而这里根本没有 TTY 可点)。
|
|
2221
2230
|
env: {
|
|
2222
2231
|
...process.env, PATH: augmentedPath(process.env.PATH), WEZARD_MANAGED: "1",
|
|
2223
|
-
|
|
2224
|
-
WEZARD_DAEMON_URL: `http://${cfg.daemon.host}:${cfg.daemon.port}/approve`,
|
|
2232
|
+
WEZARD_DAEMON_SOCK: daemonSocketPath(cfg),
|
|
2225
2233
|
WEZARD_STATE_DIR: expandHome(cfg.daemon.stateDir),
|
|
2226
2234
|
WEZARD_HOOK_TIMEOUT: String(cfg.approval.hookTimeoutSec),
|
|
2227
2235
|
},
|
|
@@ -3129,7 +3137,7 @@ export const startMirror = (deps) => {
|
|
|
3129
3137
|
const openingOf = (a) => {
|
|
3130
3138
|
const t = a.jsonlPath ? lastUserTurn(a.jsonlPath, a.openingOffset) : undefined;
|
|
3131
3139
|
a.activeEventId = t?.env?.eventId;
|
|
3132
|
-
return turnOpening(t, baseOfKey(a.target), (name) => wizardStore()?.byName(stripSigil(name))?.target);
|
|
3140
|
+
return turnOpening(t, baseOfKey(a.target), (name) => wizardStore()?.byName(stripSigil(name))?.target, deps.roomOfHash);
|
|
3133
3141
|
};
|
|
3134
3142
|
/** 频道印章: 有新印章就换频道; 没有则 `reset` (CLI 手敲 / 人从聊天发起) 回到
|
|
3135
3143
|
* home, 其余续写 (收口后的补写) 沿用上一轮。`from` = 本轮的出处, 答给谁跟着频道走。
|
|
@@ -4456,6 +4464,20 @@ export const startMirror = (deps) => {
|
|
|
4456
4464
|
// 已 spawn、还没 attach 的 pane: 分身要先说开场白、等分叉文件才能绑定, 这段里它在
|
|
4457
4465
|
// tmux 里活着却不在任何绑定上 —— 孤儿清扫必须认得它, 不能只靠进程年龄宽限。
|
|
4458
4466
|
const spawningPanes = new Set();
|
|
4467
|
+
// 正在出生 (newSession / cloneSession 还没 attach) 的 target: 这段里 store 还没有绑定,
|
|
4468
|
+
// injectText 的「no mirror attached」不能算 gone —— gone 的语义是「重试也贴不进去」,
|
|
4469
|
+
// 而出生窗口只是还没生出来。room 泵会把 gone 写成一条进群的「没有会话 (已被结束)」诊断:
|
|
4470
|
+
// 新群引导的 guide 先落账人话再起 pane, 泵在这几百毫秒里探到 gone 就误报了 (2026-11-23 现场)。
|
|
4471
|
+
const birthInFlight = new Map();
|
|
4472
|
+
const beginBirth = (target) => { birthInFlight.set(target, (birthInFlight.get(target) ?? 0) + 1); };
|
|
4473
|
+
const endBirth = (target) => {
|
|
4474
|
+
const n = (birthInFlight.get(target) ?? 0) - 1;
|
|
4475
|
+
if (n > 0)
|
|
4476
|
+
birthInFlight.set(target, n);
|
|
4477
|
+
else
|
|
4478
|
+
birthInFlight.delete(target);
|
|
4479
|
+
};
|
|
4480
|
+
const birthing = (target) => (birthInFlight.get(target) ?? 0) > 0;
|
|
4459
4481
|
const sidsClaimedByOthers = (principal) => {
|
|
4460
4482
|
const s = new Set(inFlightSids);
|
|
4461
4483
|
// 空白备用池里的会话 (以及刚被领走、attach 还没落定的那几秒) 同样不能认领:
|
|
@@ -4695,9 +4717,9 @@ export const startMirror = (deps) => {
|
|
|
4695
4717
|
let restored = Promise.resolve();
|
|
4696
4718
|
if (persistedKeys.length > 0) {
|
|
4697
4719
|
// 裸 fan-out 会把 2N 次 tmux 同时压下去 —— 几百个绑定就是七百个 client 一起
|
|
4698
|
-
// 撞 10s 超时, spawn 风暴顺带把事件循环压住,
|
|
4720
|
+
// 撞 10s 超时, spawn 风暴顺带把事件循环压住, 控制面 socket 要 25s 才 bind, 而 CLI 的
|
|
4699
4721
|
// reload 探测早放弃了 (「reload issued but /status not responding」的真身)。
|
|
4700
|
-
// 一张快照 + 封顶并发; await 立刻让出, startHttp
|
|
4722
|
+
// 一张快照 + 封顶并发; await 立刻让出, startHttp 先绑控制面 socket。
|
|
4701
4723
|
restored = (async () => {
|
|
4702
4724
|
const snap = await runTmux(["list-panes", "-a", "-F", "#{pane_id}\t#{pane_current_path}\t#{window_name}\t#{pane_pid}"]);
|
|
4703
4725
|
const panes = snap.ok ? parsePaneList(snap.stdout) : undefined;
|
|
@@ -4959,13 +4981,23 @@ export const startMirror = (deps) => {
|
|
|
4959
4981
|
const POLL_MS = 500;
|
|
4960
4982
|
const TIMEOUT_MS = 5 * 60_000; // generous: user may take a while to type
|
|
4961
4983
|
const t0 = Date.now();
|
|
4984
|
+
const sizeOf = (f) => { try {
|
|
4985
|
+
return statSync(f).size;
|
|
4986
|
+
}
|
|
4987
|
+
catch {
|
|
4988
|
+
return 0;
|
|
4989
|
+
} };
|
|
4990
|
+
const armedSize = sizeOf(a.jsonlPath); // 现在的 CLI resume 原地续写同一个 jsonl, 超时时靠它长没长区分「没 fork」和「真没动静」
|
|
4962
4991
|
let stopped = false;
|
|
4963
4992
|
let timer;
|
|
4964
4993
|
const tick = () => {
|
|
4965
4994
|
if (stopped)
|
|
4966
4995
|
return;
|
|
4967
4996
|
if (Date.now() - t0 > TIMEOUT_MS) {
|
|
4968
|
-
|
|
4997
|
+
if (!exclusive && sizeOf(a.jsonlPath) > armedSize)
|
|
4998
|
+
log.info({ target: a.target, sessionId: a.sessionId }, "mirror migration: resume 原地续写, 未 fork");
|
|
4999
|
+
else
|
|
5000
|
+
log.warn({ target: a.target, sessionId: a.sessionId }, "mirror migration: timeout, giving up");
|
|
4969
5001
|
a.migrationWatcher = undefined;
|
|
4970
5002
|
return;
|
|
4971
5003
|
}
|
|
@@ -5342,7 +5374,7 @@ export const startMirror = (deps) => {
|
|
|
5342
5374
|
const respawnSpec = (a) => {
|
|
5343
5375
|
return resumedStewardSpec(cfg, a.target, backendForPath(a.jsonlPath).name, a);
|
|
5344
5376
|
};
|
|
5345
|
-
const
|
|
5377
|
+
const newSessionOnce = async (target, windowName, opts) => {
|
|
5346
5378
|
if (opts?.guard && !opts.guard())
|
|
5347
5379
|
return { ok: false, reason: "spawn guard withdrew permission" };
|
|
5348
5380
|
const prev = byTarget.get(target);
|
|
@@ -5474,6 +5506,16 @@ export const startMirror = (deps) => {
|
|
|
5474
5506
|
afterSpawn();
|
|
5475
5507
|
return { ok: true, sessionId: r.sessionId, cwd: r.cwd, model: r.model, modelWarning: r.modelWarning, effort: r.effort };
|
|
5476
5508
|
};
|
|
5509
|
+
/** 整段出生都记在 birthInFlight 上: 期间没有绑定, 但这不等于 gone (见那里的注释)。 */
|
|
5510
|
+
const newSession = async (target, windowName, opts) => {
|
|
5511
|
+
beginBirth(target);
|
|
5512
|
+
try {
|
|
5513
|
+
return await newSessionOnce(target, windowName, opts);
|
|
5514
|
+
}
|
|
5515
|
+
finally {
|
|
5516
|
+
endBirth(target);
|
|
5517
|
+
}
|
|
5518
|
+
};
|
|
5477
5519
|
// ── Clone ───────────────────────────────────────────────────────────
|
|
5478
5520
|
// 分身 = `--resume <父 sid> --fork-session` 起的新 pane: CLI 把父亲的 transcript
|
|
5479
5521
|
// 复制成一份新的再继续写, 于是子进程开局就带着父亲此刻读过的一切 (规范、目录、
|
|
@@ -5522,7 +5564,7 @@ export const startMirror = (deps) => {
|
|
|
5522
5564
|
}
|
|
5523
5565
|
return undefined;
|
|
5524
5566
|
};
|
|
5525
|
-
const
|
|
5567
|
+
const cloneSessionOnce = async (args) => {
|
|
5526
5568
|
if (args.guard && !args.guard("paste"))
|
|
5527
5569
|
return { ok: false, reason: "spawn guard withdrew permission", inherited: false };
|
|
5528
5570
|
const p = byTarget.get(args.parent) ?? (await restoreFromStore(args.parent, undefined, () => !args.guard || args.guard()));
|
|
@@ -5639,6 +5681,16 @@ export const startMirror = (deps) => {
|
|
|
5639
5681
|
afterSpawn();
|
|
5640
5682
|
return { ok: true, sessionId: fork.sessionId, cwd: r.cwd, inherited: true, model: r.model, modelWarning: r.modelWarning, effort: r.effort };
|
|
5641
5683
|
};
|
|
5684
|
+
/** 分叉到 attach 之间同样是出生窗口 (store 里还没有这个 target 的绑定)。 */
|
|
5685
|
+
const cloneSession = async (args) => {
|
|
5686
|
+
beginBirth(args.target);
|
|
5687
|
+
try {
|
|
5688
|
+
return await cloneSessionOnce(args);
|
|
5689
|
+
}
|
|
5690
|
+
finally {
|
|
5691
|
+
endBirth(args.target);
|
|
5692
|
+
}
|
|
5693
|
+
};
|
|
5642
5694
|
/** 一个会话此刻的硬事实 —— whoami / 交接判断要用的那几个数。 */
|
|
5643
5695
|
const sessionInfo = (target) => {
|
|
5644
5696
|
const a = byTarget.get(target);
|
|
@@ -5802,9 +5854,7 @@ export const startMirror = (deps) => {
|
|
|
5802
5854
|
// peer 寻址只接受全局 wizard 名字或完整 target key。
|
|
5803
5855
|
const resolvePeerTag = (self, ref) => {
|
|
5804
5856
|
const raw = stripSigil(ref);
|
|
5805
|
-
|
|
5806
|
-
// 单机器人时 sameBot 恒真, 这一行什么也不滤。
|
|
5807
|
-
const all = allTargets().filter((k) => sameBot(self, k));
|
|
5857
|
+
const all = allTargets();
|
|
5808
5858
|
const hit = (target) => ({ ok: true, target, foreign: baseOfKey(target) !== baseOfKey(self) });
|
|
5809
5859
|
if (!raw)
|
|
5810
5860
|
return hit(baseOfKey(self));
|
|
@@ -5813,7 +5863,7 @@ export const startMirror = (deps) => {
|
|
|
5813
5863
|
}
|
|
5814
5864
|
// 名字属于身份 (§2): 优先落「身份在调用方本聊天的化身」(A 群里的 chat_ask 点名只找
|
|
5815
5865
|
// A 群的化身, 不串 B 群的); 身份在本聊天没有化身时回落锚点化身 (旧世界的跨群寻址)。
|
|
5816
|
-
const named =
|
|
5866
|
+
const named = manifestationOf(wizardStore(), raw, baseOfKey(self));
|
|
5817
5867
|
if (named && all.includes(named))
|
|
5818
5868
|
return hit(named);
|
|
5819
5869
|
if (named)
|
|
@@ -6085,7 +6135,7 @@ export const startMirror = (deps) => {
|
|
|
6085
6135
|
const foreignPeers = async (self) => {
|
|
6086
6136
|
const selfBase = baseOfKey(self);
|
|
6087
6137
|
// 只列活着的 / 有身份的 —— 冷绑定可能有几百个, 每个探活是两次 tmux。
|
|
6088
|
-
const foreign = allTargets().filter((k) => baseOfKey(k) !== selfBase &&
|
|
6138
|
+
const foreign = allTargets().filter((k) => baseOfKey(k) !== selfBase && (byTarget.has(k) || !!wizardStore()?.get(k)));
|
|
6089
6139
|
return (await Promise.all(foreign.map((t) => peerInfoOf(t, self)))).sort(byRecent);
|
|
6090
6140
|
};
|
|
6091
6141
|
// peerInfoOf 每个 target 要两次 tmux (pane 存活 + capture tail)。跑了几个月的
|
|
@@ -7338,9 +7388,9 @@ export const startMirror = (deps) => {
|
|
|
7338
7388
|
const a = byTarget.get(target) ?? (await restoreFromStore(target, undefined, permission));
|
|
7339
7389
|
if (!permission())
|
|
7340
7390
|
return denied;
|
|
7341
|
-
// A missing binding cannot recover on retry; let receipts escalate.
|
|
7391
|
+
// A missing binding cannot recover on retry; let receipts escalate. 出生窗口例外 (unattachedVerdict)。
|
|
7342
7392
|
if (!a)
|
|
7343
|
-
return
|
|
7393
|
+
return unattachedVerdict(!!deps.store.get(target), birthing(target));
|
|
7344
7394
|
if (opts?.handoff && !(await verifyClearContext(target, opts.handoff)))
|
|
7345
7395
|
return { ok: false, retryable: false, reason: "original cleared CLI process/session changed; handoff carry withheld" };
|
|
7346
7396
|
const sid = a.sessionId;
|
|
@@ -8202,8 +8252,9 @@ export const startMirror = (deps) => {
|
|
|
8202
8252
|
// Confirm the /model picker. Early Enter (before the picker renders)
|
|
8203
8253
|
// would leave it unconfirmed, so settle first; a late Enter is a
|
|
8204
8254
|
// harmless no-op in the empty input box. On confirm, claude writes
|
|
8205
|
-
// "Set model to …" as <local-command-stdout> —
|
|
8206
|
-
//
|
|
8255
|
+
// "Set model to …" as <local-command-stdout> — that receipt is CLI-local
|
|
8256
|
+
// state and stays out of the chat (shared/cli-local-status.ts); the caller
|
|
8257
|
+
// reads it off the pane through model-select, not from WeCom.
|
|
8207
8258
|
if (isModelSwitch && a.tmuxPane) {
|
|
8208
8259
|
await sleep(1000);
|
|
8209
8260
|
const e = await runTmux(["send-keys", "-t", a.tmuxPane, "Enter"]);
|