@anusornneal/chat-relay 1.3.0 → 1.3.2

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.
@@ -14,6 +14,7 @@ import {
14
14
  summarizeAgentWork,
15
15
  } from "./lifecycle.mjs";
16
16
  import { humanizeToolCall } from "./toolcall-summary.mjs";
17
+ import { toolErrorGuidance } from "./tool-error-guidance.mjs";
17
18
  import {
18
19
  HeartbeatAckWatchdog,
19
20
  HEARTBEAT_ACK_TIMEOUT_REASON,
@@ -560,7 +561,10 @@ function connect() {
560
561
  responseBytes,
561
562
  ...(result && typeof result === "object" && result.ok === false && result.error ? { error: String(result.error) } : {}),
562
563
  });
563
- sendSocketResponse(socket, message.requestId, result, responseMeta);
564
+ const advised = result && typeof result === "object" && result.ok === false && result.error
565
+ ? { ...result, ...toolErrorGuidance(action, String(result.error), message.payload) }
566
+ : result;
567
+ sendSocketResponse(socket, message.requestId, advised, responseMeta);
564
568
  } catch (error) {
565
569
  recentCalls.push({
566
570
  at: new Date().toISOString(),
@@ -588,7 +592,7 @@ function connect() {
588
592
  responseBytes,
589
593
  error: errorPayload.error,
590
594
  });
591
- sendSocketResponse(socket, message.requestId, errorPayload);
595
+ sendSocketResponse(socket, message.requestId, { ...errorPayload, ...toolErrorGuidance(action, errorPayload.error, message.payload) });
592
596
  }
593
597
  });
594
598
 
@@ -29,13 +29,16 @@ const MAX_RETAINED_BATCHES = 64;
29
29
  const ENDED_TTL_MS = 30 * 60 * 1000;
30
30
 
31
31
  const BLOCKED_COMMANDS = [
32
- /\b(mkfs|format|mount|umount|fdisk|dd|parted|diskpart|sudo|su|passwd)\b/i,
32
+ /\b(mkfs|mount|umount|fdisk|dd|parted|diskpart|sudo|su|passwd)\b/i,
33
+ // Match disk formatting as a command, not a filename, argument or Git flag.
34
+ /(?:^|[;|&]\s*|\$\(\s*)(?:\s*&\s*)?(?:format(?:\.(?:exe|com))?|Format-Volume)(?=\s|$|[;|&)]|\/)/i,
35
+ /\bcmd(?:\.exe)?\s+\/[ck]\s+(?:\"|')?format(?:\.(?:exe|com))?(?=\s|$)/i,
33
36
  /\b(adduser|useradd|usermod|groupadd|chsh|visudo|shutdown|reboot|halt)\b/i,
34
37
  /\b(poweroff|init|iptables|firewall|netsh|sfc|bcdedit|runas|cipher|takeown)\b/i,
35
38
  /\b(reg|sc)\.exe\b/i,
36
39
  ];
37
40
 
38
- function validateCommand(command) {
41
+ export function validateCommand(command) {
39
42
  if (typeof command !== "string" || command.length === 0 || command.length > 4000) {
40
43
  throw new Error("invalid_command");
41
44
  }
@@ -0,0 +1,41 @@
1
+ // Actionable advice for deterministic, non-retryable tool failures.
2
+ // This is presentation metadata only: security checks remain in their original handlers.
3
+ export function toolErrorGuidance(action, message, input = {}) {
4
+ if (typeof message !== "string") return {};
5
+ const code = message.split(":", 1)[0];
6
+ if (code === "command_blocked") {
7
+ const command = typeof input.command === "string" ? input.command : "";
8
+ const processQuery = /\b(Get-CimInstance|Win32_Process|Get-Process|tasklist)\b/i.test(command);
9
+ const fileQuery = /\b(Select-String|findstr|rg|grep)\b/i.test(command);
10
+ return {
11
+ errorCode: code,
12
+ retryable: false,
13
+ reason: "The terminal safety policy rejected this command before execution.",
14
+ suggestedTool: processQuery ? "list_processes" : fileQuery ? "start_search" : "get_config",
15
+ suggestedAction: processQuery
16
+ ? "Use list_processes for process inspection instead of shell process enumeration."
17
+ : fileQuery
18
+ ? "Use start_search with an allowed path for file/content search."
19
+ : "Inspect available capabilities; do not retry unchanged or bypass the terminal policy.",
20
+ };
21
+ }
22
+ if (code === "path_not_allowed") {
23
+ return {
24
+ errorCode: code,
25
+ retryable: false,
26
+ reason: "The requested path is outside the agent's authorized filesystem roots.",
27
+ suggestedTool: "get_config",
28
+ suggestedAction: "Check allowedRoots and use paths within them. Access elsewhere requires an authorized root configuration change; do not bypass using terminal commands.",
29
+ };
30
+ }
31
+ if (code === "replacement_count_mismatch") {
32
+ return {
33
+ errorCode: code,
34
+ retryable: false,
35
+ reason: "The exact edit text does not match the expected occurrence count in the current file.",
36
+ suggestedTool: "read_file",
37
+ suggestedAction: "Read the current file contents, then retry edit_block with fresh exact oldText; do not retry the same stale replacement.",
38
+ };
39
+ }
40
+ return {};
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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": {
@@ -55,7 +55,8 @@
55
55
  "test:self-update": "node --test test/self-update.test.mjs test/agent-lifecycle-upgrade.test.mjs",
56
56
  "test:budget": "node --test test/relay-health.test.mjs test/usage-budget.test.mjs",
57
57
  "test:soak": "node test/soak-smoke.mjs",
58
- "test:hardening": "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",
58
+ "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",
59
+ "test:tool-guidance": "node --test test/tool-error-guidance.test.mjs",
59
60
  "verify:review": "node scripts/verify-review-artifacts.mjs",
60
61
  "test:learn": "node test/learning-smoke.mjs",
61
62
  "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs",