Claude Code 2.1.330 ищет доверие worktree по корню основного репозитория (git common dir), а PEP-241 писал его только на папку worktree: агенты висели на «Is this a project you trust?» (QLFW-80). Проверено на сервере: с ключом на основную копию CLI сразу открывает рабочий экран. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
import { homedir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { codexTrustRoots } from "./codex-trust.ts";
|
|
|
|
const CONFIG = process.env.PEPPA_CLAUDE_CONFIG ?? join(homedir(), ".claude.json");
|
|
|
|
/**
|
|
* Marks a workspace as trusted in ~/.claude.json. Without it Claude Code ignores the
|
|
* project's .claude/settings.json (permissions, hooks) and .mcp.json servers.
|
|
*/
|
|
export function trustWorkspace(dir: string): void {
|
|
const cfg = existsSync(CONFIG) ? (JSON.parse(readFileSync(CONFIG, "utf8")) as Record<string, any>) : {};
|
|
if (!markClaudeTrusted(cfg, dir)) return;
|
|
const tmp = `${CONFIG}.peppa-${process.pid}`;
|
|
writeFileSync(tmp, JSON.stringify(cfg, null, 2));
|
|
renameSync(tmp, CONFIG);
|
|
}
|
|
|
|
/**
|
|
* PEP-263: Claude Code 2.1.33x looks the trust of a git worktree up by the root of the MAIN repository
|
|
* (`git rev-parse --git-common-dir`/..), not by the worktree folder — trust written only for the
|
|
* worktree left agents waiting on «Is this a project you trust?». Marks the folder and, for a
|
|
* worktree, the main repository's root (the project's workspace — never HOME). True if changed.
|
|
*/
|
|
export function markClaudeTrusted(cfg: Record<string, any>, dir: string, roots = codexTrustRoots(dir)): boolean {
|
|
cfg.projects ??= {};
|
|
let changed = false;
|
|
for (const root of roots) {
|
|
const p = (cfg.projects[root] ??= {});
|
|
if (p.hasTrustDialogAccepted && p.hasCompletedProjectOnboarding && (p.enabledMcpjsonServers ?? []).includes("peppa")) continue;
|
|
p.hasTrustDialogAccepted = true;
|
|
p.hasCompletedProjectOnboarding = true;
|
|
p.enabledMcpjsonServers = Array.from(new Set([...(p.enabledMcpjsonServers ?? []), "peppa"]));
|
|
changed = true;
|
|
}
|
|
return changed;
|
|
}
|