@robota-sdk/agent-transport 3.0.0-beta.64

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/dist/node/headless/index.cjs +1 -0
  3. package/dist/node/headless/index.d.ts +2 -0
  4. package/dist/node/headless/index.js +1 -0
  5. package/dist/node/headless-CWEpJXFK.js +7 -0
  6. package/dist/node/headless-CWEpJXFK.js.map +1 -0
  7. package/dist/node/headless-CsZFelG9.cjs +6 -0
  8. package/dist/node/http/index.cjs +1 -0
  9. package/dist/node/http/index.d.ts +2 -0
  10. package/dist/node/http/index.js +1 -0
  11. package/dist/node/http-CM3TJhrF.cjs +1 -0
  12. package/dist/node/http-DwO1AHG-.js +2 -0
  13. package/dist/node/http-DwO1AHG-.js.map +1 -0
  14. package/dist/node/index--Ti9NzQX.d.ts +64 -0
  15. package/dist/node/index--Ti9NzQX.d.ts.map +1 -0
  16. package/dist/node/index-B_rcr14p.d.ts +47 -0
  17. package/dist/node/index-B_rcr14p.d.ts.map +1 -0
  18. package/dist/node/index-C9LWCL4l.d.ts +34 -0
  19. package/dist/node/index-C9LWCL4l.d.ts.map +1 -0
  20. package/dist/node/index-CAr3ioVh.d.ts +64 -0
  21. package/dist/node/index-CAr3ioVh.d.ts.map +1 -0
  22. package/dist/node/index-CEs25wVk.d.ts +213 -0
  23. package/dist/node/index-CEs25wVk.d.ts.map +1 -0
  24. package/dist/node/index-CvXLpjJO.d.ts +213 -0
  25. package/dist/node/index-CvXLpjJO.d.ts.map +1 -0
  26. package/dist/node/index-D34WUfFH.d.ts +26 -0
  27. package/dist/node/index-D34WUfFH.d.ts.map +1 -0
  28. package/dist/node/index-Y0zHb1Bz.d.ts +47 -0
  29. package/dist/node/index-Y0zHb1Bz.d.ts.map +1 -0
  30. package/dist/node/index-k3TUjA-T.d.ts +26 -0
  31. package/dist/node/index-k3TUjA-T.d.ts.map +1 -0
  32. package/dist/node/index-nBlMTFkZ.d.ts +34 -0
  33. package/dist/node/index-nBlMTFkZ.d.ts.map +1 -0
  34. package/dist/node/index.cjs +1 -0
  35. package/dist/node/index.d.ts +6 -0
  36. package/dist/node/index.js +1 -0
  37. package/dist/node/mcp/index.cjs +1 -0
  38. package/dist/node/mcp/index.d.ts +2 -0
  39. package/dist/node/mcp/index.js +1 -0
  40. package/dist/node/mcp-BXBwF6Wu.js +2 -0
  41. package/dist/node/mcp-BXBwF6Wu.js.map +1 -0
  42. package/dist/node/mcp-DcHuGokt.cjs +1 -0
  43. package/dist/node/tui/index.cjs +1 -0
  44. package/dist/node/tui/index.d.ts +2 -0
  45. package/dist/node/tui/index.js +1 -0
  46. package/dist/node/tui-CeD_6rSo.cjs +24 -0
  47. package/dist/node/tui-zmDTPk4b.js +25 -0
  48. package/dist/node/tui-zmDTPk4b.js.map +1 -0
  49. package/dist/node/ws/index.cjs +1 -0
  50. package/dist/node/ws/index.d.ts +2 -0
  51. package/dist/node/ws/index.js +1 -0
  52. package/dist/node/ws-B-oRccFl.js +2 -0
  53. package/dist/node/ws-B-oRccFl.js.map +1 -0
  54. package/dist/node/ws-COnIgnmn.cjs +1 -0
  55. package/package.json +141 -0
  56. package/src/headless/__tests__/headless-runner-initialization.test.ts +45 -0
  57. package/src/headless/__tests__/headless-runner.test.ts +484 -0
  58. package/src/headless/__tests__/headless-skill-activation.integration.test.ts +430 -0
  59. package/src/headless/__tests__/headless-transport.test.ts +268 -0
  60. package/src/headless/headless-runner.ts +141 -0
  61. package/src/headless/headless-stream-json.ts +142 -0
  62. package/src/headless/headless-transport.ts +43 -0
  63. package/src/headless/index.ts +4 -0
  64. package/src/http/__tests__/http-transport.test.ts +55 -0
  65. package/src/http/__tests__/routes.test.ts +168 -0
  66. package/src/http/http-transport.ts +42 -0
  67. package/src/http/index.ts +4 -0
  68. package/src/http/routes.ts +151 -0
  69. package/src/index.ts +5 -0
  70. package/src/mcp/__tests__/mcp-server.test.ts +66 -0
  71. package/src/mcp/__tests__/mcp-transport.test.ts +46 -0
  72. package/src/mcp/index.ts +4 -0
  73. package/src/mcp/mcp-server.ts +162 -0
  74. package/src/mcp/mcp-transport.ts +48 -0
  75. package/src/tui/App.tsx +478 -0
  76. package/src/tui/BackgroundTaskPanel.tsx +34 -0
  77. package/src/tui/CjkTextInput.tsx +204 -0
  78. package/src/tui/ConfirmPrompt.tsx +69 -0
  79. package/src/tui/ExecutionWorkspaceDetailPane.tsx +62 -0
  80. package/src/tui/ExecutionWorkspaceSwitcher.tsx +185 -0
  81. package/src/tui/InkTerminal.ts +42 -0
  82. package/src/tui/InputArea.tsx +298 -0
  83. package/src/tui/InteractivePrompt.tsx +57 -0
  84. package/src/tui/ListPicker.tsx +94 -0
  85. package/src/tui/MenuSelect.tsx +103 -0
  86. package/src/tui/MessageList.tsx +282 -0
  87. package/src/tui/PermissionPrompt.tsx +84 -0
  88. package/src/tui/PluginTUI.tsx +256 -0
  89. package/src/tui/SessionPicker.tsx +66 -0
  90. package/src/tui/SessionStatusBar.tsx +66 -0
  91. package/src/tui/SlashAutocomplete.tsx +110 -0
  92. package/src/tui/StatusBar.tsx +213 -0
  93. package/src/tui/StreamingIndicator.tsx +91 -0
  94. package/src/tui/TextPrompt.tsx +80 -0
  95. package/src/tui/ToolCommandOutput.tsx +37 -0
  96. package/src/tui/ToolDiffBlock.tsx +30 -0
  97. package/src/tui/TransportTUI.tsx +116 -0
  98. package/src/tui/UpdateNotice.tsx +14 -0
  99. package/src/tui/UsageSummaryEntry.tsx +38 -0
  100. package/src/tui/WaveText.tsx +44 -0
  101. package/src/tui/__tests__/InteractivePrompt.test.tsx +82 -0
  102. package/src/tui/__tests__/ListPicker.test.tsx +159 -0
  103. package/src/tui/__tests__/MenuSelect.test.tsx +103 -0
  104. package/src/tui/__tests__/PluginTUI.test.tsx +167 -0
  105. package/src/tui/__tests__/SlashAutocomplete.test.tsx +140 -0
  106. package/src/tui/__tests__/TextPrompt.test.tsx +98 -0
  107. package/src/tui/__tests__/UpdateNotice.test.tsx +15 -0
  108. package/src/tui/__tests__/abort-after-permission.test.tsx +169 -0
  109. package/src/tui/__tests__/abort-streaming-e2e.test.tsx +183 -0
  110. package/src/tui/__tests__/background-task-panel.test.tsx +53 -0
  111. package/src/tui/__tests__/background-task-row-format.test.ts +59 -0
  112. package/src/tui/__tests__/cjk-text-input-flow.test.ts +109 -0
  113. package/src/tui/__tests__/cjk-text-input.test.ts +191 -0
  114. package/src/tui/__tests__/command-effect-handler.test.ts +128 -0
  115. package/src/tui/__tests__/command-output-summary.test.ts +95 -0
  116. package/src/tui/__tests__/compact-event-bridge.test.ts +20 -0
  117. package/src/tui/__tests__/confirm-permission-flow.test.ts +91 -0
  118. package/src/tui/__tests__/confirm-prompt.test.tsx +87 -0
  119. package/src/tui/__tests__/execution-workspace-switcher.test.tsx +110 -0
  120. package/src/tui/__tests__/execution-workspace-view-model.test.ts +93 -0
  121. package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +122 -0
  122. package/src/tui/__tests__/input-area-flow.test.ts +152 -0
  123. package/src/tui/__tests__/message-list-rendering.test.tsx +353 -0
  124. package/src/tui/__tests__/model-change-side-effect.test.ts +91 -0
  125. package/src/tui/__tests__/prompt-queue.test.tsx +255 -0
  126. package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +233 -0
  127. package/src/tui/__tests__/render-markdown.test.ts +72 -0
  128. package/src/tui/__tests__/selection-flow.test.ts +61 -0
  129. package/src/tui/__tests__/slash-routing-effects.test.ts +225 -0
  130. package/src/tui/__tests__/status-activity.test.ts +71 -0
  131. package/src/tui/__tests__/status-bar.test.tsx +157 -0
  132. package/src/tui/__tests__/streaming-indicator.test.tsx +137 -0
  133. package/src/tui/__tests__/text-prompt-flow.test.ts +77 -0
  134. package/src/tui/__tests__/tui-state-manager.test.ts +401 -0
  135. package/src/tui/background-task-row-format.ts +52 -0
  136. package/src/tui/command-output-summary.ts +122 -0
  137. package/src/tui/execution-workspace-view-model.ts +123 -0
  138. package/src/tui/flows/cjk-text-input-flow.ts +285 -0
  139. package/src/tui/flows/confirm-prompt-flow.ts +45 -0
  140. package/src/tui/flows/input-area-flow.ts +186 -0
  141. package/src/tui/flows/permission-prompt-flow.ts +76 -0
  142. package/src/tui/flows/selection-flow.ts +126 -0
  143. package/src/tui/flows/text-prompt-flow.ts +98 -0
  144. package/src/tui/hooks/command-effect-handler.ts +98 -0
  145. package/src/tui/hooks/command-effect-queue.ts +39 -0
  146. package/src/tui/hooks/model-change-side-effect.ts +63 -0
  147. package/src/tui/hooks/side-effects-types.ts +38 -0
  148. package/src/tui/hooks/use-interactive-session-init.ts +50 -0
  149. package/src/tui/hooks/useAutocomplete.ts +85 -0
  150. package/src/tui/hooks/useInteractiveSession.ts +273 -0
  151. package/src/tui/hooks/usePermissionQueue.ts +51 -0
  152. package/src/tui/hooks/usePluginCallbacks.ts +30 -0
  153. package/src/tui/hooks/usePluginScreenData.ts +84 -0
  154. package/src/tui/hooks/useSideEffects.ts +210 -0
  155. package/src/tui/hooks/useSlashRouting.ts +117 -0
  156. package/src/tui/hooks/useStatusLineSettings.ts +35 -0
  157. package/src/tui/index.ts +3 -0
  158. package/src/tui/plugin-tui-handlers.ts +163 -0
  159. package/src/tui/render-markdown.ts +129 -0
  160. package/src/tui/render.tsx +60 -0
  161. package/src/tui/status-activity.ts +63 -0
  162. package/src/tui/tui-cli-adapter-context.tsx +12 -0
  163. package/src/tui/tui-cli-adapter.ts +25 -0
  164. package/src/tui/tui-state-manager.ts +225 -0
  165. package/src/tui/tui-transport.ts +32 -0
  166. package/src/tui/types.ts +14 -0
  167. package/src/tui/utils/__tests__/edit-diff.test.ts +426 -0
  168. package/src/tui/utils/__tests__/paste-detection.test.ts +116 -0
  169. package/src/tui/utils/__tests__/paste-labels.test.ts +46 -0
  170. package/src/tui/utils/__tests__/tool-call-extractor.test.ts +227 -0
  171. package/src/tui/utils/__tests__/tool-diff-summary.test.ts +104 -0
  172. package/src/tui/utils/edit-diff.ts +152 -0
  173. package/src/tui/utils/paste-labels.ts +9 -0
  174. package/src/tui/utils/tool-call-extractor.ts +91 -0
  175. package/src/tui/utils/tool-diff-summary.ts +75 -0
  176. package/src/ws/__tests__/ws-handler.test.ts +407 -0
  177. package/src/ws/__tests__/ws-transport.test.ts +53 -0
  178. package/src/ws/index.ts +13 -0
  179. package/src/ws/ws-background-messages.ts +170 -0
  180. package/src/ws/ws-handler.ts +279 -0
  181. package/src/ws/ws-protocol.ts +76 -0
  182. package/src/ws/ws-transport-configurable.ts +123 -0
  183. package/src/ws/ws-transport.ts +42 -0
@@ -0,0 +1,478 @@
1
+ import React, { useState, useEffect, useMemo, useCallback } from 'react';
2
+ import { Box, Text, useApp, useInput } from 'ink';
3
+ import type { IAIProvider } from '@robota-sdk/agent-core';
4
+ import type { TPermissionMode } from '@robota-sdk/agent-core';
5
+ import type {
6
+ IBackgroundTaskRunner,
7
+ ICommandHostAdapters,
8
+ ICommandModule,
9
+ IInteractiveSession,
10
+ IInteractiveSessionStore,
11
+ TSubagentRunnerFactory,
12
+ TShellExecFn,
13
+ IExecutionDetailPage,
14
+ } from '@robota-sdk/agent-framework';
15
+ import { listResumableSessionSummaries } from '@robota-sdk/agent-framework';
16
+ import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
17
+ import type { ITransportRegistryView } from '@robota-sdk/agent-interface-transport';
18
+ import { useInteractiveSession } from './hooks/useInteractiveSession.js';
19
+ import { usePluginCallbacks } from './hooks/usePluginCallbacks.js';
20
+ import { useSideEffects } from './hooks/useSideEffects.js';
21
+ import { useStatusLineSettings } from './hooks/useStatusLineSettings.js';
22
+ import MessageList from './MessageList.js';
23
+ import SessionStatusBar from './SessionStatusBar.js';
24
+ import InputArea from './InputArea.js';
25
+ import ConfirmPrompt from './ConfirmPrompt.js';
26
+ import InteractivePrompt from './InteractivePrompt.js';
27
+ import PermissionPrompt from './PermissionPrompt.js';
28
+ import StreamingIndicator from './StreamingIndicator.js';
29
+ import PluginTUI from './PluginTUI.js';
30
+ import TransportTUI from './TransportTUI.js';
31
+ import SessionPicker from './SessionPicker.js';
32
+ import BackgroundTaskPanel from './BackgroundTaskPanel.js';
33
+ import ExecutionWorkspaceSwitcher from './ExecutionWorkspaceSwitcher.js';
34
+ import ExecutionWorkspaceDetailPane from './ExecutionWorkspaceDetailPane.js';
35
+ import UpdateNotice from './UpdateNotice.js';
36
+ import { formatModelChangeConfirmationMessage } from './hooks/model-change-side-effect.js';
37
+ import {
38
+ countActiveBackgroundWorkspaceEntries,
39
+ getDefaultBackgroundWorkspaceEntries,
40
+ } from './execution-workspace-view-model.js';
41
+ import { TuiCliAdapterProvider } from './tui-cli-adapter-context.js';
42
+ import type { ITuiCliAdapter } from './tui-cli-adapter.js';
43
+ import type { CommandRegistry } from '@robota-sdk/agent-framework';
44
+
45
+ interface IProps {
46
+ cwd: string;
47
+ provider: IAIProvider;
48
+ providerOverride?: string | undefined;
49
+ providerType?: string | undefined;
50
+ modelId?: string;
51
+ language?: string;
52
+ permissionMode?: TPermissionMode;
53
+ maxTurns?: number;
54
+ version?: string;
55
+ sessionStore?: IInteractiveSessionStore;
56
+ resumeSessionId?: string;
57
+ showSessionPickerOnStart?: boolean;
58
+ forkSession?: boolean;
59
+ sessionName?: string;
60
+ backgroundTaskRunners?: IBackgroundTaskRunner[];
61
+ subagentRunnerFactory?: TSubagentRunnerFactory;
62
+ commandModules?: readonly ICommandModule[];
63
+ commandHostAdapters?: ICommandHostAdapters;
64
+ shellExec?: TShellExecFn;
65
+ startupUpdateNotice?: Promise<string | undefined>;
66
+ transportRegistry?: ITransportRegistryView<IInteractiveSession>;
67
+ cliAdapter: ITuiCliAdapter;
68
+ reloadPluginCommandSource?: (registry: CommandRegistry) => void;
69
+ agentName?: string;
70
+ }
71
+
72
+ export default function App(props: IProps): React.ReactElement {
73
+ const [activeSessionId, setActiveSessionId] = useState<string | undefined>(props.resumeSessionId);
74
+ const [showInitialSessionPicker, setShowInitialSessionPicker] = useState(
75
+ props.showSessionPickerOnStart ?? false,
76
+ );
77
+
78
+ return (
79
+ <TuiCliAdapterProvider value={props.cliAdapter}>
80
+ <AppInner
81
+ key={activeSessionId ?? '__new__'}
82
+ {...props}
83
+ showSessionPickerOnStart={showInitialSessionPicker}
84
+ resumeSessionId={activeSessionId}
85
+ onSessionSwitch={(sessionId) => {
86
+ setShowInitialSessionPicker(false);
87
+ setActiveSessionId(sessionId);
88
+ }}
89
+ />
90
+ </TuiCliAdapterProvider>
91
+ );
92
+ }
93
+
94
+ function AppInner(
95
+ props: IProps & { onSessionSwitch: (sessionId: string) => void },
96
+ ): React.ReactElement {
97
+ const cwd = props.cwd;
98
+
99
+ const {
100
+ interactiveSession,
101
+ registry,
102
+ commandEffectQueue,
103
+ history,
104
+ addEntry,
105
+ streamingText,
106
+ activeTools,
107
+ isThinking,
108
+ isAborting,
109
+ isShuttingDown,
110
+ pendingPrompt,
111
+ executionWorkspaceSnapshot,
112
+ selectedExecutionEntryId,
113
+ selectExecutionWorkspaceEntry,
114
+ readExecutionWorkspaceDetail,
115
+ permissionRequest,
116
+ contextState,
117
+ handleSubmit: baseHandleSubmit,
118
+ handleAbort,
119
+ handleCancelQueue,
120
+ handleShutdown,
121
+ } = useInteractiveSession({
122
+ cwd,
123
+ provider: props.provider,
124
+ permissionMode: props.permissionMode,
125
+ maxTurns: props.maxTurns,
126
+ sessionStore: props.sessionStore,
127
+ resumeSessionId: props.resumeSessionId,
128
+ forkSession: props.forkSession,
129
+ sessionName: props.sessionName,
130
+ backgroundTaskRunners: props.backgroundTaskRunners,
131
+ subagentRunnerFactory: props.subagentRunnerFactory,
132
+ commandModules: props.commandModules,
133
+ commandHostAdapters: props.commandHostAdapters,
134
+ shellExec: props.shellExec,
135
+ transportRegistry: props.transportRegistry,
136
+ language: props.language,
137
+ reloadPluginCommandSource: props.reloadPluginCommandSource,
138
+ agentName: props.agentName,
139
+ });
140
+
141
+ const fallbackPluginCallbacks = usePluginCallbacks(cwd);
142
+ const pluginCallbacks = props.commandHostAdapters?.plugin ?? fallbackPluginCallbacks;
143
+ const { exit } = useApp();
144
+ const [sessionName, setSessionName] = useState<string | undefined>(props.sessionName);
145
+ const [updateNotice, setUpdateNotice] = useState<string | undefined>();
146
+ const [showExecutionWorkspaceSwitcher, setShowExecutionWorkspaceSwitcher] = useState(false);
147
+ const [executionDetailPage, setExecutionDetailPage] = useState<IExecutionDetailPage | null>(null);
148
+ const [executionDetailError, setExecutionDetailError] = useState<string | undefined>();
149
+ const [isExecutionDetailLoading, setIsExecutionDetailLoading] = useState(false);
150
+ const [statusLineSettings, setStatusLineSettings] = useStatusLineSettings();
151
+ const backgroundWorkspaceEntries = useMemo(
152
+ () => getDefaultBackgroundWorkspaceEntries(executionWorkspaceSnapshot),
153
+ [executionWorkspaceSnapshot],
154
+ );
155
+ const activeBackgroundTaskCount = countActiveBackgroundWorkspaceEntries(
156
+ executionWorkspaceSnapshot,
157
+ );
158
+ const selectedExecutionEntry = useMemo(
159
+ () =>
160
+ executionWorkspaceSnapshot?.entries.find((entry) => entry.id === selectedExecutionEntryId),
161
+ [executionWorkspaceSnapshot, selectedExecutionEntryId],
162
+ );
163
+
164
+ const {
165
+ handleSubmit,
166
+ pendingModelId,
167
+ pendingInteractionPrompt,
168
+ showPluginTUI,
169
+ showSessionPicker,
170
+ showTransportTUI,
171
+ setShowPluginTUI,
172
+ setShowSessionPicker,
173
+ setShowTransportTUI,
174
+ handleModelConfirm,
175
+ handleInteractionSubmit,
176
+ handleInteractionCancel,
177
+ } = useSideEffects({
178
+ cwd,
179
+ providerOverride: props.providerOverride,
180
+ interactiveSession,
181
+ commandEffectQueue,
182
+ addEntry,
183
+ baseHandleSubmit,
184
+ setSessionName,
185
+ setStatusLineSettings,
186
+ showSessionPickerOnStart: props.showSessionPickerOnStart,
187
+ openAgentSwitcher: () => setShowExecutionWorkspaceSwitcher(true),
188
+ });
189
+
190
+ const isSelectedEntryInteractive =
191
+ !selectedExecutionEntry ||
192
+ selectedExecutionEntry.kind === 'main_thread' ||
193
+ selectedExecutionEntry.controls.includes('send');
194
+
195
+ const activeAgentLabel =
196
+ selectedExecutionEntry && selectedExecutionEntry.kind !== 'main_thread'
197
+ ? selectedExecutionEntry.title
198
+ : undefined;
199
+
200
+ const mainThreadEntryId = useMemo(
201
+ () => executionWorkspaceSnapshot?.entries.find((e) => e.kind === 'main_thread')?.id,
202
+ [executionWorkspaceSnapshot],
203
+ );
204
+
205
+ const handleSubmitWithRouting = useCallback(
206
+ async (input: string): Promise<void> => {
207
+ if (
208
+ selectedExecutionEntry &&
209
+ selectedExecutionEntry.kind !== 'main_thread' &&
210
+ selectedExecutionEntry.controls.includes('send')
211
+ ) {
212
+ await interactiveSession.sendAgentJob(selectedExecutionEntry.sourceId, input);
213
+ } else {
214
+ await handleSubmit(input);
215
+ }
216
+ },
217
+ [selectedExecutionEntry, handleSubmit, interactiveSession],
218
+ );
219
+
220
+ // Sync session name from InteractiveSession when resuming
221
+ useEffect(() => {
222
+ const name = interactiveSession?.getName?.();
223
+ if (name && !sessionName) setSessionName(name);
224
+ }, [interactiveSession, sessionName]);
225
+
226
+ useEffect(() => {
227
+ let isMounted = true;
228
+ props.startupUpdateNotice
229
+ ?.then((notice) => {
230
+ if (isMounted && notice !== undefined) {
231
+ setUpdateNotice(notice);
232
+ }
233
+ })
234
+ .catch(() => {
235
+ // Startup update checks are best-effort and must not disrupt the TUI.
236
+ });
237
+ return () => {
238
+ isMounted = false;
239
+ };
240
+ }, [props.startupUpdateNotice]);
241
+
242
+ // Update terminal title
243
+ useEffect(() => {
244
+ const title = sessionName ? `Robota — ${sessionName}` : 'Robota';
245
+ process.stdout.write(`\x1b]0;${title}\x07`);
246
+ }, [sessionName]);
247
+
248
+ // ESC abort
249
+ useInput((_input: string, key: { escape: boolean }) => {
250
+ if (!key.escape || !isThinking) return;
251
+ if (
252
+ permissionRequest ||
253
+ showPluginTUI ||
254
+ showTransportTUI ||
255
+ showSessionPicker ||
256
+ showExecutionWorkspaceSwitcher
257
+ ) {
258
+ return;
259
+ }
260
+ handleAbort();
261
+ });
262
+
263
+ // Ctrl+B toggles the execution workspace switcher.
264
+ useInput((input: string, key: { ctrl?: boolean }) => {
265
+ if (!key.ctrl || input !== 'b') return;
266
+ if (permissionRequest || showPluginTUI || showSessionPicker || isShuttingDown) return;
267
+ setShowExecutionWorkspaceSwitcher((shown) => !shown);
268
+ });
269
+
270
+ // ESC returns to main thread when a background entry is selected (and not thinking).
271
+ useInput((_input: string, key: { escape: boolean }) => {
272
+ if (!key.escape || isThinking) return;
273
+ if (
274
+ permissionRequest ||
275
+ showPluginTUI ||
276
+ showTransportTUI ||
277
+ showSessionPicker ||
278
+ showExecutionWorkspaceSwitcher
279
+ ) {
280
+ return;
281
+ }
282
+ if (
283
+ selectedExecutionEntry &&
284
+ selectedExecutionEntry.kind !== 'main_thread' &&
285
+ mainThreadEntryId !== undefined
286
+ ) {
287
+ selectExecutionWorkspaceEntry(mainThreadEntryId);
288
+ }
289
+ });
290
+
291
+ // Ctrl+C graceful shutdown
292
+ useInput((input: string, key: { ctrl?: boolean }) => {
293
+ if (!key.ctrl || input !== 'c' || isShuttingDown) return;
294
+ void handleShutdown('prompt_input_exit').finally(() => exit());
295
+ });
296
+
297
+ useEffect(() => {
298
+ const onSigterm = (): void => {
299
+ if (isShuttingDown) return;
300
+ void handleShutdown('other').finally(() => exit());
301
+ };
302
+ process.once('SIGINT', onSigterm);
303
+ process.once('SIGTERM', onSigterm);
304
+ return () => {
305
+ process.off('SIGINT', onSigterm);
306
+ process.off('SIGTERM', onSigterm);
307
+ };
308
+ }, [handleShutdown, exit, isShuttingDown]);
309
+
310
+ useEffect(() => {
311
+ if (!selectedExecutionEntry || selectedExecutionEntry.kind === 'main_thread') {
312
+ setExecutionDetailPage(null);
313
+ setExecutionDetailError(undefined);
314
+ setIsExecutionDetailLoading(false);
315
+ return;
316
+ }
317
+
318
+ let isCurrent = true;
319
+ setIsExecutionDetailLoading(true);
320
+ setExecutionDetailError(undefined);
321
+ readExecutionWorkspaceDetail(selectedExecutionEntry.id)
322
+ .then((page) => {
323
+ if (!isCurrent) return;
324
+ setExecutionDetailPage(page);
325
+ setIsExecutionDetailLoading(false);
326
+ })
327
+ .catch((error: Error) => {
328
+ if (!isCurrent) return;
329
+ setExecutionDetailError(error.message);
330
+ setIsExecutionDetailLoading(false);
331
+ });
332
+
333
+ return () => {
334
+ isCurrent = false;
335
+ };
336
+ }, [executionWorkspaceSnapshot, readExecutionWorkspaceDetail, selectedExecutionEntry]);
337
+
338
+ // Session may not be initialized yet
339
+ let permissionMode: TPermissionMode = props.permissionMode ?? 'default';
340
+ let sessionId = '';
341
+ try {
342
+ // allow-fallback: session initializes asynchronously; use defaults until ready
343
+ const session = interactiveSession.getSession();
344
+ permissionMode = session.getPermissionMode();
345
+ sessionId = session.getSessionId();
346
+ } catch {
347
+ // allow-fallback: session initializes asynchronously; use defaults until ready
348
+ // Not yet initialized
349
+ }
350
+
351
+ return (
352
+ <Box flexDirection="column">
353
+ <Box flexDirection="column" paddingX={1} marginBottom={1}>
354
+ <Text color="cyan" bold>{`
355
+ ____ ___ ____ ___ _____ _
356
+ | _ \\ / _ \\| __ ) / _ \\_ _|/ \\
357
+ | |_) | | | | _ \\| | | || | / _ \\
358
+ | _ <| |_| | |_) | |_| || |/ ___ \\
359
+ |_| \\_\\\\___/|____/ \\___/ |_/_/ \\_\\
360
+ `}</Text>
361
+ <Text dimColor> v{props.version ?? '0.0.0'}</Text>
362
+ </Box>
363
+ {updateNotice && <UpdateNotice message={updateNotice} />}
364
+ <Box flexDirection="column" paddingX={1} flexGrow={1}>
365
+ {selectedExecutionEntry && selectedExecutionEntry.kind !== 'main_thread' ? (
366
+ <ExecutionWorkspaceDetailPane
367
+ entry={selectedExecutionEntry}
368
+ page={executionDetailPage}
369
+ loading={isExecutionDetailLoading}
370
+ error={executionDetailError}
371
+ />
372
+ ) : (
373
+ <MessageList history={history} />
374
+ )}
375
+ {isShuttingDown && (
376
+ <Box marginBottom={1}>
377
+ <Text color="yellow">Shutting down...</Text>
378
+ </Box>
379
+ )}
380
+ {(isThinking || activeTools.length > 0) && (
381
+ <Box flexDirection="column" marginBottom={1}>
382
+ <StreamingIndicator
383
+ text={streamingText}
384
+ activeTools={activeTools}
385
+ isThinking={isThinking}
386
+ />
387
+ </Box>
388
+ )}
389
+ <BackgroundTaskPanel entries={backgroundWorkspaceEntries} />
390
+ </Box>
391
+ {showExecutionWorkspaceSwitcher && (
392
+ <ExecutionWorkspaceSwitcher
393
+ snapshot={executionWorkspaceSnapshot}
394
+ selectedEntryId={selectedExecutionEntryId}
395
+ onSelect={selectExecutionWorkspaceEntry}
396
+ onClose={() => setShowExecutionWorkspaceSwitcher(false)}
397
+ />
398
+ )}
399
+ {permissionRequest && <PermissionPrompt request={permissionRequest} />}
400
+ {pendingModelId && (
401
+ <ConfirmPrompt
402
+ message={formatModelChangeConfirmationMessage(pendingModelId)}
403
+ onSelect={handleModelConfirm}
404
+ />
405
+ )}
406
+ {pendingInteractionPrompt && (
407
+ <InteractivePrompt
408
+ prompt={pendingInteractionPrompt}
409
+ onSubmit={handleInteractionSubmit}
410
+ onCancel={handleInteractionCancel}
411
+ />
412
+ )}
413
+ {showPluginTUI && (
414
+ <PluginTUI
415
+ callbacks={pluginCallbacks}
416
+ onClose={() => setShowPluginTUI(false)}
417
+ addMessage={(msg) => addEntry(messageToHistoryEntry(createSystemMessage(msg.content)))}
418
+ />
419
+ )}
420
+ {showTransportTUI && props.transportRegistry && (
421
+ <TransportTUI
422
+ registry={props.transportRegistry}
423
+ onClose={() => setShowTransportTUI(false)}
424
+ />
425
+ )}
426
+ {showSessionPicker && (
427
+ <SessionPicker
428
+ sessions={listResumableSessionSummaries(props.sessionStore, props.cwd)}
429
+ onSelect={(id) => {
430
+ setShowSessionPicker(false);
431
+ props.onSessionSwitch(id);
432
+ }}
433
+ onCancel={() => {
434
+ setShowSessionPicker(false);
435
+ addEntry(messageToHistoryEntry(createSystemMessage('Session resume cancelled.')));
436
+ }}
437
+ />
438
+ )}
439
+ <SessionStatusBar
440
+ cwd={cwd}
441
+ permissionMode={permissionMode}
442
+ modelId={props.modelId}
443
+ providerType={props.providerType}
444
+ sessionId={sessionId}
445
+ isThinking={isThinking}
446
+ activeToolCount={activeTools.length}
447
+ activeBackgroundTaskCount={activeBackgroundTaskCount}
448
+ hasPendingPrompt={pendingPrompt !== null}
449
+ contextState={contextState}
450
+ sessionName={sessionName}
451
+ settings={statusLineSettings}
452
+ activeAgentLabel={activeAgentLabel}
453
+ />
454
+ <InputArea
455
+ onSubmit={handleSubmitWithRouting}
456
+ onCancelQueue={handleCancelQueue}
457
+ isDisabled={
458
+ !!permissionRequest ||
459
+ showPluginTUI ||
460
+ showTransportTUI ||
461
+ showSessionPicker ||
462
+ showExecutionWorkspaceSwitcher ||
463
+ isShuttingDown ||
464
+ pendingInteractionPrompt !== null ||
465
+ (isThinking && !!pendingPrompt) ||
466
+ !isSelectedEntryInteractive
467
+ }
468
+ isAborting={isAborting}
469
+ pendingPrompt={pendingPrompt}
470
+ registry={registry}
471
+ sessionName={sessionName}
472
+ history={history}
473
+ />
474
+ {/* Permanent blank line below input — required for Korean IME stability. */}
475
+ <Text> </Text>
476
+ </Box>
477
+ );
478
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { Box, Text } from 'ink';
3
+ import type { IExecutionWorkspaceEntry } from '@robota-sdk/agent-framework';
4
+ import { formatBackgroundTaskRow } from './background-task-row-format.js';
5
+
6
+ interface IProps {
7
+ entries: IExecutionWorkspaceEntry[];
8
+ }
9
+
10
+ export default function BackgroundTaskPanel({ entries }: IProps): React.ReactElement | null {
11
+ if (entries.length === 0) return null;
12
+
13
+ return (
14
+ <Box flexDirection="column" marginBottom={1}>
15
+ <Text color="cyan" bold>
16
+ Background work
17
+ </Text>
18
+ {entries.map((entry, index) => {
19
+ const row = formatBackgroundTaskRow(entry, { isLast: index === entries.length - 1 });
20
+ return (
21
+ <Text key={entry.id}>
22
+ {`${row.connector} `}
23
+ <Text color={row.color}>{row.marker}</Text>
24
+ {` ${row.label}`}
25
+ {row.segments.map((segment, segmentIndex) => (
26
+ <Text key={`${segment}-${segmentIndex}`} dimColor>{` · ${segment}`}</Text>
27
+ ))}
28
+ {row.preview ? <Text dimColor>{` · ${row.preview}`}</Text> : null}
29
+ </Text>
30
+ );
31
+ })}
32
+ </Box>
33
+ );
34
+ }