@code-yeongyu/senpi-tui 2026.7.25-2

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.
Files changed (130) hide show
  1. package/README.md +790 -0
  2. package/dist/autocomplete.d.ts +57 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +646 -0
  5. package/dist/autocomplete.js.map +1 -0
  6. package/dist/components/box.d.ts +25 -0
  7. package/dist/components/box.d.ts.map +1 -0
  8. package/dist/components/box.js +117 -0
  9. package/dist/components/box.js.map +1 -0
  10. package/dist/components/cancellable-loader.d.ts +22 -0
  11. package/dist/components/cancellable-loader.d.ts.map +1 -0
  12. package/dist/components/cancellable-loader.js +36 -0
  13. package/dist/components/cancellable-loader.js.map +1 -0
  14. package/dist/components/editor.d.ts +257 -0
  15. package/dist/components/editor.d.ts.map +1 -0
  16. package/dist/components/editor.js +2014 -0
  17. package/dist/components/editor.js.map +1 -0
  18. package/dist/components/image.d.ts +28 -0
  19. package/dist/components/image.d.ts.map +1 -0
  20. package/dist/components/image.js +82 -0
  21. package/dist/components/image.js.map +1 -0
  22. package/dist/components/input.d.ts +37 -0
  23. package/dist/components/input.d.ts.map +1 -0
  24. package/dist/components/input.js +378 -0
  25. package/dist/components/input.js.map +1 -0
  26. package/dist/components/loader.d.ts +46 -0
  27. package/dist/components/loader.d.ts.map +1 -0
  28. package/dist/components/loader.js +110 -0
  29. package/dist/components/loader.js.map +1 -0
  30. package/dist/components/markdown.d.ts +105 -0
  31. package/dist/components/markdown.d.ts.map +1 -0
  32. package/dist/components/markdown.js +789 -0
  33. package/dist/components/markdown.js.map +1 -0
  34. package/dist/components/select-list.d.ts +50 -0
  35. package/dist/components/select-list.d.ts.map +1 -0
  36. package/dist/components/select-list.js +154 -0
  37. package/dist/components/select-list.js.map +1 -0
  38. package/dist/components/settings-list.d.ts +50 -0
  39. package/dist/components/settings-list.d.ts.map +1 -0
  40. package/dist/components/settings-list.js +177 -0
  41. package/dist/components/settings-list.js.map +1 -0
  42. package/dist/components/spacer.d.ts +12 -0
  43. package/dist/components/spacer.d.ts.map +1 -0
  44. package/dist/components/spacer.js +22 -0
  45. package/dist/components/spacer.js.map +1 -0
  46. package/dist/components/text.d.ts +19 -0
  47. package/dist/components/text.d.ts.map +1 -0
  48. package/dist/components/text.js +81 -0
  49. package/dist/components/text.js.map +1 -0
  50. package/dist/components/truncated-text.d.ts +13 -0
  51. package/dist/components/truncated-text.d.ts.map +1 -0
  52. package/dist/components/truncated-text.js +48 -0
  53. package/dist/components/truncated-text.js.map +1 -0
  54. package/dist/editor-component.d.ts +39 -0
  55. package/dist/editor-component.d.ts.map +1 -0
  56. package/dist/editor-component.js +2 -0
  57. package/dist/editor-component.js.map +1 -0
  58. package/dist/fuzzy.d.ts +16 -0
  59. package/dist/fuzzy.d.ts.map +1 -0
  60. package/dist/fuzzy.js +180 -0
  61. package/dist/fuzzy.js.map +1 -0
  62. package/dist/index.d.ts +25 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +35 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/keybindings.d.ts +193 -0
  67. package/dist/keybindings.d.ts.map +1 -0
  68. package/dist/keybindings.js +172 -0
  69. package/dist/keybindings.js.map +1 -0
  70. package/dist/keys.d.ts +184 -0
  71. package/dist/keys.d.ts.map +1 -0
  72. package/dist/keys.js +1174 -0
  73. package/dist/keys.js.map +1 -0
  74. package/dist/kill-ring.d.ts +28 -0
  75. package/dist/kill-ring.d.ts.map +1 -0
  76. package/dist/kill-ring.js +46 -0
  77. package/dist/kill-ring.js.map +1 -0
  78. package/dist/mux.d.ts +4 -0
  79. package/dist/mux.d.ts.map +1 -0
  80. package/dist/mux.js +10 -0
  81. package/dist/mux.js.map +1 -0
  82. package/dist/native-modifiers.d.ts +3 -0
  83. package/dist/native-modifiers.d.ts.map +1 -0
  84. package/dist/native-modifiers.js +53 -0
  85. package/dist/native-modifiers.js.map +1 -0
  86. package/dist/slash-command-autocomplete.d.ts +3 -0
  87. package/dist/slash-command-autocomplete.d.ts.map +1 -0
  88. package/dist/slash-command-autocomplete.js +38 -0
  89. package/dist/slash-command-autocomplete.js.map +1 -0
  90. package/dist/stdin-buffer.d.ts +51 -0
  91. package/dist/stdin-buffer.d.ts.map +1 -0
  92. package/dist/stdin-buffer.js +366 -0
  93. package/dist/stdin-buffer.js.map +1 -0
  94. package/dist/terminal-colors.d.ts +10 -0
  95. package/dist/terminal-colors.d.ts.map +1 -0
  96. package/dist/terminal-colors.js +59 -0
  97. package/dist/terminal-colors.js.map +1 -0
  98. package/dist/terminal-image.d.ts +88 -0
  99. package/dist/terminal-image.d.ts.map +1 -0
  100. package/dist/terminal-image.js +358 -0
  101. package/dist/terminal-image.js.map +1 -0
  102. package/dist/terminal-text.d.ts +4 -0
  103. package/dist/terminal-text.d.ts.map +1 -0
  104. package/dist/terminal-text.js +18 -0
  105. package/dist/terminal-text.js.map +1 -0
  106. package/dist/terminal.d.ts +128 -0
  107. package/dist/terminal.d.ts.map +1 -0
  108. package/dist/terminal.js +493 -0
  109. package/dist/terminal.js.map +1 -0
  110. package/dist/tui.d.ts +325 -0
  111. package/dist/tui.d.ts.map +1 -0
  112. package/dist/tui.js +1955 -0
  113. package/dist/tui.js.map +1 -0
  114. package/dist/undo-stack.d.ts +17 -0
  115. package/dist/undo-stack.d.ts.map +1 -0
  116. package/dist/undo-stack.js +27 -0
  117. package/dist/undo-stack.js.map +1 -0
  118. package/dist/utils.d.ts +91 -0
  119. package/dist/utils.d.ts.map +1 -0
  120. package/dist/utils.js +1173 -0
  121. package/dist/utils.js.map +1 -0
  122. package/dist/word-navigation.d.ts +25 -0
  123. package/dist/word-navigation.d.ts.map +1 -0
  124. package/dist/word-navigation.js +96 -0
  125. package/dist/word-navigation.js.map +1 -0
  126. package/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  127. package/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  128. package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  129. package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  130. package/package.json +48 -0
@@ -0,0 +1,646 @@
1
+ import { spawn } from "child_process";
2
+ import { readdirSync, statSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { basename, dirname, join } from "path";
5
+ import { getSlashCommandSuggestions } from "./slash-command-autocomplete.js";
6
+ const PATH_DELIMITERS = new Set([" ", "\t", '"', "'", "="]);
7
+ function toDisplayPath(value) {
8
+ return value.replace(/\\/g, "/");
9
+ }
10
+ function escapeRegex(value) {
11
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12
+ }
13
+ function buildFdPathQuery(query) {
14
+ const normalized = toDisplayPath(query);
15
+ if (!normalized.includes("/")) {
16
+ return normalized;
17
+ }
18
+ const hasTrailingSeparator = normalized.endsWith("/");
19
+ const trimmed = normalized.replace(/^\/+|\/+$/g, "");
20
+ if (!trimmed) {
21
+ return normalized;
22
+ }
23
+ const separatorPattern = "[\\\\/]";
24
+ const segments = trimmed
25
+ .split("/")
26
+ .filter(Boolean)
27
+ .map((segment) => escapeRegex(segment));
28
+ if (segments.length === 0) {
29
+ return normalized;
30
+ }
31
+ let pattern = segments.join(separatorPattern);
32
+ if (hasTrailingSeparator) {
33
+ pattern += separatorPattern;
34
+ }
35
+ return pattern;
36
+ }
37
+ function findLastDelimiter(text) {
38
+ for (let i = text.length - 1; i >= 0; i -= 1) {
39
+ if (PATH_DELIMITERS.has(text[i] ?? "")) {
40
+ return i;
41
+ }
42
+ }
43
+ return -1;
44
+ }
45
+ function findUnclosedQuoteStart(text) {
46
+ let inQuotes = false;
47
+ let quoteStart = -1;
48
+ for (let i = 0; i < text.length; i += 1) {
49
+ if (text[i] === '"') {
50
+ inQuotes = !inQuotes;
51
+ if (inQuotes) {
52
+ quoteStart = i;
53
+ }
54
+ }
55
+ }
56
+ return inQuotes ? quoteStart : null;
57
+ }
58
+ function isTokenStart(text, index) {
59
+ return index === 0 || PATH_DELIMITERS.has(text[index - 1] ?? "");
60
+ }
61
+ function extractQuotedPrefix(text) {
62
+ const quoteStart = findUnclosedQuoteStart(text);
63
+ if (quoteStart === null) {
64
+ return null;
65
+ }
66
+ if (quoteStart > 0 && text[quoteStart - 1] === "@") {
67
+ if (!isTokenStart(text, quoteStart - 1)) {
68
+ return null;
69
+ }
70
+ return text.slice(quoteStart - 1);
71
+ }
72
+ if (!isTokenStart(text, quoteStart)) {
73
+ return null;
74
+ }
75
+ return text.slice(quoteStart);
76
+ }
77
+ function parsePathPrefix(prefix) {
78
+ if (prefix.startsWith('@"')) {
79
+ return { rawPrefix: prefix.slice(2), isAtPrefix: true, isQuotedPrefix: true };
80
+ }
81
+ if (prefix.startsWith('"')) {
82
+ return { rawPrefix: prefix.slice(1), isAtPrefix: false, isQuotedPrefix: true };
83
+ }
84
+ if (prefix.startsWith("@")) {
85
+ return { rawPrefix: prefix.slice(1), isAtPrefix: true, isQuotedPrefix: false };
86
+ }
87
+ return { rawPrefix: prefix, isAtPrefix: false, isQuotedPrefix: false };
88
+ }
89
+ function buildCompletionValue(path, options) {
90
+ const needsQuotes = options.isQuotedPrefix || path.includes(" ");
91
+ const prefix = options.isAtPrefix ? "@" : "";
92
+ if (!needsQuotes) {
93
+ return `${prefix}${path}`;
94
+ }
95
+ const openQuote = `${prefix}"`;
96
+ const closeQuote = '"';
97
+ return `${openQuote}${path}${closeQuote}`;
98
+ }
99
+ // Use fd to walk directory tree (fast, respects .gitignore)
100
+ async function walkDirectoryWithFd(baseDir, fdPath, query, maxResults, signal) {
101
+ const args = [
102
+ "--base-directory",
103
+ baseDir,
104
+ "--max-results",
105
+ String(maxResults),
106
+ "--type",
107
+ "f",
108
+ "--type",
109
+ "d",
110
+ "--follow",
111
+ "--hidden",
112
+ "--exclude",
113
+ ".git",
114
+ "--exclude",
115
+ ".git/*",
116
+ "--exclude",
117
+ ".git/**",
118
+ ];
119
+ if (toDisplayPath(query).includes("/")) {
120
+ args.push("--full-path");
121
+ }
122
+ if (query) {
123
+ args.push(buildFdPathQuery(query));
124
+ }
125
+ return await new Promise((resolve) => {
126
+ if (signal.aborted) {
127
+ resolve([]);
128
+ return;
129
+ }
130
+ const child = spawn(fdPath, args, {
131
+ stdio: ["ignore", "pipe", "pipe"],
132
+ });
133
+ let stdout = "";
134
+ let resolved = false;
135
+ const finish = (results) => {
136
+ if (resolved)
137
+ return;
138
+ resolved = true;
139
+ signal.removeEventListener("abort", onAbort);
140
+ resolve(results);
141
+ };
142
+ const onAbort = () => {
143
+ if (child.exitCode === null) {
144
+ child.kill("SIGKILL");
145
+ }
146
+ };
147
+ signal.addEventListener("abort", onAbort, { once: true });
148
+ child.stdout.setEncoding("utf-8");
149
+ child.stdout.on("data", (chunk) => {
150
+ stdout += chunk;
151
+ });
152
+ child.on("error", () => {
153
+ finish([]);
154
+ });
155
+ child.on("close", (code) => {
156
+ if (signal.aborted || code !== 0 || !stdout) {
157
+ finish([]);
158
+ return;
159
+ }
160
+ const lines = stdout.trim().split("\n").filter(Boolean);
161
+ const results = [];
162
+ for (const line of lines) {
163
+ const displayLine = toDisplayPath(line);
164
+ const hasTrailingSeparator = displayLine.endsWith("/");
165
+ const normalizedPath = hasTrailingSeparator ? displayLine.slice(0, -1) : displayLine;
166
+ if (normalizedPath === ".git" || normalizedPath.startsWith(".git/") || normalizedPath.includes("/.git/")) {
167
+ continue;
168
+ }
169
+ results.push({
170
+ path: displayLine,
171
+ isDirectory: hasTrailingSeparator,
172
+ });
173
+ }
174
+ finish(results);
175
+ });
176
+ });
177
+ }
178
+ // Combined provider that handles both slash commands and file paths
179
+ export class CombinedAutocompleteProvider {
180
+ constructor(commands = [], basePath, fdPath = null) {
181
+ this.commands = commands;
182
+ this.basePath = basePath;
183
+ this.fdPath = fdPath;
184
+ }
185
+ async getSuggestions(lines, cursorLine, cursorCol, options) {
186
+ const currentLine = lines[cursorLine] || "";
187
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
188
+ const atPrefix = this.extractAtPrefix(textBeforeCursor);
189
+ if (atPrefix) {
190
+ const { rawPrefix, isQuotedPrefix } = parsePathPrefix(atPrefix);
191
+ const suggestions = await this.getFuzzyFileSuggestions(rawPrefix, {
192
+ isQuotedPrefix,
193
+ signal: options.signal,
194
+ });
195
+ if (suggestions.length === 0)
196
+ return null;
197
+ return {
198
+ items: suggestions,
199
+ prefix: atPrefix,
200
+ };
201
+ }
202
+ if (!options.force && textBeforeCursor.startsWith("/")) {
203
+ const spaceIndex = textBeforeCursor.indexOf(" ");
204
+ if (spaceIndex === -1) {
205
+ const prefix = textBeforeCursor.slice(1);
206
+ const filtered = getSlashCommandSuggestions(this.commands, prefix);
207
+ if (filtered.length === 0)
208
+ return null;
209
+ return {
210
+ items: filtered,
211
+ prefix: textBeforeCursor,
212
+ };
213
+ }
214
+ const tokenStart = textBeforeCursor.search(/\S+$/);
215
+ const currentToken = tokenStart === -1 ? "" : textBeforeCursor.slice(tokenStart);
216
+ if (currentToken.startsWith("/skill:") &&
217
+ this.isLeadingKnownSkillCommandRun(textBeforeCursor.slice(0, tokenStart))) {
218
+ const skillCommands = this.commands.filter((command) => {
219
+ const name = "name" in command ? command.name : command.value;
220
+ return name.startsWith("skill:");
221
+ });
222
+ const filtered = getSlashCommandSuggestions(skillCommands, currentToken.slice(1));
223
+ if (filtered.length === 0)
224
+ return null;
225
+ return {
226
+ items: filtered,
227
+ prefix: currentToken,
228
+ };
229
+ }
230
+ const commandName = textBeforeCursor.slice(1, spaceIndex);
231
+ const argumentText = textBeforeCursor.slice(spaceIndex + 1);
232
+ const command = this.commands.find((cmd) => {
233
+ const name = "name" in cmd ? cmd.name : cmd.value;
234
+ return name === commandName;
235
+ });
236
+ if (!command || !("getArgumentCompletions" in command) || !command.getArgumentCompletions) {
237
+ return null;
238
+ }
239
+ const argumentSuggestions = await command.getArgumentCompletions(argumentText);
240
+ if (!Array.isArray(argumentSuggestions) || argumentSuggestions.length === 0) {
241
+ return null;
242
+ }
243
+ return {
244
+ items: argumentSuggestions,
245
+ prefix: argumentText,
246
+ };
247
+ }
248
+ const pathMatch = this.extractPathPrefix(textBeforeCursor, options.force ?? false);
249
+ if (pathMatch === null) {
250
+ return null;
251
+ }
252
+ const suggestions = this.getFileSuggestions(pathMatch);
253
+ if (suggestions.length === 0)
254
+ return null;
255
+ return {
256
+ items: suggestions,
257
+ prefix: pathMatch,
258
+ };
259
+ }
260
+ applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
261
+ const currentLine = lines[cursorLine] || "";
262
+ const beforePrefix = currentLine.slice(0, cursorCol - prefix.length);
263
+ const afterCursor = currentLine.slice(cursorCol);
264
+ const isQuotedPrefix = prefix.startsWith('"') || prefix.startsWith('@"');
265
+ const hasLeadingQuoteAfterCursor = afterCursor.startsWith('"');
266
+ const hasTrailingQuoteInItem = item.value.endsWith('"');
267
+ const adjustedAfterCursor = isQuotedPrefix && hasTrailingQuoteInItem && hasLeadingQuoteAfterCursor ? afterCursor.slice(1) : afterCursor;
268
+ // Check if we're completing a slash command (prefix starts with "/" but NOT a file path).
269
+ // Skill commands may also appear after an already-known leading skill command.
270
+ const isSlashCommand = prefix.startsWith("/") &&
271
+ !prefix.slice(1).includes("/") &&
272
+ (beforePrefix.trim() === "" ||
273
+ (prefix.startsWith("/skill:") && this.isLeadingKnownSkillCommandRun(beforePrefix)));
274
+ if (isSlashCommand) {
275
+ // This is a command name completion
276
+ const newLine = `${beforePrefix}/${item.value} ${adjustedAfterCursor}`;
277
+ const newLines = [...lines];
278
+ newLines[cursorLine] = newLine;
279
+ return {
280
+ lines: newLines,
281
+ cursorLine,
282
+ cursorCol: beforePrefix.length + item.value.length + 2, // +2 for "/" and space
283
+ };
284
+ }
285
+ // Check if we're completing a file attachment (prefix starts with "@")
286
+ if (prefix.startsWith("@")) {
287
+ // This is a file attachment completion
288
+ // Don't add space after directories so user can continue autocompleting
289
+ const isDirectory = item.label.endsWith("/");
290
+ const suffix = isDirectory ? "" : " ";
291
+ const newLine = `${beforePrefix + item.value}${suffix}${adjustedAfterCursor}`;
292
+ const newLines = [...lines];
293
+ newLines[cursorLine] = newLine;
294
+ const hasTrailingQuote = item.value.endsWith('"');
295
+ const cursorOffset = isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
296
+ return {
297
+ lines: newLines,
298
+ cursorLine,
299
+ cursorCol: beforePrefix.length + cursorOffset + suffix.length,
300
+ };
301
+ }
302
+ // Check if we're in a slash command context (beforePrefix contains "/command ")
303
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
304
+ if (textBeforeCursor.includes("/") && textBeforeCursor.includes(" ")) {
305
+ // This is likely a command argument completion
306
+ const newLine = beforePrefix + item.value + adjustedAfterCursor;
307
+ const newLines = [...lines];
308
+ newLines[cursorLine] = newLine;
309
+ const isDirectory = item.label.endsWith("/");
310
+ const hasTrailingQuote = item.value.endsWith('"');
311
+ const cursorOffset = isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
312
+ return {
313
+ lines: newLines,
314
+ cursorLine,
315
+ cursorCol: beforePrefix.length + cursorOffset,
316
+ };
317
+ }
318
+ // For file paths, complete the path
319
+ const newLine = beforePrefix + item.value + adjustedAfterCursor;
320
+ const newLines = [...lines];
321
+ newLines[cursorLine] = newLine;
322
+ const isDirectory = item.label.endsWith("/");
323
+ const hasTrailingQuote = item.value.endsWith('"');
324
+ const cursorOffset = isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
325
+ return {
326
+ lines: newLines,
327
+ cursorLine,
328
+ cursorCol: beforePrefix.length + cursorOffset,
329
+ };
330
+ }
331
+ isLeadingKnownSkillCommandRun(text) {
332
+ const tokens = text.trim().split(/\s+/);
333
+ return (tokens.length > 0 &&
334
+ tokens.every((token) => {
335
+ if (!token.startsWith("/skill:"))
336
+ return false;
337
+ const commandName = token.slice(1);
338
+ return this.commands.some((command) => {
339
+ const name = "name" in command ? command.name : command.value;
340
+ return name === commandName;
341
+ });
342
+ }));
343
+ }
344
+ // Extract @ prefix for fuzzy file suggestions
345
+ extractAtPrefix(text) {
346
+ const quotedPrefix = extractQuotedPrefix(text);
347
+ if (quotedPrefix?.startsWith('@"')) {
348
+ return quotedPrefix;
349
+ }
350
+ const lastDelimiterIndex = findLastDelimiter(text);
351
+ const tokenStart = lastDelimiterIndex === -1 ? 0 : lastDelimiterIndex + 1;
352
+ if (text[tokenStart] === "@") {
353
+ return text.slice(tokenStart);
354
+ }
355
+ return null;
356
+ }
357
+ // Extract a path-like prefix from the text before cursor
358
+ extractPathPrefix(text, forceExtract = false) {
359
+ const quotedPrefix = extractQuotedPrefix(text);
360
+ if (quotedPrefix) {
361
+ return quotedPrefix;
362
+ }
363
+ const lastDelimiterIndex = findLastDelimiter(text);
364
+ const pathPrefix = lastDelimiterIndex === -1 ? text : text.slice(lastDelimiterIndex + 1);
365
+ // For forced extraction (Tab key), always return something
366
+ if (forceExtract) {
367
+ return pathPrefix;
368
+ }
369
+ // For natural triggers, return if it looks like a path, ends with /, starts with ~/, .
370
+ // Only return empty string if the text looks like it's starting a path context
371
+ if (pathPrefix.includes("/") || pathPrefix.startsWith(".") || pathPrefix.startsWith("~/")) {
372
+ return pathPrefix;
373
+ }
374
+ // Return empty string only after a space (not for completely empty text)
375
+ // Empty text should not trigger file suggestions - that's for forced Tab completion
376
+ if (pathPrefix === "" && text.endsWith(" ")) {
377
+ return pathPrefix;
378
+ }
379
+ return null;
380
+ }
381
+ // Expand home directory (~/) to actual home path
382
+ expandHomePath(path) {
383
+ if (path.startsWith("~/")) {
384
+ const expandedPath = join(homedir(), path.slice(2));
385
+ // Preserve trailing slash if original path had one
386
+ return path.endsWith("/") && !expandedPath.endsWith("/") ? `${expandedPath}/` : expandedPath;
387
+ }
388
+ else if (path === "~") {
389
+ return homedir();
390
+ }
391
+ return path;
392
+ }
393
+ resolveScopedFuzzyQuery(rawQuery) {
394
+ const normalizedQuery = toDisplayPath(rawQuery);
395
+ const slashIndex = normalizedQuery.lastIndexOf("/");
396
+ if (slashIndex === -1) {
397
+ return null;
398
+ }
399
+ const displayBase = normalizedQuery.slice(0, slashIndex + 1);
400
+ const query = normalizedQuery.slice(slashIndex + 1);
401
+ let baseDir;
402
+ if (displayBase.startsWith("~/")) {
403
+ baseDir = this.expandHomePath(displayBase);
404
+ }
405
+ else if (displayBase.startsWith("/")) {
406
+ baseDir = displayBase;
407
+ }
408
+ else {
409
+ baseDir = join(this.basePath, displayBase);
410
+ }
411
+ try {
412
+ if (!statSync(baseDir).isDirectory()) {
413
+ return null;
414
+ }
415
+ }
416
+ catch {
417
+ return null;
418
+ }
419
+ return { baseDir, query, displayBase };
420
+ }
421
+ scopedPathForDisplay(displayBase, relativePath) {
422
+ const normalizedRelativePath = toDisplayPath(relativePath);
423
+ if (displayBase === "/") {
424
+ return `/${normalizedRelativePath}`;
425
+ }
426
+ return `${toDisplayPath(displayBase)}${normalizedRelativePath}`;
427
+ }
428
+ // Get file/directory suggestions for a given path prefix
429
+ getFileSuggestions(prefix) {
430
+ try {
431
+ let searchDir;
432
+ let searchPrefix;
433
+ const { rawPrefix, isAtPrefix, isQuotedPrefix } = parsePathPrefix(prefix);
434
+ let expandedPrefix = rawPrefix;
435
+ // Handle home directory expansion
436
+ if (expandedPrefix.startsWith("~")) {
437
+ expandedPrefix = this.expandHomePath(expandedPrefix);
438
+ }
439
+ const isRootPrefix = rawPrefix === "" ||
440
+ rawPrefix === "./" ||
441
+ rawPrefix === "../" ||
442
+ rawPrefix === "~" ||
443
+ rawPrefix === "~/" ||
444
+ rawPrefix === "/" ||
445
+ (isAtPrefix && rawPrefix === "");
446
+ if (isRootPrefix) {
447
+ // Complete from specified position
448
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
449
+ searchDir = expandedPrefix;
450
+ }
451
+ else {
452
+ searchDir = join(this.basePath, expandedPrefix);
453
+ }
454
+ searchPrefix = "";
455
+ }
456
+ else if (rawPrefix.endsWith("/")) {
457
+ // If prefix ends with /, show contents of that directory
458
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
459
+ searchDir = expandedPrefix;
460
+ }
461
+ else {
462
+ searchDir = join(this.basePath, expandedPrefix);
463
+ }
464
+ searchPrefix = "";
465
+ }
466
+ else {
467
+ // Split into directory and file prefix
468
+ const dir = dirname(expandedPrefix);
469
+ const file = basename(expandedPrefix);
470
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
471
+ searchDir = dir;
472
+ }
473
+ else {
474
+ searchDir = join(this.basePath, dir);
475
+ }
476
+ searchPrefix = file;
477
+ }
478
+ const entries = readdirSync(searchDir, { withFileTypes: true });
479
+ const suggestions = [];
480
+ for (const entry of entries) {
481
+ if (!entry.name.toLowerCase().startsWith(searchPrefix.toLowerCase())) {
482
+ continue;
483
+ }
484
+ // Check if entry is a directory (or a symlink pointing to a directory)
485
+ let isDirectory = entry.isDirectory();
486
+ if (!isDirectory && entry.isSymbolicLink()) {
487
+ try {
488
+ const fullPath = join(searchDir, entry.name);
489
+ isDirectory = statSync(fullPath).isDirectory();
490
+ }
491
+ catch {
492
+ // Broken symlink or permission error - treat as file
493
+ }
494
+ }
495
+ let relativePath;
496
+ const name = entry.name;
497
+ const displayPrefix = rawPrefix;
498
+ if (displayPrefix.endsWith("/")) {
499
+ // If prefix ends with /, append entry to the prefix
500
+ relativePath = displayPrefix + name;
501
+ }
502
+ else if (displayPrefix.includes("/") || displayPrefix.includes("\\")) {
503
+ // Preserve ~/ format for home directory paths
504
+ if (displayPrefix.startsWith("~/")) {
505
+ const homeRelativeDir = displayPrefix.slice(2); // Remove ~/
506
+ const dir = dirname(homeRelativeDir);
507
+ relativePath = `~/${dir === "." ? name : join(dir, name)}`;
508
+ }
509
+ else if (displayPrefix.startsWith("/")) {
510
+ // Absolute path - construct properly
511
+ const dir = dirname(displayPrefix);
512
+ if (dir === "/") {
513
+ relativePath = `/${name}`;
514
+ }
515
+ else {
516
+ relativePath = `${dir}/${name}`;
517
+ }
518
+ }
519
+ else {
520
+ relativePath = join(dirname(displayPrefix), name);
521
+ // path.join normalizes away ./ prefix, preserve it
522
+ if (displayPrefix.startsWith("./") && !relativePath.startsWith("./")) {
523
+ relativePath = `./${relativePath}`;
524
+ }
525
+ }
526
+ }
527
+ else {
528
+ // For standalone entries, preserve ~/ if original prefix was ~/
529
+ if (displayPrefix.startsWith("~")) {
530
+ relativePath = `~/${name}`;
531
+ }
532
+ else {
533
+ relativePath = name;
534
+ }
535
+ }
536
+ relativePath = toDisplayPath(relativePath);
537
+ const pathValue = isDirectory ? `${relativePath}/` : relativePath;
538
+ const value = buildCompletionValue(pathValue, {
539
+ isDirectory,
540
+ isAtPrefix,
541
+ isQuotedPrefix,
542
+ });
543
+ suggestions.push({
544
+ value,
545
+ label: name + (isDirectory ? "/" : ""),
546
+ });
547
+ }
548
+ // Sort directories first, then alphabetically
549
+ suggestions.sort((a, b) => {
550
+ const aIsDir = a.value.endsWith("/");
551
+ const bIsDir = b.value.endsWith("/");
552
+ if (aIsDir && !bIsDir)
553
+ return -1;
554
+ if (!aIsDir && bIsDir)
555
+ return 1;
556
+ return a.label.localeCompare(b.label);
557
+ });
558
+ return suggestions;
559
+ }
560
+ catch (_e) {
561
+ // Directory doesn't exist or not accessible
562
+ return [];
563
+ }
564
+ }
565
+ // Score an entry against the query (higher = better match)
566
+ // isDirectory adds bonus to prioritize folders
567
+ scoreEntry(filePath, query, isDirectory) {
568
+ const fileName = basename(filePath);
569
+ const lowerFileName = fileName.toLowerCase();
570
+ const lowerQuery = query.toLowerCase();
571
+ let score = 0;
572
+ // Exact filename match (highest)
573
+ if (lowerFileName === lowerQuery)
574
+ score = 100;
575
+ // Filename starts with query
576
+ else if (lowerFileName.startsWith(lowerQuery))
577
+ score = 80;
578
+ // Substring match in filename
579
+ else if (lowerFileName.includes(lowerQuery))
580
+ score = 50;
581
+ // Substring match in full path
582
+ else if (filePath.toLowerCase().includes(lowerQuery))
583
+ score = 30;
584
+ // Directories get a bonus to appear first
585
+ if (isDirectory && score > 0)
586
+ score += 10;
587
+ return score;
588
+ }
589
+ // Fuzzy file search using fd (fast, respects .gitignore)
590
+ async getFuzzyFileSuggestions(query, options) {
591
+ if (!this.fdPath || options.signal.aborted) {
592
+ return [];
593
+ }
594
+ try {
595
+ const scopedQuery = this.resolveScopedFuzzyQuery(query);
596
+ const fdBaseDir = scopedQuery?.baseDir ?? this.basePath;
597
+ const fdQuery = scopedQuery?.query ?? query;
598
+ const entries = await walkDirectoryWithFd(fdBaseDir, this.fdPath, fdQuery, 100, options.signal);
599
+ if (options.signal.aborted) {
600
+ return [];
601
+ }
602
+ const scoredEntries = entries
603
+ .map((entry) => ({
604
+ ...entry,
605
+ score: fdQuery ? this.scoreEntry(entry.path, fdQuery, entry.isDirectory) : 1,
606
+ }))
607
+ .filter((entry) => entry.score > 0);
608
+ scoredEntries.sort((a, b) => b.score - a.score);
609
+ const topEntries = scoredEntries.slice(0, 20);
610
+ const suggestions = [];
611
+ for (const { path: entryPath, isDirectory } of topEntries) {
612
+ const pathWithoutSlash = isDirectory ? entryPath.slice(0, -1) : entryPath;
613
+ const displayPath = scopedQuery
614
+ ? this.scopedPathForDisplay(scopedQuery.displayBase, pathWithoutSlash)
615
+ : pathWithoutSlash;
616
+ const entryName = basename(pathWithoutSlash);
617
+ const completionPath = isDirectory ? `${displayPath}/` : displayPath;
618
+ const value = buildCompletionValue(completionPath, {
619
+ isDirectory,
620
+ isAtPrefix: true,
621
+ isQuotedPrefix: options.isQuotedPrefix,
622
+ });
623
+ suggestions.push({
624
+ value,
625
+ label: entryName + (isDirectory ? "/" : ""),
626
+ description: displayPath,
627
+ });
628
+ }
629
+ return suggestions;
630
+ }
631
+ catch {
632
+ return [];
633
+ }
634
+ }
635
+ // Check if we should trigger file completion (called on Tab key)
636
+ shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
637
+ const currentLine = lines[cursorLine] || "";
638
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
639
+ // Don't trigger if we're typing a slash command at the start of the line
640
+ if (textBeforeCursor.trim().startsWith("/") && !textBeforeCursor.trim().includes(" ")) {
641
+ return false;
642
+ }
643
+ return true;
644
+ }
645
+ }
646
+ //# sourceMappingURL=autocomplete.js.map