@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,624 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Music stage runner — the composition owner for `plugins/kk/workflows/kk-music.yaml`
|
|
4
|
+
* (task 0403, feature D8; ADR-115 keeps each YAML action one bounded call).
|
|
5
|
+
*
|
|
6
|
+
* music-prepare <works> <topic> <idea_file> <format> <theme> <directions> <force> <run_id>
|
|
7
|
+
* music-explore <run_dir> <directions> <force> <force_reason> <dry_run> <run_id> [<kk_bin>]
|
|
8
|
+
* music-select <run_dir> <choice> <auto>
|
|
9
|
+
* music-analyze <run_dir> <dry_run> [<kk_bin>]
|
|
10
|
+
* music-judge-input <run_dir>
|
|
11
|
+
* music-finalize <run_dir> <delivery_profile> <format> <run_id>
|
|
12
|
+
*
|
|
13
|
+
* **Why this file exists.** The workflow's states are `prepare -> brief -> explore -> select ->
|
|
14
|
+
* analyze -> check -> judge -> master -> finalize`. Five of those are one `kk music` verb
|
|
15
|
+
* (`check`, `master`) or one `agent.run` (`brief`, `judge`), but four are a *fan-out* or an
|
|
16
|
+
* *assembly*: authoring the run directory, taking one paid take per differentiated brief,
|
|
17
|
+
* binding the selected take and analyzing only it, assembling the judge bundle, and writing the
|
|
18
|
+
* run report. The engine executes one state at a time, so a fan-out is a verb — and each of those
|
|
19
|
+
* bodies is more than the five logical commands ADR-115 allows a shell action.
|
|
20
|
+
*
|
|
21
|
+
* **Money.** This file owns no spend rule. Every paid call is one `kk music gen` / `kk music
|
|
22
|
+
* analyze` child process, so 0400's estimate, confirmation, run-scoped dedupe and take cap decide
|
|
23
|
+
* everything. The stage adds exactly one thing on top: a brief whose take is already on disk is
|
|
24
|
+
* *adopted* (sidecar + artifact present → no child process at all), which is R5's resume rule and
|
|
25
|
+
* R2's "re-running explore pays only for briefs without a take".
|
|
26
|
+
*
|
|
27
|
+
* **No instance traffic of its own.** Node/Bun builtins only — no `@gobing-ai/*`, no HTTP, no
|
|
28
|
+
* ffmpeg. `KK_MUSIC_DRY_RUN` is inherited by the children, and the workflow's `dry_run` var
|
|
29
|
+
* forces it, so a dry run reaches the same code path as a paid one.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
34
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
35
|
+
|
|
36
|
+
/** The shipped format presets (`kk music presets`): each one names its own model. */
|
|
37
|
+
export const MUSIC_FORMATS = ['song', 'jingle', 'underscore', 'clip', 'loop'] as const;
|
|
38
|
+
|
|
39
|
+
/** Hard cap on directions — 0400's `HARD_TAKES_CAP` (the brief schema's `MAX_TAKES`). */
|
|
40
|
+
export const MAX_DIRECTIONS = 4;
|
|
41
|
+
|
|
42
|
+
/** Default directions: two differentiated briefs (0400's default `takesCap`). */
|
|
43
|
+
export const DEFAULT_DIRECTIONS = 2;
|
|
44
|
+
|
|
45
|
+
/** Run-report and selection file names, under the run directory. */
|
|
46
|
+
export const SELECTION_FILE = '3-takes/selection.json';
|
|
47
|
+
export const EXPLORE_FILE = '3-takes/explore.json';
|
|
48
|
+
export const JUDGE_INPUT_FILE = '4-judge-input.md';
|
|
49
|
+
export const VERDICT_FILE = '4-verdict-music.json';
|
|
50
|
+
export const REPORT_FILE = '5-run-report.md';
|
|
51
|
+
export const REPORT_JSON_FILE = '5-run-report.json';
|
|
52
|
+
|
|
53
|
+
/** Fail loudly: one message on stderr, exit 1 (the stage contract every sibling runner uses). */
|
|
54
|
+
export function fail(message: string): never {
|
|
55
|
+
console.error(`music: ${message}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `01`..`04` — the two-digit brief number the run-directory contract uses. */
|
|
60
|
+
export function briefNumber(n: number): string {
|
|
61
|
+
return String(n).padStart(2, '0');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** kebab-case a title into a directory-safe slug (the same rule the artifact names use). */
|
|
65
|
+
export function topicSlug(raw: string): string {
|
|
66
|
+
const slug = raw
|
|
67
|
+
.normalize('NFKD')
|
|
68
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
69
|
+
.toLowerCase()
|
|
70
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
71
|
+
.replace(/^-+/, '')
|
|
72
|
+
.replace(/-+$/, '');
|
|
73
|
+
return slug === '' ? 'music' : slug.slice(0, 48).replace(/-+$/, '');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Read + parse a JSON file, failing with the exact path when it is missing or malformed. */
|
|
77
|
+
export function readJson<T>(path: string): T {
|
|
78
|
+
if (!existsSync(path)) fail(`missing artifact ${path}`);
|
|
79
|
+
try {
|
|
80
|
+
return JSON.parse(readFileSync(path, 'utf-8')) as T;
|
|
81
|
+
} catch (error: unknown) {
|
|
82
|
+
return fail(`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Write a JSON artifact the way every kk artifact is written: 4-space JSON plus one newline. */
|
|
87
|
+
export function writeJson(path: string, value: unknown): void {
|
|
88
|
+
writeFileSync(path, `${JSON.stringify(value, null, 4)}\n`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the `kk` invocation a paid child runs under.
|
|
93
|
+
*
|
|
94
|
+
* Precedence: the explicit stage argument, then `KK_MUSIC_KK_BIN`, then `kk` on `PATH`. A checkout
|
|
95
|
+
* entry (`…/apps/cli/src/index.ts`) runs under this process's own Bun, so a test or a pre-release
|
|
96
|
+
* probe exercises this tree's verbs instead of whatever `kk` the install left on PATH (task 1110).
|
|
97
|
+
*/
|
|
98
|
+
export function kkArgv(bin: string | undefined): string[] {
|
|
99
|
+
const chosen = (bin ?? '').trim() || (process.env.KK_MUSIC_KK_BIN ?? '').trim() || 'kk';
|
|
100
|
+
return chosen.endsWith('.ts') || chosen.endsWith('.js') ? [process.execPath, chosen] : [chosen];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** One take as `content-<nn>.json` records it. */
|
|
104
|
+
export interface TakeRecord {
|
|
105
|
+
takeIndex: number;
|
|
106
|
+
instanceId: string;
|
|
107
|
+
model: string;
|
|
108
|
+
format: string;
|
|
109
|
+
digest: string;
|
|
110
|
+
artifactPath: string;
|
|
111
|
+
sidecarPath: string;
|
|
112
|
+
unitPrice: number | null;
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The single take a run delivers: what `select` binds and every later state reads. */
|
|
117
|
+
export interface Selection {
|
|
118
|
+
schemaVersion: 1;
|
|
119
|
+
brief: string;
|
|
120
|
+
auto: boolean;
|
|
121
|
+
take: TakeRecord;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Read `content-<nn>.json`'s take records, keeping only the ones whose artifact is on disk. */
|
|
125
|
+
export function existingTakes(contentPath: string): TakeRecord[] {
|
|
126
|
+
if (!existsSync(contentPath)) return [];
|
|
127
|
+
const parsed = readJson<{ metadata?: { takes?: TakeRecord[] } }>(contentPath);
|
|
128
|
+
const takes = parsed.metadata?.takes ?? [];
|
|
129
|
+
return takes.filter((take) => typeof take.artifactPath === 'string' && existsSync(take.artifactPath));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The run directory for one idea: `<works>/kk-music/<topic-slug>/`. */
|
|
133
|
+
export function runDirFor(works: string, topic: string, ideaFile: string): string {
|
|
134
|
+
const label = topic.trim() !== '' ? topic : basename(ideaFile).replace(/\.[^.]+$/, '');
|
|
135
|
+
return join(resolve(works), 'kk-music', topicSlug(label));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Write the selection and the two single-token projections `analyze`/`check`/`master` read. */
|
|
139
|
+
export function writeSelection(runDir: string, selection: Selection): void {
|
|
140
|
+
writeJson(join(runDir, SELECTION_FILE), selection);
|
|
141
|
+
writeFileSync(join(runDir, '3-takes/.take-file'), `${basename(selection.take.artifactPath)}\n`);
|
|
142
|
+
writeFileSync(join(runDir, '3-takes/.instance-id'), `${selection.take.instanceId}\n`);
|
|
143
|
+
writeFileSync(join(runDir, '3-takes/.brief'), `${selection.brief}\n`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Read the recorded selection, failing on a run that has not passed the gate yet. */
|
|
147
|
+
export function readSelection(runDir: string): Selection {
|
|
148
|
+
const selection = readJson<Selection>(join(runDir, SELECTION_FILE));
|
|
149
|
+
if (typeof selection.take?.artifactPath !== 'string' || !existsSync(selection.take.artifactPath)) {
|
|
150
|
+
fail(`selection names a take that is not on disk: ${String(selection.take?.artifactPath)}`);
|
|
151
|
+
}
|
|
152
|
+
return selection;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* `music-prepare` — resolve the run directory, stage its subdirectories, write `idea.md` and
|
|
157
|
+
* publish the run-bound path the workflow projects back into `vars.run_dir`.
|
|
158
|
+
*/
|
|
159
|
+
export function musicPrepare(args: string[]): void {
|
|
160
|
+
const [worksRaw = '', topic = '', ideaFile = '', format = 'song', theme = '', directionsRaw = '', , runId = ''] =
|
|
161
|
+
args;
|
|
162
|
+
if (topic.trim() === '' && ideaFile.trim() === '') {
|
|
163
|
+
fail('a topic (or an idea file) is required: pass topic="<one line idea>" or idea_file=<path>');
|
|
164
|
+
}
|
|
165
|
+
if (ideaFile.trim() !== '' && !existsSync(resolve(ideaFile))) {
|
|
166
|
+
fail(`idea file not found: ${resolve(ideaFile)}`);
|
|
167
|
+
}
|
|
168
|
+
if ((MUSIC_FORMATS as readonly string[]).includes(format) === false) {
|
|
169
|
+
fail(`unknown format "${format}" (use one of ${MUSIC_FORMATS.join(', ')} — see kk music presets)`);
|
|
170
|
+
}
|
|
171
|
+
if (theme.trim() === '') {
|
|
172
|
+
fail('a theme preset is required (see kk music presets for the shipped themes)');
|
|
173
|
+
}
|
|
174
|
+
const directions = directionsRaw.trim() === '' ? DEFAULT_DIRECTIONS : Number(directionsRaw);
|
|
175
|
+
if (!Number.isInteger(directions) || directions < 1 || directions > MAX_DIRECTIONS) {
|
|
176
|
+
fail(`directions ${directionsRaw} is not a whole number between 1 and ${MAX_DIRECTIONS}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const runDir = runDirFor(worksRaw === '' ? '.works' : worksRaw, topic, ideaFile);
|
|
180
|
+
mkdirSync(join(runDir, '1-brief'), { recursive: true });
|
|
181
|
+
mkdirSync(join(runDir, '3-takes'), { recursive: true });
|
|
182
|
+
|
|
183
|
+
const ideaPath = join(runDir, 'idea.md');
|
|
184
|
+
if (!existsSync(ideaPath)) {
|
|
185
|
+
if (ideaFile.trim() !== '') {
|
|
186
|
+
copyFileSync(resolve(ideaFile), ideaPath);
|
|
187
|
+
} else {
|
|
188
|
+
writeFileSync(ideaPath, `${topic.trim()}\n`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Two projections, one value: the operator-facing pointer beside the runs, and the run-bound
|
|
193
|
+
// file the workflow reads into `vars.run_dir` (the smart-seo preflight pattern).
|
|
194
|
+
const musicRoot = dirname(runDir);
|
|
195
|
+
writeFileSync(join(musicRoot, '.run-dir.txt'), `${runDir}\n`);
|
|
196
|
+
mkdirSync(resolve('.spur/run'), { recursive: true });
|
|
197
|
+
writeFileSync(resolve('.spur/run', `${runId}-music-run-dir.txt`), `${runDir}\n`);
|
|
198
|
+
|
|
199
|
+
console.error(
|
|
200
|
+
`music run directory: ${runDir} (format ${format}, theme ${theme}, directions ${String(directions)})`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** `music-explore` — one paid take per differentiated brief, adopting any brief already taken (R2/R5). */
|
|
205
|
+
export function musicExplore(args: string[]): void {
|
|
206
|
+
const [runDirRaw = '', directionsRaw = '', forceRaw = '', forceReason = '', dryRunRaw = '', runId = '', kkBin] =
|
|
207
|
+
args;
|
|
208
|
+
const runDir = resolve(runDirRaw === '' ? '.' : runDirRaw);
|
|
209
|
+
if (!existsSync(runDir)) fail(`run directory not found: ${runDir}`);
|
|
210
|
+
const directions = directionsRaw.trim() === '' ? DEFAULT_DIRECTIONS : Number(directionsRaw);
|
|
211
|
+
if (!Number.isInteger(directions) || directions < 1 || directions > MAX_DIRECTIONS) {
|
|
212
|
+
fail(`directions ${directionsRaw} is not a whole number between 1 and ${MAX_DIRECTIONS}`);
|
|
213
|
+
}
|
|
214
|
+
const force = forceRaw === 'true';
|
|
215
|
+
if (force && forceReason.trim() === '') {
|
|
216
|
+
fail('force needs a force_reason: a paid re-roll is never silent (0400 --force --reason <text>)');
|
|
217
|
+
}
|
|
218
|
+
const dryRun = dryRunRaw === 'true';
|
|
219
|
+
|
|
220
|
+
const briefs: Record<string, unknown>[] = [];
|
|
221
|
+
const takes: TakeRecord[] = [];
|
|
222
|
+
for (let index = 1; index <= directions; index += 1) {
|
|
223
|
+
const nn = briefNumber(index);
|
|
224
|
+
const briefPath = join(runDir, '1-brief', `brief-${nn}.yaml`);
|
|
225
|
+
const contentPath = join(runDir, '3-takes', `content-${nn}.json`);
|
|
226
|
+
if (!existsSync(briefPath)) {
|
|
227
|
+
fail(`missing brief ${briefPath} — author every direction before exploring (task's brief state)`);
|
|
228
|
+
}
|
|
229
|
+
const adopted = existingTakes(contentPath);
|
|
230
|
+
if (adopted.length > 0) {
|
|
231
|
+
const take = adopted[0] as TakeRecord;
|
|
232
|
+
takes.push(take);
|
|
233
|
+
briefs.push({
|
|
234
|
+
brief: briefPath,
|
|
235
|
+
content: contentPath,
|
|
236
|
+
status: 'adopted',
|
|
237
|
+
paid: false,
|
|
238
|
+
instanceId: take.instanceId,
|
|
239
|
+
model: take.model,
|
|
240
|
+
digest: take.digest,
|
|
241
|
+
unitPrice: take.unitPrice,
|
|
242
|
+
artifactPath: take.artifactPath,
|
|
243
|
+
});
|
|
244
|
+
console.error(`brief ${nn}: adopted ${take.artifactPath} (sidecar on disk — no paid request)`);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const command = [
|
|
249
|
+
...kkArgv(kkBin),
|
|
250
|
+
'music',
|
|
251
|
+
'gen',
|
|
252
|
+
'--in',
|
|
253
|
+
briefPath,
|
|
254
|
+
'--out',
|
|
255
|
+
contentPath,
|
|
256
|
+
'--takes',
|
|
257
|
+
'1',
|
|
258
|
+
'--yes',
|
|
259
|
+
...(force ? ['--force', '--reason', forceReason] : []),
|
|
260
|
+
];
|
|
261
|
+
const child = spawnSync(command[0] as string, command.slice(1), {
|
|
262
|
+
encoding: 'utf-8',
|
|
263
|
+
env: { ...process.env, ...(dryRun ? { KK_MUSIC_DRY_RUN: '1' } : {}) },
|
|
264
|
+
});
|
|
265
|
+
if (child.status !== 0) {
|
|
266
|
+
fail(`brief ${nn}: kk music gen failed (exit ${String(child.status)}): ${child.stderr.trim()}`);
|
|
267
|
+
}
|
|
268
|
+
const generated = existingTakes(contentPath);
|
|
269
|
+
if (generated.length === 0) {
|
|
270
|
+
fail(`brief ${nn}: kk music gen wrote no take beside ${contentPath}`);
|
|
271
|
+
}
|
|
272
|
+
const take = generated[0] as TakeRecord;
|
|
273
|
+
takes.push(take);
|
|
274
|
+
briefs.push({
|
|
275
|
+
brief: briefPath,
|
|
276
|
+
content: contentPath,
|
|
277
|
+
status: 'generated',
|
|
278
|
+
paid: true,
|
|
279
|
+
instanceId: take.instanceId,
|
|
280
|
+
model: take.model,
|
|
281
|
+
digest: take.digest,
|
|
282
|
+
unitPrice: take.unitPrice,
|
|
283
|
+
artifactPath: take.artifactPath,
|
|
284
|
+
});
|
|
285
|
+
console.error(`brief ${nn}: generated ${take.artifactPath} (instance ${take.instanceId}, model ${take.model})`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// The single take a run has is not a choice: record it so `auto` can skip the operator gate.
|
|
289
|
+
// With two or more takes the selection needs the operator (`select`), never a guess.
|
|
290
|
+
if (takes.length === 1) {
|
|
291
|
+
writeSelection(runDir, { schemaVersion: 1, brief: briefNumber(1), auto: true, take: takes[0] as TakeRecord });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
writeJson(join(runDir, EXPLORE_FILE), {
|
|
295
|
+
schemaVersion: 1,
|
|
296
|
+
runId,
|
|
297
|
+
directions,
|
|
298
|
+
takes: takes.length,
|
|
299
|
+
dryRun: dryRun || takes.some((take) => take.artifactPath.includes('offline')),
|
|
300
|
+
briefs,
|
|
301
|
+
});
|
|
302
|
+
console.error(`explore: ${String(takes.length)} take(s) across ${String(directions)} direction(s)`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** `music-select` — the operator's pick, validated against the takes actually on disk (the only gate). */
|
|
306
|
+
export function musicSelect(args: string[]): void {
|
|
307
|
+
const [runDirRaw = '', choiceRaw = '', autoRaw = 'false'] = args;
|
|
308
|
+
const runDir = resolve(runDirRaw === '' ? '.' : runDirRaw);
|
|
309
|
+
const choice = choiceRaw.trim();
|
|
310
|
+
if (choice === '') {
|
|
311
|
+
// The auto path: explore already bound the single take. Validate it is still whole.
|
|
312
|
+
const selection = readSelection(runDir);
|
|
313
|
+
console.error(`select: auto — brief ${selection.brief}, ${selection.take.artifactPath}`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const nn = /^\d$/.test(choice) ? briefNumber(Number(choice)) : choice;
|
|
317
|
+
if (!existsSync(join(runDir, '1-brief', `brief-${nn}.yaml`))) {
|
|
318
|
+
fail(`selection ${choice} names no authored brief (1-brief/brief-${nn}.yaml is missing)`);
|
|
319
|
+
}
|
|
320
|
+
const takes = existingTakes(join(runDir, '3-takes', `content-${nn}.json`));
|
|
321
|
+
if (takes.length === 0) {
|
|
322
|
+
fail(`selection ${choice} names no take on disk (3-takes/content-${nn}.json has no existing artifact)`);
|
|
323
|
+
}
|
|
324
|
+
const take = takes[0] as TakeRecord;
|
|
325
|
+
writeSelection(runDir, { schemaVersion: 1, brief: nn, auto: autoRaw === 'true', take });
|
|
326
|
+
console.error(`select: brief ${nn} → ${take.artifactPath} (instance ${take.instanceId})`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* `music-analyze` — pay for the selected take's instance analysis, once.
|
|
331
|
+
*
|
|
332
|
+
* A cached `analysis-<instanceId>.json` is adopted without a call (R5), and a take whose sidecar
|
|
333
|
+
* says `dryRun` gets the synthetic offline analysis spelled out as such: `KK_MUSIC_DRY_RUN=1` must
|
|
334
|
+
* stay free (AC5) and the file must never look like a paid measurement.
|
|
335
|
+
*/
|
|
336
|
+
export function musicAnalyze(args: string[]): void {
|
|
337
|
+
const [runDirRaw = '', dryRunRaw = 'false', kkBin] = args;
|
|
338
|
+
const runDir = resolve(runDirRaw === '' ? '.' : runDirRaw);
|
|
339
|
+
const selection = readSelection(runDir);
|
|
340
|
+
const instanceId = selection.take.instanceId;
|
|
341
|
+
const analysisPath = join(runDir, '3-takes', `analysis-${instanceId}.json`);
|
|
342
|
+
if (existsSync(analysisPath) && statSync(analysisPath).size > 0) {
|
|
343
|
+
console.error(`analyze: adopted ${analysisPath} (cached — no paid request)`);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const sidecar = readJson<{ dryRun?: boolean; model?: string }>(selection.take.sidecarPath);
|
|
347
|
+
if (dryRunRaw === 'true' || sidecar.dryRun === true) {
|
|
348
|
+
writeJson(analysisPath, {
|
|
349
|
+
dryRun: true,
|
|
350
|
+
provider: 'offline',
|
|
351
|
+
model: sidecar.model ?? selection.take.model,
|
|
352
|
+
summary: 'offline: synthetic analysis, no instance was called',
|
|
353
|
+
durationSeconds: 1,
|
|
354
|
+
});
|
|
355
|
+
console.error(`analyze: dry run — wrote the synthetic analysis to ${analysisPath} (no instance was called)`);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const command = [...kkArgv(kkBin), 'music', 'analyze', instanceId, '--yes', '--json'];
|
|
359
|
+
const child = spawnSync(command[0] as string, command.slice(1), { encoding: 'utf-8', env: { ...process.env } });
|
|
360
|
+
if (child.status !== 0) {
|
|
361
|
+
fail(`kk music analyze ${instanceId} failed (exit ${String(child.status)}): ${child.stderr.trim()}`);
|
|
362
|
+
}
|
|
363
|
+
writeFileSync(analysisPath, child.stdout);
|
|
364
|
+
console.error(`analyze: charged the instance analysis for ${instanceId} → ${analysisPath}`);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The analysis object of an `analysis-<id>.json` file: the verb's `--json` envelope or a bare object. */
|
|
368
|
+
export function analysisObject(raw: string): Record<string, unknown> {
|
|
369
|
+
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
370
|
+
const nested = parsed.analysis;
|
|
371
|
+
return typeof nested === 'object' && nested !== null ? (nested as Record<string, unknown>) : parsed;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** `music-judge-input` — assemble `4-judge-input.md` from the five verbatim inputs (0402's contract). */
|
|
375
|
+
export function musicJudgeInput(args: string[]): void {
|
|
376
|
+
const [runDirRaw = ''] = args;
|
|
377
|
+
const runDir = resolve(runDirRaw === '' ? '.' : runDirRaw);
|
|
378
|
+
const selection = readSelection(runDir);
|
|
379
|
+
const nn = selection.brief;
|
|
380
|
+
const required: Record<string, string> = {
|
|
381
|
+
brief: join(runDir, '1-brief', `brief-${nn}.yaml`),
|
|
382
|
+
prompt: join(runDir, '1-brief', `brief-${nn}.prompt.txt`),
|
|
383
|
+
analysis: join(runDir, '3-takes', `analysis-${selection.take.instanceId}.json`),
|
|
384
|
+
checks: `${selection.take.artifactPath}.checks.json`,
|
|
385
|
+
provenance: selection.take.sidecarPath,
|
|
386
|
+
};
|
|
387
|
+
for (const [id, path] of Object.entries(required)) {
|
|
388
|
+
if (!existsSync(path)) {
|
|
389
|
+
fail(`judge bundle input "${id}" is missing: ${path} — the bundle is never written with a hole in it`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const rows = readJson<{ id: string; result: string; measured: unknown; unit: string; source: string }[]>(
|
|
393
|
+
required.checks as string,
|
|
394
|
+
);
|
|
395
|
+
const failed = rows.filter((row) => row.result === 'fail');
|
|
396
|
+
if (failed.length > 0) {
|
|
397
|
+
fail(
|
|
398
|
+
`checks.json carries a fail row (${failed
|
|
399
|
+
.map((row) => `${row.id} measured ${String(row.measured)} ${row.unit} from ${row.source}`)
|
|
400
|
+
.join('; ')}) — the take is not judgeable`,
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const read = (path: string): string => readFileSync(path, 'utf-8').replace(/\n+$/, '');
|
|
405
|
+
const briefText = read(required.brief as string);
|
|
406
|
+
const title = /^title:\s*(.+)$/m.exec(briefText)?.[1]?.trim() ?? basename(runDir);
|
|
407
|
+
const language = /^language:\s*(.+)$/m.exec(briefText)?.[1]?.trim() ?? 'EN';
|
|
408
|
+
const instrumental = /^instrumental:\s*true\s*$/m.test(briefText);
|
|
409
|
+
const lyricsPath = join(runDir, '2-lyrics.md');
|
|
410
|
+
const lyrics = instrumental
|
|
411
|
+
? 'instrumental brief — no lyric text is sent'
|
|
412
|
+
: existsSync(lyricsPath)
|
|
413
|
+
? read(lyricsPath)
|
|
414
|
+
: 'model-authored lyrics are not in the bundle';
|
|
415
|
+
const sidecar = readJson<Record<string, unknown>>(required.provenance as string);
|
|
416
|
+
|
|
417
|
+
const bundle = [
|
|
418
|
+
`# Music judge input — ${title} / brief ${nn}`,
|
|
419
|
+
'',
|
|
420
|
+
`Judged take: ${selection.take.artifactPath}`,
|
|
421
|
+
'Rubric: music-quality',
|
|
422
|
+
`Verdict path: ${VERDICT_FILE}`,
|
|
423
|
+
'',
|
|
424
|
+
'Every number in this bundle comes from section 5 (`checks.json`) with the `unit` and `source` it was',
|
|
425
|
+
'recorded with. The take’s audio is not attached: nothing here may be graded by ear.',
|
|
426
|
+
'',
|
|
427
|
+
'## 1. brief',
|
|
428
|
+
'',
|
|
429
|
+
'```yaml',
|
|
430
|
+
briefText,
|
|
431
|
+
'```',
|
|
432
|
+
'',
|
|
433
|
+
'## 2. prompt',
|
|
434
|
+
'',
|
|
435
|
+
'```text',
|
|
436
|
+
read(required.prompt as string),
|
|
437
|
+
'```',
|
|
438
|
+
'',
|
|
439
|
+
'## 3. lyrics',
|
|
440
|
+
'',
|
|
441
|
+
`Language: ${language}`,
|
|
442
|
+
'',
|
|
443
|
+
'```text',
|
|
444
|
+
lyrics,
|
|
445
|
+
'```',
|
|
446
|
+
'',
|
|
447
|
+
'## 4. analysis',
|
|
448
|
+
'',
|
|
449
|
+
'```json',
|
|
450
|
+
JSON.stringify(analysisObject(read(required.analysis as string)), null, 4),
|
|
451
|
+
'```',
|
|
452
|
+
'',
|
|
453
|
+
'## 5. checks',
|
|
454
|
+
'',
|
|
455
|
+
'```json',
|
|
456
|
+
read(required.checks as string),
|
|
457
|
+
'```',
|
|
458
|
+
'',
|
|
459
|
+
'## 6. provenance',
|
|
460
|
+
'',
|
|
461
|
+
`- content_ref: \`${selection.take.artifactPath}\``,
|
|
462
|
+
`- checks: \`${required.checks}\``,
|
|
463
|
+
`- sidecar: \`${required.provenance}\``,
|
|
464
|
+
`- digest: \`${String(sidecar.digest ?? selection.take.digest)}\``,
|
|
465
|
+
`- instanceId: \`${selection.take.instanceId}\``,
|
|
466
|
+
`- model: \`${selection.take.model}\``,
|
|
467
|
+
`- unitPrice: \`${String(sidecar.unitPrice ?? selection.take.unitPrice ?? 'unpriced')}\``,
|
|
468
|
+
`- runId: \`${String(sidecar.runId ?? '')}\``,
|
|
469
|
+
'',
|
|
470
|
+
].join('\n');
|
|
471
|
+
writeFileSync(join(runDir, JUDGE_INPUT_FILE), bundle);
|
|
472
|
+
console.error(`judge bundle written: ${join(runDir, JUDGE_INPUT_FILE)}`);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* `music-finalize` — the run report (R4): spend summed from the take sidecars, the instance ids,
|
|
477
|
+
* the verdict, the delivery profile with its measured loudness, and the final artifact path.
|
|
478
|
+
*/
|
|
479
|
+
export function musicFinalize(args: string[]): void {
|
|
480
|
+
const [runDirRaw = '', profile = 'streaming', format = 'song', runId = ''] = args;
|
|
481
|
+
const runDir = resolve(runDirRaw === '' ? '.' : runDirRaw);
|
|
482
|
+
const selection = readSelection(runDir);
|
|
483
|
+
const verdictPath = join(runDir, VERDICT_FILE);
|
|
484
|
+
const verdict = readJson<{ verdict?: string; confidence?: string; score?: number; feedback?: string }>(verdictPath);
|
|
485
|
+
|
|
486
|
+
const takeDir = join(runDir, '3-takes');
|
|
487
|
+
const sidecars = readdirSync(takeDir)
|
|
488
|
+
.filter((name) => name.endsWith('.take.json'))
|
|
489
|
+
.sort()
|
|
490
|
+
.map((name) => ({ name, sidecar: readJson<Record<string, unknown>>(join(takeDir, name)) }));
|
|
491
|
+
const priced = sidecars
|
|
492
|
+
.map((entry) => entry.sidecar.unitPrice)
|
|
493
|
+
.filter((price): price is number => typeof price === 'number');
|
|
494
|
+
const spend = priced.reduce((sum, price) => sum + price, 0);
|
|
495
|
+
const unpriced = sidecars.length - priced.length;
|
|
496
|
+
|
|
497
|
+
const checksPath = `${selection.take.artifactPath}.checks.json`;
|
|
498
|
+
const checks =
|
|
499
|
+
readJson<{ id: string; measured: unknown; unit: string; threshold: unknown; result: string }[]>(checksPath);
|
|
500
|
+
const delivery = checks.filter((row) => row.id.startsWith('delivery.'));
|
|
501
|
+
if (delivery.length === 0) {
|
|
502
|
+
fail(`no delivery.* row in ${checksPath} — master must write the delivery check before finalize`);
|
|
503
|
+
}
|
|
504
|
+
const loudness = delivery.find((row) => row.id === 'delivery.integrated_loudness');
|
|
505
|
+
const truePeak = delivery.find((row) => row.id === 'delivery.true_peak');
|
|
506
|
+
|
|
507
|
+
const extension = extname(selection.take.artifactPath);
|
|
508
|
+
const stem = basename(selection.take.artifactPath, extension);
|
|
509
|
+
const masteredName = readdirSync(takeDir)
|
|
510
|
+
.filter((name) => name.startsWith(`${stem}.${profile}.`))
|
|
511
|
+
.sort()
|
|
512
|
+
.pop();
|
|
513
|
+
if (masteredName === undefined) {
|
|
514
|
+
fail(`no mastered file for ${selection.take.artifactPath} with profile "${profile}" — run kk music master`);
|
|
515
|
+
}
|
|
516
|
+
const masteredPath = join(takeDir, masteredName);
|
|
517
|
+
|
|
518
|
+
const report = [
|
|
519
|
+
`# Music run report — brief ${selection.brief}`,
|
|
520
|
+
'',
|
|
521
|
+
`- run: \`${runId}\``,
|
|
522
|
+
`- format: \`${format}\``,
|
|
523
|
+
`- delivery profile: \`${profile}\``,
|
|
524
|
+
`- final artifact: \`${masteredPath}\``,
|
|
525
|
+
'',
|
|
526
|
+
'## Spend',
|
|
527
|
+
'',
|
|
528
|
+
`Total: $${spend.toFixed(2)} across ${String(sidecars.length)} take(s)${
|
|
529
|
+
unpriced === 0 ? '' : ` (${String(unpriced)} unpriced)`
|
|
530
|
+
}.`,
|
|
531
|
+
'',
|
|
532
|
+
'| take | instance id | model | unit price | sidecar |',
|
|
533
|
+
'| --- | --- | --- | --- | --- |',
|
|
534
|
+
...sidecars.map(
|
|
535
|
+
({ name, sidecar }) =>
|
|
536
|
+
`| ${String(sidecar.artifactPath ?? name)} | ${String(sidecar.instanceId ?? '')} | ${String(
|
|
537
|
+
sidecar.model ?? '',
|
|
538
|
+
)} | ${typeof sidecar.unitPrice === 'number' ? `$${sidecar.unitPrice.toFixed(2)}` : 'unpriced'} | \`${name}\` |`,
|
|
539
|
+
),
|
|
540
|
+
'',
|
|
541
|
+
'## Verdict',
|
|
542
|
+
'',
|
|
543
|
+
`- verdict: \`${String(verdict.verdict ?? '')}\``,
|
|
544
|
+
`- confidence: \`${String(verdict.confidence ?? '')}\``,
|
|
545
|
+
`- score: \`${String(verdict.score ?? '')}\``,
|
|
546
|
+
...(verdict.feedback === undefined ? [] : ['', `Feedback: ${verdict.feedback}`]),
|
|
547
|
+
'',
|
|
548
|
+
'## Delivery',
|
|
549
|
+
'',
|
|
550
|
+
'| row | measured | unit | threshold | result | source |',
|
|
551
|
+
'| --- | --- | --- | --- | --- | --- |',
|
|
552
|
+
...delivery.map(
|
|
553
|
+
(row) =>
|
|
554
|
+
`| ${row.id} | ${String(row.measured)} | ${row.unit} | ${String(row.threshold)} | ${row.result} | ${String(
|
|
555
|
+
(row as { source?: string }).source ?? '',
|
|
556
|
+
)} |`,
|
|
557
|
+
),
|
|
558
|
+
'',
|
|
559
|
+
`- measured loudness: ${String(loudness?.measured ?? 'n/a')} LUFS`,
|
|
560
|
+
`- measured true peak: ${String(truePeak?.measured ?? 'n/a')} dBTP`,
|
|
561
|
+
'',
|
|
562
|
+
'## Artifacts',
|
|
563
|
+
'',
|
|
564
|
+
`- idea: \`idea.md\``,
|
|
565
|
+
`- briefs: \`1-brief/brief-${selection.brief}.yaml\` + \`1-brief/brief-${selection.brief}.prompt.txt\``,
|
|
566
|
+
`- take: \`${selection.take.artifactPath}\` (+ \`${basename(selection.take.sidecarPath)}\`)`,
|
|
567
|
+
`- checks: \`${checksPath}\``,
|
|
568
|
+
`- analysis: \`3-takes/analysis-${selection.take.instanceId}.json\``,
|
|
569
|
+
`- judge input: \`${JUDGE_INPUT_FILE}\``,
|
|
570
|
+
`- verdict: \`${VERDICT_FILE}\``,
|
|
571
|
+
`- mastered: \`${masteredPath}\``,
|
|
572
|
+
'',
|
|
573
|
+
].join('\n');
|
|
574
|
+
writeFileSync(join(runDir, REPORT_FILE), report);
|
|
575
|
+
writeJson(join(runDir, REPORT_JSON_FILE), {
|
|
576
|
+
schemaVersion: 1,
|
|
577
|
+
runId,
|
|
578
|
+
format,
|
|
579
|
+
profile,
|
|
580
|
+
finalArtifact: masteredPath,
|
|
581
|
+
spend: { total: spend, takes: sidecars.length, unpriced },
|
|
582
|
+
takes: sidecars.map(({ sidecar }) => ({
|
|
583
|
+
instanceId: sidecar.instanceId,
|
|
584
|
+
model: sidecar.model,
|
|
585
|
+
unitPrice: sidecar.unitPrice,
|
|
586
|
+
artifactPath: sidecar.artifactPath,
|
|
587
|
+
})),
|
|
588
|
+
verdict: { verdict: verdict.verdict ?? null, confidence: verdict.confidence ?? null },
|
|
589
|
+
delivery: {
|
|
590
|
+
integratedLoudness: loudness?.measured ?? null,
|
|
591
|
+
truePeak: truePeak?.measured ?? null,
|
|
592
|
+
rows: delivery,
|
|
593
|
+
},
|
|
594
|
+
});
|
|
595
|
+
console.error(
|
|
596
|
+
`run report written: ${join(runDir, REPORT_FILE)} ($${spend.toFixed(2)}, ${String(sidecars.length)} take(s))`,
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** Dispatch one `music-*` stage (the `kk stage run` entry point). */
|
|
601
|
+
export function runMusicStage(stage: string, args: string[]): void {
|
|
602
|
+
switch (stage) {
|
|
603
|
+
case 'music-prepare':
|
|
604
|
+
musicPrepare(args);
|
|
605
|
+
return;
|
|
606
|
+
case 'music-explore':
|
|
607
|
+
musicExplore(args);
|
|
608
|
+
return;
|
|
609
|
+
case 'music-select':
|
|
610
|
+
musicSelect(args);
|
|
611
|
+
return;
|
|
612
|
+
case 'music-analyze':
|
|
613
|
+
musicAnalyze(args);
|
|
614
|
+
return;
|
|
615
|
+
case 'music-judge-input':
|
|
616
|
+
musicJudgeInput(args);
|
|
617
|
+
return;
|
|
618
|
+
case 'music-finalize':
|
|
619
|
+
musicFinalize(args);
|
|
620
|
+
return;
|
|
621
|
+
default:
|
|
622
|
+
fail(`unknown music stage "${stage}"`);
|
|
623
|
+
}
|
|
624
|
+
}
|