UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

58 lines • 2.83 kB
import { isMalformedToolUseTurn } from "./continuation.js"; import { providerAuthBlockedReason, providerAuthRecoveryHint } from "./continuation-recovery.js"; import { updateGoal } from "./store.js"; import { goalStoreRef } from "./store-ref.js"; import { didTerminalPolicyRejectionEndTurn, didTerminalProviderErrorEndTurn, terminalProviderAuthFailure, } from "./terminal-provider-error.js"; export async function continueGoalAfterAgentEnd(monitor, options) { if (options.goal?.status === "active" && didTerminalPolicyRejectionEndTurn(options.event)) { const blocked = await updateGoal(goalStoreRef(options.ctx.sessionManager, options.ctx.cwd), { status: "blocked", reason: "provider policy rejection ended the turn", }); // Cancel armed timers and staged recoveries; only an explicit goal resume // may restart a policy-blocked goal, not an infrastructure recovery path. monitor.syncGoal(blocked); return blocked; } const authFailure = options.goal?.status === "active" ? terminalProviderAuthFailure(options.event) : undefined; if (authFailure !== undefined) { const blocked = await updateGoal(goalStoreRef(options.ctx.sessionManager, options.ctx.cwd), { status: "blocked", reason: providerAuthBlockedReason(authFailure), }); monitor.syncGoal(blocked); if (options.ctx.hasUI) options.ctx.ui.notify(providerAuthRecoveryHint(authFailure), "warning"); return blocked; } if (options.event.aborted === true && options.event.abortSource === "system") { return monitor.afterSystemAbort({ ctx: options.ctx, event: options.event, goal: options.goal, messages: options.event.messages, willRetry: options.event.willRetry === true, }); } const lastAssistant = [...options.event.messages].reverse().find((message) => message.role === "assistant"); if (lastAssistant?.role === "assistant" && isMalformedToolUseTurn(lastAssistant)) { return monitor.afterProviderFailure({ ctx: options.ctx, event: options.event, goal: options.goal, messages: options.event.messages, willRetry: options.event.willRetry === true, }); } if (didTerminalProviderErrorEndTurn(options.event)) { return monitor.afterProviderFailure({ ctx: options.ctx, event: options.event, goal: options.goal, messages: options.event.messages, willRetry: options.event.willRetry === true, }); } return monitor.afterAgentEnd({ ctx: options.ctx, goal: options.goal, messages: options.event.messages }); } //# sourceMappingURL=agent-end-continuation.js.map