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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/dist/node/headless/index.cjs +1 -0
  3. package/dist/node/headless/index.d.ts +2 -0
  4. package/dist/node/headless/index.js +1 -0
  5. package/dist/node/headless-CWEpJXFK.js +7 -0
  6. package/dist/node/headless-CWEpJXFK.js.map +1 -0
  7. package/dist/node/headless-CsZFelG9.cjs +6 -0
  8. package/dist/node/http/index.cjs +1 -0
  9. package/dist/node/http/index.d.ts +2 -0
  10. package/dist/node/http/index.js +1 -0
  11. package/dist/node/http-CM3TJhrF.cjs +1 -0
  12. package/dist/node/http-DwO1AHG-.js +2 -0
  13. package/dist/node/http-DwO1AHG-.js.map +1 -0
  14. package/dist/node/index--Ti9NzQX.d.ts +64 -0
  15. package/dist/node/index--Ti9NzQX.d.ts.map +1 -0
  16. package/dist/node/index-B_rcr14p.d.ts +47 -0
  17. package/dist/node/index-B_rcr14p.d.ts.map +1 -0
  18. package/dist/node/index-C9LWCL4l.d.ts +34 -0
  19. package/dist/node/index-C9LWCL4l.d.ts.map +1 -0
  20. package/dist/node/index-CAr3ioVh.d.ts +64 -0
  21. package/dist/node/index-CAr3ioVh.d.ts.map +1 -0
  22. package/dist/node/index-CEs25wVk.d.ts +213 -0
  23. package/dist/node/index-CEs25wVk.d.ts.map +1 -0
  24. package/dist/node/index-CvXLpjJO.d.ts +213 -0
  25. package/dist/node/index-CvXLpjJO.d.ts.map +1 -0
  26. package/dist/node/index-D34WUfFH.d.ts +26 -0
  27. package/dist/node/index-D34WUfFH.d.ts.map +1 -0
  28. package/dist/node/index-Y0zHb1Bz.d.ts +47 -0
  29. package/dist/node/index-Y0zHb1Bz.d.ts.map +1 -0
  30. package/dist/node/index-k3TUjA-T.d.ts +26 -0
  31. package/dist/node/index-k3TUjA-T.d.ts.map +1 -0
  32. package/dist/node/index-nBlMTFkZ.d.ts +34 -0
  33. package/dist/node/index-nBlMTFkZ.d.ts.map +1 -0
  34. package/dist/node/index.cjs +1 -0
  35. package/dist/node/index.d.ts +6 -0
  36. package/dist/node/index.js +1 -0
  37. package/dist/node/mcp/index.cjs +1 -0
  38. package/dist/node/mcp/index.d.ts +2 -0
  39. package/dist/node/mcp/index.js +1 -0
  40. package/dist/node/mcp-BXBwF6Wu.js +2 -0
  41. package/dist/node/mcp-BXBwF6Wu.js.map +1 -0
  42. package/dist/node/mcp-DcHuGokt.cjs +1 -0
  43. package/dist/node/tui/index.cjs +1 -0
  44. package/dist/node/tui/index.d.ts +2 -0
  45. package/dist/node/tui/index.js +1 -0
  46. package/dist/node/tui-CeD_6rSo.cjs +24 -0
  47. package/dist/node/tui-zmDTPk4b.js +25 -0
  48. package/dist/node/tui-zmDTPk4b.js.map +1 -0
  49. package/dist/node/ws/index.cjs +1 -0
  50. package/dist/node/ws/index.d.ts +2 -0
  51. package/dist/node/ws/index.js +1 -0
  52. package/dist/node/ws-B-oRccFl.js +2 -0
  53. package/dist/node/ws-B-oRccFl.js.map +1 -0
  54. package/dist/node/ws-COnIgnmn.cjs +1 -0
  55. package/package.json +141 -0
  56. package/src/headless/__tests__/headless-runner-initialization.test.ts +45 -0
  57. package/src/headless/__tests__/headless-runner.test.ts +484 -0
  58. package/src/headless/__tests__/headless-skill-activation.integration.test.ts +430 -0
  59. package/src/headless/__tests__/headless-transport.test.ts +268 -0
  60. package/src/headless/headless-runner.ts +141 -0
  61. package/src/headless/headless-stream-json.ts +142 -0
  62. package/src/headless/headless-transport.ts +43 -0
  63. package/src/headless/index.ts +4 -0
  64. package/src/http/__tests__/http-transport.test.ts +55 -0
  65. package/src/http/__tests__/routes.test.ts +168 -0
  66. package/src/http/http-transport.ts +42 -0
  67. package/src/http/index.ts +4 -0
  68. package/src/http/routes.ts +151 -0
  69. package/src/index.ts +5 -0
  70. package/src/mcp/__tests__/mcp-server.test.ts +66 -0
  71. package/src/mcp/__tests__/mcp-transport.test.ts +46 -0
  72. package/src/mcp/index.ts +4 -0
  73. package/src/mcp/mcp-server.ts +162 -0
  74. package/src/mcp/mcp-transport.ts +48 -0
  75. package/src/tui/App.tsx +478 -0
  76. package/src/tui/BackgroundTaskPanel.tsx +34 -0
  77. package/src/tui/CjkTextInput.tsx +204 -0
  78. package/src/tui/ConfirmPrompt.tsx +69 -0
  79. package/src/tui/ExecutionWorkspaceDetailPane.tsx +62 -0
  80. package/src/tui/ExecutionWorkspaceSwitcher.tsx +185 -0
  81. package/src/tui/InkTerminal.ts +42 -0
  82. package/src/tui/InputArea.tsx +298 -0
  83. package/src/tui/InteractivePrompt.tsx +57 -0
  84. package/src/tui/ListPicker.tsx +94 -0
  85. package/src/tui/MenuSelect.tsx +103 -0
  86. package/src/tui/MessageList.tsx +282 -0
  87. package/src/tui/PermissionPrompt.tsx +84 -0
  88. package/src/tui/PluginTUI.tsx +256 -0
  89. package/src/tui/SessionPicker.tsx +66 -0
  90. package/src/tui/SessionStatusBar.tsx +66 -0
  91. package/src/tui/SlashAutocomplete.tsx +110 -0
  92. package/src/tui/StatusBar.tsx +213 -0
  93. package/src/tui/StreamingIndicator.tsx +91 -0
  94. package/src/tui/TextPrompt.tsx +80 -0
  95. package/src/tui/ToolCommandOutput.tsx +37 -0
  96. package/src/tui/ToolDiffBlock.tsx +30 -0
  97. package/src/tui/TransportTUI.tsx +116 -0
  98. package/src/tui/UpdateNotice.tsx +14 -0
  99. package/src/tui/UsageSummaryEntry.tsx +38 -0
  100. package/src/tui/WaveText.tsx +44 -0
  101. package/src/tui/__tests__/InteractivePrompt.test.tsx +82 -0
  102. package/src/tui/__tests__/ListPicker.test.tsx +159 -0
  103. package/src/tui/__tests__/MenuSelect.test.tsx +103 -0
  104. package/src/tui/__tests__/PluginTUI.test.tsx +167 -0
  105. package/src/tui/__tests__/SlashAutocomplete.test.tsx +140 -0
  106. package/src/tui/__tests__/TextPrompt.test.tsx +98 -0
  107. package/src/tui/__tests__/UpdateNotice.test.tsx +15 -0
  108. package/src/tui/__tests__/abort-after-permission.test.tsx +169 -0
  109. package/src/tui/__tests__/abort-streaming-e2e.test.tsx +183 -0
  110. package/src/tui/__tests__/background-task-panel.test.tsx +53 -0
  111. package/src/tui/__tests__/background-task-row-format.test.ts +59 -0
  112. package/src/tui/__tests__/cjk-text-input-flow.test.ts +109 -0
  113. package/src/tui/__tests__/cjk-text-input.test.ts +191 -0
  114. package/src/tui/__tests__/command-effect-handler.test.ts +128 -0
  115. package/src/tui/__tests__/command-output-summary.test.ts +95 -0
  116. package/src/tui/__tests__/compact-event-bridge.test.ts +20 -0
  117. package/src/tui/__tests__/confirm-permission-flow.test.ts +91 -0
  118. package/src/tui/__tests__/confirm-prompt.test.tsx +87 -0
  119. package/src/tui/__tests__/execution-workspace-switcher.test.tsx +110 -0
  120. package/src/tui/__tests__/execution-workspace-view-model.test.ts +93 -0
  121. package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +122 -0
  122. package/src/tui/__tests__/input-area-flow.test.ts +152 -0
  123. package/src/tui/__tests__/message-list-rendering.test.tsx +353 -0
  124. package/src/tui/__tests__/model-change-side-effect.test.ts +91 -0
  125. package/src/tui/__tests__/prompt-queue.test.tsx +255 -0
  126. package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +233 -0
  127. package/src/tui/__tests__/render-markdown.test.ts +72 -0
  128. package/src/tui/__tests__/selection-flow.test.ts +61 -0
  129. package/src/tui/__tests__/slash-routing-effects.test.ts +225 -0
  130. package/src/tui/__tests__/status-activity.test.ts +71 -0
  131. package/src/tui/__tests__/status-bar.test.tsx +157 -0
  132. package/src/tui/__tests__/streaming-indicator.test.tsx +137 -0
  133. package/src/tui/__tests__/text-prompt-flow.test.ts +77 -0
  134. package/src/tui/__tests__/tui-state-manager.test.ts +401 -0
  135. package/src/tui/background-task-row-format.ts +52 -0
  136. package/src/tui/command-output-summary.ts +122 -0
  137. package/src/tui/execution-workspace-view-model.ts +123 -0
  138. package/src/tui/flows/cjk-text-input-flow.ts +285 -0
  139. package/src/tui/flows/confirm-prompt-flow.ts +45 -0
  140. package/src/tui/flows/input-area-flow.ts +186 -0
  141. package/src/tui/flows/permission-prompt-flow.ts +76 -0
  142. package/src/tui/flows/selection-flow.ts +126 -0
  143. package/src/tui/flows/text-prompt-flow.ts +98 -0
  144. package/src/tui/hooks/command-effect-handler.ts +98 -0
  145. package/src/tui/hooks/command-effect-queue.ts +39 -0
  146. package/src/tui/hooks/model-change-side-effect.ts +63 -0
  147. package/src/tui/hooks/side-effects-types.ts +38 -0
  148. package/src/tui/hooks/use-interactive-session-init.ts +50 -0
  149. package/src/tui/hooks/useAutocomplete.ts +85 -0
  150. package/src/tui/hooks/useInteractiveSession.ts +273 -0
  151. package/src/tui/hooks/usePermissionQueue.ts +51 -0
  152. package/src/tui/hooks/usePluginCallbacks.ts +30 -0
  153. package/src/tui/hooks/usePluginScreenData.ts +84 -0
  154. package/src/tui/hooks/useSideEffects.ts +210 -0
  155. package/src/tui/hooks/useSlashRouting.ts +117 -0
  156. package/src/tui/hooks/useStatusLineSettings.ts +35 -0
  157. package/src/tui/index.ts +3 -0
  158. package/src/tui/plugin-tui-handlers.ts +163 -0
  159. package/src/tui/render-markdown.ts +129 -0
  160. package/src/tui/render.tsx +60 -0
  161. package/src/tui/status-activity.ts +63 -0
  162. package/src/tui/tui-cli-adapter-context.tsx +12 -0
  163. package/src/tui/tui-cli-adapter.ts +25 -0
  164. package/src/tui/tui-state-manager.ts +225 -0
  165. package/src/tui/tui-transport.ts +32 -0
  166. package/src/tui/types.ts +14 -0
  167. package/src/tui/utils/__tests__/edit-diff.test.ts +426 -0
  168. package/src/tui/utils/__tests__/paste-detection.test.ts +116 -0
  169. package/src/tui/utils/__tests__/paste-labels.test.ts +46 -0
  170. package/src/tui/utils/__tests__/tool-call-extractor.test.ts +227 -0
  171. package/src/tui/utils/__tests__/tool-diff-summary.test.ts +104 -0
  172. package/src/tui/utils/edit-diff.ts +152 -0
  173. package/src/tui/utils/paste-labels.ts +9 -0
  174. package/src/tui/utils/tool-call-extractor.ts +91 -0
  175. package/src/tui/utils/tool-diff-summary.ts +75 -0
  176. package/src/ws/__tests__/ws-handler.test.ts +407 -0
  177. package/src/ws/__tests__/ws-transport.test.ts +53 -0
  178. package/src/ws/index.ts +13 -0
  179. package/src/ws/ws-background-messages.ts +170 -0
  180. package/src/ws/ws-handler.ts +279 -0
  181. package/src/ws/ws-protocol.ts +76 -0
  182. package/src/ws/ws-transport-configurable.ts +123 -0
  183. package/src/ws/ws-transport.ts +42 -0
@@ -0,0 +1,128 @@
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
+ requestModelChange: vi.fn(),
59
+ openPluginTUI: vi.fn(),
60
+ openTransportTUI: vi.fn(),
61
+ openSessionPicker: vi.fn(),
62
+ openAgentSwitcher: vi.fn(),
63
+ renameSession: vi.fn(),
64
+ applyStatusLinePatch: vi.fn(),
65
+ cliAdapter: createCliAdapter(settingsPath),
66
+ };
67
+ }
68
+
69
+ describe('applyCommandEffects', () => {
70
+ let tempHome: string;
71
+ let settingsPath: string;
72
+
73
+ beforeEach(() => {
74
+ vi.restoreAllMocks();
75
+ tempHome = mkdtempSync(join(tmpdir(), 'robota-effect-'));
76
+ settingsPath = join(tempHome, '.robota', 'settings.json');
77
+ });
78
+
79
+ afterEach(() => {
80
+ vi.unstubAllEnvs();
81
+ });
82
+
83
+ it('applies session rename effects through the UI dependency boundary', () => {
84
+ const deps = createDeps(settingsPath);
85
+
86
+ const handled = applyCommandEffects([{ type: 'session-renamed', name: 'my-session' }], deps);
87
+
88
+ expect(handled).toBe(true);
89
+ expect(deps.renameSession).toHaveBeenCalledWith('my-session');
90
+ expect(deps.requestShutdown).not.toHaveBeenCalled();
91
+ });
92
+
93
+ it('applies session picker effects through the UI dependency boundary', () => {
94
+ const deps = createDeps(settingsPath);
95
+
96
+ const handled = applyCommandEffects([{ type: 'session-picker-requested' }], deps);
97
+
98
+ expect(handled).toBe(true);
99
+ expect(deps.openSessionPicker).toHaveBeenCalledTimes(1);
100
+ expect(deps.requestShutdown).not.toHaveBeenCalled();
101
+ });
102
+
103
+ it('deletes user settings and requests shutdown for settings reset effects', () => {
104
+ const settingsDir = join(tempHome, '.robota');
105
+ mkdirSync(settingsDir, { recursive: true });
106
+ writeFileSync(settingsPath, '{}\n', 'utf8');
107
+ const deps = createDeps(settingsPath);
108
+
109
+ const handled = applyCommandEffects([{ type: 'settings-reset-requested' }], deps);
110
+
111
+ expect(handled).toBe(true);
112
+ expect(existsSync(settingsPath)).toBe(false);
113
+ expect(deps.addEntry).toHaveBeenCalledTimes(1);
114
+ expect(JSON.stringify(deps.addEntry.mock.calls[0])).toContain(`Deleted ${settingsPath}`);
115
+ expect(deps.requestShutdown).toHaveBeenCalledWith('other', 'Reset settings restart');
116
+ });
117
+
118
+ it('reports no-op settings reset when no user settings file exists', () => {
119
+ const deps = createDeps(settingsPath);
120
+
121
+ const handled = applyCommandEffects([{ type: 'settings-reset-requested' }], deps);
122
+
123
+ expect(handled).toBe(true);
124
+ expect(deps.addEntry).toHaveBeenCalledTimes(1);
125
+ expect(JSON.stringify(deps.addEntry.mock.calls[0])).toContain('No user settings found.');
126
+ expect(deps.requestShutdown).toHaveBeenCalledWith('other', 'Reset settings restart');
127
+ });
128
+ });
@@ -0,0 +1,95 @@
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
+ });
@@ -0,0 +1,20 @@
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/useInteractiveSession.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
+ });
@@ -0,0 +1,91 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ applyConfirmPromptInput,
4
+ getConfirmPromptInputAction,
5
+ } from '../flows/confirm-prompt-flow.js';
6
+ import {
7
+ applyPermissionPromptInput,
8
+ getPermissionPromptInputAction,
9
+ } from '../flows/permission-prompt-flow.js';
10
+ import { createSelectionFlowState } from '../flows/selection-flow.js';
11
+
12
+ describe('confirm prompt flow', () => {
13
+ it('Given two options When y shortcut is mapped and applied Then first option is selected', () => {
14
+ const action = getConfirmPromptInputAction('y', {}, 2);
15
+ expect(action).toEqual({ type: 'shortcut', index: 0 });
16
+
17
+ const result = applyConfirmPromptInput(createSelectionFlowState(), action!, 2);
18
+
19
+ expect(result.effect).toEqual({ type: 'select', index: 0 });
20
+ });
21
+
22
+ it('Given more than two options When y or n is typed Then shortcuts are ignored', () => {
23
+ expect(getConfirmPromptInputAction('y', {}, 3)).toBeUndefined();
24
+ expect(getConfirmPromptInputAction('n', {}, 3)).toBeUndefined();
25
+ });
26
+
27
+ it('Given selection moved right When enter is applied Then current option is selected', () => {
28
+ const moved = applyConfirmPromptInput(createSelectionFlowState(), 'next', 2).state;
29
+
30
+ const result = applyConfirmPromptInput(moved, 'select', 2);
31
+
32
+ expect(result.effect).toEqual({ type: 'select', index: 1 });
33
+ });
34
+
35
+ it('Given prompt is resolved When shortcut is applied Then no second selection is emitted', () => {
36
+ const selected = applyConfirmPromptInput(createSelectionFlowState(), 'select', 2).state;
37
+
38
+ const result = applyConfirmPromptInput(selected, { type: 'shortcut', index: 1 }, 2);
39
+
40
+ expect(result.effect).toEqual({ type: 'none' });
41
+ });
42
+ });
43
+
44
+ describe('permission prompt flow', () => {
45
+ it('Given y shortcut When applied Then allow decision is emitted', () => {
46
+ const action = getPermissionPromptInputAction('y', {});
47
+
48
+ const result = applyPermissionPromptInput(createSelectionFlowState(), action!);
49
+
50
+ expect(result.effect).toEqual({ type: 'resolve', decision: true });
51
+ });
52
+
53
+ it('Given a shortcut When applied Then allow-session decision is emitted', () => {
54
+ const action = getPermissionPromptInputAction('a', {});
55
+
56
+ const result = applyPermissionPromptInput(createSelectionFlowState(), action!);
57
+
58
+ expect(result.effect).toEqual({ type: 'resolve', decision: 'allow-session' });
59
+ });
60
+
61
+ it('Given deny shortcuts When applied Then false decision is emitted', () => {
62
+ expect(
63
+ applyPermissionPromptInput(
64
+ createSelectionFlowState(),
65
+ getPermissionPromptInputAction('n', {})!,
66
+ ).effect,
67
+ ).toEqual({ type: 'resolve', decision: false });
68
+ expect(
69
+ applyPermissionPromptInput(
70
+ createSelectionFlowState(),
71
+ getPermissionPromptInputAction('3', {})!,
72
+ ).effect,
73
+ ).toEqual({ type: 'resolve', decision: false });
74
+ });
75
+
76
+ it('Given arrow navigation When enter is applied Then selected permission is resolved', () => {
77
+ const moved = applyPermissionPromptInput(createSelectionFlowState(), 'next').state;
78
+
79
+ const result = applyPermissionPromptInput(moved, 'select');
80
+
81
+ expect(result.effect).toEqual({ type: 'resolve', decision: 'allow-session' });
82
+ });
83
+
84
+ it('Given permission is resolved When shortcut is applied Then no second decision is emitted', () => {
85
+ const resolved = applyPermissionPromptInput(createSelectionFlowState(), 'select').state;
86
+
87
+ const result = applyPermissionPromptInput(resolved, { type: 'shortcut', index: 2 });
88
+
89
+ expect(result.effect).toEqual({ type: 'none' });
90
+ });
91
+ });
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { describe, it, expect, vi } from 'vitest';
3
+ import { render } from 'ink-testing-library';
4
+ import ConfirmPrompt from '../ConfirmPrompt.js';
5
+
6
+ const delay = (ms: number) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ describe('ConfirmPrompt', () => {
9
+ it('renders message text', () => {
10
+ const { lastFrame } = render(<ConfirmPrompt message="Are you sure?" onSelect={() => {}} />);
11
+ expect(lastFrame()).toContain('Are you sure?');
12
+ });
13
+
14
+ it('renders default Yes/No options', () => {
15
+ const { lastFrame } = render(<ConfirmPrompt message="Confirm?" onSelect={() => {}} />);
16
+ const frame = lastFrame()!;
17
+ expect(frame).toContain('Yes');
18
+ expect(frame).toContain('No');
19
+ });
20
+
21
+ it('renders custom options', () => {
22
+ const { lastFrame } = render(
23
+ <ConfirmPrompt message="Pick" options={['A', 'B', 'C']} onSelect={() => {}} />,
24
+ );
25
+ const frame = lastFrame()!;
26
+ expect(frame).toContain('A');
27
+ expect(frame).toContain('B');
28
+ expect(frame).toContain('C');
29
+ });
30
+
31
+ it('first option is highlighted by default', () => {
32
+ const { lastFrame } = render(<ConfirmPrompt message="Confirm?" onSelect={() => {}} />);
33
+ const frame = lastFrame()!;
34
+ // The selected item has '> ' prefix
35
+ expect(frame).toContain('> Yes');
36
+ });
37
+
38
+ it('selects first option on Enter', () => {
39
+ const onSelect = vi.fn();
40
+ const { stdin } = render(<ConfirmPrompt message="Confirm?" onSelect={onSelect} />);
41
+ stdin.write('\r');
42
+ expect(onSelect).toHaveBeenCalledWith(0);
43
+ });
44
+
45
+ it('navigates to second option with arrow down and selects', async () => {
46
+ const onSelect = vi.fn();
47
+ const { stdin } = render(<ConfirmPrompt message="Confirm?" onSelect={onSelect} />);
48
+ // Arrow down (move to No)
49
+ stdin.write('\x1b[B');
50
+ await delay(50);
51
+ stdin.write('\r');
52
+ expect(onSelect).toHaveBeenCalledWith(1);
53
+ });
54
+
55
+ it('y shortcut selects first option (Yes)', () => {
56
+ const onSelect = vi.fn();
57
+ const { stdin } = render(<ConfirmPrompt message="Confirm?" onSelect={onSelect} />);
58
+ stdin.write('y');
59
+ expect(onSelect).toHaveBeenCalledWith(0);
60
+ });
61
+
62
+ it('n shortcut selects second option (No)', () => {
63
+ const onSelect = vi.fn();
64
+ const { stdin } = render(<ConfirmPrompt message="Confirm?" onSelect={onSelect} />);
65
+ stdin.write('n');
66
+ expect(onSelect).toHaveBeenCalledWith(1);
67
+ });
68
+
69
+ it('y/n shortcuts do not work with more than 2 options', () => {
70
+ const onSelect = vi.fn();
71
+ const { stdin } = render(
72
+ <ConfirmPrompt message="Pick" options={['A', 'B', 'C']} onSelect={onSelect} />,
73
+ );
74
+ stdin.write('y');
75
+ stdin.write('n');
76
+ expect(onSelect).not.toHaveBeenCalled();
77
+ });
78
+
79
+ it('ignores input after selection (no double-fire)', () => {
80
+ const onSelect = vi.fn();
81
+ const { stdin } = render(<ConfirmPrompt message="Confirm?" onSelect={onSelect} />);
82
+ stdin.write('\r');
83
+ stdin.write('\r');
84
+ stdin.write('y');
85
+ expect(onSelect).toHaveBeenCalledTimes(1);
86
+ });
87
+ });
@@ -0,0 +1,110 @@
1
+ import React from 'react';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import { render } from 'ink-testing-library';
4
+ import type {
5
+ IExecutionWorkspaceEntry,
6
+ IExecutionWorkspaceSnapshot,
7
+ } from '@robota-sdk/agent-framework';
8
+ import ExecutionWorkspaceSwitcher from '../ExecutionWorkspaceSwitcher.js';
9
+ import ExecutionWorkspaceDetailPane from '../ExecutionWorkspaceDetailPane.js';
10
+
11
+ function makeEntry(overrides: Partial<IExecutionWorkspaceEntry>): IExecutionWorkspaceEntry {
12
+ return {
13
+ id: 'main:session_1',
14
+ sourceId: 'session_1',
15
+ kind: 'main_thread',
16
+ origin: { kind: 'user_prompt', sessionId: 'session_1' },
17
+ status: 'idle',
18
+ title: 'Main thread',
19
+ subtitle: '2 history entries',
20
+ unread: false,
21
+ attention: 'none',
22
+ visibility: 'default',
23
+ updatedAt: '2026-05-09T00:00:00.000Z',
24
+ controls: ['select'],
25
+ ...overrides,
26
+ };
27
+ }
28
+
29
+ function makeSnapshot(): IExecutionWorkspaceSnapshot {
30
+ return {
31
+ sessionId: 'session_1',
32
+ selectedEntryId: 'main:session_1',
33
+ updatedAt: '2026-05-09T00:00:00.000Z',
34
+ entries: [
35
+ makeEntry({ id: 'main:session_1', kind: 'main_thread', title: 'Main thread' }),
36
+ makeEntry({
37
+ id: 'task:agent_1',
38
+ sourceId: 'agent_1',
39
+ kind: 'background_task',
40
+ taskKind: 'agent',
41
+ status: 'running',
42
+ title: 'Explore',
43
+ subtitle: 'general-purpose',
44
+ preview: 'Inspect task layer',
45
+ controls: ['select', 'cancel'],
46
+ }),
47
+ ],
48
+ };
49
+ }
50
+
51
+ describe('ExecutionWorkspaceSwitcher', () => {
52
+ it('renders main and background entries with selected radio markers', () => {
53
+ const { lastFrame } = render(
54
+ <ExecutionWorkspaceSwitcher
55
+ snapshot={makeSnapshot()}
56
+ selectedEntryId="task:agent_1"
57
+ onSelect={vi.fn()}
58
+ onClose={vi.fn()}
59
+ />,
60
+ );
61
+
62
+ const frame = lastFrame()!;
63
+ expect(frame).toContain('Execution workspace');
64
+ expect(frame).toContain('○ Main thread');
65
+ expect(frame).toContain('● Explore agent');
66
+ expect(frame).toContain('Inspect task layer');
67
+ });
68
+
69
+ it('commits the highlighted entry on enter without invoking task controls', () => {
70
+ const onSelect = vi.fn();
71
+ const { stdin } = render(
72
+ <ExecutionWorkspaceSwitcher
73
+ snapshot={makeSnapshot()}
74
+ selectedEntryId="main:session_1"
75
+ onSelect={onSelect}
76
+ onClose={vi.fn()}
77
+ />,
78
+ );
79
+
80
+ stdin.write('\u001B[B');
81
+ stdin.write('\r');
82
+
83
+ expect(onSelect).toHaveBeenCalledWith('task:agent_1');
84
+ });
85
+
86
+ it('renders selected entry detail records from the SDK detail page', () => {
87
+ const entry = makeEntry({
88
+ id: 'task:agent_1',
89
+ sourceId: 'agent_1',
90
+ kind: 'background_task',
91
+ taskKind: 'agent',
92
+ status: 'completed',
93
+ title: 'Explore',
94
+ preview: 'Done',
95
+ });
96
+ const { lastFrame } = render(
97
+ <ExecutionWorkspaceDetailPane
98
+ entry={entry}
99
+ page={{
100
+ entryId: 'task:agent_1',
101
+ records: [{ id: 'r1', kind: 'result', text: 'Final background result' }],
102
+ }}
103
+ />,
104
+ );
105
+
106
+ const frame = lastFrame()!;
107
+ expect(frame).toContain('Viewing Explore agent');
108
+ expect(frame).toContain('Final background result');
109
+ });
110
+ });
@@ -0,0 +1,93 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type {
3
+ IExecutionWorkspaceEntry,
4
+ IExecutionWorkspaceSnapshot,
5
+ } from '@robota-sdk/agent-framework';
6
+ import {
7
+ countActiveBackgroundWorkspaceEntries,
8
+ formatExecutionDetailRecord,
9
+ formatExecutionWorkspaceEntryRow,
10
+ getDefaultBackgroundWorkspaceEntries,
11
+ } from '../execution-workspace-view-model.js';
12
+
13
+ function makeEntry(overrides: Partial<IExecutionWorkspaceEntry>): IExecutionWorkspaceEntry {
14
+ return {
15
+ id: 'task:agent_1',
16
+ sourceId: 'agent_1',
17
+ kind: 'background_task',
18
+ origin: { kind: 'slash_command', sessionId: 'session_1', commandName: 'agent' },
19
+ taskKind: 'agent',
20
+ status: 'running',
21
+ title: 'Explore',
22
+ subtitle: 'general-purpose',
23
+ preview: 'Map the CLI state manager',
24
+ unread: false,
25
+ attention: 'none',
26
+ visibility: 'default',
27
+ updatedAt: '2026-05-09T00:00:00.000Z',
28
+ controls: ['select', 'cancel'],
29
+ ...overrides,
30
+ };
31
+ }
32
+
33
+ function makeSnapshot(entries: readonly IExecutionWorkspaceEntry[]): IExecutionWorkspaceSnapshot {
34
+ return {
35
+ sessionId: 'session_1',
36
+ selectedEntryId: 'main:session_1',
37
+ updatedAt: '2026-05-09T00:00:00.000Z',
38
+ entries,
39
+ };
40
+ }
41
+
42
+ describe('execution workspace view model', () => {
43
+ it('renders selected and inactive entries with radio markers', () => {
44
+ const row = formatExecutionWorkspaceEntryRow(makeEntry({ id: 'task:agent_1' }), {
45
+ selectedEntryId: 'task:agent_1',
46
+ });
47
+ const inactive = formatExecutionWorkspaceEntryRow(makeEntry({ id: 'task:process_1' }), {
48
+ selectedEntryId: 'task:agent_1',
49
+ });
50
+
51
+ expect(row.radio).toBe('●');
52
+ expect(row.title).toBe('Explore agent');
53
+ expect(row.subtitle).toBe('agent · general-purpose');
54
+ expect(row.statusLabel).toBe('running');
55
+ expect(inactive.radio).toBe('○');
56
+ });
57
+
58
+ it('filters default-visible background task entries for the compact panel', () => {
59
+ const snapshot = makeSnapshot([
60
+ makeEntry({ id: 'main:session_1', kind: 'main_thread', title: 'Main thread' }),
61
+ makeEntry({ id: 'task:agent_1', visibility: 'default' }),
62
+ makeEntry({ id: 'task:agent_2', visibility: 'collapsed' }),
63
+ makeEntry({ id: 'group:group_1', kind: 'background_group', visibility: 'default' }),
64
+ ]);
65
+
66
+ expect(getDefaultBackgroundWorkspaceEntries(snapshot).map((entry) => entry.id)).toEqual([
67
+ 'task:agent_1',
68
+ ]);
69
+ });
70
+
71
+ it('counts active default-visible background tasks without treating collapsed tasks as active', () => {
72
+ const snapshot = makeSnapshot([
73
+ makeEntry({ id: 'task:queued', status: 'queued' }),
74
+ makeEntry({ id: 'task:running', status: 'running' }),
75
+ makeEntry({ id: 'task:permission', status: 'waiting_permission' }),
76
+ makeEntry({ id: 'task:done', status: 'completed' }),
77
+ makeEntry({ id: 'task:hidden', status: 'running', visibility: 'collapsed' }),
78
+ ]);
79
+
80
+ expect(countActiveBackgroundWorkspaceEntries(snapshot)).toBe(3);
81
+ });
82
+
83
+ it('bounds detail record text without parsing runner-specific output', () => {
84
+ const text = formatExecutionDetailRecord({
85
+ id: 'record_1',
86
+ kind: 'process_output',
87
+ text: ` ${'a'.repeat(180)} `,
88
+ });
89
+
90
+ expect(text).toHaveLength(163);
91
+ expect(text.endsWith('...')).toBe(true);
92
+ });
93
+ });