pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Reviews Compare Notes Search Review guide fix: harden extension text and aux LLM calls
c560492dbf18e4ea5ca3b153fc9c5c094f14a18e
Oliver Jan Krylow <oliver@bugabinga.net > · 25 May 2026
unsigned
Browse files Compare with HEAD
Changed files (7) Diff layout Auto Unified Split
extensions/angel/index.ts Modified +1 / −1 text lines
387 387 systemPrompt : SYSTEM_PROMPT, systemPrompt : SYSTEM_PROMPT,388 388 messages : [{ role: "user" , content: [{ type: "text" , text: JSON .stringify (packet, null , 2 ) }], timestamp: Date .now () }], messages : [{ role: "user" , content: [{ type: "text" , text: JSON .stringify (packet, null , 2 ) }], timestamp: Date .now () }],390 - { apiKey : auth.apiKey, headers : auth.headers , signal },390 + { apiKey : auth.apiKey, headers : auth.headers , signal, cacheRetention : " none " },392 392 const raw = res.content const raw = res.content 393 393 .filter ((c): c is { type: "text" ; text: string } => c.type === "text" ) .filter ((c): c is { type: "text" ; text: string } => c.type === "text" )extensions/devil/index.ts Modified +1 / −1 text lines
599 599 systemPrompt : SYNTHESIS_SYSTEM_PROMPT, systemPrompt : SYNTHESIS_SYSTEM_PROMPT,600 600 messages : [{ role: "user" , content: [{ type: "text" , text: synthesisUserText }], timestamp: Date .now () }], messages : [{ role: "user" , content: [{ type: "text" , text: synthesisUserText }], timestamp: Date .now () }],602 - { apiKey, headers, signal : timeoutSignal, reasoning : thinkingLevel },602 + { apiKey, headers, signal : timeoutSignal, reasoning : thinkingLevel, cacheRetention : " none " },605 605 if (synthesisResponse.stopReason === "error" ) { if (synthesisResponse.stopReason === "error" ) {extensions/ghost/overlay.ts Modified +10 / −4 text lines
43 43 type ToolUpdateEvent = Extract <AgentSessionEvent , { type: "tool_execution_update" }>;type ToolUpdateEvent = Extract <AgentSessionEvent , { type: "tool_execution_update" }>;44 44 type ToolEndEvent = Extract <AgentSessionEvent , { type: "tool_execution_end" }>;type ToolEndEvent = Extract <AgentSessionEvent , { type: "tool_execution_end" }>;
46 + function safeDisplayText (text: string ): string {48 + .replace (/\x1B(?:[@-Z\\-_] | \[[0-?] * [ -/] * [@-~] | \][ ^ \x07] * (?:\x07 | \x1B\\))/ g , "" )49 + .replace (/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/ g , " " )46 53 interface GhostOverlayLayout {interface GhostOverlayLayout {47 54 innerWidth: number ; innerWidth: number ;48 55 frameHeight: number ; frameHeight: number ;551 558 export function extractMessageText (message: { content: unknown }): string {export function extractMessageText (message: { content: unknown }): string {552 - if (typeof message.content === "string" ) return message.content . trim ( );559 + if (typeof message.content === "string" ) return safeDisplayText ( message.content );553 560 if (! Array .isArray (message.content )) return "" ; if (! Array .isArray (message.content )) return "" ;555 - return message.content 562 + return safeDisplayText ( message.content 556 563 .filter ((part): part is { type: "text" ; text: string } => .filter ((part): part is { type: "text" ; text: string } => 557 564 typeof part === "object" && typeof part === "object" && 558 565 part !== null && part !== null && 560 567 typeof (part as { text?: unknown }).text === "string" typeof (part as { text?: unknown }).text === "string" 562 569 .map ((part) => part.text ) .map ((part) => part.text )567 573 export function formatGhostCwd (cwd: string ): string {export function formatGhostCwd (cwd: string ): string {extensions/pulse/index.ts Modified +1 / −1 text lines
253 + { apiKey, cacheRetention : "none" },256 256 lastResponse = textFromResponse (response); lastResponse = textFromResponse (response);extensions/q/extract.ts Modified +13 / −5 text lines
8 8 const SUGGESTION_RE = / ^ \s * (?:[-*+]\s +| \d + [.)]\s +| [A-Za-z][.)]\s +| (?:Option | Answer | Choice)\s + [A-Za-z0-9] + \s * [:.)-]\s * )(. +? )\s *$ / i ;const SUGGESTION_RE = / ^ \s * (?:[-*+]\s +| \d + [.)]\s +| [A-Za-z][.)]\s +| (?:Option | Answer | Choice)\s + [A-Za-z0-9] + \s * [:.)-]\s * )(. +? )\s *$ / i ;9 9 const QUESTION_WORD_RE = / ^ (?:should | do | does | did | can | could | would | will | which | what | when | where | why | how) \b / i ;const QUESTION_WORD_RE = / ^ (?:should | do | does | did | can | could | would | will | which | what | when | where | why | how) \b / i ;
11 + function safeDisplayText (text: string ): string {13 + .replace (/\x1B(?:[@-Z\\-_] | \[[0-?] * [ -/] * [@-~] | \][ ^ \x07] * (?:\x07 | \x1B\\))/ g , "" )14 + .replace (/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/ g , " " )15 + .replace (/\s + / g , " " )11 19 export const EXTRACTOR_PROMPT = `Extract questions and predefined answer suggestions from the assistant message. export const EXTRACTOR_PROMPT = `Extract questions and predefined answer suggestions from the assistant message. 13 21 Return ONLY JSON with this shape: Return ONLY JSON with this shape: 74 82 export function cleanQuestion (line: string ): string {export function cleanQuestion (line: string ): string {75 - return line.replace (QUESTION_PREFIX_RE, "" ).replace (QUESTION_LABEL_RE, "" ). trim ( );83 + return safeDisplayText ( line.replace (QUESTION_PREFIX_RE, "" ).replace (QUESTION_LABEL_RE, "" ));78 86 export function cleanSuggestion (line: string ): string | undefined {export function cleanSuggestion (line: string ): string | undefined {79 - const suggestion = line.match (SUGGESTION_RE)?.[1 ]?.trim ().replace (/ ^ "(. + )" $ / , "$1" );87 + const suggestion = safeDisplayText ( line.match (SUGGESTION_RE)?.[1 ]?.trim ().replace (/ ^ "(. + )" $ / , "$1" ) ?? " " ) ;80 88 return suggestion || undefined ; return suggestion || undefined ;116 124 const parsed = JSON .parse (json) as { questions?: Array <{ question?: unknown ; suggestions?: unknown }> }; const parsed = JSON .parse (json) as { questions?: Array <{ question?: unknown ; suggestions?: unknown }> };117 125 return (parsed.questions ?? []) return (parsed.questions ?? [])118 126 .map ((q) => ({ .map ((q) => ({119 - question: typeof q.question === "string" ? q.question. trim ( ) : "" ,127 + question: typeof q.question === "string" ? safeDisplayText ( q.question) : "" ,120 128 suggestions: Array .isArray (q.suggestions) suggestions: Array .isArray (q.suggestions)121 - ? unique (q.suggestions.filter ((s): s is string => typeof s === "string" ).map (( s ) => s . trim ( ) ).filter (Boolean )).slice (0 , MAX_SUGGESTIONS)129 + ? unique (q.suggestions.filter ((s): s is string => typeof s === "string" ).map (safeDisplayText ).filter (Boolean )).slice (0 , MAX_SUGGESTIONS)124 132 .filter ((q) => q.question.length > 0 ); .filter ((q) => q.question.length > 0 );133 141 const response = await complete ( const response = await complete (134 142 ctx.model, ctx.model,135 143 { systemPrompt: EXTRACTOR_PROMPT, messages: [userMessage] }, { systemPrompt: EXTRACTOR_PROMPT, messages: [userMessage] },136 - { apiKey: auth.apiKey, headers: auth.headers , signal: ctx.signal, reasoning: "low" },144 + { apiKey: auth.apiKey, headers: auth.headers , signal: ctx.signal, reasoning: "low" , cacheRetention : " none " },138 146 const raw = response.content const raw = response.content 139 147 .filter ((c): c is { type: "text" ; text: string } => c.type === "text" ) .filter ((c): c is { type: "text" ; text: string } => c.type === "text" )extensions/session-rename/index.ts Modified +1 / −0 text lines
245 245 apiKey : auth.apiKey, apiKey : auth.apiKey,246 246 headers : auth.headers , headers : auth.headers ,
248 + cacheRetention : "none" ,248 249 ... (model.reasoning ? { reasoning: "minimal" as const } : {}), ... (model.reasoning ? { reasoning: "minimal" as const } : {}),extensions/web/index.ts Modified +21 / −10 text lines
402 402 return `⬇ ${mb}/${totalMb}MB (${percent}%)` ; return `⬇ ${mb}/${totalMb}MB (${percent}%)` ;
405 + function safeTerminalText (text: string ): string {407 + .replace (/\x1B(?:[@-Z\\-_] | \[[0-?] * [ -/] * [@-~] | \][ ^ \x07] * (?:\x07 | \x1B\\))/ g , "" )408 + .replace (/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/ g , " " );411 + function safeDisplayText (text: string ): string {412 + return safeTerminalText (text).replace (/[\t\r\n ] + / g , " " ).trim ();406 416 function expandedText (result: { content: Array <{ type: string ; text?: string }> }, prefix: string , theme: { fg : (style: string , text: string ) => string }): string | null {function expandedText (result: { content: Array <{ type: string ; text?: string }> }, prefix: string , theme: { fg : (style: string , text: string ) => string }): string | null {407 417 const content = result.content [0 ]; const content = result.content [0 ];408 418 if (content?.type !== "text" ) return null ; if (content?.type !== "text" ) return null ;409 419 let text = prefix; let text = prefix;410 - for (const line of content.text .split ("\n" )) {420 + for (const line of safeTerminalText ( content.text ) .split ("\n" )) {411 421 text += `\n${theme. fg ("dim", line)}` ; text += `\n${theme. fg ("dim", line)}` ;413 423 return text; return text;416 426 function hintBox (theme: { fg : (style: string , text: string ) => string }, style: "warning" | "error" , msg: string ): Text {function hintBox (theme: { fg : (style: string , text: string ) => string }, style: "warning" | "error" , msg: string ): Text {417 - return new Text (theme.fg (style, msg), 0 , 0 );427 + return new Text (theme.fg (style, safeDisplayText ( msg)) , 0 , 0 );496 506 renderCall (args, theme) { renderCall (args, theme) {497 507 let text = theme.fg ("toolTitle" , theme.bold ("\u2B07 web_fetch " )); let text = theme.fg ("toolTitle" , theme.bold ("\u2B07 web_fetch " ));498 - text += theme.fg ("accent" , args.url);508 + text += theme.fg ("accent" , safeDisplayText ( args.url)) ;499 509 return new Text (text, 0 , 0 ); return new Text (text, 0 , 0 );523 533 if (result.isError || details?.kind === "error" ) { if (result.isError || details?.kind === "error" ) {524 534 const content = result.content [0 ]; const content = result.content [0 ];525 - const msg = (details?.error) || (content?.type === "text" ? content.text : "Fetch failed" );535 + const msg = safeDisplayText (( details?.error) || (content?.type === "text" ? content.text : "Fetch failed" )) ;526 536 return hintBox (theme, "error" , `\u2717 ${msg}` ); return hintBox (theme, "error" , `\u2717 ${msg}` );622 632 if (details?.preview) { if (details?.preview) {623 - const lines = details.preview.split ("\n" );633 + const lines = safeTerminalText ( details.preview) .split ("\n" );624 634 const maxLines = expanded ? lines.length : 30 ; const maxLines = expanded ? lines.length : 30 ;625 635 const shown = lines.slice (0 , maxLines).join ("\n" ); const shown = lines.slice (0 , maxLines).join ("\n" );626 636 const truncated = lines.length > maxLines; const truncated = lines.length > maxLines;759 769 renderCall (args, theme) { renderCall (args, theme) {760 770 let text = theme.fg ("toolTitle" , theme.bold ("\uD83D\uDD0D web_search " )); let text = theme.fg ("toolTitle" , theme.bold ("\uD83D\uDD0D web_search " ));761 - text += theme.fg ("accent" , `"${args.query}"` );771 + text += theme.fg ("accent" , `"${ safeDisplayText ( args.query) }"` );762 772 return new Text (text, 0 , 0 ); return new Text (text, 0 , 0 );783 793 if (results && results.length > 0 ) { if (results && results.length > 0 ) {784 794 const top = results.slice (0 , 5 ); const top = results.slice (0 , 5 );785 795 for (const r of top) { for (const r of top) {786 - text += `\n${theme. fg ("dim", "\u2022 " + r. title )}` ;796 + text += `\n${theme. fg ("dim", "\u2022 " + safeDisplayText ( r.title )) }` ;788 798 if (results.length > 5 ) { if (results.length > 5 ) {789 799 text += `\n${theme. fg ("muted", `... +${results. length - 5} more`)}` ; text += `\n${theme. fg ("muted", `... +${results. length - 5} more`)}` ;878 888 renderCall (args, theme) { renderCall (args, theme) {879 889 let text = theme.fg ("toolTitle" , theme.bold ("\uD83D\uDDBC understand_image " )); let text = theme.fg ("toolTitle" , theme.bold ("\uD83D\uDDBC understand_image " ));880 - const preview = args.prompt .length > 50 ? args.prompt .substring (0 , 50 ) + "..." : args.prompt ;890 + const safePrompt = safeDisplayText (args.prompt );891 + const preview = safePrompt.length > 50 ? safePrompt.substring (0 , 50 ) + "..." : safePrompt;881 892 text += theme.fg ("muted" , `"${preview}"` ); text += theme.fg ("muted" , `"${preview}"` );882 - text += " " + theme.fg ("dim" , args.image_source);893 + text += " " + theme.fg ("dim" , safeDisplayText ( args.image_source)) ;883 894 return new Text (text, 0 , 0 ); return new Text (text, 0 , 0 );901 912 const content = result.content [0 ]; const content = result.content [0 ];902 913 if (content?.type === "text" && content.text ) { if (content?.type === "text" && content.text ) {903 - text += `\n${theme. fg ("dim", content. text . substring (0, 100). replace ( / \n / g , " " ) + "...")}` ;914 + text += `\n${theme. fg ("dim", safeDisplayText ( content.text ) .substring (0, 100) + "...")}` ;905 916 text += ` ${theme. fg ("muted", `(${ keyHint ("expandTools", "to expand")})`)}` ; text += ` ${theme. fg ("muted", `(${ keyHint ("expandTools", "to expand")})`)}` ;