@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.
- package/LICENSE +21 -0
- package/dist/node/headless/index.cjs +1 -0
- package/dist/node/headless/index.d.ts +2 -0
- package/dist/node/headless/index.js +1 -0
- package/dist/node/headless-CWEpJXFK.js +7 -0
- package/dist/node/headless-CWEpJXFK.js.map +1 -0
- package/dist/node/headless-CsZFelG9.cjs +6 -0
- package/dist/node/http/index.cjs +1 -0
- package/dist/node/http/index.d.ts +2 -0
- package/dist/node/http/index.js +1 -0
- package/dist/node/http-CM3TJhrF.cjs +1 -0
- package/dist/node/http-DwO1AHG-.js +2 -0
- package/dist/node/http-DwO1AHG-.js.map +1 -0
- package/dist/node/index--Ti9NzQX.d.ts +64 -0
- package/dist/node/index--Ti9NzQX.d.ts.map +1 -0
- package/dist/node/index-B_rcr14p.d.ts +47 -0
- package/dist/node/index-B_rcr14p.d.ts.map +1 -0
- package/dist/node/index-C9LWCL4l.d.ts +34 -0
- package/dist/node/index-C9LWCL4l.d.ts.map +1 -0
- package/dist/node/index-CAr3ioVh.d.ts +64 -0
- package/dist/node/index-CAr3ioVh.d.ts.map +1 -0
- package/dist/node/index-CEs25wVk.d.ts +213 -0
- package/dist/node/index-CEs25wVk.d.ts.map +1 -0
- package/dist/node/index-CvXLpjJO.d.ts +213 -0
- package/dist/node/index-CvXLpjJO.d.ts.map +1 -0
- package/dist/node/index-D34WUfFH.d.ts +26 -0
- package/dist/node/index-D34WUfFH.d.ts.map +1 -0
- package/dist/node/index-Y0zHb1Bz.d.ts +47 -0
- package/dist/node/index-Y0zHb1Bz.d.ts.map +1 -0
- package/dist/node/index-k3TUjA-T.d.ts +26 -0
- package/dist/node/index-k3TUjA-T.d.ts.map +1 -0
- package/dist/node/index-nBlMTFkZ.d.ts +34 -0
- package/dist/node/index-nBlMTFkZ.d.ts.map +1 -0
- package/dist/node/index.cjs +1 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.js +1 -0
- package/dist/node/mcp/index.cjs +1 -0
- package/dist/node/mcp/index.d.ts +2 -0
- package/dist/node/mcp/index.js +1 -0
- package/dist/node/mcp-BXBwF6Wu.js +2 -0
- package/dist/node/mcp-BXBwF6Wu.js.map +1 -0
- package/dist/node/mcp-DcHuGokt.cjs +1 -0
- package/dist/node/tui/index.cjs +1 -0
- package/dist/node/tui/index.d.ts +2 -0
- package/dist/node/tui/index.js +1 -0
- package/dist/node/tui-CeD_6rSo.cjs +24 -0
- package/dist/node/tui-zmDTPk4b.js +25 -0
- package/dist/node/tui-zmDTPk4b.js.map +1 -0
- package/dist/node/ws/index.cjs +1 -0
- package/dist/node/ws/index.d.ts +2 -0
- package/dist/node/ws/index.js +1 -0
- package/dist/node/ws-B-oRccFl.js +2 -0
- package/dist/node/ws-B-oRccFl.js.map +1 -0
- package/dist/node/ws-COnIgnmn.cjs +1 -0
- package/package.json +141 -0
- package/src/headless/__tests__/headless-runner-initialization.test.ts +45 -0
- package/src/headless/__tests__/headless-runner.test.ts +484 -0
- package/src/headless/__tests__/headless-skill-activation.integration.test.ts +430 -0
- package/src/headless/__tests__/headless-transport.test.ts +268 -0
- package/src/headless/headless-runner.ts +141 -0
- package/src/headless/headless-stream-json.ts +142 -0
- package/src/headless/headless-transport.ts +43 -0
- package/src/headless/index.ts +4 -0
- package/src/http/__tests__/http-transport.test.ts +55 -0
- package/src/http/__tests__/routes.test.ts +168 -0
- package/src/http/http-transport.ts +42 -0
- package/src/http/index.ts +4 -0
- package/src/http/routes.ts +151 -0
- package/src/index.ts +5 -0
- package/src/mcp/__tests__/mcp-server.test.ts +66 -0
- package/src/mcp/__tests__/mcp-transport.test.ts +46 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/mcp-server.ts +162 -0
- package/src/mcp/mcp-transport.ts +48 -0
- package/src/tui/App.tsx +478 -0
- package/src/tui/BackgroundTaskPanel.tsx +34 -0
- package/src/tui/CjkTextInput.tsx +204 -0
- package/src/tui/ConfirmPrompt.tsx +69 -0
- package/src/tui/ExecutionWorkspaceDetailPane.tsx +62 -0
- package/src/tui/ExecutionWorkspaceSwitcher.tsx +185 -0
- package/src/tui/InkTerminal.ts +42 -0
- package/src/tui/InputArea.tsx +298 -0
- package/src/tui/InteractivePrompt.tsx +57 -0
- package/src/tui/ListPicker.tsx +94 -0
- package/src/tui/MenuSelect.tsx +103 -0
- package/src/tui/MessageList.tsx +282 -0
- package/src/tui/PermissionPrompt.tsx +84 -0
- package/src/tui/PluginTUI.tsx +256 -0
- package/src/tui/SessionPicker.tsx +66 -0
- package/src/tui/SessionStatusBar.tsx +66 -0
- package/src/tui/SlashAutocomplete.tsx +110 -0
- package/src/tui/StatusBar.tsx +213 -0
- package/src/tui/StreamingIndicator.tsx +91 -0
- package/src/tui/TextPrompt.tsx +80 -0
- package/src/tui/ToolCommandOutput.tsx +37 -0
- package/src/tui/ToolDiffBlock.tsx +30 -0
- package/src/tui/TransportTUI.tsx +116 -0
- package/src/tui/UpdateNotice.tsx +14 -0
- package/src/tui/UsageSummaryEntry.tsx +38 -0
- package/src/tui/WaveText.tsx +44 -0
- package/src/tui/__tests__/InteractivePrompt.test.tsx +82 -0
- package/src/tui/__tests__/ListPicker.test.tsx +159 -0
- package/src/tui/__tests__/MenuSelect.test.tsx +103 -0
- package/src/tui/__tests__/PluginTUI.test.tsx +167 -0
- package/src/tui/__tests__/SlashAutocomplete.test.tsx +140 -0
- package/src/tui/__tests__/TextPrompt.test.tsx +98 -0
- package/src/tui/__tests__/UpdateNotice.test.tsx +15 -0
- package/src/tui/__tests__/abort-after-permission.test.tsx +169 -0
- package/src/tui/__tests__/abort-streaming-e2e.test.tsx +183 -0
- package/src/tui/__tests__/background-task-panel.test.tsx +53 -0
- package/src/tui/__tests__/background-task-row-format.test.ts +59 -0
- package/src/tui/__tests__/cjk-text-input-flow.test.ts +109 -0
- package/src/tui/__tests__/cjk-text-input.test.ts +191 -0
- package/src/tui/__tests__/command-effect-handler.test.ts +128 -0
- package/src/tui/__tests__/command-output-summary.test.ts +95 -0
- package/src/tui/__tests__/compact-event-bridge.test.ts +20 -0
- package/src/tui/__tests__/confirm-permission-flow.test.ts +91 -0
- package/src/tui/__tests__/confirm-prompt.test.tsx +87 -0
- package/src/tui/__tests__/execution-workspace-switcher.test.tsx +110 -0
- package/src/tui/__tests__/execution-workspace-view-model.test.ts +93 -0
- package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +122 -0
- package/src/tui/__tests__/input-area-flow.test.ts +152 -0
- package/src/tui/__tests__/message-list-rendering.test.tsx +353 -0
- package/src/tui/__tests__/model-change-side-effect.test.ts +91 -0
- package/src/tui/__tests__/prompt-queue.test.tsx +255 -0
- package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +233 -0
- package/src/tui/__tests__/render-markdown.test.ts +72 -0
- package/src/tui/__tests__/selection-flow.test.ts +61 -0
- package/src/tui/__tests__/slash-routing-effects.test.ts +225 -0
- package/src/tui/__tests__/status-activity.test.ts +71 -0
- package/src/tui/__tests__/status-bar.test.tsx +157 -0
- package/src/tui/__tests__/streaming-indicator.test.tsx +137 -0
- package/src/tui/__tests__/text-prompt-flow.test.ts +77 -0
- package/src/tui/__tests__/tui-state-manager.test.ts +401 -0
- package/src/tui/background-task-row-format.ts +52 -0
- package/src/tui/command-output-summary.ts +122 -0
- package/src/tui/execution-workspace-view-model.ts +123 -0
- package/src/tui/flows/cjk-text-input-flow.ts +285 -0
- package/src/tui/flows/confirm-prompt-flow.ts +45 -0
- package/src/tui/flows/input-area-flow.ts +186 -0
- package/src/tui/flows/permission-prompt-flow.ts +76 -0
- package/src/tui/flows/selection-flow.ts +126 -0
- package/src/tui/flows/text-prompt-flow.ts +98 -0
- package/src/tui/hooks/command-effect-handler.ts +98 -0
- package/src/tui/hooks/command-effect-queue.ts +39 -0
- package/src/tui/hooks/model-change-side-effect.ts +63 -0
- package/src/tui/hooks/side-effects-types.ts +38 -0
- package/src/tui/hooks/use-interactive-session-init.ts +50 -0
- package/src/tui/hooks/useAutocomplete.ts +85 -0
- package/src/tui/hooks/useInteractiveSession.ts +273 -0
- package/src/tui/hooks/usePermissionQueue.ts +51 -0
- package/src/tui/hooks/usePluginCallbacks.ts +30 -0
- package/src/tui/hooks/usePluginScreenData.ts +84 -0
- package/src/tui/hooks/useSideEffects.ts +210 -0
- package/src/tui/hooks/useSlashRouting.ts +117 -0
- package/src/tui/hooks/useStatusLineSettings.ts +35 -0
- package/src/tui/index.ts +3 -0
- package/src/tui/plugin-tui-handlers.ts +163 -0
- package/src/tui/render-markdown.ts +129 -0
- package/src/tui/render.tsx +60 -0
- package/src/tui/status-activity.ts +63 -0
- package/src/tui/tui-cli-adapter-context.tsx +12 -0
- package/src/tui/tui-cli-adapter.ts +25 -0
- package/src/tui/tui-state-manager.ts +225 -0
- package/src/tui/tui-transport.ts +32 -0
- package/src/tui/types.ts +14 -0
- package/src/tui/utils/__tests__/edit-diff.test.ts +426 -0
- package/src/tui/utils/__tests__/paste-detection.test.ts +116 -0
- package/src/tui/utils/__tests__/paste-labels.test.ts +46 -0
- package/src/tui/utils/__tests__/tool-call-extractor.test.ts +227 -0
- package/src/tui/utils/__tests__/tool-diff-summary.test.ts +104 -0
- package/src/tui/utils/edit-diff.ts +152 -0
- package/src/tui/utils/paste-labels.ts +9 -0
- package/src/tui/utils/tool-call-extractor.ts +91 -0
- package/src/tui/utils/tool-diff-summary.ts +75 -0
- package/src/ws/__tests__/ws-handler.test.ts +407 -0
- package/src/ws/__tests__/ws-transport.test.ts +53 -0
- package/src/ws/index.ts +13 -0
- package/src/ws/ws-background-messages.ts +170 -0
- package/src/ws/ws-handler.ts +279 -0
- package/src/ws/ws-protocol.ts +76 -0
- package/src/ws/ws-transport-configurable.ts +123 -0
- package/src/ws/ws-transport.ts +42 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJK-aware TextInput component for Ink.
|
|
3
|
+
*
|
|
4
|
+
* Replaces ink-text-input with proper wide character support:
|
|
5
|
+
* - Uses string-width for display width calculation
|
|
6
|
+
* - Cursor position based on character index (not display columns)
|
|
7
|
+
* - Renders CJK characters correctly (2 columns each)
|
|
8
|
+
* - Uses refs for value/cursor to avoid React state batching issues
|
|
9
|
+
* (IME sends multiple keystrokes synchronously, state updates are async)
|
|
10
|
+
*
|
|
11
|
+
* Drop-in replacement: same props as ink-text-input.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import React, { useRef, useState } from 'react';
|
|
15
|
+
import { Text, useInput, usePaste } from 'ink';
|
|
16
|
+
import chalk from 'chalk';
|
|
17
|
+
import {
|
|
18
|
+
applyCjkTextInput,
|
|
19
|
+
applyCjkTextPaste,
|
|
20
|
+
createCjkTextInputFlowState,
|
|
21
|
+
syncCjkTextInputFlowState,
|
|
22
|
+
type ICjkTextInputFlowState,
|
|
23
|
+
} from './flows/cjk-text-input-flow.js';
|
|
24
|
+
|
|
25
|
+
interface IProps {
|
|
26
|
+
value: string;
|
|
27
|
+
onChange: (value: string) => void;
|
|
28
|
+
onSubmit?: (value: string) => void;
|
|
29
|
+
onPaste?: (text: string, cursorPosition: number) => void;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
focus?: boolean;
|
|
32
|
+
showCursor?: boolean;
|
|
33
|
+
/** Available width in columns for visual line wrapping navigation */
|
|
34
|
+
availableWidth?: number;
|
|
35
|
+
/** Cursor position hint for external value changes. null = end (default). */
|
|
36
|
+
cursorHint?: number | null;
|
|
37
|
+
/** When false, parent flows own up/down arrow behavior. */
|
|
38
|
+
enableVerticalNavigation?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface IInputHandlerOptions {
|
|
42
|
+
stateRef: React.MutableRefObject<ICjkTextInputFlowState>;
|
|
43
|
+
onChange: (value: string) => void;
|
|
44
|
+
onSubmit?: (value: string) => void;
|
|
45
|
+
onPaste?: (text: string, cursorPosition: number) => void;
|
|
46
|
+
availableWidth?: number;
|
|
47
|
+
focus: boolean;
|
|
48
|
+
enableVerticalNavigation: boolean;
|
|
49
|
+
forceRender: React.Dispatch<React.SetStateAction<number>>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default function CjkTextInput({
|
|
53
|
+
value,
|
|
54
|
+
onChange,
|
|
55
|
+
onSubmit,
|
|
56
|
+
onPaste,
|
|
57
|
+
placeholder = '',
|
|
58
|
+
focus = true,
|
|
59
|
+
showCursor = true,
|
|
60
|
+
availableWidth,
|
|
61
|
+
cursorHint = null,
|
|
62
|
+
enableVerticalNavigation = true,
|
|
63
|
+
}: IProps): React.ReactElement {
|
|
64
|
+
const stateRef = useRef<ICjkTextInputFlowState>(createCjkTextInputFlowState(value));
|
|
65
|
+
const [, forceRender] = useState(0);
|
|
66
|
+
|
|
67
|
+
// useCursor removed — see comment below about Terminal.app SIGSEGV
|
|
68
|
+
|
|
69
|
+
// Sync ref when value changes from parent (e.g., setValue(''), tab completion, paste)
|
|
70
|
+
stateRef.current = syncCjkTextInputFlowState(stateRef.current, value, cursorHint);
|
|
71
|
+
|
|
72
|
+
useCjkTextInputHandlers({
|
|
73
|
+
stateRef,
|
|
74
|
+
onChange,
|
|
75
|
+
onSubmit,
|
|
76
|
+
onPaste,
|
|
77
|
+
availableWidth,
|
|
78
|
+
focus,
|
|
79
|
+
enableVerticalNavigation,
|
|
80
|
+
forceRender,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Do NOT call setCursorPosition() — passing y:0 moves the real terminal cursor
|
|
84
|
+
// to the top of the entire ink output (logo area), which causes Terminal.app to
|
|
85
|
+
// SIGSEGV when Korean IME queries attributedSubstringFromRange: at that position.
|
|
86
|
+
// Without setCursorPosition, the IME candidate window appears at bottom-left
|
|
87
|
+
// (same behavior as Claude Code, issue #19207), but Terminal.app does not crash.
|
|
88
|
+
//
|
|
89
|
+
// A correct fix would require knowing the total rendered height to pass the right
|
|
90
|
+
// y coordinate, which ink does not expose to components.
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<Text>
|
|
94
|
+
{renderWithCursor(
|
|
95
|
+
stateRef.current.value,
|
|
96
|
+
stateRef.current.cursor,
|
|
97
|
+
placeholder,
|
|
98
|
+
showCursor && focus,
|
|
99
|
+
)}
|
|
100
|
+
</Text>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function useCjkTextInputHandlers(options: IInputHandlerOptions): void {
|
|
105
|
+
usePaste(
|
|
106
|
+
(text) => {
|
|
107
|
+
applyCjkFlowSafely(options, () =>
|
|
108
|
+
applyCjkTextPaste(options.stateRef.current, text, createFlowOptions(options)),
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
{ isActive: options.focus },
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
useInput(
|
|
115
|
+
(input, key) => {
|
|
116
|
+
applyCjkFlowSafely(options, () =>
|
|
117
|
+
applyCjkTextInput(options.stateRef.current, input, key, createFlowOptions(options)),
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
{ isActive: options.focus },
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createFlowOptions(options: IInputHandlerOptions): {
|
|
125
|
+
availableWidth?: number;
|
|
126
|
+
canPaste: boolean;
|
|
127
|
+
enableVerticalNavigation: boolean;
|
|
128
|
+
} {
|
|
129
|
+
return {
|
|
130
|
+
availableWidth: options.availableWidth,
|
|
131
|
+
canPaste: options.onPaste !== undefined,
|
|
132
|
+
enableVerticalNavigation: options.enableVerticalNavigation,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function applyCjkFlowSafely(
|
|
137
|
+
options: IInputHandlerOptions,
|
|
138
|
+
run: () => ReturnType<typeof applyCjkTextInput>,
|
|
139
|
+
): void {
|
|
140
|
+
try {
|
|
141
|
+
const result = run();
|
|
142
|
+
options.stateRef.current = result.state;
|
|
143
|
+
applyCjkTextInputEffect(
|
|
144
|
+
result.effect,
|
|
145
|
+
options.onChange,
|
|
146
|
+
options.onSubmit,
|
|
147
|
+
options.onPaste,
|
|
148
|
+
options.forceRender,
|
|
149
|
+
);
|
|
150
|
+
} catch {
|
|
151
|
+
// Korean IME in raw mode can produce unexpected byte sequences.
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function applyCjkTextInputEffect(
|
|
156
|
+
effect: ReturnType<typeof applyCjkTextInput>['effect'],
|
|
157
|
+
onChange: (value: string) => void,
|
|
158
|
+
onSubmit: ((value: string) => void) | undefined,
|
|
159
|
+
onPaste: ((text: string, cursorPosition: number) => void) | undefined,
|
|
160
|
+
forceRender: React.Dispatch<React.SetStateAction<number>>,
|
|
161
|
+
): void {
|
|
162
|
+
if (effect.type === 'change') {
|
|
163
|
+
onChange(effect.value);
|
|
164
|
+
} else if (effect.type === 'submit') {
|
|
165
|
+
onSubmit?.(effect.value);
|
|
166
|
+
} else if (effect.type === 'paste') {
|
|
167
|
+
onPaste?.(effect.text, effect.cursor);
|
|
168
|
+
} else if (effect.type === 'render') {
|
|
169
|
+
forceRender((n) => n + 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Render text with an inverse-style cursor at the correct position */
|
|
174
|
+
function renderWithCursor(
|
|
175
|
+
value: string,
|
|
176
|
+
cursorOffset: number,
|
|
177
|
+
placeholder: string,
|
|
178
|
+
showCursor: boolean,
|
|
179
|
+
): string {
|
|
180
|
+
if (!showCursor) {
|
|
181
|
+
return value.length > 0 ? value : placeholder ? chalk.gray(placeholder) : '';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (value.length === 0) {
|
|
185
|
+
if (placeholder.length > 0) {
|
|
186
|
+
return chalk.inverse(placeholder[0]) + chalk.gray(placeholder.slice(1));
|
|
187
|
+
}
|
|
188
|
+
return chalk.inverse(' ');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const chars = [...value];
|
|
192
|
+
let rendered = '';
|
|
193
|
+
|
|
194
|
+
for (let i = 0; i < chars.length; i++) {
|
|
195
|
+
const char = chars[i] ?? '';
|
|
196
|
+
rendered += i === cursorOffset ? chalk.inverse(char) : char;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (cursorOffset >= chars.length) {
|
|
200
|
+
rendered += chalk.inverse(' ');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return rendered;
|
|
204
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reusable confirmation prompt with arrow-key selection.
|
|
3
|
+
* Used by model change, permission prompts, and other yes/no confirmations.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState, useRef, useCallback } from 'react';
|
|
7
|
+
import { Box, Text, useInput } from 'ink';
|
|
8
|
+
import {
|
|
9
|
+
applyConfirmPromptInput,
|
|
10
|
+
getConfirmPromptInputAction,
|
|
11
|
+
type TConfirmPromptInputAction,
|
|
12
|
+
} from './flows/confirm-prompt-flow.js';
|
|
13
|
+
import { createSelectionFlowState, type ISelectionFlowState } from './flows/selection-flow.js';
|
|
14
|
+
|
|
15
|
+
interface IProps {
|
|
16
|
+
/** Message to display above the options */
|
|
17
|
+
message: string;
|
|
18
|
+
/** Options to select from (default: ['Yes', 'No']) */
|
|
19
|
+
options?: string[];
|
|
20
|
+
/** Callback with the selected index */
|
|
21
|
+
onSelect: (index: number) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function ConfirmPrompt({
|
|
25
|
+
message,
|
|
26
|
+
options = ['Yes', 'No'],
|
|
27
|
+
onSelect,
|
|
28
|
+
}: IProps): React.ReactElement {
|
|
29
|
+
const [state, setState] = useState<ISelectionFlowState>(() => createSelectionFlowState());
|
|
30
|
+
const stateRef = useRef(state);
|
|
31
|
+
const applyAction = useCallback(
|
|
32
|
+
(action: TConfirmPromptInputAction): void => {
|
|
33
|
+
const result = applyConfirmPromptInput(stateRef.current, action, options.length);
|
|
34
|
+
stateRef.current = result.state;
|
|
35
|
+
setState(result.state);
|
|
36
|
+
if (result.effect.type === 'select') {
|
|
37
|
+
onSelect(result.effect.index);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
[onSelect, options.length],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
useInput((input, key) => {
|
|
44
|
+
const action = getConfirmPromptInputAction(input, key, options.length);
|
|
45
|
+
if (action !== undefined) {
|
|
46
|
+
applyAction(action);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Box flexDirection="column" borderStyle="round" borderColor="yellow" paddingX={1}>
|
|
52
|
+
<Text color="yellow">{message}</Text>
|
|
53
|
+
<Box marginTop={1}>
|
|
54
|
+
{options.map((opt, i) => (
|
|
55
|
+
<Box key={opt} marginRight={2}>
|
|
56
|
+
<Text
|
|
57
|
+
color={i === state.selectedIndex ? 'cyan' : undefined}
|
|
58
|
+
bold={i === state.selectedIndex}
|
|
59
|
+
>
|
|
60
|
+
{i === state.selectedIndex ? '> ' : ' '}
|
|
61
|
+
{opt}
|
|
62
|
+
</Text>
|
|
63
|
+
</Box>
|
|
64
|
+
))}
|
|
65
|
+
</Box>
|
|
66
|
+
<Text dimColor> arrow keys to select, Enter to confirm</Text>
|
|
67
|
+
</Box>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import type {
|
|
4
|
+
IExecutionDetailPage,
|
|
5
|
+
IExecutionWorkspaceEntry,
|
|
6
|
+
TExecutionDetailRecordKind,
|
|
7
|
+
} from '@robota-sdk/agent-framework';
|
|
8
|
+
import {
|
|
9
|
+
formatExecutionDetailRecord,
|
|
10
|
+
formatExecutionWorkspaceEntryRow,
|
|
11
|
+
} from './execution-workspace-view-model.js';
|
|
12
|
+
|
|
13
|
+
const MAX_VISIBLE_DETAIL_RECORDS = 12;
|
|
14
|
+
|
|
15
|
+
interface IProps {
|
|
16
|
+
entry: IExecutionWorkspaceEntry;
|
|
17
|
+
page: IExecutionDetailPage | null;
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function ExecutionWorkspaceDetailPane({
|
|
23
|
+
entry,
|
|
24
|
+
page,
|
|
25
|
+
loading,
|
|
26
|
+
error,
|
|
27
|
+
}: IProps): React.ReactElement {
|
|
28
|
+
const row = formatExecutionWorkspaceEntryRow(entry, { selectedEntryId: entry.id });
|
|
29
|
+
const records = page?.records.slice(-MAX_VISIBLE_DETAIL_RECORDS) ?? [];
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
33
|
+
<Text color="cyan" bold>
|
|
34
|
+
{`Viewing ${row.title}`}
|
|
35
|
+
</Text>
|
|
36
|
+
<Text dimColor>
|
|
37
|
+
{row.statusLabel}
|
|
38
|
+
{row.subtitle ? ` · ${row.subtitle}` : ''}
|
|
39
|
+
{row.preview ? ` · ${row.preview}` : ''}
|
|
40
|
+
</Text>
|
|
41
|
+
{loading ? <Text dimColor>Loading workspace detail...</Text> : null}
|
|
42
|
+
{error ? <Text color="red">{error}</Text> : null}
|
|
43
|
+
{!loading && !error && records.length === 0 ? <Text dimColor>No detail yet</Text> : null}
|
|
44
|
+
{!loading &&
|
|
45
|
+
!error &&
|
|
46
|
+
records.map((record) => (
|
|
47
|
+
<Text key={record.id} color={getDetailRecordColor(record.kind)}>
|
|
48
|
+
{formatExecutionDetailRecord(record)}
|
|
49
|
+
</Text>
|
|
50
|
+
))}
|
|
51
|
+
{page?.nextCursor ? <Text dimColor>... more detail available</Text> : null}
|
|
52
|
+
</Box>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getDetailRecordColor(kind: TExecutionDetailRecordKind): string | undefined {
|
|
57
|
+
if (kind === 'error') return 'red';
|
|
58
|
+
if (kind === 'result') return 'green';
|
|
59
|
+
if (kind === 'process_output') return 'white';
|
|
60
|
+
if (kind === 'group_summary') return 'cyan';
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import type {
|
|
4
|
+
IExecutionWorkspaceEntry,
|
|
5
|
+
IExecutionWorkspaceSnapshot,
|
|
6
|
+
} from '@robota-sdk/agent-framework';
|
|
7
|
+
import {
|
|
8
|
+
applySelectionInput,
|
|
9
|
+
createSelectionFlowState,
|
|
10
|
+
getVerticalSelectionInputAction,
|
|
11
|
+
normalizeSelectionState,
|
|
12
|
+
type ISelectionFlowState,
|
|
13
|
+
type TSelectionInputAction,
|
|
14
|
+
} from './flows/selection-flow.js';
|
|
15
|
+
import { formatExecutionWorkspaceEntryRow } from './execution-workspace-view-model.js';
|
|
16
|
+
|
|
17
|
+
const MAX_VISIBLE_WORKSPACE_ENTRIES = 8;
|
|
18
|
+
|
|
19
|
+
interface IProps {
|
|
20
|
+
snapshot: IExecutionWorkspaceSnapshot | null;
|
|
21
|
+
selectedEntryId?: string;
|
|
22
|
+
onSelect: (entryId: string) => void;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function ExecutionWorkspaceSwitcher({
|
|
27
|
+
snapshot,
|
|
28
|
+
selectedEntryId,
|
|
29
|
+
onSelect,
|
|
30
|
+
onClose,
|
|
31
|
+
}: IProps): React.ReactElement {
|
|
32
|
+
const entries = [...(snapshot?.entries ?? [])];
|
|
33
|
+
const { normalized, visibleEntries, applyAction } = useWorkspaceSwitcherSelection({
|
|
34
|
+
entries,
|
|
35
|
+
selectedEntryId,
|
|
36
|
+
onSelect,
|
|
37
|
+
onClose,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
useInput((_input, key) => {
|
|
41
|
+
const action = getVerticalSelectionInputAction(key);
|
|
42
|
+
if (action !== undefined) applyAction(action);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Box flexDirection="column" borderStyle="round" borderColor="cyan" paddingX={1}>
|
|
47
|
+
<Text color="cyan" bold>
|
|
48
|
+
Execution workspace
|
|
49
|
+
</Text>
|
|
50
|
+
<Box flexDirection="column" marginTop={1}>
|
|
51
|
+
{visibleEntries.length === 0 ? (
|
|
52
|
+
<Text dimColor>No workspace entries</Text>
|
|
53
|
+
) : (
|
|
54
|
+
visibleEntries.map((entry, index) => (
|
|
55
|
+
<ExecutionWorkspaceSwitcherRow
|
|
56
|
+
key={entry.id}
|
|
57
|
+
entry={entry}
|
|
58
|
+
isFocused={normalized.scrollOffset + index === normalized.selectedIndex}
|
|
59
|
+
selectedEntryId={selectedEntryId}
|
|
60
|
+
/>
|
|
61
|
+
))
|
|
62
|
+
)}
|
|
63
|
+
</Box>
|
|
64
|
+
<Text dimColor>Ctrl+B Close ↑↓ Navigate Enter Switch Esc Close</Text>
|
|
65
|
+
</Box>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface IUseWorkspaceSwitcherSelectionInput {
|
|
70
|
+
entries: IExecutionWorkspaceEntry[];
|
|
71
|
+
selectedEntryId?: string;
|
|
72
|
+
onSelect: (entryId: string) => void;
|
|
73
|
+
onClose: () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function useWorkspaceSwitcherSelection({
|
|
77
|
+
entries,
|
|
78
|
+
selectedEntryId,
|
|
79
|
+
onSelect,
|
|
80
|
+
onClose,
|
|
81
|
+
}: IUseWorkspaceSwitcherSelectionInput): {
|
|
82
|
+
normalized: ISelectionFlowState;
|
|
83
|
+
visibleEntries: IExecutionWorkspaceEntry[];
|
|
84
|
+
applyAction: (action: TSelectionInputAction) => void;
|
|
85
|
+
} {
|
|
86
|
+
const [state, setState] = useState<ISelectionFlowState>(() => createSelectionFlowState());
|
|
87
|
+
const stateRef = useRef(state);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const selectedIndex = Math.max(
|
|
91
|
+
0,
|
|
92
|
+
entries.findIndex((entry) => entry.id === selectedEntryId),
|
|
93
|
+
);
|
|
94
|
+
const nextState = createNormalizedSelection({ selectedIndex, itemCount: entries.length });
|
|
95
|
+
stateRef.current = nextState;
|
|
96
|
+
setState(nextState);
|
|
97
|
+
}, [entries.length, selectedEntryId]);
|
|
98
|
+
|
|
99
|
+
const normalized = createNormalizedSelection({
|
|
100
|
+
selectedIndex: state.selectedIndex,
|
|
101
|
+
scrollOffset: state.scrollOffset,
|
|
102
|
+
itemCount: entries.length,
|
|
103
|
+
});
|
|
104
|
+
if (normalized !== state) stateRef.current = normalized;
|
|
105
|
+
return {
|
|
106
|
+
normalized,
|
|
107
|
+
visibleEntries: entries.slice(
|
|
108
|
+
normalized.scrollOffset,
|
|
109
|
+
normalized.scrollOffset + MAX_VISIBLE_WORKSPACE_ENTRIES,
|
|
110
|
+
),
|
|
111
|
+
applyAction: createApplyAction({ entries, stateRef, setState, onSelect, onClose }),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function createApplyAction({
|
|
116
|
+
entries,
|
|
117
|
+
stateRef,
|
|
118
|
+
setState,
|
|
119
|
+
onSelect,
|
|
120
|
+
onClose,
|
|
121
|
+
}: {
|
|
122
|
+
entries: IExecutionWorkspaceEntry[];
|
|
123
|
+
stateRef: React.MutableRefObject<ISelectionFlowState>;
|
|
124
|
+
setState: React.Dispatch<React.SetStateAction<ISelectionFlowState>>;
|
|
125
|
+
onSelect: (entryId: string) => void;
|
|
126
|
+
onClose: () => void;
|
|
127
|
+
}): (action: TSelectionInputAction) => void {
|
|
128
|
+
return (action): void => {
|
|
129
|
+
const result = applySelectionInput(stateRef.current, action, {
|
|
130
|
+
itemCount: entries.length,
|
|
131
|
+
maxVisible: MAX_VISIBLE_WORKSPACE_ENTRIES,
|
|
132
|
+
});
|
|
133
|
+
const nextState =
|
|
134
|
+
result.effect.type === 'select' || result.effect.type === 'cancel'
|
|
135
|
+
? { ...result.state, resolved: false }
|
|
136
|
+
: result.state;
|
|
137
|
+
stateRef.current = nextState;
|
|
138
|
+
setState(nextState);
|
|
139
|
+
if (result.effect.type === 'cancel') {
|
|
140
|
+
onClose();
|
|
141
|
+
} else if (result.effect.type === 'select') {
|
|
142
|
+
const entry = entries[result.effect.index];
|
|
143
|
+
if (entry) onSelect(entry.id);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function createNormalizedSelection(input: {
|
|
149
|
+
selectedIndex: number;
|
|
150
|
+
scrollOffset?: number;
|
|
151
|
+
itemCount: number;
|
|
152
|
+
}): ISelectionFlowState {
|
|
153
|
+
return normalizeSelectionState(
|
|
154
|
+
{
|
|
155
|
+
selectedIndex: input.selectedIndex,
|
|
156
|
+
scrollOffset: input.scrollOffset ?? 0,
|
|
157
|
+
resolved: false,
|
|
158
|
+
},
|
|
159
|
+
{ itemCount: input.itemCount, maxVisible: MAX_VISIBLE_WORKSPACE_ENTRIES },
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function ExecutionWorkspaceSwitcherRow({
|
|
164
|
+
entry,
|
|
165
|
+
isFocused,
|
|
166
|
+
selectedEntryId,
|
|
167
|
+
}: {
|
|
168
|
+
entry: IExecutionWorkspaceEntry;
|
|
169
|
+
isFocused: boolean;
|
|
170
|
+
selectedEntryId?: string;
|
|
171
|
+
}): React.ReactElement {
|
|
172
|
+
const row = formatExecutionWorkspaceEntryRow(entry, { selectedEntryId });
|
|
173
|
+
return (
|
|
174
|
+
<Text>
|
|
175
|
+
<Text color={isFocused ? 'cyan' : undefined} bold={isFocused}>
|
|
176
|
+
{isFocused ? '> ' : ' '}
|
|
177
|
+
</Text>
|
|
178
|
+
<Text color={row.color}>{row.radio}</Text>
|
|
179
|
+
<Text color={isFocused ? 'cyan' : undefined} bold={isFocused}>{` ${row.title}`}</Text>
|
|
180
|
+
<Text dimColor>{` · ${row.statusLabel}`}</Text>
|
|
181
|
+
{row.subtitle ? <Text dimColor>{` · ${row.subtitle}`}</Text> : null}
|
|
182
|
+
{row.preview ? <Text dimColor>{` · ${row.preview}`}</Text> : null}
|
|
183
|
+
</Text>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ITerminalOutput implementation for Ink TUI.
|
|
3
|
+
*
|
|
4
|
+
* Permission prompts are handled by setting React state via a callback,
|
|
5
|
+
* which triggers the PermissionPrompt component to render.
|
|
6
|
+
* All other output methods are no-ops since Ink manages rendering.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { TToolArgs } from '@robota-sdk/agent-core';
|
|
10
|
+
import type { ITerminalOutput, ISpinner } from '@robota-sdk/agent-core';
|
|
11
|
+
|
|
12
|
+
export type TPermissionResolver = (toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create an ITerminalOutput adapter for the Ink UI.
|
|
16
|
+
*
|
|
17
|
+
* @param _onPermissionRequest - Called when a tool needs user approval.
|
|
18
|
+
* The function should show a UI prompt and resolve with true (allow) or false (deny).
|
|
19
|
+
*/
|
|
20
|
+
export function createInkTerminal(_onPermissionRequest: TPermissionResolver): ITerminalOutput {
|
|
21
|
+
const noopSpinner: ISpinner = {
|
|
22
|
+
stop: () => {},
|
|
23
|
+
update: () => {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
write: () => {},
|
|
28
|
+
writeLine: () => {},
|
|
29
|
+
writeMarkdown: () => {},
|
|
30
|
+
writeError: () => {},
|
|
31
|
+
|
|
32
|
+
prompt: (_question: string) => Promise.resolve(''),
|
|
33
|
+
|
|
34
|
+
select: async (options: string[], initialIndex = 0) => {
|
|
35
|
+
// Called by permission-prompt.ts via promptForApproval
|
|
36
|
+
// We intercept at checkPermission level instead, so this shouldn't be called
|
|
37
|
+
return initialIndex;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
spinner: () => noopSpinner,
|
|
41
|
+
};
|
|
42
|
+
}
|