diff --git a/Cargo.lock b/Cargo.lock index 3581612..95c4496 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "codexcw" -version = "0.6.0" +version = "0.7.0" dependencies = [ "serde", "serde_json", @@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "codexcw-node" -version = "0.6.0" +version = "0.7.0" dependencies = [ "codexcw", "napi", @@ -47,7 +47,7 @@ dependencies = [ [[package]] name = "codexcw-py" -version = "0.6.0" +version = "0.7.0" dependencies = [ "codexcw", "pyo3", @@ -309,9 +309,9 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "pin-project-lite" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" [[package]] name = "portable-atomic" diff --git a/Cargo.toml b/Cargo.toml index 81c6c13..1ccba8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/codexcw", "bindings/node", "bindings/python"] [workspace.package] -version = "0.6.0" +version = "0.7.0" edition = "2021" rust-version = "1.90" license = "CC0-1.0" @@ -12,7 +12,7 @@ homepage = "https://github.com/c3-oss/codexcw" authors = ["c3-oss"] [workspace.dependencies] -codexcw = { path = "crates/codexcw", version = "0.6.0" } +codexcw = { path = "crates/codexcw", version = "0.7.0" } tokio = { version = "1", default-features = false, features = [ "process", "io-util", diff --git a/README.md b/README.md index 2e7b38f..0bbe438 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ Three agents share the same event model: skipped. - **Claude Code** — the `claude` agent — spawns `claude -p --output-format stream-json` and normalizes its events into the - same event model, with model selection between the `haiku`, `sonnet`, and - `opus` aliases and Claude permission modes on the request. + same event model, with model selection between the `haiku`, `sonnet`, + `opus`, and `fable` aliases and Claude permission modes on the request. - **Grok Build** — the `grok` agent — spawns Grok with `--no-auto-update`, `--output-format streaming-messages-json`, a temporary `--prompt-file`, and `--verbatim`. It uses read-only / `dontAsk` automation diff --git a/account_usage.go b/account_usage.go index 3ae71b2..4d2caea 100644 --- a/account_usage.go +++ b/account_usage.go @@ -185,7 +185,7 @@ func GetAccountUsage(ctx context.Context, req AccountUsageRequest) (*AccountUsag } // #nosec G204 -- launching the configured Codex executable is the wrapper boundary. - cmd := exec.CommandContext(ctx, executable, "-s", "read-only", "-a", "untrusted", "app-server", "--stdio") + cmd := exec.CommandContext(ctx, executable, "-s", "read-only", "-a", "never", "app-server", "--stdio") cmd.Env = accountUsageEnv(req.Env) // Bound teardown when killed child processes keep the pipes open. cmd.WaitDelay = time.Second diff --git a/account_usage_test.go b/account_usage_test.go index 9d5a3d0..8c7d96f 100644 --- a/account_usage_test.go +++ b/account_usage_test.go @@ -76,7 +76,7 @@ done assert.Contains(t, string(usage.RawAccount), "stub@example.com") args := readArgs(t, argsFile) - assert.Equal(t, []string{"-s", "read-only", "-a", "untrusted", "app-server", "--stdio"}, args) + assert.Equal(t, []string{"-s", "read-only", "-a", "never", "app-server", "--stdio"}, args) envBytes, err := os.ReadFile(envFile) require.NoError(t, err) diff --git a/bindings/node/README.md b/bindings/node/README.md index 5bd0d55..6df96ab 100644 --- a/bindings/node/README.md +++ b/bindings/node/README.md @@ -20,7 +20,7 @@ Grok must support `streaming-messages-json`. The Claude agent is selected with `new Runner({ agent: 'claude' })`; its events are normalized into the same event model, with model selection via the -`haiku`/`sonnet`/`opus` aliases (`ClaudeModel`). +`haiku`/`sonnet`/`opus`/`fable` aliases (`ClaudeModel`). Select Grok with `new Runner({ agent: 'grok' })`. New runs use read-only sandboxing and `dontAsk` permissions; Grok sessions are always persisted. diff --git a/bindings/node/__test__/smoke.test.mjs b/bindings/node/__test__/smoke.test.mjs index 1e0d24e..b7f8f12 100644 --- a/bindings/node/__test__/smoke.test.mjs +++ b/bindings/node/__test__/smoke.test.mjs @@ -159,6 +159,17 @@ test('claude and grok agents reject cyberAccessProgram', async () => { } }) +test('effort is passed to codex as model_reasoning_effort', async () => { + const { runner, argsFile } = runnerWithCapture() + + await runner.run({ prompt: 'x', effort: 'ultra' }) + + const args = readFileSync(argsFile, 'utf8').trim().split('\n') + const index = args.indexOf('model_reasoning_effort="ultra"') + assert.notEqual(index, -1) + assert.equal(args[index - 1], '-c') +}) + test('invalid agent is rejected instead of falling back to codex', () => { assert.throws( () => new Runner({ agent: 'unknown-agent' }), @@ -210,6 +221,7 @@ test('claude agent normalizes stream-json events', async () => { const result = await runner.run({ prompt: 'create hello.txt', model: ClaudeModel.Haiku, + effort: 'high', permissionMode: PermissionMode.AcceptEdits, }) @@ -263,11 +275,20 @@ test('claude agent normalizes stream-json events', async () => { assert.ok(args.includes('--verbose')) assert.ok(args.includes('--model')) assert.ok(args.includes('haiku')) + assert.equal(args[args.indexOf('--effort') + 1], 'high') assert.ok(args.includes('--permission-mode')) assert.ok(args.includes('acceptEdits')) assert.ok(args.includes('--no-session-persistence')) }) +test('ClaudeModel lists the claude --model aliases', () => { + assert.deepEqual( + { ...ClaudeModel }, + { Haiku: 'haiku', Sonnet: 'sonnet', Opus: 'opus', Fable: 'fable' }, + ) + assert.ok(Object.isFrozen(ClaudeModel)) +}) + test('claude agent rejects codex-only fields', async () => { const runner = new Runner({ agent: 'claude', executable: fakeClaude }) @@ -314,6 +335,7 @@ test('grok agent normalizes streaming-messages-json events', async () => { const result = await runner.run({ prompt: 'inspect', stdin: 'extra context', + effort: 'high', allowedTools: ['Bash(git *)'], }) @@ -348,6 +370,7 @@ test('grok agent normalizes streaming-messages-json events', async () => { ]) { assert.ok(args.includes(expected)) } + assert.equal(args[args.indexOf('--reasoning-effort') + 1], 'high') const promptIndex = args.indexOf('--prompt-file') assert.equal(existsSync(args[promptIndex + 1]), false) }) @@ -508,7 +531,7 @@ done '-s', 'read-only', '-a', - 'untrusted', + 'never', 'app-server', '--stdio', ]) diff --git a/bindings/node/binding.d.ts b/bindings/node/binding.d.ts index e59d715..5292bf1 100644 --- a/bindings/node/binding.d.ts +++ b/bindings/node/binding.d.ts @@ -261,6 +261,7 @@ export interface JsRequest { addDirs?: Array images?: Array model?: string + effort?: string profile?: string sandbox?: string approval?: string diff --git a/bindings/node/binding.js b/bindings/node/binding.js index 1e77ee5..172505e 100644 --- a/bindings/node/binding.js +++ b/bindings/node/binding.js @@ -77,8 +77,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-android-arm64') const bindingPackageVersion = require('@c3-oss/codexcw-android-arm64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -93,8 +93,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-android-arm-eabi') const bindingPackageVersion = require('@c3-oss/codexcw-android-arm-eabi/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -114,8 +114,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-win32-x64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-win32-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -130,8 +130,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-win32-x64-msvc') const bindingPackageVersion = require('@c3-oss/codexcw-win32-x64-msvc/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -147,8 +147,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-win32-ia32-msvc') const bindingPackageVersion = require('@c3-oss/codexcw-win32-ia32-msvc/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -163,8 +163,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-win32-arm64-msvc') const bindingPackageVersion = require('@c3-oss/codexcw-win32-arm64-msvc/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -182,8 +182,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-darwin-universal') const bindingPackageVersion = require('@c3-oss/codexcw-darwin-universal/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -198,8 +198,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-darwin-x64') const bindingPackageVersion = require('@c3-oss/codexcw-darwin-x64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -214,8 +214,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-darwin-arm64') const bindingPackageVersion = require('@c3-oss/codexcw-darwin-arm64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -234,8 +234,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-freebsd-x64') const bindingPackageVersion = require('@c3-oss/codexcw-freebsd-x64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -250,8 +250,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-freebsd-arm64') const bindingPackageVersion = require('@c3-oss/codexcw-freebsd-arm64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -271,8 +271,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-x64-musl') const bindingPackageVersion = require('@c3-oss/codexcw-linux-x64-musl/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -287,8 +287,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-x64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -305,8 +305,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-arm64-musl') const bindingPackageVersion = require('@c3-oss/codexcw-linux-arm64-musl/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -321,8 +321,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-arm64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-arm64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -339,8 +339,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-arm-musleabihf') const bindingPackageVersion = require('@c3-oss/codexcw-linux-arm-musleabihf/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -355,8 +355,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-arm-gnueabihf') const bindingPackageVersion = require('@c3-oss/codexcw-linux-arm-gnueabihf/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -373,8 +373,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-loong64-musl') const bindingPackageVersion = require('@c3-oss/codexcw-linux-loong64-musl/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -389,8 +389,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-loong64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-loong64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -407,8 +407,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-riscv64-musl') const bindingPackageVersion = require('@c3-oss/codexcw-linux-riscv64-musl/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -423,8 +423,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-riscv64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-riscv64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -440,8 +440,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-ppc64-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-ppc64-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -456,8 +456,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-linux-s390x-gnu') const bindingPackageVersion = require('@c3-oss/codexcw-linux-s390x-gnu/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -476,8 +476,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-openharmony-arm64') const bindingPackageVersion = require('@c3-oss/codexcw-openharmony-arm64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -492,8 +492,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-openharmony-x64') const bindingPackageVersion = require('@c3-oss/codexcw-openharmony-x64/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -508,8 +508,8 @@ function requireNative() { try { const binding = require('@c3-oss/codexcw-openharmony-arm') const bindingPackageVersion = require('@c3-oss/codexcw-openharmony-arm/package.json').version - if (bindingPackageVersion !== '0.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { diff --git a/bindings/node/index.d.ts b/bindings/node/index.d.ts index 974a2d2..e4b073f 100644 --- a/bindings/node/index.d.ts +++ b/bindings/node/index.d.ts @@ -6,7 +6,14 @@ export type Agent = 'codex' | 'claude' | 'grok' /** Sandbox policy passed to Codex or Grok. */ export type SandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access' -/** Approval policy mapped to Codex or Grok permissions. */ +/** + * Approval policy mapped to Codex or Grok permissions. + * + * `'untrusted'` is deprecated: Codex 0.167 and newer refuse it and exit before + * the run starts, so use `'on-request'` or `'never'` for Codex runs. It is still + * passed through for older Codex releases, and Grok runs still map it to + * Grok's default permission mode. + */ export type ApprovalPolicy = 'untrusted' | 'on-request' | 'never' /** Cyber access program requested from Codex. */ @@ -26,6 +33,7 @@ export declare const ClaudeModel: { readonly Haiku: 'haiku' readonly Sonnet: 'sonnet' readonly Opus: 'opus' + readonly Fable: 'fable' } /** Permission modes accepted by the claude agent's `permissionMode` field. */ @@ -231,6 +239,11 @@ export interface Request { addDirs?: string[] images?: string[] model?: string + /** + * Reasoning effort: Codex `model_reasoning_effort`, Claude `--effort`. + * Passed through unchecked; the grok agent receives --reasoning-effort. + */ + effort?: string profile?: string sandbox?: SandboxMode approval?: ApprovalPolicy diff --git a/bindings/node/index.js b/bindings/node/index.js index ebc6fe7..34f7b48 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -10,6 +10,7 @@ const ClaudeModel = Object.freeze({ Haiku: 'haiku', Sonnet: 'sonnet', Opus: 'opus', + Fable: 'fable', }) /** Permission modes accepted by the claude agent's `permissionMode` field. */ diff --git a/bindings/node/npm/darwin-arm64/package.json b/bindings/node/npm/darwin-arm64/package.json index adcedc2..da06170 100644 --- a/bindings/node/npm/darwin-arm64/package.json +++ b/bindings/node/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-darwin-arm64", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "arm64" ], diff --git a/bindings/node/npm/darwin-x64/package.json b/bindings/node/npm/darwin-x64/package.json index 322f29b..02fe27d 100644 --- a/bindings/node/npm/darwin-x64/package.json +++ b/bindings/node/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-darwin-x64", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "x64" ], diff --git a/bindings/node/npm/linux-arm64-gnu/package.json b/bindings/node/npm/linux-arm64-gnu/package.json index c38ee8b..ec18d96 100644 --- a/bindings/node/npm/linux-arm64-gnu/package.json +++ b/bindings/node/npm/linux-arm64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-linux-arm64-gnu", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "arm64" ], diff --git a/bindings/node/npm/linux-arm64-musl/package.json b/bindings/node/npm/linux-arm64-musl/package.json index 952e17e..50568f4 100644 --- a/bindings/node/npm/linux-arm64-musl/package.json +++ b/bindings/node/npm/linux-arm64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-linux-arm64-musl", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "arm64" ], diff --git a/bindings/node/npm/linux-x64-gnu/package.json b/bindings/node/npm/linux-x64-gnu/package.json index 528358f..1228786 100644 --- a/bindings/node/npm/linux-x64-gnu/package.json +++ b/bindings/node/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-linux-x64-gnu", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "x64" ], diff --git a/bindings/node/npm/linux-x64-musl/package.json b/bindings/node/npm/linux-x64-musl/package.json index 67e11d8..56add68 100644 --- a/bindings/node/npm/linux-x64-musl/package.json +++ b/bindings/node/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-linux-x64-musl", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "x64" ], diff --git a/bindings/node/npm/win32-x64-msvc/package.json b/bindings/node/npm/win32-x64-msvc/package.json index 02b2c30..c880de1 100644 --- a/bindings/node/npm/win32-x64-msvc/package.json +++ b/bindings/node/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw-win32-x64-msvc", - "version": "0.6.0", + "version": "0.7.0", "cpu": [ "x64" ], diff --git a/bindings/node/package.json b/bindings/node/package.json index 189b1ff..1a9125a 100644 --- a/bindings/node/package.json +++ b/bindings/node/package.json @@ -1,6 +1,6 @@ { "name": "@c3-oss/codexcw", - "version": "0.6.0", + "version": "0.7.0", "description": "Run Codex, Claude Code, or Grok Build non-interactively from Node.js, backed by a Rust core.", "license": "CC0-1.0", "repository": { @@ -43,12 +43,12 @@ "node": ">=18" }, "optionalDependencies": { - "@c3-oss/codexcw-darwin-x64": "0.6.0", - "@c3-oss/codexcw-darwin-arm64": "0.6.0", - "@c3-oss/codexcw-linux-x64-gnu": "0.6.0", - "@c3-oss/codexcw-linux-arm64-gnu": "0.6.0", - "@c3-oss/codexcw-linux-x64-musl": "0.6.0", - "@c3-oss/codexcw-win32-x64-msvc": "0.6.0" + "@c3-oss/codexcw-darwin-x64": "0.7.0", + "@c3-oss/codexcw-darwin-arm64": "0.7.0", + "@c3-oss/codexcw-linux-x64-gnu": "0.7.0", + "@c3-oss/codexcw-linux-arm64-gnu": "0.7.0", + "@c3-oss/codexcw-linux-x64-musl": "0.7.0", + "@c3-oss/codexcw-win32-x64-msvc": "0.7.0" }, "devDependencies": { "@napi-rs/cli": "3.7.2" diff --git a/bindings/node/src/lib.rs b/bindings/node/src/lib.rs index 3155757..138fab6 100644 --- a/bindings/node/src/lib.rs +++ b/bindings/node/src/lib.rs @@ -312,6 +312,7 @@ pub struct JsRequest { pub add_dirs: Option>, pub images: Option>, pub model: Option, + pub effort: Option, pub profile: Option, pub sandbox: Option, pub approval: Option, @@ -364,6 +365,7 @@ fn parse_sandbox(value: &str) -> Result { } } +#[allow(deprecated)] fn parse_approval(value: &str) -> Result { match value { "untrusted" => Ok(ApprovalPolicy::Untrusted), @@ -423,6 +425,7 @@ fn to_core_request(req: JsRequest) -> Result { add_dirs: req.add_dirs.unwrap_or_default(), images: req.images.unwrap_or_default(), model: req.model, + effort: req.effort, profile: req.profile, sandbox, approval, diff --git a/bindings/python/README.md b/bindings/python/README.md index a781b56..693c805 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -14,7 +14,7 @@ execution, a read-only sandbox, and approval `never`. The Claude agent is selected with `Runner(agent=codexcw.AGENT_CLAUDE)`; its events are normalized into the same event model, with model selection via the -`haiku`/`sonnet`/`opus` aliases (`CLAUDE_MODEL_*`). +`haiku`/`sonnet`/`opus`/`fable` aliases (`CLAUDE_MODEL_*`). Select Grok with `Runner(agent=codexcw.AGENT_GROK)`. New runs use read-only sandboxing and `dontAsk` permissions; Grok sessions are always persisted. diff --git a/bindings/python/pyproject.toml b/bindings/python/pyproject.toml index 109c1a3..78e06b7 100644 --- a/bindings/python/pyproject.toml +++ b/bindings/python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "codexcw" -version = "0.6.0" +version = "0.7.0" description = "Run Codex, Claude Code, or Grok Build non-interactively from Python, backed by a Rust core." readme = "README.md" requires-python = ">=3.9" diff --git a/bindings/python/python/codexcw/__init__.py b/bindings/python/python/codexcw/__init__.py index be477c4..3ca9d5c 100644 --- a/bindings/python/python/codexcw/__init__.py +++ b/bindings/python/python/codexcw/__init__.py @@ -44,6 +44,7 @@ "AGENT_CLAUDE", "AGENT_CODEX", "AGENT_GROK", + "CLAUDE_MODEL_FABLE", "CLAUDE_MODEL_HAIKU", "CLAUDE_MODEL_OPUS", "CLAUDE_MODEL_SONNET", @@ -90,6 +91,10 @@ ] # String literals accepted by ``Request.sandbox`` and ``Request.approval``. +# The ``untrusted`` approval is deprecated: Codex 0.167 and newer refuse it and +# exit before the run starts, so use ``on-request`` or ``never`` for Codex runs. +# It is still passed through for older Codex releases, and Grok runs still map +# it to Grok's default permission mode. SandboxMode = str ApprovalPolicy = str @@ -110,6 +115,7 @@ CLAUDE_MODEL_HAIKU = "haiku" CLAUDE_MODEL_SONNET = "sonnet" CLAUDE_MODEL_OPUS = "opus" +CLAUDE_MODEL_FABLE = "fable" # Permission modes accepted by the claude agent's ``Request.permission_mode``. PERMISSION_ACCEPT_EDITS = "acceptEdits" @@ -238,6 +244,10 @@ class Request: resume_last: bool = False resume_all: bool = False cyber_access_program: Optional[CyberAccessProgram] = None + # Codex ``model_reasoning_effort`` or Claude ``--effort``, passed through + # unchecked; the grok agent receives --reasoning-effort. Appended last to keep positional + # construction of earlier fields stable. + effort: Optional[str] = None @dataclass diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index f3a761f..e1f1c33 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -416,6 +416,7 @@ struct ReqData { add_dirs: Option>, images: Option>, model: Option, + effort: Option, profile: Option, sandbox: Option, approval: Option, @@ -463,6 +464,7 @@ impl ReqData { add_dirs: self.add_dirs.unwrap_or_default(), images: self.images.unwrap_or_default(), model: self.model, + effort: self.effort, profile: self.profile, sandbox, approval, @@ -555,6 +557,7 @@ fn parse_sandbox(value: &str) -> Result { } } +#[allow(deprecated)] fn parse_approval(value: &str) -> Result { match value { "untrusted" => Ok(ApprovalPolicy::Untrusted), diff --git a/bindings/python/tests/test_smoke.py b/bindings/python/tests/test_smoke.py index 187773e..4f1b8e9 100644 --- a/bindings/python/tests/test_smoke.py +++ b/bindings/python/tests/test_smoke.py @@ -184,6 +184,23 @@ def test_claude_and_grok_agents_reject_cyber_access_program(agent, executable): assert "cyber access program is not supported" in str(excinfo.value) +def test_effort_is_passed_to_codex_as_model_reasoning_effort(tmp_path): + runner, args_file, _ = _runner_with_capture(tmp_path) + + runner.run(Request(prompt="x", effort="ultra")) + + args = args_file.read_text().strip().split("\n") + index = args.index('model_reasoning_effort="ultra"') + assert args[index - 1] == "-c" + + +def test_effort_is_appended_after_existing_request_fields(): + fields = list(Request.__dataclass_fields__) + + assert fields.index("cyber_access_program") == 29 + assert fields.index("effort") == 30 + + def test_invalid_agent_is_rejected_instead_of_falling_back_to_codex(): with pytest.raises(CodexcwError) as excinfo: Runner(agent="unknown-agent") @@ -227,6 +244,7 @@ def test_claude_agent_normalizes_events(tmp_path): Request( prompt="create hello.txt", model=codexcw.CLAUDE_MODEL_HAIKU, + effort="high", permission_mode=codexcw.PERMISSION_ACCEPT_EDITS, ) ) @@ -274,11 +292,20 @@ def test_claude_agent_normalizes_events(tmp_path): assert "--verbose" in args assert "--model" in args assert "haiku" in args + assert args[args.index("--effort") + 1] == "high" assert "--permission-mode" in args assert "acceptEdits" in args assert "--no-session-persistence" in args +def test_claude_model_aliases_match_the_cli(): + assert codexcw.CLAUDE_MODEL_HAIKU == "haiku" + assert codexcw.CLAUDE_MODEL_SONNET == "sonnet" + assert codexcw.CLAUDE_MODEL_OPUS == "opus" + assert codexcw.CLAUDE_MODEL_FABLE == "fable" + assert "CLAUDE_MODEL_FABLE" in codexcw.__all__ + + def test_claude_agent_rejects_codex_only_fields(tmp_path): runner = Runner(agent=codexcw.AGENT_CLAUDE, executable=str(FAKE_CLAUDE)) @@ -320,6 +347,7 @@ def test_grok_agent_normalizes_streaming_messages(tmp_path): Request( prompt="inspect", stdin="extra context", + effort="high", allowed_tools=["Bash(git *)"], ) ) @@ -356,6 +384,7 @@ def test_grok_agent_normalizes_streaming_messages(tmp_path): "Bash(git *)", ]: assert expected in args + assert args[args.index("--reasoning-effort") + 1] == "high" prompt_index = args.index("--prompt-file") assert not Path(args[prompt_index + 1]).exists() @@ -486,7 +515,7 @@ def test_get_account_usage_reads_limits(tmp_path): "-s", "read-only", "-a", - "untrusted", + "never", "app-server", "--stdio", ] diff --git a/bindings/python/uv.lock b/bindings/python/uv.lock index 0b88976..0c2c566 100644 --- a/bindings/python/uv.lock +++ b/bindings/python/uv.lock @@ -17,7 +17,7 @@ wheels = [ [[package]] name = "codexcw" -version = "0.6.0" +version = "0.7.0" source = { editable = "." } [package.optional-dependencies] diff --git a/claude.go b/claude.go index 75afb90..119b3d4 100644 --- a/claude.go +++ b/claude.go @@ -42,6 +42,9 @@ const ( // ClaudeModelOpus selects the latest Claude Opus model. ClaudeModelOpus = "opus" + + // ClaudeModelFable selects the latest Claude Fable model. + ClaudeModelFable = "fable" ) func (r *Runner) prepareClaude(req Request) (_ []string, _ io.Reader, cleanup func(), err error) { @@ -62,6 +65,9 @@ func (r *Runner) prepareClaude(req Request) (_ []string, _ io.Reader, cleanup fu if req.Model != "" { args = append(args, "--model", req.Model) } + if req.Effort != "" { + args = append(args, "--effort", req.Effort) + } if req.PermissionMode != "" { args = append(args, "--permission-mode", string(req.PermissionMode)) } diff --git a/claude_test.go b/claude_test.go index 970e5ed..0a67dd0 100644 --- a/claude_test.go +++ b/claude_test.go @@ -243,6 +243,7 @@ func TestClaudePrepareBuildsAdvancedArgs(t *testing.T) { Dir: "/work", AddDirs: []string{"/other"}, Model: ClaudeModelOpus, + Effort: "max", PermissionMode: PermissionAcceptEdits, AllowedTools: []string{"Bash(git *)", "Edit"}, DisallowedTools: []string{"WebSearch"}, @@ -261,7 +262,7 @@ func TestClaudePrepareBuildsAdvancedArgs(t *testing.T) { for _, want := range []string{ "-p", "--output-format", "stream-json", "--verbose", - "--model", "opus", "--permission-mode", "acceptEdits", + "--model", "opus", "--effort", "max", "--permission-mode", "acceptEdits", "--allowed-tools", "Bash(git *)", "Edit", "--disallowed-tools", "WebSearch", "--dangerously-skip-permissions", "--add-dir", "/other", "--json-schema", `{"type":"object"}`, @@ -277,6 +278,13 @@ func TestClaudePermissionModeConstants(t *testing.T) { assert.Equal(t, PermissionMode("manual"), PermissionManual) } +func TestClaudeModelAliases(t *testing.T) { + assert.Equal(t, "haiku", ClaudeModelHaiku) + assert.Equal(t, "sonnet", ClaudeModelSonnet) + assert.Equal(t, "opus", ClaudeModelOpus) + assert.Equal(t, "fable", ClaudeModelFable) +} + func TestUnknownAgentIsRejectedBeforeStartingAProcess(t *testing.T) { marker := filepath.Join(t.TempDir(), "started") fake := writeFakeCodex(t, `touch "$CODEXCW_STARTED_FILE"`) diff --git a/crates/codexcw/README.md b/crates/codexcw/README.md index 25a03b9..e8eea17 100644 --- a/crates/codexcw/README.md +++ b/crates/codexcw/README.md @@ -12,8 +12,8 @@ Three agents share the same `Event` model: skipped. - **Claude Code** — `Runner::builder().agent(Agent::Claude)` — spawns `claude -p --output-format stream-json` and normalizes its events into the - same `Event` model, with model selection via the `haiku`/`sonnet`/`opus` - aliases (`claude_model`). + same `Event` model, with model selection via the + `haiku`/`sonnet`/`opus`/`fable` aliases (`claude_model`). - **Grok Build** — `Runner::builder().agent(Agent::Grok)` — uses `--no-auto-update` with `streaming-messages-json` and normalizes Messages-compatible events and tools into the same model. New runs default diff --git a/crates/codexcw/src/account_usage.rs b/crates/codexcw/src/account_usage.rs index c123e96..f736066 100644 --- a/crates/codexcw/src/account_usage.rs +++ b/crates/codexcw/src/account_usage.rs @@ -287,14 +287,7 @@ pub async fn get_account_usage(req: AccountUsageRequest) -> Result Vec { } } +fn toml_string(value: &str) -> String { + // JSON string escapes are valid in TOML. TOML also requires escaping DEL. + serde_json::to_string(value) + .expect("serializing a string is infallible") + .replace('\x7f', "\\u007f") +} + pub(crate) fn nonempty(value: &Option) -> Option { value.as_ref().filter(|v| !v.is_empty()).cloned() } @@ -278,6 +289,7 @@ mod tests { add_dirs: vec!["/other".to_string()], images: vec!["image.png".to_string()], model: Some("gpt-test".to_string()), + effort: Some("xhigh".to_string()), profile: Some("work".to_string()), sandbox: Some(SandboxMode::WorkspaceWrite), approval: Some(ApprovalPolicy::OnRequest), @@ -313,6 +325,7 @@ mod tests { "--strict-config", "-m", "gpt-test", + r#"model_reasoning_effort="xhigh""#, "-p", "work", "--enable", @@ -346,6 +359,37 @@ mod tests { } } + #[test] + fn passes_any_effort_as_quoted_config() { + let (s, a) = defaults(); + for (effort, want) in [ + ("a\n\x01\x7f", r#"model_reasoning_effort="a\n\u0001\u007f""#), + ("ultra", r#"model_reasoning_effort="ultra""#), + (r#"a"b\c"#, r#"model_reasoning_effort="a\"b\\c""#), + ] { + let prepared = prepare(&Request::new("x").effort(effort), s, a).unwrap(); + let index = prepared.args.iter().position(|arg| arg == want).unwrap(); + assert_eq!(prepared.args[index - 1], "-c"); + } + + let prepared = prepare(&Request::new("x"), s, a).unwrap(); + assert!(!prepared + .args + .iter() + .any(|arg| arg.contains("model_reasoning_effort"))); + } + + #[test] + #[allow(deprecated)] + fn still_passes_deprecated_untrusted_approval() { + let (s, a) = defaults(); + let prepared = + prepare(&Request::new("x").approval(ApprovalPolicy::Untrusted), s, a).unwrap(); + assert!(prepared + .args + .contains(&r#"approval_policy="untrusted""#.to_string())); + } + #[test] fn builds_resume_args() { let (s, a) = defaults(); @@ -355,14 +399,16 @@ mod tests { resume_all: true, persistent: true, sandbox: Some(SandboxMode::DangerFullAccess), - approval: Some(ApprovalPolicy::Untrusted), + approval: Some(ApprovalPolicy::OnRequest), cyber_access_program: Some(CyberAccessProgram::Standard), + effort: Some("low".to_string()), ..Default::default() }; let prepared = prepare(&req, s, a).unwrap(); let args = &prepared.args; assert_eq!(args[0], "exec"); assert_eq!(args[1], "resume"); + assert!(args.contains(&r#"model_reasoning_effort="low""#.to_string())); let program_index = args .iter() .position(|a| a == "--cyber-access-program") @@ -371,7 +417,7 @@ mod tests { assert!(args.contains(&"--all".to_string())); assert!(args.contains(&"thread-id".to_string())); assert!(args.contains(&r#"sandbox_mode="danger-full-access""#.to_string())); - assert!(args.contains(&r#"approval_policy="untrusted""#.to_string())); + assert!(args.contains(&r#"approval_policy="on-request""#.to_string())); assert!(!args.contains(&"--ephemeral".to_string())); assert_eq!(args.last().unwrap(), "-"); } diff --git a/crates/codexcw/src/claude.rs b/crates/codexcw/src/claude.rs index 4fb55b2..ce8cd9f 100644 --- a/crates/codexcw/src/claude.rs +++ b/crates/codexcw/src/claude.rs @@ -34,6 +34,10 @@ pub(crate) fn prepare_claude(req: &Request) -> Result { args.push("--model".to_string()); args.push(model); } + if let Some(effort) = nonempty(&req.effort) { + args.push("--effort".to_string()); + args.push(effort); + } if let Some(mode) = nonempty(&req.permission_mode) { args.push("--permission-mode".to_string()); args.push(mode); @@ -715,13 +719,22 @@ fn item_completed(base: &Event, item: Item) -> Event { #[cfg(test)] mod tests { use super::*; - use crate::request::Request; + use crate::request::{claude_model, Request}; + + #[test] + fn claude_model_aliases_match_the_cli() { + assert_eq!(claude_model::HAIKU, "haiku"); + assert_eq!(claude_model::SONNET, "sonnet"); + assert_eq!(claude_model::OPUS, "opus"); + assert_eq!(claude_model::FABLE, "fable"); + } #[test] fn builds_claude_args() { let req = Request { prompt: "diga oi".to_string(), model: Some("haiku".to_string()), + effort: Some("max".to_string()), permission_mode: Some("acceptEdits".to_string()), allowed_tools: vec!["Bash(git *)".to_string()], disallowed_tools: vec!["WebSearch".to_string()], @@ -740,6 +753,8 @@ mod tests { "--verbose", "--model", "haiku", + "--effort", + "max", "--permission-mode", "acceptEdits", "--allowed-tools", diff --git a/crates/codexcw/src/grok.rs b/crates/codexcw/src/grok.rs index 22f281d..4665c48 100644 --- a/crates/codexcw/src/grok.rs +++ b/crates/codexcw/src/grok.rs @@ -54,6 +54,10 @@ pub(crate) fn prepare_grok( args.push("--model".to_string()); args.push(model); } + if let Some(effort) = nonempty(&req.effort) { + args.push("--reasoning-effort".to_string()); + args.push(effort); + } if let Some(profile) = nonempty(&req.profile) { args.push("--agent".to_string()); args.push(profile); @@ -179,6 +183,7 @@ fn grok_sandbox(sandbox: SandboxMode) -> &'static str { } } +#[allow(deprecated)] fn grok_approval(approval: ApprovalPolicy) -> &'static str { match approval { ApprovalPolicy::Never => "dontAsk", @@ -232,6 +237,7 @@ mod tests { stdin: Some(b"extra".to_vec()), dir: Some("/work".to_string()), model: Some("grok-4.6".to_string()), + effort: Some("high".to_string()), profile: Some("reviewer".to_string()), sandbox: Some(SandboxMode::WorkspaceWrite), permission_mode: Some("acceptEdits".to_string()), @@ -252,6 +258,8 @@ mod tests { "/work", "--model", "grok-4.6", + "--reasoning-effort", + "high", "--agent", "reviewer", "--sandbox", diff --git a/crates/codexcw/src/request.rs b/crates/codexcw/src/request.rs index df8e0f4..787dfc3 100644 --- a/crates/codexcw/src/request.rs +++ b/crates/codexcw/src/request.rs @@ -32,6 +32,9 @@ impl std::fmt::Display for SandboxMode { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ApprovalPolicy { /// Ask before commands outside Codex's trusted set. + #[deprecated( + note = "Codex 0.167 and newer refuse approval_policy=\"untrusted\"; use OnRequest or Never for Codex runs" + )] Untrusted, /// Work in the sandbox and request approval on demand. OnRequest, @@ -41,6 +44,7 @@ pub enum ApprovalPolicy { impl ApprovalPolicy { /// Returns the wire string for this approval policy. + #[allow(deprecated)] pub fn as_str(&self) -> &'static str { match self { ApprovalPolicy::Untrusted => "untrusted", @@ -92,6 +96,8 @@ pub mod claude_model { pub const SONNET: &str = "sonnet"; /// The latest Claude Opus model. pub const OPUS: &str = "opus"; + /// The latest Claude Fable model. + pub const FABLE: &str = "fable"; } /// Permission modes accepted by Claude and Grok. @@ -157,6 +163,11 @@ pub struct Request { pub images: Vec, /// Model override for this run. pub model: Option, + /// Reasoning effort for this run: Codex receives it as the + /// `model_reasoning_effort` config value and Claude as `--effort`; the + /// grok agent receives --reasoning-effort. The value is passed through unchecked because + /// the accepted levels depend on the agent version and the selected model. + pub effort: Option, /// Codex config profile or Grok agent name. pub profile: Option, /// Sandbox policy override (Codex and Grok). @@ -234,6 +245,12 @@ impl Request { self } + /// Sets the reasoning effort. + pub fn effort(mut self, effort: impl Into) -> Self { + self.effort = Some(effort.into()); + self + } + /// Sets the sandbox policy. pub fn sandbox(mut self, sandbox: SandboxMode) -> Self { self.sandbox = Some(sandbox); diff --git a/crates/codexcw/tests/account_usage_it.rs b/crates/codexcw/tests/account_usage_it.rs index 2bf7c2c..8a352ac 100644 --- a/crates/codexcw/tests/account_usage_it.rs +++ b/crates/codexcw/tests/account_usage_it.rs @@ -102,14 +102,7 @@ done let args = read_args(&fake.args_file); assert_eq!( args, - [ - "-s", - "read-only", - "-a", - "untrusted", - "app-server", - "--stdio" - ] + ["-s", "read-only", "-a", "never", "app-server", "--stdio"] ); assert_eq!( std::fs::read_to_string(&fake.stdin_file).unwrap(), diff --git a/docs/examples/csharp.md b/docs/examples/csharp.md index 2a3806c..54349f4 100644 --- a/docs/examples/csharp.md +++ b/docs/examples/csharp.md @@ -176,6 +176,13 @@ await runner.RunAsync(new Request }); ``` +`ApprovalPolicy.Untrusted` is deprecated. Codex 0.167 and newer refuse +`approval_policy="untrusted"` and exit before the run starts (the exit error's +captured stderr holds Codex's "no longer supported" message), so use +`ApprovalPolicy.OnRequest` or `ApprovalPolicy.Never` for Codex runs. The value +is still passed through for older Codex releases, and Grok runs still map it to +Grok's `default` permission mode. + ## ⚠️ Bypass sandbox and approvals > **Danger.** `DangerouslyBypassSandbox` runs Codex with @@ -303,6 +310,21 @@ await runner.RunAsync(new Request }); ``` +## Reasoning effort + +`Effort` sets the reasoning effort for one run. Codex receives it as +`-c model_reasoning_effort=""` (new runs and resume) and Claude as +`--effort `. The value is passed through unchecked: Codex accepts a +different set of levels per model (`codex debug models` lists each model's +`supported_reasoning_levels`, such as `low` through `max` or `ultra`), and +Claude Code accepts `low`, `medium`, `high`, `xhigh`, and `max`. Grok receives +`--reasoning-effort `. A raw +`model_reasoning_effort` config override is passed after it and wins. + +```csharp +await runner.RunAsync(new Request { Prompt = "...", Effort = "high" }); +``` + ## Cyber access program `CyberAccessProgram` passes `--cyber-access-program` to Codex, on new runs and @@ -338,7 +360,7 @@ var runner = new Runner(new RunnerOptions { Agent = Agent.Claude }); var result = await runner.RunAsync(new Request { Prompt = "crie um arquivo TODO.md", - Model = ClaudeModels.Haiku, // "haiku", "sonnet", or "opus" + Model = ClaudeModels.Haiku, // "haiku", "sonnet", "opus", or "fable" PermissionMode = PermissionMode.AcceptEdits, }); @@ -366,8 +388,9 @@ await runner.RunAsync(new Request ``` Claude runs support `Dir` (applied as the process working directory), -`AddDirs`, `OutputSchema`/`OutputSchemaPath` (passed as `--json-schema`), and -`DangerouslyBypassSandbox` (passed as `--dangerously-skip-permissions`). +`AddDirs`, `Effort` (passed as `--effort`), `OutputSchema`/`OutputSchemaPath` +(passed as `--json-schema`), and `DangerouslyBypassSandbox` (passed as +`--dangerously-skip-permissions`). `PermissionMode`, `AllowedTools`, and `DisallowedTools` are claude-only; codex-only fields (`Sandbox`, `Approval`, `Profile`, `Config`, `Images`, feature flags) throw `InvalidRequestException` on a claude runner. diff --git a/docs/examples/go.md b/docs/examples/go.md index b62f50a..2546e1e 100644 --- a/docs/examples/go.md +++ b/docs/examples/go.md @@ -172,6 +172,13 @@ _, _ = runner.Run(ctx, codexcw.Request{ }) ``` +`ApprovalUntrusted` is deprecated. Codex 0.167 and newer refuse +`approval_policy="untrusted"` and exit before the run starts (the exit error's +captured stderr holds Codex's "no longer supported" message), so use +`ApprovalOnRequest` or `ApprovalNever` for Codex runs. The value is still passed +through for older Codex releases, and Grok runs still map it to Grok's `default` +permission mode. + ## ⚠️ Bypass sandbox and approvals > **Danger.** `DangerouslyBypassSandbox` runs Codex with @@ -284,6 +291,24 @@ _, _ = runner.Run(ctx, codexcw.Request{ }) ``` +## Reasoning effort + +`Effort` sets the reasoning effort for one run. Codex receives it as +`-c model_reasoning_effort=""` (new runs and resume) and Claude as +`--effort `. The value is passed through unchecked: Codex accepts a +different set of levels per model (`codex debug models` lists each model's +`supported_reasoning_levels`, such as `low` through `max` or `ultra`), and +Claude Code accepts `low`, `medium`, `high`, `xhigh`, and `max`. Grok receives +`--reasoning-effort `. A raw +`model_reasoning_effort` config override is passed after it and wins. + +```go +_, _ = runner.Run(ctx, codexcw.Request{ + Prompt: "...", + Effort: "high", +}) +``` + ## Cyber access program `CyberAccessProgram` passes `--cyber-access-program` to Codex, on new runs and @@ -323,7 +348,7 @@ runner := codexcw.New(codexcw.WithAgent(codexcw.AgentClaude)) result, err := runner.Run(ctx, codexcw.Request{ Prompt: "crie um arquivo TODO.md", - Model: codexcw.ClaudeModelHaiku, // "haiku", "sonnet", or "opus" + Model: codexcw.ClaudeModelHaiku, // "haiku", "sonnet", "opus", or "fable" PermissionMode: codexcw.PermissionAcceptEdits, }) if err != nil { @@ -352,8 +377,9 @@ _, _ = runner.Run(ctx, codexcw.Request{ ``` Claude runs support `Dir` (applied as the process working directory), -`AddDirs`, `OutputSchema`/`OutputSchemaPath` (passed as `--json-schema`), and -`DangerouslyBypassSandbox` (passed as `--dangerously-skip-permissions`). +`AddDirs`, `Effort` (passed as `--effort`), `OutputSchema`/`OutputSchemaPath` +(passed as `--json-schema`), and `DangerouslyBypassSandbox` (passed as +`--dangerously-skip-permissions`). `PermissionMode`, `AllowedTools`, and `DisallowedTools` are claude-only; codex-only fields (`Sandbox`, `Approval`, `Profile`, `Config`, `Images`, feature flags) return `ErrInvalidRequest` on a claude runner. diff --git a/docs/examples/python.md b/docs/examples/python.md index 95d5c30..421759a 100644 --- a/docs/examples/python.md +++ b/docs/examples/python.md @@ -154,6 +154,13 @@ runner.run(req) # sync await runner.run(req) # async ``` +`"untrusted"` is deprecated. Codex 0.167 and newer refuse +`approval_policy="untrusted"` and exit before the run starts (the exit error's +captured stderr holds Codex's "no longer supported" message), so use +`"on-request"` or `"never"` for Codex runs. The value is still passed through +for older Codex releases, and Grok runs still map it to Grok's `default` +permission mode. + ## ⚠️ Bypass sandbox and approvals > **Danger.** `dangerously_bypass_sandbox` runs Codex with @@ -257,6 +264,21 @@ runner.run(req) await runner.run(req) ``` +## Reasoning effort + +`effort` sets the reasoning effort for one run. Codex receives it as +`-c model_reasoning_effort=""` (new runs and resume) and Claude as +`--effort `. The value is passed through unchecked: Codex accepts a +different set of levels per model (`codex debug models` lists each model's +`supported_reasoning_levels`, such as `low` through `max` or `ultra`), and +Claude Code accepts `low`, `medium`, `high`, `xhigh`, and `max`. Grok receives +`--reasoning-effort `. A raw +`model_reasoning_effort` config override is passed after it and wins. + +```python +runner.run(Request(prompt="...", effort="high")) +``` + ## Cyber access program `cyber_access_program` passes `--cyber-access-program` to Codex, on new runs @@ -292,7 +314,7 @@ runner = codexcw.Runner(agent=codexcw.AGENT_CLAUDE) result = runner.run( codexcw.Request( prompt="crie um arquivo TODO.md", - model=codexcw.CLAUDE_MODEL_HAIKU, # "haiku", "sonnet", or "opus" + model=codexcw.CLAUDE_MODEL_HAIKU, # "haiku", "sonnet", "opus", or "fable" permission_mode=codexcw.PERMISSION_ACCEPT_EDITS, ) ) @@ -325,7 +347,8 @@ runner.run( ``` Claude runs support `dir` (applied as the process working directory), -`add_dirs`, `output_schema`/`output_schema_path` (passed as `--json-schema`), +`add_dirs`, `effort` (passed as `--effort`), +`output_schema`/`output_schema_path` (passed as `--json-schema`), and `dangerously_bypass_sandbox` (passed as `--dangerously-skip-permissions`). `permission_mode`, `allowed_tools`, and `disallowed_tools` are claude-only; codex-only fields (`sandbox`, `approval`, diff --git a/docs/examples/rust.md b/docs/examples/rust.md index 8de2c16..573f374 100644 --- a/docs/examples/rust.md +++ b/docs/examples/rust.md @@ -168,6 +168,13 @@ let req = Request::new("...") runner.run(req).await?; ``` +`ApprovalPolicy::Untrusted` is deprecated. Codex 0.167 and newer refuse +`approval_policy="untrusted"` and exit before the run starts (the exit error's +captured stderr holds Codex's "no longer supported" message), so use +`ApprovalPolicy::OnRequest` or `ApprovalPolicy::Never` for Codex runs. The value +is still passed through for older Codex releases, and Grok runs still map it to +Grok's `default` permission mode. + ## ⚠️ Bypass sandbox and approvals > **Danger.** `dangerously_bypass_sandbox` runs Codex with @@ -293,6 +300,21 @@ runner.run(Request { }).await?; ``` +## Reasoning effort + +`effort` sets the reasoning effort for one run. Codex receives it as +`-c model_reasoning_effort=""` (new runs and resume) and Claude as +`--effort `. The value is passed through unchecked: Codex accepts a +different set of levels per model (`codex debug models` lists each model's +`supported_reasoning_levels`, such as `low` through `max` or `ultra`), and +Claude Code accepts `low`, `medium`, `high`, `xhigh`, and `max`. Grok receives +`--reasoning-effort `. A raw +`model_reasoning_effort` config override is passed after it and wins. + +```rust +runner.run(Request::new("...").effort("high")).await?; +``` + ## Cyber access program `cyber_access_program` passes `--cyber-access-program` to Codex, on new runs @@ -335,7 +357,7 @@ let runner = Runner::builder().agent(Agent::Claude).build(); let result = runner .run(Request { prompt: "crie um arquivo TODO.md".to_string(), - model: Some(claude_model::HAIKU.to_string()), // HAIKU, SONNET, or OPUS + model: Some(claude_model::HAIKU.to_string()), // HAIKU, SONNET, OPUS, or FABLE permission_mode: Some(permission_mode::ACCEPT_EDITS.to_string()), ..Default::default() }) @@ -382,7 +404,8 @@ let _ = runner ``` Claude runs support `dir` (applied as the process working directory), -`add_dirs`, `output_schema`/`output_schema_path` (passed as `--json-schema`), +`add_dirs`, `effort` (passed as `--effort`), +`output_schema`/`output_schema_path` (passed as `--json-schema`), and `dangerously_bypass_sandbox` (passed as `--dangerously-skip-permissions`). `permission_mode`, `allowed_tools`, and `disallowed_tools` are claude-only; codex-only fields (`sandbox`, `approval`, diff --git a/docs/examples/typescript.md b/docs/examples/typescript.md index 0554761..0257a4b 100644 --- a/docs/examples/typescript.md +++ b/docs/examples/typescript.md @@ -108,6 +108,13 @@ await runner.run({ prompt: '...', sandbox: 'danger-full-access' }) await runner.run({ prompt: '...', sandbox: 'workspace-write', approval: 'on-request' }) ``` +`'untrusted'` is deprecated. Codex 0.167 and newer refuse +`approval_policy="untrusted"` and exit before the run starts (the exit error's +captured stderr holds Codex's "no longer supported" message), so use +`'on-request'` or `'never'` for Codex runs. The value is still passed through +for older Codex releases, and Grok runs still map it to Grok's `default` +permission mode. + ## ⚠️ Bypass sandbox and approvals > **Danger.** `dangerouslyBypassSandbox` runs Codex with @@ -203,6 +210,21 @@ await runner.run({ await runner.run({ prompt: '...', model: 'o3', profile: 'work' }) ``` +## Reasoning effort + +`effort` sets the reasoning effort for one run. Codex receives it as +`-c model_reasoning_effort=""` (new runs and resume) and Claude as +`--effort `. The value is passed through unchecked: Codex accepts a +different set of levels per model (`codex debug models` lists each model's +`supported_reasoning_levels`, such as `low` through `max` or `ultra`), and +Claude Code accepts `low`, `medium`, `high`, `xhigh`, and `max`. Grok receives +`--reasoning-effort `. A raw +`model_reasoning_effort` config override is passed after it and wins. + +```ts +await runner.run({ prompt: '...', effort: 'high' }) +``` + ## Cyber access program `cyberAccessProgram` passes `--cyber-access-program` to Codex, on new runs and @@ -235,7 +257,7 @@ const runner = new Runner({ agent: 'claude' }) const result = await runner.run({ prompt: 'crie um arquivo TODO.md', - model: ClaudeModel.Haiku, // 'haiku', 'sonnet', or 'opus' + model: ClaudeModel.Haiku, // 'haiku', 'sonnet', 'opus', or 'fable' permissionMode: PermissionMode.AcceptEdits, }) @@ -263,8 +285,9 @@ await runner.run({ ``` Claude runs support `dir` (applied as the process working directory), -`addDirs`, `outputSchema`/`outputSchemaPath` (passed as `--json-schema`), and -`dangerouslyBypassSandbox` (passed as `--dangerously-skip-permissions`). +`addDirs`, `effort` (passed as `--effort`), `outputSchema`/`outputSchemaPath` +(passed as `--json-schema`), and `dangerouslyBypassSandbox` (passed as +`--dangerously-skip-permissions`). `permissionMode`, `allowedTools`, and `disallowedTools` are claude-only; codex-only fields (`sandbox`, `approval`, `profile`, `config`, `images`, feature flags) reject with an `invalidRequest` error on a claude runner. diff --git a/dotnet/Codexcw.Tests/AccountUsageTests.cs b/dotnet/Codexcw.Tests/AccountUsageTests.cs index 9daa94d..96c6604 100644 --- a/dotnet/Codexcw.Tests/AccountUsageTests.cs +++ b/dotnet/Codexcw.Tests/AccountUsageTests.cs @@ -78,7 +78,7 @@ public async Task ReadsRateLimitsUsageAndAccount() Assert.Contains("stub@example.com", usage.RawAccount, StringComparison.Ordinal); Assert.Equal( - new[] { "-s", "read-only", "-a", "untrusted", "app-server", "--stdio" }, + new[] { "-s", "read-only", "-a", "never", "app-server", "--stdio" }, _dir.ReadArgs()); Assert.Equal(codexHome, File.ReadAllText(envFile).Trim()); } diff --git a/dotnet/Codexcw.Tests/ArgsTests.cs b/dotnet/Codexcw.Tests/ArgsTests.cs index c8be117..e54bda9 100644 --- a/dotnet/Codexcw.Tests/ArgsTests.cs +++ b/dotnet/Codexcw.Tests/ArgsTests.cs @@ -39,6 +39,7 @@ public async Task AdvancedArgsAndPromptComposition() AddDirs = ["/other"], Images = ["image.png"], Model = "gpt-test", + Effort = "xhigh", Profile = "work", Sandbox = SandboxMode.WorkspaceWrite, Approval = ApprovalPolicy.OnRequest, @@ -70,7 +71,7 @@ public async Task AdvancedArgsAndPromptComposition() foreach (var want in new[] { "exec", "--json", "--color", "never", "--strict-config", "-m", "gpt-test", - "-p", "work", "--enable", "feature-a", "--disable", "feature-b", "-i", + "model_reasoning_effort=\"xhigh\"", "-p", "work", "--enable", "feature-a", "--disable", "feature-b", "-i", "image.png", "--skip-git-repo-check", "--ephemeral", "--ignore-user-config", "--ignore-rules", "--cyber-access-program", "daybreak_blue", "--sandbox", "workspace-write", "-c", "approval_policy=\"on-request\"", @@ -87,6 +88,31 @@ public async Task AdvancedArgsAndPromptComposition() } } + [Theory] + [InlineData("a\n\u0001\u007f", "model_reasoning_effort=\"a\\u000a\\u0001\\u007f\"")] + [InlineData("ultra", "model_reasoning_effort=\"ultra\"")] + [InlineData("a\"b\\c", "model_reasoning_effort=\"a\\\"b\\\\c\"")] + public void EffortPassesAnyLevelAsQuotedConfig(string effort, string want) + { + var args = Prepare(new Request { Prompt = "x", Effort = effort }).Args.ToList(); + var index = args.IndexOf(want); + Assert.NotEqual(-1, index); + Assert.Equal("-c", args[index - 1]); + + Assert.DoesNotContain( + Prepare(new Request { Prompt = "x" }).Args, + arg => arg.Contains("model_reasoning_effort", StringComparison.Ordinal)); + } + + [Fact] + public void DeprecatedUntrustedApprovalIsStillPassedThrough() + { +#pragma warning disable CS0618 + var args = Prepare(new Request { Prompt = "x", Approval = ApprovalPolicy.Untrusted }).Args; +#pragma warning restore CS0618 + Assert.Contains("approval_policy=\"untrusted\"", args); + } + [Fact] public void ResumeArgsUseConfigOverrides() { @@ -97,20 +123,22 @@ public void ResumeArgsUseConfigOverrides() ResumeAll = true, Persistent = true, Sandbox = SandboxMode.DangerFullAccess, - Approval = ApprovalPolicy.Untrusted, + Approval = ApprovalPolicy.OnRequest, CyberAccessProgram = CyberAccessProgram.Standard, + Effort = "low", }); var args = prepared.Args; Assert.Equal("exec", args[0]); Assert.Equal("resume", args[1]); + Assert.Contains("model_reasoning_effort=\"low\"", args); var programIndex = args.ToList().IndexOf("--cyber-access-program"); Assert.NotEqual(-1, programIndex); Assert.Equal("standard", args[programIndex + 1]); Assert.Contains("--all", args); Assert.Contains("thread-id", args); Assert.Contains("sandbox_mode=\"danger-full-access\"", args); - Assert.Contains("approval_policy=\"untrusted\"", args); + Assert.Contains("approval_policy=\"on-request\"", args); Assert.DoesNotContain("--ephemeral", args); Assert.DoesNotContain("--color", args); Assert.Equal("-", args[^1]); @@ -181,6 +209,7 @@ public void AdvancedArgs() Dir = "/work", AddDirs = ["/other"], Model = ClaudeModels.Opus, + Effort = "max", PermissionMode = PermissionMode.AcceptEdits, AllowedTools = ["Bash(git *)", "Edit"], DisallowedTools = ["WebSearch"], @@ -192,7 +221,7 @@ public void AdvancedArgs() foreach (var want in new[] { "-p", "--output-format", "stream-json", "--verbose", - "--model", "opus", "--permission-mode", "acceptEdits", + "--model", "opus", "--effort", "max", "--permission-mode", "acceptEdits", "--allowed-tools", "Bash(git *)", "Edit", "--disallowed-tools", "WebSearch", "--dangerously-skip-permissions", "--add-dir", "/other", "--json-schema", """{"type":"object"}""", @@ -269,6 +298,15 @@ public void ValidationRequiresPrompt() { Assert.Throws(() => ClaudeArgs.Prepare(new Request())); } + + [Fact] + public void ModelAliasesMatchTheCli() + { + Assert.Equal("haiku", ClaudeModels.Haiku); + Assert.Equal("sonnet", ClaudeModels.Sonnet); + Assert.Equal("opus", ClaudeModels.Opus); + Assert.Equal("fable", ClaudeModels.Fable); + } } /// Tests that redirect the process temp directory run outside the parallel phase. diff --git a/dotnet/Codexcw.Tests/GrokTests.cs b/dotnet/Codexcw.Tests/GrokTests.cs index 004b398..39f0fcf 100644 --- a/dotnet/Codexcw.Tests/GrokTests.cs +++ b/dotnet/Codexcw.Tests/GrokTests.cs @@ -112,6 +112,7 @@ public async Task AdvancedArgsAndBufferedPrompt() Stdin = stdin, Dir = "/work", Model = "grok-code-fast-1", + Effort = "high", Profile = "reviewer", Sandbox = SandboxMode.WorkspaceWrite, PermissionMode = PermissionMode.AcceptEdits, @@ -132,6 +133,7 @@ public async Task AdvancedArgsAndBufferedPrompt() { "--cwd", "/work", "--model", "grok-code-fast-1", + "--reasoning-effort", "high", "--agent", "reviewer", "--sandbox", "workspace", "--permission-mode", "acceptEdits", diff --git a/dotnet/Codexcw/AccountUsage.cs b/dotnet/Codexcw/AccountUsage.cs index 1c36e36..9768a19 100644 --- a/dotnet/Codexcw/AccountUsage.cs +++ b/dotnet/Codexcw/AccountUsage.cs @@ -198,7 +198,7 @@ public static async Task GetAccountUsageAsync( RedirectStandardError = true, UseShellExecute = false, }; - foreach (var arg in new[] { "-s", "read-only", "-a", "untrusted", "app-server", "--stdio" }) + foreach (var arg in new[] { "-s", "read-only", "-a", "never", "app-server", "--stdio" }) { startInfo.ArgumentList.Add(arg); } diff --git a/dotnet/Codexcw/ClaudeArgs.cs b/dotnet/Codexcw/ClaudeArgs.cs index d154962..a58cf70 100644 --- a/dotnet/Codexcw/ClaudeArgs.cs +++ b/dotnet/Codexcw/ClaudeArgs.cs @@ -25,6 +25,11 @@ public static PreparedRun Prepare(Request request) args.Add("--model"); args.Add(request.Model); } + if (!string.IsNullOrEmpty(request.Effort)) + { + args.Add("--effort"); + args.Add(request.Effort); + } if (request.PermissionMode is { } mode) { args.Add("--permission-mode"); diff --git a/dotnet/Codexcw/CodexArgs.cs b/dotnet/Codexcw/CodexArgs.cs index 229af6b..50ec12a 100644 --- a/dotnet/Codexcw/CodexArgs.cs +++ b/dotnet/Codexcw/CodexArgs.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Text; namespace C3OSS.Codexcw; @@ -122,6 +123,11 @@ private static void AppendCommonArgs( args.Add("-m"); args.Add(request.Model); } + if (!string.IsNullOrEmpty(request.Effort)) + { + args.Add("-c"); + args.Add($"model_reasoning_effort={TomlString(request.Effort)}"); + } if (!string.IsNullOrEmpty(request.Profile) && !resume) { args.Add("-p"); @@ -248,6 +254,27 @@ public static async Task WritePromptAsync(Request request, Stream stdin, Cancell await stdin.FlushAsync(cancellationToken).ConfigureAwait(false); } + private static string TomlString(string value) + { + var result = new StringBuilder().Append('"'); + foreach (var ch in value) + { + if (ch < ' ' || ch == '\u007f') + { + result.Append(CultureInfo.InvariantCulture, $"\\u{(int)ch:x4}"); + } + else + { + if (ch is '"' or '\\') + { + result.Append('\\'); + } + result.Append(ch); + } + } + return result.Append('"').ToString(); + } + private static async Task CopyStdinAsync(Stream source, Stream stdin, CancellationToken cancellationToken) { var buffer = new byte[64 * 1024]; diff --git a/dotnet/Codexcw/GrokArgs.cs b/dotnet/Codexcw/GrokArgs.cs index 67663f3..9ee76f9 100644 --- a/dotnet/Codexcw/GrokArgs.cs +++ b/dotnet/Codexcw/GrokArgs.cs @@ -57,6 +57,11 @@ public static PreparedRun Prepare( args.Add("--model"); args.Add(request.Model); } + if (!string.IsNullOrEmpty(request.Effort)) + { + args.Add("--reasoning-effort"); + args.Add(request.Effort); + } if (!string.IsNullOrEmpty(request.Profile)) { args.Add("--agent"); @@ -172,7 +177,9 @@ private static void Validate(Request request) private static string GrokApproval(ApprovalPolicy policy) => policy switch { ApprovalPolicy.Never => "dontAsk", +#pragma warning disable CS0618 ApprovalPolicy.Untrusted or ApprovalPolicy.OnRequest => "default", +#pragma warning restore CS0618 _ => throw new InvalidRequestException($"unknown approval policy {(int)policy}"), }; diff --git a/dotnet/Codexcw/Request.cs b/dotnet/Codexcw/Request.cs index 4bcbd36..a562728 100644 --- a/dotnet/Codexcw/Request.cs +++ b/dotnet/Codexcw/Request.cs @@ -30,6 +30,12 @@ public enum SandboxMode public enum ApprovalPolicy { /// Asks before commands outside Codex's trusted set. + /// + /// Codex 0.167 and newer refuse approval_policy="untrusted". It is still + /// passed through for older Codex releases, and Grok runs still map it to + /// Grok's default permission mode. + /// + [Obsolete("Codex 0.167 and newer refuse approval_policy=\"untrusted\"; use OnRequest or Never for Codex runs.")] Untrusted, /// Lets Codex work in the sandbox and request approval. @@ -85,6 +91,9 @@ public static class ClaudeModels /// Selects the latest Claude Opus model. public const string Opus = "opus"; + + /// Selects the latest Claude Fable model. + public const string Fable = "fable"; } /// One -c key=value config override. @@ -121,6 +130,14 @@ public sealed record Request /// Overrides the selected agent's model for this run. public string? Model { get; init; } + /// + /// Sets the reasoning effort for this run. Codex receives it as the + /// model_reasoning_effort config value and Claude as --effort; + /// the grok agent receives --reasoning-effort. The value is passed through unchecked because + /// the accepted levels depend on the agent version and the selected model. + /// + public string? Effort { get; init; } + /// Selects a Codex config profile or Grok agent. public string? Profile { get; init; } @@ -214,7 +231,9 @@ internal static class Wire public static string ToWire(this ApprovalPolicy policy) => policy switch { +#pragma warning disable CS0618 ApprovalPolicy.Untrusted => "untrusted", +#pragma warning restore CS0618 ApprovalPolicy.OnRequest => "on-request", ApprovalPolicy.Never => "never", _ => throw new InvalidRequestException($"unknown approval policy {(int)policy}"), diff --git a/dotnet/Directory.Build.props b/dotnet/Directory.Build.props index d6958dc..81cefb4 100644 --- a/dotnet/Directory.Build.props +++ b/dotnet/Directory.Build.props @@ -1,6 +1,6 @@ - 0.6.0 + 0.7.0 net8.0;net10.0 latest enable diff --git a/grok.go b/grok.go index 6e1c36f..b7d3a3a 100644 --- a/grok.go +++ b/grok.go @@ -53,6 +53,9 @@ func (r *Runner) prepareGrok(req Request) (_ []string, _ io.Reader, cleanup func if req.Model != "" { args = append(args, "--model", req.Model) } + if req.Effort != "" { + args = append(args, "--reasoning-effort", req.Effort) + } if req.Profile != "" { args = append(args, "--agent", req.Profile) } diff --git a/grok_test.go b/grok_test.go index 8a10cab..58c3b63 100644 --- a/grok_test.go +++ b/grok_test.go @@ -131,6 +131,7 @@ func TestGrokPrepareBuildsAdvancedArgsAndBuffersStdin(t *testing.T) { Stdin: strings.NewReader("extra"), Dir: "/work", Model: "grok-code-fast-1", + Effort: "high", Profile: "reviewer", Sandbox: SandboxWorkspaceWrite, PermissionMode: PermissionAcceptEdits, @@ -146,6 +147,7 @@ func TestGrokPrepareBuildsAdvancedArgsAndBuffersStdin(t *testing.T) { for _, expected := range []string{ "--cwd", "/work", "--model", "grok-code-fast-1", + "--reasoning-effort", "high", "--agent", "reviewer", "--sandbox", "workspace", "--permission-mode", "acceptEdits", diff --git a/internal/cli/run.go b/internal/cli/run.go index d7378a4..240a46e 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -46,7 +46,7 @@ func newRunCmd() *cobra.Command { cmd.Flags().StringVarP(&flags.dir, "cd", "C", "", "working directory passed to codex") cmd.Flags().StringVarP(&flags.model, "model", "m", "", "model passed to codex") cmd.Flags().StringVar(&flags.sandbox, "sandbox", flags.sandbox, "sandbox mode (read-only, workspace-write, danger-full-access)") - cmd.Flags().StringVar(&flags.approval, "approval", flags.approval, "approval policy (untrusted, on-request, never)") + cmd.Flags().StringVar(&flags.approval, "approval", flags.approval, "approval policy (on-request, never; untrusted is deprecated and rejected by Codex 0.167+)") cmd.Flags().StringArrayVarP(&flags.config, "config", "c", nil, "codex config override as key=value") cmd.Flags().StringVarP(&flags.outputLastMessagePath, "output-last-message", "o", "", "file where codex writes the last agent message") cmd.Flags().BoolVar(&flags.persistent, "persistent", false, "persist Codex session rollout files") diff --git a/request.go b/request.go index 9b4bdea..28f4c65 100644 --- a/request.go +++ b/request.go @@ -21,6 +21,11 @@ type ApprovalPolicy string const ( // ApprovalUntrusted asks before commands outside Codex's trusted set. + // + // Deprecated: Codex 0.167 and newer refuse approval_policy="untrusted" + // and exit before the run starts; use ApprovalOnRequest or ApprovalNever + // for Codex runs. It is still passed through for older Codex releases, and + // Grok runs still map it to Grok's default permission mode. ApprovalUntrusted ApprovalPolicy = "untrusted" // ApprovalOnRequest lets Codex work in the sandbox and request approval. @@ -82,6 +87,12 @@ type Request struct { // Model overrides the selected agent's model for this run. Model string + // Effort sets the reasoning effort for this run. Codex receives it as the + // model_reasoning_effort config value and Claude as --effort; the grok + // agent receives --reasoning-effort. The value is passed through unchecked because the + // accepted levels depend on the agent version and the selected model. + Effort string + // Profile selects a Codex config profile or Grok agent. Profile string diff --git a/runner.go b/runner.go index c5575ce..98d7722 100644 --- a/runner.go +++ b/runner.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "encoding/json" "errors" "fmt" "io" @@ -616,6 +617,9 @@ func (r *Runner) appendCommonArgs(args []string, req Request, schemaPath string) if req.Model != "" { args = append(args, "-m", req.Model) } + if req.Effort != "" { + args = append(args, "-c", "model_reasoning_effort="+tomlString(req.Effort)) + } if req.Profile != "" && !resume { args = append(args, "-p", req.Profile) } @@ -684,6 +688,12 @@ func (r *Runner) appendCommonArgs(args []string, req Request, schemaPath string) return args } +func tomlString(value string) string { + // JSON string escapes are valid in TOML. TOML also requires escaping DEL. + encoded, _ := json.Marshal(value) + return strings.ReplaceAll(string(encoded), "\x7f", `\u007f`) +} + func promptReader(req Request) io.Reader { switch { case req.Prompt != "" && req.Stdin != nil: diff --git a/runner_test.go b/runner_test.go index b2b8463..260bf38 100644 --- a/runner_test.go +++ b/runner_test.go @@ -365,6 +365,7 @@ func TestPrepareBuildsAdvancedArgs(t *testing.T) { AddDirs: []string{"/other"}, Images: []string{"image.png"}, Model: "gpt-test", + Effort: "xhigh", Profile: "work", Sandbox: SandboxWorkspaceWrite, Approval: ApprovalOnRequest, @@ -398,7 +399,7 @@ func TestPrepareBuildsAdvancedArgs(t *testing.T) { for _, want := range []string{ "exec", "--json", "--color", "never", "--strict-config", "-m", "gpt-test", - "-p", "work", "--enable", "feature-a", "--disable", "feature-b", "-i", + `model_reasoning_effort="xhigh"`, "-p", "work", "--enable", "feature-a", "--disable", "feature-b", "-i", "image.png", "--skip-git-repo-check", "--ephemeral", "--ignore-user-config", "--ignore-rules", "--cyber-access-program", "daybreak_blue", "--sandbox", "workspace-write", "-c", `approval_policy="on-request"`, @@ -409,6 +410,37 @@ func TestPrepareBuildsAdvancedArgs(t *testing.T) { } } +func TestPrepareEffortPassesAnyLevelAsQuotedConfig(t *testing.T) { + for _, tt := range []struct { + effort string + want string + }{ + {effort: "a\n\x01\x7f", want: `model_reasoning_effort="a\n\u0001\u007f"`}, + {effort: "ultra", want: `model_reasoning_effort="ultra"`}, + {effort: `a"b\c`, want: `model_reasoning_effort="a\"b\\c"`}, + } { + t.Run(tt.effort, func(t *testing.T) { + args, _, _, err := New().prepare(Request{Prompt: "x", Effort: tt.effort}) + require.NoError(t, err) + effortIndex := indexOf(args, tt.want) + require.NotEqual(t, -1, effortIndex) + assert.Equal(t, "-c", args[effortIndex-1]) + }) + } + + args, _, _, err := New().prepare(Request{Prompt: "x"}) + require.NoError(t, err) + for _, arg := range args { + assert.NotContains(t, arg, "model_reasoning_effort") + } +} + +func TestPrepareStillPassesDeprecatedUntrustedApproval(t *testing.T) { + args, _, _, err := New().prepare(Request{Prompt: "x", Approval: ApprovalUntrusted}) + require.NoError(t, err) + assert.Contains(t, args, `approval_policy="untrusted"`) +} + func TestPrepareResumeArgs(t *testing.T) { args, stdin, cleanup, err := New().prepare(Request{ Prompt: "continue", @@ -416,12 +448,14 @@ func TestPrepareResumeArgs(t *testing.T) { ResumeAll: true, Persistent: true, Sandbox: SandboxDangerFullAccess, - Approval: ApprovalUntrusted, + Approval: ApprovalOnRequest, CyberAccessProgram: CyberAccessStandard, + Effort: "low", }) require.NoError(t, err) require.Nil(t, cleanup) require.NotNil(t, stdin) + assert.Contains(t, args, `model_reasoning_effort="low"`) assert.Equal(t, "exec", args[0]) assert.Equal(t, "resume", args[1]) @@ -431,7 +465,7 @@ func TestPrepareResumeArgs(t *testing.T) { assert.Contains(t, args, "--all") assert.Contains(t, args, "thread-id") assert.Contains(t, args, `sandbox_mode="danger-full-access"`) - assert.Contains(t, args, `approval_policy="untrusted"`) + assert.Contains(t, args, `approval_policy="on-request"`) assert.NotContains(t, args, "--ephemeral") assert.Equal(t, "-", args[len(args)-1]) }