zcode-pro 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/inject.js CHANGED
@@ -109,8 +109,8 @@
109
109
  }
110
110
  return res.error || "";
111
111
  }
112
- function h(tag, attrs, ...children) {
113
- const el = document.createElement(tag);
112
+ function h(tag2, attrs, ...children) {
113
+ const el = document.createElement(tag2);
114
114
  if (attrs) {
115
115
  for (const [k, v] of Object.entries(attrs)) {
116
116
  if (k === "class") el.className = v;
@@ -277,7 +277,34 @@
277
277
  proxyScopeSync: "\u540C\u6B65",
278
278
  proxyScopeSyncDesc: "WebDAV \u4E0A\u4F20\u4E0E\u4E0B\u8F7D\u8D70\u4EE3\u7406\u3002",
279
279
  tabSync: "\u540C\u6B65",
280
+ tabImport: "\u5BFC\u5165\u4F1A\u8BDD",
280
281
  tabDebug: "\u8C03\u8BD5",
282
+ importDesc: "\u628A Codex\u3001Claude Code\u3001dsh\u3001pi \u7684\u5386\u53F2\u4F1A\u8BDD\u590D\u5236\u6210 ZCode \u4EFB\u52A1\u3002\u5BFC\u5165\u662F\u5FEB\u7167\uFF0C\u4E4B\u540E\u6E90\u4F1A\u8BDD\u7684\u53D8\u5316\u4E0D\u4F1A\u518D\u540C\u6B65\u3002",
283
+ importSearch: "\u641C\u7D22\u6807\u9898\u6216\u76EE\u5F55",
284
+ importRefresh: "\u5237\u65B0",
285
+ importShowAll: "\u663E\u793A\u5168\u90E8",
286
+ importShowAllTip: "\u663E\u793A\u5B50\u4EE3\u7406\u4F1A\u8BDD\u3001pi \u91CC\u4ECE Codex \u5BFC\u5165\u7684\u526F\u672C\uFF0C\u4EE5\u53CA\u6CA1\u6709\u771F\u5B9E\u5BF9\u8BDD\u7684 Claude \u4F1A\u8BDD\uFF1B\u5DF2\u5F52\u6863\u59CB\u7EC8\u663E\u793A",
287
+ importOnlyProject: "\u53EA\u770B\u6240\u9009\u9879\u76EE",
288
+ importSelectAll: "\u5168\u9009",
289
+ importSelected: "\u5BFC\u5165\u6240\u9009\uFF08{n}\uFF09",
290
+ importImporting: "\u5BFC\u5165\u4E2D\u2026",
291
+ importLoading: "\u52A0\u8F7D\u4E2D\u2026",
292
+ importNoSessions: "\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u4F1A\u8BDD",
293
+ importNoSource: "\u6CA1\u6709\u627E\u5230\u8BE5\u5DE5\u5177\u7684\u4F1A\u8BDD\u76EE\u5F55",
294
+ importSourceMissing: "\u6CA1\u6709\u68C0\u6D4B\u5230\u4F1A\u8BDD\u76EE\u5F55",
295
+ importAlready: "\u5DF2\u5BFC\u5165",
296
+ importAlreadyArchived: "\u5DF2\u5BFC\u5165\uFF08\u4EFB\u52A1\u5DF2\u5F52\u6863\uFF09",
297
+ importArchivedTaskTip: "\u5BFC\u5165\u7684\u4EFB\u52A1\u5DF2\u5F52\u6863\uFF1B\u53D6\u6D88\u5F52\u6863\u6216\u5220\u9664\u540E\u624D\u80FD\u91CD\u65B0\u5BFC\u5165",
298
+ importArchived: "\u5DF2\u5F52\u6863",
299
+ importSubagent: "\u5B50\u4EE3\u7406",
300
+ importCodexCopy: "Codex \u526F\u672C",
301
+ importLarge: "\u5927\u6587\u4EF6",
302
+ importCwdMissing: "\u539F\u76EE\u5F55\u4E0D\u5B58\u5728",
303
+ importProjectNone: "\u4E0D\u9009\u9879\u76EE\uFF08\u5F52\u5230\u201C\u4EFB\u52A1\u201D\uFF09",
304
+ importProjectHint: "\u9879\u76EE\u53EA\u51B3\u5B9A\u4FA7\u8FB9\u680F\u5F52\u7C7B\uFF0C\u4E0D\u6539\u53D8\u4F1A\u8BDD\u539F\u6765\u7684\u5DE5\u4F5C\u76EE\u5F55",
305
+ importConfirmLarge: "\u6240\u9009\u4F1A\u8BDD\u91CC\u6709\u8D85\u8FC7 20MB \u7684\u5927\u6587\u4EF6\uFF0C\u5BFC\u5165\u53EF\u80FD\u9700\u8981\u4E00\u4E9B\u65F6\u95F4\uFF0C\u7EE7\u7EED\u5417\uFF1F",
306
+ importDone: "\u5BFC\u5165\u5B8C\u6210\uFF1A\u6210\u529F {ok}\uFF0C\u8DF3\u8FC7 {skip}\uFF0C\u5931\u8D25 {fail}",
307
+ importFailed: "\u5BFC\u5165\u5931\u8D25",
281
308
  testNoSessionHint: "\u9009\u62E9\u201C\u8DDF\u968F\u5F53\u524D\u4F1A\u8BDD[\u5F53\u524D\u6A21\u578B]\u201D\u65F6\uFF0C\u9009\u62E9\u4E0A\u6B21\u4F1A\u8BDD\u4E2D\u4F7F\u7528\u7684\u4F9B\u5E94\u5546[\u6A21\u578B]",
282
309
  syncDesc: "\u624B\u52A8\u628A ZCode Pro \u8BBE\u7F6E\u4E0E\u6A21\u578B\u8BBE\u7F6E\u5907\u4EFD\u5230 WebDAV\uFF0C\u6216\u5728\u65B0\u7535\u8111\u4E0A\u6062\u590D\u3002\u4E24\u9879\u5404\u81EA\u72EC\u7ACB\u6210\u6587\u4EF6\uFF0C\u53EF\u53EA\u4E0A\u4F20\u6216\u53EA\u8986\u76D6\u5176\u4E2D\u4E00\u9879\uFF1B\u6BCF\u6B21\u4E0A\u4F20\u4F1A\u989D\u5916\u4FDD\u7559\u4E00\u4EFD\u5E26\u65F6\u95F4\u6233\u7684\u5386\u53F2\u7248\u672C\uFF08\u4FDD\u7559\u591A\u5C11\u4E2A\u89C1\u201C\u5386\u53F2\u7248\u672C\u201D\u4E00\u884C\uFF0C\u4E0A\u4F20\u540E\u81EA\u52A8\u5220\u9664\u8D85\u51FA\u7684\u6700\u65E7\u7248\u672C\uFF09\uFF0C\u4E0B\u8F7D\u65F6\u4EFB\u9009\u4E00\u4E2A\u7248\u672C\u6062\u590D\uFF1B\u4EC5\u5728\u70B9\u51FB\u6309\u94AE\u65F6\u4F20\u8F93\uFF0C\u4E0D\u505A\u81EA\u52A8\u540C\u6B65\u3002",
283
310
  syncUrlPlaceholder: "https://dav.jianguoyun.com/dav/",
@@ -597,6 +624,8 @@
597
624
  featureSessionLink: "\u4F1A\u8BDD ID \u663E\u793A\u4E3A\u4EFB\u52A1\u540D\u94FE\u63A5",
598
625
  featureSessionLinkDesc: "\u63D0\u95EE\u4E0E\u56DE\u7B54\u91CC\u7684\u4F1A\u8BDD ID\uFF08sess_ / session_ \u5F00\u5934\uFF09\u663E\u793A\u4E3A\u4EFB\u52A1\u540D\uFF0C\u70B9\u51FB\u5207\u6362\u5230\u8BE5\u4F1A\u8BDD\uFF0C\u60AC\u505C\u53EF\u770B\u539F\u59CB ID\u3002",
599
626
  featureComposerProviderDesc: "\u6A21\u578B\u540D\u524D\u663E\u793A\u4F9B\u5E94\u5546\u540D\uFF08\u5982 BigModel-Max1 / glm-5.3\uFF09\uFF0C\u533A\u5206\u540C\u540D\u6A21\u578B\u3002",
627
+ featureSessionImport: "\u5BFC\u5165\u4F1A\u8BDD",
628
+ featureSessionImportDesc: "\u5728\u8BBE\u7F6E\u5F39\u7A97\u91CC\u628A Codex\u3001Claude Code\u3001dsh\u3001pi \u7684\u5386\u53F2\u4F1A\u8BDD\u5BFC\u5165\u6210 ZCode \u4EFB\u52A1\u3002",
600
629
  imageCopy: "\u590D\u5236\u56FE\u7247",
601
630
  imageCopied: "\u56FE\u7247\u5DF2\u590D\u5236\u5230\u526A\u8D34\u677F",
602
631
  imageCopyFailed: "\u590D\u5236\u56FE\u7247\u5931\u8D25",
@@ -878,7 +907,34 @@
878
907
  proxyScopeSync: "Sync",
879
908
  proxyScopeSyncDesc: "WebDAV upload and download go through the proxy.",
880
909
  tabSync: "Sync",
910
+ tabImport: "Session import",
881
911
  tabDebug: "Debug",
912
+ importDesc: "Copy sessions from Codex, Claude Code, dsh and pi into ZCode tasks. The copy is a snapshot; later changes in the source session are not synced.",
913
+ importSearch: "Search title or folder",
914
+ importRefresh: "Refresh",
915
+ importShowAll: "Show all",
916
+ importShowAllTip: "Show subagent sessions, pi copies imported from Codex, and Claude sessions without real conversation; archived sessions are always shown",
917
+ importOnlyProject: "Only the selected project",
918
+ importSelectAll: "Select all",
919
+ importSelected: "Import selected ({n})",
920
+ importImporting: "Importing\u2026",
921
+ importLoading: "Loading\u2026",
922
+ importNoSessions: "No sessions to import",
923
+ importNoSource: "The session folder for this tool was not found",
924
+ importSourceMissing: "No session folder detected",
925
+ importAlready: "Imported",
926
+ importAlreadyArchived: "Imported (task archived)",
927
+ importArchivedTaskTip: "The imported task is archived; unarchive or delete it before importing again",
928
+ importArchived: "Archived",
929
+ importSubagent: "Subagent",
930
+ importCodexCopy: "Codex copy",
931
+ importLarge: "Large",
932
+ importCwdMissing: "Original folder missing",
933
+ importProjectNone: "No project (Tasks section)",
934
+ importProjectHint: "The project only controls the sidebar group; the session keeps its original working folder",
935
+ importConfirmLarge: "The selection includes files larger than 20MB. Importing may take a while. Continue?",
936
+ importDone: "Import finished: {ok} imported, {skip} skipped, {fail} failed",
937
+ importFailed: "Import failed",
882
938
  testNoSessionHint: 'With "Follow current session" selected, the provider and model of the last session are used (the label shows the model name in brackets).',
883
939
  syncDesc: 'Manually back up ZCode Pro settings and model settings to WebDAV, or restore them on a new computer. The two items are stored as separate files, so you can upload or overwrite either one alone; every upload also keeps a timestamped history version (how many to keep is set in the "History" row; older ones are removed automatically after upload) and download lets you pick any of them. Data moves only when you click, never automatically.',
884
940
  syncUrlPlaceholder: "https://dav.example.com/dav/",
@@ -1197,6 +1253,8 @@
1197
1253
  featureSessionLink: "Session ID links",
1198
1254
  featureSessionLinkDesc: "Shows session IDs (sess_ / session_) in chat as task names; click to switch to that session, hover for the raw ID.",
1199
1255
  featureComposerProviderDesc: "Shows the provider before the model name (e.g. BigModel-Max1 / glm-5.3).",
1256
+ featureSessionImport: "Session import",
1257
+ featureSessionImportDesc: "Import sessions from Codex, Claude Code, dsh and pi as ZCode tasks from the settings dialog.",
1200
1258
  imageCopy: "Copy image",
1201
1259
  imageCopied: "Image copied to the clipboard.",
1202
1260
  imageCopyFailed: "Failed to copy the image.",
@@ -1436,6 +1494,17 @@
1436
1494
  "index-remap-failed": "Failed to update the task index (config changes rolled back)",
1437
1495
  "index-error": "Task index error",
1438
1496
  "index-busy": "The task index is busy. Please retry shortly.",
1497
+ "bad-source": "Unknown session source",
1498
+ "source-unavailable": "No session folder found for this tool",
1499
+ "bad-request": "Invalid import request",
1500
+ "too-many-items": "At most 1000 sessions per import; split the selection",
1501
+ "project-not-found": "Project not found or has no folder",
1502
+ "bad-source-path": "The session file is outside the source folder or no longer exists",
1503
+ "session-mismatch": "The session id does not match the file content",
1504
+ "empty-session": "No messages to import",
1505
+ "db-missing": "The ZCode session database or task index is missing",
1506
+ "import-failed": "Import failed",
1507
+ "zstd-unavailable": "This Node build cannot read dsh sessions (zstd support is missing)",
1439
1508
  "vision-invalid": "Invalid vision config",
1440
1509
  "vision-read": "Failed to read zcode-vision.json",
1441
1510
  "vision-write": "Failed to write zcode-vision.json",
@@ -2249,6 +2318,8 @@
2249
2318
  pointer-events: none;
2250
2319
  }
2251
2320
  .zcodepro-statusbar span[data-tone='warn'] { color: var(--color-amber-500, #f59e0b); }
2321
+ /* \u5B50\u9879\u4E0D\u538B\u7F29\uFF1A\u8D85\u5BBD\u65F6\u6309 HIDE_ORDER \u9690\u85CF\u6761\u76EE\uFF08status-bar.js\uFF09\uFF0C\u4E0D\u9760\u6324\u538B\u6587\u5B57 */
2322
+ .zcodepro-statusbar > * { flex-shrink: 0; }
2252
2323
  .zcodepro-statusbar span[data-tone='danger'] { color: var(--color-red-500, #ef4444); }
2253
2324
  .zcodepro-statusbar-sep { opacity: 0.45; }
2254
2325
  /* \u4F1A\u8BDD\u7EC4\u4E0E\u5168\u5C40\u7EC4\u4E4B\u95F4\u7684\u5206\u754C\u7AD6\u7EBF */
@@ -2593,6 +2664,30 @@
2593
2664
  return null;
2594
2665
  }
2595
2666
  }
2667
+ function listActiveIdsCached(base) {
2668
+ const key = String(base).replace(/[\\/]+$/, "");
2669
+ const now = Date.now();
2670
+ const hit = activeIdsCache.get(key);
2671
+ if (hit && hit.pending) return hit.pending;
2672
+ if (hit && now - hit.doneAt < ACTIVE_IDS_TTL_MS) return Promise.resolve(hit.ids);
2673
+ const services = findServices();
2674
+ const ts = services && services.zcodeTaskService;
2675
+ if (!ts || typeof ts.listActiveTaskIds !== "function") return Promise.resolve(null);
2676
+ const one = (w) => new Promise((resolve) => {
2677
+ const timer = setTimeout(() => resolve([]), ACTIVE_IDS_TIMEOUT_MS);
2678
+ Promise.resolve().then(() => ts.listActiveTaskIds({ workspacePath: w })).then(
2679
+ (r) => resolve(Array.isArray(r) ? r.map(String) : []),
2680
+ () => resolve([])
2681
+ ).finally(() => clearTimeout(timer));
2682
+ });
2683
+ const pending = Promise.all([one(key), one(key + "/")]).then(([a, b]) => {
2684
+ const ids = [...a, ...b];
2685
+ activeIdsCache.set(key, { ids, doneAt: Date.now(), pending: null });
2686
+ return ids;
2687
+ });
2688
+ activeIdsCache.set(key, { ids: hit && hit.ids || [], doneAt: hit ? hit.doneAt : 0, pending });
2689
+ return pending;
2690
+ }
2596
2691
  async function authoritativeIdle(ws) {
2597
2692
  const services = findServices();
2598
2693
  const ts = services && services.zcodeTaskService;
@@ -2794,13 +2889,7 @@
2794
2889
  }
2795
2890
  projectPaths.set(proj.name, names);
2796
2891
  }
2797
- const pairs = await Promise.all([...scanPaths].map(async (base) => {
2798
- const [a, b] = await Promise.all([
2799
- ts.listActiveTaskIds({ workspacePath: base }),
2800
- ts.listActiveTaskIds({ workspacePath: base + "/" })
2801
- ]);
2802
- return [base, [...Array.isArray(a) ? a : [], ...Array.isArray(b) ? b : []].map(String)];
2803
- }));
2892
+ const pairs = await Promise.all([...scanPaths].map(async (base) => [base, await listActiveIdsCached(base) || []]));
2804
2893
  for (const [base, ids] of pairs) {
2805
2894
  if (!ids.length) continue;
2806
2895
  byKindByPath.set(base, ids);
@@ -3141,8 +3230,8 @@
3141
3230
  }, pollMs);
3142
3231
  }
3143
3232
  function startWsRunningSpin() {
3144
- if (installed2 || typeof document === "undefined") return;
3145
- installed2 = true;
3233
+ if (installed || typeof document === "undefined") return;
3234
+ installed = true;
3146
3235
  const st = document.createElement("style");
3147
3236
  st.id = "__zcodepro_ws_style__";
3148
3237
  st.textContent = ".zcodepro-ws-loader{color:color-mix(in srgb, currentColor 85%, black) !important}";
@@ -3173,12 +3262,12 @@
3173
3262
  if (row) wsTouchAt.set(row, Date.now());
3174
3263
  }, true);
3175
3264
  }
3176
- var installed2, enabled2, SCAN_DEBOUNCE_MS, SCAN_FALLBACK_MS, PEEK_FIRST_MS, PEEK_REPEAT_MS, PEEK_SETTLE_MS, PEEK_MAX_MS, PEEK_UNMOUNT_WAIT_MS, CONFIG_POLL_MIN_MS, CONFIG_POLL_MAX_MS, TASK_SEL, WS_SEL, LOADER_FALLBACK_PATHS, runningByWs, peekTimers, activePeeks, peekedWs, wsWithRows, servicesRef, servicesMissAt, synthClick, headInfoCache, PROJECT_HEAD_TEXTS, TASK_HEAD_TEXTS, SEC_SPIN_CLASS, anyActiveCache, sectionActive, activeProjectPaths, authActiveByWs, peekChain, PEEK_EXEMPT_CLASS, cssAttr, TOUCH_WINDOW_MS, wsTouchAt, pollMs, scanDebounce;
3265
+ var installed, enabled2, SCAN_DEBOUNCE_MS, SCAN_FALLBACK_MS, PEEK_FIRST_MS, PEEK_REPEAT_MS, PEEK_SETTLE_MS, PEEK_MAX_MS, PEEK_UNMOUNT_WAIT_MS, CONFIG_POLL_MIN_MS, CONFIG_POLL_MAX_MS, TASK_SEL, WS_SEL, LOADER_FALLBACK_PATHS, runningByWs, peekTimers, activePeeks, peekedWs, wsWithRows, servicesRef, servicesMissAt, ACTIVE_IDS_TTL_MS, ACTIVE_IDS_TIMEOUT_MS, activeIdsCache, synthClick, headInfoCache, PROJECT_HEAD_TEXTS, TASK_HEAD_TEXTS, SEC_SPIN_CLASS, anyActiveCache, sectionActive, activeProjectPaths, authActiveByWs, peekChain, PEEK_EXEMPT_CLASS, cssAttr, TOUCH_WINDOW_MS, wsTouchAt, pollMs, scanDebounce;
3177
3266
  var init_ws_running = __esm({
3178
3267
  "src/inject/features/ws-running.js"() {
3179
3268
  init_core();
3180
3269
  init_ws_rows();
3181
- installed2 = false;
3270
+ installed = false;
3182
3271
  enabled2 = true;
3183
3272
  SCAN_DEBOUNCE_MS = 150;
3184
3273
  SCAN_FALLBACK_MS = 5e3;
@@ -3208,6 +3297,9 @@
3208
3297
  wsWithRows = /* @__PURE__ */ new Set();
3209
3298
  servicesRef = null;
3210
3299
  servicesMissAt = 0;
3300
+ ACTIVE_IDS_TTL_MS = 25e3;
3301
+ ACTIVE_IDS_TIMEOUT_MS = 6e3;
3302
+ activeIdsCache = /* @__PURE__ */ new Map();
3211
3303
  synthClick = (el) => {
3212
3304
  try {
3213
3305
  el.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
@@ -6586,6 +6678,399 @@
6586
6678
  showToast(L.pluginsUpdatesAvailable.replaceAll("{n}", String(status.updates.length)), "info");
6587
6679
  }
6588
6680
 
6681
+ // src/inject/features/session-import.js
6682
+ init_core();
6683
+ init_ui();
6684
+ init_ws_running();
6685
+ var INPUT_CLS = "h-8 w-full rounded-lg border border-border bg-input px-2.5 text-ui-sm text-foreground outline-none transition-shadow placeholder:text-foreground-subtle focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40";
6686
+ function tag(text, title = "") {
6687
+ return h("span", { class: "shrink-0 rounded border border-border px-1 text-ui-xs text-foreground-subtle", title: title || void 0 }, text);
6688
+ }
6689
+ function when(ms) {
6690
+ if (!ms) return "";
6691
+ try {
6692
+ return new Date(ms).toLocaleString();
6693
+ } catch {
6694
+ return "";
6695
+ }
6696
+ }
6697
+ function createSessionImportPane() {
6698
+ const L = t();
6699
+ const root = h("div", { role: "tabpanel", style: "display:none" });
6700
+ let sources = [];
6701
+ let active = "";
6702
+ let sessions = [];
6703
+ let selected = /* @__PURE__ */ new Set();
6704
+ let projects = [];
6705
+ let projectId = "";
6706
+ let showAll = false;
6707
+ let onlyProject = false;
6708
+ let search = "";
6709
+ let loading = false;
6710
+ let importing = false;
6711
+ let loaded = false;
6712
+ let pendingReload = false;
6713
+ let searchTimer = null;
6714
+ const statusEl = h("div", { class: "mt-2 min-h-4 text-ui-xs/relaxed text-foreground-subtle" });
6715
+ const listEl = h("div", { class: "max-h-80 overflow-auto divide-y divide-border" });
6716
+ const sourceTabs = h("div", { role: "tablist", "aria-orientation": "horizontal", class: "zcodepro-tablist" });
6717
+ const searchInput = h("input", {
6718
+ type: "text",
6719
+ class: INPUT_CLS + " min-w-0 flex-1",
6720
+ placeholder: L.importSearch,
6721
+ spellcheck: "false",
6722
+ autocomplete: "off"
6723
+ });
6724
+ const projectSelect = h("select", { class: INPUT_CLS + " min-w-0 max-w-56" });
6725
+ const onlyProjectBox = h("input", { type: "checkbox" });
6726
+ const showAllBox = h("input", { type: "checkbox", title: L.importShowAllTip });
6727
+ const selectAllBox = h("input", { type: "checkbox" });
6728
+ const refreshBtn = btnSmall(L.importRefresh, () => {
6729
+ void loadList();
6730
+ });
6731
+ const importBtn = btnSmall(L.importSelected.replace("{n}", "0"), () => {
6732
+ void doImport();
6733
+ }, "shrink-0", "primary");
6734
+ importBtn.disabled = true;
6735
+ const setStatus = (text, kind = "") => {
6736
+ statusEl.textContent = text || "";
6737
+ statusEl.className = "mt-2 min-h-4 text-ui-xs/relaxed " + (kind === "error" ? "text-destructive" : "text-foreground-subtle");
6738
+ };
6739
+ const selectedProject = () => projects.find((p) => p.id === projectId) || null;
6740
+ const projectRoots = () => (selectedProject()?.roots || []).map((r) => r.path).filter(Boolean);
6741
+ const refreshTaskTree = async () => {
6742
+ const rootEl = document.getElementById("root");
6743
+ const containerKey = rootEl && Object.keys(rootEl).find((k) => k.startsWith("__reactContainer$"));
6744
+ if (!containerKey) return false;
6745
+ const seen2 = /* @__PURE__ */ new Set();
6746
+ let found = null;
6747
+ const scan6 = (o) => {
6748
+ if (!o || typeof o !== "object" || seen2.has(o) || found) return;
6749
+ seen2.add(o);
6750
+ try {
6751
+ if (typeof o.refresh === "function" && "factTree" in o && "tree" in o) found = o;
6752
+ } catch {
6753
+ }
6754
+ };
6755
+ let visited = 0;
6756
+ const visit = (f) => {
6757
+ if (!f || found || visited > 6e4) return;
6758
+ visited++;
6759
+ for (const h2 of [f.memoizedProps, f.memoizedState]) {
6760
+ if (!h2 || typeof h2 !== "object") continue;
6761
+ scan6(h2);
6762
+ for (const v of Object.values(h2)) if (v && typeof v === "object") scan6(v);
6763
+ }
6764
+ visit(f.child);
6765
+ visit(f.sibling);
6766
+ };
6767
+ visit(rootEl[containerKey]);
6768
+ if (!found) return false;
6769
+ try {
6770
+ await found.refresh();
6771
+ return true;
6772
+ } catch {
6773
+ return false;
6774
+ }
6775
+ };
6776
+ const prepareWorkspaces = async (imported) => {
6777
+ const ag = findServices()?.zcodeAgentService;
6778
+ if (!ag || typeof ag.resumeSession !== "function") return;
6779
+ const seen2 = /* @__PURE__ */ new Set();
6780
+ for (const item of imported) {
6781
+ if (!item.workspace || seen2.has(item.workspace)) continue;
6782
+ seen2.add(item.workspace);
6783
+ try {
6784
+ await ag.resumeSession({ workspacePath: item.workspace, sessionId: item.taskId });
6785
+ } catch {
6786
+ }
6787
+ }
6788
+ };
6789
+ const renderSources = () => {
6790
+ sourceTabs.replaceChildren(...sources.filter((s) => s.available).map((s) => h("button", {
6791
+ type: "button",
6792
+ role: "tab",
6793
+ class: "zcodepro-tab",
6794
+ "aria-selected": String(active === s.id),
6795
+ "data-state": active === s.id ? "active" : "inactive",
6796
+ disabled: !s.available,
6797
+ title: s.available ? "" : L.importSourceMissing,
6798
+ onClick: () => {
6799
+ if (!s.available || active === s.id) return;
6800
+ active = s.id;
6801
+ selected = /* @__PURE__ */ new Set();
6802
+ sessions = [];
6803
+ renderSources();
6804
+ void loadList();
6805
+ }
6806
+ }, s.label)));
6807
+ };
6808
+ const selectable = () => sessions.filter((s) => !s.imported);
6809
+ const allSelected = () => {
6810
+ const list = selectable();
6811
+ return list.length > 0 && list.every((s) => selected.has(s.sessionId));
6812
+ };
6813
+ const renderList = () => {
6814
+ selectAllBox.checked = allSelected();
6815
+ selectAllBox.disabled = importing || !selectable().length;
6816
+ importBtn.textContent = L.importSelected.replace("{n}", String(selected.size));
6817
+ importBtn.disabled = importing || !selected.size;
6818
+ if (loading) {
6819
+ listEl.replaceChildren(h("div", { class: "px-3 py-6 text-center text-ui-sm text-foreground-subtle" }, L.importLoading));
6820
+ return;
6821
+ }
6822
+ if (!sessions.length) {
6823
+ listEl.replaceChildren(h("div", { class: "px-3 py-6 text-center text-ui-sm text-foreground-subtle" }, L.importNoSessions));
6824
+ return;
6825
+ }
6826
+ listEl.replaceChildren(...sessions.map((s) => {
6827
+ const checked = selected.has(s.sessionId);
6828
+ const box = h("input", {
6829
+ type: "checkbox",
6830
+ class: "mt-0.5 shrink-0",
6831
+ checked,
6832
+ disabled: importing || s.imported,
6833
+ onChange: () => {
6834
+ if (box.checked) selected.add(s.sessionId);
6835
+ else selected.delete(s.sessionId);
6836
+ renderList();
6837
+ }
6838
+ });
6839
+ const tags = [];
6840
+ if (s.imported) {
6841
+ tags.push(tag(
6842
+ s.importedArchived ? L.importAlreadyArchived : L.importAlready,
6843
+ s.importedArchived ? L.importArchivedTaskTip : ""
6844
+ ));
6845
+ }
6846
+ if (s.archived) tags.push(tag(L.importArchived));
6847
+ if (s.subagent) tags.push(tag(L.importSubagent));
6848
+ if (s.codexImport) tags.push(tag(L.importCodexCopy));
6849
+ if (s.large) tags.push(tag(L.importLarge));
6850
+ if (s.cwdExists === false) tags.push(tag(L.importCwdMissing));
6851
+ return h(
6852
+ "label",
6853
+ {
6854
+ class: "flex cursor-pointer items-start gap-2 px-3 py-2 transition-colors hover:bg-surface-hover",
6855
+ title: s.cwd || ""
6856
+ },
6857
+ box,
6858
+ h(
6859
+ "div",
6860
+ { class: "min-w-0 flex-1" },
6861
+ h("div", { class: "truncate text-ui-sm" }, s.title || s.sessionId),
6862
+ h(
6863
+ "div",
6864
+ { class: "mt-0.5 flex items-center gap-2 overflow-hidden" },
6865
+ h("span", { class: "min-w-0 flex-1 truncate text-ui-xs text-foreground-subtle" }, s.cwd || s.sourcePath || ""),
6866
+ h("span", { class: "shrink-0 text-ui-xs text-foreground-subtle" }, when(s.updatedAt)),
6867
+ ...tags
6868
+ )
6869
+ )
6870
+ );
6871
+ }));
6872
+ };
6873
+ const loadProjects = async () => {
6874
+ const res = await rpc("/projects-v2");
6875
+ projects = res.ok && Array.isArray(res.projects) ? res.projects : [];
6876
+ const current2 = projectId;
6877
+ projectSelect.replaceChildren(
6878
+ h("option", { value: "" }, L.importProjectNone),
6879
+ ...projects.map((p) => h("option", { value: p.id }, p.name || p.id))
6880
+ );
6881
+ projectSelect.value = projects.some((p) => p.id === current2) ? current2 : "";
6882
+ projectId = projectSelect.value;
6883
+ onlyProjectBox.disabled = !projectId;
6884
+ if (!projectId) {
6885
+ onlyProjectBox.checked = false;
6886
+ onlyProject = false;
6887
+ }
6888
+ };
6889
+ const loadList = async () => {
6890
+ if (loading || importing) {
6891
+ pendingReload = true;
6892
+ return;
6893
+ }
6894
+ loading = true;
6895
+ renderList();
6896
+ const done = () => {
6897
+ loading = false;
6898
+ if (pendingReload) {
6899
+ pendingReload = false;
6900
+ queueMicrotask(() => {
6901
+ void loadList();
6902
+ });
6903
+ }
6904
+ };
6905
+ if (!sources.length || !sources.some((s) => s.id === active && s.available)) {
6906
+ const meta = await rpc("/import/list", { method: "POST", body: { source: "" } });
6907
+ if (meta.ok && Array.isArray(meta.sources)) sources = meta.sources;
6908
+ if (!sources.some((s) => s.id === active && s.available)) {
6909
+ active = (sources.find((s) => s.available) || {}).id || "";
6910
+ }
6911
+ renderSources();
6912
+ if (!active) {
6913
+ sessions = [];
6914
+ done();
6915
+ renderList();
6916
+ setStatus(L.importNoSource);
6917
+ return;
6918
+ }
6919
+ }
6920
+ const res = await rpc("/import/list", {
6921
+ method: "POST",
6922
+ body: {
6923
+ source: active,
6924
+ showAll,
6925
+ search,
6926
+ roots: onlyProject && projectId ? projectRoots() : []
6927
+ }
6928
+ });
6929
+ if (!res.ok) {
6930
+ sessions = [];
6931
+ done();
6932
+ renderList();
6933
+ setStatus(errText(res), "error");
6934
+ return;
6935
+ }
6936
+ sources = res.sources || sources;
6937
+ sessions = res.sessions || [];
6938
+ const usable = new Set(selectable().map((s) => s.sessionId));
6939
+ selected = new Set([...selected].filter((id) => usable.has(id)));
6940
+ if (!active || !sources.some((s) => s.id === active)) {
6941
+ active = (sources.find((s) => s.available) || {}).id || "";
6942
+ }
6943
+ done();
6944
+ renderSources();
6945
+ renderList();
6946
+ setStatus(res.unavailable ? L.importNoSource : "");
6947
+ };
6948
+ const doImport = async () => {
6949
+ if (importing || !selected.size) return;
6950
+ const chosen = sessions.filter((s) => selected.has(s.sessionId));
6951
+ if (!chosen.length) return;
6952
+ if (chosen.some((s) => s.large)) {
6953
+ if (!window.confirm(L.importConfirmLarge)) return;
6954
+ }
6955
+ importing = true;
6956
+ renderList();
6957
+ setStatus(L.importImporting);
6958
+ let summary = "";
6959
+ let summaryKind = "";
6960
+ try {
6961
+ const res = await rpc("/import/run", {
6962
+ method: "POST",
6963
+ body: {
6964
+ source: active,
6965
+ projectId: projectId || null,
6966
+ items: chosen.map((s) => ({
6967
+ sessionId: s.sessionId,
6968
+ sourcePath: s.sourcePath,
6969
+ title: s.title,
6970
+ cwd: s.cwd
6971
+ }))
6972
+ }
6973
+ });
6974
+ if (!res.ok) {
6975
+ setStatus(errText(res), "error");
6976
+ showToast(L.importFailed + ": " + errText(res), "error");
6977
+ return;
6978
+ }
6979
+ const imported = Array.isArray(res.imported) ? res.imported : [];
6980
+ const skipped = Array.isArray(res.skipped) ? res.skipped : [];
6981
+ const failed = Array.isArray(res.failed) ? res.failed : [];
6982
+ const msg = L.importDone.replace("{ok}", String(imported.length)).replace("{skip}", String(skipped.length)).replace("{fail}", String(failed.length));
6983
+ const detail = failed.slice(0, 3).map((f) => `${f.sessionId}: ${f.error}`).join("; ");
6984
+ summary = msg + (detail ? " \xB7 " + detail : "");
6985
+ summaryKind = failed.length ? "error" : "";
6986
+ showToast(msg, failed.length ? "error" : "success");
6987
+ if (imported.length) {
6988
+ void (async () => {
6989
+ await prepareWorkspaces(imported);
6990
+ await refreshTaskTree().catch(() => {
6991
+ });
6992
+ })();
6993
+ }
6994
+ selected = /* @__PURE__ */ new Set();
6995
+ } finally {
6996
+ importing = false;
6997
+ }
6998
+ await loadList();
6999
+ setStatus(summary, summaryKind);
7000
+ };
7001
+ searchInput.addEventListener("input", () => {
7002
+ search = searchInput.value;
7003
+ clearTimeout(searchTimer);
7004
+ searchTimer = setTimeout(() => {
7005
+ void loadList();
7006
+ }, 250);
7007
+ });
7008
+ projectSelect.addEventListener("change", () => {
7009
+ projectId = projectSelect.value;
7010
+ onlyProjectBox.disabled = !projectId;
7011
+ if (!projectId) {
7012
+ onlyProjectBox.checked = false;
7013
+ onlyProject = false;
7014
+ }
7015
+ void loadList();
7016
+ });
7017
+ onlyProjectBox.addEventListener("change", () => {
7018
+ onlyProject = onlyProjectBox.checked;
7019
+ void loadList();
7020
+ });
7021
+ showAllBox.addEventListener("change", () => {
7022
+ showAll = showAllBox.checked;
7023
+ selected = /* @__PURE__ */ new Set();
7024
+ void loadList();
7025
+ });
7026
+ selectAllBox.addEventListener("change", () => {
7027
+ if (selectAllBox.checked) selected = new Set(selectable().map((s) => s.sessionId));
7028
+ else selected = /* @__PURE__ */ new Set();
7029
+ renderList();
7030
+ });
7031
+ const checkLabel = (box, text, title = "") => h("label", { class: "flex shrink-0 items-center gap-1.5 text-ui-xs text-foreground-subtle", title: title || void 0 }, box, text);
7032
+ root.append(
7033
+ h("p", { class: "text-ui-sm/relaxed text-foreground-subtle" }, L.importDesc),
7034
+ h("div", { class: "mt-3" }, sourceTabs),
7035
+ h(
7036
+ "div",
7037
+ { class: "mt-2 flex flex-wrap items-center gap-2" },
7038
+ searchInput,
7039
+ projectSelect,
7040
+ checkLabel(onlyProjectBox, L.importOnlyProject),
7041
+ checkLabel(showAllBox, L.importShowAll, L.importShowAllTip),
7042
+ refreshBtn
7043
+ ),
7044
+ h(
7045
+ "div",
7046
+ { class: "mt-2 flex items-center justify-between gap-2" },
7047
+ h(
7048
+ "div",
7049
+ { class: "flex items-center gap-2" },
7050
+ checkLabel(selectAllBox, L.importSelectAll),
7051
+ h("span", { class: "text-ui-xs text-foreground-subtle" }, L.importProjectHint)
7052
+ ),
7053
+ importBtn
7054
+ ),
7055
+ h("div", { class: "mt-2 rounded-xl border border-border" }, listEl),
7056
+ statusEl
7057
+ );
7058
+ root.__onShow = () => {
7059
+ if (importing) return;
7060
+ if (!loaded) {
7061
+ loaded = true;
7062
+ setStatus(L.importLoading);
7063
+ void (async () => {
7064
+ await loadProjects();
7065
+ await loadList();
7066
+ })();
7067
+ } else {
7068
+ void loadList();
7069
+ }
7070
+ };
7071
+ return root;
7072
+ }
7073
+
6589
7074
  // src/inject/features/settings-dialog.js
6590
7075
  function openExternal(url) {
6591
7076
  try {
@@ -6947,6 +7432,11 @@
6947
7432
  if (await setFeature("composerProvider", next)) f.composerProvider = next;
6948
7433
  refreshRows();
6949
7434
  }),
7435
+ settingRow(L.featureSessionImport, L.featureSessionImportDesc, f.sessionImport !== false, async () => {
7436
+ const next = !(f.sessionImport !== false);
7437
+ if (await setFeature("sessionImport", next)) f.sessionImport = next;
7438
+ refreshRows();
7439
+ }),
6950
7440
  settingRow(L.featureSandboxReclaim, L.featureSandboxReclaimDesc, f.sandboxReclaim !== false, async () => {
6951
7441
  const next = !(f.sandboxReclaim !== false);
6952
7442
  if (await setFeature("sandboxReclaim", next)) f.sandboxReclaim = next;
@@ -7182,12 +7672,13 @@
7182
7672
  const paneAgents = h("div", { role: "tabpanel", style: "display:none" });
7183
7673
  const paneProxy = h("div", { role: "tabpanel", style: "display:none" });
7184
7674
  const paneSync = h("div", { role: "tabpanel", style: "display:none" });
7675
+ const paneImport = createSessionImportPane();
7185
7676
  const paneVision = h("div", { role: "tabpanel", style: "display:none" });
7186
7677
  const paneRtk = h("div", { role: "tabpanel", style: "display:none" });
7187
7678
  const paneHeadroom = h("div", { role: "tabpanel", style: "display:none" });
7188
7679
  const paneTitleGen = h("div", { role: "tabpanel", style: "display:none" });
7189
7680
  const paneDebug = h("div", { role: "tabpanel", style: "display:none" });
7190
- const panes = { features: paneFeatures, shortcuts: paneShortcuts, styles: paneStyles, perf: panePerf, agents: paneAgents, proxy: paneProxy, sync: paneSync, vision: paneVision, headroom: paneHeadroom, rtk: paneRtk, debug: paneDebug };
7681
+ const panes = { features: paneFeatures, shortcuts: paneShortcuts, styles: paneStyles, perf: panePerf, agents: paneAgents, proxy: paneProxy, sync: paneSync, import: paneImport, vision: paneVision, headroom: paneHeadroom, rtk: paneRtk, debug: paneDebug };
7191
7682
  const tabDefs = [
7192
7683
  ["features", L.tabFeatures],
7193
7684
  ["styles", L.tabStyles],
@@ -7196,6 +7687,7 @@
7196
7687
  ["shortcuts", L.tabShortcuts],
7197
7688
  ["proxy", L.tabProxy],
7198
7689
  ["sync", L.tabSync],
7690
+ ...config.features.sessionImport !== false ? [["import", L.tabImport]] : [],
7199
7691
  ["vision", L.tabVision],
7200
7692
  ["headroom", L.tabHeadroom],
7201
7693
  ["rtk", L.tabRtk],
@@ -7217,6 +7709,7 @@
7217
7709
  if (name !== "shortcuts" && hkRecording) stopHkRecording();
7218
7710
  for (const [id, pane] of Object.entries(panes)) pane.style.display = id === name ? "" : "none";
7219
7711
  for (const [id, bar] of Object.entries(subTabBars)) bar.style.display = id === name ? "" : "none";
7712
+ if (name === "import") paneImport.__onShow?.();
7220
7713
  renderTabs();
7221
7714
  };
7222
7715
  renderTabs();
@@ -10495,6 +10988,7 @@
10495
10988
  panePerf,
10496
10989
  paneProxy,
10497
10990
  paneSync,
10991
+ paneImport,
10498
10992
  paneVision,
10499
10993
  paneHeadroom,
10500
10994
  paneRtk,
@@ -10523,7 +11017,7 @@
10523
11017
  init_core();
10524
11018
  init_ui();
10525
11019
  init_core();
10526
- var installed = false;
11020
+ var installed2 = false;
10527
11021
  var dragKey = null;
10528
11022
  var lastOverRow = null;
10529
11023
  var lastOverBefore = false;
@@ -10549,8 +11043,8 @@
10549
11043
  });
10550
11044
  }
10551
11045
  function startTaskOrderWatcher() {
10552
- if (installed || typeof document === "undefined") return;
10553
- installed = true;
11046
+ if (installed2 || typeof document === "undefined") return;
11047
+ installed2 = true;
10554
11048
  ensureStyle();
10555
11049
  document.addEventListener("dragstart", (e) => {
10556
11050
  const row = e.target.closest && e.target.closest("[data-task-item-key]");
@@ -10990,11 +11484,13 @@
10990
11484
  const s = lastStats && statsSid === sid ? lastStats.sessionSummary : null;
10991
11485
  const tps = s && s.tps != null ? s.tps : null;
10992
11486
  const est = streamEst ? streamEst.value : null;
10993
- const shown = tps != null ? tps : est;
11487
+ const streaming = !!(streamEst && Date.now() - streamEst.at < 5e3);
11488
+ const useEst = streaming && est != null;
11489
+ const shown = useEst ? est : tps != null ? tps : est;
10994
11490
  if (shown == null) return null;
10995
11491
  const zh2 = isZhLocale();
10996
- const estMark = tps == null && est != null ? "\u2248" : "";
10997
- const detail = tps != null ? `${L.sbLabelOut} ${tps.toLocaleString()} tok/s${zh2 ? "\uFF08\u5B98\u65B9\u51C0\u751F\u6210\u53E3\u5F84\uFF0C\u672C\u4F1A\u8BDD\u6811\uFF09" : " (net generation, session tree)"}` : zh2 ? "\u65E0 usage \u6570\u636E\uFF0C\u6309\u6587\u672C\u589E\u957F\u4F30\u7B97" : "no usage data, estimated from text growth";
11492
+ const estMark = useEst || tps == null ? "\u2248" : "";
11493
+ const detail = useEst ? zh2 ? "\u6D41\u5F0F\u751F\u6210\u4E2D\uFF0C\u6309\u6587\u672C\u589E\u957F\u4F30\u7B97\uFF08\u7EA6 2 \u5B57\u7B26/token\uFF09" : "streaming; estimated from text growth (~2 chars/token)" : tps != null ? `${L.sbLabelOut} ${tps.toLocaleString()} tok/s${zh2 ? "\uFF08\u5B98\u65B9\u51C0\u751F\u6210\u53E3\u5F84\uFF0C\u672C\u4F1A\u8BDD\u6811\uFF09" : " (net generation, session tree)"}` : zh2 ? "\u65E0 usage \u6570\u636E\uFF0C\u6309\u6587\u672C\u589E\u957F\u4F30\u7B97" : "no usage data, estimated from text growth";
10998
11494
  return {
10999
11495
  html: sbIcon("tokRate") + label(L.sbLabelOut) + `<b>${estMark}${fmtNum(Math.round(shown * 10) / 10)} tok/s</b>`,
11000
11496
  title: `${L.sbItemTokRate}${zh2 ? "\uFF08\u672C\u4F1A\u8BDD\uFF09\uFF1A" : " (this session): "}${detail}`,
@@ -11069,29 +11565,48 @@
11069
11565
  barEl.style.marginBottom = hasSession ? "-14px" : "0";
11070
11566
  barEl.style.paddingBottom = hasSession ? "0" : "7px";
11071
11567
  const L = t();
11072
- const parts = [];
11073
- let lastGroup = "";
11568
+ const entries = [];
11074
11569
  for (const it of items) {
11075
11570
  if (!it.on) continue;
11076
11571
  const c = itemContent(it.id, L);
11077
11572
  if (!c) continue;
11078
- const group = GLOBAL_GROUP.has(it.id) ? "g" : "s";
11079
- if (lastGroup && group !== lastGroup) parts.push('<span class="zcodepro-statusbar-groupsep"></span>');
11080
- lastGroup = group;
11081
- parts.push(`<span title="${c.title.replace(/"/g, "&quot;")}"${c.tone ? ` data-tone="${c.tone}"` : ""}>${c.html}</span>`);
11573
+ entries.push({ id: it.id, group: GLOBAL_GROUP.has(it.id) ? "g" : "s", ...c });
11082
11574
  }
11083
11575
  const SEP = '<span class="zcodepro-statusbar-sep">\xB7</span>';
11084
11576
  const GROUPSEP = '<span class="zcodepro-statusbar-groupsep"></span>';
11085
- const html = parts.reduce((acc, p, i) => {
11086
- if (i === 0) return p;
11087
- if (p === GROUPSEP || parts[i - 1] === GROUPSEP) return acc + p;
11088
- return acc + SEP + p;
11089
- }, "");
11090
- barEl.style.display = parts.length ? "" : "none";
11091
- if (html === lastRenderedHtml) return;
11092
- lastRenderedHtml = html;
11093
- barEl.innerHTML = html;
11094
- }
11577
+ const buildHtml = (hidden2) => {
11578
+ const parts = [];
11579
+ let lastGroup = "";
11580
+ for (const e of entries) {
11581
+ if (hidden2.has(e.id)) continue;
11582
+ if (lastGroup && e.group !== lastGroup) parts.push(GROUPSEP);
11583
+ lastGroup = e.group;
11584
+ parts.push(`<span title="${e.title.replace(/"/g, "&quot;")}"${e.tone ? ` data-tone="${e.tone}"` : ""}>${e.html}</span>`);
11585
+ }
11586
+ return parts.reduce((acc, p, i) => {
11587
+ if (i === 0) return p;
11588
+ if (p === GROUPSEP || parts[i - 1] === GROUPSEP) return acc + p;
11589
+ return acc + SEP + p;
11590
+ }, "");
11591
+ };
11592
+ const hidden = /* @__PURE__ */ new Set();
11593
+ for (let guard = 0; guard <= HIDE_ORDER.length; guard++) {
11594
+ const html = buildHtml(hidden);
11595
+ barEl.style.display = html ? "" : "none";
11596
+ if (html !== lastRenderedHtml) {
11597
+ lastRenderedHtml = html;
11598
+ barEl.innerHTML = html;
11599
+ }
11600
+ const gap = 8;
11601
+ let sum = 0;
11602
+ for (const c of barEl.children) sum += c.getBoundingClientRect().width + gap;
11603
+ if (sum - gap <= host.clientWidth + 2) break;
11604
+ const next = HIDE_ORDER.find((id) => !hidden.has(id));
11605
+ if (!next) break;
11606
+ hidden.add(next);
11607
+ }
11608
+ }
11609
+ var HIDE_ORDER = ["tasks", "questions", "totalTokens", "todayTokens", "inOut"];
11095
11610
  async function tick() {
11096
11611
  if (!enabled4 || document.hidden) return;
11097
11612
  refreshOfficial();
@@ -11161,6 +11676,7 @@
11161
11676
  init_core();
11162
11677
  var enabled5 = true;
11163
11678
  var rounds = [];
11679
+ var liveRounds = [];
11164
11680
  var scanTimer = 0;
11165
11681
  var turnCfg = [
11166
11682
  { id: "turnIn", on: true },
@@ -11302,6 +11818,7 @@
11302
11818
  if (sid !== lastSid2) {
11303
11819
  lastSid2 = sid;
11304
11820
  rounds = [];
11821
+ liveRounds = [];
11305
11822
  for (const r of rows) clearRow(r.row);
11306
11823
  void tick2();
11307
11824
  return;
@@ -11311,24 +11828,68 @@
11311
11828
  return;
11312
11829
  }
11313
11830
  const agg = rows.map(() => ({ in: 0, out: 0, cacheRead: 0, tpsOut: 0, genMs: 0 }));
11314
- const dayOf = (t2) => {
11315
- const d = new Date(t2);
11316
- return d.getFullYear() * 1e4 + (d.getMonth() + 1) * 100 + d.getDate();
11317
- };
11318
- for (const b of rounds) {
11319
- let owner = -1;
11320
- for (let i = 0; i < rows.length; i++) {
11321
- if (rows[i].ts <= b.at) owner = i;
11322
- else break;
11323
- }
11324
- if (owner < 0) continue;
11325
- if (dayOf(rows[owner].ts) !== dayOf(b.at)) continue;
11326
- agg[owner].in += b.in;
11327
- agg[owner].out += b.out;
11328
- agg[owner].cacheRead += b.cacheRead;
11329
- if (b.genMs) {
11330
- agg[owner].tpsOut += b.out;
11331
- agg[owner].genMs += b.genMs;
11831
+ if (rounds.some((r) => r.startAt != null)) {
11832
+ const used = /* @__PURE__ */ new Set();
11833
+ for (const b of rounds) {
11834
+ const startMin = Math.floor((b.startAt ?? b.at) / 6e4);
11835
+ const endMin = Math.floor(b.at / 6e4);
11836
+ let owner = -1;
11837
+ let bestDist = Infinity;
11838
+ for (let i = 0; i < rows.length; i++) {
11839
+ if (used.has(i)) continue;
11840
+ const m = Math.floor(rows[i].ts / 6e4);
11841
+ if (m < startMin || m > endMin) continue;
11842
+ const dist = Math.abs(rows[i].ts - b.at);
11843
+ if (dist < bestDist) {
11844
+ owner = i;
11845
+ bestDist = dist;
11846
+ }
11847
+ }
11848
+ if (owner < 0) continue;
11849
+ used.add(owner);
11850
+ agg[owner].in += b.in;
11851
+ agg[owner].out += b.out;
11852
+ agg[owner].cacheRead += b.cacheRead;
11853
+ if (b.genMs) {
11854
+ agg[owner].tpsOut += b.out;
11855
+ agg[owner].genMs += b.genMs;
11856
+ }
11857
+ }
11858
+ if (liveRounds.length && rows.length) {
11859
+ const owner = rows.length - 1;
11860
+ const lastTurnAt = rounds.length ? rounds[rounds.length - 1].at : 0;
11861
+ if (!used.has(owner) && rows[owner].ts >= lastTurnAt - 6e4) {
11862
+ for (const b of liveRounds) {
11863
+ agg[owner].in += b.in;
11864
+ agg[owner].out += b.out;
11865
+ agg[owner].cacheRead += b.cacheRead;
11866
+ if (b.genMs) {
11867
+ agg[owner].tpsOut += b.out;
11868
+ agg[owner].genMs += b.genMs;
11869
+ }
11870
+ }
11871
+ }
11872
+ }
11873
+ } else {
11874
+ const dayOf = (t2) => {
11875
+ const d = new Date(t2);
11876
+ return d.getFullYear() * 1e4 + (d.getMonth() + 1) * 100 + d.getDate();
11877
+ };
11878
+ for (const b of rounds) {
11879
+ let owner = -1;
11880
+ for (let i = 0; i < rows.length; i++) {
11881
+ if (rows[i].ts <= b.at) owner = i;
11882
+ else break;
11883
+ }
11884
+ if (owner < 0) continue;
11885
+ if (dayOf(rows[owner].ts) !== dayOf(b.at)) continue;
11886
+ agg[owner].in += b.in;
11887
+ agg[owner].out += b.out;
11888
+ agg[owner].cacheRead += b.cacheRead;
11889
+ if (b.genMs) {
11890
+ agg[owner].tpsOut += b.out;
11891
+ agg[owner].genMs += b.genMs;
11892
+ }
11332
11893
  }
11333
11894
  }
11334
11895
  for (let i = 0; i < rows.length; i++) {
@@ -11345,6 +11906,7 @@
11345
11906
  if (res && res.ok && Array.isArray(res.rounds)) {
11346
11907
  if (seq !== tickSeq2 || sid !== currentSessionId()) return;
11347
11908
  rounds = res.rounds;
11909
+ liveRounds = Array.isArray(res.live) ? res.live : [];
11348
11910
  scan3();
11349
11911
  }
11350
11912
  }
@@ -12012,8 +12574,8 @@
12012
12574
  svg.setAttribute("stroke-linejoin", "round");
12013
12575
  svg.setAttribute("class", ((baseClass || "size-4") + " " + ROBOT_CLASS).trim());
12014
12576
  svg.setAttribute("title", t().subagentRobotTip);
12015
- for (const [tag, attrs] of BOT_FALLBACK) {
12016
- const el = document.createElementNS(ns, tag);
12577
+ for (const [tag2, attrs] of BOT_FALLBACK) {
12578
+ const el = document.createElementNS(ns, tag2);
12017
12579
  for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
12018
12580
  svg.append(el);
12019
12581
  }
@@ -12056,8 +12618,8 @@
12056
12618
  svg.setAttribute("stroke-linejoin", "round");
12057
12619
  svg.setAttribute("class", `size-4 text-foreground-subtle ${TERMINAL_CLASS}`);
12058
12620
  svg.setAttribute("title", t().subagentTermTip);
12059
- for (const [tag, attrs] of TERMINAL_FALLBACK) {
12060
- const el = document.createElementNS(ns, tag);
12621
+ for (const [tag2, attrs] of TERMINAL_FALLBACK) {
12622
+ const el = document.createElementNS(ns, tag2);
12061
12623
  for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
12062
12624
  svg.append(el);
12063
12625
  }
@@ -12248,23 +12810,20 @@
12248
12810
  }
12249
12811
  liveSessions = live;
12250
12812
  liveByWs = liveWs;
12251
- const ts = services && services.zcodeTaskService;
12252
12813
  const busy = /* @__PURE__ */ new Set();
12253
- if (ts && typeof ts.listActiveTaskIds === "function") {
12254
- const needBusyWs = /* @__PURE__ */ new Set();
12255
- for (const el of document.querySelectorAll(TASK_SEL5)) {
12256
- const key = el.getAttribute("data-task-item-key") || "";
12257
- const cut = key.lastIndexOf(":");
12258
- const sid = cut > 1 ? key.slice(cut + 1) : "";
12259
- const slot = rowIconSlot(el);
12260
- const unread = slot && slot.querySelector("[data-unread-indicator]");
12261
- if (live.has(sid) || unread) needBusyWs.add(normWs(key.slice(0, cut)));
12262
- }
12263
- await Promise.all([...needBusyWs].flatMap((ws) => [ws, ws + "/"].map(async (w) => {
12264
- const r = await withTimeout(ts.listActiveTaskIds({ workspacePath: w }), CALL_TIMEOUT_MS, null);
12265
- if (Array.isArray(r)) for (const id of r) busy.add(String(id));
12266
- })));
12267
- }
12814
+ const needBusyWs = /* @__PURE__ */ new Set();
12815
+ for (const el of document.querySelectorAll(TASK_SEL5)) {
12816
+ const key = el.getAttribute("data-task-item-key") || "";
12817
+ const cut = key.lastIndexOf(":");
12818
+ const sid = cut > 1 ? key.slice(cut + 1) : "";
12819
+ const slot = rowIconSlot(el);
12820
+ const unread = slot && slot.querySelector("[data-unread-indicator]");
12821
+ if (live.has(sid) || unread) needBusyWs.add(normWs(key.slice(0, cut)));
12822
+ }
12823
+ await Promise.all([...needBusyWs].map(async (ws) => {
12824
+ const ids = await withTimeout(listActiveIdsCached(ws), CALL_TIMEOUT_MS, null);
12825
+ if (ids) for (const id of ids) busy.add(id);
12826
+ }));
12268
12827
  busySessions = busy;
12269
12828
  const term = /* @__PURE__ */ new Set();
12270
12829
  const termWs = /* @__PURE__ */ new Set();
@@ -12432,6 +12991,38 @@
12432
12991
  await reclaim(ws);
12433
12992
  blockUntil.set(ws, Date.now() + cooldownMs);
12434
12993
  }
12994
+ function dueForReclaim(workspaces, busy, idleSince2, blockUntil2, now, threshold, startupDue) {
12995
+ const due = [];
12996
+ const seen2 = /* @__PURE__ */ new Set();
12997
+ const add = (ws) => {
12998
+ if (!seen2.has(ws)) {
12999
+ seen2.add(ws);
13000
+ due.push(ws);
13001
+ }
13002
+ };
13003
+ if (startupDue) {
13004
+ for (const ws of workspaces) {
13005
+ if (busy.has(ws) || (blockUntil2.get(ws) || 0) > now) continue;
13006
+ add(ws);
13007
+ }
13008
+ }
13009
+ for (const ws of workspaces) {
13010
+ if (busy.has(ws)) {
13011
+ idleSince2.delete(ws);
13012
+ continue;
13013
+ }
13014
+ if (!idleSince2.has(ws)) {
13015
+ idleSince2.set(ws, now);
13016
+ continue;
13017
+ }
13018
+ if (now - idleSince2.get(ws) < threshold) continue;
13019
+ if ((blockUntil2.get(ws) || 0) > now) continue;
13020
+ if (seen2.has(ws)) continue;
13021
+ idleSince2.delete(ws);
13022
+ add(ws);
13023
+ }
13024
+ return due;
13025
+ }
12435
13026
  async function tick4() {
12436
13027
  if (!enabled8) {
12437
13028
  idleSince.clear();
@@ -12462,38 +13053,30 @@
12462
13053
  blockUntil.delete(ws);
12463
13054
  }
12464
13055
  }
12465
- const candidates = [...workspaces].filter((ws) => !busy.has(normP(ws)));
12466
- const res = candidates.length ? await rpc("/idle-busy", { method: "POST", body: { paths: candidates } }) : { ok: true, scan: true, busy: [] };
13056
+ const now = Date.now();
13057
+ const startupDue = !startupSweepDone && now - bootAt >= startupMinutes * 6e4;
13058
+ const due = dueForReclaim(workspaces, busy, idleSince, blockUntil, now, threshold, startupDue);
13059
+ if (!due.length) {
13060
+ if (startupDue) startupSweepDone = true;
13061
+ return;
13062
+ }
13063
+ const res = await rpc("/idle-busy", { method: "POST", body: { paths: due } });
12467
13064
  if (!res.ok || res.scan === false) {
12468
13065
  if (!scanDisabledLogged) {
12469
13066
  scanDisabledLogged = true;
12470
13067
  console.info("[zcodepro] idle-reclaim: \u540E\u53F0\u547D\u4EE4\u626B\u63CF\u4E0D\u53EF\u7528\uFF0C\u7A7A\u95F2\u56DE\u6536\u505C\u7528");
12471
13068
  }
13069
+ if (startupDue) startupSweepDone = true;
12472
13070
  idleSince.clear();
12473
13071
  return;
12474
13072
  }
13073
+ if (startupDue) startupSweepDone = true;
12475
13074
  const procBusy = new Set(res.busy || []);
12476
- const idleCandidates = candidates.filter((ws) => !procBusy.has(ws));
12477
- const now = Date.now();
12478
- if (!startupSweepDone && now - bootAt >= startupMinutes * 6e4) {
12479
- startupSweepDone = true;
12480
- for (const ws of idleCandidates) {
12481
- if ((blockUntil.get(ws) || 0) > now) continue;
12482
- await tryReclaim(ws, threshold);
12483
- }
12484
- }
12485
- for (const ws of workspaces) {
12486
- if (busy.has(ws) || procBusy.has(ws)) {
13075
+ for (const ws of due) {
13076
+ if (procBusy.has(ws)) {
12487
13077
  idleSince.delete(ws);
12488
13078
  continue;
12489
13079
  }
12490
- if (!idleSince.has(ws)) {
12491
- idleSince.set(ws, now);
12492
- continue;
12493
- }
12494
- if (now - idleSince.get(ws) < threshold) continue;
12495
- if ((blockUntil.get(ws) || 0) > now) continue;
12496
- idleSince.delete(ws);
12497
13080
  await tryReclaim(ws, threshold);
12498
13081
  }
12499
13082
  }
@@ -13066,9 +13649,9 @@
13066
13649
  continue;
13067
13650
  }
13068
13651
  if (node.nodeType !== Node.ELEMENT_NODE) continue;
13069
- const tag = node.tagName;
13070
- const el = document.createElement(tag.toLowerCase());
13071
- if (tag === "TD" || tag === "TH") {
13652
+ const tag2 = node.tagName;
13653
+ const el = document.createElement(tag2.toLowerCase());
13654
+ if (tag2 === "TD" || tag2 === "TH") {
13072
13655
  for (const a of ["colspan", "rowspan"]) {
13073
13656
  const v = node.getAttribute(a);
13074
13657
  if (v && v !== "1") el.setAttribute(a, v);