feat(pi-ssh): add reviewed agent connection flow

This commit is contained in:
云服务部-叶林立
2026-08-21 20:52:50 +08:00
parent 0ac50eb581
commit a7891f18bf
20 changed files with 208 additions and 203 deletions
+15 -4
View File
@@ -10,6 +10,7 @@ export interface SshPermissionConnection {
export interface SshPermissionIntegrationDependencies {
getPermissionsService: () => PermissionsService | undefined;
permissionsReadyChannel: string;
getConnectTarget?: (input: Record<string, unknown>) => SshPermissionConnection | null;
warn?: (message: string) => void;
}
@@ -17,7 +18,7 @@ type PermissionIntegrationApi = Pick<ExtensionAPI, "events" | "on">;
type ToolInput = Record<string, unknown>;
const REMOTE_FILE_TOOLS = ["ssh_read", "ssh_write", "ssh_edit", "ssh_find", "ssh_grep"] as const;
const REMOTE_TOOLS = [...REMOTE_FILE_TOOLS, "ssh_bash"] as const;
const REMOTE_TOOLS = ["ssh_connect", ...REMOTE_FILE_TOOLS, "ssh_bash"] as const;
function inline(value: string, limit = 240): string {
const normalized = value.replace(/\s+/g, " ").trim();
@@ -47,6 +48,13 @@ export function formatSshPermissionInput(
const target = formatTarget(connection);
const path = stringField(input, "path");
if (toolName === "ssh_connect") {
if (connection !== null) return `${target}; establish a persistent SSH2 connection`;
const hostId = inline(stringField(input, "hostId") ?? "<unspecified>");
const remotePath = stringField(input, "remotePath");
return `requested imported SSH host '${hostId}'${remotePath ? ` in remote cwd '${inline(remotePath)}'` : ""}; establish a persistent SSH2 connection`;
}
if (toolName === "ssh_read") {
const details = path ? [`remote path '${inline(path)}'`] : ["an unspecified remote path"];
if (typeof input.offset === "number") details.push(`offset ${input.offset}`);
@@ -124,9 +132,12 @@ export function installSshPermissionIntegration(
try {
for (const toolName of REMOTE_TOOLS) {
pending.push(
service.registerToolInputFormatter(toolName, (input) =>
formatSshPermissionInput(toolName, input, getConnection()),
),
service.registerToolInputFormatter(toolName, (input) => {
const target = toolName === "ssh_connect"
? dependencies.getConnectTarget?.(input) ?? null
: getConnection();
return formatSshPermissionInput(toolName, input, target);
}),
);
}
for (const toolName of REMOTE_FILE_TOOLS) {