pi-fox 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -0
  4. package/index.ts +1934 -0
  5. package/package.json +41 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Changed
10
+ - `/web-switch` renamed to `/search` with expanded hub (switch, add, add-custom, remove, onboarding)
11
+ - Search provider management moved out of `/browser`; `/browser` now manages browser engine settings only (headless, supervised)
12
+ - `/search <provider-id>` for instant provider switching at runtime (e.g. `/search brave`)
13
+ - `fetch_content` now uses [Turndown](https://github.com/mixmark-io/turndown) for HTML→Markdown conversion (replaces regex tag stripping). Falls back to plain text strip if Turndown throws on malformed HTML.
14
+ - `/browser` command handlers extracted to named async functions: `runProviderSwitch`, `runProviderAdd`, `runProviderRemove`, `runCustomProviderWizard`, `runCollectProviderMeta`, `runCollectTransform`, `runTestTransform`, `saveCustomProvider`
15
+ - `PROVIDER_REGISTRY` changed from `const` to `let` — rebuilt at startup with custom providers appended
16
+ - `ProviderId` widened to `"brave" | "perplexity" | "tavily" | "exa" | "gemini" | (string & {})` to support dynamic custom provider IDs
17
+
18
+ ### Added
19
+ - Custom search provider wizard — add any search API via `/search` → "Add custom provider" without editing source code
20
+ - `buildCustomProviderImpl()` — wraps user-defined config into a `ProviderImpl`, slots into the existing registry, fallback chain, and `/search` automatically
21
+ - Full `async function(query, n, apiKey, fetchJson)` transform contract — handles both request building and response parsing in one user-written function
22
+ - Live raw→mapped test loop in wizard (Step 3): shows raw API JSON and mapped `SearchResult` side by side, flags missing fields before saving
23
+ - Pi agent snippet in transform step — copyable prompt for getting transform help from your pi agent
24
+ - `fetchJsonCapturing` helper — captures raw API response during wizard test without affecting production search paths
25
+ - `TRANSFORM_DRAFT_PATH` template file at `~/.pi/web-cache/custom-provider-draft.js` — editable in any editor or via pi agent
26
+ - Added (dev): `@types/turndown` — TypeScript types for Turndown
27
+ - `turndown` was already listed in `package.json` and is now actively used
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vanitea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ <div align="center">
2
+
3
+ <img src="https://raw.githubusercontent.com/vaniteav/pi-fox/main/docs/banner.png" alt="Pi-Fox banner" width="100%">
4
+
5
+ # pi-fox
6
+
7
+ > A fox doesn't knock on the door. It finds the gap in the fence, slips through, and comes back with exactly what you sent it for. Pi-Fox is that instinct for your agent — quiet, quick, and it always brings receipts.
8
+
9
+ [![npm version](https://badge.fury.io/js/pi-fox.svg)](https://badge.fury.io/js/pi-fox)
10
+ [![npm downloads](https://img.shields.io/npm/dw/pi-fox)](https://www.npmjs.com/package/pi-fox)
11
+
12
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/L2J320X82M)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ Pi-Fox gives your pi agent a full [Playwright](https://playwright.dev/) browser (Firefox by default, Chromium and WebKit supported) — no API key required. Navigate pages, click, type, screenshot, and extract clean readable text out of the box. For better agentic web search, drop in a key for any of four providers — Brave, Tavily, Exa, or Gemini — all with free tiers. Prefer a different one? Use the setup wizard to add it.
19
+
20
+ With supervised mode, every move is captured and saved to your local filesystem as a chronological audit trail. Run headless by default; flip it visible when you want to watch it work. Change any setting by asking your agent or editing a single JSON file.
21
+
22
+ Under the hood it's a single TypeScript extension: a `ProviderImpl` registry for search backends, `withSupervisedScreenshot` wrapping every browser action, and `fetchJson` for all API calls — no curl, no shell-outs.
23
+
24
+ ## Install
25
+
26
+ **Via npm (recommended):**
27
+ ```bash
28
+ pi install npm:pi-fox
29
+ ```
30
+
31
+ **Manual:**
32
+ ```bash
33
+ git clone https://github.com/vaniteav/pi-fox
34
+ cp -r pi-fox ~/.pi/agent/extensions/
35
+ npx playwright install firefox
36
+ ```
37
+
38
+ ## Setup
39
+
40
+ Load pi and run `/search` — the setup wizard will guide you through picking a search provider and storing your API key.
41
+
42
+ Search providers are optional. Browser automation works without any key configured.
43
+
44
+ ## Search providers
45
+
46
+ | Provider | Free tier | Notes |
47
+ |---|---|---|
48
+ | Brave Search | 2,000 queries/mo | [Get API key](https://api.search.brave.com/) |
49
+ | Tavily | 1,000 queries/mo | [Get API key](https://tavily.com/) |
50
+ | Exa | 2,500 queries/mo | [Get API key](https://exa.ai/) |
51
+ | Gemini | Free tier | [Get API key](https://aistudio.google.com/app/apikey) |
52
+
53
+ You only need one. The first key you configure becomes the active provider automatically. With multiple providers configured, use `/search <provider-id>` to switch instantly at runtime (e.g. `/search brave`).
54
+
55
+ ## Tools
56
+
57
+ ### Browser (15 tools)
58
+
59
+ | Tool | Description |
60
+ |---|---|
61
+ | `browser_navigate` | Navigate to a URL. |
62
+ | `browser_click` | Click an element by CSS selector, visible text, or ARIA role. |
63
+ | `browser_type` | Type into an input, textarea, or contenteditable element. |
64
+ | `browser_snapshot` | Get the accessibility tree of the current page — structure, roles, and states. |
65
+ | `browser_screenshot` | Take a screenshot, returned as a base64 PNG or JPEG. |
66
+ | `browser_evaluate` | Run arbitrary JavaScript in the page context and return the result. |
67
+ | `browser_wait` | Wait for an element to appear or disappear, or pause for a fixed timeout. |
68
+ | `browser_new_tab` | Open a new browser tab. |
69
+ | `browser_list_tabs` | List all open tabs with their index, URL, and title. |
70
+ | `browser_close_tab` | Close the current tab. |
71
+ | `browser_select_tab` | Switch focus to a tab by its index. |
72
+ | `browser_back` | Navigate back one step in browser history. |
73
+ | `browser_forward` | Navigate forward one step in browser history. |
74
+ | `browser_reload` | Reload the current page. |
75
+ | `browser_close` | Close the entire browser session and free resources. |
76
+
77
+ ### Web (4 tools)
78
+
79
+ | Tool | Description |
80
+ |---|---|
81
+ | `web_search` | Search the web via your configured provider; supports multi-query, recency filtering, and domain filtering. |
82
+ | `code_search` | Search for code examples, API docs, and Stack Overflow answers; uses Exa when available, falls back to `web_search`. |
83
+ | `fetch_content` | Fetch one or more URLs and extract clean readable text from the HTML. |
84
+ | `get_search_content` | Retrieve cached content from a previous search or fetch by response ID or URL. |
85
+
86
+ ## Commands
87
+
88
+ - `/browser` — Browser status and settings: engine, headless mode, supervised mode.
89
+ - `/search` — Search provider management: status, switch, add, remove, and onboarding wizard. Use `/search <provider-id>` to switch instantly at runtime (e.g. `/search brave`).
90
+
91
+ ## Supervised mode
92
+
93
+ Screenshots are saved to `~/Pictures/pi-fox/sessions/<timestamp>/` after every navigation, click, and interaction — a chronological record of everything your agent did in the browser. Supervised mode is **on by default**.
94
+
95
+ Once you trust the workflow, turn it off:
96
+
97
+ ```json
98
+ { "browserExt": { "supervised": false } }
99
+ ```
100
+
101
+ Or just ask your agent: *"turn off supervised mode."*
102
+
103
+ ## Configuration
104
+
105
+ Full example block in `~/.pi/agent/settings.json`:
106
+
107
+ ```json
108
+ {
109
+ "browserExt": {
110
+ "supervised": true,
111
+ "headless": true,
112
+ "suppressStartupMessage": false,
113
+ "activeProvider": "brave",
114
+ "BRAVE_API_KEY": "...",
115
+ "TAVILY_API_KEY": "...",
116
+ "EXA_API_KEY": "...",
117
+ "GEMINI_API_KEY": "..."
118
+ }
119
+ }
120
+ ```
121
+
122
+ You only need the key(s) for providers you want to use. All settings can also be changed by asking your agent — for example: *"switch to Exa for searches"* or *"run the browser in visible mode."*
123
+
124
+ ## Credits
125
+
126
+ - Browser automation powered by [Playwright](https://playwright.dev/) (Microsoft)
127
+ - Built for [pi coding agent](https://github.com/earendil-works/pi-coding-agent) by earendil-works
128
+
129
+ ## License
130
+
131
+ MIT