@cydm/pie 4.14.0 → 4.15.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/README.md +5 -5
- package/dist/builtin/extensions/ask-user/index.js +4 -4
- package/dist/builtin/extensions/cron/index.js +70 -17
- package/dist/builtin/extensions/im-forward/index.js +889 -205
- package/dist/builtin/extensions/memory/index.js +6 -6
- package/dist/builtin/extensions/memory/package.json +1 -2
- package/dist/builtin/extensions/pie-proc/README.md +12 -3
- package/dist/builtin/extensions/pie-proc/index.js +88 -45
- package/dist/builtin/extensions/plan-mode/index.js +4 -4
- package/dist/builtin/extensions/subagent/index.js +5 -5
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/chunks/{chunk-FD3KBPDR.js → chunk-6AYPNTCO.js} +8 -8
- package/dist/chunks/{chunk-JJH77AUU.js → chunk-J6EZ335F.js} +8 -7
- package/dist/chunks/{chunk-EZZTMDWZ.js → chunk-JE53PC46.js} +1064 -161
- package/dist/chunks/{chunk-BOQIGMGQ.js → chunk-LIA52LJU.js} +3 -3
- package/dist/chunks/{chunk-26KRUYZH.js → chunk-MTH6QSYD.js} +1 -1
- package/dist/chunks/{chunk-UYDS75SI.js → chunk-NAMH667S.js} +11 -15
- package/dist/chunks/{chunk-IK2FR2YF.js → chunk-VWDCKHCC.js} +1 -1
- package/dist/chunks/{chunk-MCR4JYI6.js → chunk-YKV45EMY.js} +313 -149
- package/dist/chunks/{chunk-JKO42HZW.js → chunk-ZBIR5YS7.js} +1 -1
- package/dist/chunks/{chunk-KGWKRO7Z.js → chunk-ZH6EAKVM.js} +2 -2
- package/dist/chunks/{host-image-fallback-LPHB5CTL.js → host-image-fallback-GX2KXZXQ.js} +1 -1
- package/dist/chunks/{memory-git-ZJN6SPIU.js → memory-git-BJMYZHIE.js} +5 -5
- package/dist/chunks/{model-registry-GLBIUOJR.js → model-registry-T6EMM66I.js} +2 -2
- package/dist/chunks/{read-file-understanding-DFJPTTSB.js → read-file-understanding-ZRE5KDG3.js} +5 -5
- package/dist/chunks/{src-KZ7YID3I.js → src-DLAIQCKP.js} +3 -3
- package/dist/chunks/{src-ALHMJZ5R.js → src-FWL3LCBK.js} +2 -2
- package/dist/chunks/{src-LEXKDSFV.js → src-OP6LFLR6.js} +8 -4
- package/dist/chunks/{src-76Q33OY5.js → src-XJKZIY3S.js} +11 -1
- package/dist/chunks/{test-stream-OVGDTXOY.js → test-stream-P3CUEGEE.js} +1 -1
- package/dist/cli.js +408 -52
- package/models.schema.json +4 -0
- package/package.json +2 -2
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
currentWorkerLifecycleBridge,
|
|
18
18
|
syncInheritedWorkerModels
|
|
19
|
-
} from "../../../chunks/chunk-
|
|
19
|
+
} from "../../../chunks/chunk-ZBIR5YS7.js";
|
|
20
20
|
import {
|
|
21
21
|
readProcessCommandLine
|
|
22
22
|
} from "../../../chunks/chunk-7RJXKN7N.js";
|
|
@@ -29,10 +29,10 @@ import {
|
|
|
29
29
|
readDistillWorkerLog,
|
|
30
30
|
spawnDistillAutoWorker,
|
|
31
31
|
spawnWikiGcWorker
|
|
32
|
-
} from "../../../chunks/chunk-
|
|
32
|
+
} from "../../../chunks/chunk-6AYPNTCO.js";
|
|
33
33
|
import {
|
|
34
34
|
readCuratedMemoryGitLog
|
|
35
|
-
} from "../../../chunks/chunk-
|
|
35
|
+
} from "../../../chunks/chunk-VWDCKHCC.js";
|
|
36
36
|
import {
|
|
37
37
|
liveSessionHolder
|
|
38
38
|
} from "../../../chunks/chunk-Q5PSWX3B.js";
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
} from "../../../chunks/chunk-Q4NJEPIZ.js";
|
|
44
44
|
import {
|
|
45
45
|
loadResolvedModelsConfig
|
|
46
|
-
} from "../../../chunks/chunk-
|
|
46
|
+
} from "../../../chunks/chunk-NAMH667S.js";
|
|
47
47
|
import {
|
|
48
48
|
getConfigDir
|
|
49
49
|
} from "../../../chunks/chunk-CBDQJMUI.js";
|
|
@@ -52,10 +52,10 @@ import {
|
|
|
52
52
|
WikiStore,
|
|
53
53
|
estimateWikiTokens,
|
|
54
54
|
todayKey
|
|
55
|
-
} from "../../../chunks/chunk-
|
|
56
|
-
import "../../../chunks/chunk-
|
|
57
|
-
import "../../../chunks/chunk-
|
|
58
|
-
import "../../../chunks/chunk-
|
|
55
|
+
} from "../../../chunks/chunk-JE53PC46.js";
|
|
56
|
+
import "../../../chunks/chunk-J6EZ335F.js";
|
|
57
|
+
import "../../../chunks/chunk-MTH6QSYD.js";
|
|
58
|
+
import "../../../chunks/chunk-YKV45EMY.js";
|
|
59
59
|
import {
|
|
60
60
|
cronActiveCount,
|
|
61
61
|
cronBlockedSummary,
|
|
@@ -903,7 +903,7 @@ function stopOwnedTreeInner(child, signal) {
|
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
|
-
return new Promise((
|
|
906
|
+
return new Promise((resolve9) => {
|
|
907
907
|
let done = false;
|
|
908
908
|
let killer;
|
|
909
909
|
const finish = (ok) => {
|
|
@@ -916,7 +916,7 @@ function stopOwnedTreeInner(child, signal) {
|
|
|
916
916
|
} catch {
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
|
-
|
|
919
|
+
resolve9(ok);
|
|
920
920
|
};
|
|
921
921
|
const timer = setTimeout(() => {
|
|
922
922
|
try {
|
|
@@ -971,14 +971,14 @@ function shutdownConsumer(child) {
|
|
|
971
971
|
}
|
|
972
972
|
async function shutdownConsumerInner(child) {
|
|
973
973
|
let closed = false;
|
|
974
|
-
const close = new Promise((
|
|
974
|
+
const close = new Promise((resolve9) => child.once("close", () => {
|
|
975
975
|
closed = true;
|
|
976
|
-
|
|
976
|
+
resolve9();
|
|
977
977
|
}));
|
|
978
978
|
const wait = async (ms) => {
|
|
979
979
|
let timer;
|
|
980
|
-
await Promise.race([close, new Promise((
|
|
981
|
-
timer = setTimeout(
|
|
980
|
+
await Promise.race([close, new Promise((resolve9) => {
|
|
981
|
+
timer = setTimeout(resolve9, ms);
|
|
982
982
|
})]);
|
|
983
983
|
clearTimeout(timer);
|
|
984
984
|
};
|
|
@@ -1002,9 +1002,9 @@ async function shutdownConsumerInner(child) {
|
|
|
1002
1002
|
|
|
1003
1003
|
// builtin/extensions/im-forward/lark-cli.ts
|
|
1004
1004
|
async function runLarkCli(binary, args, timeoutMs = 3e4, cwd, options = {}) {
|
|
1005
|
-
return new Promise((
|
|
1005
|
+
return new Promise((resolve9) => {
|
|
1006
1006
|
if (options.signal?.aborted) {
|
|
1007
|
-
|
|
1007
|
+
resolve9({ stdout: "", error: "cancelled" });
|
|
1008
1008
|
return;
|
|
1009
1009
|
}
|
|
1010
1010
|
let child;
|
|
@@ -1019,7 +1019,7 @@ async function runLarkCli(binary, args, timeoutMs = 3e4, cwd, options = {}) {
|
|
|
1019
1019
|
...cwd ? { cwd } : {}
|
|
1020
1020
|
});
|
|
1021
1021
|
} catch {
|
|
1022
|
-
|
|
1022
|
+
resolve9({ stdout: "", error: "spawn failed" });
|
|
1023
1023
|
return;
|
|
1024
1024
|
}
|
|
1025
1025
|
let stdout = "";
|
|
@@ -1037,7 +1037,7 @@ async function runLarkCli(binary, args, timeoutMs = 3e4, cwd, options = {}) {
|
|
|
1037
1037
|
clearTimeout(killTimer);
|
|
1038
1038
|
clearTimeout(closeTimer);
|
|
1039
1039
|
options.signal?.removeEventListener("abort", abort);
|
|
1040
|
-
|
|
1040
|
+
resolve9(result);
|
|
1041
1041
|
};
|
|
1042
1042
|
const terminatedResult = () => ({ stdout: termination?.startsWith("timeout") ? stdout : "", error: termination });
|
|
1043
1043
|
const stop = (signal) => {
|
|
@@ -1123,7 +1123,7 @@ async function runLarkCli(binary, args, timeoutMs = 3e4, cwd, options = {}) {
|
|
|
1123
1123
|
errorLines?.end();
|
|
1124
1124
|
if (termination) return;
|
|
1125
1125
|
if (code === 0 && (stdout.trim() || options.allowEmpty)) finish({ stdout });
|
|
1126
|
-
else finish({ stdout, error: `exit ${code}${stderr ? `: ${stderr.slice(-300).trim()}` : ""}` });
|
|
1126
|
+
else finish({ stdout, ...stderr ? { stderr } : {}, error: `exit ${code}${stderr ? `: ${stderr.slice(-300).trim()}` : ""}` });
|
|
1127
1127
|
});
|
|
1128
1128
|
});
|
|
1129
1129
|
}
|
|
@@ -1238,8 +1238,15 @@ function parseLarkCliEnvelope(stdout) {
|
|
|
1238
1238
|
if (parsed.ok === true && isRecord(parsed.data)) return { ok: true, data: parsed.data };
|
|
1239
1239
|
if (parsed.code === 0 && isRecord(parsed.data)) return { ok: true, data: parsed.data };
|
|
1240
1240
|
if (parsed.ok === false) {
|
|
1241
|
-
|
|
1242
|
-
|
|
1241
|
+
if (isRecord(parsed.error)) {
|
|
1242
|
+
const code = typeof parsed.error.code === "number" || typeof parsed.error.code === "string" ? String(parsed.error.code) : void 0;
|
|
1243
|
+
const msg = typeof parsed.error.message === "string" && parsed.error.message.trim() ? parsed.error.message.trim() : typeof parsed.error.msg === "string" && parsed.error.msg.trim() ? parsed.error.msg.trim() : void 0;
|
|
1244
|
+
if (code && msg) return { ok: false, errorText: `lark-cli error code ${code}: ${msg}` };
|
|
1245
|
+
if (msg) return { ok: false, errorText: `lark-cli error: ${msg}` };
|
|
1246
|
+
if (code) return { ok: false, errorText: `lark-cli error code ${code}` };
|
|
1247
|
+
return { ok: false, errorText: `lark-cli error: ${JSON.stringify(parsed.error)}` };
|
|
1248
|
+
}
|
|
1249
|
+
return { ok: false, errorText: "lark-cli error: unknown" };
|
|
1243
1250
|
}
|
|
1244
1251
|
if (typeof parsed.code === "number" && parsed.code !== 0) {
|
|
1245
1252
|
return { ok: false, errorText: `lark-cli error code ${String(parsed.code)}: ${String(parsed.msg ?? "unknown")}` };
|
|
@@ -1274,13 +1281,16 @@ function extractImageKey(content) {
|
|
|
1274
1281
|
var SAFE_FEISHU_CHAT_ID = /^oc_[A-Za-z0-9_-]+$/;
|
|
1275
1282
|
var SAFE_FEISHU_THREAD_ID = /^omt_[A-Za-z0-9_-]+$/;
|
|
1276
1283
|
var SAFE_APPLINK_HOST = /^[a-z0-9.-]+$/i;
|
|
1284
|
+
var FEISHU_THREAD_LATEST_POSITION = "9999999";
|
|
1277
1285
|
function formatFeishuThreadUrl(anchor) {
|
|
1278
1286
|
const rawChat = typeof anchor.chatId === "string" && anchor.chatId ? anchor.chatId : typeof anchor.home === "string" && anchor.home ? anchor.home : "";
|
|
1279
1287
|
const rawThread = typeof anchor.threadId === "string" ? anchor.threadId : "";
|
|
1280
1288
|
if (!SAFE_FEISHU_CHAT_ID.test(rawChat) || !SAFE_FEISHU_THREAD_ID.test(rawThread)) return void 0;
|
|
1281
1289
|
const rawHost = process.env.PIE_FEISHU_APPLINK_HOST?.trim() || "applink.feishu.cn";
|
|
1282
1290
|
const host = SAFE_APPLINK_HOST.test(rawHost) ? rawHost : "applink.feishu.cn";
|
|
1283
|
-
|
|
1291
|
+
const encodedChat = encodeURIComponent(rawChat);
|
|
1292
|
+
const encodedThread = encodeURIComponent(rawThread);
|
|
1293
|
+
return `https://${host}/client/thread/open?open_chat_id=${encodedChat}&open_thread_id=${encodedThread}&openchatid=${encodedChat}&openthreadid=${encodedThread}&thread_position=${FEISHU_THREAD_LATEST_POSITION}`;
|
|
1284
1294
|
}
|
|
1285
1295
|
|
|
1286
1296
|
// builtin/extensions/im-forward/providers/feishu/setup.ts
|
|
@@ -1303,7 +1313,7 @@ async function openBrowser(url, signal, seam = {}) {
|
|
|
1303
1313
|
if (signal.aborted || !/^https:\/\/[^\s\x00-\x1f\x7f]+$/.test(url)) return "failed";
|
|
1304
1314
|
const spec = browserLaunch(seam.platform);
|
|
1305
1315
|
if (!spec) return "failed";
|
|
1306
|
-
return new Promise((
|
|
1316
|
+
return new Promise((resolve9) => {
|
|
1307
1317
|
let child;
|
|
1308
1318
|
let settled = false;
|
|
1309
1319
|
let stopping = false;
|
|
@@ -1318,7 +1328,7 @@ async function openBrowser(url, signal, seam = {}) {
|
|
|
1318
1328
|
child?.stdin?.destroy();
|
|
1319
1329
|
child?.stdout?.destroy();
|
|
1320
1330
|
child?.stderr?.destroy();
|
|
1321
|
-
|
|
1331
|
+
resolve9(result);
|
|
1322
1332
|
};
|
|
1323
1333
|
const stop = () => {
|
|
1324
1334
|
if (settled || stopping) return;
|
|
@@ -1963,7 +1973,7 @@ function normalizeMenuEvent(line, fallbackChatId) {
|
|
|
1963
1973
|
};
|
|
1964
1974
|
}
|
|
1965
1975
|
var PATCH_RETRY_DELAYS_MS = [300, 900];
|
|
1966
|
-
var PERMANENT_PATCH_ERROR_PATTERN = /\b(?:230001|230002|230011|230013|230027|230072|230073|230099|200621|200340|200341)\b|recalled|deleted|message not found|card not found|14 day|invalid_argument|permission|unauthorized|cancelled|update_multi/i;
|
|
1976
|
+
var PERMANENT_PATCH_ERROR_PATTERN = /\b(?:230001|230002|230011|230013|230027|230072|230073|230099|200621|200340|200341|99992354)\b|recalled|deleted|message not found|card not found|not a valid|not exists|14 day|invalid_argument|permission|unauthorized|cancelled|update_multi/i;
|
|
1967
1977
|
function isPermanentFeishuPatchError(reason) {
|
|
1968
1978
|
return Boolean(reason && PERMANENT_PATCH_ERROR_PATTERN.test(reason));
|
|
1969
1979
|
}
|
|
@@ -1973,20 +1983,19 @@ function sanitizePatchError(raw) {
|
|
|
1973
1983
|
}
|
|
1974
1984
|
function sleepAbortable(ms, signal) {
|
|
1975
1985
|
if (signal.aborted) return Promise.resolve(false);
|
|
1976
|
-
return new Promise((
|
|
1986
|
+
return new Promise((resolve9) => {
|
|
1977
1987
|
const onAbort = () => {
|
|
1978
1988
|
clearTimeout(timer);
|
|
1979
|
-
|
|
1989
|
+
resolve9(false);
|
|
1980
1990
|
};
|
|
1981
1991
|
const timer = setTimeout(() => {
|
|
1982
1992
|
signal.removeEventListener("abort", onAbort);
|
|
1983
|
-
|
|
1993
|
+
resolve9(true);
|
|
1984
1994
|
}, ms);
|
|
1985
|
-
timer.unref?.();
|
|
1986
1995
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
1987
1996
|
});
|
|
1988
1997
|
}
|
|
1989
|
-
function connect(binary, profile, targetKind = "chat", settings = { targetId: "" }) {
|
|
1998
|
+
function connect(binary, profile, targetKind = "chat", settings = { targetId: "" }, connectCwd) {
|
|
1990
1999
|
const lifetime = new AbortController();
|
|
1991
2000
|
const active = /* @__PURE__ */ new Set();
|
|
1992
2001
|
const native = (...args) => {
|
|
@@ -1995,18 +2004,20 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
1995
2004
|
void pending.finally(() => active.delete(pending));
|
|
1996
2005
|
return pending;
|
|
1997
2006
|
};
|
|
1998
|
-
const callDetailed = async (args) => {
|
|
1999
|
-
const result = await native(binary, profile ? [...args, "--profile", profile] : args, 3e4,
|
|
2007
|
+
const callDetailed = async (args, callCwd) => {
|
|
2008
|
+
const result = await native(binary, profile ? [...args, "--profile", profile] : args, 3e4, callCwd, { signal: lifetime.signal });
|
|
2000
2009
|
if (result.error) {
|
|
2001
|
-
const
|
|
2010
|
+
const rawEnvelope = result.stdout.trim() || result.stderr?.trim() || "";
|
|
2011
|
+
const env2 = rawEnvelope ? parseLarkCliEnvelope(rawEnvelope) : void 0;
|
|
2012
|
+
if (env2?.ok === false && env2.errorText) return { ok: false, error: env2.errorText };
|
|
2002
2013
|
return { ok: false, error: env2?.errorText ? `${result.error} (${env2.errorText})` : result.error };
|
|
2003
2014
|
}
|
|
2004
2015
|
const env = parseLarkCliEnvelope(result.stdout);
|
|
2005
2016
|
if (env.ok && env.data) return { ok: true, data: env.data };
|
|
2006
2017
|
return { ok: false, error: env.errorText ?? "empty lark-cli response" };
|
|
2007
2018
|
};
|
|
2008
|
-
const call = async (args) => {
|
|
2009
|
-
const res = await callDetailed(args);
|
|
2019
|
+
const call = async (args, callCwd) => {
|
|
2020
|
+
const res = await callDetailed(args, callCwd);
|
|
2010
2021
|
return res.ok ? res.data : void 0;
|
|
2011
2022
|
};
|
|
2012
2023
|
const lastPatchErrors = /* @__PURE__ */ new Map();
|
|
@@ -2020,22 +2031,42 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2020
2031
|
};
|
|
2021
2032
|
let canonicalAppIdCache = null;
|
|
2022
2033
|
let canonicalResolved = false;
|
|
2034
|
+
let defaultBusAppIdCache = null;
|
|
2035
|
+
let defaultBusAppIdResolved = false;
|
|
2023
2036
|
const BUS_RECONNECT_GRACE_MS = 10 * 60 * 1e3;
|
|
2037
|
+
const configuredAppId = typeof settings.appId === "string" && settings.appId.trim() ? settings.appId.trim() : typeof settings.larkCliAppId === "string" && settings.larkCliAppId.trim() ? settings.larkCliAppId.trim() : void 0;
|
|
2024
2038
|
async function canonicalAppIdNow() {
|
|
2025
2039
|
if (canonicalResolved) return canonicalAppIdCache || void 0;
|
|
2026
2040
|
if (!profile) {
|
|
2041
|
+
canonicalAppIdCache = configuredAppId ?? null;
|
|
2027
2042
|
canonicalResolved = true;
|
|
2028
|
-
return
|
|
2043
|
+
return configuredAppId;
|
|
2029
2044
|
}
|
|
2030
2045
|
try {
|
|
2031
2046
|
const result = await native(binary, ["profile", "list"], 1e4, void 0, { signal: lifetime.signal });
|
|
2032
2047
|
const profiles = result.error ? null : parseProfiles(result.stdout);
|
|
2033
|
-
if (!profiles) return
|
|
2048
|
+
if (!profiles) return configuredAppId;
|
|
2034
2049
|
const appId = profiles.find((item) => item.name === profile)?.appId;
|
|
2035
|
-
if (!appId) return
|
|
2050
|
+
if (!appId) return configuredAppId;
|
|
2036
2051
|
canonicalAppIdCache = appId;
|
|
2037
2052
|
canonicalResolved = true;
|
|
2038
2053
|
return appId;
|
|
2054
|
+
} catch {
|
|
2055
|
+
return configuredAppId;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
async function resolveBusHealthAppId() {
|
|
2059
|
+
const known = await canonicalAppIdNow();
|
|
2060
|
+
if (known) return known;
|
|
2061
|
+
if (defaultBusAppIdResolved) return defaultBusAppIdCache || void 0;
|
|
2062
|
+
try {
|
|
2063
|
+
const result = await native(binary, ["profile", "list"], 1e4, void 0, { signal: lifetime.signal });
|
|
2064
|
+
const profiles = result.error ? null : parseProfiles(result.stdout);
|
|
2065
|
+
if (!profiles) return void 0;
|
|
2066
|
+
const appId = (profiles.find((item) => item.active) ?? (profiles.length === 1 ? profiles[0] : void 0))?.appId;
|
|
2067
|
+
defaultBusAppIdCache = appId ?? null;
|
|
2068
|
+
defaultBusAppIdResolved = true;
|
|
2069
|
+
return appId;
|
|
2039
2070
|
} catch {
|
|
2040
2071
|
return void 0;
|
|
2041
2072
|
}
|
|
@@ -2060,8 +2091,19 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2060
2091
|
async sendFile(target, file, key, replyTo, options) {
|
|
2061
2092
|
const recipient = targetKind === "user" ? ["--user-id", target] : ["--chat-id", target];
|
|
2062
2093
|
const boundedKey = boundIdempotencyKey(key);
|
|
2094
|
+
const isRemoteOrKey = /^file_[A-Za-z0-9_-]+$/.test(file) || /^https?:\/\//i.test(file);
|
|
2095
|
+
let fileArg = file;
|
|
2096
|
+
let fileCwd = connectCwd;
|
|
2097
|
+
if (!isRemoteOrKey) {
|
|
2098
|
+
const resolvedFile = path7.resolve(connectCwd ?? process.cwd(), file);
|
|
2099
|
+
fileCwd = path7.dirname(resolvedFile);
|
|
2100
|
+
fileArg = path7.basename(resolvedFile);
|
|
2101
|
+
}
|
|
2063
2102
|
const threadFlag = options?.replyInThread ? ["--reply-in-thread"] : [];
|
|
2064
|
-
const data = await call(
|
|
2103
|
+
const data = await call(
|
|
2104
|
+
replyTo ? ["im", "+messages-reply", "--as", "bot", "--message-id", replyTo, ...threadFlag, "--file", fileArg, "--idempotency-key", boundedKey] : ["im", "+messages-send", "--as", "bot", ...recipient, "--file", fileArg, "--idempotency-key", boundedKey],
|
|
2105
|
+
fileCwd
|
|
2106
|
+
);
|
|
2065
2107
|
return typeof data?.message_id === "string" ? { messageId: data.message_id, threadId: typeof data.thread_id === "string" ? data.thread_id : null, ...typeof data.chat_id === "string" && data.chat_id ? { chatId: data.chat_id } : {} } : null;
|
|
2066
2108
|
},
|
|
2067
2109
|
// 4.3.10 panel cards: compile the neutral CardSpec and send it as an
|
|
@@ -2125,18 +2167,22 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2125
2167
|
},
|
|
2126
2168
|
async resolveUserName(userId, signal) {
|
|
2127
2169
|
if (!userId || signal?.aborted) return void 0;
|
|
2128
|
-
const baseArgs = ["contact", "+get-user", "--user-id", userId, "--as", "bot"];
|
|
2129
|
-
const args = profile ? [...baseArgs, "--profile", profile] : baseArgs;
|
|
2130
2170
|
const combined = signal ? AbortSignal.any([lifetime.signal, signal]) : lifetime.signal;
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
if (
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2171
|
+
const lookupAs = async (identity) => {
|
|
2172
|
+
if (combined.aborted) return void 0;
|
|
2173
|
+
const baseArgs = ["contact", "+get-user", "--user-id", userId, "--as", identity];
|
|
2174
|
+
const args = profile ? [...baseArgs, "--profile", profile] : baseArgs;
|
|
2175
|
+
const result = await native(binary, args, 1e4, void 0, { signal: combined });
|
|
2176
|
+
if (combined.aborted || result.error || !result.stdout.trim()) return void 0;
|
|
2177
|
+
try {
|
|
2178
|
+
const parsed = JSON.parse(result.stdout);
|
|
2179
|
+
if (typeof parsed?.data?.user?.name === "string" && parsed.data.user.name.trim()) return parsed.data.user.name.trim();
|
|
2180
|
+
if (typeof parsed?.name === "string" && parsed.name.trim()) return parsed.name.trim();
|
|
2181
|
+
} catch {
|
|
2182
|
+
}
|
|
2183
|
+
return void 0;
|
|
2184
|
+
};
|
|
2185
|
+
return await lookupAs("bot") ?? await lookupAs("user");
|
|
2140
2186
|
},
|
|
2141
2187
|
async metadata(id) {
|
|
2142
2188
|
const data = await call(["im", "+messages-mget", "--as", "bot", "--message-ids", id]);
|
|
@@ -2390,7 +2436,7 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2390
2436
|
// = undefined (no signal, not an alarm) — escalate only on a POSITIVE
|
|
2391
2437
|
// stale reading.
|
|
2392
2438
|
async consumeBusHealth() {
|
|
2393
|
-
const appId = await
|
|
2439
|
+
const appId = await resolveBusHealthAppId();
|
|
2394
2440
|
if (!appId) return void 0;
|
|
2395
2441
|
const larkHome = process.env.PIE_LARK_CLI_HOME && process.env.PIE_LARK_CLI_HOME.trim() ? process.env.PIE_LARK_CLI_HOME : os3.homedir();
|
|
2396
2442
|
const logPath = path7.join(larkHome, ".lark-cli", "events", appId, "bus.log");
|
|
@@ -2446,14 +2492,14 @@ var FEISHU_REACTION_MAP = {
|
|
|
2446
2492
|
async function probeCardActionSubscription(ui, cwd, binaryOverride, profile) {
|
|
2447
2493
|
const spec = resolveLaunchSpec(binaryOverride, cwd);
|
|
2448
2494
|
if (!spec) return;
|
|
2449
|
-
await new Promise((
|
|
2495
|
+
await new Promise((resolve9) => {
|
|
2450
2496
|
let settled = false;
|
|
2451
2497
|
let timer;
|
|
2452
2498
|
const done = () => {
|
|
2453
2499
|
if (settled) return;
|
|
2454
2500
|
settled = true;
|
|
2455
2501
|
if (timer) clearTimeout(timer);
|
|
2456
|
-
|
|
2502
|
+
resolve9();
|
|
2457
2503
|
};
|
|
2458
2504
|
const child = spawn4(spec.command, [...spec.prefix, "event", "consume", "card.action.trigger", "--as", "bot", ...profile ? ["--profile", profile] : []], { cwd, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
2459
2505
|
timer = setTimeout(() => {
|
|
@@ -2501,7 +2547,7 @@ var feishuProvider = {
|
|
|
2501
2547
|
connect(settings, cwd) {
|
|
2502
2548
|
const binary = resolveLaunchSpec(typeof settings.larkCli === "string" ? settings.larkCli : void 0, cwd);
|
|
2503
2549
|
const profile = typeof settings.larkCliProfile === "string" && settings.larkCliProfile.trim() ? settings.larkCliProfile.trim() : void 0;
|
|
2504
|
-
return binary ? connect(binary, profile, settings.targetKind, settings) : null;
|
|
2550
|
+
return binary ? connect(binary, profile, settings.targetKind, settings, cwd) : null;
|
|
2505
2551
|
},
|
|
2506
2552
|
setup: setupFeishu,
|
|
2507
2553
|
formatThreadUrl: formatFeishuThreadUrl,
|
|
@@ -3294,7 +3340,7 @@ function createConsumerLifecycle(ctx) {
|
|
|
3294
3340
|
}
|
|
3295
3341
|
function stopGeneration(gen) {
|
|
3296
3342
|
if (gen.startup) clearTimeout(gen.startup);
|
|
3297
|
-
return gen.stopping ??= new Promise((
|
|
3343
|
+
return gen.stopping ??= new Promise((resolve9) => {
|
|
3298
3344
|
let settled = false;
|
|
3299
3345
|
const finishWait = (failed) => {
|
|
3300
3346
|
if (settled) return;
|
|
@@ -3305,7 +3351,7 @@ function createConsumerLifecycle(ctx) {
|
|
|
3305
3351
|
ctx.log(`im-forward: ${ctx.provider} consumer stop failed`);
|
|
3306
3352
|
}
|
|
3307
3353
|
gen.retired = true;
|
|
3308
|
-
|
|
3354
|
+
resolve9();
|
|
3309
3355
|
};
|
|
3310
3356
|
const timer = setTimeout(() => finishWait(true), STOP_GENERATION_TIMEOUT_MS);
|
|
3311
3357
|
timer.unref?.();
|
|
@@ -3345,8 +3391,8 @@ function createConsumerLifecycle(ctx) {
|
|
|
3345
3391
|
async function stopGenerationWithRetry(gen) {
|
|
3346
3392
|
await stopGeneration(gen);
|
|
3347
3393
|
if (!gen.stopFailed || !gen.handle || ctx.isTerminated()) return;
|
|
3348
|
-
await new Promise((
|
|
3349
|
-
const t = setTimeout(
|
|
3394
|
+
await new Promise((resolve9) => {
|
|
3395
|
+
const t = setTimeout(resolve9, 300);
|
|
3350
3396
|
t.unref?.();
|
|
3351
3397
|
});
|
|
3352
3398
|
if (ctx.isTerminated()) return;
|
|
@@ -4404,9 +4450,9 @@ function sessionRootOwner(provider, messageId) {
|
|
|
4404
4450
|
// builtin/extensions/im-forward/runtime-outbound.ts
|
|
4405
4451
|
import * as crypto from "node:crypto";
|
|
4406
4452
|
import * as fs11 from "node:fs";
|
|
4407
|
-
import { basename } from "node:path";
|
|
4453
|
+
import { basename as basename2 } from "node:path";
|
|
4408
4454
|
var CHUNK_RETRY_DELAY_MS = 2e3;
|
|
4409
|
-
var delay = (ms) => new Promise((
|
|
4455
|
+
var delay = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
4410
4456
|
var IM_INPUT_FALLBACK_CAPTION = "Please review these images and respond.";
|
|
4411
4457
|
function createOutboundRuntime(deps) {
|
|
4412
4458
|
const { ctx, cfg, connection, isManager, routeState, isForwardingEnabled, isTerminated, getCurrentSessionId, getInputEpoch, handleInboundEvent } = deps;
|
|
@@ -4629,8 +4675,8 @@ ${recoveryHint}`,
|
|
|
4629
4675
|
};
|
|
4630
4676
|
const claimStake = () => {
|
|
4631
4677
|
let release;
|
|
4632
|
-
const token = new Promise((
|
|
4633
|
-
release =
|
|
4678
|
+
const token = new Promise((resolve9) => {
|
|
4679
|
+
release = resolve9;
|
|
4634
4680
|
});
|
|
4635
4681
|
token.release = release;
|
|
4636
4682
|
routeState.setStakeFlight(sessionId, token);
|
|
@@ -4836,7 +4882,7 @@ ${recoveryHint}`,
|
|
|
4836
4882
|
ctx.log(`im-forward: attached ${file}`);
|
|
4837
4883
|
} else if (!isTerminated() && isForwardingEnabled()) {
|
|
4838
4884
|
ctx.log(`im-forward: attachment upload failed: ${file}`);
|
|
4839
|
-
failedFiles.push(
|
|
4885
|
+
failedFiles.push(basename2(file));
|
|
4840
4886
|
}
|
|
4841
4887
|
}
|
|
4842
4888
|
if (failedFiles.length > 0 && !isTerminated() && isForwardingEnabled()) {
|
|
@@ -4918,7 +4964,7 @@ function evaluateDirectImCmdAuth(ctx, event) {
|
|
|
4918
4964
|
function formatDirectImCmdAuthRefusal(reason, senderId) {
|
|
4919
4965
|
const idSpan = senderId ? `\`${cleanCodeSpan(senderId, 64)}\`` : void 0;
|
|
4920
4966
|
if (reason === "group-requires-allowUsers") {
|
|
4921
|
-
return idSpan ? `\u26D4\uFE0F Running \`!!\` shell commands in a group chat requires \`allowUsers\` configuration. Add ${idSpan} via
|
|
4967
|
+
return idSpan ? `\u26D4\uFE0F Running \`!!\` shell commands in a group chat requires \`allowUsers\` configuration. Add ${idSpan} via \`/tools/im-forward\` or \`im-forward.json\`.` : "\u26D4\uFE0F Running `!!` shell commands in a group chat requires `allowUsers` configuration.";
|
|
4922
4968
|
}
|
|
4923
4969
|
if (reason === "panelAccess-allowUsers-unconfigured") {
|
|
4924
4970
|
return idSpan ? `\u26D4\uFE0F Running \`!!\` shell commands requires admin rights (panelAccess=allowUsers, but allowUsers is empty). Add ${idSpan} to allowUsers.` : "\u26D4\uFE0F Running `!!` shell commands requires admin rights (panelAccess=allowUsers, but allowUsers is empty).";
|
|
@@ -4992,7 +5038,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
4992
5038
|
}
|
|
4993
5039
|
const timeoutMs = opts.timeoutMs ?? DIRECT_IM_CMD_TIMEOUT_MS;
|
|
4994
5040
|
const { PIE_DEFAULT_PROVIDER: _p, PIE_DEFAULT_MODEL: _m, PIE_MANAGER_BOOTSTRAP: _b, PIE_PROC_CURATED_NAME: _c, ...cleanEnv } = process.env;
|
|
4995
|
-
return new Promise((
|
|
5041
|
+
return new Promise((resolve9) => {
|
|
4996
5042
|
let head = "";
|
|
4997
5043
|
let tail = "";
|
|
4998
5044
|
let totalBytes = 0;
|
|
@@ -5024,7 +5070,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
5024
5070
|
detached: platform !== "win32"
|
|
5025
5071
|
});
|
|
5026
5072
|
} catch (error) {
|
|
5027
|
-
|
|
5073
|
+
resolve9({
|
|
5028
5074
|
ok: false,
|
|
5029
5075
|
exitCode: null,
|
|
5030
5076
|
timedOut: false,
|
|
@@ -5064,7 +5110,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
5064
5110
|
\u2026 (middle output omitted) \u2026
|
|
5065
5111
|
${tail}` : head;
|
|
5066
5112
|
const bounded = boundCommandOutput(raw);
|
|
5067
|
-
|
|
5113
|
+
resolve9({
|
|
5068
5114
|
ok: !timedOut && exitCode === 0,
|
|
5069
5115
|
exitCode,
|
|
5070
5116
|
timedOut,
|
|
@@ -5085,10 +5131,8 @@ ${tail}` : head;
|
|
|
5085
5131
|
return;
|
|
5086
5132
|
}
|
|
5087
5133
|
closeTimer = setTimeout(() => finish(null), 1e3);
|
|
5088
|
-
closeTimer.unref?.();
|
|
5089
5134
|
});
|
|
5090
5135
|
}, killGraceMs);
|
|
5091
|
-
killTimer.unref?.();
|
|
5092
5136
|
};
|
|
5093
5137
|
const onAbort = () => terminateTree();
|
|
5094
5138
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -5232,7 +5276,7 @@ var SYNTHETIC_SENDER = (() => {
|
|
|
5232
5276
|
return `pie-${hex.slice(0, 12)}`;
|
|
5233
5277
|
})();
|
|
5234
5278
|
function deliverOnce(port, secret, text, targetSessionId, targetInstanceId) {
|
|
5235
|
-
return new Promise((
|
|
5279
|
+
return new Promise((resolve9) => {
|
|
5236
5280
|
const id = randomUUID4();
|
|
5237
5281
|
const envelope = {
|
|
5238
5282
|
v: IPC_PROTOCOL_VERSION,
|
|
@@ -5260,7 +5304,7 @@ function deliverOnce(port, secret, text, targetSessionId, targetInstanceId) {
|
|
|
5260
5304
|
settled = true;
|
|
5261
5305
|
clearTimeout(timer);
|
|
5262
5306
|
socket.destroy();
|
|
5263
|
-
|
|
5307
|
+
resolve9(ok);
|
|
5264
5308
|
};
|
|
5265
5309
|
const timer = setTimeout(() => finish(false), 5e3);
|
|
5266
5310
|
socket.once("error", () => finish(false));
|
|
@@ -5329,9 +5373,9 @@ function createAutoWakeCoordinator(ctx) {
|
|
|
5329
5373
|
const noticeCooldownUntil = /* @__PURE__ */ new Map();
|
|
5330
5374
|
const sleepCancelers = /* @__PURE__ */ new Set();
|
|
5331
5375
|
let disposed = false;
|
|
5332
|
-
const sleep = (ms) => new Promise((
|
|
5376
|
+
const sleep = (ms) => new Promise((resolve9) => {
|
|
5333
5377
|
if (disposed || !ctx.isActive()) {
|
|
5334
|
-
|
|
5378
|
+
resolve9();
|
|
5335
5379
|
return;
|
|
5336
5380
|
}
|
|
5337
5381
|
let settled = false;
|
|
@@ -5339,7 +5383,7 @@ function createAutoWakeCoordinator(ctx) {
|
|
|
5339
5383
|
if (settled) return;
|
|
5340
5384
|
settled = true;
|
|
5341
5385
|
sleepCancelers.delete(cancel);
|
|
5342
|
-
|
|
5386
|
+
resolve9();
|
|
5343
5387
|
};
|
|
5344
5388
|
const timer = setTimeout(done, ms);
|
|
5345
5389
|
timer.unref?.();
|
|
@@ -5640,9 +5684,9 @@ function scriptEnv(req, launchId) {
|
|
|
5640
5684
|
return env;
|
|
5641
5685
|
}
|
|
5642
5686
|
function execFileText(file, args) {
|
|
5643
|
-
return new Promise((
|
|
5687
|
+
return new Promise((resolve9) => {
|
|
5644
5688
|
execFile(file, args, { encoding: "utf8", timeout: 1500, maxBuffer: 512 * 1024, windowsHide: true }, (error, stdout) => {
|
|
5645
|
-
|
|
5689
|
+
resolve9(error ? void 0 : stdout);
|
|
5646
5690
|
});
|
|
5647
5691
|
});
|
|
5648
5692
|
}
|
|
@@ -5745,10 +5789,10 @@ async function executeAction(req) {
|
|
|
5745
5789
|
"=".repeat(60)
|
|
5746
5790
|
].filter((line) => line !== void 0).join("\n") + "\n");
|
|
5747
5791
|
const launchId = randomBytes(24).toString("hex");
|
|
5748
|
-
const exitCode = await new Promise((
|
|
5792
|
+
const exitCode = await new Promise((resolve9) => {
|
|
5749
5793
|
if (req.signal?.aborted) {
|
|
5750
5794
|
cancelled = true;
|
|
5751
|
-
|
|
5795
|
+
resolve9(null);
|
|
5752
5796
|
return;
|
|
5753
5797
|
}
|
|
5754
5798
|
const { command, prefix } = interpreterFor(script);
|
|
@@ -5765,7 +5809,7 @@ async function executeAction(req) {
|
|
|
5765
5809
|
} catch (error) {
|
|
5766
5810
|
logWrite(`[spawn error] ${error instanceof Error ? error.message : String(error)}
|
|
5767
5811
|
`);
|
|
5768
|
-
|
|
5812
|
+
resolve9(null);
|
|
5769
5813
|
return;
|
|
5770
5814
|
}
|
|
5771
5815
|
if (typeof child.pid === "number") {
|
|
@@ -5837,7 +5881,7 @@ async function executeAction(req) {
|
|
|
5837
5881
|
}
|
|
5838
5882
|
} catch {
|
|
5839
5883
|
}
|
|
5840
|
-
|
|
5884
|
+
resolve9(code);
|
|
5841
5885
|
};
|
|
5842
5886
|
const scheduleGroupProbe = (delayMs, probe) => {
|
|
5843
5887
|
if (settled) return;
|
|
@@ -6257,23 +6301,23 @@ async function fenceChild(childPid, marker) {
|
|
|
6257
6301
|
const cmd = readProcessCommandLine(childPid);
|
|
6258
6302
|
if (cmd === void 0 || !cmd.includes(marker)) return "unknown";
|
|
6259
6303
|
if (process.platform === "win32") {
|
|
6260
|
-
return await new Promise((
|
|
6304
|
+
return await new Promise((resolve9) => {
|
|
6261
6305
|
let killer;
|
|
6262
6306
|
try {
|
|
6263
6307
|
killer = spawn7("taskkill", ["/T", "/F", "/PID", String(childPid)], { stdio: "ignore", windowsHide: true });
|
|
6264
6308
|
} catch {
|
|
6265
|
-
|
|
6309
|
+
resolve9("unknown");
|
|
6266
6310
|
return;
|
|
6267
6311
|
}
|
|
6268
|
-
killer.on("error", () =>
|
|
6312
|
+
killer.on("error", () => resolve9("unknown"));
|
|
6269
6313
|
const deadline = Date.now() + 5e3;
|
|
6270
6314
|
const poll = () => {
|
|
6271
6315
|
if (!pidAlive5(childPid)) {
|
|
6272
|
-
|
|
6316
|
+
resolve9("fenced");
|
|
6273
6317
|
return;
|
|
6274
6318
|
}
|
|
6275
6319
|
if (Date.now() >= deadline) {
|
|
6276
|
-
|
|
6320
|
+
resolve9("unknown");
|
|
6277
6321
|
return;
|
|
6278
6322
|
}
|
|
6279
6323
|
setTimeout(poll, 100).unref?.();
|
|
@@ -6598,7 +6642,8 @@ function composeWorkerCard(peer, opts = {}) {
|
|
|
6598
6642
|
{ id: `panel.worker.models.${peer.instanceId}`, label: "\u{1F39A} Model" },
|
|
6599
6643
|
...peer.sessionControls ? [
|
|
6600
6644
|
{ id: `panel.context.${peer.instanceId}`, label: "\u{1F4CA} Context", payload: fromWorker },
|
|
6601
|
-
{ id: `panel.compact.${peer.instanceId}`, label: "\u{1F9F9} Compact", payload: fromWorker }
|
|
6645
|
+
{ id: `panel.compact.${peer.instanceId}`, label: "\u{1F9F9} Compact", payload: fromWorker },
|
|
6646
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F333} Tree", payload: fromWorker }
|
|
6602
6647
|
] : [],
|
|
6603
6648
|
{ id: `panel.worker.cron.${peer.instanceId}`, label: workerCron > 0 ? `\u23F0 Cron (${workerCron})` : "\u23F0 Cron" },
|
|
6604
6649
|
{ id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: fromWorker },
|
|
@@ -6884,8 +6929,8 @@ function parsePanelCommand(text) {
|
|
|
6884
6929
|
cmd = next?.[1] ?? "";
|
|
6885
6930
|
rest = next?.[2] ?? "";
|
|
6886
6931
|
}
|
|
6887
|
-
if (cmd !== "panel" && cmd !== "panel.refresh" && cmd !== "panel.summon" && cmd !== "panel.home" && cmd !== "panel.archive" && cmd !== "panel.models" && cmd !== "panel.context" && cmd !== "panel.compact" && cmd !== "panel.cron" && cmd !== "panel.memory" && cmd !== "panel.memory.view" && cmd !== "panel.memory.logs" && cmd !== "panel.memory.dream" && cmd !== "panel.memory.gc" && cmd !== "panel.upgrade" && cmd !== "panel.upgrade.confirm" && cmd !== "panel.help" && cmd !== "panel.actions" && cmd !== "panel.worker.offline" && cmd !== "\u9762\u677F") {
|
|
6888
|
-
if (!/^panel\.model\.[A-Za-z0-9-]+\..+$/.test(cmd) && !/^panel\.thinking\.[A-Za-z0-9-]+\.(?:off|minimal|low|medium|high|xhigh|max)$/.test(cmd) && !/^panel\.(context|compact)\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.peek(?:\.refresh)?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.archive\.view\.[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(cmd) && !/^panel\.worker(?:\.(?:models|cron))?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.cron\.(?:pause|resume|stop(?:\.confirm)?)\.[A-Za-z0-9-]{8,64}$/.test(cmd) && !/^panel\.stop\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.quit(?:\.(?:confirm|force))?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.resume\.[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(cmd) && !/^panel\.action\.[a-z0-9][a-z0-9-]{0,31}$/.test(cmd)) return void 0;
|
|
6932
|
+
if (cmd !== "panel" && cmd !== "panel.refresh" && cmd !== "panel.summon" && cmd !== "panel.home" && cmd !== "panel.archive" && cmd !== "panel.models" && cmd !== "panel.context" && cmd !== "panel.compact" && cmd !== "panel.tree" && cmd !== "panel.cron" && cmd !== "panel.memory" && cmd !== "panel.memory.view" && cmd !== "panel.memory.logs" && cmd !== "panel.memory.dream" && cmd !== "panel.memory.gc" && cmd !== "panel.upgrade" && cmd !== "panel.upgrade.confirm" && cmd !== "panel.help" && cmd !== "panel.actions" && cmd !== "panel.worker.offline" && cmd !== "\u9762\u677F") {
|
|
6933
|
+
if (!/^panel\.model\.[A-Za-z0-9-]+\..+$/.test(cmd) && !/^panel\.thinking\.[A-Za-z0-9-]+\.(?:off|minimal|low|medium|high|xhigh|max)$/.test(cmd) && !/^panel\.(context|compact)\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.tree(?:\.branch(?:\.confirm)?)?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.peek(?:\.refresh)?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.archive\.view\.[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(cmd) && !/^panel\.worker(?:\.(?:models|cron))?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.cron\.(?:pause|resume|stop(?:\.confirm)?)\.[A-Za-z0-9-]{8,64}$/.test(cmd) && !/^panel\.stop\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.quit(?:\.(?:confirm|force))?\.[A-Za-z0-9-]+$/.test(cmd) && !/^panel\.resume\.[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(cmd) && !/^panel\.action\.[a-z0-9][a-z0-9-]{0,31}$/.test(cmd)) return void 0;
|
|
6889
6934
|
}
|
|
6890
6935
|
const leadingFlag = /^--restricted(?:\s+|$)/.exec(rest);
|
|
6891
6936
|
const restricted = leadingFlag !== null;
|
|
@@ -7001,6 +7046,7 @@ function composePanel(opts = {}) {
|
|
|
7001
7046
|
const meta = `\`${cleanCodeSpan(formatPeerModel(p), 44)}\` \xB7 ${formatPeerState(p.state, p.currentTool, verDrift)}${threadLink}`;
|
|
7002
7047
|
const rowActions = p === managerPeer ? [
|
|
7003
7048
|
{ id: "panel.models", label: "\u{1F39A} Model" },
|
|
7049
|
+
...p.sessionControls ? [{ id: `panel.tree.${p.instanceId}`, label: "\u{1F333} Tree", payload: { from: "home" } }] : [],
|
|
7004
7050
|
...p.workerPeek && p.sessionId ? [{ id: `panel.peek.${p.instanceId}`, label: "\u{1F440} Peek", payload: { peek: { ref: p.instanceId, session: p.sessionId, isManager: true } } }] : []
|
|
7005
7051
|
] : [{ id: `panel.worker.${p.instanceId}`, label: "\u{1F527} \u7BA1\u7406" }];
|
|
7006
7052
|
return { text: `${label}
|
|
@@ -7243,7 +7289,7 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline2(a.lastRunBy ?? "\u2014", 20)}
|
|
|
7243
7289
|
return { spec: {
|
|
7244
7290
|
title: "Panel Commands",
|
|
7245
7291
|
columnsPerRow: cols,
|
|
7246
|
-
body: "`/panel` summons the status panel (inside a worker thread, opens that worker's dedicated panel in-thread). Controls: \u{1F504} Refresh, \u{1F4DA} \u5F52\u6863 (browse recent historical sessions across directories, inspect offline summaries, and one-click Resume workers), \u{1F39A} Model & Thinking, \u{1F4CA} Context (inspect context usage & one-tap Compact), \u{1F9E0} Memory (Wiki status, curated page preview, distill/GC triggers, and logs), \u23F0 Cron (list / pause / resume / stop scheduled jobs; create new jobs in chat), \u23F9 Stop (abort current turn), \u{1F6AA} Quit (graceful shutdown / force kill), \u267B\uFE0F Resume (when offline), \u{1F440} Peek (live snapshot). Navigation updates the card in place.",
|
|
7292
|
+
body: "`/panel` summons the status panel (inside a worker thread, opens that worker's dedicated panel in-thread). Controls: \u{1F504} Refresh, \u{1F4DA} \u5F52\u6863 (browse recent historical sessions across directories, inspect offline summaries, and one-click Resume workers), \u{1F39A} Model & Thinking, \u{1F4CA} Context (inspect context usage & one-tap Compact), \u{1F333} Tree (inspect session tree & lossless rewind/branch switch; also via `/panel.tree`), \u{1F9E0} Memory (Wiki status, curated page preview, distill/GC triggers, and logs), \u23F0 Cron (list / pause / resume / stop scheduled jobs; create new jobs in chat), \u23F9 Stop (abort current turn), \u{1F6AA} Quit (graceful shutdown / force kill), \u267B\uFE0F Resume (when offline), \u{1F440} Peek (live snapshot). Navigation updates the card in place.",
|
|
7247
7293
|
actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
|
|
7248
7294
|
}, patchOrigin: patchInPlace };
|
|
7249
7295
|
}
|
|
@@ -7627,11 +7673,119 @@ async function ensureResumedSessionTopic(opts) {
|
|
|
7627
7673
|
}
|
|
7628
7674
|
}
|
|
7629
7675
|
|
|
7630
|
-
// builtin/extensions/im-forward/runtime-panel-
|
|
7676
|
+
// builtin/extensions/im-forward/runtime-panel-upgrade.ts
|
|
7631
7677
|
import * as fs17 from "node:fs";
|
|
7632
7678
|
import * as os8 from "node:os";
|
|
7633
7679
|
import { dirname as pathDirname, join as join18, resolve as pathResolve2 } from "node:path";
|
|
7634
7680
|
import { spawn as spawnProcess } from "node:child_process";
|
|
7681
|
+
function evaluateUpgradeConfirmAuth(ctx, event) {
|
|
7682
|
+
const hasAllowUsers = Array.isArray(ctx.allowUsers) && ctx.allowUsers.length > 0;
|
|
7683
|
+
if (hasAllowUsers) {
|
|
7684
|
+
return event.sender_id && ctx.allowUsers.includes(event.sender_id) ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
7685
|
+
}
|
|
7686
|
+
if (ctx.panelAccess === "allowUsers") {
|
|
7687
|
+
return { allowed: false, reason: "panelAccess-allowUsers-unconfigured" };
|
|
7688
|
+
}
|
|
7689
|
+
if (ctx.targetKind === "user") {
|
|
7690
|
+
return ctx.targetId && event.sender_id && event.sender_id === ctx.targetId ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
7691
|
+
}
|
|
7692
|
+
if (ctx.targetId && event.chat_id === ctx.targetId) {
|
|
7693
|
+
return { allowed: true };
|
|
7694
|
+
}
|
|
7695
|
+
return { allowed: false, reason: "unbound-chat" };
|
|
7696
|
+
}
|
|
7697
|
+
function formatUpgradeAuthRefusal(reason, senderId) {
|
|
7698
|
+
const idSpan = senderId ? `\`${cleanCodeSpan(senderId, 64)}\`` : void 0;
|
|
7699
|
+
if (reason === "panelAccess-allowUsers-unconfigured") {
|
|
7700
|
+
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (panelAccess=allowUsers, but allowUsers is empty). Add ${idSpan} to allowUsers in im-forward.json.` : "\u26D4\uFE0F Upgrading pie requires admin rights (panelAccess=allowUsers, but allowUsers is empty).";
|
|
7701
|
+
}
|
|
7702
|
+
if (reason === "unbound-chat") {
|
|
7703
|
+
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers) outside the bound chat. Use /panel in the bound chat, or add ${idSpan} to allowUsers.` : "\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers) outside the bound chat.";
|
|
7704
|
+
}
|
|
7705
|
+
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers). Your ID: ${idSpan}` : "\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers).";
|
|
7706
|
+
}
|
|
7707
|
+
async function runUpgradeConfirmActor(cols, log) {
|
|
7708
|
+
const started = Date.now();
|
|
7709
|
+
let actorOk = false;
|
|
7710
|
+
let actorDetail = "";
|
|
7711
|
+
try {
|
|
7712
|
+
const entry = process.argv[1] ? pathResolve2(process.argv[1]) : "";
|
|
7713
|
+
if (!entry) throw new Error("cannot resolve the pie entry point");
|
|
7714
|
+
const configRoot = pathDirname(pathDirname(ipcDiscoveryRoot()));
|
|
7715
|
+
const managerDir = join18(configRoot, "manager");
|
|
7716
|
+
const logFile = join18(managerDir, "upgrade-actor.log");
|
|
7717
|
+
const actorEnv = resolveAbsoluteActorEnv(process.env);
|
|
7718
|
+
if (process.platform === "win32" && isWindowsServiceManager(configRoot)) {
|
|
7719
|
+
const launched = launchWindowsServiceUpgradeActor({
|
|
7720
|
+
managerDir,
|
|
7721
|
+
nodePath: process.execPath,
|
|
7722
|
+
entry,
|
|
7723
|
+
logFile,
|
|
7724
|
+
env: actorEnv
|
|
7725
|
+
});
|
|
7726
|
+
actorOk = launched.ok;
|
|
7727
|
+
actorDetail = launched.detail;
|
|
7728
|
+
} else {
|
|
7729
|
+
let out;
|
|
7730
|
+
try {
|
|
7731
|
+
fs17.mkdirSync(managerDir, { recursive: true });
|
|
7732
|
+
out = fs17.openSync(logFile, "a");
|
|
7733
|
+
} catch {
|
|
7734
|
+
out = void 0;
|
|
7735
|
+
}
|
|
7736
|
+
const child = spawnProcess(process.execPath, [entry, "manager", "upgrade"], {
|
|
7737
|
+
cwd: os8.tmpdir(),
|
|
7738
|
+
detached: true,
|
|
7739
|
+
stdio: out !== void 0 ? ["ignore", out, out] : "ignore",
|
|
7740
|
+
windowsHide: true,
|
|
7741
|
+
env: actorEnv
|
|
7742
|
+
});
|
|
7743
|
+
const spawnOutcome = await new Promise((resolve9) => {
|
|
7744
|
+
let settled = false;
|
|
7745
|
+
const settle = (v) => {
|
|
7746
|
+
if (!settled) {
|
|
7747
|
+
settled = true;
|
|
7748
|
+
resolve9(v);
|
|
7749
|
+
}
|
|
7750
|
+
};
|
|
7751
|
+
child.once("spawn", () => settle("spawned"));
|
|
7752
|
+
child.once("error", (error) => {
|
|
7753
|
+
log(`im-forward: upgrade actor spawn error: ${error instanceof Error ? error.message : String(error)}`);
|
|
7754
|
+
settle("error");
|
|
7755
|
+
});
|
|
7756
|
+
setTimeout(() => settle("timeout"), 3e3).unref?.();
|
|
7757
|
+
});
|
|
7758
|
+
child.unref();
|
|
7759
|
+
if (out !== void 0) {
|
|
7760
|
+
try {
|
|
7761
|
+
fs17.closeSync(out);
|
|
7762
|
+
} catch {
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
if (spawnOutcome === "error") {
|
|
7766
|
+
actorDetail = "the actor process failed to spawn (see the manager log)";
|
|
7767
|
+
} else {
|
|
7768
|
+
actorOk = true;
|
|
7769
|
+
actorDetail = `actor pid ${child.pid}${spawnOutcome === "timeout" ? " (spawn unconfirmed \u2014 will report via /panel)" : ""} \xB7 log ${logFile}`;
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7772
|
+
} catch (error) {
|
|
7773
|
+
actorDetail = error instanceof Error ? error.message : String(error);
|
|
7774
|
+
}
|
|
7775
|
+
log(`im-forward: panel.upgrade.confirm actor spawn ${actorOk ? "ok" : "failed"} (${actorDetail}, runtimeMs=${Date.now() - started})`);
|
|
7776
|
+
return {
|
|
7777
|
+
title: actorOk ? "Upgrade Started" : "Upgrade Failed to Start",
|
|
7778
|
+
columnsPerRow: cols,
|
|
7779
|
+
body: actorOk ? `\u2B06\uFE0F npm install + manager restart running in the background.
|
|
7780
|
+
|
|
7781
|
+
${actorDetail}
|
|
7782
|
+
|
|
7783
|
+
IM pauses briefly during the restart; tap \u{1F504} Refresh afterwards \u2014 the panel's footer line shows the outcome (old \u2192 new version).` : `Could not spawn the upgrade actor: ${actorDetail}`,
|
|
7784
|
+
actions: actorOk ? [{ id: "panel.refresh", label: "\u{1F504} Refresh" }] : [{ id: "panel.upgrade", label: "\u21A9\uFE0F Back to upgrade card" }]
|
|
7785
|
+
};
|
|
7786
|
+
}
|
|
7787
|
+
|
|
7788
|
+
// builtin/extensions/im-forward/runtime-panel-lifecycle.ts
|
|
7635
7789
|
function extractIssuedWorkerCard(spec, chatId, ownerSession, epoch) {
|
|
7636
7790
|
const peek = allCardActions(spec).find((a) => /^panel\.peek\.[A-Za-z0-9-]+$/.test(a.id));
|
|
7637
7791
|
const bound = peek && isRecord(peek.payload) && isRecord(peek.payload.peek) ? peek.payload.peek : void 0;
|
|
@@ -7771,7 +7925,7 @@ function panelHomeAction(inThread, threadWorkerSessionId, peerRef) {
|
|
|
7771
7925
|
}
|
|
7772
7926
|
return [];
|
|
7773
7927
|
}
|
|
7774
|
-
function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSessionId, verifiedQuitSessionId, verifiedCronStopSessionId) {
|
|
7928
|
+
function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSessionId, verifiedQuitSessionId, verifiedCronStopSessionId, verifiedTreeBranchSessionId) {
|
|
7775
7929
|
if (!workerScoped || !pinnedWorkerSessionId) return { blocked: false };
|
|
7776
7930
|
const cols = inThread ? 2 : 3;
|
|
7777
7931
|
if (panelCmd.cmd === "panel" || panelCmd.cmd === "\u9762\u677F") {
|
|
@@ -7781,6 +7935,20 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
|
|
|
7781
7935
|
rewrittenCmd: live ? { cmd: `panel.worker.${live.instanceId}`, restricted: false } : { cmd: "panel.worker.offline", restricted: false, payload: { sessionId: pinnedWorkerSessionId } }
|
|
7782
7936
|
};
|
|
7783
7937
|
}
|
|
7938
|
+
if (panelCmd.cmd === "panel.tree") {
|
|
7939
|
+
const live = findPeerBySessionId(pinnedWorkerSessionId);
|
|
7940
|
+
if (!live) {
|
|
7941
|
+
return { blocked: true, spec: composeOfflineWorkerCard(pinnedWorkerSessionId, { inThread, hideHome: true }) };
|
|
7942
|
+
}
|
|
7943
|
+
return {
|
|
7944
|
+
blocked: false,
|
|
7945
|
+
rewrittenCmd: {
|
|
7946
|
+
cmd: `panel.tree.${live.instanceId}`,
|
|
7947
|
+
restricted: false,
|
|
7948
|
+
payload: { ...isRecord(panelCmd.payload) ? panelCmd.payload : {}, from: "worker" }
|
|
7949
|
+
}
|
|
7950
|
+
};
|
|
7951
|
+
}
|
|
7784
7952
|
const deny = (reason) => ({
|
|
7785
7953
|
blocked: true,
|
|
7786
7954
|
spec: {
|
|
@@ -7847,6 +8015,20 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
|
|
|
7847
8015
|
}
|
|
7848
8016
|
return { blocked: false };
|
|
7849
8017
|
}
|
|
8018
|
+
const treePeerMatch = /^panel\.tree(?:\.branch(?:\.confirm)?)?\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
8019
|
+
if (treePeerMatch) {
|
|
8020
|
+
const peer = scanPeers().find((p) => p.instanceId === treePeerMatch[1]);
|
|
8021
|
+
if (peer) {
|
|
8022
|
+
if (peer.isManager || peer.sessionId !== pinnedWorkerSessionId) {
|
|
8023
|
+
return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u67E5\u770B\u6216\u64CD\u4F5C\u5F53\u524D Worker \u7684\u4F1A\u8BDD\u6811\u3002");
|
|
8024
|
+
}
|
|
8025
|
+
if (panelCmd.cmd.startsWith("panel.tree.branch.confirm.") && verifiedTreeBranchSessionId && verifiedTreeBranchSessionId !== pinnedWorkerSessionId) {
|
|
8026
|
+
return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u5207\u6362\u5F53\u524D Worker \u7684\u4F1A\u8BDD\u5206\u652F\u3002");
|
|
8027
|
+
}
|
|
8028
|
+
return { blocked: false };
|
|
8029
|
+
}
|
|
8030
|
+
return { blocked: true, spec: composeOfflineWorkerCard(pinnedWorkerSessionId, { inThread, hideHome: true }) };
|
|
8031
|
+
}
|
|
7850
8032
|
const ctrlPeerMatch = /^panel\.(?:model|thinking|context|compact|stop|peek(?:\.refresh)?)\.([A-Za-z0-9-]+)/.exec(panelCmd.cmd);
|
|
7851
8033
|
if (ctrlPeerMatch) {
|
|
7852
8034
|
const peer = scanPeers().find((p) => p.instanceId === ctrlPeerMatch[1]);
|
|
@@ -8222,32 +8404,6 @@ function isPeekAudienceAllowed(ctx, event) {
|
|
|
8222
8404
|
if (event.chatType !== "group") return !ctx.allowUsers || isAllowedUser();
|
|
8223
8405
|
return true;
|
|
8224
8406
|
}
|
|
8225
|
-
function evaluateUpgradeConfirmAuth(ctx, event) {
|
|
8226
|
-
const hasAllowUsers = Array.isArray(ctx.allowUsers) && ctx.allowUsers.length > 0;
|
|
8227
|
-
if (hasAllowUsers) {
|
|
8228
|
-
return event.sender_id && ctx.allowUsers.includes(event.sender_id) ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
8229
|
-
}
|
|
8230
|
-
if (ctx.panelAccess === "allowUsers") {
|
|
8231
|
-
return { allowed: false, reason: "panelAccess-allowUsers-unconfigured" };
|
|
8232
|
-
}
|
|
8233
|
-
if (ctx.targetKind === "user") {
|
|
8234
|
-
return ctx.targetId && event.sender_id && event.sender_id === ctx.targetId ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
8235
|
-
}
|
|
8236
|
-
if (ctx.targetId && event.chat_id === ctx.targetId) {
|
|
8237
|
-
return { allowed: true };
|
|
8238
|
-
}
|
|
8239
|
-
return { allowed: false, reason: "unbound-chat" };
|
|
8240
|
-
}
|
|
8241
|
-
function formatUpgradeAuthRefusal(reason, senderId) {
|
|
8242
|
-
const idSpan = senderId ? `\`${cleanCodeSpan(senderId, 64)}\`` : void 0;
|
|
8243
|
-
if (reason === "panelAccess-allowUsers-unconfigured") {
|
|
8244
|
-
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (panelAccess=allowUsers, but allowUsers is empty). Add ${idSpan} to allowUsers in im-forward.json.` : "\u26D4\uFE0F Upgrading pie requires admin rights (panelAccess=allowUsers, but allowUsers is empty).";
|
|
8245
|
-
}
|
|
8246
|
-
if (reason === "unbound-chat") {
|
|
8247
|
-
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers) outside the bound chat. Use /panel in the bound chat, or add ${idSpan} to allowUsers.` : "\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers) outside the bound chat.";
|
|
8248
|
-
}
|
|
8249
|
-
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers). Your ID: ${idSpan}` : "\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers).";
|
|
8250
|
-
}
|
|
8251
8407
|
function buildPeekCardSpec(targetRef, targetSession, isManagerTarget, cols, receipt, inThread = false) {
|
|
8252
8408
|
const meta = parsePeekMeta(receipt);
|
|
8253
8409
|
const actions = [
|
|
@@ -8314,86 +8470,6 @@ async function deliverPeekDeniedAtGate(params) {
|
|
|
8314
8470
|
params.rememberPanelCard(sent.messageId, currentSessionId, sent.chatId ?? event.chat_id, owner?.replyInThread || owner?.workerScoped ? { ...owner.replyInThread ? { replyTo: sent.messageId, replyInThread: true } : {}, ...owner.workerScoped ? { workerScoped: true } : {}, threadWorkerSessionId: owner.threadWorkerSessionId } : void 0);
|
|
8315
8471
|
}
|
|
8316
8472
|
}
|
|
8317
|
-
async function runUpgradeConfirmActor(cols, log) {
|
|
8318
|
-
const started = Date.now();
|
|
8319
|
-
let actorOk = false;
|
|
8320
|
-
let actorDetail = "";
|
|
8321
|
-
try {
|
|
8322
|
-
const entry = process.argv[1] ? pathResolve2(process.argv[1]) : "";
|
|
8323
|
-
if (!entry) throw new Error("cannot resolve the pie entry point");
|
|
8324
|
-
const configRoot = pathDirname(pathDirname(ipcDiscoveryRoot()));
|
|
8325
|
-
const managerDir = join18(configRoot, "manager");
|
|
8326
|
-
const logFile = join18(managerDir, "upgrade-actor.log");
|
|
8327
|
-
const actorEnv = resolveAbsoluteActorEnv(process.env);
|
|
8328
|
-
if (process.platform === "win32" && isWindowsServiceManager(configRoot)) {
|
|
8329
|
-
const launched = launchWindowsServiceUpgradeActor({
|
|
8330
|
-
managerDir,
|
|
8331
|
-
nodePath: process.execPath,
|
|
8332
|
-
entry,
|
|
8333
|
-
logFile,
|
|
8334
|
-
env: actorEnv
|
|
8335
|
-
});
|
|
8336
|
-
actorOk = launched.ok;
|
|
8337
|
-
actorDetail = launched.detail;
|
|
8338
|
-
} else {
|
|
8339
|
-
let out;
|
|
8340
|
-
try {
|
|
8341
|
-
fs17.mkdirSync(managerDir, { recursive: true });
|
|
8342
|
-
out = fs17.openSync(logFile, "a");
|
|
8343
|
-
} catch {
|
|
8344
|
-
out = void 0;
|
|
8345
|
-
}
|
|
8346
|
-
const child = spawnProcess(process.execPath, [entry, "manager", "upgrade"], {
|
|
8347
|
-
cwd: os8.tmpdir(),
|
|
8348
|
-
detached: true,
|
|
8349
|
-
stdio: out !== void 0 ? ["ignore", out, out] : "ignore",
|
|
8350
|
-
windowsHide: true,
|
|
8351
|
-
env: actorEnv
|
|
8352
|
-
});
|
|
8353
|
-
const spawnOutcome = await new Promise((resolve8) => {
|
|
8354
|
-
let settled = false;
|
|
8355
|
-
const settle = (v) => {
|
|
8356
|
-
if (!settled) {
|
|
8357
|
-
settled = true;
|
|
8358
|
-
resolve8(v);
|
|
8359
|
-
}
|
|
8360
|
-
};
|
|
8361
|
-
child.once("spawn", () => settle("spawned"));
|
|
8362
|
-
child.once("error", (error) => {
|
|
8363
|
-
log(`im-forward: upgrade actor spawn error: ${error instanceof Error ? error.message : String(error)}`);
|
|
8364
|
-
settle("error");
|
|
8365
|
-
});
|
|
8366
|
-
setTimeout(() => settle("timeout"), 3e3).unref?.();
|
|
8367
|
-
});
|
|
8368
|
-
child.unref();
|
|
8369
|
-
if (out !== void 0) {
|
|
8370
|
-
try {
|
|
8371
|
-
fs17.closeSync(out);
|
|
8372
|
-
} catch {
|
|
8373
|
-
}
|
|
8374
|
-
}
|
|
8375
|
-
if (spawnOutcome === "error") {
|
|
8376
|
-
actorDetail = "the actor process failed to spawn (see the manager log)";
|
|
8377
|
-
} else {
|
|
8378
|
-
actorOk = true;
|
|
8379
|
-
actorDetail = `actor pid ${child.pid}${spawnOutcome === "timeout" ? " (spawn unconfirmed \u2014 will report via /panel)" : ""} \xB7 log ${logFile}`;
|
|
8380
|
-
}
|
|
8381
|
-
}
|
|
8382
|
-
} catch (error) {
|
|
8383
|
-
actorDetail = error instanceof Error ? error.message : String(error);
|
|
8384
|
-
}
|
|
8385
|
-
log(`im-forward: panel.upgrade.confirm actor spawn ${actorOk ? "ok" : "failed"} (${actorDetail}, runtimeMs=${Date.now() - started})`);
|
|
8386
|
-
return {
|
|
8387
|
-
title: actorOk ? "Upgrade Started" : "Upgrade Failed to Start",
|
|
8388
|
-
columnsPerRow: cols,
|
|
8389
|
-
body: actorOk ? `\u2B06\uFE0F npm install + manager restart running in the background.
|
|
8390
|
-
|
|
8391
|
-
${actorDetail}
|
|
8392
|
-
|
|
8393
|
-
IM pauses briefly during the restart; tap \u{1F504} Refresh afterwards \u2014 the panel's footer line shows the outcome (old \u2192 new version).` : `Could not spawn the upgrade actor: ${actorDetail}`,
|
|
8394
|
-
actions: actorOk ? [{ id: "panel.refresh", label: "\u{1F504} Refresh" }] : [{ id: "panel.upgrade", label: "\u21A9\uFE0F Back to upgrade card" }]
|
|
8395
|
-
};
|
|
8396
|
-
}
|
|
8397
8473
|
|
|
8398
8474
|
// builtin/extensions/im-forward/panel-cron.ts
|
|
8399
8475
|
var PAGE_SIZE = 6;
|
|
@@ -8750,6 +8826,554 @@ function runCronPanelCommand(panelCmd, opts) {
|
|
|
8750
8826
|
return { handled: false };
|
|
8751
8827
|
}
|
|
8752
8828
|
|
|
8829
|
+
// builtin/extensions/im-forward/panel-tree.ts
|
|
8830
|
+
var TREE_PAGE_SIZE = 5;
|
|
8831
|
+
var SAFE_ENTRY_ID_RE = /^[^\x00-\x1f\x7f-\x9f\s]{1,128}$/;
|
|
8832
|
+
function extractIssuedTreeBranch(spec, chatId, ownerSession, epoch) {
|
|
8833
|
+
const confirm = allCardActions(spec).find((a) => /^panel\.tree\.branch\.confirm\.[A-Za-z0-9-]+$/.test(a.id));
|
|
8834
|
+
const payload = confirm && isRecord(confirm.payload) ? confirm.payload : void 0;
|
|
8835
|
+
const bound = payload && isRecord(payload.treeBranch) ? payload.treeBranch : void 0;
|
|
8836
|
+
if (bound && typeof bound.ref === "string" && typeof bound.session === "string" && typeof bound.entryId === "string" && bound.ref && bound.session && SAFE_ENTRY_ID_RE.test(bound.entryId)) {
|
|
8837
|
+
return {
|
|
8838
|
+
ref: bound.ref,
|
|
8839
|
+
sessionId: bound.session,
|
|
8840
|
+
entryId: bound.entryId,
|
|
8841
|
+
chatId,
|
|
8842
|
+
ownerSession,
|
|
8843
|
+
epoch
|
|
8844
|
+
};
|
|
8845
|
+
}
|
|
8846
|
+
return void 0;
|
|
8847
|
+
}
|
|
8848
|
+
function isTreePanelCommand(cmd) {
|
|
8849
|
+
return cmd === "panel.tree" || /^panel\.tree\.[A-Za-z0-9-]+$/.test(cmd) || /^panel\.tree\.branch(?:\.confirm)?\.[A-Za-z0-9-]+$/.test(cmd);
|
|
8850
|
+
}
|
|
8851
|
+
function clipText3(text, max) {
|
|
8852
|
+
return text.length <= max ? text : `${text.slice(0, Math.max(1, max - 1))}\u2026`;
|
|
8853
|
+
}
|
|
8854
|
+
function cleanInline4(text, max = 72) {
|
|
8855
|
+
return clipText3(sanitizeLiteralMarkdown(text), max);
|
|
8856
|
+
}
|
|
8857
|
+
function sanitizeTableCell3(text, max = 72) {
|
|
8858
|
+
return clipText3(sanitizeLiteralMarkdown(text).replace(/\|/g, "\uFF5C"), max);
|
|
8859
|
+
}
|
|
8860
|
+
function formatNodeClock(timestamp) {
|
|
8861
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0) return "\u2014";
|
|
8862
|
+
const d = new Date(timestamp);
|
|
8863
|
+
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
|
8864
|
+
const dd = String(d.getDate()).padStart(2, "0");
|
|
8865
|
+
const hh = String(d.getHours()).padStart(2, "0");
|
|
8866
|
+
const mi = String(d.getMinutes()).padStart(2, "0");
|
|
8867
|
+
return `${mm}-${dd} ${hh}:${mi}`;
|
|
8868
|
+
}
|
|
8869
|
+
function kindBadge(kind) {
|
|
8870
|
+
switch (kind) {
|
|
8871
|
+
case "user":
|
|
8872
|
+
return "\u{1F464} \u7528\u6237";
|
|
8873
|
+
case "assistant":
|
|
8874
|
+
return "\u{1F916} \u52A9\u624B";
|
|
8875
|
+
case "tool":
|
|
8876
|
+
return "\u{1F527} \u5DE5\u5177";
|
|
8877
|
+
case "compaction":
|
|
8878
|
+
return "\u{1F9F9} \u538B\u7F29";
|
|
8879
|
+
case "fork":
|
|
8880
|
+
return "\u{1F33F} \u5206\u53C9";
|
|
8881
|
+
default:
|
|
8882
|
+
return "\u{1F4CC} \u8BB0\u5F55";
|
|
8883
|
+
}
|
|
8884
|
+
}
|
|
8885
|
+
function parseTreeMeta(payload) {
|
|
8886
|
+
if (!isRecord(payload)) return { page: 1, filter: "key" };
|
|
8887
|
+
const page = typeof payload.page === "number" && Number.isFinite(payload.page) && payload.page >= 1 ? Math.floor(payload.page) : 1;
|
|
8888
|
+
const filter = payload.filter === "all" ? "all" : "key";
|
|
8889
|
+
const from = payload.from === "home" || payload.from === "worker" ? payload.from : void 0;
|
|
8890
|
+
const entryId = typeof payload.entryId === "string" && SAFE_ENTRY_ID_RE.test(payload.entryId) ? payload.entryId : void 0;
|
|
8891
|
+
return { page, filter, ...from ? { from } : {}, ...entryId ? { entryId } : {} };
|
|
8892
|
+
}
|
|
8893
|
+
var VALID_ENTRY_KINDS = /* @__PURE__ */ new Set(["user", "assistant", "tool", "compaction", "fork", "custom"]);
|
|
8894
|
+
function isNonNegInt(value) {
|
|
8895
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
8896
|
+
}
|
|
8897
|
+
function isPosInt(value) {
|
|
8898
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1;
|
|
8899
|
+
}
|
|
8900
|
+
function isValidNodeSummary(raw) {
|
|
8901
|
+
if (!isRecord(raw)) return false;
|
|
8902
|
+
return isPosInt(raw.seq) && typeof raw.id === "string" && SAFE_ENTRY_ID_RE.test(raw.id) && (raw.parentSeq === null || isPosInt(raw.parentSeq)) && typeof raw.kind === "string" && VALID_ENTRY_KINDS.has(raw.kind) && typeof raw.timestamp === "number" && Number.isFinite(raw.timestamp) && typeof raw.preview === "string" && raw.preview.length <= 256 && isNonNegInt(raw.childCount) && typeof raw.estTokens === "number" && Number.isFinite(raw.estTokens) && typeof raw.onActivePath === "boolean" && typeof raw.isHead === "boolean" && typeof raw.isBranchPoint === "boolean" && typeof raw.isBranchTip === "boolean" && isNonNegInt(raw.activePathAfterCount) && (raw.label === void 0 || typeof raw.label === "string" && raw.label.length <= 80);
|
|
8903
|
+
}
|
|
8904
|
+
function unwrapControlReceiptMessage(detail) {
|
|
8905
|
+
const start = detail.indexOf("{");
|
|
8906
|
+
if (start < 0) return void 0;
|
|
8907
|
+
try {
|
|
8908
|
+
const ack = JSON.parse(detail.slice(start));
|
|
8909
|
+
if (!isRecord(ack) || typeof ack.ok !== "boolean" || typeof ack.message !== "string") return void 0;
|
|
8910
|
+
return { ok: ack.ok, message: ack.message };
|
|
8911
|
+
} catch {
|
|
8912
|
+
return void 0;
|
|
8913
|
+
}
|
|
8914
|
+
}
|
|
8915
|
+
function parseTreePageReport(detail, expectedSessionId) {
|
|
8916
|
+
try {
|
|
8917
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8918
|
+
if (!ack || !ack.ok) return void 0;
|
|
8919
|
+
const parsed = JSON.parse(ack.message);
|
|
8920
|
+
if (!isRecord(parsed) || parsed.mode !== "page") return void 0;
|
|
8921
|
+
if (parsed.sessionId !== expectedSessionId || !Array.isArray(parsed.nodes)) return void 0;
|
|
8922
|
+
if (parsed.activeEntryId !== null && (typeof parsed.activeEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.activeEntryId))) return void 0;
|
|
8923
|
+
if (!isNonNegInt(parsed.activePathLength) || !isNonNegInt(parsed.totalEntries) || !isNonNegInt(parsed.totalFiltered)) return void 0;
|
|
8924
|
+
if (!isNonNegInt(parsed.branchPointCount) || !isNonNegInt(parsed.otherBranchTipCount)) return void 0;
|
|
8925
|
+
if (!isPosInt(parsed.page) || !isPosInt(parsed.pageSize) || !isPosInt(parsed.totalPages)) return void 0;
|
|
8926
|
+
if (parsed.filter !== "key" && parsed.filter !== "all") return void 0;
|
|
8927
|
+
if (typeof parsed.isIdle !== "boolean" || typeof parsed.compactionRunning !== "boolean") return void 0;
|
|
8928
|
+
if (parsed.truncated !== void 0 && typeof parsed.truncated !== "boolean") return void 0;
|
|
8929
|
+
if (parsed.nodes.length > 16 || !parsed.nodes.every(isValidNodeSummary)) return void 0;
|
|
8930
|
+
return parsed;
|
|
8931
|
+
} catch {
|
|
8932
|
+
return void 0;
|
|
8933
|
+
}
|
|
8934
|
+
}
|
|
8935
|
+
function parseTreeEntryReport(detail, expectedSessionId) {
|
|
8936
|
+
try {
|
|
8937
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8938
|
+
if (!ack || !ack.ok) return void 0;
|
|
8939
|
+
const parsed = JSON.parse(ack.message);
|
|
8940
|
+
if (!isRecord(parsed) || parsed.mode !== "entry") return void 0;
|
|
8941
|
+
if (parsed.sessionId !== expectedSessionId) return void 0;
|
|
8942
|
+
if (parsed.activeEntryId !== null && (typeof parsed.activeEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.activeEntryId))) return void 0;
|
|
8943
|
+
if (!isNonNegInt(parsed.activePathLength)) return void 0;
|
|
8944
|
+
if (typeof parsed.isIdle !== "boolean" || typeof parsed.compactionRunning !== "boolean") return void 0;
|
|
8945
|
+
if (parsed.entry !== null && !isValidNodeSummary(parsed.entry)) return void 0;
|
|
8946
|
+
return parsed;
|
|
8947
|
+
} catch {
|
|
8948
|
+
return void 0;
|
|
8949
|
+
}
|
|
8950
|
+
}
|
|
8951
|
+
function parseBranchSuccess(detail, expectedSessionId, expectedEntryId) {
|
|
8952
|
+
try {
|
|
8953
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8954
|
+
if (!ack || !ack.ok) return void 0;
|
|
8955
|
+
const parsed = JSON.parse(ack.message);
|
|
8956
|
+
if (!isRecord(parsed) || parsed.ok !== true) return void 0;
|
|
8957
|
+
if (parsed.sessionId !== expectedSessionId || parsed.activeEntryId !== expectedEntryId) return void 0;
|
|
8958
|
+
if (parsed.fromEntryId !== null && (typeof parsed.fromEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.fromEntryId))) return void 0;
|
|
8959
|
+
if (typeof parsed.alreadyActive !== "boolean") return void 0;
|
|
8960
|
+
if (!isPosInt(parsed.seq) || !isNonNegInt(parsed.pathLength) || !isNonNegInt(parsed.messageCount)) return void 0;
|
|
8961
|
+
if (typeof parsed.kind !== "string" || !VALID_ENTRY_KINDS.has(parsed.kind)) return void 0;
|
|
8962
|
+
if (typeof parsed.preview !== "string" || parsed.preview.length > 256) return void 0;
|
|
8963
|
+
return parsed;
|
|
8964
|
+
} catch {
|
|
8965
|
+
return void 0;
|
|
8966
|
+
}
|
|
8967
|
+
}
|
|
8968
|
+
function seqFromEntryId(entryId) {
|
|
8969
|
+
if (!entryId) return void 0;
|
|
8970
|
+
const m = /^e(\d+)-/.exec(entryId);
|
|
8971
|
+
if (!m) return void 0;
|
|
8972
|
+
const n = Number(m[1]);
|
|
8973
|
+
return Number.isInteger(n) && n > 0 ? n : void 0;
|
|
8974
|
+
}
|
|
8975
|
+
function backActionsFor(peer, opts) {
|
|
8976
|
+
if (opts.hideHome) {
|
|
8977
|
+
return [{ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" }];
|
|
8978
|
+
}
|
|
8979
|
+
if (opts.from === "home" || peer.isManager) {
|
|
8980
|
+
return [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }];
|
|
8981
|
+
}
|
|
8982
|
+
return [
|
|
8983
|
+
{ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" },
|
|
8984
|
+
{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
|
|
8985
|
+
];
|
|
8986
|
+
}
|
|
8987
|
+
function formatPeerErrorDetail(detail) {
|
|
8988
|
+
const unwrapped = unwrapControlReceiptMessage(detail)?.message ?? detail;
|
|
8989
|
+
if (/unknown control:\s*session\.(?:tree|branch)/i.test(unwrapped)) {
|
|
8990
|
+
return "\u8BE5\u4F1A\u8BDD\u8FD0\u884C\u7684 Pie \u7248\u672C\u8F83\u65E7\uFF0C\u6682\u4E0D\u652F\u6301\u8FDC\u7A0B Tree\uFF08\u5347\u7EA7\u540E\u53EF\u7528\uFF09\u3002";
|
|
8991
|
+
}
|
|
8992
|
+
return sanitizeLiteralMarkdown(unwrapped);
|
|
8993
|
+
}
|
|
8994
|
+
function composeTreeListCard(peer, report, opts) {
|
|
8995
|
+
const cols = opts.inThread ? 2 : 3;
|
|
8996
|
+
const displayTitle = peer.isManager ? "Manager" : workerDisplayTitle(peer);
|
|
8997
|
+
const fromVal = opts.from ?? (peer.isManager ? "home" : "worker");
|
|
8998
|
+
const navBase = { filter: report.filter, from: fromVal };
|
|
8999
|
+
const headSeq = report.nodes.find((n) => n.isHead)?.seq ?? seqFromEntryId(report.activeEntryId);
|
|
9000
|
+
const items = report.nodes.map((node) => {
|
|
9001
|
+
const marker = node.isHead ? "\u2605" : node.onActivePath ? "\u25CF" : "\u{1F33F}";
|
|
9002
|
+
const tags = [];
|
|
9003
|
+
if (node.isHead) tags.push("\u5F53\u524D");
|
|
9004
|
+
if (node.isBranchPoint) tags.push(`\u2442\xD7${node.childCount}`);
|
|
9005
|
+
if (node.isBranchTip) tags.push("\u5206\u652F\u672B");
|
|
9006
|
+
if (node.label) tags.push(`\u{1F3F7}\uFE0F${cleanInline4(node.label, 20)}`);
|
|
9007
|
+
const tagSuffix = tags.length > 0 ? ` \xB7 ${tags.join(" ")}` : "";
|
|
9008
|
+
const preview = cleanInline4(node.preview || "(\u7A7A)", 72);
|
|
9009
|
+
const text = `${marker} **#${node.seq}** ${kindBadge(node.kind)} \xB7 ${formatNodeClock(node.timestamp)}${tagSuffix}
|
|
9010
|
+
${preview}`;
|
|
9011
|
+
const actions = node.isHead ? [] : [{
|
|
9012
|
+
id: `panel.tree.branch.${peer.instanceId}`,
|
|
9013
|
+
label: node.onActivePath ? "\u23EA \u56DE\u9000" : "\u{1F33F} \u5207\u5206\u652F",
|
|
9014
|
+
payload: { entryId: node.id, page: report.page, filter: report.filter, from: fromVal }
|
|
9015
|
+
}];
|
|
9016
|
+
return { text, ...actions.length > 0 ? { actions } : {} };
|
|
9017
|
+
});
|
|
9018
|
+
const bodyLines = [];
|
|
9019
|
+
if (opts.banner) bodyLines.push(opts.banner);
|
|
9020
|
+
if (!report.isIdle || report.compactionRunning) {
|
|
9021
|
+
bodyLines.push("\u26A0\uFE0F \u4F1A\u8BDD\u5F53\u524D\u5FD9\u788C\u4E2D\uFF08\u8F93\u51FA\u6216\u538B\u7F29\u8FDB\u884C\u4E2D\uFF09\uFF0C\u5207\u6362\u524D\u8BF7\u5148\u505C\u6B62\u5F53\u524D\u8F93\u51FA\u3002");
|
|
9022
|
+
}
|
|
9023
|
+
if (report.truncated) {
|
|
9024
|
+
bodyLines.push("\u2139\uFE0F \u4F1A\u8BDD\u8282\u70B9\u8F83\u591A\uFF0C\u4EC5\u626B\u63CF\u6700\u8FD1\u7A97\u53E3\uFF08\u4ECD\u53EF\u901A\u8FC7\u8FC7\u6EE4\u67E5\u770B\u6700\u65B0\u5173\u952E\u8282\u70B9\uFF09\u3002");
|
|
9025
|
+
}
|
|
9026
|
+
if (items.length === 0) {
|
|
9027
|
+
bodyLines.push(report.filter === "key" ? "_\u6682\u65E0\u5173\u952E\u8282\u70B9\uFF0C\u53EF\u70B9\u51FB\u4E0B\u65B9\u300C\u{1F50D} \u663E\u793A\u5168\u90E8\u300D\u67E5\u770B\u6240\u6709\u8BB0\u5F55\u3002_" : "_\u5F53\u524D\u4F1A\u8BDD\u6682\u65E0\u6811\u8282\u70B9\u3002_");
|
|
9028
|
+
}
|
|
9029
|
+
const navButtons = [];
|
|
9030
|
+
if (report.page > 1) {
|
|
9031
|
+
navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `\u25C0\uFE0F \u7B2C ${report.page - 1} \u9875`, payload: { ...navBase, page: report.page - 1 } });
|
|
9032
|
+
}
|
|
9033
|
+
if (report.page < report.totalPages) {
|
|
9034
|
+
navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `\u7B2C ${report.page + 1} \u9875 \u25B6\uFE0F`, payload: { ...navBase, page: report.page + 1 } });
|
|
9035
|
+
}
|
|
9036
|
+
const toggleFilter = report.filter === "key" ? { id: `panel.tree.${peer.instanceId}`, label: "\u{1F50D} \u663E\u793A\u5168\u90E8", payload: { filter: "all", page: 1, from: fromVal } } : { id: `panel.tree.${peer.instanceId}`, label: "\u2728 \u4EC5\u5173\u952E\u8282\u70B9", payload: { filter: "key", page: 1, from: fromVal } };
|
|
9037
|
+
const subtitleParts = [
|
|
9038
|
+
headSeq !== void 0 ? `\u5F53\u524D #${headSeq}` : "\u65E0\u6D3B\u52A8\u8282\u70B9",
|
|
9039
|
+
`${report.totalEntries} \u8282\u70B9`,
|
|
9040
|
+
...report.branchPointCount > 0 ? [`${report.branchPointCount} \u5206\u53C9`] : [],
|
|
9041
|
+
...report.otherBranchTipCount > 0 ? [`${report.otherBranchTipCount} \u5176\u4ED6\u5206\u652F`] : [],
|
|
9042
|
+
`p${report.page}/${report.totalPages}`
|
|
9043
|
+
];
|
|
9044
|
+
return {
|
|
9045
|
+
title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${displayTitle}`,
|
|
9046
|
+
subtitle: subtitleParts.join(" \xB7 "),
|
|
9047
|
+
color: !report.isIdle || report.compactionRunning ? "violet" : "blue",
|
|
9048
|
+
columnsPerRow: cols,
|
|
9049
|
+
body: bodyLines.join("\n\n"),
|
|
9050
|
+
...items.length > 0 ? { items } : {},
|
|
9051
|
+
footer: "\u2605\u5F53\u524D \u25CF\u4E3B\u7EBF \u{1F33F}\u5176\u4ED6\u5206\u652F \xB7 \u56DE\u9000\u4E3A\u65E0\u635F\u5207\u5206\u652F\uFF0C\u65E7\u5206\u652F\u5B8C\u6574\u4FDD\u7559\u53EF\u968F\u65F6\u5207\u56DE\uFF08zero LLM\uFF09\u3002",
|
|
9052
|
+
actions: [
|
|
9053
|
+
...navButtons,
|
|
9054
|
+
toggleFilter,
|
|
9055
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} Refresh", payload: { ...navBase, page: report.page } },
|
|
9056
|
+
...backActionsFor(peer, { hideHome: opts.hideHome, from: fromVal, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9057
|
+
]
|
|
9058
|
+
};
|
|
9059
|
+
}
|
|
9060
|
+
function composeTreeBranchConfirmCard(peer, detail, opts) {
|
|
9061
|
+
const cols = opts.inThread ? 2 : 3;
|
|
9062
|
+
const displayTitle = peer.isManager ? "Manager" : workerDisplayTitle(peer);
|
|
9063
|
+
const fromVal = opts.from ?? (peer.isManager ? "home" : "worker");
|
|
9064
|
+
const cancelAction = {
|
|
9065
|
+
id: `panel.tree.${peer.instanceId}`,
|
|
9066
|
+
label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811",
|
|
9067
|
+
payload: { page: opts.page, filter: opts.filter, from: fromVal }
|
|
9068
|
+
};
|
|
9069
|
+
const entry = detail.entry;
|
|
9070
|
+
if (!entry) {
|
|
9071
|
+
return {
|
|
9072
|
+
title: "\u26A0\uFE0F \u8282\u70B9\u4E0D\u5B58\u5728",
|
|
9073
|
+
subtitle: displayTitle,
|
|
9074
|
+
color: "grey",
|
|
9075
|
+
columnsPerRow: cols,
|
|
9076
|
+
body: "\u76EE\u6807\u8282\u70B9\u5728\u5F53\u524D\u4F1A\u8BDD\u4E2D\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5237\u65B0\u4F1A\u8BDD\u6811\u91CD\u8BD5\u3002",
|
|
9077
|
+
actions: [cancelAction]
|
|
9078
|
+
};
|
|
9079
|
+
}
|
|
9080
|
+
if (entry.isHead) {
|
|
9081
|
+
return {
|
|
9082
|
+
title: `\u{1F333} \u5DF2\u5728\u76EE\u6807\u8282\u70B9 #${entry.seq}`,
|
|
9083
|
+
subtitle: displayTitle,
|
|
9084
|
+
color: "green",
|
|
9085
|
+
columnsPerRow: cols,
|
|
9086
|
+
body: "\u5F53\u524D\u4F1A\u8BDD\u6307\u9488\u5DF2\u7ECF\u4F4D\u4E8E\u8BE5\u8282\u70B9\uFF0C\u65E0\u9700\u5207\u6362\u3002",
|
|
9087
|
+
actions: [cancelAction]
|
|
9088
|
+
};
|
|
9089
|
+
}
|
|
9090
|
+
if (!detail.isIdle || detail.compactionRunning) {
|
|
9091
|
+
return {
|
|
9092
|
+
title: "\u26A0\uFE0F \u4F1A\u8BDD\u5FD9\u788C\uFF0C\u6682\u4E0D\u53EF\u5207\u6362\u5206\u652F",
|
|
9093
|
+
subtitle: `${displayTitle} \xB7 \u76EE\u6807 #${entry.seq}`,
|
|
9094
|
+
color: "red",
|
|
9095
|
+
columnsPerRow: cols,
|
|
9096
|
+
body: detail.compactionRunning ? "\u5F53\u524D\u6B63\u5728\u6267\u884C\u4E0A\u4E0B\u6587\u538B\u7F29\uFF08Compaction\uFF09\uFF0C\u8BF7\u7B49\u5F85\u538B\u7F29\u5B8C\u6210\u540E\u518D\u5207\u6362\u5206\u652F\u3002" : "\u5F53\u524D\u6709\u6B63\u5728\u8FDB\u884C\u6216\u6392\u961F\u7684\u56DE\u590D\uFF0C\u8BF7\u5148\u505C\u6B62\u5F53\u524D\u8F93\u51FA\u540E\u518D\u6267\u884C\u65E0\u635F\u56DE\u9000\u3002",
|
|
9097
|
+
actions: [
|
|
9098
|
+
...!detail.compactionRunning ? [{ id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: { from: fromVal, peer: peer.instanceId } }] : [],
|
|
9099
|
+
cancelAction
|
|
9100
|
+
]
|
|
9101
|
+
};
|
|
9102
|
+
}
|
|
9103
|
+
const impactLine = entry.onActivePath ? `\u5C06\u628A\u4F1A\u8BDD\u6307\u9488\u56DE\u9000\u5230 **#${entry.seq}**\uFF08\u8DF3\u8FC7\u5F53\u524D\u4E3B\u7EBF\u540E\u7EED **${entry.activePathAfterCount}** \u6761\u8BB0\u5F55\uFF09\u3002` : `\u5C06\u628A\u4F1A\u8BDD\u6307\u9488\u5207\u6362\u5230\u53E6\u4E00\u5206\u652F\u7684 **#${entry.seq}**\u3002`;
|
|
9104
|
+
return {
|
|
9105
|
+
title: entry.onActivePath ? `\u23EA \u786E\u8BA4\u56DE\u9000\u5230 #${entry.seq}` : `\u{1F33F} \u786E\u8BA4\u5207\u6362\u5230\u5206\u652F #${entry.seq}`,
|
|
9106
|
+
subtitle: `${displayTitle} \xB7 ${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)}`,
|
|
9107
|
+
color: "red",
|
|
9108
|
+
columnsPerRow: cols,
|
|
9109
|
+
body: [
|
|
9110
|
+
`| Field | Value |
|
|
9111
|
+
|---|---|
|
|
9112
|
+
| session | ${sanitizeTableCell3(displayTitle, 48)} |
|
|
9113
|
+
| target | #${entry.seq} (${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)}) |
|
|
9114
|
+
| preview | ${sanitizeTableCell3(entry.preview || "(\u7A7A)", 72)} |`,
|
|
9115
|
+
"",
|
|
9116
|
+
impactLine,
|
|
9117
|
+
"\u2705 **\u65E0\u635F\u64CD\u4F5C**\uFF1A\u539F\u6709\u5206\u652F\u5B8C\u6574\u4FDD\u7559\u5728\u4F1A\u8BDD\u6811\u4E2D\uFF0C\u968F\u65F6\u53EF\u901A\u8FC7 Tree \u518D\u5207\u56DE\u3002",
|
|
9118
|
+
"\u2139\uFE0F \u4EC5\u5207\u6362 Agent \u7684\u4F1A\u8BDD\u8BB0\u5FC6\u4E0A\u4E0B\u6587\uFF0C\u804A\u5929\u8BB0\u5F55\u4E2D\u5DF2\u53D1\u51FA\u7684\u5386\u53F2\u6D88\u606F\u4E0D\u4F1A\u88AB\u64A4\u56DE\u3002"
|
|
9119
|
+
].join("\n"),
|
|
9120
|
+
actions: [
|
|
9121
|
+
{
|
|
9122
|
+
id: `panel.tree.branch.confirm.${peer.instanceId}`,
|
|
9123
|
+
label: "\u2705 \u786E\u8BA4\u5207\u6362",
|
|
9124
|
+
style: "danger",
|
|
9125
|
+
payload: {
|
|
9126
|
+
treeBranch: { ref: peer.instanceId, session: detail.sessionId, entryId: entry.id },
|
|
9127
|
+
page: opts.page,
|
|
9128
|
+
filter: opts.filter,
|
|
9129
|
+
from: fromVal
|
|
9130
|
+
}
|
|
9131
|
+
},
|
|
9132
|
+
{
|
|
9133
|
+
id: `panel.tree.${peer.instanceId}`,
|
|
9134
|
+
label: "\u21A9\uFE0F \u53D6\u6D88",
|
|
9135
|
+
payload: { page: opts.page, filter: opts.filter, from: fromVal }
|
|
9136
|
+
}
|
|
9137
|
+
]
|
|
9138
|
+
};
|
|
9139
|
+
}
|
|
9140
|
+
async function runTreePanelCommand(panelCmd, opts) {
|
|
9141
|
+
if (!isTreePanelCommand(panelCmd.cmd)) return { handled: false };
|
|
9142
|
+
const cols = opts.inThread ? 2 : 3;
|
|
9143
|
+
const meta = parseTreeMeta(panelCmd.payload);
|
|
9144
|
+
if (!opts.canReadSensitive) {
|
|
9145
|
+
return {
|
|
9146
|
+
handled: true,
|
|
9147
|
+
keyPrefix: "panel-tree-denied",
|
|
9148
|
+
spec: {
|
|
9149
|
+
title: "\u{1F333} \u4F1A\u8BDD\u6811\u4E0D\u53EF\u7528",
|
|
9150
|
+
color: "red",
|
|
9151
|
+
columnsPerRow: cols,
|
|
9152
|
+
body: "\u26D4\uFE0F \u4F1A\u8BDD\u6811\u5305\u542B\u5BF9\u8BDD\u6458\u8981\uFF0C\u4EC5\u9650\u5DF2\u6388\u6743\u7FA4\u804A\u6216\u79C1\u804A\u8BBF\u95EE\u3002",
|
|
9153
|
+
actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
|
|
9154
|
+
}
|
|
9155
|
+
};
|
|
9156
|
+
}
|
|
9157
|
+
const resolveTargetPeer = (peerRef2) => {
|
|
9158
|
+
const peers = scanPeers();
|
|
9159
|
+
if (opts.workerScoped && opts.pinnedWorkerSessionId) {
|
|
9160
|
+
const live = findPeerBySessionId(opts.pinnedWorkerSessionId);
|
|
9161
|
+
if (!live) return void 0;
|
|
9162
|
+
if (peerRef2 && live.instanceId !== peerRef2) return void 0;
|
|
9163
|
+
return live;
|
|
9164
|
+
}
|
|
9165
|
+
if (peerRef2) return peers.find((p) => p.instanceId === peerRef2);
|
|
9166
|
+
return peers.find((p) => p.isManager);
|
|
9167
|
+
};
|
|
9168
|
+
const offlineSpec = (peerRef2) => {
|
|
9169
|
+
if (opts.workerScoped && opts.pinnedWorkerSessionId) {
|
|
9170
|
+
return composeOfflineWorkerCard(opts.pinnedWorkerSessionId, { inThread: opts.inThread, hideHome: true });
|
|
9171
|
+
}
|
|
9172
|
+
return {
|
|
9173
|
+
title: "\u{1F333} \u4F1A\u8BDD\u5DF2\u79BB\u7EBF",
|
|
9174
|
+
color: "grey",
|
|
9175
|
+
columnsPerRow: cols,
|
|
9176
|
+
body: peerRef2 ? `\u672A\u627E\u5230\u5728\u7EBF\u4F1A\u8BDD \`${cleanCodeSpan(peerRef2, 40)}\`\uFF0C\u53EF\u80FD\u5DF2\u9000\u51FA\u6216\u6B63\u5728\u91CD\u542F\u3002` : "\u672A\u627E\u5230\u5728\u7EBF\u7684 Manager \u4F1A\u8BDD\uFF0C\u8BF7\u5237\u65B0\u603B\u9762\u677F\u540E\u91CD\u8BD5\u3002",
|
|
9177
|
+
actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
|
|
9178
|
+
};
|
|
9179
|
+
};
|
|
9180
|
+
const confirmMatch = /^panel\.tree\.branch\.confirm\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9181
|
+
if (confirmMatch) {
|
|
9182
|
+
if (!opts.canMutate) {
|
|
9183
|
+
return {
|
|
9184
|
+
handled: true,
|
|
9185
|
+
keyPrefix: "panel-tree-refused",
|
|
9186
|
+
refusedText: "\u26D4\uFE0F Switching session branch requires admin rights (panelAccess=allowUsers)."
|
|
9187
|
+
};
|
|
9188
|
+
}
|
|
9189
|
+
const peerRef2 = confirmMatch[1];
|
|
9190
|
+
const wireBound = isRecord(panelCmd.payload) && isRecord(panelCmd.payload.treeBranch) ? panelCmd.payload.treeBranch : void 0;
|
|
9191
|
+
const verified = opts.verifiedBranch;
|
|
9192
|
+
if (!verified || verified.ref !== peerRef2 || !wireBound || wireBound.ref !== verified.ref || wireBound.session !== verified.sessionId || wireBound.entryId !== verified.entryId) {
|
|
9193
|
+
const livePeer = resolveTargetPeer(peerRef2);
|
|
9194
|
+
return {
|
|
9195
|
+
handled: true,
|
|
9196
|
+
keyPrefix: "panel-tree-confirm-stale",
|
|
9197
|
+
spec: {
|
|
9198
|
+
title: "\u26A0\uFE0F \u786E\u8BA4\u5361\u7247\u5DF2\u5931\u6548",
|
|
9199
|
+
color: "grey",
|
|
9200
|
+
columnsPerRow: cols,
|
|
9201
|
+
body: "\u8BE5\u5207\u6362\u786E\u8BA4\u5DF2\u8FC7\u671F\u3001\u88AB\u6D88\u8D39\u6216\u4F1A\u8BDD\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u4F1A\u8BDD\u6811\u9009\u62E9\u76EE\u6807\u8282\u70B9\u3002",
|
|
9202
|
+
actions: livePeer ? [{ id: `panel.tree.${livePeer.instanceId}`, label: "\u{1F333} \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } }] : panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
|
|
9203
|
+
}
|
|
9204
|
+
};
|
|
9205
|
+
}
|
|
9206
|
+
const peer2 = resolveTargetPeer(peerRef2);
|
|
9207
|
+
if (!peer2 || peer2.sessionId !== verified.sessionId) {
|
|
9208
|
+
return {
|
|
9209
|
+
handled: true,
|
|
9210
|
+
keyPrefix: "panel-tree-confirm-offline",
|
|
9211
|
+
clearIssuedBranch: true,
|
|
9212
|
+
spec: offlineSpec(peerRef2)
|
|
9213
|
+
};
|
|
9214
|
+
}
|
|
9215
|
+
const receipt2 = await applyPeerControl(
|
|
9216
|
+
peer2.instanceId,
|
|
9217
|
+
"session.branch",
|
|
9218
|
+
{ entryId: verified.entryId, expectedSessionId: verified.sessionId },
|
|
9219
|
+
{ instanceId: peer2.instanceId, sessionId: verified.sessionId }
|
|
9220
|
+
);
|
|
9221
|
+
if (!receipt2.ok) {
|
|
9222
|
+
return {
|
|
9223
|
+
handled: true,
|
|
9224
|
+
keyPrefix: "panel-tree-branch-failed",
|
|
9225
|
+
clearIssuedBranch: true,
|
|
9226
|
+
spec: {
|
|
9227
|
+
title: receipt2.unknown ? "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u72B6\u6001\u672A\u77E5" : "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u5DF2\u62D2\u7EDD",
|
|
9228
|
+
color: "red",
|
|
9229
|
+
columnsPerRow: cols,
|
|
9230
|
+
body: `${formatPeerErrorDetail(receipt2.detail)}${receipt2.unknown ? "\n\n\u8BF7\u5148\u5237\u65B0\u4F1A\u8BDD\u6811\u786E\u8BA4\u5F53\u524D\u6307\u9488\u540E\u518D\u51B3\u5B9A\u662F\u5426\u91CD\u8BD5\u3002" : ""}`,
|
|
9231
|
+
actions: [
|
|
9232
|
+
{ id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
|
|
9233
|
+
...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9234
|
+
]
|
|
9235
|
+
}
|
|
9236
|
+
};
|
|
9237
|
+
}
|
|
9238
|
+
const switched = parseBranchSuccess(receipt2.detail, verified.sessionId, verified.entryId);
|
|
9239
|
+
const banner = switched ? switched.alreadyActive ? `\u2139\uFE0F \u5F53\u524D\u5DF2\u4F4D\u4E8E **#${switched.seq}**\u3002` : `\u2705 \u5DF2\u65E0\u635F\u5207\u6362\u81F3 **#${switched.seq}**\uFF08\u5F53\u524D\u8DEF\u5F84 ${switched.pathLength} \u6761\u8BB0\u5F55\uFF0C\u65E7\u5206\u652F\u5DF2\u4FDD\u7559\uFF09\u3002` : "\u26A0\uFE0F \u76EE\u6807\u4F1A\u8BDD\u8FD4\u56DE\u4E86\u975E\u9884\u671F\u56DE\u6267\uFF0C\u5DF2\u5237\u65B0\u6700\u65B0\u4F1A\u8BDD\u6811\uFF0C\u8BF7\u6838\u5BF9\u5F53\u524D \u2605 \u6307\u9488\u3002";
|
|
9240
|
+
const refreshReceipt = await applyPeerControl(
|
|
9241
|
+
peer2.instanceId,
|
|
9242
|
+
"session.tree",
|
|
9243
|
+
{ page: 1, pageSize: TREE_PAGE_SIZE, filter: meta.filter },
|
|
9244
|
+
{ instanceId: peer2.instanceId, sessionId: peer2.sessionId }
|
|
9245
|
+
);
|
|
9246
|
+
const refreshed = refreshReceipt.ok ? parseTreePageReport(refreshReceipt.detail, peer2.sessionId) : void 0;
|
|
9247
|
+
if (refreshed) {
|
|
9248
|
+
return {
|
|
9249
|
+
handled: true,
|
|
9250
|
+
keyPrefix: "panel-tree-switched",
|
|
9251
|
+
clearIssuedBranch: true,
|
|
9252
|
+
spec: composeTreeListCard(peer2, refreshed, {
|
|
9253
|
+
inThread: opts.inThread,
|
|
9254
|
+
hideHome: opts.hideHome,
|
|
9255
|
+
from: meta.from,
|
|
9256
|
+
pinnedWorkerSessionId: opts.pinnedWorkerSessionId,
|
|
9257
|
+
banner
|
|
9258
|
+
})
|
|
9259
|
+
};
|
|
9260
|
+
}
|
|
9261
|
+
return {
|
|
9262
|
+
handled: true,
|
|
9263
|
+
keyPrefix: "panel-tree-switched",
|
|
9264
|
+
clearIssuedBranch: true,
|
|
9265
|
+
spec: {
|
|
9266
|
+
title: "\u{1F333} \u5206\u652F\u5DF2\u5207\u6362",
|
|
9267
|
+
color: "green",
|
|
9268
|
+
columnsPerRow: cols,
|
|
9269
|
+
body: banner,
|
|
9270
|
+
actions: [
|
|
9271
|
+
{ id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} \u67E5\u770B\u4F1A\u8BDD\u6811", payload: { page: 1, filter: meta.filter, from: meta.from } },
|
|
9272
|
+
...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9273
|
+
]
|
|
9274
|
+
}
|
|
9275
|
+
};
|
|
9276
|
+
}
|
|
9277
|
+
const branchMatch = /^panel\.tree\.branch\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9278
|
+
if (branchMatch) {
|
|
9279
|
+
if (!opts.canMutate) {
|
|
9280
|
+
return {
|
|
9281
|
+
handled: true,
|
|
9282
|
+
keyPrefix: "panel-tree-refused",
|
|
9283
|
+
refusedText: "\u26D4\uFE0F Switching session branch requires admin rights (panelAccess=allowUsers)."
|
|
9284
|
+
};
|
|
9285
|
+
}
|
|
9286
|
+
const peerRef2 = branchMatch[1];
|
|
9287
|
+
const peer2 = resolveTargetPeer(peerRef2);
|
|
9288
|
+
if (!peer2) {
|
|
9289
|
+
return { handled: true, keyPrefix: "panel-tree-offline", spec: offlineSpec(peerRef2) };
|
|
9290
|
+
}
|
|
9291
|
+
if (!meta.entryId) {
|
|
9292
|
+
return {
|
|
9293
|
+
handled: true,
|
|
9294
|
+
keyPrefix: "panel-tree-invalid-entry",
|
|
9295
|
+
spec: {
|
|
9296
|
+
title: "\u26A0\uFE0F \u65E0\u6548\u8282\u70B9",
|
|
9297
|
+
color: "red",
|
|
9298
|
+
columnsPerRow: cols,
|
|
9299
|
+
body: "\u7F3A\u5C11\u6709\u6548\u7684\u76EE\u6807\u8282\u70B9 ID\uFF0C\u8BF7\u4ECE\u4F1A\u8BDD\u6811\u5217\u8868\u91CD\u65B0\u9009\u62E9\u3002",
|
|
9300
|
+
actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
|
|
9301
|
+
}
|
|
9302
|
+
};
|
|
9303
|
+
}
|
|
9304
|
+
const receipt2 = await applyPeerControl(
|
|
9305
|
+
peer2.instanceId,
|
|
9306
|
+
"session.tree",
|
|
9307
|
+
{ entryId: meta.entryId },
|
|
9308
|
+
{ instanceId: peer2.instanceId, sessionId: peer2.sessionId }
|
|
9309
|
+
);
|
|
9310
|
+
const detail = receipt2.ok ? parseTreeEntryReport(receipt2.detail, peer2.sessionId) : void 0;
|
|
9311
|
+
if (!detail) {
|
|
9312
|
+
return {
|
|
9313
|
+
handled: true,
|
|
9314
|
+
keyPrefix: "panel-tree-entry-error",
|
|
9315
|
+
spec: {
|
|
9316
|
+
title: "\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u76EE\u6807\u8282\u70B9",
|
|
9317
|
+
color: "red",
|
|
9318
|
+
columnsPerRow: cols,
|
|
9319
|
+
body: formatPeerErrorDetail(receipt2.detail),
|
|
9320
|
+
actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
|
|
9321
|
+
}
|
|
9322
|
+
};
|
|
9323
|
+
}
|
|
9324
|
+
return {
|
|
9325
|
+
handled: true,
|
|
9326
|
+
keyPrefix: "panel-tree-branch-confirm",
|
|
9327
|
+
spec: composeTreeBranchConfirmCard(peer2, detail, {
|
|
9328
|
+
inThread: opts.inThread,
|
|
9329
|
+
hideHome: opts.hideHome,
|
|
9330
|
+
page: meta.page,
|
|
9331
|
+
filter: meta.filter,
|
|
9332
|
+
from: meta.from
|
|
9333
|
+
})
|
|
9334
|
+
};
|
|
9335
|
+
}
|
|
9336
|
+
const listMatch = /^panel\.tree\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9337
|
+
const peerRef = listMatch?.[1];
|
|
9338
|
+
const peer = resolveTargetPeer(peerRef);
|
|
9339
|
+
if (!peer) {
|
|
9340
|
+
return { handled: true, keyPrefix: "panel-tree-offline", spec: offlineSpec(peerRef) };
|
|
9341
|
+
}
|
|
9342
|
+
const receipt = await applyPeerControl(
|
|
9343
|
+
peer.instanceId,
|
|
9344
|
+
"session.tree",
|
|
9345
|
+
{ page: meta.page, pageSize: TREE_PAGE_SIZE, filter: meta.filter },
|
|
9346
|
+
{ instanceId: peer.instanceId, sessionId: peer.sessionId }
|
|
9347
|
+
);
|
|
9348
|
+
const report = receipt.ok ? parseTreePageReport(receipt.detail, peer.sessionId) : void 0;
|
|
9349
|
+
if (!report) {
|
|
9350
|
+
return {
|
|
9351
|
+
handled: true,
|
|
9352
|
+
keyPrefix: "panel-tree-error",
|
|
9353
|
+
spec: {
|
|
9354
|
+
title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${peer.isManager ? "Manager" : workerDisplayTitle(peer)}`,
|
|
9355
|
+
color: "red",
|
|
9356
|
+
columnsPerRow: cols,
|
|
9357
|
+
body: formatPeerErrorDetail(receipt.detail),
|
|
9358
|
+
actions: [
|
|
9359
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} \u91CD\u8BD5", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
|
|
9360
|
+
...backActionsFor(peer, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9361
|
+
]
|
|
9362
|
+
}
|
|
9363
|
+
};
|
|
9364
|
+
}
|
|
9365
|
+
return {
|
|
9366
|
+
handled: true,
|
|
9367
|
+
keyPrefix: "panel-tree",
|
|
9368
|
+
spec: composeTreeListCard(peer, report, {
|
|
9369
|
+
inThread: opts.inThread,
|
|
9370
|
+
hideHome: opts.hideHome,
|
|
9371
|
+
from: meta.from,
|
|
9372
|
+
pinnedWorkerSessionId: opts.pinnedWorkerSessionId
|
|
9373
|
+
})
|
|
9374
|
+
};
|
|
9375
|
+
}
|
|
9376
|
+
|
|
8753
9377
|
// builtin/extensions/im-forward/panel-memory.ts
|
|
8754
9378
|
import * as fs18 from "node:fs";
|
|
8755
9379
|
import * as path20 from "node:path";
|
|
@@ -9292,6 +9916,7 @@ function createPanelCardState(ctx) {
|
|
|
9292
9916
|
const issuedWorkerCards = /* @__PURE__ */ new Map();
|
|
9293
9917
|
const issuedQuitCards = /* @__PURE__ */ new Map();
|
|
9294
9918
|
const issuedCronStopCards = /* @__PURE__ */ new Map();
|
|
9919
|
+
const issuedTreeBranchCards = /* @__PURE__ */ new Map();
|
|
9295
9920
|
const cardPatchChains = /* @__PURE__ */ new Map();
|
|
9296
9921
|
const cardNavGens = /* @__PURE__ */ new Map();
|
|
9297
9922
|
function rememberPanelCard(messageId, sessionId, chatId, thread) {
|
|
@@ -9364,6 +9989,11 @@ function createPanelCardState(ctx) {
|
|
|
9364
9989
|
clearIssuedCronStopCard: (messageId) => {
|
|
9365
9990
|
issuedCronStopCards.delete(messageId);
|
|
9366
9991
|
},
|
|
9992
|
+
getIssuedTreeBranchCard: (messageId) => issuedTreeBranchCards.get(messageId),
|
|
9993
|
+
setIssuedTreeBranchCard: (messageId, card) => putBounded(issuedTreeBranchCards, messageId, card),
|
|
9994
|
+
clearIssuedTreeBranchCard: (messageId) => {
|
|
9995
|
+
issuedTreeBranchCards.delete(messageId);
|
|
9996
|
+
},
|
|
9367
9997
|
enqueueCardPatch: (cardId, task) => {
|
|
9368
9998
|
const prev = cardPatchChains.get(cardId) ?? Promise.resolve();
|
|
9369
9999
|
const result = prev.then(task, task);
|
|
@@ -9386,6 +10016,7 @@ function createPanelCardState(ctx) {
|
|
|
9386
10016
|
issuedWorkerCards.clear();
|
|
9387
10017
|
issuedQuitCards.clear();
|
|
9388
10018
|
issuedCronStopCards.clear();
|
|
10019
|
+
issuedTreeBranchCards.clear();
|
|
9389
10020
|
peekCards.clear();
|
|
9390
10021
|
cardNavGens.clear();
|
|
9391
10022
|
}
|
|
@@ -9405,7 +10036,7 @@ function createPanelExecutor(ctx) {
|
|
|
9405
10036
|
const workerScoped = opts?.workerScoped === true || opts?.cardOrigin?.workerScoped === true || inThread && Boolean(pinnedThreadWorkerSession);
|
|
9406
10037
|
const hideHome = workerScoped || inThread;
|
|
9407
10038
|
const threadReplyTo = opts?.threadReplyTo ?? opts?.cardOrigin?.replyTo;
|
|
9408
|
-
const cmdWorkerPeerId = panelCmd.cmd === "panel.worker.cron.offline" ? void 0 : /^panel\.worker(?:\.(?:models|cron))?\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd)?.[1] ?? /^panel\.quit\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd)?.[1];
|
|
10039
|
+
const cmdWorkerPeerId = panelCmd.cmd === "panel.worker.cron.offline" ? void 0 : /^panel\.worker(?:\.(?:models|cron))?\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd)?.[1] ?? /^panel\.tree(?:\.branch(?:\.confirm)?)?\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd)?.[1] ?? /^panel\.quit\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd)?.[1];
|
|
9409
10040
|
const resolvedWorkerSession = cmdWorkerPeerId ? scanPeers().find((p) => p.instanceId === cmdWorkerPeerId)?.sessionId : (panelCmd.cmd === "panel.worker.offline" || panelCmd.cmd === "panel.worker.cron.offline") && isRecord(panelCmd.payload) && typeof panelCmd.payload.sessionId === "string" ? panelCmd.payload.sessionId : void 0;
|
|
9410
10041
|
const threadWorkerSessionId = workerScoped && pinnedThreadWorkerSession ? pinnedThreadWorkerSession : resolvedWorkerSession ?? pinnedThreadWorkerSession;
|
|
9411
10042
|
const sendReplyTo = inThread && threadReplyTo ? threadReplyTo : void 0;
|
|
@@ -9425,7 +10056,7 @@ function createPanelExecutor(ctx) {
|
|
|
9425
10056
|
...workerSession ? { threadWorkerSessionId: workerSession } : {}
|
|
9426
10057
|
};
|
|
9427
10058
|
};
|
|
9428
|
-
const applyIssuedCards = (cardMessageId, workerBinding, quitBinding, cronStopBinding) => {
|
|
10059
|
+
const applyIssuedCards = (cardMessageId, workerBinding, quitBinding, cronStopBinding, treeBranchBinding) => {
|
|
9429
10060
|
if (!cardMessageId) return;
|
|
9430
10061
|
if (workerBinding) ctx.cards.setIssuedWorkerCard(cardMessageId, workerBinding);
|
|
9431
10062
|
else ctx.cards.clearIssuedWorkerCard(cardMessageId);
|
|
@@ -9433,6 +10064,8 @@ function createPanelExecutor(ctx) {
|
|
|
9433
10064
|
else ctx.cards.clearIssuedQuitCard(cardMessageId);
|
|
9434
10065
|
if (cronStopBinding) ctx.cards.setIssuedCronStopCard(cardMessageId, cronStopBinding);
|
|
9435
10066
|
else ctx.cards.clearIssuedCronStopCard(cardMessageId);
|
|
10067
|
+
if (treeBranchBinding) ctx.cards.setIssuedTreeBranchCard(cardMessageId, treeBranchBinding);
|
|
10068
|
+
else ctx.cards.clearIssuedTreeBranchCard(cardMessageId);
|
|
9436
10069
|
};
|
|
9437
10070
|
const claimNavGen = () => {
|
|
9438
10071
|
if (!canPatchOrigin || !event.message_id) return void 0;
|
|
@@ -9445,6 +10078,7 @@ function createPanelExecutor(ctx) {
|
|
|
9445
10078
|
const plannedWorker = isCurrent() ? extractIssuedWorkerCard(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9446
10079
|
const plannedQuit = isCurrent() ? extractIssuedQuitCard(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9447
10080
|
const plannedCronStop = isCurrent() ? extractIssuedCronStop(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
10081
|
+
const plannedTreeBranch = isCurrent() ? extractIssuedTreeBranch(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9448
10082
|
if (patchInPlace && canPatchOrigin && event.message_id && ctx.connection.patch) {
|
|
9449
10083
|
const cardId = event.message_id;
|
|
9450
10084
|
if (expectedNavGen !== void 0 && ctx.cards.getCardNav(cardId) !== expectedNavGen) return;
|
|
@@ -9456,8 +10090,10 @@ function createPanelExecutor(ctx) {
|
|
|
9456
10090
|
ctx.cards.clearPeekCard(cardId);
|
|
9457
10091
|
const prevWorker = ctx.cards.getIssuedWorkerCard(cardId);
|
|
9458
10092
|
const prevQuit = ctx.cards.getIssuedQuitCard(cardId);
|
|
10093
|
+
const prevTreeBranch = ctx.cards.getIssuedTreeBranchCard(cardId);
|
|
9459
10094
|
if (plannedWorker) ctx.cards.setIssuedWorkerCard(cardId, plannedWorker);
|
|
9460
10095
|
if (plannedQuit) ctx.cards.setIssuedQuitCard(cardId, plannedQuit);
|
|
10096
|
+
if (plannedTreeBranch) ctx.cards.setIssuedTreeBranchCard(cardId, plannedTreeBranch);
|
|
9461
10097
|
const rollbackProvisional = () => {
|
|
9462
10098
|
if (plannedWorker && ctx.cards.getIssuedWorkerCard(cardId) === plannedWorker) {
|
|
9463
10099
|
if (isCurrent() && prevWorker) ctx.cards.setIssuedWorkerCard(cardId, prevWorker);
|
|
@@ -9467,13 +10103,17 @@ function createPanelExecutor(ctx) {
|
|
|
9467
10103
|
if (isCurrent() && prevQuit) ctx.cards.setIssuedQuitCard(cardId, prevQuit);
|
|
9468
10104
|
else ctx.cards.clearIssuedQuitCard(cardId);
|
|
9469
10105
|
}
|
|
10106
|
+
if (plannedTreeBranch && ctx.cards.getIssuedTreeBranchCard(cardId) === plannedTreeBranch) {
|
|
10107
|
+
if (isCurrent() && prevTreeBranch) ctx.cards.setIssuedTreeBranchCard(cardId, prevTreeBranch);
|
|
10108
|
+
else ctx.cards.clearIssuedTreeBranchCard(cardId);
|
|
10109
|
+
}
|
|
9470
10110
|
};
|
|
9471
10111
|
try {
|
|
9472
10112
|
const ok = await ctx.connection.patch(cardId, normalizedSpec);
|
|
9473
10113
|
if (ok) {
|
|
9474
10114
|
if (isCurrent()) {
|
|
9475
10115
|
ctx.cards.rememberPanelCard(cardId, sessionId, event.chat_id, threadMetaFor(cardId, keepWorkerSession));
|
|
9476
|
-
applyIssuedCards(cardId, plannedWorker, plannedQuit, plannedCronStop);
|
|
10116
|
+
applyIssuedCards(cardId, plannedWorker, plannedQuit, plannedCronStop, plannedTreeBranch);
|
|
9477
10117
|
} else {
|
|
9478
10118
|
rollbackProvisional();
|
|
9479
10119
|
}
|
|
@@ -9504,7 +10144,7 @@ function createPanelExecutor(ctx) {
|
|
|
9504
10144
|
const sent = await ctx.connection.sendCard(freshRecipient, normalizedSpec, key, sendReplyTo, sendOpts);
|
|
9505
10145
|
if (isCurrent()) {
|
|
9506
10146
|
ctx.cards.rememberPanelCard(sent?.messageId, sessionId, sent?.chatId ?? event.chat_id, threadMetaFor(sent?.messageId, keepWorkerSession));
|
|
9507
|
-
applyIssuedCards(sent?.messageId, plannedWorker, plannedQuit, plannedCronStop);
|
|
10147
|
+
applyIssuedCards(sent?.messageId, plannedWorker, plannedQuit, plannedCronStop, plannedTreeBranch);
|
|
9508
10148
|
}
|
|
9509
10149
|
ctx.log(sent?.messageId ? `im-forward: panel card sent (${panelCmd.cmd})` : `im-forward: panel card send failed (${panelCmd.cmd})`);
|
|
9510
10150
|
} else {
|
|
@@ -9522,13 +10162,22 @@ function createPanelExecutor(ctx) {
|
|
|
9522
10162
|
};
|
|
9523
10163
|
const payloadFromWorker = isRecord(panelCmd.payload) && panelCmd.payload.from === "worker" && typeof panelCmd.payload.peer === "string" ? panelCmd.payload.peer : void 0;
|
|
9524
10164
|
const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
|
|
9525
|
-
if (event.message_id && panelCmd.cmd.startsWith("panel.cron.stop.confirm.")) {
|
|
10165
|
+
if (event.message_id && (panelCmd.cmd.startsWith("panel.cron.stop.confirm.") || panelCmd.cmd.startsWith("panel.tree.branch.confirm."))) {
|
|
9526
10166
|
await ctx.cards.enqueueCardPatch(event.message_id, async () => void 0);
|
|
9527
10167
|
if (!isCurrent()) return;
|
|
9528
10168
|
}
|
|
9529
10169
|
const issuedQuitForGuard = event.message_id ? ctx.cards.getIssuedQuitCard(event.message_id) : void 0;
|
|
9530
10170
|
const issuedCronStopForGuard = event.message_id ? ctx.cards.getIssuedCronStopCard(event.message_id) : void 0;
|
|
9531
|
-
const
|
|
10171
|
+
const issuedTreeBranchForGuard = event.message_id ? ctx.cards.getIssuedTreeBranchCard(event.message_id) : void 0;
|
|
10172
|
+
const threadScopeCheck = guardThreadWorkerScope(
|
|
10173
|
+
panelCmd,
|
|
10174
|
+
workerScoped,
|
|
10175
|
+
inThread,
|
|
10176
|
+
pinnedThreadWorkerSession,
|
|
10177
|
+
issuedQuitForGuard?.targetSession,
|
|
10178
|
+
issuedCronStopForGuard?.sessionId,
|
|
10179
|
+
issuedTreeBranchForGuard?.sessionId
|
|
10180
|
+
);
|
|
9532
10181
|
if (threadScopeCheck.blocked) {
|
|
9533
10182
|
await deliverPanelSpec(threadScopeCheck.spec, `panel-thread-scope-${event.event_id}`, true);
|
|
9534
10183
|
return;
|
|
@@ -9643,6 +10292,40 @@ function createPanelExecutor(ctx) {
|
|
|
9643
10292
|
await deliverPanelSpec(memoryResult.spec, `${memoryResult.keyPrefix}-${event.event_id}`, true);
|
|
9644
10293
|
return;
|
|
9645
10294
|
}
|
|
10295
|
+
if (isTreePanelCommand(effectiveCmd.cmd)) {
|
|
10296
|
+
const canReadSensitive = peekAudienceAllowed(event);
|
|
10297
|
+
const canMutate = canMutatePanel();
|
|
10298
|
+
const verifiedTreeBranch = issuedTreeBranchForGuard && issuedTreeBranchForGuard.chatId === event.chat_id && issuedTreeBranchForGuard.ownerSession === ctx.getCurrentSessionId() && issuedTreeBranchForGuard.epoch === ctx.getInputEpoch() ? { ref: issuedTreeBranchForGuard.ref, sessionId: issuedTreeBranchForGuard.sessionId, entryId: issuedTreeBranchForGuard.entryId } : void 0;
|
|
10299
|
+
if (event.message_id && verifiedTreeBranch && canReadSensitive && canMutate && effectiveCmd.cmd.startsWith("panel.tree.branch.confirm.")) {
|
|
10300
|
+
ctx.cards.clearIssuedTreeBranchCard(event.message_id);
|
|
10301
|
+
}
|
|
10302
|
+
const navGen = claimNavGen();
|
|
10303
|
+
const treeResult = await runTreePanelCommand(effectiveCmd, {
|
|
10304
|
+
inThread,
|
|
10305
|
+
hideHome,
|
|
10306
|
+
workerScoped,
|
|
10307
|
+
pinnedWorkerSessionId: pinnedThreadWorkerSession,
|
|
10308
|
+
canReadSensitive,
|
|
10309
|
+
canMutate,
|
|
10310
|
+
verifiedBranch: verifiedTreeBranch
|
|
10311
|
+
});
|
|
10312
|
+
if (treeResult.handled) {
|
|
10313
|
+
if (!isCurrent()) return;
|
|
10314
|
+
if (treeResult.refusedText) {
|
|
10315
|
+
ctx.log(`im-forward: ${panelCmd.cmd} refused for ${event.sender_id ?? "unknown"} (panelAccess=allowUsers)`);
|
|
10316
|
+
try {
|
|
10317
|
+
await ctx.connection.send(freshRecipient, treeResult.refusedText, `panel-refused-${event.event_id}`, sendReplyTo, sendOpts);
|
|
10318
|
+
} catch {
|
|
10319
|
+
}
|
|
10320
|
+
return;
|
|
10321
|
+
}
|
|
10322
|
+
if (event.message_id && treeResult.clearIssuedBranch) {
|
|
10323
|
+
ctx.cards.clearIssuedTreeBranchCard(event.message_id);
|
|
10324
|
+
}
|
|
10325
|
+
if (treeResult.spec) await deliverPanelSpec(treeResult.spec, `${treeResult.keyPrefix}-${event.event_id}`, true, navGen);
|
|
10326
|
+
return;
|
|
10327
|
+
}
|
|
10328
|
+
}
|
|
9646
10329
|
const verifiedCronStop = issuedCronStopForGuard && issuedCronStopForGuard.chatId === event.chat_id && issuedCronStopForGuard.ownerSession === ctx.getCurrentSessionId() && issuedCronStopForGuard.epoch === ctx.getInputEpoch() ? { jobId: issuedCronStopForGuard.jobId, sessionId: issuedCronStopForGuard.sessionId, ...issuedCronStopForGuard.storeKey ? { storeKey: issuedCronStopForGuard.storeKey } : {} } : void 0;
|
|
9647
10330
|
const cronResult = runCronPanelCommand(effectiveCmd, {
|
|
9648
10331
|
inThread,
|
|
@@ -10387,6 +11070,7 @@ function createInboundPipeline(deps) {
|
|
|
10387
11070
|
panelCards.clearIssuedWorkerCard(id);
|
|
10388
11071
|
panelCards.clearIssuedQuitCard(id);
|
|
10389
11072
|
panelCards.clearIssuedCronStopCard(id);
|
|
11073
|
+
panelCards.clearIssuedTreeBranchCard(id);
|
|
10390
11074
|
}
|
|
10391
11075
|
});
|
|
10392
11076
|
return;
|
|
@@ -10871,8 +11555,8 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
|
10871
11555
|
let drainTimer;
|
|
10872
11556
|
await Promise.race([
|
|
10873
11557
|
Promise.allSettled([...panelActionTasks]).then(() => void 0),
|
|
10874
|
-
new Promise((
|
|
10875
|
-
drainTimer = setTimeout(
|
|
11558
|
+
new Promise((resolve9) => {
|
|
11559
|
+
drainTimer = setTimeout(resolve9, ACTION_RETIRE_DRAIN_MS);
|
|
10876
11560
|
drainTimer.unref?.();
|
|
10877
11561
|
})
|
|
10878
11562
|
]);
|