Skip to content

Commit 224086e

Browse files
committed
fix(file-transfer): clarify missing paired node errors
When no nodes are paired, file-transfer tools now fail before node alias resolution with an actionable message instead of generic unknown-node retries. The paired-node schema wording also steers agents away from local/host/gateway/auto guesses.\n\nFixes #91482.
1 parent 5f6d427 commit 224086e

3 files changed

Lines changed: 63 additions & 5 deletions

File tree

‎extensions/file-transfer/src/tools/descriptors.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
2020
export const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024;
2121
export const FILE_WRITE_HARD_MAX_BYTES = 16 * 1024 * 1024;
2222

23+
const PAIRED_NODE_DESCRIPTION =
24+
"Existing paired node id, display name, or IP shown by nodes status. Do not use local, host, gateway, or auto; use local file/exec tools for local workspace paths.";
25+
2326
export const FileFetchToolSchema = Type.Object({
2427
node: Type.String({
25-
description: "Node id, name, or IP. Resolves the same way as the nodes tool.",
28+
description: PAIRED_NODE_DESCRIPTION,
2629
}),
2730
path: Type.String({
2831
description: "Absolute path to the file on the node. Canonicalized server-side.",
@@ -45,7 +48,7 @@ export const FILE_FETCH_TOOL_DESCRIPTOR: FileTransferToolDescriptor = {
4548

4649
export const DirListToolSchema = Type.Object({
4750
node: Type.String({
48-
description: "Node id, name, or IP. Resolves the same way as the nodes tool.",
51+
description: PAIRED_NODE_DESCRIPTION,
4952
}),
5053
path: Type.String({
5154
description: "Absolute path to the directory on the node. Canonicalized server-side.",
@@ -68,13 +71,13 @@ export const DIR_LIST_TOOL_DESCRIPTOR: FileTransferToolDescriptor = {
6871
label: "Directory List",
6972
name: "dir_list",
7073
description:
71-
"Retrieve a structured directory listing from a paired node. Returns file and subdirectory metadata (name, path, size, mimeType, isDir, mtime) without transferring file content. Use this to discover what files exist before fetching them with file_fetch. Pagination is offset-based; pass nextPageToken from the previous result. Requires operator opt-in: gateway.nodes.allowCommands must include 'dir.list' AND plugins.entries.file-transfer.config.nodes.<node>.allowReadPaths must match the directory path. Without policy configured, every call is denied.",
74+
"Retrieve a structured directory listing from a paired node, not the local workspace. Returns file and subdirectory metadata (name, path, size, mimeType, isDir, mtime) without transferring file content. Use this to discover what files exist before fetching them with file_fetch. Pagination is offset-based; pass nextPageToken from the previous result. Requires operator opt-in: gateway.nodes.allowCommands must include 'dir.list' AND plugins.entries.file-transfer.config.nodes.<node>.allowReadPaths must match the directory path. Without policy configured, every call is denied.",
7275
parameters: DirListToolSchema,
7376
};
7477

7578
export const DirFetchToolSchema = Type.Object({
7679
node: Type.String({
77-
description: "Node id, name, or IP. Resolves the same way as the nodes tool.",
80+
description: PAIRED_NODE_DESCRIPTION,
7881
}),
7982
path: Type.String({
8083
description: "Absolute path to the directory on the node to fetch. Canonicalized server-side.",
@@ -102,7 +105,7 @@ export const DIR_FETCH_TOOL_DESCRIPTOR: FileTransferToolDescriptor = {
102105
};
103106

104107
export const FileWriteToolSchema = Type.Object({
105-
node: Type.String({ description: "Node id or display name to write the file on." }),
108+
node: Type.String({ description: PAIRED_NODE_DESCRIPTION }),
106109
path: Type.String({
107110
description: "Absolute path on the node to write. Canonicalized server-side.",
108111
}),
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// File Transfer tests cover dir list tool plugin behavior.
2+
import {
3+
callGatewayTool,
4+
listNodes,
5+
resolveNodeIdFromList,
6+
} from "openclaw/plugin-sdk/agent-harness-runtime";
7+
import { afterEach, describe, expect, it, vi } from "vitest";
8+
import { createDirListTool } from "./dir-list-tool.js";
9+
10+
vi.mock("openclaw/plugin-sdk/agent-harness-runtime", () => ({
11+
callGatewayTool: vi.fn(),
12+
listNodes: vi.fn(),
13+
resolveNodeIdFromList: vi.fn(),
14+
}));
15+
16+
vi.mock("../shared/audit.js", () => ({
17+
appendFileTransferAudit: vi.fn(),
18+
}));
19+
20+
afterEach(() => {
21+
vi.mocked(callGatewayTool).mockReset();
22+
vi.mocked(listNodes).mockReset();
23+
vi.mocked(resolveNodeIdFromList).mockReset();
24+
});
25+
26+
describe("dir_list tool", () => {
27+
it("reports missing paired nodes before retrying guessed local node names", async () => {
28+
vi.mocked(listNodes).mockResolvedValue([]);
29+
30+
await expect(
31+
createDirListTool().execute("tool-call-1", {
32+
node: "local",
33+
path: "/tmp/project",
34+
}),
35+
).rejects.toThrow(
36+
"no paired nodes available; file-transfer tools require a paired node from nodes status. Use local file/exec tools for local workspace paths.",
37+
);
38+
39+
expect(resolveNodeIdFromList).not.toHaveBeenCalled();
40+
expect(callGatewayTool).not.toHaveBeenCalled();
41+
});
42+
43+
it("describes node as a paired-node reference, not a local alias", () => {
44+
const schema = JSON.stringify(createDirListTool().parameters);
45+
46+
expect(schema).toContain("Existing paired node id");
47+
expect(schema).toContain("nodes status");
48+
expect(schema).toContain("local, host, gateway, or auto");
49+
});
50+
});

‎extensions/file-transfer/src/tools/node-tool-invoke.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export async function invokeNodeToolPayload(input: {
4848
}> {
4949
const gatewayOpts = readGatewayCallOptions(input.params);
5050
const nodes: NodeListNode[] = await listNodes(gatewayOpts);
51+
if (nodes.length === 0) {
52+
throw new Error(
53+
"no paired nodes available; file-transfer tools require a paired node from nodes status. Use local file/exec tools for local workspace paths.",
54+
);
55+
}
5156
const nodeId = resolveNodeIdFromList(nodes, input.node, false);
5257
const nodeMeta = nodes.find((n) => n.nodeId === nodeId);
5358
const nodeDisplayName = nodeMeta?.displayName ?? input.node;

0 commit comments

Comments
 (0)