pi-ext bugabingas pi extensions
owned by admin
README Source History Refs Compare Notes Search feat(masks): add fuzzy picker and prompt scope
4b9669748d8a4d08ef9fee13c27e4dafda1e86bd
Oliver Jan Krylow <oliver@bugabinga.net > · 24 Aug 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (7) 6 + - Add Masks for quickly switching between named model and thinking combinations with `/masks`, `Alt+M`, configurable direct shortcuts, and fuzzy matching
7 + - Let prompts select a Mask for one agent turn with an optional `mask` frontmatter field
6 8 - Change Tune's fullscreen shortcut to `Ctrl+Alt+T`
7 9 - Generate git-safe's fixed-executable wrapper on first Bash use and reuse it across reloads
8 10 - Defer unused extension implementations, PATH checks, settings reads, prompt loading, and RTK probes beyond startup and reload
extensions/masks/CHANGELOG.md Modified 7 7 - Add `/masks`, configurable picker shortcut, and per-mask shortcuts
8 + - Fuzzy-match masks by name, model, thinking level, and shortcut
8 9 - Apply configured model and thinking level together
10 + - Let prompt templates equip a mask for one agent run through `mask` frontmatter
11 + - Restore the previous model and thinking level after masked prompt runs
9 12 - Validate global `masks` settings and report invalid entries
extensions/masks/README.md Modified 14 - - `/masks` opens the mask picker.
14 + - `/masks` opens the fuzzy mask picker.
15 15 - `/masks <name>` equips one mask directly.
22 + - `input` detects prompt templates declaring a mask.
23 + - `before_agent_start` equips a prompt mask.
24 + - `agent_end` restores the previous model and thinking level.
22 25 - `session_start` reports invalid mask settings.
47 50 Settings are global because masks describe personal model access and bindings.
48 51 Run `/reload` after changing them.
53 + Prompt templates may equip a mask for one agent run:
57 + description: Review this change
60 + Review the current change.
63 + `mask` must exactly match a configured mask name.
64 + The mask lasts through the prompt's tool loop and is restored at `agent_end`.
65 + Masked prompts cannot be queued while another agent run is active.
52 - The picker shows every configured mask in settings order.
69 + The picker fuzzy-matches mask names, models, thinking levels, and shortcuts.
70 + Without a query, it shows every configured mask in settings order.
53 71 A mask changes the model first, then applies its thinking level.
54 72 Missing models or credentials leave the thinking level unchanged and report an error.
55 73 Successful switches add no status because Pi's existing footer shows model and thinking.
extensions/masks/__tests__/harness.test.ts Modified 24 + function writePrompt (name
: string , content
: string )
: void {
25 + if (
! root )
throw new Error (
"missing test root" );
26 + const promptsDir
= join (
root ,
"prompts" );
27 + mkdirSync (promptsDir, { recursive:
true });
28 + writeFileSync (
join (promptsDir,
`${name}.md` ), content);
24 31 function extension () {
25 32 if (
! t)
throw new Error (
"missing test session" );
26 33 return t.session.extensionRunner.extensions[
0 ];
120 + it (
"applies prompt frontmatter for one agent run, then restores" ,
async ()
=> {
121 + const cwd
= writeSettings ({
126 + model:
"openai/gpt-4o" ,
127 + thinkingLevel:
"high" ,
134 + "---\ndescription: Review changes\nmask: focused\n---\nReview it." ,
136 + t
= await createTestSession ({ cwd, extensions: [
extensionPath ()] });
137 + const model
= context ().modelRegistry.
find (
"openai" ,
"gpt-4o" );
138 + if (
! model)
throw new Error (
"missing harness model" );
139 + model.reasoning
= true ;
141 + const inputHandler
= extension ().handlers.
get (
"input" )[
0 ];
142 + const beforeHandler
= extension ().handlers.
get (
"before_agent_start" )[
0 ];
143 + const endHandler
= extension ().handlers.
get (
"agent_end" )[
0 ];
145 + await inputHandler (
146 + { type:
"input" , text:
"/review" , source:
"interactive" },
149 + ).
toEqual ({ action:
"continue" });
151 + await beforeHandler (
153 + type:
"before_agent_start" ,
154 + prompt:
"Review it." ,
157 + systemPromptOptions: {},
161 + expect (t.session.thinkingLevel).
toBe (
"high" );
163 + await endHandler ({ type:
"agent_end" , messages: [] },
context ());
164 + expect (t.session.model.provider).
toBe (
"openai" );
165 + expect (t.session.model.
id ).
toBe (
"gpt-4o" );
166 + expect (t.session.thinkingLevel).
toBe (
"off" );
169 + it (
"rejects masked prompt templates queued mid-run" ,
async ()
=> {
170 + const cwd
= writeSettings ({
175 + model:
"openai/gpt-4o" ,
176 + thinkingLevel:
"high" ,
181 + writePrompt (
"review" ,
"---\nmask: focused\n---\nReview it." );
182 + t
= await createTestSession ({ cwd, extensions: [
extensionPath ()] });
183 + const busyContext
= {
... context (),
isIdle : ()
=> false };
184 + const result
= await extension ().handlers.
get (
"input" )[
0 ](
187 + text:
"/review later" ,
188 + source:
"interactive" ,
189 + streamingBehavior:
"followUp" ,
194 + expect (result).
toEqual ({ action:
"handled" });
195 + expect (t.events.
uiCallsFor (
"notify" ).
at (
- 1 )?.args).
toEqual ([
196 + "Prompt /review: masked prompts cannot be queued mid-run" ,
201 + it (
"fuzzy-matches non-prefix mask queries" , ()
=> {
202 + const parsed
= __test.
parseMasksSettings ({
206 + model:
"openai-codex/gpt-5.6-terra" ,
207 + thinkingLevel:
"medium" ,
211 + model:
"openai-codex/gpt-5.6-sol" ,
212 + thinkingLevel:
"xhigh" ,
218 + __test.
fuzzyMasks (parsed.config.items,
"sxh" ).
map ((mask)
=> mask.
name ),
219 + ).
toEqual ([
"sol-xhigh" ]);
222 + it (
"equips the fuzzy picker's selected result" ,
async ()
=> {
223 + const parsed
= __test.
parseMasksSettings ({
227 + model:
"openai-codex/gpt-5.6-terra" ,
228 + thinkingLevel:
"medium" ,
232 + model:
"openai-codex/gpt-5.6-sol" ,
233 + thinkingLevel:
"xhigh" ,
237 + const selected
= await __test.
chooseFuzzyMask (parsed.config.items, {
239 + custom :
async (factory
: any )
=> {
240 + let result
: string | undefined ;
241 + const component
= await factory (
242 + {
requestRender () {} },
244 + bold : (text
: string )
=> text,
245 + fg : (_color
: string , text
: string )
=> text,
248 + matches : (data
: string , action
: string )
=> 249 + action
=== "tui.select.confirm" && data
=== "\r" ,
251 + (value
: string | undefined )
=> {
255 + for (
const key
of [
"s" ,
"x" ,
"h" ,
"\r" ]) component.
handleInput (key);
261 + expect (selected?.
name ).
toBe (
"sol-xhigh" );
113 264 it (
"validates schema while preserving usable picker entries" , ()
=> {
114 265 const parsed
= __test.
parseMasksSettings ({
115 266 pickerShortcut:
"alt+m" ,
extensions/masks/index.ts Modified 1 + import { readFileSync }
from "node:fs" ;
4 5 }
from "@earendil-works/pi-coding-agent" ;
5 - import { SettingsManager }
from "@earendil-works/pi-coding-agent" ;
10 + }
from "@earendil-works/pi-coding-agent" ;
18 + }
from "@earendil-works/pi-tui" ;
7 20 const SETTINGS_KEY
= "masks" ;
8 21 const DEFAULT_PICKER_SHORTCUT
= "alt+m" ;
136 149 return [model.
slice (
0 , separator), model.
slice (separator
+ 1 )];
152 + function fuzzyMasks (items
: Mask [], query
: string )
: Mask [] {
153 + if (
! query.
trim ())
return items;
154 + return fuzzyFilter (
158 + `${mask. name } ${mask.model} ${mask.thinkingLevel} ${mask.shortcut ?? ""}` ,
162 + async function chooseFuzzyMask (
164 + ctx
: ExtensionContext ,
165 + )
: Promise <
Mask | undefined > {
166 + const selectedName
= await ctx.ui.
custom <
string | undefined >(
167 + (tui, theme, keybindings, done)
=> {
168 + const container
= new Container ();
169 + const input
= new Input ();
170 + input.focused
= true ;
171 + let list
: SelectList ;
173 + function rebuild ()
: void {
174 + const filtered
= fuzzyMasks (items, input.
getValue ());
175 + list
= new SelectList (
176 + filtered.
map ((mask)
=> ({
179 + description:
`${mask.model}:${mask.thinkingLevel}${mask.shortcut ? ` · ${mask.shortcut}` : ""}` ,
181 + Math .
min (
Math .
max (filtered.
length ,
1 ),
8 ),
183 + selectedPrefix : (text)
=> theme.
fg (
"accent" , text),
184 + selectedText : (text)
=> theme.
fg (
"accent" , text),
185 + description : (text)
=> theme.
fg (
"muted" , text),
186 + scrollInfo : (text)
=> theme.
fg (
"dim" , text),
187 + noMatch : (text)
=> theme.
fg (
"warning" , text),
190 + list.
onSelect = (item)
=> done (item.
value );
191 + list.
onCancel = ()
=> done (
undefined );
194 + container.
addChild (
195 + new DynamicBorder ((text)
=> theme.
fg (
"accent" , text)),
197 + container.
addChild (
198 + new Text (theme.
fg (
"accent" , theme.
bold (
"Masks" )),
1 ,
0 ),
200 + container.
addChild (
new Text (theme.
fg (
"dim" ,
"Fuzzy filter" ),
1 ,
0 ));
201 + container.
addChild (input);
202 + container.
addChild (
new Spacer (
1 ));
203 + container.
addChild (list);
204 + container.
addChild (
208 + "type to filter · ↑↓ select · enter equip · esc cancel" ,
214 + container.
addChild (
215 + new DynamicBorder ((text)
=> theme.
fg (
"accent" , text)),
221 + render : (width
: number )
=> container.
render (width),
222 + invalidate : ()
=> container.
invalidate (),
223 + handleInput (data
: string ) {
225 + keybindings.
matches (data,
"tui.select.up" )
|| 226 + keybindings.
matches (data,
"tui.select.down" )
228 + list.
handleInput (data);
229 + tui.
requestRender ();
232 + if (keybindings.
matches (data,
"tui.select.confirm" )) {
233 + const selected
= list.
getSelectedItem ();
234 + if (selected)
done (selected.
value );
237 + if (keybindings.
matches (data,
"tui.select.cancel" )) {
242 + const previous
= input.
getValue ();
243 + input.
handleInput (data);
244 + if (input.
getValue ()
!== previous)
rebuild ();
245 + tui.
requestRender ();
250 + return items.
find ((mask)
=> mask.
name === selectedName);
253 + function promptCommandName (text
: string )
: string | undefined {
254 + return / ^ \/([ ^ \s] + )(?:\s |$ )/ u .
exec (text)?.[
1 ];
139 257 async function applyMask (
140 258 pi
: ExtensionAPI ,
164 282 export default function masksExtension (pi
: ExtensionAPI )
: void {
165 283 const { config, errors }
= readMasksSettings ();
284 + let pendingMask
: Mask | undefined ;
287 + model
: NonNullable <
ExtensionContext [
"model" ]>;
288 + thinkingLevel
: ThinkingLevel ;
167 292 async function chooseMask (ctx
: ExtensionContext )
: Promise <
void > {
168 293 if (config.items.
length === 0 ) {
169 294 ctx.ui.
notify (
"No masks configured in settings.json" ,
"warning" );
172 - const options
= config.items.
map (
173 - (mask)
=> `${mask. name } ${mask.model}:${mask.thinkingLevel}` ,
175 - const selected
= await ctx.ui.
select (
"Masks" , options);
176 - if (selected
=== undefined )
return ;
177 - const index
= options.
indexOf (selected);
178 - if (index
>= 0 )
await applyMask (pi, config.items[index], ctx);
297 + let mask
: Mask | undefined ;
298 + if (ctx.mode
=== "tui" ) {
299 + mask
= await chooseFuzzyMask (config.items, ctx);
301 + const options
= config.items.
map (
302 + (item)
=> `${item. name } ${item.model}:${item.thinkingLevel}` ,
304 + const selected
= await ctx.ui.
select (
"Masks" , options);
305 + const index
= selected
=== undefined ? - 1 : options.
indexOf (selected);
306 + mask
= index
>= 0 ? config.items[index]
: undefined ;
308 + if (mask)
await applyMask (pi, mask, ctx);
181 311 pi.
registerShortcut (config.pickerShortcut
as Shortcut , {
342 + pi.
on (
"input" , (event, ctx)
=> {
343 + pendingMask
= undefined ;
344 + const commandName
= promptCommandName (
event .
text );
345 + if (
! commandName)
return { action:
"continue" };
348 + .
find ((item)
=> item.
source === "prompt" && item.
name === commandName);
349 + if (
! command)
return { action:
"continue" };
351 + let frontmatter
: Record <
string ,
unknown >;
353 + frontmatter
= parseFrontmatter (
354 + readFileSync (command.sourceInfo.path,
"utf8" ),
358 + `Prompt /${commandName}: ${error instanceof Error ? error.message : String (error)}` ,
361 + return { action:
"handled" };
363 + if (
! Object .
hasOwn (frontmatter,
"mask" ))
return { action:
"continue" };
364 + const maskName
= nonEmptyString (frontmatter.mask);
367 + `Prompt /${commandName}: mask must be a non-empty string` ,
370 + return { action:
"handled" };
372 + const mask
= config.items.
find ((item)
=> item.
name === maskName);
375 + `Prompt /${commandName}: unknown mask "${maskName}"` ,
378 + return { action:
"handled" };
380 + if (
! ctx.
isIdle ()) {
382 + `Prompt /${commandName}: masked prompts cannot be queued mid-run` ,
385 + return { action:
"handled" };
387 + pendingMask
= mask;
388 + return { action:
"continue" };
391 + pi.
on (
"before_agent_start" ,
async (_event, ctx)
=> {
392 + const mask
= pendingMask;
393 + pendingMask
= undefined ;
397 + `Mask "${mask. name }": no current model to restore` ,
404 + thinkingLevel: pi.
getThinkingLevel (),
406 + if (
await applyMask (pi, mask, ctx)) restoreState
= previous;
409 + async function restoreTemporaryMask (ctx
: ExtensionContext )
: Promise <
void > {
410 + const previous
= restoreState;
411 + restoreState
= undefined ;
412 + if (
! previous)
return ;
413 + if (
! (
await pi.
setModel (previous.model))) {
414 + ctx.ui.
notify (
"Failed to restore model after prompt mask" ,
"error" );
417 + pi.
setThinkingLevel (previous.thinkingLevel);
420 + pi.
on (
"agent_end" ,
async (_event, ctx)
=> restoreTemporaryMask (ctx));
212 421 pi.
on (
"session_start" , (_event, ctx)
=> {
213 422 for (
const error
of errors) ctx.ui.
notify (error,
"warning" );
424 + pi.
on (
"session_shutdown" ,
async (_event, ctx)
=> {
425 + pendingMask
= undefined ;
426 + await restoreTemporaryMask (ctx);
217 - export const __test
= { applyMask, parseMasksSettings, splitModelRef };
430 + export const __test
= {
434 + parseMasksSettings,
extensions/masks/package.json Modified 4 4 "name" :
"@bugabinga/pi-ext-masks" ,
7 7 "peerDependencies" : {
8 - "@earendil-works/pi-coding-agent" :
"*" 8 + "@earendil-works/pi-coding-agent" :
"*" ,
9 + "@earendil-works/pi-tui" :
"*" 11 12 "description" :
"Named model and thinking combinations for Pi." ,
package-lock.json Modified 317 317 "vitest" :
"^4.1.9" 319 319 "peerDependencies" : {
320 - "@earendil-works/pi-coding-agent" :
"*" 320 + "@earendil-works/pi-coding-agent" :
"*" ,
321 + "@earendil-works/pi-tui" :
"*" 323 324 "extensions/model-info" : {