pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search fix web platform tool lookup f3b9d6fde4b2e9b08134b41fda3f607392bb6cfe
Oliver Krylow <o.krylow@isp-insoft.de > · 10 Jun 2026
unsigned
Browse files Compare with HEAD
Resolve platform tools through Node instead of Unix which.
Warn about missing required web tools and info-notify optional metadata tools.
Add fake PATH binary coverage for web_fetch conversion and spawn helpers.
Changed files (9) 42 42 escalate to a human.
43 43 Do not work around `mise` or add ad-hoc scripts.
45 + ##
Cross-platform Requirements 47 + Extensions must work on Windows, macOS, and Linux unless their README explicitly scopes them narrower.
48 + Do not rely on shell-specific helpers such as `which`, `bash`, `sed`, `grep`, or `/tmp` when Node APIs can do the job.
49 + If an extension uses platform tools, check their availability when the extension loads.
50 + Notify missing required tools with warning severity.
51 + Notify missing optional tools with info severity.
52 + Tests for platform-tool behavior must exercise the real extension/tool path with controlled fake binaries on `PATH`, not only mocked helpers.
47 56 Use one sentence per line for prose.
76 76 - Add `mise run clean` for generated caches and scratch artifacts, clearing
77 77 `.demo/` contents while keeping the directory and removing `node_modules`,
78 78 `__pycache__`, `.ruff_cache`, and `extensions/diff-review/static/`
79 + - Make web extension tool availability checks cross-platform without requiring
80 + Unix `which`, handle Windows `.cmd`/`.bat` shims with spaces, avoid stale
81 + negative PATH cache entries, notify missing required/optional tools at the
82 + right severity, and add coverage
extensions/llmiterate/README.md Modified 88 - "commentPrefixes" : {
87 + "commentPrefixes" : {
175 - "include" : [
"src/**/*.{ts,tsx,rs,java,md}" ,
"docs/**/*.md" ],
176 - "exclude" : [
"**/target/**" ,
"**/dist/**" ],
177 - "debounceMs" :
3000 ,
178 - "maxFileBytes" :
1000000 ,
179 - "timeoutMs" :
600000 ,
180 - "maxWatchDirs" :
10000 ,
181 - "notify" :
"errors" ,
182 - "commentPrefixes" : {
183 - "foo" : [
"COMMENT" ],
174 + "include" : [
"src/**/*.{ts,tsx,rs,java,md}" ,
"docs/**/*.md" ],
175 + "exclude" : [
"**/target/**" ,
"**/dist/**" ],
176 + "debounceMs" :
3000 ,
177 + "maxFileBytes" :
1000000 ,
178 + "timeoutMs" :
600000 ,
179 + "maxWatchDirs" :
10000 ,
180 + "notify" :
"errors" ,
181 + "commentPrefixes" : {
182 + "foo" : [
"COMMENT" ],
extensions/web/README.md Modified 60 60 HTML conversion; DOCX/ODT/EPUB/RTF extraction.
61 + Missing binary emits a warning notification on session start.
64 + Missing binary emits a warning notification on session start.
67 + Missing binary emits an info notification on session start.
65 68 Missing/failing binary returns fallback metadata text.
67 70 audio/video metadata.
71 + Missing binary emits an info notification on session start.
68 72 Missing/failing binary returns fallback metadata text.
70 74 Provider/env config read by source:
extensions/web/__tests__/spawn.test.ts Added new file mode 100644 1 + import { randomUUID }
from "node:crypto" ;
2 + import { mkdtemp, writeFile }
from "node:fs/promises" ;
3 + import { tmpdir }
from "node:os" ;
4 + import path
from "node:path" ;
5 + import { afterEach, describe, expect, it }
from "vitest" ;
6 + import { checkToolAvailability, spawnToText }
from "../spawn" ;
8 + const originalPath
= process .
env .PATH;
9 + const originalPathAlt
= process .
env .Path;
12 + if (originalPath
=== undefined )
delete process .
env .PATH;
13 + else process .
env .PATH
= originalPath;
14 + if (originalPathAlt
=== undefined )
delete process .
env .Path;
15 + else process .
env .Path
= originalPathAlt;
18 + async function makeFakeTool (dir
: string , name
: string ) {
19 + if (
process .
platform === "win32" ) {
20 + const toolPath
= path.
join (dir,
`${name}.cmd` );
21 + await writeFile (toolPath,
"@echo off\r\nexit /b 0\r\n" );
25 + const toolPath
= path.
join (dir, name);
26 + await writeFile (toolPath,
"#!/bin/sh\nexit 0\n" , { mode:
0o755 });
30 + describe (
"checkToolAvailability" , ()
=> {
31 + it (
"finds executables on PATH without requiring Unix which" ,
async ()
=> {
32 + const dir
= await mkdtemp (path.
join (
tmpdir (),
"pi-web-path-" ));
33 + const name
= `fake-tool-${ randomUUID ()}` ;
34 + await makeFakeTool (dir, name);
35 + process .
env .PATH
= dir;
37 + await expect (
checkToolAvailability (name,
"missing" )).resolves.
toBeNull ();
40 + it (
"does not keep stale negative cache entries after PATH changes" ,
async ()
=> {
41 + const dir
= await mkdtemp (path.
join (
tmpdir (),
"pi-web-path-" ));
42 + const emptyDir
= await mkdtemp (path.
join (
tmpdir (),
"pi-web-empty-path-" ));
43 + const name
= `fake-tool-${ randomUUID ()}` ;
45 + process .
env .PATH
= emptyDir;
46 + await expect (
checkToolAvailability (name,
"missing" )).resolves.
toBe (
50 + await makeFakeTool (dir, name);
51 + process .
env .PATH
= dir;
53 + await expect (
checkToolAvailability (name,
"missing" )).resolves.
toBeNull ();
56 + it (
"runs PATH-resolved tools without a shell-specific lookup utility" ,
async ()
=> {
57 + const dir
= await mkdtemp (path.
join (
tmpdir (),
"pi web path " ));
58 + const name
= `fake-tool-${ randomUUID ()}` ;
59 + await makeFakeTool (dir, name);
60 + process .
env .PATH
= dir;
62 + await expect (
spawnToText (name, [
"arg with spaces" ])).resolves.
toBe (
"" );
extensions/web/__tests__/web-fetch-contract.test.ts Modified 1 - import { mkdtemp, readFile }
from "node:fs/promises" ;
1 + import { mkdtemp, readFile, writeFile }
from "node:fs/promises" ;
2 2 import { tmpdir }
from "node:os" ;
3 3 import path
from "node:path" ;
4 4 import { afterEach, describe, expect, it, vi }
from "vitest" ;
21 21 const originalFetch
= globalThis.fetch;
23 + async function makeFakeCommand (
28 + if (
process .
platform === "win32" ) {
30 + path.
join (dir,
`${name}.cmd` ),
31 + `@echo off\r\necho ${stdout}\r\n` ,
36 + path.
join (dir, name),
37 + `#!/bin/sh\nprintf '%s\\n' '${stdout}'\n` ,
44 + function pathEnv (dir
: string )
: Record <
string ,
string > {
45 + return process .
platform === "win32" 46 + ? { PATH: dir, Path: dir, PATHEXT:
".COM;.EXE;.BAT;.CMD" }
23 50 describe (
"web_fetch context contract" , ()
=> {
24 51 let t
: TestSession | undefined ;
61 88 expect (saved.output).
toContain (
"x" .
repeat (
10_000 ));
91 + it (
"converts HTML with PATH-resolved pandoc and no Unix which" ,
async ()
=> {
92 + globalThis.fetch
= vi.
fn (
94 + new Response (
"<html><main><h1>Hello</h1></main></html>" , {
96 + headers: {
"content-type" :
"text/html" },
100 + const binDir
= await mkdtemp (path.
join (
tmpdir (),
"pi-web-bin-" ));
101 + await makeFakeCommand (binDir,
"pandoc" ,
"converted markdown" );
102 + const webPath
= path.
resolve (
import .
meta .dirname,
"../index.ts" );
103 + t
= await createTestSession ({
104 + extensions: [webPath],
105 + env:
pathEnv (binDir),
107 + const [extension]
= t.session.extensionRunner.extensions;
108 + const result
= await extension.tools
110 + .definition.
execute (
112 + { url:
"https://93.184.216.34/html" },
113 + new AbortController ().signal,
118 + expect (result.isError).not.
toBe (
true );
119 + expect (result.details.kind).
toBe (
"html" );
120 + expect (result.
content [
0 ].
text ).
toContain (
"converted markdown" );
123 + it (
"notifies missing required and optional platform tools on session start" ,
async ()
=> {
124 + const emptyDir
= await mkdtemp (path.
join (
tmpdir (),
"pi-web-empty-bin-" ));
125 + const webPath
= path.
resolve (
import .
meta .dirname,
"../index.ts" );
126 + t
= await createTestSession ({
127 + extensions: [webPath],
128 + env:
pathEnv (emptyDir),
130 + await new Promise ((resolve)
=> setTimeout (resolve,
0 ));
132 + const notify
= t.events.
uiCallsFor (
"notify" );
133 + expect (notify.
map ((call)
=> call.args)).
toEqual (
134 + expect.
arrayContaining ([
135 + expect.
arrayContaining ([expect.
stringContaining (
"pandoc" ),
"warning" ]),
136 + expect.
arrayContaining ([
137 + expect.
stringContaining (
"pdftotext" ),
140 + expect.
arrayContaining ([expect.
stringContaining (
"identify" ),
"info" ]),
141 + expect.
arrayContaining ([expect.
stringContaining (
"ffprobe" ),
"info" ]),
64 146 it (
"line matching returns excerpts instead of full page" ,
async ()
=> {
65 147 globalThis.fetch
= vi.
fn (
extensions/web/index.ts Modified 402 + const PLATFORM_TOOL_DEPENDENCIES
= [
405 + hint: TOOL_HINTS.pandoc,
406 + level:
"warning" as const ,
407 + purpose:
"HTML and Office document conversion unavailable" ,
411 + hint: TOOL_HINTS.pdftotext,
412 + level:
"warning" as const ,
413 + purpose:
"PDF extraction unavailable" ,
417 + hint: TOOL_HINTS.identify,
418 + level:
"info" as const ,
419 + purpose:
"image metadata will use fallback text" ,
423 + hint: TOOL_HINTS.ffprobe,
424 + level:
"info" as const ,
425 + purpose:
"audio/video metadata will use fallback text" ,
429 + async function notifyMissingPlatformTools (
430 + ctx
: ExtensionContext ,
432 + if (
! ctx.hasUI)
return ;
433 + for (
const dep
of PLATFORM_TOOL_DEPENDENCIES) {
434 + const hint
= await checkToolAvailability (dep.cmd, dep.hint);
435 + if (hint) ctx.ui.
notify (
`web: ${dep.purpose}. ${hint}` , dep.level);
402 439 async function processBinary (
404 441 contentType
: string ,
722 759 const spotlightMarkers
: SpotlightMarkers = createMarkers ();
761 + pi.
on (
"session_start" ,
async (_event, ctx)
=> {
762 + await notifyMissingPlatformTools (ctx);
726 767 pi.
on (
"session_shutdown" ,
async ()
=> {
extensions/web/pandoc.ts Modified 6 - import { spawn }
from "node:child_process" ;
7 6 import { dirname, join }
from "node:path" ;
8 7 import { fileURLToPath }
from "node:url" ;
9 8 import { spawnToText }
from "./spawn.js" ;
46 - export function runPandoc (
45 + export async function runPandoc (
50 49 )
: Promise <
string > {
51 - return new Promise ((resolve, reject)
=> {
59 - : "markdown-raw_html" ;
57 + : "markdown-raw_html" ;
61 - const args
= [
"--from=html" ,
"--to=" + toFormat,
"--wrap=none" ];
59 + const args
= [
"--from=html" ,
"--to=" + toFormat,
"--wrap=none" ];
64 - args.
push (
"--lua-filter=" + LUA_FILTER);
62 + args.
push (
"--lua-filter=" + LUA_FILTER);
67 - const proc
= spawn (
"pandoc" , args);
72 - proc.stdout.
on (
"data" , (d
: Buffer )
=> (stdout
+= d));
73 - proc.stderr.
on (
"data" , (d
: Buffer )
=> (stderr
+= d));
74 - proc.
on (
"close" , (code)
=> {
77 - format
=== "html" || format
=== "json" 79 - : stripResidualTags (stdout),
82 - reject (
new Error (stderr
|| `pandoc: ${code}` ));
85 - proc.
on (
"error" , reject);
87 - proc.stdin.
write (
cleanTableClasses (html));
65 + const stdout
= await spawnToText (
"pandoc" , args,
cleanTableClasses (html));
66 + return format
=== "html" || format
=== "json" 68 + : stripResidualTags (stdout);
extensions/web/spawn.ts Modified 3 3 import { spawn }
from "node:child_process" ;
4 + import { constants }
from "node:fs" ;
5 + import { access }
from "node:fs/promises" ;
6 + import { basename, delimiter, dirname, extname, join }
from "node:path" ;
5 - export function spawnToText (
8 + export async function spawnToText (
9 12 )
: Promise <
string > {
13 + const resolved
= (
await resolveCommand (cmd))
?? cmd;
14 + const spawnArgs
= commandArgs (resolved, args);
10 15 return new Promise ((resolve, reject)
=> {
11 - const proc
= spawn (cmd, args);
16 + const proc
= spawn (spawnArgs.command, spawnArgs.args, {
18 + ... spawnArgs.
options ,
22 + let settled
= false ;
23 + const fail = (err
: Error )
=> {
24 + if (settled)
return ;
14 28 proc.stdout.
on (
"data" , (d
: Buffer )
=> (stdout
+= d));
15 29 proc.stderr.
on (
"data" , (d
: Buffer )
=> (stderr
+= d));
16 30 proc.
on (
"close" , (code)
=> {
31 + if (settled)
return ;
17 33 if (code
=== 0 )
resolve (stdout);
18 34 else reject (
new Error (stderr
|| `${cmd}: ${code}` ));
20 - proc.
on (
"error" , reject);
36 + proc.
on (
"error" , fail);
21 37 if (input
!== undefined ) {
22 38 proc.stdin.
write (input);
29 45 * Check
if a command is available on PATH.
30 46 * Returns
null if available, or an install hint string
if not.
32 - const availableCommands
= new Map <
string ,
string | null >();
48 + const availableCommands
= new Set <
string >();
50 + function pathEnv ()
: string {
51 + const key
= Object .
keys (
process .
env ).
find ((k)
=> k.
toLowerCase ()
=== "path" );
52 + return key
? (
process .
env [key]
?? "" )
: "" ;
55 + function stripPathQuotes (dir
: string )
: string {
56 + return dir.
length >= 2 && dir.
startsWith (
'"' )
&& dir.
endsWith (
'"' )
61 + function pathextEnv ()
: string [] {
62 + if (
process .
platform !== "win32" )
return [
"" ];
63 + const raw
= process .
env .PATHEXT
|| ".COM;.EXE;.BAT;.CMD" ;
66 + .
map ((ext)
=> ext.
trim ())
70 + function candidateNames (cmd
: string )
: string [] {
71 + if (
process .
platform !== "win32" || extname (cmd))
return [cmd];
74 + ... pathextEnv ().
flatMap ((ext)
=> [cmd
+ ext, cmd
+ ext.
toLowerCase ()]),
78 + async function isExecutable (filePath
: string )
: Promise <
boolean > {
82 + process .
platform === "win32" ? constants.F_OK
: constants.X_OK,
90 + export async function resolveCommand (cmd
: string )
: Promise <
string | null > {
91 + const hasPathSeparator
= cmd.
includes (
"/" )
|| cmd.
includes (
"\\" );
92 + if (hasPathSeparator) {
93 + const dir
= dirname (cmd);
94 + for (
const name
of candidateNames (
basename (cmd))) {
95 + const candidate
= join (dir, name);
96 + if (
await isExecutable (candidate))
return candidate;
101 + const names
= candidateNames (cmd);
102 + for (
const rawDir
of pathEnv ().
split (delimiter).
filter (
Boolean )) {
103 + const dir
= stripPathQuotes (rawDir);
104 + for (
const name
of names) {
105 + const candidate
= join (dir, name);
106 + if (
await isExecutable (candidate))
return candidate;
112 + function commandArgs (
118 + options
?: { windowsVerbatimArguments
: boolean };
120 + if (
process .
platform === "win32" && /\.(?:cmd | bat) $ / i .
test (resolved)) {
122 + command:
process .
env .ComSpec
|| process .
env .COMSPEC
|| "cmd.exe" ,
127 + `"${[ quoteCmdArg (resolved), ... args. map (quoteCmdArg)]. join (" ")}"` ,
129 + options: { windowsVerbatimArguments:
true },
132 + return { command: resolved, args };
135 + function quoteCmdArg (arg
: string )
: string {
136 + return `"${arg. replace (/"/ g , '""')}"` ;
34 139 export async function checkToolAvailability (
36 141 installHint
: string ,
37 142 )
: Promise <
string | null > {
38 - const cached
= availableCommands.
get (cmd);
39 - if (cached
!== undefined )
return cached;
143 + const cacheKey
= `${cmd}\0${ pathEnv ()}\0${ process . env .PATHEXT ?? ""}` ;
144 + if (availableCommands.
has (cacheKey))
return null ;
42 - await spawnToText (
"which" , [cmd]);
43 - availableCommands.
set (cmd,
null );
146 + if (
await resolveCommand (cmd)) {
147 + availableCommands.
add (cacheKey);
46 - availableCommands.
set (cmd, installHint);
150 + return installHint;