@nebulacomponents/citable 1.11.0 → 1.12.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/CHANGELOG.md +11 -0
- package/README.md +6 -1
- package/dist/universal/.agents/skills/citable/SKILL.md +3 -1
- package/dist/universal/.agents/skills/citable/VERSION +1 -1
- package/dist/universal/.agents/skills/citable/commands/README.md +1 -1
- package/dist/universal/.agents/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.agents/skills/citable/manifest.json +9 -9
- package/dist/universal/.agents/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.agents/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.claude/skills/citable/SKILL.md +3 -1
- package/dist/universal/.claude/skills/citable/VERSION +1 -1
- package/dist/universal/.claude/skills/citable/commands/README.md +1 -1
- package/dist/universal/.claude/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.claude/skills/citable/manifest.json +9 -9
- package/dist/universal/.claude/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.claude/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.cursor/skills/citable/SKILL.md +3 -1
- package/dist/universal/.cursor/skills/citable/VERSION +1 -1
- package/dist/universal/.cursor/skills/citable/commands/README.md +1 -1
- package/dist/universal/.cursor/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.cursor/skills/citable/manifest.json +9 -9
- package/dist/universal/.cursor/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.cursor/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.gemini/skills/citable/SKILL.md +3 -1
- package/dist/universal/.gemini/skills/citable/VERSION +1 -1
- package/dist/universal/.gemini/skills/citable/commands/README.md +1 -1
- package/dist/universal/.gemini/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.gemini/skills/citable/manifest.json +9 -9
- package/dist/universal/.gemini/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.gemini/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.github/skills/citable/SKILL.md +3 -1
- package/dist/universal/.github/skills/citable/VERSION +1 -1
- package/dist/universal/.github/skills/citable/commands/README.md +1 -1
- package/dist/universal/.github/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.github/skills/citable/manifest.json +9 -9
- package/dist/universal/.github/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.github/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.kiro/skills/citable/SKILL.md +3 -1
- package/dist/universal/.kiro/skills/citable/VERSION +1 -1
- package/dist/universal/.kiro/skills/citable/commands/README.md +1 -1
- package/dist/universal/.kiro/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.kiro/skills/citable/manifest.json +9 -9
- package/dist/universal/.kiro/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.kiro/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.opencode/skills/citable/SKILL.md +3 -1
- package/dist/universal/.opencode/skills/citable/VERSION +1 -1
- package/dist/universal/.opencode/skills/citable/commands/README.md +1 -1
- package/dist/universal/.opencode/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.opencode/skills/citable/manifest.json +9 -9
- package/dist/universal/.opencode/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.opencode/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.pi/agent/skills/citable/SKILL.md +3 -1
- package/dist/universal/.pi/agent/skills/citable/VERSION +1 -1
- package/dist/universal/.pi/agent/skills/citable/commands/README.md +1 -1
- package/dist/universal/.pi/agent/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.pi/agent/skills/citable/manifest.json +9 -9
- package/dist/universal/.pi/agent/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.pi/agent/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.qoder/skills/citable/SKILL.md +3 -1
- package/dist/universal/.qoder/skills/citable/VERSION +1 -1
- package/dist/universal/.qoder/skills/citable/commands/README.md +1 -1
- package/dist/universal/.qoder/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.qoder/skills/citable/manifest.json +9 -9
- package/dist/universal/.qoder/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.qoder/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.rovodev/skills/citable/SKILL.md +3 -1
- package/dist/universal/.rovodev/skills/citable/VERSION +1 -1
- package/dist/universal/.rovodev/skills/citable/commands/README.md +1 -1
- package/dist/universal/.rovodev/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.rovodev/skills/citable/manifest.json +9 -9
- package/dist/universal/.rovodev/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.rovodev/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.trae/skills/citable/SKILL.md +3 -1
- package/dist/universal/.trae/skills/citable/VERSION +1 -1
- package/dist/universal/.trae/skills/citable/commands/README.md +1 -1
- package/dist/universal/.trae/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.trae/skills/citable/manifest.json +9 -9
- package/dist/universal/.trae/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.trae/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/.trae-cn/skills/citable/SKILL.md +3 -1
- package/dist/universal/.trae-cn/skills/citable/VERSION +1 -1
- package/dist/universal/.trae-cn/skills/citable/commands/README.md +1 -1
- package/dist/universal/.trae-cn/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.trae-cn/skills/citable/manifest.json +9 -9
- package/dist/universal/.trae-cn/skills/citable/references/aeo-geo-validation.md +1 -1
- package/dist/universal/.trae-cn/skills/citable/references/capability-boundaries.md +2 -0
- package/dist/universal/manifest.json +99 -99
- package/package.json +9 -1
- package/skill/SKILL.md +3 -1
- package/skill/commands/README.md +1 -1
- package/skill/commands/observe-and-act.md +8 -1
- package/skill/references/aeo-geo-validation.md +1 -1
- package/skill/references/capability-boundaries.md +2 -0
- package/src/cli/index.js +6 -0
- package/src/commands/observe.js +118 -28
package/skill/SKILL.md
CHANGED
|
@@ -7,7 +7,7 @@ description: >
|
|
|
7
7
|
generative engine optimization, structured data governance, claim substantiation,
|
|
8
8
|
crawler policy, entity consistency, content discoverability, or wants a site audited
|
|
9
9
|
for how search and AI systems will retrieve, understand, cite, or recommend it.
|
|
10
|
-
version: 1.
|
|
10
|
+
version: 1.12.0
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
# Citable — evidence and change control for search and AI citation readiness
|
|
@@ -96,6 +96,8 @@ citable compare-snapshots [runA runB]
|
|
|
96
96
|
citable action-plan [run-id] # ordered actions, blockers, semantic gates, verification
|
|
97
97
|
citable observe <mode> [options] # render/index/citation/log/passage/consensus/performance evidence
|
|
98
98
|
citable observe bing --dataset <search_performance|ai_performance> --input <csv|json>
|
|
99
|
+
citable observe render --target <url> [--interactions] [--resume-run <run-id>]
|
|
100
|
+
citable observe performance --target <url> --lighthouse [--repeat 1..5]
|
|
99
101
|
citable apply --input <spec> [--write] # reviewed, hash-locked remediation; dry run by default
|
|
100
102
|
citable monitor [runA runB] # observation regression alerts
|
|
101
103
|
citable metrics import --provider <name> --input <csv|json>
|
package/skill/commands/README.md
CHANGED
|
@@ -34,7 +34,7 @@ intent, not executability, so statuses are strict:
|
|
|
34
34
|
| /citable ingest, map-site, map-queries, map-prompts, map-entities, map-evidence | specified (ingest.md) |
|
|
35
35
|
| /citable optimize-page | specified (optimize-page.md) — requires source-to-render mapping, claim-preserving rewrites, build execution, rollback; none of that is proven yet |
|
|
36
36
|
| /citable create-page, answer-block, architect, interlink, consolidate, metadata | specified (page-work.md) |
|
|
37
|
-
| /citable validate-render | partially implemented by `observe render`; mobile/
|
|
37
|
+
| /citable validate-render | partially implemented by `observe render`; desktop/mobile/JavaScript-disabled profiles and bounded interaction exploration are implemented, while cross-browser and application-specific journeys remain |
|
|
38
38
|
| /citable measure seo/aeo/geo, test-prompts, monitor-crawlers, monitor-contradictions | partially implemented by metric/observation imports, objective evaluation, Google/CrUX live APIs, custom citation adapters, and monitor comparisons |
|
|
39
39
|
|
|
40
40
|
Shared refusal conditions (all commands): any action that would fabricate
|
|
@@ -9,7 +9,11 @@ failure_behaviour: unavailable dependency, credential, source run, reviewer, exa
|
|
|
9
9
|
## Collection modes
|
|
10
10
|
|
|
11
11
|
- `observe render --target <URL>` uses optional Playwright. Browser evidence is
|
|
12
|
-
not search-index evidence.
|
|
12
|
+
not search-index evidence. It captures independent desktop, mobile, and
|
|
13
|
+
JavaScript-disabled profiles. `--interactions` exercises at most 20 visible
|
|
14
|
+
disclosure, inactive-tab, and load-more-like controls; it does not prove an
|
|
15
|
+
application-specific journey. `--resume-run` reuses only successful profile
|
|
16
|
+
observations from the named immutable run and recollects failed/absent ones.
|
|
13
17
|
- `observe index --input <JSON>` imports owner exports. With `--target`,
|
|
14
18
|
`--site-url`, and `GSC_ACCESS_TOKEN`, it calls Google URL Inspection, which
|
|
15
19
|
reports the indexed version rather than performing a live indexability test.
|
|
@@ -21,6 +25,9 @@ failure_behaviour: unavailable dependency, credential, source run, reviewer, exa
|
|
|
21
25
|
without IP verification remain low confidence.
|
|
22
26
|
- `observe passages|consensus --target <dir|URL>` performs static extraction.
|
|
23
27
|
- `observe performance` imports evidence or calls CrUX with `CRUX_API_KEY`.
|
|
28
|
+
`--lighthouse` instead performs 1-5 local lab runs (default 3) using optional
|
|
29
|
+
`lighthouse` and `chrome-launcher` peers, preserving each result and a median
|
|
30
|
+
summary. Lab evidence remains separate from CrUX field evidence.
|
|
24
31
|
- `observe corroboration --input <JSON>` records observable external mentions;
|
|
25
32
|
controlled or unverified sources do not become authority claims.
|
|
26
33
|
|
|
@@ -9,7 +9,7 @@ not a prediction of citation or recommendation. Report every row as
|
|
|
9
9
|
| State | Current evidence boundary |
|
|
10
10
|
| --- | --- |
|
|
11
11
|
| Retrieval eligibility | Static policy plus captured synthetic HTTP response; crawler identity remains simulated unless verified logs/IP evidence are supplied |
|
|
12
|
-
| Source extraction and support suitability | Initial
|
|
12
|
+
| Source extraction and support suitability | Initial HTML plus registries/detectors/rubrics; optional Chromium profiles can establish bounded raw/desktop/mobile/JavaScript-disabled parity, while cross-browser and application-specific journeys remain unproven |
|
|
13
13
|
| Observed citation behavior | Operator-supplied prompt-result observations only; report cohort size and property citation presence, never infer from readiness |
|
|
14
14
|
|
|
15
15
|
## AEO checks
|
|
@@ -9,6 +9,8 @@ Use the narrowest supported state. Never promote evidence across rows.
|
|
|
9
9
|
| Verified crawler reached edge | Imported evidence | `observe logs` record plus provider-published IP verification where supported |
|
|
10
10
|
| Observed in production logs | Imported evidence | Timestamped `observe logs` artifact with URL, status, bytes, latency, cache result, UA, and verification result |
|
|
11
11
|
| Indexed | Google API or imported evidence | `observe index`; Google inspection covers the indexed version, other engines require owner exports |
|
|
12
|
+
| Rendered profile observed | Optional local browser evidence | Successful profile-specific Chromium DOM, text, screenshot, failed requests, interactions, viewport, and configuration; failed profiles remain independent |
|
|
13
|
+
| Render parity compared | Bounded local comparison | Raw/desktop and mobile/desktop word ratios from the same run or explicitly resumed immutable profiles; not semantic equivalence |
|
|
12
14
|
| Returned by retrieval | Operator supplied | Provider observation containing retrieved source URL |
|
|
13
15
|
| Cited | Import or disclosed adapter | Complete `observe citations` answer with citation URL and product/adapter mode |
|
|
14
16
|
| Materially supports answer | Human review required | `citation_review` maps answer claim to source passage and names the reviewer |
|
package/src/cli/index.js
CHANGED
|
@@ -84,6 +84,9 @@ Options
|
|
|
84
84
|
--access-token <token> OAuth token (prefer provider environment variables)
|
|
85
85
|
--endpoint <url> Controlled citation adapter endpoint
|
|
86
86
|
--repeat <count> Repetitions per prompt for citation experiments
|
|
87
|
+
--interactions Exercise bounded disclosure, tab, and load-more controls
|
|
88
|
+
--resume-run <run-id> Reuse successful immutable render profiles
|
|
89
|
+
--lighthouse Run local, repeated Lighthouse lab observations
|
|
87
90
|
--ocr Explicitly request optional OCR for media images
|
|
88
91
|
--write Persist registry changes (map-claims, substantiate)
|
|
89
92
|
--json Machine-readable output only
|
|
@@ -98,6 +101,8 @@ function parseArgs(argv) {
|
|
|
98
101
|
if (a === '--write') args.write = true;
|
|
99
102
|
else if (a === '--json') args.json = true;
|
|
100
103
|
else if (a === '--ocr') args.ocr = true;
|
|
104
|
+
else if (a === '--interactions') args.interactions = true;
|
|
105
|
+
else if (a === '--lighthouse') args.lighthouse = true;
|
|
101
106
|
else if (a === '--target') args.target = argv[++i];
|
|
102
107
|
else if (a === '--base-url') args.baseUrl = argv[++i];
|
|
103
108
|
else if (a === '--ref-date') args.refDate = argv[++i];
|
|
@@ -114,6 +119,7 @@ function parseArgs(argv) {
|
|
|
114
119
|
else if (a === '--access-token') args.accessToken = argv[++i];
|
|
115
120
|
else if (a === '--endpoint') args.endpoint = argv[++i];
|
|
116
121
|
else if (a === '--repeat') args.repeat = Number(argv[++i]);
|
|
122
|
+
else if (a === '--resume-run') args.resumeRun = argv[++i];
|
|
117
123
|
else if (a === '--timeout') args.timeout = Number(argv[++i]);
|
|
118
124
|
else if (a === '--force') args.force = true;
|
|
119
125
|
else args._.push(a);
|
package/src/commands/observe.js
CHANGED
|
@@ -32,37 +32,59 @@ function canonicalReview(raw, targetOrigin) {
|
|
|
32
32
|
|
|
33
33
|
async function observeRender(root, options) {
|
|
34
34
|
if (!options.target || !/^https?:\/\//.test(options.target)) throw new Error('render requires --target <http(s) URL>');
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const profileNames = ['desktop', 'mobile', 'javascript_disabled'];
|
|
36
|
+
let reused = [], previousRaw = null;
|
|
37
|
+
if (options.resumeRun) {
|
|
38
|
+
const previousDir = path.join(root, '.citable', 'runs', options.resumeRun);
|
|
39
|
+
const observationsDir = path.join(previousDir, 'observations');
|
|
40
|
+
if (!fs.existsSync(observationsDir)) throw new Error(`resume run ${options.resumeRun} has no observations`);
|
|
41
|
+
reused = fs.readdirSync(observationsDir).filter((name) => name.endsWith('-render.json')).map((name) => JSON.parse(fs.readFileSync(path.join(observationsDir, name)))).filter((item) => item.state === 'observed' && profileNames.includes(item.data.profile) && item.data.url === options.target && Boolean(item.data.interaction_execution_requested) === Boolean(options.interactions));
|
|
42
|
+
previousRaw = fs.readFileSync(path.join(previousDir, 'manifest.json'), 'utf8');
|
|
43
|
+
}
|
|
44
|
+
let browser = null;
|
|
45
|
+
let capture = options.captureProfile;
|
|
46
|
+
if (!capture) {
|
|
47
|
+
let playwright;
|
|
48
|
+
try { playwright = await import('playwright'); } catch {
|
|
49
|
+
const item = envelope('render', { url: options.target }, { method: 'browser', source: 'playwright', state: 'not_evidenced', confidence: 'unknown', limitations: ['Optional Playwright dependency is not installed.'] });
|
|
50
|
+
return observationRun(root, 'observe render', options.target, [item], { incomplete: ['Rendered DOM capture unavailable: install Playwright and a Chromium browser.'] });
|
|
51
|
+
}
|
|
52
|
+
browser = await playwright.chromium.launch({ headless: true });
|
|
39
53
|
}
|
|
40
|
-
const initial = await fetchUrl(options.target, { timeoutMs: options.timeout || 30000, maxRetries: 1 });
|
|
41
|
-
const browser = await playwright.chromium.launch({ headless: true });
|
|
42
54
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (!capture) {
|
|
56
|
+
capture = async (name, viewport, { isMobile = false, javaScriptEnabled = true } = {}) => {
|
|
57
|
+
const context = await browser.newContext({ viewport, isMobile, javaScriptEnabled });
|
|
58
|
+
try {
|
|
59
|
+
const page = await context.newPage();
|
|
60
|
+
const failures = [];
|
|
61
|
+
page.on('requestfailed', (request) => failures.push({ url: request.url(), error: request.failure()?.errorText || 'unknown' }));
|
|
62
|
+
const response = await page.goto(options.target, { waitUntil: 'networkidle', timeout: options.timeout || 30000 });
|
|
63
|
+
const discovered = await page.locator('details > summary,[aria-expanded=false],[role=tab][aria-selected=false],button').evaluateAll((nodes) => nodes.map((node) => ({ tag: node.tagName.toLowerCase(), text: (node.textContent || '').trim().slice(0, 120), role: node.getAttribute('role'), expanded: node.getAttribute('aria-expanded') })).filter((item) => item.tag !== 'button' || /load more|show more|view more/i.test(item.text)));
|
|
64
|
+
const executed = [];
|
|
65
|
+
if (options.interactions) {
|
|
66
|
+
const controls = page.locator('details:not([open]) > summary,[aria-expanded=false],[role=tab][aria-selected=false],button');
|
|
67
|
+
for (let i = 0; i < Math.min(await controls.count(), 20); i++) { const control = controls.nth(i); const label = ((await control.textContent()) || '').trim(); if ((await control.evaluate((node) => node.tagName.toLowerCase())) === 'button' && !/load more|show more|view more/i.test(label)) continue; try { await control.click({ timeout: 2000 }); executed.push(label.slice(0, 120) || `control-${i + 1}`); } catch { executed.push(`failed:${label.slice(0, 100) || i + 1}`); } }
|
|
68
|
+
}
|
|
69
|
+
const html = await page.content(), text = await page.locator('body').innerText(), screenshot = await page.screenshot({ fullPage: true });
|
|
70
|
+
return { name, final_url: page.url(), status: response?.status() ?? null, viewport, javaScriptEnabled, html, text, screenshot, failed_requests: failures, interactions: { discovered, executed } };
|
|
71
|
+
} finally {
|
|
72
|
+
await context.close();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const initial = await (options.fetchUrl || fetchUrl)(options.target, { timeoutMs: options.timeout || 30000, maxRetries: 1 });
|
|
56
77
|
const initialText = initial.body.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, ' ').replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, ' ').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
const observations = [...reused], artifacts = { 'initial/response.html': initial.body }, incomplete = [];
|
|
79
|
+
const profiles = [{ name: 'desktop', viewport: { width: 1280, height: 900 } }, { name: 'mobile', viewport: { width: 390, height: 844 }, settings: { isMobile: true } }, { name: 'javascript_disabled', viewport: { width: 1280, height: 900 }, settings: { javaScriptEnabled: false } }];
|
|
80
|
+
for (const profile of profiles.filter((item) => !reused.some((old) => old.data.profile === item.name))) {
|
|
81
|
+
try { const result = await capture(profile.name, profile.viewport, profile.settings); const count = words(result.text).length; const data = { url: options.target, profile: profile.name, final_url: result.final_url, status: result.status, viewport: result.viewport, javascript_enabled: result.javaScriptEnabled, interaction_execution_requested: Boolean(options.interactions), html_hash: sha256(result.html), text_hash: sha256(result.text), word_count: count, raw_http_word_ratio: count ? Number((words(initialText).length / count).toFixed(3)) : null, failed_requests: result.failed_requests, interactions: result.interactions }; observations.push(envelope('render', data, { method: 'browser', source: 'playwright/chromium', raw: result.html, limitations: result.interactions.executed.length ? ['Interactions were bounded to disclosure, tab, and load-more-like controls; application-specific journeys remain untested.'] : [] })); artifacts[`rendered/${profile.name}-dom.html`] = result.html; artifacts[`rendered/${profile.name}-text.txt`] = result.text; artifacts[`screenshots/${profile.name}.png`] = result.screenshot; }
|
|
82
|
+
catch (error) { incomplete.push(`${profile.name} render failed: ${error.message}`); observations.push(envelope('render', { url: options.target, profile: profile.name }, { method: 'browser', source: 'playwright/chromium', state: 'failed', confidence: 'confirmed', raw: `${profile.name}:${error.message}`, limitations: [error.message] })); }
|
|
83
|
+
}
|
|
84
|
+
const desktop = observations.find((item) => item.data.profile === 'desktop' && item.state === 'observed'), mobile = observations.find((item) => item.data.profile === 'mobile' && item.state === 'observed');
|
|
85
|
+
observations.push(envelope('render', { url: options.target, profile: 'parity', raw_http_to_desktop_word_ratio: desktop?.data.raw_http_word_ratio ?? null, mobile_to_desktop_word_ratio: desktop?.data.word_count && mobile?.data.word_count ? Number((mobile.data.word_count / desktop.data.word_count).toFixed(3)) : null, resumed_from_run_id: options.resumeRun || null }, { method: 'static_analysis', source: options.target, state: desktop && mobile ? 'observed' : 'incomplete', confidence: 'high', limitations: desktop && mobile ? [] : ['Desktop/mobile parity is incomplete because one or more profiles failed.'] }));
|
|
86
|
+
return observationRun(root, 'observe render', options.target, observations, { rawInputs: previousRaw ? { resumed_manifest: previousRaw } : {}, incomplete, warnings: reused.length ? [`${reused.length} successful profile(s) reused from immutable run ${options.resumeRun}; failed, absent, or configuration-mismatched profiles were recollected.`] : options.resumeRun ? [`No compatible successful profiles were reusable from immutable run ${options.resumeRun}; all profiles were recollected.`] : [], artifacts });
|
|
87
|
+
} finally { if (browser) await browser.close(); }
|
|
66
88
|
}
|
|
67
89
|
|
|
68
90
|
async function observeIndex(root, options) {
|
|
@@ -248,7 +270,75 @@ async function observeConsensus(root, options) {
|
|
|
248
270
|
return observationRun(root, 'observe consensus', options.target, observations);
|
|
249
271
|
}
|
|
250
272
|
|
|
273
|
+
const median = (values) => {
|
|
274
|
+
const sorted = values.filter(Number.isFinite).sort((a, b) => a - b);
|
|
275
|
+
if (!sorted.length) return null;
|
|
276
|
+
const middle = Math.floor(sorted.length / 2);
|
|
277
|
+
return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function lighthouseMetrics(lhr) {
|
|
281
|
+
const audits = lhr.audits || {};
|
|
282
|
+
const value = (id) => Number.isFinite(audits[id]?.numericValue) ? audits[id].numericValue : null;
|
|
283
|
+
return {
|
|
284
|
+
performance_score: Number.isFinite(lhr.categories?.performance?.score) ? lhr.categories.performance.score : null,
|
|
285
|
+
first_contentful_paint_ms: value('first-contentful-paint'),
|
|
286
|
+
largest_contentful_paint_ms: value('largest-contentful-paint'),
|
|
287
|
+
cumulative_layout_shift: value('cumulative-layout-shift'),
|
|
288
|
+
total_blocking_time_ms: value('total-blocking-time'),
|
|
289
|
+
speed_index_ms: value('speed-index'),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function localLighthouseRunner(target, runIndex, options) {
|
|
294
|
+
let lighthouse, launcher;
|
|
295
|
+
try {
|
|
296
|
+
({ default: lighthouse } = await import('lighthouse'));
|
|
297
|
+
launcher = await import('chrome-launcher');
|
|
298
|
+
} catch {
|
|
299
|
+
throw new Error('optional lighthouse and chrome-launcher dependencies are not installed');
|
|
300
|
+
}
|
|
301
|
+
const chrome = await launcher.launch({ chromeFlags: ['--headless', '--no-sandbox', '--disable-gpu'] });
|
|
302
|
+
try {
|
|
303
|
+
const result = await lighthouse(target, { port: chrome.port, output: 'json', logLevel: 'error', formFactor: options.deviceProfile || 'mobile' });
|
|
304
|
+
return result.lhr;
|
|
305
|
+
} finally {
|
|
306
|
+
await chrome.kill();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function observeLighthouse(root, options) {
|
|
311
|
+
if (!/^https?:\/\//.test(options.target || '')) throw new Error('Lighthouse requires --target <http(s) URL>');
|
|
312
|
+
const repeat = Number.isInteger(options.repeat) && options.repeat >= 1 && options.repeat <= 5 ? options.repeat : 3;
|
|
313
|
+
const runner = options.lighthouseRunner || localLighthouseRunner;
|
|
314
|
+
const observations = [], artifacts = {}, incomplete = [];
|
|
315
|
+
for (let runIndex = 1; runIndex <= repeat; runIndex++) {
|
|
316
|
+
try {
|
|
317
|
+
const lhr = await runner(options.target, runIndex, options);
|
|
318
|
+
const metrics = lighthouseMetrics(lhr);
|
|
319
|
+
const data = {
|
|
320
|
+
url: options.target, provider: 'Lighthouse', evidence_type: 'lab', run_index: runIndex, runs_in_series: repeat,
|
|
321
|
+
lighthouse_version: lhr.lighthouseVersion || null, chrome_user_agent: lhr.userAgent || null, fetched_at: lhr.fetchTime || null,
|
|
322
|
+
final_url: lhr.finalDisplayedUrl || lhr.finalUrl || options.target,
|
|
323
|
+
configuration: { form_factor: lhr.configSettings?.formFactor || null, throttling_method: lhr.configSettings?.throttlingMethod || null, screen_emulation: lhr.configSettings?.screenEmulation || null, throttling: lhr.configSettings?.throttling || null },
|
|
324
|
+
metrics,
|
|
325
|
+
};
|
|
326
|
+
observations.push(envelope('performance', data, { method: 'browser', source: 'lighthouse/local', raw: JSON.stringify(lhr), limitations: ['This is controlled lab evidence, not field performance or a guarantee of user experience.'] }));
|
|
327
|
+
artifacts[`lighthouse/run-${String(runIndex).padStart(2, '0')}.json`] = JSON.stringify(lhr, null, 2);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
incomplete.push(`Lighthouse run ${runIndex} failed: ${error.message}`);
|
|
330
|
+
observations.push(envelope('performance', { url: options.target, provider: 'Lighthouse', evidence_type: 'lab', run_index: runIndex, runs_in_series: repeat }, { method: 'browser', source: 'lighthouse/local', state: 'failed', confidence: 'confirmed', raw: `run-${runIndex}:${error.message}`, limitations: [error.message] }));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const successful = observations.filter((item) => item.state === 'observed');
|
|
334
|
+
const metricNames = ['performance_score', 'first_contentful_paint_ms', 'largest_contentful_paint_ms', 'cumulative_layout_shift', 'total_blocking_time_ms', 'speed_index_ms'];
|
|
335
|
+
const medians = Object.fromEntries(metricNames.map((name) => [name, median(successful.map((item) => item.data.metrics[name]))]));
|
|
336
|
+
observations.push(envelope('performance', { url: options.target, provider: 'Lighthouse', evidence_type: 'lab_summary', requested_runs: repeat, successful_runs: successful.length, median_metrics: medians }, { method: 'static_analysis', source: 'lighthouse/local', state: successful.length ? 'observed' : 'not_evidenced', confidence: successful.length === repeat ? 'high' : 'low', limitations: ['Medians summarize only successful controlled lab runs; failed runs remain separate evidence.'] }));
|
|
337
|
+
return observationRun(root, 'observe performance --lighthouse', options.target, observations, { incomplete, artifacts });
|
|
338
|
+
}
|
|
339
|
+
|
|
251
340
|
async function observePerformance(root, options) {
|
|
341
|
+
if (options.lighthouse) return observeLighthouse(root, options);
|
|
252
342
|
if (options.input) {
|
|
253
343
|
const input = readInput(options.input);
|
|
254
344
|
const rows = Array.isArray(input.value) ? input.value : [input.value];
|