@devries-cameron20 / t3code-1 / commits / c0b08fa1f5
Fork 0

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

fix(ssh): host discovery follows Include globs in directory components (#35771)

Julius Marminge committed Nov 12, 2026 at 17:51 UTC c0b08fa1f5665166baf9161374faa57d3ddc7053
2 files changed +49 -17
packages/ssh/src/config.test.ts
+17
@@ -127,6 +127,11 @@ describe("ssh config", () => {
127 const homeDir = yield* makeTempHomeDir();
128 const sshDir = path.join(homeDir, ".ssh");
129 yield* fs.makeDirectory(path.join(sshDir, "config.d"), { recursive: true });
130 + yield* fs.makeDirectory(path.join(sshDir, "teams", "one"), { recursive: true });
131 + const blockedDir = path.join(sshDir, "teams", "blocked");
132 + yield* fs.makeDirectory(blockedDir);
133 + yield* fs.chmod(blockedDir, 0o000);
134 + yield* Effect.addFinalizer(() => fs.chmod(blockedDir, 0o755).pipe(Effect.ignore));
135 yield* fs.writeFileString(
136 path.join(sshDir, "config"),
137 [
@@ -135,9 +140,14 @@ describe("ssh config", () => {
140 "Host=equalsbox",
141 "Host *",
142 "Include=config.d/*.conf",
143 + "Include teams/*/*.conf",
144 "",
145 ].join("\n"),
146 );
147 + yield* fs.writeFileString(
148 + path.join(sshDir, "teams", "one", "hosts.conf"),
149 + "Host fixture\n HostName fixture.example.com\n",
150 + );
151 yield* fs.writeFileString(
152 path.join(sshDir, "config.d", "team.conf"),
153 [
@@ -190,6 +200,13 @@ describe("ssh config", () => {
200 port: null,
201 source: "ssh-config",
202 },
203 + {
204 + alias: "fixture",
205 + hostname: "fixture.example.com",
206 + username: null,
207 + port: null,
208 + source: "ssh-config",
209 + },
210 {
211 alias: "known.example.com",
212 hostname: "known.example.com",
packages/ssh/src/config.ts
+32 -17
@@ -97,30 +97,46 @@ function globToRegExp(pattern: string): RegExp {
97 );
98 }
99
100 -const expandGlob = Effect.fnUntraced(function* (pattern: string) {
100 +function hasGlobWildcard(value: string): boolean {
101 + return value.includes("*") || value.includes("?");
102 +}
103 +
104 +const expandGlob = Effect.fnUntraced(function* (
105 + pattern: string,
106 +): Effect.fn.Return<
107 + ReadonlyArray<string>,
108 + PlatformError.PlatformError,
109 + FileSystem.FileSystem | Path.Path
110 +> {
111 const fs = yield* FileSystem.FileSystem;
112 const path = yield* Path.Path;
103 - if (!pattern.includes("*") && !pattern.includes("?")) {
113 + if (!hasGlobWildcard(pattern)) {
114 return (yield* fs.exists(pattern)) ? [pattern] : NO_HOSTS;
115 }
116
107 - const directory = path.dirname(pattern);
117 + const directoryPattern = path.dirname(pattern);
118 const basePattern = path.basename(pattern);
109 - if (!(yield* fs.exists(directory))) {
110 - return NO_HOSTS;
111 - }
119 + const directoryIsGlob = hasGlobWildcard(directoryPattern);
120 + const directories = directoryIsGlob ? yield* expandGlob(directoryPattern) : [directoryPattern];
121
122 const matcher = globToRegExp(basePattern);
114 - const entries = yield* fs.readDirectory(directory);
123 const matchedPaths: string[] = [];
116 - for (const entry of entries) {
117 - if (entry.startsWith(".") && !basePattern.startsWith(".")) continue;
118 - if (!matcher.test(entry)) {
119 - continue;
120 - }
121 - const entryPath = path.join(directory, entry);
122 - if (yield* fs.exists(entryPath)) {
123 - matchedPaths.push(entryPath);
124 + for (const directory of directories) {
125 + if (!(yield* fs.exists(directory))) continue;
126 + if ((yield* fs.stat(directory)).type !== "Directory") continue;
127 + // Like OpenSSH's glob, a wildcard-matched directory we cannot read matches nothing.
128 + const entries = directoryIsGlob
129 + ? yield* fs.readDirectory(directory).pipe(Effect.orElseSucceed(() => NO_HOSTS))
130 + : yield* fs.readDirectory(directory);
131 + for (const entry of entries) {
132 + if (entry.startsWith(".") && !basePattern.startsWith(".")) continue;
133 + if (!matcher.test(entry)) {
134 + continue;
135 + }
136 + const entryPath = path.join(directory, entry);
137 + if (yield* fs.exists(entryPath)) {
138 + matchedPaths.push(entryPath);
139 + }
140 }
141 }
142 return matchedPaths.toSorted();
@@ -246,8 +262,7 @@ const collectSshConfigAliasesFromFile = Effect.fnUntraced(function* (
262 );
263 if (
264 /%|\$\{|\[/u.test(includePattern) ||
249 - (includePattern.startsWith("~") && !/^~(?=$|\/|\\)/u.test(includePattern)) ||
250 - hasSshPattern(path.dirname(resolvedPattern))
265 + (includePattern.startsWith("~") && !/^~(?=$|\/|\\)/u.test(includePattern))
266 ) {
267 hostNameRules.push({ conditions, directive: null, value: null });
268 continue;