Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(codex): safe default .codex/config.toml, explicit --codex-trust full opt-in

ra6b563c60ff1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9582dd9906..93e4d1bd80 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Security
+
+- `ruflo init` / `init --dual` / `@claude-flow/codex init` no longer write a permissive `.codex/config.toml` by default. The generated file now uses `sandbox_mode = "workspace-write"`, `approval_policy = "on-request"` and `web_search = "cached"` (**standard** trust); the old `danger-full-access` / `never` / `live` file needs an explicit `--codex-trust full` (or `RUFLO_CODEX_TRUST=full`). `init` prints which level was written, an existing `.codex/config.toml` is never rewritten (not even with `--force`), and a kept permissive file is flagged with how to tighten it. Found by the three-host e2e run (ADR-490). `@claude-flow/codex` 3.0.4 (bundled, ships with the next train).
+
### Fixed
Batch of reviewed fixes from @rudycelekli (PRs #4020-#4026, #4028-#4030, #4032, #4033, #4035, #4037; #4027 and #4034 landed earlier):
diff --git a/v3/@claude-flow/cli/__tests__/init-codex-trust.test.ts b/v3/@claude-flow/cli/__tests__/init-codex-trust.test.ts
new file mode 100644
index 0000000000..be07a8b3ad
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/init-codex-trust.test.ts
@@ -0,0 +1,48 @@
+/**
+ * `init --codex-trust <standard|full>`: the generated .codex/config.toml is
+ * safe by default (workspace-write, on-request approvals); only an explicit
+ * `full` restores danger-full-access. The adapter owns the file contents
+ * (see @claude-flow/codex tests/codex-trust-defaults.test.ts); this pins the
+ * CLI side: the flag exists, both key spellings parse, anything else is
+ * rejected rather than guessed, and it reaches the adapter.
+ */
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { initCommand, readCodexTrustFlag } from '../src/commands/init.js';
+
+describe('readCodexTrustFlag', () => {
+ it('reads the normalised (camelCase) and literal (kebab) keys', () => {
+ expect(readCodexTrustFlag({ codexTrust: 'full' })).toBe('full');
+ expect(readCodexTrustFlag({ 'codex-trust': 'standard' })).toBe('standard');
+ });
+
+ it('is undefined when unset, so the adapter default (standard) applies', () => {
+ expect(readCodexTrustFlag({})).toBeUndefined();
+ expect(readCodexTrustFlag({ codexTrust: '' })).toBeUndefined();
+ expect(readCodexTrustFlag({ codexTrust: false })).toBeUndefined();
+ });
+
+ it('rejects anything else with null instead of guessing a level', () => {
+ expect(readCodexTrustFlag({ codexTrust: 'yolo' })).toBeNull();
+ expect(readCodexTrustFlag({ codexTrust: 'FULL' })).toBeNull();
+ expect(readCodexTrustFlag({ codexTrust: true })).toBeNull();
+ });
+});
+
+describe('init command surface', () => {
+ it('declares --codex-trust as a string option', () => {
+ const opt = initCommand.options?.find((o) => o.name === 'codex-trust');
+ expect(opt).toBeDefined();
+ expect(opt?.type).toBe('string');
+ expect(opt?.description).toMatch(/never rewritten/);
+ });
+
+ it('forwards the level to the adapter on every Codex path', () => {
+ const src = readFileSync(fileURLToPath(new URL('../src/commands/init.ts', import.meta.url)), 'utf8');
+ // npx fallback, in-process initializer, and the auto-detect path
+ expect(src).toMatch(/\['--codex-trust', options\.codexTrust\]/);
+ expect(src).toMatch(/dual: dualMode,\s*codexTrust,/);
+ expect(src).toMatch(/dual: false, \/\/ Claude Code files were already written by the main init flow above\s*codexTrust,/);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/init.ts b/v3/@claude-flow/cli/src/commands/init.ts
index 1956ac4fee..97e89c2aff 100644
--- a/v3/@claude-flow/cli/src/commands/init.ts
+++ b/v3/@claude-flow/cli/src/commands/init.ts
@@ -101,13 +101,22 @@ async function resolveCodexInitializer(cwd: string): Promise<CodexInitializerCto
return undefined;
}
+// Trust level for a newly generated .codex/config.toml. Safe by default: only
+// an explicit `--codex-trust full` (or RUFLO_CODEX_TRUST=full, read by the
+// adapter) restores danger-full-access. Anything else is rejected here.
+export function readCodexTrustFlag(flags: Record<string, unknown>): 'standard' | 'full' | undefined | null {
+ const raw = flags.codexTrust ?? flags['codex-trust'];
+ if (raw === undefined || raw === null || raw === false || raw === '') return undefined;
+ return raw === 'standard' || raw === 'full' ? raw : null;
+}
+
// Keep Codex out of the CLI dependency graph so cold `npx ruflo --version`
// remains fast (#2561). An explicit `init --codex` may fetch the small,
// stable adapter on demand when it is not already installed by an umbrella
// package, the current project, or the global npm prefix.
export function runCodexInitializerCli(
cwd: string,
- options: { template: string; force: boolean; dual: boolean },
+ options: { template: string; force: boolean; dual: boolean; codexTrust?: 'standard' | 'full' },
): boolean {
const npxArgs = [
'-y',
@@ -117,6 +126,7 @@ export function runCodexInitializerCli(
options.template,
...(options.force ? ['--force'] : []),
...(options.dual ? ['--dual'] : []),
+ ...(options.codexTrust ? ['--codex-trust', options.codexTrust] : []),
];
const result = process.platform === 'win32'
@@ -143,6 +153,7 @@ async function maybeAutoDetectCodex(
options: { force: boolean; minimal: boolean; full: boolean },
): Promise<void> {
try {
+ const codexTrust = readCodexTrustFlag(ctx.flags) ?? undefined;
// The CLI parser turns `--no-codex-detect` into `codexDetect: false`.
// Retain the literal key for programmatic CommandContext callers.
if (ctx.flags.codexDetect === false || ctx.flags['no-codex-detect'] === true) return;
@@ -163,6 +174,7 @@ async function maybeAutoDetectCodex(
template: (options.minimal ? 'minimal' : options.full ? 'full' : 'default') as 'minimal' | 'default' | 'full' | 'enterprise',
force: options.force,
dual: false, // Claude Code files were already written by the main init flow above
+ codexTrust,
});
if (!result.success) return; // best-effort — never fail the primary init over this
@@ -386,6 +398,11 @@ async function initCodexAction(
options: { codexMode: boolean; dualMode: boolean; force: boolean; minimal: boolean; full: boolean }
): Promise<CommandResult> {
const { force, minimal, full, dualMode } = options;
+ const codexTrust = readCodexTrustFlag(ctx.flags);
+ if (codexTrust === null) {
+ output.printError(`Invalid --codex-trust: ${String(ctx.flags.codexTrust ?? ctx.flags['codex-trust'])} (valid: standard, full)`);
+ return { success: false, exitCode: 1 };
+ }
output.writeln();
output.writeln(output.bold('Initializing RuFlo V3 for OpenAI Codex'));
@@ -403,7 +420,7 @@ async function initCodexAction(
if (!CodexInitializer) {
spinner.stop();
output.printInfo('Fetching the stable Codex adapter for this initialization...');
- const success = runCodexInitializerCli(ctx.cwd, { template, force, dual: dualMode });
+ const success = runCodexInitializerCli(ctx.cwd, { template, force, dual: dualMode, codexTrust });
if (!success) {
output.printError('Codex initialization failed while running @claude-flow/codex@latest.');
return { success: false, exitCode: 1 };
@@ -418,6 +435,7 @@ async function initCodexAction(
template: template as 'minimal' | 'default' | 'full' | 'enterprise',
force,
dual: dualMode,
+ codexTrust,
});
if (!result.success) {
@@ -454,14 +472,22 @@ async function initCodexAction(
);
output.writeln();
+ // The trust level of .codex/config.toml is always shown (never truncated
+ // behind other warnings): it decides what Codex may do without asking.
+ const isTrustNote = (w: string) => w.startsWith('.codex/config.toml');
+ const trustNotes = (result.warnings ?? []).filter(isTrustNote);
+ for (const note of trustNotes) output.printInfo(note);
+ if (trustNotes.length > 0) output.writeln();
+
// Warnings
- if (result.warnings && result.warnings.length > 0) {
+ const otherWarnings = (result.warnings ?? []).filter((w) => !isTrustNote(w));
+ if (otherWarnings.length > 0) {
output.printWarning('Warnings:');
- for (const warning of result.warnings.slice(0, 5)) {
+ for (const warning of otherWarnings.slice(0, 5)) {
output.printInfo(` • ${warning}`);
}
- if (result.warnings.length > 5) {
- output.printInfo(` ... and ${result.warnings.length - 5} more`);
+ if (otherWarnings.length > 5) {
+ output.printInfo(` ... and ${otherWarnings.length - 5} more`);
}
output.writeln();
}
@@ -1747,6 +1773,11 @@ export const initCommand: Command = {
type: 'boolean',
default: false,
},
+ {
+ name: 'codex-trust',
+ description: 'Trust level of the generated .codex/config.toml: standard (default: workspace-write sandbox, on-request approvals, cached web search) or full (danger-full-access, no approvals, live web search). An existing file is never rewritten',
+ type: 'string',
+ },
{
name: 'no-codex-detect',
description: 'Skip auto-detecting the OpenAI Codex CLI and configuring its MCP server + skills',
diff --git a/v3/@claude-flow/codex/README.md b/v3/@claude-flow/codex/README.md
index ad8a6a79a8..6cedde2018 100644
--- a/v3/@claude-flow/codex/README.md
+++ b/v3/@claude-flow/codex/README.md
@@ -751,19 +751,36 @@ enabled = true
### .codex/config.toml (Local Overrides)
+`init` creates this gitignored file with **standard** trust by default:
+
```toml
# Local development overrides (gitignored)
# These settings override .agents/config.toml
-approval_policy = "never"
-sandbox_mode = "danger-full-access"
-web_search = "live"
+approval_policy = "on-request"
+sandbox_mode = "workspace-write"
+web_search = "cached"
# Disable MCP in local if needed
[mcp_servers.claude-flow]
enabled = false
```
+Codex can then write inside the workspace only and asks before anything riskier.
+Opt in to the old permissive file (`approval_policy = "never"`,
+`sandbox_mode = "danger-full-access"`, `web_search = "live"`) explicitly:
+
+```bash
+npx ruflo@latest init --dual --codex-trust full # or: RUFLO_CODEX_TRUST=full
+npx @claude-flow/codex init --codex-trust full
+```
+
+`init` prints which level you got. An existing `.codex/config.toml` is never
+rewritten, not even with `--force` (it holds your own sandbox and approval
+choices), so to change the level of an existing file edit those three keys.
+Unknown `--codex-trust` values are rejected on the command line and fall back to
+`standard` (with a warning) from the environment variable.
+
### Environment Variables
```bash
diff --git a/v3/@claude-flow/codex/package.json b/v3/@claude-flow/codex/package.json
index af16a22889..c99787bcd5 100644
--- a/v3/@claude-flow/codex/package.json
+++ b/v3/@claude-flow/codex/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/codex",
- "version": "3.0.3",
+ "version": "3.0.4",
"description": "Codex CLI integration for Ruflo (claude-flow) - OpenAI Codex platform adapter",
"type": "module",
"main": "./dist/index.js",
diff --git a/v3/@claude-flow/codex/src/cli.ts b/v3/@claude-flow/codex/src/cli.ts
index 13c102f31f..758739c678 100644
--- a/v3/@claude-flow/codex/src/cli.ts
+++ b/v3/@claude-flow/codex/src/cli.ts
@@ -85,6 +85,7 @@ program
.option('-s, --skills <skills>', 'Comma-separated list of skills to include')
.option('-f, --force', 'Overwrite existing files', false)
.option('--dual', 'Generate both Codex and Claude Code configurations', false)
+ .option('--codex-trust <level>', 'Trust level of the generated .codex/config.toml: standard (default: workspace-write sandbox, on-request approvals) or full (danger-full-access, no approvals)')
.option('-p, --path <path>', 'Project path', process.cwd())
.option('-q, --quiet', 'Suppress verbose output', false)
.action(async (options) => {
@@ -93,6 +94,12 @@ program
printBanner();
}
+ if (options.codexTrust !== undefined && !['standard', 'full'].includes(options.codexTrust)) {
+ console.error(chalk.red(`Invalid --codex-trust: ${options.codexTrust}`));
+ console.log(chalk.gray('Valid levels: standard, full'));
+ process.exit(1);
+ }
+
// Validate template
const validTemplates = ['minimal', 'default', 'full', 'enterprise'];
if (!validTemplates.includes(options.template)) {
@@ -136,6 +143,7 @@ program
skills,
force: options.force,
dual: options.dual,
+ codexTrust: options.codexTrust,
});
if (result.success) {
diff --git a/v3/@claude-flow/codex/src/initializer.ts b/v3/@claude-flow/codex/src/initializer.ts
index edcffba31d..287033dfb3 100644
--- a/v3/@claude-flow/codex/src/initializer.ts
+++ b/v3/@claude-flow/codex/src/initializer.ts
@@ -9,6 +9,7 @@ import path from 'path';
import { fileURLToPath } from 'node:url';
import type {
CodexInitOptions,
+ CodexTrust,
CodexInitResult,
AgentsMdTemplate,
BuiltInSkill,
@@ -41,6 +42,8 @@ export class CodexInitializer {
private skills: string[] = [];
private force: boolean = false;
private dual: boolean = false;
+ private codexTrust: CodexTrust = 'standard';
+ private codexTrustWarning: string | undefined;
private bundledSkillsPath: string = '';
/**
@@ -52,6 +55,9 @@ export class CodexInitializer {
this.skills = options.skills ?? DEFAULT_SKILLS_BY_TEMPLATE[this.template];
this.force = options.force ?? false;
this.dual = options.dual ?? false;
+ const trust = this.resolveCodexTrust(options.codexTrust);
+ this.codexTrust = trust.level;
+ this.codexTrustWarning = trust.warning;
// Resolve bundled skills path (relative to this file's location)
this.bundledSkillsPath = resolveBundledSkillsPath();
@@ -159,10 +165,30 @@ export class CodexInitializer {
}
// Generate local config.toml
+ // A person's own .codex/config.toml is never rewritten, not even with
+ // --force: it holds their sandbox/approval choices (and often local
+ // secrets). The trust level only shapes a file we create.
const localConfigPath = path.join(this.projectPath, '.codex', 'config.toml');
- if (await this.shouldWriteFile(localConfigPath)) {
+ if (this.codexTrustWarning) warnings.push(this.codexTrustWarning);
+ if (await fs.pathExists(localConfigPath)) {
+ warnings.push('.codex/config.toml already exists - kept (never rewritten, including with --force)');
+ const existing = await fs.readFile(localConfigPath, 'utf-8').catch(() => '');
+ if (/sandbox_mode\s*=\s*"danger-full-access"/.test(existing)) {
+ warnings.push(
+ '.codex/config.toml uses sandbox_mode = "danger-full-access": Codex can write anywhere and run without approval prompts. ' +
+ 'Edit it to "workspace-write" (and approval_policy = "on-request") to tighten it.',
+ );
+ }
+ } else {
await fs.writeFile(localConfigPath, await this.generateLocalConfigToml(), 'utf-8');
filesCreated.push('.codex/config.toml');
+ warnings.push(
+ this.codexTrust === 'full'
+ ? '.codex/config.toml: full trust (danger-full-access sandbox, no approval prompts, live web search). ' +
+ 'Switch back with --codex-trust standard or edit the file.'
+ : '.codex/config.toml: standard trust (workspace-write sandbox, on-request approvals, cached web search). ' +
+ 'Opt in to full access with --codex-trust full (or RUFLO_CODEX_TRUST=full).',
+ );
}
// Update .gitignore
@@ -552,18 +578,46 @@ export class CodexInitializer {
});
}
+ /**
+ * Trust level for a newly generated .codex/config.toml: explicit option,
+ * then RUFLO_CODEX_TRUST, then the safe default. Unknown values fall back
+ * to standard with a warning, never to full.
+ */
+ private resolveCodexTrust(option: CodexTrust | undefined): { level: CodexTrust; warning?: string } {
+ const raw = option ?? process.env.RUFLO_CODEX_TRUST;
+ if (raw === undefined || raw === '') return { level: 'standard' };
+ if (raw === 'standard' || raw === 'full') return { level: raw };
+ return {
+ level: 'standard',
+ warning: `Unknown codex trust "${String(raw)}" - using "standard" (valid: standard, full)`,
+ };
+ }
+
/**
* Generate local config.toml for .codex directory
*/
private async generateLocalConfigToml(): Promise<string> {
+ const full = this.codexTrust === 'full';
+ const approval = full ? 'never' : 'on-request';
+ const sandbox = full ? 'danger-full-access' : 'workspace-write';
+ const webSearch = full ? 'live' : 'cached';
+ const tier = full
+ ? `# Trust level: FULL (opted in with --codex-trust full or RUFLO_CODEX_TRUST=full).
+# Codex can write anywhere and runs commands without asking. Switch back with
+# --codex-trust standard, or set sandbox_mode = "workspace-write" and
+# approval_policy = "on-request" below.`
+ : `# Trust level: STANDARD (the default).
+# Codex may write inside this workspace only and asks before anything riskier.
+# Opt in to full access with --codex-trust full (or RUFLO_CODEX_TRUST=full);
+# this file is never rewritten once it exists, so edit the three keys below directly.`;
return `# Local Codex Configuration
# This file overrides .agents/config.toml for local development
# DO NOT commit this file to version control
-# Development profile - more permissive
-approval_policy = "never"
-sandbox_mode = "danger-full-access"
-web_search = "live"
+${tier}
+approval_policy = "${approval}"
+sandbox_mode = "${sandbox}"
+web_search = "${webSearch}"
# Debug settings
# Uncomment to enable debug logging
diff --git a/v3/@claude-flow/codex/src/types.ts b/v3/@claude-flow/codex/src/types.ts
index 1d63aca4e9..3acdcd6f69 100644
--- a/v3/@claude-flow/codex/src/types.ts
+++ b/v3/@claude-flow/codex/src/types.ts
@@ -163,12 +163,21 @@ export interface ConfigProfile {
/**
* Full initialization options
*/
+export type CodexTrust = 'standard' | 'full';
+
export interface CodexInitOptions {
projectPath: string;
template?: AgentsMdTemplate;
skills?: string[];
force?: boolean;
dual?: boolean; // Generate both Claude Code and Codex configs
+ /**
+ * Trust level of the generated, gitignored `.codex/config.toml`.
+ * `standard` (default): workspace-write sandbox, on-request approvals, cached web search.
+ * `full`: danger-full-access sandbox, no approvals, live web search (explicit opt-in).
+ * Also settable with RUFLO_CODEX_TRUST=full; the option wins over the environment.
+ */
+ codexTrust?: CodexTrust;
migrateFrom?: 'claude.md' | 'CLAUDE.md';
}
diff --git a/v3/@claude-flow/codex/tests/codex-trust-defaults.test.ts b/v3/@claude-flow/codex/tests/codex-trust-defaults.test.ts
new file mode 100644
index 0000000000..4282dc392d
--- /dev/null
+++ b/v3/@claude-flow/codex/tests/codex-trust-defaults.test.ts
@@ -0,0 +1,122 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { CodexInitializer } from '../src/initializer.js';
+
+let projectPath: string;
+let originalPath: string | undefined;
+let originalTrust: string | undefined;
+
+const localConfig = () => join(projectPath, '.codex', 'config.toml');
+const read = () => readFileSync(localConfig(), 'utf8');
+
+beforeEach(() => {
+ projectPath = mkdtempSync(join(tmpdir(), 'codex-trust-'));
+ originalPath = process.env.PATH;
+ originalTrust = process.env.RUFLO_CODEX_TRUST;
+ delete process.env.RUFLO_CODEX_TRUST;
+ // Keep the test away from the user's Codex/plugin registrations.
+ process.env.PATH = '';
+});
+
+afterEach(() => {
+ if (originalPath === undefined) delete process.env.PATH;
+ else process.env.PATH = originalPath;
+ if (originalTrust === undefined) delete process.env.RUFLO_CODEX_TRUST;
+ else process.env.RUFLO_CODEX_TRUST = originalTrust;
+ rmSync(projectPath, { recursive: true, force: true });
+});
+
+describe('generated .codex/config.toml trust level', () => {
+ it('defaults to workspace-write, on-request approvals and cached web search', async () => {
+ const result = await new CodexInitializer().initialize({ projectPath, template: 'minimal', dual: true });
+ expect(result.success).toBe(true);
+ const toml = read();
+ expect(toml).toMatch(/^sandbox_mode = "workspace-write"$/m);
+ expect(toml).toMatch(/^approval_policy = "on-request"$/m);
+ expect(toml).toMatch(/^web_search = "cached"$/m);
+ expect(toml).not.toContain('danger-full-access');
+ expect(toml).not.toMatch(/approval_policy = "never"/);
+ expect(toml).not.toMatch(/web_search = "live"/);
+ });
+
+ it('is also safe for a plain (non-dual) codex init', async () => {
+ await new CodexInitializer().initialize({ projectPath, template: 'minimal' });
+ expect(read()).not.toContain('danger-full-access');
+ });
+
+ it('restores the permissive values only on explicit opt-in (codexTrust: full)', async () => {
+ await new CodexInitializer().initialize({ projectPath, template: 'minimal', dual: true, codexTrust: 'full' });
+ const toml = read();
+ expect(toml).toMatch(/^sandbox_mode = "danger-full-access"$/m);
+ expect(toml).toMatch(/^approval_policy = "never"$/m);
+ expect(toml).toMatch(/^web_search = "live"$/m);
+ });
+
+ it('honours RUFLO_CODEX_TRUST=full as the config-level opt-in, and the explicit option wins', async () => {
+ process.env.RUFLO_CODEX_TRUST = 'full';
+ await new CodexInitializer().initialize({ projectPath, template: 'minimal' });
+ expect(read()).toContain('danger-full-access');
+
+ rmSync(join(projectPath, '.codex'), { recursive: true, force: true });
+ rmSync(join(projectPath, 'AGENTS.md'), { force: true });
+ await new CodexInitializer().initialize({ projectPath, template: 'minimal', force: true, codexTrust: 'standard' });
+ expect(read()).not.toContain('danger-full-access');
+ });
+
+ it('falls back to the safe level (with a warning) for an unknown trust value', async () => {
+ const result = await new CodexInitializer().initialize({
+ projectPath,
+ template: 'minimal',
+ // @ts-expect-error deliberately invalid
+ codexTrust: 'yolo',
+ });
+ expect(result.success).toBe(true);
+ expect(read()).not.toContain('danger-full-access');
+ expect((result.warnings ?? []).join('\n')).toMatch(/unknown codex trust "yolo"/i);
+ });
+
+ it('tells the person which mode they got and how to change it', async () => {
+ const safe = await new CodexInitializer().initialize({ projectPath, template: 'minimal' });
+ const note = (safe.warnings ?? []).find((w) => w.startsWith('.codex/config.toml:'));
+ expect(note).toMatch(/workspace-write/);
+ expect(note).toMatch(/--codex-trust full/);
+
+ rmSync(join(projectPath, '.codex'), { recursive: true, force: true });
+ rmSync(join(projectPath, 'AGENTS.md'), { force: true });
+ const full = await new CodexInitializer().initialize({ projectPath, template: 'minimal', force: true, codexTrust: 'full' });
+ const fullNote = (full.warnings ?? []).find((w) => w.startsWith('.codex/config.toml:'));
+ expect(fullNote).toMatch(/danger-full-access/);
+ expect(fullNote).toMatch(/--codex-trust standard/);
+ });
+});
+
+describe('an existing .codex/config.toml is never rewritten', () => {
+ const USER = '# my own settings\napproval_policy = "untrusted"\nsandbox_mode = "read-only"\n';
+
+ it('keeps the user file byte for byte, even with --force, and says so', async () => {
+ mkdirSync(join(projectPath, '.codex'), { recursive: true });
+ writeFileSync(localConfig(), USER);
+ const result = await new CodexInitializer().initialize({ projectPath, template: 'minimal', force: true });
+ expect(result.success).toBe(true);
+ expect(read()).toBe(USER);
+ expect(result.filesCreated).not.toContain('.codex/config.toml');
+ expect((result.warnings ?? []).join('\n')).toMatch(/\.codex\/config\.toml already exists - kept/);
+ });
+
+ it('keeps it even when the person asks for full trust (opt-in only affects new files)', async () => {
+ mkdirSync(join(projectPath, '.codex'), { recursive: true });
+ writeFileSync(localConfig(), USER);
+ await new CodexInitializer().initialize({ projectPath, template: 'minimal', force: true, codexTrust: 'full' });
+ expect(read()).toBe(USER);
+ });
+
+ it('warns when an older generated permissive file is kept', async () => {
+ mkdirSync(join(projectPath, '.codex'), { recursive: true });
+ writeFileSync(localConfig(), 'approval_policy = "never"\nsandbox_mode = "danger-full-access"\nweb_search = "live"\n');
+ const result = await new CodexInitializer().initialize({ projectPath, template: 'minimal', force: true });
+ expect(existsSync(localConfig())).toBe(true);
+ expect((result.warnings ?? []).join('\n')).toMatch(/danger-full-access/);
+ });
+});