@cydm/pie 4.15.2 → 4.15.4

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.
@@ -144,7 +144,7 @@ function formatIpcInputHeader(rawUserText) {
144
144
  const doneMatch = /^\[ipc-done\]\s+requestId=\S+(?:\s+outcome=(\S+))?[^\n]*(?:\n([\s\S]*))?$/.exec(body);
145
145
  if (doneMatch) {
146
146
  const outcome = doneMatch[1];
147
- tag = outcome && outcome !== "done" ? `IPC \u5B8C\u6210 (${outcome}) \xB7 ${fromPeer}` : `IPC \u5B8C\u6210 \xB7 ${fromPeer}`;
147
+ tag = outcome && outcome !== "done" ? `IPC Done (${outcome}) \xB7 ${fromPeer}` : `IPC Done \xB7 ${fromPeer}`;
148
148
  body = (doneMatch[2] ?? "").trim();
149
149
  }
150
150
  if (!body) return `> [${tag}]`;
@@ -1136,10 +1136,11 @@ var COLOR_TEMPLATE = {
1136
1136
  red: "red",
1137
1137
  violet: "violet"
1138
1138
  };
1139
- function buildButton(action, size) {
1139
+ function buildButton(action, size, fill) {
1140
1140
  return {
1141
1141
  tag: "button",
1142
1142
  ...size ? { size } : {},
1143
+ ...fill ? { width: "fill" } : {},
1143
1144
  text: { tag: "plain_text", content: action.label },
1144
1145
  type: action.style ?? "default",
1145
1146
  behaviors: [{
@@ -1224,18 +1225,38 @@ function compileCard(spec) {
1224
1225
  elements.push({ tag: "markdown", content: spec.footer, text_size: "notation" });
1225
1226
  }
1226
1227
  const perRow = spec.columnsPerRow ?? 3;
1228
+ const totalRows = Math.ceil(spec.actions.length / perRow);
1227
1229
  for (let i = 0; i < spec.actions.length; i += perRow) {
1228
1230
  const row = spec.actions.slice(i, i + perRow);
1229
- elements.push({
1230
- tag: "column_set",
1231
- flex_mode: "flow",
1232
- horizontal_spacing: "medium",
1233
- columns: row.map((action) => ({
1231
+ const makeCol = (action) => ({
1232
+ tag: "column",
1233
+ width: "weighted",
1234
+ weight: 1,
1235
+ elements: [buildButton(action, void 0, true)]
1236
+ });
1237
+ let columns;
1238
+ if (totalRows > 1 && row.length < perRow) {
1239
+ const startActions = row.filter((a) => a.align !== "end");
1240
+ const endActions = row.filter((a) => a.align === "end");
1241
+ const spacers = Array.from({ length: perRow - row.length }, () => ({
1234
1242
  tag: "column",
1235
1243
  width: "weighted",
1236
1244
  weight: 1,
1237
- elements: [buildButton(action)]
1238
- }))
1245
+ elements: []
1246
+ }));
1247
+ columns = [
1248
+ ...startActions.map(makeCol),
1249
+ ...spacers,
1250
+ ...endActions.map(makeCol)
1251
+ ];
1252
+ } else {
1253
+ columns = row.map(makeCol);
1254
+ }
1255
+ elements.push({
1256
+ tag: "column_set",
1257
+ flex_mode: "none",
1258
+ horizontal_spacing: "medium",
1259
+ columns
1239
1260
  });
1240
1261
  }
1241
1262
  const doc = {
@@ -1311,7 +1332,18 @@ function extractImageKey(content) {
1311
1332
  var SAFE_FEISHU_CHAT_ID = /^oc_[A-Za-z0-9_-]+$/;
1312
1333
  var SAFE_FEISHU_THREAD_ID = /^omt_[A-Za-z0-9_-]+$/;
1313
1334
  var SAFE_APPLINK_HOST = /^[a-z0-9.-]+$/i;
1314
- var FEISHU_THREAD_LATEST_POSITION = "9999999";
1335
+ function parseFeishuThreadPosition(value) {
1336
+ if (typeof value === "number") {
1337
+ return Number.isSafeInteger(value) && value >= 0 ? value : void 0;
1338
+ }
1339
+ if (typeof value === "string") {
1340
+ const trimmed = value.trim();
1341
+ if (!/^\d+$/.test(trimmed)) return void 0;
1342
+ const parsed = Number(trimmed);
1343
+ return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : void 0;
1344
+ }
1345
+ return void 0;
1346
+ }
1315
1347
  function formatFeishuThreadUrl(anchor) {
1316
1348
  const rawChat = typeof anchor.chatId === "string" && anchor.chatId ? anchor.chatId : typeof anchor.home === "string" && anchor.home ? anchor.home : "";
1317
1349
  const rawThread = typeof anchor.threadId === "string" ? anchor.threadId : "";
@@ -1320,7 +1352,264 @@ function formatFeishuThreadUrl(anchor) {
1320
1352
  const host = SAFE_APPLINK_HOST.test(rawHost) ? rawHost : "applink.feishu.cn";
1321
1353
  const encodedChat = encodeURIComponent(rawChat);
1322
1354
  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}`;
1355
+ const base = `https://${host}/client/thread/open?open_chat_id=${encodedChat}&open_thread_id=${encodedThread}&openchatid=${encodedChat}&openthreadid=${encodedThread}`;
1356
+ const pos = parseFeishuThreadPosition(anchor.threadPosition);
1357
+ return pos !== void 0 ? `${base}&thread_position=${pos}` : base;
1358
+ }
1359
+ function extractHttpLinkDestination(rawDest) {
1360
+ const trimmed = rawDest.trim();
1361
+ if (!trimmed) return void 0;
1362
+ let candidate;
1363
+ let rest;
1364
+ if (trimmed.startsWith("<")) {
1365
+ const closeAngle = trimmed.indexOf(">");
1366
+ if (closeAngle <= 1) return void 0;
1367
+ candidate = trimmed.slice(1, closeAngle);
1368
+ rest = trimmed.slice(closeAngle + 1).trim();
1369
+ } else {
1370
+ const ws = /\s/.exec(trimmed);
1371
+ if (ws) {
1372
+ candidate = trimmed.slice(0, ws.index);
1373
+ rest = trimmed.slice(ws.index).trim();
1374
+ } else {
1375
+ candidate = trimmed;
1376
+ rest = "";
1377
+ }
1378
+ }
1379
+ if (rest && !(/^"(?:\\.|[^"\\])*"$/.test(rest) || /^'(?:\\.|[^'\\])*'$/.test(rest) || /^\((?:\\.|[^)\\])*\)$/.test(rest))) {
1380
+ return void 0;
1381
+ }
1382
+ const unescaped = candidate.replace(/\\([()\\])/g, "$1");
1383
+ if (!/^https?:\/\/[^\s<>]+$/i.test(unescaped)) return void 0;
1384
+ return unescaped;
1385
+ }
1386
+ var MAX_LINK_DEST_SCAN = 2048;
1387
+ function indexParagraphDelimiters(text) {
1388
+ const codeSpanEnds = /* @__PURE__ */ new Map();
1389
+ const bracketEnds = /* @__PURE__ */ new Map();
1390
+ const runsByLen = /* @__PURE__ */ new Map();
1391
+ for (let i = 0; i < text.length; ) {
1392
+ const ch = text[i];
1393
+ if (ch === "\\" && i + 1 < text.length) {
1394
+ i += 2;
1395
+ continue;
1396
+ }
1397
+ if (ch === "`") {
1398
+ let run = 1;
1399
+ while (i + run < text.length && text[i + run] === "`") run++;
1400
+ let list = runsByLen.get(run);
1401
+ if (!list) {
1402
+ list = [];
1403
+ runsByLen.set(run, list);
1404
+ }
1405
+ list.push(i);
1406
+ i += run;
1407
+ continue;
1408
+ }
1409
+ i++;
1410
+ }
1411
+ const runCursor = /* @__PURE__ */ new Map();
1412
+ const bracketStack = [];
1413
+ for (let i = 0; i < text.length; ) {
1414
+ const ch = text[i];
1415
+ if (ch === "\\" && i + 1 < text.length) {
1416
+ i += 2;
1417
+ continue;
1418
+ }
1419
+ if (ch === "`") {
1420
+ let run = 1;
1421
+ while (i + run < text.length && text[i + run] === "`") run++;
1422
+ const list = runsByLen.get(run);
1423
+ let cursor = runCursor.get(run) ?? 0;
1424
+ while (list && cursor < list.length && list[cursor] <= i) cursor++;
1425
+ if (list && cursor < list.length) {
1426
+ const closePos = list[cursor];
1427
+ runCursor.set(run, cursor + 1);
1428
+ codeSpanEnds.set(i, closePos + run);
1429
+ i = closePos + run;
1430
+ continue;
1431
+ }
1432
+ runCursor.set(run, list?.length ?? 0);
1433
+ i += run;
1434
+ continue;
1435
+ }
1436
+ if (ch === "[") {
1437
+ bracketStack.push(i);
1438
+ } else if (ch === "]" && bracketStack.length > 0) {
1439
+ const openIdx = bracketStack.pop();
1440
+ bracketEnds.set(openIdx, i);
1441
+ }
1442
+ i++;
1443
+ }
1444
+ return { codeSpanEnds, bracketEnds };
1445
+ }
1446
+ function findLinkDestEnd(text, start, lastCloseParen) {
1447
+ if (start > lastCloseParen) return -1;
1448
+ const limit = Math.min(lastCloseParen + 1, start + MAX_LINK_DEST_SCAN);
1449
+ let depth = 0;
1450
+ let inQuote = null;
1451
+ let inAngle = false;
1452
+ let i = start;
1453
+ while (i < limit) {
1454
+ const ch = text[i];
1455
+ if (ch === "\n" || ch === "\r") return -1;
1456
+ if (ch === "\\" && i + 1 < limit) {
1457
+ i += 2;
1458
+ continue;
1459
+ }
1460
+ if (inQuote) {
1461
+ if (ch === inQuote) inQuote = null;
1462
+ i++;
1463
+ continue;
1464
+ }
1465
+ if (inAngle) {
1466
+ if (ch === ">") inAngle = false;
1467
+ i++;
1468
+ continue;
1469
+ }
1470
+ if (ch === "<" && depth === 0 && text.slice(start, i).trim() === "") {
1471
+ inAngle = true;
1472
+ i++;
1473
+ continue;
1474
+ }
1475
+ if ((ch === '"' || ch === "'") && depth === 0 && i > start && /\s/.test(text[i - 1])) {
1476
+ inQuote = ch;
1477
+ i++;
1478
+ continue;
1479
+ }
1480
+ if (ch === "(") {
1481
+ depth++;
1482
+ } else if (ch === ")") {
1483
+ if (depth === 0) return i;
1484
+ depth--;
1485
+ }
1486
+ i++;
1487
+ }
1488
+ return -1;
1489
+ }
1490
+ function rewriteParagraphPostLinks(para) {
1491
+ if (!para.includes("](") && !/<https?:\/\//i.test(para)) return para;
1492
+ const { codeSpanEnds, bracketEnds } = indexParagraphDelimiters(para);
1493
+ const lastCloseParen = para.lastIndexOf(")");
1494
+ let out = "";
1495
+ let i = 0;
1496
+ while (i < para.length) {
1497
+ const ch = para[i];
1498
+ if (ch === "\\" && i + 1 < para.length) {
1499
+ out += para.slice(i, i + 2);
1500
+ i += 2;
1501
+ continue;
1502
+ }
1503
+ if (ch === "`") {
1504
+ const spanEnd = codeSpanEnds.get(i);
1505
+ if (spanEnd !== void 0) {
1506
+ out += para.slice(i, spanEnd);
1507
+ i = spanEnd;
1508
+ } else {
1509
+ let run = 1;
1510
+ while (i + run < para.length && para[i + run] === "`") run++;
1511
+ out += para.slice(i, i + run);
1512
+ i += run;
1513
+ }
1514
+ continue;
1515
+ }
1516
+ if (ch === "!" && para[i + 1] === "[") {
1517
+ const altEnd = bracketEnds.get(i + 1);
1518
+ if (altEnd !== void 0 && para[altEnd + 1] === "(") {
1519
+ const destEnd = findLinkDestEnd(para, altEnd + 2, lastCloseParen);
1520
+ if (destEnd >= 0) {
1521
+ out += para.slice(i, destEnd + 1);
1522
+ i = destEnd + 1;
1523
+ continue;
1524
+ }
1525
+ }
1526
+ out += "![";
1527
+ i += 2;
1528
+ continue;
1529
+ }
1530
+ if (ch === "<") {
1531
+ const auto = /^<(https?:\/\/[^\s<>]+)>/i.exec(para.slice(i));
1532
+ if (auto) {
1533
+ out += auto[1];
1534
+ i += auto[0].length;
1535
+ continue;
1536
+ }
1537
+ }
1538
+ if (ch === "[") {
1539
+ const labelEnd = bracketEnds.get(i);
1540
+ if (labelEnd !== void 0 && para[labelEnd + 1] === "(") {
1541
+ const destEnd = findLinkDestEnd(para, labelEnd + 2, lastCloseParen);
1542
+ if (destEnd >= 0) {
1543
+ const rawDest = para.slice(labelEnd + 2, destEnd);
1544
+ const url = extractHttpLinkDestination(rawDest);
1545
+ if (url) {
1546
+ const rawLabel = para.slice(i + 1, labelEnd).trim();
1547
+ const plainLabel = rawLabel.replace(/^[`*_\s]+|[`*_\s]+$/g, "");
1548
+ if (!plainLabel || plainLabel === url) {
1549
+ out += url;
1550
+ } else {
1551
+ out += `${rawLabel} ( ${url} )`;
1552
+ }
1553
+ i = destEnd + 1;
1554
+ continue;
1555
+ }
1556
+ out += para.slice(i, destEnd + 1);
1557
+ i = destEnd + 1;
1558
+ continue;
1559
+ }
1560
+ }
1561
+ }
1562
+ out += ch;
1563
+ i++;
1564
+ }
1565
+ return out;
1566
+ }
1567
+ function leadingIndentColumns(line) {
1568
+ let cols = 0;
1569
+ for (const ch of line) {
1570
+ if (ch === " ") cols += 1;
1571
+ else if (ch === " ") cols = 4 * Math.ceil((cols + 1) / 4);
1572
+ else break;
1573
+ }
1574
+ return cols;
1575
+ }
1576
+ function preserveFeishuPostMarkdownLinks(markdown) {
1577
+ if (!markdown || !markdown.includes("](") && !/<https?:\/\//i.test(markdown)) {
1578
+ return markdown;
1579
+ }
1580
+ const rawLines = markdown.split("\n");
1581
+ const scan = scanFenceLines(markdown.includes("\r") ? markdown.replace(/\r\n/g, "\n") : markdown);
1582
+ const outLines = [];
1583
+ let changed = false;
1584
+ let i = 0;
1585
+ while (i < rawLines.length) {
1586
+ const inFence = scan.stateAtLineStart[i] !== null || scan.openedBy[i] !== null || scan.closedBy[i] !== null;
1587
+ const trimmed = rawLines[i].trim();
1588
+ if (inFence || trimmed === "") {
1589
+ outLines.push(rawLines[i]);
1590
+ i++;
1591
+ continue;
1592
+ }
1593
+ const start = i;
1594
+ while (i < rawLines.length) {
1595
+ const f = scan.stateAtLineStart[i] !== null || scan.openedBy[i] !== null || scan.closedBy[i] !== null;
1596
+ if (f || rawLines[i].trim() === "") break;
1597
+ i++;
1598
+ }
1599
+ const blockLines = rawLines.slice(start, i);
1600
+ const precededByBlankOrStart = start === 0 || rawLines[start - 1].trim() === "";
1601
+ const startsWithListMarker = /^\s*(?:[-*+]|\d{1,9}[.)])(?:\s|$)/.test(blockLines[0]);
1602
+ const isIndentedCodeBlock = precededByBlankOrStart && !startsWithListMarker && blockLines.every((l) => leadingIndentColumns(l) >= 4);
1603
+ if (isIndentedCodeBlock) {
1604
+ outLines.push(...blockLines);
1605
+ continue;
1606
+ }
1607
+ const joined = blockLines.join("\n");
1608
+ const rewritten = rewriteParagraphPostLinks(joined);
1609
+ if (rewritten !== joined) changed = true;
1610
+ outLines.push(...rewritten.split("\n"));
1611
+ }
1612
+ return changed ? outLines.join("\n") : markdown;
1324
1613
  }
1325
1614
 
1326
1615
  // builtin/extensions/im-forward/providers/feishu/setup.ts
@@ -2115,8 +2404,10 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
2115
2404
  const recipient = targetKind === "user" ? ["--user-id", target] : ["--chat-id", target];
2116
2405
  const boundedKey = boundIdempotencyKey(key);
2117
2406
  const threadFlag = options?.replyInThread ? ["--reply-in-thread"] : [];
2118
- const data = await call(replyTo ? ["im", "+messages-reply", "--as", "bot", "--message-id", replyTo, "--markdown", text, ...threadFlag, "--idempotency-key", boundedKey] : ["im", "+messages-send", "--as", "bot", ...recipient, "--markdown", text, "--idempotency-key", boundedKey]);
2119
- 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;
2407
+ const markdown = preserveFeishuPostMarkdownLinks(text);
2408
+ const data = await call(replyTo ? ["im", "+messages-reply", "--as", "bot", "--message-id", replyTo, "--markdown", markdown, ...threadFlag, "--idempotency-key", boundedKey] : ["im", "+messages-send", "--as", "bot", ...recipient, "--markdown", markdown, "--idempotency-key", boundedKey]);
2409
+ const threadPosition = parseFeishuThreadPosition(data?.thread_message_position);
2410
+ 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 } : {}, ...threadPosition !== void 0 ? { threadPosition } : {} } : null;
2120
2411
  },
2121
2412
  async sendFile(target, file, key, replyTo, options) {
2122
2413
  const recipient = targetKind === "user" ? ["--user-id", target] : ["--chat-id", target];
@@ -2134,7 +2425,8 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
2134
2425
  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
2426
  fileCwd
2136
2427
  );
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;
2428
+ const threadPosition = parseFeishuThreadPosition(data?.thread_message_position);
2429
+ 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 } : {}, ...threadPosition !== void 0 ? { threadPosition } : {} } : null;
2138
2430
  },
2139
2431
  // 4.3.10 panel cards: compile the neutral CardSpec and send it as an
2140
2432
  // interactive message. The card JSON is provider-private output of
@@ -2145,7 +2437,8 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
2145
2437
  const content = JSON.stringify(compileCard(spec));
2146
2438
  const threadFlag = options?.replyInThread ? ["--reply-in-thread"] : [];
2147
2439
  const data = await call(replyTo ? ["im", "+messages-reply", "--as", "bot", "--message-id", replyTo, "--msg-type", "interactive", "--content", content, ...threadFlag, "--idempotency-key", boundedKey] : ["im", "+messages-send", "--as", "bot", ...recipient, "--msg-type", "interactive", "--content", content, "--idempotency-key", boundedKey]);
2148
- 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;
2440
+ const threadPosition = parseFeishuThreadPosition(data?.thread_message_position);
2441
+ 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 } : {}, ...threadPosition !== void 0 ? { threadPosition } : {} } : null;
2149
2442
  },
2150
2443
  // 4.3.10: patch an existing card in place (admin panels refresh without
2151
2444
  // re-sending). Feishu bound: the message must be <14 days old. Transient
@@ -2183,7 +2476,8 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
2183
2476
  async openTopic(_target, rootMessageId, key) {
2184
2477
  const boundedKey = boundIdempotencyKey(key);
2185
2478
  const data = await call(["im", "+messages-reply", "--as", "bot", "--message-id", rootMessageId, "--markdown", "\xB7", "--reply-in-thread", "--idempotency-key", boundedKey]);
2186
- 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;
2479
+ const threadPosition = parseFeishuThreadPosition(data?.thread_message_position);
2480
+ 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 } : {}, ...threadPosition !== void 0 ? { threadPosition } : {} } : null;
2187
2481
  },
2188
2482
  async acknowledge(id) {
2189
2483
  await call(["im", "reactions", "create", "--as", "bot", "--params", JSON.stringify({ message_id: id }), "--data", JSON.stringify({ reaction_type: { emoji_type: "THUMBSUP" } })]);
@@ -2217,12 +2511,40 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
2217
2511
  async metadata(id) {
2218
2512
  const data = await call(["im", "+messages-mget", "--as", "bot", "--message-ids", id]);
2219
2513
  const message = Array.isArray(data?.messages) ? data.messages[0] : void 0;
2514
+ const threadPosition = isRecord(message) ? parseFeishuThreadPosition(message.thread_message_position) : void 0;
2220
2515
  return isRecord(message) ? {
2221
2516
  threadId: typeof message.thread_id === "string" && message.thread_id || null,
2222
2517
  replyTo: typeof message.reply_to === "string" && message.reply_to || typeof message.root_id === "string" && message.root_id || null,
2223
- ...typeof message.chat_id === "string" && message.chat_id ? { chatId: message.chat_id } : {}
2518
+ ...typeof message.chat_id === "string" && message.chat_id ? { chatId: message.chat_id } : {},
2519
+ ...threadPosition !== void 0 ? { threadPosition } : {}
2224
2520
  } : null;
2225
2521
  },
2522
+ async latestThreadPosition(threadId, anchorMessageId, signal) {
2523
+ if (lifetime.signal.aborted || signal?.aborted) return null;
2524
+ const combined = signal ? AbortSignal.any([lifetime.signal, signal]) : lifetime.signal;
2525
+ const listArgs = ["im", "+threads-messages-list", "--as", "bot", "--thread", threadId, "--order", "desc", "--page-size", "1", "--no-reactions"];
2526
+ const result = await native(binary, profile ? [...listArgs, "--profile", profile] : listArgs, 3e3, void 0, { signal: combined });
2527
+ if (!result.error) {
2528
+ const data = parseLarkCliEnvelope(result.stdout).data;
2529
+ const latest = Array.isArray(data?.messages) ? data.messages[0] : void 0;
2530
+ const pos = isRecord(latest) ? parseFeishuThreadPosition(latest.thread_message_position) : void 0;
2531
+ if (pos !== void 0) return pos;
2532
+ return null;
2533
+ }
2534
+ if (anchorMessageId && !combined.aborted && /230027|user_unauthorized|authorization|permission/i.test(result.error)) {
2535
+ const mgetArgs = ["im", "+messages-mget", "--as", "bot", "--message-ids", anchorMessageId];
2536
+ const mgetRes = await native(binary, profile ? [...mgetArgs, "--profile", profile] : mgetArgs, 2500, void 0, { signal: combined });
2537
+ if (!mgetRes.error) {
2538
+ const meta = parseLarkCliEnvelope(mgetRes.stdout).data;
2539
+ const msg = Array.isArray(meta?.messages) ? meta.messages[0] : void 0;
2540
+ if (isRecord(msg) && (typeof msg.thread_id !== "string" || !msg.thread_id || msg.thread_id === threadId)) {
2541
+ const pos = parseFeishuThreadPosition(msg.thread_message_position);
2542
+ if (pos !== void 0) return pos;
2543
+ }
2544
+ }
2545
+ }
2546
+ return null;
2547
+ },
2226
2548
  async threadMessages(id) {
2227
2549
  const args = ["im", "+threads-messages-list", "--as", "bot", "--thread", id];
2228
2550
  const result = await native(binary, profile ? [...args, "--profile", profile] : args, 3e4, void 0, { signal: lifetime.signal });
@@ -2599,6 +2921,18 @@ function findImplementedProvider(id) {
2599
2921
  }
2600
2922
 
2601
2923
  // builtin/extensions/im-forward/session-anchors.ts
2924
+ function normalizeThreadPosition(value) {
2925
+ if (typeof value === "number") {
2926
+ return Number.isSafeInteger(value) && value >= 0 ? value : void 0;
2927
+ }
2928
+ if (typeof value === "string") {
2929
+ const trimmed = value.trim();
2930
+ if (!/^\d+$/.test(trimmed)) return void 0;
2931
+ const parsed = Number(trimmed);
2932
+ return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : void 0;
2933
+ }
2934
+ return void 0;
2935
+ }
2602
2936
  function anchorsDir() {
2603
2937
  return path8.join(addressBookRoot(), "im-forward", "anchors");
2604
2938
  }
@@ -2606,6 +2940,45 @@ function anchorPath(sessionId) {
2606
2940
  const safe = sessionId.replace(/[^a-zA-Z0-9._-]/g, "_");
2607
2941
  return path8.join(anchorsDir(), `${safe}.json`);
2608
2942
  }
2943
+ function positionHintPath(sessionId) {
2944
+ const safe = sessionId.replace(/[^A-Za-z0-9_.-]/g, "_");
2945
+ return path8.join(anchorsDir(), "positions", `${safe}.json`);
2946
+ }
2947
+ function readPositionHint(sessionId, provider, threadId) {
2948
+ if (!threadId) return void 0;
2949
+ try {
2950
+ const raw = fs6.readFileSync(positionHintPath(sessionId), "utf8");
2951
+ const parsed = JSON.parse(raw);
2952
+ if (parsed.provider !== provider || parsed.threadId !== threadId) return void 0;
2953
+ return normalizeThreadPosition(parsed.threadPosition);
2954
+ } catch {
2955
+ return void 0;
2956
+ }
2957
+ }
2958
+ function resolveMergedThreadPosition(sessionId, provider, anchor) {
2959
+ const inlinePos = normalizeThreadPosition(anchor.threadPosition);
2960
+ const sidecarPos = readPositionHint(sessionId, provider, anchor.threadId);
2961
+ if (inlinePos === void 0) return sidecarPos;
2962
+ if (sidecarPos === void 0) return inlinePos;
2963
+ return Math.max(inlinePos, sidecarPos);
2964
+ }
2965
+ function writeJsonFileAtomically(target, data) {
2966
+ fs6.mkdirSync(path8.dirname(target), { recursive: true });
2967
+ const payload = `${JSON.stringify(data)}
2968
+ `;
2969
+ const tmp = `${target}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
2970
+ try {
2971
+ fs6.writeFileSync(tmp, payload, "utf8");
2972
+ fs6.renameSync(tmp, target);
2973
+ return true;
2974
+ } catch {
2975
+ try {
2976
+ fs6.rmSync(tmp, { force: true });
2977
+ } catch {
2978
+ }
2979
+ return false;
2980
+ }
2981
+ }
2609
2982
  function loadPersistedAnchor(sessionId, identity) {
2610
2983
  try {
2611
2984
  const raw = fs6.readFileSync(anchorPath(sessionId), "utf8");
@@ -2617,11 +2990,13 @@ function loadPersistedAnchor(sessionId, identity) {
2617
2990
  // DM root on restart). The provider check stays: a re-bound app is a
2618
2991
  // different home entirely.
2619
2992
  (parsed.targetId === identity.targetId || typeof parsed.anchor.home === "string")) {
2993
+ const threadPosition = resolveMergedThreadPosition(sessionId, parsed.provider, parsed.anchor);
2620
2994
  return {
2621
2995
  messageId: parsed.anchor.messageId,
2622
2996
  ...typeof parsed.anchor.threadId === "string" && parsed.anchor.threadId ? { threadId: parsed.anchor.threadId } : {},
2623
2997
  ...typeof parsed.anchor.home === "string" && parsed.anchor.home ? { home: parsed.anchor.home } : {},
2624
2998
  ...typeof parsed.anchor.chatId === "string" && parsed.anchor.chatId ? { chatId: parsed.anchor.chatId } : {},
2999
+ ...threadPosition !== void 0 ? { threadPosition } : {},
2625
3000
  at: parsed.anchor.at
2626
3001
  };
2627
3002
  }
@@ -2632,25 +3007,139 @@ function loadPersistedAnchor(sessionId, identity) {
2632
3007
  }
2633
3008
  function savePersistedAnchor(sessionId, identity, anchor) {
2634
3009
  try {
3010
+ const target = anchorPath(sessionId);
3011
+ const incomingPos = normalizeThreadPosition(anchor.threadPosition);
3012
+ let mergedPos = incomingPos;
3013
+ let threadChanged = false;
3014
+ try {
3015
+ const prevRaw = fs6.readFileSync(target, "utf8");
3016
+ const prev = JSON.parse(prevRaw);
3017
+ if (prev.provider === identity.provider && anchor.threadId && prev.anchor?.threadId === anchor.threadId) {
3018
+ const prevPos = resolveMergedThreadPosition(sessionId, identity.provider, prev.anchor);
3019
+ if (prevPos !== void 0) {
3020
+ mergedPos = incomingPos !== void 0 ? Math.max(prevPos, incomingPos) : prevPos;
3021
+ }
3022
+ } else if (prev.anchor?.threadId && prev.anchor.threadId !== anchor.threadId) {
3023
+ threadChanged = true;
3024
+ }
3025
+ } catch {
3026
+ }
3027
+ const cleanAnchor = {
3028
+ messageId: anchor.messageId,
3029
+ ...anchor.threadId ? { threadId: anchor.threadId } : {},
3030
+ ...anchor.home ? { home: anchor.home } : {},
3031
+ ...anchor.chatId ? { chatId: anchor.chatId } : {},
3032
+ ...mergedPos !== void 0 ? { threadPosition: mergedPos } : {},
3033
+ at: anchor.at
3034
+ };
2635
3035
  const file = {
2636
3036
  provider: identity.provider,
2637
3037
  targetId: identity.targetId,
2638
- anchor
3038
+ anchor: cleanAnchor
2639
3039
  };
2640
- const target = anchorPath(sessionId);
2641
- fs6.mkdirSync(path8.dirname(target), { recursive: true });
2642
- fs6.writeFileSync(target, `${JSON.stringify(file)}
2643
- `, "utf8");
3040
+ writeJsonFileAtomically(target, file);
3041
+ if (anchor.threadId && mergedPos !== void 0) {
3042
+ const hint = { provider: identity.provider, threadId: anchor.threadId, threadPosition: mergedPos };
3043
+ writeJsonFileAtomically(positionHintPath(sessionId), hint);
3044
+ } else if (threadChanged || !anchor.threadId) {
3045
+ try {
3046
+ fs6.rmSync(positionHintPath(sessionId), { force: true });
3047
+ } catch {
3048
+ }
3049
+ }
2644
3050
  } catch {
2645
3051
  }
2646
3052
  }
3053
+ function updatePersistedAnchorThreadPosition(sessionId, provider, threadId, threadPosition) {
3054
+ const pos = normalizeThreadPosition(threadPosition);
3055
+ if (!sessionId || !provider || !threadId || pos === void 0) return false;
3056
+ try {
3057
+ const raw = fs6.readFileSync(anchorPath(sessionId), "utf8");
3058
+ const parsed = JSON.parse(raw);
3059
+ if (parsed.provider !== provider || typeof parsed.targetId !== "string" || !parsed.anchor || parsed.anchor.threadId !== threadId || typeof parsed.anchor.messageId !== "string" || !parsed.anchor.messageId || typeof parsed.anchor.at !== "number") {
3060
+ return false;
3061
+ }
3062
+ const prevPos = resolveMergedThreadPosition(sessionId, provider, parsed.anchor);
3063
+ if (prevPos !== void 0 && pos <= prevPos) return false;
3064
+ const hint = { provider, threadId, threadPosition: pos };
3065
+ return writeJsonFileAtomically(positionHintPath(sessionId), hint);
3066
+ } catch {
3067
+ return false;
3068
+ }
3069
+ }
3070
+ var inFlightPositionLookups = /* @__PURE__ */ new Map();
3071
+ async function refreshAnchorThreadPositions(sessionIds, provider, lookup, opts = {}) {
3072
+ const unique = [...new Set(sessionIds.filter((s) => typeof s === "string" && s.length > 0))];
3073
+ if (unique.length === 0) return;
3074
+ const maxTargets = typeof opts.maxTargets === "number" && opts.maxTargets > 0 ? Math.min(opts.maxTargets, 24) : 12;
3075
+ const targets = [];
3076
+ for (const sessionId of unique) {
3077
+ if (targets.length >= maxTargets) break;
3078
+ try {
3079
+ const raw = fs6.readFileSync(anchorPath(sessionId), "utf8");
3080
+ const parsed = JSON.parse(raw);
3081
+ if (parsed.provider !== provider || !parsed.anchor?.threadId) continue;
3082
+ const existingPos = resolveMergedThreadPosition(sessionId, provider, parsed.anchor);
3083
+ if (!opts.force && existingPos !== void 0) continue;
3084
+ targets.push({
3085
+ sessionId,
3086
+ threadId: parsed.anchor.threadId,
3087
+ ...typeof parsed.anchor.messageId === "string" && parsed.anchor.messageId ? { messageId: parsed.anchor.messageId } : {}
3088
+ });
3089
+ } catch {
3090
+ }
3091
+ }
3092
+ if (targets.length === 0) return;
3093
+ const timeoutMs = typeof opts.timeoutMs === "number" && opts.timeoutMs > 0 ? opts.timeoutMs : 1500;
3094
+ const concurrency = typeof opts.concurrency === "number" && opts.concurrency > 0 ? Math.min(opts.concurrency, 8) : 4;
3095
+ const controller = new AbortController();
3096
+ let timer;
3097
+ const deadline = new Promise((resolve9) => {
3098
+ timer = setTimeout(() => {
3099
+ controller.abort();
3100
+ resolve9();
3101
+ }, timeoutMs);
3102
+ timer.unref?.();
3103
+ });
3104
+ let cursor = 0;
3105
+ const worker = async () => {
3106
+ while (!controller.signal.aborted) {
3107
+ const idx = cursor++;
3108
+ if (idx >= targets.length) return;
3109
+ const item = targets[idx];
3110
+ const dedupKey = `${provider}:${item.threadId}`;
3111
+ let pending = inFlightPositionLookups.get(dedupKey);
3112
+ if (!pending) {
3113
+ pending = Promise.resolve().then(() => lookup(item.threadId, item.messageId, controller.signal)).catch(() => null).finally(() => {
3114
+ if (inFlightPositionLookups.get(dedupKey) === pending) {
3115
+ inFlightPositionLookups.delete(dedupKey);
3116
+ }
3117
+ });
3118
+ inFlightPositionLookups.set(dedupKey, pending);
3119
+ }
3120
+ const pos = await pending;
3121
+ if (pos !== null && pos !== void 0) {
3122
+ updatePersistedAnchorThreadPosition(item.sessionId, provider, item.threadId, pos);
3123
+ }
3124
+ }
3125
+ };
3126
+ const workers = Array.from({ length: Math.min(concurrency, targets.length) }, () => worker());
3127
+ try {
3128
+ await Promise.race([Promise.allSettled(workers), deadline]);
3129
+ } finally {
3130
+ if (timer) clearTimeout(timer);
3131
+ controller.abort();
3132
+ }
3133
+ }
2647
3134
  function resolveSessionThreadUrl(sessionId) {
2648
3135
  if (!sessionId) return void 0;
2649
3136
  try {
2650
3137
  const raw = fs6.readFileSync(anchorPath(sessionId), "utf8");
2651
3138
  const parsed = JSON.parse(raw);
2652
3139
  if (typeof parsed.provider !== "string" || !parsed.anchor) return void 0;
2653
- return findImplementedProvider(parsed.provider)?.formatThreadUrl?.(parsed.anchor);
3140
+ const threadPosition = resolveMergedThreadPosition(sessionId, parsed.provider, parsed.anchor);
3141
+ const anchorWithPos = threadPosition !== void 0 ? { ...parsed.anchor, threadPosition } : { ...parsed.anchor, threadPosition: void 0 };
3142
+ return findImplementedProvider(parsed.provider)?.formatThreadUrl?.(anchorWithPos);
2654
3143
  } catch {
2655
3144
  return void 0;
2656
3145
  }
@@ -2727,7 +3216,7 @@ function createRuntimeRoutes(ctx) {
2727
3216
  if (live) return { messageId: live.messageId, threadId: live.threadId };
2728
3217
  return { threadId: null };
2729
3218
  }
2730
- function persistSessionAnchor(sessionId, messageId, threadId, home, chatId) {
3219
+ function persistSessionAnchor(sessionId, messageId, threadId, home, chatId, threadPosition) {
2731
3220
  if (threadId) persistedAnchorsLoaded.add(sessionId);
2732
3221
  replyAnchor.set(sessionId, { messageId, threadId, at: Date.now() });
2733
3222
  const resolvedChatId = chatId || (ctx.targetKind !== "user" && home ? home : void 0);
@@ -2737,6 +3226,7 @@ function createRuntimeRoutes(ctx) {
2737
3226
  ...threadId ? { threadId } : {},
2738
3227
  ...home ? { home } : {},
2739
3228
  ...resolvedChatId ? { chatId: resolvedChatId } : {},
3229
+ ...threadPosition !== void 0 ? { threadPosition } : {},
2740
3230
  at: Date.now()
2741
3231
  });
2742
3232
  } catch (error) {
@@ -3253,10 +3743,10 @@ Malformed verified Peek response.`;
3253
3743
  if (turnEntries.length > 0) {
3254
3744
  const meta = parsePeekMeta(receipt);
3255
3745
  const modelTag = typeof report.model === "string" && report.model ? ` \xB7 \`${cleanCodeSpan(report.model, 56)}\`` : "";
3256
- const pageTag = meta.totalPages > 1 ? ` \xB7 \u7B2C ${meta.page}/${meta.totalPages} \u9875` : "";
3746
+ const pageTag = meta.totalPages > 1 ? ` \xB7 Page ${meta.page}/${meta.totalPages}` : "";
3257
3747
  const header = `**Live status:** ${report.active ? "working" : "idle"}${modelTag} \xB7 snapshot ${age(report.generatedAt)}${report.active && report.startedAt ? ` \xB7 active ${age(report.startedAt)}` : ""}${pageTag}`;
3258
3748
  const blocks = turnEntries.map((e) => {
3259
- const roleLabel = e.role === "user" ? e.tag === "ipc-done" ? "\u{1F4E8} Worker \u56DE\u62A5" : e.tag === "ipc-check" ? "\u23F1 \u8FDB\u5EA6\u68C0\u67E5" : "\u{1F464} \u7528\u6237" : e.tag === "error" ? "\u26A0\uFE0F \u52A9\u624B\uFF08\u9519\u8BEF\uFF09" : e.tag === "aborted" ? "\u23F9 \u52A9\u624B\uFF08\u5DF2\u4E2D\u6B62\uFF09" : "\u{1F916} \u52A9\u624B";
3749
+ const roleLabel = e.role === "user" ? e.tag === "ipc-done" ? "\u{1F4E8} Worker Report" : e.tag === "ipc-check" ? "\u23F1 Progress Check" : "\u{1F464} User" : e.tag === "error" ? "\u26A0\uFE0F Assistant (error)" : e.tag === "aborted" ? "\u23F9 Assistant (aborted)" : "\u{1F916} Assistant";
3260
3750
  const when = typeof e.at === "number" ? ` \xB7 ${age(e.at)}` : "";
3261
3751
  return `**${roleLabel}${when}**
3262
3752
  ${e.text}`;
@@ -3264,17 +3754,17 @@ ${e.text}`;
3264
3754
  const sections = [header, ...blocks];
3265
3755
  if (report.active && meta.page === 1 && items.length > 0) {
3266
3756
  const lastTurnAssistant = [...turnEntries].reverse().find((e) => e.role === "assistant")?.text;
3267
- const liveLines = items.filter((i) => !(i.kind === "assistant" && i.text === lastTurnAssistant)).map((i) => i.kind === "tool" ? `- \u{1F527} ${age(i.at)} \xB7 ${i.text}` : `**\u26A1 \u5B9E\u65F6\u8F93\u51FA \xB7 ${age(i.at)}**
3757
+ const liveLines = items.filter((i) => !(i.kind === "assistant" && i.text === lastTurnAssistant)).map((i) => i.kind === "tool" ? `- \u{1F527} ${age(i.at)} \xB7 ${i.text}` : `**\u26A1 Live Output \xB7 ${age(i.at)}**
3268
3758
  ${i.text}`);
3269
3759
  if (liveLines.length > 0) {
3270
3760
  sections.push(`---
3271
- **\u26A1 \u5F53\u524D\u6267\u884C\u4E2D**
3761
+ **\u26A1 Running Now**
3272
3762
  ${liveLines.join("\n\n")}`);
3273
3763
  }
3274
3764
  }
3275
3765
  const budget = typeof report.turns?.charBudget === "number" ? report.turns.charBudget : 1e3;
3276
3766
  const total = typeof report.turns?.totalEntries === "number" ? report.turns.totalEntries : turnEntries.length;
3277
- sections.push(`_Calm \u6B63\u6587\u5FEB\u7167\uFF08\u7EA6 ${budget} \u5B57/\u9875\uFF0C\u5171 ${total} \u6761\u6B63\u6587\uFF09\xB7 \u4E0D\u542B thinking \u4E0E\u5DE5\u5177\u8BE6\u60C5_`);
3767
+ sections.push(`_Calm text snapshot (~${budget} chars/page, ${total} entries) \xB7 thinking & tool details omitted_`);
3278
3768
  return sections.join("\n\n");
3279
3769
  }
3280
3770
  const live = items.map((i) => i.kind === "tool" ? `- \u{1F527} ${age(i.at)} \xB7 ${i.text}` : `**Assistant activity \xB7 ${age(i.at)}**
@@ -4490,7 +4980,7 @@ function createOutboundRuntime(deps) {
4490
4980
  const { ctx, cfg, connection, isManager, routeState, isForwardingEnabled, isTerminated, getCurrentSessionId, getInputEpoch, handleInboundEvent } = deps;
4491
4981
  const IM_INPUT_PREFIX = connection.sourcePrefix;
4492
4982
  const resolveSessionAnchor = (sessionId) => routeState.resolveSessionAnchor(sessionId);
4493
- const persistSessionAnchor = (sessionId, messageId, threadId, home, chatId) => routeState.persistSessionAnchor(sessionId, messageId, threadId, home, chatId);
4983
+ const persistSessionAnchor = (sessionId, messageId, threadId, home, chatId, threadPosition) => routeState.persistSessionAnchor(sessionId, messageId, threadId, home, chatId, threadPosition);
4494
4984
  let forwardCounter = 0;
4495
4985
  const incarnation = crypto.randomUUID();
4496
4986
  let anchorFallbacks = 0;
@@ -4808,11 +5298,13 @@ ${recoveryHint}`,
4808
5298
  settleDelivery(deliverRequests, true);
4809
5299
  markSettled?.();
4810
5300
  registerRoute(sent, sessionId);
5301
+ let lastThreadSent = sent;
4811
5302
  const legacyUpgrade = !isManager && anchor !== void 0 && !sessionAnchor.threadId && sent.messageId !== anchor;
4812
5303
  const stakeNeeded = stakeFlightToken !== void 0;
4813
5304
  if (stakeNeeded) {
4814
5305
  try {
4815
5306
  let threadId = sent.threadId, anchorChatId = sent.chatId ?? null;
5307
+ let threadPos = sent.threadPosition;
4816
5308
  if (!threadId && connection.openTopic) {
4817
5309
  const opener = await providerCall(
4818
5310
  "thread opener",
@@ -4820,14 +5312,19 @@ ${recoveryHint}`,
4820
5312
  );
4821
5313
  threadId = opener?.threadId ?? null;
4822
5314
  anchorChatId ??= opener?.chatId ?? null;
4823
- if (opener) registerRoute(opener, sessionId);
5315
+ threadPos = opener?.threadPosition ?? threadPos;
5316
+ if (opener) {
5317
+ registerRoute(opener, sessionId);
5318
+ lastThreadSent = opener;
5319
+ }
4824
5320
  }
4825
5321
  if (!threadId || !anchorChatId) {
4826
5322
  const meta = await providerCall("metadata", () => connection.metadata(sent.messageId));
4827
5323
  threadId ??= meta?.threadId ?? null;
4828
5324
  anchorChatId ??= meta?.chatId ?? null;
5325
+ threadPos ??= meta?.threadPosition;
4829
5326
  }
4830
- persistSessionAnchor(sessionId, sent.messageId, threadId, cfg.targetId, anchorChatId);
5327
+ persistSessionAnchor(sessionId, sent.messageId, threadId, cfg.targetId, anchorChatId, threadPos);
4831
5328
  if (threadId) {
4832
5329
  claimThreadOwnership({ provider: cfg.provider, threadId }, sessionId);
4833
5330
  }
@@ -4874,6 +5371,20 @@ ${recoveryHint}`,
4874
5371
  return;
4875
5372
  }
4876
5373
  registerRoute(next, sessionId);
5374
+ lastThreadSent = next;
5375
+ }
5376
+ const effectiveThreadId = lastThreadSent.threadId ?? threadPlacement.topicId ?? sessionAnchorThreadId ?? null;
5377
+ if (effectiveThreadId && lastThreadSent.messageId) {
5378
+ if (lastThreadSent.threadPosition !== void 0) {
5379
+ updatePersistedAnchorThreadPosition(sessionId, cfg.provider, effectiveThreadId, lastThreadSent.threadPosition);
5380
+ } else if (!isTerminated() && isForwardingEnabled()) {
5381
+ const targetMsgId = lastThreadSent.messageId;
5382
+ void providerCall("thread position", () => connection.metadata(targetMsgId)).then((meta) => {
5383
+ if (meta?.threadPosition !== void 0 && (!meta.threadId || meta.threadId === effectiveThreadId) && !isTerminated()) {
5384
+ updatePersistedAnchorThreadPosition(sessionId, cfg.provider, effectiveThreadId, meta.threadPosition);
5385
+ }
5386
+ }).catch(() => void 0);
5387
+ }
4877
5388
  }
4878
5389
  if (connection.sendFile && !isTerminated() && isForwardingEnabled() && !systemNotice) {
4879
5390
  const files = collectFileReferences(
@@ -5480,13 +5991,13 @@ function createAutoWakeCoordinator(ctx) {
5480
5991
  if (!info || !info.allowed) {
5481
5992
  if (!hasLivePeer(sessionId)) {
5482
5993
  cooldownUntil.set(sessionId, nowFn() + cooldownMs);
5483
- const reason = sanitizeLiteralMarkdown(info?.reason ?? "\u672A\u627E\u5230\u53EF\u6062\u590D\u7684\u4F1A\u8BDD\u8BB0\u5F55");
5994
+ const reason = sanitizeLiteralMarkdown(info?.reason ?? "no resumable session history found");
5484
5995
  ctx.log(`im-forward: auto-wake refused for ${sessionId}: ${reason}`);
5485
5996
  await sendNotice(
5486
5997
  sessionId,
5487
5998
  first.event,
5488
5999
  first.meta,
5489
- `\u{1F4A4} \u8BE5\u8BDD\u9898\u5BF9\u5E94\u7684 Worker \u5DF2\u79BB\u7EBF\u4E14\u65E0\u6CD5\u81EA\u52A8\u5524\u9192\uFF1A${reason}`,
6000
+ `\u{1F4A4} The worker for this thread is offline and cannot auto-wake: ${reason}`,
5490
6001
  "unresumable"
5491
6002
  );
5492
6003
  return;
@@ -5503,7 +6014,7 @@ function createAutoWakeCoordinator(ctx) {
5503
6014
  sessionId,
5504
6015
  first.event,
5505
6016
  first.meta,
5506
- `\u26A0\uFE0F \u81EA\u52A8\u5524\u9192 Worker \u5931\u8D25\uFF1A${sanitizeLiteralMarkdown(res.detail)}`,
6017
+ `\u26A0\uFE0F Failed to auto-wake worker: ${sanitizeLiteralMarkdown(res.detail)}`,
5507
6018
  "spawn-failed"
5508
6019
  );
5509
6020
  return;
@@ -5536,7 +6047,7 @@ function createAutoWakeCoordinator(ctx) {
5536
6047
  sessionId,
5537
6048
  next.event,
5538
6049
  next.meta,
5539
- "\u23F1\uFE0F Worker \u81EA\u52A8\u5524\u9192\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u53D1\u6D88\u606F\u6216\u5728 `/panel` \u4E2D\u67E5\u770B\u72B6\u6001\u3002",
6050
+ "\u23F1\uFE0F Worker auto-wake timed out. Resend your message shortly or check status in `/panel`.",
5540
6051
  "timeout"
5541
6052
  );
5542
6053
  }
@@ -5552,7 +6063,7 @@ function createAutoWakeCoordinator(ctx) {
5552
6063
  sessionId,
5553
6064
  first.event,
5554
6065
  first.meta,
5555
- `\u26A0\uFE0F \u81EA\u52A8\u5524\u9192 Worker \u5F02\u5E38\uFF1A${sanitizeLiteralMarkdown(error instanceof Error ? error.message : String(error))}`,
6066
+ `\u26A0\uFE0F Worker auto-wake error: ${sanitizeLiteralMarkdown(error instanceof Error ? error.message : String(error))}`,
5556
6067
  "error"
5557
6068
  );
5558
6069
  } finally {
@@ -5570,7 +6081,7 @@ function createAutoWakeCoordinator(ctx) {
5570
6081
  sessionId,
5571
6082
  event,
5572
6083
  meta,
5573
- "\u26D4\uFE0F \u8BE5\u8BDD\u9898\u5BF9\u5E94\u7684 Worker \u5F53\u524D\u5DF2\u79BB\u7EBF\uFF0C\u4F60\u6CA1\u6709\u81EA\u52A8\u5524\u9192\u6743\u9650\uFF08\u53D7 panelAccess=allowUsers \u9650\u5236\uFF09\u3002",
6084
+ "\u26D4\uFE0F The worker for this thread is offline and you lack permission to auto-wake it (restricted by panelAccess=allowUsers).",
5574
6085
  "denied"
5575
6086
  );
5576
6087
  }
@@ -5585,7 +6096,7 @@ function createAutoWakeCoordinator(ctx) {
5585
6096
  sessionId,
5586
6097
  event,
5587
6098
  meta,
5588
- "\u23F3 Worker \u6B63\u5728\u5524\u9192\u4E14\u5F85\u53D1\u961F\u5217\u5DF2\u6EE1\uFF0C\u8BF7\u7B49\u51E0\u79D2\u5C31\u7EEA\u540E\u518D\u53D1\u3002",
6099
+ "\u23F3 Worker is waking up and the pending queue is full. Wait a few seconds and retry.",
5589
6100
  "queue-full"
5590
6101
  );
5591
6102
  return;
@@ -5613,7 +6124,7 @@ function createAutoWakeCoordinator(ctx) {
5613
6124
  sessionId,
5614
6125
  event,
5615
6126
  meta,
5616
- "\u23F3 \u5F53\u524D\u540C\u65F6\u5524\u9192\u7684 Worker \u8F83\u591A\uFF0C\u8BF7\u51E0\u79D2\u540E\u91CD\u8BD5\u3002",
6127
+ "\u23F3 Too many workers are waking up concurrently. Retry in a few seconds.",
5617
6128
  "busy-cap"
5618
6129
  );
5619
6130
  return;
@@ -6506,7 +7017,7 @@ async function acquireLock(actionId, triggerName, timeoutMs = DEFAULT_TIMEOUT_MS
6506
7017
  holder: {
6507
7018
  triggerName: existing.triggerName,
6508
7019
  startedAt: existing.startedAt,
6509
- note: `\u4E0A\u4E00\u6B21\u6267\u884C\u7684\u8FDB\u7A0B\u8EAB\u4EFD\u65E0\u6CD5\u786E\u8BA4\uFF08\u53EF\u80FD\u7528\u4E86 exec \u5305\u88C5\u6539\u53D8\u4E86 argv\uFF09\u3002\u4E3A\u5B89\u5168\u8D77\u89C1\u4E0D\u81EA\u52A8\u91CA\u653E\u3002\u4EBA\u5DE5\u786E\u8BA4\u65E7\u8FDB\u7A0B\u5DF2\u505C\u6B62\u540E\uFF0C\u5220\u9664 ${dir} \u5373\u53EF\u6062\u590D\u3002`
7020
+ note: `Previous run's process identity could not be verified (argv may have changed via exec wrapper). Not auto-releasing for safety. Confirm the old process stopped, then delete ${dir} to recover.`
6510
7021
  }
6511
7022
  };
6512
7023
  }
@@ -6670,13 +7181,12 @@ function composeWorkerCard(peer, opts = {}) {
6670
7181
  { id: `panel.worker.models.${peer.instanceId}`, label: "\u{1F39A} Model" },
6671
7182
  ...peer.sessionControls ? [
6672
7183
  { id: `panel.context.${peer.instanceId}`, label: "\u{1F4CA} Context", payload: fromWorker },
6673
- { id: `panel.compact.${peer.instanceId}`, label: "\u{1F9F9} Compact", payload: fromWorker },
6674
7184
  { id: `panel.tree.${peer.instanceId}`, label: "\u{1F333} Tree", payload: fromWorker }
6675
7185
  ] : [],
6676
7186
  { id: `panel.worker.cron.${peer.instanceId}`, label: workerCron > 0 ? `\u23F0 Cron (${workerCron})` : "\u23F0 Cron" },
7187
+ ...peer.workerPeek && peer.sessionId ? [{ id: `panel.peek.${peer.instanceId}`, label: "\u{1F440} Peek", payload: peekCtx }] : [],
6677
7188
  { id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: fromWorker },
6678
- ...canQuit ? [{ id: `panel.quit.${peer.instanceId}`, label: "\u{1F6AA} Quit", style: "danger" }] : [],
6679
- ...peer.workerPeek && peer.sessionId ? [{ id: `panel.peek.${peer.instanceId}`, label: "\u{1F440} Peek", payload: peekCtx }] : []
7189
+ ...canQuit ? [{ id: `panel.quit.${peer.instanceId}`, label: "\u{1F6AA} Quit", style: "danger" }] : []
6680
7190
  ];
6681
7191
  const title = workerDisplayTitle(peer);
6682
7192
  const modelDisplay = formatPeerModel(peer);
@@ -6686,21 +7196,21 @@ function composeWorkerCard(peer, opts = {}) {
6686
7196
  const visibleActions = wActions.slice(0, maxCustom);
6687
7197
  const items = visibleActions.map((a) => ({
6688
7198
  text: `**${cleanInline(a.label, 36)}**
6689
- ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline(a.lastRunBy ?? "\u2014", 24)}`,
7199
+ ${a.runs} run(s) \xB7 last ${cleanInline(a.lastRunBy ?? "\u2014", 24)}`,
6690
7200
  actions: [{
6691
7201
  id: `panel.action.${a.id}`,
6692
- label: "\u25B6\uFE0F \u8FD0\u884C",
7202
+ label: "\u25B6\uFE0F Run",
6693
7203
  payload: workerCtx
6694
7204
  }]
6695
7205
  }));
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";
7206
+ const footer = wActions.length > maxCustom ? `More actions (copy to run): ${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 ? "No custom worker actions yet (actions with scope=worker appear here)." : "Inline buttons run in this worker's context (zero LLM).";
6697
7207
  const threadUrl = resolveSessionThreadUrl(peer.sessionId);
6698
7208
  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})`] : []
7209
+ `- **name**: ${cleanInline(peer.name, 48)} \xB7 **state**: ${cleanInline(state, 48)}`,
7210
+ `- **model**: \`${cleanCodeSpan(modelDisplay, 56)}\``,
7211
+ `- **host**: ${cleanInline(managedLabel, 48)} \xB7 **version**: ${cleanInline(peer.version ?? "\u2014", 24)}`,
7212
+ ...peer.cwd ? [`- **cwd**: \`${cleanCodeSpan(peer.cwd, 96)}\``] : [],
7213
+ ...threadUrl ? [`- **thread**: [\u{1F4AC} Open Thread \u2197](${threadUrl})`] : []
6704
7214
  ];
6705
7215
  return {
6706
7216
  title: `\u{1F527} ${title}`,
@@ -6712,14 +7222,14 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline(a.lastRunBy ?? "\u2014", 24)}`,
6712
7222
  footer,
6713
7223
  actions: [
6714
7224
  ...fixedActions,
6715
- ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }]
7225
+ ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home", align: "end" }]
6716
7226
  ]
6717
7227
  };
6718
7228
  }
6719
7229
  function composeTargetModelsCard(peer, catalog, opts) {
6720
7230
  const isManager = opts.scope === "manager";
6721
7231
  const navCmd = isManager ? "panel.models" : `panel.worker.models.${peer.instanceId}`;
6722
- const backAction = isManager ? { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" } : { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" };
7232
+ const backAction = isManager ? { id: "panel.home", label: "\u21A9\uFE0F Home" } : { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" };
6723
7233
  const controlMeta = { from: opts.scope, peer: peer.instanceId };
6724
7234
  const displayTitle = isManager ? "Manager" : workerDisplayTitle(peer);
6725
7235
  const safeDisplayTitle = cleanInline(displayTitle, 36);
@@ -6745,15 +7255,15 @@ ${cleanInline(m.name, 48)}` : "";
6745
7255
  text: `${isCur ? "\u2605 " : ""}\`${cleanCodeSpan(m.id, 44)}\`${subtitleLine}`,
6746
7256
  actions: [{
6747
7257
  id: `panel.model.${peer.instanceId}.${m.ref}`,
6748
- label: isCur ? "\u2713 \u5F53\u524D" : "\u5207\u6362",
7258
+ label: isCur ? "\u2713 Active" : "Select",
6749
7259
  ...isCur ? { style: "primary" } : {},
6750
7260
  payload: { ...controlMeta, provider: selectedGroup.provider, page: page2 }
6751
7261
  }]
6752
7262
  };
6753
7263
  });
6754
7264
  const navButtons2 = [];
6755
- if (page2 > 1) navButtons2.push({ id: navCmd, label: `\u25C0\uFE0F \u7B2C ${page2 - 1} \u9875`, payload: { provider: selectedGroup.provider, page: page2 - 1 } });
6756
- if (page2 < totalPages2) navButtons2.push({ id: navCmd, label: `\u7B2C ${page2 + 1} \u9875 \u25B6\uFE0F`, payload: { provider: selectedGroup.provider, page: page2 + 1 } });
7265
+ if (page2 > 1) navButtons2.push({ id: navCmd, label: `\u25C0\uFE0F Page ${page2 - 1}`, payload: { provider: selectedGroup.provider, page: page2 - 1 } });
7266
+ if (page2 < totalPages2) navButtons2.push({ id: navCmd, label: `Page ${page2 + 1} \u25B6\uFE0F`, payload: { provider: selectedGroup.provider, page: page2 + 1 } });
6757
7267
  return {
6758
7268
  title: `\u{1F39A} ${selectedGroup.provider} \xB7 ${displayTitle}`,
6759
7269
  subtitle: `${selectedGroup.models.length} model(s)${totalPages2 > 1 ? ` \xB7 p${page2}/${totalPages2}` : ""} \xB7 Current: ${currentSummary}`,
@@ -6761,10 +7271,10 @@ ${cleanInline(m.name, 48)}` : "";
6761
7271
  columnsPerRow: cols,
6762
7272
  body: headerInfo,
6763
7273
  items: items2,
6764
- footer: "\u70B9\u51FB\u53F3\u4FA7\u6309\u94AE\u5373\u5207\uFF0C\u4E0B\u6B21\u6267\u884C\u751F\u6548\uFF08zero LLM\uFF09\u3002",
7274
+ footer: "Tap a button to switch immediately; applies on the next turn (zero LLM).",
6765
7275
  actions: [
6766
7276
  ...navButtons2,
6767
- { id: navCmd, label: "\u21A9\uFE0F \u5168\u90E8 Provider", payload: {} },
7277
+ { id: navCmd, label: "\u21A9\uFE0F All Providers", payload: {} },
6768
7278
  backAction
6769
7279
  ].slice(0, 6)
6770
7280
  };
@@ -6772,7 +7282,7 @@ ${cleanInline(m.name, 48)}` : "";
6772
7282
  const advertisedThinkingLevels = peer.supportedThinkingLevels;
6773
7283
  const dynamicThinkingLevels = Array.isArray(advertisedThinkingLevels) ? advertisedThinkingLevels.length === 0 || advertisedThinkingLevels.length === 1 && advertisedThinkingLevels[0] === "off" ? [] : advertisedThinkingLevels.slice(0, 7) : THINKING_LEVELS;
6774
7284
  const activeThinkingDisplay = peer.effectiveThinkingLevel ?? peer.thinkingLevel;
6775
- const thinkingHint = Array.isArray(advertisedThinkingLevels) && dynamicThinkingLevels.length === 0 ? advertisedThinkingLevels.length === 0 ? "\n_\u5F53\u524D\u6A21\u578B\u4F7F\u7528\u56FA\u5B9A\u5185\u7F6E\u63A8\u7406\uFF08\u4E0D\u652F\u6301\u6309\u6863\u4F4D\u5207\u6362\uFF09_" : "\n_\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u601D\u8003\u6863\u4F4D_" : "";
7285
+ const thinkingHint = Array.isArray(advertisedThinkingLevels) && dynamicThinkingLevels.length === 0 ? advertisedThinkingLevels.length === 0 ? "\n_Current model uses fixed built-in reasoning (thinking levels cannot be switched)._" : "\n_Current model does not support thinking levels._" : "";
6776
7286
  const makeThinkingButtons = (overviewPage) => dynamicThinkingLevels.map((level) => {
6777
7287
  const isCur = activeThinkingDisplay === level;
6778
7288
  return {
@@ -6792,7 +7302,7 @@ ${cleanInline(m.name, 48)}` : "";
6792
7302
  text: `${isCur ? "\u2605 " : ""}\`${cleanCodeSpan(m.ref, 48)}\`${subtitleLine}`,
6793
7303
  actions: [{
6794
7304
  id: `panel.model.${peer.instanceId}.${m.ref}`,
6795
- label: isCur ? "\u2713 \u5F53\u524D" : "\u5207\u6362",
7305
+ label: isCur ? "\u2713 Active" : "Select",
6796
7306
  ...isCur ? { style: "primary" } : {},
6797
7307
  payload: controlMeta
6798
7308
  }]
@@ -6805,9 +7315,9 @@ ${cleanInline(m.name, 48)}` : "";
6805
7315
  columnsPerRow: cols,
6806
7316
  body: allModels.length > 0 ? `${headerInfo}${thinkingHint}` : `${headerInfo}${thinkingHint}
6807
7317
 
6808
- _models.json \u4E2D\u672A\u627E\u5230\u53EF\u7528\u6A21\u578B_`,
7318
+ _No available models found in models.json._`,
6809
7319
  ...items2.length > 0 ? { items: items2 } : {},
6810
- footer: "\u884C\u5185\u6309\u94AE\u5207\u6A21\u578B\uFF0C\u4E0B\u65B9 \u{1F9E0} \u6309\u94AE\u76F4\u63A5\u5207 Thinking\uFF0C\u4E0B\u6B21\u6267\u884C\u751F\u6548\uFF08zero LLM\uFF09\u3002",
7320
+ footer: "Use inline buttons for Model and \u{1F9E0} buttons below for Thinking; applies next turn (zero LLM).",
6811
7321
  actions: [
6812
7322
  ...makeThinkingButtons(),
6813
7323
  backAction
@@ -6827,12 +7337,12 @@ _models.json \u4E2D\u672A\u627E\u5230\u53EF\u7528\u6A21\u578B_`,
6827
7337
  const preview = overflow > 0 ? `${sample.join(", ")} (+${overflow} more)` : sample.join(", ");
6828
7338
  const action = g.models.length === 1 ? {
6829
7339
  id: `panel.model.${peer.instanceId}.${g.models[0].ref}`,
6830
- label: currentModel === g.models[0].ref ? "\u2713 \u5F53\u524D" : "\u5207\u6362",
7340
+ label: currentModel === g.models[0].ref ? "\u2713 Active" : "Select",
6831
7341
  ...currentModel === g.models[0].ref ? { style: "primary" } : {},
6832
7342
  payload: { ...controlMeta, page }
6833
7343
  } : {
6834
7344
  id: navCmd,
6835
- label: hasCur ? "\u2605 \u5C55\u5F00" : "\u5C55\u5F00",
7345
+ label: hasCur ? "\u2605 Expand" : "Expand",
6836
7346
  ...hasCur ? { style: "primary" } : {},
6837
7347
  payload: { provider: g.provider, page: 1 }
6838
7348
  };
@@ -6843,8 +7353,8 @@ _models.json \u4E2D\u672A\u627E\u5230\u53EF\u7528\u6A21\u578B_`,
6843
7353
  };
6844
7354
  });
6845
7355
  const navButtons = [];
6846
- if (page > 1) navButtons.push({ id: navCmd, label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1 } });
6847
- if (page < totalPages) navButtons.push({ id: navCmd, label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1 } });
7356
+ if (page > 1) navButtons.push({ id: navCmd, label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1 } });
7357
+ if (page < totalPages) navButtons.push({ id: navCmd, label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1 } });
6848
7358
  return {
6849
7359
  title: `\u{1F39A} Model & Thinking \xB7 ${displayTitle}`,
6850
7360
  subtitle: `Current: ${currentSummary} \xB7 ${catalog.length} providers / ${totalModels} models${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""}`,
@@ -6852,7 +7362,7 @@ _models.json \u4E2D\u672A\u627E\u5230\u53EF\u7528\u6A21\u578B_`,
6852
7362
  columnsPerRow: cols,
6853
7363
  body: `${headerInfo}${thinkingHint}`,
6854
7364
  items,
6855
- footer: "\u5355\u6A21\u578B Provider \u70B9\u51FB\u76F4\u5207\uFF0C\u591A\u6A21\u578B Provider \u70B9\u51FB\u5C55\u5F00\uFF1B\u4E0B\u65B9 \u{1F9E0} \u6309\u94AE\u76F4\u63A5\u5207 Thinking\uFF08zero LLM\uFF09\u3002",
7365
+ footer: "Single-model providers switch in one tap; multi-model providers expand. Use \u{1F9E0} buttons below for Thinking (zero LLM).",
6856
7366
  actions: [
6857
7367
  ...navButtons,
6858
7368
  ...makeThinkingButtons(page),
@@ -6869,34 +7379,34 @@ function composeWorkerQuitConfirmCard(peer, opts = {}) {
6869
7379
  const canQuit = canRemotelyQuitPeer(peer);
6870
7380
  if (!canQuit) {
6871
7381
  return {
6872
- title: "\u26D4\uFE0F \u4E0D\u53EF\u8FDC\u7A0B\u9000\u51FA",
7382
+ title: "\u26D4\uFE0F Remote Quit Unavailable",
6873
7383
  color: "red",
6874
7384
  columnsPerRow: opts.inThread ? 2 : 3,
6875
- body: `${peer.isManager ? "Manager \u5BBF\u4E3B" : "\u4EA4\u4E92\u5F0F TUI \u4F1A\u8BDD"}\u4E0D\u5141\u8BB8\u4ECE\u98DE\u4E66\u8FDC\u7A0B\u9000\u51FA\uFF08\u4ECD\u53EF\u4F7F\u7528 Stop / Model / Context / Compact\uFF09\u3002`,
7385
+ body: `${peer.isManager ? "The manager host" : "Interactive TUI sessions"} cannot be quit remotely from IM (you can still use Stop / Model / Context / Tree).`,
6876
7386
  actions: [
6877
7387
  { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Back" },
6878
- ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }]
7388
+ ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home" }]
6879
7389
  ]
6880
7390
  };
6881
7391
  }
6882
7392
  const state = peer.state === "working" && peer.currentTool ? `working\xB7${peer.currentTool}` : peer.state;
6883
7393
  const quitPayload = { quit: { ref: peer.instanceId, session: peer.sessionId, ...managed?.generation ? { generation: managed.generation } : {} } };
6884
7394
  return {
6885
- title: `\u{1F6AA} \u786E\u8BA4\u9000\u51FA \xB7 ${workerDisplayTitle(peer)}`,
7395
+ title: `\u{1F6AA} Confirm Quit \xB7 ${workerDisplayTitle(peer)}`,
6886
7396
  subtitle: `${peer.name} \xB7 ${state}`,
6887
7397
  color: "red",
6888
7398
  columnsPerRow: opts.inThread ? 2 : 3,
6889
7399
  body: [
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)}\``] : [],
7400
+ `- **name**: ${cleanInline(peer.name, 48)} \xB7 **state**: ${cleanInline(state, 48)}`,
7401
+ `- **session**: \`${cleanCodeSpan(peer.sessionId, 64)}\``,
7402
+ ...peer.cwd ? [`- **cwd**: \`${cleanCodeSpan(peer.cwd, 96)}\``] : [],
6893
7403
  ``,
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"
7404
+ peer.state === "working" ? "\u26A0\uFE0F This worker is currently running a turn. Graceful quit will abort the turn, flush state, and release locks." : "Graceful quit tells this worker to flush state, release IPC locks, and exit cleanly (session history is preserved for Resume)."
6895
7405
  ].join("\n"),
6896
7406
  actions: [
6897
- { id: `panel.quit.confirm.${peer.instanceId}`, label: "\u2705 \u786E\u8BA4\u4F18\u96C5\u9000\u51FA", style: "danger", payload: quitPayload },
6898
- ...managed ? [{ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} \u5F3A\u5236\u7EC8\u6B62", style: "danger", payload: quitPayload }] : [],
6899
- { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F \u53D6\u6D88" }
7407
+ { id: `panel.quit.confirm.${peer.instanceId}`, label: "\u2705 Graceful Quit", style: "danger", payload: quitPayload },
7408
+ ...managed ? [{ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} Force Kill", style: "danger", payload: quitPayload }] : [],
7409
+ { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Cancel" }
6900
7410
  ]
6901
7411
  };
6902
7412
  }
@@ -6905,14 +7415,14 @@ function composeOfflineWorkerCard(sessionId, opts = {}) {
6905
7415
  const bridge = currentWorkerLifecycleBridge();
6906
7416
  const resumable = sessionId ? bridge?.inspectResumable(sessionId) : void 0;
6907
7417
  const lines = [
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"
7418
+ sessionId ? `Worker session \`${cleanCodeSpan(sessionId, 64)}\` for this thread is offline (it may have exited or expired via TTL).` : "This session is currently offline (it may have exited or expired via TTL)."
6909
7419
  ];
6910
7420
  if (resumable) {
6911
7421
  lines.push(
6912
7422
  "",
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)})`}`
7423
+ `- **name**: ${cleanInline(resumable.name, 48)}`,
7424
+ `- **cwd**: \`${cleanCodeSpan(resumable.cwd, 96)}\``,
7425
+ `- **resume**: ${resumable.allowed ? "ready" : `unavailable (${cleanInline(resumable.reason ?? "blocked", 64)})`}`
6916
7426
  );
6917
7427
  }
6918
7428
  const actions = [];
@@ -6927,10 +7437,10 @@ function composeOfflineWorkerCard(sessionId, opts = {}) {
6927
7437
  actions.push({ id: `panel.worker.${opts.peerId}`, label: "\u{1F504} Refresh" });
6928
7438
  }
6929
7439
  if (!hideHome) {
6930
- actions.push({ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" });
7440
+ actions.push({ id: "panel.home", label: "\u{1F4CB} Home" });
6931
7441
  }
6932
7442
  return {
6933
- title: "\u{1F4A4} Worker \u5DF2\u79BB\u7EBF",
7443
+ title: "\u{1F4A4} Worker Offline",
6934
7444
  subtitle: resumable ? `${resumable.name} \xB7 offline` : "offline",
6935
7445
  color: "grey",
6936
7446
  columnsPerRow: opts.inThread ? 2 : 3,
@@ -7067,61 +7577,60 @@ function composePanel(opts = {}) {
7067
7577
  const label = formatPeerSessionLabel(p);
7068
7578
  const verDrift = p.version && currentVer !== "unknown" && p.version !== currentVer ? ` \xB7 v${p.version}` : "";
7069
7579
  const threadUrl = resolveSessionThreadUrl(p.sessionId);
7070
- const threadLink = threadUrl ? ` \xB7 [\u{1F4AC} \u8BDD\u9898](${threadUrl})` : "";
7580
+ const threadLink = threadUrl ? ` \xB7 [\u{1F4AC} Thread](${threadUrl})` : "";
7071
7581
  const meta = `\`${cleanCodeSpan(formatPeerModel(p), 44)}\` \xB7 ${formatPeerState(p.state, p.currentTool, verDrift)}${threadLink}`;
7072
7582
  const rowActions = p === managerPeer ? [
7073
7583
  { id: "panel.models", label: "\u{1F39A} Model" },
7074
7584
  ...p.sessionControls ? [{ id: `panel.tree.${p.instanceId}`, label: "\u{1F333} Tree", payload: { from: "home" } }] : [],
7075
7585
  ...p.workerPeek && p.sessionId ? [{ id: `panel.peek.${p.instanceId}`, label: "\u{1F440} Peek", payload: { peek: { ref: p.instanceId, session: p.sessionId, isManager: true } } }] : []
7076
- ] : [{ id: `panel.worker.${p.instanceId}`, label: "\u{1F527} \u7BA1\u7406" }];
7586
+ ] : [{ id: `panel.worker.${p.instanceId}`, label: "\u{1F527} Manage" }];
7077
7587
  return { text: `${label}
7078
7588
  ${meta}`, actions: rowActions };
7079
7589
  });
7080
7590
  const nav = [];
7081
- if (page > 1) nav.push({ id: "panel.home", label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1 } });
7082
- if (page < totalPages) nav.push({ id: "panel.home", label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1 } });
7591
+ if (page > 1) nav.push({ id: "panel.home", label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1 } });
7592
+ if (page < totalPages) nav.push({ id: "panel.home", label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1 } });
7083
7593
  const upgradeLine = upgradeSummaryLine();
7084
7594
  const footerParts = [];
7085
- if (totalPages > 1) footerParts.push(`\u7B2C ${page}/${totalPages} \u9875`);
7595
+ if (totalPages > 1) footerParts.push(`Page ${page}/${totalPages}`);
7086
7596
  footerParts.push(`${upgradeLine} \xB7 ${peers.length} session(s) \xB7 ${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false })}`);
7087
7597
  const activeCron = cronActiveCount();
7088
7598
  const blockedCron = cronBlockedSummary();
7089
7599
  if (blockedCron.memoryBlocked) {
7090
7600
  const errNote = blockedCron.memoryError ? ` (${cleanCodeSpan(blockedCron.memoryError).slice(0, 60)})` : "";
7091
- footerParts.unshift(`\u26A0\uFE0F Memory \u5B9A\u65F6\u84B8\u998F\u5DF2\u963B\u585E${errNote}\uFF0C\u8BF7\u70B9 Cron \u67E5\u770B/\u6062\u590D`);
7601
+ footerParts.unshift(`\u26A0\uFE0F Memory distillation cron is blocked${errNote} \u2014 open Cron to inspect or resume`);
7092
7602
  } else if (blockedCron.blockedCount > 0) {
7093
- footerParts.unshift(`\u26A0\uFE0F ${blockedCron.blockedCount} \u4E2A Cron \u4EFB\u52A1\u5904\u4E8E blocked \u72B6\u6001`);
7603
+ footerParts.unshift(`\u26A0\uFE0F ${blockedCron.blockedCount} cron job(s) blocked`);
7094
7604
  }
7095
- const cronLabel = blockedCron.blockedCount > 0 ? `\u26A0\uFE0F Cron (${blockedCron.blockedCount}\u963B)` : activeCron > 0 ? `\u23F0 Cron (${activeCron})` : "\u23F0 Cron";
7605
+ const cronLabel = blockedCron.blockedCount > 0 ? `\u26A0\uFE0F Cron (${blockedCron.blockedCount}!)` : activeCron > 0 ? `\u23F0 Cron (${activeCron})` : "\u23F0 Cron";
7096
7606
  const fixed = [
7097
7607
  { id: "panel.refresh", label: "\u{1F504} Refresh", ...totalPages > 1 ? { payload: { page } } : {} },
7098
- { id: "panel.summon", label: "\u{1F4CB} Resummon" },
7099
- { id: "panel.archive", label: "\u{1F4DA} \u5F52\u6863" },
7608
+ { id: "panel.archive", label: "\u{1F4DA} Archive" },
7100
7609
  ...!managerPeer ? [{ id: "panel.models", label: "\u{1F39A} Model" }] : [],
7101
7610
  { id: "panel.context", label: "\u{1F4CA} Context" },
7102
7611
  { id: "panel.memory", label: "\u{1F9E0} Memory" },
7103
7612
  { id: "panel.cron", label: cronLabel },
7104
- { id: "panel.upgrade", label: "\u2B06\uFE0F Upgrade" },
7105
- { id: "panel.help", label: "\u2753 Help" }
7613
+ { id: "panel.upgrade", label: "\u2B06\uFE0F Upgrade" }
7106
7614
  ];
7615
+ const helpAction = { id: "panel.help", label: "\u2753 Help", align: "end" };
7107
7616
  const CARD_ACTION_BUDGET = 18;
7108
7617
  const inlineCount = items.reduce((sum, item) => sum + (item.actions?.length ?? 0), 0);
7109
7618
  const custom = managerActions();
7110
- const slots = Math.max(0, CARD_ACTION_BUDGET - inlineCount - fixed.length - nav.length);
7619
+ const slots = Math.max(0, CARD_ACTION_BUDGET - inlineCount - fixed.length - 1 - nav.length);
7111
7620
  const inline = custom.length <= slots ? custom : custom.slice(0, Math.max(0, slots - 1));
7112
7621
  const customButtons = inline.map((a) => ({ id: `panel.action.${a.id}`, label: a.label.slice(0, 20) }));
7113
- if (custom.length > inline.length && slots > 0) customButtons.push({ id: "panel.actions", label: `\u26A1 \u5168\u90E8\u52A8\u4F5C (${custom.length})` });
7622
+ if (custom.length > inline.length && slots > 0) customButtons.push({ id: "panel.actions", label: `\u26A1 All Actions (${custom.length})` });
7114
7623
  return {
7115
7624
  title: "Pie Panel",
7116
7625
  subtitle: `${os6.hostname()} \xB7 ${peers.length} session(s)${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""} \xB7 pie ${pieVersion()}`,
7117
7626
  color: "blue",
7118
7627
  columnsPerRow: opts.inThread ? 2 : 3,
7119
- body: peers.length === 0 ? "_\u5F53\u524D\u6682\u65E0\u5728\u7EBF Pie \u4F1A\u8BDD_" : "",
7628
+ body: peers.length === 0 ? "_No online Pie sessions._" : "",
7120
7629
  ...items.length > 0 ? { items } : {},
7121
7630
  footer: footerParts.join(" \xB7 "),
7122
7631
  // r1-P2: only REGISTERED commands get buttons — unmapped ids would fall
7123
7632
  // through to an LLM turn (a button press must never spend a model turn).
7124
- actions: [...nav, ...fixed, ...customButtons]
7633
+ actions: [...nav, ...fixed, ...customButtons, helpAction]
7125
7634
  };
7126
7635
  }
7127
7636
  function pieVersion() {
@@ -7183,7 +7692,7 @@ function executePanelCommand(input) {
7183
7692
  color: "violet",
7184
7693
  columnsPerRow: cols,
7185
7694
  body: "_No live manager session found._",
7186
- actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
7695
+ actions: [{ id: "panel.home", label: "\u21A9\uFE0F Home" }]
7187
7696
  },
7188
7697
  patchOrigin: patchInPlace
7189
7698
  };
@@ -7205,22 +7714,22 @@ function executePanelCommand(input) {
7205
7714
  text: `${formatPeerSessionLabel(p)}
7206
7715
  \`${cleanCodeSpan(formatPeerModel(p), 44)}\` \xB7 ${formatPeerState(p.state, p.currentTool)}`,
7207
7716
  actions: isCompactOnly ? [{ id: `panel.compact.${p.instanceId}`, label: "\u{1F9F9} Compact" }] : [
7208
- { id: `panel.context.${p.instanceId}`, label: "\u{1F4CA} \u67E5\u770B" },
7209
- { id: `panel.compact.${p.instanceId}`, label: "\u{1F9F9} \u538B\u7F29" }
7717
+ { id: `panel.context.${p.instanceId}`, label: "\u{1F4CA} Inspect" },
7718
+ { id: `panel.compact.${p.instanceId}`, label: "\u{1F9F9} Compact" }
7210
7719
  ]
7211
7720
  }));
7212
7721
  const nav = [];
7213
- if (page > 1) nav.push({ id: input.cmd, label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1 } });
7214
- if (page < totalPages) nav.push({ id: input.cmd, label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1 } });
7722
+ if (page > 1) nav.push({ id: input.cmd, label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1 } });
7723
+ if (page < totalPages) nav.push({ id: input.cmd, label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1 } });
7215
7724
  return { spec: {
7216
7725
  title: isCompactOnly ? "Compact Context" : "Context & Compact",
7217
- subtitle: `${peers.length} session(s)${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""} \xB7 ${isCompactOnly ? "\u624B\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587\u5386\u53F2" : "\u67E5\u770B\u4E0A\u4E0B\u6587\u4F30\u7B97\u6216\u624B\u52A8\u538B\u7F29\u5386\u53F2"}`,
7726
+ subtitle: `${peers.length} session(s)${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""} \xB7 ${isCompactOnly ? "Manually compact context history" : "Inspect context usage or compact history"}`,
7218
7727
  color: "violet",
7219
7728
  columnsPerRow: cols,
7220
- body: peers.length === 0 ? "_\u5F53\u524D\u6682\u65E0\u652F\u6301\u8BE5\u63A7\u5236\u7684\u5728\u7EBF\u4F1A\u8BDD_" : "",
7729
+ body: peers.length === 0 ? "_No online sessions currently support this control._" : "",
7221
7730
  ...items.length > 0 ? { items } : {},
7222
- footer: isCompactOnly ? "\u538B\u7F29\u4F1A\u5C06\u65E7\u5386\u53F2\u603B\u7ED3\u4E3A checkpoint \u5E76\u4FDD\u7559\u5C3E\u90E8\uFF08\u4E0E /sessions/compact \u76F8\u540C\uFF09\uFF1B\u4F1A\u8BDD\u5FD9\u788C\u65F6\u4F1A\u62D2\u7EDD\uFF0C\u8BF7\u7A7A\u95F2\u65F6\u91CD\u8BD5\u3002" : "\u300C\u{1F4CA} \u67E5\u770B\u300D\u67E5\u8BE2\u5B9E\u65F6\u4E0A\u4E0B\u6587\u5360\u7528\uFF08zero LLM\uFF09\uFF1B\u300C\u{1F9F9} \u538B\u7F29\u300D\u603B\u7ED3\u65E7\u5386\u53F2\u5E76\u4FDD\u7559\u5C3E\u90E8\uFF08\u4F1A\u8BDD\u7A7A\u95F2\u65F6\u53EF\u6267\u884C\uFF09\u3002",
7223
- actions: [...nav, { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
7731
+ footer: isCompactOnly ? "Compaction summarizes older history into a checkpoint while keeping recent turns (same as /sessions/compact). Refused while busy; retry when idle." : "Inspect checks live context usage (zero LLM). Compact summarizes older history while keeping recent turns (available when idle).",
7732
+ actions: [...nav, { id: "panel.home", label: "\u21A9\uFE0F Home" }]
7224
7733
  }, patchOrigin: patchInPlace };
7225
7734
  }
7226
7735
  if (input.cmd === "panel.actions") {
@@ -7231,21 +7740,21 @@ function executePanelCommand(input) {
7231
7740
  const slice = all.slice((page - 1) * PAGE_SIZE2, page * PAGE_SIZE2);
7232
7741
  const items = slice.map((a) => ({
7233
7742
  text: `**${cleanInline2(a.label, 36)}**
7234
- ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline2(a.lastRunBy ?? "\u2014", 20)} \xB7 \u521B\u5EFA ${cleanInline2(a.creator?.name ?? "\u2014", 20)}`,
7235
- actions: [{ id: `panel.action.${a.id}`, label: "\u25B6\uFE0F \u8FD0\u884C" }]
7743
+ ${a.runs} run(s) \xB7 last ${cleanInline2(a.lastRunBy ?? "\u2014", 20)} \xB7 by ${cleanInline2(a.creator?.name ?? "\u2014", 20)}`,
7744
+ actions: [{ id: `panel.action.${a.id}`, label: "\u25B6\uFE0F Run" }]
7236
7745
  }));
7237
7746
  const nav = [];
7238
- if (page > 1) nav.push({ id: "panel.actions", label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1 } });
7239
- if (page < totalPages) nav.push({ id: "panel.actions", label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1 } });
7747
+ if (page > 1) nav.push({ id: "panel.actions", label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1 } });
7748
+ if (page < totalPages) nav.push({ id: "panel.actions", label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1 } });
7240
7749
  return { spec: {
7241
- title: "\u5168\u90E8\u52A8\u4F5C",
7242
- subtitle: `${all.length} registered${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""} \xB7 \u70B9\u51FB\u884C\u5185\u6309\u94AE\u76F4\u63A5\u8FD0\u884C\uFF08zero LLM\uFF09`,
7750
+ title: "All Actions",
7751
+ subtitle: `${all.length} registered${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""} \xB7 tap inline buttons to run (zero LLM)`,
7243
7752
  color: "violet",
7244
7753
  columnsPerRow: cols,
7245
- body: all.length === 0 ? "_\u6682\u65E0\u81EA\u5B9A\u4E49\u52A8\u4F5C \u2014 \u53EF\u76F4\u63A5\u5728\u5BF9\u8BDD\u4E2D\u8BA9 Manager \u521B\u5EFA\uFF08\u4F8B\u5982\u300C\u5E2E\u6211\u505A\u4E2A\u6309\u94AE\uFF0C\u80FD\u2026\u300D\uFF09_" : "",
7754
+ body: all.length === 0 ? "_No custom actions yet \u2014 ask Manager in chat to create one._" : "",
7246
7755
  ...items.length > 0 ? { items } : {},
7247
- footer: "\u6BCF\u6B21\u6267\u884C\u90FD\u4F1A\u8BB0\u5F55\u89E6\u53D1\u4EBA\u4E0E\u5BA1\u8BA1\u65E5\u5FD7\uFF08zero LLM\uFF0C\u76F4\u63A5\u8FD0\u884C\u811A\u672C\uFF09\u3002",
7248
- actions: [...nav, { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
7756
+ footer: "Each run records the caller and audit log (zero LLM, runs script directly).",
7757
+ actions: [...nav, { id: "panel.home", label: "\u21A9\uFE0F Home" }]
7249
7758
  }, patchOrigin: patchInPlace };
7250
7759
  }
7251
7760
  if (input.cmd === "panel.worker.offline") {
@@ -7306,7 +7815,7 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline2(a.lastRunBy ?? "\u2014", 20)}
7306
7815
  ].join("\n"),
7307
7816
  actions: [
7308
7817
  { id: "panel.upgrade.confirm", label: "\u2B06\uFE0F Install latest + restart", style: "primary", requireAllowUsers: true },
7309
- { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }
7818
+ { id: "panel.home", label: "\u21A9\uFE0F Home" }
7310
7819
  ]
7311
7820
  }, patchOrigin: patchInPlace };
7312
7821
  }
@@ -7314,8 +7823,8 @@ ${a.runs} \u6B21 \xB7 \u6700\u8FD1 ${cleanInline2(a.lastRunBy ?? "\u2014", 20)}
7314
7823
  return { spec: {
7315
7824
  title: "Panel Commands",
7316
7825
  columnsPerRow: cols,
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.",
7318
- actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
7826
+ body: "`/panel` summons the status panel (inside a worker thread, opens that worker's dedicated panel in-thread). Controls: \u{1F504} Refresh, \u{1F4DA} Archive (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 (resident workers: graceful shutdown / force kill), \u267B\uFE0F Resume (when offline), \u{1F440} Peek (live snapshot). Navigation updates the card in place.",
7827
+ actions: [{ id: "panel.home", label: "\u21A9\uFE0F Home" }]
7319
7828
  }, patchOrigin: patchInPlace };
7320
7829
  }
7321
7830
  const homePage = input.cmd === "panel.home" || input.cmd === "panel.refresh" ? parsePage(input.payload) : 1;
@@ -7350,10 +7859,10 @@ function formatRelativeTime(timestamp) {
7350
7859
  const mins = Math.floor(diffMs / 6e4);
7351
7860
  const hours = Math.floor(diffMs / 36e5);
7352
7861
  const days = Math.floor(diffMs / 864e5);
7353
- if (mins < 1) return "\u521A\u521A";
7354
- if (mins < 60) return `${mins}m\u524D`;
7355
- if (hours < 24) return `${hours}h\u524D`;
7356
- if (days < 7) return `${days}d\u524D`;
7862
+ if (mins < 1) return "just now";
7863
+ if (mins < 60) return `${mins}m ago`;
7864
+ if (hours < 24) return `${hours}h ago`;
7865
+ if (days < 7) return `${days}d ago`;
7357
7866
  const d = new Date(timestamp);
7358
7867
  const mm = String(d.getMonth() + 1).padStart(2, "0");
7359
7868
  const dd = String(d.getDate()).padStart(2, "0");
@@ -7404,11 +7913,11 @@ function composeArchiveListCard(opts = {}) {
7404
7913
  const bridge = currentWorkerLifecycleBridge();
7405
7914
  if (!bridge?.listRecentSessions) {
7406
7915
  return {
7407
- title: "\u{1F4DA} \u5F52\u6863\u4F1A\u8BDD",
7916
+ title: "\u{1F4DA} Session Archive",
7408
7917
  color: "grey",
7409
7918
  columnsPerRow: cols,
7410
- body: "\u5F53\u524D\u8FDB\u7A0B\u672A\u6302\u8F7D `pie-proc` \u5F52\u6863\u7D22\u5F15\uFF0C\u65E0\u6CD5\u5217\u51FA\u5386\u53F2\u4F1A\u8BDD\u3002",
7411
- actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
7919
+ body: "`pie-proc` archive index is not attached on this host; historical sessions cannot be listed.",
7920
+ actions: [{ id: "panel.home", label: "\u21A9\uFE0F Home" }]
7412
7921
  };
7413
7922
  }
7414
7923
  const livePeers = scanPeers();
@@ -7434,18 +7943,18 @@ function composeArchiveListCard(opts = {}) {
7434
7943
  const items = listed.sessions.map((s) => {
7435
7944
  const livePeer = liveBySession.get(s.sessionId);
7436
7945
  const threadUrl = resolveSessionThreadUrl(s.sessionId);
7437
- const statusBadge = livePeer ? livePeer.state === "working" ? "\u{1F7E1} \u8FD0\u884C\u4E2D" : "\u{1F7E2} \u5728\u7EBF" : s.livePid ? `\u{1F7E1} \u5360\u7528(pid ${s.livePid})` : s.resumable ? "\u{1F4A4} \u53EF\u5524\u9192" : "\u{1F512} \u53EA\u8BFB";
7946
+ const statusBadge = livePeer ? livePeer.state === "working" ? "\u{1F7E1} Working" : "\u{1F7E2} Online" : s.livePid ? `\u{1F7E1} Busy (pid ${s.livePid})` : s.resumable ? "\u{1F4A4} Resumable" : "\u{1F512} Read-only";
7438
7947
  const metaParts = [
7439
7948
  statusBadge,
7440
7949
  formatRelativeTime(s.updatedAt),
7441
7950
  `${s.messageCount} msgs`,
7442
- ...threadUrl ? [`[\u{1F4AC} \u8BDD\u9898](${threadUrl})`] : []
7951
+ ...threadUrl ? [`[\u{1F4AC} Thread](${threadUrl})`] : []
7443
7952
  ];
7444
7953
  const rowActions = [
7445
- { id: `panel.archive.view.${s.sessionId}`, label: "\u{1F440} \u6458\u8981", payload: { page, scope } }
7954
+ { id: `panel.archive.view.${s.sessionId}`, label: "\u{1F440} Summary", payload: { page, scope } }
7446
7955
  ];
7447
7956
  if (livePeer && !livePeer.isManager) {
7448
- rowActions.push({ id: `panel.worker.${livePeer.instanceId}`, label: "\u{1F527} \u7BA1\u7406" });
7957
+ rowActions.push({ id: `panel.worker.${livePeer.instanceId}`, label: "\u{1F527} Manage" });
7449
7958
  } else if (!livePeer && s.resumable) {
7450
7959
  rowActions.push({
7451
7960
  id: `panel.resume.${s.sessionId}`,
@@ -7460,30 +7969,30 @@ ${metaParts.join(" \xB7 ")}`,
7460
7969
  };
7461
7970
  });
7462
7971
  const nav = [];
7463
- if (page > 1) nav.push({ id: "panel.archive", label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1, scope } });
7464
- if (page < totalPages) nav.push({ id: "panel.archive", label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1, scope } });
7465
- const toggleAction = scope === "all" ? { id: "panel.archive", label: "\u{1F4AC} \u4EC5 IM \u8BDD\u9898", payload: { page: 1, scope: "im" } } : { id: "panel.archive", label: "\u{1F310} \u5168\u90E8\u76EE\u5F55", payload: { page: 1, scope: "all" } };
7466
- const scopeLabel = scope === "im" ? "\u4EC5 IM \u8BDD\u9898" : "\u5168\u90E8\u76EE\u5F55";
7467
- const emptyText = scope === "im" ? "_\u6682\u65E0\u5E26 IM \u8BDD\u9898\u8BB0\u5F55\u7684\u5386\u53F2\u4F1A\u8BDD \u2014 \u53EF\u5207\u6362\u300C\u{1F310} \u5168\u90E8\u76EE\u5F55\u300D\u67E5\u770B\u5168\u90E8\u9879\u76EE\u4F1A\u8BDD\u3002_" : "_\u6682\u65E0\u53EF\u5C55\u793A\u7684\u5386\u53F2\u4F1A\u8BDD\u8BB0\u5F55\u3002_";
7972
+ if (page > 1) nav.push({ id: "panel.archive", label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1, scope } });
7973
+ if (page < totalPages) nav.push({ id: "panel.archive", label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1, scope } });
7974
+ const toggleAction = scope === "all" ? { id: "panel.archive", label: "\u{1F4AC} IM Threads", payload: { page: 1, scope: "im" } } : { id: "panel.archive", label: "\u{1F310} All Dirs", payload: { page: 1, scope: "all" } };
7975
+ const scopeLabel = scope === "im" ? "IM Threads" : "All Dirs";
7976
+ const emptyText = scope === "im" ? '_No archived sessions with IM threads yet \u2014 switch to "\u{1F310} All Dirs" to browse all project sessions._' : "_No archived sessions available._";
7468
7977
  return {
7469
- title: "\u{1F4DA} \u5F52\u6863\u4F1A\u8BDD",
7470
- subtitle: `${scopeLabel} \xB7 ${listed.total} \u6761${listed.truncated ? "+" : ""}${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""}`,
7978
+ title: "\u{1F4DA} Session Archive",
7979
+ subtitle: `${scopeLabel} \xB7 ${listed.total}${listed.truncated ? "+" : ""} session(s)${totalPages > 1 ? ` \xB7 p${page}/${totalPages}` : ""}`,
7471
7980
  color: "violet",
7472
7981
  columnsPerRow: cols,
7473
7982
  body: items.length === 0 ? emptyText : "",
7474
7983
  ...items.length > 0 ? { items } : {},
7475
- footer: "\u70B9\u51FB \u{1F440} \u6458\u8981\u79BB\u7EBF\u67E5\u770B\u6700\u8FD1\u5BF9\u8BDD\uFF08zero LLM\uFF09\uFF1B\u70B9\u51FB \u267B\uFE0F Resume \u5524\u9192\u5BF9\u5E94 Worker\uFF08\u65E0\u8BDD\u9898\u4F1A\u81EA\u52A8\u5EFA\u8BDD\u9898\uFF09\u3002",
7984
+ footer: "Tap \u{1F440} Summary to read recent turns offline (zero LLM), or \u267B\uFE0F Resume to wake the worker (auto-opens a thread if needed).",
7476
7985
  actions: [
7477
7986
  ...nav,
7478
7987
  toggleAction,
7479
7988
  { id: "panel.archive", label: "\u{1F504} Refresh", payload: { page, scope } },
7480
- { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }
7989
+ { id: "panel.home", label: "\u21A9\uFE0F Home" }
7481
7990
  ]
7482
7991
  };
7483
7992
  }
7484
7993
  function renderRecentTurnsMarkdown(turns) {
7485
7994
  if (turns.length === 0) {
7486
- return "_\u6700\u8FD1\u672A\u627E\u5230\u53EF\u8BFB\u6587\u672C\u5BF9\u8BDD\uFF08\u53EF\u80FD\u5168\u662F\u5DE5\u5177\u8C03\u7528\u6216\u5DF2\u538B\u7F29\uFF09\u3002_";
7995
+ return "_No readable text turns found recently (may contain only tool calls or compacted entries)._";
7487
7996
  }
7488
7997
  const blocks = [];
7489
7998
  let used = 0;
@@ -7504,25 +8013,25 @@ function composeArchiveDetailCard(sessionId, opts = {}) {
7504
8013
  const cols = opts.inThread ? 2 : 3;
7505
8014
  const page = Math.max(1, Math.floor(opts.page ?? 1));
7506
8015
  const scope = opts.scope === "im" ? "im" : "all";
7507
- const backAction = { id: "panel.archive", label: "\u21A9\uFE0F \u8FD4\u56DE\u5F52\u6863", payload: { page, scope } };
7508
- const homeAction = { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" };
8016
+ const backAction = { id: "panel.archive", label: "\u21A9\uFE0F Archive", payload: { page, scope } };
8017
+ const homeAction = { id: "panel.home", label: "\u{1F4CB} Home" };
7509
8018
  const bridge = currentWorkerLifecycleBridge();
7510
8019
  if (!bridge?.readSessionRecentTurns) {
7511
8020
  return {
7512
- title: "\u{1F4C4} \u4F1A\u8BDD\u6458\u8981\u4E0D\u53EF\u7528",
8021
+ title: "\u{1F4C4} Summary Unavailable",
7513
8022
  color: "grey",
7514
8023
  columnsPerRow: cols,
7515
- body: "\u5F53\u524D\u8FDB\u7A0B\u672A\u6302\u8F7D `pie-proc` \u5F52\u6863\u8BFB\u53D6\u5668\u3002",
8024
+ body: "`pie-proc` archive reader is not attached on this host.",
7516
8025
  actions: [backAction, homeAction]
7517
8026
  };
7518
8027
  }
7519
8028
  const res = bridge.readSessionRecentTurns(sessionId, { maxTurns: 6, maxCharsPerTurn: 300 });
7520
8029
  if (!res.ok || !res.session) {
7521
8030
  return {
7522
- title: "\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u4F1A\u8BDD",
8031
+ title: "\u26A0\uFE0F Cannot Read Session",
7523
8032
  color: "red",
7524
8033
  columnsPerRow: cols,
7525
- body: sanitizeLiteralMarkdown(res.error ?? `\u672A\u627E\u5230\u4F1A\u8BDD ${sessionId}`),
8034
+ body: sanitizeLiteralMarkdown(res.error ?? `Session ${sessionId} not found`),
7526
8035
  actions: [backAction, homeAction]
7527
8036
  };
7528
8037
  }
@@ -7530,19 +8039,19 @@ function composeArchiveDetailCard(sessionId, opts = {}) {
7530
8039
  const livePeer = findPeerBySessionId(s.sessionId);
7531
8040
  const threadUrl = resolveSessionThreadUrl(s.sessionId);
7532
8041
  const shortCwd = formatShortCwd(s.cwd);
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)})`;
8042
+ const statusText = livePeer ? livePeer.state === "working" ? "\u{1F7E1} Working (online)" : "\u{1F7E2} Online" : s.livePid ? `\u{1F7E1} Busy (pid ${s.livePid})` : s.resumable ? "\u{1F4A4} Offline \xB7 Resumable" : `\u{1F512} Not resumable (${cleanInline3(s.resumeReason ?? "blocked by allowCwd", 48)})`;
7534
8043
  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})`] : []
8044
+ `- **title**: ${cleanInline3(cleanArchiveTitle(s.name), 72)}`,
8045
+ `- **session**: \`${cleanCodeSpan(s.sessionId, 64)}\`${s.workerName ? ` \xB7 **worker**: ${cleanInline3(s.workerName, 48)}` : ""}`,
8046
+ ...shortCwd ? [`- **cwd**: \`${cleanCodeSpan(shortCwd, 88)}\``] : [],
8047
+ ...s.model ? [`- **model**: \`${cleanCodeSpan(s.model + (s.thinkingLevel ? ` (${s.thinkingLevel})` : ""), 56)}\``] : [],
8048
+ `- **updated**: ${formatClock(s.updatedAt)} (${formatRelativeTime(s.updatedAt)}) \xB7 ${s.messageCount} msgs`,
8049
+ `- **status**: ${statusText}`,
8050
+ ...threadUrl ? [`- **thread**: [\u{1F4AC} Open Thread \u2197](${threadUrl})`] : []
7542
8051
  ];
7543
8052
  const actions = [];
7544
8053
  if (livePeer && !livePeer.isManager) {
7545
- actions.push({ id: `panel.worker.${livePeer.instanceId}`, label: "\u{1F527} \u7BA1\u7406 Worker", style: "primary" });
8054
+ actions.push({ id: `panel.worker.${livePeer.instanceId}`, label: "\u{1F527} Manage Worker", style: "primary" });
7546
8055
  } else if (!livePeer && s.resumable) {
7547
8056
  actions.push({
7548
8057
  id: `panel.resume.${s.sessionId}`,
@@ -7565,7 +8074,7 @@ function composeArchiveDetailCard(sessionId, opts = {}) {
7565
8074
  body: `${infoLines.join("\n")}
7566
8075
 
7567
8076
  ---
7568
- **\u6700\u8FD1\u5BF9\u8BDD\u6458\u8981**\uFF08\u79BB\u7EBF\u8BFB\u53D6\uFF0Czero LLM\uFF09
8077
+ **Recent Conversation Summary** (offline read, zero LLM)
7569
8078
 
7570
8079
  ${renderRecentTurnsMarkdown(res.turns)}`,
7571
8080
  actions
@@ -7581,11 +8090,11 @@ function runArchivePanelCommand(panelCmd, opts) {
7581
8090
  handled: true,
7582
8091
  keyPrefix: "panel-archive-denied",
7583
8092
  spec: {
7584
- title: "\u{1F4DA} \u5F52\u6863\u4E0D\u53EF\u7528",
8093
+ title: "\u{1F4DA} Archive Unavailable",
7585
8094
  color: "red",
7586
8095
  columnsPerRow: cols,
7587
- body: "\u26D4\uFE0F \u5F52\u6863\u4F1A\u8BDD\u67E5\u8BE2\u4EC5\u9650\u5DF2\u6388\u6743\u7684\u79C1\u804A\u6216\u7ED1\u5B9A\u7FA4\u804A\u4F7F\u7528\u3002",
7588
- actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
8096
+ body: "\u26D4\uFE0F Session archive is restricted to authorized DMs or the bound group chat.",
8097
+ actions: [{ id: "panel.home", label: "\u21A9\uFE0F Home" }]
7589
8098
  }
7590
8099
  };
7591
8100
  }
@@ -7603,11 +8112,11 @@ function runArchivePanelCommand(panelCmd, opts) {
7603
8112
  handled: true,
7604
8113
  keyPrefix: "panel-archive-invalid",
7605
8114
  spec: {
7606
- title: "\u26A0\uFE0F \u65E0\u6548\u4F1A\u8BDD ID",
8115
+ title: "\u26A0\uFE0F Invalid Session ID",
7607
8116
  color: "red",
7608
8117
  columnsPerRow: cols,
7609
- body: "\u65E0\u6548\u7684\u4F1A\u8BDD\u6807\u8BC6\u7B26\u3002",
7610
- actions: [{ id: "panel.archive", label: "\u21A9\uFE0F \u8FD4\u56DE\u5F52\u6863", payload: nav }]
8118
+ body: "Invalid session identifier.",
8119
+ actions: [{ id: "panel.archive", label: "\u21A9\uFE0F Archive", payload: nav }]
7611
8120
  }
7612
8121
  };
7613
8122
  }
@@ -7621,6 +8130,14 @@ async function ensureResumedSessionTopic(opts) {
7621
8130
  const identity = { provider: opts.provider, targetId: opts.targetId };
7622
8131
  const existing = loadPersistedAnchor(opts.sessionId, identity);
7623
8132
  if (existing?.threadId) {
8133
+ if (opts.connection.latestThreadPosition) {
8134
+ await refreshAnchorThreadPositions(
8135
+ [opts.sessionId],
8136
+ opts.provider,
8137
+ (tid, mid, sig) => opts.connection.latestThreadPosition(tid, mid, sig),
8138
+ { force: true, timeoutMs: 1500 }
8139
+ );
8140
+ }
7624
8141
  return {
7625
8142
  opened: false,
7626
8143
  threadId: existing.threadId,
@@ -7629,37 +8146,47 @@ async function ensureResumedSessionTopic(opts) {
7629
8146
  }
7630
8147
  const dirName = formatProjectName(opts.cwd);
7631
8148
  const displayName = opts.workerName?.trim() || opts.sessionId.slice(0, 12);
7632
- const readyText = `\u267B\uFE0F \u5DF2\u5524\u9192\u5F52\u6863\u4F1A\u8BDD **${cleanInline3(displayName, 40)}**${dirName ? ` (\`${cleanCodeSpan(dirName, 32)}\`)` : ""}
7633
- \u76F4\u63A5\u5728\u672C\u8BDD\u9898\u56DE\u590D\u5373\u53EF\u7EE7\u7EED\u5BF9\u8BDD\u3002`;
8149
+ const readyText = `\u267B\uFE0F Resumed archived session **${cleanInline3(displayName, 40)}**${dirName ? ` (\`${cleanCodeSpan(dirName, 32)}\`)` : ""}
8150
+ Reply in this thread to continue.`;
7634
8151
  const baseKey = `panel-resume-topic-${opts.eventId}-${opts.sessionId}`;
7635
8152
  try {
7636
8153
  let anchorMessageId;
8154
+ let positionQueryMessageId;
7637
8155
  let threadId = null;
7638
8156
  let anchorChatId = existing?.chatId ?? null;
8157
+ let threadPosition;
7639
8158
  if (existing?.messageId) {
7640
8159
  anchorMessageId = existing.messageId;
7641
8160
  const reply = await opts.connection.send(opts.recipient, readyText, baseKey, existing.messageId, { replyInThread: true });
8161
+ positionQueryMessageId = reply?.messageId;
7642
8162
  threadId = reply?.threadId ?? null;
7643
8163
  anchorChatId ??= reply?.chatId ?? null;
8164
+ threadPosition = reply?.threadPosition;
7644
8165
  } else {
7645
8166
  const sent = await opts.connection.send(opts.recipient, readyText, baseKey);
7646
8167
  if (!sent?.messageId) {
7647
- return { opened: false, note: "\u81EA\u52A8\u5EFA\u8BDD\u9898\u5931\u8D25\uFF08\u6D88\u606F\u53D1\u9001\u672A\u8FD4\u56DE messageId\uFF09\uFF0C\u53EF\u5728\u603B\u9762\u677F\u8FDB\u5165\u6216\u4F7F\u7528 `\u540D\u5B57: \u6D88\u606F` \u5BF9\u8BDD\u3002" };
8168
+ return { opened: false, note: "Failed to auto-open a thread (no messageId returned). Open it from Home or address it with `name: message`." };
7648
8169
  }
7649
8170
  anchorMessageId = sent.messageId;
7650
8171
  threadId = sent.threadId ?? null;
7651
8172
  anchorChatId ??= sent.chatId ?? null;
8173
+ threadPosition = sent.threadPosition;
7652
8174
  if (!threadId && opts.connection.openTopic) {
7653
8175
  const opener = await opts.connection.openTopic(opts.recipient, sent.messageId, `${baseKey}-opener`);
8176
+ positionQueryMessageId = opener?.messageId;
7654
8177
  threadId = opener?.threadId ?? null;
7655
8178
  anchorChatId ??= opener?.chatId ?? null;
8179
+ threadPosition = opener?.threadPosition ?? threadPosition;
7656
8180
  }
7657
8181
  }
7658
- if (!threadId || !anchorChatId) {
8182
+ if (!threadId || !anchorChatId || threadPosition === void 0 && positionQueryMessageId) {
7659
8183
  try {
7660
- const meta = await opts.connection.metadata(anchorMessageId);
8184
+ const meta = await opts.connection.metadata(positionQueryMessageId ?? anchorMessageId);
7661
8185
  threadId ??= meta?.threadId ?? null;
7662
8186
  anchorChatId ??= meta?.chatId ?? null;
8187
+ if (!meta?.threadId || !threadId || meta.threadId === threadId) {
8188
+ threadPosition ??= meta?.threadPosition;
8189
+ }
7663
8190
  } catch {
7664
8191
  }
7665
8192
  }
@@ -7675,6 +8202,7 @@ async function ensureResumedSessionTopic(opts) {
7675
8202
  ...threadId ? { threadId } : {},
7676
8203
  home: opts.recipient,
7677
8204
  ...anchorChatId ? { chatId: anchorChatId } : {},
8205
+ ...threadPosition !== void 0 ? { threadPosition } : {},
7678
8206
  at: Date.now()
7679
8207
  });
7680
8208
  claimSessionRoot(opts.provider, anchorMessageId, opts.sessionId);
@@ -7688,7 +8216,7 @@ async function ensureResumedSessionTopic(opts) {
7688
8216
  };
7689
8217
  } catch (error) {
7690
8218
  opts.log(`im-forward: auto-open topic for resumed session ${opts.sessionId} failed: ${error instanceof Error ? error.message : String(error)}`);
7691
- return { opened: false, note: "\u81EA\u52A8\u5EFA\u8BDD\u9898\u5931\u8D25\uFF0C\u53EF\u5728\u603B\u9762\u677F\u6253\u5F00\u8BE5 Worker \u6216\u4F7F\u7528 `\u540D\u5B57: \u6D88\u606F` \u5BF9\u8BDD\u3002" };
8219
+ return { opened: false, note: "Failed to auto-open a thread. Open this worker from Home or address it with `name: message`." };
7692
8220
  }
7693
8221
  }
7694
8222
 
@@ -7924,23 +8452,23 @@ function composeUpdatedModelsCard(opts) {
7924
8452
  banner: opts.banner
7925
8453
  });
7926
8454
  }
7927
- const homeOpt = opts.hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
8455
+ const homeOpt = opts.hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home" }];
7928
8456
  return {
7929
- title: opts.receipt.ok ? "\u2705 \u5DF2\u66F4\u65B0\u914D\u7F6E" : "\u26A0\uFE0F \u66F4\u65B0\u5931\u8D25",
8457
+ title: opts.receipt.ok ? "\u2705 Settings Updated" : "\u26A0\uFE0F Update Failed",
7930
8458
  color: opts.receipt.ok ? "green" : "red",
7931
8459
  columnsPerRow: cols,
7932
8460
  body: `${opts.banner}
7933
8461
 
7934
8462
  ${sanitizeLiteralMarkdown(opts.receipt.detail)}`,
7935
- actions: effectiveScope === "manager" ? [{ id: "panel.models", label: "\u{1F39A} Model & Thinking" }, { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }] : opts.hideHome ? panelHomeAction(true, opts.threadWorkerSessionId, opts.peerRef) : [{ id: `panel.worker.${opts.peerRef}`, label: "\u21A9\uFE0F Worker" }, ...homeOpt]
8463
+ actions: effectiveScope === "manager" ? [{ id: "panel.models", label: "\u{1F39A} Model & Thinking" }, { id: "panel.home", label: "\u{1F4CB} Home" }] : opts.hideHome ? panelHomeAction(true, opts.threadWorkerSessionId, opts.peerRef) : [{ id: `panel.worker.${opts.peerRef}`, label: "\u21A9\uFE0F Worker" }, ...homeOpt]
7936
8464
  };
7937
8465
  }
7938
8466
  function panelHomeAction(inThread, threadWorkerSessionId, peerRef) {
7939
- if (!inThread) return [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
8467
+ if (!inThread) return [{ id: "panel.home", label: "\u{1F4CB} Home" }];
7940
8468
  if (peerRef) return [{ id: `panel.worker.${peerRef}`, label: "\u21A9\uFE0F Worker" }];
7941
8469
  if (threadWorkerSessionId) {
7942
8470
  const live = findPeerBySessionId(threadWorkerSessionId);
7943
- return live ? [{ id: `panel.worker.${live.instanceId}`, label: "\u21A9\uFE0F Worker" }] : [{ id: "panel.worker.offline", label: "\u{1F504} Worker \u9762\u677F", payload: { sessionId: threadWorkerSessionId } }];
8471
+ return live ? [{ id: `panel.worker.${live.instanceId}`, label: "\u21A9\uFE0F Worker" }] : [{ id: "panel.worker.offline", label: "\u{1F504} Worker Panel", payload: { sessionId: threadWorkerSessionId } }];
7944
8472
  }
7945
8473
  return [];
7946
8474
  }
@@ -7971,7 +8499,7 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
7971
8499
  const deny = (reason) => ({
7972
8500
  blocked: true,
7973
8501
  spec: {
7974
- title: "\u26D4\uFE0F \u4EC5\u9650\u5F53\u524D Worker \u9762\u677F",
8502
+ title: "\u26D4\uFE0F Worker Panel Only",
7975
8503
  color: "red",
7976
8504
  columnsPerRow: cols,
7977
8505
  body: reason,
@@ -7979,24 +8507,24 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
7979
8507
  }
7980
8508
  });
7981
8509
  if (THREAD_FORBIDDEN_GLOBAL_CMDS.has(panelCmd.cmd) || panelCmd.cmd.startsWith("panel.archive.view.")) {
7982
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u64CD\u4F5C\u603B\u9762\u677F\u3001\u5F52\u6863\u6216 Manager\uFF0C\u8BF7\u5728\u4E3B\u7FA4/\u79C1\u804A\u4F7F\u7528 `/panel`\u3002");
8510
+ return deny("In-thread worker panels cannot access Home, Archive, or Manager. Use `/panel` in the main chat or DM.");
7983
8511
  }
7984
8512
  if (panelCmd.cmd === "panel.worker.offline" || panelCmd.cmd === "panel.worker.cron.offline") {
7985
8513
  const rawSid = panelCmd.payload && typeof panelCmd.payload === "object" && !Array.isArray(panelCmd.payload) ? panelCmd.payload.sessionId : void 0;
7986
8514
  if (typeof rawSid === "string" && rawSid.trim() && rawSid.trim() !== pinnedWorkerSessionId) {
7987
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u8BBF\u95EE\u5176\u4ED6 Worker \u4F1A\u8BDD\u3002");
8515
+ return deny("In-thread worker panels cannot access other worker sessions.");
7988
8516
  }
7989
8517
  return { blocked: false };
7990
8518
  }
7991
8519
  const resumeMatch = /^panel\.resume\.([A-Za-z0-9][A-Za-z0-9-_]{5,63})$/.exec(panelCmd.cmd);
7992
8520
  if (resumeMatch && resumeMatch[1] !== pinnedWorkerSessionId) {
7993
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u6062\u590D\u5F53\u524D thread \u5BF9\u5E94\u7684 Worker\u3002");
8521
+ return deny("In-thread worker panels can only resume the worker belonging to this thread.");
7994
8522
  }
7995
8523
  const actionMatch = /^panel\.action\.([a-z0-9][a-z0-9-]{0,31})$/.exec(panelCmd.cmd);
7996
8524
  if (actionMatch) {
7997
8525
  const action = findAction(actionMatch[1]);
7998
8526
  if (action?.scope === "manager") {
7999
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u6267\u884C Manager \u7EA7\u52A8\u4F5C\u3002");
8527
+ return deny("In-thread worker panels cannot run manager-scoped actions.");
8000
8528
  }
8001
8529
  return { blocked: false };
8002
8530
  }
@@ -8004,21 +8532,21 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
8004
8532
  if (viewPeerMatch) {
8005
8533
  const peer = scanPeers().find((p) => p.instanceId === viewPeerMatch[1]);
8006
8534
  if (peer && (peer.isManager || peer.sessionId !== pinnedWorkerSessionId)) {
8007
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u67E5\u770B\u6216\u64CD\u4F5C\u5F53\u524D Worker\u3002");
8535
+ return deny("In-thread worker panels can only inspect or control the current worker.");
8008
8536
  }
8009
8537
  return { blocked: false };
8010
8538
  }
8011
8539
  const cronJobMatch = /^panel\.cron\.(?:pause|resume|stop(?:\.confirm)?)\.([A-Za-z0-9-]{8,64})$/.exec(panelCmd.cmd);
8012
8540
  if (cronJobMatch) {
8013
8541
  if (panelCmd.cmd.startsWith("panel.cron.stop.confirm.") && verifiedCronStopSessionId && verifiedCronStopSessionId !== pinnedWorkerSessionId) {
8014
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u64CD\u4F5C\u5F53\u524D Worker \u7684\u5B9A\u65F6\u4EFB\u52A1\u3002");
8542
+ return deny("In-thread worker panels can only manage this worker's scheduled jobs.");
8015
8543
  }
8016
8544
  const bridge = currentCronPanelBridge();
8017
8545
  if (bridge) {
8018
8546
  const jobId = cronJobMatch[1];
8019
8547
  const allMatches = bridge.listJobs().jobs.filter((j) => j.id === jobId);
8020
8548
  if (allMatches.length > 0 && !allMatches.some((j) => j.sessionId === pinnedWorkerSessionId)) {
8021
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u64CD\u4F5C\u5F53\u524D Worker \u7684\u5B9A\u65F6\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u64CD\u4F5C Manager\u3001\u7CFB\u7EDF\u6216\u5176\u4ED6 Worker \u7684\u4EFB\u52A1\u3002");
8549
+ return deny("In-thread worker panels can only manage this worker's scheduled jobs, not manager, system, or other workers' jobs.");
8022
8550
  }
8023
8551
  }
8024
8552
  return { blocked: false };
@@ -8027,10 +8555,10 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
8027
8555
  if (quitExecMatch) {
8028
8556
  const peer = scanPeers().find((p) => p.instanceId === quitExecMatch[1]);
8029
8557
  if (peer && (peer.isManager || peer.sessionId !== pinnedWorkerSessionId)) {
8030
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u9000\u51FA Manager \u6216\u5176\u4ED6 Worker\u3002");
8558
+ return deny("In-thread worker panels cannot quit Manager or other workers.");
8031
8559
  }
8032
8560
  if (verifiedQuitSessionId && verifiedQuitSessionId !== pinnedWorkerSessionId) {
8033
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u9000\u51FA\u5176\u4ED6 Worker\u3002");
8561
+ return deny("In-thread worker panels cannot quit other workers.");
8034
8562
  }
8035
8563
  return { blocked: false };
8036
8564
  }
@@ -8039,10 +8567,10 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
8039
8567
  const peer = scanPeers().find((p) => p.instanceId === treePeerMatch[1]);
8040
8568
  if (peer) {
8041
8569
  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");
8570
+ return deny("In-thread worker panels can only view or control this worker's session tree.");
8043
8571
  }
8044
8572
  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");
8573
+ return deny("In-thread worker panels can only switch this worker's session branch.");
8046
8574
  }
8047
8575
  return { blocked: false };
8048
8576
  }
@@ -8053,7 +8581,7 @@ function guardThreadWorkerScope(panelCmd, workerScoped, inThread, pinnedWorkerSe
8053
8581
  const peer = scanPeers().find((p) => p.instanceId === ctrlPeerMatch[1]);
8054
8582
  if (peer) {
8055
8583
  if (peer.isManager || peer.sessionId !== pinnedWorkerSessionId) {
8056
- return deny("Thread \u5185\u7684 Worker \u9762\u677F\u53EA\u80FD\u64CD\u4F5C\u5F53\u524D Worker\uFF0C\u4E0D\u80FD\u64CD\u4F5C Manager \u6216\u5176\u4ED6 Worker\u3002");
8584
+ return deny("In-thread worker panels can only control the current worker, not Manager or other workers.");
8057
8585
  }
8058
8586
  return { blocked: false };
8059
8587
  }
@@ -8066,7 +8594,7 @@ function isMutatingWorkerLifecycleCommand(cmd) {
8066
8594
  }
8067
8595
  async function runWorkerLifecycleCommand(panelCmd, inThread, verifiedQuit, threadWorkerSessionId, hideHome = inThread, onResumed) {
8068
8596
  const cols = inThread ? 2 : 3;
8069
- const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
8597
+ const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home" }];
8070
8598
  const homeOrWorker = (peerRef) => panelHomeAction(hideHome, threadWorkerSessionId, peerRef);
8071
8599
  const thinkingAction = /^panel\.thinking\.([A-Za-z0-9-]+)\.(off|minimal|low|medium|high|xhigh|max)$/.exec(panelCmd.cmd);
8072
8600
  if (thinkingAction) {
@@ -8076,7 +8604,7 @@ async function runWorkerLifecycleCommand(panelCmd, inThread, verifiedQuit, threa
8076
8604
  const rec = panelCmd.payload && typeof panelCmd.payload === "object" && !Array.isArray(panelCmd.payload) ? panelCmd.payload : void 0;
8077
8605
  const fromManager = !hideHome && rec?.from === "manager";
8078
8606
  const page = typeof rec?.page === "number" && Number.isFinite(rec.page) ? Math.floor(rec.page) : void 0;
8079
- const banner = receipt.ok ? `\u2705 \u5DF2\u5207\u6362\u4E3A \`thinking=${level}\`\uFF08\u4E0B\u6B21\u6267\u884C\u751F\u6548\uFF09` : `\u26A0\uFE0F \u5207\u6362 \`thinking=${level}\` \u5931\u8D25\uFF1A${sanitizeLiteralMarkdown(receipt.detail)}`;
8607
+ const banner = receipt.ok ? `\u2705 Switched to \`thinking=${level}\` (applies next turn)` : `\u26A0\uFE0F Failed to switch \`thinking=${level}\`: ${sanitizeLiteralMarkdown(receipt.detail)}`;
8080
8608
  return {
8081
8609
  handled: true,
8082
8610
  keyPrefix: "panel-thinking",
@@ -8123,10 +8651,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8123
8651
  handled: true,
8124
8652
  keyPrefix: "panel-quit-unverified",
8125
8653
  spec: {
8126
- title: "\u26D4\uFE0F \u9000\u51FA\u786E\u8BA4\u5DF2\u5931\u6548",
8654
+ title: "\u26D4\uFE0F Quit Confirmation Expired",
8127
8655
  color: "red",
8128
8656
  columnsPerRow: cols,
8129
- body: "\u7F3A\u5C11\u6709\u6548\u7684\u9000\u51FA\u786E\u8BA4\u5361\u7247\u7ED1\u5B9A\uFF08\u6216\u5DF2\u8FC7\u671F\uFF09\u3002\u8BF7\u4ECE /panel \u91CD\u65B0\u6253\u5F00\u76EE\u6807 worker \u540E\u518D\u64CD\u4F5C\u3002",
8657
+ body: "Missing or expired quit confirmation binding. Re-open the target worker from `/panel` and try again.",
8130
8658
  actions: homeOrWorker()
8131
8659
  }
8132
8660
  };
@@ -8147,10 +8675,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8147
8675
  handled: true,
8148
8676
  keyPrefix: "panel-quit-stale",
8149
8677
  spec: {
8150
- title: "\u26A0\uFE0F Worker \u4F1A\u8BDD\u5DF2\u53D8\u66F4",
8678
+ title: "\u26A0\uFE0F Worker Session Changed",
8151
8679
  color: "red",
8152
8680
  columnsPerRow: cols,
8153
- body: "\u76EE\u6807\u5361\u7247\u7ED1\u5B9A\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5237\u65B0\u9762\u677F\u540E\u91CD\u8BD5\u3002",
8681
+ body: "This card's target binding expired. Refresh the panel and try again.",
8154
8682
  actions: [
8155
8683
  { id: `panel.worker.${peerRef}`, label: "\u{1F504} Refresh" },
8156
8684
  ...homeOpt
@@ -8163,10 +8691,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8163
8691
  handled: true,
8164
8692
  keyPrefix: "panel-quit-refused",
8165
8693
  spec: {
8166
- title: "\u26D4\uFE0F \u4E0D\u53EF\u8FDC\u7A0B\u9000\u51FA",
8694
+ title: "\u26D4\uFE0F Remote Quit Unavailable",
8167
8695
  color: "red",
8168
8696
  columnsPerRow: cols,
8169
- body: `${peer.isManager ? "Manager \u5BBF\u4E3B" : "\u4EA4\u4E92\u5F0F TUI \u4F1A\u8BDD"}\u4E0D\u5141\u8BB8\u4ECE\u98DE\u4E66\u8FDC\u7A0B\u9000\u51FA\u3002`,
8697
+ body: `${peer.isManager ? "The manager host" : "Interactive TUI sessions"} cannot be quit remotely from IM.`,
8170
8698
  actions: [
8171
8699
  { id: `panel.worker.${peerRef}`, label: "\u21A9\uFE0F Back" },
8172
8700
  ...homeOpt
@@ -8194,7 +8722,7 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8194
8722
  actions2.push({ id: `panel.resume.${peer.sessionId}`, label: "\u267B\uFE0F Resume Worker", style: "primary" });
8195
8723
  }
8196
8724
  if (!exited && managed) {
8197
- actions2.push({ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} \u5F3A\u5236\u7EC8\u6B62", style: "danger", payload: { quit: { ref: peer.instanceId, session: peer.sessionId, generation: managed.generation } } });
8725
+ actions2.push({ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} Force Kill", style: "danger", payload: { quit: { ref: peer.instanceId, session: peer.sessionId, generation: managed.generation } } });
8198
8726
  }
8199
8727
  actions2.push({ id: "panel.worker.offline", label: "\u{1F504} Refresh", payload: { sessionId: peer.sessionId } });
8200
8728
  actions2.push(...homeOpt);
@@ -8202,17 +8730,17 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8202
8730
  handled: true,
8203
8731
  keyPrefix: "panel-quit-ok",
8204
8732
  spec: {
8205
- title: exited ? `\u2705 Worker \u5DF2\u9000\u51FA \xB7 ${peer.name}` : `\u23F3 \u4F18\u96C5\u9000\u51FA\u5DF2\u4E0B\u53D1 \xB7 ${peer.name}`,
8733
+ title: exited ? `\u2705 Worker Exited \xB7 ${peer.name}` : `\u23F3 Graceful Quit Sent \xB7 ${peer.name}`,
8206
8734
  color: exited ? "green" : "blue",
8207
8735
  columnsPerRow: cols,
8208
- body: exited ? resumable?.allowed ? `\u5DF2\u4F18\u96C5\u9000\u51FA \`${cleanCodeSpan(peer.name, 48)}\`\uFF08\u4F1A\u8BDD \`${cleanCodeSpan(peer.sessionId, 64)}\` \u5DF2\u4FDD\u5B58\uFF0C\u53EF\u968F\u65F6 Resume\uFF09\u3002` : `\u5DF2\u4F18\u96C5\u9000\u51FA \`${cleanCodeSpan(peer.name, 48)}\`\uFF08\u4F1A\u8BDD \`${cleanCodeSpan(peer.sessionId, 64)}\` ${resumable?.reason ? `\u6682\u4E0D\u53EF Resume\uFF1A${sanitizeLiteralMarkdown(resumable.reason)}` : "\u5C1A\u672A\u4EA7\u751F\u53EF\u6062\u590D\u7684\u6301\u4E45\u5316\u4F1A\u8BDD\u8BB0\u5F55"}\uFF09\u3002` : `\u5DF2\u5411 \`${cleanCodeSpan(peer.name, 48)}\` \u4E0B\u53D1\u4F18\u96C5\u9000\u51FA\u6307\u4EE4\uFF0C\u6B63\u5728\u6536\u5C3E\u843D\u76D8\u3002\u7A0D\u540E\u70B9 \u{1F504} Refresh \u786E\u8BA4${managed ? "\uFF0C\u82E5\u65E0\u54CD\u5E94\u53EF\u70B9 \u{1F480} \u5F3A\u5236\u7EC8\u6B62" : ""}\u3002`,
8736
+ body: exited ? resumable?.allowed ? `Gracefully exited \`${cleanCodeSpan(peer.name, 48)}\` (session \`${cleanCodeSpan(peer.sessionId, 64)}\` saved; ready to Resume anytime).` : `Gracefully exited \`${cleanCodeSpan(peer.name, 48)}\` (session \`${cleanCodeSpan(peer.sessionId, 64)}\` ${resumable?.reason ? `cannot be resumed yet: ${sanitizeLiteralMarkdown(resumable.reason)}` : "has no persisted resumable history yet"}).` : `Sent graceful quit to \`${cleanCodeSpan(peer.name, 48)}\`; flushing state. Tap \u{1F504} Refresh shortly to verify${managed ? ", or tap \u{1F480} Force Kill if unresponsive" : ""}.`,
8209
8737
  actions: actions2
8210
8738
  }
8211
8739
  };
8212
8740
  }
8213
8741
  const actions = [];
8214
8742
  if (managed) {
8215
- actions.push({ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} \u5F3A\u5236\u7EC8\u6B62", style: "danger", payload: { quit: { ref: peer.instanceId, session: peer.sessionId, generation: managed.generation } } });
8743
+ actions.push({ id: `panel.quit.force.${peer.instanceId}`, label: "\u{1F480} Force Kill", style: "danger", payload: { quit: { ref: peer.instanceId, session: peer.sessionId, generation: managed.generation } } });
8216
8744
  }
8217
8745
  actions.push({ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Back" });
8218
8746
  actions.push(...homeOpt);
@@ -8220,10 +8748,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8220
8748
  handled: true,
8221
8749
  keyPrefix: "panel-quit-fail",
8222
8750
  spec: {
8223
- title: `\u26A0\uFE0F \u4F18\u96C5\u9000\u51FA\u672A\u54CD\u5E94 \xB7 ${peer.name}`,
8751
+ title: `\u26A0\uFE0F Graceful Quit Unresponsive \xB7 ${peer.name}`,
8224
8752
  color: "red",
8225
8753
  columnsPerRow: cols,
8226
- body: `${sanitizeLiteralMarkdown(receipt.detail)}${managed ? "\n\n\u8BE5 worker \u7531 `pie-proc` \u6258\u7BA1\uFF0C\u53EF\u70B9\u51FB\u4E0B\u65B9 **\u{1F480} \u5F3A\u5236\u7EC8\u6B62**\uFF08\u6309 launchToken \u4E25\u683C\u6821\u9A8C\u540E\u6E05\u7406\u8FDB\u7A0B\u7EC4\uFF09\u3002" : ""}`,
8754
+ body: `${sanitizeLiteralMarkdown(receipt.detail)}${managed ? "\n\nThis worker is supervised by `pie-proc`; tap **\u{1F480} Force Kill** below to terminate its process group (verified by launchToken)." : ""}`,
8227
8755
  actions
8228
8756
  }
8229
8757
  };
@@ -8236,10 +8764,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8236
8764
  handled: true,
8237
8765
  keyPrefix: "panel-quit-force-unverified",
8238
8766
  spec: {
8239
- title: "\u26D4\uFE0F \u5F3A\u5236\u7EC8\u6B62\u7ED1\u5B9A\u5DF2\u5931\u6548",
8767
+ title: "\u26D4\uFE0F Force Kill Binding Expired",
8240
8768
  color: "red",
8241
8769
  columnsPerRow: cols,
8242
- body: "\u7F3A\u5C11\u6709\u6548\u7684\u5F3A\u5236\u7EC8\u6B62\u5361\u7247\u7ED1\u5B9A\uFF08\u6216\u5DF2\u8FC7\u671F\uFF09\u3002\u8BF7\u4ECE /panel \u91CD\u65B0\u6253\u5F00\u76EE\u6807 worker \u540E\u518D\u64CD\u4F5C\u3002",
8770
+ body: "Missing or expired force-kill card binding. Re-open the target worker from `/panel` and try again.",
8243
8771
  actions: homeOrWorker()
8244
8772
  }
8245
8773
  };
@@ -8251,10 +8779,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8251
8779
  handled: true,
8252
8780
  keyPrefix: "panel-quit-force-refused",
8253
8781
  spec: {
8254
- title: "\u26D4\uFE0F \u4E0D\u53EF\u5F3A\u5236\u7EC8\u6B62",
8782
+ title: "\u26D4\uFE0F Force Kill Unavailable",
8255
8783
  color: "red",
8256
8784
  columnsPerRow: cols,
8257
- body: "Manager \u6216\u4EA4\u4E92\u5F0F TUI \u4F1A\u8BDD\u4E0D\u652F\u6301\u8FDC\u7A0B\u5F3A\u5236\u7EC8\u6B62\u3002",
8785
+ body: "Manager and interactive TUI sessions do not support remote force kill.",
8258
8786
  actions: homeOrWorker(peerRef)
8259
8787
  }
8260
8788
  };
@@ -8264,10 +8792,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8264
8792
  handled: true,
8265
8793
  keyPrefix: "panel-quit-force-stale",
8266
8794
  spec: {
8267
- title: "\u26A0\uFE0F Worker \u4F1A\u8BDD\u5DF2\u53D8\u66F4",
8795
+ title: "\u26A0\uFE0F Worker Session Changed",
8268
8796
  color: "red",
8269
8797
  columnsPerRow: cols,
8270
- body: "\u76EE\u6807\u5361\u7247\u7ED1\u5B9A\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5237\u65B0\u9762\u677F\u540E\u91CD\u8BD5\u3002",
8798
+ body: "This card's target binding expired. Refresh the panel and try again.",
8271
8799
  actions: homeOrWorker()
8272
8800
  }
8273
8801
  };
@@ -8280,10 +8808,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8280
8808
  handled: true,
8281
8809
  keyPrefix: "panel-quit-force-unmanaged",
8282
8810
  spec: {
8283
- title: "\u26A0\uFE0F \u65E0\u6CD5\u5F3A\u5236\u7EC8\u6B62",
8811
+ title: "\u26A0\uFE0F Cannot Force Kill",
8284
8812
  color: "red",
8285
8813
  columnsPerRow: cols,
8286
- body: "\u672A\u5728\u5F53\u524D manager \u7684 `pie-proc` \u6CE8\u518C\u8868\u4E2D\u627E\u5230\u8BE5\u6258\u7BA1 worker\uFF08\u53EF\u80FD\u5DF2\u9000\u51FA\u6216\u5E76\u975E\u7531 manager \u62C9\u8D77\uFF09\u3002",
8814
+ body: "Managed worker not found in this manager's `pie-proc` registry (it may have exited or was not spawned by this manager).",
8287
8815
  actions: [
8288
8816
  { id: "panel.worker.offline", label: "\u{1F504} Refresh", payload: { sessionId: targetSession } },
8289
8817
  ...homeOpt
@@ -8296,10 +8824,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8296
8824
  handled: true,
8297
8825
  keyPrefix: "panel-quit-force-incarnation",
8298
8826
  spec: {
8299
- title: "\u26D4\uFE0F Worker \u5B9E\u4F8B\u4EE3\u9645\u5DF2\u53D8\u66F4",
8827
+ title: "\u26D4\uFE0F Worker Generation Changed",
8300
8828
  color: "red",
8301
8829
  columnsPerRow: cols,
8302
- body: "\u8BE5\u5F3A\u5236\u7EC8\u6B62\u5361\u7247\u7B7E\u53D1\u81EA\u66F4\u65E9\u7684 worker \u8FDB\u7A0B\u4EE3\u9645\uFF08\u53EF\u80FD\u5DF2\u91CD\u542F/Resume \u4E3A\u65B0\u5B9E\u4F8B\uFF09\uFF0C\u5DF2\u62D2\u7EDD\u8BEF\u6740\u65B0\u8FDB\u7A0B\u3002\u8BF7\u5237\u65B0\u9762\u677F\u540E\u91CD\u8BD5\u3002",
8830
+ body: "This force-kill card was issued for an earlier worker generation (the worker may have restarted or resumed). Refused to kill the new process; refresh and retry.",
8303
8831
  actions: [
8304
8832
  { id: "panel.worker.offline", label: "\u{1F504} Refresh", payload: { sessionId: targetSession } },
8305
8833
  ...homeOpt
@@ -8313,7 +8841,7 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8313
8841
  handled: true,
8314
8842
  keyPrefix: "panel-quit-force-result",
8315
8843
  spec: {
8316
- title: res.ok ? `\u2705 \u5DF2\u5F3A\u5236\u7EC8\u6B62 \xB7 ${managed.name}` : `\u26A0\uFE0F \u5F3A\u5236\u7EC8\u6B62\u672A\u786E\u8BA4 \xB7 ${managed.name}`,
8844
+ title: res.ok ? `\u2705 Force Killed \xB7 ${managed.name}` : `\u26A0\uFE0F Force Kill Unconfirmed \xB7 ${managed.name}`,
8317
8845
  color: res.ok ? "green" : "red",
8318
8846
  columnsPerRow: cols,
8319
8847
  body: sanitizeLiteralMarkdown(res.detail),
@@ -8331,7 +8859,7 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8331
8859
  const rec = isRecord(panelCmd.payload) ? panelCmd.payload : void 0;
8332
8860
  const archiveBack = !hideHome && rec?.from === "archive" ? [{
8333
8861
  id: "panel.archive",
8334
- label: "\u21A9\uFE0F \u8FD4\u56DE\u5F52\u6863",
8862
+ label: "\u21A9\uFE0F Archive",
8335
8863
  payload: {
8336
8864
  page: typeof rec.page === "number" && Number.isFinite(rec.page) && rec.page >= 1 ? Math.floor(rec.page) : 1,
8337
8865
  scope: rec.scope === "im" ? "im" : "all"
@@ -8344,14 +8872,14 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8344
8872
  handled: true,
8345
8873
  keyPrefix: "panel-resume-live",
8346
8874
  spec: {
8347
- title: `\u{1F7E2} Worker \u5DF2\u5728\u7EBF \xB7 ${sanitizeLiteralMarkdown(alreadyLive.name)}`,
8875
+ title: `\u{1F7E2} Worker Already Online \xB7 ${sanitizeLiteralMarkdown(alreadyLive.name)}`,
8348
8876
  color: "green",
8349
8877
  columnsPerRow: cols,
8350
- body: `\u4F1A\u8BDD \`${cleanCodeSpan(sessionId, 64)}\` \u5F53\u524D\u5DF2\u5728\u7EBF\uFF08\u72B6\u6001\uFF1A${sanitizeLiteralMarkdown(alreadyLive.state)}\uFF09\uFF0C\u65E0\u9700\u91CD\u590D\u5524\u9192\u3002${liveThread ? `
8878
+ body: `Session \`${cleanCodeSpan(sessionId, 64)}\` is already online (state: ${sanitizeLiteralMarkdown(alreadyLive.state)}).${liveThread ? `
8351
8879
 
8352
- [\u{1F4AC} \u6253\u5F00\u8BDD\u9898 \u2197](${liveThread})` : ""}`,
8880
+ [\u{1F4AC} Open Thread \u2197](${liveThread})` : ""}`,
8353
8881
  actions: [
8354
- { id: `panel.worker.${alreadyLive.instanceId}`, label: "\u{1F527} \u6253\u5F00 Worker \u9762\u677F", style: "primary" },
8882
+ { id: `panel.worker.${alreadyLive.instanceId}`, label: "\u{1F527} Open Worker Panel", style: "primary" },
8355
8883
  ...archiveBack,
8356
8884
  ...homeOpt
8357
8885
  ]
@@ -8364,10 +8892,10 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8364
8892
  handled: true,
8365
8893
  keyPrefix: "panel-resume-unavailable",
8366
8894
  spec: {
8367
- title: "\u26A0\uFE0F Resume \u4E0D\u53EF\u7528",
8895
+ title: "\u26A0\uFE0F Resume Unavailable",
8368
8896
  color: "red",
8369
8897
  columnsPerRow: cols,
8370
- body: "\u5F53\u524D\u8FDB\u7A0B\u672A\u6302\u8F7D `pie-proc` \u751F\u547D\u5468\u671F\u7BA1\u7406\u5668\uFF0C\u65E0\u6CD5\u8FDC\u7A0B\u62C9\u8D77 worker\u3002",
8898
+ body: "`pie-proc` lifecycle manager is not attached on this host; cannot resume workers remotely.",
8371
8899
  actions: [...archiveBack, ...homeOrWorker()]
8372
8900
  }
8373
8901
  };
@@ -8380,11 +8908,11 @@ ${sanitizeLiteralMarkdown(receipt.detail)}`,
8380
8908
  if (topic.threadUrl) {
8381
8909
  topicLine = topic.opened ? `
8382
8910
 
8383
- \u{1F195} \u5DF2\u81EA\u52A8\u521B\u5EFA\u65B0\u8BDD\u9898\uFF1A[\u{1F4AC} \u6253\u5F00\u8BDD\u9898 \u2197](${topic.threadUrl})` : `
8911
+ \u{1F195} Opened a new thread: [\u{1F4AC} Open Thread \u2197](${topic.threadUrl})` : `
8384
8912
 
8385
- \u{1F4AC} \u5DF2\u5173\u8054\u539F\u8BDD\u9898\uFF1A[\u{1F4AC} \u6253\u5F00\u539F\u8BDD\u9898 \u2197](${topic.threadUrl})`;
8913
+ \u{1F4AC} Linked existing thread: [\u{1F4AC} Open Thread \u2197](${topic.threadUrl})`;
8386
8914
  } else if (topic.opened) {
8387
- topicLine = "\n\n\u{1F195} \u5DF2\u81EA\u52A8\u53D1\u9001\u5C31\u7EEA\u6D88\u606F\u5E76\u521B\u5EFA\u65B0\u8BDD\u9898\uFF0C\u53EF\u76F4\u63A5\u5728\u65B0\u8BDD\u9898\u91CC\u56DE\u590D\u7EE7\u7EED\u5BF9\u8BDD\u3002";
8915
+ topicLine = "\n\n\u{1F195} Sent a ready message and opened a new thread \u2014 reply there to continue.";
8388
8916
  } else if (topic.note) {
8389
8917
  topicLine = `
8390
8918
 
@@ -8395,14 +8923,14 @@ _${sanitizeLiteralMarkdown(topic.note)}_`;
8395
8923
  handled: true,
8396
8924
  keyPrefix: "panel-resume-result",
8397
8925
  spec: {
8398
- title: res.ok ? `\u267B\uFE0F Worker \u5DF2\u62C9\u8D77${res.name ? ` \xB7 ${res.name}` : ""}` : "\u26A0\uFE0F Resume \u5931\u8D25",
8926
+ title: res.ok ? `\u267B\uFE0F Worker Resumed${res.name ? ` \xB7 ${res.name}` : ""}` : "\u26A0\uFE0F Resume Failed",
8399
8927
  color: res.ok ? "green" : "red",
8400
8928
  columnsPerRow: cols,
8401
8929
  body: res.ok ? `${sanitizeLiteralMarkdown(res.detail)}${topicLine}
8402
8930
 
8403
- \u7B49\u5F85 1-2 \u79D2\u5F85 worker \u5C31\u7EEA\u540E\uFF0C\u70B9\u4E0B\u65B9 **\u{1F504} \u6253\u5F00 Worker \u9762\u677F** \u67E5\u770B\u5B9E\u65F6\u72B6\u6001\uFF0C\u6216\u76F4\u63A5\u8FDB\u5165\u8BDD\u9898\u7EE7\u7EED\u53D1\u6D88\u606F\u3002` : sanitizeLiteralMarkdown(res.detail),
8931
+ Wait 1\u20132s for the worker to connect, then tap **\u{1F504} Open Worker Panel** below or continue in its thread.` : sanitizeLiteralMarkdown(res.detail),
8404
8932
  actions: [
8405
- { id: "panel.worker.offline", label: "\u{1F504} \u6253\u5F00 Worker \u9762\u677F", payload: { sessionId } },
8933
+ { id: "panel.worker.offline", label: "\u{1F504} Open Worker Panel", payload: { sessionId } },
8406
8934
  ...archiveBack,
8407
8935
  ...homeOpt
8408
8936
  ]
@@ -8428,21 +8956,21 @@ function buildPeekCardSpec(targetRef, targetSession, isManagerTarget, cols, rece
8428
8956
  const actions = [
8429
8957
  {
8430
8958
  id: `panel.peek.refresh.${targetRef}`,
8431
- label: meta.page > 1 ? "\u23ED \u6700\u65B0" : "\u{1F504} Refresh",
8959
+ label: meta.page > 1 ? "\u23ED Latest" : "\u{1F504} Refresh",
8432
8960
  payload: { peek: { ref: targetRef, session: targetSession, page: 1 } }
8433
8961
  }
8434
8962
  ];
8435
8963
  if (meta.page < meta.totalPages) {
8436
8964
  actions.push({
8437
8965
  id: `panel.peek.refresh.${targetRef}`,
8438
- label: "\u25C0\uFE0F \u66F4\u65E9",
8966
+ label: "\u25C0\uFE0F Older",
8439
8967
  payload: { peek: { ref: targetRef, session: targetSession, page: meta.page + 1 } }
8440
8968
  });
8441
8969
  }
8442
8970
  if (meta.page > 2) {
8443
8971
  actions.push({
8444
8972
  id: `panel.peek.refresh.${targetRef}`,
8445
- label: "\u8F83\u65B0 \u25B6\uFE0F",
8973
+ label: "Newer \u25B6\uFE0F",
8446
8974
  payload: { peek: { ref: targetRef, session: targetSession, page: meta.page - 1 } }
8447
8975
  });
8448
8976
  }
@@ -8450,7 +8978,7 @@ function buildPeekCardSpec(targetRef, targetSession, isManagerTarget, cols, rece
8450
8978
  actions.push({ id: `panel.worker.${targetRef}`, label: "\u21A9\uFE0F Worker" });
8451
8979
  }
8452
8980
  if (!inThread) {
8453
- actions.push({ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" });
8981
+ actions.push({ id: "panel.home", label: "\u{1F4CB} Home" });
8454
8982
  }
8455
8983
  return {
8456
8984
  title: isManagerTarget ? "\u{1F440} Manager Peek" : "\u{1F440} Worker Peek",
@@ -8515,13 +9043,13 @@ function formatNextTime(next, enabled, state) {
8515
9043
  }
8516
9044
  function formatJobState(job) {
8517
9045
  if (job.state === "running") {
8518
- if (job.pendingAction === "remove") return "\u23F3 \u5F85\u505C\u6B62";
8519
- if (job.pendingAction === "pause") return "\u23F3 \u5F85\u6682\u505C";
9046
+ if (job.pendingAction === "remove") return "\u23F3 stopping";
9047
+ if (job.pendingAction === "pause") return "\u23F3 pausing";
8520
9048
  return "\u{1F7E1} running";
8521
9049
  }
8522
9050
  if (job.state === "blocked") return "\u{1F534} blocked";
8523
9051
  if (!job.enabled) {
8524
- if (job.remaining !== void 0 && job.remaining <= 0) return "\u2705 \u5DF2\u5B8C\u6210";
9052
+ if (job.remaining !== void 0 && job.remaining <= 0) return "\u2705 done";
8525
9053
  return "\u23F8 paused";
8526
9054
  }
8527
9055
  return "\u{1F7E2} ready";
@@ -8547,15 +9075,15 @@ function composeCronListCard(opts) {
8547
9075
  const baseMeta = isWorker ? { from: "worker", ...opts.peer ? { peer: opts.peer.instanceId } : {}, ...targetSessionId ? { sessionId: targetSessionId } : {} } : { from: "global" };
8548
9076
  const backActions = isWorker ? [
8549
9077
  ...opts.peer ? [{ id: `panel.worker.${opts.peer.instanceId}`, label: "\u21A9\uFE0F Worker" }] : targetSessionId ? [{ id: "panel.worker.offline", label: "\u21A9\uFE0F Worker", payload: { sessionId: targetSessionId } }] : [],
8550
- ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }]
8551
- ] : [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }];
9078
+ ...hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home" }]
9079
+ ] : [{ id: "panel.home", label: "\u21A9\uFE0F Home" }];
8552
9080
  const bridge = currentCronPanelBridge();
8553
9081
  if (!bridge) {
8554
9082
  return {
8555
9083
  title: `\u23F0 Cron${titleSuffix}`,
8556
9084
  color: "grey",
8557
9085
  columnsPerRow: cols,
8558
- body: "\u5F53\u524D\u8FDB\u7A0B\u672A\u542F\u7528 `cron` \u6269\u5C55\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u5B9A\u65F6\u4EFB\u52A1\u3002",
9086
+ body: "The `cron` extension is not enabled on this host; scheduled jobs cannot be listed.",
8559
9087
  actions: backActions
8560
9088
  };
8561
9089
  }
@@ -8580,35 +9108,35 @@ function composeCronListCard(opts) {
8580
9108
  const rowActions = [];
8581
9109
  if (job.state === "running") {
8582
9110
  if (job.pendingAction !== "pause" && job.pendingAction !== "remove") {
8583
- rowActions.push({ id: `panel.cron.pause.${job.id}`, label: "\u23F8 \u6682\u505C", payload: actionPayload });
9111
+ rowActions.push({ id: `panel.cron.pause.${job.id}`, label: "\u23F8 Pause", payload: actionPayload });
8584
9112
  }
8585
9113
  if (job.pendingAction !== "remove") {
8586
- rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 \u505C\u6B62", style: "danger", payload: actionPayload });
9114
+ rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 Stop", style: "danger", payload: actionPayload });
8587
9115
  }
8588
9116
  } else if (job.enabled && job.state !== "blocked") {
8589
- rowActions.push({ id: `panel.cron.pause.${job.id}`, label: "\u23F8 \u6682\u505C", payload: actionPayload });
8590
- rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 \u505C\u6B62", style: "danger", payload: actionPayload });
9117
+ rowActions.push({ id: `panel.cron.pause.${job.id}`, label: "\u23F8 Pause", payload: actionPayload });
9118
+ rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 Stop", style: "danger", payload: actionPayload });
8591
9119
  } else {
8592
9120
  if (canResumeJob(job)) {
8593
- rowActions.push({ id: `panel.cron.resume.${job.id}`, label: "\u25B6\uFE0F \u6062\u590D", style: "primary", payload: actionPayload });
9121
+ rowActions.push({ id: `panel.cron.resume.${job.id}`, label: "\u25B6\uFE0F Resume", style: "primary", payload: actionPayload });
8594
9122
  }
8595
- rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 \u505C\u6B62", style: "danger", payload: actionPayload });
9123
+ rowActions.push({ id: `panel.cron.stop.${job.id}`, label: "\u23F9 Stop", style: "danger", payload: actionPayload });
8596
9124
  }
8597
9125
  return { text: lines.join("\n"), actions: rowActions };
8598
9126
  });
8599
9127
  const bodyParts = [];
8600
9128
  if (opts.banner) bodyParts.push(opts.banner);
8601
9129
  if (jobs.length === 0) {
8602
- bodyParts.push(isWorker ? "_\u5F53\u524D Worker \u6682\u65E0\u5B9A\u65F6\u4EFB\u52A1_" : "_\u5F53\u524D\u6682\u65E0\u5B9A\u65F6\u4EFB\u52A1_");
9130
+ bodyParts.push(isWorker ? "_No scheduled jobs for this worker._" : "_No scheduled jobs._");
8603
9131
  }
8604
9132
  const footerParts = [];
8605
9133
  if (listed.warnings && listed.warnings.length > 0) {
8606
9134
  footerParts.push(`\u26A0\uFE0F _${cleanInlineText(listed.warnings.join(" \xB7 "), 160)}_`);
8607
9135
  }
8608
- footerParts.push("\u65B0\u589E\u5B9A\u65F6\u4EFB\u52A1\u8BF7\u76F4\u63A5\u5728\u5BF9\u8BDD\u4E2D\u544A\u8BC9 Pie\uFF1B\u884C\u5185\u6309\u94AE\u53EF\u76F4\u63A5\u6682\u505C\u3001\u6062\u590D\u6216\u505C\u6B62\uFF08zero LLM\uFF09\u3002");
9136
+ footerParts.push("Create new scheduled jobs in chat; inline buttons pause, resume, or stop jobs directly (zero LLM).");
8609
9137
  const navButtons = [];
8610
- if (page > 1) navButtons.push({ id: navCmd, label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { ...baseMeta, page: page - 1 } });
8611
- if (page < totalPages) navButtons.push({ id: navCmd, label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { ...baseMeta, page: page + 1 } });
9138
+ if (page > 1) navButtons.push({ id: navCmd, label: `\u25C0\uFE0F Page ${page - 1}`, payload: { ...baseMeta, page: page - 1 } });
9139
+ if (page < totalPages) navButtons.push({ id: navCmd, label: `Page ${page + 1} \u25B6\uFE0F`, payload: { ...baseMeta, page: page + 1 } });
8612
9140
  navButtons.push({ id: navCmd, label: "\u{1F504} Refresh", payload: { ...baseMeta, page } });
8613
9141
  return {
8614
9142
  title: `\u23F0 Cron${titleSuffix}`,
@@ -8633,20 +9161,20 @@ function composeCronStopConfirmCard(job, opts) {
8633
9161
  cronStop: { jobId: job.id, sessionId: job.sessionId, storeKey: job.storeKey }
8634
9162
  };
8635
9163
  return {
8636
- title: "\u23F9 \u786E\u8BA4\u505C\u6B62\u5B9A\u65F6\u4EFB\u52A1",
9164
+ title: "\u23F9 Confirm Stop Cron Job",
8637
9165
  subtitle: `${cleanCell(job.schedule.text, 48)} \xB7 ${formatJobState(job)}`,
8638
9166
  color: "red",
8639
9167
  columnsPerRow: cols,
8640
9168
  body: [
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)}`] : [],
9169
+ `- **task**: ${cleanCell(job.summary, 64)}`,
9170
+ `- **schedule**: ${formatScheduleCell(job)} \xB7 **state**: ${formatJobState(job)}`,
9171
+ ...job.ownerLabel ? [`- **owner**: ${cleanCell(job.ownerLabel, 32)}`] : [],
8644
9172
  ``,
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"
9173
+ job.state === "running" ? "\u26A0\uFE0F This job is currently running. Confirming will queue removal as soon as this turn finishes." : job.managedBy ? `Stopping removes managed job \`${cleanCodeSpan(job.managedBy, 64)}\` and remembers the opt-out (it will not auto-recreate on restart).` : "Stopping permanently removes this scheduled job (you can recreate it in chat anytime)."
8646
9174
  ].join("\n"),
8647
9175
  actions: [
8648
- { id: `panel.cron.stop.confirm.${job.id}`, label: "\u2705 \u786E\u8BA4\u505C\u6B62\u5220\u9664", style: "danger", payload: stopPayload },
8649
- { id: backListCmd, label: "\u21A9\uFE0F \u53D6\u6D88", payload: baseMeta }
9176
+ { id: `panel.cron.stop.confirm.${job.id}`, label: "\u2705 Confirm Stop", style: "danger", payload: stopPayload },
9177
+ { id: backListCmd, label: "\u21A9\uFE0F Cancel", payload: baseMeta }
8650
9178
  ]
8651
9179
  };
8652
9180
  }
@@ -8715,10 +9243,10 @@ function runCronPanelCommand(panelCmd, opts) {
8715
9243
  handled: true,
8716
9244
  keyPrefix: "panel-worker-cron-offline",
8717
9245
  spec: {
8718
- title: "\u23F0 Cron \xB7 Worker \u5DF2\u79BB\u7EBF",
9246
+ title: "\u23F0 Cron \xB7 Worker Offline",
8719
9247
  color: "grey",
8720
9248
  columnsPerRow: cols,
8721
- body: "\u672A\u627E\u5230\u8BE5 Worker \u4F1A\u8BDD\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002",
9249
+ body: "Worker session not found. Please refresh and try again.",
8722
9250
  actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
8723
9251
  }
8724
9252
  };
@@ -8762,7 +9290,7 @@ function runCronPanelCommand(panelCmd, opts) {
8762
9290
  inThread: opts.inThread,
8763
9291
  hideHome: opts.hideHome,
8764
9292
  page: meta.page,
8765
- banner: "\u26A0\uFE0F \u672A\u627E\u5230\u8BE5\u5B9A\u65F6\u4EFB\u52A1\uFF08\u53EF\u80FD\u5DF2\u88AB\u505C\u6B62\u6216\u5DF2\u5B8C\u6210\uFF09\u3002"
9293
+ banner: "\u26A0\uFE0F Scheduled job not found (it may have already stopped or completed)."
8766
9294
  })
8767
9295
  };
8768
9296
  }
@@ -8803,7 +9331,7 @@ function runCronPanelCommand(panelCmd, opts) {
8803
9331
  inThread: opts.inThread,
8804
9332
  hideHome: opts.hideHome,
8805
9333
  page: meta.page,
8806
- banner: "\u26D4\uFE0F \u505C\u6B62\u786E\u8BA4\u7ED1\u5B9A\u5DF2\u5931\u6548\u6216\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u70B9\u51FB \u23F9 \u505C\u6B62\u6309\u94AE\u3002"
9334
+ banner: "\u26D4\uFE0F Stop confirmation expired or invalid. Please tap \u23F9 Stop again."
8807
9335
  })
8808
9336
  };
8809
9337
  }
@@ -8824,8 +9352,9 @@ function runCronPanelCommand(panelCmd, opts) {
8824
9352
  ...opts.senderId ? { senderId: opts.senderId } : {},
8825
9353
  ...storeKey ? { storeKey } : {}
8826
9354
  });
8827
- const verb = action === "pause" ? "\u6682\u505C" : action === "resume" ? "\u6062\u590D" : "\u505C\u6B62\u5220\u9664";
8828
- const banner = res.ok ? res.outcome === "deferred" ? `\u23F3 \u5DF2\u6392\u961F${verb}\uFF08\u4EFB\u52A1\u8FD0\u884C\u4E2D\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u81EA\u52A8\u751F\u6548\uFF09` : `\u2705 \u5DF2${verb}\u5B9A\u65F6\u4EFB\u52A1${res.job ? `\uFF1A${cleanInlineText(res.job.summary, 40)}` : ""}` : `\u26A0\uFE0F ${verb}\u5931\u8D25\uFF1A${cleanInlineText(res.detail, 120)}`;
9355
+ const verb = action === "pause" ? "pause" : action === "resume" ? "resume" : "stop";
9356
+ const pastVerb = action === "pause" ? "Paused" : action === "resume" ? "Resumed" : "Stopped";
9357
+ const banner = res.ok ? res.outcome === "deferred" ? `\u23F3 Queued ${verb} (job is running; takes effect after this turn)` : `\u2705 ${pastVerb} cron job${res.job ? `: ${cleanInlineText(res.job.summary, 40)}` : ""}` : `\u26A0\uFE0F Failed to ${verb}: ${cleanInlineText(res.detail, 120)}`;
8829
9358
  return {
8830
9359
  handled: true,
8831
9360
  keyPrefix: `panel-cron-${action}`,
@@ -8882,17 +9411,17 @@ function formatNodeClock(timestamp) {
8882
9411
  function kindBadge(kind) {
8883
9412
  switch (kind) {
8884
9413
  case "user":
8885
- return "\u{1F464} \u7528\u6237";
9414
+ return "\u{1F464} User";
8886
9415
  case "assistant":
8887
- return "\u{1F916} \u52A9\u624B";
9416
+ return "\u{1F916} Assistant";
8888
9417
  case "tool":
8889
- return "\u{1F527} \u5DE5\u5177";
9418
+ return "\u{1F527} Tool";
8890
9419
  case "compaction":
8891
- return "\u{1F9F9} \u538B\u7F29";
9420
+ return "\u{1F9F9} Compact";
8892
9421
  case "fork":
8893
- return "\u{1F33F} \u5206\u53C9";
9422
+ return "\u{1F33F} Fork";
8894
9423
  default:
8895
- return "\u{1F4CC} \u8BB0\u5F55";
9424
+ return "\u{1F4CC} Entry";
8896
9425
  }
8897
9426
  }
8898
9427
  function parseTreeMeta(payload) {
@@ -8990,17 +9519,17 @@ function backActionsFor(peer, opts) {
8990
9519
  return [{ id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" }];
8991
9520
  }
8992
9521
  if (opts.from === "home" || peer.isManager) {
8993
- return [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }];
9522
+ return [{ id: "panel.home", label: "\u21A9\uFE0F Home" }];
8994
9523
  }
8995
9524
  return [
8996
9525
  { id: `panel.worker.${peer.instanceId}`, label: "\u21A9\uFE0F Worker" },
8997
- { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
9526
+ { id: "panel.home", label: "\u{1F4CB} Home" }
8998
9527
  ];
8999
9528
  }
9000
9529
  function formatPeerErrorDetail(detail) {
9001
9530
  const unwrapped = unwrapControlReceiptMessage(detail)?.message ?? detail;
9002
9531
  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";
9532
+ return "This session is running an older version of Pie that does not support remote Tree (upgrade to enable).";
9004
9533
  }
9005
9534
  return sanitizeLiteralMarkdown(unwrapped);
9006
9535
  }
@@ -9013,17 +9542,17 @@ function composeTreeListCard(peer, report, opts) {
9013
9542
  const items = report.nodes.map((node) => {
9014
9543
  const marker = node.isHead ? "\u2605" : node.onActivePath ? "\u25CF" : "\u{1F33F}";
9015
9544
  const tags = [];
9016
- if (node.isHead) tags.push("\u5F53\u524D");
9545
+ if (node.isHead) tags.push("current");
9017
9546
  if (node.isBranchPoint) tags.push(`\u2442\xD7${node.childCount}`);
9018
- if (node.isBranchTip) tags.push("\u5206\u652F\u672B");
9547
+ if (node.isBranchTip) tags.push("branch tip");
9019
9548
  if (node.label) tags.push(`\u{1F3F7}\uFE0F${cleanInline4(node.label, 20)}`);
9020
9549
  const tagSuffix = tags.length > 0 ? ` \xB7 ${tags.join(" ")}` : "";
9021
- const preview = cleanInline4(node.preview || "(\u7A7A)", 72);
9550
+ const preview = cleanInline4(node.preview || "(empty)", 72);
9022
9551
  const text = `${marker} **#${node.seq}** ${kindBadge(node.kind)} \xB7 ${formatNodeClock(node.timestamp)}${tagSuffix}
9023
9552
  ${preview}`;
9024
9553
  const actions = node.isHead ? [] : [{
9025
9554
  id: `panel.tree.branch.${peer.instanceId}`,
9026
- label: node.onActivePath ? "\u23EA \u56DE\u9000" : "\u{1F33F} \u5207\u5206\u652F",
9555
+ label: node.onActivePath ? "\u23EA Rewind" : "\u{1F33F} Switch",
9027
9556
  payload: { entryId: node.id, page: report.page, filter: report.filter, from: fromVal }
9028
9557
  }];
9029
9558
  return { text, ...actions.length > 0 ? { actions } : {} };
@@ -9031,37 +9560,37 @@ ${preview}`;
9031
9560
  const bodyLines = [];
9032
9561
  if (opts.banner) bodyLines.push(opts.banner);
9033
9562
  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");
9563
+ bodyLines.push("\u26A0\uFE0F Session is currently busy (streaming or compacting). Stop the current turn before switching branches.");
9035
9564
  }
9036
9565
  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");
9566
+ bodyLines.push("\u2139\uFE0F Large session tree \u2014 scanning only the most recent window (filter still shows latest key entries).");
9038
9567
  }
9039
9568
  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_");
9569
+ bodyLines.push(report.filter === "key" ? '_No key entries yet \u2014 tap "\u{1F50D} Show All" below to view all entries._' : "_No tree entries in this session yet._");
9041
9570
  }
9042
9571
  const navButtons = [];
9043
9572
  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 } });
9573
+ navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `\u25C0\uFE0F Page ${report.page - 1}`, payload: { ...navBase, page: report.page - 1 } });
9045
9574
  }
9046
9575
  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 } });
9576
+ navButtons.push({ id: `panel.tree.${peer.instanceId}`, label: `Page ${report.page + 1} \u25B6\uFE0F`, payload: { ...navBase, page: report.page + 1 } });
9048
9577
  }
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 } };
9578
+ const toggleFilter = report.filter === "key" ? { id: `panel.tree.${peer.instanceId}`, label: "\u{1F50D} Show All", payload: { filter: "all", page: 1, from: fromVal } } : { id: `panel.tree.${peer.instanceId}`, label: "\u2728 Key Only", payload: { filter: "key", page: 1, from: fromVal } };
9050
9579
  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`] : [],
9580
+ headSeq !== void 0 ? `HEAD #${headSeq}` : "no active entry",
9581
+ `${report.totalEntries} entries`,
9582
+ ...report.branchPointCount > 0 ? [`${report.branchPointCount} forks`] : [],
9583
+ ...report.otherBranchTipCount > 0 ? [`${report.otherBranchTipCount} other branches`] : [],
9055
9584
  `p${report.page}/${report.totalPages}`
9056
9585
  ];
9057
9586
  return {
9058
- title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${displayTitle}`,
9587
+ title: `\u{1F333} Session Tree \xB7 ${displayTitle}`,
9059
9588
  subtitle: subtitleParts.join(" \xB7 "),
9060
9589
  color: !report.isIdle || report.compactionRunning ? "violet" : "blue",
9061
9590
  columnsPerRow: cols,
9062
9591
  body: bodyLines.join("\n\n"),
9063
9592
  ...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",
9593
+ footer: "\u2605 current \u25CF active path \u{1F33F} other branch \xB7 Rewind is lossless; old branches stay intact to switch back anytime (zero LLM).",
9065
9594
  actions: [
9066
9595
  ...navButtons,
9067
9596
  toggleFilter,
@@ -9076,62 +9605,62 @@ function composeTreeBranchConfirmCard(peer, detail, opts) {
9076
9605
  const fromVal = opts.from ?? (peer.isManager ? "home" : "worker");
9077
9606
  const cancelAction = {
9078
9607
  id: `panel.tree.${peer.instanceId}`,
9079
- label: "\u21A9\uFE0F \u8FD4\u56DE\u4F1A\u8BDD\u6811",
9608
+ label: "\u21A9\uFE0F Tree",
9080
9609
  payload: { page: opts.page, filter: opts.filter, from: fromVal }
9081
9610
  };
9082
9611
  const entry = detail.entry;
9083
9612
  if (!entry) {
9084
9613
  return {
9085
- title: "\u26A0\uFE0F \u8282\u70B9\u4E0D\u5B58\u5728",
9614
+ title: "\u26A0\uFE0F Entry Not Found",
9086
9615
  subtitle: displayTitle,
9087
9616
  color: "grey",
9088
9617
  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",
9618
+ body: "The target entry no longer exists in this session. Refresh the session tree and try again.",
9090
9619
  actions: [cancelAction]
9091
9620
  };
9092
9621
  }
9093
9622
  if (entry.isHead) {
9094
9623
  return {
9095
- title: `\u{1F333} \u5DF2\u5728\u76EE\u6807\u8282\u70B9 #${entry.seq}`,
9624
+ title: `\u{1F333} Already at Entry #${entry.seq}`,
9096
9625
  subtitle: displayTitle,
9097
9626
  color: "green",
9098
9627
  columnsPerRow: cols,
9099
- body: "\u5F53\u524D\u4F1A\u8BDD\u6307\u9488\u5DF2\u7ECF\u4F4D\u4E8E\u8BE5\u8282\u70B9\uFF0C\u65E0\u9700\u5207\u6362\u3002",
9628
+ body: "The session pointer is already on this entry \u2014 no switch needed.",
9100
9629
  actions: [cancelAction]
9101
9630
  };
9102
9631
  }
9103
9632
  if (!detail.isIdle || detail.compactionRunning) {
9104
9633
  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}`,
9634
+ title: "\u26A0\uFE0F Session Busy \u2014 Cannot Switch Branch",
9635
+ subtitle: `${displayTitle} \xB7 target #${entry.seq}`,
9107
9636
  color: "red",
9108
9637
  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",
9638
+ body: detail.compactionRunning ? "Context compaction is currently running. Wait for it to finish before switching branches." : "A turn is currently running or queued. Stop the current turn before rewinding.",
9110
9639
  actions: [
9111
9640
  ...!detail.compactionRunning ? [{ id: `panel.stop.${peer.instanceId}`, label: "\u23F9 Stop", payload: { from: fromVal, peer: peer.instanceId } }] : [],
9112
9641
  cancelAction
9113
9642
  ]
9114
9643
  };
9115
9644
  }
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`;
9645
+ const impactLine = entry.onActivePath ? `Rewinds the session pointer to **#${entry.seq}** (skipping **${entry.activePathAfterCount}** subsequent entry/entries on the current path).` : `Switches the session pointer to **#${entry.seq}** on another branch.`;
9117
9646
  return {
9118
- title: entry.onActivePath ? `\u23EA \u786E\u8BA4\u56DE\u9000\u5230 #${entry.seq}` : `\u{1F33F} \u786E\u8BA4\u5207\u6362\u5230\u5206\u652F #${entry.seq}`,
9647
+ title: entry.onActivePath ? `\u23EA Confirm Rewind to #${entry.seq}` : `\u{1F33F} Confirm Switch to Branch #${entry.seq}`,
9119
9648
  subtitle: `${displayTitle} \xB7 ${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)}`,
9120
9649
  color: "red",
9121
9650
  columnsPerRow: cols,
9122
9651
  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)}`,
9652
+ `- **session**: ${cleanInline4(displayTitle, 48)}`,
9653
+ `- **target**: #${entry.seq} (${kindBadge(entry.kind)} \xB7 ${formatNodeClock(entry.timestamp)})`,
9654
+ `- **preview**: ${cleanInline4(entry.preview || "(empty)", 72)}`,
9126
9655
  "",
9127
9656
  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"
9657
+ "\u2705 **Lossless**: the previous branch stays intact in the session tree and can be restored via Tree anytime.",
9658
+ "\u2139\uFE0F Switches only the agent's session context \u2014 previously sent chat messages are not recalled."
9130
9659
  ].join("\n"),
9131
9660
  actions: [
9132
9661
  {
9133
9662
  id: `panel.tree.branch.confirm.${peer.instanceId}`,
9134
- label: "\u2705 \u786E\u8BA4\u5207\u6362",
9663
+ label: "\u2705 Confirm Switch",
9135
9664
  style: "danger",
9136
9665
  payload: {
9137
9666
  treeBranch: { ref: peer.instanceId, session: detail.sessionId, entryId: entry.id },
@@ -9142,7 +9671,7 @@ function composeTreeBranchConfirmCard(peer, detail, opts) {
9142
9671
  },
9143
9672
  {
9144
9673
  id: `panel.tree.${peer.instanceId}`,
9145
- label: "\u21A9\uFE0F \u53D6\u6D88",
9674
+ label: "\u21A9\uFE0F Cancel",
9146
9675
  payload: { page: opts.page, filter: opts.filter, from: fromVal }
9147
9676
  }
9148
9677
  ]
@@ -9157,10 +9686,10 @@ async function runTreePanelCommand(panelCmd, opts) {
9157
9686
  handled: true,
9158
9687
  keyPrefix: "panel-tree-denied",
9159
9688
  spec: {
9160
- title: "\u{1F333} \u4F1A\u8BDD\u6811\u4E0D\u53EF\u7528",
9689
+ title: "\u{1F333} Session Tree Unavailable",
9161
9690
  color: "red",
9162
9691
  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",
9692
+ body: "\u26D4\uFE0F Session tree contains conversation previews and is restricted to authorized chats or DMs.",
9164
9693
  actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
9165
9694
  }
9166
9695
  };
@@ -9181,10 +9710,10 @@ async function runTreePanelCommand(panelCmd, opts) {
9181
9710
  return composeOfflineWorkerCard(opts.pinnedWorkerSessionId, { inThread: opts.inThread, hideHome: true });
9182
9711
  }
9183
9712
  return {
9184
- title: "\u{1F333} \u4F1A\u8BDD\u5DF2\u79BB\u7EBF",
9713
+ title: "\u{1F333} Session Offline",
9185
9714
  color: "grey",
9186
9715
  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",
9716
+ body: peerRef2 ? `Online session \`${cleanCodeSpan(peerRef2, 40)}\` was not found (it may have exited or be restarting).` : "No online manager session found. Refresh Home and try again.",
9188
9717
  actions: panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
9189
9718
  };
9190
9719
  };
@@ -9206,11 +9735,11 @@ async function runTreePanelCommand(panelCmd, opts) {
9206
9735
  handled: true,
9207
9736
  keyPrefix: "panel-tree-confirm-stale",
9208
9737
  spec: {
9209
- title: "\u26A0\uFE0F \u786E\u8BA4\u5361\u7247\u5DF2\u5931\u6548",
9738
+ title: "\u26A0\uFE0F Confirmation Expired",
9210
9739
  color: "grey",
9211
9740
  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)
9741
+ body: "This branch switch confirmation expired, was already used, or the session changed. Open Session Tree again to pick a target.",
9742
+ actions: livePeer ? [{ id: `panel.tree.${livePeer.instanceId}`, label: "\u{1F333} Back to Tree", payload: { page: meta.page, filter: meta.filter, from: meta.from } }] : panelHomeAction(opts.hideHome, opts.pinnedWorkerSessionId)
9214
9743
  }
9215
9744
  };
9216
9745
  }
@@ -9235,19 +9764,19 @@ async function runTreePanelCommand(panelCmd, opts) {
9235
9764
  keyPrefix: "panel-tree-branch-failed",
9236
9765
  clearIssuedBranch: true,
9237
9766
  spec: {
9238
- title: receipt2.unknown ? "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u72B6\u6001\u672A\u77E5" : "\u26A0\uFE0F \u5206\u652F\u5207\u6362\u5DF2\u62D2\u7EDD",
9767
+ title: receipt2.unknown ? "\u26A0\uFE0F Branch Switch Status Unknown" : "\u26A0\uFE0F Branch Switch Refused",
9239
9768
  color: "red",
9240
9769
  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" : ""}`,
9770
+ body: `${formatPeerErrorDetail(receipt2.detail)}${receipt2.unknown ? "\n\nRefresh the session tree to check the current pointer before retrying." : ""}`,
9242
9771
  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 } },
9772
+ { id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} Back to Tree", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
9244
9773
  ...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
9245
9774
  ]
9246
9775
  }
9247
9776
  };
9248
9777
  }
9249
9778
  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";
9779
+ const banner = switched ? switched.alreadyActive ? `\u2139\uFE0F Already at **#${switched.seq}**.` : `\u2705 Losslessly switched to **#${switched.seq}** (${switched.pathLength} entries on active path; previous branch preserved).` : "\u26A0\uFE0F Received an unexpected receipt; refreshed the session tree \u2014 please verify the current \u2605 pointer.";
9251
9780
  const refreshReceipt = await applyPeerControl(
9252
9781
  peer2.instanceId,
9253
9782
  "session.tree",
@@ -9274,12 +9803,12 @@ async function runTreePanelCommand(panelCmd, opts) {
9274
9803
  keyPrefix: "panel-tree-switched",
9275
9804
  clearIssuedBranch: true,
9276
9805
  spec: {
9277
- title: "\u{1F333} \u5206\u652F\u5DF2\u5207\u6362",
9806
+ title: "\u{1F333} Branch Switched",
9278
9807
  color: "green",
9279
9808
  columnsPerRow: cols,
9280
9809
  body: banner,
9281
9810
  actions: [
9282
- { id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} \u67E5\u770B\u4F1A\u8BDD\u6811", payload: { page: 1, filter: meta.filter, from: meta.from } },
9811
+ { id: `panel.tree.${peer2.instanceId}`, label: "\u{1F333} View Tree", payload: { page: 1, filter: meta.filter, from: meta.from } },
9283
9812
  ...backActionsFor(peer2, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
9284
9813
  ]
9285
9814
  }
@@ -9304,11 +9833,11 @@ async function runTreePanelCommand(panelCmd, opts) {
9304
9833
  handled: true,
9305
9834
  keyPrefix: "panel-tree-invalid-entry",
9306
9835
  spec: {
9307
- title: "\u26A0\uFE0F \u65E0\u6548\u8282\u70B9",
9836
+ title: "\u26A0\uFE0F Invalid Entry",
9308
9837
  color: "red",
9309
9838
  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 } }]
9839
+ body: "Missing valid target entry ID. Please pick an entry from the session tree.",
9840
+ actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F Tree", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
9312
9841
  }
9313
9842
  };
9314
9843
  }
@@ -9324,11 +9853,11 @@ async function runTreePanelCommand(panelCmd, opts) {
9324
9853
  handled: true,
9325
9854
  keyPrefix: "panel-tree-entry-error",
9326
9855
  spec: {
9327
- title: "\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u76EE\u6807\u8282\u70B9",
9856
+ title: "\u26A0\uFE0F Cannot Read Target Entry",
9328
9857
  color: "red",
9329
9858
  columnsPerRow: cols,
9330
9859
  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 } }]
9860
+ actions: [{ id: `panel.tree.${peer2.instanceId}`, label: "\u21A9\uFE0F Tree", payload: { page: meta.page, filter: meta.filter, from: meta.from } }]
9332
9861
  }
9333
9862
  };
9334
9863
  }
@@ -9362,12 +9891,12 @@ async function runTreePanelCommand(panelCmd, opts) {
9362
9891
  handled: true,
9363
9892
  keyPrefix: "panel-tree-error",
9364
9893
  spec: {
9365
- title: `\u{1F333} \u4F1A\u8BDD\u6811 \xB7 ${peer.isManager ? "Manager" : workerDisplayTitle(peer)}`,
9894
+ title: `\u{1F333} Session Tree \xB7 ${peer.isManager ? "Manager" : workerDisplayTitle(peer)}`,
9366
9895
  color: "red",
9367
9896
  columnsPerRow: cols,
9368
9897
  body: formatPeerErrorDetail(receipt.detail),
9369
9898
  actions: [
9370
- { id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} \u91CD\u8BD5", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
9899
+ { id: `panel.tree.${peer.instanceId}`, label: "\u{1F504} Retry", payload: { page: meta.page, filter: meta.filter, from: meta.from } },
9371
9900
  ...backActionsFor(peer, { hideHome: opts.hideHome, from: meta.from, pinnedWorkerSessionId: opts.pinnedWorkerSessionId })
9372
9901
  ]
9373
9902
  }
@@ -9403,7 +9932,7 @@ function parsePage2(payload, field = "page") {
9403
9932
  return Math.floor(raw);
9404
9933
  }
9405
9934
  function formatDateTime(ts) {
9406
- if (typeof ts !== "number" || !Number.isFinite(ts) || ts <= 0) return "\u5C1A\u672A\u8FD0\u884C";
9935
+ if (typeof ts !== "number" || !Number.isFinite(ts) || ts <= 0) return "never";
9407
9936
  const d = new Date(ts);
9408
9937
  const mm = String(d.getMonth() + 1).padStart(2, "0");
9409
9938
  const dd = String(d.getDate()).padStart(2, "0");
@@ -9445,7 +9974,7 @@ function enumerateCuratedPages(memoryRoot, wiki) {
9445
9974
  if (userContent !== null) {
9446
9975
  entries.push({
9447
9976
  key: USER_PAGE_KEY,
9448
- label: "\u{1F464} USER.md\uFF08\u7528\u6237\u753B\u50CF\u4E0E\u504F\u597D\uFF09",
9977
+ label: "\u{1F464} USER.md (Profile & Preferences)",
9449
9978
  category: "user",
9450
9979
  tokens: estimateWikiTokens(userContent)
9451
9980
  });
@@ -9464,7 +9993,7 @@ function enumerateCuratedPages(memoryRoot, wiki) {
9464
9993
  const content = wiki.readPage(rel) ?? "";
9465
9994
  entries.push({
9466
9995
  key: `wiki/${rel}`,
9467
- label: `\u{1F4E6} wiki/${rel}\uFF08\u5F52\u6863\uFF09`,
9996
+ label: `\u{1F4E6} wiki/${rel} (archived)`,
9468
9997
  category: "archived",
9469
9998
  tokens: estimateWikiTokens(content)
9470
9999
  });
@@ -9482,22 +10011,22 @@ function readAllowlistedPage(memoryRoot, wiki, pageKey) {
9482
10011
  function summarizeMemoryCron() {
9483
10012
  try {
9484
10013
  const bridge = currentCronPanelBridge();
9485
- if (!bridge) return "\u672A\u63A5\u5165 Cron \u6865\u63A5";
10014
+ if (!bridge) return "Cron bridge unavailable";
9486
10015
  const job = bridge.listJobs().jobs.find((j) => j.isProcess && j.managedBy === "memory");
9487
- if (!job) return "\u672A\u542F\u7528\uFF08\u53EF\u7528 `pie memory schedule on` \u5F00\u542F\uFF09";
9488
- if (job.state === "running") return "\u{1F7E1} \u8FD0\u884C\u4E2D";
10016
+ if (!job) return "Not enabled (run `pie memory schedule on`)";
10017
+ if (job.state === "running") return "\u{1F7E1} Running";
9489
10018
  if (job.state === "blocked") {
9490
- const detail = job.error ? `\uFF08${cleanCodeSpan(job.error, 80)}\uFF09` : "";
9491
- return `\u{1F534} \u5DF2\u963B\u585E${detail}`;
10019
+ const detail = job.error ? ` (${cleanCodeSpan(job.error, 80)})` : "";
10020
+ return `\u{1F534} Blocked${detail}`;
9492
10021
  }
9493
- if (!job.enabled) return "\u23F8 \u5DF2\u6682\u505C";
10022
+ if (!job.enabled) return "\u23F8 Paused";
9494
10023
  const nextText = job.next !== null ? formatDateTime(job.next) : "\u2014";
9495
10024
  if (job.error && job.error.startsWith("degraded")) {
9496
- return `\u{1F7E0} \u9000\u907F\u91CD\u8BD5\u4E2D \xB7 \u4E0B\u6B21 ${nextText}`;
10025
+ return `\u{1F7E0} Retrying \xB7 next ${nextText}`;
9497
10026
  }
9498
- return `\u{1F7E2} \u6B63\u5E38\uFF08\`${cleanCodeSpan(job.schedule.text, 24)}\` \xB7 \u4E0B\u6B21 ${nextText}\uFF09`;
10027
+ return `\u{1F7E2} Active (\`${cleanCodeSpan(job.schedule.text, 24)}\` \xB7 next ${nextText})`;
9499
10028
  } catch {
9500
- return "\u72B6\u6001\u4E0D\u53EF\u8BFB";
10029
+ return "Unavailable";
9501
10030
  }
9502
10031
  }
9503
10032
  function composeMemoryCard(opts) {
@@ -9516,26 +10045,26 @@ function composeMemoryCard(opts) {
9516
10045
  const slice = allEntries.slice((page - 1) * MEMORY_PAGE_SIZE, page * MEMORY_PAGE_SIZE);
9517
10046
  const items = slice.map((entry) => ({
9518
10047
  text: `**${sanitizeLiteralMarkdown(entry.label)}**
9519
- \u7EA6 ${entry.tokens} tokens`,
10048
+ ~${entry.tokens} tokens`,
9520
10049
  actions: [{
9521
10050
  id: "panel.memory.view",
9522
- label: "\u{1F4D6} \u67E5\u770B",
10051
+ label: "\u{1F4D6} View",
9523
10052
  payload: { pageKey: entry.key, returnPage: page }
9524
10053
  }]
9525
10054
  }));
9526
- const missingLine = missingDates.length === 0 ? "\u8FD1 7 \u5929\u5DF2\u5B8C\u6574\u8986\u76D6 \u2705" : `\u8FD1 7 \u5929\u7F3A\u65E5 ${missingDates.length} \u5929\uFF08${missingDates.slice(-4).map((d) => d.slice(5)).join(", ")}${missingDates.length > 4 ? "\u2026" : ""}\uFF09`;
9527
- const lastFailLine = meta.lastDreamError ? `- **\u6700\u8FD1\u5931\u8D25**\uFF1A\`${cleanCodeSpan(meta.lastDreamError, 100)}\`${meta.lastDreamFailedDate ? ` (${meta.lastDreamFailedDate})` : ""}` : void 0;
10055
+ const missingLine = missingDates.length === 0 ? "7-day coverage complete \u2705" : `missing ${missingDates.length} day(s) in last 7d (${missingDates.slice(-4).map((d) => d.slice(5)).join(", ")}${missingDates.length > 4 ? "\u2026" : ""})`;
10056
+ const lastFailLine = meta.lastDreamError ? `- **Last failure**: \`${cleanCodeSpan(meta.lastDreamError, 100)}\`${meta.lastDreamFailedDate ? ` (${meta.lastDreamFailedDate})` : ""}` : void 0;
9528
10057
  const bodyLines = [
9529
10058
  ...opts.banner ? [opts.banner, ""] : [],
9530
- `- **Wiki**\uFF1A${exists ? `\u6D3B\u8DC3 ${activePages.length}/${DEFAULT_WIKI_LIMITS.maxActivePages} \u9875 \xB7 \u5F52\u6863 ${archivedPages.length} \u9875` : "\u5C1A\u672A\u521D\u59CB\u5316\uFF08\u9996\u6B21\u84B8\u998F\u81EA\u52A8\u521B\u5EFA\uFF09"} \xB7 index \u7EA6 ${indexTokens}/${DEFAULT_WIKI_LIMITS.maxIndexTokens} tokens`,
9531
- `- **Dream**\uFF1A\u4E0A\u6B21 ${formatDateTime(meta.lastDreamAt)} \xB7 ${missingLine}`,
10059
+ `- **Wiki**: ${exists ? `${activePages.length}/${DEFAULT_WIKI_LIMITS.maxActivePages} active \xB7 ${archivedPages.length} archived` : "Not initialized yet (created on first distill)"} \xB7 index ~${indexTokens}/${DEFAULT_WIKI_LIMITS.maxIndexTokens} tokens`,
10060
+ `- **Dream**: last ${formatDateTime(meta.lastDreamAt)} \xB7 ${missingLine}`,
9532
10061
  ...lastFailLine ? [lastFailLine] : [],
9533
- `- **GC**\uFF1A\u4E0A\u6B21 ${formatDateTime(meta.lastGcAt)} \xB7 **\u5B9A\u65F6\u4EFB\u52A1**\uFF1A${summarizeMemoryCron()}`,
9534
- ...allEntries.length === 0 ? ["", "_\u5F53\u524D\u6682\u65E0\u53EF\u6D4F\u89C8\u7684\u8BB0\u5FC6\u9875\u9762\u3002_"] : []
10062
+ `- **GC**: last ${formatDateTime(meta.lastGcAt)} \xB7 **Schedule**: ${summarizeMemoryCron()}`,
10063
+ ...allEntries.length === 0 ? ["", "_No memory pages available yet._"] : []
9535
10064
  ];
9536
10065
  const nav = [];
9537
- if (page > 1) nav.push({ id: "panel.memory", label: `\u25C0\uFE0F \u7B2C ${page - 1} \u9875`, payload: { page: page - 1 } });
9538
- if (page < totalPages) nav.push({ id: "panel.memory", label: `\u7B2C ${page + 1} \u9875 \u25B6\uFE0F`, payload: { page: page + 1 } });
10066
+ if (page > 1) nav.push({ id: "panel.memory", label: `\u25C0\uFE0F Page ${page - 1}`, payload: { page: page - 1 } });
10067
+ if (page < totalPages) nav.push({ id: "panel.memory", label: `Page ${page + 1} \u25B6\uFE0F`, payload: { page: page + 1 } });
9539
10068
  const defaultColor = meta.lastDreamError ? "red" : "violet";
9540
10069
  return {
9541
10070
  title: "\u{1F9E0} Memory \xB7 Wiki & Dreaming",
@@ -9544,14 +10073,14 @@ function composeMemoryCard(opts) {
9544
10073
  columnsPerRow: cols,
9545
10074
  body: bodyLines.join("\n"),
9546
10075
  ...items.length > 0 ? { items } : {},
9547
- footer: "\u70B9\u51FB\u884C\u5185\u300C\u{1F4D6} \u67E5\u770B\u300D\u9884\u89C8\u9875\u9762\uFF1B\u300C\u{1F319} \u7ACB\u5373\u84B8\u998F\u300D\u4E0E\u300C\u{1F9F9} \u89E6\u53D1 GC\u300D\u5747\u5728\u540E\u53F0\u72EC\u7ACB\u8FD0\u884C\uFF0C\u4E0D\u5360\u7528\u5F53\u524D\u4F1A\u8BDD\u3002",
10076
+ footer: "Tap \u{1F4D6} View to preview a page. \u{1F319} Dream Now and \u{1F9F9} Run GC run detached in the background.",
9548
10077
  actions: [
9549
10078
  ...nav,
9550
- { id: "panel.memory.dream", label: "\u{1F319} \u7ACB\u5373\u84B8\u998F", style: "primary" },
9551
- { id: "panel.memory.gc", label: "\u{1F9F9} \u89E6\u53D1 GC" },
9552
- { id: "panel.memory.logs", label: "\u{1F4DC} \u84B8\u998F\u65E5\u5FD7" },
10079
+ { id: "panel.memory.dream", label: "\u{1F319} Dream Now", style: "primary" },
10080
+ { id: "panel.memory.gc", label: "\u{1F9F9} Run GC" },
10081
+ { id: "panel.memory.logs", label: "\u{1F4DC} Logs" },
9553
10082
  { id: "panel.memory", label: "\u{1F504} Refresh", payload: { page } },
9554
- { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }
10083
+ { id: "panel.home", label: "\u21A9\uFE0F Home" }
9555
10084
  ]
9556
10085
  };
9557
10086
  }
@@ -9563,28 +10092,28 @@ function composeMemoryPageCard(opts) {
9563
10092
  const found = readAllowlistedPage(memoryRoot, wiki, opts.pageKey);
9564
10093
  if (!found) {
9565
10094
  return {
9566
- title: "\u26A0\uFE0F \u9875\u9762\u4E0D\u53EF\u7528",
10095
+ title: "\u26A0\uFE0F Page Unavailable",
9567
10096
  color: "grey",
9568
10097
  columnsPerRow: cols,
9569
- body: `\u672A\u627E\u5230\u6216\u65E0\u6743\u8BBF\u95EE\u9875\u9762 \`${cleanCodeSpan(opts.pageKey, 80)}\`\u3002\u8BF7\u8FD4\u56DE Memory \u5217\u8868\u91CD\u65B0\u9009\u62E9\u3002`,
10098
+ body: `Page \`${cleanCodeSpan(opts.pageKey, 80)}\` was not found or is not accessible. Return to Memory to select another page.`,
9570
10099
  actions: [
9571
- { id: "panel.memory", label: "\u21A9\uFE0F \u8FD4\u56DE Memory", payload: { page: returnPage } },
9572
- { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
10100
+ { id: "panel.memory", label: "\u21A9\uFE0F Memory", payload: { page: returnPage } },
10101
+ { id: "panel.home", label: "\u{1F4CB} Home" }
9573
10102
  ]
9574
10103
  };
9575
10104
  }
9576
- const preview = truncateMarkdown(found.content.trim() || "_(\u7A7A\u9875\u9762)_", PAGE_PREVIEW_CHAR_BUDGET);
10105
+ const preview = truncateMarkdown(found.content.trim() || "_(empty page)_", PAGE_PREVIEW_CHAR_BUDGET);
9577
10106
  return {
9578
10107
  title: `\u{1F4D6} ${cleanCodeSpan(found.entry.key, 48)}`,
9579
- subtitle: `\u7EA6 ${found.entry.tokens} tokens \xB7 ${found.content.length} chars \xB7 \u53EA\u8BFB\u9884\u89C8`,
10108
+ subtitle: `~${found.entry.tokens} tokens \xB7 ${found.content.length} chars \xB7 read-only`,
9580
10109
  color: "blue",
9581
10110
  columnsPerRow: cols,
9582
10111
  body: preview,
9583
- footer: "\u5982\u9700\u4FEE\u6539\u6216\u5220\u9664\u8BB0\u5FC6\uFF0C\u76F4\u63A5\u5728\u5BF9\u8BDD\u4E2D\u544A\u8BC9 Manager \u5373\u53EF\u3002",
10112
+ footer: "To edit or delete memories, tell Manager directly in chat.",
9584
10113
  actions: [
9585
10114
  { id: "panel.memory.view", label: "\u{1F504} Refresh", payload: { pageKey: found.entry.key, returnPage } },
9586
- { id: "panel.memory", label: "\u21A9\uFE0F \u8FD4\u56DE Memory", payload: { page: returnPage } },
9587
- { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
10115
+ { id: "panel.memory", label: "\u21A9\uFE0F Memory", payload: { page: returnPage } },
10116
+ { id: "panel.home", label: "\u{1F4CB} Home" }
9588
10117
  ]
9589
10118
  };
9590
10119
  }
@@ -9593,27 +10122,27 @@ function composeMemoryLogsCard(opts) {
9593
10122
  const memoryRoot = resolveMemoryRoot(opts.memoryRoot);
9594
10123
  const workerLines = (opts.hooks?.readWorkerLog ?? readDistillWorkerLog)(memoryRoot, LOG_LINE_LIMIT);
9595
10124
  const gitLines = (opts.hooks?.readGitLog ?? readCuratedMemoryGitLog)(memoryRoot, GIT_LOG_LIMIT);
9596
- const workerSection = workerLines.length > 0 ? `**distill-worker.log\uFF08\u6700\u8FD1 ${workerLines.length} \u884C\uFF09**
10125
+ const workerSection = workerLines.length > 0 ? `**distill-worker.log (last ${workerLines.length} lines)**
9597
10126
  \`\`\`
9598
10127
  ${sanitizeFenceContent(workerLines.join("\n"), 1500)}
9599
- \`\`\`` : "**distill-worker.log**\uFF1A_\u6682\u65E0\u8BB0\u5F55_";
9600
- const gitSection = gitLines.length > 0 ? `**Curated Git \u53D8\u66F4\uFF08\u6700\u8FD1\uFF09**
10128
+ \`\`\`` : "**distill-worker.log**: _no entries yet_";
10129
+ const gitSection = gitLines.length > 0 ? `**Curated Git History (recent)**
9601
10130
  \`\`\`
9602
10131
  ${sanitizeFenceContent(gitLines.join("\n"), 900)}
9603
- \`\`\`` : "**Curated Git \u53D8\u66F4**\uFF1A_\u6682\u65E0\u63D0\u4EA4_";
10132
+ \`\`\`` : "**Curated Git History**: _no commits yet_";
9604
10133
  return {
9605
- title: "\u{1F4DC} Memory \u84B8\u998F\u65E5\u5FD7",
9606
- subtitle: "worker \u65E5\u5FD7 + curated git \u5386\u53F2 \xB7 zero LLM",
10134
+ title: "\u{1F4DC} Memory Distillation Logs",
10135
+ subtitle: "worker log + curated git history \xB7 zero LLM",
9607
10136
  color: "blue",
9608
10137
  columnsPerRow: cols,
9609
10138
  body: `${workerSection}
9610
10139
 
9611
10140
  ${gitSection}`,
9612
10141
  actions: [
9613
- { id: "panel.memory.dream", label: "\u{1F319} \u7ACB\u5373\u84B8\u998F", style: "primary" },
10142
+ { id: "panel.memory.dream", label: "\u{1F319} Dream Now", style: "primary" },
9614
10143
  { id: "panel.memory.logs", label: "\u{1F504} Refresh" },
9615
- { id: "panel.memory", label: "\u21A9\uFE0F \u8FD4\u56DE Memory" },
9616
- { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }
10144
+ { id: "panel.memory", label: "\u21A9\uFE0F Memory" },
10145
+ { id: "panel.home", label: "\u{1F4CB} Home" }
9617
10146
  ]
9618
10147
  };
9619
10148
  }
@@ -9636,11 +10165,11 @@ function runMemoryPanelCommand(panelCmd, opts) {
9636
10165
  handled: true,
9637
10166
  keyPrefix: "panel-memory-denied",
9638
10167
  spec: {
9639
- title: "\u{1F9E0} Memory \u4E0D\u53EF\u7528",
10168
+ title: "\u{1F9E0} Memory Unavailable",
9640
10169
  color: "red",
9641
10170
  columnsPerRow: cols,
9642
- body: "\u26D4\uFE0F Memory \u9762\u677F\u4EC5\u9650\u5DF2\u6388\u6743\u7684\u5BF9\u8BDD\u6216\u7BA1\u7406\u5458\u79C1\u804A\u67E5\u770B\u3002",
9643
- actions: [{ id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
10171
+ body: "\u26D4\uFE0F The Memory panel is restricted to authorized chats or admin DMs.",
10172
+ actions: [{ id: "panel.home", label: "\u21A9\uFE0F Home" }]
9644
10173
  }
9645
10174
  };
9646
10175
  }
@@ -9672,7 +10201,7 @@ function runMemoryPanelCommand(panelCmd, opts) {
9672
10201
  if (!opts.canMutate) {
9673
10202
  return {
9674
10203
  handled: true,
9675
- refusedText: "\u26D4\uFE0F \u89E6\u53D1 Memory \u84B8\u998F\u6216 GC \u9700\u8981\u7BA1\u7406\u5458\u6743\u9650\uFF08panelAccess=allowUsers\uFF09\u3002"
10204
+ refusedText: "\u26D4\uFE0F Triggering Memory distillation or GC requires admin rights (panelAccess=allowUsers)."
9676
10205
  };
9677
10206
  }
9678
10207
  const probeLockFree = opts.hooks?.probeLockFree ?? defaultProbeLockFree;
@@ -9684,7 +10213,7 @@ function runMemoryPanelCommand(panelCmd, opts) {
9684
10213
  memoryRoot,
9685
10214
  inThread: opts.inThread,
9686
10215
  page,
9687
- banner: "\u23F3 **\u5DF2\u6709 Memory \u540E\u53F0\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C**\uFF08\u6301\u6709 `distill.lock`\uFF09\uFF0C\u8BF7\u7A0D\u5019\u70B9\u300C\u{1F4DC} \u84B8\u998F\u65E5\u5FD7\u300D\u67E5\u770B\u8FDB\u5EA6\u3002",
10216
+ banner: '\u23F3 **A Memory background job is already running** (holding `distill.lock`). Tap "\u{1F4DC} Logs" shortly to check progress.',
9688
10217
  bannerColor: "grey"
9689
10218
  })
9690
10219
  };
@@ -9700,7 +10229,7 @@ function runMemoryPanelCommand(panelCmd, opts) {
9700
10229
  memoryRoot,
9701
10230
  inThread: opts.inThread,
9702
10231
  page,
9703
- banner: ok2 ? "\u{1F319} **\u5DF2\u5728\u540E\u53F0\u542F\u52A8\u8865\u84B8\u998F (`--auto`)**\uFF0C\u5B8C\u6210\u540E\u81EA\u52A8\u66F4\u65B0 Wiki \u4E0E Git\uFF08\u70B9\u300C\u{1F4DC} \u84B8\u998F\u65E5\u5FD7\u300D\u67E5\u770B\u5B9E\u65F6\u8FDB\u5EA6\uFF09\u3002" : "\u274C **\u540E\u53F0\u84B8\u998F\u8FDB\u7A0B\u542F\u52A8\u5931\u8D25**\uFF0C\u8BF7\u70B9\u300C\u{1F4DC} \u84B8\u998F\u65E5\u5FD7\u300D\u6392\u67E5\u539F\u56E0\u3002",
10232
+ banner: ok2 ? '\u{1F319} **Started background distillation (`--auto`)**. Wiki and Git will update automatically when done (tap "\u{1F4DC} Logs" to monitor).' : '\u274C **Failed to start background distillation worker**. Tap "\u{1F4DC} Logs" to inspect.',
9704
10233
  bannerColor: ok2 ? "green" : "red"
9705
10234
  })
9706
10235
  };
@@ -9714,7 +10243,7 @@ function runMemoryPanelCommand(panelCmd, opts) {
9714
10243
  memoryRoot,
9715
10244
  inThread: opts.inThread,
9716
10245
  page,
9717
- banner: ok ? "\u{1F9F9} **\u5DF2\u5728\u540E\u53F0\u542F\u52A8 Wiki GC**\uFF08\u5F52\u6863\u4E0D\u6D3B\u8DC3\u9879\u76EE\u3001\u6E05\u7406\u8FC7\u671F\u951A\u70B9\u3001\u538B\u7F29\u8D85\u9884\u7B97\u9875\u9762\uFF09\uFF0C\u70B9\u300C\u{1F4DC} \u84B8\u998F\u65E5\u5FD7\u300D\u67E5\u770B\u8FDB\u5EA6\u3002" : "\u274C **\u540E\u53F0 Wiki GC \u542F\u52A8\u5931\u8D25**\uFF0C\u8BF7\u70B9\u300C\u{1F4DC} \u84B8\u998F\u65E5\u5FD7\u300D\u6392\u67E5\u539F\u56E0\u3002",
10246
+ banner: ok ? '\u{1F9F9} **Started background Wiki GC** (archives stale projects, prunes expired anchors, compacts over-budget pages). Tap "\u{1F4DC} Logs" to monitor.' : '\u274C **Failed to start background Wiki GC**. Tap "\u{1F4DC} Logs" to inspect.',
9718
10247
  bannerColor: ok ? "green" : "red"
9719
10248
  })
9720
10249
  };
@@ -10172,7 +10701,7 @@ function createPanelExecutor(ctx) {
10172
10701
  return true;
10173
10702
  };
10174
10703
  const payloadFromWorker = isRecord(panelCmd.payload) && panelCmd.payload.from === "worker" && typeof panelCmd.payload.peer === "string" ? panelCmd.payload.peer : void 0;
10175
- const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }];
10704
+ const homeOpt = hideHome ? [] : [{ id: "panel.home", label: "\u{1F4CB} Home" }];
10176
10705
  if (event.message_id && (panelCmd.cmd.startsWith("panel.cron.stop.confirm.") || panelCmd.cmd.startsWith("panel.tree.branch.confirm."))) {
10177
10706
  await ctx.cards.enqueueCardPatch(event.message_id, async () => void 0);
10178
10707
  if (!isCurrent()) return;
@@ -10221,7 +10750,7 @@ function createPanelExecutor(ctx) {
10221
10750
  const modelProvider = isRecord(panelCmd.payload) && typeof panelCmd.payload.provider === "string" && panelCmd.payload.provider.trim() ? panelCmd.payload.provider.trim() : void 0;
10222
10751
  const modelPage = isRecord(panelCmd.payload) && typeof panelCmd.payload.page === "number" && Number.isFinite(panelCmd.payload.page) ? Math.floor(panelCmd.payload.page) : void 0;
10223
10752
  const scope = workerScoped || hideHome || payloadFromWorker ? "worker" : "manager";
10224
- const banner = receipt.ok ? `\u2705 \u5DF2\u5207\u6362\u6A21\u578B\u4E3A \`${cleanCodeSpan(model, 56)}\`\uFF08\u4E0B\u6B21\u6267\u884C\u751F\u6548\uFF09` : `\u26A0\uFE0F \u5207\u6362\u6A21\u578B \`${cleanCodeSpan(model, 56)}\` \u5931\u8D25\uFF1A${sanitizeLiteralMarkdown(receipt.detail)}`;
10753
+ const banner = receipt.ok ? `\u2705 Switched model to \`${cleanCodeSpan(model, 56)}\` (applies next turn)` : `\u26A0\uFE0F Failed to switch model \`${cleanCodeSpan(model, 56)}\`: ${sanitizeLiteralMarkdown(receipt.detail)}`;
10225
10754
  const spec = composeUpdatedModelsCard({
10226
10755
  peerRef,
10227
10756
  scope,
@@ -10277,6 +10806,10 @@ function createPanelExecutor(ctx) {
10277
10806
  return;
10278
10807
  }
10279
10808
  }
10809
+ const archiveViewSession = /^panel\.archive\.view\.([A-Za-z0-9._-]+)$/.exec(effectiveCmd.cmd)?.[1];
10810
+ if (archiveViewSession && peekAudienceAllowed(event) && ctx.connection.latestThreadPosition) {
10811
+ await refreshAnchorThreadPositions([archiveViewSession], ctx.provider, (tid, mid, sig) => ctx.connection.latestThreadPosition(tid, mid, sig), { force: true, timeoutMs: 1500 });
10812
+ }
10280
10813
  const archiveResult = runArchivePanelCommand(effectiveCmd, {
10281
10814
  inThread,
10282
10815
  provider: ctx.provider,
@@ -10500,10 +11033,10 @@ function createPanelExecutor(ctx) {
10500
11033
  actions: [
10501
11034
  {
10502
11035
  id: `panel.compact.${contextAction[1]}`,
10503
- label: "\u{1F9F9} \u538B\u7F29",
11036
+ label: "\u{1F9F9} Compact",
10504
11037
  ...workerScoped || payloadFromWorker ? { payload: { from: "worker", peer: workerScoped ? contextAction[1] : payloadFromWorker } } : {}
10505
11038
  },
10506
- ...workerScoped ? [{ id: `panel.worker.${contextAction[1]}`, label: "\u21A9\uFE0F Back to worker" }] : payloadFromWorker ? [{ id: `panel.worker.${payloadFromWorker}`, label: "\u21A9\uFE0F Back to worker" }, ...homeOpt] : hideHome ? panelHomeAction(true, threadWorkerSessionId, contextAction[1]) : [{ id: "panel.context", label: "\u21A9\uFE0F Back to context list" }, { id: "panel.home", label: "\u{1F4CB} \u603B\u9762\u677F" }]
11039
+ ...workerScoped ? [{ id: `panel.worker.${contextAction[1]}`, label: "\u21A9\uFE0F Back to worker" }] : payloadFromWorker ? [{ id: `panel.worker.${payloadFromWorker}`, label: "\u21A9\uFE0F Back to worker" }, ...homeOpt] : hideHome ? panelHomeAction(true, threadWorkerSessionId, contextAction[1]) : [{ id: "panel.context", label: "\u21A9\uFE0F Back to context list" }, { id: "panel.home", label: "\u{1F4CB} Home" }]
10507
11040
  ]
10508
11041
  };
10509
11042
  await deliverPanelSpec(spec, `panel-context-${event.event_id}`, true, navGen);
@@ -10574,11 +11107,11 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10574
11107
  const action = findAction(actionId);
10575
11108
  if (!action) {
10576
11109
  await deliverPanelSpec({
10577
- title: "\u26A0\uFE0F \u52A8\u4F5C\u5DF2\u79FB\u9664",
10578
- body: `\`${actionId}\` \u4E0D\u5728\u6CE8\u518C\u8868\u91CC\uFF08\u53EF\u80FD\u5DF2\u88AB\u5220\u9664\uFF09\u3002
11110
+ title: "\u26A0\uFE0F Action Removed",
11111
+ body: `\`${actionId}\` is not in the registry (it may have been removed).
10579
11112
 
10580
- \u70B9 /panel \u7684 \u26A1 \u5168\u90E8\u52A8\u4F5C \u67E5\u770B\u5F53\u524D\u53EF\u7528\u7684\u6309\u94AE\u3002`,
10581
- actions: hideHome ? panelHomeAction(true, threadWorkerSessionId) : [{ id: "panel.actions", label: "\u26A1 \u5168\u90E8\u52A8\u4F5C" }, { id: "panel.home", label: "\u21A9\uFE0F \u603B\u9762\u677F" }]
11113
+ Open \u26A1 All Actions from /panel to see currently available actions.`,
11114
+ actions: hideHome ? panelHomeAction(true, threadWorkerSessionId) : [{ id: "panel.actions", label: "\u26A1 All Actions" }, { id: "panel.home", label: "\u21A9\uFE0F Home" }]
10582
11115
  }, `panel-action-gone-${event.event_id}`, true);
10583
11116
  return;
10584
11117
  }
@@ -10604,7 +11137,7 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10604
11137
  const ambName = cleanCodeSpan(action.scope.startsWith("worker:") ? action.scope.slice("worker:".length) : payloadWorker?.name ?? "", 64);
10605
11138
  await deliverPanelSpec({
10606
11139
  title: `\u26A0\uFE0F ${action.label}`,
10607
- body: `\u540D\u5B57 \`${ambName}\` \u540C\u65F6\u547D\u4E2D\u591A\u4E2A\u5728\u7EBF session\u2014\u2014\u4ECE /panel \u2192 \u{1F4C2} \u70B9\u76EE\u6807 worker \u7684\u5361\u8FDB\u53BB\u518D\u70B9\uFF08\u6309\u94AE\u5E26\u7CBE\u786E\u5730\u5740\uFF09\u3002`,
11140
+ body: `Name \`${ambName}\` matched multiple online sessions \u2014 open the target worker card from /panel and run it there (cards carry an exact address).`,
10608
11141
  actions: panelHomeAction(hideHome, threadWorkerSessionId)
10609
11142
  }, `panel-action-ambiguous-${event.event_id}`, true);
10610
11143
  return;
@@ -10614,13 +11147,13 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10614
11147
  const generic = action.scope === "worker" && !payloadWorker?.name && !payloadWorker?.ref;
10615
11148
  await deliverPanelSpec({
10616
11149
  title: `\u26A0\uFE0F ${action.label}`,
10617
- body: generic ? "\u8FD9\u662F worker \u901A\u7528\u6309\u94AE\u2014\u2014\u8BF7\u5728\u67D0\u4E2A worker \u7684\u5361\u7247\u4E0A\u70B9\u51FB\uFF08/panel \u2192 \u{1F4C2} \u9009\u62E9 worker\uFF09\uFF0C\u811A\u672C\u9700\u8981\u77E5\u9053\u66FF\u54EA\u4E2A worker \u8DD1\u3002" : `worker \`${cleanCodeSpan(wanted, 64)}\` \u4E0D\u5728\u7EBF\uFF08worker \u6709 TTL \u56DE\u6536\uFF09\u3002\u7B49\u5B83\u5728\u7EBF\u65F6\u518D\u4ECE\u5B83\u7684\u5361\u7247\u89E6\u53D1\u3002`,
11150
+ body: generic ? "This is a generic worker action \u2014 open a specific worker card from /panel to run it with that worker's context." : `Worker \`${cleanCodeSpan(wanted, 64)}\` is offline (workers expire via TTL). Wait until it is online and trigger from its card.`,
10618
11151
  actions: panelHomeAction(hideHome, threadWorkerSessionId)
10619
11152
  }, `panel-action-offline-${event.event_id}`, true);
10620
11153
  return;
10621
11154
  }
10622
11155
  if (workerScoped && pinnedThreadWorkerSession && peer.sessionId !== pinnedThreadWorkerSession) {
10623
- await deliverPanelSpec({ title: "\u26D4\uFE0F \u4EC5\u9650\u5F53\u524D Worker \u9762\u677F", color: "red", body: "Thread \u5185\u7684 Worker \u9762\u677F\u4E0D\u80FD\u5BF9\u5176\u4ED6 Worker \u6267\u884C\u52A8\u4F5C\u3002", actions: panelHomeAction(true, pinnedThreadWorkerSession) }, `panel-action-scope-${event.event_id}`, true);
11156
+ await deliverPanelSpec({ title: "\u26D4\uFE0F Worker Panel Only", color: "red", body: "In-thread worker panels cannot run actions on other workers.", actions: panelHomeAction(true, pinnedThreadWorkerSession) }, `panel-action-scope-${event.event_id}`, true);
10624
11157
  return;
10625
11158
  }
10626
11159
  workerCtx = { name: peer.name, ref: peer.instanceId, ...peer.cwd ? { dir: peer.cwd } : {} };
@@ -10632,7 +11165,7 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10632
11165
  const since = lock.holder.startedAt > 0 ? new Date(lock.holder.startedAt).toLocaleTimeString("en-GB", { hour12: false }) : "?";
10633
11166
  await deliverPanelSpec({
10634
11167
  title: `\u23F3 ${action.label}`,
10635
- body: lock.holder.note ? `\u26A0\uFE0F ${sanitizeLiteralMarkdown(lock.holder.note)}` : `\u6B63\u5728\u8FD0\u884C\u4E2D\uFF08\u7531 ${sanitizeLiteralMarkdown(lock.holder.triggerName)} \u89E6\u53D1\u4E8E ${since}\uFF09\u3002\u540C\u4E00\u52A8\u4F5C\u540C\u65F6\u53EA\u8DD1\u4E00\u4E2A\u2014\u2014\u7B49\u5B83\u5B8C\u6210\u6216\u8D85\u65F6\u540E\u518D\u70B9\u3002`,
11168
+ body: lock.holder.note ? `\u26A0\uFE0F ${sanitizeLiteralMarkdown(lock.holder.note)}` : `Already running (triggered by ${sanitizeLiteralMarkdown(lock.holder.triggerName)} at ${since}). Only one run of this action can execute at a time \u2014 wait for it to finish or time out.`,
10636
11169
  actions: panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)
10637
11170
  }, `panel-action-busy-${event.event_id}`, true);
10638
11171
  return;
@@ -10653,7 +11186,7 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10653
11186
  title: `\u26A0\uFE0F ${action.label}`,
10654
11187
  color: "red",
10655
11188
  body,
10656
- actions: [{ id: `panel.action.${actionId}`, label: "\u{1F501} \u91CD\u8BD5", ...workerCtx ? { payload: { worker: { name: workerCtx.name, ...workerCtx.ref ? { ref: workerCtx.ref } : {} } } } : {} }, ...panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)]
11189
+ actions: [{ id: `panel.action.${actionId}`, label: "\u{1F501} Retry", ...workerCtx ? { payload: { worker: { name: workerCtx.name, ...workerCtx.ref ? { ref: workerCtx.ref } : {} } } } : {} }, ...panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)]
10657
11190
  }, `panel-action-cancel-${event.event_id}`);
10658
11191
  if (!runtimeAlive() || !isCurrent()) {
10659
11192
  lock.release();
@@ -10667,9 +11200,9 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10667
11200
  ackMessageId = await sendActionCard({
10668
11201
  title: `\u{1F680} ${action.label}`,
10669
11202
  color: "blue",
10670
- body: `\u7531 ${sanitizeLiteralMarkdown(triggerQuick)} \u89E6\u53D1 \xB7 \u8FD0\u884C\u4E2D\u2026\uFF08\u8D85\u65F6\u4E0A\u9650 ${timeoutS}s\uFF09
11203
+ body: `Triggered by ${sanitizeLiteralMarkdown(triggerQuick)} \xB7 running\u2026 (timeout ${timeoutS}s)
10671
11204
 
10672
- \u5B8C\u6210\u540E\u672C\u5361\u81EA\u52A8\u66F4\u65B0\u4E3A\u7ED3\u679C\u3002`,
11205
+ This card will update automatically when done.`,
10673
11206
  actions: []
10674
11207
  }, `panel-action-${event.event_id}`, isCurrent);
10675
11208
  return true;
@@ -10678,13 +11211,13 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10678
11211
  try {
10679
11212
  if (!await initialAck) return;
10680
11213
  if (actionAbort.signal.aborted) {
10681
- if (ackMessageId) await publishCancellation("\u8FD0\u884C\u65F6\u5DF2\u9000\u51FA\uFF0C\u672C\u6B21\u64CD\u4F5C\u672A\u6267\u884C\u3002");
11214
+ if (ackMessageId) await publishCancellation("Runtime exited before execution started; action was not run.");
10682
11215
  else ctx.log(`im-forward: panel action ${actionId} retired with no initial card receipt; script not started`);
10683
11216
  return;
10684
11217
  }
10685
11218
  actionAbort.signal.removeEventListener("abort", lock.release);
10686
11219
  if (!lock.rearm(action.timeoutMs ?? DEFAULT_TIMEOUT_MS)) {
10687
- await publishCancellation("\u6267\u884C\u69FD\u5728\u542F\u52A8\u524D\u6613\u4E3B\uFF0C\u672C\u6B21\u89E6\u53D1\u5DF2\u53D6\u6D88\uFF08\u672A\u6267\u884C\uFF09\u3002\u8BF7\u91CD\u8BD5\u3002");
11220
+ await publishCancellation("Execution slot changed hands before launch; cancelled (not run). Please retry.");
10688
11221
  return;
10689
11222
  }
10690
11223
  ctx.log(`im-forward: panel action ${actionId} triggered by ${triggerQuick} (${triggerOpenId ?? "no-openid"})${workerCtx ? ` as worker ${workerCtx.name}` : ""}`);
@@ -10710,7 +11243,7 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10710
11243
  ok: false,
10711
11244
  logFile: result2.logFile
10712
11245
  });
10713
- await publishCancellation(ctx.isTerminated() ? "\u8FD0\u884C\u65F6\u5DF2\u9000\u51FA\uFF0C\u672C\u6B21\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002\u82E5\u811A\u672C\u6B64\u524D\u4EA7\u751F\u4E86\u8F93\u51FA\uFF0C\u8BF7\u5148\u6838\u5BF9\u7ED3\u679C\u518D\u91CD\u8BD5\u3002" : "\u6267\u884C\u69FD\u5728\u811A\u672C\u542F\u52A8\u4E00\u523B\u6613\u4E3B\uFF0C\u672C\u6B21\u89E6\u53D1\u5DF2\u53D6\u6D88\uFF08\u811A\u672C\u5DF2\u5728\u542F\u52A8\u65F6\u7EC8\u6B62\uFF1B\u53EF\u80FD\u5DF2\u6709\u90E8\u5206\u8F93\u51FA\uFF09\u3002\u8BF7\u91CD\u8BD5\u3002");
11246
+ await publishCancellation(ctx.isTerminated() ? "Runtime exited; action cancelled. Check for partial output before retrying." : "Execution slot changed hands at launch; script terminated (partial output may exist). Please retry.");
10714
11247
  return;
10715
11248
  }
10716
11249
  const triggerName = ctx.isTerminated() ? triggerQuick : await resolveUserName(triggerOpenId, {
@@ -10733,16 +11266,16 @@ ${receipt.ok ? "Compaction runs on the target host (LLM summary \u2014 may take
10733
11266
  });
10734
11267
  if (!actionCanDeliver()) return;
10735
11268
  const icon = result2.timedOut ? "\u23F1\uFE0F" : result2.ok ? "\u2705" : "\u274C";
10736
- const statusLine = result2.timedOut ? `\u8D85\u65F6\uFF08>${timeoutS}s\uFF09\uFF0C\u5DF2\u7EC8\u6B62` : result2.ok ? `\u8017\u65F6 ${(result2.durationMs / 1e3).toFixed(1)}s` : `exit ${result2.exitCode ?? "?"} \xB7 \u8017\u65F6 ${(result2.durationMs / 1e3).toFixed(1)}s`;
11269
+ const statusLine = result2.timedOut ? `timed out (>${timeoutS}s), terminated` : result2.ok ? `took ${(result2.durationMs / 1e3).toFixed(1)}s` : `exit ${result2.exitCode ?? "?"} \xB7 took ${(result2.durationMs / 1e3).toFixed(1)}s`;
10737
11270
  const outBody = truncateMarkdown(result2.stdout.trim() || (result2.ok ? "_(no output)_" : ""));
10738
11271
  const logNote = result2.logDegraded ? `
10739
- _(\u65E5\u5FD7\u4E0D\u5B8C\u6574\uFF1A\u8D85\u9650\u6216\u5199\u5165\u5931\u8D25\uFF1B\u5DF2\u6709\u90E8\u5206\u89C1 ${result2.logFile})_` : result2.stdoutTruncated || result2.stderrTruncated ? `
10740
- _(\u8F93\u51FA\u8FC7\u957F\u5DF2\u622A\u65AD;\u5B8C\u6574\u89C1 ${result2.logFile})_` : "";
11272
+ _(log incomplete: over limit or write failed; partial log at ${result2.logFile})_` : result2.stdoutTruncated || result2.stderrTruncated ? `
11273
+ _(output truncated; full log at ${result2.logFile})_` : "";
10741
11274
  const resultSpec = {
10742
11275
  title: `${icon} ${action.label}`,
10743
11276
  color: result2.ok ? "green" : "red",
10744
11277
  body: [
10745
- `\u7531 ${sanitizeLiteralMarkdown(triggerName)} \u89E6\u53D1 \xB7 ${statusLine}${workerCtx ? ` \xB7 as ${sanitizeLiteralMarkdown(workerCtx.name)}` : ""}`,
11278
+ `Triggered by ${sanitizeLiteralMarkdown(triggerName)} \xB7 ${statusLine}${workerCtx ? ` \xB7 as ${sanitizeLiteralMarkdown(workerCtx.name)}` : ""}`,
10746
11279
  ``,
10747
11280
  outBody,
10748
11281
  result2.stderrTail.trim() && !result2.ok ? `
@@ -10752,7 +11285,7 @@ ${result2.stderrTail.trim().slice(0, 1500).replace(/`/g, "'").replace(/</g, "\u2
10752
11285
  \`\`\`` : "",
10753
11286
  logNote
10754
11287
  ].filter((line) => line !== "").join("\n"),
10755
- actions: [{ id: `panel.action.${actionId}`, label: "\u{1F501} \u518D\u8DD1\u4E00\u6B21", ...workerCtx ? { payload: { worker: { name: workerCtx.name, ...workerCtx.ref ? { ref: workerCtx.ref } : {} } } } : {} }, ...panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)]
11288
+ actions: [{ id: `panel.action.${actionId}`, label: "\u{1F501} Run Again", ...workerCtx ? { payload: { worker: { name: workerCtx.name, ...workerCtx.ref ? { ref: workerCtx.ref } : {} } } } : {} }, ...panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)]
10756
11289
  };
10757
11290
  await publishTerminal(resultSpec, `panel-action-result-${event.event_id}`);
10758
11291
  } catch (error) {
@@ -10760,7 +11293,7 @@ ${result2.stderrTail.trim().slice(0, 1500).replace(/`/g, "'").replace(/</g, "\u2
10760
11293
  await publishTerminal({
10761
11294
  title: `\u274C ${action.label}`,
10762
11295
  color: "red",
10763
- body: `\u6267\u884C\u5668\u81EA\u8EAB\u51FA\u9519\uFF1A${sanitizeLiteralMarkdown(error instanceof Error ? error.message : String(error))}`,
11296
+ body: `Runner error: ${sanitizeLiteralMarkdown(error instanceof Error ? error.message : String(error))}`,
10764
11297
  actions: panelHomeAction(hideHome, threadWorkerSessionId, workerCtx?.ref)
10765
11298
  }, `panel-action-error-${event.event_id}`);
10766
11299
  } finally {
@@ -10773,6 +11306,14 @@ ${result2.stderrTail.trim().slice(0, 1500).replace(/`/g, "'").replace(/</g, "\u2
10773
11306
  await initialAck;
10774
11307
  return;
10775
11308
  }
11309
+ if (ctx.connection.latestThreadPosition) {
11310
+ const isHomeOrRefresh = effectiveCmd.cmd === "panel.home" || effectiveCmd.cmd === "panel" || effectiveCmd.cmd === "\u9762\u677F" || effectiveCmd.cmd === "panel.refresh" || effectiveCmd.cmd === "panel.summon";
11311
+ const isWorkerView = effectiveCmd.cmd.startsWith("panel.worker.");
11312
+ const targetIds = isWorkerView ? threadWorkerSessionId ? [threadWorkerSessionId] : [] : isHomeOrRefresh ? scanPeers().map((p) => p.sessionId) : [];
11313
+ if (targetIds.length > 0) {
11314
+ await refreshAnchorThreadPositions(targetIds, ctx.provider, (tid, mid, sig) => ctx.connection.latestThreadPosition(tid, mid, sig), { force: effectiveCmd.cmd === "panel.refresh" || isWorkerView, timeoutMs: 1500 });
11315
+ }
11316
+ }
10776
11317
  const result = executePanelCommand({ ...effectiveCmd, senderId: event.sender_id, originCardId: canPatchOrigin ? event.message_id : void 0, inThread, ...workerScoped ? { workerScoped: true } : {}, ...threadWorkerSessionId ? { fallbackSessionId: threadWorkerSessionId } : {} });
10777
11318
  await deliverPanelSpec(result.spec, `panel-${event.event_id}`, result.patchOrigin);
10778
11319
  };
@@ -11330,12 +11871,15 @@ ${imagelessCaption || (imageKeys.length ? IM_INPUT_FALLBACK_CAPTION2 : "") || ca
11330
11871
  }
11331
11872
  return;
11332
11873
  }
11874
+ const chosenThreadId = route.threadId ?? meta.threadId ?? null;
11875
+ const inboundThreadPos = chosenThreadId && (!meta.threadId || meta.threadId === chosenThreadId) ? meta.threadPosition : void 0;
11333
11876
  persistSessionAnchor(
11334
11877
  route.sessionId,
11335
11878
  messageId,
11336
- route.threadId ?? meta.threadId ?? null,
11879
+ chosenThreadId,
11880
+ event.chat_id,
11337
11881
  event.chat_id,
11338
- event.chat_id
11882
+ inboundThreadPos
11339
11883
  );
11340
11884
  claimSessionRoot(cfg.provider, messageId, route.sessionId);
11341
11885
  if (route.threadId ?? meta.threadId) {
@@ -11807,9 +12351,9 @@ function initializeImForward(ctx, providers = implementedProviders, runtimeFacto
11807
12351
  ...typeof args.id === "string" && args.id.trim() ? { id: args.id.trim() } : {},
11808
12352
  ...args.creatorName || args.creatorOpenId ? { creator: { ...typeof args.creatorOpenId === "string" ? { openId: args.creatorOpenId } : {}, ...typeof args.creatorName === "string" ? { name: args.creatorName } : {} } } : {}
11809
12353
  });
11810
- return text(`\u2705 \u6309\u94AE\u5DF2\u6CE8\u518C:\u3010${created.label}\u3011id=\`${created.id}\` scope=${created.scope}
12354
+ return text(`\u2705 Registered button: [${created.label}] id=\`${created.id}\` scope=${created.scope}
11811
12355
 
11812
- \u4E0B\u6B21 /panel \u5373\u53EF\u89C1(\u4E3B\u5361\u6309\u4F7F\u7528\u9891\u6B21\u5185\u8054,\u6216 \u26A1 \u5168\u90E8\u52A8\u4F5C \u91CC)\u3002\u70B9\u51FB\u5373\u8DD1\u811A\u672C,\u96F6 LLM\u3002`);
12356
+ Visible on the next /panel (inlined by usage frequency, or under \u26A1 All Actions). Runs script directly with zero LLM.`);
11813
12357
  } catch (error) {
11814
12358
  return text(`add failed: ${error instanceof Error ? error.message : String(error)}`, true);
11815
12359
  }
@@ -11818,7 +12362,7 @@ function initializeImForward(ctx, providers = implementedProviders, runtimeFacto
11818
12362
  const id = typeof args.id === "string" ? args.id.trim() : "";
11819
12363
  if (!id) return text("remove requires id", true);
11820
12364
  const removed = removeAction(id);
11821
- return removed ? text(`\u{1F5D1} \u6309\u94AE\u3010${removed.label}\u3011(${id}) \u5DF2\u4ECE\u6CE8\u518C\u8868\u79FB\u9664(\u811A\u672C\u6587\u4EF6\u4FDD\u7559\u5728\u78C1\u76D8,\u6309\u94AE\u4E0D\u518D\u51FA\u73B0)\u3002`) : text(`action id "${id}" not found`, true);
12365
+ return removed ? text(`\u{1F5D1} Removed button [${removed.label}] (${id}) from the registry (script file stays on disk; button no longer shown).`) : text(`action id "${id}" not found`, true);
11822
12366
  }
11823
12367
  return text(`unknown action "${act}"`, true);
11824
12368
  }