@demigodmode/pi-web-agent 1.7.0 → 1.7.2

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/CHANGELOG.md CHANGED
@@ -18,6 +18,35 @@ The format is intentionally simple and release-oriented.
18
18
  ### Breaking
19
19
  - None.
20
20
 
21
+ ## [1.7.2] - 2026-08-12
22
+ ### Added
23
+ - None.
24
+
25
+ ### Changed
26
+ - None.
27
+
28
+ ### Fixed
29
+ - Candidate scoring now matches GitHub sources by parsed hostname instead of a `url.includes('github.com/')` substring check that could also match unrelated hosts like `evil.com/github.com/`.
30
+ - `decodeHtmlEntities` now decodes `&amp;` last so an already-encoded entity such as `&amp;lt;` no longer collapses into `<` (double-unescape).
31
+ - The CI workflow now sets an explicit read-only default `GITHUB_TOKEN` permission.
32
+ - Bumped transitive `postcss`, `undici`, and `brace-expansion` in the lockfile to clear reported advisories.
33
+
34
+ ### Breaking
35
+ - None.
36
+
37
+ ## [1.7.1] - 2026-07-31
38
+ ### Added
39
+ - None.
40
+
41
+ ### Changed
42
+ - None.
43
+
44
+ ### Fixed
45
+ - The issue #34 Pi-loader compatibility patch now resolves hoisted and nested `tr46` and `cssstyle` installations correctly instead of assuming they live inside `pi-web-agent/node_modules`.
46
+
47
+ ### Breaking
48
+ - None.
49
+
21
50
  ## [1.7.0] - 2026-07-17
22
51
  ### Added
23
52
  - Exa is now available as a hosted search backend for `web_explore`, aimed at research-quality source discovery. Set `EXA_API_KEY` in the environment and choose `exa` from **Settings → Backends**. Closes #2.
@@ -25,18 +25,24 @@ export function extractReadableContent(html, maxLength = 4000) {
25
25
  text
26
26
  };
27
27
  }
28
+ const NAMED_ENTITIES = {
29
+ '&nbsp;': ' ',
30
+ '&amp;': '&',
31
+ '&lt;': '<',
32
+ '&gt;': '>',
33
+ '&quot;': '"'
34
+ };
28
35
  function decodeHtmlEntities(text) {
29
- return text
30
- .replace(/&nbsp;/gi, ' ')
31
- .replace(/&amp;/gi, '&')
32
- .replace(/&lt;/gi, '<')
33
- .replace(/&gt;/gi, '>')
34
- .replace(/&quot;/gi, '"')
35
- .replace(/&#39;/gi, "'")
36
- .replace(/&#x27;/gi, "'")
37
- .replace(/&#x2F;/gi, '/')
38
- .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)))
39
- .replace(/&#x([\da-f]+);/gi, (_, code) => String.fromCharCode(parseInt(code, 16)));
36
+ // Single pass so each entity is decoded exactly once. A multi-pass decode
37
+ // rescans its own output, which double-unescapes either &amp;lt; -> < or
38
+ // &#38;amp; -> & depending on the pass order. One pass avoids both.
39
+ return text.replace(/&(?:#(\d+)|#x([\da-f]+)|nbsp|amp|lt|gt|quot);/gi, (match, dec, hex) => {
40
+ if (dec !== undefined)
41
+ return String.fromCharCode(Number(dec));
42
+ if (hex !== undefined)
43
+ return String.fromCharCode(parseInt(hex, 16));
44
+ return NAMED_ENTITIES[match.toLowerCase()] ?? match;
45
+ });
40
46
  }
41
47
  function extractTitle(html) {
42
48
  const match = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
@@ -1,9 +1,10 @@
1
- import { classifySourceProfile } from './source-profile.js';
1
+ import { classifySourceProfile, hostOf } from './source-profile.js';
2
2
  function wantsDiscussionSources(query = '') {
3
3
  return /reddit|forum|forums|discussion|thread|comments|community|user experience|people recommend/i.test(query);
4
4
  }
5
5
  function candidateScore(result, query) {
6
- const url = result.url.toLowerCase();
6
+ const host = hostOf(result.url);
7
+ const isGithub = host === 'github.com' || (host?.endsWith('.github.com') ?? false);
7
8
  const profile = classifySourceProfile(result.url);
8
9
  const wantsThreads = wantsDiscussionSources(query);
9
10
  if (profile.kind === 'official-docs')
@@ -15,7 +16,7 @@ function candidateScore(result, query) {
15
16
  return 2;
16
17
  if (profile.kind === 'issue-thread')
17
18
  return 3;
18
- if (url.includes('github.com/'))
19
+ if (isGithub)
19
20
  return 4;
20
21
  if (profile.kind === 'package-page')
21
22
  return 6;
@@ -23,7 +24,7 @@ function candidateScore(result, query) {
23
24
  }
24
25
  if (profile.kind === 'issue-thread')
25
26
  return 2;
26
- if (url.includes('github.com/'))
27
+ if (isGithub)
27
28
  return 3;
28
29
  if (profile.kind === 'package-page')
29
30
  return 5;
@@ -5,4 +5,5 @@ export type SourceProfile = {
5
5
  sourceKind: ResearchSourceKind;
6
6
  shouldPreferHeadlessWhenWeak: boolean;
7
7
  };
8
+ export declare function hostOf(rawUrl: string): string | undefined;
8
9
  export declare function classifySourceProfile(rawUrl: string): SourceProfile;
@@ -10,6 +10,9 @@ function parseUrl(rawUrl) {
10
10
  return undefined;
11
11
  }
12
12
  }
13
+ export function hostOf(rawUrl) {
14
+ return parseUrl(rawUrl)?.hostname.toLowerCase().replace(/^www\./, '');
15
+ }
13
16
  function isOfficialApi(host, path) {
14
17
  return ((host === 'playwright.dev' && path.startsWith('/docs/api/')) ||
15
18
  (host === 'vitest.dev' && path.startsWith('/config/')));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@demigodmode/pi-web-agent",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Pi package for reliable web access with explicit search, fetch, and headless boundaries.",
5
5
  "type": "module",
6
6
  "main": "./dist/extension.js",
@@ -11,14 +11,30 @@
11
11
  // Safe to run multiple times and safe to no-op if the target files or
12
12
  // patterns are missing (e.g. a future dependency bump changes the shape).
13
13
  import { readFileSync, writeFileSync, existsSync } from "node:fs";
14
- import { fileURLToPath } from "node:url";
15
- import { dirname, join } from "node:path";
14
+ import { createRequire } from "node:module";
15
+ import { dirname, join, relative, sep } from "node:path";
16
16
 
17
- const __dirname = dirname(fileURLToPath(import.meta.url));
18
- const nodeModules = join(__dirname, "..", "node_modules");
17
+ const resolveFromHere = createRequire(import.meta.url).resolve;
18
+
19
+ function findPackageRoot(entryFile, packageName) {
20
+ let directory = dirname(entryFile);
21
+ while (true) {
22
+ const manifestFile = join(directory, "package.json");
23
+ if (existsSync(manifestFile)) {
24
+ const manifest = JSON.parse(readFileSync(manifestFile, "utf8"));
25
+ if (manifest.name === packageName) return directory;
26
+ }
27
+
28
+ const parent = dirname(directory);
29
+ if (parent === directory) {
30
+ throw new Error(`could not find the ${packageName} package root from ${entryFile}`);
31
+ }
32
+ directory = parent;
33
+ }
34
+ }
19
35
 
20
36
  function patchTr46() {
21
- const file = join(nodeModules, "tr46", "index.js");
37
+ const file = resolveFromHere("tr46");
22
38
  if (!existsSync(file)) {
23
39
  console.debug("patch-jiti-compat: tr46/index.js not found, skipping");
24
40
  return;
@@ -45,13 +61,14 @@ module.exports[Symbol.iterator] = Set.prototype[Symbol.iterator].bind(module.exp
45
61
  `;
46
62
 
47
63
  function patchCssstyleSetExports() {
64
+ const packageRoot = findPackageRoot(resolveFromHere("cssstyle"), "cssstyle");
48
65
  const files = [
49
- join(nodeModules, "cssstyle", "lib", "allExtraProperties.js"),
50
- join(nodeModules, "cssstyle", "lib", "generated", "allProperties.js"),
51
- join(nodeModules, "cssstyle", "lib", "generated", "implementedProperties.js"),
66
+ join(packageRoot, "lib", "allExtraProperties.js"),
67
+ join(packageRoot, "lib", "generated", "allProperties.js"),
68
+ join(packageRoot, "lib", "generated", "implementedProperties.js"),
52
69
  ];
53
70
  for (const file of files) {
54
- const label = `cssstyle/${file.slice(nodeModules.length + 1)}`;
71
+ const label = `cssstyle/${relative(packageRoot, file).split(sep).join("/")}`;
55
72
  if (!existsSync(file)) {
56
73
  console.debug(`patch-jiti-compat: ${label} not found, skipping`);
57
74
  continue;
@@ -67,10 +84,15 @@ function patchCssstyleSetExports() {
67
84
  }
68
85
  }
69
86
 
70
- try {
71
- patchTr46();
72
- patchCssstyleSetExports();
73
- } catch (err) {
74
- // Never fail the install over a best-effort compat patch.
75
- console.warn("patch-jiti-compat: skipped, non-fatal error:", err.message);
87
+ function runBestEffort(label, patch) {
88
+ try {
89
+ patch();
90
+ } catch (err) {
91
+ // Never fail the install over a best-effort compat patch.
92
+ const message = err instanceof Error ? err.message : String(err);
93
+ console.warn(`patch-jiti-compat: ${label} skipped, non-fatal error: ${message}`);
94
+ }
76
95
  }
96
+
97
+ runBestEffort("tr46", patchTr46);
98
+ runBestEffort("cssstyle", patchCssstyleSetExports);