@causyne/agent 1.20.95 → 1.20.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.95",
3
+ "version": "1.20.96",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -13,11 +13,12 @@
13
13
  // Pure Node. No dependency, no shell.
14
14
 
15
15
  import fs from 'fs';
16
- import fsp from 'fs/promises';
17
16
  import path from 'path';
18
17
  import { listCommands } from '../commands.js';
19
18
  import { listCompiledSkills as listSkillsForCompletion } from '../skillsManager.js';
20
19
  import { sanitize, shortenHome } from './text.js';
20
+ import { WorkspaceFileIndex } from './workspaceFileIndex.js';
21
+ export { WorkspaceFileIndex as FileIndex };
21
22
 
22
23
  export const MAX_VISIBLE = 8;
23
24
 
@@ -29,8 +30,6 @@ const SKIP_DIRECTORIES = new Set([
29
30
  '.idea', '.cache', 'coverage', 'vendor', 'Pods', '.causyne'
30
31
  ]);
31
32
 
32
- const MAX_INDEX_ENTRIES = 20000;
33
- const MAX_INDEX_DEPTH = 12;
34
33
 
35
34
  /** A value is offerable only if printing it changes nothing. */
36
35
  export function isTerminalSafe(value) {
@@ -52,26 +51,28 @@ export function isTerminalSafe(value) {
52
51
  */
53
52
  export function score(candidate, query) {
54
53
  if (!query) return 0;
55
- const haystack = candidate.toLowerCase();
56
- const needle = query.toLowerCase();
57
-
58
- if (haystack.startsWith(needle)) return 1000 - candidate.length;
59
-
60
- const base = haystack.slice(haystack.lastIndexOf('/') + 1);
61
- if (base.startsWith(needle)) return 800 - candidate.length;
62
- if (haystack.includes(needle)) return 700 - candidate.length;
63
- if (base.includes(needle)) return 600 - candidate.length;
64
-
65
- // Subsequence: every character of the query in order, gaps allowed. This is
66
- // what lets "tuich" find "tui/chatRenderer.js".
67
- let index = 0;
54
+ const full = candidate.toLocaleLowerCase();
55
+ const needle = query.toLocaleLowerCase();
56
+ const leaf = full.replace(/\/$/, '').split('/').at(-1) || '';
57
+ const isDirectory = candidate.endsWith('/');
58
+ const pathPenalty = Math.min(candidate.length, 180);
59
+ const fileBonus = isDirectory ? 0 : 20;
60
+
61
+ if (leaf === needle) return 1800 + fileBonus - pathPenalty;
62
+ if (leaf.startsWith(needle)) return 1500 + fileBonus - pathPenalty;
63
+ if (leaf.includes(needle)) return 1200 + fileBonus - pathPenalty;
64
+ if (full.startsWith(needle)) return 1050 + fileBonus - pathPenalty;
65
+ if (full.includes(needle)) return 900 + fileBonus - pathPenalty;
66
+
67
+ // Fallback: a bounded subsequence match for abbreviations such as tuich.
68
+ let cursor = 0;
68
69
  let gaps = 0;
69
- for (const character of haystack) {
70
- if (character === needle[index]) {
71
- index += 1;
72
- if (index === needle.length) return 400 - gaps - candidate.length;
73
- } else if (index > 0) {
74
- gaps += 1;
70
+ for (const character of full) {
71
+ if (character === needle[cursor]) {
72
+ cursor++;
73
+ if (cursor === needle.length) return 400 - gaps - pathPenalty;
74
+ } else if (cursor > 0) {
75
+ gaps++;
75
76
  }
76
77
  }
77
78
  return -1;
@@ -110,7 +111,7 @@ function rank(items, query, limit = 50, focusDir = null) {
110
111
  value += 2000;
111
112
  }
112
113
  if (focusPrefix && val.toLowerCase().startsWith(focusPrefix)) {
113
- value += 3000;
114
+ value += 90;
114
115
  }
115
116
  const resultItem = matchedAlias
116
117
  ? { ...item, description: `(alias: /${matchedAlias}) ${item.description}` }
@@ -118,7 +119,7 @@ function rank(items, query, limit = 50, focusDir = null) {
118
119
  scored.push({ item: resultItem, value });
119
120
  }
120
121
  }
121
- scored.sort((a, b) => b.value - a.value);
122
+ scored.sort((a, b) => b.value - a.value || a.item.value.localeCompare(b.item.value));
122
123
  const ranked = scored.slice(0, limit).map((entry) => entry.item);
123
124
  ranked.total = scored.length;
124
125
  return ranked;
@@ -244,67 +245,7 @@ function argumentItems(name) {
244
245
  * upgrades the experience once it is ready. If it is never ready, nothing
245
246
  * breaks — the caller must never await it.
246
247
  */
247
- export class FileIndex {
248
- constructor(root) {
249
- this.root = root;
250
- this.entries = null;
251
- this.building = null;
252
- this.truncated = false;
253
- }
254
-
255
- get isReady() {
256
- return Array.isArray(this.entries);
257
- }
258
-
259
- /** Kick off the walk. Safe to call repeatedly; only the first one runs. */
260
- ensure() {
261
- if (this.entries || this.building) return this.building;
262
- this.building = this.walk()
263
- .then((entries) => { this.entries = entries; return entries; })
264
- .catch(() => { this.entries = []; return []; })
265
- .finally(() => { this.building = null; });
266
- return this.building;
267
- }
268
-
269
- async walk() {
270
- const found = [];
271
- const queue = [{ dir: this.root, depth: 0 }];
272
- let next = 0;
273
-
274
- while (next < queue.length && found.length < MAX_INDEX_ENTRIES) {
275
- const { dir, depth } = queue[next++];
276
- let listing;
277
- try {
278
- listing = await fsp.readdir(dir, { withFileTypes: true });
279
- } catch (e) {
280
- continue; // unreadable directory is not an error worth surfacing here
281
- }
282
-
283
- for (const entry of listing) {
284
- if (entry.name.startsWith('.') && entry.name !== '.env.example') continue;
285
- const full = path.join(dir, entry.name);
286
-
287
- if (entry.isDirectory()) {
288
- if (SKIP_DIRECTORIES.has(entry.name) || depth >= MAX_INDEX_DEPTH) continue;
289
- queue.push({ dir: full, depth: depth + 1 });
290
- const relDir = path.relative(this.root, full).split(path.sep).join('/') + '/';
291
- if (isTerminalSafe(relDir)) found.push(relDir);
292
- continue;
293
- }
294
- if (!entry.isFile()) continue;
295
-
296
- const relative = path.relative(this.root, full).split(path.sep).join('/');
297
- if (!isTerminalSafe(relative)) continue;
298
- found.push(relative);
299
- if (found.length >= MAX_INDEX_ENTRIES) {
300
- this.truncated = true;
301
- break;
302
- }
303
- }
304
- }
305
- return found;
306
- }
307
- }
248
+ // FileIndex is now owned by src/tui/workspaceFileIndex.ts.
308
249
 
309
250
  /**
310
251
  * Resolve both the authorized root and candidate to physical paths before
@@ -462,11 +403,11 @@ export function suggest(text, cursor, options = {}) {
462
403
  const root = options.root || process.cwd();
463
404
  const index = options.index;
464
405
  const focusDir = options.focusDir || null;
465
- if (index && !index.isReady) index.ensure();
406
+ if (index) void index.ensure();
466
407
 
467
408
  let pool;
468
409
  if (index && index.isReady && trigger.query) {
469
- pool = index.entries.map((relative) => ({
410
+ pool = index.candidates(trigger.query).map((relative) => ({
470
411
  value: relative,
471
412
  match: relative,
472
413
  label: relative,
@@ -495,7 +436,7 @@ export function suggest(text, cursor, options = {}) {
495
436
  pool = directoryItems(root, trigger.query);
496
437
  }
497
438
 
498
- const items = rank(pool, trigger.query, 50, focusDir);
439
+ const items = rank(pool, trigger.query, 500, focusDir);
499
440
  if (items.length === 0) return null;
500
441
  return { ...trigger, items, total: items.total };
501
442
  }
package/src/tui/prompt.js CHANGED
@@ -121,6 +121,8 @@ export class ChatPrompt {
121
121
  this.editor = new LineEditor();
122
122
  this.history = options.history || new PromptHistory();
123
123
  this.index = new FileIndex(this.root);
124
+ this._unsubscribeFileIndex = null;
125
+ this.bindFileIndex(this.index);
124
126
  this.decoder = new KeyDecoder();
125
127
  this.inputFramer = new TerminalInputFramer();
126
128
  this.inputFrameTimer = null;
@@ -1304,12 +1306,32 @@ export class ChatPrompt {
1304
1306
  // Completion
1305
1307
  // -------------------------------------------------------------------------
1306
1308
 
1309
+ /** A completed scan must refresh the currently displayed @ picker. */
1310
+ bindFileIndex(index) {
1311
+ if (typeof this._unsubscribeFileIndex === 'function') this._unsubscribeFileIndex();
1312
+ this._unsubscribeFileIndex = index.subscribe(() => {
1313
+ // Ignore a late callback from a previous workspace or a dismissed prompt.
1314
+ if (this.index !== index || !this.active) return;
1315
+ const trigger = detectTrigger(this.editor.getText(), this.cursorOffset());
1316
+ if (!trigger || trigger.kind !== 'file') return;
1317
+ this.openCompletion(false);
1318
+ if (index.truncated) this.notice = 'Workspace file index reached its safety limit; narrow the project root.';
1319
+ else if (this.notice === 'Indexing workspace files…') this.notice = null;
1320
+ this.scheduleDraw();
1321
+ });
1322
+ void index.ensure();
1323
+ }
1324
+
1307
1325
  /** Dynamically re-target the prompt root and optional focused subproject. */
1308
1326
  setWorkingRoot(newRoot, focusDir = null) {
1327
+ if (typeof this._unsubscribeFileIndex === 'function') this._unsubscribeFileIndex();
1328
+ this.index?.dispose();
1309
1329
  this.root = newRoot;
1310
1330
  this.focusDir = focusDir;
1311
1331
  this.index = new FileIndex(newRoot);
1312
- this.index.ensure();
1332
+ this.bindFileIndex(this.index);
1333
+ const trigger = detectTrigger(this.editor.getText(), this.cursorOffset());
1334
+ if (trigger?.kind === 'file') this.openCompletion(false);
1313
1335
  }
1314
1336
 
1315
1337
  cursorOffset() {
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Causyne: bounded, asynchronous, workspace-scoped index for @ references.
3
+ * This module never follows symlinks or invokes external binaries.
4
+ * It indexes nested project paths once, not on each keystroke.
5
+ */
6
+ import { readdir } from 'node:fs/promises';
7
+ import path from 'node:path';
8
+ const SKIP = new Set([
9
+ '.git', '.causyne', 'node_modules', '.next', '.nuxt', '.svelte-kit',
10
+ '.venv', 'venv', '__pycache__', '.gradle', '.idea', '.cache',
11
+ 'coverage', 'vendor', 'Pods', 'dist', 'build', 'out', 'target'
12
+ ]);
13
+ const DEFAULT_MAX_ENTRIES = 100_000;
14
+ const DEFAULT_MAX_DIRS = 20_000;
15
+ const DEFAULT_MAX_DEPTH = 32;
16
+ const DEFAULT_REFRESH_MS = 45_000;
17
+ const YIELD_EVERY = 48;
18
+ function finiteInt(value, fallback, minimum = 1) {
19
+ return Number.isSafeInteger(value) && value !== undefined && value >= minimum ? value : fallback;
20
+ }
21
+ /** Terminal control codes must never be inserted into a selectable path. */
22
+ function safeRelative(relative) {
23
+ return relative.length > 0 && relative.length <= 4096
24
+ && !/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(relative);
25
+ }
26
+ export class WorkspaceFileIndex {
27
+ root;
28
+ entries = null;
29
+ truncated = false;
30
+ indexed = [];
31
+ listeners = new Set();
32
+ building = null;
33
+ generation = 0;
34
+ completedAt = 0;
35
+ disposed = false;
36
+ maxEntries;
37
+ maxDirs;
38
+ maxDepth;
39
+ refreshMs;
40
+ constructor(root, options = {}) {
41
+ this.root = path.resolve(root);
42
+ this.maxEntries = finiteInt(options.maxEntries, DEFAULT_MAX_ENTRIES);
43
+ this.maxDirs = finiteInt(options.maxDirs, DEFAULT_MAX_DIRS);
44
+ this.maxDepth = finiteInt(options.maxDepth, DEFAULT_MAX_DEPTH);
45
+ this.refreshMs = finiteInt(options.refreshMs, DEFAULT_REFRESH_MS, 0);
46
+ }
47
+ get isReady() { return this.entries !== null; }
48
+ get isBuilding() { return this.building !== null; }
49
+ subscribe(listener) {
50
+ if (this.disposed)
51
+ return () => { };
52
+ this.listeners.add(listener);
53
+ return () => { this.listeners.delete(listener); };
54
+ }
55
+ invalidate() { this.completedAt = 0; }
56
+ dispose() {
57
+ this.disposed = true;
58
+ this.generation++;
59
+ this.listeners.clear();
60
+ }
61
+ /**
62
+ * Starts a scan only when required. Existing results remain available while
63
+ * a TTL refresh runs. Consumers receive one event when the snapshot changes.
64
+ */
65
+ ensure(force = false) {
66
+ if (this.disposed)
67
+ return Promise.resolve(this.entries ?? []);
68
+ if (this.building)
69
+ return this.building;
70
+ if (!force && this.entries && Date.now() - this.completedAt < this.refreshMs) {
71
+ return Promise.resolve(this.entries);
72
+ }
73
+ const generation = ++this.generation;
74
+ this.building = this.scan(generation)
75
+ .then(({ entries, truncated }) => {
76
+ if (this.disposed || generation !== this.generation)
77
+ return this.entries ?? [];
78
+ this.entries = entries;
79
+ this.indexed = entries.map(value => ({ value, folded: value.toLocaleLowerCase() }));
80
+ this.truncated = truncated;
81
+ this.completedAt = Date.now();
82
+ for (const listener of [...this.listeners]) {
83
+ try {
84
+ listener();
85
+ }
86
+ catch { /* UI listeners cannot fail the index */ }
87
+ }
88
+ return entries;
89
+ })
90
+ .catch(() => {
91
+ // Keep any previous snapshot if the root becomes unreadable.
92
+ if (!this.disposed && generation === this.generation && this.entries === null) {
93
+ this.entries = [];
94
+ this.indexed = [];
95
+ this.completedAt = Date.now();
96
+ for (const listener of [...this.listeners]) {
97
+ try {
98
+ listener();
99
+ }
100
+ catch { /* never propagate to keyboard handling */ }
101
+ }
102
+ }
103
+ return this.entries ?? [];
104
+ })
105
+ .finally(() => { if (generation === this.generation)
106
+ this.building = null; });
107
+ return this.building;
108
+ }
109
+ /** Contiguous matches take priority; fuzzy matching remains the JS fallback. */
110
+ candidates(query) {
111
+ if (!query)
112
+ return this.entries ?? [];
113
+ const needle = query.toLocaleLowerCase();
114
+ const direct = this.indexed.filter(entry => entry.folded.includes(needle));
115
+ return (direct.length > 0 ? direct.map(entry => entry.value) : this.entries ?? []);
116
+ }
117
+ async scan(generation) {
118
+ const found = [];
119
+ const queue = [
120
+ { absolute: this.root, relative: '', depth: 0 }
121
+ ];
122
+ let cursor = 0;
123
+ let truncated = false;
124
+ while (cursor < queue.length) {
125
+ if (this.disposed || generation !== this.generation)
126
+ break;
127
+ if (cursor >= this.maxDirs || found.length >= this.maxEntries) {
128
+ truncated = true;
129
+ break;
130
+ }
131
+ const current = queue[cursor++];
132
+ if (!current)
133
+ break;
134
+ let listing;
135
+ try {
136
+ listing = await readdir(current.absolute, { withFileTypes: true });
137
+ }
138
+ catch {
139
+ continue;
140
+ }
141
+ listing.sort((a, b) => a.name.localeCompare(b.name));
142
+ for (const entry of listing) {
143
+ if (this.disposed || generation !== this.generation)
144
+ break;
145
+ if (entry.isSymbolicLink())
146
+ continue;
147
+ if (!entry.isFile() && !entry.isDirectory())
148
+ continue;
149
+ const relative = current.relative ? `${current.relative}/${entry.name}` : entry.name;
150
+ if (!safeRelative(relative))
151
+ continue;
152
+ if (entry.isDirectory()) {
153
+ if (SKIP.has(entry.name))
154
+ continue;
155
+ if (current.depth < this.maxDepth) {
156
+ if (queue.length >= this.maxDirs)
157
+ truncated = true;
158
+ else
159
+ queue.push({
160
+ absolute: path.join(current.absolute, entry.name),
161
+ relative, depth: current.depth + 1
162
+ });
163
+ }
164
+ else
165
+ truncated = true;
166
+ found.push(`${relative}/`);
167
+ }
168
+ else {
169
+ found.push(relative);
170
+ }
171
+ if (found.length >= this.maxEntries) {
172
+ truncated = true;
173
+ break;
174
+ }
175
+ }
176
+ // Periodically yield: typing, rendering and cancellation must remain responsive.
177
+ if (cursor % YIELD_EVERY === 0) {
178
+ await new Promise(resolve => setImmediate(resolve));
179
+ }
180
+ }
181
+ return { entries: found, truncated };
182
+ }
183
+ }
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Causyne: bounded, asynchronous, workspace-scoped index for @ references.
3
+ * This module never follows symlinks or invokes external binaries.
4
+ * It indexes nested project paths once, not on each keystroke.
5
+ */
6
+ import { readdir } from 'node:fs/promises';
7
+ import path from 'node:path';
8
+
9
+ const SKIP = new Set([
10
+ '.git', '.causyne', 'node_modules', '.next', '.nuxt', '.svelte-kit',
11
+ '.venv', 'venv', '__pycache__', '.gradle', '.idea', '.cache',
12
+ 'coverage', 'vendor', 'Pods', 'dist', 'build', 'out', 'target'
13
+ ]);
14
+ const DEFAULT_MAX_ENTRIES = 100_000;
15
+ const DEFAULT_MAX_DIRS = 20_000;
16
+ const DEFAULT_MAX_DEPTH = 32;
17
+ const DEFAULT_REFRESH_MS = 45_000;
18
+ const YIELD_EVERY = 48;
19
+
20
+ export interface WorkspaceFileIndexOptions {
21
+ maxEntries?: number;
22
+ maxDirs?: number;
23
+ maxDepth?: number;
24
+ refreshMs?: number;
25
+ }
26
+
27
+ function finiteInt(value: number | undefined, fallback: number, minimum = 1): number {
28
+ return Number.isSafeInteger(value) && value !== undefined && value >= minimum ? value : fallback;
29
+ }
30
+
31
+ /** Terminal control codes must never be inserted into a selectable path. */
32
+ function safeRelative(relative: string): boolean {
33
+ return relative.length > 0 && relative.length <= 4096
34
+ && !/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(relative);
35
+ }
36
+
37
+ interface IndexedPath {
38
+ value: string;
39
+ folded: string;
40
+ }
41
+
42
+ export class WorkspaceFileIndex {
43
+ readonly root: string;
44
+ entries: string[] | null = null;
45
+ truncated = false;
46
+ private indexed: IndexedPath[] = [];
47
+ private listeners = new Set<() => void>();
48
+ private building: Promise<string[]> | null = null;
49
+ private generation = 0;
50
+ private completedAt = 0;
51
+ private disposed = false;
52
+ private readonly maxEntries: number;
53
+ private readonly maxDirs: number;
54
+ private readonly maxDepth: number;
55
+ private readonly refreshMs: number;
56
+
57
+ constructor(root: string, options: WorkspaceFileIndexOptions = {}) {
58
+ this.root = path.resolve(root);
59
+ this.maxEntries = finiteInt(options.maxEntries, DEFAULT_MAX_ENTRIES);
60
+ this.maxDirs = finiteInt(options.maxDirs, DEFAULT_MAX_DIRS);
61
+ this.maxDepth = finiteInt(options.maxDepth, DEFAULT_MAX_DEPTH);
62
+ this.refreshMs = finiteInt(options.refreshMs, DEFAULT_REFRESH_MS, 0);
63
+ }
64
+
65
+ get isReady(): boolean { return this.entries !== null; }
66
+ get isBuilding(): boolean { return this.building !== null; }
67
+
68
+ subscribe(listener: () => void): () => void {
69
+ if (this.disposed) return () => {};
70
+ this.listeners.add(listener);
71
+ return () => { this.listeners.delete(listener); };
72
+ }
73
+
74
+ invalidate(): void { this.completedAt = 0; }
75
+
76
+ dispose(): void {
77
+ this.disposed = true;
78
+ this.generation++;
79
+ this.listeners.clear();
80
+ }
81
+
82
+ /**
83
+ * Starts a scan only when required. Existing results remain available while
84
+ * a TTL refresh runs. Consumers receive one event when the snapshot changes.
85
+ */
86
+ ensure(force = false): Promise<string[]> {
87
+ if (this.disposed) return Promise.resolve(this.entries ?? []);
88
+ if (this.building) return this.building;
89
+ if (!force && this.entries && Date.now() - this.completedAt < this.refreshMs) {
90
+ return Promise.resolve(this.entries);
91
+ }
92
+ const generation = ++this.generation;
93
+ this.building = this.scan(generation)
94
+ .then(({ entries, truncated }) => {
95
+ if (this.disposed || generation !== this.generation) return this.entries ?? [];
96
+ this.entries = entries;
97
+ this.indexed = entries.map(value => ({ value, folded: value.toLocaleLowerCase() }));
98
+ this.truncated = truncated;
99
+ this.completedAt = Date.now();
100
+ for (const listener of [...this.listeners]) {
101
+ try { listener(); } catch { /* UI listeners cannot fail the index */ }
102
+ }
103
+ return entries;
104
+ })
105
+ .catch(() => {
106
+ // Keep any previous snapshot if the root becomes unreadable.
107
+ if (!this.disposed && generation === this.generation && this.entries === null) {
108
+ this.entries = [];
109
+ this.indexed = [];
110
+ this.completedAt = Date.now();
111
+ for (const listener of [...this.listeners]) {
112
+ try { listener(); } catch { /* never propagate to keyboard handling */ }
113
+ }
114
+ }
115
+ return this.entries ?? [];
116
+ })
117
+ .finally(() => { if (generation === this.generation) this.building = null; });
118
+ return this.building;
119
+ }
120
+
121
+ /** Contiguous matches take priority; fuzzy matching remains the JS fallback. */
122
+ candidates(query: string): string[] {
123
+ if (!query) return this.entries ?? [];
124
+ const needle = query.toLocaleLowerCase();
125
+ const direct = this.indexed.filter(entry => entry.folded.includes(needle));
126
+ return (direct.length > 0 ? direct.map(entry => entry.value) : this.entries ?? []);
127
+ }
128
+
129
+ private async scan(generation: number): Promise<{ entries: string[]; truncated: boolean }> {
130
+ const found: string[] = [];
131
+ const queue: Array<{ absolute: string; relative: string; depth: number }> = [
132
+ { absolute: this.root, relative: '', depth: 0 }
133
+ ];
134
+ let cursor = 0;
135
+ let truncated = false;
136
+
137
+ while (cursor < queue.length) {
138
+ if (this.disposed || generation !== this.generation) break;
139
+ if (cursor >= this.maxDirs || found.length >= this.maxEntries) {
140
+ truncated = true;
141
+ break;
142
+ }
143
+ const current = queue[cursor++];
144
+ if (!current) break;
145
+ let listing;
146
+ try { listing = await readdir(current.absolute, { withFileTypes: true }); }
147
+ catch { continue; }
148
+ listing.sort((a, b) => a.name.localeCompare(b.name));
149
+
150
+ for (const entry of listing) {
151
+ if (this.disposed || generation !== this.generation) break;
152
+ if (entry.isSymbolicLink()) continue;
153
+ if (!entry.isFile() && !entry.isDirectory()) continue;
154
+ const relative = current.relative ? `${current.relative}/${entry.name}` : entry.name;
155
+ if (!safeRelative(relative)) continue;
156
+
157
+ if (entry.isDirectory()) {
158
+ if (SKIP.has(entry.name)) continue;
159
+ if (current.depth < this.maxDepth) {
160
+ if (queue.length >= this.maxDirs) truncated = true;
161
+ else queue.push({
162
+ absolute: path.join(current.absolute, entry.name),
163
+ relative, depth: current.depth + 1
164
+ });
165
+ } else truncated = true;
166
+ found.push(`${relative}/`);
167
+ } else {
168
+ found.push(relative);
169
+ }
170
+ if (found.length >= this.maxEntries) { truncated = true; break; }
171
+ }
172
+ // Periodically yield: typing, rendering and cancellation must remain responsive.
173
+ if (cursor % YIELD_EVERY === 0) {
174
+ await new Promise<void>(resolve => setImmediate(resolve));
175
+ }
176
+ }
177
+ return { entries: found, truncated };
178
+ }
179
+ }