@robota-sdk/agent-transport 3.0.0-beta.74 → 3.0.0-beta.76

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 (197) hide show
  1. package/README.md +10 -10
  2. package/dist/node/headless/index.cjs +1 -1
  3. package/dist/node/headless/index.d.ts +1 -1
  4. package/dist/node/headless/index.js +1 -1
  5. package/dist/node/headless-OnpVk4-k.cjs +15 -0
  6. package/dist/node/{headless-D02zUEGh.js → headless-mRYilLfC.js} +2 -2
  7. package/dist/node/{headless-D02zUEGh.js.map → headless-mRYilLfC.js.map} +1 -1
  8. package/dist/node/{index-DE3-dHqw.d.ts → index-CYl7ksS6.d.ts} +12 -2
  9. package/dist/node/{index-DE3-dHqw.d.ts.map → index-CYl7ksS6.d.ts.map} +1 -1
  10. package/dist/node/{index-WKTgvhlg.d.ts → index-E8Gx4-lc.d.ts} +12 -2
  11. package/dist/node/{index-WKTgvhlg.d.ts.map → index-E8Gx4-lc.d.ts.map} +1 -1
  12. package/dist/node/index.cjs +1 -1
  13. package/dist/node/index.d.ts +2 -7
  14. package/dist/node/index.d.ts.map +1 -1
  15. package/dist/node/index.js +1 -1
  16. package/dist/node/index.js.map +1 -1
  17. package/package.json +7 -75
  18. package/src/headless/HeadlessInteractionChannel.ts +21 -1
  19. package/src/index.ts +1 -5
  20. package/src/transport-registry.ts +0 -9
  21. package/dist/node/headless-BeHAOlIM.cjs +0 -15
  22. package/dist/node/http/index.cjs +0 -1
  23. package/dist/node/http/index.d.ts +0 -2
  24. package/dist/node/http/index.js +0 -1
  25. package/dist/node/http-2Jiuflc1.js +0 -2
  26. package/dist/node/http-2Jiuflc1.js.map +0 -1
  27. package/dist/node/http-CBAvefLw.cjs +0 -1
  28. package/dist/node/index-BQLN_Lc9.d.ts +0 -78
  29. package/dist/node/index-BQLN_Lc9.d.ts.map +0 -1
  30. package/dist/node/index-BnAGE-u9.d.ts +0 -33
  31. package/dist/node/index-BnAGE-u9.d.ts.map +0 -1
  32. package/dist/node/index-BrQ4gGw0.d.ts +0 -213
  33. package/dist/node/index-BrQ4gGw0.d.ts.map +0 -1
  34. package/dist/node/index-CoeBF21y.d.ts +0 -213
  35. package/dist/node/index-CoeBF21y.d.ts.map +0 -1
  36. package/dist/node/index-DHt-2VQ-.d.ts +0 -46
  37. package/dist/node/index-DHt-2VQ-.d.ts.map +0 -1
  38. package/dist/node/index-DMwKN5Le.d.ts +0 -33
  39. package/dist/node/index-DMwKN5Le.d.ts.map +0 -1
  40. package/dist/node/index-IvYaYY6v.d.ts +0 -78
  41. package/dist/node/index-IvYaYY6v.d.ts.map +0 -1
  42. package/dist/node/index-c0M42fsA.d.ts +0 -46
  43. package/dist/node/index-c0M42fsA.d.ts.map +0 -1
  44. package/dist/node/mcp/index.cjs +0 -1
  45. package/dist/node/mcp/index.d.ts +0 -2
  46. package/dist/node/mcp/index.js +0 -1
  47. package/dist/node/mcp-BOglBJNy.cjs +0 -1
  48. package/dist/node/mcp-D3BBVK7C.js +0 -2
  49. package/dist/node/mcp-D3BBVK7C.js.map +0 -1
  50. package/dist/node/rolldown-runtime-CMqjfN_6.cjs +0 -1
  51. package/dist/node/tui/index.cjs +0 -1
  52. package/dist/node/tui/index.d.ts +0 -2
  53. package/dist/node/tui/index.js +0 -1
  54. package/dist/node/tui-Btb1q88j.js +0 -25
  55. package/dist/node/tui-Btb1q88j.js.map +0 -1
  56. package/dist/node/tui-SbUT7Zlt.cjs +0 -24
  57. package/dist/node/ws/index.cjs +0 -1
  58. package/dist/node/ws/index.d.ts +0 -2
  59. package/dist/node/ws/index.js +0 -1
  60. package/dist/node/ws-Dc2RUwVs.js +0 -2
  61. package/dist/node/ws-Dc2RUwVs.js.map +0 -1
  62. package/dist/node/ws-QNMQn5kg.cjs +0 -1
  63. package/src/http/__tests__/http-transport.test.ts +0 -55
  64. package/src/http/__tests__/routes.test.ts +0 -168
  65. package/src/http/http-transport.ts +0 -41
  66. package/src/http/index.ts +0 -4
  67. package/src/http/routes.ts +0 -152
  68. package/src/mcp/__tests__/mcp-server.test.ts +0 -66
  69. package/src/mcp/__tests__/mcp-transport.test.ts +0 -46
  70. package/src/mcp/index.ts +0 -4
  71. package/src/mcp/mcp-server.ts +0 -163
  72. package/src/mcp/mcp-transport.ts +0 -48
  73. package/src/tui/App.tsx +0 -488
  74. package/src/tui/BackgroundTaskPanel.tsx +0 -36
  75. package/src/tui/CjkTextInput.tsx +0 -199
  76. package/src/tui/ConfirmPrompt.tsx +0 -70
  77. package/src/tui/ContextWarningBanner.tsx +0 -34
  78. package/src/tui/ExecutionWorkspaceDetailPane.tsx +0 -64
  79. package/src/tui/ExecutionWorkspaceSwitcher.tsx +0 -187
  80. package/src/tui/InputArea.tsx +0 -310
  81. package/src/tui/InteractivePrompt.tsx +0 -59
  82. package/src/tui/ListPicker.tsx +0 -95
  83. package/src/tui/MenuSelect.tsx +0 -104
  84. package/src/tui/MessageList.tsx +0 -284
  85. package/src/tui/PermissionPrompt.tsx +0 -86
  86. package/src/tui/PluginTUI.tsx +0 -258
  87. package/src/tui/SessionPicker.tsx +0 -68
  88. package/src/tui/SessionStatusBar.tsx +0 -70
  89. package/src/tui/SlashAutocomplete.tsx +0 -110
  90. package/src/tui/StatusBar.tsx +0 -209
  91. package/src/tui/StreamingIndicator.tsx +0 -93
  92. package/src/tui/TextPrompt.tsx +0 -81
  93. package/src/tui/ToolCommandOutput.tsx +0 -39
  94. package/src/tui/ToolDiffBlock.tsx +0 -32
  95. package/src/tui/TransportTUI.tsx +0 -117
  96. package/src/tui/TuiInteractionChannel.ts +0 -483
  97. package/src/tui/UpdateNotice.tsx +0 -14
  98. package/src/tui/UsageSummaryEntry.tsx +0 -39
  99. package/src/tui/WaveText.tsx +0 -44
  100. package/src/tui/__tests__/InteractivePrompt.test.tsx +0 -82
  101. package/src/tui/__tests__/ListPicker.test.tsx +0 -159
  102. package/src/tui/__tests__/MenuSelect.test.tsx +0 -103
  103. package/src/tui/__tests__/PluginTUI.test.tsx +0 -167
  104. package/src/tui/__tests__/SlashAutocomplete.test.tsx +0 -140
  105. package/src/tui/__tests__/TextPrompt.test.tsx +0 -98
  106. package/src/tui/__tests__/TuiInteractionChannel.display-contract.test.ts +0 -239
  107. package/src/tui/__tests__/TuiInteractionChannel.lifecycle.test.ts +0 -297
  108. package/src/tui/__tests__/TuiInteractionChannel.requestAction.test.ts +0 -124
  109. package/src/tui/__tests__/UpdateNotice.test.tsx +0 -15
  110. package/src/tui/__tests__/abort-after-permission.test.tsx +0 -169
  111. package/src/tui/__tests__/abort-streaming-e2e.test.tsx +0 -183
  112. package/src/tui/__tests__/background-task-panel.test.tsx +0 -53
  113. package/src/tui/__tests__/background-task-row-format.test.ts +0 -59
  114. package/src/tui/__tests__/channel-factory-integration.test.ts +0 -138
  115. package/src/tui/__tests__/cjk-text-input-flow.test.ts +0 -109
  116. package/src/tui/__tests__/cjk-text-input.test.ts +0 -191
  117. package/src/tui/__tests__/command-effect-handler.test.ts +0 -127
  118. package/src/tui/__tests__/command-output-summary.test.ts +0 -95
  119. package/src/tui/__tests__/compact-event-bridge.test.ts +0 -20
  120. package/src/tui/__tests__/confirm-permission-flow.test.ts +0 -130
  121. package/src/tui/__tests__/confirm-prompt.test.tsx +0 -87
  122. package/src/tui/__tests__/execution-workspace-switcher.test.tsx +0 -110
  123. package/src/tui/__tests__/execution-workspace-view-model.test.ts +0 -93
  124. package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +0 -125
  125. package/src/tui/__tests__/input-area-flow.test.ts +0 -164
  126. package/src/tui/__tests__/message-list-rendering.test.tsx +0 -353
  127. package/src/tui/__tests__/prompt-queue.test.tsx +0 -255
  128. package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +0 -233
  129. package/src/tui/__tests__/pty/pty-driver.ts +0 -135
  130. package/src/tui/__tests__/pty/tui-pty.ptytest.ts +0 -61
  131. package/src/tui/__tests__/render-channel-options.test.ts +0 -32
  132. package/src/tui/__tests__/render-markdown.test.ts +0 -72
  133. package/src/tui/__tests__/selection-flow.test.ts +0 -61
  134. package/src/tui/__tests__/session-init-poller.test.ts +0 -102
  135. package/src/tui/__tests__/session-naming.test.ts +0 -64
  136. package/src/tui/__tests__/session-switch-channel.test.tsx +0 -307
  137. package/src/tui/__tests__/slash-routing-effects.test.ts +0 -228
  138. package/src/tui/__tests__/status-activity.test.ts +0 -71
  139. package/src/tui/__tests__/status-bar.test.tsx +0 -158
  140. package/src/tui/__tests__/streaming-indicator.test.tsx +0 -137
  141. package/src/tui/__tests__/text-prompt-flow.test.ts +0 -77
  142. package/src/tui/__tests__/tui-channel-init-failure.test.ts +0 -57
  143. package/src/tui/__tests__/tui-state-manager.test.ts +0 -401
  144. package/src/tui/background-task-row-format.ts +0 -53
  145. package/src/tui/command-interaction.ts +0 -9
  146. package/src/tui/command-output-summary.ts +0 -122
  147. package/src/tui/create-default-tui-cli-adapter.ts +0 -41
  148. package/src/tui/execution-workspace-view-model.ts +0 -123
  149. package/src/tui/flows/cjk-text-input-flow.ts +0 -285
  150. package/src/tui/flows/confirm-prompt-flow.ts +0 -45
  151. package/src/tui/flows/input-area-flow.ts +0 -189
  152. package/src/tui/flows/permission-prompt-flow.ts +0 -85
  153. package/src/tui/flows/selection-flow.ts +0 -126
  154. package/src/tui/flows/session-init-poller.ts +0 -77
  155. package/src/tui/flows/text-prompt-flow.ts +0 -98
  156. package/src/tui/hooks/command-effect-handler.ts +0 -97
  157. package/src/tui/hooks/command-effect-queue.ts +0 -39
  158. package/src/tui/hooks/side-effects-types.ts +0 -35
  159. package/src/tui/hooks/useAutocomplete.ts +0 -87
  160. package/src/tui/hooks/usePluginCallbacks.ts +0 -31
  161. package/src/tui/hooks/usePluginScreenData.ts +0 -85
  162. package/src/tui/hooks/useSideEffects.ts +0 -175
  163. package/src/tui/hooks/useSlashRouting.ts +0 -118
  164. package/src/tui/hooks/useStatusLineSettings.ts +0 -37
  165. package/src/tui/hooks/useTuiChannel.ts +0 -95
  166. package/src/tui/index.ts +0 -14
  167. package/src/tui/interactions/CommandConfirm.tsx +0 -36
  168. package/src/tui/interactions/CommandPicker.tsx +0 -77
  169. package/src/tui/interactions/__tests__/CommandConfirm.test.tsx +0 -124
  170. package/src/tui/interactions/__tests__/CommandPicker.test.tsx +0 -138
  171. package/src/tui/plugin-tui-handlers.ts +0 -163
  172. package/src/tui/render-markdown.ts +0 -130
  173. package/src/tui/render.tsx +0 -117
  174. package/src/tui/session-naming.ts +0 -33
  175. package/src/tui/status-activity.ts +0 -63
  176. package/src/tui/tui-cli-adapter-context.tsx +0 -13
  177. package/src/tui/tui-cli-adapter.ts +0 -25
  178. package/src/tui/tui-state-manager.ts +0 -226
  179. package/src/tui/tui-transport.ts +0 -35
  180. package/src/tui/types.ts +0 -15
  181. package/src/tui/utils/__tests__/edit-diff.test.ts +0 -426
  182. package/src/tui/utils/__tests__/paste-detection.test.ts +0 -116
  183. package/src/tui/utils/__tests__/paste-labels.test.ts +0 -46
  184. package/src/tui/utils/__tests__/tool-call-extractor.test.ts +0 -227
  185. package/src/tui/utils/__tests__/tool-diff-summary.test.ts +0 -104
  186. package/src/tui/utils/edit-diff.ts +0 -153
  187. package/src/tui/utils/paste-labels.ts +0 -9
  188. package/src/tui/utils/tool-call-extractor.ts +0 -92
  189. package/src/tui/utils/tool-diff-summary.ts +0 -75
  190. package/src/ws/__tests__/ws-handler.test.ts +0 -409
  191. package/src/ws/__tests__/ws-transport.test.ts +0 -53
  192. package/src/ws/index.ts +0 -13
  193. package/src/ws/ws-background-messages.ts +0 -170
  194. package/src/ws/ws-handler.ts +0 -280
  195. package/src/ws/ws-protocol.ts +0 -78
  196. package/src/ws/ws-transport-configurable.ts +0 -128
  197. package/src/ws/ws-transport.ts +0 -42
@@ -1,117 +0,0 @@
1
- /**
2
- * TransportTUI — interactive overlay for transport enable/disable settings.
3
- *
4
- * Arrow keys navigate the list, space toggles enabled/disabled, enter/esc closes.
5
- */
6
-
7
- import { Box, Text, useInput } from 'ink';
8
- import React, { useState, useCallback } from 'react';
9
-
10
- import type {
11
- IInteractiveSession,
12
- ITransportEntry,
13
- ITransportRegistryView,
14
- } from '@robota-sdk/agent-interface-transport';
15
-
16
- const TRANSPORT_NAME_WIDTH = 18;
17
-
18
- interface IEntryRowProps {
19
- entry: ITransportEntry<IInteractiveSession>;
20
- selected: boolean;
21
- }
22
-
23
- function TransportEntryRow({ entry, selected }: IEntryRowProps): React.ReactElement {
24
- const enabled = entry.config.enabled;
25
- const dot = enabled ? '●' : '○';
26
- const badge = enabled ? '[enabled] ' : '[disabled]';
27
- const portOpt = entry.config.options?.port;
28
- const portHint = typeof portOpt === 'number' ? `port: ${portOpt}` : '';
29
- return (
30
- <Box>
31
- <Text color={selected ? 'cyan' : undefined} bold={selected}>
32
- {`${dot} ${entry.transport.name.padEnd(TRANSPORT_NAME_WIDTH)} ${badge} ${portHint}`}
33
- </Text>
34
- </Box>
35
- );
36
- }
37
-
38
- type TKey = { upArrow: boolean; downArrow: boolean; escape: boolean; return: boolean };
39
-
40
- function useTransportInput(
41
- entries: ITransportEntry<IInteractiveSession>[],
42
- cursor: number,
43
- saving: boolean,
44
- registry: ITransportRegistryView<IInteractiveSession>,
45
- setCursor: (fn: (c: number) => number) => void,
46
- setSaving: (v: boolean) => void,
47
- onClose: () => void,
48
- refresh: () => void,
49
- ): void {
50
- useInput(
51
- useCallback(
52
- (_input: string, key: TKey) => {
53
- if (saving) return;
54
- if (key.upArrow) {
55
- setCursor((c) => Math.max(0, c - 1));
56
- return;
57
- }
58
- if (key.downArrow) {
59
- setCursor((c) => Math.min(entries.length - 1, c + 1));
60
- return;
61
- }
62
- if (key.escape || key.return) {
63
- onClose();
64
- return;
65
- }
66
- if (_input === ' ') {
67
- const entry = entries[cursor];
68
- if (!entry) return;
69
- setSaving(true);
70
- registry
71
- .setEnabled(entry.transport.name, !entry.config.enabled)
72
- .then(() => {
73
- refresh();
74
- setSaving(false);
75
- })
76
- .catch(() => setSaving(false));
77
- }
78
- },
79
- [saving, entries, cursor, registry, onClose, refresh, setCursor, setSaving],
80
- ),
81
- );
82
- }
83
-
84
- interface IProps {
85
- registry: ITransportRegistryView<IInteractiveSession>;
86
- onClose: () => void;
87
- }
88
-
89
- export default function TransportTUI({ registry, onClose }: IProps): React.ReactElement {
90
- const [entries, setEntries] = useState(() => registry.getAll());
91
- const [cursor, setCursor] = useState(0);
92
- const [saving, setSaving] = useState(false);
93
- const refresh = useCallback((): void => {
94
- setEntries(registry.getAll());
95
- }, [registry]);
96
-
97
- useTransportInput(entries, cursor, saving, registry, setCursor, setSaving, onClose, refresh);
98
-
99
- return (
100
- <Box flexDirection="column" paddingX={2} paddingY={1}>
101
- <Text bold>Settings › Transports</Text>
102
- <Box marginTop={1} flexDirection="column">
103
- {entries.map((entry, i) => (
104
- <TransportEntryRow key={entry.transport.name} entry={entry} selected={i === cursor} />
105
- ))}
106
- </Box>
107
- <Box marginTop={1}>
108
- <Text dimColor>↑↓ select space toggle enter/esc close</Text>
109
- </Box>
110
- {saving && (
111
- <Box marginTop={1}>
112
- <Text color="yellow">Saving…</Text>
113
- </Box>
114
- )}
115
- </Box>
116
- );
117
- }
@@ -1,483 +0,0 @@
1
- /**
2
- * TuiInteractionChannel — implements IInteractionChannel for the Ink TUI.
3
- *
4
- * Moves session lifecycle (InteractiveSession, CommandRegistry, TuiStateManager)
5
- * out of React hooks and into a plain TypeScript class.
6
- */
7
-
8
- import {
9
- createSystemMessage,
10
- createUserMessage,
11
- messageToHistoryEntry,
12
- } from '@robota-sdk/agent-core';
13
- import { InteractiveSession, CommandRegistry } from '@robota-sdk/agent-framework';
14
-
15
- import { createSessionInitPoller } from './flows/session-init-poller.js';
16
- import { CommandEffectQueue, type ICommandEffectQueue } from './hooks/command-effect-queue.js';
17
- import { applySystemCommandResult } from './hooks/useSlashRouting.js';
18
- import { generateSessionName } from './session-naming.js';
19
- import { TuiStateManager } from './tui-state-manager.js';
20
-
21
- import type { ISessionInitPoller, TSessionInitFailure } from './flows/session-init-poller.js';
22
- import type { IPermissionRequest } from './types.js';
23
- import type { IAIProvider, TPermissionMode, TSessionEndReason } from '@robota-sdk/agent-core';
24
- import type { TToolArgs } from '@robota-sdk/agent-core';
25
- import type {
26
- IBackgroundTaskRunner,
27
- ICommandHostAdapters,
28
- ICommandModule,
29
- TSubagentRunnerFactory,
30
- TShellExecFn,
31
- } from '@robota-sdk/agent-framework';
32
- import type {
33
- IActionRequest,
34
- IActionResponse,
35
- ICommandInfo,
36
- IExecutionDetailPage,
37
- IExecutionResult,
38
- IExecutionWorkspaceEvent,
39
- IInteractionChannel,
40
- IInteractiveSession,
41
- IInteractiveSessionStore,
42
- ITransportRegistryView,
43
- InteractionEvent,
44
- TPermissionResultValue,
45
- } from '@robota-sdk/agent-interface-transport';
46
-
47
- const SESSION_INIT_POLL_MS = 200;
48
- const SESSION_INIT_TIMEOUT_MS = 15000;
49
-
50
- export interface ITuiInteractionChannelOptions {
51
- cwd: string;
52
- provider: IAIProvider;
53
- permissionMode?: TPermissionMode;
54
- maxTurns?: number;
55
- sessionStore?: IInteractiveSessionStore;
56
- resumeSessionId?: string;
57
- forkSession?: boolean;
58
- sessionName?: string;
59
- onAutoNamed?: (name: string) => void;
60
- backgroundTaskRunners?: IBackgroundTaskRunner[];
61
- subagentRunnerFactory?: TSubagentRunnerFactory;
62
- commandModules?: readonly ICommandModule[];
63
- commandHostAdapters?: ICommandHostAdapters;
64
- shellExec?: TShellExecFn;
65
- transportRegistry?: ITransportRegistryView<IInteractiveSession>;
66
- language?: string;
67
- reloadPluginCommandSource?: (registry: CommandRegistry) => void;
68
- agentName?: string;
69
- systemPrompt?: string;
70
- appendSystemPrompt?: string;
71
- allowedTools?: string[];
72
- deniedTools?: string[];
73
- }
74
-
75
- export class TuiInteractionChannel implements IInteractionChannel {
76
- readonly stateManager: TuiStateManager;
77
-
78
- private readonly interactiveSession: InteractiveSession;
79
- private readonly registry: CommandRegistry;
80
- private readonly commandEffectQueue: ICommandEffectQueue;
81
- private readonly opts: ITuiInteractionChannelOptions;
82
-
83
- private submitHandler: ((text: string) => Promise<void>) | null = null;
84
- private actionQueue: Array<{
85
- action: IActionRequest;
86
- resolve: (response: IActionResponse) => void;
87
- }> = [];
88
- private processingAction = false;
89
-
90
- permissionRequest: IPermissionRequest | null = null;
91
- pendingAction: IActionRequest | null = null;
92
- availableCommands: ICommandInfo[] = [];
93
- isShuttingDown = false;
94
- sessionName: string | undefined;
95
-
96
- private autoNameTriggered = false;
97
- private sessionStarted = false;
98
- private initPoller: ISessionInitPoller | null = null;
99
- private permissionQueue: Array<{
100
- toolName: string;
101
- toolArgs: TToolArgs;
102
- resolve: (result: TPermissionResultValue) => void;
103
- }> = [];
104
- private processingPermission = false;
105
-
106
- /** Set by React hook to trigger re-render on state change */
107
- onChange: (() => void) | null = null;
108
-
109
- constructor(opts: ITuiInteractionChannelOptions) {
110
- this.opts = opts;
111
- this.sessionName = opts.sessionName;
112
- this.stateManager = new TuiStateManager();
113
- this.stateManager.onChange = () => this.onChange?.();
114
-
115
- this.interactiveSession = this.createSession();
116
- this.registry = this.createRegistry();
117
- this.commandEffectQueue = new CommandEffectQueue();
118
- }
119
-
120
- private createSession(): InteractiveSession {
121
- const opts = this.opts;
122
- return new InteractiveSession({
123
- cwd: opts.cwd,
124
- provider: opts.provider,
125
- permissionMode: opts.permissionMode,
126
- maxTurns: opts.maxTurns,
127
- permissionHandler: (toolName, toolArgs) => this.handlePermissionRequest(toolName, toolArgs),
128
- sessionStore: opts.sessionStore,
129
- resumeSessionId: opts.resumeSessionId,
130
- forkSession: opts.forkSession,
131
- sessionName: opts.sessionName,
132
- backgroundTaskRunners: opts.backgroundTaskRunners,
133
- subagentRunnerFactory: opts.subagentRunnerFactory,
134
- commandModules: opts.commandModules,
135
- commandHostAdapters: opts.commandHostAdapters,
136
- shellExec: opts.shellExec,
137
- language: opts.language,
138
- agentName: opts.agentName,
139
- systemPrompt: opts.systemPrompt,
140
- appendSystemPrompt: opts.appendSystemPrompt,
141
- allowedTools: opts.allowedTools,
142
- deniedTools: opts.deniedTools,
143
- });
144
- }
145
-
146
- private createRegistry(): CommandRegistry {
147
- const registry = new CommandRegistry();
148
- for (const module of this.opts.commandModules ?? []) {
149
- registry.addModule(module);
150
- }
151
- this.opts.reloadPluginCommandSource?.(registry);
152
- return registry;
153
- }
154
-
155
- // ── IInteractionChannel ──────────────────────────────────────
156
-
157
- onSubmit(handler: (text: string) => Promise<void>): void {
158
- this.submitHandler = handler;
159
- }
160
-
161
- write(_event: InteractionEvent): void {
162
- // Intentionally unused in TUI direct-wiring mode.
163
- // TuiInteractionChannel subscribes to session events directly via start() →
164
- // wireSessionEvents(), not through the IInteractionChannel event protocol used
165
- // by createInteractiveRuntime. The two paths are mutually exclusive.
166
- }
167
-
168
- async requestAction(action: IActionRequest): Promise<IActionResponse> {
169
- return new Promise<IActionResponse>((resolve) => {
170
- this.actionQueue.push({ action, resolve });
171
- this.processNextAction();
172
- });
173
- }
174
-
175
- setAvailableCommands(commands: ICommandInfo[]): void {
176
- this.availableCommands = commands;
177
- this.onChange?.();
178
- }
179
-
180
- setBusy(busy: boolean): void {
181
- this.stateManager.onThinking(busy);
182
- }
183
-
184
- async start(): Promise<void> {
185
- if (this.sessionStarted) return;
186
- this.sessionStarted = true;
187
- this.wireSessionEvents();
188
- this.syncRestoredHistory();
189
- this.startInitCheck();
190
-
191
- if (this.opts.transportRegistry) {
192
- await this.opts.transportRegistry.startAll(this.interactiveSession);
193
- }
194
- }
195
-
196
- async stop(): Promise<void> {
197
- this.onChange = null;
198
- this.sessionStarted = false;
199
- this.stopInitCheck();
200
- if (this.opts.transportRegistry) {
201
- await this.opts.transportRegistry.stopAll();
202
- }
203
- }
204
-
205
- // ── Additional methods for App.tsx ───────────────────────────
206
-
207
- getSession(): InteractiveSession {
208
- return this.interactiveSession;
209
- }
210
-
211
- getRegistry(): CommandRegistry {
212
- return this.registry;
213
- }
214
-
215
- getCommandEffectQueue(): ICommandEffectQueue {
216
- return this.commandEffectQueue;
217
- }
218
-
219
- abort(): void {
220
- this.stateManager.setAborting(true);
221
- this.interactiveSession.abort();
222
- }
223
-
224
- cancelQueue(): void {
225
- this.interactiveSession.cancelQueue();
226
- this.stateManager.setPendingPrompt(null);
227
- }
228
-
229
- async shutdown(options?: { reason?: TSessionEndReason }): Promise<void> {
230
- if (this.isShuttingDown) return;
231
- this.isShuttingDown = true;
232
- this.stateManager.addEntry(messageToHistoryEntry(createSystemMessage('Shutting down...')));
233
- this.onChange?.();
234
- await this.interactiveSession.shutdown({
235
- reason: options?.reason ?? 'prompt_input_exit',
236
- message: 'CLI shutdown',
237
- });
238
- }
239
-
240
- selectExecutionWorkspaceEntry(entryId: string): void {
241
- this.stateManager.selectExecutionWorkspaceEntry(entryId);
242
- }
243
-
244
- async readExecutionWorkspaceDetail(entryId: string): Promise<IExecutionDetailPage> {
245
- return this.interactiveSession.readExecutionWorkspaceDetail(entryId);
246
- }
247
-
248
- async sendAgentJob(jobId: string, input: string): Promise<void> {
249
- await this.interactiveSession.sendAgentJob(jobId, input);
250
- }
251
-
252
- setSessionName(name: string): void {
253
- this.sessionName = name;
254
- this.interactiveSession.setName(name);
255
- this.onChange?.();
256
- }
257
-
258
- resolveAction(response: IActionResponse): void {
259
- const pending = this.actionQueue[0];
260
- if (!pending) return;
261
- this.actionQueue.shift();
262
- this.processingAction = false;
263
- this.pendingAction = null;
264
- this.onChange?.();
265
- pending.resolve(response);
266
- this.processNextAction();
267
- }
268
-
269
- async handleInput(input: string): Promise<void> {
270
- if (!input.startsWith('/')) {
271
- await this.interactiveSession.submit(input);
272
- this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());
273
- return;
274
- }
275
- await this.handleSlashCommand(input);
276
- }
277
-
278
- private async handleSlashCommand(input: string): Promise<void> {
279
- const parts = input.slice(1).split(/\s+/);
280
- const cmd = parts[0]?.toLowerCase() ?? '';
281
- const args = parts.slice(1).join(' ');
282
-
283
- const result = await this.interactiveSession.executeCommand(cmd, args);
284
- if (result) {
285
- if (result.effects?.some((effect) => effect.type === 'session-execution-started')) {
286
- this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());
287
- return;
288
- }
289
- applySystemCommandResult(
290
- result,
291
- this.interactiveSession,
292
- this.registry,
293
- this.stateManager,
294
- this.commandEffectQueue,
295
- this.opts.reloadPluginCommandSource,
296
- );
297
- return;
298
- }
299
-
300
- this.stateManager.addEntry(
301
- messageToHistoryEntry(createSystemMessage(`Unknown command "/${cmd}". Type /help for help.`)),
302
- );
303
- }
304
-
305
- // ── Private helpers ──────────────────────────────────────────
306
-
307
- private processNextAction(): void {
308
- if (this.processingAction) return;
309
- const next = this.actionQueue[0];
310
- if (!next) {
311
- this.pendingAction = null;
312
- this.onChange?.();
313
- return;
314
- }
315
- this.processingAction = true;
316
- this.pendingAction = next.action;
317
- this.onChange?.();
318
- }
319
-
320
- private handlePermissionRequest(
321
- toolName: string,
322
- toolArgs: TToolArgs,
323
- ): Promise<TPermissionResultValue> {
324
- return new Promise<TPermissionResultValue>((resolve) => {
325
- this.permissionQueue.push({ toolName, toolArgs, resolve });
326
- this.processNextPermission();
327
- });
328
- }
329
-
330
- private processNextPermission(): void {
331
- if (this.processingPermission) return;
332
- const next = this.permissionQueue[0];
333
- if (!next) {
334
- this.permissionRequest = null;
335
- this.onChange?.();
336
- return;
337
- }
338
- this.processingPermission = true;
339
- this.permissionRequest = {
340
- toolName: next.toolName,
341
- toolArgs: next.toolArgs,
342
- resolve: (result) => {
343
- this.permissionQueue.shift();
344
- this.processingPermission = false;
345
- this.permissionRequest = null;
346
- next.resolve(result);
347
- setTimeout(() => this.processNextPermission(), 0);
348
- },
349
- };
350
- this.onChange?.();
351
- }
352
-
353
- private wireSessionEvents(): void {
354
- const session = this.interactiveSession;
355
- const manager = this.stateManager;
356
-
357
- const onUserMessage = (content: string): void => {
358
- this.handleAutoNaming(content);
359
- manager.addEntry(messageToHistoryEntry(createUserMessage(content)));
360
- };
361
- const onComplete = (result: IExecutionResult): void => {
362
- manager.onComplete(result);
363
- manager.syncHistory(session.getFullHistory());
364
- };
365
- const onError = (): void => {
366
- manager.onError();
367
- manager.syncHistory(session.getFullHistory());
368
- };
369
- const onCompact = (): void => {
370
- manager.syncHistory(session.getFullHistory());
371
- };
372
- const onSkillActivation = (): void => {
373
- manager.syncHistory(session.getFullHistory());
374
- };
375
- const onMemoryEvent = (): void => {
376
- manager.syncHistory(session.getFullHistory());
377
- };
378
- const onExecutionWorkspaceEvent = (event: IExecutionWorkspaceEvent): void => {
379
- manager.syncExecutionWorkspaceSnapshot(event.snapshot);
380
- };
381
-
382
- session.on('user_message', onUserMessage);
383
- session.on('text_delta', manager.onTextDelta);
384
- session.on('tool_start', manager.onToolStart);
385
- session.on('tool_end', manager.onToolEnd);
386
- session.on('thinking', manager.onThinking);
387
- session.on('complete', onComplete);
388
- session.on('interrupted', manager.onInterrupted);
389
- session.on('error', onError);
390
- session.on('context_update', manager.onContextUpdate);
391
- session.on('compact', onCompact);
392
- session.on('skill_activation', onSkillActivation);
393
- session.on('memory_event', onMemoryEvent);
394
- session.on('execution_workspace_event', onExecutionWorkspaceEvent);
395
- }
396
-
397
- private handleAutoNaming(content: string): void {
398
- if (this.autoNameTriggered) return;
399
- if (this.opts.sessionName || this.interactiveSession.getName()) return;
400
- this.autoNameTriggered = true;
401
- generateSessionName(this.opts.provider, content)
402
- .then((name) => {
403
- this.interactiveSession.setName(name);
404
- this.sessionName = name;
405
- this.opts.onAutoNamed?.(name);
406
- this.onChange?.();
407
- })
408
- .catch(() => {
409
- this.autoNameTriggered = false;
410
- });
411
- }
412
-
413
- private syncRestoredHistory(): void {
414
- if (this.stateManager.history.length === 0) {
415
- const restored = this.interactiveSession.getFullHistory();
416
- if (restored.length > 0) {
417
- this.stateManager.syncHistory(restored);
418
- }
419
- }
420
- }
421
-
422
- private startInitCheck(): void {
423
- this.initPoller = createSessionInitPoller({
424
- check: () => this.runInitCheck(),
425
- intervalMs: SESSION_INIT_POLL_MS,
426
- timeoutMs: SESSION_INIT_TIMEOUT_MS,
427
- onReady: () => undefined,
428
- onFailure: (failure) => this.onInitFailure(failure),
429
- });
430
- this.initPoller.start();
431
- }
432
-
433
- /** Throws while the session is not ready; the init poller classifies the error. */
434
- private runInitCheck(): void {
435
- const ctx = this.interactiveSession.getContextState();
436
- this.stateManager.setContextState({
437
- percentage: ctx.usedPercentage,
438
- usedTokens: ctx.usedTokens,
439
- maxTokens: ctx.maxTokens,
440
- });
441
- const restored = this.interactiveSession.getFullHistory();
442
- if (restored.length > 0) {
443
- this.stateManager.syncHistory(restored);
444
- }
445
- this.syncExecutionWorkspace();
446
- }
447
-
448
- private onInitFailure(failure: TSessionInitFailure): void {
449
- const message =
450
- failure.kind === 'timeout'
451
- ? `Session initialization timed out after ${SESSION_INIT_TIMEOUT_MS / 1000}s${
452
- failure.lastError ? ` (last error: ${failure.lastError.message})` : ''
453
- }`
454
- : `Session initialization failed: ${failure.error.message}`;
455
- this.stateManager.onError();
456
- this.stateManager.addEntry({
457
- id: `session-init-error-${Date.now()}`,
458
- timestamp: new Date(),
459
- category: 'event',
460
- type: 'session-init-error',
461
- data: { message },
462
- });
463
- }
464
-
465
- private stopInitCheck(): void {
466
- this.initPoller?.stop();
467
- this.initPoller = null;
468
- }
469
-
470
- private syncExecutionWorkspace(): void {
471
- try {
472
- // allow-fallback: session may not be initialized yet; swallow until ready
473
- this.stateManager.syncExecutionWorkspaceSnapshot(
474
- this.interactiveSession.getExecutionWorkspaceSnapshot({
475
- selectedEntryId: this.stateManager.selectedExecutionEntryId,
476
- }),
477
- );
478
- } catch {
479
- // allow-fallback: session may not be initialized yet; swallow until ready
480
- /* Session not initialized yet */
481
- }
482
- }
483
- }
@@ -1,14 +0,0 @@
1
- import { Box, Text } from 'ink';
2
- import React from 'react';
3
-
4
- interface IProps {
5
- message: string;
6
- }
7
-
8
- export default function UpdateNotice({ message }: IProps): React.ReactElement {
9
- return (
10
- <Box paddingX={1} marginBottom={1}>
11
- <Text color="yellow">{message}</Text>
12
- </Box>
13
- );
14
- }
@@ -1,39 +0,0 @@
1
- import { formatTokenCount } from '@robota-sdk/agent-core';
2
- import { Box, Text } from 'ink';
3
- import React from 'react';
4
-
5
- import type { IHistoryEntry } from '@robota-sdk/agent-core';
6
- import type { IUsageSnapshot } from '@robota-sdk/agent-interface-transport';
7
-
8
- const TOKEN_COMPACT_THRESHOLD = 1000;
9
-
10
- export default function UsageSummaryEntry({ entry }: { entry: IHistoryEntry }): React.ReactElement {
11
- const usage = entry.data as IUsageSnapshot | undefined;
12
- if (!usage) return <></>;
13
- const prompt = usage.promptTokens !== undefined ? formatUsageTokenCount(usage.promptTokens) : '?';
14
- const completion =
15
- usage.completionTokens !== undefined ? formatUsageTokenCount(usage.completionTokens) : '?';
16
- const total = formatUsageTokenCount(usage.totalTokens);
17
- const context = `${Math.round(usage.contextUsedPercentage)}% (${formatTokenCount(
18
- usage.contextUsedTokens,
19
- )}/${formatTokenCount(usage.contextMaxTokens)})`;
20
- const costLabel = usage.costStatus === 'unknown' ? 'cost unknown' : `cost ${usage.costStatus}`;
21
-
22
- return (
23
- <Box flexDirection="column" marginBottom={1}>
24
- <Box>
25
- <Text color="white" bold>
26
- Usage:{' '}
27
- </Text>
28
- <Text dimColor>
29
- {usage.kind} {total} tokens (in {prompt} / out {completion}) · Context {context} ·{' '}
30
- {costLabel}
31
- </Text>
32
- </Box>
33
- </Box>
34
- );
35
- }
36
-
37
- function formatUsageTokenCount(tokens: number): string {
38
- return tokens < TOKEN_COMPACT_THRESHOLD ? tokens.toLocaleString() : formatTokenCount(tokens);
39
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * WaveText — renders text with a subtle wave color animation.
3
- * Groups of 3-4 characters share the same color, creating a soft flowing effect.
4
- * Colors stay in a narrow range (dim grays) to avoid harsh contrast.
5
- */
6
-
7
- import { Text } from 'ink';
8
- import React, { useState, useEffect } from 'react';
9
-
10
- // Subtle gray tones — minimal contrast, soft wave
11
- const WAVE_COLORS = ['#666666', '#888888', '#aaaaaa', '#888888'] as const;
12
- const INTERVAL_MS = 400;
13
- const CHARS_PER_GROUP = 4;
14
-
15
- interface IProps {
16
- text: string;
17
- }
18
-
19
- export default function WaveText({ text }: IProps): React.ReactElement {
20
- const [tick, setTick] = useState(0);
21
-
22
- useEffect(() => {
23
- const timer = setInterval(() => {
24
- setTick((prev) => prev + 1);
25
- }, INTERVAL_MS);
26
- return () => clearInterval(timer);
27
- }, []);
28
-
29
- const chars = [...text];
30
-
31
- return (
32
- <Text>
33
- {chars.map((char, i) => {
34
- const group = Math.floor(i / CHARS_PER_GROUP);
35
- const colorIndex = (tick + group) % WAVE_COLORS.length;
36
- return (
37
- <Text key={i} color={WAVE_COLORS[colorIndex]}>
38
- {char}
39
- </Text>
40
- );
41
- })}
42
- </Text>
43
- );
44
- }