@anusornneal/chat-relay 1.3.5 โ†’ 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -170,7 +170,7 @@ A single account can own multiple computers. Each computer keeps its own agent i
170
170
 
171
171
  Clone the repository only when developing Chat Relay itself. Normal users should use the zero-checkout `npx` flow above.
172
172
 
173
- Agents must create new WIP backups or Git worktrees only when necessary and only inside the **owning target project's** `workspace/` folder (e.g. `chat-relay/workspace/worktrees/<id>`). Do not create sibling project folders. See [Project workspace policy](docs/PROJECT_WORKSPACE_POLICY.md) and `AGENTS.md`; existing legacy folders remain untouched until verified cleanup.
173
+ Agents must create new WIP backups or Git worktrees only when necessary and only inside the **owning target project's** `.workspace/` folder (e.g. `chat-relay/.workspace/worktrees/<id>`). Do not create sibling project folders. See [Project workspace policy](docs/PROJECT_WORKSPACE_POLICY.md) and `AGENTS.md`; existing legacy folders remain untouched until verified cleanup.
174
174
 
175
175
  Common development commands:
176
176
 
@@ -22,6 +22,16 @@ const MAX_READ_RESPONSE_BYTES = 48 * 1024;
22
22
  const MIN_READ_RESPONSE_BYTES = 1024;
23
23
  const MAX_WRITE_BYTES = 256 * 1024;
24
24
  const MAX_SEARCH_FILES = 5000;
25
+ const MAX_SEARCH_FIRST_PAGE_RESULTS = 20;
26
+ const MAX_SEARCH_FIRST_PAGE_BYTES = 16 * 1024;
27
+ const MAX_SEARCH_SESSIONS = 64;
28
+ const SEARCH_SESSION_TTL_MS = 15 * 60 * 1000;
29
+ const GENERATED_SEARCH_DIRS = new Set(["build", "dist", "coverage", "out", "__pycache__"]);
30
+ const SEARCH_BINARY_EXTENSIONS = new Set([
31
+ ".apk", ".aab", ".class", ".dex", ".jar", ".so", ".dll", ".exe", ".bin",
32
+ ".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico", ".pdf", ".zip", ".gz",
33
+ ".mp3", ".mp4", ".woff", ".woff2", ".ttf", ".otf", ".db", ".sqlite",
34
+ ]);
25
35
  const DEFAULT_LIST_LIMIT = 200;
26
36
  const MAX_LIST_LIMIT = 500;
27
37
  const DEFAULT_LIST_RESPONSE_BYTES = 48 * 1024;
@@ -32,6 +42,10 @@ function skipWalkDirectory(name) {
32
42
  return SKIP_DIRS.has(name) || (name.startsWith(".") && !ALLOWED_DOT_DIRS.has(name));
33
43
  }
34
44
 
45
+ function skipSearchDirectory(name) {
46
+ return skipWalkDirectory(name) || GENERATED_SEARCH_DIRS.has(name.toLowerCase());
47
+ }
48
+
35
49
  function splitRoots(spec) {
36
50
  if (!spec) return [process.cwd()];
37
51
  return spec.split(";").map((value) => value.trim()).filter(Boolean).map((value) => path.resolve(value));
@@ -442,6 +456,16 @@ export class FileManager {
442
456
  return { ok: true, path: target };
443
457
  }
444
458
 
459
+ #pruneSearchSessions(reserve = 0) {
460
+ const now = Date.now();
461
+ for (const [id, session] of this.searches) {
462
+ if (session.expiresAt <= now) this.searches.delete(id);
463
+ }
464
+ while (this.searches.size > MAX_SEARCH_SESSIONS - reserve) {
465
+ this.searches.delete(this.searches.keys().next().value);
466
+ }
467
+ }
468
+
445
469
  async startSearch(input, pattern, searchType = "files", maxResults = 100) {
446
470
  const target = await this.#resolveExisting(input);
447
471
  if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 300) {
@@ -455,33 +479,40 @@ export class FileManager {
455
479
  status: "RUNNING",
456
480
  createdAt: Date.now(),
457
481
  results: [],
482
+ scanned: 0,
483
+ incomplete: false,
484
+ stopReason: null,
458
485
  error: null,
459
486
  };
460
- this.searches.set(sessionId, session);
461
487
 
462
488
  try {
463
489
  const limit = Math.min(Math.max(Number(maxResults) || 100, 1), 500);
464
490
  const needle = pattern.toLowerCase();
465
- let scanned = 0;
466
-
467
491
  const queue = [target];
468
- while (queue.length > 0 && session.results.length < limit && scanned < MAX_SEARCH_FILES) {
492
+
493
+ while (queue.length > 0 && session.results.length < limit && session.scanned < MAX_SEARCH_FILES) {
469
494
  const current = queue.shift();
470
495
  const items = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
471
496
  items.sort((a, b) => a.name.localeCompare(b.name));
472
497
  for (const item of items) {
473
- if (session.results.length >= limit || scanned >= MAX_SEARCH_FILES) break;
474
- if (item.isDirectory() && skipWalkDirectory(item.name)) continue;
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;
475
504
  const fullPath = path.join(current, item.name);
476
- scanned++;
505
+ session.scanned++;
477
506
 
478
507
  if (searchType === "files" && item.name.toLowerCase().includes(needle)) {
479
508
  session.results.push({ path: fullPath, name: item.name, type: item.isDirectory() ? "directory" : "file" });
480
- } else if (searchType === "content" && item.isFile()) {
509
+ } else if (searchType === "content" && item.isFile()
510
+ && !SEARCH_BINARY_EXTENSIONS.has(path.extname(item.name).toLowerCase())) {
481
511
  const info = await fs.stat(fullPath).catch(() => null);
482
512
  if (info && info.size <= 1024 * 1024) {
483
- const text = await fs.readFile(fullPath, "utf8").catch(() => null);
484
- if (text != null) {
513
+ const bytes = await fs.readFile(fullPath).catch(() => null);
514
+ if (bytes && !bytes.subarray(0, 1024).includes(0)) {
515
+ const text = bytes.toString("utf8");
485
516
  const index = text.toLowerCase().indexOf(needle);
486
517
  if (index >= 0) {
487
518
  const before = text.slice(0, index);
@@ -493,34 +524,71 @@ export class FileManager {
493
524
  }
494
525
  if (item.isDirectory()) queue.push(fullPath);
495
526
  }
527
+ if (!session.incomplete && queue.length > 0
528
+ && (session.results.length >= limit || session.scanned >= MAX_SEARCH_FILES)) {
529
+ session.incomplete = true;
530
+ session.stopReason = session.results.length >= limit ? "result_limit" : "scan_limit";
531
+ }
496
532
  }
497
533
  session.status = "COMPLETED";
498
- session.scanned = scanned;
499
534
  } catch (error) {
500
535
  session.status = "ERROR";
536
+ session.incomplete = true;
537
+ session.stopReason = "error";
501
538
  session.error = error instanceof Error ? error.message : "search_failed";
502
539
  }
503
540
 
541
+ // The search is synchronous from the caller's perspective. Retain only finished sessions.
542
+ this.#pruneSearchSessions(1);
543
+ session.expiresAt = Date.now() + SEARCH_SESSION_TTL_MS;
544
+ this.searches.set(sessionId, session);
545
+
546
+ // Most callers only need the first few matches; avoid a second MCP round trip.
547
+ const firstPage = [];
548
+ let pageBytes = 0;
549
+ for (const item of session.results.slice(0, MAX_SEARCH_FIRST_PAGE_RESULTS)) {
550
+ const size = byteSize(item);
551
+ if (firstPage.length > 0 && pageBytes + size > MAX_SEARCH_FIRST_PAGE_BYTES) break;
552
+ firstPage.push(item);
553
+ pageBytes += size;
554
+ }
504
555
  return {
505
556
  sessionId,
506
557
  status: session.status,
507
558
  totalResults: session.results.length,
508
- scanned: session.scanned ?? 0,
559
+ scanned: session.scanned,
560
+ incomplete: session.incomplete,
561
+ stopReason: session.stopReason,
509
562
  error: session.error,
563
+ offset: 0,
564
+ results: firstPage,
565
+ nextOffset: firstPage.length < session.results.length ? firstPage.length : null,
510
566
  };
511
567
  }
512
568
 
513
569
  getSearchResults(sessionId, offset = 0, length = 50) {
514
- const session = this.searches.get(String(sessionId));
570
+ this.#pruneSearchSessions();
571
+ const key = String(sessionId);
572
+ const session = this.searches.get(key);
515
573
  if (!session) throw new Error("search_not_found");
574
+ session.expiresAt = Date.now() + SEARCH_SESSION_TTL_MS;
575
+ this.searches.delete(key);
576
+ this.searches.set(key, session);
577
+
516
578
  const start = Math.max(Number(offset) || 0, 0);
517
579
  const count = Math.min(Math.max(Number(length) || 50, 1), 100);
580
+ const results = session.results.slice(start, start + count);
581
+ const nextOffset = start + results.length;
518
582
  return {
519
583
  sessionId: session.id,
520
584
  status: session.status,
521
585
  totalResults: session.results.length,
586
+ scanned: session.scanned,
587
+ incomplete: session.incomplete,
588
+ stopReason: session.stopReason,
522
589
  offset: start,
523
- results: session.results.slice(start, start + count),
590
+ results,
591
+ nextOffset: nextOffset < session.results.length ? nextOffset : null,
524
592
  error: session.error,
525
593
  };
526
594
  }
package/cli/tui.mjs CHANGED
@@ -338,10 +338,6 @@ function activityIcon(item) {
338
338
  return "";
339
339
  }
340
340
 
341
- function activitySourceIcon(category) {
342
- return { Filesystem: "๐Ÿ“", Terminal: "๐Ÿ“Ÿ", Desktop: "๐Ÿ–ฅ๏ธ", Learn: "๐Ÿง " }[category] || "โš™๏ธ";
343
- }
344
-
345
341
  function shortActivityDetail(value, project) {
346
342
  const normalized = String(value || "").replace(/\\/g, "/").replace(/\s+/g, " ").trim();
347
343
  if (!normalized) return "";
@@ -397,18 +393,10 @@ function activityRows(item, width, { color = false, twoLines = false } = {}) {
397
393
  : prefix + operation + ending;
398
394
  if (!twoLines) return [headline];
399
395
 
400
- const category = activityCategory(item);
401
- const secondary = " ยท " + activitySourceIcon(category);
402
- // Keep request/response telemetry in transaction state but leave it out of
403
- // the monitoring view, where it competes with operation and project context.
404
- const textWidth = Math.max(1, limit - opStart);
405
- const name = truncateCells(project, textWidth);
406
- const rest = truncateCells(secondary, Math.max(0, textWidth - terminalCellWidth(name)));
396
+ // Display the project on its own line without duplicating the operation icon.
397
+ const name = truncateCells(project, Math.max(1, limit - opStart));
407
398
  const metadata = " ".repeat(opStart)
408
- + (color
409
- ? tint(name, item.ok === false ? MONITOR.bad : item.project ? MONITOR.muted : MONITOR.dim, true)
410
- + tint(rest, item.ok === false ? MONITOR.bad : MONITOR.dim, true)
411
- : name + rest);
399
+ + tint(name, item.ok === false ? MONITOR.bad : item.project ? MONITOR.muted : MONITOR.dim, color);
412
400
  const rows = [headline, metadata];
413
401
  const extra = item.error && item.ok === false ? "Error: " + shortActivityDetail(item.error, project)
414
402
  : shortActivityDetail(item.detail, project);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "1.3.5",
3
+ "version": "1.4.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": {
@@ -59,12 +59,13 @@
59
59
  "test:self-update": "node --test test/self-update.test.mjs test/agent-lifecycle-upgrade.test.mjs",
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
- "test:hardening": "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",
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
64
  "test:tool-guidance": "node --test test/tool-error-guidance.test.mjs",
64
65
  "verify:review": "node scripts/verify-review-artifacts.mjs",
65
66
  "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",
66
67
  "test:learn-usage": "node test/learn-usage.test.mjs && node test/learn-usage-integration.test.mjs && node test/learn-usage-mcp.test.mjs",
67
- "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs && node test/learning-thai-fixtures.mjs",
68
+ "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs && node test/learning-thai-fixtures.mjs && node --test test/learn-preflight-gate.test.mjs test/learn-reflection.test.mjs",
68
69
  "test:worker-hotpath": "node --experimental-strip-types --test test/relay-result.test.mjs"
69
70
  },
70
71
  "dependencies": {