@devries-cameron20 / t3code-1 / commits / 46aa37b106
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(ssh): host discovery follows quoted Include paths (#21396)

Co-authored-by: TurpoFIN <turpofin@gmail.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Julius Marminge committed Oct 19, 2026 at 16:23 UTC 46aa37b1068c4ed7e5386049693a8519268f8207
2 files changed +75 -19
packages/ssh/src/config.test.ts
+28
@@ -19,6 +19,34 @@ function makeTempHomeDir() {
19 }
20
21 describe("ssh config", () => {
22 + it.effect("follows quoted and escaped Include paths like OpenSSH", () =>
23 + Effect.gen(function* () {
24 + const fs = yield* FileSystem.FileSystem;
25 + const path = yield* Path.Path;
26 + const homeDir = yield* makeTempHomeDir();
27 + const sshDir = path.join(homeDir, ".ssh");
28 + const quotedDir = path.join(homeDir, "quoted dir");
29 + yield* fs.makeDirectory(sshDir);
30 + yield* fs.makeDirectory(quotedDir);
31 + yield* fs.writeFileString(path.join(quotedDir, "team#1=a.conf"), "Host quoted\n");
32 + yield* fs.writeFileString(path.join(homeDir, "escaped space.conf"), "Host escaped\n");
33 + yield* fs.writeFileString(
34 + path.join(sshDir, "config"),
35 + [
36 + `Include "${path.join(quotedDir, "team#1=a.conf")}" # comment`,
37 + `Include ${path.join(homeDir, "escaped space.conf").replaceAll(" ", "\\ ")}`,
38 + "",
39 + ].join("\n"),
40 + );
41 +
42 + const hosts = yield* discoverSshHosts({ homeDir });
43 + assert.deepEqual(
44 + hosts.map((host) => host.alias),
45 + ["escaped", "quoted"],
46 + );
47 + }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
48 + );
49 +
50 it.effect("discovers ssh config hosts across included files", () =>
51 Effect.gen(function* () {
52 const fs = yield* FileSystem.FileSystem;
packages/ssh/src/config.ts
+47 -19
@@ -11,22 +11,55 @@ import { SshHostDiscoveryError } from "./errors.ts";
11
12 const NO_HOSTS: ReadonlyArray<string> = [] as const;
13
14 -function stripInlineComment(line: string): string {
15 - const hashIndex = line.indexOf("#");
16 - return (hashIndex >= 0 ? line.slice(0, hashIndex) : line).trim();
17 -}
14 +// Mirrors OpenSSH readconf: the keyword may be followed by one optional "=",
15 +// then the arguments are split like misc.c argv_split() with quotes, the
16 +// escapes \\ \" \' and unquoted "\ ", and "#" starting a comment only at
17 +// the start of a token. A line with an unterminated quote is ignored.
18 +function splitDirectiveArgs(line: string): ReadonlyArray<string> {
19 + const match = /^\s*([^\s=]+)\s*=?\s*(.*)$/u.exec(line);
20 + if (!match) {
21 + return [];
22 + }
23
19 -function splitDirectiveArgs(value: string): ReadonlyArray<string> {
20 - const args: Array<string> = [];
21 - for (const rawEntry of value
22 - .replace(/=(?!=)/gu, " ")
23 - .trim()
24 - .split(/\s+/u)) {
25 - const entry = rawEntry.trim();
26 - if (entry.length > 0) {
27 - args.push(entry);
24 + const args = [match[1]!];
25 + const rest = match[2]!;
26 + let token: string | null = null;
27 + let quote: string | null = null;
28 + for (let index = 0; index < rest.length; index += 1) {
29 + const char = rest[index]!;
30 + const next = rest[index + 1];
31 + if (
32 + char === "\\" &&
33 + (next === '"' || next === "'" || next === "\\" || (quote === null && next === " "))
34 + ) {
35 + token = (token ?? "") + next;
36 + index += 1;
37 + } else if (quote !== null) {
38 + if (char === quote) {
39 + quote = null;
40 + } else {
41 + token = (token ?? "") + char;
42 + }
43 + } else if (char === '"' || char === "'") {
44 + quote = char;
45 + token ??= "";
46 + } else if (/\s/u.test(char)) {
47 + if (token !== null) {
48 + args.push(token);
49 + token = null;
50 + }
51 + } else if (char === "#" && token === null) {
52 + break;
53 + } else {
54 + token = (token ?? "") + char;
55 }
56 }
57 + if (quote !== null) {
58 + return [];
59 + }
60 + if (token !== null) {
61 + args.push(token);
62 + }
63 return args;
64 }
65
@@ -111,12 +144,7 @@ const collectSshConfigAliasesFromFile = Effect.fnUntraced(function* (
144 const raw = yield* fs.readFileString(resolvedPath);
145
146 for (const line of raw.split(/\r?\n/u)) {
114 - const stripped = stripInlineComment(line);
115 - if (stripped.length === 0) {
116 - continue;
117 - }
118 -
119 - const [directive = "", ...rawArgs] = splitDirectiveArgs(stripped);
147 + const [directive = "", ...rawArgs] = splitDirectiveArgs(line);
148 const normalizedDirective = directive.toLowerCase();
149 if (normalizedDirective === "include") {
150 for (const includePattern of rawArgs) {