@nebulacomponents/citable 1.10.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 +22 -0
- package/README.md +9 -1
- package/dist/universal/.agents/skills/citable/SKILL.md +4 -1
- package/dist/universal/.agents/skills/citable/VERSION +1 -1
- package/dist/universal/.agents/skills/citable/commands/README.md +2 -1
- package/dist/universal/.agents/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.agents/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.agents/skills/citable/manifest.json +12 -10
- 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/.agents/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.agents/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.claude/skills/citable/SKILL.md +4 -1
- package/dist/universal/.claude/skills/citable/VERSION +1 -1
- package/dist/universal/.claude/skills/citable/commands/README.md +2 -1
- package/dist/universal/.claude/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.claude/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.claude/skills/citable/manifest.json +12 -10
- 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/.claude/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.claude/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.cursor/skills/citable/SKILL.md +4 -1
- package/dist/universal/.cursor/skills/citable/VERSION +1 -1
- package/dist/universal/.cursor/skills/citable/commands/README.md +2 -1
- package/dist/universal/.cursor/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.cursor/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.cursor/skills/citable/manifest.json +12 -10
- 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/.cursor/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.cursor/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.gemini/skills/citable/SKILL.md +4 -1
- package/dist/universal/.gemini/skills/citable/VERSION +1 -1
- package/dist/universal/.gemini/skills/citable/commands/README.md +2 -1
- package/dist/universal/.gemini/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.gemini/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.gemini/skills/citable/manifest.json +12 -10
- 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/.gemini/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.gemini/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.github/skills/citable/SKILL.md +4 -1
- package/dist/universal/.github/skills/citable/VERSION +1 -1
- package/dist/universal/.github/skills/citable/commands/README.md +2 -1
- package/dist/universal/.github/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.github/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.github/skills/citable/manifest.json +12 -10
- 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/.github/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.github/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.kiro/skills/citable/SKILL.md +4 -1
- package/dist/universal/.kiro/skills/citable/VERSION +1 -1
- package/dist/universal/.kiro/skills/citable/commands/README.md +2 -1
- package/dist/universal/.kiro/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.kiro/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.kiro/skills/citable/manifest.json +12 -10
- 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/.kiro/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.kiro/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.opencode/skills/citable/SKILL.md +4 -1
- package/dist/universal/.opencode/skills/citable/VERSION +1 -1
- package/dist/universal/.opencode/skills/citable/commands/README.md +2 -1
- package/dist/universal/.opencode/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.opencode/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.opencode/skills/citable/manifest.json +12 -10
- 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/.opencode/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.opencode/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.pi/agent/skills/citable/SKILL.md +4 -1
- package/dist/universal/.pi/agent/skills/citable/VERSION +1 -1
- package/dist/universal/.pi/agent/skills/citable/commands/README.md +2 -1
- package/dist/universal/.pi/agent/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.pi/agent/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.pi/agent/skills/citable/manifest.json +12 -10
- 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/.pi/agent/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.pi/agent/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.qoder/skills/citable/SKILL.md +4 -1
- package/dist/universal/.qoder/skills/citable/VERSION +1 -1
- package/dist/universal/.qoder/skills/citable/commands/README.md +2 -1
- package/dist/universal/.qoder/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.qoder/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.qoder/skills/citable/manifest.json +12 -10
- 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/.qoder/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.qoder/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.rovodev/skills/citable/SKILL.md +4 -1
- package/dist/universal/.rovodev/skills/citable/VERSION +1 -1
- package/dist/universal/.rovodev/skills/citable/commands/README.md +2 -1
- package/dist/universal/.rovodev/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.rovodev/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.rovodev/skills/citable/manifest.json +12 -10
- 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/.rovodev/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.rovodev/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.trae/skills/citable/SKILL.md +4 -1
- package/dist/universal/.trae/skills/citable/VERSION +1 -1
- package/dist/universal/.trae/skills/citable/commands/README.md +2 -1
- package/dist/universal/.trae/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.trae/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.trae/skills/citable/manifest.json +12 -10
- 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/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.trae/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/.trae-cn/skills/citable/SKILL.md +4 -1
- package/dist/universal/.trae-cn/skills/citable/VERSION +1 -1
- package/dist/universal/.trae-cn/skills/citable/commands/README.md +2 -1
- package/dist/universal/.trae-cn/skills/citable/commands/media-evidence.md +17 -0
- package/dist/universal/.trae-cn/skills/citable/commands/observe-and-act.md +8 -1
- package/dist/universal/.trae-cn/skills/citable/manifest.json +12 -10
- 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/.trae-cn/skills/citable/schemas/media-manifest.schema.json +2 -0
- package/dist/universal/.trae-cn/skills/citable/schemas/observation.schema.json +1 -1
- package/dist/universal/manifest.json +147 -123
- package/package.json +16 -3
- package/schemas/media-manifest.schema.json +2 -0
- package/schemas/observation.schema.json +1 -1
- package/skill/SKILL.md +4 -1
- package/skill/commands/README.md +2 -1
- package/skill/commands/media-evidence.md +17 -0
- 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 +9 -1
- package/src/commands/observe.js +121 -29
- package/src/observations/media.js +75 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebulacomponents/citable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Production-grade SEO, AEO, and GEO agent skill with auditable detection, claim governance, evidence validation, and multi-agent installation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"seo",
|
|
@@ -90,14 +90,27 @@
|
|
|
90
90
|
"ajv-formats": "^3.0.1",
|
|
91
91
|
"csv-parse": "^7.0.1",
|
|
92
92
|
"js-yaml": "^5.2.1",
|
|
93
|
-
"node-html-parser": "^9.0.0"
|
|
93
|
+
"node-html-parser": "^9.0.0",
|
|
94
|
+
"pdfjs-dist": "^6.1.200"
|
|
94
95
|
},
|
|
95
96
|
"peerDependencies": {
|
|
96
|
-
"
|
|
97
|
+
"chrome-launcher": ">=1.2.1",
|
|
98
|
+
"lighthouse": ">=13.4.0",
|
|
99
|
+
"playwright": ">=1.50.0",
|
|
100
|
+
"tesseract.js": ">=7.0.0"
|
|
97
101
|
},
|
|
98
102
|
"peerDependenciesMeta": {
|
|
103
|
+
"chrome-launcher": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"lighthouse": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
99
109
|
"playwright": {
|
|
100
110
|
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"tesseract.js": {
|
|
113
|
+
"optional": true
|
|
101
114
|
}
|
|
102
115
|
}
|
|
103
116
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id":"citable://schemas/media-manifest.schema.json","$schema":"http://json-schema.org/draft-07/schema#","title":"Media evidence import manifest","type":"object","additionalProperties":false,"required":["version","items"],"properties":{"version":{"const":1},"items":{"type":"array","minItems":1,"items":{"type":"object","additionalProperties":false,"required":["media_id","type","path","source_url","page_url","claim_ids","permission_status"],"properties":{"media_id":{"type":"string","pattern":"^MEDIA-[A-Z0-9][A-Z0-9_-]*$"},"type":{"type":"string","enum":["pdf","transcript","image"]},"path":{"type":"string","minLength":1},"source_url":{"type":["string","null"]},"page_url":{"type":["string","null"]},"claim_ids":{"type":"array","uniqueItems":true,"items":{"type":"string"}},"permission_status":{"type":"string","enum":["owner_authorized","licensed","public_unknown","internal"]},"image_src":{"type":"string"},"language":{"type":"string"},"published_at":{"type":"string","format":"date-time"}}}}}}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"required": ["observation_id", "kind", "state", "collected_at", "collection_method", "confidence", "source", "evidence_hash", "data"],
|
|
8
8
|
"properties": {
|
|
9
9
|
"observation_id": { "type": "string", "minLength": 1 },
|
|
10
|
-
"kind": { "type": "string", "enum": ["render", "index", "citation", "citation_review", "crawler_log", "bing_webmaster", "passage", "canonical_freshness", "performance", "corroboration", "metric"] },
|
|
10
|
+
"kind": { "type": "string", "enum": ["render", "index", "citation", "citation_review", "crawler_log", "bing_webmaster", "passage", "canonical_freshness", "performance", "corroboration", "metric", "media_pdf", "media_transcript", "media_image"] },
|
|
11
11
|
"state": { "type": "string", "enum": ["observed", "not_observed", "not_evidenced", "incomplete", "review_required", "failed"] },
|
|
12
12
|
"collected_at": { "type": "string", "format": "date-time" },
|
|
13
13
|
"collection_method": { "type": "string", "enum": ["live_api", "browser", "owner_import", "synthetic_fetch", "static_analysis", "human_review"] },
|
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>
|
|
@@ -117,6 +119,7 @@ citable reviews sample <sampling-plan-id> [--write]
|
|
|
117
119
|
citable reviews evaluate
|
|
118
120
|
citable schedules run <schedule-id> [--ref-date YYYY-MM-DD]
|
|
119
121
|
citable project github <run-id>
|
|
122
|
+
citable observe media --input <manifest.json> [--ocr]
|
|
120
123
|
```
|
|
121
124
|
|
|
122
125
|
Audit scopes: `technical seo aeo geo architecture entity claims evidence schema
|
package/skill/commands/README.md
CHANGED
|
@@ -30,10 +30,11 @@ intent, not executability, so statuses are strict:
|
|
|
30
30
|
| /citable governance validate / evaluate | implemented — validates reviewer and exception authority and emits immutable dispositions without changing failed findings |
|
|
31
31
|
| /citable reviews queue / prioritize / plan / sample / evaluate | implemented — materiality queues, reproducible sampling, stale-decision checks, and independent disagreement adjudication |
|
|
32
32
|
| /citable schedules run / project github | implemented — canonical scheduled audits and hash-bound non-authoritative GitHub projections |
|
|
33
|
+
| /citable observe media | implemented — bounded PDF, transcript, image-context, optional OCR, and declared claim-link evidence |
|
|
33
34
|
| /citable ingest, map-site, map-queries, map-prompts, map-entities, map-evidence | specified (ingest.md) |
|
|
34
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 |
|
|
35
36
|
| /citable create-page, answer-block, architect, interlink, consolidate, metadata | specified (page-work.md) |
|
|
36
|
-
| /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 |
|
|
37
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 |
|
|
38
39
|
|
|
39
40
|
Shared refusal conditions (all commands): any action that would fabricate
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Media evidence collection
|
|
2
|
+
|
|
3
|
+
Use `citable observe media --input <manifest.json>` for bounded local-media
|
|
4
|
+
evidence. The manifest declares source URL, owning page, permission status, and
|
|
5
|
+
linked claim IDs for each PDF, transcript, or image-context source.
|
|
6
|
+
|
|
7
|
+
PDF collection extracts native text, basic metadata, and stable page anchors.
|
|
8
|
+
It does not establish reading order, table structure, footnote linkage,
|
|
9
|
+
signatures, revisions, scan accuracy, accessibility, or claim support.
|
|
10
|
+
Transcript collection preserves cues but does not verify speakers, timing,
|
|
11
|
+
accuracy, or source-media parity. Image collection records alt text, captions,
|
|
12
|
+
and nearby figure text without inferring visual entailment.
|
|
13
|
+
|
|
14
|
+
OCR is off by default. `--ocr` explicitly requests the optional `tesseract.js`
|
|
15
|
+
path; an unavailable engine or image produces incomplete evidence, never guessed
|
|
16
|
+
text. Every media-to-claim relationship is declarative and still requires
|
|
17
|
+
human-authoritative semantic review.
|
|
@@ -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
|
@@ -43,7 +43,7 @@ Commands
|
|
|
43
43
|
compare-snapshots [a b] Regression diff between two audit runs
|
|
44
44
|
action-plan [run] Turn audit findings into ordered remediation work
|
|
45
45
|
observe <mode> Collect render, index, citation, log, Bing, passage,
|
|
46
|
-
consensus, performance, or
|
|
46
|
+
consensus, performance, corroboration, or media evidence
|
|
47
47
|
apply Apply a reviewed, hash-locked remediation spec
|
|
48
48
|
monitor [runA runB] Compare observation runs and emit regression alerts
|
|
49
49
|
metrics import Import declared metric observations from CSV/JSON
|
|
@@ -84,6 +84,10 @@ 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
|
|
90
|
+
--ocr Explicitly request optional OCR for media images
|
|
87
91
|
--write Persist registry changes (map-claims, substantiate)
|
|
88
92
|
--json Machine-readable output only
|
|
89
93
|
|
|
@@ -96,6 +100,9 @@ function parseArgs(argv) {
|
|
|
96
100
|
const a = argv[i];
|
|
97
101
|
if (a === '--write') args.write = true;
|
|
98
102
|
else if (a === '--json') args.json = true;
|
|
103
|
+
else if (a === '--ocr') args.ocr = true;
|
|
104
|
+
else if (a === '--interactions') args.interactions = true;
|
|
105
|
+
else if (a === '--lighthouse') args.lighthouse = true;
|
|
99
106
|
else if (a === '--target') args.target = argv[++i];
|
|
100
107
|
else if (a === '--base-url') args.baseUrl = argv[++i];
|
|
101
108
|
else if (a === '--ref-date') args.refDate = argv[++i];
|
|
@@ -112,6 +119,7 @@ function parseArgs(argv) {
|
|
|
112
119
|
else if (a === '--access-token') args.accessToken = argv[++i];
|
|
113
120
|
else if (a === '--endpoint') args.endpoint = argv[++i];
|
|
114
121
|
else if (a === '--repeat') args.repeat = Number(argv[++i]);
|
|
122
|
+
else if (a === '--resume-run') args.resumeRun = argv[++i];
|
|
115
123
|
else if (a === '--timeout') args.timeout = Number(argv[++i]);
|
|
116
124
|
else if (a === '--force') args.force = true;
|
|
117
125
|
else args._.push(a);
|
package/src/commands/observe.js
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { parse as parseCsv } from 'csv-parse/sync';
|
|
8
8
|
import { crawlerIdentity } from '../observations/crawlerIdentity.js';
|
|
9
9
|
import { validateAgainst } from '../shared/schemaValidator.js';
|
|
10
|
+
import { observeMedia } from '../observations/media.js';
|
|
10
11
|
|
|
11
12
|
const originOf = (value) => { try { return new URL(value).origin; } catch { return null; } };
|
|
12
13
|
const words = (text) => String(text || '').trim().split(/\s+/).filter(Boolean);
|
|
@@ -31,37 +32,59 @@ function canonicalReview(raw, targetOrigin) {
|
|
|
31
32
|
|
|
32
33
|
async function observeRender(root, options) {
|
|
33
34
|
if (!options.target || !/^https?:\/\//.test(options.target)) throw new Error('render requires --target <http(s) URL>');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 });
|
|
38
53
|
}
|
|
39
|
-
const initial = await fetchUrl(options.target, { timeoutMs: options.timeout || 30000, maxRetries: 1 });
|
|
40
|
-
const browser = await playwright.chromium.launch({ headless: true });
|
|
41
54
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 });
|
|
55
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();
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
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(); }
|
|
65
88
|
}
|
|
66
89
|
|
|
67
90
|
async function observeIndex(root, options) {
|
|
@@ -247,7 +270,75 @@ async function observeConsensus(root, options) {
|
|
|
247
270
|
return observationRun(root, 'observe consensus', options.target, observations);
|
|
248
271
|
}
|
|
249
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
|
+
|
|
250
340
|
async function observePerformance(root, options) {
|
|
341
|
+
if (options.lighthouse) return observeLighthouse(root, options);
|
|
251
342
|
if (options.input) {
|
|
252
343
|
const input = readInput(options.input);
|
|
253
344
|
const rows = Array.isArray(input.value) ? input.value : [input.value];
|
|
@@ -289,6 +380,7 @@ export async function observe(root, mode, options = {}) {
|
|
|
289
380
|
case 'consensus': return observeConsensus(root, options);
|
|
290
381
|
case 'performance': return observePerformance(root, options);
|
|
291
382
|
case 'corroboration': return observeCorroboration(root, options);
|
|
292
|
-
|
|
383
|
+
case 'media': return observeMedia(root, options);
|
|
384
|
+
default: throw new Error('observe mode must be render, index, citations, logs, bing, passages, consensus, performance, corroboration, or media');
|
|
293
385
|
}
|
|
294
386
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from 'node-html-parser';
|
|
4
|
+
import { envelope, observationRun, readInput } from './common.js';
|
|
5
|
+
import { loadRegistries } from '../registries/index.js';
|
|
6
|
+
import { validateAgainst } from '../shared/schemaValidator.js';
|
|
7
|
+
|
|
8
|
+
function resolveMediaPath(manifestFile, value) {
|
|
9
|
+
const file = path.resolve(path.dirname(manifestFile), value);
|
|
10
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new Error(`media file not found: ${value}`);
|
|
11
|
+
return file;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function pdfEvidence(item, file, artifacts) {
|
|
15
|
+
const pdfjs = await import('pdfjs-dist/legacy/build/pdf.mjs');
|
|
16
|
+
const bytes = new Uint8Array(fs.readFileSync(file));
|
|
17
|
+
const document = await pdfjs.getDocument({ data: bytes, disableWorker: true, useSystemFonts: true }).promise;
|
|
18
|
+
const metadata = await document.getMetadata().catch(() => ({ info: {}, metadata: null }));
|
|
19
|
+
const pages = [];
|
|
20
|
+
for (let number = 1; number <= document.numPages; number++) {
|
|
21
|
+
const page = await document.getPage(number);
|
|
22
|
+
const content = await page.getTextContent();
|
|
23
|
+
const text = content.items.map((entry) => entry.str).join(' ').replace(/\s+/g, ' ').trim();
|
|
24
|
+
pages.push({ page: number, text, word_count: text ? text.split(/\s+/).length : 0, anchor: `${item.source_url || file}#page=${number}` });
|
|
25
|
+
}
|
|
26
|
+
artifacts[`media/${item.media_id}/extracted.txt`] = pages.map((page) => `--- page ${page.page} ---\n${page.text}`).join('\n');
|
|
27
|
+
return envelope('media_pdf', { media_id: item.media_id, source_url: item.source_url, page_url: item.page_url, claim_ids: item.claim_ids, permission_status: item.permission_status, page_count: document.numPages, pages, metadata: metadata.info || {}, tagged: Boolean(metadata.info?.IsTagged) }, { method: 'static_analysis', source: file, raw: bytes, confidence: 'high', limitations: ['Reading order, tables, footnotes, signatures, revisions, accessibility tags, and scanned text are not fully validated.', 'Page text extraction does not establish that linked claims are supported.'] });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function transcriptEvidence(item, file, artifacts) {
|
|
31
|
+
const raw = fs.readFileSync(file, 'utf8');
|
|
32
|
+
const cues = raw.split(/\r?\n\r?\n/).map((block) => { const lines = block.split(/\r?\n/).filter(Boolean); const timing = lines.find((line) => line.includes('-->')) || null; const text = lines.filter((line) => line !== 'WEBVTT' && line !== timing && !/^\d+$/.test(line)).join(' ').replace(/<[^>]+>/g, '').trim(); return text ? { timing, text } : null; }).filter(Boolean);
|
|
33
|
+
const text = cues.map((cue) => cue.text).join(' ');
|
|
34
|
+
artifacts[`media/${item.media_id}/transcript.txt`] = text;
|
|
35
|
+
return envelope('media_transcript', { media_id: item.media_id, source_url: item.source_url, page_url: item.page_url, claim_ids: item.claim_ids, permission_status: item.permission_status, language: item.language || null, published_at: item.published_at || null, cues, word_count: text ? text.split(/\s+/).length : 0 }, { method: 'owner_import', source: file, raw, limitations: ['Speaker identity, transcription accuracy, timing accuracy, and media parity require human verification.', 'Transcript ingestion does not establish that linked claims are supported.'] });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function imageEvidence(item, file, options) {
|
|
39
|
+
const html = fs.readFileSync(file, 'utf8');
|
|
40
|
+
const root = parse(html);
|
|
41
|
+
const images = root.querySelectorAll('img');
|
|
42
|
+
const image = item.image_src ? images.find((node) => node.getAttribute('src') === item.image_src) : images[0];
|
|
43
|
+
if (!image) return envelope('media_image', { media_id: item.media_id, image_src: item.image_src || null, page_url: item.page_url, claim_ids: item.claim_ids }, { method: 'static_analysis', source: file, raw: html, state: 'not_observed', limitations: ['No matching image was found in the supplied HTML.'] });
|
|
44
|
+
const figure = image.closest('figure');
|
|
45
|
+
const caption = figure?.querySelector('figcaption')?.text.replace(/\s+/g, ' ').trim() || null;
|
|
46
|
+
const alt = image.getAttribute('alt');
|
|
47
|
+
const nearby_text = (figure || image.parentNode)?.text?.replace(/\s+/g, ' ').trim() || null;
|
|
48
|
+
let ocr = { state: 'not_requested', text: null };
|
|
49
|
+
if (options.ocr) {
|
|
50
|
+
try { const tesseract = await import('tesseract.js'); const result = await tesseract.recognize(path.resolve(path.dirname(file), image.getAttribute('src')), item.language || 'eng'); ocr = { state: 'observed', text: result.data.text }; }
|
|
51
|
+
catch { ocr = { state: 'not_evidenced', text: null }; }
|
|
52
|
+
}
|
|
53
|
+
return envelope('media_image', { media_id: item.media_id, image_src: image.getAttribute('src'), source_url: item.source_url, page_url: item.page_url, claim_ids: item.claim_ids, permission_status: item.permission_status, alt: alt ?? null, caption, nearby_text, ocr }, { method: 'static_analysis', source: file, raw: html, state: options.ocr && ocr.state === 'not_evidenced' ? 'incomplete' : 'observed', confidence: 'high', limitations: [...(!alt && !caption ? ['Neither alt text nor a figure caption supplies textual context.'] : []), ...(ocr.state === 'not_evidenced' ? ['OCR was explicitly requested but the optional tesseract.js dependency or image resource was unavailable.'] : []), 'Alt text, captions, nearby text, and OCR do not establish semantic equivalence or claim support.'] });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function observeMedia(root, options) {
|
|
57
|
+
const input = readInput(options.input);
|
|
58
|
+
const check = validateAgainst('media-manifest.schema.json', input.value);
|
|
59
|
+
if (!check.valid) throw new Error(`media manifest violates contract: ${check.errors.join('; ')}`);
|
|
60
|
+
const { registries, problems } = loadRegistries(root);
|
|
61
|
+
if (problems.length) throw new Error(`registry validation failed: ${problems.join('; ')}`);
|
|
62
|
+
const claimIds = new Set(registries.claims.entries.map((claim) => claim.claim_id));
|
|
63
|
+
const observations = [], artifacts = {}, rawInputs = { media_manifest: input.raw };
|
|
64
|
+
for (const item of input.value.items) {
|
|
65
|
+
const unknown = item.claim_ids.filter((id) => !claimIds.has(id));
|
|
66
|
+
if (unknown.length) throw new Error(`${item.media_id} references unknown claim ids: ${unknown.join(', ')}`);
|
|
67
|
+
const file = resolveMediaPath(input.file, item.path);
|
|
68
|
+
rawInputs[`media_${item.media_id}`] = fs.readFileSync(file);
|
|
69
|
+
if (item.type === 'pdf') observations.push(await pdfEvidence(item, file, artifacts));
|
|
70
|
+
else if (item.type === 'transcript') observations.push(transcriptEvidence(item, file, artifacts));
|
|
71
|
+
else observations.push(await imageEvidence(item, file, options));
|
|
72
|
+
}
|
|
73
|
+
const incomplete = observations.filter((item) => item.state === 'incomplete').map((item) => `${item.data.media_id}: requested extraction is incomplete`);
|
|
74
|
+
return observationRun(root, 'observe media', input.file, observations, { rawInputs, artifacts, incomplete });
|
|
75
|
+
}
|