pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search fix(leaks): block unresolved placeholders in writes
861008b2d5e29b4367fbb0f1194343bbc9790455
Review <review@example.invalid > · 23 Jun 2026
unsigned
Browse files Compare with HEAD
Changed files (3) 52 52 final answer, with regression and manual coverage for create-check-answer flow
53 53 - Fix goldfish task output semantics so active tasks render as accent `◌`, done
54 54 tasks as success `✓`, idle widgets as warning, and errors as error
55 + - Block unresolved `__LEAK_*__` placeholders in mutating tool calls outside the
extensions/leaks/__tests__/pi-direct.test.ts Modified 154 154 view.notices.
some ((notice)
=> notice.
includes (
"usage: /leaks" )),
158 + it (
"blocks unresolved leak placeholders in mutating tools outside leaks" ,
async ()
=> {
159 + const runtime
= fakePi ();
160 + leaks (runtime.pi
as never );
162 + const placeholder
= "__LEAK_TOKEN_abcdef123456__" ;
163 + const hook
= runtime.handlers.
get (
"tool_call" );
164 + if (
! hook)
throw new Error (
"missing tool_call hook" );
166 + const writeResult
= await hook (
170 + toolCallId:
"write-2" ,
171 + input: { path:
"README.md" , content: placeholder },
175 + expect (writeResult).
toEqual ({
178 + "Blocked: unresolved `__LEAK_*__` placeholder in write target outside `pi-ext/extensions/leaks/`. Ask user for real value, restore from source, or remove placeholder." ,
181 + const editResult
= await hook (
185 + toolCallId:
"edit-1" ,
188 + edits: [{ oldText:
"old" , newText: placeholder }],
193 + expect (editResult).
toMatchObject ({ block:
true });
195 + const oldTextOnly
= await hook (
199 + toolCallId:
"edit-2" ,
202 + edits: [{ oldText: placeholder, newText:
"clean" }],
207 + expect (oldTextOnly).
toBeUndefined ();
209 + const bashResult
= await hook (
213 + toolCallId:
"bash-1" ,
214 + input: { command:
`printf %s ${placeholder}` },
218 + expect (bashResult).
toMatchObject ({ block:
true });
221 + it (
"allows unresolved leak placeholders inside the leaks extension" ,
async ()
=> {
222 + const runtime
= fakePi ();
223 + leaks (runtime.pi
as never );
224 + const placeholder
= "__LEAK_TOKEN_abcdef123456__" ;
225 + const root
= path.
resolve (
import .
meta .dirname,
".." );
226 + const hook
= runtime.handlers.
get (
"tool_call" );
227 + if (
! hook)
throw new Error (
"missing tool_call hook" );
234 + toolCallId:
"write-1" ,
235 + input: { path: path.
join (
root ,
"README.md" ), content: placeholder },
239 + ).resolves.
toBeUndefined ();
245 + toolCallId:
"bash-1" ,
246 + input: { command:
`printf %s ${placeholder}` },
248 + {
... ui ().ctx, cwd:
root },
250 + ).resolves.
toBeUndefined ();
extensions/leaks/src/pi.ts Modified 47 47 restoreEventProperty (engine,
event as Record <
string ,
unknown >,
"message" );
50 - pi.
on (
"tool_call" ,
async (event)
=> {
50 + pi.
on (
"tool_call" ,
async (event, ctx)
=> {
51 51 restoreEventProperty (engine,
event as Record <
string ,
unknown >,
"input" );
52 + return blockUnresolvedPlaceholderToolCall (
event , ctx.cwd);
54 55 pi.
on (
"tool_execution_start" ,
async (event)
=> {
126 127 Object .
assign (target, source);
130 + const LEAK_PLACEHOLDER_RE
= /__LEAK_[A-Za-z0-9_] * __/ ;
131 + const LEAKS_EXTENSION_ROOT
= path.
resolve (
import .
meta .dirname,
".." );
132 + const BLOCK_REASON_SUFFIX
= 133 + "outside `pi-ext/extensions/leaks/`. Ask user for real value, restore from source, or remove placeholder." ;
135 + function blockUnresolvedPlaceholderToolCall (
138 + )
: { block
: true ; reason
: string }
| undefined {
139 + if (
! isPlainObject (
event ))
return undefined ;
140 + const toolName
= event .toolName;
141 + const input
= event .
input ;
142 + if (
! isPlainObject (input))
return undefined ;
144 + if (toolName
=== "bash" ) {
145 + if (
containsLeakPlaceholder (input.command)
&& ! isInLeaksExtension (cwd))
146 + return blockPlaceholder (
"bash command" );
150 + if (toolName
=== "write" ) {
152 + containsLeakPlaceholder (input.
content )
&& 153 + ! isPathInLeaksExtension (cwd, input.path)
155 + return blockPlaceholder (
"write target" );
159 + if (toolName
=== "edit" ) {
160 + if (
isPathInLeaksExtension (cwd, input.path))
return undefined ;
161 + if (
! Array .
isArray (input.edits))
return undefined ;
162 + if (input.edits.
some ((edit)
=> containsEditWritePlaceholder (edit)))
163 + return blockPlaceholder (
"edit target" );
169 + function containsEditWritePlaceholder (edit
: unknown ) {
170 + return isPlainObject (edit)
&& containsLeakPlaceholder (edit.newText);
173 + function containsLeakPlaceholder (value
: unknown ) {
174 + return typeof value
=== "string" && LEAK_PLACEHOLDER_RE.
test (value);
177 + function blockPlaceholder (target
: string ) {
180 + reason:
`Blocked: unresolved \`__LEAK_*__\` placeholder in ${target} ${BLOCK_REASON_SUFFIX}` ,
184 + function isPathInLeaksExtension (cwd
: string , file
: unknown ) {
185 + if (
typeof file
!== "string" )
return false ;
186 + return isInLeaksExtension (path.
resolve (cwd, file));
189 + function isInLeaksExtension (candidate
: string ) {
190 + const relative
= path.
relative (LEAKS_EXTENSION_ROOT, path.
resolve (candidate));
193 + (
! relative.
startsWith (
".." )
&& ! path.
isAbsolute (relative))
129 197 function readSettings (cwd
: string ) {
130 198 const file
= path.
join (cwd,
".pi" ,
"settings.json" );
131 199 if (
! existsSync (file))
return { regex: [] };