@autopilot-agent/cli 0.2.0 → 0.3.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.
Files changed (73) hide show
  1. package/README.md +10 -5
  2. package/dist/activity-animation.d.ts +4 -0
  3. package/dist/activity-animation.js +11 -17
  4. package/dist/composition-root.d.ts +31 -1
  5. package/dist/composition-root.js +112 -3
  6. package/dist/context-report.d.ts +8 -3
  7. package/dist/context-report.js +14 -2
  8. package/dist/controller.d.ts +34 -4
  9. package/dist/controller.js +434 -90
  10. package/dist/error-diagnostics.d.ts +2 -0
  11. package/dist/error-diagnostics.js +3 -1
  12. package/dist/event-projector.d.ts +16 -2
  13. package/dist/event-projector.js +74 -5
  14. package/dist/index.d.ts +1 -1
  15. package/dist/main.js +142 -7
  16. package/dist/parser.js +498 -0
  17. package/dist/renderer.js +3 -1
  18. package/dist/session-summary.d.ts +7 -0
  19. package/dist/session-summary.js +25 -0
  20. package/dist/session-title.d.ts +5 -0
  21. package/dist/session-title.js +10 -0
  22. package/dist/thread-commands.d.ts +37 -0
  23. package/dist/thread-commands.js +233 -0
  24. package/dist/thread-host.d.ts +31 -0
  25. package/dist/thread-host.js +76 -0
  26. package/dist/timeline-lines.js +36 -28
  27. package/dist/tui/app.d.ts +22 -0
  28. package/dist/tui/app.js +112 -40
  29. package/dist/tui/approval.d.ts +4 -0
  30. package/dist/tui/approval.js +13 -4
  31. package/dist/tui/constants.d.ts +1 -1
  32. package/dist/tui/constants.js +1 -1
  33. package/dist/tui/format.d.ts +1 -1
  34. package/dist/tui/format.js +19 -9
  35. package/dist/tui/hooks/use-prompt-input.d.ts +52 -0
  36. package/dist/tui/hooks/use-prompt-input.js +148 -20
  37. package/dist/tui/hooks/use-status-view.d.ts +2 -2
  38. package/dist/tui/hooks/use-status-view.js +38 -11
  39. package/dist/tui/inline-output.d.ts +17 -0
  40. package/dist/tui/inline-output.js +31 -0
  41. package/dist/tui/input/clipboard-image.d.ts +17 -0
  42. package/dist/tui/input/clipboard-image.js +117 -0
  43. package/dist/tui/input-area.d.ts +8 -0
  44. package/dist/tui/input-area.js +18 -3
  45. package/dist/tui/lifecycle.js +2 -5
  46. package/dist/tui/markdown/diff.d.ts +1 -1
  47. package/dist/tui/markdown/diff.js +28 -1
  48. package/dist/tui/performance-diagnostics.js +2 -0
  49. package/dist/tui/prompt-input.d.ts +1 -0
  50. package/dist/tui/prompt-input.js +5 -3
  51. package/dist/tui/render-mode.d.ts +4 -4
  52. package/dist/tui/render-mode.js +5 -11
  53. package/dist/tui/run.js +37 -49
  54. package/dist/tui/session-manager.d.ts +115 -0
  55. package/dist/tui/session-manager.js +383 -0
  56. package/dist/tui/session-workspace.d.ts +9 -0
  57. package/dist/tui/session-workspace.js +383 -0
  58. package/dist/tui/status-line.d.ts +3 -0
  59. package/dist/tui/status-line.js +12 -6
  60. package/dist/tui/store.js +27 -5
  61. package/dist/tui/timeline/live.js +2 -3
  62. package/dist/tui/timeline/progress.js +3 -2
  63. package/dist/tui/timeline/static-timeline.js +1 -2
  64. package/dist/tui/timeline/turn.js +3 -2
  65. package/dist/tui/transcript.d.ts +1 -1
  66. package/dist/tui/transcript.js +19 -1
  67. package/dist/tui/trust-dialog.d.ts +3 -0
  68. package/dist/tui/trust-dialog.js +23 -2
  69. package/dist/tui/types.d.ts +8 -0
  70. package/dist/tui/types.js +4 -1
  71. package/dist/tui/viewport/sources.js +6 -13
  72. package/dist/types.d.ts +152 -2
  73. package/package.json +4 -4
@@ -0,0 +1,383 @@
1
+ /** 单窗口轻量会话目录:普通历史只保留标题/UUID,显式打开后才创建完整视图与分页历史。 */
2
+ import { getCliSessionDisplayTitle } from "../session-title.js";
3
+ import { createInitialCliProjection } from "../event-projector.js";
4
+ import { createCliTuiStore } from "./store.js";
5
+ /** 主子视图共用已保存交互文案,底层暂停状态保持原样。 */
6
+ export function getCliInteractionLabel(view) {
7
+ if (view?.interaction?.state !== "decided")
8
+ return undefined;
9
+ const decision = view.interaction.decision === "approved" ? "已批准" : "决定已保存";
10
+ return `${decision},${view.interaction.continuation?.state === "failed" ? "恢复失败" : "等待恢复"}`;
11
+ }
12
+ /** 创建Project级轻量目录,所有分页/异步结果固定写回原目标。 */
13
+ export function createCliSessionManager(options) {
14
+ const entries = new Map();
15
+ const directory = new Map();
16
+ const listeners = new Set();
17
+ let selectedId = options.initialSession.id;
18
+ let directoryCursor;
19
+ let directoryLoaded = false;
20
+ let directoryLoading = false;
21
+ let directoryRequest;
22
+ let refreshing = false;
23
+ let refreshAbort;
24
+ let selectionGeneration = 0;
25
+ let stopped = false;
26
+ let timer;
27
+ /** 发布实际目录/状态变化,后台事件不抢选中目标。 */
28
+ function notify() { if (!stopped)
29
+ for (const listener of listeners)
30
+ listener(); }
31
+ /** 将事件固定路由到该entry,未打开的关联目标只保存轻量安全状态。 */
32
+ function bind(entry) {
33
+ entry.controller.setEventListener(function receive(event, projection) {
34
+ entry.store.acceptEvent(event, projection);
35
+ if (event.type === "approval_required" || event.type === "todo_updated" || event.type === "status") {
36
+ if (selectedId !== entry.sessionId)
37
+ entry.unread = true;
38
+ notify();
39
+ }
40
+ });
41
+ entry.controller.setQueuedInputListener?.(function queued(input) { entry.store.markQueuedInputStarted(input); });
42
+ }
43
+ /** 仅为已打开目标或真实关联摘要建立宿主对象,不为普通目录项创建对象。 */
44
+ function attach(id, title, controller, opened) {
45
+ const entry = { sessionId: id, title: getCliSessionDisplayTitle(title, id), attachments: [], controller, store: createCliTuiStore(), unread: false, hydrated: false, opened, historyMore: true, historyLoading: false, viewState: { draftRef: {}, initialStarted: false, lastSubmittedPrompt: { current: undefined } } };
46
+ let interaction = "";
47
+ entry.store.subscribe(function interactionChanged() {
48
+ const state = entry.store.getSnapshot();
49
+ const current = JSON.stringify([state.liveTurnId, state.status, state.pendingApproval?.approvalId]);
50
+ if (current !== interaction) {
51
+ interaction = current;
52
+ notify();
53
+ }
54
+ });
55
+ entries.set(id, entry);
56
+ bind(entry);
57
+ return entry;
58
+ }
59
+ const initial = attach(options.initialSession.id, options.initialSession.title, options.initialController, true);
60
+ initial.pendingPrompts = options.initialSession.presentation?.messages.filter(function user(message) { return message.role === "user"; }) ?? [];
61
+ directory.set(initial.sessionId, { sessionId: initial.sessionId, title: initial.title });
62
+ /** 按需获取一页标题,不调用Session完整list/get、transcript或checkpoint。 */
63
+ function loadDirectory() {
64
+ if (directoryRequest)
65
+ return directoryRequest;
66
+ if (stopped || directoryLoaded && !directoryCursor)
67
+ return Promise.resolve();
68
+ if (!options.readDirectoryPage)
69
+ return Promise.reject(new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE"));
70
+ directoryLoading = true;
71
+ notify();
72
+ directoryRequest = options.readDirectoryPage({ cursor: directoryCursor, limit: 20 }).then(function loaded(page) {
73
+ if (stopped)
74
+ return;
75
+ for (const item of page.items)
76
+ directory.set(item.id, { sessionId: item.id, title: getCliSessionDisplayTitle(item.title, item.id) });
77
+ directoryCursor = page.nextCursor;
78
+ directoryLoaded = true;
79
+ }).finally(function release() { directoryRequest = undefined; directoryLoading = false; notify(); });
80
+ return directoryRequest;
81
+ }
82
+ /** 元数据已确认的新/未知/终态立即失效旧交互,不等待正文页追赶。 */
83
+ function reconcileObservedIdentity(entry, relation) {
84
+ const current = entry.controller.getProjection();
85
+ const active = relation.status === "running" || relation.status === "waiting_approval" || relation.status === "waiting_user_input";
86
+ const changedIdentity = !entry.summaryKnown || entry.summaryTurnId !== relation.activeTurnId;
87
+ if (changedIdentity) {
88
+ entry.summaryReady = false;
89
+ entry.summaryApproval = undefined;
90
+ }
91
+ entry.summaryTurnId = relation.activeTurnId;
92
+ entry.summaryStatus = relation.status;
93
+ entry.summaryKnown = true;
94
+ const invalid = changedIdentity || current.turnId !== relation.activeTurnId || !relation.activeTurnId || !active || current.pendingApproval && relation.status !== "waiting_approval";
95
+ const status = relation.status ?? "idle";
96
+ if (invalid && (changedIdentity || current.pendingApproval || current.turnId !== relation.activeTurnId || current.status !== status)) {
97
+ entry.controller.invalidateObservedTurn?.({ turnId: relation.activeTurnId, status });
98
+ const cleared = entry.controller.invalidateObservedTurn ? entry.controller.getProjection() : { ...createInitialCliProjection(), turnId: relation.activeTurnId, status };
99
+ entry.store.syncProjection(cleared);
100
+ notify();
101
+ }
102
+ }
103
+ /** 当前交互只采用已追到尾的安全摘要;未完成追赶时旧卡不进入输入许可。 */
104
+ function syncCurrentInteraction(entry) {
105
+ if (!entry.summaryKnown || !entry.summaryTurnId || entry.controller.isExecuting?.())
106
+ return;
107
+ let approval = entry.summaryReady && entry.summaryStatus === "waiting_approval" ? entry.summaryApproval : undefined;
108
+ if (approval?.event.type === "approval_required") {
109
+ const request = approval.event.result.approval;
110
+ if (Number.isFinite(Date.parse(request.expiresAt)) && Date.parse(request.expiresAt) <= Date.now()) {
111
+ if (entry.summaryRejectedId !== request.approvalId)
112
+ entry.store.addNotice("审批已过期,请在目标会话通过原继续入口刷新");
113
+ entry.summaryRejectedId = request.approvalId;
114
+ approval = undefined;
115
+ }
116
+ }
117
+ entry.controller.syncObservedInteraction?.({ turnId: entry.summaryTurnId, status: entry.summaryStatus ?? "idle", approval, requestId: entry.executionView?.interaction?.requestId });
118
+ entry.store.syncProjection(entry.controller.getProjection());
119
+ }
120
+ /** 宿主统一安全投影直接提供当前请求;正文历史未追到尾也不阻挡审批。 */
121
+ function applyExecutionView(entry, view) {
122
+ const previous = entry.executionView;
123
+ if (previous?.turnId === view.turnId && view.lastSeq < previous.lastSeq)
124
+ return;
125
+ entry.executionView = view;
126
+ reconcileObservedIdentity(entry, { activeTurnId: view.turnId, status: view.status });
127
+ entry.summaryApproval = view.interaction?.state === "pending" ? view.interaction.approval : undefined;
128
+ entry.summaryReady = true;
129
+ const diagnostic = view.interaction?.continuation?.failureDiagnostic;
130
+ const notice = (view.continuation ?? view.interaction?.continuation)?.failureCode === "BOUNDARY_CHANGED" ? "原决定或答案已保存,执行结果未确认,请先核对原任务状态" : view.interaction?.state === "decided" ? `${view.waiting === "user_input" ? "答案" : view.interaction.decision === "approved" ? "批准决定" : "审批决定"}已保存,${view.interaction.continuation?.state === "failed" ? `恢复失败${diagnostic ? `(${diagnostic.category}/${diagnostic.code},${diagnostic.stage},已观察启动=${diagnostic.started})` : ""},请在目标会话通过 /resume 重试原请求` : "等待兼容宿主继续原任务"}` : view.interaction?.state === "expired" ? "审批已过期,请在目标会话继续刷新" : view.interaction?.state === "unconfirmed" ? "交互状态待确认,请稍后刷新" : view.warning === "summary_lag" ? "执行状态尚未同步,当前审批仍待处理" : view.execution === "lost" ? "执行已失联,结果未确认" : view.execution === "unconfirmed" ? "执行状态待确认,结果未确认" : undefined;
131
+ if (notice && notice !== entry.interactionNotice)
132
+ entry.store.addNotice(notice);
133
+ if (view.waiting === "user_input" && view.interaction?.state === "pending" && view.interaction.question) {
134
+ const questionNotice = JSON.stringify([view.turnId, view.interaction.question.requestId]);
135
+ if (entry.interactionNotice !== questionNotice) {
136
+ const first = view.interaction.question.questions[0];
137
+ entry.store.addNotice([`等待回答 ${first.header}`, first.question, ...first.options.map(function option(item, n) { return `${n + 1}. ${item.label} — ${item.description}`; }), "在目标会话输入选项编号或自定义答案;/resume重新显示问题"].join("\n"));
138
+ }
139
+ entry.interactionNotice = questionNotice;
140
+ }
141
+ else
142
+ entry.interactionNotice = notice;
143
+ syncCurrentInteraction(entry);
144
+ }
145
+ /** 无论正文是否打开均独立分页追踪交互,最多100事件,不回放正文、不启动目标。 */
146
+ async function refreshInteraction(entry) {
147
+ if (!options.readEventPage || !entry.summaryTurnId || entry.controller.isExecuting?.())
148
+ return;
149
+ const turnId = entry.summaryTurnId;
150
+ const status = entry.summaryStatus;
151
+ const controller = entry.controller;
152
+ if (status !== "running" && status !== "waiting_approval" && status !== "waiting_user_input") {
153
+ entry.summaryApproval = undefined;
154
+ entry.summaryReady = true;
155
+ syncCurrentInteraction(entry);
156
+ return;
157
+ }
158
+ const page = await options.readEventPage(entry.sessionId, { cursor: entry.summaryCursor, limit: 100 });
159
+ if (stopped || entry.summaryTurnId !== turnId || entry.summaryStatus !== status || entry.controller !== controller || controller.isExecuting?.())
160
+ return;
161
+ if (!entry.opened)
162
+ entry.controller.observe?.(page.items.filter(function light(envelope) { return envelope.turnId === turnId && ["turn_started", "approval_required", "todo_updated", "turn_paused", "turn_completed", "turn_failed", "turn_interrupted", "question_required"].includes(envelope.event.type); }));
163
+ for (const envelope of page.items) {
164
+ if (envelope.turnId !== turnId)
165
+ continue;
166
+ if (envelope.event.type === "turn_started" || envelope.event.type === "turn_completed" || envelope.event.type === "turn_failed" || envelope.event.type === "turn_interrupted")
167
+ entry.summaryApproval = undefined;
168
+ if (envelope.event.type === "approval_required")
169
+ entry.summaryApproval = envelope;
170
+ }
171
+ entry.summaryCursor = page.cursor ?? page.nextCursor ?? entry.summaryCursor;
172
+ entry.summaryReady = !page.nextCursor;
173
+ syncCurrentInteraction(entry);
174
+ }
175
+ /** 对精确目标读取最多100事件;未翻完旧历史时不会自动全量追赶。 */
176
+ async function loadHistory(sessionId = selectedId) {
177
+ const entry = entries.get(sessionId);
178
+ if (!entry || !entry.opened || entry.historyLoading || stopped)
179
+ return;
180
+ if (!options.readEventPage)
181
+ throw new Error("CLI_SESSION_HISTORY_UNAVAILABLE");
182
+ entry.historyLoading = true;
183
+ try {
184
+ const page = await options.readEventPage(sessionId, { cursor: entry.historyCursor, limit: 100 });
185
+ if (stopped || selectedId !== sessionId || entry.controller.isExecuting?.())
186
+ return;
187
+ const through = page.nextCursor ? Date.parse(page.items[page.items.length - 1]?.timestamp ?? "") : Infinity;
188
+ const prompts = (entry.pendingPrompts ?? []).filter(function visible(message) { return message.createdAt <= through; });
189
+ entry.pendingPrompts = (entry.pendingPrompts ?? []).filter(function later(message) { return message.createdAt > through; });
190
+ const history = [...prompts.map(function prompt(message) { return { at: message.createdAt, prompt: message.content, event: undefined }; }), ...page.items.map(function event(envelope) { return { at: Date.parse(envelope.timestamp), prompt: undefined, event: envelope }; })].sort(function chronological(a, b) { return a.at - b.at; });
191
+ for (const item of history) {
192
+ if (item.event)
193
+ entry.controller.observe?.([item.event]);
194
+ else if (item.prompt)
195
+ entry.store.recordPrompt(item.prompt);
196
+ }
197
+ if (entry.summaryKnown) {
198
+ reconcileObservedIdentity(entry, { activeTurnId: entry.summaryTurnId, status: entry.summaryStatus });
199
+ syncCurrentInteraction(entry);
200
+ }
201
+ entry.historyCursor = page.cursor ?? page.nextCursor ?? entry.historyCursor;
202
+ entry.historyMore = Boolean(page.nextCursor);
203
+ entry.hydrated = true;
204
+ }
205
+ finally {
206
+ entry.historyLoading = false;
207
+ notify();
208
+ }
209
+ }
210
+ /** 只提取当前关联Turn的审批/阻塞/阶段/终态,不把回答或工具正文搬进隐藏状态。 */
211
+ async function refresh() {
212
+ if (refreshing || stopped)
213
+ return;
214
+ refreshing = true;
215
+ const abort = new AbortController();
216
+ refreshAbort = abort;
217
+ try {
218
+ const observedId = selectedId;
219
+ const summary = await options.readSummary?.(observedId, abort.signal);
220
+ if (abort.signal.aborted || stopped || selectedId !== observedId)
221
+ return;
222
+ const observed = entries.get(observedId);
223
+ if (observed && summary) {
224
+ if (summary.executionView && !observed.controller.isExecuting?.())
225
+ applyExecutionView(observed, summary.executionView);
226
+ else {
227
+ if (summary.status !== undefined && !observed.controller.isExecuting?.())
228
+ reconcileObservedIdentity(observed, { status: summary.status, activeTurnId: summary.currentTurnId ?? summary.activeTurnId });
229
+ if (summary.status !== undefined)
230
+ await refreshInteraction(observed);
231
+ }
232
+ const title = getCliSessionDisplayTitle(summary.title, observedId);
233
+ if (observed.title !== title) {
234
+ observed.title = title;
235
+ directory.set(observedId, { sessionId: observedId, title });
236
+ notify();
237
+ }
238
+ }
239
+ const relations = await options.readRelations?.(observedId, abort.signal) ?? [];
240
+ if (abort.signal.aborted || stopped || selectedId !== observedId)
241
+ return;
242
+ let changed = false;
243
+ for (const relation of relations) {
244
+ if (abort.signal.aborted || stopped || selectedId !== observedId)
245
+ return;
246
+ if (relation.threadId === observedId || relation.parentThreadId !== observedId)
247
+ continue;
248
+ const active = relation.status === "running" || relation.status === "waiting_approval" || relation.status === "waiting_user_input";
249
+ let entry = entries.get(relation.threadId);
250
+ if (!entry && !active)
251
+ continue;
252
+ if (!entry) {
253
+ entry = attach(relation.threadId, relation.title, options.createController(relation.threadId), false);
254
+ changed = true;
255
+ }
256
+ const title = getCliSessionDisplayTitle(relation.title, relation.threadId);
257
+ if (entry.title !== title || entry.parentSessionId !== observedId)
258
+ changed = true;
259
+ entry.title = title;
260
+ entry.parentSessionId = observedId;
261
+ if (relation.executionView && !entry.controller.isExecuting?.())
262
+ applyExecutionView(entry, relation.executionView);
263
+ else {
264
+ if (!entry.controller.isExecuting?.())
265
+ reconcileObservedIdentity(entry, relation);
266
+ if (active && relation.activeTurnId)
267
+ await refreshInteraction(entry);
268
+ }
269
+ }
270
+ if (abort.signal.aborted || stopped || selectedId !== observedId)
271
+ return;
272
+ const entry = entries.get(observedId);
273
+ if (entry.opened && (!entry.hydrated || !entry.historyMore && entry.historyCursor) && !entry.controller.isExecuting?.())
274
+ await loadHistory(entry.sessionId);
275
+ if (changed)
276
+ notify();
277
+ }
278
+ catch (error) {
279
+ if (!abort.signal.aborted)
280
+ throw error;
281
+ }
282
+ finally {
283
+ if (refreshAbort === abort)
284
+ refreshAbort = undefined;
285
+ refreshing = false;
286
+ }
287
+ }
288
+ /** 原目标结果只写原Store,picker仍由前台App消费。 */
289
+ function handleResult(entry, result) {
290
+ entry.store.syncProjection(entry.controller.getProjection());
291
+ if (result.kind === "error" && selectedId !== entry.sessionId)
292
+ entry.unread = true;
293
+ if (!result.skillOptions && !result.permissionOptions && !result.modelOptions && !result.effortOptions && !result.jobView && !result.contextView) {
294
+ for (const line of result.lines)
295
+ if (line.trim() && !line.startsWith("input queued:") && !line.startsWith("queued input started:"))
296
+ entry.store.addNotice(line);
297
+ if (!result.lines.length && result.message)
298
+ entry.store.addNotice(result.message);
299
+ }
300
+ notify();
301
+ }
302
+ /** 选择只打开精确UUID的视图和首历史页,绝不调用resume/continue/start。 */
303
+ async function select(sessionId) {
304
+ refreshAbort?.abort();
305
+ const generation = ++selectionGeneration;
306
+ let entry = entries.get(sessionId);
307
+ if (!entry) {
308
+ if (!directory.has(sessionId))
309
+ return;
310
+ const session = await options.runtime.sessions.get(sessionId);
311
+ if (!session || session.productMode !== "work" || session.projectId !== options.projectId || stopped || generation !== selectionGeneration)
312
+ return;
313
+ entry = attach(session.id, session.title, options.createController(session.id), true);
314
+ entry.pendingPrompts = session.presentation?.messages.filter(function user(message) { return message.role === "user"; }) ?? [];
315
+ }
316
+ else if (!entry.opened) {
317
+ const session = await options.runtime.sessions.get(sessionId);
318
+ if (!session || session.productMode !== "work" || session.projectId !== options.projectId || stopped || generation !== selectionGeneration)
319
+ return;
320
+ entry.opened = true;
321
+ entry.hydrated = false;
322
+ entry.pendingPrompts = session.presentation?.messages.filter(function user(message) { return message.role === "user"; }) ?? [];
323
+ bind(entry);
324
+ }
325
+ selectedId = sessionId;
326
+ entry.unread = false;
327
+ notify();
328
+ if (!entry.hydrated || !entry.historyMore && entry.historyCursor)
329
+ await loadHistory(sessionId);
330
+ }
331
+ /** 停止本宿主轮询和正在执行的精确目标,等待审批原样保留。 */
332
+ async function stop() {
333
+ stopped = true;
334
+ refreshAbort?.abort();
335
+ if (timer)
336
+ clearInterval(timer);
337
+ for (const entry of entries.values())
338
+ entry.controller.beginShutdown?.();
339
+ const report = { stopped: [], waiting: [], recoverable: [], unconfirmed: [] };
340
+ for (const entry of entries.values()) {
341
+ const view = entry.controller.getProjection();
342
+ if (view.status === "waiting_approval" || view.status === "waiting_user_input") {
343
+ report.waiting.push(entry.sessionId);
344
+ continue;
345
+ }
346
+ if (entry.controller.isExecuting?.() && view.status === "running" && view.turnId) {
347
+ const targetTurn = view.turnId;
348
+ try {
349
+ await entry.controller.dispatch({ type: "cancel_turn" });
350
+ const session = await options.runtime.sessions.get(entry.sessionId);
351
+ if (session?.activeTurnId === targetTurn && session.status === "running")
352
+ report.unconfirmed.push(entry.sessionId);
353
+ else
354
+ report.stopped.push(entry.sessionId);
355
+ }
356
+ catch {
357
+ report.unconfirmed.push(entry.sessionId);
358
+ }
359
+ }
360
+ else if (view.recoverable)
361
+ report.recoverable.push(entry.sessionId);
362
+ else if (view.status === "running")
363
+ report.unconfirmed.push(entry.sessionId);
364
+ }
365
+ return report;
366
+ }
367
+ return {
368
+ entries: function list() { return [...entries.values()]; },
369
+ directory: function listDirectory() { return [...directory.values()]; },
370
+ directoryState: function directoryState() { return { loading: directoryLoading, more: !directoryLoaded || Boolean(directoryCursor) }; },
371
+ selected: function selected() { return entries.get(selectedId); },
372
+ related: function related(sessionId = selectedId) { return [...entries.values()].filter(function child(entry) { return entry.sessionId !== sessionId && entry.parentSessionId === sessionId; }); },
373
+ select, refresh, loadDirectory, loadHistory, handleResult, stop,
374
+ subscribe: function subscribe(listener) { listeners.add(listener); return function unsubscribe() { listeners.delete(listener); }; },
375
+ /** 首屏不等待历史;仅已打开/关联活动目标后续按游标有界观察。 */
376
+ start: function start() {
377
+ void loadHistory(initial.sessionId).catch(function failed() { initial.store.addNotice("历史暂不可用,可按Ctrl+L重试"); });
378
+ void refresh().catch(function failed() { initial.store.addNotice("关联任务观察暂不可用"); });
379
+ timer = setInterval(function observe() { void refresh().catch(function failed() { entries.get(selectedId)?.store.addNotice("关联任务观察暂不可用"); }); }, 1000);
380
+ timer.unref?.();
381
+ },
382
+ };
383
+ }
@@ -0,0 +1,9 @@
1
+ /** inline单窗口会话壳:目录按需分页,仅当前会话挂载正文,输入按原目标隔离。 */
2
+ import { type ComponentProps } from "react";
3
+ import { CliTuiApp } from "./app.js";
4
+ import type { CliSessionManager } from "./session-manager.js";
5
+ /** 按Session保存草稿引用,仅挂载当前正文;目录选择不执行或取消Turn。 */
6
+ export declare function CliSessionWorkspace(props: Omit<ComponentProps<typeof CliTuiApp>, "controller" | "store" | "onResult"> & {
7
+ manager: CliSessionManager;
8
+ onResult(result: Parameters<ComponentProps<typeof CliTuiApp>["onResult"]>[0]): void;
9
+ }): import("react/jsx-runtime").JSX.Element;