pi-ext bugabingas pi extensions
owned by admin
README Source History Refs Compare Notes Search Registered lightweight The System command/governance proxies and deferred parser implementation; import fell 91% Win32 and 84% WSL with all checks passing 26984a5d6bef599b53ccc1ead244ea30b3a9e109
Oliver Krylow <o.krylow@isp-insoft.de > · 24 Aug 2026
SSH signature · not checked
Browse files Compare with HEAD
Result: {"status":"keep","the_system_import_ms":91,"elapsed_s":175.2,"win32_start_reload_ms":9221.157,"win32_extension_tax_ms":5072.027,"win32_startup_ms":6842.446,"win32_reload_ms":2378.711,"wsl_start_reload_ms":1886.281,"wsl_extension_tax_ms":945.895,"wsl_the_system_import_ms":29}
Changed files (4) extensions/the-system/index.ts Modified 1 - import type { ExtensionAPI }
from "@earendil-works/pi-coding-agent" ;
3 + type ExtensionContext,
5 + }
from "@earendil-works/pi-coding-agent" ;
2 6 import { createMockupTool }
from "./mockup.js" ;
3 - import { registerSystemGovernance }
from "./system.js" ;
4 - import { createSystemCommand }
from "./system-command.js" ;
7 + import { systemArgumentCompletions }
from "./system-command-meta.js" ;
9 + function isStaleContextError (error
: unknown )
: boolean {
11 + error
instanceof Error && 12 + error.message.
includes (
"ctx is stale after session replacement or reload" )
6 16 export default function registerTheSystem (pi
: ExtensionAPI )
: void {
7 - registerSystemGovernance (pi);
18 + let notified
= false ;
20 + const notifyOnce = async (ctx
: ExtensionContext , ticket
: number )
=> {
21 + if (notified
|| ticket
!== generation)
return ;
23 + const { runtimeNotice }
= await import (
"./system.js" );
24 + if (notified
|| ticket
!== generation)
return ;
25 + const message
= runtimeNotice (ctx.cwd);
26 + if (
! message)
return ;
27 + if (ctx.hasUI) ctx.ui.
notify (message,
"warning" );
30 + if (
! isStaleContextError (error))
throw error;
34 + pi.
on (
"session_start" , (_event, ctx)
=> {
35 + const ticket
= ++ generation;
37 + const timer
= setTimeout (()
=> {
38 + if (ticket
=== generation)
39 + void notifyOnce (ctx, ticket).
catch ((error)
=> 40 + console .
error (
"The System startup check failed:" , error),
45 + pi.
on (
"session_shutdown" , ()
=> {
49 + pi.
on (
"before_agent_start" ,
async (event, ctx)
=> {
50 + await notifyOnce (ctx, generation);
51 + const { composeSystemPrompt }
= await import (
"./system.js" );
52 + return { systemPrompt:
composeSystemPrompt (ctx.cwd,
event .systemPrompt) };
54 + pi.
on (
"tool_call" ,
async (event, ctx)
=> {
56 + ! isToolCallEventType (
"write" ,
event )
&& 57 + ! isToolCallEventType (
"edit" ,
event )
60 + const { preflightFileMutation }
= await import (
"./system.js" );
63 + select : (title
: string , items
: string [])
=> ctx.ui.
select (title, items),
65 + if (
isToolCallEventType (
"write" ,
event ))
66 + return preflightFileMutation (ctx.cwd,
"write" ,
event .
input , ui);
67 + if (
isToolCallEventType (
"edit" ,
event ))
68 + return preflightFileMutation (ctx.cwd,
"edit" ,
event .
input , ui);
8 71 pi.
registerTool (
createMockupTool ());
9 - pi.
registerCommand (
"system" ,
createSystemCommand (pi));
72 + pi.
registerCommand (
"system" , {
73 + description:
"The System project governance" ,
74 + getArgumentCompletions: systemArgumentCompletions,
75 + handler :
async (args, ctx)
=> {
76 + const { createSystemCommand }
= await import (
"./system-command.js" );
77 + await createSystemCommand (pi).
handler (args, ctx);
extensions/the-system/system-command-meta.ts Added new file mode 100644 1 + import type { AutocompleteItem }
from "@earendil-works/pi-tui" ;
3 + export const SYSTEM_SUBCOMMANDS
= [
18 + export function systemArgumentCompletions (
20 + )
: AutocompleteItem []
| null {
21 + if (prefix.
includes (
" " ))
return null ;
22 + if (SYSTEM_SUBCOMMANDS.
some ((item)
=> item
=== prefix))
return null ;
23 + const items
= SYSTEM_SUBCOMMANDS.
filter ((item)
=> item.
startsWith (prefix)).
map (
24 + (item)
=> ({ value: item, label: item }),
26 + return items.
length ? items
: null ;
extensions/the-system/system-command.ts Modified 6 6 ExtensionCommandContext,
8 8 } from
"@earendil-works/pi-coding-agent" ;
9 - import type { AutocompleteItem }
from "@earendil-works/pi-tui" ;
11 9 import { runDoctor }
from "./doctor.ts" ;
20 18 import { applyInitialization, inspectInitialization }
from "./init.ts" ;
21 19 import { openHtmlFile }
from "./open-browser.ts" ;
22 20 import { openEditableFile }
from "./open-editor.ts" ;
21 + import { systemArgumentCompletions }
from "./system-command-meta.ts" ;
23 22 import { systemPromptFor }
from "./system-prompts.ts" ;
25 24 const LIFECYCLE
= new Set ([
34 33 const NON_LIFECYCLE
= new Set ([
"init" ,
"doctor" ,
"view" ,
"book" ,
"edit" ]);
35 - const SUBCOMMANDS
= [
50 34 type CommandOptions = Omit <
RegisteredCommand ,
"name" | "sourceInfo" >;
52 36 export function createSystemCommand (pi
: ExtensionAPI )
: CommandOptions {
54 38 description:
"The System project governance" ,
55 - getArgumentCompletions (prefix
: string )
: AutocompleteItem []
| null {
56 - if (prefix.
includes (
" " ))
return null ;
57 - if (SUBCOMMANDS.
some ((item)
=> item
=== prefix))
return null ;
58 - const items
= SUBCOMMANDS.
filter ((item)
=> item.
startsWith (prefix)).
map (
59 - (item)
=> ({ value: item, label: item }),
61 - return items.
length ? items
: null ;
39 + getArgumentCompletions: systemArgumentCompletions,
63 40 handler :
async (args
: string , ctx
: ExtensionCommandContext )
=> {
64 41 const parsed
= parseSystemArgs (args);
65 42 if (
! parsed.subcommand) {
extensions/the-system/system.ts Modified 2 2 import { existsSync, lstatSync, readFileSync }
from "node:fs" ;
3 3 import path
from "node:path" ;
9 7 }
from "@earendil-works/pi-coding-agent" ;
10 - import { isToolCallEventType }
from "@earendil-works/pi-coding-agent" ;
13 10 type DocumentMetadata,
417 - export function registerSystemGovernance (pi
: ExtensionAPI )
: void {
418 - let notified
= false ;
419 - const notifyOnce = (_event
: unknown , ctx
: ExtensionContext )
=> {
420 - if (notified
|| ! ctx.hasUI)
return ;
421 - const message
= runtimeNotice (ctx.cwd);
422 - if (
! message)
return ;
423 - ctx.ui.
notify (message,
"warning" );
426 - pi.
on (
"session_start" ,
async (event, ctx)
=> {
428 - notifyOnce (
event , ctx);
430 - pi.
on (
"before_agent_start" ,
async (event, ctx)
=> {
431 - notifyOnce (
event , ctx);
432 - return { systemPrompt:
composeSystemPrompt (ctx.cwd,
event .systemPrompt) };
434 - pi.
on (
"tool_call" ,
async (event, ctx)
=> {
435 - const ui
: GovernanceUI = {
437 - select : (title, items)
=> ctx.ui.
select (title, items),
439 - if (
isToolCallEventType (
"write" ,
event ))
440 - return preflightFileMutation (ctx.cwd,
"write" ,
event .
input , ui);
441 - if (
isToolCallEventType (
"edit" ,
event ))
442 - return preflightFileMutation (ctx.cwd,
"edit" ,
event .
input , ui);