@anusornneal/chat-relay 1.4.0 → 1.5.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.
@@ -46,6 +46,23 @@ function skipSearchDirectory(name) {
46
46
  return skipWalkDirectory(name) || GENERATED_SEARCH_DIRS.has(name.toLowerCase());
47
47
  }
48
48
 
49
+ const SEARCH_CONTENT_CONCURRENCY = 8;
50
+
51
+ async function matchSearchContent(fullPath, needle) {
52
+ const info = await fs.stat(fullPath).catch(() => null);
53
+ if (!info || info.size > 1024 * 1024) return null;
54
+ const bytes = await fs.readFile(fullPath).catch(() => null);
55
+ if (!bytes || bytes.subarray(0, 1024).includes(0)) return null;
56
+ const content = bytes.toString("utf8");
57
+ const index = content.toLowerCase().indexOf(needle);
58
+ if (index < 0) return null;
59
+ return {
60
+ path: fullPath,
61
+ line: content.slice(0, index).split(/\r?\n/).length,
62
+ preview: content.slice(index, index + 240),
63
+ };
64
+ }
65
+
49
66
  function splitRoots(spec) {
50
67
  if (!spec) return [process.cwd()];
51
68
  return spec.split(";").map((value) => value.trim()).filter(Boolean).map((value) => path.resolve(value));
@@ -494,35 +511,37 @@ export class FileManager {
494
511
  const current = queue.shift();
495
512
  const items = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
496
513
  items.sort((a, b) => a.name.localeCompare(b.name));
497
- for (const item of items) {
498
- if (session.results.length >= limit || session.scanned >= MAX_SEARCH_FILES) {
499
- session.incomplete = true;
500
- session.stopReason = session.results.length >= limit ? "result_limit" : "scan_limit";
501
- break;
502
- }
503
- if (item.isDirectory() && skipSearchDirectory(item.name)) continue;
504
- const fullPath = path.join(current, item.name);
505
- session.scanned++;
506
-
507
- if (searchType === "files" && item.name.toLowerCase().includes(needle)) {
508
- session.results.push({ path: fullPath, name: item.name, type: item.isDirectory() ? "directory" : "file" });
509
- } else if (searchType === "content" && item.isFile()
510
- && !SEARCH_BINARY_EXTENSIONS.has(path.extname(item.name).toLowerCase())) {
511
- const info = await fs.stat(fullPath).catch(() => null);
512
- if (info && info.size <= 1024 * 1024) {
513
- const bytes = await fs.readFile(fullPath).catch(() => null);
514
- if (bytes && !bytes.subarray(0, 1024).includes(0)) {
515
- const text = bytes.toString("utf8");
516
- const index = text.toLowerCase().indexOf(needle);
517
- if (index >= 0) {
518
- const before = text.slice(0, index);
519
- const line = before.split(/\r?\n/).length;
520
- session.results.push({ path: fullPath, line, preview: text.slice(index, index + 240) });
521
- }
522
- }
514
+ // Prefetch up to eight independent file reads without changing BFS result order.
515
+ // Speculative reads may exceed the logical result cap by at most one small window.
516
+ const windowSize = searchType === "content" ? SEARCH_CONTENT_CONCURRENCY : Math.max(items.length, 1);
517
+ for (let offset = 0; offset < items.length; offset += windowSize) {
518
+ const group = items.slice(offset, offset + windowSize);
519
+ const contentMatches = searchType === "content"
520
+ ? await Promise.all(group.map((item) =>
521
+ item.isFile() && !SEARCH_BINARY_EXTENSIONS.has(path.extname(item.name).toLowerCase())
522
+ ? matchSearchContent(path.join(current, item.name), needle)
523
+ : null))
524
+ : null;
525
+
526
+ for (let index = 0; index < group.length; index++) {
527
+ if (session.results.length >= limit || session.scanned >= MAX_SEARCH_FILES) {
528
+ session.incomplete = true;
529
+ session.stopReason = session.results.length >= limit ? "result_limit" : "scan_limit";
530
+ break;
531
+ }
532
+ const item = group[index];
533
+ if (item.isDirectory() && skipSearchDirectory(item.name)) continue;
534
+ const fullPath = path.join(current, item.name);
535
+ session.scanned++;
536
+
537
+ if (searchType === "files" && item.name.toLowerCase().includes(needle)) {
538
+ session.results.push({ path: fullPath, name: item.name, type: item.isDirectory() ? "directory" : "file" });
539
+ } else if (contentMatches?.[index]) {
540
+ session.results.push(contentMatches[index]);
523
541
  }
542
+ if (item.isDirectory()) queue.push(fullPath);
524
543
  }
525
- if (item.isDirectory()) queue.push(fullPath);
544
+ if (session.incomplete) break;
526
545
  }
527
546
  if (!session.incomplete && queue.length > 0
528
547
  && (session.results.length >= limit || session.scanned >= MAX_SEARCH_FILES)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Zero-checkout remote MCP agent for ChatGPT with terminal, filesystem, process, multi-user, and multi-agent support.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -60,7 +60,9 @@
60
60
  "test:budget": "node --test test/relay-health.test.mjs test/usage-budget.test.mjs",
61
61
  "test:soak": "node test/soak-smoke.mjs",
62
62
  "test:file-search": "node --test test/file-search.test.mjs",
63
- "test:hardening": "npm run test:file-search && npm run test:tool-guidance && npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && npm run test:worker-hotpath && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:no-quota && npm run test:usage-storage && npm run test:learn && npm run test:learn-bootstrap && npm run test:soak",
63
+ "test:hardening": "npm run test:file-search && npm run test:batch-contract && npm run test:terminal-perf && npm run test:tool-guidance && npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && npm run test:worker-hotpath && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:no-quota && npm run test:usage-storage && npm run test:learn && npm run test:learn-bootstrap && npm run test:soak",
64
+ "test:batch-contract": "node --test test/tool-contract-batch.test.mjs",
65
+ "test:terminal-perf": "node --test test/terminal-perf.test.mjs",
64
66
  "test:tool-guidance": "node --test test/tool-error-guidance.test.mjs",
65
67
  "verify:review": "node scripts/verify-review-artifacts.mjs",
66
68
  "test:learn": "node test/learning-smoke.mjs && node test/project-alias-sqlite.test.mjs && node test/project-merge-mcp.test.mjs && node --test test/shared-learn.test.mjs test/shared-learn-ui.test.mjs && npm run test:learn-usage",