codebase-cli 2.0.0-pre.3 → 2.0.0-pre.30
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/dist/agent/agent.js +10 -2
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/config.js +101 -20
- package/dist/agent/config.js.map +1 -1
- package/dist/agent/prompt-suggestion.js +145 -0
- package/dist/agent/prompt-suggestion.js.map +1 -0
- package/dist/agent/system-prompt.js +15 -0
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/app-server/protocol.js +7 -0
- package/dist/app-server/protocol.js.map +1 -0
- package/dist/app-server/server.js +241 -0
- package/dist/app-server/server.js.map +1 -0
- package/dist/auth/credentials.js +10 -0
- package/dist/auth/credentials.js.map +1 -1
- package/dist/auth/flow.js +145 -24
- package/dist/auth/flow.js.map +1 -1
- package/dist/cli.js +58 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/builtins.js +155 -5
- package/dist/commands/builtins.js.map +1 -1
- package/dist/commands/registry.js +46 -1
- package/dist/commands/registry.js.map +1 -1
- package/dist/glue/client.js +10 -1
- package/dist/glue/client.js.map +1 -1
- package/dist/headless/run.js +1 -1
- package/dist/headless/run.js.map +1 -1
- package/dist/hooks/manager.js +8 -2
- package/dist/hooks/manager.js.map +1 -1
- package/dist/permissions/store.js +4 -0
- package/dist/permissions/store.js.map +1 -1
- package/dist/projects/cli.js +92 -0
- package/dist/projects/cli.js.map +1 -0
- package/dist/projects/client.js +120 -0
- package/dist/projects/client.js.map +1 -0
- package/dist/projects/types.js +2 -0
- package/dist/projects/types.js.map +1 -0
- package/dist/skills/platform-loader.js +133 -38
- package/dist/skills/platform-loader.js.map +1 -1
- package/dist/tools/__test__/mock-tool-context.js +31 -0
- package/dist/tools/__test__/mock-tool-context.js.map +1 -0
- package/dist/tools/read-file.js +8 -2
- package/dist/tools/read-file.js.map +1 -1
- package/dist/ui/App.js +244 -17
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/FirstRunSetup.js +66 -14
- package/dist/ui/FirstRunSetup.js.map +1 -1
- package/dist/ui/Input.js +270 -14
- package/dist/ui/Input.js.map +1 -1
- package/dist/ui/Markdown.js +286 -0
- package/dist/ui/Markdown.js.map +1 -0
- package/dist/ui/Message.js +604 -25
- package/dist/ui/Message.js.map +1 -1
- package/dist/ui/MessageList.js +100 -3
- package/dist/ui/MessageList.js.map +1 -1
- package/dist/ui/Permission.js +43 -20
- package/dist/ui/Permission.js.map +1 -1
- package/dist/ui/PixelC.js +25 -0
- package/dist/ui/PixelC.js.map +1 -0
- package/dist/ui/Status.js +213 -7
- package/dist/ui/Status.js.map +1 -1
- package/dist/ui/Throbber.js +11 -7
- package/dist/ui/Throbber.js.map +1 -1
- package/dist/ui/Welcome.js +59 -0
- package/dist/ui/Welcome.js.map +1 -0
- package/dist/ui/attachments.js +68 -0
- package/dist/ui/attachments.js.map +1 -0
- package/dist/ui/debug-input.js +44 -0
- package/dist/ui/debug-input.js.map +1 -0
- package/dist/ui/highlight.js +324 -0
- package/dist/ui/highlight.js.map +1 -0
- package/dist/ui/history-store.js +60 -0
- package/dist/ui/history-store.js.map +1 -0
- package/dist/ui/path-complete.js +102 -0
- package/dist/ui/path-complete.js.map +1 -0
- package/dist/ui/terminal-restore.js +83 -0
- package/dist/ui/terminal-restore.js.map +1 -0
- package/package.json +5 -1
package/dist/ui/Input.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text, useInput } from "ink";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useMemo, useRef, useState } from "react";
|
|
4
|
+
import { logInputEvent } from "./debug-input.js";
|
|
4
5
|
import { backspace, deleteForward, initialInputState, insertChar, killToEnd, killToStart, killWordBack, moveEnd, moveLeft, moveRight, moveStart, undo, yank, } from "./input-state.js";
|
|
6
|
+
import { completePath, findAtTokenAt } from "./path-complete.js";
|
|
7
|
+
const MAX_SUGGESTIONS = 6;
|
|
8
|
+
const PLACEHOLDERS_FRESH = [
|
|
9
|
+
"Ask anything · / for commands",
|
|
10
|
+
"Try /help to see what I can do",
|
|
11
|
+
"Tell me what to build · / for commands",
|
|
12
|
+
"Paste a stack trace, a TODO, or a question",
|
|
13
|
+
"What are we working on?",
|
|
14
|
+
];
|
|
15
|
+
const PLACEHOLDERS_RETURNING = [
|
|
16
|
+
"Welcome back · ↑ for prior prompts",
|
|
17
|
+
"Picking up where you left off · ↑ for history",
|
|
18
|
+
"What's next? · ↑ recalls past prompts",
|
|
19
|
+
"Ready when you are · / for commands · ↑ for history",
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Pick a placeholder once per Input mount. The returning-user variants
|
|
23
|
+
* mention ↑ for history so users with persisted prompts learn the
|
|
24
|
+
* shortcut; fresh sessions emphasize / and free-form prompts.
|
|
25
|
+
*/
|
|
26
|
+
function pickPlaceholder(hasHistory) {
|
|
27
|
+
const pool = hasHistory ? PLACEHOLDERS_RETURNING : PLACEHOLDERS_FRESH;
|
|
28
|
+
return pool[Math.floor(Math.random() * pool.length)];
|
|
29
|
+
}
|
|
5
30
|
/**
|
|
6
31
|
* Single-line input with Emacs / readline editing. Cursor positioning,
|
|
7
32
|
* kill ring with Ctrl-K/U/W/Y, and Ctrl-Z undo. Stay in tight feedback
|
|
@@ -18,22 +43,192 @@ import { backspace, deleteForward, initialInputState, insertChar, killToEnd, kil
|
|
|
18
43
|
* Ctrl-W kill word before cursor
|
|
19
44
|
* Ctrl-Y yank (paste from kill ring)
|
|
20
45
|
* Ctrl-Z undo
|
|
21
|
-
* Ctrl-C
|
|
46
|
+
* Ctrl-C busy → cancel turn (stay in app); double-tap → exit
|
|
22
47
|
*/
|
|
23
|
-
export function Input({ disabled, onSubmit, onAbort }) {
|
|
48
|
+
export function Input({ disabled, onSubmit, onAbort, commands, history, cwd, suggestion, onSuggestionDismiss, }) {
|
|
24
49
|
const [state, setState] = useState(initialInputState());
|
|
50
|
+
const [suggestionIdx, setSuggestionIdx] = useState(0);
|
|
51
|
+
/**
|
|
52
|
+
* History cursor:
|
|
53
|
+
* -1 → live buffer (no history navigation in progress)
|
|
54
|
+
* 0..N-1 → indexing from the newest backwards (0 = most recent)
|
|
55
|
+
* We snapshot the live buffer the first time the user steps into
|
|
56
|
+
* history so ↓-past-newest returns to whatever they were typing.
|
|
57
|
+
*/
|
|
58
|
+
const [historyIdx, setHistoryIdx] = useState(-1);
|
|
59
|
+
const [liveBuffer, setLiveBuffer] = useState(null);
|
|
60
|
+
// Stable per-mount placeholder so the hint doesn't flicker between renders.
|
|
61
|
+
const placeholderRef = useRef(pickPlaceholder((history?.length ?? 0) > 0));
|
|
62
|
+
// @-path completion cycler — `pathMatches` is the list, `pathIdx` is
|
|
63
|
+
// the current cycle position. Both reset whenever the buffer
|
|
64
|
+
// changes away from the active @-token.
|
|
65
|
+
const [pathMatches, setPathMatches] = useState([]);
|
|
66
|
+
const [pathIdx, setPathIdx] = useState(0);
|
|
67
|
+
const lastAtTokenRef = useRef(null);
|
|
68
|
+
// Autocomplete only fires when the buffer starts with `/` AND there's
|
|
69
|
+
// no whitespace yet (so once the user types a space, they're past the
|
|
70
|
+
// command name and into args — no more suggestions).
|
|
71
|
+
const autocompleteActive = state.buffer.startsWith("/") && !state.buffer.includes(" ");
|
|
72
|
+
const suggestions = useMemo(() => {
|
|
73
|
+
if (!autocompleteActive || !commands)
|
|
74
|
+
return [];
|
|
75
|
+
const query = state.buffer.slice(1).toLowerCase();
|
|
76
|
+
const matches = commands.filter((c) => c.name.toLowerCase().startsWith(query));
|
|
77
|
+
return matches.slice(0, MAX_SUGGESTIONS);
|
|
78
|
+
}, [autocompleteActive, commands, state.buffer]);
|
|
79
|
+
const clampedSuggestionIdx = Math.min(suggestionIdx, Math.max(0, suggestions.length - 1));
|
|
25
80
|
useInput((input, key) => {
|
|
81
|
+
// First thing — log every keystroke when --debug-input is on, so
|
|
82
|
+
// we can diagnose "key X doesn't work" reports from real terminals.
|
|
83
|
+
logInputEvent(input, key);
|
|
26
84
|
if (key.ctrl && input === "c") {
|
|
27
85
|
onAbort?.();
|
|
28
86
|
return;
|
|
29
87
|
}
|
|
30
88
|
if (disabled)
|
|
31
89
|
return;
|
|
90
|
+
// Ghost-text suggestion accept. Only fires when there's no slash
|
|
91
|
+
// or @-path completion in flight AND the buffer is empty (the
|
|
92
|
+
// suggestion is contextual to the conversation, not to whatever
|
|
93
|
+
// the user is mid-typing). Tab fills the buffer and clears the
|
|
94
|
+
// suggestion. Any other keystroke dismisses the suggestion so it
|
|
95
|
+
// doesn't keep flashing after the user has started a fresh idea.
|
|
96
|
+
if (suggestion && state.buffer.length === 0) {
|
|
97
|
+
if (key.tab && !autocompleteActive) {
|
|
98
|
+
setState({ ...initialInputState(), buffer: suggestion, cursor: suggestion.length });
|
|
99
|
+
onSuggestionDismiss?.();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// Anything user-driven that isn't bare cursor navigation should
|
|
103
|
+
// kill the ghost — they've moved on.
|
|
104
|
+
const isPassThrough = key.upArrow ||
|
|
105
|
+
key.downArrow ||
|
|
106
|
+
key.leftArrow ||
|
|
107
|
+
key.rightArrow ||
|
|
108
|
+
key.escape ||
|
|
109
|
+
(key.ctrl && (input === "c" || input === "d"));
|
|
110
|
+
if (!isPassThrough) {
|
|
111
|
+
onSuggestionDismiss?.();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Autocomplete navigation runs BEFORE generic input handling so Tab
|
|
115
|
+
// doesn't insert a literal tab and arrow keys don't fight cursor
|
|
116
|
+
// movement when we have a suggestion list to navigate.
|
|
117
|
+
if (autocompleteActive && suggestions.length > 0) {
|
|
118
|
+
if (key.upArrow) {
|
|
119
|
+
setSuggestionIdx((i) => (i - 1 + suggestions.length) % suggestions.length);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (key.downArrow) {
|
|
123
|
+
setSuggestionIdx((i) => (i + 1) % suggestions.length);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (key.tab) {
|
|
127
|
+
const chosen = suggestions[clampedSuggestionIdx];
|
|
128
|
+
setState({ ...initialInputState(), buffer: `/${chosen.name} `, cursor: chosen.name.length + 2 });
|
|
129
|
+
setSuggestionIdx(0);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// @-path Tab completion. Only kicks in when slash autocomplete is
|
|
134
|
+
// inactive and the cursor sits inside an @-token. Repeated Tab
|
|
135
|
+
// cycles through matches; any keypress other than Tab clears the
|
|
136
|
+
// cycle so the next Tab recomputes a fresh list.
|
|
137
|
+
if (key.tab && !autocompleteActive && cwd) {
|
|
138
|
+
const at = findAtTokenAt(state.buffer, state.cursor);
|
|
139
|
+
if (at) {
|
|
140
|
+
let matches = pathMatches;
|
|
141
|
+
let idx = pathIdx;
|
|
142
|
+
const cached = lastAtTokenRef.current;
|
|
143
|
+
const sameContext = cached && cached.buffer === state.buffer && cached.cursor === state.cursor && matches.length > 0;
|
|
144
|
+
if (!sameContext) {
|
|
145
|
+
matches = completePath(at.prefix, cwd);
|
|
146
|
+
idx = 0;
|
|
147
|
+
setPathMatches(matches);
|
|
148
|
+
setPathIdx(0);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
idx = (idx + 1) % matches.length;
|
|
152
|
+
setPathIdx(idx);
|
|
153
|
+
}
|
|
154
|
+
if (matches.length === 0)
|
|
155
|
+
return;
|
|
156
|
+
const chosen = matches[idx];
|
|
157
|
+
const before = state.buffer.slice(0, at.start);
|
|
158
|
+
const after = state.buffer.slice(state.cursor);
|
|
159
|
+
const inserted = `@${chosen}`;
|
|
160
|
+
const newBuffer = before + inserted + after;
|
|
161
|
+
const newCursor = before.length + inserted.length;
|
|
162
|
+
setState({ ...initialInputState(), buffer: newBuffer, cursor: newCursor });
|
|
163
|
+
lastAtTokenRef.current = { buffer: newBuffer, cursor: newCursor };
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// History navigation: only when autocomplete is closed and the
|
|
168
|
+
// cursor sits at the start of the buffer (or buffer is empty).
|
|
169
|
+
// That way ↑/↓ in the middle of a long line still behave as
|
|
170
|
+
// cursor moves, matching shell readline.
|
|
171
|
+
if (history && history.length > 0 && !autocompleteActive && state.cursor === 0) {
|
|
172
|
+
if (key.upArrow) {
|
|
173
|
+
const nextIdx = historyIdx < 0 ? 0 : Math.min(historyIdx + 1, history.length - 1);
|
|
174
|
+
if (historyIdx < 0)
|
|
175
|
+
setLiveBuffer(state.buffer);
|
|
176
|
+
const entry = history[history.length - 1 - nextIdx] ?? "";
|
|
177
|
+
setHistoryIdx(nextIdx);
|
|
178
|
+
setState({ ...initialInputState(), buffer: entry, cursor: entry.length });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (key.downArrow) {
|
|
182
|
+
if (historyIdx < 0)
|
|
183
|
+
return; // already at live buffer
|
|
184
|
+
const nextIdx = historyIdx - 1;
|
|
185
|
+
if (nextIdx < 0) {
|
|
186
|
+
const restored = liveBuffer ?? "";
|
|
187
|
+
setHistoryIdx(-1);
|
|
188
|
+
setLiveBuffer(null);
|
|
189
|
+
setState({ ...initialInputState(), buffer: restored, cursor: restored.length });
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const entry = history[history.length - 1 - nextIdx] ?? "";
|
|
193
|
+
setHistoryIdx(nextIdx);
|
|
194
|
+
setState({ ...initialInputState(), buffer: entry, cursor: entry.length });
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Esc clears the buffer back to empty (and exits history mode) so
|
|
200
|
+
// the user can bail out of a half-typed prompt without having to
|
|
201
|
+
// hammer Backspace. Matches CC's behavior; harmless when empty.
|
|
202
|
+
if (key.escape) {
|
|
203
|
+
if (state.buffer.length === 0 && historyIdx < 0)
|
|
204
|
+
return;
|
|
205
|
+
setState(initialInputState());
|
|
206
|
+
setSuggestionIdx(0);
|
|
207
|
+
setHistoryIdx(-1);
|
|
208
|
+
setLiveBuffer(null);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
32
211
|
if (key.return) {
|
|
212
|
+
// `\<Enter>` inserts a newline instead of submitting — the CC
|
|
213
|
+
// convention for multi-line input. Strip the trailing `\` and
|
|
214
|
+
// replace it with a newline so the buffer reads cleanly.
|
|
215
|
+
if (state.buffer.endsWith("\\") && state.cursor === state.buffer.length) {
|
|
216
|
+
const stripped = state.buffer.slice(0, -1);
|
|
217
|
+
setState({ ...initialInputState(), buffer: `${stripped}\n`, cursor: stripped.length + 1 });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// Enter on a single-suggestion autocomplete still submits — if
|
|
221
|
+
// the user wanted to complete, they'd Tab. If they hit Enter on
|
|
222
|
+
// `/cos`, that's a clear "run /cost" intent only if it's an
|
|
223
|
+
// exact match; otherwise we submit as-typed and let the command
|
|
224
|
+
// registry's not-found path surface the typo.
|
|
33
225
|
const trimmed = state.buffer.trim();
|
|
34
226
|
if (trimmed.length > 0) {
|
|
35
227
|
onSubmit(trimmed);
|
|
36
228
|
setState(initialInputState());
|
|
229
|
+
setSuggestionIdx(0);
|
|
230
|
+
setHistoryIdx(-1);
|
|
231
|
+
setLiveBuffer(null);
|
|
37
232
|
}
|
|
38
233
|
return;
|
|
39
234
|
}
|
|
@@ -46,13 +241,35 @@ export function Input({ disabled, onSubmit, onAbort }) {
|
|
|
46
241
|
return setState(moveStart(state));
|
|
47
242
|
if (key.ctrl && input === "e")
|
|
48
243
|
return setState(moveEnd(state));
|
|
49
|
-
// Edits
|
|
50
|
-
|
|
244
|
+
// Edits. Some terminals (Linux console, tmux, certain SSH configs)
|
|
245
|
+
// deliver Backspace as raw 0x7f/0x08 without setting key.backspace,
|
|
246
|
+
// or even surface it as key.delete. We catch every shape so the
|
|
247
|
+
// floor — "Backspace deletes a char" — always works.
|
|
248
|
+
const isBackspaceByte = input === "\x7f" || input === "\b";
|
|
249
|
+
if (key.backspace || isBackspaceByte) {
|
|
250
|
+
setSuggestionIdx(0);
|
|
51
251
|
return setState(backspace(state));
|
|
52
|
-
|
|
252
|
+
}
|
|
253
|
+
// `key.delete` historically also fires for Backspace on some Ink
|
|
254
|
+
// builds, so prefer the backspace semantics when the buffer is
|
|
255
|
+
// non-empty and the cursor isn't at end-of-line. Forward-delete
|
|
256
|
+
// stays accessible via Ctrl-D.
|
|
257
|
+
if (key.delete) {
|
|
258
|
+
if (state.cursor > 0 && state.cursor === state.buffer.length) {
|
|
259
|
+
setSuggestionIdx(0);
|
|
260
|
+
return setState(backspace(state));
|
|
261
|
+
}
|
|
53
262
|
return setState(deleteForward(state));
|
|
54
|
-
|
|
263
|
+
}
|
|
264
|
+
// Ctrl-D matches readline: on an empty buffer it's EOF (i.e. quit),
|
|
265
|
+
// on a non-empty buffer it deletes forward like Delete.
|
|
266
|
+
if (key.ctrl && input === "d") {
|
|
267
|
+
if (state.buffer.length === 0) {
|
|
268
|
+
onAbort?.();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
55
271
|
return setState(deleteForward(state));
|
|
272
|
+
}
|
|
56
273
|
// Kill ring
|
|
57
274
|
if (key.ctrl && input === "k")
|
|
58
275
|
return setState(killToEnd(state));
|
|
@@ -65,20 +282,59 @@ export function Input({ disabled, onSubmit, onAbort }) {
|
|
|
65
282
|
// Undo
|
|
66
283
|
if (key.ctrl && input === "z")
|
|
67
284
|
return setState(undo(state));
|
|
68
|
-
// Printable text — Ink's useInput delivers individual chars (or pasted runs)
|
|
69
|
-
|
|
285
|
+
// Printable text — Ink's useInput delivers individual chars (or pasted runs).
|
|
286
|
+
// Strip control bytes (0x00–0x1f, 0x7f) so a stray Backspace or escape
|
|
287
|
+
// fragment doesn't end up inserted as a glyph in the buffer.
|
|
288
|
+
const isPrintable = input && !key.ctrl && !key.meta && !/[\x00-\x1f\x7f]/.test(input);
|
|
289
|
+
if (isPrintable) {
|
|
290
|
+
setSuggestionIdx(0);
|
|
291
|
+
// Once the user starts editing on top of a recalled history
|
|
292
|
+
// entry, snap out of history mode — the entry is now their
|
|
293
|
+
// own buffer and ↓ shouldn't try to bring it back.
|
|
294
|
+
if (historyIdx >= 0) {
|
|
295
|
+
setHistoryIdx(-1);
|
|
296
|
+
setLiveBuffer(null);
|
|
297
|
+
}
|
|
298
|
+
// Break the @-Tab cycle so the next Tab recomputes from the new text.
|
|
299
|
+
if (pathMatches.length > 0) {
|
|
300
|
+
setPathMatches([]);
|
|
301
|
+
setPathIdx(0);
|
|
302
|
+
lastAtTokenRef.current = null;
|
|
303
|
+
}
|
|
70
304
|
setState(insertChar(state, input));
|
|
71
305
|
}
|
|
72
306
|
});
|
|
73
|
-
return (_jsxs(Box, { paddingX: 1, children: [_jsxs(Text, { color: disabled ? "gray" : "cyan", children: [disabled ? "·" : ">", " "] }), disabled ? _jsx(Text, { children: state.buffer }) : _jsx(RenderedBuffer, { buffer: state.buffer, cursor: state.cursor })] }));
|
|
307
|
+
return (_jsxs(Box, { flexDirection: "column", children: [autocompleteActive && suggestions.length > 0 ? (_jsx(SlashSuggestions, { suggestions: suggestions, selected: clampedSuggestionIdx })) : null, _jsxs(Box, { paddingX: 1, children: [_jsxs(Text, { color: disabled ? "gray" : "cyan", children: [disabled ? "·" : ">", " "] }), disabled ? (_jsx(Text, { children: state.buffer })) : state.buffer.length === 0 ? (_jsxs(_Fragment, { children: [_jsx(Text, { color: "cyan", children: "\u258E" }), suggestion ? (_jsxs(_Fragment, { children: [_jsx(Text, { dimColor: true, children: suggestion }), _jsx(Text, { dimColor: true, children: " " }), _jsx(Text, { dimColor: true, children: "\u21B9 tab" })] })) : (_jsx(Text, { dimColor: true, children: placeholderRef.current }))] })) : (_jsx(RenderedBuffer, { buffer: state.buffer, cursor: state.cursor }))] })] }));
|
|
308
|
+
}
|
|
309
|
+
function SlashSuggestions({ suggestions, selected, }) {
|
|
310
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, marginBottom: 0, children: [suggestions.map((cmd, i) => {
|
|
311
|
+
const isSelected = i === selected;
|
|
312
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { color: isSelected ? "cyan" : "gray", bold: isSelected, children: [isSelected ? "▸ " : " ", `/${cmd.name}`] }), cmd.description ? (_jsxs(Text, { dimColor: true, children: [" ", "\u2014 ", cmd.description.slice(0, 60)] })) : null] }, `sug-${cmd.name}`));
|
|
313
|
+
}), _jsx(Box, { marginTop: 0, children: _jsx(Text, { dimColor: true, children: "\u2191\u2193 to move \u00B7 Tab to complete \u00B7 Enter to send as-typed" }) })] }));
|
|
74
314
|
}
|
|
75
315
|
/**
|
|
76
316
|
* Render the buffer with a visible cursor block at the cursor position.
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* the
|
|
317
|
+
* Splits on `\n` so multi-line pastes (and `\<Enter>` newlines) show
|
|
318
|
+
* as stacked rows — otherwise pasted code collapses into one line and
|
|
319
|
+
* the user can't see what they're sending.
|
|
80
320
|
*/
|
|
81
321
|
function RenderedBuffer({ buffer, cursor }) {
|
|
322
|
+
if (!buffer.includes("\n"))
|
|
323
|
+
return _jsx(SingleLineBuffer, { buffer: buffer, cursor: cursor });
|
|
324
|
+
const lines = buffer.split("\n");
|
|
325
|
+
let consumed = 0;
|
|
326
|
+
return (_jsx(Box, { flexDirection: "column", children: lines.map((line, idx) => {
|
|
327
|
+
const lineStart = consumed;
|
|
328
|
+
const lineEnd = consumed + line.length;
|
|
329
|
+
const cursorOnThisLine = cursor >= lineStart && cursor <= lineEnd;
|
|
330
|
+
consumed = lineEnd + 1;
|
|
331
|
+
if (!cursorOnThisLine) {
|
|
332
|
+
return _jsx(Text, { children: line.length === 0 ? " " : line }, `line-${idx}-${line.slice(0, 8)}`);
|
|
333
|
+
}
|
|
334
|
+
return (_jsx(SingleLineBuffer, { buffer: line, cursor: cursor - lineStart }, `line-${idx}-cur-${line.slice(0, 8)}`));
|
|
335
|
+
}) }));
|
|
336
|
+
}
|
|
337
|
+
function SingleLineBuffer({ buffer, cursor }) {
|
|
82
338
|
if (cursor >= buffer.length) {
|
|
83
339
|
return (_jsxs(_Fragment, { children: [_jsx(Text, { children: buffer }), _jsx(Text, { color: "cyan", children: "\u258E" })] }));
|
|
84
340
|
}
|
package/dist/ui/Input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../../src/ui/Input.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EACN,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,SAAS,EACT,IAAI,EACJ,IAAI,GACJ,MAAM,kBAAkB,CAAC;AAQ1B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAc;IAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAExD,QAAQ,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,CAAC,IAAI,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;YAC/B,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO;QACR,CAAC;QAED,IAAI,QAAQ;YAAE,OAAO;QAErB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,QAAQ,CAAC,OAAO,CAAC,CAA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,CAAC,CAAC;IACvC,OAAO,CACN,8BACC,KAAC,IAAI,cAAE,MAAM,GAAQ,EACrB,KAAC,IAAI,IAAC,OAAO,kBAAE,QAAQ,GAAQ,EAC/B,KAAC,IAAI,cAAE,KAAK,GAAQ,IAClB,CACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { colorForKind, highlight, rulesFor } from "./highlight.js";
|
|
4
|
+
import { wrapText } from "./wrap.js";
|
|
5
|
+
export function Markdown({ text, width, keyPrefix }) {
|
|
6
|
+
const blocks = parseBlocks(text);
|
|
7
|
+
return (_jsx(Box, { flexDirection: "column", children: blocks.map((block, i) => (_jsx(MarkdownBlock, { block: block, width: width, keyPrefix: `${keyPrefix}-${i}` }, `${keyPrefix}-${i}-${block.kind}`))) }));
|
|
8
|
+
}
|
|
9
|
+
function MarkdownBlock({ block, width, keyPrefix }) {
|
|
10
|
+
if (block.kind === "blank") {
|
|
11
|
+
return _jsx(Text, { children: " " });
|
|
12
|
+
}
|
|
13
|
+
if (block.kind === "code-block") {
|
|
14
|
+
return _jsx(HighlightedCodeBlock, { text: block.text, lang: block.lang, keyPrefix: keyPrefix });
|
|
15
|
+
}
|
|
16
|
+
if (block.kind === "heading") {
|
|
17
|
+
return _jsx(SpanLine, { spans: block.spans, width: width, bold: true, color: "cyan", keyPrefix: keyPrefix });
|
|
18
|
+
}
|
|
19
|
+
if (block.kind === "list") {
|
|
20
|
+
return (_jsx(Box, { flexDirection: "column", children: block.items.map((item, i) => (_jsx(ListRow, { item: item, width: width, keyPrefix: `${keyPrefix}-li-${i}` }, `${keyPrefix}-li-${i}-${item.marker}`))) }));
|
|
21
|
+
}
|
|
22
|
+
if (block.kind === "quote") {
|
|
23
|
+
// Use SpanLine to preserve inline styling, but wrap in a left-bar gutter
|
|
24
|
+
// so block-quotes read like one in a terminal.
|
|
25
|
+
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { marginRight: 1, children: _jsx(Text, { dimColor: true, children: "\u2502" }) }), _jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(SpanLine, { spans: block.spans, width: Math.max(20, width - 2), keyPrefix: keyPrefix, dim: true }) })] }));
|
|
26
|
+
}
|
|
27
|
+
return _jsx(SpanLine, { spans: block.spans, width: width, keyPrefix: keyPrefix });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Render a fenced code block with regex-based syntax highlighting if
|
|
31
|
+
* the language is recognized. Walks the token list and splits on \n so
|
|
32
|
+
* the per-line key invariant from the rest of the renderer holds.
|
|
33
|
+
* Unsupported languages render in the original cyan tone.
|
|
34
|
+
*/
|
|
35
|
+
function HighlightedCodeBlock({ text, lang, keyPrefix, }) {
|
|
36
|
+
const rules = rulesFor(lang);
|
|
37
|
+
if (!rules) {
|
|
38
|
+
const lines = text.split("\n");
|
|
39
|
+
return (_jsx(Box, { flexDirection: "column", marginLeft: 2, children: lines.map((line, i) => (_jsx(Text, { color: "cyan", children: line.length === 0 ? " " : line }, `${keyPrefix}-cl-${i}-${line.slice(0, 12)}`))) }));
|
|
40
|
+
}
|
|
41
|
+
// Split the highlighted token stream into per-line rows so the
|
|
42
|
+
// columns stay aligned with the surrounding markdown and the keys
|
|
43
|
+
// stay stable.
|
|
44
|
+
const rows = [[]];
|
|
45
|
+
for (const tok of highlight(text, lang)) {
|
|
46
|
+
const color = colorForKind(tok.kind);
|
|
47
|
+
const parts = tok.text.split("\n");
|
|
48
|
+
for (let i = 0; i < parts.length; i++) {
|
|
49
|
+
if (i > 0)
|
|
50
|
+
rows.push([]);
|
|
51
|
+
if (parts[i].length > 0)
|
|
52
|
+
rows[rows.length - 1].push({ color, text: parts[i] });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return (_jsx(Box, { flexDirection: "column", marginLeft: 2, children: rows.map((row, i) => {
|
|
56
|
+
const previewKey = row
|
|
57
|
+
.map((c) => c.text)
|
|
58
|
+
.join("")
|
|
59
|
+
.slice(0, 12);
|
|
60
|
+
return (_jsx(Text, { children: row.length === 0
|
|
61
|
+
? " "
|
|
62
|
+
: row.map((c, ci) => (
|
|
63
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: pure presentational
|
|
64
|
+
_jsx(Text, { color: c.color, children: c.text }, `${keyPrefix}-hl-${i}-c${ci}`))) }, `${keyPrefix}-hl-${i}-${previewKey}`));
|
|
65
|
+
}) }));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One list-item row: marker in cyan (e.g. "•" / "1.") + the item body
|
|
69
|
+
* wrapped to the remaining width, with continuation lines indented
|
|
70
|
+
* under the body so wrapped lines hang neatly past the marker.
|
|
71
|
+
*/
|
|
72
|
+
function ListRow({ item, width, keyPrefix }) {
|
|
73
|
+
const markerCol = item.marker.length + 1; // marker + the gap space
|
|
74
|
+
const indentCols = item.indent * 2;
|
|
75
|
+
const bodyWidth = Math.max(10, width - markerCol - indentCols);
|
|
76
|
+
const plain = item.spans.map((s) => s.text).join("");
|
|
77
|
+
const wrapped = bodyWidth > 0 ? wrapText(plain, bodyWidth) : [plain];
|
|
78
|
+
let consumed = 0;
|
|
79
|
+
return (_jsx(Box, { flexDirection: "column", children: wrapped.map((line, lineIdx) => {
|
|
80
|
+
const chunks = sliceSpans(item.spans, consumed, consumed + line.length);
|
|
81
|
+
consumed += line.length;
|
|
82
|
+
if (lineIdx < wrapped.length - 1 && plain[consumed] === " ")
|
|
83
|
+
consumed += 1;
|
|
84
|
+
const rowKey = `${keyPrefix}-row-${lineIdx}-${line.slice(0, 8)}`;
|
|
85
|
+
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { children: " ".repeat(indentCols) }), lineIdx === 0 ? _jsxs(Text, { color: "cyan", children: [item.marker, " "] }) : _jsx(Text, { children: " ".repeat(markerCol) }), _jsx(Box, { flexGrow: 1, children: _jsx(Text, { children: chunks.map((c, ci) => (_jsx(Text
|
|
86
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: ci is a stable position within a single wrapped row; reusing instances is harmless
|
|
87
|
+
, { bold: c.kind === "bold", italic: c.kind === "italic", color: c.kind === "code" ? "cyan" : undefined, children: c.text }, `${rowKey}-c${ci}`))) }) })] }, rowKey));
|
|
88
|
+
}) }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Render a sequence of inline spans, wrapped to `width`. We wrap on
|
|
92
|
+
* the plain-text representation, then walk the spans in parallel to
|
|
93
|
+
* decide where to break and what styling each chunk gets. This keeps
|
|
94
|
+
* select-copy clean while preserving styled segments across line
|
|
95
|
+
* breaks.
|
|
96
|
+
*/
|
|
97
|
+
function SpanLine({ spans, width, bold, color, dim, keyPrefix, }) {
|
|
98
|
+
// For the first cut: serialize spans into one rich-text line, wrap
|
|
99
|
+
// the plain projection, and emit one <Text> per row with all spans
|
|
100
|
+
// inlined. Wrap calculation uses the plain text so column counts
|
|
101
|
+
// stay accurate; the rendered output retains the styling.
|
|
102
|
+
const plain = spans.map((s) => s.text).join("");
|
|
103
|
+
const wrapped = wrapText(plain, width);
|
|
104
|
+
let consumed = 0;
|
|
105
|
+
return (_jsx(_Fragment, { children: wrapped.map((line, lineIdx) => {
|
|
106
|
+
const chunks = sliceSpans(spans, consumed, consumed + line.length);
|
|
107
|
+
consumed += line.length;
|
|
108
|
+
// Account for the line break (wrap-ansi drops the trailing space).
|
|
109
|
+
if (lineIdx < wrapped.length - 1 && plain[consumed] === " ")
|
|
110
|
+
consumed += 1;
|
|
111
|
+
const rowKey = `${keyPrefix}-r-${lineIdx}-${line.slice(0, 12)}`;
|
|
112
|
+
return (_jsx(Text, { children: chunks.map((c, ci) => (_jsx(Text
|
|
113
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: ci is a stable position within a single wrapped row
|
|
114
|
+
, { bold: bold || c.kind === "bold", italic: c.kind === "italic", dimColor: dim, color: c.kind === "code" ? "cyan" : color, children: c.text }, `${rowKey}-c${ci}`))) }, rowKey));
|
|
115
|
+
}) }));
|
|
116
|
+
}
|
|
117
|
+
/** Slice the span sequence to the [start, end) range of the plain projection. */
|
|
118
|
+
function sliceSpans(spans, start, end) {
|
|
119
|
+
const out = [];
|
|
120
|
+
let cursor = 0;
|
|
121
|
+
for (const span of spans) {
|
|
122
|
+
const spanEnd = cursor + span.text.length;
|
|
123
|
+
if (spanEnd <= start) {
|
|
124
|
+
cursor = spanEnd;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (cursor >= end)
|
|
128
|
+
break;
|
|
129
|
+
const sliceStart = Math.max(0, start - cursor);
|
|
130
|
+
const sliceEnd = Math.min(span.text.length, end - cursor);
|
|
131
|
+
out.push({ kind: span.kind, text: span.text.slice(sliceStart, sliceEnd) });
|
|
132
|
+
cursor = spanEnd;
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
// ── parsing ─────────────────────────────────────────────────────────
|
|
137
|
+
function parseBlocks(text) {
|
|
138
|
+
const blocks = [];
|
|
139
|
+
const lines = text.split("\n");
|
|
140
|
+
let i = 0;
|
|
141
|
+
while (i < lines.length) {
|
|
142
|
+
const line = lines[i];
|
|
143
|
+
// Fenced code block.
|
|
144
|
+
const fence = line.match(/^```(.*)$/);
|
|
145
|
+
if (fence) {
|
|
146
|
+
const lang = fence[1].trim() || undefined;
|
|
147
|
+
const body = [];
|
|
148
|
+
i++;
|
|
149
|
+
while (i < lines.length && !lines[i].match(/^```\s*$/)) {
|
|
150
|
+
body.push(lines[i]);
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
i++; // skip closing fence (or EOF)
|
|
154
|
+
blocks.push({ kind: "code-block", lang, text: body.join("\n") });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// Blank line.
|
|
158
|
+
if (line.trim() === "") {
|
|
159
|
+
blocks.push({ kind: "blank" });
|
|
160
|
+
i++;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Heading.
|
|
164
|
+
const heading = line.match(/^(#{1,3})\s+(.+)$/);
|
|
165
|
+
if (heading) {
|
|
166
|
+
const level = heading[1].length;
|
|
167
|
+
blocks.push({ kind: "heading", level, spans: parseInline(heading[2]) });
|
|
168
|
+
i++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// List (bulleted or ordered). Consumes consecutive list rows + any
|
|
172
|
+
// continuation lines that are deeper-indented than the list marker.
|
|
173
|
+
const listProbe = matchListLine(line);
|
|
174
|
+
if (listProbe) {
|
|
175
|
+
const items = [];
|
|
176
|
+
let ordered = listProbe.ordered;
|
|
177
|
+
while (i < lines.length) {
|
|
178
|
+
const row = matchListLine(lines[i]);
|
|
179
|
+
if (!row)
|
|
180
|
+
break;
|
|
181
|
+
ordered = ordered || row.ordered;
|
|
182
|
+
const itemLines = [row.body];
|
|
183
|
+
i++;
|
|
184
|
+
// Continuation lines: indented, non-empty, non-list rows.
|
|
185
|
+
while (i < lines.length) {
|
|
186
|
+
const peek = lines[i];
|
|
187
|
+
if (peek.trim() === "")
|
|
188
|
+
break;
|
|
189
|
+
if (matchListLine(peek))
|
|
190
|
+
break;
|
|
191
|
+
if (peek.match(/^#{1,3}\s+/))
|
|
192
|
+
break;
|
|
193
|
+
if (peek.match(/^```/))
|
|
194
|
+
break;
|
|
195
|
+
itemLines.push(peek.trim());
|
|
196
|
+
i++;
|
|
197
|
+
}
|
|
198
|
+
items.push({
|
|
199
|
+
marker: row.marker,
|
|
200
|
+
indent: row.indent,
|
|
201
|
+
spans: parseInline(itemLines.join(" ")),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
blocks.push({ kind: "list", ordered, items });
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
// Block-quote (single-line for now; runs collapse on blank line).
|
|
208
|
+
if (line.match(/^>\s?/)) {
|
|
209
|
+
const quoteLines = [line.replace(/^>\s?/, "")];
|
|
210
|
+
i++;
|
|
211
|
+
while (i < lines.length && lines[i].match(/^>\s?/)) {
|
|
212
|
+
quoteLines.push(lines[i].replace(/^>\s?/, ""));
|
|
213
|
+
i++;
|
|
214
|
+
}
|
|
215
|
+
blocks.push({ kind: "quote", spans: parseInline(quoteLines.join(" ")) });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
// Paragraph (consume until blank line, fence, list, quote, or heading).
|
|
219
|
+
const paraLines = [line];
|
|
220
|
+
i++;
|
|
221
|
+
while (i < lines.length) {
|
|
222
|
+
const peek = lines[i];
|
|
223
|
+
if (peek.trim() === "")
|
|
224
|
+
break;
|
|
225
|
+
if (peek.match(/^```/))
|
|
226
|
+
break;
|
|
227
|
+
if (peek.match(/^#{1,3}\s+/))
|
|
228
|
+
break;
|
|
229
|
+
if (matchListLine(peek))
|
|
230
|
+
break;
|
|
231
|
+
if (peek.match(/^>\s?/))
|
|
232
|
+
break;
|
|
233
|
+
paraLines.push(peek);
|
|
234
|
+
i++;
|
|
235
|
+
}
|
|
236
|
+
blocks.push({ kind: "paragraph", spans: parseInline(paraLines.join(" ")) });
|
|
237
|
+
}
|
|
238
|
+
return blocks;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Detect a list row and return its marker, body, indent depth, and
|
|
242
|
+
* kind. Matches `- foo`, `* foo`, `+ foo`, and ordered `12. foo`. The
|
|
243
|
+
* leading-whitespace count maps to a 2-space-per-level indent: 0 or 1
|
|
244
|
+
* leading spaces stay at level 0, 2-3 → 1, 4-5 → 2, etc.
|
|
245
|
+
*/
|
|
246
|
+
function matchListLine(line) {
|
|
247
|
+
const m = line.match(/^(\s*)([-*+]|\d+\.)\s+(.*)$/);
|
|
248
|
+
if (!m)
|
|
249
|
+
return null;
|
|
250
|
+
const indent = Math.floor(m[1].length / 2);
|
|
251
|
+
const raw = m[2];
|
|
252
|
+
const ordered = /^\d+\./.test(raw);
|
|
253
|
+
const marker = ordered ? raw : "•";
|
|
254
|
+
return { marker, body: m[3], indent, ordered };
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Split a single line of inline text into styled spans. Greedy, non-
|
|
258
|
+
* nested — `**bold _italic_**` doesn't render correctly, but plain
|
|
259
|
+
* `**bold**` and `*italic*` and `` `code` `` all work, which is what
|
|
260
|
+
* 95% of real responses look like.
|
|
261
|
+
*/
|
|
262
|
+
function parseInline(text) {
|
|
263
|
+
const spans = [];
|
|
264
|
+
const pattern = /(\*\*(.+?)\*\*|`([^`]+?)`|\*([^*\s][^*]*?)\*)/g;
|
|
265
|
+
let lastIndex = 0;
|
|
266
|
+
for (const match of text.matchAll(pattern)) {
|
|
267
|
+
const matchStart = match.index ?? 0;
|
|
268
|
+
if (matchStart > lastIndex) {
|
|
269
|
+
spans.push({ kind: "text", text: text.slice(lastIndex, matchStart) });
|
|
270
|
+
}
|
|
271
|
+
if (match[2] !== undefined)
|
|
272
|
+
spans.push({ kind: "bold", text: match[2] });
|
|
273
|
+
else if (match[3] !== undefined)
|
|
274
|
+
spans.push({ kind: "code", text: match[3] });
|
|
275
|
+
else if (match[4] !== undefined)
|
|
276
|
+
spans.push({ kind: "italic", text: match[4] });
|
|
277
|
+
lastIndex = matchStart + match[0].length;
|
|
278
|
+
}
|
|
279
|
+
if (lastIndex < text.length) {
|
|
280
|
+
spans.push({ kind: "text", text: text.slice(lastIndex) });
|
|
281
|
+
}
|
|
282
|
+
if (spans.length === 0)
|
|
283
|
+
spans.push({ kind: "text", text });
|
|
284
|
+
return spans;
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=Markdown.js.map
|