@anusornneal/chat-relay 1.2.3 → 1.3.1
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.
|
@@ -310,7 +310,35 @@ export class DesktopManager {
|
|
|
310
310
|
return this.runControl(() => this.runner("mouse_click", { x, y, button, clicks }));
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
async
|
|
313
|
+
async clickImageTarget(input = {}) {
|
|
314
|
+
const gate = this.gate();
|
|
315
|
+
if (gate) return gate;
|
|
316
|
+
const { imageWidth, imageHeight, desktopOriginX, desktopOriginY, desktopWidth, desktopHeight } = input;
|
|
317
|
+
const numbers = [imageWidth, imageHeight, desktopOriginX, desktopOriginY, desktopWidth, desktopHeight, input.x, input.y];
|
|
318
|
+
if (numbers.some((value) => !Number.isFinite(value)) ||
|
|
319
|
+
!numbers.every(Number.isInteger) ||
|
|
320
|
+
imageWidth <= 0 || imageHeight <= 0 || desktopWidth <= 0 || desktopHeight <= 0 ||
|
|
321
|
+
input.x < 0 || input.x >= imageWidth || input.y < 0 || input.y >= imageHeight) {
|
|
322
|
+
return { ok: false, error: "invalid_image_coordinates" };
|
|
323
|
+
}
|
|
324
|
+
const targetWidth = input.targetWidth ?? 1;
|
|
325
|
+
const targetHeight = input.targetHeight ?? 1;
|
|
326
|
+
if (![targetWidth, targetHeight].every(Number.isInteger) ||
|
|
327
|
+
targetWidth <= 0 || targetHeight <= 0 ||
|
|
328
|
+
input.x + targetWidth > imageWidth || input.y + targetHeight > imageHeight) {
|
|
329
|
+
return { ok: false, error: "invalid_target_bounds" };
|
|
330
|
+
}
|
|
331
|
+
const x = desktopOriginX + Math.floor((input.x + targetWidth / 2) * desktopWidth / imageWidth);
|
|
332
|
+
const y = desktopOriginY + Math.floor((input.y + targetHeight / 2) * desktopHeight / imageHeight);
|
|
333
|
+
const button = String(input.button || "left").toLowerCase();
|
|
334
|
+
const clicks = Number(input.clicks ?? 1);
|
|
335
|
+
if (!["left", "right", "middle"].includes(button)) return { ok: false, error: "invalid_button" };
|
|
336
|
+
if (clicks !== 1 && clicks !== 2) return { ok: false, error: "invalid_click_count" };
|
|
337
|
+
return this.runControl(async () => {
|
|
338
|
+
const result = await this.runner("mouse_click", { x, y, button, clicks });
|
|
339
|
+
return { ...result, target: { x, y, source: "image", verified: false } };
|
|
340
|
+
});
|
|
341
|
+
} async keyboardInput(input = {}) {
|
|
314
342
|
const gate = this.gate();
|
|
315
343
|
if (gate) return gate;
|
|
316
344
|
|
package/agent/local-agent.mjs
CHANGED
|
@@ -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,
|
|
@@ -246,6 +247,8 @@ async function handlePayload(payload) {
|
|
|
246
247
|
return desktop.listWindows(payload);
|
|
247
248
|
case "desktop.window.focus":
|
|
248
249
|
return desktop.focusWindow(payload);
|
|
250
|
+
case "desktop.mouse.click_image":
|
|
251
|
+
return desktop.clickImageTarget(payload);
|
|
249
252
|
case "desktop.mouse.click":
|
|
250
253
|
return desktop.mouseClick(payload);
|
|
251
254
|
case "desktop.keyboard.input":
|
|
@@ -558,7 +561,10 @@ function connect() {
|
|
|
558
561
|
responseBytes,
|
|
559
562
|
...(result && typeof result === "object" && result.ok === false && result.error ? { error: String(result.error) } : {}),
|
|
560
563
|
});
|
|
561
|
-
|
|
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);
|
|
562
568
|
} catch (error) {
|
|
563
569
|
recentCalls.push({
|
|
564
570
|
at: new Date().toISOString(),
|
|
@@ -586,7 +592,7 @@ function connect() {
|
|
|
586
592
|
responseBytes,
|
|
587
593
|
error: errorPayload.error,
|
|
588
594
|
});
|
|
589
|
-
sendSocketResponse(socket, message.requestId, errorPayload);
|
|
595
|
+
sendSocketResponse(socket, message.requestId, { ...errorPayload, ...toolErrorGuidance(action, errorPayload.error, message.payload) });
|
|
590
596
|
}
|
|
591
597
|
});
|
|
592
598
|
|
|
@@ -29,13 +29,14 @@ const MAX_RETAINED_BATCHES = 64;
|
|
|
29
29
|
const ENDED_TTL_MS = 30 * 60 * 1000;
|
|
30
30
|
|
|
31
31
|
const BLOCKED_COMMANDS = [
|
|
32
|
-
/\b(mkfs|
|
|
32
|
+
/\b(mkfs|mount|umount|fdisk|dd|parted|diskpart|sudo|su|passwd)\b/i,
|
|
33
|
+
/\bformat\b(?!-(?:List|Table)\b)/i,
|
|
33
34
|
/\b(adduser|useradd|usermod|groupadd|chsh|visudo|shutdown|reboot|halt)\b/i,
|
|
34
35
|
/\b(poweroff|init|iptables|firewall|netsh|sfc|bcdedit|runas|cipher|takeown)\b/i,
|
|
35
36
|
/\b(reg|sc)\.exe\b/i,
|
|
36
37
|
];
|
|
37
38
|
|
|
38
|
-
function validateCommand(command) {
|
|
39
|
+
export function validateCommand(command) {
|
|
39
40
|
if (typeof command !== "string" || command.length === 0 || command.length > 4000) {
|
|
40
41
|
throw new Error("invalid_command");
|
|
41
42
|
}
|
|
@@ -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
|
+
}
|
|
@@ -247,6 +247,8 @@ export function humanizeToolCall(payload = {}) {
|
|
|
247
247
|
return "List open windows";
|
|
248
248
|
case "desktop.window.focus":
|
|
249
249
|
return `Focus window · ${cleanText(payload.title ?? payload.windowId ?? payload.handle ?? "", 64)}`;
|
|
250
|
+
case "desktop.mouse.click_image":
|
|
251
|
+
return "Click screenshot target";
|
|
250
252
|
case "desktop.mouse.click": {
|
|
251
253
|
const button = cleanText(payload.button || "left", 12);
|
|
252
254
|
return `${button[0]?.toUpperCase() || "L"}${button.slice(1)} click`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anusornneal/chat-relay",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|