fix(pi-ssh): harden remote execution and search

This commit is contained in:
云服务部-叶林立
2026-08-24 23:04:29 +08:00
parent a7891f18bf
commit aff91b0972
30 changed files with 1063 additions and 222 deletions
+3 -4
View File
@@ -10,6 +10,7 @@ import {
} from "../src/import.ts";
import { expandUserPath } from "../src/config.ts";
import { probeHostKey, Ssh2Transport } from "../src/ssh2-transport.ts";
import { probeRemotePath } from "../src/remote-probe.ts";
import { loadVaultOrEmpty, rotateVaultKey, saveVault } from "../src/vault.ts";
async function question(prompt) {
@@ -136,10 +137,8 @@ async function importHost(config, alias) {
try {
console.log("Testing SSH2 authentication...");
await transport.connect();
const result = await transport.capture('printf "%s\\n%s" "$HOME" "$(pwd)"', ".", 20);
if (result.exitCode !== 0) throw new Error("remote HOME/cwd probe failed");
const [remoteHome, remoteCwd] = result.output.toString("utf8").trim().split(/\r?\n/, 2);
if (!remoteHome || !remoteCwd) throw new Error("remote HOME/cwd probe returned incomplete output");
await probeRemotePath(transport, "home");
const remoteCwd = await probeRemotePath(transport, "cwd");
host.defaultCwd = remoteCwd;
console.log(`Connected successfully; default cwd: ${remoteCwd}`);
} finally {