@gobing-ai/knowledge-kit 0.1.29 → 0.1.30
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/api.js +8724 -3861
- package/dist/board/collect/index.js +69 -1
- package/dist/board/daily-voice/index.js +474 -265
- package/dist/board/itc/index.js +69 -1
- package/dist/board/wiki/index.css +1305 -0
- package/dist/board/wiki/index.js +1621 -0
- package/dist/index.js +34689 -28532
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +14 -1
- package/plugins/generations/core-facts-gen/dist/index.js +14 -1
- package/plugins/generations/daily-article-gen/dist/index.js +14 -1
- package/plugins/generations/dailynews-gen/dist/index.js +14 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +32 -2
- package/plugins/generations/episode-plan-gen/src/index.ts +19 -1
- package/plugins/generations/gemini-tts/dist/index.js +14 -1
- package/plugins/generations/image-gen/dist/index.js +14 -1
- package/plugins/generations/music-gen/dist/index.js +15 -2
- package/plugins/generations/news-report-gen/dist/index.js +14 -1
- package/plugins/generations/vibe-voice-tts/dist/index.js +14 -1
- package/plugins/generations/video-gen/README.md +245 -8
- package/plugins/generations/video-gen/dist/index.js +22447 -4763
- package/plugins/generations/video-gen/package.json +1 -0
- package/plugins/generations/video-gen/presets/formats/avatar.yaml +5 -0
- package/plugins/generations/video-gen/presets/formats/editorial.yaml +6 -0
- package/plugins/generations/video-gen/presets/formats/hybrid-pip.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/daily-ai.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/neutral.yaml +3 -0
- package/plugins/generations/video-gen/python/colab_comfyui_h3.py +322 -0
- package/plugins/generations/video-gen/python/comfyui-h3-i2v-api.json +47 -0
- package/plugins/generations/video-gen/python/comfyui-h3-models.json +32 -0
- package/plugins/generations/video-gen/python/comfyui_model_cache.py +388 -0
- package/plugins/generations/video-gen/python/drive_client.py +187 -0
- package/plugins/generations/video-gen/src/brief-cli.ts +65 -0
- package/plugins/generations/video-gen/src/brief.ts +464 -0
- package/plugins/generations/video-gen/src/ccu-ledger.ts +206 -3
- package/plugins/generations/video-gen/src/colab-runner.ts +346 -35
- package/plugins/generations/video-gen/src/index.ts +141 -109
- package/plugins/generations/video-gen/src/inputs.ts +162 -4
- package/plugins/generations/video-gen/src/layout.ts +33 -0
- package/plugins/generations/video-gen/src/props.ts +27 -3
- package/plugins/generations/video-gen/src/remotion/AvatarReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/EditorialReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/Root.tsx +2 -0
- package/plugins/generations/video-gen/src/remotion/engine.ts +3 -7
- package/plugins/generations/video-gen/src/render.ts +25 -0
- package/plugins/generations/video-gen/src/request.ts +150 -20
- package/plugins/generations/video-gen/src/visual-provider.ts +116 -3
- package/plugins/generations/voice-gen/dist/index.js +14 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +14 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +14 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +14 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +14 -1
- package/plugins/ingestions/web-search/dist/index.js +14 -1
- package/plugins/kk/config.example.yaml +1 -1
- package/plugins/kk/mcp-tools.yaml +47 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/itc-surfdash-locales.json +42 -0
- package/plugins/kk/scripts/daily-stages.ts +87 -6
- package/plugins/kk/scripts/kk-workflow-stages.ts +64 -9
- package/plugins/kk/scripts/video-stages.ts +332 -0
- package/plugins/kk/scripts/wiki-normalize-audio.ts +354 -0
- package/plugins/kk/scripts/wiki-normalize-document.ts +495 -0
- package/plugins/kk/scripts/wiki-normalize-stages.ts +96 -0
- package/plugins/kk/scripts/wiki-stage-runtime.ts +39 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +2 -1
- package/plugins/kk/workflows/kk-collect.yaml +10 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +70 -8
- package/plugins/kk/workflows/kk-smart-seo.yaml +8 -0
- package/plugins/kk/workflows/kk-storm-research.yaml +10 -0
- package/plugins/kk/workflows/kk-video-generate.yaml +169 -0
- package/plugins/kk/workflows/kk-wiki-digest.yaml +49 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +281 -268
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/cnblogs-pub/dist/index.js +281 -268
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/csdn-pub/dist/index.js +281 -268
- package/plugins/publishings/csdn-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/emdash-pub/dist/index.js +33 -3
- package/plugins/publishings/infoq-pub/dist/index.js +281 -268
- package/plugins/publishings/infoq-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/jike-pub/dist/index.js +281 -268
- package/plugins/publishings/jike-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/juejin-pub/dist/index.js +281 -268
- package/plugins/publishings/juejin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +281 -268
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/medium-pub/dist/index.js +281 -268
- package/plugins/publishings/medium-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/podcast-pub/dist/index.js +39 -9
- package/plugins/publishings/qiita-pub/dist/index.js +33 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +281 -268
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +175 -0
- package/plugins/publishings/sspai-pub/dist/index.js +281 -268
- package/plugins/publishings/sspai-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/substack-pub/dist/index.js +281 -268
- package/plugins/publishings/substack-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +99 -39
- package/plugins/publishings/surfdash-pub/plugin.json +54 -0
- package/plugins/publishings/surfdash-pub/src/index.ts +36 -5
- package/plugins/publishings/threads-pub/dist/index.js +281 -268
- package/plugins/publishings/threads-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +665 -451
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +215 -3
- package/plugins/publishings/weibo-pub/dist/index.js +281 -268
- package/plugins/publishings/weibo-pub/dist/profile-check.js +189 -1
- package/plugins/publishings/x-pub/dist/index.js +281 -268
- package/plugins/publishings/x-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/xhs-pub/dist/index.js +281 -268
- package/plugins/publishings/xhs-pub/dist/profile-check.js +119 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +281 -268
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/youtube-pub/dist/index.js +14 -1
- package/plugins/publishings/zenn-pub/dist/index.js +37 -7
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { accessSync, constants, existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { delimiter, join } from 'node:path';
|
|
5
|
+
import { NormalizeStageError, type WikiNormalizeManifest } from './wiki-normalize-stages';
|
|
6
|
+
import { wikiStageRuntime } from './wiki-stage-runtime';
|
|
7
|
+
|
|
8
|
+
export const WIKI_DOC_MAX_PAGES = 25;
|
|
9
|
+
export const WIKI_IMAGE_MAX_PIXELS = 20_000_000;
|
|
10
|
+
export const WIKI_NORM_TEXT_MAX_BYTES = 2 * 1024 * 1024;
|
|
11
|
+
export const WIKI_PAGE_TIMEOUT_MS = 60_000;
|
|
12
|
+
export const WIKI_JOB_DEADLINE_MS = 900_000;
|
|
13
|
+
|
|
14
|
+
export type DocumentSourceLocator =
|
|
15
|
+
| { type: 'line'; startLine: number; endLine: number }
|
|
16
|
+
| { type: 'page'; page: number }
|
|
17
|
+
| {
|
|
18
|
+
type: 'box';
|
|
19
|
+
page: number;
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
imageWidth: number;
|
|
25
|
+
imageHeight: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface DocumentNormalizationResult {
|
|
29
|
+
version: 1;
|
|
30
|
+
inputId: string;
|
|
31
|
+
captureId: string;
|
|
32
|
+
originalSha256: string;
|
|
33
|
+
mediaKind: 'text' | 'pdf' | 'image';
|
|
34
|
+
normalizer: { name: string; version: string; parametersHash: string };
|
|
35
|
+
text: string;
|
|
36
|
+
segments: { text: string; locator: DocumentSourceLocator; confidence?: number }[];
|
|
37
|
+
warnings: string[];
|
|
38
|
+
bounds?: { pages?: number };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ProcessRunResult {
|
|
42
|
+
exitCode: number;
|
|
43
|
+
stdout: string;
|
|
44
|
+
stderr: string;
|
|
45
|
+
timedOut: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ProcessRunner = (cmd: string, args: string[], timeoutMs: number) => Promise<ProcessRunResult>;
|
|
49
|
+
|
|
50
|
+
export function runProcessDefault(cmd: string, args: string[], timeoutMs: number): Promise<ProcessRunResult> {
|
|
51
|
+
return wikiStageRuntime.runWikiNormalizerProcess(cmd, args, timeoutMs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sha256(input: string): string {
|
|
55
|
+
return createHash('sha256').update(input).digest('hex');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function findExecutableOnPath(name: string, pathEnv = process.env.PATH ?? ''): string | undefined {
|
|
59
|
+
for (const dir of pathEnv.split(delimiter)) {
|
|
60
|
+
if (!dir) continue;
|
|
61
|
+
const candidate = join(dir, name);
|
|
62
|
+
try {
|
|
63
|
+
accessSync(candidate, constants.X_OK);
|
|
64
|
+
return candidate;
|
|
65
|
+
} catch {
|
|
66
|
+
// Try next PATH entry.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DocumentCapabilities {
|
|
73
|
+
pdfinfo: string;
|
|
74
|
+
pdftotext: string;
|
|
75
|
+
pdftoppm: string;
|
|
76
|
+
tesseract: string;
|
|
77
|
+
versionString: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function probeDocumentCapabilities(
|
|
81
|
+
runner: ProcessRunner = runProcessDefault,
|
|
82
|
+
pathEnv = process.env.PATH ?? '',
|
|
83
|
+
): Promise<DocumentCapabilities> {
|
|
84
|
+
const pdfinfo = findExecutableOnPath('pdfinfo', pathEnv);
|
|
85
|
+
if (!pdfinfo) throw new NormalizeStageError('capability.unavailable', 'pdfinfo');
|
|
86
|
+
const pdftotext = findExecutableOnPath('pdftotext', pathEnv);
|
|
87
|
+
if (!pdftotext) throw new NormalizeStageError('capability.unavailable', 'pdftotext');
|
|
88
|
+
const pdftoppm = findExecutableOnPath('pdftoppm', pathEnv);
|
|
89
|
+
if (!pdftoppm) throw new NormalizeStageError('capability.unavailable', 'pdftoppm');
|
|
90
|
+
const tesseract = findExecutableOnPath('tesseract', pathEnv);
|
|
91
|
+
if (!tesseract) throw new NormalizeStageError('capability.unavailable', 'tesseract');
|
|
92
|
+
|
|
93
|
+
const langsRes = await runner(tesseract, ['--list-langs'], WIKI_PAGE_TIMEOUT_MS);
|
|
94
|
+
if (langsRes.timedOut) throw new NormalizeStageError('deadline', 'tesseract --list-langs timed out');
|
|
95
|
+
if (langsRes.exitCode !== 0) {
|
|
96
|
+
throw new NormalizeStageError('capability.unavailable', 'tesseract --list-langs failed');
|
|
97
|
+
}
|
|
98
|
+
const langs = new Set(
|
|
99
|
+
langsRes.stdout
|
|
100
|
+
.split('\n')
|
|
101
|
+
.map((l) => l.trim())
|
|
102
|
+
.filter((l) => l !== '' && !l.startsWith('List of available languages')),
|
|
103
|
+
);
|
|
104
|
+
for (const req of ['eng', 'chi_sim']) {
|
|
105
|
+
if (!langs.has(req)) {
|
|
106
|
+
throw new NormalizeStageError('capability.unavailable', `tesseract lang ${req}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const [pdfVerRes, tessVerRes] = await Promise.all([
|
|
111
|
+
runner(pdftotext, ['-v'], 5000),
|
|
112
|
+
runner(tesseract, ['--version'], 5000),
|
|
113
|
+
]);
|
|
114
|
+
const pdfVer = (pdfVerRes.stderr || pdfVerRes.stdout).split('\n')[0]?.trim() ?? 'pdftotext';
|
|
115
|
+
const tessVer = (tessVerRes.stdout || tessVerRes.stderr).split('\n')[0]?.trim() ?? 'tesseract';
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
pdfinfo,
|
|
119
|
+
pdftotext,
|
|
120
|
+
pdftoppm,
|
|
121
|
+
tesseract,
|
|
122
|
+
versionString: `${pdfVer}; ${tessVer}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function probeImageDimensions(filePath: string, format: string): { width: number; height: number } {
|
|
127
|
+
const buf = readFileSync(filePath);
|
|
128
|
+
if (format === 'png') {
|
|
129
|
+
if (buf.length < 24 || buf.subarray(0, 8).toString('hex') !== '89504e470d0a1a0a') {
|
|
130
|
+
throw new NormalizeStageError('media.invalid', 'invalid PNG signature');
|
|
131
|
+
}
|
|
132
|
+
if (buf.subarray(12, 16).toString('ascii') !== 'IHDR') {
|
|
133
|
+
throw new NormalizeStageError('media.invalid', 'missing PNG IHDR chunk');
|
|
134
|
+
}
|
|
135
|
+
const width = buf.readUInt32BE(16);
|
|
136
|
+
const height = buf.readUInt32BE(20);
|
|
137
|
+
if (width <= 0 || height <= 0) throw new NormalizeStageError('media.invalid', 'invalid PNG dimensions');
|
|
138
|
+
if (width * height > WIKI_IMAGE_MAX_PIXELS) {
|
|
139
|
+
throw new NormalizeStageError('budget.exceeded', `image ${width}x${height} exceeds 20 MP`);
|
|
140
|
+
}
|
|
141
|
+
return { width, height };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (format === 'jpeg') {
|
|
145
|
+
if (buf.length < 4 || buf[0] !== 0xff || buf[1] !== 0xd8) {
|
|
146
|
+
throw new NormalizeStageError('media.invalid', 'invalid JPEG signature');
|
|
147
|
+
}
|
|
148
|
+
let offset = 2;
|
|
149
|
+
while (offset + 4 < buf.length) {
|
|
150
|
+
if (buf[offset] !== 0xff) {
|
|
151
|
+
offset += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const marker = buf[offset + 1] ?? 0;
|
|
155
|
+
if (marker === 0xd8 || marker === 0xd9 || marker === 0x00) {
|
|
156
|
+
offset += 2;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (offset + 4 > buf.length) break;
|
|
160
|
+
const segLen = buf.readUInt16BE(offset + 2);
|
|
161
|
+
if (segLen < 2) break;
|
|
162
|
+
const isSof =
|
|
163
|
+
(marker >= 0xc0 && marker <= 0xc3) ||
|
|
164
|
+
(marker >= 0xc5 && marker <= 0xc7) ||
|
|
165
|
+
(marker >= 0xc9 && marker <= 0xcb) ||
|
|
166
|
+
(marker >= 0xcd && marker <= 0xcf);
|
|
167
|
+
if (isSof && offset + 9 <= buf.length) {
|
|
168
|
+
const height = buf.readUInt16BE(offset + 5);
|
|
169
|
+
const width = buf.readUInt16BE(offset + 7);
|
|
170
|
+
if (width <= 0 || height <= 0) {
|
|
171
|
+
throw new NormalizeStageError('media.invalid', 'invalid JPEG dimensions');
|
|
172
|
+
}
|
|
173
|
+
if (width * height > WIKI_IMAGE_MAX_PIXELS) {
|
|
174
|
+
throw new NormalizeStageError('budget.exceeded', `image ${width}x${height} exceeds 20 MP`);
|
|
175
|
+
}
|
|
176
|
+
return { width, height };
|
|
177
|
+
}
|
|
178
|
+
offset += 2 + segLen;
|
|
179
|
+
}
|
|
180
|
+
throw new NormalizeStageError('media.invalid', 'missing JPEG SOF dimensions');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
throw new NormalizeStageError('media.invalid', `unsupported image format '${format}'`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function assertTextBudget(text: string): void {
|
|
187
|
+
if (text.trim() === '') {
|
|
188
|
+
throw new NormalizeStageError('recognition.empty', 'empty normalized text');
|
|
189
|
+
}
|
|
190
|
+
if (Buffer.byteLength(text, 'utf8') > WIKI_NORM_TEXT_MAX_BYTES) {
|
|
191
|
+
throw new NormalizeStageError('budget.exceeded', `normalized text exceeds ${WIKI_NORM_TEXT_MAX_BYTES} bytes`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function normalizeText(ctx: {
|
|
196
|
+
manifest: WikiNormalizeManifest;
|
|
197
|
+
originalPath: string;
|
|
198
|
+
}): DocumentNormalizationResult {
|
|
199
|
+
const rawBytes = readFileSync(ctx.originalPath);
|
|
200
|
+
let decoded: string;
|
|
201
|
+
try {
|
|
202
|
+
decoded = new TextDecoder('utf-8', { fatal: true }).decode(rawBytes);
|
|
203
|
+
} catch {
|
|
204
|
+
throw new NormalizeStageError('media.invalid', 'invalid UTF-8 text');
|
|
205
|
+
}
|
|
206
|
+
assertTextBudget(decoded);
|
|
207
|
+
|
|
208
|
+
const lines = decoded.replace(/\r\n/g, '\n').split('\n');
|
|
209
|
+
const segments: { text: string; locator: DocumentSourceLocator }[] = [];
|
|
210
|
+
let paraLines: string[] = [];
|
|
211
|
+
let paraStart = 1;
|
|
212
|
+
|
|
213
|
+
const flush = (endLine: number) => {
|
|
214
|
+
const text = paraLines.join('\n').trim();
|
|
215
|
+
if (text !== '') {
|
|
216
|
+
segments.push({ text, locator: { type: 'line', startLine: paraStart, endLine } });
|
|
217
|
+
}
|
|
218
|
+
paraLines = [];
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
222
|
+
const line = lines[i] ?? '';
|
|
223
|
+
if (line.trim() === '') {
|
|
224
|
+
if (paraLines.length > 0) flush(i);
|
|
225
|
+
paraStart = i + 2;
|
|
226
|
+
} else {
|
|
227
|
+
if (paraLines.length === 0) paraStart = i + 1;
|
|
228
|
+
paraLines.push(line);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (paraLines.length > 0) flush(lines.length);
|
|
232
|
+
if (segments.length === 0) {
|
|
233
|
+
throw new NormalizeStageError('recognition.empty', 'no non-empty text segments');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const fullText = segments.map((s) => s.text).join('\n\n');
|
|
237
|
+
assertTextBudget(fullText);
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
version: 1,
|
|
241
|
+
inputId: ctx.manifest.inputId,
|
|
242
|
+
captureId: ctx.manifest.captureId,
|
|
243
|
+
originalSha256: ctx.manifest.sha256,
|
|
244
|
+
mediaKind: 'text',
|
|
245
|
+
normalizer: {
|
|
246
|
+
name: 'kk-wiki-text',
|
|
247
|
+
version: '1.0.0',
|
|
248
|
+
parametersHash: sha256('utf8-paragraph-lines-v1'),
|
|
249
|
+
},
|
|
250
|
+
text: fullText,
|
|
251
|
+
segments,
|
|
252
|
+
warnings: [],
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
interface TsvWord {
|
|
257
|
+
block: string;
|
|
258
|
+
par: string;
|
|
259
|
+
line: string;
|
|
260
|
+
left: number;
|
|
261
|
+
top: number;
|
|
262
|
+
width: number;
|
|
263
|
+
height: number;
|
|
264
|
+
conf: number;
|
|
265
|
+
text: string;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function parseTesseractTsv(
|
|
269
|
+
tsv: string,
|
|
270
|
+
page: number,
|
|
271
|
+
imageWidth: number,
|
|
272
|
+
imageHeight: number,
|
|
273
|
+
): { text: string; locator: DocumentSourceLocator; confidence?: number }[] {
|
|
274
|
+
const rows = tsv.split('\n');
|
|
275
|
+
const groups = new Map<string, TsvWord[]>();
|
|
276
|
+
|
|
277
|
+
for (let i = 1; i < rows.length; i += 1) {
|
|
278
|
+
const row = rows[i]?.trimEnd();
|
|
279
|
+
if (!row) continue;
|
|
280
|
+
const cols = row.split('\t');
|
|
281
|
+
if (cols.length < 12) continue;
|
|
282
|
+
if (cols[0] !== '5') continue;
|
|
283
|
+
const conf = Number(cols[10]);
|
|
284
|
+
const text = (cols[11] ?? '').trim();
|
|
285
|
+
if (!Number.isFinite(conf) || conf < 0 || text === '') continue;
|
|
286
|
+
|
|
287
|
+
const left = Math.max(0, Math.min(imageWidth, Number(cols[6])));
|
|
288
|
+
const top = Math.max(0, Math.min(imageHeight, Number(cols[7])));
|
|
289
|
+
const width = Math.max(1, Math.min(imageWidth - left, Number(cols[8])));
|
|
290
|
+
const height = Math.max(1, Math.min(imageHeight - top, Number(cols[9])));
|
|
291
|
+
if (![left, top, width, height].every(Number.isFinite)) continue;
|
|
292
|
+
|
|
293
|
+
const key = `${cols[2]}:${cols[3]}:${cols[4]}`;
|
|
294
|
+
const list = groups.get(key) ?? [];
|
|
295
|
+
list.push({
|
|
296
|
+
block: cols[2] ?? '0',
|
|
297
|
+
par: cols[3] ?? '0',
|
|
298
|
+
line: cols[4] ?? '0',
|
|
299
|
+
left,
|
|
300
|
+
top,
|
|
301
|
+
width,
|
|
302
|
+
height,
|
|
303
|
+
conf,
|
|
304
|
+
text,
|
|
305
|
+
});
|
|
306
|
+
groups.set(key, list);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const segments: { text: string; locator: DocumentSourceLocator; confidence?: number }[] = [];
|
|
310
|
+
for (const words of groups.values()) {
|
|
311
|
+
const minX = Math.min(...words.map((w) => w.left));
|
|
312
|
+
const minY = Math.min(...words.map((w) => w.top));
|
|
313
|
+
const maxX = Math.max(...words.map((w) => w.left + w.width));
|
|
314
|
+
const maxY = Math.max(...words.map((w) => w.top + w.height));
|
|
315
|
+
const meanConf = words.reduce((acc, w) => acc + w.conf, 0) / words.length;
|
|
316
|
+
segments.push({
|
|
317
|
+
text: words.map((w) => w.text).join(' '),
|
|
318
|
+
locator: {
|
|
319
|
+
type: 'box',
|
|
320
|
+
page,
|
|
321
|
+
x: minX,
|
|
322
|
+
y: minY,
|
|
323
|
+
width: Math.max(1, maxX - minX),
|
|
324
|
+
height: Math.max(1, maxY - minY),
|
|
325
|
+
imageWidth,
|
|
326
|
+
imageHeight,
|
|
327
|
+
},
|
|
328
|
+
confidence: Math.round(meanConf * 100) / 100,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return segments;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async function runOcrOnPng(
|
|
335
|
+
tesseract: string,
|
|
336
|
+
pngPath: string,
|
|
337
|
+
page: number,
|
|
338
|
+
imageWidth: number,
|
|
339
|
+
imageHeight: number,
|
|
340
|
+
runner: ProcessRunner,
|
|
341
|
+
): Promise<{ text: string; locator: DocumentSourceLocator; confidence?: number }[]> {
|
|
342
|
+
const res = await runner(
|
|
343
|
+
tesseract,
|
|
344
|
+
[pngPath, 'stdout', '-l', 'eng+chi_sim', '--psm', '3', 'tsv'],
|
|
345
|
+
WIKI_PAGE_TIMEOUT_MS,
|
|
346
|
+
);
|
|
347
|
+
if (res.timedOut) throw new NormalizeStageError('deadline', `tesseract page ${page} timed out`);
|
|
348
|
+
if (res.exitCode !== 0) {
|
|
349
|
+
throw new NormalizeStageError('media.invalid', `tesseract failed on page ${page}: ${res.stderr.trim()}`);
|
|
350
|
+
}
|
|
351
|
+
const segs = parseTesseractTsv(res.stdout, page, imageWidth, imageHeight);
|
|
352
|
+
if (segs.length === 0) {
|
|
353
|
+
throw new NormalizeStageError('recognition.empty', `no OCR words recognized on page ${page}`);
|
|
354
|
+
}
|
|
355
|
+
return segs;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export async function normalizePdf(
|
|
359
|
+
ctx: { manifest: WikiNormalizeManifest; originalPath: string },
|
|
360
|
+
deps: { runner?: ProcessRunner; pathEnv?: string } = {},
|
|
361
|
+
): Promise<DocumentNormalizationResult> {
|
|
362
|
+
const jobStart = Date.now();
|
|
363
|
+
const baseRunner = deps.runner ?? runProcessDefault;
|
|
364
|
+
const runner: ProcessRunner = (cmd, args, timeoutMs) => {
|
|
365
|
+
const remaining = WIKI_JOB_DEADLINE_MS - (Date.now() - jobStart);
|
|
366
|
+
if (remaining <= 0) throw new NormalizeStageError('deadline', 'normalization job exceeded 900s deadline');
|
|
367
|
+
return baseRunner(cmd, args, Math.min(timeoutMs, remaining));
|
|
368
|
+
};
|
|
369
|
+
const caps = await probeDocumentCapabilities(runner, deps.pathEnv);
|
|
370
|
+
|
|
371
|
+
const infoRes = await runner(caps.pdfinfo, [ctx.originalPath], WIKI_PAGE_TIMEOUT_MS);
|
|
372
|
+
if (infoRes.timedOut) throw new NormalizeStageError('deadline', 'pdfinfo timed out');
|
|
373
|
+
if (infoRes.exitCode !== 0) {
|
|
374
|
+
throw new NormalizeStageError('media.invalid', `pdfinfo failed: ${infoRes.stderr.trim()}`);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const encryptedMatch = /^Encrypted:\s*(.+)$/m.exec(infoRes.stdout);
|
|
378
|
+
if (encryptedMatch?.[1]?.trim().toLowerCase().startsWith('yes')) {
|
|
379
|
+
throw new NormalizeStageError('media.invalid', 'encrypted PDF is not supported');
|
|
380
|
+
}
|
|
381
|
+
const pagesMatch = /^Pages:\s*(\d+)/m.exec(infoRes.stdout);
|
|
382
|
+
const pages = pagesMatch ? Number.parseInt(pagesMatch[1] ?? '', 10) : Number.NaN;
|
|
383
|
+
if (!Number.isFinite(pages) || pages < 1) {
|
|
384
|
+
throw new NormalizeStageError('media.invalid', 'could not parse PDF page count');
|
|
385
|
+
}
|
|
386
|
+
if (pages > WIKI_DOC_MAX_PAGES) {
|
|
387
|
+
throw new NormalizeStageError('budget.exceeded', `PDF has ${pages} pages (max ${WIKI_DOC_MAX_PAGES})`);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const workDir = join(tmpdir(), `kk-wiki-norm-${ctx.manifest.captureId}`);
|
|
391
|
+
mkdirSync(workDir, { recursive: true });
|
|
392
|
+
const segments: { text: string; locator: DocumentSourceLocator; confidence?: number }[] = [];
|
|
393
|
+
const warnings: string[] = [];
|
|
394
|
+
let usedOcr = false;
|
|
395
|
+
|
|
396
|
+
try {
|
|
397
|
+
for (let p = 1; p <= pages; p += 1) {
|
|
398
|
+
if (Date.now() - jobStart > WIKI_JOB_DEADLINE_MS) {
|
|
399
|
+
throw new NormalizeStageError('deadline', 'normalization job exceeded 900s deadline');
|
|
400
|
+
}
|
|
401
|
+
const txtRes = await runner(
|
|
402
|
+
caps.pdftotext,
|
|
403
|
+
['-f', String(p), '-l', String(p), '-layout', '-enc', 'UTF-8', ctx.originalPath, '-'],
|
|
404
|
+
WIKI_PAGE_TIMEOUT_MS,
|
|
405
|
+
);
|
|
406
|
+
if (txtRes.timedOut) throw new NormalizeStageError('deadline', `pdftotext page ${p} timed out`);
|
|
407
|
+
if (txtRes.exitCode !== 0) {
|
|
408
|
+
throw new NormalizeStageError('media.invalid', `pdftotext failed on page ${p}`);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (txtRes.stdout.trim() !== '') {
|
|
412
|
+
segments.push({ text: txtRes.stdout.trim(), locator: { type: 'page', page: p } });
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ponytail: OCR only text-empty pages; OCR inline images on text pages when required
|
|
417
|
+
usedOcr = true;
|
|
418
|
+
const prefix = join(workDir, `page-${p}`);
|
|
419
|
+
const ppmRes = await runner(
|
|
420
|
+
caps.pdftoppm,
|
|
421
|
+
['-f', String(p), '-l', String(p), '-r', '200', '-scale-to', '2048', '-png', ctx.originalPath, prefix],
|
|
422
|
+
WIKI_PAGE_TIMEOUT_MS,
|
|
423
|
+
);
|
|
424
|
+
if (ppmRes.timedOut) throw new NormalizeStageError('deadline', `pdftoppm page ${p} timed out`);
|
|
425
|
+
if (ppmRes.exitCode !== 0) {
|
|
426
|
+
throw new NormalizeStageError('media.invalid', `pdftoppm failed on page ${p}`);
|
|
427
|
+
}
|
|
428
|
+
const pngName = readdirSync(workDir).find((f) => f.startsWith(`page-${p}`) && f.endsWith('.png'));
|
|
429
|
+
if (!pngName) {
|
|
430
|
+
throw new NormalizeStageError('media.invalid', `pdftoppm produced no PNG for page ${p}`);
|
|
431
|
+
}
|
|
432
|
+
const pngPath = join(workDir, pngName);
|
|
433
|
+
const dims = probeImageDimensions(pngPath, 'png');
|
|
434
|
+
const ocrSegs = await runOcrOnPng(caps.tesseract, pngPath, p, dims.width, dims.height, runner);
|
|
435
|
+
segments.push(...ocrSegs);
|
|
436
|
+
}
|
|
437
|
+
} finally {
|
|
438
|
+
if (existsSync(workDir)) rmSync(workDir, { recursive: true, force: true });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (usedOcr) warnings.push('ocr-only-empty-pages');
|
|
442
|
+
const coveredPages = new Set(segments.map((s) => (s.locator.type === 'line' ? 0 : s.locator.page)));
|
|
443
|
+
if (coveredPages.size !== pages) {
|
|
444
|
+
throw new NormalizeStageError('recognition.empty', `expected ${pages} pages, got ${coveredPages.size}`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const fullText = segments.map((s) => s.text).join('\n\n');
|
|
448
|
+
assertTextBudget(fullText);
|
|
449
|
+
|
|
450
|
+
return {
|
|
451
|
+
version: 1,
|
|
452
|
+
inputId: ctx.manifest.inputId,
|
|
453
|
+
captureId: ctx.manifest.captureId,
|
|
454
|
+
originalSha256: ctx.manifest.sha256,
|
|
455
|
+
mediaKind: 'pdf',
|
|
456
|
+
normalizer: {
|
|
457
|
+
name: 'poppler+tesseract',
|
|
458
|
+
version: caps.versionString,
|
|
459
|
+
parametersHash: sha256('pdf-r200-scale2048-eng+chi_sim-psm3'),
|
|
460
|
+
},
|
|
461
|
+
text: fullText,
|
|
462
|
+
segments,
|
|
463
|
+
warnings,
|
|
464
|
+
bounds: { pages },
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export async function normalizeImage(
|
|
469
|
+
ctx: { manifest: WikiNormalizeManifest; originalPath: string },
|
|
470
|
+
deps: { runner?: ProcessRunner; pathEnv?: string } = {},
|
|
471
|
+
): Promise<DocumentNormalizationResult> {
|
|
472
|
+
const runner = deps.runner ?? runProcessDefault;
|
|
473
|
+
const dims = probeImageDimensions(ctx.originalPath, ctx.manifest.format);
|
|
474
|
+
const caps = await probeDocumentCapabilities(runner, deps.pathEnv);
|
|
475
|
+
const segments = await runOcrOnPng(caps.tesseract, ctx.originalPath, 1, dims.width, dims.height, runner);
|
|
476
|
+
const fullText = segments.map((s) => s.text).join('\n\n');
|
|
477
|
+
assertTextBudget(fullText);
|
|
478
|
+
|
|
479
|
+
return {
|
|
480
|
+
version: 1,
|
|
481
|
+
inputId: ctx.manifest.inputId,
|
|
482
|
+
captureId: ctx.manifest.captureId,
|
|
483
|
+
originalSha256: ctx.manifest.sha256,
|
|
484
|
+
mediaKind: 'image',
|
|
485
|
+
normalizer: {
|
|
486
|
+
name: 'tesseract',
|
|
487
|
+
version: caps.versionString,
|
|
488
|
+
parametersHash: sha256('image-eng+chi_sim-psm3'),
|
|
489
|
+
},
|
|
490
|
+
text: fullText,
|
|
491
|
+
segments,
|
|
492
|
+
warnings: [],
|
|
493
|
+
bounds: { pages: 1 },
|
|
494
|
+
};
|
|
495
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AudioNormalizationResult,
|
|
3
|
+
type AudioSourceLocator,
|
|
4
|
+
normalizeAudio,
|
|
5
|
+
probeAudioCapabilities,
|
|
6
|
+
} from './wiki-normalize-audio';
|
|
7
|
+
import {
|
|
8
|
+
type DocumentNormalizationResult,
|
|
9
|
+
type DocumentSourceLocator,
|
|
10
|
+
normalizeImage,
|
|
11
|
+
normalizePdf,
|
|
12
|
+
normalizeText,
|
|
13
|
+
probeDocumentCapabilities,
|
|
14
|
+
} from './wiki-normalize-document';
|
|
15
|
+
import { wikiStageRuntime } from './wiki-stage-runtime';
|
|
16
|
+
|
|
17
|
+
export interface WikiNormalizeManifest {
|
|
18
|
+
version: 1;
|
|
19
|
+
inputId: string;
|
|
20
|
+
captureId: string;
|
|
21
|
+
mediaKind: 'text' | 'pdf' | 'image' | 'audio';
|
|
22
|
+
format: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
byteLength: number;
|
|
25
|
+
sha256: string;
|
|
26
|
+
capturedAt: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type NormalizeFailureReason =
|
|
30
|
+
| 'capability.unavailable'
|
|
31
|
+
| 'media.invalid'
|
|
32
|
+
| 'budget.exceeded'
|
|
33
|
+
| 'deadline'
|
|
34
|
+
| 'recognition.empty';
|
|
35
|
+
|
|
36
|
+
export class NormalizeStageError extends Error {
|
|
37
|
+
readonly reason: NormalizeFailureReason;
|
|
38
|
+
constructor(reason: NormalizeFailureReason, detail: string) {
|
|
39
|
+
super(`${reason}: ${detail}`);
|
|
40
|
+
this.reason = reason;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type AnyNormalizationResult = DocumentNormalizationResult | AudioNormalizationResult;
|
|
45
|
+
export type AnySourceLocator = DocumentSourceLocator | AudioSourceLocator;
|
|
46
|
+
|
|
47
|
+
export type MediaBranchHandler = (ctx: {
|
|
48
|
+
vaultRoot: string;
|
|
49
|
+
manifest: WikiNormalizeManifest;
|
|
50
|
+
originalPath: string;
|
|
51
|
+
}) => Promise<AnyNormalizationResult | undefined> | AnyNormalizationResult | undefined;
|
|
52
|
+
|
|
53
|
+
const MEDIA_BRANCHES: Record<WikiNormalizeManifest['mediaKind'], MediaBranchHandler> = {
|
|
54
|
+
text: normalizeText,
|
|
55
|
+
pdf: normalizePdf,
|
|
56
|
+
image: normalizeImage,
|
|
57
|
+
audio: normalizeAudio,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export async function runWikiNormalizeStage(args: readonly string[]): Promise<void> {
|
|
61
|
+
const [vaultRoot, inputId] = args;
|
|
62
|
+
if (!vaultRoot || !inputId) throw new Error('usage: wiki-normalize <vault> <inputId>');
|
|
63
|
+
await wikiStageRuntime.runWikiFileNormalization({
|
|
64
|
+
vaultRoot,
|
|
65
|
+
inputId,
|
|
66
|
+
normalize: (ctx) => MEDIA_BRANCHES[ctx.manifest.mediaKind](ctx),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function runWikiNormalizeProbeStage(): Promise<void> {
|
|
71
|
+
let docAvailable = true;
|
|
72
|
+
let docReason: string | undefined;
|
|
73
|
+
try {
|
|
74
|
+
await probeDocumentCapabilities();
|
|
75
|
+
} catch (err) {
|
|
76
|
+
docAvailable = false;
|
|
77
|
+
docReason = err instanceof Error ? err.message : String(err);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let audioAvailable = true;
|
|
81
|
+
let audioReason: string | undefined;
|
|
82
|
+
try {
|
|
83
|
+
probeAudioCapabilities();
|
|
84
|
+
} catch (err) {
|
|
85
|
+
audioAvailable = false;
|
|
86
|
+
audioReason = err instanceof Error ? err.message : String(err);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const result = {
|
|
90
|
+
text: { available: true },
|
|
91
|
+
pdf: docAvailable ? { available: true } : { available: false, reason: docReason },
|
|
92
|
+
image: docAvailable ? { available: true } : { available: false, reason: docReason },
|
|
93
|
+
audio: audioAvailable ? { available: true } : { available: false, reason: audioReason },
|
|
94
|
+
};
|
|
95
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
96
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import type { ProcessRunResult } from './wiki-normalize-document';
|
|
4
|
+
import type { AnyNormalizationResult, WikiNormalizeManifest } from './wiki-normalize-stages';
|
|
5
|
+
|
|
6
|
+
interface WikiStageRuntime {
|
|
7
|
+
runWikiFileNormalization(options: {
|
|
8
|
+
vaultRoot: string;
|
|
9
|
+
inputId: string;
|
|
10
|
+
normalize: (ctx: {
|
|
11
|
+
vaultRoot: string;
|
|
12
|
+
manifest: WikiNormalizeManifest;
|
|
13
|
+
originalPath: string;
|
|
14
|
+
}) => Promise<AnyNormalizationResult | undefined> | AnyNormalizationResult | undefined;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
runWikiNormalizerProcess(
|
|
17
|
+
cmd: string,
|
|
18
|
+
args: string[],
|
|
19
|
+
timeoutMs: number,
|
|
20
|
+
env?: Record<string, string | undefined>,
|
|
21
|
+
): Promise<ProcessRunResult>;
|
|
22
|
+
discoverWikiCaptionWorker(env: Record<string, string | undefined>): string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const entry = [
|
|
26
|
+
new URL('../../../dist/index.js', import.meta.url),
|
|
27
|
+
new URL('../../../apps/cli/src/wiki/normalization.ts', import.meta.url),
|
|
28
|
+
].find((path) => existsSync(path));
|
|
29
|
+
if (!entry) throw new Error('wiki stage runtime missing: build or reinstall knowledge-kit');
|
|
30
|
+
const runtime: unknown = await import(entry.href);
|
|
31
|
+
assert(
|
|
32
|
+
runtime &&
|
|
33
|
+
typeof runtime === 'object' &&
|
|
34
|
+
['runWikiFileNormalization', 'runWikiNormalizerProcess', 'discoverWikiCaptionWorker'].every(
|
|
35
|
+
(name) => name in runtime && typeof Reflect.get(runtime, name) === 'function',
|
|
36
|
+
),
|
|
37
|
+
'wiki stage runtime incompatible: rebuild or reinstall knowledge-kit',
|
|
38
|
+
);
|
|
39
|
+
export const wikiStageRuntime = runtime as WikiStageRuntime;
|
|
@@ -93,6 +93,7 @@ Read the curated plan `Doc[]` (`--in`) and the curate exclusions (`--excluded`).
|
|
|
93
93
|
- `lead`: one spoken bridge into the item (≤80 chars). It is not the title and not a rhetorical question.
|
|
94
94
|
- `insight` (optional; omitting it and writing `""` are the same thing — both validate, and the builder and the
|
|
95
95
|
renderer skip only the comment sentence, never the item): 2–4 sentences (≤380 chars) anchored to the doc's named actors, saying why it matters or what to watch. At most one sentence of commentary is required for a short item — leave the field as a single sentence, or omit the comment entirely when the item needs no judgement. Never restate the doc's facts, numbers or phrasing (the listener has just heard them), give no generic advice or methodology, and add no new facts. The cap is a ceiling, not a target.
|
|
96
|
+
- **Duration floor (13 min):** the rendered VoiceScript (`intro` + `items[].lead` + `body` + `items[].insight` + `outro`) must total at least **4,500 chars** (~13.4 min at 5.6 chars/s) or the pre-TTS gate refuses the run. When `--in` has ≤9 items, write substantive 150–260 char `insight`s (within the 380-char cap) and full `intro`/`outro` (within 150 chars) rather than one-line stubs.
|
|
96
97
|
- `card`: optional per-item card slot `{ "copy": "≤12字标题", "points": ["要点1", "要点2"], "subject": "English visual scene" }` (2–4 points). `subject` is composed per `../daily-news-illustrations/SKILL.md` mode `card` — the card series' artwork direction is that skill's, while `copy`/`points` and the episode `cards.title`/`body` stay here.
|
|
97
98
|
|
|
98
99
|
At the episode level, write:
|
|
@@ -171,7 +172,7 @@ reject a plan, so they are written to `24-script/<date>_08_script-write_advisori
|
|
|
171
172
|
## Mode: curate / curate --fix
|
|
172
173
|
|
|
173
174
|
See `references/selection.md`. Reads QC candidates (`--in`) and writes two JSON files:
|
|
174
|
-
1. `--out-plan` (`21-plan/<date>_03_plan_plan.json`): bare `Doc[]` of **kept** items only, in editorial order (lead first), with `title`, `body` and `metadata.brief` adapted into spoken simplified Chinese.
|
|
175
|
+
1. `--out-plan` (`21-plan/<date>_03_plan_plan.json`): bare `Doc[]` of **kept** items only, in editorial order (lead first), with `title`, `body` and `metadata.brief` adapted into spoken simplified Chinese. Keep total `body` chars across kept items ≥4,600 chars when enough valid items exist; when ≤10 items are kept, preserve full factual detail from the source rather than over-condensing into short stubs.
|
|
175
176
|
2. `--out-excluded` (`21-plan/<date>_03_curate_excluded.json`): `[{"id":"<Doc.id>","reason":"<具体中文原因>"}]` for every dropped candidate (`[]` when none dropped). Every candidate id must land in **exactly one** of the two files.
|
|
176
177
|
|
|
177
178
|
With `--fix <errors.json>` (`missing-plan`, `invalid-json`, `unknown-id`, `missing-item`, `conflict-id`, `empty-plan`, `cn-lead:XY-02`), repair the partition so every candidate id is accounted for exactly once and at least one in-scope item is kept. `cn-lead:XY-02` (its `detail` carries the matched terms and the message) is not an inventory problem: move that item out of the lead position and rewrite its title/`metadata.brief` into a neutral headline that names the AI-industry fact, keeping every fact and number — see `references/selection.md` § CN lead.
|
|
@@ -292,3 +292,13 @@ transitions:
|
|
|
292
292
|
terminalReason: failed-check
|
|
293
293
|
guard:
|
|
294
294
|
kind: always
|
|
295
|
+
|
|
296
|
+
# MCP exposure (task 0428): typed allowlist only — Spur validates these params, then stringifies
|
|
297
|
+
# them into the workflow's own vars. Paths, plugin selection and engine vars stay unexposed.
|
|
298
|
+
metadata:
|
|
299
|
+
mcp:
|
|
300
|
+
expose: true
|
|
301
|
+
params:
|
|
302
|
+
limit: { type: number, description: Items per source (default 10) }
|
|
303
|
+
last30days_topic: { type: string, description: last30days source topic }
|
|
304
|
+
horizon_hours: { type: number, description: Lookback window in hours (default 6) }
|