@gobing-ai/knowledge-kit 0.1.19 → 0.1.22
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 +1315 -264
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +14674 -8775
- 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/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23544 -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 +31 -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 +30 -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 +904 -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 +918 -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/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
- 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 +897 -34
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- 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/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- 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/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +10 -9
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +11 -9
- package/plugins/kk/workflows/kk-music.yaml +328 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
- 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 +54 -7
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +43 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- 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 +437 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +492 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- 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 +122 -28
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +159 -25
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +37 -4
- package/plugins/publishings/threads-pub/dist/index.js +9206 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21149 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +18 -1
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +57 -3
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +274 -44
- package/plugins/publishings/x-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- 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
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Take checks and the delivery check (task 0405 R2/R4) plus the
|
|
3
|
+
* `<artifact>.checks.json` record they share.
|
|
4
|
+
*
|
|
5
|
+
* **Take checks answer "is this generation usable?"** and run *before* the
|
|
6
|
+
* judge: duration against the brief, dead air at either edge, and the presence of
|
|
7
|
+
* the instance analysis. They deliberately never look at loudness — raw provider
|
|
8
|
+
* output has arbitrary loudness, so a loudness gate here would fail every take
|
|
9
|
+
* (the gate-order bug 0405 exists to fix). BPM/key/section agreement with the
|
|
10
|
+
* brief is `warn` only, because the instance analysis is itself a model estimate.
|
|
11
|
+
*
|
|
12
|
+
* **Delivery checks answer "does the delivered file hit the target?"** and run
|
|
13
|
+
* *after* master, on the encoded output (R4) — lossy encoding can push true peak
|
|
14
|
+
* back over the ceiling, so measuring the intermediate would miss exactly the
|
|
15
|
+
* failure the check exists for. `delivery.*` rows are appended to the same
|
|
16
|
+
* `checks.json`.
|
|
17
|
+
*
|
|
18
|
+
* **Every row carries `id`, `measured`, `threshold`, `unit`, `source` and
|
|
19
|
+
* `result`** (R2). `source` is `<tool> <version>` from the measurement's own
|
|
20
|
+
* `-version` banner, so a report can say which ffmpeg decided. A check that could
|
|
21
|
+
* not be measured is `fail` with a `note` explaining why — never skipped.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { createNodeFileSystem, type FileSystem } from '@gobing-ai/ts-runtime';
|
|
25
|
+
import type { MusicModel } from '../brief';
|
|
26
|
+
import { durationSeconds } from '../brief';
|
|
27
|
+
import { type AudioMeasurement, AudioToolError, type MeasureOptions, measureAudio } from './measure';
|
|
28
|
+
import { DELIVERY_LOUDNESS_TOLERANCE_LU, type DeliveryProfile } from './profile';
|
|
29
|
+
|
|
30
|
+
/** `<artifact>.checks.json` suffix (R2). */
|
|
31
|
+
export const CHECKS_SUFFIX = '.checks.json';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Leading-silence ceiling in seconds. One second of dead air at the head is
|
|
35
|
+
* already an edit on every social platform; anything longer looks like a broken
|
|
36
|
+
* export rather than a musical intro.
|
|
37
|
+
*/
|
|
38
|
+
export const LEADING_SILENCE_MAX_SECONDS = 1;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Trailing-silence ceiling in seconds. A three-second tail is a normal reverb
|
|
42
|
+
* decay and a usable loop/outro handle; a longer one is dead air a platform will
|
|
43
|
+
* keep counting against the runtime.
|
|
44
|
+
*/
|
|
45
|
+
export const TRAILING_SILENCE_MAX_SECONDS = 3;
|
|
46
|
+
|
|
47
|
+
/** Pro duration tolerance as a fraction of the target (R2: ±20%). */
|
|
48
|
+
export const PRO_DURATION_TOLERANCE_RATIO = 0.2;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Pro duration tolerance floor in seconds (R2: "±20% or ±10 s, whichever is
|
|
52
|
+
* larger"). The floor exists because a provider take of a 0:30 target is never
|
|
53
|
+
* musically 30.0 s: ±10 s accepts a real 0:24–0:36 take instead of failing on
|
|
54
|
+
* generation jitter.
|
|
55
|
+
*/
|
|
56
|
+
export const PRO_DURATION_TOLERANCE_FLOOR_SECONDS = 10;
|
|
57
|
+
|
|
58
|
+
/** Clip takes are a fixed short form: 25–35 s (R2). */
|
|
59
|
+
export const CLIP_DURATION_MIN_SECONDS = 25;
|
|
60
|
+
export const CLIP_DURATION_MAX_SECONDS = 35;
|
|
61
|
+
|
|
62
|
+
/** BPM agreement tolerance for the warn-only analysis check: ±10% of the brief's figure. */
|
|
63
|
+
export const BPM_TOLERANCE_RATIO = 0.1;
|
|
64
|
+
|
|
65
|
+
/** Decimal places every measured value is rounded to before it is compared or recorded. */
|
|
66
|
+
const REPORT_DIGITS = 2;
|
|
67
|
+
|
|
68
|
+
/** One row's outcome. `fail` is the only result that makes a command exit non-zero (R2). */
|
|
69
|
+
export type CheckResult = 'pass' | 'warn' | 'fail';
|
|
70
|
+
|
|
71
|
+
/** One recorded check (R2's required field set, plus an optional explanation). */
|
|
72
|
+
export interface CheckRow {
|
|
73
|
+
/** Dotted id: `duration.target`, `silence.leading`, `delivery.true_peak`, … */
|
|
74
|
+
id: string;
|
|
75
|
+
/** What was measured; `null` when the measurement itself failed. */
|
|
76
|
+
measured: number | string | null;
|
|
77
|
+
/** The limit it was compared against: a ceiling number or a `min–max` band string. */
|
|
78
|
+
threshold: number | string | null;
|
|
79
|
+
unit: string;
|
|
80
|
+
/** `<tool> <version>`, e.g. `ffprobe 8.1.2`. */
|
|
81
|
+
source: string;
|
|
82
|
+
result: CheckResult;
|
|
83
|
+
/** Why a row is `warn`/`fail` when the numbers alone do not say it. */
|
|
84
|
+
note?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Everything the take checks need. */
|
|
88
|
+
export interface TakeCheckInput {
|
|
89
|
+
/** `pro` gates the brief's duration target; `clip` uses the fixed 25–35 s window. */
|
|
90
|
+
model: MusicModel;
|
|
91
|
+
/** The brief's recorded `m:ss` target (pro only). */
|
|
92
|
+
durationTarget?: string;
|
|
93
|
+
/** The take's measurement; absent when measuring failed. */
|
|
94
|
+
measurement?: AudioMeasurement;
|
|
95
|
+
/** The measurement failure, when there is one — every measurement row then fails. */
|
|
96
|
+
measurementError?: string;
|
|
97
|
+
/** The instance analysis (`null` when the instance carried none). */
|
|
98
|
+
analysis?: Record<string, unknown> | null;
|
|
99
|
+
/** Resolved style/theme text the brief declares, for the BPM/key agreement checks. */
|
|
100
|
+
briefStyle?: string;
|
|
101
|
+
/** `brief.structure.length`, for the section-count agreement check. */
|
|
102
|
+
briefSectionCount?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Round a measured value for recording; keeps `-Infinity` honest instead of printing `NaN`. */
|
|
106
|
+
function round(value: number): number {
|
|
107
|
+
if (!Number.isFinite(value)) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
const factor = 10 ** REPORT_DIGITS;
|
|
111
|
+
return Math.round(value * factor) / factor;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** `24–36` — a band threshold as one readable string. */
|
|
115
|
+
function band(low: number, high: number): string {
|
|
116
|
+
return `${String(round(low))}–${String(round(high))}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Build one measurement-derived row, failing it when the measurement is unavailable. */
|
|
120
|
+
function measurementRow(input: {
|
|
121
|
+
id: string;
|
|
122
|
+
measured: number | string | null;
|
|
123
|
+
threshold: number | string;
|
|
124
|
+
unit: string;
|
|
125
|
+
source: string;
|
|
126
|
+
result: CheckResult;
|
|
127
|
+
note?: string;
|
|
128
|
+
}): CheckRow {
|
|
129
|
+
return {
|
|
130
|
+
id: input.id,
|
|
131
|
+
measured: input.measured === null ? null : round(Number(input.measured)),
|
|
132
|
+
threshold: input.threshold,
|
|
133
|
+
unit: input.unit,
|
|
134
|
+
source: input.source,
|
|
135
|
+
result: input.result,
|
|
136
|
+
...(input.note === undefined ? {} : { note: input.note }),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** `null`-measured row for a check whose measurement never landed (R2: fail, never skip). */
|
|
141
|
+
function unmeasuredRow(id: string, threshold: number | string, unit: string, source: string, note: string): CheckRow {
|
|
142
|
+
return { id, measured: null, threshold, unit, source, result: 'fail', note };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** What the brief declares musically: the BPM band and key the analysis is compared against. */
|
|
146
|
+
export interface BriefMusicalTargets {
|
|
147
|
+
bpm?: { low: number; high: number };
|
|
148
|
+
key?: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Canonicalise `D minor` / `Dm` / `d MINOR` to `D minor`. */
|
|
152
|
+
export function canonicalKey(text: string): string | undefined {
|
|
153
|
+
const match = /([A-Ga-g])([#b]?)\s*(minor|major|min|maj|m)\b/i.exec(text);
|
|
154
|
+
if (match === null) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const root = `${(match[1] ?? '').toUpperCase()}${match[2] ?? ''}`;
|
|
158
|
+
const qualityRaw = (match[3] ?? '').toLowerCase();
|
|
159
|
+
const quality = qualityRaw.startsWith('m') && qualityRaw !== 'maj' ? 'minor' : 'major';
|
|
160
|
+
return `${root} ${quality}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Read the BPM band and key a brief's style/theme text declares.
|
|
165
|
+
*
|
|
166
|
+
* Only what the text states is returned: a range (`100-115 BPM`) is used as-is;
|
|
167
|
+
* a single figure (`at 78 BPM`) becomes ±{@link BPM_TOLERANCE_RATIO} because a
|
|
168
|
+
* point estimate from a preset is not a metronomic command. Both are warn-only
|
|
169
|
+
* comparisons (R2), so a loose band loses nothing.
|
|
170
|
+
*/
|
|
171
|
+
export function briefMusicalTargets(text: string | undefined): BriefMusicalTargets {
|
|
172
|
+
if (text === undefined || text.trim() === '') {
|
|
173
|
+
return {};
|
|
174
|
+
}
|
|
175
|
+
const targets: BriefMusicalTargets = {};
|
|
176
|
+
const range = /(\d{2,3})\s*(?:-|–|—|to)\s*(\d{2,3})\s*bpm/i.exec(text);
|
|
177
|
+
const single = /(\d{2,3})\s*bpm/i.exec(text);
|
|
178
|
+
if (range !== null) {
|
|
179
|
+
const low = Number(range[1]);
|
|
180
|
+
const high = Number(range[2]);
|
|
181
|
+
targets.bpm = { low: Math.min(low, high), high: Math.max(low, high) };
|
|
182
|
+
} else if (single !== null) {
|
|
183
|
+
const value = Number(single[1]);
|
|
184
|
+
targets.bpm = { low: value * (1 - BPM_TOLERANCE_RATIO), high: value * (1 + BPM_TOLERANCE_RATIO) };
|
|
185
|
+
}
|
|
186
|
+
const key = /(?:in\s+)?([A-G][#b]?\s*(?:minor|major|min|maj|m)\b)/i.exec(text);
|
|
187
|
+
if (key !== null) {
|
|
188
|
+
const canonical = canonicalKey(key[1] ?? '');
|
|
189
|
+
if (canonical !== undefined) {
|
|
190
|
+
targets.key = canonical;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return targets;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Read a positive finite number from an analysis field (`"78"` or `78`), else `undefined`. */
|
|
197
|
+
function analysisNumber(analysis: Record<string, unknown>, field: string): number | undefined {
|
|
198
|
+
const raw = analysis[field];
|
|
199
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) {
|
|
200
|
+
return raw;
|
|
201
|
+
}
|
|
202
|
+
if (typeof raw === 'string' && raw.trim() !== '' && Number.isFinite(Number(raw))) {
|
|
203
|
+
return Number(raw);
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Read a section count from `analysis.sections` (an array or a number), else `undefined`. */
|
|
209
|
+
function analysisSectionCount(analysis: Record<string, unknown>): number | undefined {
|
|
210
|
+
const sections = analysis.sections ?? analysis.section_count;
|
|
211
|
+
if (Array.isArray(sections)) {
|
|
212
|
+
return sections.length;
|
|
213
|
+
}
|
|
214
|
+
if (typeof sections === 'number' && Number.isFinite(sections)) {
|
|
215
|
+
return sections;
|
|
216
|
+
}
|
|
217
|
+
if (typeof sections === 'string' && Number.isFinite(Number(sections))) {
|
|
218
|
+
return Number(sections);
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Build the pre-master take check rows (R2).
|
|
225
|
+
*
|
|
226
|
+
* Order is stable (`duration`, `silence.*`, `analysis.*`) so a diff of two
|
|
227
|
+
* `checks.json` files is readable. Loudness is absent by design: R2 keeps raw
|
|
228
|
+
* loudness out of the take gate.
|
|
229
|
+
*/
|
|
230
|
+
export function buildTakeCheckRows(input: TakeCheckInput): CheckRow[] {
|
|
231
|
+
const rows: CheckRow[] = [];
|
|
232
|
+
const measurement = input.measurement;
|
|
233
|
+
const failure = input.measurementError;
|
|
234
|
+
const ffprobeSource = measurement?.tools.ffprobe ?? 'ffprobe';
|
|
235
|
+
const ffmpegSource = measurement?.tools.ffmpeg ?? 'ffmpeg';
|
|
236
|
+
const probeNote = failure === undefined ? 'no measurement' : failure;
|
|
237
|
+
|
|
238
|
+
// ── duration (R2) ───────────────────────────────────────────────────────
|
|
239
|
+
if (input.model === 'pro') {
|
|
240
|
+
const target = input.durationTarget;
|
|
241
|
+
const targetSeconds = target === undefined ? undefined : safeDurationSeconds(target);
|
|
242
|
+
const tolerance =
|
|
243
|
+
targetSeconds === undefined
|
|
244
|
+
? PRO_DURATION_TOLERANCE_FLOOR_SECONDS
|
|
245
|
+
: Math.max(targetSeconds * PRO_DURATION_TOLERANCE_RATIO, PRO_DURATION_TOLERANCE_FLOOR_SECONDS);
|
|
246
|
+
const threshold =
|
|
247
|
+
targetSeconds === undefined
|
|
248
|
+
? `brief durationTarget (missing)`
|
|
249
|
+
: band(Math.max(0, targetSeconds - tolerance), targetSeconds + tolerance);
|
|
250
|
+
if (targetSeconds === undefined) {
|
|
251
|
+
rows.push(
|
|
252
|
+
unmeasuredRow(
|
|
253
|
+
'duration.target',
|
|
254
|
+
threshold,
|
|
255
|
+
's',
|
|
256
|
+
ffprobeSource,
|
|
257
|
+
'the resolved job recorded no durationTarget, so the take cannot be checked against the brief',
|
|
258
|
+
),
|
|
259
|
+
);
|
|
260
|
+
} else if (measurement === undefined) {
|
|
261
|
+
rows.push(
|
|
262
|
+
unmeasuredRow('duration.target', threshold, 's', ffprobeSource, `measurement failed: ${probeNote}`),
|
|
263
|
+
);
|
|
264
|
+
} else {
|
|
265
|
+
const measured = measurement.probe.durationSeconds;
|
|
266
|
+
rows.push(
|
|
267
|
+
measurementRow({
|
|
268
|
+
id: 'duration.target',
|
|
269
|
+
measured,
|
|
270
|
+
threshold,
|
|
271
|
+
unit: 's',
|
|
272
|
+
source: ffprobeSource,
|
|
273
|
+
result:
|
|
274
|
+
measured >= targetSeconds - tolerance && measured <= targetSeconds + tolerance
|
|
275
|
+
? 'pass'
|
|
276
|
+
: 'fail',
|
|
277
|
+
note: `brief target ${target ?? ''} ±${String(round(tolerance))} s`,
|
|
278
|
+
}),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
const threshold = band(CLIP_DURATION_MIN_SECONDS, CLIP_DURATION_MAX_SECONDS);
|
|
283
|
+
if (measurement === undefined) {
|
|
284
|
+
rows.push(
|
|
285
|
+
unmeasuredRow('duration.clip', threshold, 's', ffprobeSource, `measurement failed: ${probeNote}`),
|
|
286
|
+
);
|
|
287
|
+
} else {
|
|
288
|
+
const measured = measurement.probe.durationSeconds;
|
|
289
|
+
rows.push(
|
|
290
|
+
measurementRow({
|
|
291
|
+
id: 'duration.clip',
|
|
292
|
+
measured,
|
|
293
|
+
threshold,
|
|
294
|
+
unit: 's',
|
|
295
|
+
source: ffprobeSource,
|
|
296
|
+
result:
|
|
297
|
+
measured >= CLIP_DURATION_MIN_SECONDS && measured <= CLIP_DURATION_MAX_SECONDS
|
|
298
|
+
? 'pass'
|
|
299
|
+
: 'fail',
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ── silence (R2) ────────────────────────────────────────────────────────
|
|
306
|
+
const silenceRows: Array<{ id: string; measuredKey: 'leadingSeconds' | 'trailingSeconds'; ceiling: number }> = [
|
|
307
|
+
{ id: 'silence.leading', measuredKey: 'leadingSeconds', ceiling: LEADING_SILENCE_MAX_SECONDS },
|
|
308
|
+
{ id: 'silence.trailing', measuredKey: 'trailingSeconds', ceiling: TRAILING_SILENCE_MAX_SECONDS },
|
|
309
|
+
];
|
|
310
|
+
for (const { id, measuredKey, ceiling } of silenceRows) {
|
|
311
|
+
if (measurement === undefined) {
|
|
312
|
+
rows.push(
|
|
313
|
+
unmeasuredRow(id, ceiling, 's', `${ffmpegSource} silencedetect`, `measurement failed: ${probeNote}`),
|
|
314
|
+
);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const measured = measurement.silence[measuredKey];
|
|
318
|
+
rows.push(
|
|
319
|
+
measurementRow({
|
|
320
|
+
id,
|
|
321
|
+
measured,
|
|
322
|
+
threshold: ceiling,
|
|
323
|
+
unit: 's',
|
|
324
|
+
source: `${ffmpegSource} silencedetect`,
|
|
325
|
+
result: measured <= ceiling ? 'pass' : 'fail',
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ── instance analysis present (R2) ──────────────────────────────────────
|
|
331
|
+
const analysis = input.analysis ?? null;
|
|
332
|
+
const analysisPresent = analysis !== null && Object.keys(analysis).length > 0;
|
|
333
|
+
rows.push({
|
|
334
|
+
id: 'analysis.present',
|
|
335
|
+
measured: analysisPresent ? 'present' : 'absent',
|
|
336
|
+
threshold: 'present',
|
|
337
|
+
unit: 'state',
|
|
338
|
+
source: 'lyria instance analysis',
|
|
339
|
+
result: analysisPresent ? 'pass' : 'fail',
|
|
340
|
+
...(analysisPresent
|
|
341
|
+
? {}
|
|
342
|
+
: { note: 'the take carries no instance analysis; run the analyze step before judging' }),
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// ── brief vs analysis agreement (warn only, R2) ─────────────────────────
|
|
346
|
+
const targets = briefMusicalTargets(input.briefStyle);
|
|
347
|
+
if (targets.bpm !== undefined) {
|
|
348
|
+
const threshold = band(targets.bpm.low, targets.bpm.high);
|
|
349
|
+
const bpm = analysisPresent && analysis !== null ? analysisNumber(analysis, 'bpm') : undefined;
|
|
350
|
+
if (bpm === undefined) {
|
|
351
|
+
rows.push({
|
|
352
|
+
id: 'analysis.bpm',
|
|
353
|
+
measured: null,
|
|
354
|
+
threshold,
|
|
355
|
+
unit: 'bpm',
|
|
356
|
+
source: 'lyria instance analysis',
|
|
357
|
+
result: 'warn',
|
|
358
|
+
note: 'the analysis carries no BPM, so agreement with the brief could not be compared',
|
|
359
|
+
});
|
|
360
|
+
} else {
|
|
361
|
+
rows.push({
|
|
362
|
+
id: 'analysis.bpm',
|
|
363
|
+
measured: round(bpm),
|
|
364
|
+
threshold,
|
|
365
|
+
unit: 'bpm',
|
|
366
|
+
source: 'lyria instance analysis',
|
|
367
|
+
result: bpm >= targets.bpm.low && bpm <= targets.bpm.high ? 'pass' : 'warn',
|
|
368
|
+
...(bpm >= targets.bpm.low && bpm <= targets.bpm.high
|
|
369
|
+
? {}
|
|
370
|
+
: { note: 'the analysis estimate is outside the brief band; a warn, never a fail (R2)' }),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (targets.key !== undefined) {
|
|
375
|
+
const rawKey = analysisPresent && analysis !== null ? (analysis.key ?? analysis.key_signature) : undefined;
|
|
376
|
+
const measured = typeof rawKey === 'string' && rawKey.trim() !== '' ? (canonicalKey(rawKey) ?? rawKey) : null;
|
|
377
|
+
rows.push({
|
|
378
|
+
id: 'analysis.key',
|
|
379
|
+
measured,
|
|
380
|
+
threshold: targets.key,
|
|
381
|
+
unit: 'key',
|
|
382
|
+
source: 'lyria instance analysis',
|
|
383
|
+
result: measured === null ? 'warn' : measured.toLowerCase() === targets.key.toLowerCase() ? 'pass' : 'warn',
|
|
384
|
+
...(measured === null
|
|
385
|
+
? { note: 'the analysis carries no key, so agreement with the brief could not be compared' }
|
|
386
|
+
: {}),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (input.briefSectionCount !== undefined && input.briefSectionCount > 0) {
|
|
390
|
+
const sections = analysisPresent && analysis !== null ? analysisSectionCount(analysis) : undefined;
|
|
391
|
+
rows.push({
|
|
392
|
+
id: 'analysis.sections',
|
|
393
|
+
measured: sections ?? null,
|
|
394
|
+
threshold: input.briefSectionCount,
|
|
395
|
+
unit: 'sections',
|
|
396
|
+
source: 'lyria instance analysis',
|
|
397
|
+
result: sections === undefined ? 'warn' : sections === input.briefSectionCount ? 'pass' : 'warn',
|
|
398
|
+
...(sections === undefined
|
|
399
|
+
? { note: 'the analysis carries no section list, so agreement with the brief could not be compared' }
|
|
400
|
+
: {}),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return rows;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** `durationSeconds` for a well-formed `m:ss`, `undefined` for anything else (the schema already rejected it upstream). */
|
|
408
|
+
function safeDurationSeconds(value: string): number | undefined {
|
|
409
|
+
try {
|
|
410
|
+
return durationSeconds(value);
|
|
411
|
+
} catch {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** `true` when no row is `fail` — R2's exit rule. */
|
|
417
|
+
export function checksPassed(rows: readonly CheckRow[]): boolean {
|
|
418
|
+
return rows.every((row) => row.result !== 'fail');
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Exit code for a row set: `0` only when nothing failed (R2). */
|
|
422
|
+
export function checksExitCode(rows: readonly CheckRow[]): number {
|
|
423
|
+
return checksPassed(rows) ? 0 : 1;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** `<artifact>.checks.json` (R2) — one file per take, shared by take and delivery rows. */
|
|
427
|
+
export function checksPathFor(artifactPath: string): string {
|
|
428
|
+
return `${artifactPath}${CHECKS_SUFFIX}`;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** Serialize the row file the way every kk artifact is written: 4-space JSON plus a trailing newline. */
|
|
432
|
+
export function serializeChecks(rows: readonly CheckRow[]): string {
|
|
433
|
+
return `${JSON.stringify(rows, null, 4)}\n`;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Read a checks file back, tolerating a malformed or absent one as "no rows yet". */
|
|
437
|
+
export async function readChecks(path: string, fileSystem: FileSystem = createNodeFileSystem()): Promise<CheckRow[]> {
|
|
438
|
+
if (!(await fileSystem.exists(path))) {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
let parsed: unknown;
|
|
442
|
+
try {
|
|
443
|
+
parsed = JSON.parse(await fileSystem.readFile(path));
|
|
444
|
+
} catch {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
if (!Array.isArray(parsed)) {
|
|
448
|
+
return [];
|
|
449
|
+
}
|
|
450
|
+
return parsed.filter(
|
|
451
|
+
(row): row is CheckRow => typeof row === 'object' && row !== null && typeof row.id === 'string',
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Write a checks file (`<artifact>.checks.json`). */
|
|
456
|
+
export async function writeChecks(
|
|
457
|
+
path: string,
|
|
458
|
+
rows: readonly CheckRow[],
|
|
459
|
+
fileSystem: FileSystem = createNodeFileSystem(),
|
|
460
|
+
): Promise<void> {
|
|
461
|
+
await fileSystem.writeFile(path, serializeChecks(rows));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Merge a fresh row set into an existing checks file: rows with the same `id`
|
|
466
|
+
* are replaced, new ones appended, everything else preserved. The delivery check
|
|
467
|
+
* uses this so `delivery.*` rows join the take rows in one file (R4) without
|
|
468
|
+
* rewriting them.
|
|
469
|
+
*/
|
|
470
|
+
export function mergeChecks(existing: readonly CheckRow[], incoming: readonly CheckRow[]): CheckRow[] {
|
|
471
|
+
const merged = [...existing];
|
|
472
|
+
for (const row of incoming) {
|
|
473
|
+
const index = merged.findIndex((candidate) => candidate.id === row.id);
|
|
474
|
+
if (index === -1) {
|
|
475
|
+
merged.push(row);
|
|
476
|
+
} else {
|
|
477
|
+
merged[index] = row;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return merged;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Outcome of a take check run. */
|
|
484
|
+
export interface TakeCheckOutcome {
|
|
485
|
+
/** The rows written to `<artifact>.checks.json`. */
|
|
486
|
+
rows: CheckRow[];
|
|
487
|
+
ok: boolean;
|
|
488
|
+
/** `0` when no row failed, `1` otherwise (R2's "exits non-zero exactly when any check is fail"). */
|
|
489
|
+
exitCode: number;
|
|
490
|
+
checksPath: string;
|
|
491
|
+
/** The measurement, when it landed — 0402's rubric reads these numbers. */
|
|
492
|
+
measurement?: AudioMeasurement;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** Everything {@link runTakeChecks} needs. */
|
|
496
|
+
export interface TakeCheckOptions extends TakeCheckInput, MeasureOptions {
|
|
497
|
+
/** The provider take on disk. */
|
|
498
|
+
artifactPath: string;
|
|
499
|
+
/** Override the checks-file path (defaults to {@link checksPathFor}). */
|
|
500
|
+
checksPath?: string;
|
|
501
|
+
fileSystem?: FileSystem;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Measure a take and write its pre-master checks (R2).
|
|
506
|
+
*
|
|
507
|
+
* A measurement failure is recorded as `fail` rows rather than thrown, so
|
|
508
|
+
* `checks.json` always explains itself and the caller's exit code is the same
|
|
509
|
+
* either way. Any other error (e.g. an unwritable checks path) still throws.
|
|
510
|
+
*/
|
|
511
|
+
export async function runTakeChecks(options: TakeCheckOptions): Promise<TakeCheckOutcome> {
|
|
512
|
+
const {
|
|
513
|
+
artifactPath,
|
|
514
|
+
model,
|
|
515
|
+
durationTarget,
|
|
516
|
+
analysis,
|
|
517
|
+
briefStyle,
|
|
518
|
+
briefSectionCount,
|
|
519
|
+
checksPath,
|
|
520
|
+
fileSystem,
|
|
521
|
+
...measure
|
|
522
|
+
} = options;
|
|
523
|
+
let measurement: AudioMeasurement | undefined;
|
|
524
|
+
let measurementError: string | undefined;
|
|
525
|
+
try {
|
|
526
|
+
measurement = await measureAudio(artifactPath, measure);
|
|
527
|
+
} catch (error: unknown) {
|
|
528
|
+
measurementError = error instanceof AudioToolError ? error.message : String(error);
|
|
529
|
+
}
|
|
530
|
+
const rows = buildTakeCheckRows({
|
|
531
|
+
model,
|
|
532
|
+
...(durationTarget === undefined ? {} : { durationTarget }),
|
|
533
|
+
...(measurement === undefined ? {} : { measurement }),
|
|
534
|
+
...(measurementError === undefined ? {} : { measurementError }),
|
|
535
|
+
...(analysis === undefined ? {} : { analysis }),
|
|
536
|
+
...(briefStyle === undefined ? {} : { briefStyle }),
|
|
537
|
+
...(briefSectionCount === undefined ? {} : { briefSectionCount }),
|
|
538
|
+
});
|
|
539
|
+
const path = checksPath ?? checksPathFor(artifactPath);
|
|
540
|
+
await writeChecks(path, rows, fileSystem ?? createNodeFileSystem());
|
|
541
|
+
return {
|
|
542
|
+
rows,
|
|
543
|
+
ok: checksPassed(rows),
|
|
544
|
+
exitCode: checksExitCode(rows),
|
|
545
|
+
checksPath: path,
|
|
546
|
+
...(measurement === undefined ? {} : { measurement }),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Everything the delivery check needs. */
|
|
551
|
+
export interface DeliveryCheckInput {
|
|
552
|
+
/** The profile the master pass targeted. */
|
|
553
|
+
profile: DeliveryProfile;
|
|
554
|
+
/** The profile's name, recorded in row notes. */
|
|
555
|
+
profileName: string;
|
|
556
|
+
/** The measurement of the **encoded output** (R4), never the intermediate. */
|
|
557
|
+
measurement?: AudioMeasurement;
|
|
558
|
+
/** The measurement failure, when there is one. */
|
|
559
|
+
measurementError?: string;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Build the post-master delivery rows (R4): integrated loudness inside
|
|
564
|
+
* `lufs ± 1 LU`, true peak at or below the ceiling, and the sample rate the
|
|
565
|
+
* profile asked for (the end-to-end proof of the `-ar` guard).
|
|
566
|
+
*
|
|
567
|
+
* A missing loudness measurement fails the loudness and true-peak rows: a
|
|
568
|
+
* delivery whose target cannot be verified is not a delivery.
|
|
569
|
+
*/
|
|
570
|
+
export function buildDeliveryCheckRows(input: DeliveryCheckInput): CheckRow[] {
|
|
571
|
+
const { profile, profileName, measurement, measurementError } = input;
|
|
572
|
+
const loudnessSource = `${measurement?.tools.ffmpeg ?? 'ffmpeg'} loudnorm`;
|
|
573
|
+
const probeSource = measurement?.tools.ffprobe ?? 'ffprobe';
|
|
574
|
+
const low = profile.lufs - DELIVERY_LOUDNESS_TOLERANCE_LU;
|
|
575
|
+
const high = profile.lufs + DELIVERY_LOUDNESS_TOLERANCE_LU;
|
|
576
|
+
const loudnessThreshold = band(low, high);
|
|
577
|
+
const rows: CheckRow[] = [];
|
|
578
|
+
|
|
579
|
+
if (measurement === undefined) {
|
|
580
|
+
const note = `measurement of the encoded output failed: ${measurementError ?? 'no measurement'}`;
|
|
581
|
+
rows.push(unmeasuredRow('delivery.integrated_loudness', loudnessThreshold, 'LUFS', loudnessSource, note));
|
|
582
|
+
rows.push(unmeasuredRow('delivery.true_peak', profile.truePeak, 'dBTP', loudnessSource, note));
|
|
583
|
+
rows.push(unmeasuredRow('delivery.sample_rate', profile.sampleRate, 'Hz', probeSource, note));
|
|
584
|
+
return rows;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const integrated = measurement.loudness.integratedLufs;
|
|
588
|
+
rows.push({
|
|
589
|
+
id: 'delivery.integrated_loudness',
|
|
590
|
+
measured: round(integrated),
|
|
591
|
+
threshold: loudnessThreshold,
|
|
592
|
+
unit: 'LUFS',
|
|
593
|
+
source: loudnessSource,
|
|
594
|
+
result: integrated >= low && integrated <= high ? 'pass' : 'fail',
|
|
595
|
+
note: `${profileName} target ${String(profile.lufs)} LUFS ±${String(DELIVERY_LOUDNESS_TOLERANCE_LU)} LU`,
|
|
596
|
+
});
|
|
597
|
+
const truePeak = measurement.loudness.truePeakDbtp;
|
|
598
|
+
rows.push({
|
|
599
|
+
id: 'delivery.true_peak',
|
|
600
|
+
measured: round(truePeak),
|
|
601
|
+
threshold: profile.truePeak,
|
|
602
|
+
unit: 'dBTP',
|
|
603
|
+
source: loudnessSource,
|
|
604
|
+
result: truePeak <= profile.truePeak ? 'pass' : 'fail',
|
|
605
|
+
note: `${profileName} ceiling ${String(profile.truePeak)} dBTP, measured on the encoded output`,
|
|
606
|
+
});
|
|
607
|
+
const sampleRate = measurement.probe.sampleRate;
|
|
608
|
+
rows.push({
|
|
609
|
+
id: 'delivery.sample_rate',
|
|
610
|
+
measured: sampleRate,
|
|
611
|
+
threshold: profile.sampleRate,
|
|
612
|
+
unit: 'Hz',
|
|
613
|
+
source: probeSource,
|
|
614
|
+
result: sampleRate === profile.sampleRate ? 'pass' : 'fail',
|
|
615
|
+
note: 'the `-ar` guard: loudnorm upsamples to 192 kHz unless the output rate is explicit',
|
|
616
|
+
});
|
|
617
|
+
return rows;
|
|
618
|
+
}
|