@ywldan/kiro 0.2.11 → 0.3.0

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/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
- export function Input({ disabled, placeholder, width, mask = false, allowEmpty = false, slashMenu = true, slashCommands, history, onSubmit, onCancel, onPaletteChange, }) {
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 ? filterSlashCommands(text, slashCommands) : [];
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
- onPaletteChange?.(menuOpen
35
- ? { commands: visibleCommands, activeIndex: Math.max(0, activeIndex - menuStart) }
36
- : null);
37
- // visibleCommands is derived from text, activeIndex and menuStart.
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
- }, [menuOpen, text, activeIndex, menuStart, onPaletteChange]);
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 displayChars = mask ? chars.map(() => '•') : chars;
228
- const charWidths = displayChars.map((char) => Math.max(1, stringWidth(char)));
229
- let start = 0;
230
- let widthToCursor = charWidths.slice(0, cursor).reduce((total, value) => total + value, 0);
231
- const cursorWidth = cursor < displayChars.length ? (charWidths[cursor] ?? 1) : 1;
232
- while (start < cursor && widthToCursor + cursorWidth > maxWidth) {
233
- widthToCursor -= charWidths[start] ?? 1;
234
- start++;
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
- let end = start;
237
- let used = 0;
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 before = displayChars.slice(start, cursor).join('');
246
- const at = displayChars[cursor] ?? ' ';
247
- const after = displayChars.slice(cursor + 1, end).join('');
248
- const showPlaceholder = chars.length === 0;
249
- return (_jsxs(Box, { flexShrink: 0, children: [_jsx(Text, { color: disabled ? 'gray' : 'cyan', bold: true, children: '› ' }), disabled ? (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: placeholder })) : showPlaceholder ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { inverse: true, children: " " }), _jsxs(Text, { dimColor: true, children: [" ", placeholder] })] })) : (_jsxs(Text, { wrap: "truncate-end", children: [before, _jsx(Text, { inverse: true, children: at }), after] }))] }));
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
@@ -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),
@@ -22,8 +22,8 @@ export function UsageCard({ usage, contextTokens, contextWindow, contextEstimate
22
22
  const accent = busy ? 'cyan' : 'gray';
23
23
  const innerWidth = Math.max(8, width - 4);
24
24
  const title = truncateToWidth(`Usage · ${usage.requests} req`, innerWidth);
25
- const prompt = usage.requests > 0 ? formatTokens(usage.promptTokens) : '—';
26
- const completion = usage.requests > 0 ? formatTokens(usage.completionTokens) : '—';
25
+ const prompt = usage.requests > 0 ? formatTokens(usage.promptTokens) : '-';
26
+ const completion = usage.requests > 0 ? formatTokens(usage.completionTokens) : '-';
27
27
  const bar = contextBar(contextTokens, contextWindow, Math.max(4, innerWidth - 9));
28
28
  const contextLine = truncateToWidth(`ctx ${bar} ${formatPercent(contextTokens, contextWindow).padStart(4)}`, innerWidth);
29
29
  const windowLine = truncateToWidth(`${contextEstimated ? '~' : ''}${formatTokens(contextTokens)} / ${formatTokens(contextWindow)} window`, innerWidth);
@@ -0,0 +1,111 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { walkTree } from '../tools/walk.js';
4
+ const execFileAsync = promisify(execFile);
5
+ export const MAX_INDEX_FILES = 50_000;
6
+ const MAX_GIT_OUTPUT_BYTES = 20 * 1024 * 1024;
7
+ function normalize(paths) {
8
+ const unique = new Set();
9
+ for (const raw of paths) {
10
+ const path = raw.split('\\').join('/').replace(/^\.\//, '');
11
+ if (!path || path.includes('\n'))
12
+ continue;
13
+ unique.add(path);
14
+ }
15
+ return [...unique].sort((left, right) => left.localeCompare(right)).slice(0, MAX_INDEX_FILES);
16
+ }
17
+ /** Tracked and untracked files, honouring .gitignore. Null when git is unavailable or fails. */
18
+ async function gitFiles(cwd, signal) {
19
+ try {
20
+ const { stdout } = await execFileAsync('git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'], {
21
+ cwd,
22
+ timeout: 3000,
23
+ maxBuffer: MAX_GIT_OUTPUT_BYTES,
24
+ signal,
25
+ });
26
+ return normalize(stdout.split('\0'));
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ async function walkFiles(cwd, signal) {
33
+ const controller = new AbortController();
34
+ const onAbort = () => controller.abort();
35
+ if (signal?.aborted)
36
+ return [];
37
+ signal?.addEventListener('abort', onAbort, { once: true });
38
+ const files = [];
39
+ try {
40
+ await walkTree({
41
+ cwd,
42
+ rootAbs: cwd,
43
+ signal: controller.signal,
44
+ visit(entry) {
45
+ if (entry.isDir)
46
+ return true;
47
+ files.push(entry.rel);
48
+ return files.length < MAX_INDEX_FILES;
49
+ },
50
+ });
51
+ }
52
+ finally {
53
+ signal?.removeEventListener('abort', onAbort);
54
+ }
55
+ return normalize(files);
56
+ }
57
+ /** File list for the @ menu: git first, then a .gitignore-aware walk. */
58
+ export async function listProjectFiles(cwd, signal) {
59
+ if (signal?.aborted)
60
+ return [];
61
+ const fromGit = await gitFiles(cwd, signal);
62
+ if (fromGit !== null)
63
+ return fromGit;
64
+ return walkFiles(cwd, signal);
65
+ }
66
+ function subsequence(text, needle) {
67
+ let index = 0;
68
+ for (const char of text) {
69
+ if (char === needle[index])
70
+ index++;
71
+ if (index === needle.length)
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+ /** Ranks paths for a mention query: basename matches first, then path matches. */
77
+ export function filterFiles(files, query, limit = 200) {
78
+ const needle = query.trim().toLowerCase();
79
+ if (!needle)
80
+ return files.slice(0, limit);
81
+ const scored = [];
82
+ for (const file of files) {
83
+ const lower = file.toLowerCase();
84
+ const base = lower.slice(lower.lastIndexOf('/') + 1);
85
+ let score = 0;
86
+ if (lower === needle)
87
+ score = 1000;
88
+ else if (base.startsWith(needle))
89
+ score = 900;
90
+ else if (base.includes(needle))
91
+ score = 800;
92
+ else if (lower.startsWith(needle))
93
+ score = 750;
94
+ else if (lower.split('/').some((segment) => segment.startsWith(needle)))
95
+ score = 700;
96
+ else if (lower.includes(needle))
97
+ score = 600;
98
+ else if (subsequence(base, needle))
99
+ score = 500;
100
+ else if (subsequence(lower, needle))
101
+ score = 400;
102
+ else
103
+ continue;
104
+ scored.push({ path: file, score });
105
+ }
106
+ scored.sort((left, right) => right.score - left.score ||
107
+ left.path.length - right.path.length ||
108
+ left.path.localeCompare(right.path));
109
+ return scored.slice(0, limit).map((entry) => entry.path);
110
+ }
111
+ //# sourceMappingURL=file-index.js.map
@@ -0,0 +1,63 @@
1
+ const BOUNDARY = /[\s([{'"]/;
2
+ /** Index of a freshly typed @ that can start a mention, or null. */
3
+ export function mentionOpeningAt(chars, cursor) {
4
+ if (cursor < 1 || chars[cursor - 1] !== '@')
5
+ return null;
6
+ if (cursor === 1)
7
+ return 0;
8
+ return BOUNDARY.test(chars[cursor - 2] ?? '') ? cursor - 1 : null;
9
+ }
10
+ /** Nearest valid mention ending at the caret, used after a typed chunk. */
11
+ export function mentionNearby(chars, cursor) {
12
+ for (let start = cursor - 1; start >= 0 && cursor - start <= 200; start--) {
13
+ const char = chars[start];
14
+ if (char === '\n')
15
+ return null;
16
+ if (char !== '@')
17
+ continue;
18
+ if (start > 0 && !BOUNDARY.test(chars[start - 1] ?? ''))
19
+ continue;
20
+ if (mentionAt(chars, cursor, start))
21
+ return start;
22
+ }
23
+ return null;
24
+ }
25
+ /** Reads the mention that starts at `start`, or null when the caret left it or it has whitespace. */
26
+ export function mentionAt(chars, cursor, start) {
27
+ if (start < 0 || start >= chars.length || chars[start] !== '@')
28
+ return null;
29
+ if (start > 0 && !BOUNDARY.test(chars[start - 1] ?? ''))
30
+ return null;
31
+ if (cursor <= start)
32
+ return null;
33
+ const quote = chars[start + 1];
34
+ if (quote === '"') {
35
+ let close = -1;
36
+ for (let index = start + 2; index < chars.length; index++) {
37
+ if (chars[index] === '"') {
38
+ close = index;
39
+ break;
40
+ }
41
+ if (chars[index] === '\n')
42
+ return null;
43
+ }
44
+ if (close !== -1 && close < cursor)
45
+ return null;
46
+ const end = close === -1 ? cursor : close + 1;
47
+ return {
48
+ start,
49
+ end,
50
+ query: chars.slice(start + 2, Math.min(cursor, end)).join(''),
51
+ quoted: true,
52
+ };
53
+ }
54
+ const query = chars.slice(start + 1, cursor).join('');
55
+ if (/[\s\n]/.test(query))
56
+ return null;
57
+ return { start, end: cursor, query, quoted: false };
58
+ }
59
+ /** Text to insert for a file path, quoting names that contain spaces. */
60
+ export function mentionText(file) {
61
+ return /[\s"]/.test(file) ? `@"${file.replace(/"/g, '\\"')}"` : `@${file}`;
62
+ }
63
+ //# sourceMappingURL=mention.js.map
package/dist/ui/mouse.js CHANGED
@@ -3,7 +3,7 @@ export const MOUSE_SCROLL_LINES = 3;
3
3
  /**
4
4
  * Enables button/wheel reporting with SGR coordinates; paired with MOUSE_OFF.
5
5
  * xterm has no wheel-only mode, so turning this on also hands clicks to Kiro
6
- * instead of starting a text selection — copy/paste then needs Shift+drag.
6
+ * instead of starting a text selection, so copy/paste needs Shift+drag.
7
7
  */
8
8
  export const MOUSE_ON = '\x1b[?1000h\x1b[?1006h';
9
9
  export const MOUSE_OFF = '\x1b[?1006l\x1b[?1000l';