feat(ssh): use the agent AI account in new environments (#21248)

Use the agent-selected AI account for new SSH environments. Preserve
remote-machine authentication for existing environments and expose it as
an advanced option. Keep managed credentials private while preserving
supported conversation state and credential refreshes across turns.

Validated with focused route, adapter, lifecycle, and real-process tests;
final CI passed on d634944df1.
Greptile Apex reviewed that revision at 5/5 with no unresolved threads.
External neutral security reports remain documented in the pull request.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip authored and GitHub committed 2026-11-13 13:20:13 -08:00
1 parent 2a8b485140
commit 12aa08721c
77 files changed
+6115 -3898

No files matched your search

@@ -1,7 +1,8 @@
import { mkdtemp, rm } from "node:fs/promises";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { spawn } from "node:child_process";
vi.mock("node:child_process", async (importOriginal) => {
const actual = await importOriginal<typeof import("node:child_process")>();
@@ -18,10 +19,11 @@ vi.mock("node:child_process", async (importOriginal) => {
};
});
import { createSshCommandManagedRuntimeRunner } from "./ssh.js";
import { createSshCommandManagedRuntimeRunner, runSshCommand } from "./ssh.js";
const roots: string[] = [];
afterEach(async () => {
vi.unstubAllEnvs();
for (const root of roots.splice(0)) await rm(root, { recursive: true, force: true });
});
@@ -38,6 +40,23 @@ async function runner() {
}
describe("SSH command-managed argv", () => {
it.each(["spawn", "command"])("decodes with BSD-compatible flags and preserves stdin through %s", async mode => {
const bin = await mkdtemp(path.join(os.tmpdir(), "ssh-bsd-base64-"));
roots.push(bin);
await writeFile(path.join(bin, "base64"), `#!${process.execPath}\nif (process.argv.length !== 3 || process.argv[2] !== '-d') process.exit(2);\nlet text='';process.stdin.on('data', b => text+=b);process.stdin.on('end', () => process.stdout.write(Buffer.from(text,'base64')));\n`, { mode: 0o700 });
vi.stubEnv("PATH", bin + path.delimiter + process.env.PATH);
const invocation = { command: "sh", args: ["-c", 'printf "%s\\n" "$SENTINEL_TEXT"; cat'], env: { SENTINEL_TEXT: "fixture-credential" }, stdin: "provider input\n", timeoutMs: 5000 };
const result = mode === "spawn" ? await (await runner()).execute(invocation) : await runSshCommand({ host: "fixture.invalid", port: 22, username: "fixture", remoteWorkspacePath: "/tmp", privateKey: null, knownHosts: null, strictHostKeyChecking: true }, 'printf "%s\\n" "$SENTINEL_TEXT"; cat', invocation);
expect(result.stdout).toBe("fixture-credential\nprovider input\n");
});
it("delivers configured credentials without placing them in SSH process arguments and preserves provider stdin", async () => {
const token = "selected-agent-subscription-canary";
const result = await (await runner()).execute({ command: "sh", args: ["-c", 'printf "%s\\n" "$CLAUDE_CODE_OAUTH_TOKEN"; cat'],
env: { CLAUDE_CODE_OAUTH_TOKEN: token }, stdin: "provider input\n", timeoutMs: 5000 });
expect(result.exitCode).toBe(0);
expect(result.stdout).toBe(token + "\nprovider input\n");
expect(vi.mocked(spawn).mock.calls.at(-1)?.[1]?.join(" ")).not.toContain(token);
});
it("rejects environment keys that could be interpreted as env options", async () => {
await expect((await runner()).execute({ command: "true", env: { "-u": "PATH" } }))
.rejects.toThrow("Invalid SSH environment variable key");