Compare commits

...
7 changed files with 157 additions and 0 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'@expo/build-tools': minor
---
Add optional `model` and `effort` inputs to `eas/run_agent` that select the model and the reasoning effort level the agent CLI uses.
@@ -32,6 +32,8 @@ const inputs = {
agent_run_id: { value: '0199b0a0-1111-7222-8333-444455556666' },
max_duration_seconds: { value: 1800 },
prompt: { value: 'Fix the failing test.' },
model: { value: undefined as string | undefined },
effort: { value: undefined as string | undefined },
};
const env = {
PATH: '/usr/local/bin:/usr/bin',
@@ -129,6 +131,39 @@ describe(createRunAgentBuildFunction, () => {
}
});
it.each([
['no model when the input is not set', undefined],
['a model alias', 'opus'],
['a full model name', 'claude-opus-4-5'],
['a model name with a context window suffix', 'sonnet[1m]'],
['a model name with a dot', 'gpt-5.1-codex'],
['a model name with other punctuation', 'provider/model@2026:v1'],
])('hands %s to the agent run', async (_name, model) => {
const runAgentSpy = jest.spyOn(agentRun, 'runAgentAsync').mockResolvedValue();
try {
await runAsync({ inputs: { ...inputs, model: { value: model } } });
expect(runAgentSpy.mock.calls[0][0].model).toBe(model);
} finally {
runAgentSpy.mockRestore();
}
});
it.each([
['no effort level when the input is not set', undefined],
['an effort level', 'high'],
['an effort level the step does not know', 'ultra'],
])('hands %s to the agent run', async (_name, effort) => {
const runAgentSpy = jest.spyOn(agentRun, 'runAgentAsync').mockResolvedValue();
try {
await runAsync({ inputs: { ...inputs, effort: { value: effort } } });
expect(runAgentSpy.mock.calls[0][0].effort).toBe(effort);
} finally {
runAgentSpy.mockRestore();
}
});
it.each([
['wss://staging-mcp.expo.test', 'https://staging-mcp.expo.test/mcp'],
['ws://localhost:8787', 'http://localhost:8787/mcp'],
@@ -172,6 +207,10 @@ describe(createRunAgentBuildFunction, () => {
['a negative duration', { inputs: { ...inputs, max_duration_seconds: { value: -300 } } }],
['a fractional duration', { inputs: { ...inputs, max_duration_seconds: { value: 12.5 } } }],
['an empty prompt', { inputs: { ...inputs, prompt: { value: '' } } }],
['an empty model', { inputs: { ...inputs, model: { value: '' } } }],
['a model that reads as a flag', { inputs: { ...inputs, model: { value: '--continue' } } }],
['an empty effort level', { inputs: { ...inputs, effort: { value: '' } } }],
['an effort level that reads as a flag', { inputs: { ...inputs, effort: { value: '-p' } } }],
['no EXPO_TOKEN', { env: { ...env, EXPO_TOKEN: '' } }],
['no PATH', { env: { ...env, PATH: '' } }],
['no Expo API URL', { ctx: { ...ctx, expoApiV2BaseUrl: undefined } }],
@@ -38,6 +38,16 @@ export function createRunAgentBuildFunction(ctx: CustomBuildContext): BuildFunct
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'model',
required: false,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'effort',
required: false,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
],
fn: async (stepCtx, { inputs, env, signal }) => {
const inputErrors = {
@@ -45,6 +55,8 @@ export function createRunAgentBuildFunction(ctx: CustomBuildContext): BuildFunct
agentRunId: `The "agent_run_id" input must be the UUID of an agent run, but received "${String(inputs.agent_run_id.value)}".`,
maxDurationSeconds: `The "max_duration_seconds" input must be a positive whole number of seconds, but received "${String(inputs.max_duration_seconds.value)}".`,
prompt: 'The "prompt" input must be a non-empty string.',
model: `The "model" input must be a non-empty model name that does not start with "-", but received "${String(inputs.model.value)}".`,
effort: `The "effort" input must be a non-empty effort level that does not start with "-", but received "${String(inputs.effort.value)}".`,
};
const parsedInputs = z
.object({
@@ -55,12 +67,24 @@ export function createRunAgentBuildFunction(ctx: CustomBuildContext): BuildFunct
.int({ error: inputErrors.maxDurationSeconds })
.positive({ error: inputErrors.maxDurationSeconds }),
prompt: z.string({ error: inputErrors.prompt }).min(1, { error: inputErrors.prompt }),
model: z
.string({ error: inputErrors.model })
.min(1, { error: inputErrors.model })
.refine(model => !model.startsWith('-'), { error: inputErrors.model })
.optional(),
effort: z
.string({ error: inputErrors.effort })
.min(1, { error: inputErrors.effort })
.refine(effort => !effort.startsWith('-'), { error: inputErrors.effort })
.optional(),
})
.safeParse({
agent_kind: inputs.agent_kind.value,
agent_run_id: inputs.agent_run_id.value,
max_duration_seconds: inputs.max_duration_seconds.value,
prompt: inputs.prompt.value,
model: inputs.model.value,
effort: inputs.effort.value,
});
if (!parsedInputs.success) {
throw createValidationError(parsedInputs.error);
@@ -70,6 +94,8 @@ export function createRunAgentBuildFunction(ctx: CustomBuildContext): BuildFunct
agent_run_id: agentRunId,
max_duration_seconds: maxDurationSeconds,
prompt,
model,
effort,
} = parsedInputs.data;
const parsedEnv = z
.object({
@@ -117,6 +143,8 @@ export function createRunAgentBuildFunction(ctx: CustomBuildContext): BuildFunct
agentKind,
agentRunId,
prompt,
model,
effort,
expoToken,
expoApiV2BaseUrl: ctx.expoApiV2BaseUrl,
mcpUrl: mcpUrl.toString(),
@@ -222,6 +222,31 @@ describe(runAgentAsync, () => {
expect(agent.stdin).toHaveBeenCalledWith('Fix the failing test.');
});
it.each([
['the requested model', { model: 'opus' }, ['--model', 'opus']],
['the requested effort level', { effort: 'high' }, ['--effort', 'high']],
[
'the requested model and effort level',
{ model: 'opus', effort: 'high' },
['--model', 'opus', '--effort', 'high'],
],
])('runs Claude Code with %s, also when it resumes', async (_name, options, flags) => {
leaseMock
.mockResolvedValueOnce(anthropicLease)
.mockResolvedValueOnce({ ...anthropicLease, accessToken: 'renewed-access-token' });
const invocations = mockSpawn({
onAgent: agent => agent.exit(invocations.length === 1 ? 1 : 0),
});
await runAgentAsync(createOptions(options));
expect(invocations).toHaveLength(2);
const [first, resumed] = invocations;
expect(first.args.slice(-flags.length)).toEqual(flags);
expect(resumed.args).toContain('--continue');
expect(resumed.args.slice(-flags.length)).toEqual(flags);
});
it('writes the agent output as log lines', async () => {
leaseMock.mockResolvedValue(anthropicLease);
const logger = createMockLogger();
@@ -395,6 +420,46 @@ describe(runAgentAsync, () => {
expect(agent.stdin).toHaveBeenCalledWith('Fix the failing test.');
});
it.each([
['the requested model', { model: 'gpt-5.1-codex' }, ['model = "gpt-5.1-codex"']],
[
'a model name that is escaped so that it cannot add settings',
{ model: 'gpt"\nshell_tool = true\n[features]' },
['model = "gpt\\"\\nshell_tool = true\\n[features]"'],
],
['the requested effort level', { effort: 'high' }, ['model_reasoning_effort = "high"']],
[
'an effort level that is escaped so that it cannot add settings',
{ effort: 'high"\nshell_tool = true' },
['model_reasoning_effort = "high\\"\\nshell_tool = true"'],
],
[
'the requested model and effort level',
{ model: 'gpt-5.1-codex', effort: 'xhigh' },
['model = "gpt-5.1-codex"', 'model_reasoning_effort = "xhigh"'],
],
['its default model and effort level when none are requested', {}, []],
])('runs Codex with %s, also when it resumes', async (_name, options, modelSettings) => {
leaseMock
.mockResolvedValueOnce(openaiLease)
.mockResolvedValueOnce({ ...openaiLease, accessToken: 'renewed-access-token' });
const invocations = mockSpawn({
onAgent: agent => {
const config = agent.readHomeFile('.codex/config.toml').content;
const rootSettings = config.slice(0, config.indexOf('\n['));
expect(rootSettings.split('\n').filter(line => line.startsWith('model'))).toEqual(
modelSettings
);
agent.exit(invocations.length === 1 ? 1 : 0);
},
});
await runAgentAsync(createOptions({ agentKind: 'codex', ...options }));
expect(invocations).toHaveLength(2);
expect(invocations[1].args).toContain('resume');
});
it('escalates to SIGKILL when the agent ignores the stop', async () => {
jest.useFakeTimers({ doNotFake: ['nextTick', 'setImmediate', 'queueMicrotask'] });
leaseMock.mockResolvedValue(anthropicLease);
@@ -29,6 +29,8 @@ export async function runAgentAsync({
agentKind,
agentRunId,
prompt,
model,
effort,
expoToken,
expoApiV2BaseUrl,
mcpUrl,
@@ -41,6 +43,8 @@ export async function runAgentAsync({
agentKind: AgentKind;
agentRunId: string;
prompt: string;
model?: string;
effort?: string;
expoToken: string;
expoApiV2BaseUrl: string;
/** The Expo MCP server's streamable HTTP endpoint. */
@@ -106,6 +110,8 @@ export async function runAgentAsync({
minimalEnv,
mcpServer,
prompt,
model,
effort,
credentials,
isResuming,
});
@@ -116,6 +122,8 @@ export async function runAgentAsync({
minimalEnv,
mcpServer,
prompt,
model,
effort,
credentials,
isResuming,
});
@@ -29,6 +29,8 @@ export async function prepareClaudeCodeAsync({
minimalEnv,
mcpServer,
prompt,
model,
effort,
credentials,
isResuming,
}: {
@@ -36,6 +38,8 @@ export async function prepareClaudeCodeAsync({
minimalEnv: Record<string, string>;
mcpServer: McpServer;
prompt: string;
model: string | undefined;
effort: string | undefined;
credentials: AgentRunProviderCredentials;
isResuming: boolean;
}): Promise<AgentInvocation> {
@@ -58,6 +62,8 @@ export async function prepareClaudeCodeAsync({
// gets one.
...['--tools', '', '--allowedTools', `mcp__${MCP_SERVER_NAME}`],
...['--mcp-config', mcpConfigPath, '--strict-mcp-config'],
...(model ? ['--model', model] : []),
...(effort ? ['--effort', effort] : []),
],
env: {
...minimalEnv,
@@ -28,6 +28,8 @@ export async function prepareCodexAsync({
minimalEnv,
mcpServer,
prompt,
model,
effort,
credentials,
isResuming,
}: {
@@ -35,6 +37,8 @@ export async function prepareCodexAsync({
minimalEnv: Record<string, string>;
mcpServer: McpServer;
prompt: string;
model: string | undefined;
effort: string | undefined;
credentials: AgentRunProviderCredentials;
isResuming: boolean;
}): Promise<AgentInvocation> {
@@ -51,6 +55,8 @@ export async function prepareCodexAsync({
'sandbox_mode = "read-only"',
'web_search = "disabled"',
'check_for_update_on_startup = false',
...(model ? [`model = ${JSON.stringify(model)}`] : []),
...(effort ? [`model_reasoning_effort = ${JSON.stringify(effort)}`] : []),
'',
'[features]',
'shell_tool = false',