@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,138 +0,0 @@
1
- /**
2
- * CLI-B11 TC-02: real-store channel factory integration.
3
- *
4
- * The official CI equivalent of real-resume-verify-v3.mjs: build the channel
5
- * exactly the way render.tsx does (toChannelOptions + TuiInteractionChannel)
6
- * over a REAL project session store with a persisted conversation, and assert
7
- * the restored model context is non-empty. No store/session mocks.
8
- */
9
-
10
- import { mkdtempSync, rmSync } from 'node:fs';
11
- import { tmpdir } from 'node:os';
12
- import { join } from 'node:path';
13
-
14
- import { createProjectSessionStore } from '@robota-sdk/agent-framework';
15
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
16
-
17
- import { createScriptedProvider } from '../../testing/scripted-provider.js';
18
- import { toChannelOptions, type IRenderOptions } from '../render.js';
19
- import { TuiInteractionChannel } from '../TuiInteractionChannel.js';
20
-
21
- import type { ITuiCliAdapter } from '../tui-cli-adapter.js';
22
- import type { TUniversalMessage } from '@robota-sdk/agent-core';
23
- import type { IInteractiveSessionStore } from '@robota-sdk/agent-interface-transport';
24
-
25
- const RESTORE_DEADLINE_MS = 10_000;
26
- const POLL_MS = 50;
27
-
28
- function fakeCliAdapter(settingsPath: string): ITuiCliAdapter {
29
- return {
30
- getUserSettingsPath: () => settingsPath,
31
- readSettings: () => ({}),
32
- writeSettings: vi.fn(),
33
- deleteSettings: vi.fn().mockReturnValue(false),
34
- applyStatusLineSettings: vi.fn(),
35
- reloadPluginCommandSource: vi.fn(),
36
- applyActiveModelChange: vi.fn().mockReturnValue({ applied: true }),
37
- getGitBranch: vi.fn().mockReturnValue(undefined),
38
- getProviderDisplayName: vi.fn((type: string) => type),
39
- };
40
- }
41
-
42
- function persistConversation(store: IInteractiveSessionStore, id: string, cwd: string): void {
43
- const messages: TUniversalMessage[] = [
44
- { role: 'user', content: 'Remember the number 42.' } as TUniversalMessage,
45
- { role: 'assistant', content: 'Noted: 42.' } as TUniversalMessage,
46
- { role: 'user', content: 'And the city is Busan.' } as TUniversalMessage,
47
- { role: 'assistant', content: 'Noted: Busan.' } as TUniversalMessage,
48
- ];
49
- store.save({
50
- id,
51
- cwd,
52
- createdAt: '2026-06-13T00:00:00.000Z',
53
- updatedAt: '2026-06-13T00:00:00.000Z',
54
- messages,
55
- });
56
- }
57
-
58
- describe('channel factory restores persisted context (CLI-B11 TC-02)', () => {
59
- let cwd: string;
60
- let channel: TuiInteractionChannel | undefined;
61
-
62
- beforeEach(() => {
63
- cwd = mkdtempSync(join(tmpdir(), 'robota-b11-int-'));
64
- });
65
-
66
- afterEach(async () => {
67
- await channel?.stop();
68
- channel = undefined;
69
- rmSync(cwd, { recursive: true, force: true });
70
- });
71
-
72
- it('createChannel(sessionId) over a real FileSessionStore yields usedTokens > 0', async () => {
73
- const store = createProjectSessionStore(cwd);
74
- const sessionId = 'b11-restore-session';
75
- persistConversation(store, sessionId, cwd);
76
-
77
- // Exactly the render.tsx factory: toChannelOptions(options, resumeSessionId).
78
- const scripted = createScriptedProvider([{ text: 'unused in this test' }]);
79
- const options: IRenderOptions = {
80
- cwd,
81
- provider: scripted.provider,
82
- sessionStore: store,
83
- cliAdapter: fakeCliAdapter(join(cwd, 'settings.json')),
84
- };
85
- channel = new TuiInteractionChannel(toChannelOptions(options, sessionId));
86
- await channel.start();
87
-
88
- // Restoration is asynchronous (pendingRestoreMessages inject after init).
89
- const deadline = Date.now() + RESTORE_DEADLINE_MS;
90
- let usedTokens = 0;
91
- while (Date.now() < deadline) {
92
- try {
93
- // allow-fallback: session init is asynchronous; poll until it is ready
94
- usedTokens = channel.getSession().getContextState().usedTokens;
95
- if (usedTokens > 0) break;
96
- } catch {
97
- // allow-fallback: session init is asynchronous; poll until it is ready
98
- }
99
- await new Promise((resolve) => setTimeout(resolve, POLL_MS));
100
- }
101
-
102
- // The persisted messages were injected into the model context — the exact
103
- // signal that was 0 in the 2026-05-31 bug. (getFullHistory() is the display
104
- // log restored from record.history, which this record intentionally omits.)
105
- expect(usedTokens).toBeGreaterThan(0);
106
- });
107
-
108
- it('a channel created WITHOUT resumeSessionId starts with an empty context (control)', async () => {
109
- const store = createProjectSessionStore(cwd);
110
- persistConversation(store, 'b11-other-session', cwd);
111
-
112
- const scripted = createScriptedProvider([{ text: 'unused' }]);
113
- const options: IRenderOptions = {
114
- cwd,
115
- provider: scripted.provider,
116
- sessionStore: store,
117
- cliAdapter: fakeCliAdapter(join(cwd, 'settings.json')),
118
- };
119
- channel = new TuiInteractionChannel(toChannelOptions(options, undefined));
120
- await channel.start();
121
-
122
- const deadline = Date.now() + RESTORE_DEADLINE_MS;
123
- let ready = false;
124
- while (Date.now() < deadline && !ready) {
125
- try {
126
- // allow-fallback: session init is asynchronous; poll until it is ready
127
- channel.getSession().getContextState();
128
- ready = true;
129
- } catch {
130
- // allow-fallback: session init is asynchronous; poll until it is ready
131
- await new Promise((resolve) => setTimeout(resolve, POLL_MS));
132
- }
133
- }
134
-
135
- expect(ready).toBe(true);
136
- expect(channel.getSession().getFullHistory()).toHaveLength(0);
137
- });
138
- });
@@ -1,109 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- applyCjkTextInput,
4
- applyCjkTextPaste,
5
- createCjkTextInputFlowState,
6
- syncCjkTextInputFlowState,
7
- } from '../flows/cjk-text-input-flow.js';
8
-
9
- describe('cjk text input flow', () => {
10
- it('Given printable input When applied Then value changes at cursor', () => {
11
- const result = applyCjkTextInput(
12
- createCjkTextInputFlowState('ab'),
13
- 'c',
14
- {},
15
- { canPaste: true },
16
- );
17
-
18
- expect(result.state).toMatchObject({ value: 'abc', cursor: 3 });
19
- expect(result.effect).toEqual({ type: 'change', value: 'abc' });
20
- });
21
-
22
- it('Given cursor in middle When backspace is applied Then previous char is removed', () => {
23
- const state = { ...createCjkTextInputFlowState('abc'), cursor: 2 };
24
-
25
- const result = applyCjkTextInput(state, '', { backspace: true }, { canPaste: true });
26
-
27
- expect(result.state).toMatchObject({ value: 'ac', cursor: 1 });
28
- expect(result.effect).toEqual({ type: 'change', value: 'ac' });
29
- });
30
-
31
- it('Given return key When applied Then submit effect contains current value', () => {
32
- const result = applyCjkTextInput(
33
- createCjkTextInputFlowState('hello'),
34
- '',
35
- { return: true },
36
- { canPaste: true },
37
- );
38
-
39
- expect(result.effect).toEqual({ type: 'submit', value: 'hello' });
40
- });
41
-
42
- it('Given multiline fallback paste When applied Then paste effect is emitted', () => {
43
- const result = applyCjkTextInput(
44
- createCjkTextInputFlowState(''),
45
- 'a\nb',
46
- {},
47
- { canPaste: true },
48
- );
49
-
50
- expect(result.effect).toEqual({ type: 'paste', text: 'a\nb', cursor: 0 });
51
- });
52
-
53
- it('Given Ink usePaste single-line text When applied Then text is inserted at cursor', () => {
54
- const state = { ...createCjkTextInputFlowState('ab'), cursor: 1 };
55
-
56
- const result = applyCjkTextPaste(state, '한글', { canPaste: true });
57
-
58
- expect(result.state).toMatchObject({ value: 'a한글b', cursor: 3 });
59
- expect(result.effect).toEqual({ type: 'change', value: 'a한글b' });
60
- });
61
-
62
- it('Given Ink usePaste multiline text When applied Then normalized paste effect is emitted', () => {
63
- const state = { ...createCjkTextInputFlowState('ab'), cursor: 1 };
64
-
65
- const result = applyCjkTextPaste(state, 'x\r\ny\rz', { canPaste: true });
66
-
67
- expect(result.state).toBe(state);
68
- expect(result.effect).toEqual({ type: 'paste', text: 'x\ny\nz', cursor: 1 });
69
- });
70
-
71
- it('Given bracketed multiline paste When end marker arrives Then buffered paste is emitted', () => {
72
- const started = applyCjkTextInput(
73
- createCjkTextInputFlowState('x'),
74
- '[200~hello',
75
- {},
76
- { canPaste: true },
77
- ).state;
78
- const result = applyCjkTextInput(started, '\nworld[201~', {}, { canPaste: true });
79
-
80
- expect(result.effect).toEqual({ type: 'paste', text: 'hello\nworld', cursor: 1 });
81
- expect(result.state.isPasting).toBe(false);
82
- });
83
-
84
- it('Given external value update When synced Then cursor hint is honored', () => {
85
- const state = createCjkTextInputFlowState('abc');
86
-
87
- const result = syncCjkTextInputFlowState(state, 'a[Pasted]bc', 9);
88
-
89
- expect(result).toMatchObject({ value: 'a[Pasted]bc', cursor: 9 });
90
- });
91
-
92
- it('Given vertical navigation disabled When up arrow is applied Then cursor is unchanged', () => {
93
- const state = { ...createCjkTextInputFlowState('abcdef'), cursor: 5 };
94
-
95
- const result = applyCjkTextInput(
96
- state,
97
- '',
98
- { upArrow: true },
99
- {
100
- canPaste: true,
101
- enableVerticalNavigation: false,
102
- availableWidth: 2,
103
- },
104
- );
105
-
106
- expect(result.state).toBe(state);
107
- expect(result.effect).toEqual({ type: 'none' });
108
- });
109
- });
@@ -1,191 +0,0 @@
1
- /**
2
- * Tests for CjkTextInput pure utility functions.
3
- *
4
- * These test the input filtering and insertion logic extracted from
5
- * the React component, without requiring Ink/React rendering.
6
- */
7
-
8
- import { describe, it, expect } from 'vitest';
9
- import {
10
- filterPrintable,
11
- insertAtCursor,
12
- displayOffset,
13
- charIndexAtDisplayOffset,
14
- } from '../flows/cjk-text-input-flow.js';
15
-
16
- describe('filterPrintable', () => {
17
- it('returns empty string for null input', () => {
18
- expect(filterPrintable(null)).toBe('');
19
- });
20
-
21
- it('returns empty string for undefined input', () => {
22
- expect(filterPrintable(undefined)).toBe('');
23
- });
24
-
25
- it('returns empty string for empty string', () => {
26
- expect(filterPrintable('')).toBe('');
27
- });
28
-
29
- it('passes through normal ASCII text', () => {
30
- expect(filterPrintable('hello')).toBe('hello');
31
- });
32
-
33
- it('passes through Korean characters', () => {
34
- expect(filterPrintable('안녕하세요')).toBe('안녕하세요');
35
- });
36
-
37
- it('passes through emoji', () => {
38
- expect(filterPrintable('🎉')).toBe('🎉');
39
- });
40
-
41
- it('filters out null byte', () => {
42
- expect(filterPrintable('\x00')).toBe('');
43
- });
44
-
45
- it('filters out escape character', () => {
46
- expect(filterPrintable('\x1b')).toBe('');
47
- });
48
-
49
- it('filters out DEL character', () => {
50
- expect(filterPrintable('\x7f')).toBe('');
51
- });
52
-
53
- it('filters out mixed control characters, keeps printable', () => {
54
- expect(filterPrintable('\x01hello\x02world\x7f')).toBe('helloworld');
55
- });
56
-
57
- it('returns empty when input is only control characters', () => {
58
- expect(filterPrintable('\x00\x01\x02\x03\x1f\x7f')).toBe('');
59
- });
60
-
61
- it('handles tab character (0x09) — filtered as control', () => {
62
- expect(filterPrintable('\t')).toBe('');
63
- });
64
-
65
- it('handles newline (0x0a) — filtered as control', () => {
66
- expect(filterPrintable('\n')).toBe('');
67
- });
68
- });
69
-
70
- describe('insertAtCursor', () => {
71
- it('inserts at the beginning', () => {
72
- const result = insertAtCursor('world', 0, 'hello ');
73
- expect(result.value).toBe('hello world');
74
- expect(result.cursor).toBe(6);
75
- });
76
-
77
- it('inserts at the end', () => {
78
- const result = insertAtCursor('hello', 5, ' world');
79
- expect(result.value).toBe('hello world');
80
- expect(result.cursor).toBe(11);
81
- });
82
-
83
- it('inserts in the middle', () => {
84
- const result = insertAtCursor('helo', 3, 'l');
85
- expect(result.value).toBe('hello');
86
- expect(result.cursor).toBe(4);
87
- });
88
-
89
- it('inserts into empty string', () => {
90
- const result = insertAtCursor('', 0, 'abc');
91
- expect(result.value).toBe('abc');
92
- expect(result.cursor).toBe(3);
93
- });
94
-
95
- it('handles multi-character paste', () => {
96
- const result = insertAtCursor('ac', 1, 'bb');
97
- expect(result.value).toBe('abbc');
98
- expect(result.cursor).toBe(3);
99
- });
100
-
101
- it('handles Korean character insertion', () => {
102
- const result = insertAtCursor('안세요', 1, '녕하');
103
- expect(result.value).toBe('안녕하세요');
104
- expect(result.cursor).toBe(3);
105
- });
106
-
107
- it('handles emoji insertion', () => {
108
- const result = insertAtCursor('hello world', 6, '🎉 ');
109
- expect(result.value).toBe('hello 🎉 world');
110
- expect(result.cursor).toBe(9);
111
- });
112
- });
113
-
114
- describe('displayOffset', () => {
115
- it('returns 0 for charIndex 0', () => {
116
- expect(displayOffset([...'hello'], 0, 10)).toBe(0);
117
- });
118
-
119
- it('returns char count for ASCII within one line', () => {
120
- expect(displayOffset([...'hello'], 3, 10)).toBe(3);
121
- });
122
-
123
- it('accumulates across wrap boundary', () => {
124
- // "abcde" width 3: offset at index 4 = 4 (abc on line 0, de on line 1)
125
- expect(displayOffset([...'abcde'], 4, 3)).toBe(4);
126
- });
127
-
128
- it('cursor before CJK char is at end of previous content', () => {
129
- // "abcd한" width 5: cursor before "한" is at col 4 on line 0
130
- // gap happens when "한" renders, not at cursor position
131
- expect(displayOffset([...'abcd한'], 4, 5)).toBe(4);
132
- // cursor after "한": 4(gap included) + 2 = 7 → but via offset: gap is at render
133
- expect(displayOffset([...'abcd한'], 5, 5)).toBe(7);
134
- });
135
-
136
- it('handles pure CJK', () => {
137
- // "한글" width 5: "한"=2, "글"=2 → total 4, fits on one line
138
- expect(displayOffset([...'한글'], 2, 5)).toBe(4);
139
- });
140
-
141
- it('handles CJK wrapping', () => {
142
- // "한글테" width 5: cursor before "테" is after "글" (offset 4)
143
- // "테" doesn't fit at col 4, but cursor is BEFORE the wrap
144
- expect(displayOffset([...'한글테'], 2, 5)).toBe(4);
145
- // cursor after "테": gap(1) + 2 = offset 7
146
- expect(displayOffset([...'한글테'], 3, 5)).toBe(7);
147
- });
148
- });
149
-
150
- describe('charIndexAtDisplayOffset', () => {
151
- it('returns 0 for offset 0', () => {
152
- expect(charIndexAtDisplayOffset([...'hello'], 0, 10)).toBe(0);
153
- });
154
-
155
- it('finds correct index for ASCII', () => {
156
- expect(charIndexAtDisplayOffset([...'hello'], 3, 10)).toBe(3);
157
- });
158
-
159
- it('returns text length when offset exceeds text', () => {
160
- expect(charIndexAtDisplayOffset([...'hi'], 100, 10)).toBe(2);
161
- });
162
-
163
- it('round-trips with displayOffset for ASCII', () => {
164
- const text = 'abcdefghij';
165
- const chars = [...text];
166
- const width = 4;
167
- for (let i = 0; i <= chars.length; i++) {
168
- const off = displayOffset(chars, i, width);
169
- expect(charIndexAtDisplayOffset(chars, off, width)).toBe(i);
170
- }
171
- });
172
-
173
- it('round-trips with displayOffset for CJK', () => {
174
- const text = '한글테스트';
175
- const chars = [...text];
176
- const width = 5;
177
- for (let i = 0; i <= chars.length; i++) {
178
- const off = displayOffset(chars, i, width);
179
- expect(charIndexAtDisplayOffset(chars, off, width)).toBe(i);
180
- }
181
- });
182
-
183
- it('up arrow simulation: offset - width gives previous line position', () => {
184
- // "abcdef" width 3: line 0 = "abc", line 1 = "def"
185
- // cursor at index 4 (line 1, col 1) → offset = 4
186
- // offset - 3 = 1 → charIndex 1 (line 0, col 1)
187
- const chars = [...'abcdef'];
188
- const off = displayOffset(chars, 4, 3);
189
- expect(charIndexAtDisplayOffset(chars, off - 3, 3)).toBe(1);
190
- });
191
- });
@@ -1,127 +0,0 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- mkdtempSync,
5
- readFileSync,
6
- unlinkSync,
7
- writeFileSync,
8
- } from 'node:fs';
9
- import { dirname, join } from 'node:path';
10
- import { tmpdir } from 'node:os';
11
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
12
- import { applyCommandEffects } from '../hooks/command-effect-handler.js';
13
- import type { ITuiCliAdapter } from '../tui-cli-adapter.js';
14
- import type { TUniversalValue } from '@robota-sdk/agent-core';
15
-
16
- function readSettingsFile(path: string): Record<string, TUniversalValue> {
17
- if (!existsSync(path)) return {};
18
- try {
19
- // allow-fallback: test helper; corrupt settings return empty object
20
- return JSON.parse(readFileSync(path, 'utf8')) as Record<string, TUniversalValue>;
21
- } catch {
22
- // allow-fallback: test helper; corrupt settings return empty object
23
- return {};
24
- }
25
- }
26
-
27
- function writeSettingsFile(path: string, settings: Record<string, TUniversalValue>): void {
28
- mkdirSync(dirname(path), { recursive: true });
29
- writeFileSync(path, JSON.stringify(settings, null, 2) + '\n', 'utf8');
30
- }
31
-
32
- function deleteSettingsFile(path: string): boolean {
33
- if (existsSync(path)) {
34
- unlinkSync(path);
35
- return true;
36
- }
37
- return false;
38
- }
39
-
40
- function createCliAdapter(settingsPath: string): ITuiCliAdapter {
41
- return {
42
- getUserSettingsPath: () => settingsPath,
43
- readSettings: readSettingsFile,
44
- writeSettings: writeSettingsFile,
45
- deleteSettings: deleteSettingsFile,
46
- applyStatusLineSettings: vi.fn(),
47
- reloadPluginCommandSource: vi.fn(),
48
- applyActiveModelChange: vi.fn().mockReturnValue({ applied: true }),
49
- getGitBranch: vi.fn().mockReturnValue(undefined),
50
- getProviderDisplayName: vi.fn((type: string) => type),
51
- };
52
- }
53
-
54
- function createDeps(settingsPath: string) {
55
- return {
56
- addEntry: vi.fn(),
57
- requestShutdown: vi.fn(),
58
- openPluginTUI: vi.fn(),
59
- openTransportTUI: vi.fn(),
60
- openSessionPicker: vi.fn(),
61
- openAgentSwitcher: vi.fn(),
62
- renameSession: vi.fn(),
63
- applyStatusLinePatch: vi.fn(),
64
- cliAdapter: createCliAdapter(settingsPath),
65
- };
66
- }
67
-
68
- describe('applyCommandEffects', () => {
69
- let tempHome: string;
70
- let settingsPath: string;
71
-
72
- beforeEach(() => {
73
- vi.restoreAllMocks();
74
- tempHome = mkdtempSync(join(tmpdir(), 'robota-effect-'));
75
- settingsPath = join(tempHome, '.robota', 'settings.json');
76
- });
77
-
78
- afterEach(() => {
79
- vi.unstubAllEnvs();
80
- });
81
-
82
- it('applies session rename effects through the UI dependency boundary', () => {
83
- const deps = createDeps(settingsPath);
84
-
85
- const handled = applyCommandEffects([{ type: 'session-renamed', name: 'my-session' }], deps);
86
-
87
- expect(handled).toBe(true);
88
- expect(deps.renameSession).toHaveBeenCalledWith('my-session');
89
- expect(deps.requestShutdown).not.toHaveBeenCalled();
90
- });
91
-
92
- it('applies session picker effects through the UI dependency boundary', () => {
93
- const deps = createDeps(settingsPath);
94
-
95
- const handled = applyCommandEffects([{ type: 'session-picker-requested' }], deps);
96
-
97
- expect(handled).toBe(true);
98
- expect(deps.openSessionPicker).toHaveBeenCalledTimes(1);
99
- expect(deps.requestShutdown).not.toHaveBeenCalled();
100
- });
101
-
102
- it('deletes user settings and requests shutdown for settings reset effects', () => {
103
- const settingsDir = join(tempHome, '.robota');
104
- mkdirSync(settingsDir, { recursive: true });
105
- writeFileSync(settingsPath, '{}\n', 'utf8');
106
- const deps = createDeps(settingsPath);
107
-
108
- const handled = applyCommandEffects([{ type: 'settings-reset-requested' }], deps);
109
-
110
- expect(handled).toBe(true);
111
- expect(existsSync(settingsPath)).toBe(false);
112
- expect(deps.addEntry).toHaveBeenCalledTimes(1);
113
- expect(JSON.stringify(deps.addEntry.mock.calls[0])).toContain(`Deleted ${settingsPath}`);
114
- expect(deps.requestShutdown).toHaveBeenCalledWith('other', 'Reset settings restart');
115
- });
116
-
117
- it('reports no-op settings reset when no user settings file exists', () => {
118
- const deps = createDeps(settingsPath);
119
-
120
- const handled = applyCommandEffects([{ type: 'settings-reset-requested' }], deps);
121
-
122
- expect(handled).toBe(true);
123
- expect(deps.addEntry).toHaveBeenCalledTimes(1);
124
- expect(JSON.stringify(deps.addEntry.mock.calls[0])).toContain('No user settings found.');
125
- expect(deps.requestShutdown).toHaveBeenCalledWith('other', 'Reset settings restart');
126
- });
127
- });
@@ -1,95 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatCommandOutputSummary } from '../command-output-summary.js';
3
-
4
- describe('formatCommandOutputSummary', () => {
5
- it('renders short command output inline without transcript decoration', () => {
6
- const summary = formatCommandOutputSummary({
7
- toolName: 'Bash',
8
- firstArg: 'echo hello',
9
- isRunning: false,
10
- result: 'success',
11
- toolResultData: JSON.stringify({ success: true, output: 'hello\n', exitCode: 0 }),
12
- });
13
-
14
- expect(summary).toMatchObject({
15
- status: 'success',
16
- statusLabel: 'ok',
17
- previewLines: ['hello'],
18
- omittedLineCount: 0,
19
- transcriptHint: undefined,
20
- });
21
- });
22
-
23
- it('renders long command output with a bounded preview and transcript hint', () => {
24
- const output = Array.from({ length: 8 }, (_, index) => `line-${index + 1}`).join('\n');
25
- const summary = formatCommandOutputSummary({
26
- toolName: 'Bash',
27
- firstArg: 'pnpm test',
28
- isRunning: false,
29
- result: 'success',
30
- toolResultData: JSON.stringify({ success: true, output, exitCode: 0 }),
31
- });
32
-
33
- expect(summary?.previewLines).toEqual(['line-1', 'line-2', 'line-3', 'line-4']);
34
- expect(summary?.omittedLineCount).toBe(4);
35
- expect(summary?.transcriptHint).toBe('... +4 lines (full output in session transcript)');
36
- });
37
-
38
- it('keeps stderr distinct when stdout and stderr are structured separately', () => {
39
- const summary = formatCommandOutputSummary({
40
- toolName: 'Bash',
41
- firstArg: 'node script.js',
42
- isRunning: false,
43
- result: 'success',
44
- toolResultData: JSON.stringify({
45
- success: true,
46
- stdout: 'ok',
47
- stderr: 'warn',
48
- exitCode: 0,
49
- }),
50
- });
51
-
52
- expect(summary?.previewLines).toEqual(['ok', '[stderr] warn']);
53
- });
54
-
55
- it('marks non-zero exit codes as failed even when the tool transport succeeded', () => {
56
- const summary = formatCommandOutputSummary({
57
- toolName: 'Bash',
58
- firstArg: 'exit 42',
59
- isRunning: false,
60
- result: 'success',
61
- toolResultData: JSON.stringify({ success: true, output: '', exitCode: 42 }),
62
- });
63
-
64
- expect(summary?.status).toBe('error');
65
- expect(summary?.statusLabel).toBe('exit 42');
66
- expect(summary?.previewLines).toEqual([]);
67
- });
68
-
69
- it('renders no-output commands without dangling transcript hints', () => {
70
- const summary = formatCommandOutputSummary({
71
- toolName: 'Bash',
72
- firstArg: 'true',
73
- isRunning: false,
74
- result: 'success',
75
- toolResultData: JSON.stringify({ success: true, output: '', exitCode: 0 }),
76
- });
77
-
78
- expect(summary?.status).toBe('success');
79
- expect(summary?.previewLines).toEqual([]);
80
- expect(summary?.omittedLineCount).toBe(0);
81
- expect(summary?.transcriptHint).toBeUndefined();
82
- });
83
-
84
- it('ignores non-command tools', () => {
85
- const summary = formatCommandOutputSummary({
86
- toolName: 'Read',
87
- firstArg: 'file.ts',
88
- isRunning: false,
89
- result: 'success',
90
- toolResultData: 'large file content',
91
- });
92
-
93
- expect(summary).toBeUndefined();
94
- });
95
- });
@@ -1,20 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
3
- import { TuiStateManager } from '../tui-state-manager.js';
4
- import { applyCompactEventToManager } from '../hooks/useTuiChannel.js';
5
-
6
- describe('compact event bridge', () => {
7
- it('syncs session history so automatic compaction notifications render', () => {
8
- const manager = new TuiStateManager();
9
- const notification = messageToHistoryEntry(
10
- createSystemMessage('Auto compacted context: 84% -> 35%'),
11
- );
12
- const session = {
13
- getFullHistory: () => [notification],
14
- };
15
-
16
- applyCompactEventToManager(session, manager);
17
-
18
- expect(manager.history).toEqual([notification]);
19
- });
20
- });