@robota-sdk/agent-transport 3.0.0-beta.75 → 3.0.0-beta.77

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 (231) hide show
  1. package/LICENSE +661 -21
  2. package/README.md +17 -14
  3. package/dist/node/headless/index.cjs +1 -1
  4. package/dist/node/headless/index.d.ts +1 -1
  5. package/dist/node/headless/index.js +1 -1
  6. package/dist/node/{headless-mRYilLfC.js → headless-DG_MEbf0.js} +7 -4
  7. package/dist/node/headless-DG_MEbf0.js.map +1 -0
  8. package/dist/node/headless-xq77JBq0.cjs +18 -0
  9. package/dist/node/{index-E8Gx4-lc.d.ts → index-CrJ2Lhn3.d.ts} +16 -3
  10. package/dist/node/index-CrJ2Lhn3.d.ts.map +1 -0
  11. package/dist/node/index-JIvzrtaA.d.ts +52 -0
  12. package/dist/node/index-JIvzrtaA.d.ts.map +1 -0
  13. package/dist/node/{index-CYl7ksS6.d.ts → index-JTD_xtEQ.d.ts} +15 -2
  14. package/dist/node/index-JTD_xtEQ.d.ts.map +1 -0
  15. package/dist/node/index-y_HBOfzO.d.ts +52 -0
  16. package/dist/node/index-y_HBOfzO.d.ts.map +1 -0
  17. package/dist/node/index.cjs +1 -1
  18. package/dist/node/index.d.ts +10 -9
  19. package/dist/node/index.d.ts.map +1 -1
  20. package/dist/node/index.js +1 -1
  21. package/dist/node/index.js.map +1 -1
  22. package/dist/node/programmatic/index.cjs +1 -0
  23. package/dist/node/programmatic/index.d.ts +2 -0
  24. package/dist/node/programmatic/index.js +1 -0
  25. package/dist/node/programmatic-6wLf68qJ.cjs +1 -0
  26. package/dist/node/programmatic-70dxIXtS.js +2 -0
  27. package/dist/node/programmatic-70dxIXtS.js.map +1 -0
  28. package/dist/node/testing/index.cjs +1 -1
  29. package/dist/node/testing/index.d.ts +2 -21
  30. package/dist/node/testing/index.js +1 -2
  31. package/package.json +15 -71
  32. package/src/__tests__/programmatic/programmatic-ask-user.test.ts +32 -0
  33. package/src/__tests__/programmatic/programmatic-driver.test.ts +107 -0
  34. package/src/__tests__/programmatic/programmatic-flows.test.ts +140 -0
  35. package/src/__tests__/transport-registry.stop-all.test.ts +53 -0
  36. package/src/headless/HeadlessInteractionChannel.ts +22 -5
  37. package/src/headless/__tests__/headless-goal-runner.test.ts +108 -0
  38. package/src/headless/__tests__/headless-runner.test.ts +2 -1
  39. package/src/headless/headless-runner.ts +67 -1
  40. package/src/headless/headless-stream-json.ts +1 -1
  41. package/src/headless/print-terminal.ts +1 -0
  42. package/src/index.ts +2 -5
  43. package/src/programmatic/ProgrammaticInteractionChannel.ts +82 -0
  44. package/src/programmatic/createProgrammaticAgent.ts +71 -0
  45. package/src/programmatic/index.ts +5 -0
  46. package/src/testing/index.ts +7 -4
  47. package/src/transport-registry.ts +15 -12
  48. package/dist/node/headless-CT2ibQnr.cjs +0 -15
  49. package/dist/node/headless-mRYilLfC.js.map +0 -1
  50. package/dist/node/http/index.cjs +0 -1
  51. package/dist/node/http/index.d.ts +0 -2
  52. package/dist/node/http/index.js +0 -1
  53. package/dist/node/http-2Jiuflc1.js +0 -2
  54. package/dist/node/http-2Jiuflc1.js.map +0 -1
  55. package/dist/node/http-CBAvefLw.cjs +0 -1
  56. package/dist/node/index-BNccqSpv.d.ts +0 -86
  57. package/dist/node/index-BNccqSpv.d.ts.map +0 -1
  58. package/dist/node/index-BUhHIf7X.d.ts +0 -86
  59. package/dist/node/index-BUhHIf7X.d.ts.map +0 -1
  60. package/dist/node/index-BnAGE-u9.d.ts +0 -33
  61. package/dist/node/index-BnAGE-u9.d.ts.map +0 -1
  62. package/dist/node/index-BrQ4gGw0.d.ts +0 -213
  63. package/dist/node/index-BrQ4gGw0.d.ts.map +0 -1
  64. package/dist/node/index-CYl7ksS6.d.ts.map +0 -1
  65. package/dist/node/index-CoeBF21y.d.ts +0 -213
  66. package/dist/node/index-CoeBF21y.d.ts.map +0 -1
  67. package/dist/node/index-DHt-2VQ-.d.ts +0 -46
  68. package/dist/node/index-DHt-2VQ-.d.ts.map +0 -1
  69. package/dist/node/index-DMwKN5Le.d.ts +0 -33
  70. package/dist/node/index-DMwKN5Le.d.ts.map +0 -1
  71. package/dist/node/index-E8Gx4-lc.d.ts.map +0 -1
  72. package/dist/node/index-c0M42fsA.d.ts +0 -46
  73. package/dist/node/index-c0M42fsA.d.ts.map +0 -1
  74. package/dist/node/mcp/index.cjs +0 -1
  75. package/dist/node/mcp/index.d.ts +0 -2
  76. package/dist/node/mcp/index.js +0 -1
  77. package/dist/node/mcp-BOglBJNy.cjs +0 -1
  78. package/dist/node/mcp-D3BBVK7C.js +0 -2
  79. package/dist/node/mcp-D3BBVK7C.js.map +0 -1
  80. package/dist/node/rolldown-runtime-CMqjfN_6.cjs +0 -1
  81. package/dist/node/testing/index.d.ts.map +0 -1
  82. package/dist/node/testing/index.js.map +0 -1
  83. package/dist/node/tui/index.cjs +0 -1
  84. package/dist/node/tui/index.d.ts +0 -2
  85. package/dist/node/tui/index.js +0 -1
  86. package/dist/node/tui-CcH5EsQh.js +0 -25
  87. package/dist/node/tui-CcH5EsQh.js.map +0 -1
  88. package/dist/node/tui-DznRbcku.cjs +0 -24
  89. package/dist/node/ws/index.cjs +0 -1
  90. package/dist/node/ws/index.d.ts +0 -2
  91. package/dist/node/ws/index.js +0 -1
  92. package/dist/node/ws-Dc2RUwVs.js +0 -2
  93. package/dist/node/ws-Dc2RUwVs.js.map +0 -1
  94. package/dist/node/ws-QNMQn5kg.cjs +0 -1
  95. package/src/http/__tests__/http-transport.test.ts +0 -55
  96. package/src/http/__tests__/routes.test.ts +0 -168
  97. package/src/http/http-transport.ts +0 -41
  98. package/src/http/index.ts +0 -4
  99. package/src/http/routes.ts +0 -152
  100. package/src/mcp/__tests__/mcp-server.test.ts +0 -66
  101. package/src/mcp/__tests__/mcp-transport.test.ts +0 -46
  102. package/src/mcp/index.ts +0 -4
  103. package/src/mcp/mcp-server.ts +0 -163
  104. package/src/mcp/mcp-transport.ts +0 -48
  105. package/src/testing/__tests__/scripted-provider.test.ts +0 -73
  106. package/src/testing/scripted-provider.ts +0 -73
  107. package/src/tui/App.tsx +0 -491
  108. package/src/tui/BackgroundTaskPanel.tsx +0 -36
  109. package/src/tui/CjkTextInput.tsx +0 -199
  110. package/src/tui/ConfirmPrompt.tsx +0 -70
  111. package/src/tui/ContextWarningBanner.tsx +0 -34
  112. package/src/tui/ExecutionWorkspaceDetailPane.tsx +0 -64
  113. package/src/tui/ExecutionWorkspaceSwitcher.tsx +0 -187
  114. package/src/tui/InputArea.tsx +0 -310
  115. package/src/tui/InteractivePrompt.tsx +0 -59
  116. package/src/tui/ListPicker.tsx +0 -95
  117. package/src/tui/MenuSelect.tsx +0 -104
  118. package/src/tui/MessageList.tsx +0 -284
  119. package/src/tui/PermissionPrompt.tsx +0 -86
  120. package/src/tui/PluginTUI.tsx +0 -258
  121. package/src/tui/SessionPicker.tsx +0 -68
  122. package/src/tui/SessionStatusBar.tsx +0 -73
  123. package/src/tui/SlashAutocomplete.tsx +0 -110
  124. package/src/tui/StatusBar.tsx +0 -236
  125. package/src/tui/StreamingIndicator.tsx +0 -93
  126. package/src/tui/TextPrompt.tsx +0 -81
  127. package/src/tui/ToolCommandOutput.tsx +0 -39
  128. package/src/tui/ToolDiffBlock.tsx +0 -32
  129. package/src/tui/TransportTUI.tsx +0 -117
  130. package/src/tui/TuiInteractionChannel.ts +0 -495
  131. package/src/tui/UpdateNotice.tsx +0 -14
  132. package/src/tui/UsageSummaryEntry.tsx +0 -39
  133. package/src/tui/WaveText.tsx +0 -44
  134. package/src/tui/__tests__/InteractivePrompt.test.tsx +0 -82
  135. package/src/tui/__tests__/ListPicker.test.tsx +0 -159
  136. package/src/tui/__tests__/MenuSelect.test.tsx +0 -103
  137. package/src/tui/__tests__/PluginTUI.test.tsx +0 -167
  138. package/src/tui/__tests__/SlashAutocomplete.test.tsx +0 -140
  139. package/src/tui/__tests__/TextPrompt.test.tsx +0 -98
  140. package/src/tui/__tests__/TuiInteractionChannel.display-contract.test.ts +0 -239
  141. package/src/tui/__tests__/TuiInteractionChannel.lifecycle.test.ts +0 -297
  142. package/src/tui/__tests__/TuiInteractionChannel.requestAction.test.ts +0 -124
  143. package/src/tui/__tests__/UpdateNotice.test.tsx +0 -15
  144. package/src/tui/__tests__/abort-after-permission.test.tsx +0 -169
  145. package/src/tui/__tests__/abort-streaming-e2e.test.tsx +0 -183
  146. package/src/tui/__tests__/background-task-panel.test.tsx +0 -53
  147. package/src/tui/__tests__/background-task-row-format.test.ts +0 -59
  148. package/src/tui/__tests__/channel-factory-integration.test.ts +0 -138
  149. package/src/tui/__tests__/cjk-text-input-flow.test.ts +0 -109
  150. package/src/tui/__tests__/cjk-text-input.test.ts +0 -191
  151. package/src/tui/__tests__/command-effect-handler.test.ts +0 -127
  152. package/src/tui/__tests__/command-output-summary.test.ts +0 -95
  153. package/src/tui/__tests__/compact-event-bridge.test.ts +0 -20
  154. package/src/tui/__tests__/confirm-permission-flow.test.ts +0 -130
  155. package/src/tui/__tests__/confirm-prompt.test.tsx +0 -87
  156. package/src/tui/__tests__/execution-workspace-switcher.test.tsx +0 -110
  157. package/src/tui/__tests__/execution-workspace-view-model.test.ts +0 -93
  158. package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +0 -125
  159. package/src/tui/__tests__/input-area-flow.test.ts +0 -164
  160. package/src/tui/__tests__/message-list-rendering.test.tsx +0 -353
  161. package/src/tui/__tests__/prompt-queue.test.tsx +0 -255
  162. package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +0 -233
  163. package/src/tui/__tests__/pty/pty-driver.ts +0 -135
  164. package/src/tui/__tests__/pty/tui-pty.ptytest.ts +0 -61
  165. package/src/tui/__tests__/render-channel-options.test.ts +0 -32
  166. package/src/tui/__tests__/render-markdown.test.ts +0 -72
  167. package/src/tui/__tests__/selection-flow.test.ts +0 -61
  168. package/src/tui/__tests__/session-init-poller.test.ts +0 -102
  169. package/src/tui/__tests__/session-naming.test.ts +0 -64
  170. package/src/tui/__tests__/session-switch-channel.test.tsx +0 -307
  171. package/src/tui/__tests__/slash-routing-effects.test.ts +0 -228
  172. package/src/tui/__tests__/status-activity.test.ts +0 -71
  173. package/src/tui/__tests__/status-bar.test.tsx +0 -177
  174. package/src/tui/__tests__/streaming-indicator.test.tsx +0 -137
  175. package/src/tui/__tests__/text-prompt-flow.test.ts +0 -77
  176. package/src/tui/__tests__/tui-channel-init-failure.test.ts +0 -57
  177. package/src/tui/__tests__/tui-state-manager.test.ts +0 -401
  178. package/src/tui/background-task-row-format.ts +0 -53
  179. package/src/tui/command-interaction.ts +0 -9
  180. package/src/tui/command-output-summary.ts +0 -122
  181. package/src/tui/create-default-tui-cli-adapter.ts +0 -41
  182. package/src/tui/execution-workspace-view-model.ts +0 -123
  183. package/src/tui/flows/cjk-text-input-flow.ts +0 -285
  184. package/src/tui/flows/confirm-prompt-flow.ts +0 -45
  185. package/src/tui/flows/input-area-flow.ts +0 -189
  186. package/src/tui/flows/permission-prompt-flow.ts +0 -85
  187. package/src/tui/flows/selection-flow.ts +0 -126
  188. package/src/tui/flows/session-init-poller.ts +0 -77
  189. package/src/tui/flows/text-prompt-flow.ts +0 -98
  190. package/src/tui/hooks/command-effect-handler.ts +0 -97
  191. package/src/tui/hooks/command-effect-queue.ts +0 -39
  192. package/src/tui/hooks/side-effects-types.ts +0 -35
  193. package/src/tui/hooks/useAutocomplete.ts +0 -87
  194. package/src/tui/hooks/usePluginCallbacks.ts +0 -31
  195. package/src/tui/hooks/usePluginScreenData.ts +0 -85
  196. package/src/tui/hooks/useSideEffects.ts +0 -175
  197. package/src/tui/hooks/useSlashRouting.ts +0 -118
  198. package/src/tui/hooks/useStatusLineSettings.ts +0 -37
  199. package/src/tui/hooks/useTuiChannel.ts +0 -95
  200. package/src/tui/index.ts +0 -14
  201. package/src/tui/interactions/CommandConfirm.tsx +0 -36
  202. package/src/tui/interactions/CommandPicker.tsx +0 -77
  203. package/src/tui/interactions/__tests__/CommandConfirm.test.tsx +0 -124
  204. package/src/tui/interactions/__tests__/CommandPicker.test.tsx +0 -138
  205. package/src/tui/plugin-tui-handlers.ts +0 -163
  206. package/src/tui/render-markdown.ts +0 -130
  207. package/src/tui/render.tsx +0 -129
  208. package/src/tui/session-naming.ts +0 -33
  209. package/src/tui/status-activity.ts +0 -63
  210. package/src/tui/tui-cli-adapter-context.tsx +0 -13
  211. package/src/tui/tui-cli-adapter.ts +0 -25
  212. package/src/tui/tui-state-manager.ts +0 -226
  213. package/src/tui/tui-transport.ts +0 -35
  214. package/src/tui/types.ts +0 -15
  215. package/src/tui/utils/__tests__/edit-diff.test.ts +0 -426
  216. package/src/tui/utils/__tests__/paste-detection.test.ts +0 -116
  217. package/src/tui/utils/__tests__/paste-labels.test.ts +0 -46
  218. package/src/tui/utils/__tests__/tool-call-extractor.test.ts +0 -227
  219. package/src/tui/utils/__tests__/tool-diff-summary.test.ts +0 -104
  220. package/src/tui/utils/edit-diff.ts +0 -153
  221. package/src/tui/utils/paste-labels.ts +0 -9
  222. package/src/tui/utils/tool-call-extractor.ts +0 -92
  223. package/src/tui/utils/tool-diff-summary.ts +0 -75
  224. package/src/ws/__tests__/ws-handler.test.ts +0 -409
  225. package/src/ws/__tests__/ws-transport.test.ts +0 -53
  226. package/src/ws/index.ts +0 -13
  227. package/src/ws/ws-background-messages.ts +0 -170
  228. package/src/ws/ws-handler.ts +0 -280
  229. package/src/ws/ws-protocol.ts +0 -78
  230. package/src/ws/ws-transport-configurable.ts +0 -128
  231. package/src/ws/ws-transport.ts +0 -42
@@ -1,85 +0,0 @@
1
- import {
2
- applySelectionInput,
3
- getDirectionalSelectionInputAction,
4
- type ISelectionFlowState,
5
- type ISelectionInputKey,
6
- type TSelectionInputAction,
7
- } from './selection-flow.js';
8
-
9
- export const PERMISSION_PROMPT_OPTIONS = [
10
- 'Allow [y]',
11
- 'Allow always (this session) [s]',
12
- 'Allow always (this project) [p]',
13
- 'Deny [n]',
14
- ] as const;
15
-
16
- export type TPermissionPromptDecision = true | 'allow-session' | 'allow-project' | false;
17
- export type TPermissionPromptInputAction =
18
- | TSelectionInputAction
19
- | { type: 'shortcut'; index: number };
20
-
21
- export type TPermissionPromptEffect =
22
- | { type: 'none' }
23
- | { type: 'resolve'; decision: TPermissionPromptDecision };
24
-
25
- export function getPermissionPromptInputAction(
26
- input: string,
27
- key: ISelectionInputKey,
28
- ): TPermissionPromptInputAction | undefined {
29
- const action = getDirectionalSelectionInputAction({ ...key, escape: false });
30
- if (action !== undefined) {
31
- return action;
32
- }
33
- if (input === 'y' || input === '1') {
34
- return { type: 'shortcut', index: 0 };
35
- }
36
- if (input === 's' || input === 'a' || input === '2') {
37
- return { type: 'shortcut', index: 1 };
38
- }
39
- if (input === 'p' || input === '3') {
40
- return { type: 'shortcut', index: 2 };
41
- }
42
- if (input === 'n' || input === 'd' || input === '4') {
43
- return { type: 'shortcut', index: 3 };
44
- }
45
- return undefined;
46
- }
47
-
48
- export function applyPermissionPromptInput(
49
- state: ISelectionFlowState,
50
- action: TPermissionPromptInputAction,
51
- ): { state: ISelectionFlowState; effect: TPermissionPromptEffect } {
52
- if (state.resolved) {
53
- return { state, effect: { type: 'none' } };
54
- }
55
- if (typeof action !== 'string') {
56
- return resolvePermissionIndex(state, action.index);
57
- }
58
- const result = applySelectionInput(state, action, {
59
- itemCount: PERMISSION_PROMPT_OPTIONS.length,
60
- });
61
- if (result.effect.type !== 'select') {
62
- return { state: result.state, effect: { type: 'none' } };
63
- }
64
- return {
65
- state: result.state,
66
- effect: { type: 'resolve', decision: getPermissionDecision(result.effect.index) },
67
- };
68
- }
69
-
70
- function getPermissionDecision(index: number): TPermissionPromptDecision {
71
- if (index === 0) return true;
72
- if (index === 1) return 'allow-session';
73
- if (index === 2) return 'allow-project';
74
- return false;
75
- }
76
-
77
- function resolvePermissionIndex(
78
- state: ISelectionFlowState,
79
- index: number,
80
- ): { state: ISelectionFlowState; effect: TPermissionPromptEffect } {
81
- return {
82
- state: { ...state, selectedIndex: index, resolved: true },
83
- effect: { type: 'resolve', decision: getPermissionDecision(index) },
84
- };
85
- }
@@ -1,126 +0,0 @@
1
- export interface ISelectionFlowState {
2
- selectedIndex: number;
3
- scrollOffset: number;
4
- resolved: boolean;
5
- }
6
-
7
- export interface ISelectionInputKey {
8
- escape?: boolean;
9
- return?: boolean;
10
- upArrow?: boolean;
11
- downArrow?: boolean;
12
- leftArrow?: boolean;
13
- rightArrow?: boolean;
14
- }
15
-
16
- export type TSelectionInputAction = 'cancel' | 'select' | 'previous' | 'next';
17
-
18
- export type TSelectionEffect =
19
- | { type: 'none' }
20
- | { type: 'cancel' }
21
- | { type: 'select'; index: number };
22
-
23
- export interface ISelectionFlowOptions {
24
- itemCount: number;
25
- maxVisible?: number;
26
- wrap?: boolean;
27
- enabled?: boolean;
28
- }
29
-
30
- export function createSelectionFlowState(): ISelectionFlowState {
31
- return { selectedIndex: 0, scrollOffset: 0, resolved: false };
32
- }
33
-
34
- export function getVerticalSelectionInputAction(
35
- key: ISelectionInputKey,
36
- ): TSelectionInputAction | undefined {
37
- if (key.escape === true) return 'cancel';
38
- if (key.upArrow === true) return 'previous';
39
- if (key.downArrow === true) return 'next';
40
- if (key.return === true) return 'select';
41
- return undefined;
42
- }
43
-
44
- export function getDirectionalSelectionInputAction(
45
- key: ISelectionInputKey,
46
- ): TSelectionInputAction | undefined {
47
- if (key.escape === true) return 'cancel';
48
- if (key.leftArrow === true || key.upArrow === true) return 'previous';
49
- if (key.rightArrow === true || key.downArrow === true) return 'next';
50
- if (key.return === true) return 'select';
51
- return undefined;
52
- }
53
-
54
- export function applySelectionInput(
55
- state: ISelectionFlowState,
56
- action: TSelectionInputAction,
57
- options: ISelectionFlowOptions,
58
- ): { state: ISelectionFlowState; effect: TSelectionEffect } {
59
- if (state.resolved) {
60
- return { state, effect: { type: 'none' } };
61
- }
62
- if (action === 'cancel') {
63
- return { state: { ...state, resolved: true }, effect: { type: 'cancel' } };
64
- }
65
- if (options.enabled === false || options.itemCount === 0) {
66
- return { state, effect: { type: 'none' } };
67
- }
68
- if (action === 'select') {
69
- const index = clampIndex(state.selectedIndex, options.itemCount);
70
- return {
71
- state: { ...state, selectedIndex: index, resolved: true },
72
- effect: { type: 'select', index },
73
- };
74
- }
75
- const selectedIndex = moveSelection(state.selectedIndex, action, options);
76
- const scrollOffset = resolveScrollOffset(selectedIndex, state.scrollOffset, options);
77
- return { state: { ...state, selectedIndex, scrollOffset }, effect: { type: 'none' } };
78
- }
79
-
80
- export function normalizeSelectionState(
81
- state: ISelectionFlowState,
82
- options: ISelectionFlowOptions,
83
- ): ISelectionFlowState {
84
- if (options.itemCount === 0) {
85
- return { ...state, selectedIndex: 0, scrollOffset: 0 };
86
- }
87
- const selectedIndex = clampIndex(state.selectedIndex, options.itemCount);
88
- const scrollOffset = resolveScrollOffset(selectedIndex, state.scrollOffset, options);
89
- if (selectedIndex === state.selectedIndex && scrollOffset === state.scrollOffset) {
90
- return state;
91
- }
92
- return {
93
- ...state,
94
- selectedIndex,
95
- scrollOffset,
96
- };
97
- }
98
-
99
- function moveSelection(
100
- selectedIndex: number,
101
- action: TSelectionInputAction,
102
- options: ISelectionFlowOptions,
103
- ): number {
104
- if (action === 'previous') {
105
- if (options.wrap === true && selectedIndex === 0) return options.itemCount - 1;
106
- return Math.max(0, selectedIndex - 1);
107
- }
108
- if (options.wrap === true && selectedIndex === options.itemCount - 1) return 0;
109
- return Math.min(options.itemCount - 1, selectedIndex + 1);
110
- }
111
-
112
- function resolveScrollOffset(
113
- selectedIndex: number,
114
- scrollOffset: number,
115
- options: ISelectionFlowOptions,
116
- ): number {
117
- const maxVisible = options.maxVisible ?? options.itemCount;
118
- if (maxVisible <= 0) return 0;
119
- if (selectedIndex < scrollOffset) return selectedIndex;
120
- if (selectedIndex >= scrollOffset + maxVisible) return selectedIndex - maxVisible + 1;
121
- return Math.max(0, scrollOffset);
122
- }
123
-
124
- function clampIndex(index: number, itemCount: number): number {
125
- return Math.min(Math.max(index, 0), itemCount - 1);
126
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * Bounded polling helper for asynchronous session initialization.
3
- *
4
- * Distinguishes benign "not yet initialized" errors (retried until a timeout)
5
- * from real failures (surfaced immediately), so the TUI can show an error
6
- * instead of spinning forever.
7
- */
8
-
9
- export type TSessionInitFailure =
10
- | { kind: 'timeout'; lastError: Error | undefined }
11
- | { kind: 'error'; error: Error };
12
-
13
- export interface ISessionInitPollerOptions {
14
- /** Throws while the session is not ready; returns normally when ready. */
15
- check: () => void;
16
- intervalMs: number;
17
- timeoutMs: number;
18
- /** Returns true when an error means "keep polling". Defaults to /not initialized/i. */
19
- isBenignError?: (error: Error) => boolean;
20
- onReady: () => void;
21
- onFailure: (failure: TSessionInitFailure) => void;
22
- }
23
-
24
- export interface ISessionInitPoller {
25
- start(): void;
26
- stop(): void;
27
- }
28
-
29
- function defaultIsBenignError(error: Error): boolean {
30
- return /not initialized/i.test(error.message);
31
- }
32
-
33
- export function createSessionInitPoller(options: ISessionInitPollerOptions): ISessionInitPoller {
34
- const isBenign = options.isBenignError ?? defaultIsBenignError;
35
- let timer: ReturnType<typeof setInterval> | null = null;
36
- let elapsedMs = 0;
37
- let lastBenignError: Error | undefined;
38
-
39
- function stop(): void {
40
- if (timer !== null) {
41
- clearInterval(timer);
42
- timer = null;
43
- }
44
- }
45
-
46
- function tick(): void {
47
- elapsedMs += options.intervalMs;
48
- try {
49
- options.check();
50
- } catch (raw) {
51
- // allow-fallback: poller's purpose is to classify and route this error, never to swallow it
52
- const error = raw instanceof Error ? raw : new Error(String(raw));
53
- if (!isBenign(error)) {
54
- stop();
55
- options.onFailure({ kind: 'error', error });
56
- return;
57
- }
58
- lastBenignError = error;
59
- if (elapsedMs >= options.timeoutMs) {
60
- stop();
61
- options.onFailure({ kind: 'timeout', lastError: lastBenignError });
62
- }
63
- return;
64
- }
65
- stop();
66
- options.onReady();
67
- }
68
-
69
- return {
70
- start(): void {
71
- if (timer !== null) return;
72
- elapsedMs = 0;
73
- timer = setInterval(tick, options.intervalMs);
74
- },
75
- stop,
76
- };
77
- }
@@ -1,98 +0,0 @@
1
- export interface ITextPromptFlowState {
2
- value: string;
3
- error?: string;
4
- resolved: boolean;
5
- }
6
-
7
- export interface ITextPromptInputKey {
8
- escape?: boolean;
9
- return?: boolean;
10
- backspace?: boolean;
11
- delete?: boolean;
12
- ctrl?: boolean;
13
- meta?: boolean;
14
- }
15
-
16
- export type TTextPromptInputAction =
17
- | { type: 'cancel' }
18
- | { type: 'submit' }
19
- | { type: 'delete' }
20
- | { type: 'insert'; value: string };
21
-
22
- export type TTextPromptEffect =
23
- | { type: 'none' }
24
- | { type: 'cancel' }
25
- | { type: 'submit'; value: string };
26
-
27
- export interface ITextPromptFlowOptions {
28
- allowEmpty: boolean;
29
- validate?: (value: string) => string | undefined;
30
- }
31
-
32
- export function createTextPromptFlowState(): ITextPromptFlowState {
33
- return { value: '', resolved: false };
34
- }
35
-
36
- export function getTextPromptInputAction(
37
- input: string,
38
- key: ITextPromptInputKey,
39
- ): TTextPromptInputAction | undefined {
40
- if (key.escape === true) {
41
- return { type: 'cancel' };
42
- }
43
- if (key.return === true) {
44
- return { type: 'submit' };
45
- }
46
- if (key.backspace === true || key.delete === true) {
47
- return { type: 'delete' };
48
- }
49
- if (input && key.ctrl !== true && key.meta !== true) {
50
- return { type: 'insert', value: input };
51
- }
52
- return undefined;
53
- }
54
-
55
- export function applyTextPromptInput(
56
- state: ITextPromptFlowState,
57
- action: TTextPromptInputAction,
58
- options: ITextPromptFlowOptions,
59
- ): { state: ITextPromptFlowState; effect: TTextPromptEffect } {
60
- if (state.resolved) {
61
- return { state, effect: { type: 'none' } };
62
- }
63
- if (action.type === 'cancel') {
64
- return { state: { ...state, resolved: true }, effect: { type: 'cancel' } };
65
- }
66
- if (action.type === 'delete') {
67
- return {
68
- state: { ...state, value: state.value.slice(0, -1), error: undefined },
69
- effect: { type: 'none' },
70
- };
71
- }
72
- if (action.type === 'insert') {
73
- return {
74
- state: { ...state, value: state.value + action.value, error: undefined },
75
- effect: { type: 'none' },
76
- };
77
- }
78
- return submitTextPromptValue(state, options);
79
- }
80
-
81
- function submitTextPromptValue(
82
- state: ITextPromptFlowState,
83
- options: ITextPromptFlowOptions,
84
- ): { state: ITextPromptFlowState; effect: TTextPromptEffect } {
85
- const trimmed = state.value.trim();
86
- if (!trimmed && !options.allowEmpty) {
87
- const emptyError = options.validate?.(trimmed);
88
- return {
89
- state: emptyError ? { ...state, error: emptyError } : state,
90
- effect: { type: 'none' },
91
- };
92
- }
93
- const error = options.validate?.(trimmed);
94
- if (error !== undefined) {
95
- return { state: { ...state, error }, effect: { type: 'none' } };
96
- }
97
- return { state: { ...state, resolved: true }, effect: { type: 'submit', value: trimmed } };
98
- }
@@ -1,97 +0,0 @@
1
- import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
2
- import { isStatusLineCommandSettingsPatch } from '@robota-sdk/agent-framework';
3
-
4
- import type { ITuiCliAdapter } from '../tui-cli-adapter.js';
5
- import type { IHistoryEntry, TSessionEndReason } from '@robota-sdk/agent-core';
6
- import type {
7
- TCommandEffect,
8
- TStatusLineCommandSettingsPatch,
9
- } from '@robota-sdk/agent-interface-transport';
10
-
11
- export interface ICommandEffectHandlerDeps {
12
- addEntry: (entry: IHistoryEntry) => void;
13
- requestShutdown: (reason: TSessionEndReason, message: string) => void;
14
- openPluginTUI: () => void;
15
- openSessionPicker: () => void;
16
- openTransportTUI: () => void;
17
- openAgentSwitcher: () => void;
18
- renameSession: (name: string) => void;
19
- applyStatusLinePatch: (patch: TStatusLineCommandSettingsPatch) => boolean;
20
- cliAdapter: ITuiCliAdapter;
21
- }
22
-
23
- export function applyCommandEffects(
24
- effects: readonly TCommandEffect[],
25
- deps: ICommandEffectHandlerDeps,
26
- ): boolean {
27
- for (const effect of effects) {
28
- if (effect.type === 'language-change-requested') {
29
- applyLanguageEffect(effect.language, deps);
30
- return true;
31
- }
32
- if (effect.type === 'settings-reset-requested') {
33
- applySettingsResetEffect(deps);
34
- return true;
35
- }
36
- if (effect.type === 'session-exit-requested') {
37
- deps.requestShutdown(
38
- effect.reason ?? 'prompt_input_exit',
39
- effect.message ?? 'User requested exit',
40
- );
41
- return true;
42
- }
43
- if (effect.type === 'session-restart-requested') {
44
- deps.requestShutdown(effect.reason, effect.message);
45
- return true;
46
- }
47
- if (effect.type === 'plugin-tui-requested') {
48
- deps.openPluginTUI();
49
- return true;
50
- }
51
- if (effect.type === 'settings-tui-requested') {
52
- deps.openTransportTUI();
53
- return true;
54
- }
55
- if (effect.type === 'agent-switcher-requested') {
56
- deps.openAgentSwitcher();
57
- return true;
58
- }
59
- if (effect.type === 'session-picker-requested') {
60
- deps.openSessionPicker();
61
- return true;
62
- }
63
- if (effect.type === 'session-renamed') {
64
- deps.renameSession(effect.name);
65
- return true;
66
- }
67
- if (effect.type === 'statusline-settings-patch') {
68
- if (isStatusLineCommandSettingsPatch(effect.patch)) {
69
- return deps.applyStatusLinePatch(effect.patch);
70
- }
71
- }
72
- }
73
- return false;
74
- }
75
-
76
- function applyLanguageEffect(language: string, deps: ICommandEffectHandlerDeps): void {
77
- const settingsPath = deps.cliAdapter.getUserSettingsPath();
78
- const settings = deps.cliAdapter.readSettings(settingsPath);
79
- settings.language = language;
80
- deps.cliAdapter.writeSettings(settingsPath, settings);
81
- deps.addEntry(
82
- messageToHistoryEntry(createSystemMessage(`Language set to "${language}". Restarting...`)),
83
- );
84
- deps.requestShutdown('other', 'Language change restart');
85
- }
86
-
87
- function applySettingsResetEffect(deps: ICommandEffectHandlerDeps): void {
88
- const settingsPath = deps.cliAdapter.getUserSettingsPath();
89
- if (deps.cliAdapter.deleteSettings(settingsPath)) {
90
- deps.addEntry(
91
- messageToHistoryEntry(createSystemMessage(`Deleted ${settingsPath}. Exiting...`)),
92
- );
93
- } else {
94
- deps.addEntry(messageToHistoryEntry(createSystemMessage('No user settings found.')));
95
- }
96
- deps.requestShutdown('other', 'Reset settings restart');
97
- }
@@ -1,39 +0,0 @@
1
- import type { ICommandInteraction, TCommandEffect } from '@robota-sdk/agent-interface-transport';
2
-
3
- export type TQueuedCommandState =
4
- | {
5
- type: 'interaction';
6
- interaction: ICommandInteraction;
7
- }
8
- | {
9
- type: 'effects';
10
- effects: readonly TCommandEffect[];
11
- };
12
-
13
- export interface ICommandEffectQueue {
14
- enqueueInteraction(interaction: ICommandInteraction): void;
15
- enqueueEffects(effects: readonly TCommandEffect[]): void;
16
- drain(): TQueuedCommandState | undefined;
17
- clear(): void;
18
- }
19
-
20
- export class CommandEffectQueue implements ICommandEffectQueue {
21
- private readonly queue: TQueuedCommandState[] = [];
22
-
23
- enqueueInteraction(interaction: ICommandInteraction): void {
24
- this.queue.push({ type: 'interaction', interaction });
25
- }
26
-
27
- enqueueEffects(effects: readonly TCommandEffect[]): void {
28
- if (effects.length === 0) return;
29
- this.queue.push({ type: 'effects', effects: [...effects] });
30
- }
31
-
32
- drain(): TQueuedCommandState | undefined {
33
- return this.queue.shift();
34
- }
35
-
36
- clear(): void {
37
- this.queue.length = 0;
38
- }
39
- }
@@ -1,35 +0,0 @@
1
- import type { ICommandEffectQueue } from './command-effect-queue.js';
2
- import type { IHistoryEntry } from '@robota-sdk/agent-core';
3
- import type { InteractiveSession } from '@robota-sdk/agent-framework';
4
- import type {
5
- IStatusLineCommandSettings as TStatusLineSettings,
6
- TCommandInteractionPrompt as TInteractivePrompt,
7
- } from '@robota-sdk/agent-interface-transport';
8
-
9
- export type { TInteractivePrompt, TStatusLineSettings };
10
-
11
- export interface IUseSideEffectsOptions {
12
- cwd: string;
13
- providerOverride?: string | undefined;
14
- interactiveSession: InteractiveSession;
15
- commandEffectQueue: ICommandEffectQueue;
16
- addEntry: (entry: IHistoryEntry) => void;
17
- baseHandleSubmit: (input: string) => Promise<void>;
18
- setSessionName: (name: string) => void;
19
- setStatusLineSettings: (settings: TStatusLineSettings) => void;
20
- showSessionPickerOnStart?: boolean;
21
- openAgentSwitcher?: () => void;
22
- }
23
-
24
- export interface IUseSideEffectsResult {
25
- handleSubmit: (input: string) => Promise<void>;
26
- pendingInteractionPrompt: TInteractivePrompt | null;
27
- showPluginTUI: boolean;
28
- showSessionPicker: boolean;
29
- showTransportTUI: boolean;
30
- setShowPluginTUI: (show: boolean) => void;
31
- setShowSessionPicker: (show: boolean) => void;
32
- setShowTransportTUI: (show: boolean) => void;
33
- handleInteractionSubmit: (value: string) => Promise<void>;
34
- handleInteractionCancel: () => void;
35
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * Slash command autocomplete hook.
3
- * Extracted from InputArea.tsx for single-responsibility.
4
- */
5
-
6
- import React, { useState, useMemo } from 'react';
7
-
8
- import type { CommandRegistry } from '@robota-sdk/agent-framework';
9
- import type { ICommand } from '@robota-sdk/agent-interface-transport';
10
-
11
- /** Parse input to determine autocomplete state */
12
- function parseSlashInput(value: string): {
13
- isSlash: boolean;
14
- parentCommand: string;
15
- filter: string;
16
- } {
17
- if (!value.startsWith('/')) return { isSlash: false, parentCommand: '', filter: '' };
18
- const afterSlash = value.slice(1);
19
- const spaceIndex = afterSlash.indexOf(' ');
20
- if (spaceIndex === -1) return { isSlash: true, parentCommand: '', filter: afterSlash };
21
- const parent = afterSlash.slice(0, spaceIndex);
22
- const rest = afterSlash.slice(spaceIndex + 1);
23
- return { isSlash: true, parentCommand: parent, filter: rest };
24
- }
25
-
26
- /** Hook: manage autocomplete state */
27
- export function useAutocomplete(
28
- value: string,
29
- registry: CommandRegistry | undefined,
30
- ): {
31
- showPopup: boolean;
32
- filteredCommands: ICommand[];
33
- selectedIndex: number;
34
- setSelectedIndex: React.Dispatch<React.SetStateAction<number>>;
35
- isSubcommandMode: boolean;
36
- setShowPopup: React.Dispatch<React.SetStateAction<boolean>>;
37
- } {
38
- const [selectedIndex, setSelectedIndex] = useState(0);
39
- const [dismissed, setDismissed] = useState(false);
40
-
41
- // Reset dismissed when input changes
42
- const prevValueRef = React.useRef(value);
43
- if (prevValueRef.current !== value) {
44
- prevValueRef.current = value;
45
- if (dismissed) setDismissed(false);
46
- }
47
-
48
- const parsed = parseSlashInput(value);
49
- const isSubcommandMode = parsed.isSlash && parsed.parentCommand.length > 0;
50
-
51
- const filteredCommands = useMemo(() => {
52
- if (!registry || !parsed.isSlash || dismissed) return [];
53
- if (isSubcommandMode) {
54
- const subs = registry.getSubcommands(parsed.parentCommand);
55
- if (subs.length === 0) return [];
56
- if (!parsed.filter) return subs;
57
- const lower = parsed.filter.toLowerCase();
58
- return subs.filter((c) => c.name.toLowerCase().startsWith(lower));
59
- }
60
- return registry.getCommands(parsed.filter);
61
- }, [registry, parsed.isSlash, parsed.parentCommand, parsed.filter, dismissed, isSubcommandMode]);
62
-
63
- const showPopup = parsed.isSlash && filteredCommands.length > 0 && !dismissed;
64
-
65
- // Clamp selectedIndex
66
- if (selectedIndex >= filteredCommands.length && filteredCommands.length > 0) {
67
- setSelectedIndex(filteredCommands.length - 1);
68
- }
69
-
70
- return {
71
- showPopup,
72
- filteredCommands,
73
- selectedIndex,
74
- setSelectedIndex,
75
- isSubcommandMode,
76
- setShowPopup: (val) => {
77
- if (typeof val === 'function') {
78
- setDismissed((prev) => {
79
- const nextVal = (val as (prev: boolean) => boolean)(!prev);
80
- return !nextVal;
81
- });
82
- } else {
83
- setDismissed(!val);
84
- }
85
- },
86
- };
87
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Hook: returns a no-op ICommandPluginAdapter for when no plugin adapter is provided.
3
- *
4
- * In normal usage, App receives commandHostAdapters.plugin from the CLI (agent-cli), which
5
- * constructs the real adapter. This fallback exists only for test environments where no adapter
6
- * is injected.
7
- */
8
-
9
- import { useMemo } from 'react';
10
-
11
- import type { ICommandPluginAdapter } from '@robota-sdk/agent-interface-transport';
12
-
13
- function createNoOpPluginAdapter(): ICommandPluginAdapter {
14
- return {
15
- listInstalled: async () => [],
16
- listAvailablePlugins: async () => [],
17
- install: async () => undefined,
18
- uninstall: async () => undefined,
19
- enable: async () => undefined,
20
- disable: async () => undefined,
21
- marketplaceAdd: async () => '',
22
- marketplaceRemove: async () => undefined,
23
- marketplaceUpdate: async () => undefined,
24
- marketplaceList: async () => [],
25
- reloadPlugins: async () => ({ loadedPluginCount: 0 }),
26
- };
27
- }
28
-
29
- export function usePluginCallbacks(_cwd: string): ICommandPluginAdapter {
30
- return useMemo(() => createNoOpPluginAdapter(), []);
31
- }