@rind-ai/cli 0.4.1 → 0.6.1
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/bin/rind.js +5 -5
- package/lib/assistant-renderer.js +179 -265
- package/lib/choice-menu-state.js +46 -46
- package/lib/cli-input-actions.js +548 -0
- package/lib/cli-output-controller.js +460 -0
- package/lib/cli-runtime-controller.js +350 -0
- package/lib/cli-state-store.js +32 -0
- package/lib/cli-state.js +41 -0
- package/lib/command-controller.js +159 -126
- package/lib/compact-context-state.js +22 -22
- package/lib/components/assistant-message.js +169 -0
- package/lib/components/composer-area.js +25 -0
- package/lib/components/dynamic-block.js +20 -0
- package/lib/components/monitor-stack.js +35 -0
- package/lib/components/text-block.js +47 -0
- package/lib/components/tool-block.js +122 -0
- package/lib/composer-terminal.js +224 -203
- package/lib/event-controller.js +243 -242
- package/lib/frontend-cli-implementation.js +656 -1111
- package/lib/input-controller.js +75 -94
- package/lib/input-errors.js +3 -3
- package/lib/interrupt-state.js +9 -9
- package/lib/line-editor.js +541 -541
- package/lib/local-slash-commands.js +217 -0
- package/lib/markdown-lines.js +103 -0
- package/lib/model-menu-state.js +50 -50
- package/lib/one-shot-progress.js +145 -0
- package/lib/one-shot.js +228 -0
- package/lib/question-menu-state.js +61 -0
- package/lib/rendering.js +1295 -1037
- package/lib/runtime-client.js +241 -193
- package/lib/runtime-env.js +21 -21
- package/lib/runtime-protocol.js +122 -15
- package/lib/slash-command-mode.js +16 -27
- package/lib/slash-menu-state.js +59 -59
- package/lib/{background-controller.js → task-monitor-controller.js} +411 -289
- package/lib/terminal-key.js +97 -97
- package/lib/text-width.js +335 -151
- package/lib/theme-menu-state.js +31 -0
- package/lib/theme.js +134 -0
- package/lib/tool-display.js +680 -0
- package/lib/tui/component.js +55 -0
- package/lib/tui/cursor.js +29 -0
- package/lib/tui/input-buffer.js +172 -0
- package/lib/tui/tui.js +591 -0
- package/lib/turn-controller.js +68 -78
- package/package.json +28 -28
- package/lib/assistant-stream-buffer.js +0 -25
- package/lib/terminal-ui.js +0 -581
package/lib/event-controller.js
CHANGED
|
@@ -1,242 +1,243 @@
|
|
|
1
|
-
import { runtimeEventType } from "./runtime-protocol.js";
|
|
2
|
-
import {
|
|
3
|
-
cancelledText,
|
|
4
|
-
contextBuiltLine,
|
|
5
|
-
errorLine,
|
|
6
|
-
|
|
7
|
-
planUpdatedLine,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
output.
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
case "
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
output.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
output.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
output.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
output.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
case "turn_failed":
|
|
125
|
-
output.
|
|
126
|
-
output.
|
|
127
|
-
output.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
output.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
output.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
1
|
+
import { runtimeEventType } from "./runtime-protocol.js";
|
|
2
|
+
import {
|
|
3
|
+
cancelledText,
|
|
4
|
+
contextBuiltLine,
|
|
5
|
+
errorLine,
|
|
6
|
+
goalContinuedLine,
|
|
7
|
+
planUpdatedLine,
|
|
8
|
+
turnCompletedLine,
|
|
9
|
+
} from "./rendering.js";
|
|
10
|
+
|
|
11
|
+
export function createEventController({
|
|
12
|
+
state = {},
|
|
13
|
+
input = {},
|
|
14
|
+
output = {},
|
|
15
|
+
monitor = {},
|
|
16
|
+
}) {
|
|
17
|
+
const pendingFileChanges = new Map();
|
|
18
|
+
const pendingPlanInputs = new Map();
|
|
19
|
+
let toolStats = { completed: 0, failed: 0 };
|
|
20
|
+
|
|
21
|
+
async function handle(message) {
|
|
22
|
+
if (state.runtimeClosing) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const event = message?.event;
|
|
26
|
+
const eventType = runtimeEventType(message);
|
|
27
|
+
if (!event || typeof event !== "object") {
|
|
28
|
+
if (state.debug) {
|
|
29
|
+
output.debug?.(`Ignoring runtime event without payload: ${eventType || "unknown"}`);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
switch (eventType) {
|
|
34
|
+
case "assistant_delta":
|
|
35
|
+
output.assistantAppend?.(event.text || "");
|
|
36
|
+
return;
|
|
37
|
+
case "context_built": {
|
|
38
|
+
if (output.handleContextBuilt?.(event)) {
|
|
39
|
+
output.resetContextUsage?.();
|
|
40
|
+
}
|
|
41
|
+
const line = contextBuiltLine(event);
|
|
42
|
+
if (line) {
|
|
43
|
+
output.closeAssistant?.();
|
|
44
|
+
output.log?.(() => line);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
case "tool_input_started":
|
|
49
|
+
output.closeAssistant?.();
|
|
50
|
+
rememberPlanInputStart(event);
|
|
51
|
+
output.beginTool?.(event);
|
|
52
|
+
return;
|
|
53
|
+
case "tool_input_delta":
|
|
54
|
+
appendPlanInput(event);
|
|
55
|
+
return;
|
|
56
|
+
case "tool_input_ended":
|
|
57
|
+
return;
|
|
58
|
+
case "tool_requested":
|
|
59
|
+
output.closeAssistant?.();
|
|
60
|
+
rememberPlanInputPreview(event);
|
|
61
|
+
monitor.recordCommand?.(event);
|
|
62
|
+
monitor.recordDelegateRequest?.(event);
|
|
63
|
+
output.beginTool?.(event);
|
|
64
|
+
return;
|
|
65
|
+
case "tool_call_started":
|
|
66
|
+
output.closeAssistant?.();
|
|
67
|
+
output.beginTool?.(event);
|
|
68
|
+
return;
|
|
69
|
+
case "tool_result": {
|
|
70
|
+
output.closeAssistant?.();
|
|
71
|
+
const fileChange = pendingFileChanges.get(event.tool_call_id);
|
|
72
|
+
pendingFileChanges.delete(event.tool_call_id);
|
|
73
|
+
const planInput = takePlanInput(event);
|
|
74
|
+
monitor.recordResult?.(event);
|
|
75
|
+
monitor.recordDelegateResult?.(event);
|
|
76
|
+
recordToolResult(event);
|
|
77
|
+
const plan = event.tool_name === "update_plan" && event.status === "completed"
|
|
78
|
+
? parsePlanInput(planInput)
|
|
79
|
+
: null;
|
|
80
|
+
const goal = event.tool_name === "update_goal" && event.status === "completed"
|
|
81
|
+
? parseToolData(event.result)
|
|
82
|
+
: null;
|
|
83
|
+
if (goal?.status) {
|
|
84
|
+
output.updateGoal?.(goal);
|
|
85
|
+
}
|
|
86
|
+
if (plan) {
|
|
87
|
+
output.log?.(() => planUpdatedLine(plan));
|
|
88
|
+
}
|
|
89
|
+
output.finishTool?.(event, fileChange);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
case "file_change":
|
|
93
|
+
if (event.tool_call_id) {
|
|
94
|
+
pendingFileChanges.set(event.tool_call_id, event);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
case "tool_progress": {
|
|
98
|
+
const message = progressMessage(event.payload);
|
|
99
|
+
if (message) {
|
|
100
|
+
output.closeAssistant?.();
|
|
101
|
+
output.updateToolProgress?.(event.tool_call_id, message);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case "token_stats_updated":
|
|
106
|
+
output.closeAssistant?.();
|
|
107
|
+
output.setStats?.(event.stats && typeof event.stats === "object" ? event.stats : {});
|
|
108
|
+
if (!state.activeTurn) {
|
|
109
|
+
output.redraw?.();
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
case "user_question_requested":
|
|
113
|
+
await input.answerQuestion?.(event);
|
|
114
|
+
return;
|
|
115
|
+
case "queued_input_delivered":
|
|
116
|
+
output.setGoalChasing?.(false);
|
|
117
|
+
output.deliverQueuedInput?.(event.input || "", event.mode || "steering", event.input_id || "");
|
|
118
|
+
return;
|
|
119
|
+
case "goal_continued":
|
|
120
|
+
output.closeAssistant?.();
|
|
121
|
+
output.setGoalChasing?.(true);
|
|
122
|
+
output.log?.(() => goalContinuedLine(event.round));
|
|
123
|
+
return;
|
|
124
|
+
case "turn_failed":
|
|
125
|
+
output.clearQueuedInputs?.();
|
|
126
|
+
output.clearCompactContext?.();
|
|
127
|
+
output.closeAssistant?.();
|
|
128
|
+
output.setGoalChasing?.(false);
|
|
129
|
+
output.log?.(() => errorLine(event.error));
|
|
130
|
+
resetTurnState();
|
|
131
|
+
return;
|
|
132
|
+
case "turn_cancelled":
|
|
133
|
+
output.clearQueuedInputs?.();
|
|
134
|
+
output.clearCompactContext?.();
|
|
135
|
+
output.closeAssistant?.();
|
|
136
|
+
output.setGoalChasing?.(false);
|
|
137
|
+
output.log?.(() => cancelledText());
|
|
138
|
+
resetTurnState();
|
|
139
|
+
return;
|
|
140
|
+
case "turn_completed":
|
|
141
|
+
output.clearQueuedInputs?.();
|
|
142
|
+
output.clearCompactContext?.();
|
|
143
|
+
output.closeAssistant?.();
|
|
144
|
+
output.setGoalChasing?.(false);
|
|
145
|
+
output.log?.(turnCompletedLine(event, toolStats));
|
|
146
|
+
resetTurnState();
|
|
147
|
+
return;
|
|
148
|
+
default:
|
|
149
|
+
if (state.debug) {
|
|
150
|
+
output.debug?.(`Ignoring unknown runtime event: ${eventType || "unknown"}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function progressMessage(payload) {
|
|
156
|
+
if (!payload || typeof payload !== "object") {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
for (const key of ["message", "status", "text"]) {
|
|
160
|
+
const value = String(payload[key] || "").trim();
|
|
161
|
+
if (value) {
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return "";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function resetTurnState() {
|
|
169
|
+
toolStats = { completed: 0, failed: 0 };
|
|
170
|
+
pendingFileChanges.clear();
|
|
171
|
+
pendingPlanInputs.clear();
|
|
172
|
+
monitor.clearDelegates?.();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function recordToolResult(event) {
|
|
176
|
+
if (event.status === "failed") {
|
|
177
|
+
toolStats.failed += 1;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
toolStats.completed += 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function rememberPlanInputStart(event) {
|
|
184
|
+
if (event.tool_name === "update_plan" && event.tool_call_id) {
|
|
185
|
+
pendingPlanInputs.set(event.tool_call_id, "");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function appendPlanInput(event) {
|
|
190
|
+
if (event.tool_name !== "update_plan" || !event.tool_call_id) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const current = pendingPlanInputs.get(event.tool_call_id);
|
|
194
|
+
if (current !== undefined) {
|
|
195
|
+
pendingPlanInputs.set(event.tool_call_id, current + String(event.delta || ""));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function rememberPlanInputPreview(event) {
|
|
200
|
+
if (event.tool_name !== "update_plan" || !event.tool_call_id) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const current = pendingPlanInputs.get(event.tool_call_id);
|
|
204
|
+
if (!current) {
|
|
205
|
+
pendingPlanInputs.set(event.tool_call_id, String(event.args_preview || ""));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function takePlanInput(event) {
|
|
210
|
+
if (event.tool_name !== "update_plan" || !event.tool_call_id) {
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
const value = pendingPlanInputs.get(event.tool_call_id) || "";
|
|
214
|
+
pendingPlanInputs.delete(event.tool_call_id);
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
handle,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function parsePlanInput(value) {
|
|
224
|
+
const args = parseObject(value);
|
|
225
|
+
return Array.isArray(args.plan) ? args.plan : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function parseToolData(value) {
|
|
229
|
+
const parsed = parseObject(value);
|
|
230
|
+
return parsed.data && typeof parsed.data === "object" ? parsed.data : {};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function parseObject(value) {
|
|
234
|
+
if (value && typeof value === "object") {
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const parsed = JSON.parse(String(value || ""));
|
|
239
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
240
|
+
} catch {
|
|
241
|
+
return {};
|
|
242
|
+
}
|
|
243
|
+
}
|