@taurgis/bonsai 3.2.0 → 3.2.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/README.md +7 -4
- package/agents/agents/salesforce-docs-researcher.agent.md +14 -1
- package/agents/instructions/salesforce-research.instructions.md +2 -1
- package/bin/cli.mjs +9 -17
- package/dist/base-command.d.ts +22 -12
- package/dist/base-command.js +86 -49
- package/dist/commands/config/base.js +11 -2
- package/dist/commands/config/get.js +8 -12
- package/dist/commands/config/index.js +2 -2
- package/dist/commands/config/list.js +10 -16
- package/dist/commands/config/set.d.ts +2 -1
- package/dist/commands/config/set.js +34 -27
- package/dist/commands/config/unset.d.ts +2 -1
- package/dist/commands/config/unset.js +25 -24
- package/dist/commands/fetch.d.ts +7 -15
- package/dist/commands/fetch.js +57 -401
- package/dist/commands/import.d.ts +4 -9
- package/dist/commands/import.js +56 -284
- package/dist/commands/inspect.d.ts +7 -1
- package/dist/commands/inspect.js +103 -52
- package/dist/commands/list.d.ts +13 -1
- package/dist/commands/list.js +79 -32
- package/dist/commands/prune.d.ts +4 -1
- package/dist/commands/prune.js +55 -75
- package/dist/commands/status.d.ts +3 -2
- package/dist/commands/status.js +52 -79
- package/dist/hooks/command-not-found/suggest.d.ts +1 -0
- package/dist/hooks/command-not-found/suggest.js +66 -39
- package/dist/lib/argv.d.ts +24 -3
- package/dist/lib/argv.js +124 -53
- package/dist/lib/batch.d.ts +41 -0
- package/dist/lib/batch.js +39 -0
- package/dist/lib/cache-view.d.ts +21 -0
- package/dist/lib/cache-view.js +30 -0
- package/dist/lib/cli-emit.d.ts +28 -0
- package/dist/lib/cli-emit.js +44 -0
- package/dist/lib/cli-error-policy.d.ts +57 -0
- package/dist/lib/cli-error-policy.js +74 -0
- package/dist/lib/cli-flag-manifest.d.ts +5 -0
- package/dist/lib/cli-flag-manifest.js +8 -0
- package/dist/lib/cli-presentation.d.ts +39 -0
- package/dist/lib/cli-presentation.js +50 -0
- package/dist/lib/cli-result-types.d.ts +88 -0
- package/dist/lib/cli-result-types.js +2 -0
- package/dist/lib/config/index.d.ts +21 -3
- package/dist/lib/config/index.js +58 -3
- package/dist/lib/config-persist.d.ts +28 -0
- package/dist/lib/config-persist.js +29 -0
- package/dist/lib/envelope.d.ts +41 -3
- package/dist/lib/envelope.js +147 -4
- package/dist/lib/help-preflight.d.ts +5 -8
- package/dist/lib/help-preflight.js +13 -32
- package/dist/lib/json-meta.d.ts +0 -2
- package/dist/lib/json-meta.js +21 -25
- package/dist/lib/limit-flag.d.ts +11 -1
- package/dist/lib/limit-flag.js +19 -6
- package/dist/lib/parse-error-ux.d.ts +5 -0
- package/dist/lib/parse-error-ux.js +73 -0
- package/dist/lib/prune-flags.d.ts +28 -0
- package/dist/lib/prune-flags.js +74 -0
- package/dist/lib/research/artifact-index.d.ts +11 -2
- package/dist/lib/research/artifact-index.js +7 -4
- package/dist/lib/research/browser.d.ts +41 -2
- package/dist/lib/research/browser.js +139 -50
- package/dist/lib/research/capture.d.ts +24 -2
- package/dist/lib/research/capture.js +24 -4
- package/dist/lib/research/cli-io.d.ts +33 -0
- package/dist/lib/research/cli-io.js +27 -0
- package/dist/lib/research/compress.d.ts +7 -0
- package/dist/lib/research/compress.js +7 -3
- package/dist/lib/research/docs/capabilities.d.ts +15 -0
- package/dist/lib/research/docs/capabilities.js +5 -0
- package/dist/lib/research/docs/clean-dom.d.ts +2 -0
- package/dist/lib/research/docs/clean-dom.js +2 -0
- package/dist/lib/research/docs/code-blocks.d.ts +2 -0
- package/dist/lib/research/docs/code-blocks.js +2 -0
- package/dist/lib/research/docs/detect.d.ts +4 -0
- package/dist/lib/research/docs/detect.js +4 -0
- package/dist/lib/research/docs/machine-readable.d.ts +18 -0
- package/dist/lib/research/docs/machine-readable.js +10 -0
- package/dist/lib/research/docs/markdown-source.d.ts +20 -0
- package/dist/lib/research/docs/markdown-source.js +19 -2
- package/dist/lib/research/docs/quality-gates.d.ts +5 -0
- package/dist/lib/research/docs/quality-gates.js +4 -0
- package/dist/lib/research/docs/rsc.d.ts +9 -2
- package/dist/lib/research/docs/rsc.js +5 -2
- package/dist/lib/research/docs/section-artifacts.d.ts +12 -0
- package/dist/lib/research/docs/section-artifacts.js +12 -0
- package/dist/lib/research/docs/sections.d.ts +18 -0
- package/dist/lib/research/docs/sections.js +17 -1
- package/dist/lib/research/docs/source-map.d.ts +28 -0
- package/dist/lib/research/docs/source-map.js +27 -0
- package/dist/lib/research/docs/validate.d.ts +35 -2
- package/dist/lib/research/docs/validate.js +47 -2
- package/dist/lib/research/extract.d.ts +16 -0
- package/dist/lib/research/extract.js +12 -1
- package/dist/lib/research/fetch-command-service.d.ts +36 -0
- package/dist/lib/research/fetch-command-service.js +310 -0
- package/dist/lib/research/fetch-result.d.ts +114 -0
- package/dist/lib/research/fetch-result.js +212 -0
- package/dist/lib/research/fetcher.d.ts +46 -8
- package/dist/lib/research/fetcher.js +58 -30
- package/dist/lib/research/freshness.d.ts +54 -11
- package/dist/lib/research/freshness.js +91 -31
- package/dist/lib/research/import-command-service.d.ts +56 -0
- package/dist/lib/research/import-command-service.js +381 -0
- package/dist/lib/research/keywords.js +5 -1
- package/dist/lib/research/markdown.d.ts +12 -1
- package/dist/lib/research/markdown.js +13 -5
- package/dist/lib/research/persist-artifact.d.ts +23 -0
- package/dist/lib/research/persist-artifact.js +27 -0
- package/dist/lib/research/prompt-injection.d.ts +8 -0
- package/dist/lib/research/prompt-injection.js +42 -13
- package/dist/lib/research/proxy.d.ts +14 -8
- package/dist/lib/research/proxy.js +14 -10
- package/dist/lib/research/revalidate.d.ts +49 -20
- package/dist/lib/research/revalidate.js +80 -15
- package/dist/lib/research/schema.d.ts +7 -0
- package/dist/lib/research/schema.js +2 -0
- package/dist/lib/research/secret-scan.d.ts +6 -0
- package/dist/lib/research/secret-scan.js +8 -0
- package/dist/lib/research/secure-write.d.ts +4 -0
- package/dist/lib/research/secure-write.js +31 -2
- package/dist/lib/research/storage.d.ts +5 -1
- package/dist/lib/research/storage.js +8 -3
- package/dist/lib/research/summarize.d.ts +15 -0
- package/dist/lib/research/summarize.js +11 -0
- package/dist/lib/research/url.d.ts +9 -6
- package/dist/lib/research/url.js +33 -21
- package/dist/lib/text.d.ts +7 -2
- package/dist/lib/text.js +13 -2
- package/dist/lib/value-flags.d.ts +14 -0
- package/dist/lib/value-flags.js +28 -0
- package/dist/sites/coveo.d.ts +10 -0
- package/dist/sites/coveo.js +10 -0
- package/dist/sites/index.d.ts +16 -0
- package/dist/sites/index.js +16 -4
- package/dist/sites/markdown-twin.d.ts +31 -0
- package/dist/sites/markdown-twin.js +56 -0
- package/dist/sites/salesforce/fetch-page.d.ts +8 -2
- package/dist/sites/salesforce/fetch-page.js +14 -3
- package/dist/sites/salesforce/help-tooling-markdown.d.ts +30 -0
- package/dist/sites/salesforce/help-tooling-markdown.js +74 -0
- package/dist/sites/salesforce/index.d.ts +1 -0
- package/dist/sites/salesforce/index.js +1 -0
- package/dist/sites/salesforce-developer/fetch-page.d.ts +6 -1
- package/dist/sites/salesforce-developer/fetch-page.js +6 -1
- package/dist/sites/salesforce-developer/index.d.ts +1 -0
- package/dist/sites/salesforce-developer/index.js +1 -0
- package/dist/sites/salesforce-developer/route-markdown.d.ts +18 -6
- package/dist/sites/salesforce-developer/route-markdown.js +29 -67
- package/dist/sites/salesforce-doc-fetch.d.ts +39 -5
- package/dist/sites/salesforce-doc-fetch.js +52 -7
- package/dist/sites/salesforce-dom-probe.d.ts +20 -2
- package/dist/sites/salesforce-dom-probe.js +20 -2
- package/dist/sites/types.d.ts +14 -8
- package/dist/sites/types.js +3 -0
- package/oclif.manifest.json +104 -98
- package/package.json +19 -7
- package/agents/agents/official-docs-researcher.agent.md +0 -87
- package/agents/instructions/web-research.instructions.md +0 -44
- package/agents/skills/web-research/SKILL.md +0 -118
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
/** Two-valued confidence marker: `verified` = observed in bytes; `signal` = hinted but unproven. */
|
|
1
2
|
export type Evidence = 'verified' | 'signal';
|
|
3
|
+
/** Recognized client-side doc rendering engines. */
|
|
2
4
|
export type DocsEngine = 'vitepress' | 'docusaurus' | 'starlight' | 'next' | 'generated-static' | 'spa';
|
|
5
|
+
/** Reusable docs generators and hosted platforms layered on top of (or independent of) an engine. */
|
|
3
6
|
export type DocsFramework = 'mkdocs' | 'material-mkdocs' | 'sphinx' | 'nextra' | 'fumadocs' | 'gitbook' | 'mintlify' | 'readme' | 'redocly' | 'docsify' | 'rspress' | 'vuepress' | 'docsy' | 'just-the-docs';
|
|
7
|
+
/** Recognized machine-readable artifact types a docs site may expose. */
|
|
4
8
|
export type MachineReadableType = 'llms.txt' | 'llms-full.txt' | 'route-markdown' | 'search-index' | 'sitemap' | 'source-edit-link';
|
|
9
|
+
/** A machine-readable artifact discovered (or inferred) for a docs site. */
|
|
5
10
|
export interface MachineReadableArtifact {
|
|
6
11
|
type: MachineReadableType;
|
|
7
12
|
url: string;
|
|
8
13
|
evidence: Evidence;
|
|
9
14
|
}
|
|
15
|
+
/** A pointer to the public Markdown/MDX source for a page. Only `verified` once a raw URL is fetched successfully. */
|
|
10
16
|
export interface SourceHint {
|
|
11
17
|
type: 'markdown' | 'mdx' | 'html';
|
|
12
18
|
url?: string;
|
|
@@ -15,7 +21,9 @@ export interface SourceHint {
|
|
|
15
21
|
path?: string;
|
|
16
22
|
evidence: Evidence;
|
|
17
23
|
}
|
|
24
|
+
/** Known search providers a docs site may use. */
|
|
18
25
|
export type SearchProvider = 'algolia-docsearch' | 'vitepress-local' | 'pagefind' | 'docusaurus-local' | 'mkdocs-local' | 'sphinx-searchindex' | 'jekyll-json' | 'sitemap' | 'llms.txt' | 'readme-algolia' | 'custom';
|
|
26
|
+
/** Search capability detected for a docs site, with optional index coordinates. */
|
|
19
27
|
export interface SearchCapability {
|
|
20
28
|
provider: SearchProvider;
|
|
21
29
|
evidence: Evidence;
|
|
@@ -25,11 +33,13 @@ export interface SearchCapability {
|
|
|
25
33
|
apiKey?: string;
|
|
26
34
|
publicEndpoint?: string;
|
|
27
35
|
}
|
|
36
|
+
/** A single entry in a docs site's page map: title, route URL, and optional source path. */
|
|
28
37
|
export interface PageMapEntry {
|
|
29
38
|
title: string;
|
|
30
39
|
url: string;
|
|
31
40
|
sourcePath?: string;
|
|
32
41
|
}
|
|
42
|
+
/** Full capability snapshot for a docs site, as populated by the detector and probe modules. */
|
|
33
43
|
export interface SiteCapabilities {
|
|
34
44
|
docsEngine?: DocsEngine;
|
|
35
45
|
framework?: DocsFramework;
|
|
@@ -40,4 +50,9 @@ export interface SiteCapabilities {
|
|
|
40
50
|
pageMap?: PageMapEntry[];
|
|
41
51
|
notes: string[];
|
|
42
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns a baseline SiteCapabilities with no engine/framework detected and an empty capability set.
|
|
55
|
+
*
|
|
56
|
+
* @returns A minimal SiteCapabilities object suitable as a starting point for detectors and probes.
|
|
57
|
+
*/
|
|
43
58
|
export declare function emptyCapabilities(): SiteCapabilities;
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
// two-valued: `verified` means observed in the supplied bytes (markup/data/HTTP), `signal` means
|
|
5
5
|
// the page hints at the capability but the endpoint/index/source is not proven. A visible search
|
|
6
6
|
// button is at most a `signal` — never `verified` (see T-16/T-20 acceptance criteria).
|
|
7
|
+
/**
|
|
8
|
+
* Returns a baseline SiteCapabilities with no engine/framework detected and an empty capability set.
|
|
9
|
+
*
|
|
10
|
+
* @returns A minimal SiteCapabilities object suitable as a starting point for detectors and probes.
|
|
11
|
+
*/
|
|
7
12
|
export function emptyCapabilities() {
|
|
8
13
|
return { recommendedCapture: 'static', machineReadable: [], notes: [] };
|
|
9
14
|
}
|
|
@@ -33,6 +33,8 @@ function dropDataImages(document) {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Strips decorative docs chrome and base64 images from the document in place before extraction.
|
|
36
|
+
*
|
|
37
|
+
* @param document - linkedom Document object to mutate.
|
|
36
38
|
*/
|
|
37
39
|
export function cleanDocsChrome(document) {
|
|
38
40
|
for (const selector of CHROME_SELECTORS)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reconstructs newline-delimited text for every highlighted code block in the document and tags it
|
|
3
3
|
* with a `language-x` class when one is detectable. Idempotent and a no-op on plain `<pre>` blocks.
|
|
4
|
+
*
|
|
5
|
+
* @param document - linkedom Document object to mutate in place.
|
|
4
6
|
*/
|
|
5
7
|
export declare function normalizeCodeBlocks(document: any): void;
|
|
@@ -76,6 +76,8 @@ function flattenCodeStructure(pre, code) {
|
|
|
76
76
|
/**
|
|
77
77
|
* Reconstructs newline-delimited text for every highlighted code block in the document and tags it
|
|
78
78
|
* with a `language-x` class when one is detectable. Idempotent and a no-op on plain `<pre>` blocks.
|
|
79
|
+
*
|
|
80
|
+
* @param document - linkedom Document object to mutate in place.
|
|
79
81
|
*/
|
|
80
82
|
export function normalizeCodeBlocks(document) {
|
|
81
83
|
removeCopyButtons(document);
|
|
@@ -2,5 +2,9 @@ import type { SiteCapabilities } from './capabilities.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Inspects page HTML and returns the detected docs engine/framework plus any capability signals.
|
|
4
4
|
* Always returns a result; an unrecognized page yields a best-effort static/SPA shape classification.
|
|
5
|
+
*
|
|
6
|
+
* @param html - Full page HTML to inspect (not executed — signals matched as substrings).
|
|
7
|
+
* @param url - Page URL used to resolve relative links in source/llms.txt hints.
|
|
8
|
+
* @returns Detected SiteCapabilities including engine, framework, recommended capture, and signals.
|
|
5
9
|
*/
|
|
6
10
|
export declare function detectDocsEngine(html: string, url: string): SiteCapabilities;
|
|
@@ -226,6 +226,10 @@ const FAMILY_DETECTORS = [
|
|
|
226
226
|
/**
|
|
227
227
|
* Inspects page HTML and returns the detected docs engine/framework plus any capability signals.
|
|
228
228
|
* Always returns a result; an unrecognized page yields a best-effort static/SPA shape classification.
|
|
229
|
+
*
|
|
230
|
+
* @param html - Full page HTML to inspect (not executed — signals matched as substrings).
|
|
231
|
+
* @param url - Page URL used to resolve relative links in source/llms.txt hints.
|
|
232
|
+
* @returns Detected SiteCapabilities including engine, framework, recommended capture, and signals.
|
|
229
233
|
*/
|
|
230
234
|
export function detectDocsEngine(html, url) {
|
|
231
235
|
const { document } = parseHTML(html);
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { MachineReadableArtifact, SiteCapabilities } from './capabilities.js';
|
|
2
|
+
/** A successfully validated machine-readable artifact and its body text. */
|
|
2
3
|
export interface MachineReadableResult {
|
|
3
4
|
artifact: MachineReadableArtifact;
|
|
4
5
|
body: string;
|
|
5
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Injectable HTTP fetcher used by the machine-readable probe functions.
|
|
9
|
+
* Tests supply a fixture fetcher; production code uses `fetchText`.
|
|
10
|
+
*
|
|
11
|
+
* @param url - Absolute URL to fetch.
|
|
12
|
+
* @returns Response body, final URL after redirects, status code, and content-type header.
|
|
13
|
+
*/
|
|
6
14
|
export type TextFetcher = (url: string) => Promise<{
|
|
7
15
|
content: string;
|
|
8
16
|
finalUrl: string;
|
|
@@ -12,10 +20,20 @@ export type TextFetcher = (url: string) => Promise<{
|
|
|
12
20
|
/**
|
|
13
21
|
* Probes conventional and advertised `llms.txt` URLs. Returns the first that validates as same-origin
|
|
14
22
|
* text, or null. The result is a site-INDEX artifact for discovery — not a replacement for page content.
|
|
23
|
+
*
|
|
24
|
+
* @param pageUrl - The doc page URL; its origin is used for same-origin checks and candidate construction.
|
|
25
|
+
* @param caps - Site capabilities from the detector, carrying any advertised llms.txt links.
|
|
26
|
+
* @param fetcher - HTTP fetcher (injectable for tests).
|
|
27
|
+
* @returns A verified MachineReadableResult, or null when no valid llms.txt is found.
|
|
15
28
|
*/
|
|
16
29
|
export declare function probeLlmsTxt(pageUrl: string, caps: SiteCapabilities, fetcher?: TextFetcher): Promise<MachineReadableResult | null>;
|
|
17
30
|
/**
|
|
18
31
|
* Probes a page-level `.md` route. The derived route is only a candidate: it must be same-origin,
|
|
19
32
|
* fetch successfully, and validate as non-HTML/non-error Markdown before being trusted.
|
|
33
|
+
*
|
|
34
|
+
* @param pageUrl - The doc page URL to derive the `.md` route from.
|
|
35
|
+
* @param caps - Site capabilities carrying any advertised route-markdown links.
|
|
36
|
+
* @param fetcher - HTTP fetcher (injectable for tests).
|
|
37
|
+
* @returns A verified MachineReadableResult, or null when no valid route Markdown is found.
|
|
20
38
|
*/
|
|
21
39
|
export declare function probeRouteMarkdown(pageUrl: string, caps: SiteCapabilities, fetcher?: TextFetcher): Promise<MachineReadableResult | null>;
|
|
@@ -34,6 +34,11 @@ async function tryFetchValidText(url, fetcher) {
|
|
|
34
34
|
/**
|
|
35
35
|
* Probes conventional and advertised `llms.txt` URLs. Returns the first that validates as same-origin
|
|
36
36
|
* text, or null. The result is a site-INDEX artifact for discovery — not a replacement for page content.
|
|
37
|
+
*
|
|
38
|
+
* @param pageUrl - The doc page URL; its origin is used for same-origin checks and candidate construction.
|
|
39
|
+
* @param caps - Site capabilities from the detector, carrying any advertised llms.txt links.
|
|
40
|
+
* @param fetcher - HTTP fetcher (injectable for tests).
|
|
41
|
+
* @returns A verified MachineReadableResult, or null when no valid llms.txt is found.
|
|
37
42
|
*/
|
|
38
43
|
export async function probeLlmsTxt(pageUrl, caps, fetcher = defaultFetcher) {
|
|
39
44
|
for (const candidate of llmsTxtCandidates(pageUrl, caps)) {
|
|
@@ -50,6 +55,11 @@ export async function probeLlmsTxt(pageUrl, caps, fetcher = defaultFetcher) {
|
|
|
50
55
|
/**
|
|
51
56
|
* Probes a page-level `.md` route. The derived route is only a candidate: it must be same-origin,
|
|
52
57
|
* fetch successfully, and validate as non-HTML/non-error Markdown before being trusted.
|
|
58
|
+
*
|
|
59
|
+
* @param pageUrl - The doc page URL to derive the `.md` route from.
|
|
60
|
+
* @param caps - Site capabilities carrying any advertised route-markdown links.
|
|
61
|
+
* @param fetcher - HTTP fetcher (injectable for tests).
|
|
62
|
+
* @returns A verified MachineReadableResult, or null when no valid route Markdown is found.
|
|
53
63
|
*/
|
|
54
64
|
export async function probeRouteMarkdown(pageUrl, caps, fetcher = defaultFetcher) {
|
|
55
65
|
const advertised = caps.machineReadable
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import type { ExtractionResult } from '../extract.js';
|
|
2
|
+
/** Result of stripping a YAML frontmatter block from a Markdown document. */
|
|
2
3
|
export interface ParsedFrontmatter {
|
|
3
4
|
frontmatter: Record<string, string>;
|
|
4
5
|
body: string;
|
|
5
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the leading YAML frontmatter block from a Markdown string. Only flat scalar keys are
|
|
9
|
+
* read; nested structures are silently ignored. The returned `body` has the frontmatter block
|
|
10
|
+
* and its delimiters stripped.
|
|
11
|
+
*
|
|
12
|
+
* @param md - Raw Markdown/MDX string, possibly starting with `---` frontmatter.
|
|
13
|
+
* @returns Parsed flat key/value frontmatter and the remaining Markdown body.
|
|
14
|
+
*/
|
|
6
15
|
export declare function parseFrontmatter(md: string): ParsedFrontmatter;
|
|
7
16
|
/**
|
|
8
17
|
* Removes dangerous embedded HTML from untrusted Markdown: <script>/<style> blocks, inline event
|
|
9
18
|
* handler attributes, and javascript: URLs. Leaves ordinary Markdown and benign inline HTML intact.
|
|
19
|
+
*
|
|
20
|
+
* @param md - Markdown/MDX source string from a public but untrusted URL.
|
|
21
|
+
* @returns Sanitized Markdown with unsafe HTML constructs removed.
|
|
10
22
|
*/
|
|
11
23
|
export declare function sanitizeSourceMarkdown(md: string): string;
|
|
12
24
|
/**
|
|
@@ -14,11 +26,19 @@ export declare function sanitizeSourceMarkdown(md: string): string;
|
|
|
14
26
|
* fences through verbatim. Every text-level cleanup in this pipeline must go through this guard:
|
|
15
27
|
* fenced code is quoted material, and "cleaning" it destroys the samples readers came for
|
|
16
28
|
* (a `<script>` line in an example, a bash `# comment`, a literal `javascript:` URL).
|
|
29
|
+
*
|
|
30
|
+
* @param md - Markdown document to process.
|
|
31
|
+
* @param transform - Function applied to each non-fenced segment.
|
|
32
|
+
* @returns Transformed Markdown with fenced code blocks left verbatim.
|
|
17
33
|
*/
|
|
18
34
|
export declare function outsideFences(md: string, transform: (segment: string) => string): string;
|
|
19
35
|
/**
|
|
20
36
|
* Builds an ExtractionResult from public Markdown/MDX source. Frontmatter is parsed for the title
|
|
21
37
|
* and the body is sanitized. The detailed Markdown is the source itself, preserving code fences,
|
|
22
38
|
* tabs, and admonitions better than HTML conversion.
|
|
39
|
+
*
|
|
40
|
+
* @param md - Raw Markdown/MDX source from a public URL.
|
|
41
|
+
* @param sourceUrl - The URL the source was fetched from; used for MDN KumaScript gating and the quality note.
|
|
42
|
+
* @returns ExtractionResult with the cleaned Markdown body as `detailedMarkdown`.
|
|
23
43
|
*/
|
|
24
44
|
export declare function extractFromSource(md: string, sourceUrl: string): ExtractionResult;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { dropEmptyLinks, htmlToMarkdown } from '../markdown.js';
|
|
2
2
|
import { sanitizePromptInjection } from '../prompt-injection.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the leading YAML frontmatter block from a Markdown string. Only flat scalar keys are
|
|
5
|
+
* read; nested structures are silently ignored. The returned `body` has the frontmatter block
|
|
6
|
+
* and its delimiters stripped.
|
|
7
|
+
*
|
|
8
|
+
* @param md - Raw Markdown/MDX string, possibly starting with `---` frontmatter.
|
|
9
|
+
* @returns Parsed flat key/value frontmatter and the remaining Markdown body.
|
|
10
|
+
*/
|
|
5
11
|
export function parseFrontmatter(md) {
|
|
6
12
|
const normalized = md.replace(/^/, '');
|
|
7
13
|
if (!normalized.startsWith('---'))
|
|
@@ -29,6 +35,9 @@ export function parseFrontmatter(md) {
|
|
|
29
35
|
/**
|
|
30
36
|
* Removes dangerous embedded HTML from untrusted Markdown: <script>/<style> blocks, inline event
|
|
31
37
|
* handler attributes, and javascript: URLs. Leaves ordinary Markdown and benign inline HTML intact.
|
|
38
|
+
*
|
|
39
|
+
* @param md - Markdown/MDX source string from a public but untrusted URL.
|
|
40
|
+
* @returns Sanitized Markdown with unsafe HTML constructs removed.
|
|
32
41
|
*/
|
|
33
42
|
export function sanitizeSourceMarkdown(md) {
|
|
34
43
|
return (md
|
|
@@ -103,6 +112,10 @@ function stripMdnHiddenSamples(md) {
|
|
|
103
112
|
* fences through verbatim. Every text-level cleanup in this pipeline must go through this guard:
|
|
104
113
|
* fenced code is quoted material, and "cleaning" it destroys the samples readers came for
|
|
105
114
|
* (a `<script>` line in an example, a bash `# comment`, a literal `javascript:` URL).
|
|
115
|
+
*
|
|
116
|
+
* @param md - Markdown document to process.
|
|
117
|
+
* @param transform - Function applied to each non-fenced segment.
|
|
118
|
+
* @returns Transformed Markdown with fenced code blocks left verbatim.
|
|
106
119
|
*/
|
|
107
120
|
export function outsideFences(md, transform) {
|
|
108
121
|
return md
|
|
@@ -198,6 +211,10 @@ function confidenceFor(length) {
|
|
|
198
211
|
* Builds an ExtractionResult from public Markdown/MDX source. Frontmatter is parsed for the title
|
|
199
212
|
* and the body is sanitized. The detailed Markdown is the source itself, preserving code fences,
|
|
200
213
|
* tabs, and admonitions better than HTML conversion.
|
|
214
|
+
*
|
|
215
|
+
* @param md - Raw Markdown/MDX source from a public URL.
|
|
216
|
+
* @param sourceUrl - The URL the source was fetched from; used for MDN KumaScript gating and the quality note.
|
|
217
|
+
* @returns ExtractionResult with the cleaned Markdown body as `detailedMarkdown`.
|
|
201
218
|
*/
|
|
202
219
|
export function extractFromSource(md, sourceUrl) {
|
|
203
220
|
const { frontmatter, body } = parseFrontmatter(md);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Quality analysis result: stable `quality:*` codes and an index-hub detection flag. */
|
|
1
2
|
export interface QualitySignals {
|
|
2
3
|
codes: string[];
|
|
3
4
|
isIndexHub: boolean;
|
|
@@ -5,5 +6,9 @@ export interface QualitySignals {
|
|
|
5
6
|
/**
|
|
6
7
|
* Analyzes extracted Markdown and returns stable quality codes plus an index/hub flag. `markdown`
|
|
7
8
|
* is the detailed representation; `title` helps the error-page heuristic on short pages.
|
|
9
|
+
*
|
|
10
|
+
* @param markdown - Detailed Markdown text to analyze.
|
|
11
|
+
* @param title - Page title used to strengthen the error-page heuristic on short pages.
|
|
12
|
+
* @returns Stable `quality:*` codes and `isIndexHub` flag.
|
|
8
13
|
*/
|
|
9
14
|
export declare function analyzeMarkdownQuality(markdown: string, title?: string): QualitySignals;
|
|
@@ -40,6 +40,10 @@ function hasCollapsedCode(markdown) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Analyzes extracted Markdown and returns stable quality codes plus an index/hub flag. `markdown`
|
|
42
42
|
* is the detailed representation; `title` helps the error-page heuristic on short pages.
|
|
43
|
+
*
|
|
44
|
+
* @param markdown - Detailed Markdown text to analyze.
|
|
45
|
+
* @param title - Page title used to strengthen the error-page heuristic on short pages.
|
|
46
|
+
* @returns Stable `quality:*` codes and `isIndexHub` flag.
|
|
43
47
|
*/
|
|
44
48
|
export function analyzeMarkdownQuality(markdown, title = '') {
|
|
45
49
|
const codes = [];
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { PageMapEntry } from './capabilities.js';
|
|
2
|
+
/**
|
|
3
|
+
* Page-map and source-path data recovered from a Next.js / React Server Components (RSC) HTML payload.
|
|
4
|
+
* `sourcePathHints` are unverified; they must be validated before being promoted to a source link.
|
|
5
|
+
*/
|
|
2
6
|
export interface NextRscData {
|
|
3
7
|
pageMap: PageMapEntry[];
|
|
4
8
|
sourcePathHints: string[];
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
|
-
* Scans Next/RSC HTML for a page map (route + title, with optional
|
|
8
|
-
* `filePath` source hints. Returns empty arrays when no payload is present.
|
|
11
|
+
* Scans Next.js / React Server Components (RSC) HTML for a page map (route + title, with optional
|
|
12
|
+
* source path) and any `filePath` source hints. Returns empty arrays when no payload is present.
|
|
13
|
+
*
|
|
14
|
+
* @param html - Full page HTML containing embedded `__NEXT_DATA__` or `self.__next_f` payloads.
|
|
15
|
+
* @returns Recovered page map entries and unverified source-path hints.
|
|
9
16
|
*/
|
|
10
17
|
export declare function extractNextRscData(html: string): NextRscData;
|
|
@@ -7,8 +7,11 @@ function dedupe(items) {
|
|
|
7
7
|
return [...new Set(items.filter(Boolean))];
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Scans Next/RSC HTML for a page map (route + title, with optional
|
|
11
|
-
* `filePath` source hints. Returns empty arrays when no payload is present.
|
|
10
|
+
* Scans Next.js / React Server Components (RSC) HTML for a page map (route + title, with optional
|
|
11
|
+
* source path) and any `filePath` source hints. Returns empty arrays when no payload is present.
|
|
12
|
+
*
|
|
13
|
+
* @param html - Full page HTML containing embedded `__NEXT_DATA__` or `self.__next_f` payloads.
|
|
14
|
+
* @returns Recovered page map entries and unverified source-path hints.
|
|
12
15
|
*/
|
|
13
16
|
export function extractNextRscData(html) {
|
|
14
17
|
const text = unescapeFlight(html);
|
|
@@ -3,11 +3,23 @@ import type { SummaryLevel } from '../../config/schema.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Derives section child artifacts from a parent page artifact. Returns [] when the page is short
|
|
5
5
|
* or has too few headings to chunk.
|
|
6
|
+
*
|
|
7
|
+
* @param parent - The parent page artifact whose `detailed` Markdown will be split.
|
|
8
|
+
* @param currentTime - Timestamp to embed in child artifact metadata.
|
|
9
|
+
* @param summaryLevel - Extractive summarization level for building each child's `compressed` field.
|
|
10
|
+
* @returns Array of section ResearchArtifacts, empty when the page is below the token threshold.
|
|
6
11
|
*/
|
|
7
12
|
export declare function buildSectionArtifacts(parent: ResearchArtifact, currentTime: Date, summaryLevel: SummaryLevel): ResearchArtifact[];
|
|
8
13
|
/**
|
|
9
14
|
* Regenerates a page's section artifacts: writes fresh children and archives any prior child whose
|
|
10
15
|
* heading no longer exists, so a revalidated parent never leaves orphaned sections active. Returns
|
|
11
16
|
* the number of active section children written.
|
|
17
|
+
*
|
|
18
|
+
* @param dataDir - Root data directory used by `scanCacheDir` and `writeArtifact`.
|
|
19
|
+
* @param parent - The parent page artifact to derive sections from.
|
|
20
|
+
* @param currentTime - Timestamp embedded in the child artifacts.
|
|
21
|
+
* @param summaryLevel - Extractive summarization level for child `compressed` fields.
|
|
22
|
+
* @returns Count of active section children written to disk.
|
|
23
|
+
* @throws {Error} When `writeArtifact` rejects a path or the filesystem write fails.
|
|
12
24
|
*/
|
|
13
25
|
export declare function persistSectionArtifacts(dataDir: string, parent: ResearchArtifact, currentTime: Date, summaryLevel: SummaryLevel): number;
|
|
@@ -16,6 +16,11 @@ function childKey(parentKey, anchor) {
|
|
|
16
16
|
/**
|
|
17
17
|
* Derives section child artifacts from a parent page artifact. Returns [] when the page is short
|
|
18
18
|
* or has too few headings to chunk.
|
|
19
|
+
*
|
|
20
|
+
* @param parent - The parent page artifact whose `detailed` Markdown will be split.
|
|
21
|
+
* @param currentTime - Timestamp to embed in child artifact metadata.
|
|
22
|
+
* @param summaryLevel - Extractive summarization level for building each child's `compressed` field.
|
|
23
|
+
* @returns Array of section ResearchArtifacts, empty when the page is below the token threshold.
|
|
19
24
|
*/
|
|
20
25
|
export function buildSectionArtifacts(parent, currentTime, summaryLevel) {
|
|
21
26
|
if (estimateTokens(parent.detailed) <= SECTION_TOKEN_THRESHOLD)
|
|
@@ -58,6 +63,13 @@ function activeChildrenOf(dataDir, parentKey) {
|
|
|
58
63
|
* Regenerates a page's section artifacts: writes fresh children and archives any prior child whose
|
|
59
64
|
* heading no longer exists, so a revalidated parent never leaves orphaned sections active. Returns
|
|
60
65
|
* the number of active section children written.
|
|
66
|
+
*
|
|
67
|
+
* @param dataDir - Root data directory used by `scanCacheDir` and `writeArtifact`.
|
|
68
|
+
* @param parent - The parent page artifact to derive sections from.
|
|
69
|
+
* @param currentTime - Timestamp embedded in the child artifacts.
|
|
70
|
+
* @param summaryLevel - Extractive summarization level for child `compressed` fields.
|
|
71
|
+
* @returns Count of active section children written to disk.
|
|
72
|
+
* @throws {Error} When `writeArtifact` rejects a path or the filesystem write fails.
|
|
61
73
|
*/
|
|
62
74
|
export function persistSectionArtifacts(dataDir, parent, currentTime, summaryLevel) {
|
|
63
75
|
const children = buildSectionArtifacts(parent, currentTime, summaryLevel);
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
/** A single H2/H3 section chunk extracted from a long Markdown document. */
|
|
1
2
|
export interface SectionChunk {
|
|
2
3
|
anchor: string;
|
|
3
4
|
headingPath: string;
|
|
4
5
|
level: number;
|
|
5
6
|
content: string;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Strips Markdown formatting from a raw heading string, returning plain text suitable for building
|
|
10
|
+
* GitHub-style anchors and breadcrumb labels.
|
|
11
|
+
*
|
|
12
|
+
* @param raw - The heading text as it appears in Markdown (may contain links, code, emphasis).
|
|
13
|
+
* @returns Plain text with links, images, inline code, and emphasis markers removed.
|
|
14
|
+
*/
|
|
7
15
|
export declare function headingPlainText(raw: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Converts plain heading text into a GitHub-compatible anchor slug: lowercase, punctuation
|
|
18
|
+
* removed, spaces replaced with hyphens.
|
|
19
|
+
*
|
|
20
|
+
* @param text - Plain heading text (output of `headingPlainText`).
|
|
21
|
+
* @returns URL-safe anchor slug string.
|
|
22
|
+
*/
|
|
8
23
|
export declare function slugifyHeading(text: string): string;
|
|
9
24
|
/**
|
|
10
25
|
* Splits Markdown into H2/H3 section chunks. Returns an empty array when the document has fewer
|
|
11
26
|
* than two such headings (nothing meaningful to chunk).
|
|
27
|
+
*
|
|
28
|
+
* @param markdown - Full detailed Markdown document to split.
|
|
29
|
+
* @returns Ordered array of H2/H3 section chunks, or an empty array for short/flat documents.
|
|
12
30
|
*/
|
|
13
31
|
export declare function splitMarkdownSections(markdown: string): SectionChunk[];
|
|
@@ -8,6 +8,13 @@ const HEADING_RE = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
|
|
|
8
8
|
// "API documentation" — not the raw link syntax, which otherwise leaks the URL into the anchor and
|
|
9
9
|
// breadcrumb. Confirmed against github-slugger, which documents that it operates on plain heading
|
|
10
10
|
// text rather than parsing Markdown: https://github.com/Flet/github-slugger
|
|
11
|
+
/**
|
|
12
|
+
* Strips Markdown formatting from a raw heading string, returning plain text suitable for building
|
|
13
|
+
* GitHub-style anchors and breadcrumb labels.
|
|
14
|
+
*
|
|
15
|
+
* @param raw - The heading text as it appears in Markdown (may contain links, code, emphasis).
|
|
16
|
+
* @returns Plain text with links, images, inline code, and emphasis markers removed.
|
|
17
|
+
*/
|
|
11
18
|
export function headingPlainText(raw) {
|
|
12
19
|
// The `\(…\)` part tolerates one level of balanced parens so a real-world target like
|
|
13
20
|
// `URL_(disambiguation)` doesn't leave a dangling ")" in the rendered breadcrumb text.
|
|
@@ -20,7 +27,13 @@ export function headingPlainText(raw) {
|
|
|
20
27
|
.replace(/\s+/g, ' ')
|
|
21
28
|
.trim();
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Converts plain heading text into a GitHub-compatible anchor slug: lowercase, punctuation
|
|
32
|
+
* removed, spaces replaced with hyphens.
|
|
33
|
+
*
|
|
34
|
+
* @param text - Plain heading text (output of `headingPlainText`).
|
|
35
|
+
* @returns URL-safe anchor slug string.
|
|
36
|
+
*/
|
|
24
37
|
export function slugifyHeading(text) {
|
|
25
38
|
return text
|
|
26
39
|
.toLowerCase()
|
|
@@ -61,6 +74,9 @@ function breadcrumb(headings, current) {
|
|
|
61
74
|
/**
|
|
62
75
|
* Splits Markdown into H2/H3 section chunks. Returns an empty array when the document has fewer
|
|
63
76
|
* than two such headings (nothing meaningful to chunk).
|
|
77
|
+
*
|
|
78
|
+
* @param markdown - Full detailed Markdown document to split.
|
|
79
|
+
* @returns Ordered array of H2/H3 section chunks, or an empty array for short/flat documents.
|
|
64
80
|
*/
|
|
65
81
|
export function splitMarkdownSections(markdown) {
|
|
66
82
|
const lines = markdown.split('\n');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** A resolved pointer to a public GitHub source file for a documentation page. */
|
|
1
2
|
export interface GithubSource {
|
|
2
3
|
repository: string;
|
|
3
4
|
branch: string;
|
|
@@ -7,13 +8,40 @@ export interface GithubSource {
|
|
|
7
8
|
/**
|
|
8
9
|
* Converts a GitHub `edit`/`blob` URL into a raw.githubusercontent.com URL. Returns null for any
|
|
9
10
|
* URL that is not a recognized GitHub edit/blob link, so callers never fabricate a raw URL.
|
|
11
|
+
*
|
|
12
|
+
* @param href - A GitHub edit or blob URL (or any other string).
|
|
13
|
+
* @returns A GithubSource candidate, or null when `href` is not a recognized edit/blob link.
|
|
10
14
|
*/
|
|
11
15
|
export declare function parseGithubSourceLink(href: string): GithubSource | null;
|
|
16
|
+
/**
|
|
17
|
+
* Maps a Node.js API docs URL to its source file in the nodejs/node GitHub repository.
|
|
18
|
+
* Returns null when the URL is not a recognized Node.js API page.
|
|
19
|
+
*
|
|
20
|
+
* @param url - A nodejs.org API documentation URL.
|
|
21
|
+
* @returns A GithubSource candidate, or null for unrecognized URLs.
|
|
22
|
+
*/
|
|
12
23
|
export declare function mapNodeApiSource(url: string): GithubSource | null;
|
|
24
|
+
/**
|
|
25
|
+
* Maps an MDN developer.mozilla.org URL to its source file in the mdn/content GitHub repository.
|
|
26
|
+
* Returns null when the URL is not a recognized MDN docs page.
|
|
27
|
+
*
|
|
28
|
+
* @param url - An MDN documentation URL.
|
|
29
|
+
* @returns A GithubSource candidate, or null for unrecognized URLs.
|
|
30
|
+
*/
|
|
13
31
|
export declare function mapMdnSource(url: string): GithubSource | null;
|
|
32
|
+
/**
|
|
33
|
+
* Derives the candidate `.md` route URL for a VitePress page. Returns null when the URL already
|
|
34
|
+
* ends with `.md` or cannot be parsed. The result is a candidate that must be validated by fetching.
|
|
35
|
+
*
|
|
36
|
+
* @param url - A VitePress documentation page URL.
|
|
37
|
+
* @returns The derived `.md` route URL, or null for non-applicable URLs.
|
|
38
|
+
*/
|
|
14
39
|
export declare function vitepressRouteMarkdown(url: string): string | null;
|
|
15
40
|
/**
|
|
16
41
|
* Tries every known URL->source mapper in turn. Returns the first candidate, or null. The result
|
|
17
42
|
* is a CANDIDATE; it must be validated by fetching before being recorded as a verified source.
|
|
43
|
+
*
|
|
44
|
+
* @param url - A documentation page URL to map.
|
|
45
|
+
* @returns The first GithubSource candidate, or null when no mapper recognizes the URL.
|
|
18
46
|
*/
|
|
19
47
|
export declare function mapUrlToSource(url: string): GithubSource | null;
|
|
@@ -5,6 +5,9 @@ const GITHUB_EDIT_BLOB = /^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/(?:edit|blo
|
|
|
5
5
|
/**
|
|
6
6
|
* Converts a GitHub `edit`/`blob` URL into a raw.githubusercontent.com URL. Returns null for any
|
|
7
7
|
* URL that is not a recognized GitHub edit/blob link, so callers never fabricate a raw URL.
|
|
8
|
+
*
|
|
9
|
+
* @param href - A GitHub edit or blob URL (or any other string).
|
|
10
|
+
* @returns A GithubSource candidate, or null when `href` is not a recognized edit/blob link.
|
|
8
11
|
*/
|
|
9
12
|
export function parseGithubSourceLink(href) {
|
|
10
13
|
const match = href.match(GITHUB_EDIT_BLOB);
|
|
@@ -25,6 +28,13 @@ export function parseGithubSourceLink(href) {
|
|
|
25
28
|
// Node.js API docs: https://nodejs.org/api/url.html -> nodejs/node/doc/api/url.md on the release
|
|
26
29
|
// line. Deterministic and fixture-proven; mapping is advertised only after a successful fetch.
|
|
27
30
|
const NODE_API = /^https?:\/\/nodejs\.org\/(?:[a-z-]+\/)?(?:docs\/)?(?:latest(?:-v\d+\.x)?\/)?api\/([a-z_]+)\.html/i;
|
|
31
|
+
/**
|
|
32
|
+
* Maps a Node.js API docs URL to its source file in the nodejs/node GitHub repository.
|
|
33
|
+
* Returns null when the URL is not a recognized Node.js API page.
|
|
34
|
+
*
|
|
35
|
+
* @param url - A nodejs.org API documentation URL.
|
|
36
|
+
* @returns A GithubSource candidate, or null for unrecognized URLs.
|
|
37
|
+
*/
|
|
28
38
|
export function mapNodeApiSource(url) {
|
|
29
39
|
const match = url.match(NODE_API);
|
|
30
40
|
if (!match)
|
|
@@ -41,6 +51,13 @@ export function mapNodeApiSource(url) {
|
|
|
41
51
|
// MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/... -> mdn/content
|
|
42
52
|
// files/en-us/web/javascript/.../index.md (content paths are lowercased).
|
|
43
53
|
const MDN_DOCS = /^https?:\/\/developer\.mozilla\.org\/([a-zA-Z-]+)\/docs\/(.+?)\/?$/;
|
|
54
|
+
/**
|
|
55
|
+
* Maps an MDN developer.mozilla.org URL to its source file in the mdn/content GitHub repository.
|
|
56
|
+
* Returns null when the URL is not a recognized MDN docs page.
|
|
57
|
+
*
|
|
58
|
+
* @param url - An MDN documentation URL.
|
|
59
|
+
* @returns A GithubSource candidate, or null for unrecognized URLs.
|
|
60
|
+
*/
|
|
44
61
|
export function mapMdnSource(url) {
|
|
45
62
|
const match = url.match(MDN_DOCS);
|
|
46
63
|
if (!match)
|
|
@@ -59,6 +76,13 @@ export function mapMdnSource(url) {
|
|
|
59
76
|
}
|
|
60
77
|
// VitePress route Markdown: a docs page at /guide/intro.html (or /guide/intro) also serves
|
|
61
78
|
// /guide/intro.md. Returns the candidate `.md` route URL; validate before use (T-24/T-19).
|
|
79
|
+
/**
|
|
80
|
+
* Derives the candidate `.md` route URL for a VitePress page. Returns null when the URL already
|
|
81
|
+
* ends with `.md` or cannot be parsed. The result is a candidate that must be validated by fetching.
|
|
82
|
+
*
|
|
83
|
+
* @param url - A VitePress documentation page URL.
|
|
84
|
+
* @returns The derived `.md` route URL, or null for non-applicable URLs.
|
|
85
|
+
*/
|
|
62
86
|
export function vitepressRouteMarkdown(url) {
|
|
63
87
|
let parsed;
|
|
64
88
|
try {
|
|
@@ -81,6 +105,9 @@ export function vitepressRouteMarkdown(url) {
|
|
|
81
105
|
/**
|
|
82
106
|
* Tries every known URL->source mapper in turn. Returns the first candidate, or null. The result
|
|
83
107
|
* is a CANDIDATE; it must be validated by fetching before being recorded as a verified source.
|
|
108
|
+
*
|
|
109
|
+
* @param url - A documentation page URL to map.
|
|
110
|
+
* @returns The first GithubSource candidate, or null when no mapper recognizes the URL.
|
|
84
111
|
*/
|
|
85
112
|
export function mapUrlToSource(url) {
|
|
86
113
|
return mapNodeApiSource(url) ?? mapMdnSource(url);
|
|
@@ -1,13 +1,46 @@
|
|
|
1
|
+
/** Result of validating a machine-readable artifact body. `reason` is set when `ok` is false. */
|
|
1
2
|
export interface ArtifactValidation {
|
|
2
3
|
ok: boolean;
|
|
3
4
|
reason?: string;
|
|
4
5
|
}
|
|
5
|
-
/** True when short text reads like an error/soft-404 page rather than real content.
|
|
6
|
+
/** True when short text reads like an error/soft-404 page rather than real content.
|
|
7
|
+
*
|
|
8
|
+
* @param text - Body text to inspect (only short bodies trigger the heuristic).
|
|
9
|
+
* @returns True when the text matches an error/soft-404 pattern.
|
|
10
|
+
*/
|
|
6
11
|
export declare function looksLikeErrorPage(text: string): boolean;
|
|
7
|
-
/** Same docs origin guard: a probed artifact must live on the same hostname as the page.
|
|
12
|
+
/** Same docs origin guard: a probed artifact must live on the same hostname as the page.
|
|
13
|
+
*
|
|
14
|
+
* @param candidateUrl - URL of the artifact to validate.
|
|
15
|
+
* @param baseUrl - URL of the original page being researched.
|
|
16
|
+
* @returns True when both URLs share the same hostname.
|
|
17
|
+
*/
|
|
8
18
|
export declare function isSameDocsOrigin(candidateUrl: string, baseUrl: string): boolean;
|
|
9
19
|
/**
|
|
10
20
|
* Validates that an `llms.txt` or route-Markdown body is usable: non-empty, not an HTML page, and
|
|
11
21
|
* not a soft error page. HTML returned for a `.md`/`.txt` probe is the most common false positive.
|
|
22
|
+
*
|
|
23
|
+
* @param body - Raw response body from the probe fetch.
|
|
24
|
+
* @returns `{ ok: true }` when the body is valid, or `{ ok: false, reason }` explaining the failure.
|
|
12
25
|
*/
|
|
13
26
|
export declare function validateTextArtifact(body: string): ArtifactValidation;
|
|
27
|
+
/** The subset of a fetch response a Markdown-twin probe needs to validate. */
|
|
28
|
+
export interface MarkdownTwinResponse {
|
|
29
|
+
contentType: string | null;
|
|
30
|
+
finalUrl: string;
|
|
31
|
+
content: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates a probed `.md`-route response as a trustworthy Markdown twin, the shared trust
|
|
35
|
+
* contract behind both the developer.salesforce.com and help.salesforce.com twin probes: the
|
|
36
|
+
* server must label it `text/markdown`, the redirect chain must land on the expected host over
|
|
37
|
+
* https (never a plain-http downgrade or an on-path host), and the body must pass
|
|
38
|
+
* {@link validateTextArtifact} (non-empty, non-HTML, not a soft-error page). A 200 HTML "not
|
|
39
|
+
* found" shell — the most common false positive for a `.md` probe — fails the content-type check
|
|
40
|
+
* before the body is even inspected.
|
|
41
|
+
*
|
|
42
|
+
* @param res - The probe response's content-type, final URL after redirects, and body.
|
|
43
|
+
* @param allowedHost - Hostname the redirect chain must land on (compared case-insensitively).
|
|
44
|
+
* @returns True when the response is a trustworthy Markdown twin.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isValidatedMarkdownTwin(res: MarkdownTwinResponse, allowedHost: string): boolean;
|