@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
80 lines • 4.85 kB
TypeScript
import { type AgentMessage } from "@earendil-works/pi-agent-core";
import type { Goal } from "./types.ts";
type AssistantAgentMessage = Extract<AgentMessage, {
role: "assistant";
}>;
export declare const GOAL_CONTINUATION_CAP = 8;
export declare const GOAL_STALL_TOOLLESS_THRESHOLD = 3;
export declare const GOAL_REPETITION_HASH_STREAK = 3;
export declare const GOAL_LENGTH_RECOVERY_LIMIT = 1;
/**
* Consecutive automatic continuations without progress before the goal blocks (omo#10280).
* Progress is a tool-using turn, a changed todo state, or new human input (direct, or a
* human-input monitor delivery); varied narration alone is not. Measured across 593 goal
* sessions (30 days): toolless stretches that recovered into tool use peaked at 29 (p99 7);
* the #1139 stall ran 122. 60 is twice the measured peak, above the #447 pin (50).
*/
export declare const GOAL_NO_PROGRESS_CONTINUATION_LIMIT = 60;
export declare const GOAL_USER_GRACE_DELAY_MS = 10000;
export type GoalContinuationPath = "immediate" | "monitorDelayed" | "userGrace" | "sessionStart" | "systemRecovery" | "providerRecovery";
export type GoalContinuationInput = {
readonly goal: Goal | null;
readonly isIdle: boolean;
readonly hasPendingMessages: boolean;
readonly path: GoalContinuationPath;
readonly lastStopReason: AssistantAgentMessage["stopReason"] | undefined;
readonly lastTurnWasMalformedToolUse: boolean;
readonly consecutiveContinuations: number;
readonly lastContinuationSignature: string | undefined;
readonly currentSignature: string | undefined;
readonly consecutiveLengthRecoveries: number;
readonly recentNormalizedOutputHashes: readonly string[];
readonly toollessContinuationStreak: number;
readonly continuationPending: boolean;
/** The last turn was rejected (or silently starved) by context size and recovery did not shrink it. */
readonly lastTurnStuckOnContextOverflow: boolean;
/**
* The wake re-checks a provider that refused for a usage or rate limit, either on the armed provider retry or as
* the first wake of a session opened in the middle of that wait. Waiting out a limit is not a stall, so it spends
* neither the continuation cap nor the no-progress budget (senpi#4085).
*/
readonly limitWait?: boolean;
};
export type GoalContinuationVerdict = {
kind: "continue";
prompt: "full" | "minimal";
stallNotice: boolean;
} | {
kind: "deny";
reason: "not-eligible" | "single-flight" | "cap" | "stale" | "repetition" | "length-exhausted" | "no-progress" | "context-overflow";
};
export declare function didAgentEndCleanly(messages: readonly AgentMessage[]): boolean;
export declare function isMalformedToolUseTurn(message: AssistantAgentMessage): boolean;
export declare function evaluateGoalContinuation(input: GoalContinuationInput): GoalContinuationVerdict;
/** Produces a stable, whitespace-insensitive representation for repetition detection. */
export declare function normalizeAssistantText(text: string): string;
/** Hashes normalized assistant text with the deterministic 32-bit FNV-1a algorithm. */
export declare function hashAssistantText(text: string): string;
/**
* Identifies the observable goal progress for stale-continuation admission.
* Deliberately excludes goal.updatedAt because usage accounting updates it after every agent turn.
*/
export declare function buildGoalContinuationSignature(goal: Pick<Goal, "id">, openTodos: number, totalTodos: number, lastAssistantTextHash: string): string;
export declare function hasGoalContinuationProgress(input: Pick<GoalContinuationInput, "lastContinuationSignature" | "currentSignature">): boolean;
/** True when the open/total todo counts in the signature changed; the narration hash is ignored. */
export declare function hasGoalTodoProgress(input: Pick<GoalContinuationInput, "lastContinuationSignature" | "currentSignature">): boolean;
/**
* How many recent tool-effect fingerprints a new one must differ from to count as progress. Far above the guard's
* 60, so rotating through a fixed set of calls earns at most one progress turn per distinct call.
*/
export declare const GOAL_TOOL_EFFECT_WINDOW = 256;
/**
* Fingerprint of what a turn's tools did: every call's name and arguments (numbers masked unless the tool mutates
* files), and every result's error flag and text with run-to-run noise masked. Re-running the same call with the
* same outcome yields the same fingerprint, so a tool loop is not progress. A turn whose tool results all failed
* has no fingerprint: failing is never progress.
*/
export declare function toolEffectFingerprint(messages: readonly AgentMessage[]): string | undefined;
export declare function continuationTurnUsedTools(messages: readonly AgentMessage[]): boolean;
export {};
//# sourceMappingURL=continuation.d.ts.map