SSH extension: evaluate pwd on remote when no path given, use accent color for status

This commit is contained in:
Mario Zechner 2026-01-08 20:37:56 +01:00
parent b0e5954cf8
commit dc54c308a9

View file

@ -120,12 +120,10 @@ export default function (pi: ExtensionAPI) {
const localEdit = createEditTool(localCwd); const localEdit = createEditTool(localCwd);
const localBash = createBashTool(localCwd); const localBash = createBashTool(localCwd);
const getSsh = () => { // Resolved lazily on session_start (CLI flags not available during factory)
const arg = pi.getFlag("ssh") as string | undefined; let resolvedSsh: { remote: string; remoteCwd: string } | null = null;
if (!arg) return null;
const [remote, path] = arg.includes(":") ? arg.split(":") : [arg, "~"]; const getSsh = () => resolvedSsh;
return { remote, remoteCwd: path };
};
pi.registerTool({ pi.registerTool({
...localRead, ...localRead,
@ -184,10 +182,20 @@ export default function (pi: ExtensionAPI) {
}); });
pi.on("session_start", async (_event, ctx) => { pi.on("session_start", async (_event, ctx) => {
const ssh = getSsh(); // Resolve SSH config now that CLI flags are available
if (ssh) { const arg = pi.getFlag("ssh") as string | undefined;
ctx.ui.setStatus("ssh", `SSH: ${ssh.remote}:${ssh.remoteCwd}`); if (arg) {
ctx.ui.notify(`SSH mode: ${ssh.remote}:${ssh.remoteCwd}`, "info"); if (arg.includes(":")) {
const [remote, path] = arg.split(":");
resolvedSsh = { remote, remoteCwd: path };
} else {
// No path given, evaluate pwd on remote
const remote = arg;
const pwd = (await sshExec(remote, "pwd")).toString().trim();
resolvedSsh = { remote, remoteCwd: pwd };
}
ctx.ui.setStatus("ssh", ctx.ui.theme.fg("accent", `SSH: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`));
ctx.ui.notify(`SSH mode: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`, "info");
} }
}); });