@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.
Files changed (149) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/collect/index.js +1 -0
  3. package/dist/board/daily-voice/index.js +1279 -261
  4. package/dist/board/itc/index.js +1 -0
  5. package/dist/index.js +13938 -8966
  6. package/package.json +1 -1
  7. package/plugins/generations/dailynews-gen/dist/index.js +285 -16
  8. package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
  9. package/plugins/generations/dailynews-gen/src/index.ts +23 -4
  10. package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
  11. package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
  12. package/plugins/generations/gemini-tts/dist/index.js +47 -7
  13. package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
  14. package/plugins/generations/music-gen/README.md +277 -0
  15. package/plugins/generations/music-gen/dist/index.js +23580 -0
  16. package/plugins/generations/music-gen/package.json +24 -0
  17. package/plugins/generations/music-gen/plugin.json +23 -0
  18. package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
  19. package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
  20. package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
  21. package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
  22. package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
  23. package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
  24. package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
  25. package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
  26. package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
  27. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
  28. package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
  29. package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
  30. package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
  31. package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
  32. package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
  33. package/plugins/generations/music-gen/src/artifact.ts +223 -0
  34. package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
  35. package/plugins/generations/music-gen/src/audio/master.ts +267 -0
  36. package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
  37. package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
  38. package/plugins/generations/music-gen/src/audio.ts +122 -0
  39. package/plugins/generations/music-gen/src/brief.ts +191 -0
  40. package/plugins/generations/music-gen/src/config.ts +451 -0
  41. package/plugins/generations/music-gen/src/content.ts +199 -0
  42. package/plugins/generations/music-gen/src/digest.ts +100 -0
  43. package/plugins/generations/music-gen/src/index.ts +147 -0
  44. package/plugins/generations/music-gen/src/job.ts +131 -0
  45. package/plugins/generations/music-gen/src/plugin.ts +371 -0
  46. package/plugins/generations/music-gen/src/presets.ts +951 -0
  47. package/plugins/generations/music-gen/src/render.ts +87 -0
  48. package/plugins/generations/music-gen/src/request.ts +102 -0
  49. package/plugins/generations/music-gen/src/spend.ts +495 -0
  50. package/plugins/generations/music-gen/tsconfig.json +8 -0
  51. package/plugins/generations/omni-voice-gen/uv.toml +5 -0
  52. package/plugins/generations/vibe-voice-tts/README.md +64 -0
  53. package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
  54. package/plugins/generations/vibe-voice-tts/package.json +16 -0
  55. package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
  56. package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
  57. package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
  58. package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
  59. package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
  60. package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
  61. package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
  62. package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
  63. package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
  64. package/plugins/generations/voice-gen/dist/index.js +31 -1
  65. package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
  66. package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
  67. package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
  68. package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
  69. package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
  70. package/plugins/generations/voxcpm-tts/uv.toml +5 -0
  71. package/plugins/kk/README.md +21 -0
  72. package/plugins/kk/decisions/kk-safety.yaml +5 -2
  73. package/plugins/kk/plugin.json +1 -1
  74. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
  75. package/plugins/kk/scripts/cover-compositor.ts +380 -32
  76. package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
  77. package/plugins/kk/scripts/daily-stages.ts +933 -60
  78. package/plugins/kk/scripts/episode-identity.ts +180 -0
  79. package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
  80. package/plugins/kk/scripts/music-stages.ts +624 -0
  81. package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
  82. package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
  83. package/plugins/kk/scripts/source-citation.ts +187 -0
  84. package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
  85. package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
  86. package/plugins/kk/skills/content-judge/SKILL.md +11 -6
  87. package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
  88. package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
  89. package/plugins/kk/skills/content-safety/SKILL.md +12 -0
  90. package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
  91. package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
  92. package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
  93. package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
  94. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
  95. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
  96. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
  97. package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
  98. package/plugins/kk/workflows/kk-music.yaml +332 -0
  99. package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
  100. package/plugins/kk/workflows/kk-publish.yaml +4 -1
  101. package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
  102. package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
  103. package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
  104. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
  105. package/plugins/publishings/csdn-pub/dist/index.js +11 -1
  106. package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
  107. package/plugins/publishings/infoq-pub/dist/index.js +11 -1
  108. package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
  109. package/plugins/publishings/jike-pub/dist/index.js +11 -1
  110. package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
  111. package/plugins/publishings/juejin-pub/dist/index.js +11 -1
  112. package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
  113. package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
  114. package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
  115. package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
  116. package/plugins/publishings/podcast-pub/dist/index.js +586 -20
  117. package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
  118. package/plugins/publishings/podcast-pub/src/index.ts +257 -5
  119. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
  120. package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
  121. package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
  122. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
  123. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
  124. package/plugins/publishings/sspai-pub/dist/index.js +11 -1
  125. package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
  126. package/plugins/publishings/substack-pub/dist/index.js +11 -1
  127. package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
  128. package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
  129. package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
  130. package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
  131. package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
  132. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
  133. package/plugins/publishings/threads-pub/dist/index.js +58 -6
  134. package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
  135. package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
  136. package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
  137. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
  138. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
  139. package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
  140. package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
  141. package/plugins/publishings/weibo-pub/dist/index.js +11 -1
  142. package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
  143. package/plugins/publishings/x-pub/dist/index.js +95 -10
  144. package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
  145. package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
  146. package/plugins/publishings/xhs-pub/dist/index.js +11 -1
  147. package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
  148. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
  149. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
@@ -0,0 +1,122 @@
1
+ import type { AudioFormat } from './brief';
2
+
3
+ /**
4
+ * Audio bytes knowledge (task 0398 R2/R4): the *delivered* container is read
5
+ * from the returned bytes, never assumed from the request's `format` field
6
+ * (`docs/design/music-gen.md` §6.2), and the offline adapter emits a
7
+ * deterministic silent WAV from the same module.
8
+ */
9
+
10
+ /** Content-type → container map for the case where the bytes are truncated or unrecognised. */
11
+ const CONTENT_TYPE_FORMATS: Readonly<Record<string, AudioFormat>> = {
12
+ 'audio/mpeg': 'mp3',
13
+ 'audio/mp3': 'mp3',
14
+ 'audio/mpeg3': 'mp3',
15
+ 'audio/wav': 'wav',
16
+ 'audio/wave': 'wav',
17
+ 'audio/x-wav': 'wav',
18
+ };
19
+
20
+ /** True when the first bytes are an MPEG audio frame header or an ID3 tag. */
21
+ function looksLikeMp3(bytes: Uint8Array): boolean {
22
+ if (bytes.length >= 3 && bytes[0] === 0x49 && bytes[1] === 0x44 && bytes[2] === 0x33) {
23
+ return true; // 'ID3'
24
+ }
25
+ const first = bytes[0];
26
+ const second = bytes[1];
27
+ if (first === undefined || second === undefined) {
28
+ return false;
29
+ }
30
+ // 11-bit frame sync (0xFFE) with a non-zero version/layer nibble.
31
+ return first === 0xff && (second & 0xe0) === 0xe0 && (second & 0x06) !== 0;
32
+ }
33
+
34
+ /** True when the bytes open with a RIFF/WAVE container. */
35
+ function looksLikeWav(bytes: Uint8Array): boolean {
36
+ if (bytes.length < 12) {
37
+ return false;
38
+ }
39
+ const ascii = (from: number, length: number): string =>
40
+ String.fromCharCode(...Array.from(bytes.slice(from, from + length)));
41
+ return ascii(0, 4) === 'RIFF' && ascii(8, 4) === 'WAVE';
42
+ }
43
+
44
+ /**
45
+ * Detect the delivered audio container. Magic bytes win; the content type is
46
+ * only a fallback, and `null` means "this response carries no audio" — an
47
+ * ambiguous post-send outcome, never a silent assumption.
48
+ */
49
+ export function detectAudioFormat(bytes: Uint8Array, contentType?: string): AudioFormat | null {
50
+ if (looksLikeWav(bytes)) {
51
+ return 'wav';
52
+ }
53
+ if (looksLikeMp3(bytes)) {
54
+ return 'mp3';
55
+ }
56
+ if (contentType !== undefined) {
57
+ const base = contentType.split(';')[0]?.trim().toLowerCase() ?? '';
58
+ const mapped = CONTENT_TYPE_FORMATS[base];
59
+ if (mapped !== undefined) {
60
+ return mapped;
61
+ }
62
+ }
63
+ return null;
64
+ }
65
+
66
+ /** Sample rate of the offline WAV: 8 kHz mono 16-bit keeps the fixture tiny and byte-stable. */
67
+ export const SILENT_WAV_SAMPLE_RATE = 8_000;
68
+
69
+ /** Duration of the offline WAV in whole seconds. */
70
+ export const SILENT_WAV_SECONDS = 1;
71
+
72
+ /** Write a 16-bit little-endian value at `offset`. */
73
+ function writeUint16LE(target: Uint8Array, offset: number, value: number): void {
74
+ target[offset] = value & 0xff;
75
+ target[offset + 1] = (value >> 8) & 0xff;
76
+ }
77
+
78
+ /** Write a 32-bit little-endian value at `offset`. */
79
+ function writeUint32LE(target: Uint8Array, offset: number, value: number): void {
80
+ target[offset] = value & 0xff;
81
+ target[offset + 1] = (value >> 8) & 0xff;
82
+ target[offset + 2] = (value >> 16) & 0xff;
83
+ target[offset + 3] = (value >> 24) & 0xff;
84
+ }
85
+
86
+ /**
87
+ * A deterministic silent WAV (R4): every sample is zero, so the bytes depend on
88
+ * the duration alone. No clock, no randomness — two runs produce identical
89
+ * bytes, which is what lets the offline suite assert on them.
90
+ */
91
+ export function silentWav(seconds: number = SILENT_WAV_SECONDS): Uint8Array {
92
+ if (!Number.isInteger(seconds) || seconds <= 0) {
93
+ throw new Error(`silentWav needs a positive integer duration in seconds (got ${String(seconds)})`);
94
+ }
95
+ const channels = 1;
96
+ const bitsPerSample = 16;
97
+ const blockAlign = (channels * bitsPerSample) / 8;
98
+ const dataBytes = SILENT_WAV_SAMPLE_RATE * seconds * blockAlign;
99
+ const bytes = new Uint8Array(44 + dataBytes);
100
+ const header = 'RIFF';
101
+ for (const [index, char] of [...header].entries()) {
102
+ bytes[index] = char.charCodeAt(0);
103
+ }
104
+ writeUint32LE(bytes, 4, 36 + dataBytes);
105
+ const wave = 'WAVEfmt ';
106
+ for (const [index, char] of [...wave].entries()) {
107
+ bytes[8 + index] = char.charCodeAt(0);
108
+ }
109
+ writeUint32LE(bytes, 16, 16); // PCM chunk size
110
+ writeUint16LE(bytes, 20, 1); // PCM
111
+ writeUint16LE(bytes, 22, channels);
112
+ writeUint32LE(bytes, 24, SILENT_WAV_SAMPLE_RATE);
113
+ writeUint32LE(bytes, 28, SILENT_WAV_SAMPLE_RATE * blockAlign); // byte rate
114
+ writeUint16LE(bytes, 32, blockAlign);
115
+ writeUint16LE(bytes, 34, bitsPerSample);
116
+ const data = 'data';
117
+ for (const [index, char] of [...data].entries()) {
118
+ bytes[36 + index] = char.charCodeAt(0);
119
+ }
120
+ writeUint32LE(bytes, 40, dataBytes);
121
+ return bytes;
122
+ }
@@ -0,0 +1,191 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * MusicBrief contract (task 0397 R1): the single authored input document for a
5
+ * music job, its `m:ss` duration helpers and the field→target mapping that
6
+ * makes the wire mapping total.
7
+ *
8
+ * Authority: `docs/design/music-gen.md` §2. The YAML authoring form is
9
+ * documented once in `plugins/generations/music-gen/README.md` — there is no
10
+ * second schema.
11
+ */
12
+
13
+ /** `m:ss` — the only duration shape the brief, the preset defaults and the instance request accept. */
14
+ export const MMSS_PATTERN = /^\d{1,2}:[0-5]\d$/;
15
+
16
+ /**
17
+ * Provider ceiling for `model: pro` ("up to roughly three minutes"). A target
18
+ * beyond it cannot be honoured, so the schema rejects it instead of shipping a
19
+ * request the model will silently truncate.
20
+ */
21
+ export const MAX_DURATION_SECONDS = 180;
22
+
23
+ /** Below five seconds a target is not a musical statement; it is a click. */
24
+ export const MIN_DURATION_SECONDS = 5;
25
+
26
+ /** The instance accepts at most ten reference images per request. */
27
+ export const MAX_IMAGES = 10;
28
+
29
+ /** Hard cap on takes per invocation (task 0400 R4); takes are sequential requests, never one batched call. */
30
+ export const MAX_TAKES = 4;
31
+
32
+ /** Built-in take count when the brief is silent. */
33
+ export const DEFAULT_TAKES = 1;
34
+
35
+ /** The instance's two model selectors; `pro` and `clip` are instance-side model ids, not API model ids. */
36
+ export const MUSIC_MODELS = ['pro', 'clip'] as const;
37
+ export type MusicModel = (typeof MUSIC_MODELS)[number];
38
+
39
+ /** Requested audio container. The response format is authoritative (task 0398 R2). */
40
+ export const AUDIO_FORMATS = ['mp3', 'wav'] as const;
41
+ export type AudioFormat = (typeof AUDIO_FORMATS)[number];
42
+
43
+ /** Short language tag (`EN`, `zh-CN`); always sent so the instance default `EN` never applies. */
44
+ export const LANGUAGE_PATTERN = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
45
+
46
+ /** Parse `m:ss` into whole seconds; throws on anything the schema would reject. */
47
+ export function durationSeconds(value: string): number {
48
+ if (!MMSS_PATTERN.test(value)) {
49
+ throw new Error(`duration "${value}" is not m:ss`);
50
+ }
51
+ const [minutes, seconds] = value.split(':');
52
+ return Number(minutes) * 60 + Number(seconds);
53
+ }
54
+
55
+ /** Render whole seconds back to `m:ss` (0405 measures a delivered file against the recorded target). */
56
+ export function formatDuration(seconds: number): string {
57
+ const minutes = Math.floor(seconds / 60);
58
+ return `${minutes}:${String(seconds % 60).padStart(2, '0')}`;
59
+ }
60
+
61
+ /** One timestamped structure line. `note` is the musical instruction for that section. */
62
+ export const StructureEntrySchema = z
63
+ .object({
64
+ at: z.string().regex(MMSS_PATTERN, 'structure.at must be m:ss'),
65
+ section: z.string().min(1),
66
+ note: z.string().min(1).optional(),
67
+ })
68
+ .strict();
69
+
70
+ export type StructureEntry = z.infer<typeof StructureEntrySchema>;
71
+
72
+ /**
73
+ * Where one brief field goes. Every schema key must carry one entry
74
+ * ({@link BRIEF_FIELD_TARGETS} is checked against `MusicBriefSchema.shape`), so
75
+ * no field can be silently dropped — the total-mapping requirement of R1.
76
+ */
77
+ export interface BriefFieldTarget {
78
+ /** Prompt segment the field renders into (R2), when it renders at all. */
79
+ prompt?: string;
80
+ /** Instance request field(s) the field maps to (R3). */
81
+ request?: readonly string[];
82
+ /** True when the field selects or overrides a preset layer (R4). */
83
+ resolution?: boolean;
84
+ /** Where a value that never reaches the wire is recorded. */
85
+ recording?: string;
86
+ }
87
+
88
+ /**
89
+ * R1 totality table: brief field → prompt segment / request field / resolution
90
+ * input / recording slot. `meta` is the one field that is recorded only.
91
+ */
92
+ export const BRIEF_FIELD_TARGETS: Record<string, BriefFieldTarget> = {
93
+ title: { request: ['title'] },
94
+ model: { request: ['model'], resolution: true },
95
+ format: {
96
+ resolution: true,
97
+ recording: 'resolved job (`format` names the format preset; instance `format` is audio_format)',
98
+ },
99
+ theme: { resolution: true, recording: 'resolved job (`theme` names the theme preset)' },
100
+ duration_target: {
101
+ request: ['durationTarget'],
102
+ resolution: true,
103
+ recording: 'resolved job + take sidecar for 0405 measurement',
104
+ },
105
+ language: { request: ['language'], resolution: true },
106
+ instrumental: { prompt: 'Instrumental only — no vocals.', request: ['lyrics'], resolution: true },
107
+ audio_format: { request: ['format'], resolution: true },
108
+ style: { prompt: 'technical direction (first segment)', resolution: true },
109
+ avoid: { prompt: 'Avoid: … (second segment, omitted when empty)', resolution: true },
110
+ structure: { prompt: 'timestamped structure lines (third segment)', resolution: true },
111
+ lyrics: { request: ['lyrics'] },
112
+ images: { request: ['images'] },
113
+ takes: { recording: 'N sequential single-take requests (batchCount=1 each) + take sidecar' },
114
+ meta: { recording: 'take sidecar only; never sent to the instance' },
115
+ };
116
+
117
+ /**
118
+ * The authored brief. Optional fields fall through to preset resolution
119
+ * (R4); a field that survives every layer as `undefined` and has no built-in
120
+ * default makes `resolveJob` fail loudly rather than letting the instance
121
+ * substitute its own default (R3).
122
+ */
123
+ export const MusicBriefSchema = z
124
+ .object({
125
+ title: z.string().min(1),
126
+ model: z.enum(MUSIC_MODELS).optional(),
127
+ format: z.string().min(1),
128
+ theme: z.string().min(1),
129
+ duration_target: z.string().regex(MMSS_PATTERN, 'duration_target must be m:ss').optional(),
130
+ language: z.string().regex(LANGUAGE_PATTERN, 'language must be a short tag such as EN or zh-CN').optional(),
131
+ instrumental: z.boolean().optional(),
132
+ audio_format: z.enum(AUDIO_FORMATS).optional(),
133
+ style: z.string().min(1).optional(),
134
+ avoid: z.array(z.string().min(1)).optional(),
135
+ structure: z.array(StructureEntrySchema).optional(),
136
+ lyrics: z.string().optional(),
137
+ images: z.array(z.string().min(1)).max(MAX_IMAGES).optional(),
138
+ takes: z.number().int().min(1).max(MAX_TAKES).optional(),
139
+ meta: z.record(z.string(), z.unknown()).optional(),
140
+ })
141
+ .strict()
142
+ .superRefine((brief, ctx) => {
143
+ const structure = brief.structure ?? [];
144
+ for (let index = 1; index < structure.length; index += 1) {
145
+ const previous = structure[index - 1];
146
+ const current = structure[index];
147
+ if (previous === undefined || current === undefined) {
148
+ continue;
149
+ }
150
+ // The field schema already reports a malformed timestamp; do not throw from a refinement.
151
+ if (!MMSS_PATTERN.test(previous.at) || !MMSS_PATTERN.test(current.at)) {
152
+ continue;
153
+ }
154
+ if (durationSeconds(current.at) < durationSeconds(previous.at)) {
155
+ ctx.addIssue({
156
+ code: 'custom',
157
+ path: ['structure', index, 'at'],
158
+ message: `structure must not move backwards (${current.at} follows ${previous.at})`,
159
+ });
160
+ }
161
+ }
162
+ if (brief.duration_target !== undefined && MMSS_PATTERN.test(brief.duration_target)) {
163
+ const seconds = durationSeconds(brief.duration_target);
164
+ if (seconds < MIN_DURATION_SECONDS || seconds > MAX_DURATION_SECONDS) {
165
+ ctx.addIssue({
166
+ code: 'custom',
167
+ path: ['duration_target'],
168
+ message: `duration_target must be between 0:05 and 3:00 (got ${brief.duration_target})`,
169
+ });
170
+ }
171
+ }
172
+ if (brief.instrumental === true && (brief.lyrics ?? '').trim() !== '') {
173
+ ctx.addIssue({
174
+ code: 'custom',
175
+ path: ['lyrics'],
176
+ message: 'an instrumental brief must not carry lyrics — drop the lyrics or the instrumental flag',
177
+ });
178
+ }
179
+ });
180
+
181
+ export type MusicBrief = z.infer<typeof MusicBriefSchema>;
182
+
183
+ /** Parse an already-decoded document. Throws `ZodError` on the first invalid field set. */
184
+ export function parseMusicBrief(value: unknown): MusicBrief {
185
+ return MusicBriefSchema.parse(value);
186
+ }
187
+
188
+ /** Parse a YAML brief document (the authoring form in the plugin README). */
189
+ export function parseMusicBriefYaml(text: string): MusicBrief {
190
+ return parseMusicBrief(Bun.YAML.parse(text));
191
+ }