feat(extensions): establish canonical goal source (#54, #55)

This commit is contained in:
2026-09-06 02:32:32 -05:00
parent 44f257cb06
commit d4696d09eb
43 changed files with 6845 additions and 0 deletions
+30
View File
@@ -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" };
}