@herbertgao/pi-extensions 2026.11.18 → 2026.11.19

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 (151) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +2 -23
  4. package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
  5. package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
  6. package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
  7. package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
  8. package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
  9. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
  10. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
  11. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
  12. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
  13. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
  14. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
  15. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
  16. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
  17. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
  18. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
  19. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
  20. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
  21. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
  22. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
  23. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
  24. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
  25. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
  26. package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
  27. package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
  28. package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
  29. package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
  30. package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
  31. package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
  32. package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
  33. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
  34. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
  35. package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
  36. package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
  37. package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
  38. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
  39. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
  40. package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
  41. package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
  42. package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
  43. package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
  44. package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
  45. package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
  46. package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
  47. package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
  48. package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
  49. package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
  50. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
  51. package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
  52. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
  53. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
  54. package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
  55. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
  56. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
  57. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
  58. package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
  59. package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
  60. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
  61. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
  62. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
  63. package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
  64. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
  65. package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
  66. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
  67. package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
  68. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
  69. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  70. package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
  71. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
  72. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
  73. package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
  74. package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
  75. package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
  76. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
  77. package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
  78. package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
  79. package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
  80. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
  81. package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
  82. package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
  83. package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
  84. package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
  85. package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
  86. package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
  87. package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
  88. package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
  89. package/node_modules/pi-commandcode-provider/README.md +3 -2
  90. package/node_modules/pi-commandcode-provider/index.ts +120 -13
  91. package/node_modules/pi-commandcode-provider/package.json +4 -3
  92. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
  93. package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
  94. package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
  95. package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
  96. package/package.json +11 -14
  97. package/node_modules/pi-antigravity/README.md +0 -298
  98. package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
  99. package/node_modules/pi-antigravity/package.json +0 -87
  100. package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
  101. package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
  102. package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
  103. package/node_modules/pi-antigravity/src/client/client.ts +0 -602
  104. package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
  105. package/node_modules/pi-antigravity/src/client/index.ts +0 -2
  106. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
  107. package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
  108. package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
  109. package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
  110. package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
  111. package/node_modules/pi-antigravity/src/image/image.ts +0 -427
  112. package/node_modules/pi-antigravity/src/image/index.ts +0 -1
  113. package/node_modules/pi-antigravity/src/image/native.ts +0 -69
  114. package/node_modules/pi-antigravity/src/index.ts +0 -547
  115. package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
  116. package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
  117. package/node_modules/pi-antigravity/src/models/index.ts +0 -3
  118. package/node_modules/pi-antigravity/src/models/models.ts +0 -647
  119. package/node_modules/pi-antigravity/src/search/index.ts +0 -1
  120. package/node_modules/pi-antigravity/src/search/search.ts +0 -967
  121. package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
  122. package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
  123. package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
  124. package/node_modules/pi-antigravity/src/types/index.ts +0 -2
  125. package/node_modules/pi-antigravity/src/types/types.ts +0 -329
  126. package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
  127. package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
  128. package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
  129. package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
  130. package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
  131. package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
  132. package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
  133. package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
  134. package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
  135. package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
  136. package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
  137. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
  138. package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
  139. package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
  140. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
  141. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
  142. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
  143. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
  144. package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
  145. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
  146. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
  147. package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
  148. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
  149. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
  150. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
  151. package/node_modules/pi-antigravity/tsconfig.json +0 -21
@@ -1,328 +0,0 @@
1
- import { parseDocument } from "./document.js";
2
- import { advanceFence, FENCE_LINE, type Fence } from "./fences.js";
3
- import { repairText } from "../utils/text.js";
4
- import { isRecord } from "../utils/util.js";
5
- import { METADATA_LIMITS } from "./metadata.js";
6
- import {
7
- classifyCopyCompleteness,
8
- extractPageMetadata,
9
- htmlToMarkdown,
10
- looksLikeHtml,
11
- sanitizeMetadataText,
12
- } from "./markdown.js";
13
-
14
- export type ContentAssessment = "readable" | "empty" | "suspected-shell" | "suspected-access-wall";
15
-
16
- export type PageInspection = {
17
- rendered: string;
18
- completeness: "complete" | "incomplete" | "unknown";
19
- assessment: ContentAssessment;
20
- notes?: string[];
21
- metadata: ReturnType<typeof extractPageMetadata> & {
22
- author?: string;
23
- published?: string;
24
- language?: string;
25
- };
26
- alternates: Array<{
27
- url: string;
28
- type: "text/markdown" | "application/json";
29
- language?: string;
30
- }>;
31
- };
32
-
33
- function normalizedWallHeading(value: string): string {
34
- return value
35
- .replace(/\s*[|•–—-]\s*cloudflare\s*$/i, "")
36
- .replace(/\s+/g, " ")
37
- .trim();
38
- }
39
-
40
- /**
41
- * Headings that are a wall on their own. They stay exact: "429 Too Many Requests"
42
- * is also the title of a real article about that status, and "Forbidden error
43
- * handling" is a real article title.
44
- */
45
- const ACCESS_WALL_HEADINGS = [
46
- "forbidden",
47
- "403 forbidden",
48
- "unauthorized",
49
- "401 unauthorized",
50
- "access denied",
51
- ];
52
-
53
- /**
54
- * Openings of the interstitials that stand in for an article. The heading of a real
55
- * wall usually carries more than the phrase itself ("Please enable JavaScript to
56
- * continue"), so a phrase that opens the heading marks a wall.
57
- */
58
- const ACCESS_WALL_OPENINGS = [
59
- "just a moment",
60
- "just a second",
61
- "one more step",
62
- "robot or human",
63
- "please wait while we verify",
64
- "access to this page has been denied",
65
- "you don't have permission",
66
- "verifying your browser",
67
- "too many requests",
68
- "verify you are human",
69
- "verifying you are human",
70
- "attention required",
71
- "you have been blocked",
72
- "sorry, you have been blocked",
73
- "checking your browser",
74
- "security check",
75
- "enable javascript",
76
- "please enable javascript",
77
- "javascript is required",
78
- "javascript required",
79
- "are you a robot",
80
- "unusual traffic",
81
- "request blocked",
82
- "rate limited",
83
- "you are being rate limited",
84
- ];
85
-
86
- /** Sign-in pages read like a wall, but an article title may also start with one. */
87
- const ACCESS_WALL_SIGN_IN_OPENINGS = ["sign in", "log in"];
88
-
89
- /** How much text may follow the wall phrase before the heading is an article title. */
90
- const ACCESS_WALL_TAIL = 40;
91
- const ACCESS_WALL_SIGN_IN_TAIL = 24;
92
-
93
- /** A short block/sign-in heading, not an article that happens to discuss one. */
94
- function isAccessWallHeading(value: string | undefined): boolean {
95
- if (!value) return false;
96
- const text = normalizedWallHeading(value).toLowerCase();
97
- if (!text) return false;
98
- if (ACCESS_WALL_HEADINGS.includes(text.replace(/[.!…\s]*$/, ""))) return true;
99
- const opens = (opening: string, tail: number) =>
100
- text.startsWith(opening) &&
101
- (text.length - opening.length <= tail || /browser|human|verify|access/.test(text));
102
- return (
103
- ACCESS_WALL_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_TAIL)) ||
104
- ACCESS_WALL_SIGN_IN_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_SIGN_IN_TAIL))
105
- );
106
- }
107
-
108
- /** A wall heading alone cannot overrule substantial article content. */
109
- function hasArticleContent(rendered: string): boolean {
110
- const body = rendered.replace(/^#{1,6} .*$/gm, "").trim();
111
- return (
112
- (body.length >= 500 && /[.!?:]/.test(body)) ||
113
- (body.length >= 80 && /\b(?:HTTP|status code|response|client|server)\b/i.test(body))
114
- );
115
- }
116
-
117
- function isLoadingShell(rendered: string): boolean {
118
- const visible = rendered.replace(/^#{1,6} .*$/gm, "").trim();
119
- return /^(?:loading|please wait|redirecting|initializing)[.!…\s]*$/i.test(visible);
120
- }
121
-
122
- /** Match structured data to this page without treating fragments as separate pages. */
123
- function pageIdentity(value: unknown, baseUrl: string): string | undefined {
124
- if (isRecord(value)) value = value["@id"];
125
- if (typeof value !== "string") return undefined;
126
- try {
127
- const url = new URL(value, baseUrl);
128
- url.hash = "";
129
- return url.href;
130
- } catch {
131
- return undefined;
132
- }
133
- }
134
-
135
- /** Inspect data before destructive Markdown cleanup; never execute page scripts. */
136
- export function inspectPage(content: string, url: string, contentType?: string): PageInspection {
137
- if (!looksLikeHtml(content, contentType)) {
138
- const rendered = repairText(content).trim();
139
- let title: string | undefined;
140
- let fence: Fence | undefined;
141
- for (const line of rendered.split("\n")) {
142
- const previous = fence;
143
- fence = advanceFence(fence, line);
144
- if (!previous && !fence && !FENCE_LINE.test(line)) {
145
- title = /^ {0,3}# +(.+?)(?: +#+)?\s*$/.exec(line)?.[1];
146
- if (title) break;
147
- }
148
- }
149
- return {
150
- rendered,
151
- completeness: "unknown",
152
- assessment: rendered ? "readable" : "empty",
153
- metadata: { title: sanitizeMetadataText(title, 300) },
154
- alternates: [],
155
- };
156
- }
157
- const document = parseDocument(content);
158
- const metadata: PageInspection["metadata"] = extractPageMetadata(content, document);
159
- metadata.language = sanitizeMetadataText(document.documentElement.lang || undefined, 50);
160
- const nodes: Record<string, unknown>[] = [];
161
- let budget = 256_000;
162
- for (const script of Array.from(
163
- document.querySelectorAll('script[type="application/ld+json"]'),
164
- ).slice(0, 16)) {
165
- const text = script.textContent ?? "";
166
- budget -= text.length;
167
- if (budget < 0) break;
168
- try {
169
- const value: unknown = JSON.parse(text);
170
- const roots = Array.isArray(value) ? value : [value];
171
- for (const root of roots) {
172
- if (!isRecord(root)) continue;
173
- nodes.push(root);
174
- if (Array.isArray(root["@graph"])) nodes.push(...root["@graph"].filter(isRecord));
175
- }
176
- } catch {
177
- // Invalid or truncated structured data is not evidence.
178
- }
179
- }
180
- const identity = pageIdentity(url, url);
181
- const article = nodes.find((node) => {
182
- const types = Array.isArray(node["@type"]) ? node["@type"] : [node["@type"]];
183
- return (
184
- types.some(
185
- (type) =>
186
- typeof type === "string" && /^(Article|NewsArticle|BlogPosting|TechArticle)$/.test(type),
187
- ) &&
188
- [node.url, node.mainEntityOfPage, node["@id"]].some(
189
- (value) => pageIdentity(value, url) === identity,
190
- )
191
- );
192
- });
193
- if (article) {
194
- const text = (value: unknown, field: keyof typeof METADATA_LIMITS) =>
195
- typeof value === "string" && value.trim()
196
- ? sanitizeMetadataText(value, METADATA_LIMITS[field])
197
- : undefined;
198
- metadata.title ??= text(article.headline, "title");
199
- metadata.description ??= text(article.description, "description");
200
- metadata.updated ??= text(article.dateModified, "updated");
201
- metadata.published = text(article.datePublished, "published");
202
- metadata.language ??= text(article.inLanguage, "language");
203
- const author: unknown = Array.isArray(article.author) ? article.author[0] : article.author;
204
- const person: unknown =
205
- isRecord(author) && !author.name && typeof author["@id"] === "string"
206
- ? nodes.find((node) => node["@id"] === author["@id"])
207
- : author;
208
- metadata.author = isRecord(person) ? text(person.name, "author") : text(person, "author");
209
- }
210
-
211
- const alternates: PageInspection["alternates"] = [];
212
- for (const link of Array.from(document.querySelectorAll("link[href][type]"))) {
213
- if (!(link.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).includes("alternate"))
214
- continue;
215
- const type = link.getAttribute("type")?.split(";")[0].toLowerCase().trim();
216
- if (type !== "text/markdown" && type !== "application/json") continue;
217
- try {
218
- const alternate = new URL(link.getAttribute("href")!, url);
219
- if (alternate.origin !== new URL(url).origin || alternate.username || alternate.password)
220
- continue;
221
- if (/\.pdf$/i.test(alternate.pathname)) continue;
222
- alternate.hash = "";
223
- if (alternate.href === identity || alternates.some((item) => item.url === alternate.href))
224
- continue;
225
- const language = sanitizeMetadataText(
226
- link.getAttribute("hreflang") ?? undefined,
227
- 35,
228
- )?.toLowerCase();
229
- const declaredLanguage = language && language !== "x-default" ? language : undefined;
230
- alternates.push({
231
- url: alternate.href,
232
- type,
233
- ...(declaredLanguage ? { language: declaredLanguage } : {}),
234
- });
235
- } catch {
236
- // Ignore invalid URLs, including malformed base-relative references.
237
- }
238
- }
239
- const pageLanguage = metadata.language?.split("-")[0].toLowerCase();
240
- const sameLanguage = pageLanguage
241
- ? alternates.filter((item) => !item.language || item.language.split("-")[0] === pageLanguage)
242
- : alternates;
243
- const preferred = sameLanguage.length ? sameLanguage : alternates;
244
- preferred.sort((a, b) => Number(b.type === "text/markdown") - Number(a.type === "text/markdown"));
245
- const appScript = Boolean(document.querySelector('script[src], script[type="module"]'));
246
- const rendered = htmlToMarkdown(content, { baseUrl: url, document });
247
- const heading = /^# +(.+)$/m.exec(rendered)?.[1] || "";
248
- // A page that loads an application script and shows nothing else is a shell.
249
- const completeness = classifyCopyCompleteness(content);
250
- // A page that loads application JavaScript and shows only a placeholder is a shell.
251
- // A cut-off copy holding only a heading has lost its body; report it as empty.
252
- const bodyMissing =
253
- !rendered.trim() ||
254
- (completeness === "incomplete" && !rendered.replace(/^#{1,6} .*$/gm, "").trim());
255
- const assessment: ContentAssessment = bodyMissing
256
- ? // A copy that ends before the content is cut off, not an application shell.
257
- appScript && completeness !== "incomplete"
258
- ? "suspected-shell"
259
- : "empty"
260
- : isAccessWallHeading(heading || metadata.title) &&
261
- /\b(?:check(?:ing)?|verif\w*|captcha|blocked|denied|permission|enable javascript|sign in|log in)\b/i.test(
262
- rendered.replace(/^#{1,6} .*$/gm, ""),
263
- ) &&
264
- !hasArticleContent(rendered)
265
- ? "suspected-access-wall"
266
- : appScript && isLoadingShell(rendered)
267
- ? "suspected-shell"
268
- : "readable";
269
- return {
270
- rendered,
271
- completeness,
272
- assessment,
273
- metadata,
274
- alternates: preferred.slice(0, 8),
275
- };
276
- }
277
-
278
- /**
279
- * Inspection of a source the converter will not take on. Raw mode returns the crawled
280
- * source as it is, so the page's size limits the answer, not the read.
281
- */
282
- export function inspectUnconverted(content: string, reason: string): PageInspection {
283
- return {
284
- rendered: "",
285
- completeness: classifyCopyCompleteness(content),
286
- assessment: content.trim() ? "readable" : "empty",
287
- notes: [`Not converted: ${reason}`],
288
- metadata: {},
289
- alternates: [],
290
- };
291
- }
292
-
293
- /** Decode only explicit article-body JSON shapes from an advertised representation. */
294
- export function articleRepresentation(content: string, articleUrl: string): string | undefined {
295
- let value: unknown;
296
- try {
297
- value = JSON.parse(content);
298
- } catch {
299
- return undefined;
300
- }
301
- if (!isRecord(value)) return undefined;
302
- // GitHub Docs article API.
303
- if (
304
- isRecord(value.meta) &&
305
- value.meta.documentType === "article" &&
306
- typeof value.body === "string" &&
307
- Array.isArray(value.meta.breadcrumbs)
308
- ) {
309
- const current: unknown = value.meta.breadcrumbs.at(-1);
310
- if (
311
- isRecord(current) &&
312
- pageIdentity(current.href, articleUrl) === pageIdentity(articleUrl, articleUrl)
313
- )
314
- return value.body;
315
- }
316
- // WordPress single-post REST representation (not an index or oEmbed summary).
317
- if (
318
- typeof value.id === "number" &&
319
- typeof value.link === "string" &&
320
- pageIdentity(value.link, articleUrl) === pageIdentity(articleUrl, articleUrl) &&
321
- isRecord(value.content) &&
322
- value.content.protected !== true &&
323
- typeof value.content.rendered === "string"
324
- ) {
325
- return value.content.rendered;
326
- }
327
- return undefined;
328
- }
@@ -1,4 +0,0 @@
1
- /** Defaults and limits shared by retrieval and display. */
2
- export const DEFAULT_WEB_FETCH_MAX_CHARS = 60_000;
3
- export const WEB_FETCH_TIMEOUT_MS = 10_000;
4
- export const MAX_RESPONSE_BYTES = 5_000_000;