pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Reviews Compare Notes Search Review guide feat(angel): on/off toggle, Doubt rename, advisor-uncertain banner ba397120cf7fb92c69641b79795a6376470241e9
Oliver Jan Krylow <oliver@bugabinga.net > · 29 Jun 2026
unsigned
Browse files Compare with HEAD
Replace the `/angel <question>` + `/angel-policy` surface with a single
`/angel on|off` session toggle. Rename the low-confidence `Devil` field to
`Doubt` (widget badge `consider-devil` → `low confidence`). Inject a
`> ⚠ ADVISOR UNCERTAIN` banner (or `INSUFFICIENT CONTEXT`) at the top of
formatted advice when confidence is below threshold, so the receiving model
is told to verify assumptions and risks and prefer read-only operations
before acting on `Next:`.
Also bundled (per "commit all"):
- changelog: document the mode extension's memory-only-state restore-on-off
/ restore-on-shutdown behavior (the feature landed in 4870b53)
- add the `/wr` "wrap it up" prompt
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Changed files (4) Diff layout Auto Unified Split
+24 / −0 text lines
3 3 ## Unreleased ## Unreleased
5 + - Rename angel low-confidence `Devil` field to `Doubt` and widget badge from6 + `consider-devil` to `low confidence`7 + - Inject a `> ⚠ ADVISOR UNCERTAIN` banner at the top of formatted angel advice8 + when confidence < 50% (or `INSUFFICIENT CONTEXT` banner when the advisor9 + reports insufficient context) so the receiving model is explicitly told to10 + verify assumptions and risks and prefer read-only operations before acting12 + - Make `/mode off` a no-op with `no mode active` notify when no mode is active,13 + and otherwise restore baseline tools/model/thinking only for fields the active14 + mode overrode, skipping restore for fields the user manually changed since15 + switch and for fields whose baseline ref is stale, while keeping the16 + `<mode_kernel>` guard so the mode body and reminder are physically removed17 + from the system prompt after off18 + - Restore mode baseline tools/model/thinking on `session_shutdown` so a mode19 + left active at session end does not leave the user's default model, thinking,20 + or tool filter polluted for the next session21 + - Capture `getAllTools()` (name + `sourceInfo.source`) in the mode baseline so22 + `/mode off` and shutdown restore can union new pi builtin tools back into the23 + active tool set, while leaving post-switch extension tool registrations out24 + unless the user explicitly enabled them25 + - Document that mode `model`/`thinking` overrides are not session-scoped in the26 + current SDK: `pi.setModel` and `pi.setThinkingLevel` rewrite the user's27 + default model and thinking in settings, and only the `mode` extension's28 + baseline capture and restore-on-off / restore-on-shutdown mitigates the bleed5 29 - Convert extension drivers, helper scripts, and skill scripts from Python to MJS,- Convert extension drivers, helper scripts, and skill scripts from Python to MJS,6 30 remove the Python/ruff project setup, and rename the goal pexpect test task remove the Python/ruff project setup, and rename the goal pexpect test task7 31 - Fix notes widget rendering so Pi displays it at column zero with width-aware- Fix notes widget rendering so Pi displays it at column zero with width-awareextensions/angel/README.md Modified +9 / −9 text lines
40 40 ### Commands ### Commands 42 - - `/angel <question>`:43 - manual advisor consult.44 - Requires UI and a non-empty question.45 - Opens full advice in editor.47 - show latest enforceable policy in editor, or print it without UI.43 + toggle Angel for the current session.44 + Argument hint `<on|off>` and tab completion for `on` / `off`.45 + Defaults to `settings.enabled !== false` on session start.46 + No persistence — resets each session.47 + Re-runs `syncAvailability` to show/hide the `angel` tool and status.123 123 - Persists advice as `angel-advice` entries with packet summary metadata.- Persists advice as `angel-advice` entries with packet summary metadata.124 124 - Injects formatted advice into the agent loop after configured failed- Injects formatted advice into the agent loop after configured failed125 125 tool-result intervals. tool-result intervals.126 - - Stores the latest enforceable policy for `/angel-policy`.
127 126 - Keeps semantic guidance in `advisoryOnly`; only dangerous-command detection is- Keeps semantic guidance in `advisoryOnly`; only dangerous-command detection is128 127 mechanical. mechanical.129 - - Tool render marks low-confidence advice as `consider-devil `; formatted advice130 - marks `Devil` as recommended when confidence is below 50%.128 + - Tool render marks low-confidence advice as `low confidence `; formatted advice129 + prepends a `> ⚠ ADVISOR UNCERTAIN` banner and marks `Doubt` as recommended when130 + confidence is below 50%.132 132 ## Policy Gates ## Policy Gates extensions/angel/index.ts Modified +39 / −69 text lines
8 8 * { "angel" : { "pairs" : [{ "executor" : "a" , "advisor" : "b" }], ... } } * { "angel" : { "pairs" : [{ "executor" : "a" , "advisor" : "b" }], ... } }10 10 * Tools : angel (question? , context? ) * Tools : angel (question? , context? )11 - * Commands: / angel < question> , / angel- policy11 + * Commands: / angel on| off14 14 import { existsSync, readFileSync } from "node:fs" ;import { existsSync, readFileSync } from "node:fs" ;25 25 getAgentDir, getAgentDir,26 26 serializeConversation, serializeConversation,27 27 } from "@earendil-works/pi-coding-agent" ;} from "@earendil-works/pi-coding-agent" ;
28 + import type { AutocompleteItem } from "@earendil-works/pi-tui" ;28 29 import { Text } from "@earendil-works/pi-tui" ;import { Text } from "@earendil-works/pi-tui" ;29 30 import { Type } from "typebox" ;import { Type } from "typebox" ;418 419 function formatAdvice (r: AngelResult ): string {function formatAdvice (r: AngelResult ): string {419 420 const { advice: a, advisorKey, executorKey, tokens, packet } = r; const { advice: a, advisorKey, executorKey, tokens, packet } = r;
421 + const lowConfidence = a.confidence < CONFIDENCE_THRESHOLD;422 + const warning = lowConfidence423 + ? `\n> ⚠ **ADVISOR UNCERTAIN** (${ Math . round (a.confidence * 100)}% confidence). Verify assumptions and risks before acting on \`Next:\`. Prefer read-only operations.${a.insufficientContext ? " Context is also insufficient — ask the human." : ""}\n` 424 + : a.insufficientContext425 + ? "\n> ⚠ **INSUFFICIENT CONTEXT**. Ask the human for clarification before acting on `Next:`.\n" 420 427 const lines = [ const lines = [421 428 "## Angel\n" , "## Angel\n" ,422 430 `**Summary:** ${a. summary }` , `**Summary:** ${a. summary }` ,423 431 `**Next:** ${a.nextAction}` , `**Next:** ${a.nextAction}` ,424 432 `**Confidence:** ${ Math . round (a.confidence * 100)}%${a.insufficientContext ? " · insufficient context" : ""}` , `**Confidence:** ${ Math . round (a.confidence * 100)}%${a.insufficientContext ? " · insufficient context" : ""}` ,425 - `**Devil:** ${a.confidence < CONFIDENCE_THRESHOLD ? "⚠ recommended" : "not needed"}\n` ,433 + `**Doubt:** ${lowConfidence ? "⚠ recommended" : "not needed"}\n` ,426 434 "### Risks" , "### Risks" ,427 435 bulletList (a.risks), bulletList (a.risks),428 436 "### Assumptions" , "### Assumptions" ,504 512 let callCount = 0 ; let callCount = 0 ;505 513 let toolErrorCount = 0 ; let toolErrorCount = 0 ;506 - let latestAdvice: Advice | null = null ;
507 514 let gatedDangerousCommands = new Set <string >(); let gatedDangerousCommands = new Set <string >();
515 + let sessionEnabled = settings.enabled !== false ;517 + const isEnabled = (): boolean => sessionEnabled && settings.enabled !== false ;511 521 function syncAvailability (ctx: ExtensionContext , executor = ctx.model) { function syncAvailability (ctx: ExtensionContext , executor = ctx.model) {512 522 const binding = const binding = 513 - executor && settings.enabled !== false 514 - ? resolveBinding (ctx, settings, executor)523 + executor && isEnabled ( ) ? resolveBinding (ctx, settings, executor) : null ; 516 524 const available = binding !== null ; const available = binding !== null ;517 525 const tools = pi.getActiveTools (); const tools = pi.getActiveTools ();518 526 const has = tools.includes ("angel" ); const has = tools.includes ("angel" );540 548 extraContext?: string, extraContext?: string,541 549 signal?: AbortSignal, signal?: AbortSignal,542 550 ): Promise < AngelResult> { ): Promise < AngelResult> {543 - if (settings.enabled === false ) throw new Error ("Angel is disabled" );551 + if (! isEnabled ( )) throw new Error ("Angel is disabled" );544 552 if (callCount >= maxCalls) if (callCount >= maxCalls)545 553 throw new Error (`Max Angel calls (${maxCalls}) reached` ); throw new Error (`Max Angel calls (${maxCalls}) reached` );557 565 const packet = await buildPacket (ctx, trigger, question, extraContext); const packet = await buildPacket (ctx, trigger, question, extraContext);558 566 const result = await consult (binding, packet, auth, signal); const result = await consult (binding, packet, auth, signal);560 - latestAdvice = result.advice;
562 568 pi.appendEntry ("angel-advice" , { pi.appendEntry ("angel-advice" , {563 569 timestamp: Date .now (), timestamp: Date .now (),564 570 executor: result.executorKey, executor: result.executorKey,585 591 pi.on ("session_start" , (_event, ctx) => { pi.on ("session_start" , (_event, ctx) => {586 592 callCount = 0 ; callCount = 0 ;587 593 toolErrorCount = 0 ; toolErrorCount = 0 ;588 - latestAdvice = null ;
589 594 gatedDangerousCommands = new Set <string >(); gatedDangerousCommands = new Set <string >();
595 + sessionEnabled = settings.enabled !== false ;591 - for (const e of ctx.sessionManager.getBranch ()) {592 - if (e.type === "custom" && e.customType === "angel-advice" ) {593 - const d = (e.data as { advice?: Advice } | undefined )?.advice;594 - if (d) latestAdvice = d;596 - e.type === "message" && 597 - e.message.role === "custom" && 598 - e.message.customType === "angel-advice" 600 - const d = (e.message.details as { advice?: Advice } | undefined )602 - if (d) latestAdvice = d;
605 597 syncAvailability (ctx); syncAvailability (ctx);611 603 pi.on ("tool_call" , async (event, ctx) => { pi.on ("tool_call" , async (event, ctx) => {612 - if (settings.enabled === false || policyGate === "off" ) return ;604 + if (! isEnabled () || policyGate === "off" ) return ;613 605 if (! isDangerousCommand (event .toolName, event .input )) return ; if (! isDangerousCommand (event .toolName, event .input )) return ;615 607 const binding = resolveBinding (ctx, settings); const binding = resolveBinding (ctx, settings);645 637 pi.on ("tool_result" , async (event, ctx) => { pi.on ("tool_result" , async (event, ctx) => {647 - settings.enabled === false || 648 - autoOnErrors <= 0 || 649 - event .toolName === "angel" 638 + if (! isEnabled () || autoOnErrors <= 0 || event .toolName === "angel" ) return ;652 639 if (! event .isError) return ; if (! event .isError) return ;653 640 toolErrorCount++ ; toolErrorCount++ ;654 641 if (toolErrorCount % autoOnErrors !== 0 ) return ; if (toolErrorCount % autoOnErrors !== 0 ) return ;740 727 if (a.insufficientContext) if (a.insufficientContext)741 728 out += theme.fg ("warning" , " insufficient-context" ); out += theme.fg ("warning" , " insufficient-context" );742 729 if (a.confidence < CONFIDENCE_THRESHOLD) if (a.confidence < CONFIDENCE_THRESHOLD)743 - out += theme.fg ("warning" , " consider-devil" );730 + out += theme.fg ("warning" , " low confidence" );744 731 out += `\n${theme. fg ("toolTitle", "Next: ")}${a.nextAction}` ; out += `\n${theme. fg ("toolTitle", "Next: ")}${a.nextAction}` ;745 732 if (a.enforceablePolicy.length > 0 ) if (a.enforceablePolicy.length > 0 )746 733 out += `\n${theme. fg ("warning", `${a.enforceablePolicy. length } policy gate(s) active`)}` ; out += `\n${theme. fg ("warning", `${a.enforceablePolicy. length } policy gate(s) active`)}` ;804 791 pi.registerCommand ("angel" , { pi.registerCommand ("angel" , {805 - description: "Consult Angel structured advisor" ,792 + description: "Enable/disable Angel for this session" ,793 + argumentHint: "<on|off>" ,794 + getArgumentCompletions : (prefix): AutocompleteItem [] | null => {795 + const items: AutocompleteItem [] = [796 + { value: "on" , label: "on" },797 + { value: "off" , label: "off" },799 + const filtered = items.filter ((i) => 800 + i.value .startsWith (prefix.toLowerCase ()),802 + return filtered.length > 0 ? filtered : null ;806 804 handler : async (args, ctx) => { handler : async (args, ctx) => {807 - if (! ctx.hasUI) return ;808 - const question = args.trim ();810 - ctx.ui.notify ("Usage: /angel <question> " , "error" );805 + const arg = args.trim ().toLowerCase ();806 + if (arg !== "on" && arg !== "off" ) {807 + if ( ctx.hasUI ) ctx . ui.notify ("Usage: /angel on|off " , "error" );815 - const result = await runAngel (822 - const edited = await ctx.ui.editor ("Angel" , formatAdvice (result));823 - if (edited !== undefined ) ctx.ui.setEditorText (edited);810 + sessionEnabled = arg === "on" ;811 + syncAvailability (ctx);825 813 ctx.ui.notify ( ctx.ui.notify (826 - `Angel failed: ${err instanceof Error ? err.message : err}` ,814 + `Angel ${sessionEnabled ? "enabled" : "disabled"}` ,833 - pi.registerCommand ("angel-policy" , {834 - description: "Show latest Angel enforceable policy" ,835 - handler : async (_args, ctx) => {836 - const policy = latestAdvice?.enforceablePolicy ?? [];839 - ? policy.map ((p) => `- ${p}` ).join ("\n" )840 - : "No Angel policy active." ;842 - const edited = await ctx.ui.editor ("Angel Policy" , text);843 - if (edited !== undefined ) ctx.ui.setEditorText (edited);
new file mode 100644+7 / −0 text lines
2 + description: Wrap it up3 + argument-hint: "[instructions]"6 + good, wrap it up and implement what we decided step by step, end to end. tdd, brutal.