Files
Netcatty/electron/capabilities/catalog/sftp.cjs
T
bincxz 7ae2a33063 feat(sftp): add SCP-mode remote file browsing with Auto fallback
Some hosts (e.g. NAS/Synology root) expose SSH but not the SFTP subsystem.
Add hybrid SCP mode: shell-backed list/manage and OpenSSH scp -t/-f transfers
behind the existing SFTP UI, transfer queue, and sftp.* AI/CLI/MCP tools.

Hosts can choose Auto (SFTP then SCP), SFTP only, or force SCP. Include unit
tests and optional env-gated real OpenSSH integration tests.
2026-07-15 13:04:13 +08:00

140 lines
4.6 KiB
JavaScript

"use strict";
const { CAPABILITY_STATUS } = require("../constants.cjs");
function sftpCapability(id, description, policyOverrides, surfaces) {
return {
id,
domain: "sftp",
status: CAPABILITY_STATUS.IMPLEMENTED,
description,
policy: {
write: false,
sensitiveRead: false,
longRunning: true,
requiresChatSession: true,
bypassesObserverBlock: false,
bypassesApproval: true,
bypassesChatCancel: true,
...policyOverrides,
},
surfaces,
};
}
/** @type {import("../types.cjs").CapabilityDefinition[]} */
const SFTP_CAPABILITIES = [
sftpCapability(
"sftp.list",
"List a remote directory over the session file backend (SFTP or SCP-mode).",
{ sensitiveRead: true },
{
builtin: { rpcMethod: "netcatty/sftp/list" },
public: { rpcMethod: "public/sftp/list", mcpTool: "sftp_list", confirmInConfirmMode: true },
cli: { command: ["sftp", "list"] },
},
),
sftpCapability(
"sftp.read",
"Read a remote file over the session file backend (SFTP or SCP-mode).",
{ sensitiveRead: true },
{
builtin: { rpcMethod: "netcatty/sftp/read" },
public: { rpcMethod: "public/sftp/readFile", mcpTool: "sftp_read_file", confirmInConfirmMode: true },
cli: { command: ["sftp", "read"] },
},
),
sftpCapability(
"sftp.write",
"Write a remote file over the session file backend (SFTP or SCP-mode).",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/write" },
public: { rpcMethod: "public/sftp/writeFile", mcpTool: "sftp_write_file" },
cli: { command: ["sftp", "write"] },
},
),
sftpCapability(
"sftp.download",
"Download a remote file to a local path.",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/download" },
public: { rpcMethod: "public/sftp/download", mcpTool: "sftp_download" },
cli: { command: ["sftp", "download"] },
},
),
sftpCapability(
"sftp.upload",
"Upload a local file to a remote path.",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/upload" },
public: { rpcMethod: "public/sftp/upload", mcpTool: "sftp_upload" },
cli: { command: ["sftp", "upload"] },
},
),
sftpCapability(
"sftp.stat",
"Get remote file metadata over the session file backend (SFTP or SCP-mode).",
{ sensitiveRead: true },
{
builtin: { rpcMethod: "netcatty/sftp/stat" },
public: { rpcMethod: "public/sftp/stat", mcpTool: "sftp_stat", confirmInConfirmMode: true },
cli: { command: ["sftp", "stat"] },
},
),
sftpCapability(
"sftp.home",
"Get the remote home directory for a session.",
{ sensitiveRead: true },
{
builtin: { rpcMethod: "netcatty/sftp/home" },
public: { rpcMethod: "public/sftp/home", mcpTool: "sftp_home", confirmInConfirmMode: true },
cli: { command: ["sftp", "home"] },
},
),
sftpCapability(
"sftp.mkdir",
"Create a remote directory over the session file backend (SFTP or SCP-mode).",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/mkdir" },
public: { rpcMethod: "public/sftp/mkdir", mcpTool: "sftp_mkdir" },
cli: { command: ["sftp", "mkdir"] },
},
),
sftpCapability(
"sftp.delete",
"Delete a remote file or directory over the session file backend (SFTP or SCP-mode).",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/delete" },
public: { rpcMethod: "public/sftp/delete", mcpTool: "sftp_delete" },
cli: { command: ["sftp", "delete"] },
},
),
sftpCapability(
"sftp.rename",
"Rename a remote file or directory over the session file backend (SFTP or SCP-mode).",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/rename" },
public: { rpcMethod: "public/sftp/rename", mcpTool: "sftp_rename" },
cli: { command: ["sftp", "rename"] },
},
),
sftpCapability(
"sftp.chmod",
"Change remote file permissions over the session file backend (SFTP or SCP-mode).",
{ write: true, bypassesApproval: false, bypassesChatCancel: false },
{
builtin: { rpcMethod: "netcatty/sftp/chmod" },
public: { rpcMethod: "public/sftp/chmod", mcpTool: "sftp_chmod" },
cli: { command: ["sftp", "chmod"] },
},
),
];
module.exports = { SFTP_CAPABILITIES };