|
| 1 | +/** |
| 2 | + * Top-level CLI-backed agent runner orchestration. |
| 3 | + */ |
1 | 4 | import type { ReplyPayload } from "../auto-reply/reply-payload.js"; |
2 | 5 | import { SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js"; |
3 | 6 | import { formatErrorMessage } from "../infra/errors.js"; |
@@ -44,10 +47,12 @@ const cliRunnerDeps = { |
44 | 47 | }, |
45 | 48 | }; |
46 | 49 |
|
| 50 | +/** Overrides top-level CLI runner dependencies for tests. */ |
47 | 51 | export function setCliRunnerTestDeps(overrides: Partial<typeof cliRunnerDeps>): void { |
48 | 52 | Object.assign(cliRunnerDeps, overrides); |
49 | 53 | } |
50 | 54 |
|
| 55 | +/** Restores default top-level CLI runner dependencies after tests. */ |
51 | 56 | export function restoreCliRunnerTestDeps(): void { |
52 | 57 | cliRunnerDeps.claudeCliSessionTranscriptHasContent = claudeCliSessionTranscriptHasContentImpl; |
53 | 58 | cliRunnerDeps.delay = async (delayMs: number) => { |
@@ -80,6 +85,7 @@ function shouldRetryFreshCliSessionAfterFailover(params: { |
80 | 85 | } |
81 | 86 | } |
82 | 87 |
|
| 88 | +/** Checks whether a Claude CLI session binding has reached its transcript file. */ |
83 | 89 | export async function isCliBindingFlushed( |
84 | 90 | sessionId: string | undefined, |
85 | 91 | provider: string | undefined, |
@@ -281,6 +287,7 @@ async function finalizeCliContextEngineTurn(params: { |
281 | 287 | } |
282 | 288 | } |
283 | 289 |
|
| 290 | +/** Prepares and runs one CLI-backed agent turn. */ |
284 | 291 | export async function runCliAgent(params: RunCliAgentParams): Promise<EmbeddedAgentRunResult> { |
285 | 292 | // Cron gate must fire before prepareCliRunContext — that call allocates |
286 | 293 | // backend resources released only by runPreparedCliAgent's try…finally. |
@@ -351,6 +358,7 @@ export async function runCliAgent(params: RunCliAgentParams): Promise<EmbeddedAg |
351 | 358 | } |
352 | 359 | } |
353 | 360 |
|
| 361 | +/** Runs an already-prepared CLI agent context through hooks and execution. */ |
354 | 362 | export async function runPreparedCliAgent( |
355 | 363 | context: PreparedCliRunContext, |
356 | 364 | ): Promise<EmbeddedAgentRunResult> { |
@@ -850,11 +858,13 @@ export async function runPreparedCliAgent( |
850 | 858 | } |
851 | 859 | } |
852 | 860 |
|
| 861 | +/** Legacy Claude-specific wrapper params for the generic CLI runner. */ |
853 | 862 | export type RunClaudeCliAgentParams = Omit<RunCliAgentParams, "provider" | "cliSessionId"> & { |
854 | 863 | provider?: string; |
855 | 864 | claudeSessionId?: string; |
856 | 865 | }; |
857 | 866 |
|
| 867 | +/** Converts legacy Claude CLI wrapper params into generic CLI runner params. */ |
858 | 868 | export function buildRunClaudeCliAgentParams(params: RunClaudeCliAgentParams): RunCliAgentParams { |
859 | 869 | return { |
860 | 870 | sessionId: params.sessionId, |
@@ -892,6 +902,7 @@ export function buildRunClaudeCliAgentParams(params: RunClaudeCliAgentParams): R |
892 | 902 | }; |
893 | 903 | } |
894 | 904 |
|
| 905 | +/** Runs the legacy Claude CLI wrapper through the generic CLI runner. */ |
895 | 906 | export async function runClaudeCliAgent( |
896 | 907 | params: RunClaudeCliAgentParams, |
897 | 908 | ): Promise<EmbeddedAgentRunResult> { |
|
0 commit comments