@ywldan/kiro 0.2.12 → 0.3.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/README.md +516 -498
- package/dist/agent/prompt.js +1 -0
- package/dist/doctor.js +251 -0
- package/dist/index.js +49 -40
- package/dist/sessions.js +96 -14
- package/dist/tools/search.js +2 -60
- package/dist/tools/walk.js +62 -0
- package/dist/ui/App.js +96 -29
- package/dist/ui/Input.js +199 -31
- package/dist/ui/MessageList.js +26 -0
- package/dist/ui/SessionPicker.js +112 -0
- package/dist/ui/commands.js +2 -2
- package/dist/ui/file-index.js +111 -0
- package/dist/ui/mention.js +63 -0
- package/dist/ui/session-picker.js +96 -0
- package/dist/ui/text.js +159 -7
- package/dist/version.js +1 -1
- package/package.json +61 -61
package/dist/ui/App.js
CHANGED
|
@@ -12,16 +12,19 @@ import { applyOverrides, contextWindowFor, resolveProfile, saveConfig, } from '.
|
|
|
12
12
|
import { discoverModels, testConnection } from '../model/discovery.js';
|
|
13
13
|
import { runAddFlow, runEditFlow, runRemoveFlow, } from '../model/wizard.js';
|
|
14
14
|
import { createProvider } from '../providers/index.js';
|
|
15
|
-
import { dropIncompleteToolCalls, formatSessionTime, isSessionId, listSessions, loadSession, newSessionId, projectSessionsDir, saveSession, titleFromMessages, } from '../sessions.js';
|
|
15
|
+
import { dropIncompleteToolCalls, formatSessionTime, isSessionId, listAllSessions, listSessions, loadSession, newSessionId, projectSessionsDir, saveSession, titleFromMessages, } from '../sessions.js';
|
|
16
16
|
import { ApprovalPrompt } from './ApprovalPrompt.js';
|
|
17
17
|
import { ApprovalPolicy } from './approval-policy.js';
|
|
18
18
|
import { builtinCommandNames, buildSkillCommands, SLASH_COMMANDS, slashHelpLines, } from './commands.js';
|
|
19
19
|
import { defaultExportPath, renderTranscriptMarkdown } from './export.js';
|
|
20
|
+
import { listProjectFiles } from './file-index.js';
|
|
20
21
|
import { buildResumedView } from './history.js';
|
|
21
22
|
import { Input } from './Input.js';
|
|
22
23
|
import { MessageList } from './MessageList.js';
|
|
23
24
|
import { MOUSE_OFF, MOUSE_ON } from './mouse.js';
|
|
24
25
|
import { ModelPicker } from './ModelPicker.js';
|
|
26
|
+
import { SessionPicker } from './SessionPicker.js';
|
|
27
|
+
import { SESSION_INLINE_ROWS, shortCwd } from './session-picker.js';
|
|
25
28
|
import { PICKER_INLINE_ROWS, pickerPopupRect, withProfileModel, withProfileModels, } from './model-picker.js';
|
|
26
29
|
import { formatProfileList } from './profile-list.js';
|
|
27
30
|
import { loadPromptHistory, recordPrompt } from './prompt-history.js';
|
|
@@ -83,11 +86,23 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
83
86
|
const [cancelling, setCancelling] = useState(false);
|
|
84
87
|
const [pendingApproval, setPendingApproval] = useState(null);
|
|
85
88
|
const [pickerOpen, setPickerOpen] = useState(false);
|
|
89
|
+
const [sessionPicker, setSessionPicker] = useState(null);
|
|
86
90
|
const [quitArmed, setQuitArmed] = useState(false);
|
|
87
91
|
const [palette, setPalette] = useState(null);
|
|
88
92
|
const [usageCardEnabled, setUsageCardEnabled] = useState(true);
|
|
89
93
|
const [mouseOn, setMouseOn] = useState(mouseEnabled);
|
|
90
94
|
const [expandedToolId, setExpandedToolId] = useState(null);
|
|
95
|
+
const [inputRows, setInputRows] = useState(1);
|
|
96
|
+
const fileIndexRef = useRef(null);
|
|
97
|
+
const loadFileIndex = useCallback(async () => {
|
|
98
|
+
const cached = fileIndexRef.current;
|
|
99
|
+
if (cached && cached.cwd === cwd && Date.now() - cached.builtAt < 5000) {
|
|
100
|
+
return cached.files;
|
|
101
|
+
}
|
|
102
|
+
const files = await listProjectFiles(cwd);
|
|
103
|
+
fileIndexRef.current = { cwd, files, builtAt: Date.now() };
|
|
104
|
+
return files;
|
|
105
|
+
}, [cwd]);
|
|
91
106
|
const messagesRef = useRef((initialSession?.messages ?? []).filter((message) => message.role !== 'system'));
|
|
92
107
|
const usageRef = useRef(null);
|
|
93
108
|
const roundStartedAtRef = useRef(0);
|
|
@@ -480,6 +495,15 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
480
495
|
useEffect(() => {
|
|
481
496
|
void refreshSkillCommands();
|
|
482
497
|
}, [refreshSkillCommands]);
|
|
498
|
+
/** Loads the session list for the picker; other directories are grouped by cwd. */
|
|
499
|
+
const openSessionPicker = useCallback(async () => {
|
|
500
|
+
try {
|
|
501
|
+
setSessionPicker(await listAllSessions(cwd, 20));
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
addNotice('error', error instanceof Error ? error.message : String(error));
|
|
505
|
+
}
|
|
506
|
+
}, [cwd, addNotice]);
|
|
483
507
|
/** Mentions once per run when the model pulls instructions that came from the repo. */
|
|
484
508
|
const noteProjectSkill = useCallback(async (rawArguments) => {
|
|
485
509
|
let name;
|
|
@@ -807,6 +831,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
807
831
|
'',
|
|
808
832
|
' Model subcommands: /model <name> · /model add · /model edit [name] ·',
|
|
809
833
|
' /model remove [name] · /model test [name] · /model list --remote',
|
|
834
|
+
' Sessions: /resume opens a picker; ←/→ switches between this directory and others.',
|
|
810
835
|
'',
|
|
811
836
|
'Keys: Enter sends · / opens commands · PgUp/PgDn scrolls · Ctrl+O expands tool output ·',
|
|
812
837
|
' Tab completes a command · Esc cancels a wizard step · /mouse toggles wheel scroll',
|
|
@@ -990,27 +1015,42 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
990
1015
|
case '/resume': {
|
|
991
1016
|
transitioningRef.current = true;
|
|
992
1017
|
try {
|
|
1018
|
+
if (command === '/resume' && !argument) {
|
|
1019
|
+
await openSessionPicker();
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
993
1022
|
if (command === '/sessions' || !argument) {
|
|
994
|
-
const
|
|
995
|
-
listedSessionsRef.current =
|
|
996
|
-
|
|
1023
|
+
const data = await listAllSessions(cwd, 10);
|
|
1024
|
+
listedSessionsRef.current = data.current;
|
|
1025
|
+
const otherCount = data.others.reduce((total, group) => total + group.sessions.length, 0);
|
|
1026
|
+
if (data.current.length === 0 && otherCount === 0) {
|
|
997
1027
|
addNotice('info', `No saved sessions for this directory yet. Sessions are stored in ${projectSessionsDir(cwd)}.`);
|
|
998
1028
|
}
|
|
999
1029
|
else {
|
|
1000
|
-
const lines =
|
|
1030
|
+
const lines = ['Sessions (most recent first):'];
|
|
1031
|
+
lines.push(`This directory (${data.current.length}):`);
|
|
1032
|
+
if (data.current.length === 0)
|
|
1033
|
+
lines.push(' (none)');
|
|
1034
|
+
data.current.forEach((session, index) => {
|
|
1001
1035
|
const marker = session.id === sessionRef.current?.id ? '*' : ' ';
|
|
1002
1036
|
const messages = `${session.messageCount} msg${session.messageCount === 1 ? '' : 's'}`;
|
|
1003
|
-
|
|
1037
|
+
lines.push(`${marker} ${index + 1}. ${session.id} ${formatSessionTime(session.updatedAt)} ${messages} ${session.title}`);
|
|
1004
1038
|
});
|
|
1005
|
-
|
|
1006
|
-
'
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1039
|
+
if (otherCount > 0) {
|
|
1040
|
+
lines.push('Other directories:');
|
|
1041
|
+
for (const group of data.others) {
|
|
1042
|
+
lines.push(` ${shortCwd(group.cwd, cwd)}`);
|
|
1043
|
+
for (const session of group.sessions) {
|
|
1044
|
+
const messages = `${session.messageCount} msg${session.messageCount === 1 ? '' : 's'}`;
|
|
1045
|
+
lines.push(` ${session.id} ${formatSessionTime(session.updatedAt)} ${messages} ${session.title}`);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
lines.push('', 'Use /resume to pick a session, or /resume <number|id> for this directory.');
|
|
1050
|
+
addNotice('info', lines.join('\n'));
|
|
1011
1051
|
}
|
|
1012
|
-
if (skipped > 0) {
|
|
1013
|
-
addNotice('muted', `Skipped ${skipped} unreadable session file${skipped === 1 ? '' : 's'}.`);
|
|
1052
|
+
if (data.skipped > 0) {
|
|
1053
|
+
addNotice('muted', `Skipped ${data.skipped} unreadable session file${data.skipped === 1 ? '' : 's'}.`);
|
|
1014
1054
|
}
|
|
1015
1055
|
return;
|
|
1016
1056
|
}
|
|
@@ -1214,6 +1254,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1214
1254
|
cwd,
|
|
1215
1255
|
listRemoteModels,
|
|
1216
1256
|
mouseOn,
|
|
1257
|
+
openSessionPicker,
|
|
1217
1258
|
persistSession,
|
|
1218
1259
|
profileName,
|
|
1219
1260
|
quit,
|
|
@@ -1227,6 +1268,15 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1227
1268
|
version,
|
|
1228
1269
|
yolo,
|
|
1229
1270
|
]);
|
|
1271
|
+
/** Resumes a picker selection only when it belongs to the current directory. */
|
|
1272
|
+
const handleSessionPick = (session) => {
|
|
1273
|
+
setSessionPicker(null);
|
|
1274
|
+
if (path.resolve(session.cwd) !== path.resolve(cwd)) {
|
|
1275
|
+
addNotice('info', `Session ${session.id} belongs to ${shortCwd(session.cwd, cwd)}. Start kiro in that directory to resume it.`);
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
void handleCommand(`/resume ${session.id}`);
|
|
1279
|
+
};
|
|
1230
1280
|
/** Runs the next queued item once the app is idle, including queued slash commands. */
|
|
1231
1281
|
const drainQueue = useCallback(() => {
|
|
1232
1282
|
if (busyRef.current ||
|
|
@@ -1254,6 +1304,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1254
1304
|
const trimmed = value.trim();
|
|
1255
1305
|
if (!trimmed)
|
|
1256
1306
|
return;
|
|
1307
|
+
const isCommand = trimmed.startsWith('/') && !trimmed.includes('\n');
|
|
1257
1308
|
if (wizardActiveRef.current || transitioningRef.current) {
|
|
1258
1309
|
// The wizard owns the keyboard; ignore stray input.
|
|
1259
1310
|
return;
|
|
@@ -1262,7 +1313,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1262
1313
|
// Type-ahead: the message runs as soon as the current turn finishes.
|
|
1263
1314
|
queuedRef.current.push(trimmed);
|
|
1264
1315
|
setQueuedCount(queuedRef.current.length);
|
|
1265
|
-
if (!
|
|
1316
|
+
if (!isCommand) {
|
|
1266
1317
|
setItems((current) => [
|
|
1267
1318
|
...current,
|
|
1268
1319
|
{ kind: 'user', id: nextItemIdRef.current++, text: trimmed },
|
|
@@ -1271,7 +1322,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1271
1322
|
addNotice('muted', 'Queued. It runs after the current turn; PgUp/PgDn still scrolls the transcript meanwhile.');
|
|
1272
1323
|
return;
|
|
1273
1324
|
}
|
|
1274
|
-
if (
|
|
1325
|
+
if (isCommand) {
|
|
1275
1326
|
void handleCommand(trimmed).finally(() => drainQueueRef.current?.());
|
|
1276
1327
|
return;
|
|
1277
1328
|
}
|
|
@@ -1313,7 +1364,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1313
1364
|
if (key.ctrl && input === 'o') {
|
|
1314
1365
|
if (wizardActiveRef.current || wizardPromptRef.current || pendingApprovalRef.current)
|
|
1315
1366
|
return;
|
|
1316
|
-
if (pickerOpen)
|
|
1367
|
+
if (pickerOpen || sessionPicker !== null)
|
|
1317
1368
|
return;
|
|
1318
1369
|
expandLastToolOutput();
|
|
1319
1370
|
return;
|
|
@@ -1325,6 +1376,11 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1325
1376
|
setPickerOpen(false);
|
|
1326
1377
|
return;
|
|
1327
1378
|
}
|
|
1379
|
+
if (sessionPicker !== null) {
|
|
1380
|
+
disarmQuit();
|
|
1381
|
+
setSessionPicker(null);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1328
1384
|
if (wizardActiveRef.current) {
|
|
1329
1385
|
disarmQuit();
|
|
1330
1386
|
cancelWizard();
|
|
@@ -1368,21 +1424,32 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1368
1424
|
: null;
|
|
1369
1425
|
const activeProfile = runtimeConfig.profiles[profileName];
|
|
1370
1426
|
const contextWindow = contextWindowFor(activeProfile);
|
|
1371
|
-
const pickerPopup = pickerOpen
|
|
1427
|
+
const pickerPopup = (pickerOpen || sessionPicker !== null) && !pendingApproval
|
|
1428
|
+
? pickerPopupRect(columns, rows)
|
|
1429
|
+
: null;
|
|
1372
1430
|
const pickerInline = pickerOpen && !pendingApproval && pickerPopup === null;
|
|
1373
|
-
const
|
|
1431
|
+
const sessionInline = sessionPicker !== null && !pendingApproval && pickerPopup === null && !pickerOpen;
|
|
1432
|
+
const extraInputRows = pendingApproval || pickerInline || sessionInline ? 0 : Math.max(0, inputRows - 1);
|
|
1433
|
+
const viewportHeight = Math.max(3, rows -
|
|
1434
|
+
5 -
|
|
1435
|
+
extraInputRows -
|
|
1436
|
+
(pendingApproval ? 12 : 0) -
|
|
1437
|
+
(pickerInline ? PICKER_INLINE_ROWS : 0) -
|
|
1438
|
+
(sessionInline ? SESSION_INLINE_ROWS : 0));
|
|
1374
1439
|
const showUsageCard = usageCardEnabled && shouldShowUsageCard(columns, viewportHeight);
|
|
1375
1440
|
const chatWidth = showUsageCard ? Math.max(40, width - USAGE_CARD_WIDTH - USAGE_CARD_GAP) : width;
|
|
1376
|
-
return (_jsxs(Box, { flexDirection: "column", width: columns, paddingX: 1, children: [_jsxs(Box, { flexDirection: "row", alignItems: "flex-end", width: width, children: [_jsx(MessageList, { items: items, width: chatWidth, height: viewportHeight, resetSignal: resetSignal, expandedToolId: expandedToolId, palette: palette, interactive: !pendingApproval && !pickerOpen && !wizardActive && wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, onDecision: resolveApproval })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : (_jsx(Input, { disabled: pickerOpen, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, placeholder: pickerOpen
|
|
1441
|
+
return (_jsxs(Box, { flexDirection: "column", width: columns, paddingX: 1, children: [_jsxs(Box, { flexDirection: "row", alignItems: "flex-end", width: width, children: [_jsx(MessageList, { items: items, width: chatWidth, height: viewportHeight, resetSignal: resetSignal, expandedToolId: expandedToolId, palette: palette, interactive: !pendingApproval && !pickerOpen && sessionPicker === null && !wizardActive && wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, onDecision: resolveApproval })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : sessionInline && sessionPicker ? (_jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: width, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) })) : (_jsx(Input, { disabled: pickerOpen || sessionPicker !== null, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, fileMenu: !wizardActive && !wizardPrompt, loadFiles: loadFileIndex, maxRows: Math.max(1, Math.min(6, rows - 9)), history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, onHeightChange: setInputRows, placeholder: pickerOpen
|
|
1377
1442
|
? 'Model picker open · Esc to close'
|
|
1378
|
-
:
|
|
1379
|
-
?
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
:
|
|
1385
|
-
? '
|
|
1386
|
-
:
|
|
1443
|
+
: sessionPicker
|
|
1444
|
+
? 'Session picker open · Esc to close'
|
|
1445
|
+
: wizardPrompt
|
|
1446
|
+
? wizardPrompt.defaultValue && !wizardPrompt.mask
|
|
1447
|
+
? `${wizardPrompt.label} [${wizardPrompt.defaultValue}]`
|
|
1448
|
+
: wizardPrompt.label
|
|
1449
|
+
: busy
|
|
1450
|
+
? 'Kiro is working… type ahead, or Ctrl+C to cancel'
|
|
1451
|
+
: wizardActive
|
|
1452
|
+
? 'Working… Esc to cancel'
|
|
1453
|
+
: 'Ask Kiro to build or change something…', slashMenu: !wizardActive && !wizardPrompt, onSubmit: handleSubmit, onCancel: wizardActive ? cancelWizard : undefined }, wizardPrompt?.id ?? 0)), _jsx(StatusBar, { width: width, profile: profileName, model: activeProfile?.model ?? 'unknown', cwd: cwd, activity: activity, toolName: activeTool ?? undefined, busySince: busySince ?? undefined, queued: queuedCount > 0 ? queuedCount : undefined, yolo: yolo, autoAllowed: autoAllowed, quitHint: quitArmed, contextTokens: showUsageCard ? undefined : contextTokens, contextWindow: showUsageCard ? undefined : contextWindow }), pickerOpen && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: pickerPopup.width, height: pickerPopup.height, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) }) })) : sessionPicker && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: pickerPopup.width, height: pickerPopup.height, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) }) })) : null] }));
|
|
1387
1454
|
}
|
|
1388
1455
|
//# sourceMappingURL=App.js.map
|
package/dist/ui/Input.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Box, Text, useInput, useStdin } from 'ink';
|
|
4
|
-
import stringWidth from 'string-width';
|
|
5
4
|
import { filterSlashCommands } from './commands.js';
|
|
5
|
+
import { filterFiles } from './file-index.js';
|
|
6
|
+
import { mentionAt, mentionNearby, mentionText } from './mention.js';
|
|
6
7
|
import { isMouseSequence } from './mouse.js';
|
|
7
|
-
import { applyInputOps, parseEditSequence, parseInputChunk, } from './text.js';
|
|
8
|
+
import { applyInputOps, cursorLineIndex, feedPaste, layoutInput, parseEditSequence, parseInputChunk, } from './text.js';
|
|
8
9
|
const MAX_INPUT_CHARS = 20_000;
|
|
9
10
|
const MAX_MENU_ROWS = 6;
|
|
10
|
-
|
|
11
|
+
const MAX_VISIBLE_LINES = 6;
|
|
12
|
+
const PASTE_ON = '\x1b[?2004h';
|
|
13
|
+
const PASTE_OFF = '\x1b[?2004l';
|
|
14
|
+
export function Input({ disabled, placeholder, width, mask = false, allowEmpty = false, slashMenu = true, fileMenu = true, loadFiles, maxRows = MAX_VISIBLE_LINES, slashCommands, history, onSubmit, onCancel, onHeightChange, onPaletteChange, }) {
|
|
11
15
|
const { stdin } = useStdin();
|
|
12
16
|
const [state, setState] = useState({ chars: [], cursor: 0 });
|
|
13
17
|
const [selected, setSelected] = useState(0);
|
|
14
18
|
const [historyIndex, setHistoryIndex] = useState(null);
|
|
19
|
+
const [mentionStart, setMentionStart] = useState(null);
|
|
20
|
+
const [files, setFiles] = useState(null);
|
|
21
|
+
const [filesLoading, setFilesLoading] = useState(false);
|
|
15
22
|
const stateRef = useRef(state);
|
|
16
23
|
stateRef.current = state;
|
|
24
|
+
const pasteRef = useRef({ open: false, buffer: '', pending: '' });
|
|
17
25
|
const text = state.chars.join('');
|
|
18
26
|
const recalled = historyIndex !== null ? (history?.[historyIndex] ?? null) : null;
|
|
19
27
|
useEffect(() => {
|
|
@@ -22,21 +30,89 @@ export function Input({ disabled, placeholder, width, mask = false, allowEmpty =
|
|
|
22
30
|
setHistoryIndex(null);
|
|
23
31
|
}
|
|
24
32
|
}, [historyIndex, recalled, text]);
|
|
25
|
-
const matches = slashMenu && !mask && !disabled
|
|
33
|
+
const matches = slashMenu && !mask && !disabled && !text.includes('\n')
|
|
34
|
+
? filterSlashCommands(text, slashCommands)
|
|
35
|
+
: [];
|
|
26
36
|
const menuOpen = matches.length > 0;
|
|
27
37
|
const activeIndex = Math.min(selected, Math.max(0, matches.length - 1));
|
|
28
38
|
const menuStart = Math.max(0, Math.min(activeIndex - Math.floor(MAX_MENU_ROWS / 2), matches.length - MAX_MENU_ROWS));
|
|
29
39
|
const visibleCommands = matches.slice(menuStart, menuStart + MAX_MENU_ROWS);
|
|
40
|
+
const mention = fileMenu && !mask && !disabled && mentionStart !== null && !text.startsWith('/')
|
|
41
|
+
? mentionAt(state.chars, state.cursor, mentionStart)
|
|
42
|
+
: null;
|
|
43
|
+
const mentionOpen = mention !== null;
|
|
44
|
+
const mentionQuery = mention?.query ?? '';
|
|
45
|
+
const fileMatches = mention && files ? filterFiles(files, mentionQuery) : [];
|
|
46
|
+
const fileActive = Math.min(selected, Math.max(0, fileMatches.length - 1));
|
|
47
|
+
const fileStart = Math.max(0, Math.min(fileActive - Math.floor(MAX_MENU_ROWS / 2), fileMatches.length - MAX_MENU_ROWS));
|
|
48
|
+
const visibleFiles = fileMatches.slice(fileStart, fileStart + MAX_MENU_ROWS);
|
|
49
|
+
const filesHeader = filesLoading && files === null
|
|
50
|
+
? 'files · indexing…'
|
|
51
|
+
: fileMatches.length === 0
|
|
52
|
+
? `files · no matches for "${mentionQuery}" · Esc to close`
|
|
53
|
+
: `files ${fileStart + 1}-${fileStart + visibleFiles.length} of ${fileMatches.length} · ↑/↓ move · Tab/Enter insert · Esc close`;
|
|
54
|
+
const fileSignature = `${mentionOpen}|${mentionQuery}|${filesLoading}|${fileStart}|${fileActive}|${visibleFiles.join('\u0000')}`;
|
|
30
55
|
useEffect(() => {
|
|
31
56
|
setSelected(0);
|
|
32
57
|
}, [text]);
|
|
33
58
|
useEffect(() => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
if (!mentionOpen || !loadFiles)
|
|
60
|
+
return;
|
|
61
|
+
let cancelled = false;
|
|
62
|
+
setFilesLoading(true);
|
|
63
|
+
loadFiles()
|
|
64
|
+
.then((list) => {
|
|
65
|
+
if (!cancelled)
|
|
66
|
+
setFiles(list);
|
|
67
|
+
})
|
|
68
|
+
.catch(() => {
|
|
69
|
+
if (!cancelled)
|
|
70
|
+
setFiles([]);
|
|
71
|
+
})
|
|
72
|
+
.finally(() => {
|
|
73
|
+
if (!cancelled)
|
|
74
|
+
setFilesLoading(false);
|
|
75
|
+
});
|
|
76
|
+
return () => {
|
|
77
|
+
cancelled = true;
|
|
78
|
+
};
|
|
79
|
+
}, [mentionOpen, loadFiles]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (mentionStart !== null && !mentionAt(state.chars, state.cursor, mentionStart)) {
|
|
82
|
+
setMentionStart(null);
|
|
83
|
+
}
|
|
84
|
+
}, [state, mentionStart]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (menuOpen) {
|
|
87
|
+
onPaletteChange?.({
|
|
88
|
+
kind: 'commands',
|
|
89
|
+
commands: visibleCommands,
|
|
90
|
+
activeIndex: Math.max(0, activeIndex - menuStart),
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (mentionOpen) {
|
|
95
|
+
onPaletteChange?.({
|
|
96
|
+
kind: 'files',
|
|
97
|
+
files: visibleFiles,
|
|
98
|
+
activeIndex: Math.max(0, fileActive - fileStart),
|
|
99
|
+
header: filesHeader,
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
onPaletteChange?.(null);
|
|
104
|
+
// visible rows are derived from text, fileSignature, and the window offsets.
|
|
38
105
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
-
}, [
|
|
106
|
+
}, [
|
|
107
|
+
menuOpen,
|
|
108
|
+
text,
|
|
109
|
+
activeIndex,
|
|
110
|
+
menuStart,
|
|
111
|
+
mentionOpen,
|
|
112
|
+
fileSignature,
|
|
113
|
+
filesHeader,
|
|
114
|
+
onPaletteChange,
|
|
115
|
+
]);
|
|
40
116
|
useEffect(() => () => onPaletteChange?.(null), [onPaletteChange]);
|
|
41
117
|
const update = (chars, cursor) => {
|
|
42
118
|
const next = { chars, cursor: Math.max(0, Math.min(cursor, chars.length)) };
|
|
@@ -89,12 +165,58 @@ export function Input({ disabled, placeholder, width, mask = false, allowEmpty =
|
|
|
89
165
|
// deleteBackward/deleteForward only use stable setters and refs.
|
|
90
166
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
167
|
}, [disabled, stdin]);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (disabled || !process.stdout.isTTY)
|
|
170
|
+
return;
|
|
171
|
+
process.stdout.write(PASTE_ON);
|
|
172
|
+
return () => {
|
|
173
|
+
process.stdout.write(PASTE_OFF);
|
|
174
|
+
};
|
|
175
|
+
}, [disabled]);
|
|
92
176
|
useInput((input, key) => {
|
|
93
177
|
const { chars, cursor } = stateRef.current;
|
|
94
178
|
if (key.backspace || key.delete)
|
|
95
179
|
return; // handled from raw stdin above
|
|
96
180
|
if (isMouseSequence(input))
|
|
97
181
|
return;
|
|
182
|
+
const pasted = feedPaste(pasteRef.current, input);
|
|
183
|
+
pasteRef.current = pasted.state;
|
|
184
|
+
if (pasted.consumed) {
|
|
185
|
+
if (pasted.text !== null) {
|
|
186
|
+
const inserted = mask ? pasted.text.replace(/\n/g, ' ') : pasted.text;
|
|
187
|
+
const applied = applyInputOps({ chars, cursor }, [{ type: 'insert', text: inserted }], MAX_INPUT_CHARS);
|
|
188
|
+
setMentionStart(null);
|
|
189
|
+
update(applied.state.chars, applied.state.cursor);
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (mention) {
|
|
194
|
+
if (key.upArrow) {
|
|
195
|
+
if (fileMatches.length > 0) {
|
|
196
|
+
setSelected((fileActive - 1 + fileMatches.length) % fileMatches.length);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (key.downArrow) {
|
|
201
|
+
if (fileMatches.length > 0) {
|
|
202
|
+
setSelected((fileActive + 1) % fileMatches.length);
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if ((key.tab || key.return) && fileMatches.length > 0) {
|
|
207
|
+
const file = fileMatches[fileActive];
|
|
208
|
+
const inserted = Array.from(`${mentionText(file)} `);
|
|
209
|
+
const next = [
|
|
210
|
+
...chars.slice(0, mention.start),
|
|
211
|
+
...inserted,
|
|
212
|
+
...chars.slice(mention.end),
|
|
213
|
+
];
|
|
214
|
+
update(next, mention.start + inserted.length);
|
|
215
|
+
setMentionStart(null);
|
|
216
|
+
setSelected(0);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
98
220
|
if (menuOpen) {
|
|
99
221
|
if (key.upArrow) {
|
|
100
222
|
setSelected((activeIndex - 1 + matches.length) % matches.length);
|
|
@@ -147,29 +269,46 @@ export function Input({ disabled, placeholder, width, mask = false, allowEmpty =
|
|
|
147
269
|
if (key.return) {
|
|
148
270
|
if (menuOpen) {
|
|
149
271
|
const command = matches[activeIndex].name;
|
|
272
|
+
setMentionStart(null);
|
|
150
273
|
update([], 0);
|
|
151
274
|
setSelected(0);
|
|
152
275
|
onSubmit(command);
|
|
153
276
|
return;
|
|
154
277
|
}
|
|
278
|
+
if (!mask && key.meta) {
|
|
279
|
+
update([...chars.slice(0, cursor), '\n', ...chars.slice(cursor)], cursor + 1);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!mask && cursor > 0 && chars[cursor - 1] === '\\') {
|
|
283
|
+
update([...chars.slice(0, cursor - 1), '\n', ...chars.slice(cursor)], cursor);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
155
286
|
const value = chars.join('');
|
|
156
287
|
if (value.trim() || allowEmpty) {
|
|
288
|
+
setMentionStart(null);
|
|
157
289
|
update([], 0);
|
|
158
290
|
onSubmit(value);
|
|
159
291
|
}
|
|
160
292
|
return;
|
|
161
293
|
}
|
|
162
294
|
if (key.escape) {
|
|
295
|
+
if (mentionOpen) {
|
|
296
|
+
setMentionStart(null);
|
|
297
|
+
setSelected(0);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
163
300
|
update([], 0);
|
|
164
301
|
if (onCancel)
|
|
165
302
|
onCancel();
|
|
166
303
|
return;
|
|
167
304
|
}
|
|
168
305
|
if (key.ctrl && input === 'a') {
|
|
306
|
+
setMentionStart(null);
|
|
169
307
|
update(chars, 0);
|
|
170
308
|
return;
|
|
171
309
|
}
|
|
172
310
|
if (key.ctrl && input === 'e') {
|
|
311
|
+
setMentionStart(null);
|
|
173
312
|
update(chars, chars.length);
|
|
174
313
|
return;
|
|
175
314
|
}
|
|
@@ -191,18 +330,22 @@ export function Input({ disabled, placeholder, width, mask = false, allowEmpty =
|
|
|
191
330
|
return;
|
|
192
331
|
}
|
|
193
332
|
if (key.leftArrow) {
|
|
333
|
+
setMentionStart(null);
|
|
194
334
|
update(chars, cursor - 1);
|
|
195
335
|
return;
|
|
196
336
|
}
|
|
197
337
|
if (key.rightArrow) {
|
|
338
|
+
setMentionStart(null);
|
|
198
339
|
update(chars, cursor + 1);
|
|
199
340
|
return;
|
|
200
341
|
}
|
|
201
342
|
if (key.home) {
|
|
343
|
+
setMentionStart(null);
|
|
202
344
|
update(chars, 0);
|
|
203
345
|
return;
|
|
204
346
|
}
|
|
205
347
|
if (key.end) {
|
|
348
|
+
setMentionStart(null);
|
|
206
349
|
update(chars, chars.length);
|
|
207
350
|
return;
|
|
208
351
|
}
|
|
@@ -210,42 +353,67 @@ export function Input({ disabled, placeholder, width, mask = false, allowEmpty =
|
|
|
210
353
|
return;
|
|
211
354
|
// Chunks that mix text with control bytes (\r, \x7f, ctrl keys) are not
|
|
212
355
|
// decoded by Ink, so replay their control bytes as edits in chunk order.
|
|
213
|
-
const ops = parseInputChunk(input);
|
|
356
|
+
const ops = parseInputChunk(mask ? input.replace(/\n/g, ' ') : input);
|
|
214
357
|
if (ops.length === 0)
|
|
215
358
|
return;
|
|
216
359
|
const applied = applyInputOps({ chars, cursor }, ops, MAX_INPUT_CHARS);
|
|
217
360
|
const value = applied.state.chars.join('');
|
|
218
361
|
if (applied.submitted && (value.trim() || allowEmpty)) {
|
|
362
|
+
setMentionStart(null);
|
|
219
363
|
update([], 0);
|
|
220
364
|
onSubmit(value);
|
|
221
365
|
return;
|
|
222
366
|
}
|
|
367
|
+
if (!mask && fileMenu && !value.startsWith('/')) {
|
|
368
|
+
const opened = mentionNearby(applied.state.chars, applied.state.cursor);
|
|
369
|
+
if (opened !== null)
|
|
370
|
+
setMentionStart(opened);
|
|
371
|
+
}
|
|
223
372
|
update(applied.state.chars, applied.state.cursor);
|
|
224
373
|
}, { isActive: !disabled });
|
|
225
374
|
const maxWidth = Math.max(4, width - 2);
|
|
226
375
|
const { chars, cursor } = state;
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
376
|
+
const lines = layoutInput(chars, maxWidth, mask);
|
|
377
|
+
const cursorIndex = cursorLineIndex(lines, cursor);
|
|
378
|
+
const windowSize = Math.max(1, Math.min(maxRows, MAX_VISIBLE_LINES, lines.length));
|
|
379
|
+
const windowStart = Math.max(0, Math.min(cursorIndex - windowSize + 1, lines.length - windowSize));
|
|
380
|
+
const visible = lines.slice(windowStart, windowStart + windowSize);
|
|
381
|
+
const hiddenAbove = windowStart > 0;
|
|
382
|
+
const hiddenBelow = windowStart + visible.length < lines.length;
|
|
383
|
+
const rows = disabled || chars.length === 0 ? 1 : visible.length;
|
|
384
|
+
useEffect(() => {
|
|
385
|
+
onHeightChange?.(rows);
|
|
386
|
+
}, [rows, onHeightChange]);
|
|
387
|
+
if (disabled) {
|
|
388
|
+
return (_jsxs(Box, { flexShrink: 0, children: [_jsx(Text, { color: "gray", bold: true, children: '› ' }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: placeholder })] }));
|
|
235
389
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
while (end < displayChars.length) {
|
|
239
|
-
const charWidth = charWidths[end] ?? 1;
|
|
240
|
-
if (used + charWidth > maxWidth)
|
|
241
|
-
break;
|
|
242
|
-
used += charWidth;
|
|
243
|
-
end++;
|
|
390
|
+
if (chars.length === 0) {
|
|
391
|
+
return (_jsxs(Box, { flexShrink: 0, children: [_jsx(Text, { color: "cyan", bold: true, children: '› ' }), _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { inverse: true, children: " " }), _jsxs(Text, { dimColor: true, children: [" ", placeholder] })] })] }));
|
|
244
392
|
}
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
393
|
+
const shown = (values) => (mask ? '•'.repeat(values.length) : values.join(''));
|
|
394
|
+
return (_jsx(Box, { flexDirection: "column", flexShrink: 0, children: visible.map((line, offset) => {
|
|
395
|
+
const absolute = windowStart + offset;
|
|
396
|
+
const isCursor = absolute === cursorIndex;
|
|
397
|
+
const isFirst = absolute === 0;
|
|
398
|
+
const isLast = offset === visible.length - 1;
|
|
399
|
+
const prefix = isLast && hiddenBelow
|
|
400
|
+
? '↓ '
|
|
401
|
+
: offset === 0 && hiddenAbove
|
|
402
|
+
? '↑ '
|
|
403
|
+
: isFirst
|
|
404
|
+
? '› '
|
|
405
|
+
: ' ';
|
|
406
|
+
const prefixColor = isFirst && !hiddenAbove ? 'cyan' : 'gray';
|
|
407
|
+
const before = shown(chars.slice(line.start, Math.min(cursor, line.end)));
|
|
408
|
+
const at = isCursor
|
|
409
|
+
? cursor < line.end
|
|
410
|
+
? shown([chars[cursor]])
|
|
411
|
+
: ' '
|
|
412
|
+
: '';
|
|
413
|
+
const after = isCursor
|
|
414
|
+
? shown(chars.slice(Math.min(cursor + 1, line.end), line.end))
|
|
415
|
+
: '';
|
|
416
|
+
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: prefixColor, dimColor: prefixColor === 'gray', bold: prefixColor === 'cyan', children: prefix }), isCursor ? (_jsxs(Text, { wrap: "truncate-end", children: [before, _jsx(Text, { inverse: true, children: at }), after] })) : (_jsx(Text, { wrap: "truncate-end", children: line.text }))] }, absolute));
|
|
417
|
+
}) }));
|
|
250
418
|
}
|
|
251
419
|
//# sourceMappingURL=Input.js.map
|
package/dist/ui/MessageList.js
CHANGED
|
@@ -186,6 +186,32 @@ export function buildLines(items, width, expandedToolId = null) {
|
|
|
186
186
|
const PALETTE_ROWS = 6;
|
|
187
187
|
/** Header plus the visible command rows; padded so filtering never changes its height. */
|
|
188
188
|
export function buildPaletteLines(palette, width) {
|
|
189
|
+
if (palette.kind === 'files') {
|
|
190
|
+
const header = {
|
|
191
|
+
prefix: ' ',
|
|
192
|
+
text: truncateToWidth(palette.header, width),
|
|
193
|
+
dim: true,
|
|
194
|
+
};
|
|
195
|
+
const rows = palette.files.slice(0, PALETTE_ROWS).map((file, index) => {
|
|
196
|
+
const active = index === palette.activeIndex;
|
|
197
|
+
const slash = file.lastIndexOf('/');
|
|
198
|
+
const directory = slash === -1 ? '' : file.slice(0, slash + 1);
|
|
199
|
+
const name = file.slice(slash + 1);
|
|
200
|
+
return {
|
|
201
|
+
prefix: active ? '› ' : ' ',
|
|
202
|
+
prefixColor: active ? 'cyan' : undefined,
|
|
203
|
+
text: '',
|
|
204
|
+
segments: [
|
|
205
|
+
{ text: directory, dim: true },
|
|
206
|
+
{ text: name, bold: active },
|
|
207
|
+
],
|
|
208
|
+
inverse: active,
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
while (rows.length < PALETTE_ROWS)
|
|
212
|
+
rows.push({ prefix: '', text: '' });
|
|
213
|
+
return [header, ...rows];
|
|
214
|
+
}
|
|
189
215
|
const header = {
|
|
190
216
|
prefix: ' ',
|
|
191
217
|
text: truncateToWidth('commands · ↑/↓ move · Tab complete · Enter run', width),
|