setup: workspace, dev deps, and project-local extension install
- Add pnpm-workspace.yaml for monorepo - Add @mariozechner/pi-coding-agent as root devDependency (TS types) - Create .pi/settings.json with local package reference - Extension auto-loads and hot-reloads via /reload
This commit is contained in:
parent
57d238a1ea
commit
68c7cb2daf
5
.pi/settings.json
Normal file
5
.pi/settings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
"../packages/pi-turn-limit"
|
||||||
|
]
|
||||||
|
}
|
||||||
1
autoresearch.jsonl
Normal file
1
autoresearch.jsonl
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"type":"config","name":"Turn-limit extension naming","metricName":"extension_name","metricUnit":"","bestDirection":"lower"}
|
||||||
3847
package-lock.json
generated
Normal file
3847
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,5 +7,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=24"
|
"node": ">=24"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@mariozechner/pi-coding-agent": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,11 @@
|
|||||||
"description": "Pi coding agent extension to limit number of turns taken by a model",
|
"description": "Pi coding agent extension to limit number of turns taken by a model",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/turn-limit.ts"
|
||||||
},
|
},
|
||||||
"keywords": ["pi-package"],
|
"keywords": ["pi-package"],
|
||||||
"pi": {
|
"pi": {
|
||||||
"extensions": ["src/index.ts"]
|
"extensions": ["src/turn-limit.ts"]
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@mariozechner/pi-coding-agent": "*"
|
"@mariozechner/pi-coding-agent": "*"
|
||||||
|
|||||||
56
packages/pi-turn-limit/src/turn-limit.ts
Normal file
56
packages/pi-turn-limit/src/turn-limit.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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