@spzxg/cli-ui 0.6.13 → 0.6.17

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +100 -2
  2. package/README.md +131 -7
  3. package/dist/{cli-ui-embed-CXaGT9e4.js → cli-ui-embed-REq-GvM7.js} +20350 -19892
  4. package/dist/{cli-ui-index-bMQJjEBW.js → cli-ui-index-p_XTnmsN.js} +2 -2
  5. package/dist/{cli-ui-jszip.min-D_w3a6AF.js → cli-ui-jszip.min-0mqaiYeK.js} +1 -1
  6. package/dist/{cli-ui-jszip.min-AMeWMDT5.js → cli-ui-jszip.min-CJa9yrKW.js} +2 -2
  7. package/dist/{cli-ui-xlsx-DMzew4IO.js → cli-ui-xlsx-BPL7P3mE.js} +1 -1
  8. package/dist/cli-ui.css +1 -1
  9. package/dist/cli-ui.js +1 -1
  10. package/package.json +1 -1
  11. package/src/board/BrowserPane.tsx +93 -30
  12. package/src/board/ChangesPane.tsx +86 -62
  13. package/src/board/CliBoard.tsx +62 -27
  14. package/src/board/FileViewer.tsx +49 -13
  15. package/src/board/context.ts +38 -7
  16. package/src/board/diffLines.ts +46 -0
  17. package/src/board/diffRefresh.ts +63 -0
  18. package/src/board/fileDiff.tsx +117 -0
  19. package/src/board/fileKind.ts +5 -3
  20. package/src/board/fileScope.ts +4 -2
  21. package/src/board/fileWatch.ts +59 -9
  22. package/src/board/linkage.ts +68 -0
  23. package/src/board/pathResolve.ts +108 -0
  24. package/src/board/useBoardUpload.tsx +7 -7
  25. package/src/board/workspace.ts +7 -1
  26. package/src/chat/CliChat.tsx +197 -216
  27. package/src/chat/Composer.tsx +10 -9
  28. package/src/chat/queueEdit.ts +27 -0
  29. package/src/components.tsx +2 -2
  30. package/src/core/blocks.ts +4 -1
  31. package/src/core/client.ts +86 -9
  32. package/src/core/config.ts +1 -1
  33. package/src/core/conversation.ts +23 -5
  34. package/src/core/documentUpload.ts +22 -5
  35. package/src/core/provider.tsx +14 -8
  36. package/src/core/store.ts +307 -63
  37. package/src/core/types.ts +49 -0
  38. package/src/elements.tsx +8 -5
  39. package/src/msglist/CliMsgList.tsx +30 -9
  40. package/src/operator/node/AgentConnect.tsx +28 -29
  41. package/src/operator/node/AppearancePanel.tsx +1 -1
  42. package/src/operator/node/BranchHistory.tsx +11 -7
  43. package/src/operator/node/BranchNavigator.tsx +1 -1
  44. package/src/operator/node/BrowserPane.tsx +7 -7
  45. package/src/operator/node/Chat.tsx +53 -272
  46. package/src/operator/node/CommandPalette.tsx +1 -1
  47. package/src/operator/node/Composer.tsx +13 -6
  48. package/src/operator/node/Layout.tsx +1 -1
  49. package/src/operator/node/Markdown.tsx +6 -36
  50. package/src/operator/node/Modal.tsx +1 -1
  51. package/src/operator/node/OnboardingWizard.tsx +11 -9
  52. package/src/operator/node/Orchestrator.tsx +18 -8
  53. package/src/operator/node/ProjectLanding.tsx +1 -1
  54. package/src/operator/node/ProjectsColumn.tsx +1 -1
  55. package/src/operator/node/ProviderAuth.tsx +16 -16
  56. package/src/operator/node/RunSwitch.tsx +1 -1
  57. package/src/operator/node/Services.tsx +1 -1
  58. package/src/operator/node/SessionRail.tsx +55 -19
  59. package/src/operator/node/SessionView.tsx +18 -16
  60. package/src/operator/node/SettingsView.tsx +1 -1
  61. package/src/operator/node/TaskBoard.tsx +1 -1
  62. package/src/operator/node/TaskChanges.tsx +83 -108
  63. package/src/operator/node/TaskHero.tsx +5 -5
  64. package/src/operator/node/TasksColumn.tsx +1 -1
  65. package/src/operator/node/Transcript.tsx +15 -250
  66. package/src/operator/node/Welcome.tsx +1 -1
  67. package/src/operator/node/WorktreePrune.tsx +1 -1
  68. package/src/operator/node/api.ts +17 -0
  69. package/src/operator/node/boardBackend.ts +4 -1
  70. package/src/operator/node/boardEvents.ts +17 -3
  71. package/src/operator/node/boardInteraction.ts +7 -4
  72. package/src/operator/node/boardState.ts +23 -14
  73. package/src/operator/node/composerDraft.ts +22 -0
  74. package/src/operator/node/fileLinks.ts +4 -38
  75. package/src/operator/node/format.ts +13 -104
  76. package/src/operator/node/github.tsx +14 -14
  77. package/src/operator/node/liveStream.ts +47 -6
  78. package/src/operator/node/modals.tsx +59 -22
  79. package/src/operator/node/recheckOnReturn.ts +28 -0
  80. package/src/operator/node/shared.tsx +10 -50
  81. package/src/operator/node/types.ts +9 -0
  82. package/src/operator/node/useOrchestrator.ts +9 -8
  83. package/src/operator/node/useRecaps.ts +15 -4
  84. package/src/operator/node/useTaskStream.ts +2 -2
  85. package/src/operator.base.css +9 -4
  86. package/src/operator.css +9 -4
  87. package/src/styles.css +22 -8
  88. package/src/ui/Markdown.tsx +36 -21
  89. package/src/ui/Popover.tsx +1 -1
  90. package/src/ui/QueuedMessages.tsx +58 -15
  91. package/src/ui/SubagentChat.tsx +42 -6
  92. package/src/ui/Transcript.tsx +19 -14
  93. package/src/ui/fileLinks.ts +6 -3
  94. package/src/ui/format.ts +27 -9
  95. package/src/ui/icons.tsx +2 -0
  96. package/src/ui/shared.tsx +11 -7
  97. package/src/ui/transcriptModel.ts +40 -9
  98. package/src/ui/useTranscriptWindow.ts +253 -0
  99. package/src/operator/node/icons.tsx +0 -88
  100. package/src/operator/node/transcriptModel.ts +0 -129
@@ -3,7 +3,7 @@
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import type { Priority, Status, AskQuestion, AskAnswers } from "./protocol/types";
5
5
  import type { ResolveResult } from "./TaskChanges";
6
- import { jget, jsend } from "./api";
6
+ import { cancelPendingMessage, jget, jsend } from "./api";
7
7
  import { isAwaiting, blockerTitles, formatAnswersText } from "./format";
8
8
  import { loadPersist, readUrlSel } from "./persist";
9
9
  import { DEFAULT_SETTINGS, EMPTY_AGENTS, type AgentsBundle, type OnboardingT, type ProjectRow, type TaskRow } from "./types";
@@ -401,11 +401,11 @@ export function useOrchestrator() {
401
401
  }, []);
402
402
 
403
403
  // Drop a queued (not-yet-run) follow-up. The server publishes `dequeued`,
404
- // which the stream handler turns into removing the bubble — so this is
405
- // fire-and-forget; no optimistic local mutation needed.
406
- const cancelQueued = useCallback(async (taskId: string, pendingId: string) => {
407
- try { await fetch(`/api/tasks/${taskId}/pending`, { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ pendingId }) }); } catch {}
408
- }, []);
404
+ // which the stream handler turns into removing the bubble — no optimistic
405
+ // local mutation needed. Resolves false when the message had already been
406
+ // dequeued to run (nothing removed) so "edit" won't duplicate it; throws when
407
+ // the request itself failed so the queue row can say so.
408
+ const cancelQueued = useCallback((taskId: string, pendingId: string) => cancelPendingMessage(taskId, pendingId), []);
409
409
 
410
410
  // Materialize a conflicted merge in the task's worktree, then stream an AI
411
411
  // resolution turn into the transcript. Returns enough for TaskChanges to show
@@ -638,8 +638,9 @@ export function useOrchestrator() {
638
638
  jget<ProjectRow[]>("/api/projects").then(setProjects);
639
639
  });
640
640
  }, []);
641
- const removeProject = async (id: string) => {
642
- await jsend(`/api/projects/${id}`, "DELETE");
641
+ // confirm: the storage root the user was shown, for a platform-created Job project.
642
+ const removeProject = async (id: string, confirm?: { delete_storage: string }) => {
643
+ await jsend(`/api/projects/${id}`, "DELETE", confirm);
643
644
  const ps = await jget<ProjectRow[]>("/api/projects");
644
645
  setProjects(ps);
645
646
  setModal(null);
@@ -4,6 +4,9 @@ import { useCallback, useEffect, useState, type MutableRefObject } from "react";
4
4
  import { jget, jsend } from "./api";
5
5
  import type { RecapInfo, TaskRow } from "./types";
6
6
 
7
+ /** Automatic recap sweeps run on user activity, at most this often. */
8
+ const SWEEP_GAP_MS = 5 * 60 * 1000;
9
+
7
10
  // Owns project "where you left off" recaps plus the selection-on-landing logic:
8
11
  // fetch/generate a recap when entering a project, sweep stale projects on an
9
12
  // interval, and decide whether to land on the recap or auto-pick the first task.
@@ -73,18 +76,26 @@ export function useRecaps({ selProj, selTask, tasks, setSelTask, selProjRef, set
73
76
  if (!tasks.some((t) => t.id === selTask)) setSelTask(null);
74
77
  }, [selTask, tasks, selProj, setSelTask]);
75
78
 
76
- // Proactively sweep for stale projects on load and on an interval, then
77
- // refresh the currently-open project's recap so a freshly-baked one appears.
79
+ // Proactively sweep for stale projects on load and whenever the user is here —
80
+ // tab visible again, window focused, a click or key press — at most once per
81
+ // 5 min (no timer: an untouched tab doesn't keep sweeping), then refresh the
82
+ // currently-open project's recap so a freshly-baked one appears.
78
83
  useEffect(() => {
79
84
  if (!settingsReady || !backgroundJobs || recapMode !== "automatic") return;
85
+ let last = 0;
80
86
  const sweep = () => {
87
+ if (document.hidden || Date.now() - last < SWEEP_GAP_MS) return;
88
+ last = Date.now();
81
89
  jsend("/api/recaps/sweep", "POST")
82
90
  .then(() => { if (selProjRef.current) fetchRecap(selProjRef.current); })
83
91
  .catch(() => {});
84
92
  };
85
93
  sweep();
86
- const t = setInterval(sweep, 5 * 60 * 1000);
87
- return () => clearInterval(t);
94
+ const onVisible = () => { if (document.visibilityState === "visible") sweep(); };
95
+ const activity = ["focus", "pointerdown", "keydown"] as const;
96
+ for (const name of activity) window.addEventListener(name, sweep, { passive: true });
97
+ document.addEventListener("visibilitychange", onVisible);
98
+ return () => { for (const name of activity) window.removeEventListener(name, sweep); document.removeEventListener("visibilitychange", onVisible); };
88
99
  }, [backgroundJobs, fetchRecap, recapMode, selProjRef, settingsReady]);
89
100
 
90
101
  return { recaps, fetchRecap };
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useRef, useState, type MutableRefObject } from
4
4
  import type { TaskStreamEvent, ToolData, AskAnswers, Message } from "./protocol/types";
5
5
  import { jget } from "./api";
6
6
  import { openLive } from "./liveStream";
7
- import { HISTORY_PAGE, SNAPSHOT_TAIL, indexFromEnd, mergeSnapshot, toolDataOf, touchRecent, trimToTail } from "./transcriptModel";
7
+ import { HISTORY_PAGE, SNAPSHOT_TAIL, indexFromEnd, mergeSnapshot, toolDataOf, touchRecent, trimToTail } from "../../ui/transcriptModel";
8
8
  import { contextPct } from "./format";
9
9
  import { capsFor } from "./agents";
10
10
  import type { AgentsBundle, Msg, ProjectRow, TaskRow } from "./types";
@@ -96,7 +96,7 @@ export function useTaskStream({ selTask, selProjRef, agentsRef, setTaskRunning,
96
96
  // objects, so a reconnect doesn't re-render the whole transcript.
97
97
  const committed: Msg[] = ev.messages.map(toMsg);
98
98
  const queued: Msg[] = ev.pending.map((p) => ({ id: p.id, role: "queued" as const, content: p.content, generation: p.generation, ts: p.created_at }));
99
- const merged = mergeSnapshot(msgsRef.current[taskId], committed, queued, ev.older ?? 0);
99
+ const merged = mergeSnapshot(msgsRef.current[taskId], committed, ev.older ?? 0, queued);
100
100
  msgsRef.current = { ...msgsRef.current, [taskId]: merged.msgs };
101
101
  setMsgsByTask((prev) => ({ ...prev, [taskId]: merged.msgs }));
102
102
  setOlderByTask((prev) => ({ ...prev, [taskId]: merged.older }));
@@ -1450,7 +1450,8 @@ button.pop-item:hover{background:var(--surface-2);}
1450
1450
  .composer .comp-box{border-radius:26px;border-color:var(--line);box-shadow:0 4px 20px rgba(0,0,0,.035);}
1451
1451
  .composer .comp-box:focus-within{border-color:var(--line-strong);box-shadow:0 6px 24px rgba(0,0,0,.055);}
1452
1452
  .composer .comp-toolbar{gap:6px;padding:6px 12px 12px;}
1453
- .composer .comp-area{padding:12px 20px 4px;}
1453
+ /* 文字区默认两行:上下只留很少的空白,整个输入框约 102px(工具栏 42px)。 */
1454
+ .composer .comp-area{padding:8px 20px 2px;}
1454
1455
  .composer .attach-chip.image{width:108px;height:88px;border-radius:12px;}
1455
1456
  .composer .attach-chip.image>img{height:100%;object-fit:cover;}
1456
1457
  .composer .attach-chip .attach-x{width:26px;height:26px;top:4px;right:4px;font-size:16px;}
@@ -1459,7 +1460,7 @@ button.pop-item:hover{background:var(--surface-2);}
1459
1460
  .composer .attach-row .attach-chip{flex:none;}
1460
1461
  .composer .cli-blocks{max-height:min(30vh,180px);}
1461
1462
  @container(max-width:420px){
1462
- .composer .comp-area{padding:12px 16px 4px;}
1463
+ .composer .comp-area{padding:8px 16px 2px;}
1463
1464
  .composer .comp-toolbar{gap:4px;padding:6px 10px 10px;}
1464
1465
  .composer .comp-setting{padding:6px 9px;}
1465
1466
  .composer .attach-chip.image{width:86px;height:76px;}
@@ -1475,6 +1476,9 @@ button.pop-item:hover{background:var(--surface-2);}
1475
1476
  .composer .comp-model .comp-setting>svg{width:12px;height:12px;}
1476
1477
  .composer .comp-foot{flex-wrap:wrap;gap:6px;}
1477
1478
  .composer .comp-foot>.send-group{margin-left:auto;}
1479
+ /* 智能体紧挨发送按钮:它和发送都用 margin-left:auto 会平分空位,智能体被挤到中间(PC 窄聊天栏也会进到这一档)。
1480
+ 改为智能体占满空位、按钮靠右;换行时发送仍靠右。 */
1481
+ .composer .comp-foot>.comp-model{flex:1 1 auto;display:flex;justify-content:flex-end;margin-left:0;}
1478
1482
  }
1479
1483
  @media(pointer:coarse){
1480
1484
  .composer-popover .composer-option{min-height:52px;}
@@ -1871,11 +1875,12 @@ button.pop-item:hover{background:var(--surface-2);}
1871
1875
  [data-chat-layout]>.cli-refs,[data-chat-layout]>.cli-queue{width:calc(100% - 2 * var(--cli-chat-gutter) - var(--cli-chat-scrollbar,0px));max-width:var(--cli-chat-content-max);margin-inline:auto;margin-inline-start:max(var(--cli-chat-gutter),calc((100% - var(--cli-chat-scrollbar,0px) - var(--cli-chat-content-max)) / 2));flex-shrink:0;}
1872
1876
  @container chat-column (max-width:900px){[data-chat-layout]>*{--cli-chat-content-max:100%;}}
1873
1877
  @container chat-column (max-width:640px){[data-chat-layout]>*{--cli-chat-gutter:12px;}.session [data-chat-layout]>.composer{padding-inline-end:var(--cli-chat-gutter);}}
1878
+ /* PC:正文与输入区两侧留白 64px,窄聊天栏 48px(0.6.14 起在 0.6.13 的基础上再翻一倍);手机保持 16 / 12px。 */
1874
1879
  @media (min-width:761px){
1875
- [data-chat-layout]{--cli-chat-gutter:32px;}
1880
+ [data-chat-layout]{--cli-chat-gutter:64px;}
1876
1881
  .session [data-chat-layout] .composer{padding-inline:var(--cli-chat-gutter);padding-inline-end:calc(var(--cli-chat-gutter) + var(--cli-chat-scrollbar,0px));}
1877
1882
  [data-chat-layout] .composer>.composer-inner{width:100%;max-width:var(--cli-chat-content-max);margin-inline:auto;}
1878
- @container chat-column (max-width:640px){[data-chat-layout]>*{--cli-chat-gutter:24px;}.session [data-chat-layout] .composer{padding-inline-end:var(--cli-chat-gutter);}}
1883
+ @container chat-column (max-width:640px){[data-chat-layout]>*{--cli-chat-gutter:48px;}.session [data-chat-layout] .composer{padding-inline-end:var(--cli-chat-gutter);}}
1879
1884
  }
1880
1885
  .task-origin{display:flex;align-items:center;gap:5px;font-size:10px;color:var(--ink-3);padding-top:7px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
1881
1886
  .fork-sources{display:flex;flex-wrap:wrap;gap:6px;padding:12px 14px 0;}
package/src/operator.css CHANGED
@@ -1450,7 +1450,8 @@
1450
1450
  .cli-ui .composer .comp-box{border-radius:26px;border-color:var(--line);box-shadow:0 4px 20px rgba(0,0,0,.035);}
1451
1451
  .cli-ui .composer .comp-box:focus-within{border-color:var(--line-strong);box-shadow:0 6px 24px rgba(0,0,0,.055);}
1452
1452
  .cli-ui .composer .comp-toolbar{gap:6px;padding:6px 12px 12px;}
1453
- .cli-ui .composer .comp-area{padding:12px 20px 4px;}
1453
+ /* 文字区默认两行:上下只留很少的空白,整个输入框约 102px(工具栏 42px)。 */
1454
+ .cli-ui .composer .comp-area{padding:8px 20px 2px;}
1454
1455
  .cli-ui .composer .attach-chip.image{width:108px;height:88px;border-radius:12px;}
1455
1456
  .cli-ui .composer .attach-chip.image>img{height:100%;object-fit:cover;}
1456
1457
  .cli-ui .composer .attach-chip .attach-x{width:26px;height:26px;top:4px;right:4px;font-size:16px;}
@@ -1459,7 +1460,7 @@
1459
1460
  .cli-ui .composer .attach-row .attach-chip{flex:none;}
1460
1461
  .cli-ui .composer .cli-blocks{max-height:min(30vh,180px);}
1461
1462
  @container(max-width:420px){
1462
- .cli-ui .composer .comp-area{padding:12px 16px 4px;}
1463
+ .cli-ui .composer .comp-area{padding:8px 16px 2px;}
1463
1464
  .cli-ui .composer .comp-toolbar{gap:4px;padding:6px 10px 10px;}
1464
1465
  .cli-ui .composer .comp-setting{padding:6px 9px;}
1465
1466
  .cli-ui .composer .attach-chip.image{width:86px;height:76px;}
@@ -1475,6 +1476,9 @@
1475
1476
  .cli-ui .composer .comp-model .comp-setting>svg{width:12px;height:12px;}
1476
1477
  .cli-ui .composer .comp-foot{flex-wrap:wrap;gap:6px;}
1477
1478
  .cli-ui .composer .comp-foot>.send-group{margin-left:auto;}
1479
+ /* 智能体紧挨发送按钮:它和发送都用 margin-left:auto 会平分空位,智能体被挤到中间(PC 窄聊天栏也会进到这一档)。
1480
+ 改为智能体占满空位、按钮靠右;换行时发送仍靠右。 */
1481
+ .cli-ui .composer .comp-foot>.comp-model{flex:1 1 auto;display:flex;justify-content:flex-end;margin-left:0;}
1478
1482
  }
1479
1483
  @media(pointer:coarse){
1480
1484
  .cli-ui .composer-popover .composer-option{min-height:52px;}
@@ -1871,11 +1875,12 @@
1871
1875
  .cli-ui [data-chat-layout]>.cli-refs,.cli-ui [data-chat-layout]>.cli-queue{width:calc(100% - 2 * var(--cli-chat-gutter) - var(--cli-chat-scrollbar,0px));max-width:var(--cli-chat-content-max);margin-inline:auto;margin-inline-start:max(var(--cli-chat-gutter),calc((100% - var(--cli-chat-scrollbar,0px) - var(--cli-chat-content-max)) / 2));flex-shrink:0;}
1872
1876
  @container chat-column (max-width:900px){.cli-ui [data-chat-layout]>*{--cli-chat-content-max:100%;}}
1873
1877
  @container chat-column (max-width:640px){.cli-ui [data-chat-layout]>*{--cli-chat-gutter:12px;}.cli-ui .session [data-chat-layout]>.composer{padding-inline-end:var(--cli-chat-gutter);}}
1878
+ /* PC:正文与输入区两侧留白 64px,窄聊天栏 48px(0.6.14 起在 0.6.13 的基础上再翻一倍);手机保持 16 / 12px。 */
1874
1879
  @media (min-width:761px){
1875
- .cli-ui [data-chat-layout]{--cli-chat-gutter:32px;}
1880
+ .cli-ui [data-chat-layout]{--cli-chat-gutter:64px;}
1876
1881
  .cli-ui .session [data-chat-layout] .composer{padding-inline:var(--cli-chat-gutter);padding-inline-end:calc(var(--cli-chat-gutter) + var(--cli-chat-scrollbar,0px));}
1877
1882
  .cli-ui [data-chat-layout] .composer>.composer-inner{width:100%;max-width:var(--cli-chat-content-max);margin-inline:auto;}
1878
- @container chat-column (max-width:640px){.cli-ui [data-chat-layout]>*{--cli-chat-gutter:24px;}.cli-ui .session [data-chat-layout] .composer{padding-inline-end:var(--cli-chat-gutter);}}
1883
+ @container chat-column (max-width:640px){.cli-ui [data-chat-layout]>*{--cli-chat-gutter:48px;}.cli-ui .session [data-chat-layout] .composer{padding-inline-end:var(--cli-chat-gutter);}}
1879
1884
  }
1880
1885
  .cli-ui .task-origin{display:flex;align-items:center;gap:5px;font-size:10px;color:var(--ink-3);padding-top:7px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
1881
1886
  .cli-ui .fork-sources{display:flex;flex-wrap:wrap;gap:6px;padding:12px 14px 0;}
package/src/styles.css CHANGED
@@ -53,7 +53,11 @@
53
53
  .cli-ui .sess-head .crumb{overflow-wrap:anywhere;}
54
54
  .cli-ui .cli-export{white-space:nowrap;}
55
55
  .cli-ui .comp-area textarea{min-width:0;}
56
- .cli-ui .composer .comp-foot{gap:4px;padding:4px 10px;background:transparent;border-top:0;flex-wrap:wrap;}
56
+ .cli-ui .composer .comp-foot{gap:4px;padding:5px 10px;background:transparent;border-top:0;flex-wrap:wrap;}
57
+ /* 工具栏收紧:加号、发送 / 停止保留 44px 点击区、32px 视觉圆形,执行类型 / 智能体保留 38px 按钮;
58
+ 负外边距让它们不再撑高这一行(行高按 32px 计),点击区照旧。 */
59
+ .cli-ui .composer .comp-foot .cli-attach,.cli-ui .composer .comp-foot .send{margin-block:-6px;}
60
+ .cli-ui .composer .comp-foot>.comp-control{margin-block:-3px;}
57
61
  .cli-ui .comp-foot>.comp-control{flex:0 0 auto;}
58
62
  .cli-ui .comp-foot .permission{padding-inline:6px;}
59
63
  .cli-ui .cli-attach{display:inline-flex;justify-content:center;align-items:center;gap:5px;min-width:44px;min-height:44px;padding:0 8px;border-radius:7px;color:var(--ink-3);font-size:12px;}
@@ -179,6 +183,11 @@
179
183
  .cli-ui .cli-fv-csv th{position:sticky;top:0;background:var(--surface-2);font-weight:600;}
180
184
  .cli-ui .cli-fv-note{padding:18px 16px;font-size:13px;color:var(--ink-3);line-height:1.7;}
181
185
  .cli-ui .cli-fv-note.err{color:var(--red);}
186
+ /* 相对路径打不开时按对话线索补全:查找中 / 几个候选(见 board/pathResolve.ts)。 */
187
+ .cli-ui .cli-fv-resolve{margin-top:10px;color:var(--ink-2);display:flex;flex-wrap:wrap;align-items:center;gap:6px;}
188
+ .cli-ui .cli-fv-candidate{max-width:100%;overflow:hidden;text-overflow:ellipsis;font-family:var(--mono);border:1px solid var(--line-2);}
189
+ .cli-ui .cli-fv-resolved{color:var(--ink-2);overflow-wrap:anywhere;}
190
+ .cli-ui .cli-fv-resolved code{font-family:var(--mono);font-size:11.5px;}
182
191
  .cli-ui .cli-zip-bar{display:flex;flex-wrap:wrap;align-items:center;gap:6px 8px;}
183
192
  .cli-ui .cli-zip-meter{flex:1 1 100%;height:3px;border-radius:2px;background:var(--line-2);overflow:hidden;}
184
193
  .cli-ui .cli-zip-meter>span{display:block;height:100%;background:var(--accent);transition:width .2s;}
@@ -457,20 +466,25 @@ cli-split{display:block;}
457
466
 
458
467
  /* The live queue sits just above the composer; expanded content stays in a viewport-bound card. */
459
468
  .cli-ui .cli-queue{flex:none;min-width:0;max-height:154px;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;margin:0 16px -12px;padding:4px 10px 16px;border:1px solid var(--line);border-radius:18px 18px 0 0;background:var(--raise);}
460
- .cli-ui .cli-queue-row{display:flex;align-items:center;gap:8px;min-width:0;min-height:44px;}
469
+ .cli-ui .cli-queue-row{display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0;min-height:44px;}
461
470
  .cli-ui .cli-queue-row+.cli-queue-row{border-top:1px solid var(--line-2);}
462
471
  .cli-ui .cli-queue-icon{display:grid;place-items:center;flex:none;width:20px;color:var(--ink-4);}
463
472
  .cli-ui .cli-queue-icon svg{width:16px;height:16px;}
464
473
  .cli-ui .cli-queue-summary{display:flex;align-items:center;gap:8px;flex:1;min-width:0;min-height:40px;padding:4px 0;text-align:left;color:var(--ink-2);}
465
474
  .cli-ui .cli-queue-thumb{flex:none;width:32px;height:32px;object-fit:cover;border:1px solid var(--line);border-radius:7px;}
466
475
  .cli-ui .cli-queue-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;line-height:1.5;}
467
- .cli-ui .cli-queue-remove,.cli-ui .cli-queue-more{display:grid;place-items:center;flex:none;width:30px;height:34px;border-radius:9px;color:var(--ink-3);}
468
- .cli-ui .cli-queue-remove svg,.cli-ui .cli-queue-more svg{width:17px;height:17px;}
476
+ .cli-ui .cli-queue-acts{display:flex;align-items:center;gap:2px;flex:none;}
477
+ .cli-ui .cli-queue-act{display:grid;place-items:center;flex:none;width:30px;height:34px;border-radius:9px;color:var(--ink-3);}
478
+ .cli-ui .cli-queue-act svg{width:17px;height:17px;}
479
+ .cli-ui .cli-queue-act:disabled{opacity:.38;cursor:not-allowed;}
480
+ .cli-ui .cli-queue-act[aria-busy="true"]{opacity:1;cursor:progress;}
481
+ .cli-ui .cli-queue-act .spinner{width:14px;height:14px;}
482
+ .cli-ui .cli-queue-error{flex-basis:100%;margin:-6px 0 6px 28px;color:var(--red);font-size:12px;line-height:1.5;overflow-wrap:anywhere;}
469
483
  @media(hover:hover) and (pointer:fine){
470
- .cli-ui .cli-queue-remove:hover,.cli-ui .cli-queue-more:hover{background:var(--surface-2);color:var(--ink);}
471
- .cli-ui .cli-queue-remove:hover{color:var(--red);}
484
+ .cli-ui .cli-queue-act:not(:disabled):hover{background:var(--surface-2);color:var(--ink);}
485
+ .cli-ui .cli-queue-remove:not(:disabled):hover{color:var(--red);}
472
486
  }
473
- .cli-ui .cli-queue-summary:focus-visible,.cli-ui .cli-queue-remove:focus-visible,.cli-ui .cli-queue-more:focus-visible{outline:2px solid var(--accent);outline-offset:1px;border-radius:8px;}
487
+ .cli-ui .cli-queue-summary:focus-visible,.cli-ui .cli-queue-act:focus-visible{outline:2px solid var(--accent);outline-offset:1px;border-radius:8px;}
474
488
  .cli-ui .cli-queue-popover{width:420px;}
475
489
  .cli-ui .cli-queue-detail{max-height:min(44vh,320px);overflow:auto;overscroll-behavior:contain;overflow-wrap:anywhere;}
476
490
  .cli-ui .cli-queue-detail .msg{margin:0;}
@@ -485,7 +499,7 @@ cli-split{display:block;}
485
499
  .cli-ui .cli-queue{margin:0 10px -12px;padding:4px 6px 16px;max-height:112px;}
486
500
  .cli-ui .cli-queue-row{gap:5px;}
487
501
  }
488
- @media(pointer:coarse){.cli-ui .cli-queue-remove,.cli-ui .cli-queue-more{width:44px;height:44px;}}
502
+ @media(pointer:coarse){.cli-ui .cli-queue-act{width:44px;height:44px;}}
489
503
  @media(max-height:500px){.cli-ui .cli-queue{max-height:70px;}}
490
504
 
491
505
  /* Keep controls reachable when a keyboard, split host or landscape view leaves little height. */
@@ -1,4 +1,4 @@
1
- import { memo, useContext, type ComponentProps, type MouseEvent } from "react";
1
+ import { memo, useContext, type ComponentProps, type MouseEvent, type ReactNode } from "react";
2
2
  import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
3
3
  import remarkGfm from "remark-gfm";
4
4
  import rehypeHighlight from "rehype-highlight";
@@ -24,11 +24,6 @@ function MdLink({ href, children, ...props }: ComponentProps<"a">) {
24
24
  return <a {...props} href={href} target="_blank" rel="noreferrer">{children}</a>;
25
25
  }
26
26
 
27
- function MdCode({children, ...props}: ComponentProps<"code">) {
28
- const path=inlineFilePath(children);
29
- return path ? <MdLink href={path}><code {...props}>{children}</code></MdLink> : <code {...props}>{children}</code>;
30
- }
31
-
32
27
  function MdImg({ src, alt, ...props }: ComponentProps<"img">) {
33
28
  const resolve = useContext(FileLinkContext);
34
29
  const local = typeof src === "string" ? localFilePath(src) : null;
@@ -41,20 +36,40 @@ function MdImg({ src, alt, ...props }: ComponentProps<"img">) {
41
36
  return <img {...props} alt={alt ?? ""} src={src} />;
42
37
  }
43
38
 
44
- // 缺省的地址处理会把 file: 等非网页协议清空;放行 file: 和 Windows 路径,交给上面按本地文件处理(与 Operator 一致)。
39
+ // 缺省的地址处理会把 file: 等非网页协议清空;放行 file: 和 Windows 路径,交给链接 / 图片组件按本地文件处理(与 Operator 一致)。
45
40
  const urlTransform = (url: string) => (/^file:/i.test(url) || /^[a-z]:[\\/]/i.test(url) ? url : defaultUrlTransform(url));
46
41
 
47
- export const Markdown = memo(function Markdown({ children, highlight = true }: { children: string; highlight?: boolean }) {
48
- return (
49
- <div className="md">
50
- <ReactMarkdown
51
- remarkPlugins={[remarkGfm]}
52
- rehypePlugins={highlight ? [[rehypeHighlight, { detect: false, ignoreMissing: true }]] : []}
53
- components={{ a: MdLink, img: MdImg, code: MdCode }}
54
- urlTransform={urlTransform}
55
- >
56
- {children}
57
- </ReactMarkdown>
58
- </div>
59
- );
60
- });
42
+ /** 本地文件链接 / 图片怎么打开:各适配自己给(中枢:看板或宿主给的地址;节点:任务的文件接口)。其余渲染规则共用。 */
43
+ export interface MarkdownLinks {
44
+ Link: (props: ComponentProps<"a">) => ReactNode;
45
+ Image: (props: ComponentProps<"img">) => ReactNode;
46
+ }
47
+
48
+ /**
49
+ * 智能体 markdown 输出的渲染器(中枢与节点适配共用):标题、列表、表格、带语言的代码块(高亮)、行内代码、链接。
50
+ * 只高亮写明语言的代码块(自动识别在流式输出时很耗),并 memo,文字没变的消息重渲染时跳过整个解析。
51
+ * 长得像文件路径的行内代码(report.md、src/a.ts:12)按本地文件链接处理。
52
+ */
53
+ export function createMarkdown({ Link, Image }: MarkdownLinks) {
54
+ function Code({ children, ...props }: ComponentProps<"code">) {
55
+ const path = inlineFilePath(children);
56
+ return path ? <Link href={path}><code {...props}>{children}</code></Link> : <code {...props}>{children}</code>;
57
+ }
58
+ const components = { a: Link, img: Image, code: Code };
59
+ return memo(function Markdown({ children, highlight = true }: { children: string; highlight?: boolean }) {
60
+ return (
61
+ <div className="md">
62
+ <ReactMarkdown
63
+ remarkPlugins={[remarkGfm]}
64
+ rehypePlugins={highlight ? [[rehypeHighlight, { detect: false, ignoreMissing: true }]] : []}
65
+ components={components}
66
+ urlTransform={urlTransform}
67
+ >
68
+ {children}
69
+ </ReactMarkdown>
70
+ </div>
71
+ );
72
+ });
73
+ }
74
+
75
+ export const Markdown = createMarkdown({ Link: MdLink, Image: MdImg });
@@ -83,7 +83,7 @@ export function Popover({ children, onClose, className, ariaLabel = "选项", pl
83
83
  <div className="cli-ui" data-theme={markerRef.current?.closest("[data-theme]")?.getAttribute("data-theme") ?? "dark"}><div
84
84
  ref={menuRef}
85
85
  className={`popover${className ? ` ${className}` : ""}`} role="dialog" aria-label={ariaLabel}
86
- style={{ position: "fixed", top: pos?.top ?? -9999, left: pos?.left ?? -9999, right: "auto", visibility: pos ? "visible" : "hidden" }}
86
+ style={{ position: "fixed", top: pos?.top ?? -9999, left: pos?.left ?? -9999, right: "auto", visibility: pos ? "visible" : "hidden", zIndex: markerRef.current?.closest(".workspace-drawer-layer") ? 80 : undefined }}
87
87
  onClick={(e) => e.stopPropagation()}
88
88
  >
89
89
  {children}
@@ -1,41 +1,61 @@
1
- import { useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react";
1
+ import { useEffect, useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react";
2
2
  import type { Msg } from "../core/types";
3
3
  import { splitMessage } from "../core/blocks";
4
4
  import { withoutBoardContext } from "../board/context";
5
5
  import { Icon } from "./icons";
6
- import { splitAttachments, type MsgAttachment } from "./format";
6
+ import { splitAttachments, type AttachmentScope, type MsgAttachment } from "./format";
7
7
  import { MessageView, type MessageViewOptions } from "./Transcript";
8
8
  import { Popover } from "./Popover";
9
9
 
10
10
  const detailView: MessageViewOptions = { timestamps: false, initialBadge: false, userLabel: "你", agentName: "智能体", viewingBlock: false };
11
+ type QueueAction = (message: Msg) => void | Promise<unknown>;
11
12
  export interface QueuedMessagesProps {
12
13
  scopeKey: string;
13
14
  messages: readonly Msg[];
14
- onCancel?: (message: Msg) => void;
15
+ /** 删除:从队列中撤回。不传 = 只读(三个操作都不显示)。 */
16
+ onCancel?: QueueAction;
17
+ /**
18
+ * 立即发送:打断正在执行的回复,排队消息随即按顺序发出。只在有回复正在执行时传;
19
+ * 只对排在最前面的一条可用(后面的要等前面的先发)。
20
+ */
21
+ onSendNow?: QueueAction;
22
+ /** 没有 onSendNow 时按钮上的说明(缺省:当前没有正在执行的回复)。 */
23
+ sendNowUnavailable?: string;
24
+ /** 编辑:先撤回这一条,撤回成功后把内容放回输入框(与输入框里已有的草稿合并)。 */
25
+ onEdit?: QueueAction;
15
26
  attachmentUrl?: (attachment: MsgAttachment) => string | null;
27
+ attachmentScope?: AttachmentScope;
16
28
  renderMessage?: (message: Msg) => ReactNode;
17
29
  }
18
30
 
19
31
  /** The original live queue remains authoritative; this view never removes or resends messages locally. */
20
- export function QueuedMessages({ scopeKey, messages, onCancel, attachmentUrl, renderMessage }: QueuedMessagesProps) {
32
+ export function QueuedMessages({ scopeKey, messages, onCancel, onSendNow, sendNowUnavailable, onEdit, attachmentUrl, attachmentScope, renderMessage }: QueuedMessagesProps) {
21
33
  if (!messages.length) return null;
22
34
  return <div className="cli-queue" role="list" aria-label={`排队消息(${messages.length})`}>
23
- {messages.map((message, index) => <QueuedMessage key={`${scopeKey}:${message.id}`} message={message} index={index} onCancel={onCancel} attachmentUrl={attachmentUrl} renderMessage={renderMessage} />)}
35
+ {messages.map((message, index) => <QueuedMessage key={`${scopeKey}:${message.id}`} message={message} index={index} onCancel={onCancel} onSendNow={onSendNow} sendNowUnavailable={sendNowUnavailable} onEdit={onEdit} attachmentUrl={attachmentUrl} attachmentScope={attachmentScope} renderMessage={renderMessage} />)}
24
36
  </div>;
25
37
  }
26
38
 
27
- function QueuedMessage({ message, index, onCancel, attachmentUrl, renderMessage }: Omit<QueuedMessagesProps, "messages" | "scopeKey"> & { message: Msg; index: number }) {
39
+ type Busy = "send" | "edit" | "cancel";
40
+ const BUSY_TEXT: Record<Busy, string> = { send: "正在打断当前回复…", edit: "正在撤回到输入框…", cancel: "正在删除…" };
41
+
42
+ function QueuedMessage({ message, index, onCancel, onSendNow, sendNowUnavailable, onEdit, attachmentUrl, attachmentScope, renderMessage }: Omit<QueuedMessagesProps, "messages" | "scopeKey"> & { message: Msg; index: number }) {
28
43
  const [open, setOpen] = useState(false);
29
44
  const [copying, setCopying] = useState(false);
30
45
  const [feedback, setFeedback] = useState<{ error: boolean; text: string } | null>(null);
46
+ // 一次只做一个操作:在途时三个按钮都不可点,免得重复撤回 / 重复打断。
47
+ const [busy, setBusy] = useState<Busy | null>(null);
48
+ const [actionError, setActionError] = useState<string | null>(null);
49
+ const alive = useRef(true);
50
+ useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
31
51
  const returnFocusRef = useRef<HTMLButtonElement | null>(null);
32
52
  const content = useMemo(() => withoutBoardContext(message.content), [message.content]);
33
53
  const preview = useMemo(() => {
34
- const { text, attachments } = splitAttachments(content);
54
+ const { text, attachments } = splitAttachments(content, attachmentScope);
35
55
  const body = splitMessage(text).map(part => part.kind === "text" ? part.text : part.block.name).join(" · ").replace(/\s+/g, " ").trim().slice(0, 160);
36
56
  const summary = [body, ...attachments.map(attachment => attachment.name)].filter(Boolean).join(" · ");
37
57
  return { summary: summary || "查看排队消息", attachments };
38
- }, [content]);
58
+ }, [content, attachmentScope]);
39
59
  const thumbnail = preview.attachments.filter(attachment => attachment.kind === "image").map(attachment => ({ attachment, url: attachmentUrl?.(attachment) })).find(item => item.url);
40
60
  const toggle = (event: MouseEvent<HTMLButtonElement>) => { returnFocusRef.current = event.currentTarget; setOpen(value => !value); setFeedback(null); };
41
61
  const copy = async () => {
@@ -49,17 +69,40 @@ function QueuedMessage({ message, index, onCancel, attachmentUrl, renderMessage
49
69
  setFeedback({ error: true, text: error instanceof Error ? error.message : "复制失败,请重试" });
50
70
  } finally { setCopying(false); }
51
71
  };
52
- return <div className="cli-queue-row" role="listitem" data-queued-id={message.id}>
72
+ const run = async (kind: Busy, action: QueueAction | undefined) => {
73
+ if (!action || busy) return;
74
+ setBusy(kind); setActionError(null); setOpen(false);
75
+ try {
76
+ await action(message);
77
+ } catch (error) {
78
+ // 宿主自己报过错的会正常返回;抛出来的在这一行里说明。
79
+ if (alive.current) setActionError(error instanceof Error ? error.message : String(error));
80
+ } finally {
81
+ if (alive.current) setBusy(null);
82
+ }
83
+ };
84
+ const n = index + 1;
85
+ const actions = !!onCancel;
86
+ const sendBlocked = !onSendNow ? sendNowUnavailable ?? "当前没有正在执行的回复,排队消息会自动发送" : index > 0 ? `前面还有 ${index} 条排队消息,会先按顺序发送` : null;
87
+ const sendTitle = busy === "send" ? BUSY_TEXT.send : sendBlocked ?? "立即发送:打断当前回复,马上发送这条消息";
88
+ return <div className="cli-queue-row" role="listitem" data-queued-id={message.id} aria-busy={busy ? true : undefined}>
53
89
  <span className="cli-queue-icon" aria-hidden="true">{Icon.list()}</span>
54
- <button className="cli-queue-summary" aria-label={`查看第 ${index + 1} 条排队消息`} aria-expanded={open} aria-haspopup="dialog" onClick={toggle} title={preview.summary}>
90
+ <button className="cli-queue-summary" aria-label={`查看第 ${n} 条排队消息`} aria-expanded={open} aria-haspopup="dialog" onClick={toggle} title={preview.summary}>
55
91
  {thumbnail?.url && <img className="cli-queue-thumb" src={thumbnail.url} alt={thumbnail.attachment.name} loading="lazy" onError={event => { event.currentTarget.hidden = true; }} />}
56
- <span className="cli-queue-text">{preview.summary}</span>
92
+ <span className="cli-queue-text">{busy ? BUSY_TEXT[busy] : preview.summary}</span>
57
93
  </button>
58
- {onCancel && <button className="cli-queue-remove" title="从队列中移除" aria-label={`移除第 ${index + 1} 条排队消息`} onClick={() => onCancel(message)}>{Icon.x()}</button>}
59
- <button className="cli-queue-more" title="更多排队消息操作" aria-label={`第 ${index + 1} 条排队消息的更多操作`} aria-expanded={open} aria-haspopup="dialog" onClick={toggle}>{Icon.dots()}</button>
94
+ {actions && <div className="cli-queue-acts">
95
+ <button className="cli-queue-act cli-queue-send" title={sendTitle} aria-label={`立即发送第 ${n} 条排队消息`}
96
+ disabled={!!busy || !!sendBlocked} aria-busy={busy === "send" || undefined} onClick={() => void run("send", onSendNow)}>{busy === "send" ? <span className="spinner" /> : Icon.enter()}</button>
97
+ {onEdit && <button className="cli-queue-act cli-queue-edit" title={busy === "edit" ? BUSY_TEXT.edit : "编辑:撤回这条消息,放回输入框修改"} aria-label={`编辑第 ${n} 条排队消息`}
98
+ disabled={!!busy} aria-busy={busy === "edit" || undefined} onClick={() => void run("edit", onEdit)}>{busy === "edit" ? <span className="spinner" /> : Icon.edit()}</button>}
99
+ <button className="cli-queue-act cli-queue-remove" title={busy === "cancel" ? BUSY_TEXT.cancel : "删除:从队列中移除"} aria-label={`删除第 ${n} 条排队消息`}
100
+ disabled={!!busy} aria-busy={busy === "cancel" || undefined} onClick={() => void run("cancel", onCancel)}>{busy === "cancel" ? <span className="spinner" /> : Icon.x()}</button>
101
+ </div>}
102
+ {actionError && <div className="cli-queue-error" role="alert">{actionError}</div>}
60
103
  {open && <Popover className="composer-popover cli-queue-popover" ariaLabel="排队消息内容" placement="top" align="start" returnFocusRef={returnFocusRef} onClose={() => setOpen(false)}>
61
- <div className="pop-sec">第 {index + 1} 条排队消息</div>
62
- <div className="cli-queue-detail" onClick={event => { if (event.defaultPrevented && event.target instanceof Element && event.target.closest("a")) setOpen(false); }}>{renderMessage ? renderMessage({ ...message, role: "user", content }) : <MessageView m={{ ...message, role: "user", content }} initial={false} hideWho handlers={{ attachmentUrl }} view={detailView} />}</div>
104
+ <div className="pop-sec">第 {n} 条排队消息</div>
105
+ <div className="cli-queue-detail" onClick={event => { if (event.defaultPrevented && event.target instanceof Element && event.target.closest("a")) setOpen(false); }}>{renderMessage ? renderMessage({ ...message, role: "user", content }) : <MessageView m={{ ...message, role: "user", content }} initial={false} hideWho handlers={{ attachmentUrl, attachmentScope }} view={detailView} />}</div>
63
106
  {message.note && <div className="cli-queue-note">{message.note}</div>}
64
107
  <div className="cli-queue-actions"><button className="pop-item" disabled={copying} onClick={() => void copy()}>{Icon.copy()} {copying ? "复制中…" : "复制消息"}</button></div>
65
108
  {feedback && <div className="cli-queue-feedback" role={feedback.error ? "alert" : "status"}>{feedback.text}</div>}
@@ -49,6 +49,9 @@ export function SubagentChatScope({ scopeKey, messages, load, renderMessage, chi
49
49
  </SubagentContext.Provider>;
50
50
  }
51
51
 
52
+ /** 子代理记录按动静补读时,相邻两次至少隔这么久。 */
53
+ const SUBAGENT_REFRESH_GAP_MS = 2_000;
54
+
52
55
  function SubagentPanel({ selection, messages, load, renderMessage, onClose, modal }: {
53
56
  selection: Selection; messages: Msg[]; load?: LoadSubagent;
54
57
  renderMessage: (message: Msg, agentName: string) => ReactNode; onClose: () => void; modal: boolean;
@@ -66,14 +69,20 @@ function SubagentPanel({ selection, messages, load, renderMessage, onClose, moda
66
69
  const [shownCount, setShownCount] = useState(120);
67
70
  const { id } = selection.info;
68
71
 
72
+ // 不定时轮询:打开时读一次;之后父对话的实时流里这个子代理有了新动静(状态、更新时间、新的子消息),
73
+ // 或页面回到前台时再读——仅在服务端说记录还会变(refreshable)且子代理还在跑时;相邻两次至少隔 2 秒,挤在一起的合并。
74
+ const live = useRef(false);
75
+ const refreshSoon = useRef<(() => void) | null>(null);
69
76
  useEffect(() => {
70
77
  let disposed = false;
71
78
  let timer: ReturnType<typeof setTimeout> | undefined;
79
+ let inflight = false, again = false, last = 0;
72
80
  if (!load) { setLoading(false); return; }
73
81
  setLoading(true); setError(null);
74
- const refresh = async (initial = false) => {
82
+ const refresh = async () => {
75
83
  if (disposed) return;
76
- if (!initial && document.visibilityState === "hidden") { timer = setTimeout(() => void refresh(), 5000); return; }
84
+ if (inflight) { again = true; return; }
85
+ inflight = true; last = Date.now();
77
86
  try {
78
87
  const value = await load(id, selection.generation);
79
88
  if (value.subagent?.id !== id || !Array.isArray(value.messages)) throw new Error("子代理记录与当前选择不匹配");
@@ -86,14 +95,41 @@ function SubagentPanel({ selection, messages, load, renderMessage, onClose, moda
86
95
  older: overlap ? previous?.older ?? value.older : value.older,
87
96
  before: overlap ? previous?.before : value.messages[0]?.id };
88
97
  }); setError(null);
89
- if (value.refreshable && ["running", "unknown"].includes(value.subagent.status)) timer = setTimeout(() => void refresh(), 5000);
98
+ live.current = !!value.refreshable && ["running", "unknown"].includes(value.subagent.status);
90
99
  } catch (cause) {
91
100
  if (!disposed) setError(cause instanceof Error ? cause.message : String(cause));
92
- } finally { if (!disposed) setLoading(false); }
101
+ } finally {
102
+ inflight = false;
103
+ if (!disposed) setLoading(false);
104
+ if (again && !disposed) { again = false; schedule(); }
105
+ }
106
+ };
107
+ const schedule = () => {
108
+ if (disposed || timer || !live.current) return;
109
+ timer = setTimeout(() => { timer = undefined; void refresh(); }, Math.max(0, SUBAGENT_REFRESH_GAP_MS - (Date.now() - last)));
93
110
  };
94
- void refresh(true);
95
- return () => { disposed = true; if (timer) clearTimeout(timer); };
111
+ refreshSoon.current = () => { if (document.visibilityState !== "hidden") schedule(); };
112
+ const onVisibility = () => { if (document.visibilityState === "visible") schedule(); };
113
+ document.addEventListener("visibilitychange", onVisibility);
114
+ void refresh();
115
+ return () => { disposed = true; if (timer) clearTimeout(timer); refreshSoon.current = null; document.removeEventListener("visibilitychange", onVisibility); };
96
116
  }, [load, id, selection.generation, attempt]);
117
+ // 父对话里这个子代理的动静:只看实时流(不看自己读回来的快照,免得读一次又触发下一次)。
118
+ const parentActivity = useMemo(() => {
119
+ let mark = "";
120
+ for (const message of messages) {
121
+ if (message.generation !== selection.generation) continue;
122
+ const candidate = subagentFields(message).subagent;
123
+ if (candidate?.id === id) mark = `${candidate.status}:${candidate.updatedAt ?? 0}`;
124
+ }
125
+ return `${mark}|${childMessages(messages, id, selection.generation).length}`;
126
+ }, [messages, id, selection.generation]);
127
+ const seenActivity = useRef(parentActivity);
128
+ useEffect(() => {
129
+ if (seenActivity.current === parentActivity) return;
130
+ seenActivity.current = parentActivity;
131
+ refreshSoon.current?.();
132
+ }, [parentActivity]);
97
133
 
98
134
  const info = useMemo(() => {
99
135
  let latest = snapshot?.subagent ?? selection.info;