@dungle-scrubs/tallow 0.8.21 → 0.8.23

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 (217) hide show
  1. package/dist/cli.js +35 -4
  2. package/dist/cli.js.map +1 -1
  3. package/dist/config.d.ts +1 -1
  4. package/dist/config.js +1 -1
  5. package/dist/interactive-mode-patch.d.ts +2 -0
  6. package/dist/interactive-mode-patch.d.ts.map +1 -1
  7. package/dist/interactive-mode-patch.js +82 -0
  8. package/dist/interactive-mode-patch.js.map +1 -1
  9. package/dist/sdk.d.ts +17 -0
  10. package/dist/sdk.d.ts.map +1 -1
  11. package/dist/sdk.js +68 -1
  12. package/dist/sdk.js.map +1 -1
  13. package/dist/workspace-transition-relay.d.ts +40 -7
  14. package/dist/workspace-transition-relay.d.ts.map +1 -1
  15. package/dist/workspace-transition-relay.js +81 -16
  16. package/dist/workspace-transition-relay.js.map +1 -1
  17. package/extensions/__integration__/background-task-widget-ownership.test.ts +216 -0
  18. package/extensions/__integration__/claude-hooks-compat.test.ts +156 -0
  19. package/extensions/__integration__/slash-command-bridge.test.ts +169 -23
  20. package/extensions/_shared/atomic-write.ts +1 -1
  21. package/extensions/_shared/bordered-box.ts +102 -0
  22. package/extensions/_shared/interop-events.ts +5 -0
  23. package/extensions/_shared/pid-registry.ts +1 -1
  24. package/extensions/agent-commands-tool/index.ts +4 -1
  25. package/extensions/background-task-tool/__tests__/lifecycle.test.ts +50 -25
  26. package/extensions/background-task-tool/index.ts +139 -221
  27. package/extensions/bash-tool-enhanced/index.ts +1 -75
  28. package/extensions/cd-tool/index.ts +2 -2
  29. package/extensions/context-fork/spawn.ts +4 -1
  30. package/extensions/health/index.ts +6 -6
  31. package/extensions/hooks/__tests__/claude-compat.test.ts +35 -0
  32. package/extensions/hooks/__tests__/subprocess-hardening.test.ts +73 -0
  33. package/extensions/hooks/index.ts +27 -4
  34. package/extensions/loop/__tests__/loop.test.ts +168 -4
  35. package/extensions/loop/extension.json +6 -5
  36. package/extensions/loop/index.ts +242 -31
  37. package/extensions/plan-mode-tool/__tests__/agent-end-execution.test.ts +373 -0
  38. package/extensions/plan-mode-tool/index.ts +103 -41
  39. package/extensions/prompt-suggestions/__tests__/editor-compatibility.test.ts +42 -0
  40. package/extensions/prompt-suggestions/index.ts +41 -6
  41. package/extensions/slash-command-bridge/__tests__/slash-command-bridge.test.ts +267 -671
  42. package/extensions/slash-command-bridge/extension.json +1 -1
  43. package/extensions/slash-command-bridge/index.ts +230 -116
  44. package/extensions/subagent-tool/index.ts +2 -2
  45. package/extensions/subagent-tool/process.ts +4 -5
  46. package/extensions/tasks/commands/register-tasks-extension.ts +41 -0
  47. package/extensions/teams-tool/__tests__/peer-messaging.test.ts +29 -24
  48. package/extensions/teams-tool/dashboard.ts +3 -5
  49. package/extensions/teams-tool/dispatch/auto-dispatch.ts +18 -1
  50. package/extensions/teams-tool/tools/teammate-tools.ts +9 -6
  51. package/extensions/wezterm-pane-control/__tests__/index.test.ts +88 -4
  52. package/extensions/wezterm-pane-control/index.ts +113 -8
  53. package/package.json +6 -4
  54. package/packages/tallow-tui/README.md +51 -0
  55. package/packages/tallow-tui/dist/autocomplete.d.ts +48 -0
  56. package/packages/tallow-tui/dist/autocomplete.d.ts.map +1 -0
  57. package/packages/tallow-tui/dist/autocomplete.js +564 -0
  58. package/packages/tallow-tui/dist/autocomplete.js.map +1 -0
  59. package/packages/tallow-tui/dist/border-styles.d.ts +32 -0
  60. package/packages/tallow-tui/dist/border-styles.d.ts.map +1 -0
  61. package/packages/tallow-tui/dist/border-styles.js +46 -0
  62. package/packages/tallow-tui/dist/border-styles.js.map +1 -0
  63. package/packages/tallow-tui/dist/components/bordered-box.d.ts +52 -0
  64. package/packages/tallow-tui/dist/components/bordered-box.d.ts.map +1 -0
  65. package/packages/tallow-tui/dist/components/bordered-box.js +89 -0
  66. package/packages/tallow-tui/dist/components/bordered-box.js.map +1 -0
  67. package/packages/tallow-tui/dist/components/box.d.ts +22 -0
  68. package/packages/tallow-tui/dist/components/box.d.ts.map +1 -0
  69. package/packages/tallow-tui/dist/components/box.js +104 -0
  70. package/packages/tallow-tui/dist/components/box.js.map +1 -0
  71. package/packages/tallow-tui/dist/components/cancellable-loader.d.ts +22 -0
  72. package/packages/tallow-tui/dist/components/cancellable-loader.d.ts.map +1 -0
  73. package/packages/tallow-tui/dist/components/cancellable-loader.js +35 -0
  74. package/packages/tallow-tui/dist/components/cancellable-loader.js.map +1 -0
  75. package/packages/tallow-tui/dist/components/editor.d.ts +240 -0
  76. package/packages/tallow-tui/dist/components/editor.d.ts.map +1 -0
  77. package/packages/tallow-tui/dist/components/editor.js +1766 -0
  78. package/packages/tallow-tui/dist/components/editor.js.map +1 -0
  79. package/packages/tallow-tui/dist/components/image.d.ts +126 -0
  80. package/packages/tallow-tui/dist/components/image.d.ts.map +1 -0
  81. package/packages/tallow-tui/dist/components/image.js +245 -0
  82. package/packages/tallow-tui/dist/components/image.js.map +1 -0
  83. package/packages/tallow-tui/dist/components/input.d.ts +37 -0
  84. package/packages/tallow-tui/dist/components/input.d.ts.map +1 -0
  85. package/packages/tallow-tui/dist/components/input.js +439 -0
  86. package/packages/tallow-tui/dist/components/input.js.map +1 -0
  87. package/packages/tallow-tui/dist/components/loader.d.ts +88 -0
  88. package/packages/tallow-tui/dist/components/loader.d.ts.map +1 -0
  89. package/packages/tallow-tui/dist/components/loader.js +146 -0
  90. package/packages/tallow-tui/dist/components/loader.js.map +1 -0
  91. package/packages/tallow-tui/dist/components/markdown.d.ts +95 -0
  92. package/packages/tallow-tui/dist/components/markdown.d.ts.map +1 -0
  93. package/packages/tallow-tui/dist/components/markdown.js +633 -0
  94. package/packages/tallow-tui/dist/components/markdown.js.map +1 -0
  95. package/packages/tallow-tui/dist/components/select-list.d.ts +32 -0
  96. package/packages/tallow-tui/dist/components/select-list.d.ts.map +1 -0
  97. package/packages/tallow-tui/dist/components/select-list.js +156 -0
  98. package/packages/tallow-tui/dist/components/select-list.js.map +1 -0
  99. package/packages/tallow-tui/dist/components/settings-list.d.ts +50 -0
  100. package/packages/tallow-tui/dist/components/settings-list.d.ts.map +1 -0
  101. package/packages/tallow-tui/dist/components/settings-list.js +189 -0
  102. package/packages/tallow-tui/dist/components/settings-list.js.map +1 -0
  103. package/packages/tallow-tui/dist/components/spacer.d.ts +12 -0
  104. package/packages/tallow-tui/dist/components/spacer.d.ts.map +1 -0
  105. package/packages/tallow-tui/dist/components/spacer.js +23 -0
  106. package/packages/tallow-tui/dist/components/spacer.js.map +1 -0
  107. package/packages/tallow-tui/dist/components/text.d.ts +19 -0
  108. package/packages/tallow-tui/dist/components/text.d.ts.map +1 -0
  109. package/packages/tallow-tui/dist/components/text.js +91 -0
  110. package/packages/tallow-tui/dist/components/text.js.map +1 -0
  111. package/packages/tallow-tui/dist/components/truncated-text.d.ts +13 -0
  112. package/packages/tallow-tui/dist/components/truncated-text.d.ts.map +1 -0
  113. package/packages/tallow-tui/dist/components/truncated-text.js +51 -0
  114. package/packages/tallow-tui/dist/components/truncated-text.js.map +1 -0
  115. package/packages/tallow-tui/dist/editor-component.d.ts +50 -0
  116. package/packages/tallow-tui/dist/editor-component.d.ts.map +1 -0
  117. package/packages/tallow-tui/dist/editor-component.js +2 -0
  118. package/packages/tallow-tui/dist/editor-component.js.map +1 -0
  119. package/packages/tallow-tui/dist/fuzzy.d.ts +16 -0
  120. package/packages/tallow-tui/dist/fuzzy.d.ts.map +1 -0
  121. package/packages/tallow-tui/dist/fuzzy.js +107 -0
  122. package/packages/tallow-tui/dist/fuzzy.js.map +1 -0
  123. package/packages/tallow-tui/dist/index.d.ts +25 -0
  124. package/packages/tallow-tui/dist/index.d.ts.map +1 -0
  125. package/packages/tallow-tui/dist/index.js +35 -0
  126. package/packages/tallow-tui/dist/index.js.map +1 -0
  127. package/packages/tallow-tui/dist/keybindings.d.ts +39 -0
  128. package/packages/tallow-tui/dist/keybindings.d.ts.map +1 -0
  129. package/packages/tallow-tui/dist/keybindings.js +114 -0
  130. package/packages/tallow-tui/dist/keybindings.js.map +1 -0
  131. package/packages/tallow-tui/dist/keys.d.ts +168 -0
  132. package/packages/tallow-tui/dist/keys.d.ts.map +1 -0
  133. package/packages/tallow-tui/dist/keys.js +971 -0
  134. package/packages/tallow-tui/dist/keys.js.map +1 -0
  135. package/packages/tallow-tui/dist/kill-ring.d.ts +28 -0
  136. package/packages/tallow-tui/dist/kill-ring.d.ts.map +1 -0
  137. package/packages/tallow-tui/dist/kill-ring.js +44 -0
  138. package/packages/tallow-tui/dist/kill-ring.js.map +1 -0
  139. package/packages/tallow-tui/dist/stdin-buffer.d.ts +48 -0
  140. package/packages/tallow-tui/dist/stdin-buffer.d.ts.map +1 -0
  141. package/packages/tallow-tui/dist/stdin-buffer.js +317 -0
  142. package/packages/tallow-tui/dist/stdin-buffer.js.map +1 -0
  143. package/packages/tallow-tui/dist/terminal-image.d.ts +161 -0
  144. package/packages/tallow-tui/dist/terminal-image.d.ts.map +1 -0
  145. package/packages/tallow-tui/dist/terminal-image.js +460 -0
  146. package/packages/tallow-tui/dist/terminal-image.js.map +1 -0
  147. package/packages/tallow-tui/dist/terminal.d.ts +102 -0
  148. package/packages/tallow-tui/dist/terminal.d.ts.map +1 -0
  149. package/packages/tallow-tui/dist/terminal.js +263 -0
  150. package/packages/tallow-tui/dist/terminal.js.map +1 -0
  151. package/packages/tallow-tui/dist/test-utils/capability-env.d.ts +14 -0
  152. package/packages/tallow-tui/dist/test-utils/capability-env.d.ts.map +1 -0
  153. package/packages/tallow-tui/dist/test-utils/capability-env.js +55 -0
  154. package/packages/tallow-tui/dist/test-utils/capability-env.js.map +1 -0
  155. package/packages/tallow-tui/dist/tui.d.ts +239 -0
  156. package/packages/tallow-tui/dist/tui.d.ts.map +1 -0
  157. package/packages/tallow-tui/dist/tui.js +1058 -0
  158. package/packages/tallow-tui/dist/tui.js.map +1 -0
  159. package/packages/tallow-tui/dist/undo-stack.d.ts +17 -0
  160. package/packages/tallow-tui/dist/undo-stack.d.ts.map +1 -0
  161. package/packages/tallow-tui/dist/undo-stack.js +25 -0
  162. package/packages/tallow-tui/dist/undo-stack.js.map +1 -0
  163. package/packages/tallow-tui/dist/utils.d.ts +96 -0
  164. package/packages/tallow-tui/dist/utils.d.ts.map +1 -0
  165. package/packages/tallow-tui/dist/utils.js +843 -0
  166. package/packages/tallow-tui/dist/utils.js.map +1 -0
  167. package/packages/tallow-tui/package.json +24 -0
  168. package/packages/tallow-tui/src/__tests__/__snapshots__/render.test.ts.snap +121 -0
  169. package/packages/tallow-tui/src/__tests__/editor-border.test.ts +72 -0
  170. package/packages/tallow-tui/src/__tests__/editor-change-listener.test.ts +121 -0
  171. package/packages/tallow-tui/src/__tests__/editor-ghost-text.test.ts +112 -0
  172. package/packages/tallow-tui/src/__tests__/fuzzy.test.ts +91 -0
  173. package/packages/tallow-tui/src/__tests__/image-component.test.ts +113 -0
  174. package/packages/tallow-tui/src/__tests__/keys.test.ts +141 -0
  175. package/packages/tallow-tui/src/__tests__/render.test.ts +179 -0
  176. package/packages/tallow-tui/src/__tests__/stdin-buffer.test.ts +82 -0
  177. package/packages/tallow-tui/src/__tests__/terminal-image.test.ts +363 -0
  178. package/packages/tallow-tui/src/__tests__/tui-diff-regression.test.ts +454 -0
  179. package/packages/tallow-tui/src/__tests__/tui-render-scheduling.test.ts +256 -0
  180. package/packages/tallow-tui/src/__tests__/utils.test.ts +259 -0
  181. package/packages/tallow-tui/src/autocomplete.ts +716 -0
  182. package/packages/tallow-tui/src/border-styles.ts +60 -0
  183. package/packages/tallow-tui/src/components/bordered-box.ts +113 -0
  184. package/packages/tallow-tui/src/components/box.ts +137 -0
  185. package/packages/tallow-tui/src/components/cancellable-loader.ts +40 -0
  186. package/packages/tallow-tui/src/components/editor.ts +2143 -0
  187. package/packages/tallow-tui/src/components/image.ts +315 -0
  188. package/packages/tallow-tui/src/components/input.ts +522 -0
  189. package/packages/tallow-tui/src/components/loader.ts +187 -0
  190. package/packages/tallow-tui/src/components/markdown.ts +780 -0
  191. package/packages/tallow-tui/src/components/select-list.ts +197 -0
  192. package/packages/tallow-tui/src/components/settings-list.ts +264 -0
  193. package/packages/tallow-tui/src/components/spacer.ts +28 -0
  194. package/packages/tallow-tui/src/components/text.ts +113 -0
  195. package/packages/tallow-tui/src/components/truncated-text.ts +65 -0
  196. package/packages/tallow-tui/src/editor-component.ts +92 -0
  197. package/packages/tallow-tui/src/fuzzy.ts +133 -0
  198. package/packages/tallow-tui/src/index.ts +118 -0
  199. package/packages/tallow-tui/src/keybindings.ts +183 -0
  200. package/packages/tallow-tui/src/keys.ts +1189 -0
  201. package/packages/tallow-tui/src/kill-ring.ts +46 -0
  202. package/packages/tallow-tui/src/stdin-buffer.ts +386 -0
  203. package/packages/tallow-tui/src/terminal-image.ts +619 -0
  204. package/packages/tallow-tui/src/terminal.ts +350 -0
  205. package/packages/tallow-tui/src/test-utils/capability-env.ts +56 -0
  206. package/packages/tallow-tui/src/tui.ts +1336 -0
  207. package/packages/tallow-tui/src/undo-stack.ts +28 -0
  208. package/packages/tallow-tui/src/utils.ts +948 -0
  209. package/packages/tallow-tui/tsconfig.build.json +21 -0
  210. package/runtime/agent-runner.ts +20 -0
  211. package/runtime/atomic-write.ts +8 -0
  212. package/runtime/otel.ts +12 -0
  213. package/runtime/resolve-module.ts +23 -0
  214. package/runtime/runtime-path-provider.ts +12 -0
  215. package/runtime/runtime-provenance.ts +17 -0
  216. package/runtime/workspace-transition-relay.ts +21 -0
  217. package/runtime/workspace-transition.ts +29 -0
@@ -0,0 +1,716 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { readdirSync, statSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { basename, dirname, join } from "node:path";
5
+ import { fuzzyFilter } from "./fuzzy.js";
6
+
7
+ const PATH_DELIMITERS = new Set([" ", "\t", '"', "'", "="]);
8
+
9
+ function findLastDelimiter(text: string): number {
10
+ for (let i = text.length - 1; i >= 0; i -= 1) {
11
+ if (PATH_DELIMITERS.has(text[i] ?? "")) {
12
+ return i;
13
+ }
14
+ }
15
+ return -1;
16
+ }
17
+
18
+ function findUnclosedQuoteStart(text: string): number | null {
19
+ let inQuotes = false;
20
+ let quoteStart = -1;
21
+
22
+ for (let i = 0; i < text.length; i += 1) {
23
+ if (text[i] === '"') {
24
+ inQuotes = !inQuotes;
25
+ if (inQuotes) {
26
+ quoteStart = i;
27
+ }
28
+ }
29
+ }
30
+
31
+ return inQuotes ? quoteStart : null;
32
+ }
33
+
34
+ function isTokenStart(text: string, index: number): boolean {
35
+ return index === 0 || PATH_DELIMITERS.has(text[index - 1] ?? "");
36
+ }
37
+
38
+ function extractQuotedPrefix(text: string): string | null {
39
+ const quoteStart = findUnclosedQuoteStart(text);
40
+ if (quoteStart === null) {
41
+ return null;
42
+ }
43
+
44
+ if (quoteStart > 0 && text[quoteStart - 1] === "@") {
45
+ if (!isTokenStart(text, quoteStart - 1)) {
46
+ return null;
47
+ }
48
+ return text.slice(quoteStart - 1);
49
+ }
50
+
51
+ if (!isTokenStart(text, quoteStart)) {
52
+ return null;
53
+ }
54
+
55
+ return text.slice(quoteStart);
56
+ }
57
+
58
+ function parsePathPrefix(prefix: string): {
59
+ rawPrefix: string;
60
+ isAtPrefix: boolean;
61
+ isQuotedPrefix: boolean;
62
+ } {
63
+ if (prefix.startsWith('@"')) {
64
+ return { rawPrefix: prefix.slice(2), isAtPrefix: true, isQuotedPrefix: true };
65
+ }
66
+ if (prefix.startsWith('"')) {
67
+ return { rawPrefix: prefix.slice(1), isAtPrefix: false, isQuotedPrefix: true };
68
+ }
69
+ if (prefix.startsWith("@")) {
70
+ return { rawPrefix: prefix.slice(1), isAtPrefix: true, isQuotedPrefix: false };
71
+ }
72
+ return { rawPrefix: prefix, isAtPrefix: false, isQuotedPrefix: false };
73
+ }
74
+
75
+ function buildCompletionValue(
76
+ path: string,
77
+ options: { isDirectory: boolean; isAtPrefix: boolean; isQuotedPrefix: boolean }
78
+ ): string {
79
+ const needsQuotes = options.isQuotedPrefix || path.includes(" ");
80
+ const prefix = options.isAtPrefix ? "@" : "";
81
+
82
+ if (!needsQuotes) {
83
+ return `${prefix}${path}`;
84
+ }
85
+
86
+ const openQuote = `${prefix}"`;
87
+ const closeQuote = '"';
88
+ return `${openQuote}${path}${closeQuote}`;
89
+ }
90
+
91
+ // Use fd to walk directory tree (fast, respects .gitignore)
92
+ function walkDirectoryWithFd(
93
+ baseDir: string,
94
+ fdPath: string,
95
+ query: string,
96
+ maxResults: number
97
+ ): Array<{ path: string; isDirectory: boolean }> {
98
+ const args = [
99
+ "--base-directory",
100
+ baseDir,
101
+ "--max-results",
102
+ String(maxResults),
103
+ "--type",
104
+ "f",
105
+ "--type",
106
+ "d",
107
+ "--full-path",
108
+ "--hidden",
109
+ "--exclude",
110
+ ".git",
111
+ "--exclude",
112
+ ".git/*",
113
+ "--exclude",
114
+ ".git/**",
115
+ ];
116
+
117
+ // Add query as pattern if provided
118
+ if (query) {
119
+ args.push(query);
120
+ }
121
+
122
+ const result = spawnSync(fdPath, args, {
123
+ encoding: "utf-8",
124
+ stdio: ["pipe", "pipe", "pipe"],
125
+ maxBuffer: 10 * 1024 * 1024,
126
+ });
127
+
128
+ if (result.status !== 0 || !result.stdout) {
129
+ return [];
130
+ }
131
+
132
+ const lines = result.stdout.trim().split("\n").filter(Boolean);
133
+ const results: Array<{ path: string; isDirectory: boolean }> = [];
134
+
135
+ for (const line of lines) {
136
+ const normalizedPath = line.endsWith("/") ? line.slice(0, -1) : line;
137
+ if (
138
+ normalizedPath === ".git" ||
139
+ normalizedPath.startsWith(".git/") ||
140
+ normalizedPath.includes("/.git/")
141
+ ) {
142
+ continue;
143
+ }
144
+
145
+ // fd outputs directories with trailing /
146
+ const isDirectory = line.endsWith("/");
147
+ results.push({
148
+ path: line,
149
+ isDirectory,
150
+ });
151
+ }
152
+
153
+ return results;
154
+ }
155
+
156
+ export interface AutocompleteItem {
157
+ value: string;
158
+ label: string;
159
+ description?: string;
160
+ }
161
+
162
+ export interface SlashCommand {
163
+ name: string;
164
+ description?: string;
165
+ // Function to get argument completions for this command
166
+ // Returns null if no argument completion is available
167
+ getArgumentCompletions?(argumentPrefix: string): AutocompleteItem[] | null;
168
+ }
169
+
170
+ export interface AutocompleteProvider {
171
+ // Get autocomplete suggestions for current text/cursor position
172
+ // Returns null if no suggestions available
173
+ getSuggestions(
174
+ lines: string[],
175
+ cursorLine: number,
176
+ cursorCol: number
177
+ ): {
178
+ items: AutocompleteItem[];
179
+ prefix: string; // What we're matching against (e.g., "/" or "src/")
180
+ } | null;
181
+
182
+ // Apply the selected item
183
+ // Returns the new text and cursor position
184
+ applyCompletion(
185
+ lines: string[],
186
+ cursorLine: number,
187
+ cursorCol: number,
188
+ item: AutocompleteItem,
189
+ prefix: string
190
+ ): {
191
+ lines: string[];
192
+ cursorLine: number;
193
+ cursorCol: number;
194
+ };
195
+ }
196
+
197
+ // Combined provider that handles both slash commands and file paths
198
+ export class CombinedAutocompleteProvider implements AutocompleteProvider {
199
+ private commands: (SlashCommand | AutocompleteItem)[];
200
+ private basePath: string;
201
+ private fdPath: string | null;
202
+
203
+ constructor(
204
+ commands: (SlashCommand | AutocompleteItem)[] = [],
205
+ basePath: string = process.cwd(),
206
+ fdPath: string | null = null
207
+ ) {
208
+ this.commands = commands;
209
+ this.basePath = basePath;
210
+ this.fdPath = fdPath;
211
+ }
212
+
213
+ getSuggestions(
214
+ lines: string[],
215
+ cursorLine: number,
216
+ cursorCol: number
217
+ ): { items: AutocompleteItem[]; prefix: string } | null {
218
+ const currentLine = lines[cursorLine] || "";
219
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
220
+
221
+ // Check for @ file reference (fuzzy search) - must be after a delimiter or at start
222
+ const atPrefix = this.extractAtPrefix(textBeforeCursor);
223
+ if (atPrefix) {
224
+ const { rawPrefix, isQuotedPrefix } = parsePathPrefix(atPrefix);
225
+ const suggestions = this.getFuzzyFileSuggestions(rawPrefix, {
226
+ isQuotedPrefix: isQuotedPrefix,
227
+ });
228
+ if (suggestions.length === 0) return null;
229
+
230
+ return {
231
+ items: suggestions,
232
+ prefix: atPrefix,
233
+ };
234
+ }
235
+
236
+ // Check for slash commands
237
+ if (textBeforeCursor.startsWith("/")) {
238
+ const spaceIndex = textBeforeCursor.indexOf(" ");
239
+
240
+ if (spaceIndex === -1) {
241
+ // No space yet - complete command names with fuzzy matching
242
+ const prefix = textBeforeCursor.slice(1); // Remove the "/"
243
+ const commandItems = this.commands.map((cmd) => ({
244
+ name: "name" in cmd ? cmd.name : cmd.value,
245
+ label: "name" in cmd ? cmd.name : cmd.label,
246
+ description: cmd.description,
247
+ }));
248
+
249
+ const filtered = fuzzyFilter(commandItems, prefix, (item) => item.name).map((item) => ({
250
+ value: item.name,
251
+ label: item.label,
252
+ ...(item.description && { description: item.description }),
253
+ }));
254
+
255
+ if (filtered.length === 0) return null;
256
+
257
+ return {
258
+ items: filtered,
259
+ prefix: textBeforeCursor,
260
+ };
261
+ } else {
262
+ // Space found - complete command arguments
263
+ const commandName = textBeforeCursor.slice(1, spaceIndex); // Command without "/"
264
+ const argumentText = textBeforeCursor.slice(spaceIndex + 1); // Text after space
265
+
266
+ const command = this.commands.find((cmd) => {
267
+ const name = "name" in cmd ? cmd.name : cmd.value;
268
+ return name === commandName;
269
+ });
270
+ if (!command || !("getArgumentCompletions" in command) || !command.getArgumentCompletions) {
271
+ return null; // No argument completion for this command
272
+ }
273
+
274
+ const argumentSuggestions = command.getArgumentCompletions(argumentText);
275
+ if (!argumentSuggestions || argumentSuggestions.length === 0) {
276
+ return null;
277
+ }
278
+
279
+ return {
280
+ items: argumentSuggestions,
281
+ prefix: argumentText,
282
+ };
283
+ }
284
+ }
285
+
286
+ // Check for file paths - triggered by Tab or if we detect a path pattern
287
+ const pathMatch = this.extractPathPrefix(textBeforeCursor, false);
288
+
289
+ if (pathMatch !== null) {
290
+ const suggestions = this.getFileSuggestions(pathMatch);
291
+ if (suggestions.length === 0) return null;
292
+
293
+ // Check if we have an exact match that is a directory
294
+ // In that case, we might want to return suggestions for the directory content instead
295
+ // But only if the prefix ends with /
296
+ if (
297
+ suggestions.length === 1 &&
298
+ suggestions[0]?.value === pathMatch &&
299
+ !pathMatch.endsWith("/")
300
+ ) {
301
+ // Exact match found (e.g. user typed "src" and "src/" is the only match)
302
+ // We still return it so user can select it and add /
303
+ return {
304
+ items: suggestions,
305
+ prefix: pathMatch,
306
+ };
307
+ }
308
+
309
+ return {
310
+ items: suggestions,
311
+ prefix: pathMatch,
312
+ };
313
+ }
314
+
315
+ return null;
316
+ }
317
+
318
+ applyCompletion(
319
+ lines: string[],
320
+ cursorLine: number,
321
+ cursorCol: number,
322
+ item: AutocompleteItem,
323
+ prefix: string
324
+ ): { lines: string[]; cursorLine: number; cursorCol: number } {
325
+ const currentLine = lines[cursorLine] || "";
326
+ const beforePrefix = currentLine.slice(0, cursorCol - prefix.length);
327
+ const afterCursor = currentLine.slice(cursorCol);
328
+ const isQuotedPrefix = prefix.startsWith('"') || prefix.startsWith('@"');
329
+ const hasLeadingQuoteAfterCursor = afterCursor.startsWith('"');
330
+ const hasTrailingQuoteInItem = item.value.endsWith('"');
331
+ const adjustedAfterCursor =
332
+ isQuotedPrefix && hasTrailingQuoteInItem && hasLeadingQuoteAfterCursor
333
+ ? afterCursor.slice(1)
334
+ : afterCursor;
335
+
336
+ // Check if we're completing a slash command (prefix starts with "/" but NOT a file path)
337
+ // Slash commands are at the start of the line and don't contain path separators after the first /
338
+ const isSlashCommand =
339
+ prefix.startsWith("/") && beforePrefix.trim() === "" && !prefix.slice(1).includes("/");
340
+ if (isSlashCommand) {
341
+ // This is a command name completion
342
+ const newLine = `${beforePrefix}/${item.value} ${adjustedAfterCursor}`;
343
+ const newLines = [...lines];
344
+ newLines[cursorLine] = newLine;
345
+
346
+ return {
347
+ lines: newLines,
348
+ cursorLine,
349
+ cursorCol: beforePrefix.length + item.value.length + 2, // +2 for "/" and space
350
+ };
351
+ }
352
+
353
+ // Check if we're completing a file attachment (prefix starts with "@")
354
+ if (prefix.startsWith("@")) {
355
+ // This is a file attachment completion
356
+ // Don't add space after directories so user can continue autocompleting
357
+ const isDirectory = item.label.endsWith("/");
358
+ const suffix = isDirectory ? "" : " ";
359
+ const newLine = `${beforePrefix + item.value}${suffix}${adjustedAfterCursor}`;
360
+ const newLines = [...lines];
361
+ newLines[cursorLine] = newLine;
362
+
363
+ const hasTrailingQuote = item.value.endsWith('"');
364
+ const cursorOffset =
365
+ isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
366
+
367
+ return {
368
+ lines: newLines,
369
+ cursorLine,
370
+ cursorCol: beforePrefix.length + cursorOffset + suffix.length,
371
+ };
372
+ }
373
+
374
+ // Check if we're in a slash command context (beforePrefix contains "/command ")
375
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
376
+ if (textBeforeCursor.includes("/") && textBeforeCursor.includes(" ")) {
377
+ // This is likely a command argument completion
378
+ const newLine = beforePrefix + item.value + adjustedAfterCursor;
379
+ const newLines = [...lines];
380
+ newLines[cursorLine] = newLine;
381
+
382
+ const isDirectory = item.label.endsWith("/");
383
+ const hasTrailingQuote = item.value.endsWith('"');
384
+ const cursorOffset =
385
+ isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
386
+
387
+ return {
388
+ lines: newLines,
389
+ cursorLine,
390
+ cursorCol: beforePrefix.length + cursorOffset,
391
+ };
392
+ }
393
+
394
+ // For file paths, complete the path
395
+ const newLine = beforePrefix + item.value + adjustedAfterCursor;
396
+ const newLines = [...lines];
397
+ newLines[cursorLine] = newLine;
398
+
399
+ const isDirectory = item.label.endsWith("/");
400
+ const hasTrailingQuote = item.value.endsWith('"');
401
+ const cursorOffset =
402
+ isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
403
+
404
+ return {
405
+ lines: newLines,
406
+ cursorLine,
407
+ cursorCol: beforePrefix.length + cursorOffset,
408
+ };
409
+ }
410
+
411
+ // Extract @ prefix for fuzzy file suggestions
412
+ private extractAtPrefix(text: string): string | null {
413
+ const quotedPrefix = extractQuotedPrefix(text);
414
+ if (quotedPrefix?.startsWith('@"')) {
415
+ return quotedPrefix;
416
+ }
417
+
418
+ const lastDelimiterIndex = findLastDelimiter(text);
419
+ const tokenStart = lastDelimiterIndex === -1 ? 0 : lastDelimiterIndex + 1;
420
+
421
+ if (text[tokenStart] === "@") {
422
+ return text.slice(tokenStart);
423
+ }
424
+
425
+ return null;
426
+ }
427
+
428
+ // Extract a path-like prefix from the text before cursor
429
+ private extractPathPrefix(text: string, forceExtract: boolean = false): string | null {
430
+ const quotedPrefix = extractQuotedPrefix(text);
431
+ if (quotedPrefix) {
432
+ return quotedPrefix;
433
+ }
434
+
435
+ const lastDelimiterIndex = findLastDelimiter(text);
436
+ const pathPrefix = lastDelimiterIndex === -1 ? text : text.slice(lastDelimiterIndex + 1);
437
+
438
+ // For forced extraction (Tab key), always return something
439
+ if (forceExtract) {
440
+ return pathPrefix;
441
+ }
442
+
443
+ // For natural triggers, return if it looks like a path, ends with /, starts with ~/, .
444
+ // Only return empty string if the text looks like it's starting a path context
445
+ if (pathPrefix.includes("/") || pathPrefix.startsWith(".") || pathPrefix.startsWith("~/")) {
446
+ return pathPrefix;
447
+ }
448
+
449
+ // Return empty string only after a space (not for completely empty text)
450
+ // Empty text should not trigger file suggestions - that's for forced Tab completion
451
+ if (pathPrefix === "" && text.endsWith(" ")) {
452
+ return pathPrefix;
453
+ }
454
+
455
+ return null;
456
+ }
457
+
458
+ // Expand home directory (~/) to actual home path
459
+ private expandHomePath(path: string): string {
460
+ if (path.startsWith("~/")) {
461
+ const expandedPath = join(homedir(), path.slice(2));
462
+ // Preserve trailing slash if original path had one
463
+ return path.endsWith("/") && !expandedPath.endsWith("/") ? `${expandedPath}/` : expandedPath;
464
+ } else if (path === "~") {
465
+ return homedir();
466
+ }
467
+ return path;
468
+ }
469
+
470
+ // Get file/directory suggestions for a given path prefix
471
+ private getFileSuggestions(prefix: string): AutocompleteItem[] {
472
+ try {
473
+ let searchDir: string;
474
+ let searchPrefix: string;
475
+ const { rawPrefix, isAtPrefix, isQuotedPrefix } = parsePathPrefix(prefix);
476
+ let expandedPrefix = rawPrefix;
477
+
478
+ // Handle home directory expansion
479
+ if (expandedPrefix.startsWith("~")) {
480
+ expandedPrefix = this.expandHomePath(expandedPrefix);
481
+ }
482
+
483
+ const isRootPrefix =
484
+ rawPrefix === "" ||
485
+ rawPrefix === "./" ||
486
+ rawPrefix === "../" ||
487
+ rawPrefix === "~" ||
488
+ rawPrefix === "~/" ||
489
+ rawPrefix === "/" ||
490
+ (isAtPrefix && rawPrefix === "");
491
+
492
+ if (isRootPrefix) {
493
+ // Complete from specified position
494
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
495
+ searchDir = expandedPrefix;
496
+ } else {
497
+ searchDir = join(this.basePath, expandedPrefix);
498
+ }
499
+ searchPrefix = "";
500
+ } else if (rawPrefix.endsWith("/")) {
501
+ // If prefix ends with /, show contents of that directory
502
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
503
+ searchDir = expandedPrefix;
504
+ } else {
505
+ searchDir = join(this.basePath, expandedPrefix);
506
+ }
507
+ searchPrefix = "";
508
+ } else {
509
+ // Split into directory and file prefix
510
+ const dir = dirname(expandedPrefix);
511
+ const file = basename(expandedPrefix);
512
+ if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
513
+ searchDir = dir;
514
+ } else {
515
+ searchDir = join(this.basePath, dir);
516
+ }
517
+ searchPrefix = file;
518
+ }
519
+
520
+ const entries = readdirSync(searchDir, { withFileTypes: true });
521
+ const suggestions: AutocompleteItem[] = [];
522
+
523
+ for (const entry of entries) {
524
+ if (!entry.name.toLowerCase().startsWith(searchPrefix.toLowerCase())) {
525
+ continue;
526
+ }
527
+
528
+ // Check if entry is a directory (or a symlink pointing to a directory)
529
+ let isDirectory = entry.isDirectory();
530
+ if (!isDirectory && entry.isSymbolicLink()) {
531
+ try {
532
+ const fullPath = join(searchDir, entry.name);
533
+ isDirectory = statSync(fullPath).isDirectory();
534
+ } catch {
535
+ // Broken symlink or permission error - treat as file
536
+ }
537
+ }
538
+
539
+ let relativePath: string;
540
+ const name = entry.name;
541
+ const displayPrefix = rawPrefix;
542
+
543
+ if (displayPrefix.endsWith("/")) {
544
+ // If prefix ends with /, append entry to the prefix
545
+ relativePath = displayPrefix + name;
546
+ } else if (displayPrefix.includes("/")) {
547
+ // Preserve ~/ format for home directory paths
548
+ if (displayPrefix.startsWith("~/")) {
549
+ const homeRelativeDir = displayPrefix.slice(2); // Remove ~/
550
+ const dir = dirname(homeRelativeDir);
551
+ relativePath = `~/${dir === "." ? name : join(dir, name)}`;
552
+ } else if (displayPrefix.startsWith("/")) {
553
+ // Absolute path - construct properly
554
+ const dir = dirname(displayPrefix);
555
+ if (dir === "/") {
556
+ relativePath = `/${name}`;
557
+ } else {
558
+ relativePath = `${dir}/${name}`;
559
+ }
560
+ } else {
561
+ relativePath = join(dirname(displayPrefix), name);
562
+ }
563
+ } else {
564
+ // For standalone entries, preserve ~/ if original prefix was ~/
565
+ if (displayPrefix.startsWith("~")) {
566
+ relativePath = `~/${name}`;
567
+ } else {
568
+ relativePath = name;
569
+ }
570
+ }
571
+
572
+ const pathValue = isDirectory ? `${relativePath}/` : relativePath;
573
+ const value = buildCompletionValue(pathValue, {
574
+ isDirectory,
575
+ isAtPrefix,
576
+ isQuotedPrefix,
577
+ });
578
+
579
+ suggestions.push({
580
+ value,
581
+ label: name + (isDirectory ? "/" : ""),
582
+ });
583
+ }
584
+
585
+ // Sort directories first, then alphabetically
586
+ suggestions.sort((a, b) => {
587
+ const aIsDir = a.value.endsWith("/");
588
+ const bIsDir = b.value.endsWith("/");
589
+ if (aIsDir && !bIsDir) return -1;
590
+ if (!aIsDir && bIsDir) return 1;
591
+ return a.label.localeCompare(b.label);
592
+ });
593
+
594
+ return suggestions;
595
+ } catch (_e) {
596
+ // Directory doesn't exist or not accessible
597
+ return [];
598
+ }
599
+ }
600
+
601
+ // Score an entry against the query (higher = better match)
602
+ // isDirectory adds bonus to prioritize folders
603
+ private scoreEntry(filePath: string, query: string, isDirectory: boolean): number {
604
+ const fileName = basename(filePath);
605
+ const lowerFileName = fileName.toLowerCase();
606
+ const lowerQuery = query.toLowerCase();
607
+
608
+ let score = 0;
609
+
610
+ // Exact filename match (highest)
611
+ if (lowerFileName === lowerQuery) score = 100;
612
+ // Filename starts with query
613
+ else if (lowerFileName.startsWith(lowerQuery)) score = 80;
614
+ // Substring match in filename
615
+ else if (lowerFileName.includes(lowerQuery)) score = 50;
616
+ // Substring match in full path
617
+ else if (filePath.toLowerCase().includes(lowerQuery)) score = 30;
618
+
619
+ // Directories get a bonus to appear first
620
+ if (isDirectory && score > 0) score += 10;
621
+
622
+ return score;
623
+ }
624
+
625
+ // Fuzzy file search using fd (fast, respects .gitignore)
626
+ private getFuzzyFileSuggestions(
627
+ query: string,
628
+ options: { isQuotedPrefix: boolean }
629
+ ): AutocompleteItem[] {
630
+ if (!this.fdPath) {
631
+ // fd not available, return empty results
632
+ return [];
633
+ }
634
+
635
+ try {
636
+ const entries = walkDirectoryWithFd(this.basePath, this.fdPath, query, 100);
637
+
638
+ // Score entries
639
+ const scoredEntries = entries
640
+ .map((entry) => ({
641
+ ...entry,
642
+ score: query ? this.scoreEntry(entry.path, query, entry.isDirectory) : 1,
643
+ }))
644
+ .filter((entry) => entry.score > 0);
645
+
646
+ // Sort by score (descending) and take top 20
647
+ scoredEntries.sort((a, b) => b.score - a.score);
648
+ const topEntries = scoredEntries.slice(0, 20);
649
+
650
+ // Build suggestions
651
+ const suggestions: AutocompleteItem[] = [];
652
+ for (const { path: entryPath, isDirectory } of topEntries) {
653
+ // fd already includes trailing / for directories
654
+ const pathWithoutSlash = isDirectory ? entryPath.slice(0, -1) : entryPath;
655
+ const entryName = basename(pathWithoutSlash);
656
+ const value = buildCompletionValue(entryPath, {
657
+ isDirectory,
658
+ isAtPrefix: true,
659
+ isQuotedPrefix: options.isQuotedPrefix,
660
+ });
661
+
662
+ suggestions.push({
663
+ value,
664
+ label: entryName + (isDirectory ? "/" : ""),
665
+ description: pathWithoutSlash,
666
+ });
667
+ }
668
+
669
+ return suggestions;
670
+ } catch {
671
+ return [];
672
+ }
673
+ }
674
+
675
+ // Force file completion (called on Tab key) - always returns suggestions
676
+ getForceFileSuggestions(
677
+ lines: string[],
678
+ cursorLine: number,
679
+ cursorCol: number
680
+ ): { items: AutocompleteItem[]; prefix: string } | null {
681
+ const currentLine = lines[cursorLine] || "";
682
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
683
+
684
+ // Don't trigger if we're typing a slash command at the start of the line
685
+ if (textBeforeCursor.trim().startsWith("/") && !textBeforeCursor.trim().includes(" ")) {
686
+ return null;
687
+ }
688
+
689
+ // Force extract path prefix - this will always return something
690
+ const pathMatch = this.extractPathPrefix(textBeforeCursor, true);
691
+ if (pathMatch !== null) {
692
+ const suggestions = this.getFileSuggestions(pathMatch);
693
+ if (suggestions.length === 0) return null;
694
+
695
+ return {
696
+ items: suggestions,
697
+ prefix: pathMatch,
698
+ };
699
+ }
700
+
701
+ return null;
702
+ }
703
+
704
+ // Check if we should trigger file completion (called on Tab key)
705
+ shouldTriggerFileCompletion(lines: string[], cursorLine: number, cursorCol: number): boolean {
706
+ const currentLine = lines[cursorLine] || "";
707
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
708
+
709
+ // Don't trigger if we're typing a slash command at the start of the line
710
+ if (textBeforeCursor.trim().startsWith("/") && !textBeforeCursor.trim().includes(" ")) {
711
+ return false;
712
+ }
713
+
714
+ return true;
715
+ }
716
+ }