MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / ensureTrustedProject

Function ensureTrustedProject

src/workspaces/adapters/codex.ts:388–411  ·  view source on GitHub ↗

* Add (or no-op if present) a `[projects." "] trust_level = "trusted"` * entry to `~/.codex/config.toml`. Uses a minimal append-or-rewrite strategy * — we don't bring in a TOML library because the section grammar is simple * and we only ever touch one section per workspace. * * If the proje

(cwd: string)

Source from the content-addressed store, hash-verified

386 * what value it has (the user may have set `read_only` deliberately).
387 */
388async function ensureTrustedProject(cwd: string): Promise<void> {
389 const abs = resolve(cwd);
390 const configPath = join(homedir(), '.codex', 'config.toml');
391
392 let existing = '';
393 try {
394 existing = await readFile(configPath, 'utf8');
395 } catch (err) {
396 if (!isENOENT(err)) throw err;
397 await mkdir(dirname(configPath), { recursive: true });
398 }
399
400 // Match either single- or triple-bracket [projects."<path>"] headers.
401 const headerEsc = abs.replace(/[\\"]/g, (c) => `\\${c}`);
402 const headerRe = new RegExp(
403 `^\\[projects\\."${headerEsc.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"\\]\\s*$`,
404 'm',
405 );
406 if (headerRe.test(existing)) return; // already configured — don't clobber
407
408 const block = `\n[projects."${headerEsc}"]\ntrust_level = "trusted"\n`;
409 const next = existing.endsWith('\n') || existing.length === 0 ? existing + block : existing + '\n' + block;
410 await writeFile(configPath, next, 'utf8');
411}
412
413function isENOENT(err: unknown): boolean {
414 return typeof err === 'object' && err !== null && (err as { code?: string }).code === 'ENOENT';

Callers 1

bootstrapFunction · 0.85

Calls 1

isENOENTFunction · 0.70

Tested by

no test coverage detected