@pi-lab/webfetch 0.1.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 anthod0
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @pi-lab/webfetch
2
2
 
3
- A web fetching extension for [pi coding agent](https://github.com/badlogic/pi-mono). Adds a `webfetch` tool — fetch any URL and get back clean Markdown, ready for the model to read.
3
+ A web fetching extension for [pi coding agent](https://github.com/earendil-works/pi). Adds a `webfetch` tool — fetch any URL and get back clean Markdown, ready for the model to read.
4
4
 
5
5
  ## Install
6
6
 
@@ -14,5 +14,5 @@ pi install npm:@pi-lab/webfetch
14
14
  - **Pagination** — large pages are sliced into chunks; the model reads page by page using `offset`.
15
15
  - **Inline script index** — `<script>` tags are stripped from the Markdown body but listed as a numbered index at the end. The model can read any of them with `script=N`.
16
16
  - **Redirect handling** — same-domain redirects are followed automatically (up to 10 hops); cross-domain redirects are surfaced to the model so it can decide whether to follow.
17
- - **Binary downloads** — non-text responses (PDFs, images, etc.) are saved to `.pi/pi-lab/webfetch/tmp/` and the file path is returned.
18
- - **LRU cache** — processed Markdown is cached in memory (default: 50 MB, 15 min TTL) so paginating the same URL doesn't re-fetch.
17
+ - **Binary downloads** — non-text responses (PDFs, images, etc.) are saved to `~/.pi/agent/pi-lab/tmp/webfetch/` and the file path is returned.
18
+ - **LRU cache** — processed Markdown is cached in memory so paginating the same URL doesn't re-fetch.
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Type } from "@sinclair/typebox";
2
- import { join } from "node:path";
3
- import { keyHint } from "@mariozechner/pi-coding-agent";
4
- import { Text } from "@mariozechner/pi-tui";
2
+ import { keyHint } from "@earendil-works/pi-coding-agent";
3
+ import { Text } from "@earendil-works/pi-tui";
5
4
  import { LRUCache } from "lru-cache";
6
5
  import { mkdir, writeFile } from "node:fs/promises";
6
+ import { join } from "node:path";
7
7
  import { Readability } from "@mozilla/readability";
8
8
  import { parseHTML } from "linkedom";
9
9
  import TurndownService from "turndown";
10
+ import { homedir } from "node:os";
10
11
  //#region src/config.ts
11
12
  const DEFAULT_CONFIG = {
12
13
  maxPageLength: 2e4,
@@ -233,6 +234,20 @@ function processPlainText(text) {
233
234
  return text;
234
235
  }
235
236
  //#endregion
237
+ //#region ../utils/src/paths.ts
238
+ function getPiLabGlobalDir(home = homedir()) {
239
+ return join(home, ".pi", "agent", "pi-lab");
240
+ }
241
+ function getPiLabGlobalTmpDir(name, home = homedir()) {
242
+ const tmpDir = join(getPiLabGlobalDir(home), "tmp");
243
+ return name ? join(tmpDir, name) : tmpDir;
244
+ }
245
+ //#endregion
246
+ //#region src/paths.ts
247
+ function getBinaryTempDir(home = homedir()) {
248
+ return getPiLabGlobalTmpDir("webfetch", home);
249
+ }
250
+ //#endregion
236
251
  //#region src/tool.ts
237
252
  function formatScriptIndex(scripts) {
238
253
  if (scripts.length === 0) return "";
@@ -313,7 +328,7 @@ function registerWebFetchTool(pi, config) {
313
328
  } catch {
314
329
  throw new Error(`Invalid URL: ${url}`);
315
330
  }
316
- const tempDir = join(ctx.cwd, ".pi", "pi-lab", "webfetch", "tmp");
331
+ const tempDir = getBinaryTempDir();
317
332
  let entry = cache.get(normalizedUrl);
318
333
  if (!entry) {
319
334
  onUpdate?.({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-lab/webfetch",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "WebFetch tool extension for pi coding agent",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -17,17 +17,18 @@
17
17
  ]
18
18
  },
19
19
  "devDependencies": {
20
- "@mariozechner/pi-coding-agent": "^0.67.68",
21
- "@mariozechner/pi-tui": "^0.67.68",
20
+ "@earendil-works/pi-coding-agent": "^0.74.0",
21
+ "@earendil-works/pi-tui": "^0.74.0",
22
22
  "@sinclair/typebox": "^0.34.49",
23
23
  "@types/mozilla__readability": "^0.4.0",
24
24
  "@types/node": "^25.6.0",
25
25
  "@types/turndown": "^5.0.6",
26
- "tsdown": "^0.21.9"
26
+ "tsdown": "^0.21.9",
27
+ "@pi-lab/utils": "0.0.0"
27
28
  },
28
29
  "peerDependencies": {
29
- "@mariozechner/pi-coding-agent": "^0.67.68",
30
- "@mariozechner/pi-tui": "^0.67.68",
30
+ "@earendil-works/pi-coding-agent": "^0.74.0",
31
+ "@earendil-works/pi-tui": "^0.74.0",
31
32
  "@sinclair/typebox": "^0.34.49"
32
33
  },
33
34
  "dependencies": {