mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat: add codex reasoning effort option (#297)
This commit is contained in:
@@ -102,7 +102,7 @@ export class ApiMachineClient {
|
||||
|
||||
setRPCHandlers({ spawnSession, stopSession, requestShutdown }: MachineRpcHandlers): void {
|
||||
this.rpcHandlerManager.registerHandler('spawn-happy-session', async (params: any) => {
|
||||
const { directory, sessionId, resumeSessionId, machineId, approvedNewDirectoryCreation, agent, model, yolo, token, sessionType, worktreeName } = params || {}
|
||||
const { directory, sessionId, resumeSessionId, machineId, approvedNewDirectoryCreation, agent, model, modelReasoningEffort, yolo, token, sessionType, worktreeName } = params || {}
|
||||
|
||||
if (!directory) {
|
||||
throw new Error('Directory is required')
|
||||
@@ -116,6 +116,7 @@ export class ApiMachineClient {
|
||||
approvedNewDirectoryCreation,
|
||||
agent,
|
||||
model,
|
||||
modelReasoningEffort,
|
||||
yolo,
|
||||
token,
|
||||
sessionType,
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface EnhancedMode {
|
||||
permissionMode: PermissionMode;
|
||||
model?: string;
|
||||
collaborationMode: CodexCollaborationMode;
|
||||
modelReasoningEffort?: string;
|
||||
}
|
||||
|
||||
interface LoopOptions {
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function runCodex(opts: {
|
||||
permissionMode?: PermissionMode;
|
||||
resumeSessionId?: string;
|
||||
model?: string;
|
||||
modelReasoningEffort?: string;
|
||||
}): Promise<void> {
|
||||
const workingDirectory = getInvokedCwd();
|
||||
const startedBy = opts.startedBy ?? 'terminal';
|
||||
@@ -45,6 +46,7 @@ export async function runCodex(opts: {
|
||||
const messageQueue = new MessageQueue2<EnhancedMode>((mode) => hashObject({
|
||||
permissionMode: mode.permissionMode,
|
||||
model: mode.model,
|
||||
modelReasoningEffort: mode.modelReasoningEffort,
|
||||
collaborationMode: mode.collaborationMode
|
||||
}));
|
||||
|
||||
@@ -53,6 +55,7 @@ export async function runCodex(opts: {
|
||||
|
||||
let currentPermissionMode: PermissionMode = opts.permissionMode ?? 'default';
|
||||
let currentModel = opts.model;
|
||||
const currentModelReasoningEffort = opts.modelReasoningEffort;
|
||||
let currentCollaborationMode: EnhancedMode['collaborationMode'] = 'default';
|
||||
|
||||
const lifecycle = createRunnerLifecycle({
|
||||
@@ -105,6 +108,7 @@ export async function runCodex(opts: {
|
||||
const enhancedMode: EnhancedMode = {
|
||||
permissionMode: messagePermissionMode ?? 'default',
|
||||
model: currentModel,
|
||||
modelReasoningEffort: currentModelReasoningEffort,
|
||||
collaborationMode: currentCollaborationMode
|
||||
};
|
||||
const formattedText = formatMessageWithAttachments(message.content.text, message.content.attachments);
|
||||
|
||||
@@ -64,6 +64,22 @@ describe('appServerConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes model reasoning effort via thread config', () => {
|
||||
const params = buildThreadStartParams({
|
||||
mode: { permissionMode: 'default', modelReasoningEffort: 'xhigh', collaborationMode: 'default' },
|
||||
mcpServers
|
||||
});
|
||||
|
||||
expect(params.config).toEqual({
|
||||
'mcp_servers.hapi': {
|
||||
command: 'node',
|
||||
args: ['mcp']
|
||||
},
|
||||
developer_instructions: codexSystemPrompt,
|
||||
model_reasoning_effort: 'xhigh'
|
||||
});
|
||||
});
|
||||
|
||||
it('builds turn params with mode defaults', () => {
|
||||
const params = buildTurnStartParams({
|
||||
threadId: 'thread-1',
|
||||
|
||||
@@ -84,7 +84,8 @@ export function buildThreadStartParams(args: {
|
||||
} = resolveInstructions(args);
|
||||
const configWithInstructions = {
|
||||
...config,
|
||||
developer_instructions: resolvedDeveloperInstructions
|
||||
developer_instructions: resolvedDeveloperInstructions,
|
||||
...(args.mode.modelReasoningEffort ? { model_reasoning_effort: args.mode.modelReasoningEffort } : {})
|
||||
};
|
||||
|
||||
const params: ThreadStartParams = {
|
||||
|
||||
@@ -18,6 +18,7 @@ export const codexCommand: CommandDefinition = {
|
||||
permissionMode?: CodexPermissionMode
|
||||
resumeSessionId?: string
|
||||
model?: string
|
||||
modelReasoningEffort?: string
|
||||
} = {}
|
||||
const unknownArgs: string[] = []
|
||||
|
||||
@@ -44,6 +45,12 @@ export const codexCommand: CommandDefinition = {
|
||||
}
|
||||
options.model = model
|
||||
unknownArgs.push('--model', model)
|
||||
} else if (arg === '--model-reasoning-effort') {
|
||||
const effort = commandArgs[++i]
|
||||
if (!effort) {
|
||||
throw new Error('Missing --model-reasoning-effort value')
|
||||
}
|
||||
options.modelReasoningEffort = effort
|
||||
} else {
|
||||
unknownArgs.push(arg)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface SpawnSessionOptions {
|
||||
approvedNewDirectoryCreation?: boolean
|
||||
agent?: 'claude' | 'codex' | 'cursor' | 'gemini' | 'opencode'
|
||||
model?: string
|
||||
modelReasoningEffort?: string
|
||||
yolo?: boolean
|
||||
token?: string
|
||||
sessionType?: 'simple' | 'worktree'
|
||||
|
||||
@@ -361,6 +361,9 @@ export async function startRunner(): Promise<void> {
|
||||
if (options.model && agent !== 'opencode') {
|
||||
args.push('--model', options.model);
|
||||
}
|
||||
if (options.modelReasoningEffort && agent === 'codex') {
|
||||
args.push('--model-reasoning-effort', options.modelReasoningEffort);
|
||||
}
|
||||
if (yolo) {
|
||||
args.push('--yolo');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user