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