@anusornneal/chat-relay 1.3.5 โ 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.
- package/README.md +1 -1
- package/agent/file-manager.mjs +116 -29
- package/cli/tui.mjs +3 -15
- package/package.json +6 -3
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**
|
|
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
|
|
package/agent/file-manager.mjs
CHANGED
|
@@ -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,27 @@ 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
|
+
|
|
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
|
+
|
|
35
66
|
function splitRoots(spec) {
|
|
36
67
|
if (!spec) return [process.cwd()];
|
|
37
68
|
return spec.split(";").map((value) => value.trim()).filter(Boolean).map((value) => path.resolve(value));
|
|
@@ -442,6 +473,16 @@ export class FileManager {
|
|
|
442
473
|
return { ok: true, path: target };
|
|
443
474
|
}
|
|
444
475
|
|
|
476
|
+
#pruneSearchSessions(reserve = 0) {
|
|
477
|
+
const now = Date.now();
|
|
478
|
+
for (const [id, session] of this.searches) {
|
|
479
|
+
if (session.expiresAt <= now) this.searches.delete(id);
|
|
480
|
+
}
|
|
481
|
+
while (this.searches.size > MAX_SEARCH_SESSIONS - reserve) {
|
|
482
|
+
this.searches.delete(this.searches.keys().next().value);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
445
486
|
async startSearch(input, pattern, searchType = "files", maxResults = 100) {
|
|
446
487
|
const target = await this.#resolveExisting(input);
|
|
447
488
|
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 300) {
|
|
@@ -455,72 +496,118 @@ export class FileManager {
|
|
|
455
496
|
status: "RUNNING",
|
|
456
497
|
createdAt: Date.now(),
|
|
457
498
|
results: [],
|
|
499
|
+
scanned: 0,
|
|
500
|
+
incomplete: false,
|
|
501
|
+
stopReason: null,
|
|
458
502
|
error: null,
|
|
459
503
|
};
|
|
460
|
-
this.searches.set(sessionId, session);
|
|
461
504
|
|
|
462
505
|
try {
|
|
463
506
|
const limit = Math.min(Math.max(Number(maxResults) || 100, 1), 500);
|
|
464
507
|
const needle = pattern.toLowerCase();
|
|
465
|
-
let scanned = 0;
|
|
466
|
-
|
|
467
508
|
const queue = [target];
|
|
468
|
-
|
|
509
|
+
|
|
510
|
+
while (queue.length > 0 && session.results.length < limit && session.scanned < MAX_SEARCH_FILES) {
|
|
469
511
|
const current = queue.shift();
|
|
470
512
|
const items = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
|
|
471
513
|
items.sort((a, b) => a.name.localeCompare(b.name));
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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]);
|
|
492
541
|
}
|
|
542
|
+
if (item.isDirectory()) queue.push(fullPath);
|
|
493
543
|
}
|
|
494
|
-
if (
|
|
544
|
+
if (session.incomplete) break;
|
|
545
|
+
}
|
|
546
|
+
if (!session.incomplete && queue.length > 0
|
|
547
|
+
&& (session.results.length >= limit || session.scanned >= MAX_SEARCH_FILES)) {
|
|
548
|
+
session.incomplete = true;
|
|
549
|
+
session.stopReason = session.results.length >= limit ? "result_limit" : "scan_limit";
|
|
495
550
|
}
|
|
496
551
|
}
|
|
497
552
|
session.status = "COMPLETED";
|
|
498
|
-
session.scanned = scanned;
|
|
499
553
|
} catch (error) {
|
|
500
554
|
session.status = "ERROR";
|
|
555
|
+
session.incomplete = true;
|
|
556
|
+
session.stopReason = "error";
|
|
501
557
|
session.error = error instanceof Error ? error.message : "search_failed";
|
|
502
558
|
}
|
|
503
559
|
|
|
560
|
+
// The search is synchronous from the caller's perspective. Retain only finished sessions.
|
|
561
|
+
this.#pruneSearchSessions(1);
|
|
562
|
+
session.expiresAt = Date.now() + SEARCH_SESSION_TTL_MS;
|
|
563
|
+
this.searches.set(sessionId, session);
|
|
564
|
+
|
|
565
|
+
// Most callers only need the first few matches; avoid a second MCP round trip.
|
|
566
|
+
const firstPage = [];
|
|
567
|
+
let pageBytes = 0;
|
|
568
|
+
for (const item of session.results.slice(0, MAX_SEARCH_FIRST_PAGE_RESULTS)) {
|
|
569
|
+
const size = byteSize(item);
|
|
570
|
+
if (firstPage.length > 0 && pageBytes + size > MAX_SEARCH_FIRST_PAGE_BYTES) break;
|
|
571
|
+
firstPage.push(item);
|
|
572
|
+
pageBytes += size;
|
|
573
|
+
}
|
|
504
574
|
return {
|
|
505
575
|
sessionId,
|
|
506
576
|
status: session.status,
|
|
507
577
|
totalResults: session.results.length,
|
|
508
|
-
scanned: session.scanned
|
|
578
|
+
scanned: session.scanned,
|
|
579
|
+
incomplete: session.incomplete,
|
|
580
|
+
stopReason: session.stopReason,
|
|
509
581
|
error: session.error,
|
|
582
|
+
offset: 0,
|
|
583
|
+
results: firstPage,
|
|
584
|
+
nextOffset: firstPage.length < session.results.length ? firstPage.length : null,
|
|
510
585
|
};
|
|
511
586
|
}
|
|
512
587
|
|
|
513
588
|
getSearchResults(sessionId, offset = 0, length = 50) {
|
|
514
|
-
|
|
589
|
+
this.#pruneSearchSessions();
|
|
590
|
+
const key = String(sessionId);
|
|
591
|
+
const session = this.searches.get(key);
|
|
515
592
|
if (!session) throw new Error("search_not_found");
|
|
593
|
+
session.expiresAt = Date.now() + SEARCH_SESSION_TTL_MS;
|
|
594
|
+
this.searches.delete(key);
|
|
595
|
+
this.searches.set(key, session);
|
|
596
|
+
|
|
516
597
|
const start = Math.max(Number(offset) || 0, 0);
|
|
517
598
|
const count = Math.min(Math.max(Number(length) || 50, 1), 100);
|
|
599
|
+
const results = session.results.slice(start, start + count);
|
|
600
|
+
const nextOffset = start + results.length;
|
|
518
601
|
return {
|
|
519
602
|
sessionId: session.id,
|
|
520
603
|
status: session.status,
|
|
521
604
|
totalResults: session.results.length,
|
|
605
|
+
scanned: session.scanned,
|
|
606
|
+
incomplete: session.incomplete,
|
|
607
|
+
stopReason: session.stopReason,
|
|
522
608
|
offset: start,
|
|
523
|
-
results
|
|
609
|
+
results,
|
|
610
|
+
nextOffset: nextOffset < session.results.length ? nextOffset : null,
|
|
524
611
|
error: session.error,
|
|
525
612
|
};
|
|
526
613
|
}
|
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
|
-
|
|
401
|
-
const
|
|
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
|
+
"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": {
|
|
@@ -59,12 +59,15 @@
|
|
|
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:
|
|
62
|
+
"test:file-search": "node --test test/file-search.test.mjs",
|
|
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",
|
|
63
66
|
"test:tool-guidance": "node --test test/tool-error-guidance.test.mjs",
|
|
64
67
|
"verify:review": "node scripts/verify-review-artifacts.mjs",
|
|
65
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",
|
|
66
69
|
"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",
|
|
70
|
+
"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
71
|
"test:worker-hotpath": "node --experimental-strip-types --test test/relay-result.test.mjs"
|
|
69
72
|
},
|
|
70
73
|
"dependencies": {
|