@cleocode/adapters 2026.11.4 → 2026.11.5-rc.ci.721
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.source-stamp.json +1 -1
- package/dist/index.js +268 -14
- package/dist/index.js.map +2 -2
- package/dist/orca-execution.d.ts +7 -0
- package/dist/orca-execution.d.ts.map +1 -1
- package/dist/orca-execution.js +33 -4
- package/dist/orca-execution.js.map +1 -1
- package/dist/providers/claude-code/index.js +268 -13
- package/dist/providers/claude-code/index.js.map +2 -2
- package/dist/providers/claude-code/lead-mcp.d.ts +27 -0
- package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +6 -2
- package/dist/providers/claude-sdk/index.js.map +1 -1
- package/dist/providers/codex/index.js +6 -2
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/gemini-cli/index.js +6 -2
- package/dist/providers/gemini-cli/index.js.map +1 -1
- package/dist/providers/kimi/index.js +6 -2
- package/dist/providers/kimi/index.js.map +1 -1
- package/dist/providers/openai-sdk/index.js +6 -2
- package/dist/providers/openai-sdk/index.js.map +1 -1
- package/dist/providers/opencode/index.js +6 -2
- package/dist/providers/opencode/index.js.map +1 -1
- package/dist/providers/pi/index.js +6 -2
- package/dist/providers/pi/index.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/orca-execution-fixture.ts +39 -1
- package/src/__tests__/orca-execution.test.ts +58 -0
- package/src/orca-execution.ts +39 -4
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +154 -1
- package/src/providers/claude-code/lead-mcp.ts +403 -13
|
@@ -24,13 +24,14 @@ import {
|
|
|
24
24
|
lstatSync,
|
|
25
25
|
readdirSync,
|
|
26
26
|
readFileSync,
|
|
27
|
+
readlinkSync,
|
|
27
28
|
realpathSync,
|
|
28
29
|
type Stats,
|
|
29
30
|
statSync,
|
|
30
31
|
} from 'node:fs';
|
|
31
32
|
import { writeFile } from 'node:fs/promises';
|
|
32
33
|
import { homedir } from 'node:os';
|
|
33
|
-
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
34
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, win32 } from 'node:path';
|
|
34
35
|
import type { LeadMcpReport } from '@cleocode/contracts';
|
|
35
36
|
import {
|
|
36
37
|
LEAD_MAILBOX_MCP_SERVER,
|
|
@@ -91,23 +92,412 @@ function readJson(file: string): unknown {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
/**
|
|
95
|
-
|
|
95
|
+
/**
|
|
96
|
+
* The host facts Claude Code 2.1.322's unsafe-path rule reads. Its macOS
|
|
97
|
+
* build also refuses automounted `/network/...` paths and, when `/home` is an
|
|
98
|
+
* automount, another user's `/home/<user>`.
|
|
99
|
+
*/
|
|
100
|
+
export interface ClaudePathHost {
|
|
101
|
+
/** Claude's macOS automount rules apply (the darwin build). */
|
|
102
|
+
readonly darwin: boolean;
|
|
103
|
+
/** `/home` is an automount: `/etc/auto_master` maps it, or it is its own mount. */
|
|
104
|
+
readonly homeAutomount: boolean;
|
|
105
|
+
/** The home directory of the Claude process judged (its `os.homedir()`, from its own HOME). */
|
|
106
|
+
readonly home: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let homeAutomountMemo: boolean | undefined;
|
|
110
|
+
|
|
111
|
+
/** True for a missing-path error (`ENOENT`). */
|
|
112
|
+
function isEnoent(err: unknown): boolean {
|
|
113
|
+
return err instanceof Error && 'code' in err && err.code === 'ENOENT';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Claude's `/home` automount probe; any unexpected failure counts as automounted. */
|
|
117
|
+
function homeIsAutomount(): boolean {
|
|
118
|
+
try {
|
|
119
|
+
let mapped = false;
|
|
120
|
+
try {
|
|
121
|
+
mapped = readFileSync('/etc/auto_master', 'utf8')
|
|
122
|
+
.split('\n')
|
|
123
|
+
.some((line) => {
|
|
124
|
+
const fields = line.replace(/#.*$/, '').trim().split(/\s+/);
|
|
125
|
+
return fields.length >= 2 && fields[0]?.toLowerCase() === '/home';
|
|
126
|
+
});
|
|
127
|
+
} catch (err) {
|
|
128
|
+
if (!isEnoent(err)) throw err;
|
|
129
|
+
}
|
|
130
|
+
if (mapped) return true;
|
|
131
|
+
try {
|
|
132
|
+
return statSync('/home').dev !== statSync('/Users').dev;
|
|
133
|
+
} catch (err) {
|
|
134
|
+
if (isEnoent(err)) return true;
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* This machine's {@link ClaudePathHost} for a Claude process whose home is
|
|
144
|
+
* `home`; the `/home` probe runs once per process, as in Claude.
|
|
145
|
+
*/
|
|
146
|
+
function claudePathHost(home: string = homedir()): ClaudePathHost {
|
|
147
|
+
const darwin = process.platform === 'darwin';
|
|
148
|
+
if (darwin) homeAutomountMemo ??= homeIsAutomount();
|
|
149
|
+
return { darwin, homeAutomount: homeAutomountMemo ?? false, home };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const lowerAscii = (text: string): string => text.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
153
|
+
const foldCase = (text: string): string => text.toUpperCase().toLowerCase();
|
|
154
|
+
const foldVisible = (text: string): string => foldCase(text.replace(/[---]/g, ''));
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Claude's lexical walk of an absolute path (`.` skipped, `..` pops), calling
|
|
158
|
+
* `visit` after each pushed component; returns the parts left at the end, or
|
|
159
|
+
* `null` for a relative path.
|
|
160
|
+
*/
|
|
161
|
+
function walkParts(path: string, visit?: (parts: readonly string[]) => void): string[] | null {
|
|
162
|
+
if (!path.startsWith('/')) return null;
|
|
163
|
+
const parts: string[] = [];
|
|
164
|
+
for (const part of path.split('/')) {
|
|
165
|
+
if (part === '' || part === '.') continue;
|
|
166
|
+
if (part === '..') {
|
|
167
|
+
parts.pop();
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
parts.push(part);
|
|
171
|
+
visit?.(parts);
|
|
172
|
+
}
|
|
173
|
+
return parts;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** `/net/<host>` or `/Network/Servers/<host>` (Claude's `v`). */
|
|
177
|
+
function isNetMount(parts: readonly string[]): boolean {
|
|
178
|
+
const [first = '', second = ''] = parts;
|
|
179
|
+
return (
|
|
180
|
+
(parts.length === 2 && foldVisible(first) === 'net') ||
|
|
181
|
+
(parts.length === 3 && foldVisible(first) === 'network' && foldVisible(second) === 'servers')
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The network host a path is mounted from, lowercased, or `null` (Claude's `nK`). */
|
|
186
|
+
function netHost(path: string): string | null {
|
|
187
|
+
let host: string | null = null;
|
|
188
|
+
walkParts(path, (parts) => {
|
|
189
|
+
if (host === null && isNetMount(parts)) host = lowerAscii(parts.at(-1) ?? '');
|
|
190
|
+
});
|
|
191
|
+
return host;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** First component equals `name` under `test` (Claude's `k$` and `sb` walks). */
|
|
195
|
+
function firstPartIs(path: string, test: (part: string) => boolean): boolean {
|
|
196
|
+
let first: string | undefined;
|
|
197
|
+
walkParts(path, (parts) => {
|
|
198
|
+
if (parts.length === 1 && first === undefined && test(parts[0] ?? '')) first = parts[0];
|
|
199
|
+
});
|
|
200
|
+
return first !== undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const underNetwork = (path: string): boolean =>
|
|
204
|
+
firstPartIs(path, (part) => part.toLowerCase() === 'network');
|
|
205
|
+
const underVolfs = (path: string): boolean =>
|
|
206
|
+
/\/\.(?:vol|file|nofollow|resolve)(?:\/|$)/i.test(path) &&
|
|
207
|
+
firstPartIs(path, (part) => /^\.(?:vol|file|nofollow|resolve)$/i.test(part));
|
|
208
|
+
const isNetRoot = (path: string): boolean => {
|
|
209
|
+
const parts = walkParts(path);
|
|
210
|
+
return parts?.length === 1 && parts[0]?.toLowerCase() === 'net';
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/** macOS `/System/Volumes/Data/<firmlinked>` spelled as its firmlink (Claude's `u0`). */
|
|
214
|
+
function dataVolumeAlias(path: string): string {
|
|
215
|
+
const parts = path.split('/');
|
|
216
|
+
const [root, system = '', volumes = '', data = ''] = parts;
|
|
217
|
+
if (
|
|
218
|
+
parts.length < 5 ||
|
|
219
|
+
root !== '' ||
|
|
220
|
+
foldCase(system) !== 'system' ||
|
|
221
|
+
foldCase(volumes) !== 'volumes' ||
|
|
222
|
+
foldCase(data) !== 'data'
|
|
223
|
+
)
|
|
224
|
+
return path;
|
|
225
|
+
const rest = parts.slice(4);
|
|
226
|
+
for (const link of FIRMLINKS) {
|
|
227
|
+
const linkParts = link.split('/');
|
|
228
|
+
if (
|
|
229
|
+
rest.length >= linkParts.length &&
|
|
230
|
+
linkParts.every((part, i) => foldCase(rest[i] ?? '') === foldCase(part))
|
|
231
|
+
)
|
|
232
|
+
return `/${rest.join('/')}`;
|
|
233
|
+
}
|
|
234
|
+
return path;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const FIRMLINKS = [
|
|
238
|
+
'usr/local',
|
|
239
|
+
'usr/libexec/cups',
|
|
240
|
+
'usr/share/snmp',
|
|
241
|
+
'AppleInternal',
|
|
242
|
+
'Applications',
|
|
243
|
+
'Library',
|
|
244
|
+
'Users',
|
|
245
|
+
'Volumes',
|
|
246
|
+
'cores',
|
|
247
|
+
'home',
|
|
248
|
+
'media',
|
|
249
|
+
'mnt',
|
|
250
|
+
'opt',
|
|
251
|
+
'pkg',
|
|
252
|
+
'private',
|
|
253
|
+
'sw',
|
|
254
|
+
] as const;
|
|
255
|
+
|
|
256
|
+
/** Automount prefixes a path reaches, up to six components deep (Claude's `Q`). */
|
|
257
|
+
function automountPrefixes(
|
|
258
|
+
path: string,
|
|
259
|
+
host: ClaudePathHost,
|
|
260
|
+
): { complete: string[]; partial: string[] } {
|
|
261
|
+
const complete: string[] = [];
|
|
262
|
+
const partial: string[] = [];
|
|
263
|
+
walkParts(path, (parts) => {
|
|
264
|
+
if (parts.length > 6) return;
|
|
265
|
+
const spelled = `/${parts.join('/')}`;
|
|
266
|
+
const at = (host.darwin ? dataVolumeAlias(spelled) : spelled).split('/').filter(Boolean);
|
|
267
|
+
const [first = '', second = '', third = ''] = at;
|
|
268
|
+
if (first.toLowerCase() === 'network') {
|
|
269
|
+
if (at.length === 1) partial.push('/network/');
|
|
270
|
+
else if (at.length === 2) partial.push(`/network/${lowerAscii(second)}/`);
|
|
271
|
+
else if (at.length === 3)
|
|
272
|
+
complete.push(`/network/${lowerAscii(second)}/${lowerAscii(third)}`);
|
|
273
|
+
} else if (host.homeAutomount && first.toLowerCase() === 'home' && at.length === 2) {
|
|
274
|
+
complete.push(`/home/${second}`);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return { complete, partial };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** True when `path` reaches a macOS automount (Claude's `Y1`). */
|
|
281
|
+
function reachesAutomount(path: string, host: ClaudePathHost): boolean {
|
|
282
|
+
if (!host.darwin) return false;
|
|
283
|
+
if (underNetwork(path) || underVolfs(path)) return true;
|
|
284
|
+
if (!path.startsWith('/')) return false;
|
|
285
|
+
const { complete, partial } = automountPrefixes(path, host);
|
|
286
|
+
if (partial.length > 0 || complete.some((prefix) => prefix.startsWith('/network/'))) return true;
|
|
287
|
+
const homes = complete.filter((prefix) => prefix.startsWith('/home/'));
|
|
288
|
+
if (homes.length === 0) return false;
|
|
289
|
+
const own = /^\/home\/([^/]+)/.exec(dataVolumeAlias(host.home));
|
|
290
|
+
const ownHome = own ? `/home/${own[1]}` : null;
|
|
291
|
+
return homes.some((prefix) => prefix !== ownHome);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** True when `path` reaches an automount other than `base`'s own (Claude's `NNo`). */
|
|
295
|
+
function leavesAutomount(path: string, base: string, host: ClaudePathHost): boolean {
|
|
296
|
+
if (!reachesAutomount(path, host)) return false;
|
|
297
|
+
const own = automountPrefixes(base, host).complete[0] ?? null;
|
|
298
|
+
const { complete, partial } = automountPrefixes(path, host);
|
|
299
|
+
if ((complete.length === 0 && partial.length === 0) || own === null) return true;
|
|
300
|
+
return (
|
|
301
|
+
complete.some((prefix) => prefix !== own) || partial.some((prefix) => !own.startsWith(prefix))
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const DOS_DEVICE = /^[\\/]\?\?[\\/]/;
|
|
306
|
+
const isDosDevice = (path: string): boolean =>
|
|
307
|
+
DOS_DEVICE.test(path) || (path.includes('??') && DOS_DEVICE.test(win32.normalize(path)));
|
|
308
|
+
const isUncLike = (path: string): boolean => /^[\\/]{2}/.test(path) || isDosDevice(path);
|
|
309
|
+
|
|
310
|
+
/** The UNC server of a path, lowercased, or `null` (Claude's `KP`). */
|
|
311
|
+
function uncServer(path: string): string | null {
|
|
312
|
+
if (/^[\\/]{2}[?.][\\/](?!unc[\\/])/i.test(path)) return null;
|
|
313
|
+
const server = /^[\\/]{2}(?:[?.][\\/]unc[\\/])?([^\\/]+)/i.exec(path)?.[1];
|
|
314
|
+
return server === undefined ? null : lowerAscii(server);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** A UNC spelling on another server, a device path or a dotted UNC segment (Claude's `RQ`). */
|
|
318
|
+
function uncEscape(path: string, base: string): boolean {
|
|
319
|
+
if (!isUncLike(path)) return false;
|
|
320
|
+
if (/^[\\/]{2}[?.][\\/]/.test(path) || isDosDevice(path)) return true;
|
|
321
|
+
if (/(^|[\\/])\.{1,2}[. ]*([\\/]|$)/.test(path)) return true;
|
|
322
|
+
const server = uncServer(path);
|
|
323
|
+
return server === null || server !== uncServer(base);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Claude Code 2.1.322's unsafe-path predicate (`ua` in its bundle): `text`,
|
|
328
|
+
* as written and resolved against `base`, must not name another UNC server,
|
|
329
|
+
* a device path, another `/net` host, `/net` itself, `/network`, a macOS volfs
|
|
330
|
+
* root or another automount. Claude applies it to the gitdir, commondir and
|
|
331
|
+
* backlink text and to every symlink target its walks follow.
|
|
332
|
+
*
|
|
333
|
+
* @param text - The path as written (a gitdir line or a raw symlink target).
|
|
334
|
+
* @param base - The directory `text` is relative to.
|
|
335
|
+
* @param host - The host facts the macOS rules read.
|
|
336
|
+
* @returns True when Claude would refuse the path.
|
|
337
|
+
* @internal
|
|
338
|
+
*/
|
|
339
|
+
export function claudeUnsafePath(
|
|
340
|
+
text: string,
|
|
341
|
+
base: string,
|
|
342
|
+
host: ClaudePathHost = claudePathHost(),
|
|
343
|
+
): boolean {
|
|
344
|
+
const resolved = resolve(base, text);
|
|
345
|
+
if (uncEscape(text, base) || uncEscape(resolved, base)) return true;
|
|
346
|
+
const baseHost = netHost(base);
|
|
347
|
+
for (const path of [text, resolved]) {
|
|
348
|
+
const pathHost = netHost(path);
|
|
349
|
+
if (pathHost !== null && pathHost !== baseHost) return true;
|
|
350
|
+
if (underNetwork(path) || isNetRoot(path) || underVolfs(path)) return true;
|
|
351
|
+
if (leavesAutomount(path, base, host)) return true;
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** A walked component that leaves its anchor's mount (Claude's `E$`). */
|
|
357
|
+
function componentEscapes(path: string, anchor: string, host: ClaudePathHost): boolean {
|
|
358
|
+
if (underVolfs(path)) return true;
|
|
359
|
+
const pathHost = netHost(path);
|
|
360
|
+
if (pathHost !== null && pathHost !== netHost(anchor)) return true;
|
|
361
|
+
return leavesAutomount(path, anchor, host);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
type PathKind = 'absent' | 'file' | 'dir' | 'symlink' | 'special' | 'other';
|
|
365
|
+
|
|
366
|
+
/** `lstat` kind of a path (Claude's `Pt`). */
|
|
367
|
+
function pathKind(path: string): PathKind {
|
|
368
|
+
try {
|
|
369
|
+
const stat = lstatSync(path);
|
|
370
|
+
if (stat.isSymbolicLink()) return 'symlink';
|
|
371
|
+
return stat.isFile() ? 'file' : stat.isDirectory() ? 'dir' : 'special';
|
|
372
|
+
} catch (err) {
|
|
373
|
+
const code = err instanceof Error && 'code' in err ? err.code : undefined;
|
|
374
|
+
return code === 'ENOENT' || code === 'ENOTDIR' ? 'absent' : 'other';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** A symlink's target text when it is valid UTF-8 without NUL, else `null`. */
|
|
379
|
+
function linkText(path: string): string | null {
|
|
380
|
+
try {
|
|
381
|
+
const raw = readlinkSync(path, { encoding: 'buffer' });
|
|
382
|
+
const text = raw.toString('utf8');
|
|
383
|
+
return text.includes('\0') || !Buffer.from(text, 'utf8').equals(raw) ? null : text;
|
|
384
|
+
} catch {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Claude's component walk (`Ge`): every component stays on `anchor`'s mount,
|
|
391
|
+
* is absent, a file, a directory or a symlink whose raw target passes
|
|
392
|
+
* {@link claudeUnsafePath}; links are followed at most 40 times.
|
|
393
|
+
*/
|
|
394
|
+
function walksSafely(path: string, anchor: string, host: ClaudePathHost, hops = 40): boolean {
|
|
395
|
+
if (hops <= 0) return false;
|
|
396
|
+
const rooted = path.startsWith('/');
|
|
397
|
+
const parts = path.slice(rooted ? 1 : 0).split(/\/+/);
|
|
398
|
+
let at = rooted ? '/' : '';
|
|
399
|
+
for (const [index, part] of parts.entries()) {
|
|
400
|
+
if (part === '' || part === '.') continue;
|
|
401
|
+
if (part === '..') {
|
|
402
|
+
at = dirname(at);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
at = join(at, part);
|
|
406
|
+
if (componentEscapes(at, anchor, host) || underNetwork(at)) return false;
|
|
407
|
+
const kind = pathKind(at);
|
|
408
|
+
if (kind === 'other' || kind === 'special') return false;
|
|
409
|
+
if (kind === 'symlink') {
|
|
410
|
+
const target = linkText(at);
|
|
411
|
+
if (target === null || claudeUnsafePath(target, dirname(at), host)) return false;
|
|
412
|
+
const base = target.startsWith('/') ? target : `${dirname(at)}/${target}`;
|
|
413
|
+
const rest = parts.slice(index + 1).join('/');
|
|
414
|
+
const next = rest ? (base.endsWith('/') ? base + rest : `${base}/${rest}`) : base;
|
|
415
|
+
return walksSafely(next, anchor, host, hops - 1);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Claude's `ye`: `text` relative to `base` walks safely, as written and resolved. */
|
|
422
|
+
function textWalksSafely(text: string, base: string, host: ClaudePathHost, anchor = base): boolean {
|
|
423
|
+
const written = text.startsWith('/') ? text : `${base}/${text}`;
|
|
424
|
+
const resolved = resolve(base, text);
|
|
425
|
+
return (
|
|
426
|
+
walksSafely(written, anchor, host) &&
|
|
427
|
+
(resolved === written || walksSafely(resolved, anchor, host))
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** A git metadata file Claude reads (`K6` passed: safe walk, not a symlink), trimmed. */
|
|
432
|
+
function readGitMetaFile(gitDir: string, name: string, host: ClaudePathHost): string | null {
|
|
433
|
+
const file = join(gitDir, name);
|
|
434
|
+
if (!walksSafely(file, gitDir, host) || ['symlink', 'special', 'other'].includes(pathKind(file)))
|
|
435
|
+
return null;
|
|
436
|
+
return readFileSync(file, 'utf8').trim();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Claude's `tt`: `path` is a file or directory, or a symlink whose raw target
|
|
441
|
+
* passes the unsafe-path rule and walk and resolves to a file or directory.
|
|
442
|
+
*/
|
|
443
|
+
function usableGitEntry(path: string, base: string, host: ClaudePathHost): boolean {
|
|
444
|
+
try {
|
|
445
|
+
const entry = lstatSync(path);
|
|
446
|
+
if (!entry.isSymbolicLink()) return entry.isDirectory() || entry.isFile();
|
|
447
|
+
const target = linkText(path);
|
|
448
|
+
if (
|
|
449
|
+
target === null ||
|
|
450
|
+
claudeUnsafePath(target, base, host) ||
|
|
451
|
+
!textWalksSafely(target, base, host)
|
|
452
|
+
)
|
|
453
|
+
return false;
|
|
454
|
+
const resolved = statSync(path);
|
|
455
|
+
return resolved.isDirectory() || resolved.isFile();
|
|
456
|
+
} catch {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Claude's canonical root for a linked worktree (`findCanonicalGitRoot`, `cr`
|
|
463
|
+
* in Claude Code 2.1.322): a worktrees entry of the common directory with a
|
|
464
|
+
* matching backlink. Paths resolve lexically, never realpath-followed; only
|
|
465
|
+
* the backlink is compared by real path. Every gitdir, commondir and backlink
|
|
466
|
+
* text and every symlink target on the way passes Claude's unsafe-path rule.
|
|
467
|
+
* A bare common directory with a usable `.git` of its own is refused, as in
|
|
468
|
+
* Claude; an unusable one (dangling or unsafe link) is ignored, as in Claude.
|
|
469
|
+
*
|
|
470
|
+
* @param dir - The linked worktree's top directory.
|
|
471
|
+
* @param home - The lead Claude process's home, from the lead environment.
|
|
472
|
+
*/
|
|
473
|
+
function linkedWorktreeTrustRoot(dir: string, home: string): string | null {
|
|
474
|
+
const host = claudePathHost(home);
|
|
96
475
|
const link = readFileSync(join(dir, '.git'), 'utf8').trim();
|
|
97
476
|
if (!link.startsWith('gitdir:')) return null;
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
477
|
+
const gitText = link.slice(7).trim();
|
|
478
|
+
if (claudeUnsafePath(gitText, dir, host) || !textWalksSafely(gitText, dir, host)) return null;
|
|
479
|
+
const gitDir = resolve(dir, gitText);
|
|
480
|
+
const common = readGitMetaFile(gitDir, 'commondir', host);
|
|
481
|
+
if (
|
|
482
|
+
common === null ||
|
|
483
|
+
claudeUnsafePath(common, gitDir, host) ||
|
|
484
|
+
!textWalksSafely(common, gitDir, host)
|
|
485
|
+
)
|
|
102
486
|
return null;
|
|
103
|
-
const commonDir =
|
|
487
|
+
const commonDir = resolve(gitDir, common);
|
|
488
|
+
if (dirname(gitDir) !== join(commonDir, 'worktrees')) return null;
|
|
489
|
+
const back = readGitMetaFile(gitDir, 'gitdir', host);
|
|
104
490
|
if (
|
|
105
|
-
|
|
106
|
-
|
|
491
|
+
back === null ||
|
|
492
|
+
claudeUnsafePath(back, dir, host) ||
|
|
493
|
+
!textWalksSafely(back, gitDir, host, dir)
|
|
107
494
|
)
|
|
108
495
|
return null;
|
|
109
|
-
if (
|
|
110
|
-
|
|
496
|
+
if ([dir, gitDir, back, commonDir].some((path) => path.includes('\\'))) return null;
|
|
497
|
+
if (realpathSync(resolve(gitDir, back)) !== join(realpathSync(dir), '.git')) return null;
|
|
498
|
+
if (basename(commonDir) !== '.git' && usableGitEntry(join(commonDir, '.git'), commonDir, host))
|
|
499
|
+
return null;
|
|
500
|
+
return (basename(commonDir) === '.git' ? dirname(commonDir) : commonDir).normalize('NFC');
|
|
111
501
|
}
|
|
112
502
|
|
|
113
503
|
/** Claude Code's truthy env parse: `1`, `true`, `yes` or `on`, any case, trimmed. */
|
|
@@ -239,7 +629,7 @@ export function requireLeadProjectTrust(
|
|
|
239
629
|
if (trusted(dir)) return configPath;
|
|
240
630
|
const gitEntry = lstatSync(join(dir, '.git'), { throwIfNoEntry: false });
|
|
241
631
|
if (gitEntry || dirname(dir) === dir) {
|
|
242
|
-
const mainRoot = gitEntry?.isFile() ? linkedWorktreeTrustRoot(dir) : null;
|
|
632
|
+
const mainRoot = gitEntry?.isFile() ? linkedWorktreeTrustRoot(dir, home) : null;
|
|
243
633
|
if (mainRoot && mainRoot !== realpathSync(home) && trusted(mainRoot)) return configPath;
|
|
244
634
|
break;
|
|
245
635
|
}
|