@gobing-ai/knowledge-kit 0.1.24 → 0.1.27
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/index.js +416 -79
- package/package.json +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +47 -6
- package/plugins/generations/episode-plan-gen/src/index.ts +71 -7
- package/plugins/generations/music-gen/dist/index.js +17 -13
- package/plugins/generations/music-gen/src/audio/measure.ts +25 -20
- package/plugins/kk/decisions/extract/ai-news.yaml +8 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +4 -4
- package/plugins/kk/publish-presets/itc-main.json +39 -23
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +880 -131
- package/plugins/kk/scripts/kk-workflow-stages.ts +58 -3
- package/plugins/kk/skills/content-safety/references/platforms/apple-podcasts.md +12 -5
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +8 -0
- package/plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md +5 -0
- package/plugins/kk/skills/daily-news-cover/SKILL.md +96 -0
- package/plugins/kk/skills/daily-news-illustrations/SKILL.md +123 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +25 -6
- package/plugins/kk/skills/news-editorial/references/daily-visual-composition.md +150 -0
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +1 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +13 -1
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +6 -3
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -4
- package/plugins/kk/workflows/kk-news-generate.yaml +71 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +35 -3
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +35 -3
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/csdn-pub/dist/index.js +35 -3
- package/plugins/publishings/csdn-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/infoq-pub/dist/index.js +35 -3
- package/plugins/publishings/infoq-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/jike-pub/dist/index.js +35 -3
- package/plugins/publishings/jike-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/juejin-pub/dist/index.js +35 -3
- package/plugins/publishings/juejin-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +86 -14
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +52 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +9229 -279
- package/plugins/publishings/medium-pub/dist/profile-check.js +21205 -0
- package/plugins/publishings/medium-pub/package.json +3 -1
- package/plugins/publishings/medium-pub/plugin.json +6 -1
- package/plugins/publishings/medium-pub/src/browser-rail.ts +280 -0
- package/plugins/publishings/medium-pub/src/index.ts +17 -1
- package/plugins/publishings/medium-pub/src/profile-check.ts +27 -0
- package/plugins/publishings/shipinhao-pub/dist/index.js +38 -4
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +37 -4
- package/plugins/publishings/shipinhao-pub/src/flow.ts +5 -0
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +11 -4
- package/plugins/publishings/sspai-pub/dist/index.js +35 -3
- package/plugins/publishings/sspai-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/substack-pub/dist/index.js +35 -3
- package/plugins/publishings/substack-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/surfdash-pub/dist/index.js +53 -15
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +35 -3
- package/plugins/publishings/threads-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/wechatmp-pub/dist/index.js +326 -44
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +69 -4
- package/plugins/publishings/wechatmp-pub/src/flow.ts +447 -53
- package/plugins/publishings/wechatmp-pub/src/index.ts +68 -2
- package/plugins/publishings/wechatmp-pub/src/page.ts +8 -0
- package/plugins/publishings/weibo-pub/dist/index.js +58 -9
- package/plugins/publishings/weibo-pub/dist/profile-check.js +57 -9
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +76 -8
- package/plugins/publishings/x-pub/dist/index.js +35 -3
- package/plugins/publishings/x-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/xhs-pub/dist/index.js +35 -3
- package/plugins/publishings/xhs-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +35 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +35 -3
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic CN-platform lead gate (task 0433).
|
|
4
|
+
*
|
|
5
|
+
* Incident 2026-11-24 (`.works/kk-news-generate/20261124`): the curator led the episode with
|
|
6
|
+
* 英伟达董事会恢复黄仁勋职务并新设国家安全与出口管制委员会 — the day's biggest story, and exactly the
|
|
7
|
+
* mainline the CN platforms block. The variants safety review graded it afterwards (`XY-02` 小宇宙,
|
|
8
|
+
* `WX-01` 公众号, both `block`), `bundle.safety.excludedPlatforms` dropped `podcast-pub.episode` and
|
|
9
|
+
* `wechatmp-pub.文章`, and the day paid for a 12.6 min / 753 s TTS pass it could only deliver to
|
|
10
|
+
* surfdash + 视频号 + 即刻. The pipeline was right; the editorial selection never considered the surface it
|
|
11
|
+
* was writing for.
|
|
12
|
+
*
|
|
13
|
+
* This module is the pre-spend half of 0433 R3/R4: a PURE function, no LLM call, that fails the plan
|
|
14
|
+
* when the LEAD title/summary trips the CN-blocked mainline vocabulary, so the failure lands in the plan
|
|
15
|
+
* stage (`curate-check`, node 4 of 25 in `kk-news-generate.yaml`) instead of after the `voice` TTS spend
|
|
16
|
+
* (node 18) and the post-spend `safety-variants` verdict (node 24).
|
|
17
|
+
*
|
|
18
|
+
* Calibration (task 0438): the two-signal detector (AI object × policy signal, with the context-dependent
|
|
19
|
+
* signals gated on a government actor) is measured, not argued — `plugins/kk/tests/fixtures/
|
|
20
|
+
* cn-lead-calibration.json` holds 30 class leads (≥28 must trip), 86 product leads (≤3 may trip) and the
|
|
21
|
+
* accepted misses. Every added term/actor is pinned by a class row that goes clean without it. Re-measure
|
|
22
|
+
* with `bun test plugins/kk/tests/cn-lead-gate-0438.test.ts`; extend by ADDING rows, never by editing a row
|
|
23
|
+
* after seeing the gate's output.
|
|
24
|
+
*
|
|
25
|
+
* Scope — deliberately narrow, and it is a *position* constraint, not an exclusion rule:
|
|
26
|
+
* - Only the lead is scanned (plan index 0), and only its `title` + summary (`metadata.brief`). A body
|
|
27
|
+
* item may discuss export controls; `news-editorial` SKILL.md shared rule 2 keeps that story IN scope.
|
|
28
|
+
* What R1 forbids is LEADING a CN-distributed cut with it.
|
|
29
|
+
* - A hit is not a publish verdict. `content-safety` deliberately refuses to publish a word list, and a
|
|
30
|
+
* 字词命中 stays an input to context judgment there (XY-03). Here the vocabulary only decides whether
|
|
31
|
+
* the *lead position* is admissible on the CN cut before any money is spent; the post-spend review
|
|
32
|
+
* keeps its own, contextual say over the whole episode.
|
|
33
|
+
* - The vocabulary is the machine-readable form of the two shipped platform rules, which stay the source
|
|
34
|
+
* of truth: `plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md` (XY-02,
|
|
35
|
+
* `时政/公共事务主线:政治、外交/贸易管制、军事、公共政策争议`) and `.../wechatmp.md` (WX-01, same
|
|
36
|
+
* shape for 图文/音频). Re-verify against those files, not against this table, if a platform ruling
|
|
37
|
+
* changes — and keep `CN_LEAD_RULE_IDS` naming them in every failure message so the `curate --fix`
|
|
38
|
+
* pass can fix by rule.
|
|
39
|
+
* - 2026-11-24 operator ruling (both reference files): XY-02/WX-01 were narrowed to a *domestic-China*
|
|
40
|
+
* political/social mainline; an overseas vendor under its own regulator's security review is `note`,
|
|
41
|
+
* not `escalate`. This gate is stricter than that ruling on purpose — it is about the LEAD of a
|
|
42
|
+
* CN-distributed cut, which is what cost the day its primary channel, and it costs nothing to lead
|
|
43
|
+
* with the second story instead. See `news-editorial/references/selection.md` § CN lead.
|
|
44
|
+
*
|
|
45
|
+
* Adoption policy (R2, chosen and recorded): DEMOTE, do not fork the cut. The pipeline ships one zh cut
|
|
46
|
+
* and one TTS pass, so a tripping lead is moved to the best body position and the first clean item leads.
|
|
47
|
+
* Tradeoff: the CN surface loses its biggest story from the lead position instead of gaining a second,
|
|
48
|
+
* overseas-only lead — one script, one synthesis bill, no second render path. See selection.md.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** The shipped platform review items this gate stands on (stable ids — the fix pass routes on them). */
|
|
52
|
+
export const CN_LEAD_RULE_IDS = ['XY-02', 'WX-01'] as const;
|
|
53
|
+
|
|
54
|
+
/** The CN-blocked mainline classes R1 names, one row per class. */
|
|
55
|
+
export type CnLeadMainline = 'trade-control' | 'state-security-review' | 'political-affairs';
|
|
56
|
+
|
|
57
|
+
export interface CnLeadVocabularyRow {
|
|
58
|
+
/** The mainline class, as it reads in the failure message. */
|
|
59
|
+
mainline: CnLeadMainline;
|
|
60
|
+
/** Slash-separated English gloss so an operator reading a refusal knows what tripped. */
|
|
61
|
+
label: string;
|
|
62
|
+
terms: readonly string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The machine-readable vocabulary. Kept to terms that name the MAINLINE of a lead in normal AI-industry
|
|
67
|
+
* copy — a term that survives only as background inside a body paragraph is out of scope by construction
|
|
68
|
+
* (only the lead is scanned). CJK terms match as substrings; Latin terms match from a word boundary and
|
|
69
|
+
* allow a plural/possessive suffix (`export control` → `export controls`), never a bare substring
|
|
70
|
+
* (`war` must not match `software`).
|
|
71
|
+
*/
|
|
72
|
+
export const CN_LEAD_VOCABULARY: readonly CnLeadVocabularyRow[] = [
|
|
73
|
+
{
|
|
74
|
+
mainline: 'trade-control',
|
|
75
|
+
label: '贸易管制 / 出口管制',
|
|
76
|
+
terms: [
|
|
77
|
+
'出口管制',
|
|
78
|
+
'出口禁令',
|
|
79
|
+
'出口限制',
|
|
80
|
+
'出口许可',
|
|
81
|
+
'出口新规',
|
|
82
|
+
'出口合规',
|
|
83
|
+
'对华出口',
|
|
84
|
+
'对华出货',
|
|
85
|
+
'获准对华',
|
|
86
|
+
'出货需申请',
|
|
87
|
+
'审批许可',
|
|
88
|
+
'许可证制度',
|
|
89
|
+
'贸易管制',
|
|
90
|
+
'贸易战',
|
|
91
|
+
'关税战',
|
|
92
|
+
'加征关税',
|
|
93
|
+
'芯片关税',
|
|
94
|
+
'关税',
|
|
95
|
+
'实体清单',
|
|
96
|
+
'技术封锁',
|
|
97
|
+
'技术禁运',
|
|
98
|
+
'禁运',
|
|
99
|
+
'制裁',
|
|
100
|
+
'反制裁',
|
|
101
|
+
'长臂管辖',
|
|
102
|
+
'商务部',
|
|
103
|
+
'export control',
|
|
104
|
+
'export ban',
|
|
105
|
+
'export restriction',
|
|
106
|
+
'export license',
|
|
107
|
+
'entity list',
|
|
108
|
+
'trade war',
|
|
109
|
+
'tariff',
|
|
110
|
+
'sanction',
|
|
111
|
+
'embargo',
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
mainline: 'state-security-review',
|
|
116
|
+
label: '公共安全审查 / 国家安全审查',
|
|
117
|
+
terms: [
|
|
118
|
+
'国家安全',
|
|
119
|
+
'安全审查',
|
|
120
|
+
'外资审查',
|
|
121
|
+
'外国投资审查',
|
|
122
|
+
'反间谍',
|
|
123
|
+
'间谍',
|
|
124
|
+
'情报法',
|
|
125
|
+
'外国情报',
|
|
126
|
+
'情报机构',
|
|
127
|
+
'网络安全审查',
|
|
128
|
+
'数据出境',
|
|
129
|
+
'national security',
|
|
130
|
+
'security review',
|
|
131
|
+
'espionage',
|
|
132
|
+
'foreign intelligence',
|
|
133
|
+
'cfius',
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
mainline: 'political-affairs',
|
|
138
|
+
label: '时政 / 军事',
|
|
139
|
+
terms: [
|
|
140
|
+
'政治局',
|
|
141
|
+
'人大常委会',
|
|
142
|
+
'全国人大',
|
|
143
|
+
'政协',
|
|
144
|
+
'涉台',
|
|
145
|
+
'台湾问题',
|
|
146
|
+
'选举结果',
|
|
147
|
+
'涉港',
|
|
148
|
+
'国安法',
|
|
149
|
+
'反分裂',
|
|
150
|
+
'军事演习',
|
|
151
|
+
'军演',
|
|
152
|
+
'军事冲突',
|
|
153
|
+
'国防部',
|
|
154
|
+
'军方',
|
|
155
|
+
'美军',
|
|
156
|
+
'军队',
|
|
157
|
+
'外交部',
|
|
158
|
+
'武统',
|
|
159
|
+
'台海',
|
|
160
|
+
'两会',
|
|
161
|
+
'听证',
|
|
162
|
+
'网信办',
|
|
163
|
+
'工信部',
|
|
164
|
+
'中央经济工作会议',
|
|
165
|
+
'军控',
|
|
166
|
+
'军用',
|
|
167
|
+
'情报部门',
|
|
168
|
+
'法案',
|
|
169
|
+
'行政令',
|
|
170
|
+
'国会',
|
|
171
|
+
'国务院',
|
|
172
|
+
'白宫',
|
|
173
|
+
'politburo',
|
|
174
|
+
'military exercise',
|
|
175
|
+
'military conflict',
|
|
176
|
+
'armed forces',
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The second detector: a policy signal over an AI-industry object.
|
|
183
|
+
*
|
|
184
|
+
* Enumeration alone cannot cover ordinary phrasings (review visit 3 measured 6/23 ordinarily-written
|
|
185
|
+
* class leads caught while 25/33 keyword-dense ones were): `美国拟进一步收紧对华芯片出口` carries no
|
|
186
|
+
* enumerated compound, yet it is exactly the XY-02 class. Requiring BOTH halve keeps it off product
|
|
187
|
+
* news — `新模型…`、`小米发布旗舰手机` and a valuation round carry no policy signal — while any lead
|
|
188
|
+
* that reads as policy acting on the AI industry is caught whatever the wording.
|
|
189
|
+
*/
|
|
190
|
+
const AI_OBJECT_TERMS: readonly string[] = [
|
|
191
|
+
'芯片',
|
|
192
|
+
'半导体',
|
|
193
|
+
'算力',
|
|
194
|
+
'英伟达',
|
|
195
|
+
'台积电',
|
|
196
|
+
'大模型',
|
|
197
|
+
'模型',
|
|
198
|
+
'人工智能',
|
|
199
|
+
'生成式',
|
|
200
|
+
'数据中心',
|
|
201
|
+
'ai',
|
|
202
|
+
'gpu',
|
|
203
|
+
];
|
|
204
|
+
/**
|
|
205
|
+
* Signals a product's own copy also uses (0438): the 政策/规则/规范/指南/指引 a vendor publishes for its
|
|
206
|
+
* own product, and 许可 (open-source licence) / 审查 (code review) / 调查 (postmortem) / 限制 (usage
|
|
207
|
+
* limit). Each counts only when {@link GOVERNMENT_ACTOR_RE} matches the same surface.
|
|
208
|
+
*/
|
|
209
|
+
const CONTEXT_DEPENDENT_SIGNALS: ReadonlySet<string> = new Set([
|
|
210
|
+
'政策',
|
|
211
|
+
'规则',
|
|
212
|
+
'规范',
|
|
213
|
+
'指南',
|
|
214
|
+
'指引',
|
|
215
|
+
'许可',
|
|
216
|
+
'审查',
|
|
217
|
+
'调查',
|
|
218
|
+
'限制',
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Government / jurisdiction actors that turn a context-dependent signal into a policy act. Every entry
|
|
223
|
+
* is pinned by a `class` row of `tests/fixtures/cn-lead-calibration.json` that trips only through it.
|
|
224
|
+
* Actors that trip on their own are left out: 网信办/工信部/商务部/国务院/政协 are vocabulary terms,
|
|
225
|
+
* and 市场监管 contains the plain signal 监管. The generic 部门/会议/国家 are left out because a company
|
|
226
|
+
* 安全部门 is not a regulator.
|
|
227
|
+
* No single-character tokens (`市` would match 市场).
|
|
228
|
+
*/
|
|
229
|
+
const GOVERNMENT_ACTOR_RE = /教育部|央行|人民银行|数据局|总局|财政部|司法部|药监局|委员会|政府|美国|美方|欧盟/;
|
|
230
|
+
|
|
231
|
+
const POLICY_SIGNAL_TERMS: readonly string[] = [
|
|
232
|
+
'出口',
|
|
233
|
+
'进口',
|
|
234
|
+
'关税',
|
|
235
|
+
'制裁',
|
|
236
|
+
'许可',
|
|
237
|
+
'审查',
|
|
238
|
+
'禁令',
|
|
239
|
+
'禁售',
|
|
240
|
+
'限制',
|
|
241
|
+
'收紧',
|
|
242
|
+
'放宽',
|
|
243
|
+
'规则',
|
|
244
|
+
'政策',
|
|
245
|
+
'办法',
|
|
246
|
+
'行动计划',
|
|
247
|
+
'约谈',
|
|
248
|
+
'规范',
|
|
249
|
+
'指南',
|
|
250
|
+
'法案',
|
|
251
|
+
'监管',
|
|
252
|
+
'调查',
|
|
253
|
+
'豁免',
|
|
254
|
+
'补贴',
|
|
255
|
+
'听证',
|
|
256
|
+
'两会',
|
|
257
|
+
'台海',
|
|
258
|
+
'选举',
|
|
259
|
+
'军方',
|
|
260
|
+
'国防',
|
|
261
|
+
'指引',
|
|
262
|
+
'条例',
|
|
263
|
+
'细则',
|
|
264
|
+
'备案',
|
|
265
|
+
'征求意见',
|
|
266
|
+
'供应',
|
|
267
|
+
'管制',
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
export interface CnLeadHit {
|
|
271
|
+
/** Which vocabulary class matched. */
|
|
272
|
+
mainline: CnLeadMainline;
|
|
273
|
+
/** The rule ids that class stands on. */
|
|
274
|
+
ruleIds: readonly string[];
|
|
275
|
+
/** The term as written in {@link CN_LEAD_VOCABULARY}. */
|
|
276
|
+
term: string;
|
|
277
|
+
/** The lead surface that carried it. */
|
|
278
|
+
field: 'title' | 'summary';
|
|
279
|
+
/** `vocabulary` = an enumerated {@link CN_LEAD_VOCABULARY} term; `two-signal` = AI object × policy signal. */
|
|
280
|
+
detector: 'vocabulary' | 'two-signal';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface CnLeadScan {
|
|
284
|
+
hits: CnLeadHit[];
|
|
285
|
+
/** Unique matched terms, in vocabulary order — the failure message's evidence. */
|
|
286
|
+
terms: string[];
|
|
287
|
+
/** The rule ids that apply, deduped (`XY-02`, `WX-01`). */
|
|
288
|
+
ruleIds: string[];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const LATIN = /^[\x20-\x7e]+$/;
|
|
292
|
+
|
|
293
|
+
function escapeRegex(term: string): string {
|
|
294
|
+
return term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** CJK matching ignores internal whitespace: a translated title may space a term apart. */
|
|
298
|
+
function squash(text: string): string {
|
|
299
|
+
return text.replace(/\s+/g, '');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** True when `text` carries `term` — substring for CJK; for Latin a whole word, plural/possessive allowed. */
|
|
303
|
+
function trips(text: string, term: string): boolean {
|
|
304
|
+
if (LATIN.test(term)) {
|
|
305
|
+
return new RegExp(`(^|[^a-z0-9])${escapeRegex(term)}(?:s|'s)?(?![a-z0-9])`, 'i').test(text);
|
|
306
|
+
}
|
|
307
|
+
return squash(text).includes(squash(term));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Scan one lead surface (title + summary). Pure; no I/O, no LLM, no state. */
|
|
311
|
+
export function scanCnLead(title: string, summary: string): CnLeadScan {
|
|
312
|
+
const hits: CnLeadHit[] = [];
|
|
313
|
+
for (const row of CN_LEAD_VOCABULARY) {
|
|
314
|
+
for (const term of row.terms) {
|
|
315
|
+
for (const [field, text] of [
|
|
316
|
+
['title', title],
|
|
317
|
+
['summary', summary],
|
|
318
|
+
] as const) {
|
|
319
|
+
if (text.trim() !== '' && trips(text, term)) {
|
|
320
|
+
hits.push({
|
|
321
|
+
mainline: row.mainline,
|
|
322
|
+
ruleIds: CN_LEAD_RULE_IDS,
|
|
323
|
+
term,
|
|
324
|
+
field,
|
|
325
|
+
detector: 'vocabulary',
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// Second detector: a policy signal over an AI-industry object (see the constant's rationale).
|
|
332
|
+
for (const [field, text] of [
|
|
333
|
+
['title', title],
|
|
334
|
+
['summary', summary],
|
|
335
|
+
] as const) {
|
|
336
|
+
if (text.trim() === '') continue;
|
|
337
|
+
const object = AI_OBJECT_TERMS.find((term) => trips(text, term));
|
|
338
|
+
if (object === undefined) continue;
|
|
339
|
+
// A context-dependent signal ("更新模型使用政策", "代码审查") is a product fact unless a government
|
|
340
|
+
// actor sits in the same surface; the actor then joins the evidence term.
|
|
341
|
+
const actor = squash(text).match(GOVERNMENT_ACTOR_RE)?.[0];
|
|
342
|
+
const policy = POLICY_SIGNAL_TERMS.find(
|
|
343
|
+
(term) => trips(text, term) && (!CONTEXT_DEPENDENT_SIGNALS.has(term) || actor !== undefined),
|
|
344
|
+
);
|
|
345
|
+
if (policy === undefined) continue;
|
|
346
|
+
const term = CONTEXT_DEPENDENT_SIGNALS.has(policy) ? `${object}+${policy}+${actor}` : `${object}+${policy}`;
|
|
347
|
+
hits.push({ mainline: 'trade-control', ruleIds: CN_LEAD_RULE_IDS, term, field, detector: 'two-signal' });
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
hits,
|
|
351
|
+
terms: [...new Set(hits.map((hit) => hit.term))],
|
|
352
|
+
ruleIds: [...new Set(hits.flatMap((hit) => [...hit.ruleIds]))],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* The lead surface of one plan doc: `title` + the summary the episode actually ships.
|
|
358
|
+
*
|
|
359
|
+
* The shipped CN show notes use `metadata.brief`, else the lead's FIRST body sentence
|
|
360
|
+
* (`planItemsForPodcast` in `daily-stages.ts`), so the fallback is scanned too — otherwise a raw
|
|
361
|
+
* `--final` candidate (which never carries a `brief`) has its summary half unscanned while that very
|
|
362
|
+
* sentence reaches the podcast notes (review P3, 0433).
|
|
363
|
+
*/
|
|
364
|
+
export function leadSurfaceOf(doc: Record<string, unknown>): { id: string; title: string; summary: string } {
|
|
365
|
+
const metadata = doc.metadata;
|
|
366
|
+
const meta = metadata !== null && typeof metadata === 'object' ? (metadata as Record<string, unknown>) : {};
|
|
367
|
+
const body = typeof doc.body === 'string' ? doc.body : '';
|
|
368
|
+
const summary =
|
|
369
|
+
[meta.brief, doc.summary, firstBodySentence(body)].find(
|
|
370
|
+
(value): value is string => typeof value === 'string' && value.trim() !== '',
|
|
371
|
+
) ?? '';
|
|
372
|
+
return { id: typeof doc.id === 'string' ? doc.id : '', title: String(doc.title ?? ''), summary };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** The lead's first sentence — the shape `planItemsForPodcast` falls back to for the show notes. */
|
|
376
|
+
function firstBodySentence(body: string): string {
|
|
377
|
+
return (
|
|
378
|
+
body
|
|
379
|
+
.trim()
|
|
380
|
+
.split(/(?<=[。!?!?\n])/)[0]
|
|
381
|
+
?.trim() ?? ''
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** The failure message. Names the platform rule ids, the terms and the fix, so `--fix` can route. */
|
|
386
|
+
export function cnLeadMessage(leadId: string, title: string, scan: CnLeadScan): string {
|
|
387
|
+
return (
|
|
388
|
+
`cn-lead (${CN_LEAD_RULE_IDS.join('/')}): the plan lead [${leadId}] 「${title}」 trips the CN-blocked ` +
|
|
389
|
+
`mainline vocabulary (${scan.terms.join('、')}) — ` +
|
|
390
|
+
`XY-02 (小宇宙) / WX-01 (微信公众号) block a CN-distributed cut whose lead is 时政/贸易管制/公共安全审查. ` +
|
|
391
|
+
'Demote it to a body item and lead with the first clean story; rewrite its title/summary as a neutral ' +
|
|
392
|
+
'headline that names the AI-industry fact (news-editorial references/selection.md § CN lead)'
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface CnLeadPlanVerdict {
|
|
397
|
+
ok: boolean;
|
|
398
|
+
leadId: string | null;
|
|
399
|
+
leadTitle: string;
|
|
400
|
+
hits: CnLeadHit[];
|
|
401
|
+
terms: string[];
|
|
402
|
+
ruleIds: string[];
|
|
403
|
+
/** `''` when ok; otherwise the operator/agent-facing refusal (names XY-02/WX-01). */
|
|
404
|
+
message: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* The gate over a plan `Doc[]`: only index 0 is scanned. An empty plan passes — the `empty-plan` rule
|
|
409
|
+
* owns that case, and a second refusal for the same condition would only double-report it.
|
|
410
|
+
*/
|
|
411
|
+
export function checkCnLeadPlan(docs: readonly Record<string, unknown>[]): CnLeadPlanVerdict {
|
|
412
|
+
const lead = docs[0];
|
|
413
|
+
if (lead === undefined) {
|
|
414
|
+
return { ok: true, leadId: null, leadTitle: '', hits: [], terms: [], ruleIds: [], message: '' };
|
|
415
|
+
}
|
|
416
|
+
const surface = leadSurfaceOf(lead);
|
|
417
|
+
const scan = scanCnLead(surface.title, surface.summary);
|
|
418
|
+
return {
|
|
419
|
+
ok: scan.hits.length === 0,
|
|
420
|
+
leadId: surface.id,
|
|
421
|
+
leadTitle: surface.title,
|
|
422
|
+
hits: scan.hits,
|
|
423
|
+
terms: scan.terms,
|
|
424
|
+
ruleIds: scan.ruleIds,
|
|
425
|
+
message: scan.hits.length === 0 ? '' : cnLeadMessage(surface.id, surface.title, scan),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export interface CnLeadEnforcement {
|
|
430
|
+
/** The plan to write. Identical (same array) when nothing had to change. */
|
|
431
|
+
docs: Record<string, unknown>[];
|
|
432
|
+
/** The lead that was moved, and where it now sits (body position, never the last one by rule). */
|
|
433
|
+
demoted: { id: string; from: number; to: number } | null;
|
|
434
|
+
/** Set when EVERY item carries a vocabulary hit: no safe lead exists, so the caller refuses before synthesis. */
|
|
435
|
+
blocked: { id: string; message: string } | null;
|
|
436
|
+
/**
|
|
437
|
+
* 0438 R4: no clean candidate, but this one trips only the two-signal detector (a heuristic that also
|
|
438
|
+
* fires on product copy) — it leads, and the caller logs it instead of refusing the day.
|
|
439
|
+
*/
|
|
440
|
+
weakLead: { id: string; terms: string[] } | null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* R2's chosen behaviour, as code: DEMOTE. When the lead trips, the first item whose lead surface is clean
|
|
445
|
+
* becomes the lead and the tripping story moves to the first body position after it, everything else
|
|
446
|
+
* keeping its relative order. Returns the input array untouched (same reference) when nothing trips, so a
|
|
447
|
+
* caller can persist only what changed.
|
|
448
|
+
*
|
|
449
|
+
* With no clean candidate, the first candidate whose hits are all `two-signal` leads as `weakLead`
|
|
450
|
+
* (0438 R4): refusing a day on a heuristic that 2/86 product leads also trip costs more than it saves.
|
|
451
|
+
* `blocked` is the honest dead end: every candidate carries an enumerated vocabulary hit, so no lead this
|
|
452
|
+
* cut may carry exists, and inventing one would be worse than refusing the day before the TTS spend.
|
|
453
|
+
*/
|
|
454
|
+
export function enforceCnLead(docs: readonly Record<string, unknown>[]): CnLeadEnforcement {
|
|
455
|
+
const unchanged = docs as Record<string, unknown>[];
|
|
456
|
+
const verdict = checkCnLeadPlan(docs);
|
|
457
|
+
if (verdict.ok) return { docs: unchanged, demoted: null, blocked: null, weakLead: null };
|
|
458
|
+
const tripping = docs[0] as Record<string, unknown>;
|
|
459
|
+
const rest = docs.slice(1);
|
|
460
|
+
const cleanIndex = rest.findIndex((entry) => checkCnLeadPlan([entry]).ok);
|
|
461
|
+
if (cleanIndex !== -1) {
|
|
462
|
+
const clean = rest[cleanIndex] as Record<string, unknown>;
|
|
463
|
+
const reordered = [clean, ...rest.slice(0, cleanIndex), tripping, ...rest.slice(cleanIndex + 1)];
|
|
464
|
+
return {
|
|
465
|
+
docs: reordered,
|
|
466
|
+
demoted: { id: verdict.leadId ?? '', from: 0, to: cleanIndex + 1 },
|
|
467
|
+
blocked: null,
|
|
468
|
+
weakLead: null,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
const scans = docs.map((entry) => {
|
|
472
|
+
const { title, summary } = leadSurfaceOf(entry);
|
|
473
|
+
return scanCnLead(title, summary);
|
|
474
|
+
});
|
|
475
|
+
const weakIndex = scans.findIndex((scan) => scan.hits.every((hit) => hit.detector === 'two-signal'));
|
|
476
|
+
if (weakIndex === -1) {
|
|
477
|
+
return {
|
|
478
|
+
docs: unchanged,
|
|
479
|
+
demoted: null,
|
|
480
|
+
blocked: { id: verdict.leadId ?? '', message: verdict.message },
|
|
481
|
+
weakLead: null,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
const weak = docs[weakIndex] as Record<string, unknown>;
|
|
485
|
+
const weakLead = { id: String(weak.id ?? ''), terms: (scans[weakIndex] as CnLeadScan).terms };
|
|
486
|
+
if (weakIndex === 0) return { docs: unchanged, demoted: null, blocked: null, weakLead };
|
|
487
|
+
const reordered = [weak, tripping, ...rest.filter((entry) => entry !== weak)];
|
|
488
|
+
return {
|
|
489
|
+
docs: reordered,
|
|
490
|
+
demoted: { id: verdict.leadId ?? '', from: 0, to: 1 },
|
|
491
|
+
blocked: null,
|
|
492
|
+
weakLead,
|
|
493
|
+
};
|
|
494
|
+
}
|