Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-1521]): auto-correct bare Claude model ids to Bedrock form at CLI-argv build time
Adam Eivyc5a18e7a96db
diff --git a/server/lib/cliProviderArgs.js b/server/lib/cliProviderArgs.jsindex 10f9b6987c..adfaad9486 100644--- a/server/lib/cliProviderArgs.js+++ b/server/lib/cliProviderArgs.js@@ -16,7 +16,7 @@* - Claude Code: `-p -` (+ `--model <id>`)*/-import { resolveCliModel, hasModelFlag } from './providerModels.js';+import { resolveCliModel, hasModelFlag, resolveBedrockCliModel } from './providerModels.js';import { ensureAntigravityPrintArgs, isAntigravityCliProvider } from './antigravity.js';/**@@ -80,7 +80,15 @@ export function buildCliArgs(provider) {// cli — respect user-baked model flags.const args = [...baseArgs, '-p', '-'];if (effectiveDefaultModel && !hasModelFlag(baseArgs)) {- args.push('--model', effectiveDefaultModel);+ // On a Bedrock box a bare `claude-opus-4-8` is rejected — map it to the+ // region-prefixed Bedrock id just-in-time (no-op off Bedrock / for+ // already-prefixed ids). provider.envVars carries CLAUDE_CODE_USE_BEDROCK+ // for the bedrock provider variants; process.env covers a Bedrock host.+ const model = resolveBedrockCliModel(effectiveDefaultModel, {+ env: { ...process.env, ...provider?.envVars },+ providerId,+ });+ args.push('--model', model);}return args;}diff --git a/server/lib/cliProviderArgs.test.js b/server/lib/cliProviderArgs.test.jsnew file mode 100644index 0000000000..26fd08459c--- /dev/null+++ b/server/lib/cliProviderArgs.test.js@@ -0,0 +1,76 @@+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { buildCliArgs, stripBrokenModelFlags } from './cliProviderArgs.js';++describe('cliProviderArgs', () => {+ // buildCliArgs reads process.env for the Bedrock signal; isolate the tests+ // from whatever the host/CI environment happens to set.+ let savedBedrock;+ beforeEach(() => {+ savedBedrock = process.env.CLAUDE_CODE_USE_BEDROCK;+ delete process.env.CLAUDE_CODE_USE_BEDROCK;+ });+ afterEach(() => {+ if (savedBedrock === undefined) delete process.env.CLAUDE_CODE_USE_BEDROCK;+ else process.env.CLAUDE_CODE_USE_BEDROCK = savedBedrock;+ });++ describe('buildCliArgs — Claude Code (default)', () => {+ it('passes a bare Claude model through unchanged when Bedrock mode is off', () => {+ const args = buildCliArgs({ id: 'claude-code', command: 'claude', defaultModel: 'claude-opus-4-8' });+ expect(args).toEqual(['-p', '-', '--model', 'claude-opus-4-8']);+ });++ it('maps a bare Claude model to its Bedrock form when CLAUDE_CODE_USE_BEDROCK is set (via provider.envVars)', () => {+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});+ const args = buildCliArgs({+ id: 'claude-code',+ command: 'claude',+ defaultModel: 'claude-opus-4-8',+ envVars: { CLAUDE_CODE_USE_BEDROCK: '1' },+ });+ expect(args).toEqual(['-p', '-', '--model', 'global.anthropic.claude-opus-4-8']);+ spy.mockRestore();+ });++ it('leaves an already-region-prefixed Bedrock model untouched', () => {+ const args = buildCliArgs({+ id: 'claude-code-bedrock',+ command: 'claude',+ defaultModel: 'us.anthropic.claude-opus-4-7-v1:0',+ envVars: { CLAUDE_CODE_USE_BEDROCK: '1' },+ });+ expect(args).toEqual(['-p', '-', '--model', 'us.anthropic.claude-opus-4-7-v1:0']);+ });++ it('respects a user-baked --model pin and skips injection (no Bedrock map)', () => {+ const args = buildCliArgs({+ id: 'claude-code',+ command: 'claude',+ defaultModel: 'claude-opus-4-8',+ args: ['--model', 'claude-sonnet-4-6'],+ envVars: { CLAUDE_CODE_USE_BEDROCK: '1' },+ });+ expect(args).toEqual(['--model', 'claude-sonnet-4-6', '-p', '-']);+ });+ });++ describe('buildCliArgs — other vendors are never Bedrock-mapped', () => {+ it('codex model passes through even with Bedrock on', () => {+ const args = buildCliArgs({+ id: 'codex',+ command: 'codex',+ defaultModel: 'gpt-5',+ envVars: { CLAUDE_CODE_USE_BEDROCK: '1' },+ });+ expect(args).toEqual(['exec', '--model', 'gpt-5', '-']);+ });+ });++ describe('stripBrokenModelFlags', () => {+ it('drops dangling / empty model flags but keeps pinned ones', () => {+ expect(stripBrokenModelFlags(['--model'])).toEqual([]);+ expect(stripBrokenModelFlags(['--model='])).toEqual([]);+ expect(stripBrokenModelFlags(['--model', 'x'])).toEqual(['--model', 'x']);+ });+ });+});diff --git a/server/lib/providerModels.js b/server/lib/providerModels.jsindex baa8b731d5..ce5bd9cd03 100644--- a/server/lib/providerModels.js+++ b/server/lib/providerModels.js@@ -17,6 +17,113 @@ export const isCodexConfiguredDefault = (model) => model === CODEX_CONFIGURED_DE*/export const resolveCliModel = (model) => isCodexConfiguredDefault(model) ? null : (model || null);+/**+ * Claude Code on AWS Bedrock wants region-prefixed model ids+ * (`global.anthropic.claude-opus-4-8`, `us.anthropic.claude-opus-4-1-...-v1:0`).+ * When `CLAUDE_CODE_USE_BEDROCK` is set on the box, passing a bare+ * `claude --model claude-opus-4-8` is rejected ("provided model identifier is+ * invalid") — which is exactly how a bare-id `claude-code` provider config+ * breaks autopilot/pipeline runs on a Bedrock host. The helpers below map a+ * bare id to its Bedrock form just-in-time at CLI-argv build time; the stored+ * provider config stays bare (so a box can move in/out of Bedrock mode freely).+ */++// Family → the env var Claude Code reads for that tier's resolved model. A+// Bedrock wrapper sets these to the exact region-prefixed id it wants, so when+// present they are preferred over a blind prefix-rewrite.+const BEDROCK_FAMILY_ENV = {+ opus: 'ANTHROPIC_DEFAULT_OPUS_MODEL',+ sonnet: 'ANTHROPIC_DEFAULT_SONNET_MODEL',+ haiku: 'ANTHROPIC_DEFAULT_HAIKU_MODEL',+ fable: 'ANTHROPIC_DEFAULT_FABLE_MODEL',+};++/**+ * True when the box is in Claude-Code-on-Bedrock mode. Treats the documented+ * `CLAUDE_CODE_USE_BEDROCK=1` plus the usual truthy spellings as enabled;+ * `0`/`false`/`no`/empty/unset are off.+ */+export const isBedrockEnabled = (env = process.env) => {+ const v = env?.CLAUDE_CODE_USE_BEDROCK;+ if (v == null) return false;+ const s = String(v).trim().toLowerCase();+ return s !== '' && s !== '0' && s !== 'false' && s !== 'no';+};++/**+ * True when an id already carries a Bedrock region prefix+ * (`global.anthropic.…`, `us.anthropic.…`, `eu.anthropic.…`, `apac.anthropic.…`)+ * or the bare `anthropic.…` form. Such ids are left untouched.+ */+export const hasBedrockRegionPrefix = (id) =>+ typeof id === 'string' && (/^[a-z]+\.anthropic\./i.test(id) || /^anthropic\./i.test(id));++const detectClaudeFamily = (id) => {+ if (typeof id !== 'string') return null;+ const lower = id.toLowerCase();+ return Object.keys(BEDROCK_FAMILY_ENV).find((fam) => lower.includes(fam)) || null;+};++/**+ * Map a bare Claude model id to its Bedrock form when (and only when) Bedrock+ * mode is on. Pure — no logging, no env mutation.+ *+ * - No-op when Bedrock mode is off, the id is empty/non-string, or it already+ * carries a region/`anthropic.` prefix.+ * - No-op for non-Claude ids (codex `gpt-5`, gemini, etc.) — only ids with a+ * recognized Claude family or a `claude…` prefix are rewritten, so applying+ * this at a shared argv chokepoint can't corrupt another vendor's model.+ * - Prefers the matching `ANTHROPIC_DEFAULT_<FAMILY>_MODEL` env value when it+ * is itself a region-prefixed Bedrock id (the wrapper's exact choice); else+ * falls back to a `global.anthropic.<id>` prefix-rewrite.+ *+ * @param {string|null|undefined} id+ * @param {NodeJS.ProcessEnv} [env]+ * @returns {string|null|undefined} the mapped id (or the input unchanged)+ */+export function toBedrockModelId(id, env = process.env) {+ if (!isBedrockEnabled(env)) return id;+ if (typeof id !== 'string' || !id) return id;+ if (hasBedrockRegionPrefix(id)) return id;+ const family = detectClaudeFamily(id);+ if (!family && !/^claude[-.]/i.test(id)) return id; // not a Claude id — leave alone+ if (family) {+ const override = env?.[BEDROCK_FAMILY_ENV[family]];+ if (hasBedrockRegionPrefix(override)) return override;+ }+ return `global.anthropic.${id}`;+}++// Dedup so the auto-correction notice prints once per (provider, model) per+// process rather than on every run.+const _warnedBareBedrockModels = new Set();++/**+ * One-time (per process, per provider+model) notice that a stored Claude-Code+ * model id reads non-Bedrock while the box is in Bedrock mode and is being+ * auto-corrected for this run. Surfaces via the emoji-prefixed console.error+ * path so the config stays self-explanatory.+ */+export function warnBareBedrockModel(providerId, originalId, mappedId) {+ const key = `${providerId || 'claude-code'}::${originalId}`;+ if (_warnedBareBedrockModels.has(key)) return;+ _warnedBareBedrockModels.add(key);+ console.error(+ `⚠️ Provider '${providerId || 'claude-code'}' model '${originalId}' is bare but CLAUDE_CODE_USE_BEDROCK is set — auto-correcting to Bedrock id '${mappedId}' for this run (stored config unchanged; set a global.anthropic.* / us.anthropic.* model to silence).`,+ );+}++/**+ * Side-effecting convenience used at CLI-argv build time: map a bare Claude id+ * to its Bedrock form and emit the one-time auto-correction notice when the map+ * actually changed the id. Returns the id to pass to `--model`.+ */+export function resolveBedrockCliModel(id, { env = process.env, providerId } = {}) {+ const mapped = toBedrockModelId(id, env);+ if (mapped !== id) warnBareBedrockModel(providerId, id, mapped);+ return mapped;+}+/*** Strip the sentinel from a model list — the user-selectable view.* @param {string[]} modelsdiff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.jsindex 086c89e214..f51226f5db 100644--- a/server/lib/providerModels.test.js+++ b/server/lib/providerModels.test.js@@ -1,4 +1,4 @@-import { describe, it, expect } from 'vitest';+import { describe, it, expect, vi } from 'vitest';import {ANTIGRAVITY_CONFIGURED_DEFAULT,CODEX_CONFIGURED_DEFAULT,@@ -6,7 +6,11 @@ import {resolveCliModel,filterSelectableModels,hasModelFlag,- extractBakedModel+ extractBakedModel,+ isBedrockEnabled,+ hasBedrockRegionPrefix,+ toBedrockModelId,+ resolveBedrockCliModel} from './providerModels.js';describe('providerModels', () => {@@ -164,4 +168,125 @@ describe('providerModels', () => {}}});++ describe('isBedrockEnabled', () => {+ it('is true for the documented and common truthy spellings', () => {+ for (const v of ['1', 'true', 'TRUE', 'yes', 'on', 'anything']) {+ expect(isBedrockEnabled({ CLAUDE_CODE_USE_BEDROCK: v }), v).toBe(true);+ }+ });+ it('is false for off / unset spellings', () => {+ for (const v of ['0', 'false', 'FALSE', 'no', '', ' ']) {+ expect(isBedrockEnabled({ CLAUDE_CODE_USE_BEDROCK: v }), v).toBe(false);+ }+ expect(isBedrockEnabled({})).toBe(false);+ expect(isBedrockEnabled()).toBe(typeof process.env.CLAUDE_CODE_USE_BEDROCK !== 'undefined'+ ? isBedrockEnabled(process.env) : false);+ });+ });++ describe('hasBedrockRegionPrefix', () => {+ it('recognizes region-prefixed and bare anthropic. forms', () => {+ expect(hasBedrockRegionPrefix('global.anthropic.claude-opus-4-8')).toBe(true);+ expect(hasBedrockRegionPrefix('us.anthropic.claude-opus-4-1-20250805-v1:0')).toBe(true);+ expect(hasBedrockRegionPrefix('eu.anthropic.claude-sonnet-4-6')).toBe(true);+ expect(hasBedrockRegionPrefix('apac.anthropic.claude-haiku-4-5')).toBe(true);+ expect(hasBedrockRegionPrefix('anthropic.claude-opus-4-8-v1:0')).toBe(true);+ });+ it('rejects bare ids and non-strings', () => {+ expect(hasBedrockRegionPrefix('claude-opus-4-8')).toBe(false);+ expect(hasBedrockRegionPrefix('gpt-5')).toBe(false);+ expect(hasBedrockRegionPrefix('')).toBe(false);+ expect(hasBedrockRegionPrefix(null)).toBe(false);+ expect(hasBedrockRegionPrefix(undefined)).toBe(false);+ });+ });++ describe('toBedrockModelId', () => {+ const ON = { CLAUDE_CODE_USE_BEDROCK: '1' };++ it('is a no-op when Bedrock mode is off (every bare id passes through)', () => {+ for (const id of ['claude-opus-4-8', 'claude-sonnet-4-6', 'claude-fable-5', 'gpt-5']) {+ expect(toBedrockModelId(id, {}), id).toBe(id);+ expect(toBedrockModelId(id, { CLAUDE_CODE_USE_BEDROCK: '0' }), id).toBe(id);+ }+ });++ it('prefix-rewrites each bare Claude family when Bedrock is on (no env override)', () => {+ const table = [+ ['claude-opus-4-8', 'global.anthropic.claude-opus-4-8'],+ ['claude-sonnet-4-6', 'global.anthropic.claude-sonnet-4-6'],+ ['claude-fable-5', 'global.anthropic.claude-fable-5'],+ ['claude-haiku-4-5-20251001', 'global.anthropic.claude-haiku-4-5-20251001'],+ ];+ for (const [bare, expected] of table) {+ expect(toBedrockModelId(bare, ON), bare).toBe(expected);+ }+ });++ it('prefers the matching ANTHROPIC_DEFAULT_<FAMILY>_MODEL when it is region-prefixed', () => {+ const env = {+ CLAUDE_CODE_USE_BEDROCK: '1',+ ANTHROPIC_DEFAULT_OPUS_MODEL: 'us.anthropic.claude-opus-4-8-20260101-v1:0',+ ANTHROPIC_DEFAULT_SONNET_MODEL: 'global.anthropic.claude-sonnet-4-6-v1:0',+ ANTHROPIC_DEFAULT_HAIKU_MODEL: 'us.anthropic.claude-haiku-4-5-v1:0',+ ANTHROPIC_DEFAULT_FABLE_MODEL: 'global.anthropic.claude-fable-5-v1:0',+ };+ expect(toBedrockModelId('claude-opus-4-8', env)).toBe('us.anthropic.claude-opus-4-8-20260101-v1:0');+ expect(toBedrockModelId('claude-sonnet-4-6', env)).toBe('global.anthropic.claude-sonnet-4-6-v1:0');+ expect(toBedrockModelId('claude-haiku-4-5-20251001', env)).toBe('us.anthropic.claude-haiku-4-5-v1:0');+ expect(toBedrockModelId('claude-fable-5', env)).toBe('global.anthropic.claude-fable-5-v1:0');+ });++ it('ignores a non-region-prefixed env override and falls back to prefix-rewrite', () => {+ const env = { CLAUDE_CODE_USE_BEDROCK: '1', ANTHROPIC_DEFAULT_OPUS_MODEL: 'claude-opus-4-8' };+ expect(toBedrockModelId('claude-opus-4-8', env)).toBe('global.anthropic.claude-opus-4-8');+ });++ it('is a no-op for ids already carrying a region / anthropic. prefix', () => {+ for (const id of [+ 'global.anthropic.claude-opus-4-5-20251101-v1:0',+ 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',+ 'anthropic.claude-opus-4-8-v1:0',+ ]) {+ expect(toBedrockModelId(id, ON), id).toBe(id);+ }+ });++ it('leaves non-Claude vendor ids untouched even with Bedrock on', () => {+ for (const id of ['gpt-5', 'gemini-2.5-pro', 'o1-preview']) {+ expect(toBedrockModelId(id, ON), id).toBe(id);+ }+ });++ it('passes through empty / non-string ids', () => {+ expect(toBedrockModelId('', ON)).toBe('');+ expect(toBedrockModelId(null, ON)).toBeNull();+ expect(toBedrockModelId(undefined, ON)).toBeUndefined();+ });+ });++ describe('resolveBedrockCliModel', () => {+ it('returns the mapped id and warns once per provider+model', () => {+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});+ const opts = { env: { CLAUDE_CODE_USE_BEDROCK: '1' }, providerId: 'claude-code-resolve-test' };+ const first = resolveBedrockCliModel('claude-opus-4-8', opts);+ const second = resolveBedrockCliModel('claude-opus-4-8', opts);+ expect(first).toBe('global.anthropic.claude-opus-4-8');+ expect(second).toBe('global.anthropic.claude-opus-4-8');+ // Deduped: only the first rewrite of this provider+model logs.+ expect(spy).toHaveBeenCalledTimes(1);+ expect(spy.mock.calls[0][0]).toMatch(/CLAUDE_CODE_USE_BEDROCK/);+ spy.mockRestore();+ });++ it('does not warn when the id is unchanged (off Bedrock, or already prefixed)', () => {+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});+ expect(resolveBedrockCliModel('claude-opus-4-8', { env: {} })).toBe('claude-opus-4-8');+ expect(resolveBedrockCliModel('us.anthropic.claude-opus-4-7-v1:0', { env: { CLAUDE_CODE_USE_BEDROCK: '1' } }))+ .toBe('us.anthropic.claude-opus-4-7-v1:0');+ expect(spy).not.toHaveBeenCalled();+ spy.mockRestore();+ });+ });});diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex faee36f5b1..b0a90eb373 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -12,7 +12,7 @@* No cycle risk: this module imports nothing from either consumer.*/-import { resolveCliModel, hasModelFlag } from './providerModels.js';+import { resolveCliModel, hasModelFlag, resolveBedrockCliModel } from './providerModels.js';import { ensureAntigravityTuiArgs, isAntigravityCommand } from './antigravity.js';// ─── Paste handshake constants ────────────────────────────────────────────@@ -405,7 +405,16 @@ export function buildTuiInvocation(provider, model) {const baseArgs = applyCommandDefaults(command, [...(provider?.args || [])]);const effectiveModel = resolveCliModel(model);const shouldInject = !isAntigravityCommand(command) && effectiveModel && !hasModelFlag(baseArgs);- const args = shouldInject ? [...baseArgs, '--model', effectiveModel] : baseArgs;+ // Map a bare Claude id to its Bedrock form when the box is in Bedrock mode+ // (no-op otherwise / for non-Claude ids) — mirrors buildCliArgs for the+ // claude-code-tui runner.+ const injectedModel = shouldInject+ ? resolveBedrockCliModel(effectiveModel, {+ env: { ...process.env, ...provider?.envVars },+ providerId: provider?.id,+ })+ : effectiveModel;+ const args = shouldInject ? [...baseArgs, '--model', injectedModel] : baseArgs;return { command, args };}diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex 67ed491b58..f8c95b68f2 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -314,6 +314,17 @@ describe('tuiHandshake.applyCommandDefaults', () => {});describe('tuiHandshake.buildTuiInvocation', () => {+ // buildTuiInvocation reads process.env for the Bedrock signal; isolate from host/CI.+ let savedBedrock;+ beforeEach(() => {+ savedBedrock = process.env.CLAUDE_CODE_USE_BEDROCK;+ delete process.env.CLAUDE_CODE_USE_BEDROCK;+ });+ afterEach(() => {+ if (savedBedrock === undefined) delete process.env.CLAUDE_CODE_USE_BEDROCK;+ else process.env.CLAUDE_CODE_USE_BEDROCK = savedBedrock;+ });+it('uses provider.command when present and skips codex defaults for non-literal-codex command names', () => {const provider = { id: 'codex', command: 'my-codex-wrapper', args: ['exec', '-'] };const out = buildTuiInvocation(provider, null);@@ -380,6 +391,14 @@ describe('tuiHandshake.buildTuiInvocation', () => {expect(out.command).toBe('claude');expect(out.args).toEqual(['--model', 'opus-x']);});++ it('maps a bare Claude model to its Bedrock form when CLAUDE_CODE_USE_BEDROCK is set (claude-code-tui runner)', () => {+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});+ const provider = { id: 'claude-code-tui', args: ['-p', '-'], envVars: { CLAUDE_CODE_USE_BEDROCK: '1' } };+ const out = buildTuiInvocation(provider, 'claude-opus-4-8');+ expect(out.args).toEqual(['-p', '-', '--model', 'global.anthropic.claude-opus-4-8']);+ spy.mockRestore();+ });});describe('tuiHandshake.detectMissingTuiBinary', () => {diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.jsindex ae21c85a94..4906def29c 100644--- a/server/services/agentCliSpawning.js+++ b/server/services/agentCliSpawning.js@@ -26,6 +26,7 @@ import { createCodexStderrFormatter } from '../lib/codexCliOutput.js';import { PROVIDER_TYPES } from '../lib/aiToolkit/constants.js';import { createImmediateFallbackSignalDetector } from '../lib/aiToolkit/errorDetection.js';import { ensureAntigravityPrintArgs, isAntigravityCliProvider } from '../lib/antigravity.js';+import { resolveBedrockCliModel } from '../lib/providerModels.js';import { agentGuardEnv } from '../lib/agentGuard/index.js';const AGENTS_DIR = PATHS.cosAgents;@@ -281,7 +282,13 @@ export function buildCliSpawnConfig(provider, model) {...(provider?.args || []), // User-configured provider args];if (effectiveModel) {- args.push('--model', effectiveModel);+ // Bedrock box: map a bare Claude id to its region-prefixed Bedrock form+ // just-in-time (no-op off Bedrock / for already-prefixed or non-Claude ids).+ const injectedModel = resolveBedrockCliModel(effectiveModel, {+ env: { ...process.env, ...provider?.envVars },+ providerId,+ });+ args.push('--model', injectedModel);}return {diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 1a31a72754..80056a3ba1 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -17,7 +17,7 @@ import { analyzeAgentFailure } from './agentErrorAnalysis.js';import { finalizeAgent, releaseAgentLane } from './agentLifecycle.js';import { activeAgents, userTerminatedAgents, pausedAgents } from './agentState.js';import { PATHS } from '../lib/fileUtils.js';-import { resolveCliModel } from '../lib/providerModels.js';+import { resolveCliModel, resolveBedrockCliModel } from '../lib/providerModels.js';import { createStreamingAnsiStripper, stripAnsi } from '../lib/ansiStrip.js';import { createImmediateFallbackSignalDetector } from '../lib/aiToolkit/errorDetection.js';import { isAntigravityCommand } from '../lib/antigravity.js';@@ -177,16 +177,23 @@ function shellHasLiveChild(shellPid) {});}-function appendModelArgs(args, model, command) {+function appendModelArgs(args, model, command, provider) {if (isAntigravityCommand(command)) return args;const effectiveModel = resolveCliModel(model);- return effectiveModel ? [...args, '--model', effectiveModel] : args;+ if (!effectiveModel) return args;+ // Bedrock box: map a bare Claude id to its region-prefixed form just-in-time+ // (no-op off Bedrock / for non-Claude ids).+ const injectedModel = resolveBedrockCliModel(effectiveModel, {+ env: { ...process.env, ...provider?.envVars },+ providerId: provider?.id,+ });+ return [...args, '--model', injectedModel];}export function buildTuiSpawnConfig(provider, model) {const command = provider?.command || inferTuiCommand(provider?.id);const baseArgs = applyCommandDefaults(command, [...(provider?.args || [])]);- const args = appendModelArgs(baseArgs, model, command);+ const args = appendModelArgs(baseArgs, model, command, provider);return {command,diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex c1e6a609c5..d58ff16100 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -100,7 +100,10 @@ tryReadFile: vi.fn().mockResolvedValue(null),vi.mock('../lib/providerModels.js', () => ({// Mirror the real behaviour: pass through the model string, return null for// the codex-configured-default sentinel or null/undefined input.- resolveCliModel: vi.fn((m) => (m === 'codex-configured-default' || !m) ? null : m)+ resolveCliModel: vi.fn((m) => (m === 'codex-configured-default' || !m) ? null : m),+ // Bedrock map is a no-op off Bedrock — mirror that pass-through here (the+ // mapper itself is unit-tested in providerModels.test.js).+ resolveBedrockCliModel: vi.fn((m) => m)}));// Shrink buffer thresholds so the truncation tests can trip them with tiny