tidy: remove old turn-limit file
This commit is contained in:
parent
68c7cb2daf
commit
f0d53a5ced
@ -1,56 +0,0 @@
|
||||
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
||||
|
||||
// ============================================================================
|
||||
// Configuration
|
||||
// ============================================================================
|
||||
|
||||
const DEFAULT_MAX_TURNS = 25;
|
||||
|
||||
function getMaxTurns(): number {
|
||||
const env = process.env.PI_MAX_TURNS;
|
||||
if (!env) return DEFAULT_MAX_TURNS;
|
||||
const parsed = parseInt(env, 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_MAX_TURNS;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Pure detection logic (testable)
|
||||
// ============================================================================
|
||||
|
||||
export function checkTurnLimit(
|
||||
turnIndex: number,
|
||||
maxTurns: number,
|
||||
): { exceeded: boolean; turnIndex: number; maxTurns: number } {
|
||||
return {
|
||||
exceeded: turnIndex > maxTurns,
|
||||
turnIndex,
|
||||
maxTurns,
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Extension handler
|
||||
// ============================================================================
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
let turnCount = 0;
|
||||
const maxTurns = getMaxTurns();
|
||||
|
||||
pi.on("agent_start", async (_event, ctx) => {
|
||||
// Reset counter for each new user prompt
|
||||
turnCount = 0;
|
||||
});
|
||||
|
||||
pi.on("turn_start", async (event, ctx) => {
|
||||
turnCount++;
|
||||
|
||||
const { exceeded } = checkTurnLimit(event.turnIndex, maxTurns);
|
||||
if (exceeded && ctx.hasUI) {
|
||||
ctx.ui.notify(
|
||||
`Turn limit exceeded: ${maxTurns} turns reached. Agent aborted.`,
|
||||
"error",
|
||||
);
|
||||
ctx.abort();
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user