@cydm/pie 4.14.1 → 4.15.1
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/im-forward/index.js +964 -269
- package/dist/builtin/extensions/memory/index.js +6 -6
- package/dist/builtin/extensions/memory/package.json +1 -2
- package/dist/builtin/extensions/pie-proc/index.js +6 -6
- 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-IQDVL34H.js → chunk-6AYPNTCO.js} +8 -8
- package/dist/chunks/{chunk-SYZR74QO.js → chunk-J6EZ335F.js} +8 -7
- package/dist/chunks/{chunk-X3ZVZB2R.js → chunk-JE53PC46.js} +633 -148
- package/dist/chunks/{chunk-2WLKAMOH.js → chunk-LIA52LJU.js} +3 -3
- package/dist/chunks/{chunk-SAXKBFX3.js → chunk-MTH6QSYD.js} +1 -1
- package/dist/chunks/{chunk-TTSQWGAT.js → chunk-NAMH667S.js} +10 -15
- package/dist/chunks/{chunk-DJ4LO7PQ.js → chunk-VWDCKHCC.js} +1 -1
- package/dist/chunks/{chunk-IM7DLPPY.js → chunk-YKV45EMY.js} +239 -141
- package/dist/chunks/{chunk-OQCKDEEE.js → chunk-ZBIR5YS7.js} +1 -1
- package/dist/chunks/{chunk-TNRZEQD5.js → chunk-ZH6EAKVM.js} +2 -2
- package/dist/chunks/{host-image-fallback-AEKY2LSZ.js → host-image-fallback-GX2KXZXQ.js} +1 -1
- package/dist/chunks/{memory-git-G56IXFWU.js → memory-git-BJMYZHIE.js} +5 -5
- package/dist/chunks/{model-registry-4LM2I6FR.js → model-registry-T6EMM66I.js} +2 -2
- package/dist/chunks/{read-file-understanding-GTNZHAK5.js → read-file-understanding-ZRE5KDG3.js} +5 -5
- package/dist/chunks/{src-3YJ4UVEC.js → src-DLAIQCKP.js} +3 -3
- package/dist/chunks/{src-APNP4M4N.js → src-FWL3LCBK.js} +2 -2
- package/dist/chunks/{src-T6AUO53N.js → src-OP6LFLR6.js} +8 -4
- package/dist/chunks/{src-TNUD7EDH.js → src-XJKZIY3S.js} +11 -1
- package/dist/chunks/{test-stream-EF2DHEHV.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
|
}
|
|
@@ -1165,20 +1165,50 @@ function compileCard(spec) {
|
|
|
1165
1165
|
}
|
|
1166
1166
|
for (const item of items) {
|
|
1167
1167
|
const rowActions = item.actions ?? [];
|
|
1168
|
+
if (rowActions.length >= 2) {
|
|
1169
|
+
elements.push({
|
|
1170
|
+
tag: "column_set",
|
|
1171
|
+
flex_mode: "none",
|
|
1172
|
+
background_style: "grey-50",
|
|
1173
|
+
columns: [
|
|
1174
|
+
{
|
|
1175
|
+
tag: "column",
|
|
1176
|
+
width: "weighted",
|
|
1177
|
+
weight: 1,
|
|
1178
|
+
padding: "8px 10px",
|
|
1179
|
+
vertical_spacing: "small",
|
|
1180
|
+
elements: [
|
|
1181
|
+
{ tag: "markdown", content: item.text },
|
|
1182
|
+
{
|
|
1183
|
+
tag: "column_set",
|
|
1184
|
+
flex_mode: "flow",
|
|
1185
|
+
horizontal_spacing: "small",
|
|
1186
|
+
columns: rowActions.map((action) => ({
|
|
1187
|
+
tag: "column",
|
|
1188
|
+
width: "auto",
|
|
1189
|
+
elements: [buildButton(action, "small")]
|
|
1190
|
+
}))
|
|
1191
|
+
}
|
|
1192
|
+
]
|
|
1193
|
+
}
|
|
1194
|
+
]
|
|
1195
|
+
});
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1168
1198
|
const columns = [
|
|
1169
1199
|
{
|
|
1170
1200
|
tag: "column",
|
|
1171
1201
|
width: "weighted",
|
|
1172
1202
|
weight: 1,
|
|
1173
1203
|
vertical_align: "center",
|
|
1174
|
-
padding: rowActions.length > 0 ? "
|
|
1204
|
+
padding: rowActions.length > 0 ? "8px 0px 8px 10px" : "8px 10px",
|
|
1175
1205
|
elements: [{ tag: "markdown", content: item.text }]
|
|
1176
1206
|
},
|
|
1177
|
-
...rowActions.map((action
|
|
1207
|
+
...rowActions.map((action) => ({
|
|
1178
1208
|
tag: "column",
|
|
1179
1209
|
width: "auto",
|
|
1180
1210
|
vertical_align: "center",
|
|
1181
|
-
padding:
|
|
1211
|
+
padding: "8px 10px 8px 0px",
|
|
1182
1212
|
elements: [buildButton(action, "small")]
|
|
1183
1213
|
}))
|
|
1184
1214
|
];
|
|
@@ -1199,7 +1229,7 @@ function compileCard(spec) {
|
|
|
1199
1229
|
elements.push({
|
|
1200
1230
|
tag: "column_set",
|
|
1201
1231
|
flex_mode: "flow",
|
|
1202
|
-
|
|
1232
|
+
horizontal_spacing: "medium",
|
|
1203
1233
|
columns: row.map((action) => ({
|
|
1204
1234
|
tag: "column",
|
|
1205
1235
|
width: "weighted",
|
|
@@ -1238,8 +1268,15 @@ function parseLarkCliEnvelope(stdout) {
|
|
|
1238
1268
|
if (parsed.ok === true && isRecord(parsed.data)) return { ok: true, data: parsed.data };
|
|
1239
1269
|
if (parsed.code === 0 && isRecord(parsed.data)) return { ok: true, data: parsed.data };
|
|
1240
1270
|
if (parsed.ok === false) {
|
|
1241
|
-
|
|
1242
|
-
|
|
1271
|
+
if (isRecord(parsed.error)) {
|
|
1272
|
+
const code = typeof parsed.error.code === "number" || typeof parsed.error.code === "string" ? String(parsed.error.code) : void 0;
|
|
1273
|
+
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;
|
|
1274
|
+
if (code && msg) return { ok: false, errorText: `lark-cli error code ${code}: ${msg}` };
|
|
1275
|
+
if (msg) return { ok: false, errorText: `lark-cli error: ${msg}` };
|
|
1276
|
+
if (code) return { ok: false, errorText: `lark-cli error code ${code}` };
|
|
1277
|
+
return { ok: false, errorText: `lark-cli error: ${JSON.stringify(parsed.error)}` };
|
|
1278
|
+
}
|
|
1279
|
+
return { ok: false, errorText: "lark-cli error: unknown" };
|
|
1243
1280
|
}
|
|
1244
1281
|
if (typeof parsed.code === "number" && parsed.code !== 0) {
|
|
1245
1282
|
return { ok: false, errorText: `lark-cli error code ${String(parsed.code)}: ${String(parsed.msg ?? "unknown")}` };
|
|
@@ -1274,13 +1311,16 @@ function extractImageKey(content) {
|
|
|
1274
1311
|
var SAFE_FEISHU_CHAT_ID = /^oc_[A-Za-z0-9_-]+$/;
|
|
1275
1312
|
var SAFE_FEISHU_THREAD_ID = /^omt_[A-Za-z0-9_-]+$/;
|
|
1276
1313
|
var SAFE_APPLINK_HOST = /^[a-z0-9.-]+$/i;
|
|
1314
|
+
var FEISHU_THREAD_LATEST_POSITION = "9999999";
|
|
1277
1315
|
function formatFeishuThreadUrl(anchor) {
|
|
1278
1316
|
const rawChat = typeof anchor.chatId === "string" && anchor.chatId ? anchor.chatId : typeof anchor.home === "string" && anchor.home ? anchor.home : "";
|
|
1279
1317
|
const rawThread = typeof anchor.threadId === "string" ? anchor.threadId : "";
|
|
1280
1318
|
if (!SAFE_FEISHU_CHAT_ID.test(rawChat) || !SAFE_FEISHU_THREAD_ID.test(rawThread)) return void 0;
|
|
1281
1319
|
const rawHost = process.env.PIE_FEISHU_APPLINK_HOST?.trim() || "applink.feishu.cn";
|
|
1282
1320
|
const host = SAFE_APPLINK_HOST.test(rawHost) ? rawHost : "applink.feishu.cn";
|
|
1283
|
-
|
|
1321
|
+
const encodedChat = encodeURIComponent(rawChat);
|
|
1322
|
+
const encodedThread = encodeURIComponent(rawThread);
|
|
1323
|
+
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
1324
|
}
|
|
1285
1325
|
|
|
1286
1326
|
// builtin/extensions/im-forward/providers/feishu/setup.ts
|
|
@@ -1303,7 +1343,7 @@ async function openBrowser(url, signal, seam = {}) {
|
|
|
1303
1343
|
if (signal.aborted || !/^https:\/\/[^\s\x00-\x1f\x7f]+$/.test(url)) return "failed";
|
|
1304
1344
|
const spec = browserLaunch(seam.platform);
|
|
1305
1345
|
if (!spec) return "failed";
|
|
1306
|
-
return new Promise((
|
|
1346
|
+
return new Promise((resolve9) => {
|
|
1307
1347
|
let child;
|
|
1308
1348
|
let settled = false;
|
|
1309
1349
|
let stopping = false;
|
|
@@ -1318,7 +1358,7 @@ async function openBrowser(url, signal, seam = {}) {
|
|
|
1318
1358
|
child?.stdin?.destroy();
|
|
1319
1359
|
child?.stdout?.destroy();
|
|
1320
1360
|
child?.stderr?.destroy();
|
|
1321
|
-
|
|
1361
|
+
resolve9(result);
|
|
1322
1362
|
};
|
|
1323
1363
|
const stop = () => {
|
|
1324
1364
|
if (settled || stopping) return;
|
|
@@ -1963,7 +2003,7 @@ function normalizeMenuEvent(line, fallbackChatId) {
|
|
|
1963
2003
|
};
|
|
1964
2004
|
}
|
|
1965
2005
|
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;
|
|
2006
|
+
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
2007
|
function isPermanentFeishuPatchError(reason) {
|
|
1968
2008
|
return Boolean(reason && PERMANENT_PATCH_ERROR_PATTERN.test(reason));
|
|
1969
2009
|
}
|
|
@@ -1973,20 +2013,19 @@ function sanitizePatchError(raw) {
|
|
|
1973
2013
|
}
|
|
1974
2014
|
function sleepAbortable(ms, signal) {
|
|
1975
2015
|
if (signal.aborted) return Promise.resolve(false);
|
|
1976
|
-
return new Promise((
|
|
2016
|
+
return new Promise((resolve9) => {
|
|
1977
2017
|
const onAbort = () => {
|
|
1978
2018
|
clearTimeout(timer);
|
|
1979
|
-
|
|
2019
|
+
resolve9(false);
|
|
1980
2020
|
};
|
|
1981
2021
|
const timer = setTimeout(() => {
|
|
1982
2022
|
signal.removeEventListener("abort", onAbort);
|
|
1983
|
-
|
|
2023
|
+
resolve9(true);
|
|
1984
2024
|
}, ms);
|
|
1985
|
-
timer.unref?.();
|
|
1986
2025
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
1987
2026
|
});
|
|
1988
2027
|
}
|
|
1989
|
-
function connect(binary, profile, targetKind = "chat", settings = { targetId: "" }) {
|
|
2028
|
+
function connect(binary, profile, targetKind = "chat", settings = { targetId: "" }, connectCwd) {
|
|
1990
2029
|
const lifetime = new AbortController();
|
|
1991
2030
|
const active = /* @__PURE__ */ new Set();
|
|
1992
2031
|
const native = (...args) => {
|
|
@@ -1995,18 +2034,20 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
1995
2034
|
void pending.finally(() => active.delete(pending));
|
|
1996
2035
|
return pending;
|
|
1997
2036
|
};
|
|
1998
|
-
const callDetailed = async (args) => {
|
|
1999
|
-
const result = await native(binary, profile ? [...args, "--profile", profile] : args, 3e4,
|
|
2037
|
+
const callDetailed = async (args, callCwd) => {
|
|
2038
|
+
const result = await native(binary, profile ? [...args, "--profile", profile] : args, 3e4, callCwd, { signal: lifetime.signal });
|
|
2000
2039
|
if (result.error) {
|
|
2001
|
-
const
|
|
2040
|
+
const rawEnvelope = result.stdout.trim() || result.stderr?.trim() || "";
|
|
2041
|
+
const env2 = rawEnvelope ? parseLarkCliEnvelope(rawEnvelope) : void 0;
|
|
2042
|
+
if (env2?.ok === false && env2.errorText) return { ok: false, error: env2.errorText };
|
|
2002
2043
|
return { ok: false, error: env2?.errorText ? `${result.error} (${env2.errorText})` : result.error };
|
|
2003
2044
|
}
|
|
2004
2045
|
const env = parseLarkCliEnvelope(result.stdout);
|
|
2005
2046
|
if (env.ok && env.data) return { ok: true, data: env.data };
|
|
2006
2047
|
return { ok: false, error: env.errorText ?? "empty lark-cli response" };
|
|
2007
2048
|
};
|
|
2008
|
-
const call = async (args) => {
|
|
2009
|
-
const res = await callDetailed(args);
|
|
2049
|
+
const call = async (args, callCwd) => {
|
|
2050
|
+
const res = await callDetailed(args, callCwd);
|
|
2010
2051
|
return res.ok ? res.data : void 0;
|
|
2011
2052
|
};
|
|
2012
2053
|
const lastPatchErrors = /* @__PURE__ */ new Map();
|
|
@@ -2020,22 +2061,42 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2020
2061
|
};
|
|
2021
2062
|
let canonicalAppIdCache = null;
|
|
2022
2063
|
let canonicalResolved = false;
|
|
2064
|
+
let defaultBusAppIdCache = null;
|
|
2065
|
+
let defaultBusAppIdResolved = false;
|
|
2023
2066
|
const BUS_RECONNECT_GRACE_MS = 10 * 60 * 1e3;
|
|
2067
|
+
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
2068
|
async function canonicalAppIdNow() {
|
|
2025
2069
|
if (canonicalResolved) return canonicalAppIdCache || void 0;
|
|
2026
2070
|
if (!profile) {
|
|
2071
|
+
canonicalAppIdCache = configuredAppId ?? null;
|
|
2027
2072
|
canonicalResolved = true;
|
|
2028
|
-
return
|
|
2073
|
+
return configuredAppId;
|
|
2029
2074
|
}
|
|
2030
2075
|
try {
|
|
2031
2076
|
const result = await native(binary, ["profile", "list"], 1e4, void 0, { signal: lifetime.signal });
|
|
2032
2077
|
const profiles = result.error ? null : parseProfiles(result.stdout);
|
|
2033
|
-
if (!profiles) return
|
|
2078
|
+
if (!profiles) return configuredAppId;
|
|
2034
2079
|
const appId = profiles.find((item) => item.name === profile)?.appId;
|
|
2035
|
-
if (!appId) return
|
|
2080
|
+
if (!appId) return configuredAppId;
|
|
2036
2081
|
canonicalAppIdCache = appId;
|
|
2037
2082
|
canonicalResolved = true;
|
|
2038
2083
|
return appId;
|
|
2084
|
+
} catch {
|
|
2085
|
+
return configuredAppId;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
async function resolveBusHealthAppId() {
|
|
2089
|
+
const known = await canonicalAppIdNow();
|
|
2090
|
+
if (known) return known;
|
|
2091
|
+
if (defaultBusAppIdResolved) return defaultBusAppIdCache || void 0;
|
|
2092
|
+
try {
|
|
2093
|
+
const result = await native(binary, ["profile", "list"], 1e4, void 0, { signal: lifetime.signal });
|
|
2094
|
+
const profiles = result.error ? null : parseProfiles(result.stdout);
|
|
2095
|
+
if (!profiles) return void 0;
|
|
2096
|
+
const appId = (profiles.find((item) => item.active) ?? (profiles.length === 1 ? profiles[0] : void 0))?.appId;
|
|
2097
|
+
defaultBusAppIdCache = appId ?? null;
|
|
2098
|
+
defaultBusAppIdResolved = true;
|
|
2099
|
+
return appId;
|
|
2039
2100
|
} catch {
|
|
2040
2101
|
return void 0;
|
|
2041
2102
|
}
|
|
@@ -2060,8 +2121,19 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2060
2121
|
async sendFile(target, file, key, replyTo, options) {
|
|
2061
2122
|
const recipient = targetKind === "user" ? ["--user-id", target] : ["--chat-id", target];
|
|
2062
2123
|
const boundedKey = boundIdempotencyKey(key);
|
|
2124
|
+
const isRemoteOrKey = /^file_[A-Za-z0-9_-]+$/.test(file) || /^https?:\/\//i.test(file);
|
|
2125
|
+
let fileArg = file;
|
|
2126
|
+
let fileCwd = connectCwd;
|
|
2127
|
+
if (!isRemoteOrKey) {
|
|
2128
|
+
const resolvedFile = path7.resolve(connectCwd ?? process.cwd(), file);
|
|
2129
|
+
fileCwd = path7.dirname(resolvedFile);
|
|
2130
|
+
fileArg = path7.basename(resolvedFile);
|
|
2131
|
+
}
|
|
2063
2132
|
const threadFlag = options?.replyInThread ? ["--reply-in-thread"] : [];
|
|
2064
|
-
const data = await call(
|
|
2133
|
+
const data = await call(
|
|
2134
|
+
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],
|
|
2135
|
+
fileCwd
|
|
2136
|
+
);
|
|
2065
2137
|
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
2138
|
},
|
|
2067
2139
|
// 4.3.10 panel cards: compile the neutral CardSpec and send it as an
|
|
@@ -2125,18 +2197,22 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2125
2197
|
},
|
|
2126
2198
|
async resolveUserName(userId, signal) {
|
|
2127
2199
|
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
2200
|
const combined = signal ? AbortSignal.any([lifetime.signal, signal]) : lifetime.signal;
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
if (
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2201
|
+
const lookupAs = async (identity) => {
|
|
2202
|
+
if (combined.aborted) return void 0;
|
|
2203
|
+
const baseArgs = ["contact", "+get-user", "--user-id", userId, "--as", identity];
|
|
2204
|
+
const args = profile ? [...baseArgs, "--profile", profile] : baseArgs;
|
|
2205
|
+
const result = await native(binary, args, 1e4, void 0, { signal: combined });
|
|
2206
|
+
if (combined.aborted || result.error || !result.stdout.trim()) return void 0;
|
|
2207
|
+
try {
|
|
2208
|
+
const parsed = JSON.parse(result.stdout);
|
|
2209
|
+
if (typeof parsed?.data?.user?.name === "string" && parsed.data.user.name.trim()) return parsed.data.user.name.trim();
|
|
2210
|
+
if (typeof parsed?.name === "string" && parsed.name.trim()) return parsed.name.trim();
|
|
2211
|
+
} catch {
|
|
2212
|
+
}
|
|
2213
|
+
return void 0;
|
|
2214
|
+
};
|
|
2215
|
+
return await lookupAs("bot") ?? await lookupAs("user");
|
|
2140
2216
|
},
|
|
2141
2217
|
async metadata(id) {
|
|
2142
2218
|
const data = await call(["im", "+messages-mget", "--as", "bot", "--message-ids", id]);
|
|
@@ -2390,7 +2466,7 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
|
|
|
2390
2466
|
// = undefined (no signal, not an alarm) — escalate only on a POSITIVE
|
|
2391
2467
|
// stale reading.
|
|
2392
2468
|
async consumeBusHealth() {
|
|
2393
|
-
const appId = await
|
|
2469
|
+
const appId = await resolveBusHealthAppId();
|
|
2394
2470
|
if (!appId) return void 0;
|
|
2395
2471
|
const larkHome = process.env.PIE_LARK_CLI_HOME && process.env.PIE_LARK_CLI_HOME.trim() ? process.env.PIE_LARK_CLI_HOME : os3.homedir();
|
|
2396
2472
|
const logPath = path7.join(larkHome, ".lark-cli", "events", appId, "bus.log");
|
|
@@ -2446,14 +2522,14 @@ var FEISHU_REACTION_MAP = {
|
|
|
2446
2522
|
async function probeCardActionSubscription(ui, cwd, binaryOverride, profile) {
|
|
2447
2523
|
const spec = resolveLaunchSpec(binaryOverride, cwd);
|
|
2448
2524
|
if (!spec) return;
|
|
2449
|
-
await new Promise((
|
|
2525
|
+
await new Promise((resolve9) => {
|
|
2450
2526
|
let settled = false;
|
|
2451
2527
|
let timer;
|
|
2452
2528
|
const done = () => {
|
|
2453
2529
|
if (settled) return;
|
|
2454
2530
|
settled = true;
|
|
2455
2531
|
if (timer) clearTimeout(timer);
|
|
2456
|
-
|
|
2532
|
+
resolve9();
|
|
2457
2533
|
};
|
|
2458
2534
|
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
2535
|
timer = setTimeout(() => {
|
|
@@ -2501,7 +2577,7 @@ var feishuProvider = {
|
|
|
2501
2577
|
connect(settings, cwd) {
|
|
2502
2578
|
const binary = resolveLaunchSpec(typeof settings.larkCli === "string" ? settings.larkCli : void 0, cwd);
|
|
2503
2579
|
const profile = typeof settings.larkCliProfile === "string" && settings.larkCliProfile.trim() ? settings.larkCliProfile.trim() : void 0;
|
|
2504
|
-
return binary ? connect(binary, profile, settings.targetKind, settings) : null;
|
|
2580
|
+
return binary ? connect(binary, profile, settings.targetKind, settings, cwd) : null;
|
|
2505
2581
|
},
|
|
2506
2582
|
setup: setupFeishu,
|
|
2507
2583
|
formatThreadUrl: formatFeishuThreadUrl,
|
|
@@ -3228,20 +3304,22 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`;
|
|
|
3228
3304
|
const ack = JSON.parse(receipt.detail.slice(ackStart));
|
|
3229
3305
|
if (ack.ok !== true || typeof ack.message !== "string") return fallback;
|
|
3230
3306
|
const r = JSON.parse(ack.message);
|
|
3231
|
-
const safeOutcome = typeof r.lastCompactOutcome === "string" && r.lastCompactOutcome ? sanitizeLiteralMarkdown(r.lastCompactOutcome)
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3307
|
+
const safeOutcome = typeof r.lastCompactOutcome === "string" && r.lastCompactOutcome ? sanitizeLiteralMarkdown(r.lastCompactOutcome) : void 0;
|
|
3308
|
+
const est = typeof r.estimatedTokens === "number" ? r.estimatedTokens.toLocaleString() : "?";
|
|
3309
|
+
const win = r.contextWindow ? r.contextWindow.toLocaleString() : "unknown";
|
|
3310
|
+
const usage = typeof r.percent === "number" ? `${r.percent}%` : "unknown";
|
|
3311
|
+
const autoCompact = r.autoCompactEnabled ? `at ${(r.autoCompactLimitTokens ?? 0).toLocaleString()} tokens` : "off";
|
|
3312
|
+
const stateText = r.compactionRunning ? "compacting" : r.isStreaming ? "working" : "idle";
|
|
3313
|
+
return [
|
|
3314
|
+
`\u{1F4CA} **Context estimate** \xB7 ${safePeer}`,
|
|
3315
|
+
"",
|
|
3316
|
+
`- **Estimated tokens**\uFF1A${est} / ${win}\uFF08**${usage}**\uFF09`,
|
|
3317
|
+
`- **State**\uFF1A${stateText} \xB7 **Queued inputs**\uFF1A${r.pendingQueuedInputs ?? 0}`,
|
|
3318
|
+
`- **Auto-compact**\uFF1A${autoCompact}`,
|
|
3319
|
+
...safeOutcome ? [`- **Last compact**\uFF1A${safeOutcome}`] : [],
|
|
3320
|
+
"",
|
|
3321
|
+
"_Estimate (bytes/4 heuristic) \u2014 same basis as the TUI's /debugs/context report._"
|
|
3322
|
+
].join("\n");
|
|
3245
3323
|
} catch {
|
|
3246
3324
|
return fallback;
|
|
3247
3325
|
}
|
|
@@ -3294,7 +3372,7 @@ function createConsumerLifecycle(ctx) {
|
|
|
3294
3372
|
}
|
|
3295
3373
|
function stopGeneration(gen) {
|
|
3296
3374
|
if (gen.startup) clearTimeout(gen.startup);
|
|
3297
|
-
return gen.stopping ??= new Promise((
|
|
3375
|
+
return gen.stopping ??= new Promise((resolve9) => {
|
|
3298
3376
|
let settled = false;
|
|
3299
3377
|
const finishWait = (failed) => {
|
|
3300
3378
|
if (settled) return;
|
|
@@ -3305,7 +3383,7 @@ function createConsumerLifecycle(ctx) {
|
|
|
3305
3383
|
ctx.log(`im-forward: ${ctx.provider} consumer stop failed`);
|
|
3306
3384
|
}
|
|
3307
3385
|
gen.retired = true;
|
|
3308
|
-
|
|
3386
|
+
resolve9();
|
|
3309
3387
|
};
|
|
3310
3388
|
const timer = setTimeout(() => finishWait(true), STOP_GENERATION_TIMEOUT_MS);
|
|
3311
3389
|
timer.unref?.();
|
|
@@ -3345,8 +3423,8 @@ function createConsumerLifecycle(ctx) {
|
|
|
3345
3423
|
async function stopGenerationWithRetry(gen) {
|
|
3346
3424
|
await stopGeneration(gen);
|
|
3347
3425
|
if (!gen.stopFailed || !gen.handle || ctx.isTerminated()) return;
|
|
3348
|
-
await new Promise((
|
|
3349
|
-
const t = setTimeout(
|
|
3426
|
+
await new Promise((resolve9) => {
|
|
3427
|
+
const t = setTimeout(resolve9, 300);
|
|
3350
3428
|
t.unref?.();
|
|
3351
3429
|
});
|
|
3352
3430
|
if (ctx.isTerminated()) return;
|
|
@@ -4404,9 +4482,9 @@ function sessionRootOwner(provider, messageId) {
|
|
|
4404
4482
|
// builtin/extensions/im-forward/runtime-outbound.ts
|
|
4405
4483
|
import * as crypto from "node:crypto";
|
|
4406
4484
|
import * as fs11 from "node:fs";
|
|
4407
|
-
import { basename } from "node:path";
|
|
4485
|
+
import { basename as basename2 } from "node:path";
|
|
4408
4486
|
var CHUNK_RETRY_DELAY_MS = 2e3;
|
|
4409
|
-
var delay = (ms) => new Promise((
|
|
4487
|
+
var delay = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
4410
4488
|
var IM_INPUT_FALLBACK_CAPTION = "Please review these images and respond.";
|
|
4411
4489
|
function createOutboundRuntime(deps) {
|
|
4412
4490
|
const { ctx, cfg, connection, isManager, routeState, isForwardingEnabled, isTerminated, getCurrentSessionId, getInputEpoch, handleInboundEvent } = deps;
|
|
@@ -4629,8 +4707,8 @@ ${recoveryHint}`,
|
|
|
4629
4707
|
};
|
|
4630
4708
|
const claimStake = () => {
|
|
4631
4709
|
let release;
|
|
4632
|
-
const token = new Promise((
|
|
4633
|
-
release =
|
|
4710
|
+
const token = new Promise((resolve9) => {
|
|
4711
|
+
release = resolve9;
|
|
4634
4712
|
});
|
|
4635
4713
|
token.release = release;
|
|
4636
4714
|
routeState.setStakeFlight(sessionId, token);
|
|
@@ -4836,7 +4914,7 @@ ${recoveryHint}`,
|
|
|
4836
4914
|
ctx.log(`im-forward: attached ${file}`);
|
|
4837
4915
|
} else if (!isTerminated() && isForwardingEnabled()) {
|
|
4838
4916
|
ctx.log(`im-forward: attachment upload failed: ${file}`);
|
|
4839
|
-
failedFiles.push(
|
|
4917
|
+
failedFiles.push(basename2(file));
|
|
4840
4918
|
}
|
|
4841
4919
|
}
|
|
4842
4920
|
if (failedFiles.length > 0 && !isTerminated() && isForwardingEnabled()) {
|
|
@@ -4918,7 +4996,7 @@ function evaluateDirectImCmdAuth(ctx, event) {
|
|
|
4918
4996
|
function formatDirectImCmdAuthRefusal(reason, senderId) {
|
|
4919
4997
|
const idSpan = senderId ? `\`${cleanCodeSpan(senderId, 64)}\`` : void 0;
|
|
4920
4998
|
if (reason === "group-requires-allowUsers") {
|
|
4921
|
-
return idSpan ? `\u26D4\uFE0F Running \`!!\` shell commands in a group chat requires \`allowUsers\` configuration. Add ${idSpan} via
|
|
4999
|
+
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
5000
|
}
|
|
4923
5001
|
if (reason === "panelAccess-allowUsers-unconfigured") {
|
|
4924
5002
|
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 +5070,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
4992
5070
|
}
|
|
4993
5071
|
const timeoutMs = opts.timeoutMs ?? DIRECT_IM_CMD_TIMEOUT_MS;
|
|
4994
5072
|
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((
|
|
5073
|
+
return new Promise((resolve9) => {
|
|
4996
5074
|
let head = "";
|
|
4997
5075
|
let tail = "";
|
|
4998
5076
|
let totalBytes = 0;
|
|
@@ -5024,7 +5102,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
5024
5102
|
detached: platform !== "win32"
|
|
5025
5103
|
});
|
|
5026
5104
|
} catch (error) {
|
|
5027
|
-
|
|
5105
|
+
resolve9({
|
|
5028
5106
|
ok: false,
|
|
5029
5107
|
exitCode: null,
|
|
5030
5108
|
timedOut: false,
|
|
@@ -5064,7 +5142,7 @@ async function executeDirectImCommand(command, opts) {
|
|
|
5064
5142
|
\u2026 (middle output omitted) \u2026
|
|
5065
5143
|
${tail}` : head;
|
|
5066
5144
|
const bounded = boundCommandOutput(raw);
|
|
5067
|
-
|
|
5145
|
+
resolve9({
|
|
5068
5146
|
ok: !timedOut && exitCode === 0,
|
|
5069
5147
|
exitCode,
|
|
5070
5148
|
timedOut,
|
|
@@ -5085,10 +5163,8 @@ ${tail}` : head;
|
|
|
5085
5163
|
return;
|
|
5086
5164
|
}
|
|
5087
5165
|
closeTimer = setTimeout(() => finish(null), 1e3);
|
|
5088
|
-
closeTimer.unref?.();
|
|
5089
5166
|
});
|
|
5090
5167
|
}, killGraceMs);
|
|
5091
|
-
killTimer.unref?.();
|
|
5092
5168
|
};
|
|
5093
5169
|
const onAbort = () => terminateTree();
|
|
5094
5170
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -5232,7 +5308,7 @@ var SYNTHETIC_SENDER = (() => {
|
|
|
5232
5308
|
return `pie-${hex.slice(0, 12)}`;
|
|
5233
5309
|
})();
|
|
5234
5310
|
function deliverOnce(port, secret, text, targetSessionId, targetInstanceId) {
|
|
5235
|
-
return new Promise((
|
|
5311
|
+
return new Promise((resolve9) => {
|
|
5236
5312
|
const id = randomUUID4();
|
|
5237
5313
|
const envelope = {
|
|
5238
5314
|
v: IPC_PROTOCOL_VERSION,
|
|
@@ -5260,7 +5336,7 @@ function deliverOnce(port, secret, text, targetSessionId, targetInstanceId) {
|
|
|
5260
5336
|
settled = true;
|
|
5261
5337
|
clearTimeout(timer);
|
|
5262
5338
|
socket.destroy();
|
|
5263
|
-
|
|
5339
|
+
resolve9(ok);
|
|
5264
5340
|
};
|
|
5265
5341
|
const timer = setTimeout(() => finish(false), 5e3);
|
|
5266
5342
|
socket.once("error", () => finish(false));
|
|
@@ -5329,9 +5405,9 @@ function createAutoWakeCoordinator(ctx) {
|
|
|
5329
5405
|
const noticeCooldownUntil = /* @__PURE__ */ new Map();
|
|
5330
5406
|
const sleepCancelers = /* @__PURE__ */ new Set();
|
|
5331
5407
|
let disposed = false;
|
|
5332
|
-
const sleep = (ms) => new Promise((
|
|
5408
|
+
const sleep = (ms) => new Promise((resolve9) => {
|
|
5333
5409
|
if (disposed || !ctx.isActive()) {
|
|
5334
|
-
|
|
5410
|
+
resolve9();
|
|
5335
5411
|
return;
|
|
5336
5412
|
}
|
|
5337
5413
|
let settled = false;
|
|
@@ -5339,7 +5415,7 @@ function createAutoWakeCoordinator(ctx) {
|
|
|
5339
5415
|
if (settled) return;
|
|
5340
5416
|
settled = true;
|
|
5341
5417
|
sleepCancelers.delete(cancel);
|
|
5342
|
-
|
|
5418
|
+
resolve9();
|
|
5343
5419
|
};
|
|
5344
5420
|
const timer = setTimeout(done, ms);
|
|
5345
5421
|
timer.unref?.();
|
|
@@ -5640,9 +5716,9 @@ function scriptEnv(req, launchId) {
|
|
|
5640
5716
|
return env;
|
|
5641
5717
|
}
|
|
5642
5718
|
function execFileText(file, args) {
|
|
5643
|
-
return new Promise((
|
|
5719
|
+
return new Promise((resolve9) => {
|
|
5644
5720
|
execFile(file, args, { encoding: "utf8", timeout: 1500, maxBuffer: 512 * 1024, windowsHide: true }, (error, stdout) => {
|
|
5645
|
-
|
|
5721
|
+
resolve9(error ? void 0 : stdout);
|
|
5646
5722
|
});
|
|
5647
5723
|
});
|
|
5648
5724
|
}
|
|
@@ -5745,10 +5821,10 @@ async function executeAction(req) {
|
|
|
5745
5821
|
"=".repeat(60)
|
|
5746
5822
|
].filter((line) => line !== void 0).join("\n") + "\n");
|
|
5747
5823
|
const launchId = randomBytes(24).toString("hex");
|
|
5748
|
-
const exitCode = await new Promise((
|
|
5824
|
+
const exitCode = await new Promise((resolve9) => {
|
|
5749
5825
|
if (req.signal?.aborted) {
|
|
5750
5826
|
cancelled = true;
|
|
5751
|
-
|
|
5827
|
+
resolve9(null);
|
|
5752
5828
|
return;
|
|
5753
5829
|
}
|
|
5754
5830
|
const { command, prefix } = interpreterFor(script);
|
|
@@ -5765,7 +5841,7 @@ async function executeAction(req) {
|
|
|
5765
5841
|
} catch (error) {
|
|
5766
5842
|
logWrite(`[spawn error] ${error instanceof Error ? error.message : String(error)}
|
|
5767
5843
|
`);
|
|
5768
|
-
|
|
5844
|
+
resolve9(null);
|
|
5769
5845
|
return;
|
|
5770
5846
|
}
|
|
5771
5847
|
if (typeof child.pid === "number") {
|
|
@@ -5837,7 +5913,7 @@ async function executeAction(req) {
|
|
|
5837
5913
|
}
|
|
5838
5914
|
} catch {
|
|
5839
5915
|
}
|
|
5840
|
-
|
|
5916
|
+
resolve9(code);
|
|
5841
5917
|
};
|
|
5842
5918
|
const scheduleGroupProbe = (delayMs, probe) => {
|
|
5843
5919
|
if (settled) return;
|
|
@@ -6257,23 +6333,23 @@ async function fenceChild(childPid, marker) {
|
|
|
6257
6333
|
const cmd = readProcessCommandLine(childPid);
|
|
6258
6334
|
if (cmd === void 0 || !cmd.includes(marker)) return "unknown";
|
|
6259
6335
|
if (process.platform === "win32") {
|
|
6260
|
-
return await new Promise((
|
|
6336
|
+
return await new Promise((resolve9) => {
|
|
6261
6337
|
let killer;
|
|
6262
6338
|
try {
|
|
6263
6339
|
killer = spawn7("taskkill", ["/T", "/F", "/PID", String(childPid)], { stdio: "ignore", windowsHide: true });
|
|
6264
6340
|
} catch {
|
|
6265
|
-
|
|
6341
|
+
resolve9("unknown");
|
|
6266
6342
|
return;
|
|
6267
6343
|
}
|
|
6268
|
-
killer.on("error", () =>
|
|
6344
|
+
killer.on("error", () => resolve9("unknown"));
|
|
6269
6345
|
const deadline = Date.now() + 5e3;
|
|
6270
6346
|
const poll = () => {
|
|
6271
6347
|
if (!pidAlive5(childPid)) {
|
|
6272
|
-
|
|
6348
|
+
resolve9("fenced");
|
|
6273
6349
|
return;
|
|
6274
6350
|
}
|
|
6275
6351
|
if (Date.now() >= deadline) {
|
|
6276
|
-
|
|
6352
|
+
resolve9("unknown");
|
|
6277
6353
|
return;
|
|
6278
6354
|
}
|
|
6279
6355
|
setTimeout(poll, 100).unref?.();
|
|
@@ -6483,10 +6559,6 @@ function workerDisplayTitle(peer) {
|
|
|
6483
6559
|
if (peer.isManager) return "manager";
|
|
6484
6560
|
return peer.name;
|
|
6485
6561
|
}
|
|
6486
|
-
function sanitizeTableCell(text, max = 64) {
|
|
6487
|
-
const cleaned = sanitizeLiteralMarkdown(text).replace(/\|/g, "\uFF5C");
|
|
6488
|
-
return cleaned.length <= max ? cleaned : `${cleaned.slice(0, max - 1)}\u2026`;
|
|
6489
|
-
}
|
|
6490
6562
|
function cleanInline(text, max = 48) {
|
|
6491
6563
|
const cleaned = sanitizeLiteralMarkdown(text);
|
|
6492
6564
|
return cleaned.length <= max ? cleaned : `${cleaned.slice(0, max - 1)}\u2026`;
|
|
@@ -6598,7 +6670,8 @@ function composeWorkerCard(peer, opts = {}) {
|
|
|
6598
6670
|
{ id: `panel.worker.models.${peer.instanceId}`, label: "\u{1F39A} Model" },
|
|
6599
6671
|
...peer.sessionControls ? [
|
|
6600
6672
|
{ id: `panel.context.${peer.instanceId}`, label: "\u{1F4CA} Context", payload: fromWorker },
|
|
6601
|
-
{ id: `panel.compact.${peer.instanceId}`, label: "\u{1F9F9} Compact", payload: fromWorker }
|
|
6673
|
+
{ id: `panel.compact.${peer.instanceId}`, label: "\u{1F9F9} Compact", payload: fromWorker },
|
|
6674
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F333} Tree", payload: fromWorker }
|
|
6602
6675
|
] : [],
|
|
6603
6676
|
{ id: `panel.worker.cron.${peer.instanceId}`, label: workerCron > 0 ? `\u23F0 Cron (${workerCron})` : "\u23F0 Cron" },
|
|
6604
6677
|
{ id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: fromWorker },
|
|
@@ -6622,20 +6695,19 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline(a.lastRunBy ?? "\u2014", 24)}`,
|
|
|
6622
6695
|
}));
|
|
6623
6696
|
const footer = wActions.length > maxCustom ? `\u66F4\u591A\u52A8\u4F5C\u53EF\u590D\u5236\u89E6\u53D1\uFF1A${wActions.slice(maxCustom).map((a) => `\`/card panel.action.${cleanCodeSpan(a.id, 32)} ${cleanCodeSpan(JSON.stringify({ worker: { ref: peer.instanceId } }), 80)}\``).join(" \xB7 ")}` : wActions.length === 0 ? "\u6682\u65E0\u81EA\u5B9A\u4E49 Worker \u52A8\u4F5C\uFF08\u914D\u7F6E scope=worker \u7684\u52A8\u4F5C\u4F1A\u663E\u793A\u5728\u8FD9\u91CC\uFF09\u3002" : "\u4E0A\u65B9\u884C\u5185\u6309\u94AE\u5E26\u5F53\u524D Worker \u4E0A\u4E0B\u6587\u6267\u884C\uFF08zero LLM\uFF09\u3002";
|
|
6624
6697
|
const threadUrl = resolveSessionThreadUrl(peer.sessionId);
|
|
6698
|
+
const infoLines = [
|
|
6699
|
+
`- **name**\uFF1A${cleanInline(peer.name, 48)} \xB7 **state**\uFF1A${cleanInline(state, 48)}`,
|
|
6700
|
+
`- **model**\uFF1A\`${cleanCodeSpan(modelDisplay, 56)}\``,
|
|
6701
|
+
`- **host**\uFF1A${cleanInline(managedLabel, 48)} \xB7 **version**\uFF1A${cleanInline(peer.version ?? "\u2014", 24)}`,
|
|
6702
|
+
...peer.cwd ? [`- **cwd**\uFF1A\`${cleanCodeSpan(peer.cwd, 96)}\``] : [],
|
|
6703
|
+
...threadUrl ? [`- **thread**\uFF1A[\u{1F4AC} \u6253\u5F00\u8BDD\u9898 \u2197](${threadUrl})`] : []
|
|
6704
|
+
];
|
|
6625
6705
|
return {
|
|
6626
6706
|
title: `\u{1F527} ${title}`,
|
|
6627
6707
|
subtitle: `${peer.project ?? "\u2014"} \xB7 ${modelDisplay} \xB7 ${state}`,
|
|
6628
6708
|
color: peer.state === "working" ? "blue" : "green",
|
|
6629
6709
|
columnsPerRow: opts.inThread ? 2 : 3,
|
|
6630
|
-
body:
|
|
6631
|
-
|---|---|
|
|
6632
|
-
| name | ${sanitizeTableCell(peer.name, 48)} |
|
|
6633
|
-
| state | ${sanitizeTableCell(state, 48)} |
|
|
6634
|
-
| model | \`${cleanCodeSpan(modelDisplay, 56)}\` |
|
|
6635
|
-
| host | ${sanitizeTableCell(managedLabel, 48)} |
|
|
6636
|
-
| version | ${sanitizeTableCell(peer.version ?? "\u2014", 24)} |${peer.cwd ? `
|
|
6637
|
-
| cwd | \`${cleanCodeSpan(peer.cwd, 96)}\` |` : ""}${threadUrl ? `
|
|
6638
|
-
| thread | [\u{1F4AC} \u6253\u5F00\u8BDD\u9898 \u2197](${threadUrl}) |` : ""}`,
|
|
6710
|
+
body: infoLines.join("\n"),
|
|
6639
6711
|
...items.length > 0 ? { items } : {},
|
|
6640
6712
|
footer,
|
|
6641
6713
|
actions: [
|
|
@@ -6815,12 +6887,9 @@ function composeWorkerQuitConfirmCard(peer, opts = {}) {
|
|
|
6815
6887
|
color: "red",
|
|
6816
6888
|
columnsPerRow: opts.inThread ? 2 : 3,
|
|
6817
6889
|
body: [
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
| session | \`${cleanCodeSpan(peer.sessionId, 64)}\` |
|
|
6822
|
-
| state | ${sanitizeTableCell(state, 48)} |${peer.cwd ? `
|
|
6823
|
-
| cwd | \`${cleanCodeSpan(peer.cwd, 96)}\` |` : ""}`,
|
|
6890
|
+
`- **name**\uFF1A${cleanInline(peer.name, 48)} \xB7 **state**\uFF1A${cleanInline(state, 48)}`,
|
|
6891
|
+
`- **session**\uFF1A\`${cleanCodeSpan(peer.sessionId, 64)}\``,
|
|
6892
|
+
...peer.cwd ? [`- **cwd**\uFF1A\`${cleanCodeSpan(peer.cwd, 96)}\``] : [],
|
|
6824
6893
|
``,
|
|
6825
6894
|
peer.state === "working" ? "\u26A0\uFE0F \u8BE5 worker \u5F53\u524D\u6B63\u5728\u6267\u884C\u56DE\u5408\uFF1B\u4F18\u96C5\u9000\u51FA\u4F1A\u5148\u4E2D\u65AD\u5F53\u524D\u56DE\u5408\u3001\u843D\u76D8\u5E76\u91CA\u653E\u9501\u3002" : "\u4F18\u96C5\u9000\u51FA\u4F1A\u901A\u77E5\u8BE5 worker \u843D\u76D8\u3001\u91CA\u653E IPC \u9501\u5E76\u5E72\u51C0\u9000\u51FA\uFF08\u4F1A\u8BDD\u8BB0\u5F55\u4FDD\u7559\uFF0C\u53EF\u968F\u65F6 Resume\uFF09\u3002"
|
|
6826
6895
|
].join("\n"),
|
|
@@ -6839,11 +6908,12 @@ function composeOfflineWorkerCard(sessionId, opts = {}) {
|
|
|
6839
6908
|
sessionId ? `\u8BE5 thread \u5173\u8054\u7684 worker \u4F1A\u8BDD \`${cleanCodeSpan(sessionId, 64)}\` \u5F53\u524D\u4E0D\u5728\u7EBF\uFF08\u53EF\u80FD\u5DF2\u9000\u51FA\u6216\u88AB TTL \u56DE\u6536\uFF09\u3002` : "\u8BE5 session \u5F53\u524D\u4E0D\u5728\u7EBF\uFF08\u53EF\u80FD\u5DF2\u9000\u51FA\u6216\u88AB TTL \u56DE\u6536\uFF09\u3002"
|
|
6840
6909
|
];
|
|
6841
6910
|
if (resumable) {
|
|
6842
|
-
lines.push(
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6911
|
+
lines.push(
|
|
6912
|
+
"",
|
|
6913
|
+
`- **name**\uFF1A${cleanInline(resumable.name, 48)}`,
|
|
6914
|
+
`- **cwd**\uFF1A\`${cleanCodeSpan(resumable.cwd, 96)}\``,
|
|
6915
|
+
`- **resume**\uFF1A${resumable.allowed ? "ready" : `unavailable (${cleanInline(resumable.reason ?? "blocked", 64)})`}`
|
|
6916
|
+
);
|
|
6847
6917
|
}
|
|
6848
6918
|
const actions = [];
|
|
6849
6919
|
if (resumable?.allowed && sessionId) {
|
|
@@ -6884,8 +6954,8 @@ function parsePanelCommand(text) {
|
|
|
6884
6954
|
cmd = next?.[1] ?? "";
|
|
6885
6955
|
rest = next?.[2] ?? "";
|
|
6886
6956
|
}
|
|
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;
|
|
6957
|
+
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") {
|
|
6958
|
+
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
6959
|
}
|
|
6890
6960
|
const leadingFlag = /^--restricted(?:\s+|$)/.exec(rest);
|
|
6891
6961
|
const restricted = leadingFlag !== null;
|
|
@@ -7001,6 +7071,7 @@ function composePanel(opts = {}) {
|
|
|
7001
7071
|
const meta = `\`${cleanCodeSpan(formatPeerModel(p), 44)}\` \xB7 ${formatPeerState(p.state, p.currentTool, verDrift)}${threadLink}`;
|
|
7002
7072
|
const rowActions = p === managerPeer ? [
|
|
7003
7073
|
{ id: "panel.models", label: "\u{1F39A} Model" },
|
|
7074
|
+
...p.sessionControls ? [{ id: `panel.tree.${p.instanceId}`, label: "\u{1F333} Tree", payload: { from: "home" } }] : [],
|
|
7004
7075
|
...p.workerPeek && p.sessionId ? [{ id: `panel.peek.${p.instanceId}`, label: "\u{1F440} Peek", payload: { peek: { ref: p.instanceId, session: p.sessionId, isManager: true } } }] : []
|
|
7005
7076
|
] : [{ id: `panel.worker.${p.instanceId}`, label: "\u{1F527} \u7BA1\u7406" }];
|
|
7006
7077
|
return { text: `${label}
|
|
@@ -7243,7 +7314,7 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline2(a.lastRunBy ?? "\u2014", 20)}
|
|
|
7243
7314
|
return { spec: {
|
|
7244
7315
|
title: "Panel Commands",
|
|
7245
7316
|
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.",
|
|
7317
|
+
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
7318
|
actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
|
|
7248
7319
|
}, patchOrigin: patchInPlace };
|
|
7249
7320
|
}
|
|
@@ -7263,9 +7334,6 @@ function clipText(text, max) {
|
|
|
7263
7334
|
function cleanInline3(text, max = 44) {
|
|
7264
7335
|
return clipText(sanitizeLiteralMarkdown(text), max);
|
|
7265
7336
|
}
|
|
7266
|
-
function sanitizeTableCell2(text, max = 64) {
|
|
7267
|
-
return clipText(sanitizeLiteralMarkdown(text).replace(/\|/g, "\uFF5C"), max);
|
|
7268
|
-
}
|
|
7269
7337
|
function cleanArchiveTitle(raw) {
|
|
7270
7338
|
let s = raw.trim();
|
|
7271
7339
|
if (s.startsWith("[pie-ipc]")) {
|
|
@@ -7462,18 +7530,15 @@ function composeArchiveDetailCard(sessionId, opts = {}) {
|
|
|
7462
7530
|
const livePeer = findPeerBySessionId(s.sessionId);
|
|
7463
7531
|
const threadUrl = resolveSessionThreadUrl(s.sessionId);
|
|
7464
7532
|
const shortCwd = formatShortCwd(s.cwd);
|
|
7465
|
-
const statusText = livePeer ? livePeer.state === "working" ? "\u{1F7E1} \u8FD0\u884C\u4E2D\uFF08\u5728\u7EBF\uFF09" : "\u{1F7E2} \u5728\u7EBF" : s.livePid ? `\u{1F7E1} \u5DF2\u88AB\u5360\u7528 (pid ${s.livePid})` : s.resumable ? "\u{1F4A4} \u79BB\u7EBF \xB7 \u53EF\u4E00\u952E\u5524\u9192" : `\u{1F512} \u4E0D\u53EF\u5524\u9192 (${
|
|
7466
|
-
const
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
...
|
|
7474
|
-
`| updated | ${formatClock(s.updatedAt)} (${formatRelativeTime(s.updatedAt)}) \xB7 ${s.messageCount} msgs |`,
|
|
7475
|
-
`| status | ${statusText} |`,
|
|
7476
|
-
...threadUrl ? [`| thread | [\u{1F4AC} \u6253\u5F00\u539F\u8BDD\u9898 \u2197](${threadUrl}) |`] : []
|
|
7533
|
+
const statusText = livePeer ? livePeer.state === "working" ? "\u{1F7E1} \u8FD0\u884C\u4E2D\uFF08\u5728\u7EBF\uFF09" : "\u{1F7E2} \u5728\u7EBF" : s.livePid ? `\u{1F7E1} \u5DF2\u88AB\u5360\u7528 (pid ${s.livePid})` : s.resumable ? "\u{1F4A4} \u79BB\u7EBF \xB7 \u53EF\u4E00\u952E\u5524\u9192" : `\u{1F512} \u4E0D\u53EF\u5524\u9192 (${cleanInline3(s.resumeReason ?? "\u53D7 allowCwd \u9650\u5236", 48)})`;
|
|
7534
|
+
const infoLines = [
|
|
7535
|
+
`- **title**\uFF1A${cleanInline3(cleanArchiveTitle(s.name), 72)}`,
|
|
7536
|
+
`- **session**\uFF1A\`${cleanCodeSpan(s.sessionId, 64)}\`${s.workerName ? ` \xB7 **worker**\uFF1A${cleanInline3(s.workerName, 48)}` : ""}`,
|
|
7537
|
+
...shortCwd ? [`- **cwd**\uFF1A\`${cleanCodeSpan(shortCwd, 88)}\``] : [],
|
|
7538
|
+
...s.model ? [`- **model**\uFF1A\`${cleanCodeSpan(s.model + (s.thinkingLevel ? ` (${s.thinkingLevel})` : ""), 56)}\``] : [],
|
|
7539
|
+
`- **updated**\uFF1A${formatClock(s.updatedAt)} (${formatRelativeTime(s.updatedAt)}) \xB7 ${s.messageCount} msgs`,
|
|
7540
|
+
`- **status**\uFF1A${statusText}`,
|
|
7541
|
+
...threadUrl ? [`- **thread**\uFF1A[\u{1F4AC} \u6253\u5F00\u539F\u8BDD\u9898 \u2197](${threadUrl})`] : []
|
|
7477
7542
|
];
|
|
7478
7543
|
const actions = [];
|
|
7479
7544
|
if (livePeer && !livePeer.isManager) {
|
|
@@ -7497,7 +7562,7 @@ function composeArchiveDetailCard(sessionId, opts = {}) {
|
|
|
7497
7562
|
subtitle: `${projectTag ?? s.sessionId.slice(0, 12)} \xB7 ${formatRelativeTime(s.updatedAt)} \xB7 ${s.messageCount} msgs`,
|
|
7498
7563
|
color: livePeer ? "green" : "violet",
|
|
7499
7564
|
columnsPerRow: cols,
|
|
7500
|
-
body: `${
|
|
7565
|
+
body: `${infoLines.join("\n")}
|
|
7501
7566
|
|
|
7502
7567
|
---
|
|
7503
7568
|
**\u6700\u8FD1\u5BF9\u8BDD\u6458\u8981**\uFF08\u79BB\u7EBF\u8BFB\u53D6\uFF0Czero LLM\uFF09
|
|
@@ -7627,11 +7692,119 @@ async function ensureResumedSessionTopic(opts) {
|
|
|
7627
7692
|
}
|
|
7628
7693
|
}
|
|
7629
7694
|
|
|
7630
|
-
// builtin/extensions/im-forward/runtime-panel-
|
|
7695
|
+
// builtin/extensions/im-forward/runtime-panel-upgrade.ts
|
|
7631
7696
|
import * as fs17 from "node:fs";
|
|
7632
7697
|
import * as os8 from "node:os";
|
|
7633
7698
|
import { dirname as pathDirname, join as join18, resolve as pathResolve2 } from "node:path";
|
|
7634
7699
|
import { spawn as spawnProcess } from "node:child_process";
|
|
7700
|
+
function evaluateUpgradeConfirmAuth(ctx, event) {
|
|
7701
|
+
const hasAllowUsers = Array.isArray(ctx.allowUsers) && ctx.allowUsers.length > 0;
|
|
7702
|
+
if (hasAllowUsers) {
|
|
7703
|
+
return event.sender_id && ctx.allowUsers.includes(event.sender_id) ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
7704
|
+
}
|
|
7705
|
+
if (ctx.panelAccess === "allowUsers") {
|
|
7706
|
+
return { allowed: false, reason: "panelAccess-allowUsers-unconfigured" };
|
|
7707
|
+
}
|
|
7708
|
+
if (ctx.targetKind === "user") {
|
|
7709
|
+
return ctx.targetId && event.sender_id && event.sender_id === ctx.targetId ? { allowed: true } : { allowed: false, reason: "not-in-allowUsers" };
|
|
7710
|
+
}
|
|
7711
|
+
if (ctx.targetId && event.chat_id === ctx.targetId) {
|
|
7712
|
+
return { allowed: true };
|
|
7713
|
+
}
|
|
7714
|
+
return { allowed: false, reason: "unbound-chat" };
|
|
7715
|
+
}
|
|
7716
|
+
function formatUpgradeAuthRefusal(reason, senderId) {
|
|
7717
|
+
const idSpan = senderId ? `\`${cleanCodeSpan(senderId, 64)}\`` : void 0;
|
|
7718
|
+
if (reason === "panelAccess-allowUsers-unconfigured") {
|
|
7719
|
+
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).";
|
|
7720
|
+
}
|
|
7721
|
+
if (reason === "unbound-chat") {
|
|
7722
|
+
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.";
|
|
7723
|
+
}
|
|
7724
|
+
return idSpan ? `\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers). Your ID: ${idSpan}` : "\u26D4\uFE0F Upgrading pie requires admin rights (allowUsers).";
|
|
7725
|
+
}
|
|
7726
|
+
async function runUpgradeConfirmActor(cols, log) {
|
|
7727
|
+
const started = Date.now();
|
|
7728
|
+
let actorOk = false;
|
|
7729
|
+
let actorDetail = "";
|
|
7730
|
+
try {
|
|
7731
|
+
const entry = process.argv[1] ? pathResolve2(process.argv[1]) : "";
|
|
7732
|
+
if (!entry) throw new Error("cannot resolve the pie entry point");
|
|
7733
|
+
const configRoot = pathDirname(pathDirname(ipcDiscoveryRoot()));
|
|
7734
|
+
const managerDir = join18(configRoot, "manager");
|
|
7735
|
+
const logFile = join18(managerDir, "upgrade-actor.log");
|
|
7736
|
+
const actorEnv = resolveAbsoluteActorEnv(process.env);
|
|
7737
|
+
if (process.platform === "win32" && isWindowsServiceManager(configRoot)) {
|
|
7738
|
+
const launched = launchWindowsServiceUpgradeActor({
|
|
7739
|
+
managerDir,
|
|
7740
|
+
nodePath: process.execPath,
|
|
7741
|
+
entry,
|
|
7742
|
+
logFile,
|
|
7743
|
+
env: actorEnv
|
|
7744
|
+
});
|
|
7745
|
+
actorOk = launched.ok;
|
|
7746
|
+
actorDetail = launched.detail;
|
|
7747
|
+
} else {
|
|
7748
|
+
let out;
|
|
7749
|
+
try {
|
|
7750
|
+
fs17.mkdirSync(managerDir, { recursive: true });
|
|
7751
|
+
out = fs17.openSync(logFile, "a");
|
|
7752
|
+
} catch {
|
|
7753
|
+
out = void 0;
|
|
7754
|
+
}
|
|
7755
|
+
const child = spawnProcess(process.execPath, [entry, "manager", "upgrade"], {
|
|
7756
|
+
cwd: os8.tmpdir(),
|
|
7757
|
+
detached: true,
|
|
7758
|
+
stdio: out !== void 0 ? ["ignore", out, out] : "ignore",
|
|
7759
|
+
windowsHide: true,
|
|
7760
|
+
env: actorEnv
|
|
7761
|
+
});
|
|
7762
|
+
const spawnOutcome = await new Promise((resolve9) => {
|
|
7763
|
+
let settled = false;
|
|
7764
|
+
const settle = (v) => {
|
|
7765
|
+
if (!settled) {
|
|
7766
|
+
settled = true;
|
|
7767
|
+
resolve9(v);
|
|
7768
|
+
}
|
|
7769
|
+
};
|
|
7770
|
+
child.once("spawn", () => settle("spawned"));
|
|
7771
|
+
child.once("error", (error) => {
|
|
7772
|
+
log(`im-forward: upgrade actor spawn error: ${error instanceof Error ? error.message : String(error)}`);
|
|
7773
|
+
settle("error");
|
|
7774
|
+
});
|
|
7775
|
+
setTimeout(() => settle("timeout"), 3e3).unref?.();
|
|
7776
|
+
});
|
|
7777
|
+
child.unref();
|
|
7778
|
+
if (out !== void 0) {
|
|
7779
|
+
try {
|
|
7780
|
+
fs17.closeSync(out);
|
|
7781
|
+
} catch {
|
|
7782
|
+
}
|
|
7783
|
+
}
|
|
7784
|
+
if (spawnOutcome === "error") {
|
|
7785
|
+
actorDetail = "the actor process failed to spawn (see the manager log)";
|
|
7786
|
+
} else {
|
|
7787
|
+
actorOk = true;
|
|
7788
|
+
actorDetail = `actor pid ${child.pid}${spawnOutcome === "timeout" ? " (spawn unconfirmed \u2014 will report via /panel)" : ""} \xB7 log ${logFile}`;
|
|
7789
|
+
}
|
|
7790
|
+
}
|
|
7791
|
+
} catch (error) {
|
|
7792
|
+
actorDetail = error instanceof Error ? error.message : String(error);
|
|
7793
|
+
}
|
|
7794
|
+
log(`im-forward: panel.upgrade.confirm actor spawn ${actorOk ? "ok" : "failed"} (${actorDetail}, runtimeMs=${Date.now() - started})`);
|
|
7795
|
+
return {
|
|
7796
|
+
title: actorOk ? "Upgrade Started" : "Upgrade Failed to Start",
|
|
7797
|
+
columnsPerRow: cols,
|
|
7798
|
+
body: actorOk ? `\u2B06\uFE0F npm install + manager restart running in the background.
|
|
7799
|
+
|
|
7800
|
+
${actorDetail}
|
|
7801
|
+
|
|
7802
|
+
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}`,
|
|
7803
|
+
actions: actorOk ? [{ id: "panel.refresh", label: "\u{1F504} Refresh" }] : [{ id: "panel.upgrade", label: "\u21A9\uFE0F Back to upgrade card" }]
|
|
7804
|
+
};
|
|
7805
|
+
}
|
|
7806
|
+
|
|
7807
|
+
// builtin/extensions/im-forward/runtime-panel-lifecycle.ts
|
|
7635
7808
|
function extractIssuedWorkerCard(spec, chatId, ownerSession, epoch) {
|
|
7636
7809
|
const peek = allCardActions(spec).find((a) => /^panel\.peek\.[A-Za-z0-9-]+$/.test(a.id));
|
|
7637
7810
|
const bound = peek && isRecord(peek.payload) && isRecord(peek.payload.peek) ? peek.payload.peek : void 0;
|
|
@@ -7771,7 +7944,7 @@ function panelHomeAction(inThread, threadWorkerSessionId, peerRef) {
|
|
|
7771
7944
|
}
|
|
7772
7945
|
return [];
|
|
7773
7946
|
}
|
|
7774
|
-
function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSessionId, verifiedQuitSessionId, verifiedCronStopSessionId) {
|
|
7947
|
+
function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSessionId, verifiedQuitSessionId, verifiedCronStopSessionId, verifiedTreeBranchSessionId) {
|
|
7775
7948
|
if (!workerScoped || !pinnedWorkerSessionId) return { blocked: false };
|
|
7776
7949
|
const cols = inThread ? 2 : 3;
|
|
7777
7950
|
if (panelCmd.cmd === "panel" || panelCmd.cmd === "\u9762\u677F") {
|
|
@@ -7781,6 +7954,20 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
|
|
|
7781
7954
|
rewrittenCmd: live ? { cmd: `panel.worker.${live.instanceId}`, restricted: false } : { cmd: "panel.worker.offline", restricted: false, payload: { sessionId: pinnedWorkerSessionId } }
|
|
7782
7955
|
};
|
|
7783
7956
|
}
|
|
7957
|
+
if (panelCmd.cmd === "panel.tree") {
|
|
7958
|
+
const live = findPeerBySessionId(pinnedWorkerSessionId);
|
|
7959
|
+
if (!live) {
|
|
7960
|
+
return { blocked: true, spec: composeOfflineWorkerCard(pinnedWorkerSessionId, { inThread, hideHome: true }) };
|
|
7961
|
+
}
|
|
7962
|
+
return {
|
|
7963
|
+
blocked: false,
|
|
7964
|
+
rewrittenCmd: {
|
|
7965
|
+
cmd: `panel.tree.${live.instanceId}`,
|
|
7966
|
+
restricted: false,
|
|
7967
|
+
payload: { ...isRecord(panelCmd.payload) ? panelCmd.payload : {}, from: "worker" }
|
|
7968
|
+
}
|
|
7969
|
+
};
|
|
7970
|
+
}
|
|
7784
7971
|
const deny = (reason) => ({
|
|
7785
7972
|
blocked: true,
|
|
7786
7973
|
spec: {
|
|
@@ -7847,6 +8034,20 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
|
|
|
7847
8034
|
}
|
|
7848
8035
|
return { blocked: false };
|
|
7849
8036
|
}
|
|
8037
|
+
const treePeerMatch = /^panel\.tree(?:\.branch(?:\.confirm)?)?\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
8038
|
+
if (treePeerMatch) {
|
|
8039
|
+
const peer = scanPeers().find((p) => p.instanceId === treePeerMatch[1]);
|
|
8040
|
+
if (peer) {
|
|
8041
|
+
if (peer.isManager || peer.sessionId !== pinnedWorkerSessionId) {
|
|
8042
|
+
return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u67E5\u770B\u6216\u64CD\u4F5C\u5F53\u524D Worker \u7684\u4F1A\u8BDD\u6811\u3002");
|
|
8043
|
+
}
|
|
8044
|
+
if (panelCmd.cmd.startsWith("panel.tree.branch.confirm.") && verifiedTreeBranchSessionId && verifiedTreeBranchSessionId !== pinnedWorkerSessionId) {
|
|
8045
|
+
return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u5207\u6362\u5F53\u524D Worker \u7684\u4F1A\u8BDD\u5206\u652F\u3002");
|
|
8046
|
+
}
|
|
8047
|
+
return { blocked: false };
|
|
8048
|
+
}
|
|
8049
|
+
return { blocked: true, spec: composeOfflineWorkerCard(pinnedWorkerSessionId, { inThread, hideHome: true }) };
|
|
8050
|
+
}
|
|
7850
8051
|
const ctrlPeerMatch = /^panel\.(?:model|thinking|context|compact|stop|peek(?:\.refresh)?)\.([A-Za-z0-9-]+)/.exec(panelCmd.cmd);
|
|
7851
8052
|
if (ctrlPeerMatch) {
|
|
7852
8053
|
const peer = scanPeers().find((p) => p.instanceId === ctrlPeerMatch[1]);
|
|
@@ -8222,32 +8423,6 @@ function isPeekAudienceAllowed(ctx, event) {
|
|
|
8222
8423
|
if (event.chatType !== "group") return !ctx.allowUsers || isAllowedUser();
|
|
8223
8424
|
return true;
|
|
8224
8425
|
}
|
|
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
8426
|
function buildPeekCardSpec(targetRef, targetSession, isManagerTarget, cols, receipt, inThread = false) {
|
|
8252
8427
|
const meta = parsePeekMeta(receipt);
|
|
8253
8428
|
const actions = [
|
|
@@ -8314,86 +8489,6 @@ async function deliverPeekDeniedAtGate(params) {
|
|
|
8314
8489
|
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
8490
|
}
|
|
8316
8491
|
}
|
|
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
8492
|
|
|
8398
8493
|
// builtin/extensions/im-forward/panel-cron.ts
|
|
8399
8494
|
var PAGE_SIZE = 6;
|
|
@@ -8543,12 +8638,9 @@ function composeCronStopConfirmCard(job, opts) {
|
|
|
8543
8638
|
color: "red",
|
|
8544
8639
|
columnsPerRow: cols,
|
|
8545
8640
|
body: [
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
| schedule | ${formatScheduleCell(job)} |
|
|
8550
|
-
| state | ${formatJobState(job)} |${job.ownerLabel ? `
|
|
8551
|
-
| owner | ${cleanCell(job.ownerLabel, 32)} |` : ""}`,
|
|
8641
|
+
`- **task**\uFF1A${cleanCell(job.summary, 64)}`,
|
|
8642
|
+
`- **schedule**\uFF1A${formatScheduleCell(job)} \xB7 **state**\uFF1A${formatJobState(job)}`,
|
|
8643
|
+
...job.ownerLabel ? [`- **owner**\uFF1A${cleanCell(job.ownerLabel, 32)}`] : [],
|
|
8552
8644
|
``,
|
|
8553
8645
|
job.state === "running" ? "\u26A0\uFE0F \u8BE5\u4EFB\u52A1\u5F53\u524D\u6B63\u5728\u6267\u884C\uFF1B\u786E\u8BA4\u540E\u5C06\u6392\u961F\u7B49\u5F85\u672C\u8F6E\u7ED3\u675F\u5E76\u81EA\u52A8\u505C\u6B62\u5220\u9664\u3002" : job.managedBy ? `\u505C\u6B62\u540E\u5C06\u79FB\u9664\u53D7\u7BA1\u5B9A\u65F6\u4EFB\u52A1 \`${cleanCodeSpan(job.managedBy, 64)}\` \u5E76\u8BB0\u4F4F\u5173\u95ED\u610F\u56FE\uFF08\u91CD\u542F\u4E0D\u4F1A\u81EA\u52A8\u6062\u590D\uFF09\u3002` : "\u505C\u6B62\u540E\u5C06\u6C38\u4E45\u5220\u9664\u8BE5\u5B9A\u65F6\u4EFB\u52A1\uFF08\u540E\u7EED\u9700\u8981\u53EF\u5728\u5BF9\u8BDD\u4E2D\u91CD\u65B0\u521B\u5EFA\uFF09\u3002"
|
|
8554
8646
|
].join("\n"),
|
|
@@ -8750,6 +8842,549 @@ function runCronPanelCommand(panelCmd, opts) {
|
|
|
8750
8842
|
return { handled: false };
|
|
8751
8843
|
}
|
|
8752
8844
|
|
|
8845
|
+
// builtin/extensions/im-forward/panel-tree.ts
|
|
8846
|
+
var TREE_PAGE_SIZE = 5;
|
|
8847
|
+
var SAFE_ENTRY_ID_RE = /^[^\x00-\x1f\x7f-\x9f\s]{1,128}$/;
|
|
8848
|
+
function extractIssuedTreeBranch(spec, chatId, ownerSession, epoch) {
|
|
8849
|
+
const confirm = allCardActions(spec).find((a) => /^panel\.tree\.branch\.confirm\.[A-Za-z0-9-]+$/.test(a.id));
|
|
8850
|
+
const payload = confirm && isRecord(confirm.payload) ? confirm.payload : void 0;
|
|
8851
|
+
const bound = payload && isRecord(payload.treeBranch) ? payload.treeBranch : void 0;
|
|
8852
|
+
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)) {
|
|
8853
|
+
return {
|
|
8854
|
+
ref: bound.ref,
|
|
8855
|
+
sessionId: bound.session,
|
|
8856
|
+
entryId: bound.entryId,
|
|
8857
|
+
chatId,
|
|
8858
|
+
ownerSession,
|
|
8859
|
+
epoch
|
|
8860
|
+
};
|
|
8861
|
+
}
|
|
8862
|
+
return void 0;
|
|
8863
|
+
}
|
|
8864
|
+
function isTreePanelCommand(cmd) {
|
|
8865
|
+
return cmd === "panel.tree" || /^panel\.tree\.[A-Za-z0-9-]+$/.test(cmd) || /^panel\.tree\.branch(?:\.confirm)?\.[A-Za-z0-9-]+$/.test(cmd);
|
|
8866
|
+
}
|
|
8867
|
+
function clipText3(text, max) {
|
|
8868
|
+
return text.length <= max ? text : `${text.slice(0, Math.max(1, max - 1))}\u2026`;
|
|
8869
|
+
}
|
|
8870
|
+
function cleanInline4(text, max = 72) {
|
|
8871
|
+
return clipText3(sanitizeLiteralMarkdown(text), max);
|
|
8872
|
+
}
|
|
8873
|
+
function formatNodeClock(timestamp) {
|
|
8874
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0) return "\u2014";
|
|
8875
|
+
const d = new Date(timestamp);
|
|
8876
|
+
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
|
8877
|
+
const dd = String(d.getDate()).padStart(2, "0");
|
|
8878
|
+
const hh = String(d.getHours()).padStart(2, "0");
|
|
8879
|
+
const mi = String(d.getMinutes()).padStart(2, "0");
|
|
8880
|
+
return `${mm}-${dd} ${hh}:${mi}`;
|
|
8881
|
+
}
|
|
8882
|
+
function kindBadge(kind) {
|
|
8883
|
+
switch (kind) {
|
|
8884
|
+
case "user":
|
|
8885
|
+
return "\u{1F464} \u7528\u6237";
|
|
8886
|
+
case "assistant":
|
|
8887
|
+
return "\u{1F916} \u52A9\u624B";
|
|
8888
|
+
case "tool":
|
|
8889
|
+
return "\u{1F527} \u5DE5\u5177";
|
|
8890
|
+
case "compaction":
|
|
8891
|
+
return "\u{1F9F9} \u538B\u7F29";
|
|
8892
|
+
case "fork":
|
|
8893
|
+
return "\u{1F33F} \u5206\u53C9";
|
|
8894
|
+
default:
|
|
8895
|
+
return "\u{1F4CC} \u8BB0\u5F55";
|
|
8896
|
+
}
|
|
8897
|
+
}
|
|
8898
|
+
function parseTreeMeta(payload) {
|
|
8899
|
+
if (!isRecord(payload)) return { page: 1, filter: "key" };
|
|
8900
|
+
const page = typeof payload.page === "number" && Number.isFinite(payload.page) && payload.page >= 1 ? Math.floor(payload.page) : 1;
|
|
8901
|
+
const filter = payload.filter === "all" ? "all" : "key";
|
|
8902
|
+
const from = payload.from === "home" || payload.from === "worker" ? payload.from : void 0;
|
|
8903
|
+
const entryId = typeof payload.entryId === "string" && SAFE_ENTRY_ID_RE.test(payload.entryId) ? payload.entryId : void 0;
|
|
8904
|
+
return { page, filter, ...from ? { from } : {}, ...entryId ? { entryId } : {} };
|
|
8905
|
+
}
|
|
8906
|
+
var VALID_ENTRY_KINDS = /* @__PURE__ */ new Set(["user", "assistant", "tool", "compaction", "fork", "custom"]);
|
|
8907
|
+
function isNonNegInt(value) {
|
|
8908
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
8909
|
+
}
|
|
8910
|
+
function isPosInt(value) {
|
|
8911
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1;
|
|
8912
|
+
}
|
|
8913
|
+
function isValidNodeSummary(raw) {
|
|
8914
|
+
if (!isRecord(raw)) return false;
|
|
8915
|
+
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);
|
|
8916
|
+
}
|
|
8917
|
+
function unwrapControlReceiptMessage(detail) {
|
|
8918
|
+
const start = detail.indexOf("{");
|
|
8919
|
+
if (start < 0) return void 0;
|
|
8920
|
+
try {
|
|
8921
|
+
const ack = JSON.parse(detail.slice(start));
|
|
8922
|
+
if (!isRecord(ack) || typeof ack.ok !== "boolean" || typeof ack.message !== "string") return void 0;
|
|
8923
|
+
return { ok: ack.ok, message: ack.message };
|
|
8924
|
+
} catch {
|
|
8925
|
+
return void 0;
|
|
8926
|
+
}
|
|
8927
|
+
}
|
|
8928
|
+
function parseTreePageReport(detail, expectedSessionId) {
|
|
8929
|
+
try {
|
|
8930
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8931
|
+
if (!ack || !ack.ok) return void 0;
|
|
8932
|
+
const parsed = JSON.parse(ack.message);
|
|
8933
|
+
if (!isRecord(parsed) || parsed.mode !== "page") return void 0;
|
|
8934
|
+
if (parsed.sessionId !== expectedSessionId || !Array.isArray(parsed.nodes)) return void 0;
|
|
8935
|
+
if (parsed.activeEntryId !== null && (typeof parsed.activeEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.activeEntryId))) return void 0;
|
|
8936
|
+
if (!isNonNegInt(parsed.activePathLength) || !isNonNegInt(parsed.totalEntries) || !isNonNegInt(parsed.totalFiltered)) return void 0;
|
|
8937
|
+
if (!isNonNegInt(parsed.branchPointCount) || !isNonNegInt(parsed.otherBranchTipCount)) return void 0;
|
|
8938
|
+
if (!isPosInt(parsed.page) || !isPosInt(parsed.pageSize) || !isPosInt(parsed.totalPages)) return void 0;
|
|
8939
|
+
if (parsed.filter !== "key" && parsed.filter !== "all") return void 0;
|
|
8940
|
+
if (typeof parsed.isIdle !== "boolean" || typeof parsed.compactionRunning !== "boolean") return void 0;
|
|
8941
|
+
if (parsed.truncated !== void 0 && typeof parsed.truncated !== "boolean") return void 0;
|
|
8942
|
+
if (parsed.nodes.length > 16 || !parsed.nodes.every(isValidNodeSummary)) return void 0;
|
|
8943
|
+
return parsed;
|
|
8944
|
+
} catch {
|
|
8945
|
+
return void 0;
|
|
8946
|
+
}
|
|
8947
|
+
}
|
|
8948
|
+
function parseTreeEntryReport(detail, expectedSessionId) {
|
|
8949
|
+
try {
|
|
8950
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8951
|
+
if (!ack || !ack.ok) return void 0;
|
|
8952
|
+
const parsed = JSON.parse(ack.message);
|
|
8953
|
+
if (!isRecord(parsed) || parsed.mode !== "entry") return void 0;
|
|
8954
|
+
if (parsed.sessionId !== expectedSessionId) return void 0;
|
|
8955
|
+
if (parsed.activeEntryId !== null && (typeof parsed.activeEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.activeEntryId))) return void 0;
|
|
8956
|
+
if (!isNonNegInt(parsed.activePathLength)) return void 0;
|
|
8957
|
+
if (typeof parsed.isIdle !== "boolean" || typeof parsed.compactionRunning !== "boolean") return void 0;
|
|
8958
|
+
if (parsed.entry !== null && !isValidNodeSummary(parsed.entry)) return void 0;
|
|
8959
|
+
return parsed;
|
|
8960
|
+
} catch {
|
|
8961
|
+
return void 0;
|
|
8962
|
+
}
|
|
8963
|
+
}
|
|
8964
|
+
function parseBranchSuccess(detail, expectedSessionId, expectedEntryId) {
|
|
8965
|
+
try {
|
|
8966
|
+
const ack = unwrapControlReceiptMessage(detail);
|
|
8967
|
+
if (!ack || !ack.ok) return void 0;
|
|
8968
|
+
const parsed = JSON.parse(ack.message);
|
|
8969
|
+
if (!isRecord(parsed) || parsed.ok !== true) return void 0;
|
|
8970
|
+
if (parsed.sessionId !== expectedSessionId || parsed.activeEntryId !== expectedEntryId) return void 0;
|
|
8971
|
+
if (parsed.fromEntryId !== null && (typeof parsed.fromEntryId !== "string" || !SAFE_ENTRY_ID_RE.test(parsed.fromEntryId))) return void 0;
|
|
8972
|
+
if (typeof parsed.alreadyActive !== "boolean") return void 0;
|
|
8973
|
+
if (!isPosInt(parsed.seq) || !isNonNegInt(parsed.pathLength) || !isNonNegInt(parsed.messageCount)) return void 0;
|
|
8974
|
+
if (typeof parsed.kind !== "string" || !VALID_ENTRY_KINDS.has(parsed.kind)) return void 0;
|
|
8975
|
+
if (typeof parsed.preview !== "string" || parsed.preview.length > 256) return void 0;
|
|
8976
|
+
return parsed;
|
|
8977
|
+
} catch {
|
|
8978
|
+
return void 0;
|
|
8979
|
+
}
|
|
8980
|
+
}
|
|
8981
|
+
function seqFromEntryId(entryId) {
|
|
8982
|
+
if (!entryId) return void 0;
|
|
8983
|
+
const m = /^e(\d+)-/.exec(entryId);
|
|
8984
|
+
if (!m) return void 0;
|
|
8985
|
+
const n = Number(m[1]);
|
|
8986
|
+
return Number.isInteger(n) && n > 0 ? n : void 0;
|
|
8987
|
+
}
|
|
8988
|
+
function backActionsFor(peer, opts) {
|
|
8989
|
+
if (opts.hideHome) {
|
|
8990
|
+
return [{ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" }];
|
|
8991
|
+
}
|
|
8992
|
+
if (opts.from === "home" || peer.isManager) {
|
|
8993
|
+
return [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }];
|
|
8994
|
+
}
|
|
8995
|
+
return [
|
|
8996
|
+
{ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" },
|
|
8997
|
+
{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
|
|
8998
|
+
];
|
|
8999
|
+
}
|
|
9000
|
+
function formatPeerErrorDetail(detail) {
|
|
9001
|
+
const unwrapped = unwrapControlReceiptMessage(detail)?.message ?? detail;
|
|
9002
|
+
if (/unknown control:\s*session\.(?:tree|branch)/i.test(unwrapped)) {
|
|
9003
|
+
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";
|
|
9004
|
+
}
|
|
9005
|
+
return sanitizeLiteralMarkdown(unwrapped);
|
|
9006
|
+
}
|
|
9007
|
+
function composeTreeListCard(peer, report, opts) {
|
|
9008
|
+
const cols = opts.inThread ? 2 : 3;
|
|
9009
|
+
const displayTitle = peer.isManager ? "Manager" : workerDisplayTitle(peer);
|
|
9010
|
+
const fromVal = opts.from ?? (peer.isManager ? "home" : "worker");
|
|
9011
|
+
const navBase = { filter: report.filter, from: fromVal };
|
|
9012
|
+
const headSeq = report.nodes.find((n) => n.isHead)?.seq ?? seqFromEntryId(report.activeEntryId);
|
|
9013
|
+
const items = report.nodes.map((node) => {
|
|
9014
|
+
const marker = node.isHead ? "\u2605" : node.onActivePath ? "\u25CF" : "\u{1F33F}";
|
|
9015
|
+
const tags = [];
|
|
9016
|
+
if (node.isHead) tags.push("\u5F53\u524D");
|
|
9017
|
+
if (node.isBranchPoint) tags.push(`\u2442\xD7${node.childCount}`);
|
|
9018
|
+
if (node.isBranchTip) tags.push("\u5206\u652F\u672B");
|
|
9019
|
+
if (node.label) tags.push(`\u{1F3F7}\uFE0F${cleanInline4(node.label, 20)}`);
|
|
9020
|
+
const tagSuffix = tags.length > 0 ? ` \xB7 ${tags.join(" ")}` : "";
|
|
9021
|
+
const preview = cleanInline4(node.preview || "(\u7A7A)", 72);
|
|
9022
|
+
const text = `${marker} **#${node.seq}** ${kindBadge(node.kind)} \xB7 ${formatNodeClock(node.timestamp)}${tagSuffix}
|
|
9023
|
+
${preview}`;
|
|
9024
|
+
const actions = node.isHead ? [] : [{
|
|
9025
|
+
id: `panel.tree.branch.${peer.instanceId}`,
|
|
9026
|
+
label: node.onActivePath ? "\u23EA \u56DE\u9000" : "\u{1F33F} \u5207\u5206\u652F",
|
|
9027
|
+
payload: { entryId: node.id, page: report.page, filter: report.filter, from: fromVal }
|
|
9028
|
+
}];
|
|
9029
|
+
return { text, ...actions.length > 0 ? { actions } : {} };
|
|
9030
|
+
});
|
|
9031
|
+
const bodyLines = [];
|
|
9032
|
+
if (opts.banner) bodyLines.push(opts.banner);
|
|
9033
|
+
if (!report.isIdle || report.compactionRunning) {
|
|
9034
|
+
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");
|
|
9035
|
+
}
|
|
9036
|
+
if (report.truncated) {
|
|
9037
|
+
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");
|
|
9038
|
+
}
|
|
9039
|
+
if (items.length === 0) {
|
|
9040
|
+
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_");
|
|
9041
|
+
}
|
|
9042
|
+
const navButtons = [];
|
|
9043
|
+
if (report.page > 1) {
|
|
9044
|
+
navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `\u25C0\uFE0F \u7B2C ${report.page - 1} \u9875`, payload: { ...navBase, page: report.page - 1 } });
|
|
9045
|
+
}
|
|
9046
|
+
if (report.page < report.totalPages) {
|
|
9047
|
+
navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `\u7B2C ${report.page + 1} \u9875 \u25B6\uFE0F`, payload: { ...navBase, page: report.page + 1 } });
|
|
9048
|
+
}
|
|
9049
|
+
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 } };
|
|
9050
|
+
const subtitleParts = [
|
|
9051
|
+
headSeq !== void 0 ? `\u5F53\u524D #${headSeq}` : "\u65E0\u6D3B\u52A8\u8282\u70B9",
|
|
9052
|
+
`${report.totalEntries} \u8282\u70B9`,
|
|
9053
|
+
...report.branchPointCount > 0 ? [`${report.branchPointCount} \u5206\u53C9`] : [],
|
|
9054
|
+
...report.otherBranchTipCount > 0 ? [`${report.otherBranchTipCount} \u5176\u4ED6\u5206\u652F`] : [],
|
|
9055
|
+
`p${report.page}/${report.totalPages}`
|
|
9056
|
+
];
|
|
9057
|
+
return {
|
|
9058
|
+
title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${displayTitle}`,
|
|
9059
|
+
subtitle: subtitleParts.join(" \xB7 "),
|
|
9060
|
+
color: !report.isIdle || report.compactionRunning ? "violet" : "blue",
|
|
9061
|
+
columnsPerRow: cols,
|
|
9062
|
+
body: bodyLines.join("\n\n"),
|
|
9063
|
+
...items.length > 0 ? { items } : {},
|
|
9064
|
+
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",
|
|
9065
|
+
actions: [
|
|
9066
|
+
...navButtons,
|
|
9067
|
+
toggleFilter,
|
|
9068
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} Refresh", payload: { ...navBase, page: report.page } },
|
|
9069
|
+
...backActionsFor(peer, { hideHome: opts.hideHome, from: fromVal, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9070
|
+
]
|
|
9071
|
+
};
|
|
9072
|
+
}
|
|
9073
|
+
function composeTreeBranchConfirmCard(peer, detail, opts) {
|
|
9074
|
+
const cols = opts.inThread ? 2 : 3;
|
|
9075
|
+
const displayTitle = peer.isManager ? "Manager" : workerDisplayTitle(peer);
|
|
9076
|
+
const fromVal = opts.from ?? (peer.isManager ? "home" : "worker");
|
|
9077
|
+
const cancelAction = {
|
|
9078
|
+
id: `panel.tree.${peer.instanceId}`,
|
|
9079
|
+
label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811",
|
|
9080
|
+
payload: { page: opts.page, filter: opts.filter, from: fromVal }
|
|
9081
|
+
};
|
|
9082
|
+
const entry = detail.entry;
|
|
9083
|
+
if (!entry) {
|
|
9084
|
+
return {
|
|
9085
|
+
title: "\u26A0\uFE0F \u8282\u70B9\u4E0D\u5B58\u5728",
|
|
9086
|
+
subtitle: displayTitle,
|
|
9087
|
+
color: "grey",
|
|
9088
|
+
columnsPerRow: cols,
|
|
9089
|
+
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",
|
|
9090
|
+
actions: [cancelAction]
|
|
9091
|
+
};
|
|
9092
|
+
}
|
|
9093
|
+
if (entry.isHead) {
|
|
9094
|
+
return {
|
|
9095
|
+
title: `\u{1F333} \u5DF2\u5728\u76EE\u6807\u8282\u70B9 #${entry.seq}`,
|
|
9096
|
+
subtitle: displayTitle,
|
|
9097
|
+
color: "green",
|
|
9098
|
+
columnsPerRow: cols,
|
|
9099
|
+
body: "\u5F53\u524D\u4F1A\u8BDD\u6307\u9488\u5DF2\u7ECF\u4F4D\u4E8E\u8BE5\u8282\u70B9\uFF0C\u65E0\u9700\u5207\u6362\u3002",
|
|
9100
|
+
actions: [cancelAction]
|
|
9101
|
+
};
|
|
9102
|
+
}
|
|
9103
|
+
if (!detail.isIdle || detail.compactionRunning) {
|
|
9104
|
+
return {
|
|
9105
|
+
title: "\u26A0\uFE0F \u4F1A\u8BDD\u5FD9\u788C\uFF0C\u6682\u4E0D\u53EF\u5207\u6362\u5206\u652F",
|
|
9106
|
+
subtitle: `${displayTitle} \xB7 \u76EE\u6807 #${entry.seq}`,
|
|
9107
|
+
color: "red",
|
|
9108
|
+
columnsPerRow: cols,
|
|
9109
|
+
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",
|
|
9110
|
+
actions: [
|
|
9111
|
+
...!detail.compactionRunning ? [{ id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: { from: fromVal, peer: peer.instanceId } }] : [],
|
|
9112
|
+
cancelAction
|
|
9113
|
+
]
|
|
9114
|
+
};
|
|
9115
|
+
}
|
|
9116
|
+
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`;
|
|
9117
|
+
return {
|
|
9118
|
+
title: entry.onActivePath ? `\u23EA \u786E\u8BA4\u56DE\u9000\u5230 #${entry.seq}` : `\u{1F33F} \u786E\u8BA4\u5207\u6362\u5230\u5206\u652F #${entry.seq}`,
|
|
9119
|
+
subtitle: `${displayTitle} \xB7 ${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)}`,
|
|
9120
|
+
color: "red",
|
|
9121
|
+
columnsPerRow: cols,
|
|
9122
|
+
body: [
|
|
9123
|
+
`- **session**\uFF1A${cleanInline4(displayTitle, 48)}`,
|
|
9124
|
+
`- **target**\uFF1A#${entry.seq} (${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)})`,
|
|
9125
|
+
`- **preview**\uFF1A${cleanInline4(entry.preview || "(\u7A7A)", 72)}`,
|
|
9126
|
+
"",
|
|
9127
|
+
impactLine,
|
|
9128
|
+
"\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",
|
|
9129
|
+
"\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"
|
|
9130
|
+
].join("\n"),
|
|
9131
|
+
actions: [
|
|
9132
|
+
{
|
|
9133
|
+
id: `panel.tree.branch.confirm.${peer.instanceId}`,
|
|
9134
|
+
label: "\u2705 \u786E\u8BA4\u5207\u6362",
|
|
9135
|
+
style: "danger",
|
|
9136
|
+
payload: {
|
|
9137
|
+
treeBranch: { ref: peer.instanceId, session: detail.sessionId, entryId: entry.id },
|
|
9138
|
+
page: opts.page,
|
|
9139
|
+
filter: opts.filter,
|
|
9140
|
+
from: fromVal
|
|
9141
|
+
}
|
|
9142
|
+
},
|
|
9143
|
+
{
|
|
9144
|
+
id: `panel.tree.${peer.instanceId}`,
|
|
9145
|
+
label: "\u21A9\uFE0F \u53D6\u6D88",
|
|
9146
|
+
payload: { page: opts.page, filter: opts.filter, from: fromVal }
|
|
9147
|
+
}
|
|
9148
|
+
]
|
|
9149
|
+
};
|
|
9150
|
+
}
|
|
9151
|
+
async function runTreePanelCommand(panelCmd, opts) {
|
|
9152
|
+
if (!isTreePanelCommand(panelCmd.cmd)) return { handled: false };
|
|
9153
|
+
const cols = opts.inThread ? 2 : 3;
|
|
9154
|
+
const meta = parseTreeMeta(panelCmd.payload);
|
|
9155
|
+
if (!opts.canReadSensitive) {
|
|
9156
|
+
return {
|
|
9157
|
+
handled: true,
|
|
9158
|
+
keyPrefix: "panel-tree-denied",
|
|
9159
|
+
spec: {
|
|
9160
|
+
title: "\u{1F333} \u4F1A\u8BDD\u6811\u4E0D\u53EF\u7528",
|
|
9161
|
+
color: "red",
|
|
9162
|
+
columnsPerRow: cols,
|
|
9163
|
+
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",
|
|
9164
|
+
actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
|
|
9165
|
+
}
|
|
9166
|
+
};
|
|
9167
|
+
}
|
|
9168
|
+
const resolveTargetPeer = (peerRef2) => {
|
|
9169
|
+
const peers = scanPeers();
|
|
9170
|
+
if (opts.workerScoped && opts.pinnedWorkerSessionId) {
|
|
9171
|
+
const live = findPeerBySessionId(opts.pinnedWorkerSessionId);
|
|
9172
|
+
if (!live) return void 0;
|
|
9173
|
+
if (peerRef2 && live.instanceId !== peerRef2) return void 0;
|
|
9174
|
+
return live;
|
|
9175
|
+
}
|
|
9176
|
+
if (peerRef2) return peers.find((p) => p.instanceId === peerRef2);
|
|
9177
|
+
return peers.find((p) => p.isManager);
|
|
9178
|
+
};
|
|
9179
|
+
const offlineSpec = (peerRef2) => {
|
|
9180
|
+
if (opts.workerScoped && opts.pinnedWorkerSessionId) {
|
|
9181
|
+
return composeOfflineWorkerCard(opts.pinnedWorkerSessionId, { inThread: opts.inThread, hideHome: true });
|
|
9182
|
+
}
|
|
9183
|
+
return {
|
|
9184
|
+
title: "\u{1F333} \u4F1A\u8BDD\u5DF2\u79BB\u7EBF",
|
|
9185
|
+
color: "grey",
|
|
9186
|
+
columnsPerRow: cols,
|
|
9187
|
+
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",
|
|
9188
|
+
actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
|
|
9189
|
+
};
|
|
9190
|
+
};
|
|
9191
|
+
const confirmMatch = /^panel\.tree\.branch\.confirm\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9192
|
+
if (confirmMatch) {
|
|
9193
|
+
if (!opts.canMutate) {
|
|
9194
|
+
return {
|
|
9195
|
+
handled: true,
|
|
9196
|
+
keyPrefix: "panel-tree-refused",
|
|
9197
|
+
refusedText: "\u26D4\uFE0F Switching session branch requires admin rights (panelAccess=allowUsers)."
|
|
9198
|
+
};
|
|
9199
|
+
}
|
|
9200
|
+
const peerRef2 = confirmMatch[1];
|
|
9201
|
+
const wireBound = isRecord(panelCmd.payload) && isRecord(panelCmd.payload.treeBranch) ? panelCmd.payload.treeBranch : void 0;
|
|
9202
|
+
const verified = opts.verifiedBranch;
|
|
9203
|
+
if (!verified || verified.ref !== peerRef2 || !wireBound || wireBound.ref !== verified.ref || wireBound.session !== verified.sessionId || wireBound.entryId !== verified.entryId) {
|
|
9204
|
+
const livePeer = resolveTargetPeer(peerRef2);
|
|
9205
|
+
return {
|
|
9206
|
+
handled: true,
|
|
9207
|
+
keyPrefix: "panel-tree-confirm-stale",
|
|
9208
|
+
spec: {
|
|
9209
|
+
title: "\u26A0\uFE0F \u786E\u8BA4\u5361\u7247\u5DF2\u5931\u6548",
|
|
9210
|
+
color: "grey",
|
|
9211
|
+
columnsPerRow: cols,
|
|
9212
|
+
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",
|
|
9213
|
+
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)
|
|
9214
|
+
}
|
|
9215
|
+
};
|
|
9216
|
+
}
|
|
9217
|
+
const peer2 = resolveTargetPeer(peerRef2);
|
|
9218
|
+
if (!peer2 || peer2.sessionId !== verified.sessionId) {
|
|
9219
|
+
return {
|
|
9220
|
+
handled: true,
|
|
9221
|
+
keyPrefix: "panel-tree-confirm-offline",
|
|
9222
|
+
clearIssuedBranch: true,
|
|
9223
|
+
spec: offlineSpec(peerRef2)
|
|
9224
|
+
};
|
|
9225
|
+
}
|
|
9226
|
+
const receipt2 = await applyPeerControl(
|
|
9227
|
+
peer2.instanceId,
|
|
9228
|
+
"session.branch",
|
|
9229
|
+
{ entryId: verified.entryId, expectedSessionId: verified.sessionId },
|
|
9230
|
+
{ instanceId: peer2.instanceId, sessionId: verified.sessionId }
|
|
9231
|
+
);
|
|
9232
|
+
if (!receipt2.ok) {
|
|
9233
|
+
return {
|
|
9234
|
+
handled: true,
|
|
9235
|
+
keyPrefix: "panel-tree-branch-failed",
|
|
9236
|
+
clearIssuedBranch: true,
|
|
9237
|
+
spec: {
|
|
9238
|
+
title: receipt2.unknown ? "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u72B6\u6001\u672A\u77E5" : "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u5DF2\u62D2\u7EDD",
|
|
9239
|
+
color: "red",
|
|
9240
|
+
columnsPerRow: cols,
|
|
9241
|
+
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" : ""}`,
|
|
9242
|
+
actions: [
|
|
9243
|
+
{ id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
|
|
9244
|
+
...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9245
|
+
]
|
|
9246
|
+
}
|
|
9247
|
+
};
|
|
9248
|
+
}
|
|
9249
|
+
const switched = parseBranchSuccess(receipt2.detail, verified.sessionId, verified.entryId);
|
|
9250
|
+
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";
|
|
9251
|
+
const refreshReceipt = await applyPeerControl(
|
|
9252
|
+
peer2.instanceId,
|
|
9253
|
+
"session.tree",
|
|
9254
|
+
{ page: 1, pageSize: TREE_PAGE_SIZE, filter: meta.filter },
|
|
9255
|
+
{ instanceId: peer2.instanceId, sessionId: peer2.sessionId }
|
|
9256
|
+
);
|
|
9257
|
+
const refreshed = refreshReceipt.ok ? parseTreePageReport(refreshReceipt.detail, peer2.sessionId) : void 0;
|
|
9258
|
+
if (refreshed) {
|
|
9259
|
+
return {
|
|
9260
|
+
handled: true,
|
|
9261
|
+
keyPrefix: "panel-tree-switched",
|
|
9262
|
+
clearIssuedBranch: true,
|
|
9263
|
+
spec: composeTreeListCard(peer2, refreshed, {
|
|
9264
|
+
inThread: opts.inThread,
|
|
9265
|
+
hideHome: opts.hideHome,
|
|
9266
|
+
from: meta.from,
|
|
9267
|
+
pinnedWorkerSessionId: opts.pinnedWorkerSessionId,
|
|
9268
|
+
banner
|
|
9269
|
+
})
|
|
9270
|
+
};
|
|
9271
|
+
}
|
|
9272
|
+
return {
|
|
9273
|
+
handled: true,
|
|
9274
|
+
keyPrefix: "panel-tree-switched",
|
|
9275
|
+
clearIssuedBranch: true,
|
|
9276
|
+
spec: {
|
|
9277
|
+
title: "\u{1F333} \u5206\u652F\u5DF2\u5207\u6362",
|
|
9278
|
+
color: "green",
|
|
9279
|
+
columnsPerRow: cols,
|
|
9280
|
+
body: banner,
|
|
9281
|
+
actions: [
|
|
9282
|
+
{ id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} \u67E5\u770B\u4F1A\u8BDD\u6811", payload: { page: 1, filter: meta.filter, from: meta.from } },
|
|
9283
|
+
...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9284
|
+
]
|
|
9285
|
+
}
|
|
9286
|
+
};
|
|
9287
|
+
}
|
|
9288
|
+
const branchMatch = /^panel\.tree\.branch\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9289
|
+
if (branchMatch) {
|
|
9290
|
+
if (!opts.canMutate) {
|
|
9291
|
+
return {
|
|
9292
|
+
handled: true,
|
|
9293
|
+
keyPrefix: "panel-tree-refused",
|
|
9294
|
+
refusedText: "\u26D4\uFE0F Switching session branch requires admin rights (panelAccess=allowUsers)."
|
|
9295
|
+
};
|
|
9296
|
+
}
|
|
9297
|
+
const peerRef2 = branchMatch[1];
|
|
9298
|
+
const peer2 = resolveTargetPeer(peerRef2);
|
|
9299
|
+
if (!peer2) {
|
|
9300
|
+
return { handled: true, keyPrefix: "panel-tree-offline", spec: offlineSpec(peerRef2) };
|
|
9301
|
+
}
|
|
9302
|
+
if (!meta.entryId) {
|
|
9303
|
+
return {
|
|
9304
|
+
handled: true,
|
|
9305
|
+
keyPrefix: "panel-tree-invalid-entry",
|
|
9306
|
+
spec: {
|
|
9307
|
+
title: "\u26A0\uFE0F \u65E0\u6548\u8282\u70B9",
|
|
9308
|
+
color: "red",
|
|
9309
|
+
columnsPerRow: cols,
|
|
9310
|
+
body: "\u7F3A\u5C11\u6709\u6548\u7684\u76EE\u6807\u8282\u70B9 ID\uFF0C\u8BF7\u4ECE\u4F1A\u8BDD\u6811\u5217\u8868\u91CD\u65B0\u9009\u62E9\u3002",
|
|
9311
|
+
actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
|
|
9312
|
+
}
|
|
9313
|
+
};
|
|
9314
|
+
}
|
|
9315
|
+
const receipt2 = await applyPeerControl(
|
|
9316
|
+
peer2.instanceId,
|
|
9317
|
+
"session.tree",
|
|
9318
|
+
{ entryId: meta.entryId },
|
|
9319
|
+
{ instanceId: peer2.instanceId, sessionId: peer2.sessionId }
|
|
9320
|
+
);
|
|
9321
|
+
const detail = receipt2.ok ? parseTreeEntryReport(receipt2.detail, peer2.sessionId) : void 0;
|
|
9322
|
+
if (!detail) {
|
|
9323
|
+
return {
|
|
9324
|
+
handled: true,
|
|
9325
|
+
keyPrefix: "panel-tree-entry-error",
|
|
9326
|
+
spec: {
|
|
9327
|
+
title: "\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u76EE\u6807\u8282\u70B9",
|
|
9328
|
+
color: "red",
|
|
9329
|
+
columnsPerRow: cols,
|
|
9330
|
+
body: formatPeerErrorDetail(receipt2.detail),
|
|
9331
|
+
actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
|
|
9332
|
+
}
|
|
9333
|
+
};
|
|
9334
|
+
}
|
|
9335
|
+
return {
|
|
9336
|
+
handled: true,
|
|
9337
|
+
keyPrefix: "panel-tree-branch-confirm",
|
|
9338
|
+
spec: composeTreeBranchConfirmCard(peer2, detail, {
|
|
9339
|
+
inThread: opts.inThread,
|
|
9340
|
+
hideHome: opts.hideHome,
|
|
9341
|
+
page: meta.page,
|
|
9342
|
+
filter: meta.filter,
|
|
9343
|
+
from: meta.from
|
|
9344
|
+
})
|
|
9345
|
+
};
|
|
9346
|
+
}
|
|
9347
|
+
const listMatch = /^panel\.tree\.([A-Za-z0-9-]+)$/.exec(panelCmd.cmd);
|
|
9348
|
+
const peerRef = listMatch?.[1];
|
|
9349
|
+
const peer = resolveTargetPeer(peerRef);
|
|
9350
|
+
if (!peer) {
|
|
9351
|
+
return { handled: true, keyPrefix: "panel-tree-offline", spec: offlineSpec(peerRef) };
|
|
9352
|
+
}
|
|
9353
|
+
const receipt = await applyPeerControl(
|
|
9354
|
+
peer.instanceId,
|
|
9355
|
+
"session.tree",
|
|
9356
|
+
{ page: meta.page, pageSize: TREE_PAGE_SIZE, filter: meta.filter },
|
|
9357
|
+
{ instanceId: peer.instanceId, sessionId: peer.sessionId }
|
|
9358
|
+
);
|
|
9359
|
+
const report = receipt.ok ? parseTreePageReport(receipt.detail, peer.sessionId) : void 0;
|
|
9360
|
+
if (!report) {
|
|
9361
|
+
return {
|
|
9362
|
+
handled: true,
|
|
9363
|
+
keyPrefix: "panel-tree-error",
|
|
9364
|
+
spec: {
|
|
9365
|
+
title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${peer.isManager ? "Manager" : workerDisplayTitle(peer)}`,
|
|
9366
|
+
color: "red",
|
|
9367
|
+
columnsPerRow: cols,
|
|
9368
|
+
body: formatPeerErrorDetail(receipt.detail),
|
|
9369
|
+
actions: [
|
|
9370
|
+
{ id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} \u91CD\u8BD5", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
|
|
9371
|
+
...backActionsFor(peer, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
|
|
9372
|
+
]
|
|
9373
|
+
}
|
|
9374
|
+
};
|
|
9375
|
+
}
|
|
9376
|
+
return {
|
|
9377
|
+
handled: true,
|
|
9378
|
+
keyPrefix: "panel-tree",
|
|
9379
|
+
spec: composeTreeListCard(peer, report, {
|
|
9380
|
+
inThread: opts.inThread,
|
|
9381
|
+
hideHome: opts.hideHome,
|
|
9382
|
+
from: meta.from,
|
|
9383
|
+
pinnedWorkerSessionId: opts.pinnedWorkerSessionId
|
|
9384
|
+
})
|
|
9385
|
+
};
|
|
9386
|
+
}
|
|
9387
|
+
|
|
8753
9388
|
// builtin/extensions/im-forward/panel-memory.ts
|
|
8754
9389
|
import * as fs18 from "node:fs";
|
|
8755
9390
|
import * as path20 from "node:path";
|
|
@@ -9292,6 +9927,7 @@ function createPanelCardState(ctx) {
|
|
|
9292
9927
|
const issuedWorkerCards = /* @__PURE__ */ new Map();
|
|
9293
9928
|
const issuedQuitCards = /* @__PURE__ */ new Map();
|
|
9294
9929
|
const issuedCronStopCards = /* @__PURE__ */ new Map();
|
|
9930
|
+
const issuedTreeBranchCards = /* @__PURE__ */ new Map();
|
|
9295
9931
|
const cardPatchChains = /* @__PURE__ */ new Map();
|
|
9296
9932
|
const cardNavGens = /* @__PURE__ */ new Map();
|
|
9297
9933
|
function rememberPanelCard(messageId, sessionId, chatId, thread) {
|
|
@@ -9364,6 +10000,11 @@ function createPanelCardState(ctx) {
|
|
|
9364
10000
|
clearIssuedCronStopCard: (messageId) => {
|
|
9365
10001
|
issuedCronStopCards.delete(messageId);
|
|
9366
10002
|
},
|
|
10003
|
+
getIssuedTreeBranchCard: (messageId) => issuedTreeBranchCards.get(messageId),
|
|
10004
|
+
setIssuedTreeBranchCard: (messageId, card) => putBounded(issuedTreeBranchCards, messageId, card),
|
|
10005
|
+
clearIssuedTreeBranchCard: (messageId) => {
|
|
10006
|
+
issuedTreeBranchCards.delete(messageId);
|
|
10007
|
+
},
|
|
9367
10008
|
enqueueCardPatch: (cardId, task) => {
|
|
9368
10009
|
const prev = cardPatchChains.get(cardId) ?? Promise.resolve();
|
|
9369
10010
|
const result = prev.then(task, task);
|
|
@@ -9386,6 +10027,7 @@ function createPanelCardState(ctx) {
|
|
|
9386
10027
|
issuedWorkerCards.clear();
|
|
9387
10028
|
issuedQuitCards.clear();
|
|
9388
10029
|
issuedCronStopCards.clear();
|
|
10030
|
+
issuedTreeBranchCards.clear();
|
|
9389
10031
|
peekCards.clear();
|
|
9390
10032
|
cardNavGens.clear();
|
|
9391
10033
|
}
|
|
@@ -9405,7 +10047,7 @@ function createPanelExecutor(ctx) {
|
|
|
9405
10047
|
const workerScoped = opts?.workerScoped === true || opts?.cardOrigin?.workerScoped === true || inThread && Boolean(pinnedThreadWorkerSession);
|
|
9406
10048
|
const hideHome = workerScoped || inThread;
|
|
9407
10049
|
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];
|
|
10050
|
+
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
10051
|
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
10052
|
const threadWorkerSessionId = workerScoped && pinnedThreadWorkerSession ? pinnedThreadWorkerSession : resolvedWorkerSession ?? pinnedThreadWorkerSession;
|
|
9411
10053
|
const sendReplyTo = inThread && threadReplyTo ? threadReplyTo : void 0;
|
|
@@ -9425,7 +10067,7 @@ function createPanelExecutor(ctx) {
|
|
|
9425
10067
|
...workerSession ? { threadWorkerSessionId: workerSession } : {}
|
|
9426
10068
|
};
|
|
9427
10069
|
};
|
|
9428
|
-
const applyIssuedCards = (cardMessageId, workerBinding, quitBinding, cronStopBinding) => {
|
|
10070
|
+
const applyIssuedCards = (cardMessageId, workerBinding, quitBinding, cronStopBinding, treeBranchBinding) => {
|
|
9429
10071
|
if (!cardMessageId) return;
|
|
9430
10072
|
if (workerBinding) ctx.cards.setIssuedWorkerCard(cardMessageId, workerBinding);
|
|
9431
10073
|
else ctx.cards.clearIssuedWorkerCard(cardMessageId);
|
|
@@ -9433,6 +10075,8 @@ function createPanelExecutor(ctx) {
|
|
|
9433
10075
|
else ctx.cards.clearIssuedQuitCard(cardMessageId);
|
|
9434
10076
|
if (cronStopBinding) ctx.cards.setIssuedCronStopCard(cardMessageId, cronStopBinding);
|
|
9435
10077
|
else ctx.cards.clearIssuedCronStopCard(cardMessageId);
|
|
10078
|
+
if (treeBranchBinding) ctx.cards.setIssuedTreeBranchCard(cardMessageId, treeBranchBinding);
|
|
10079
|
+
else ctx.cards.clearIssuedTreeBranchCard(cardMessageId);
|
|
9436
10080
|
};
|
|
9437
10081
|
const claimNavGen = () => {
|
|
9438
10082
|
if (!canPatchOrigin || !event.message_id) return void 0;
|
|
@@ -9445,6 +10089,7 @@ function createPanelExecutor(ctx) {
|
|
|
9445
10089
|
const plannedWorker = isCurrent() ? extractIssuedWorkerCard(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9446
10090
|
const plannedQuit = isCurrent() ? extractIssuedQuitCard(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9447
10091
|
const plannedCronStop = isCurrent() ? extractIssuedCronStop(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
10092
|
+
const plannedTreeBranch = isCurrent() ? extractIssuedTreeBranch(normalizedSpec, event.chat_id, sessionId, ctx.getInputEpoch()) : void 0;
|
|
9448
10093
|
if (patchInPlace && canPatchOrigin && event.message_id && ctx.connection.patch) {
|
|
9449
10094
|
const cardId = event.message_id;
|
|
9450
10095
|
if (expectedNavGen !== void 0 && ctx.cards.getCardNav(cardId) !== expectedNavGen) return;
|
|
@@ -9456,8 +10101,10 @@ function createPanelExecutor(ctx) {
|
|
|
9456
10101
|
ctx.cards.clearPeekCard(cardId);
|
|
9457
10102
|
const prevWorker = ctx.cards.getIssuedWorkerCard(cardId);
|
|
9458
10103
|
const prevQuit = ctx.cards.getIssuedQuitCard(cardId);
|
|
10104
|
+
const prevTreeBranch = ctx.cards.getIssuedTreeBranchCard(cardId);
|
|
9459
10105
|
if (plannedWorker) ctx.cards.setIssuedWorkerCard(cardId, plannedWorker);
|
|
9460
10106
|
if (plannedQuit) ctx.cards.setIssuedQuitCard(cardId, plannedQuit);
|
|
10107
|
+
if (plannedTreeBranch) ctx.cards.setIssuedTreeBranchCard(cardId, plannedTreeBranch);
|
|
9461
10108
|
const rollbackProvisional = () => {
|
|
9462
10109
|
if (plannedWorker && ctx.cards.getIssuedWorkerCard(cardId) === plannedWorker) {
|
|
9463
10110
|
if (isCurrent() && prevWorker) ctx.cards.setIssuedWorkerCard(cardId, prevWorker);
|
|
@@ -9467,13 +10114,17 @@ function createPanelExecutor(ctx) {
|
|
|
9467
10114
|
if (isCurrent() && prevQuit) ctx.cards.setIssuedQuitCard(cardId, prevQuit);
|
|
9468
10115
|
else ctx.cards.clearIssuedQuitCard(cardId);
|
|
9469
10116
|
}
|
|
10117
|
+
if (plannedTreeBranch && ctx.cards.getIssuedTreeBranchCard(cardId) === plannedTreeBranch) {
|
|
10118
|
+
if (isCurrent() && prevTreeBranch) ctx.cards.setIssuedTreeBranchCard(cardId, prevTreeBranch);
|
|
10119
|
+
else ctx.cards.clearIssuedTreeBranchCard(cardId);
|
|
10120
|
+
}
|
|
9470
10121
|
};
|
|
9471
10122
|
try {
|
|
9472
10123
|
const ok = await ctx.connection.patch(cardId, normalizedSpec);
|
|
9473
10124
|
if (ok) {
|
|
9474
10125
|
if (isCurrent()) {
|
|
9475
10126
|
ctx.cards.rememberPanelCard(cardId, sessionId, event.chat_id, threadMetaFor(cardId, keepWorkerSession));
|
|
9476
|
-
applyIssuedCards(cardId, plannedWorker, plannedQuit, plannedCronStop);
|
|
10127
|
+
applyIssuedCards(cardId, plannedWorker, plannedQuit, plannedCronStop, plannedTreeBranch);
|
|
9477
10128
|
} else {
|
|
9478
10129
|
rollbackProvisional();
|
|
9479
10130
|
}
|
|
@@ -9504,7 +10155,7 @@ function createPanelExecutor(ctx) {
|
|
|
9504
10155
|
const sent = await ctx.connection.sendCard(freshRecipient, normalizedSpec, key, sendReplyTo, sendOpts);
|
|
9505
10156
|
if (isCurrent()) {
|
|
9506
10157
|
ctx.cards.rememberPanelCard(sent?.messageId, sessionId, sent?.chatId ?? event.chat_id, threadMetaFor(sent?.messageId, keepWorkerSession));
|
|
9507
|
-
applyIssuedCards(sent?.messageId, plannedWorker, plannedQuit, plannedCronStop);
|
|
10158
|
+
applyIssuedCards(sent?.messageId, plannedWorker, plannedQuit, plannedCronStop, plannedTreeBranch);
|
|
9508
10159
|
}
|
|
9509
10160
|
ctx.log(sent?.messageId ? `im-forward: panel card sent (${panelCmd.cmd})` : `im-forward: panel card send failed (${panelCmd.cmd})`);
|
|
9510
10161
|
} else {
|
|
@@ -9522,13 +10173,22 @@ function createPanelExecutor(ctx) {
|
|
|
9522
10173
|
};
|
|
9523
10174
|
const payloadFromWorker = isRecord(panelCmd.payload) && panelCmd.payload.from === "worker" && typeof panelCmd.payload.peer === "string" ? panelCmd.payload.peer : void 0;
|
|
9524
10175
|
const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
|
|
9525
|
-
if (event.message_id && panelCmd.cmd.startsWith("panel.cron.stop.confirm.")) {
|
|
10176
|
+
if (event.message_id && (panelCmd.cmd.startsWith("panel.cron.stop.confirm.") || panelCmd.cmd.startsWith("panel.tree.branch.confirm."))) {
|
|
9526
10177
|
await ctx.cards.enqueueCardPatch(event.message_id, async () => void 0);
|
|
9527
10178
|
if (!isCurrent()) return;
|
|
9528
10179
|
}
|
|
9529
10180
|
const issuedQuitForGuard = event.message_id ? ctx.cards.getIssuedQuitCard(event.message_id) : void 0;
|
|
9530
10181
|
const issuedCronStopForGuard = event.message_id ? ctx.cards.getIssuedCronStopCard(event.message_id) : void 0;
|
|
9531
|
-
const
|
|
10182
|
+
const issuedTreeBranchForGuard = event.message_id ? ctx.cards.getIssuedTreeBranchCard(event.message_id) : void 0;
|
|
10183
|
+
const threadScopeCheck = guardThreadWorkerScope(
|
|
10184
|
+
panelCmd,
|
|
10185
|
+
workerScoped,
|
|
10186
|
+
inThread,
|
|
10187
|
+
pinnedThreadWorkerSession,
|
|
10188
|
+
issuedQuitForGuard?.targetSession,
|
|
10189
|
+
issuedCronStopForGuard?.sessionId,
|
|
10190
|
+
issuedTreeBranchForGuard?.sessionId
|
|
10191
|
+
);
|
|
9532
10192
|
if (threadScopeCheck.blocked) {
|
|
9533
10193
|
await deliverPanelSpec(threadScopeCheck.spec, `panel-thread-scope-${event.event_id}`, true);
|
|
9534
10194
|
return;
|
|
@@ -9643,6 +10303,40 @@ function createPanelExecutor(ctx) {
|
|
|
9643
10303
|
await deliverPanelSpec(memoryResult.spec, `${memoryResult.keyPrefix}-${event.event_id}`, true);
|
|
9644
10304
|
return;
|
|
9645
10305
|
}
|
|
10306
|
+
if (isTreePanelCommand(effectiveCmd.cmd)) {
|
|
10307
|
+
const canReadSensitive = peekAudienceAllowed(event);
|
|
10308
|
+
const canMutate = canMutatePanel();
|
|
10309
|
+
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;
|
|
10310
|
+
if (event.message_id && verifiedTreeBranch && canReadSensitive && canMutate && effectiveCmd.cmd.startsWith("panel.tree.branch.confirm.")) {
|
|
10311
|
+
ctx.cards.clearIssuedTreeBranchCard(event.message_id);
|
|
10312
|
+
}
|
|
10313
|
+
const navGen = claimNavGen();
|
|
10314
|
+
const treeResult = await runTreePanelCommand(effectiveCmd, {
|
|
10315
|
+
inThread,
|
|
10316
|
+
hideHome,
|
|
10317
|
+
workerScoped,
|
|
10318
|
+
pinnedWorkerSessionId: pinnedThreadWorkerSession,
|
|
10319
|
+
canReadSensitive,
|
|
10320
|
+
canMutate,
|
|
10321
|
+
verifiedBranch: verifiedTreeBranch
|
|
10322
|
+
});
|
|
10323
|
+
if (treeResult.handled) {
|
|
10324
|
+
if (!isCurrent()) return;
|
|
10325
|
+
if (treeResult.refusedText) {
|
|
10326
|
+
ctx.log(`im-forward: ${panelCmd.cmd} refused for ${event.sender_id ?? "unknown"} (panelAccess=allowUsers)`);
|
|
10327
|
+
try {
|
|
10328
|
+
await ctx.connection.send(freshRecipient, treeResult.refusedText, `panel-refused-${event.event_id}`, sendReplyTo, sendOpts);
|
|
10329
|
+
} catch {
|
|
10330
|
+
}
|
|
10331
|
+
return;
|
|
10332
|
+
}
|
|
10333
|
+
if (event.message_id && treeResult.clearIssuedBranch) {
|
|
10334
|
+
ctx.cards.clearIssuedTreeBranchCard(event.message_id);
|
|
10335
|
+
}
|
|
10336
|
+
if (treeResult.spec) await deliverPanelSpec(treeResult.spec, `${treeResult.keyPrefix}-${event.event_id}`, true, navGen);
|
|
10337
|
+
return;
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
9646
10340
|
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
10341
|
const cronResult = runCronPanelCommand(effectiveCmd, {
|
|
9648
10342
|
inThread,
|
|
@@ -10387,6 +11081,7 @@ function createInboundPipeline(deps) {
|
|
|
10387
11081
|
panelCards.clearIssuedWorkerCard(id);
|
|
10388
11082
|
panelCards.clearIssuedQuitCard(id);
|
|
10389
11083
|
panelCards.clearIssuedCronStopCard(id);
|
|
11084
|
+
panelCards.clearIssuedTreeBranchCard(id);
|
|
10390
11085
|
}
|
|
10391
11086
|
});
|
|
10392
11087
|
return;
|
|
@@ -10871,8 +11566,8 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
|
10871
11566
|
let drainTimer;
|
|
10872
11567
|
await Promise.race([
|
|
10873
11568
|
Promise.allSettled([...panelActionTasks]).then(() => void 0),
|
|
10874
|
-
new Promise((
|
|
10875
|
-
drainTimer = setTimeout(
|
|
11569
|
+
new Promise((resolve9) => {
|
|
11570
|
+
drainTimer = setTimeout(resolve9, ACTION_RETIRE_DRAIN_MS);
|
|
10876
11571
|
drainTimer.unref?.();
|
|
10877
11572
|
})
|
|
10878
11573
|
]);
|