@gobing-ai/knowledge-kit 0.1.20 → 0.1.23
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/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1279 -261
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +13938 -8966
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/gemini-tts/dist/index.js +47 -7
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23580 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +951 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/generations/omni-voice-gen/uv.toml +5 -0
- package/plugins/generations/vibe-voice-tts/README.md +64 -0
- package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
- package/plugins/generations/vibe-voice-tts/package.json +16 -0
- package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
- package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
- package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
- package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
- package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
- package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
- package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
- package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
- package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
- package/plugins/generations/voice-gen/dist/index.js +31 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
- package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
- package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
- package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
- package/plugins/generations/voxcpm-tts/uv.toml +5 -0
- package/plugins/kk/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +933 -60
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +332 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
- package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
- package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
- package/plugins/publishings/threads-pub/dist/index.js +58 -6
- package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
- package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
- package/plugins/publishings/weibo-pub/dist/index.js +11 -1
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/dist/index.js +95 -10
- package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -8,7 +8,8 @@ import { spawnSync } from 'node:child_process';
|
|
|
8
8
|
* missing or malformed artifact takes the bounded retry edge. The revision predicate also uses the
|
|
9
9
|
* safety request digest rather than Spur's Git working-tree `requireDiff` contract because daily
|
|
10
10
|
* drafts live under the ignored `.works` tree. The publish predicate keeps a real safety escalation
|
|
11
|
-
* out of unattended publication
|
|
11
|
+
* out of unattended publication, from either classifier, without mistaking an ABSTAINED decision
|
|
12
|
+
* (the maker failed, nothing was judged) for one.
|
|
12
13
|
*/
|
|
13
14
|
import { createHash } from 'node:crypto';
|
|
14
15
|
import { readFileSync } from 'node:fs';
|
|
@@ -147,9 +148,24 @@ function judgeValid(workDir: string, scopeDir: string, runDate: string): string
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
|
-
* The
|
|
151
|
-
*
|
|
152
|
-
*
|
|
151
|
+
* The final publish contract for unattended publication, over the fold token, the gate's status and
|
|
152
|
+
* the catalog decision row.
|
|
153
|
+
*
|
|
154
|
+
* Two independent classifiers share one `pass|escalate|exclude` vocabulary, and an `escalate` from
|
|
155
|
+
* either means a human has to look:
|
|
156
|
+
*
|
|
157
|
+
* - **the gate's persisted status** (report + judge verdict + contract checks) — the authority on
|
|
158
|
+
* `block`/`revise`, and a real `escalate` there refuses unattended publication;
|
|
159
|
+
* - **the `kk-safety-verdict` catalog decision** — its `escalate` is a judged verdict ("the evidence
|
|
160
|
+
* cannot settle this"), so an unattended run refuses it too. 0317 R6 admitted every escalate here,
|
|
161
|
+
* which let a judged escalation publish under `--skip-review` with no human anywhere.
|
|
162
|
+
*
|
|
163
|
+
* The SAME row is also where a maker failure lands: `source: "default"` + `degraded: true` means the
|
|
164
|
+
* decision ABSTAINED and nothing was judged (measured 2026-11-20 on fm-local, whose guardrails refuse
|
|
165
|
+
* safety-report text — 9 asks since 11-05, every one "The model refused to answer"). An abstention is
|
|
166
|
+
* not a verdict, so the gate's own verdict stands and the run publishes; `daily-safety-verdict`
|
|
167
|
+
* records it on stderr. A row that names no provenance is treated the same way: absent evidence of a
|
|
168
|
+
* judgement is not evidence of one.
|
|
153
169
|
*/
|
|
154
170
|
function publishValid(workDir: string, scopeDir: string, runDate: string, unattendedArg: string): string | null {
|
|
155
171
|
if (unattendedArg !== 'true' && unattendedArg !== 'false') return 'unattended must be true or false';
|
|
@@ -167,8 +183,15 @@ function publishValid(workDir: string, scopeDir: string, runDate: string, unatte
|
|
|
167
183
|
if (!new Set(['pass', 'exclude', 'escalate']).has(gateStatus)) {
|
|
168
184
|
return `gate status ${gateStatus || 'missing'} is not publish-valid`;
|
|
169
185
|
}
|
|
170
|
-
if (unattendedArg
|
|
186
|
+
if (unattendedArg !== 'true') return null;
|
|
187
|
+
if (gateStatus === 'escalate')
|
|
171
188
|
return 'unattended run refuses a real safety escalation; attended review is required';
|
|
189
|
+
const decision = readJson(safetyPath(workDir, scopeDir, runDate, 'safety-verdict.decision'));
|
|
190
|
+
const judgedEscalate =
|
|
191
|
+
String(decision?.value ?? '') === 'escalate' && decision?.source === 'model' && decision?.degraded !== true;
|
|
192
|
+
if (judgedEscalate) {
|
|
193
|
+
const confidence = String(decision?.confidenceLevel ?? 'unstated');
|
|
194
|
+
return `kk-safety-verdict escalated on the evidence (confidence ${confidence}) — the decision requires a human, so an unattended run must not publish`;
|
|
172
195
|
}
|
|
173
196
|
return null;
|
|
174
197
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0394 R1/R16 — where a rendered citation may legitimately point.
|
|
3
|
+
*
|
|
4
|
+
* The ingest hop writes three independent provenance slots (`horizon-ingest/src/index.ts:125`):
|
|
5
|
+
*
|
|
6
|
+
* `sourceUri` the headline URL the digest linked — the *retrieval* destination.
|
|
7
|
+
* `metadata.source` the collector classification from the digest's source line
|
|
8
|
+
* (`hackernews · user1 · …`), i.e. the transport, not a publisher.
|
|
9
|
+
* `metadata.references` the `<details>References</details>` links — item-specific evidence.
|
|
10
|
+
*
|
|
11
|
+
* The editorial renderer used to print `metadata.source` beside `sourceUri`, so a link that lands
|
|
12
|
+
* on `example.com/alpha` was labelled `hackernews` and an aggregator permalink was labelled as if
|
|
13
|
+
* it were the publisher. This module resolves the pair the renderer may emit, without guessing:
|
|
14
|
+
*
|
|
15
|
+
* 1. A retrieval URL that is a known discussion/aggregator platform page is a *transport*: one
|
|
16
|
+
* off-origin reference then corroborates an original → cite that reference, labelled by its own
|
|
17
|
+
* host (the identity is read from the URL that is actually linked, never inferred). A reference
|
|
18
|
+
* that itself lands on a known aggregator host is another transport page, never an original, so
|
|
19
|
+
* it can never corroborate one.
|
|
20
|
+
* 2. Otherwise cite the retrieval URL. A publisher's own page is already the verifiable origin and
|
|
21
|
+
* stays authoritative — a secondary reference is not allowed to displace it. The label is the
|
|
22
|
+
* collector classification only when that classification corroborates the destination host
|
|
23
|
+
* (existing taxonomy preserved), else the host.
|
|
24
|
+
* 3. A retrieval URL that is a known discussion/aggregator platform page is labelled explicitly
|
|
25
|
+
* (`docs/tasks/0394`, "when an aggregator is the only verifiable source, label it explicitly").
|
|
26
|
+
* 4. No http(s) candidate at all → `null`; the caller renders no link (unchanged behaviour).
|
|
27
|
+
*
|
|
28
|
+
* Deliberately absent: redirect fetching, publisher-name inference, and any URL backfill. An
|
|
29
|
+
* ambiguous reference set declines to pick — two different off-origin origins prove nothing.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** How the resolved link was chosen. Reported by audit tooling; never part of the rendered text. */
|
|
33
|
+
export type CitationKind = 'direct' | 'original' | 'aggregator-fallback';
|
|
34
|
+
|
|
35
|
+
export interface SourceCitation {
|
|
36
|
+
/** The `href` the citation links to: a corroborated original, else the retrieval URL. */
|
|
37
|
+
url: string;
|
|
38
|
+
/** The link text: a host (or a corroborated classification), plus the marker when aggregator. */
|
|
39
|
+
label: string;
|
|
40
|
+
kind: CitationKind;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Marker appended to a link that is known to be a transport/aggregator page rather than the
|
|
45
|
+
* publisher's own page. Mechanical, not editorial wording — the writer skill owns prose.
|
|
46
|
+
*/
|
|
47
|
+
export const AGGREGATOR_MARKER = '(聚合)';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The platforms whose pages aggregate someone else's article, keyed by the collector classification
|
|
51
|
+
* the digest source line carries (`hackernews · user1 · … · [Discussion](…)`). Only the two transports
|
|
52
|
+
* this corpus actually emits are listed; an unknown classification never makes a host an aggregator,
|
|
53
|
+
* because that would be a guess (0394 design, "no guessed publishers").
|
|
54
|
+
*/
|
|
55
|
+
const AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]>> = {
|
|
56
|
+
hackernews: ['news.ycombinator.com'],
|
|
57
|
+
reddit: ['reddit.com', 'old.reddit.com', 'redd.it'],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const HTTP_URL = /^https?:\/\//i;
|
|
61
|
+
|
|
62
|
+
/** A trimmed `http(s)` URL, or `null` — the only scheme a citation may carry. */
|
|
63
|
+
function httpUrl(raw: unknown): URL | null {
|
|
64
|
+
if (typeof raw !== 'string') return null;
|
|
65
|
+
const trimmed = raw.trim();
|
|
66
|
+
if (!HTTP_URL.test(trimmed)) return null;
|
|
67
|
+
try {
|
|
68
|
+
return new URL(trimmed);
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Host identity for a label: lowercased, `www.` stripped — the same normalisation the renderer used. */
|
|
75
|
+
function hostOf(url: URL): string {
|
|
76
|
+
return url.hostname.toLowerCase().replace(/^www\./, '');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** `metadata.source` as the collector classification, or `''` when absent/blank/non-string. */
|
|
80
|
+
function classificationOf(doc: Record<string, unknown> | null | undefined): string {
|
|
81
|
+
const meta = doc?.metadata;
|
|
82
|
+
if (meta === null || typeof meta !== 'object') return '';
|
|
83
|
+
const source = (meta as Record<string, unknown>).source;
|
|
84
|
+
return typeof source === 'string' ? source.trim() : '';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `metadata.references`, http(s) only, de-duplicated by URL — the item-specific evidence set. */
|
|
88
|
+
function referenceUrls(doc: Record<string, unknown> | null | undefined): string[] {
|
|
89
|
+
const meta = doc?.metadata;
|
|
90
|
+
if (meta === null || typeof meta !== 'object') return [];
|
|
91
|
+
const raw = (meta as Record<string, unknown>).references;
|
|
92
|
+
if (!Array.isArray(raw)) return [];
|
|
93
|
+
const urls: string[] = [];
|
|
94
|
+
for (const entry of raw) {
|
|
95
|
+
const url = httpUrl(entry);
|
|
96
|
+
if (url !== null && !urls.includes(url.toString())) urls.push(url.toString());
|
|
97
|
+
}
|
|
98
|
+
return urls;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Does the collector classification describe this destination? (`openai.com` ~ `openai.com`). */
|
|
102
|
+
function corroborates(classification: string, host: string): boolean {
|
|
103
|
+
if (classification === '') return false;
|
|
104
|
+
const normalized = classification
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.replace(HTTP_URL, '')
|
|
107
|
+
.replace(/^www\./, '')
|
|
108
|
+
.replace(/\/.*$/, '');
|
|
109
|
+
return normalized !== '' && (host === normalized || host.endsWith(`.${normalized}`));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Does `host` sit under one of these platform domains? */
|
|
113
|
+
function matchesAggregatorHost(hosts: readonly string[], host: string): boolean {
|
|
114
|
+
return hosts.some((aggregator) => host === aggregator || host.endsWith(`.${aggregator}`));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Is this host the transport platform the classification names (a page about someone else's item)? */
|
|
118
|
+
function isAggregator(classification: string, host: string): boolean {
|
|
119
|
+
const hosts = AGGREGATOR_HOSTS[classification.toLowerCase()];
|
|
120
|
+
return hosts !== undefined && matchesAggregatorHost(hosts, host);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Is this host *any* platform in the aggregator table, whatever the classification says? The
|
|
125
|
+
* classification only decides the marker (rule 3); for corroboration the host alone says "transport",
|
|
126
|
+
* because an unclassified permalink on a known aggregator is still not an original.
|
|
127
|
+
*/
|
|
128
|
+
function isKnownAggregatorHost(host: string): boolean {
|
|
129
|
+
return Object.values(AGGREGATOR_HOSTS).some((hosts) => matchesAggregatorHost(hosts, host));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Cite the retrieval URL: corroborated classification, else the verified host; aggregator marked. */
|
|
133
|
+
function citeRetrieval(url: URL, classification: string): SourceCitation {
|
|
134
|
+
const host = hostOf(url);
|
|
135
|
+
if (isAggregator(classification, host)) {
|
|
136
|
+
return { url: url.toString(), label: `${host}${AGGREGATOR_MARKER}`, kind: 'aggregator-fallback' };
|
|
137
|
+
}
|
|
138
|
+
return { url: url.toString(), label: corroborates(classification, host) ? classification : host, kind: 'direct' };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Resolve the one citation a rendered item may carry. `null` means "no verifiable link" — the
|
|
143
|
+
* caller emits no source line, exactly as before this change.
|
|
144
|
+
*/
|
|
145
|
+
export function resolveSourceCitation(
|
|
146
|
+
doc: Record<string, unknown> | null | undefined,
|
|
147
|
+
sourceUri: unknown,
|
|
148
|
+
): SourceCitation | null {
|
|
149
|
+
const classification = classificationOf(doc);
|
|
150
|
+
const retrieval = httpUrl(sourceUri);
|
|
151
|
+
if (retrieval === null) {
|
|
152
|
+
// No retrieval URL: a usable reference is still evidence, and its host is its identity — but a
|
|
153
|
+
// reference that is itself a transport page keeps the aggregator marker (never a bare original).
|
|
154
|
+
const references = referenceUrls(doc)
|
|
155
|
+
.map((raw) => httpUrl(raw))
|
|
156
|
+
.filter((url): url is URL => url !== null);
|
|
157
|
+
const original = references.find((url) => !isKnownAggregatorHost(hostOf(url)));
|
|
158
|
+
if (original !== undefined) {
|
|
159
|
+
return { url: original.toString(), label: hostOf(original), kind: 'original' };
|
|
160
|
+
}
|
|
161
|
+
const [transport] = references;
|
|
162
|
+
if (transport === undefined) return null;
|
|
163
|
+
const host = hostOf(transport);
|
|
164
|
+
return {
|
|
165
|
+
url: transport.toString(),
|
|
166
|
+
label: `${host}${AGGREGATOR_MARKER}`,
|
|
167
|
+
kind: 'aggregator-fallback',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const origins = new Map<string, URL>();
|
|
171
|
+
for (const raw of referenceUrls(doc)) {
|
|
172
|
+
const url = httpUrl(raw);
|
|
173
|
+
if (url === null || url.origin === retrieval.origin) continue;
|
|
174
|
+
// A reference on a known aggregator host is someone else's transport page, not this item's
|
|
175
|
+
// publisher: excluding it keeps an aggregator from being cited as a bare `original`.
|
|
176
|
+
if (isKnownAggregatorHost(hostOf(url))) continue;
|
|
177
|
+
if (!origins.has(url.origin)) origins.set(url.origin, url);
|
|
178
|
+
}
|
|
179
|
+
// Only a transport page is displaced: when the retrieval URL is already the publisher's own page,
|
|
180
|
+
// that page is the verifiable origin and an off-origin reference must not replace it. Exactly one
|
|
181
|
+
// off-origin origin corroborates; two or more prove nothing about which is the item's publisher.
|
|
182
|
+
if (origins.size === 1 && isKnownAggregatorHost(hostOf(retrieval))) {
|
|
183
|
+
const [url] = [...origins.values()] as [URL];
|
|
184
|
+
return { url: url.toString(), label: hostOf(url), kind: 'original' };
|
|
185
|
+
}
|
|
186
|
+
return citeRetrieval(retrieval, classification);
|
|
187
|
+
}
|