@demigodmode/pi-web-agent 1.7.1 → 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,22 @@ 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
+
21
37
  ## [1.7.1] - 2026-07-31
22
38
  ### Added
23
39
  - None.
@@ -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.1",
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",