From ab064267733700528e55d1606b0c7d3c1518a5c0 Mon Sep 17 00:00:00 2001 From: weishu Date: Sun, 21 Dec 2025 23:13:14 +0800 Subject: [PATCH] feat: add source file execution and fix function name reference - Add support for running CLI from TypeScript source when using tsx or similar tools - Fix outdated happy__change_title reference to hapi__change_title in codex prompt --- cli/src/codex/runCodex.ts | 2 +- cli/src/utils/spawnHappyCLI.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/src/codex/runCodex.ts b/cli/src/codex/runCodex.ts index 3d656259..773fa0a4 100644 --- a/cli/src/codex/runCodex.ts +++ b/cli/src/codex/runCodex.ts @@ -623,7 +623,7 @@ export async function runCodex(opts: { if (!wasCreated) { const startConfig: CodexSessionConfig = { - prompt: first ? message.message + '\n\n' + trimIdent(`Based on this message, call functions.happy__change_title to change chat session title that would represent the current task. If chat idea would change dramatically - call this function again to update the title.`) : message.message, + prompt: first ? message.message + '\n\n' + trimIdent(`Based on this message, call functions.hapi__change_title to change chat session title that would represent the current task. If chat idea would change dramatically - call this function again to update the title.`) : message.message, sandbox, 'approval-policy': approvalPolicy, config: { mcp_servers: mcpServers } diff --git a/cli/src/utils/spawnHappyCLI.ts b/cli/src/utils/spawnHappyCLI.ts index 3cd1cfd3..39179313 100644 --- a/cli/src/utils/spawnHappyCLI.ts +++ b/cli/src/utils/spawnHappyCLI.ts @@ -102,6 +102,16 @@ export function getHappyCliCommand(args: string[]): HappyCliCommand { const isBunRuntime = Boolean((process.versions as Record).bun); const entrypoint = isBunRuntime ? resolveEntrypointForBun(projectRoot) : distEntrypoint; + const argv1 = process.argv[1] ?? ''; + const runningFromSource = argv1.endsWith(join('src', 'index.ts')) || process.execArgv.some((arg) => arg.includes('tsx')); + const srcEntrypoint = join(projectRoot, 'src', 'index.ts'); + if (!isBunRuntime && runningFromSource && existsSync(srcEntrypoint)) { + return { + command: process.execPath, + args: [...process.execArgv, srcEntrypoint, ...args] + }; + } + const spawnArgs = isBunRuntime ? [entrypoint, ...args] : [ '--no-warnings', '--no-deprecation',