@@ -0,0 +1,30 @@
|
||||
// Pure settle decision for the goal loop — extracted so the abort/error/cap
|
||||
// paths (AC4, AC5) are hermetically testable without a live agent run.
|
||||
|
||||
import { checkLimitReached, type GoalState } from "./state.ts";
|
||||
|
||||
export type SettleDecision = { action: "inject" } | { action: "wait" } | { action: "pause"; reason: string };
|
||||
|
||||
/**
|
||||
* Decide what the loop does when the agent settles while a goal is active.
|
||||
* stopReason comes from the last assistant message ("stop", "toolUse",
|
||||
* "aborted", "error", ...).
|
||||
*/
|
||||
export function decideSettle(state: GoalState, stopReason: string | undefined): SettleDecision {
|
||||
if (stopReason === "aborted") {
|
||||
return { action: "pause", reason: "paused: run aborted (Esc)" };
|
||||
}
|
||||
if (stopReason === "error") {
|
||||
return { action: "pause", reason: "paused: run error" };
|
||||
}
|
||||
if (state.waitTimeoutSeconds && state.activeWait && !state.activeWait.wakeSent) {
|
||||
return { action: "wait" };
|
||||
}
|
||||
if (checkLimitReached(state)) {
|
||||
return {
|
||||
action: "pause",
|
||||
reason: `paused: cap of ${state.maxChecks} checks reached without a report`,
|
||||
};
|
||||
}
|
||||
return { action: "inject" };
|
||||
}
|
||||
Reference in New Issue
Block a user