@gobing-ai/knowledge-kit 0.1.15 → 0.1.16
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 +1603 -1
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +58 -52
- package/plugins/generations/content-gen/src/storm.ts +94 -61
- package/plugins/generations/core-facts-gen/dist/index.js +1 -1
- package/plugins/generations/daily-article-gen/dist/index.js +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +1 -1
- package/plugins/generations/gemini-tts/dist/index.js +1 -1
- package/plugins/generations/image-gen/README.md +31 -10
- package/plugins/generations/image-gen/assets/sample/cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__clean-webapp-ui.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__cute.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__daily-news.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__editorial.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__fresh.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__minimalist.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__photorealistic.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__sketch.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__technical-diagram.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__vibrant.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__warm.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__xhs-knowledge.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/free__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/illustration__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/xhs-card__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/dist/index.js +1 -1
- package/plugins/generations/image-gen/presets/formats/daily-news-podcast-cover.yaml +18 -0
- package/plugins/generations/image-gen/presets/styles/quasi-news-podcast.yaml +9 -0
- package/plugins/generations/news-report-gen/dist/index.js +1 -1
- package/plugins/generations/voice-gen/dist/index.js +1 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +1 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +1 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +1 -1
- package/plugins/ingestions/web-search/dist/index.js +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +12 -3
- package/plugins/kk/publish-presets/daily-ai-voice.json +11 -3
- package/plugins/kk/scripts/cover-compositor.ts +152 -0
- package/plugins/kk/scripts/daily-cover-mock.ts +164 -0
- package/plugins/kk/scripts/daily-scheduled-run.ts +188 -3
- package/plugins/kk/scripts/daily-stages.ts +134 -26
- package/plugins/kk/scripts/daily-triage-core.ts +451 -0
- package/plugins/kk/scripts/daily-triage.ts +74 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +31 -2
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +16 -10
- package/plugins/kk/skills/news-editorial/SKILL.md +3 -3
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +2 -1
- package/plugins/kk/skills/publish/SKILL.md +1 -1
- package/plugins/kk/skills/wiki-authoring/SKILL.md +53 -0
- package/plugins/kk/skills/wiki-authoring/references/page-shapes.md +44 -0
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +3 -3
- package/plugins/kk/workflows/kk-daily-safety.yaml +32 -7
- package/plugins/publishings/bilibili-pub/dist/index.js +1 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +1 -1
- package/plugins/publishings/csdn-pub/dist/index.js +1 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/emdash-pub/dist/index.js +1 -1
- package/plugins/publishings/infoq-pub/dist/index.js +1 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/jike-pub/dist/index.js +1 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/juejin-pub/dist/index.js +1 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +1 -1
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/medium-pub/dist/index.js +1 -1
- package/plugins/publishings/podcast-pub/dist/index.js +1 -1
- package/plugins/publishings/qiita-pub/dist/index.js +1 -1
- package/plugins/publishings/shipinhao-pub/dist/index.js +222 -50
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +48 -1
- package/plugins/publishings/shipinhao-pub/plugin.json +2 -2
- package/plugins/publishings/shipinhao-pub/src/flow.ts +335 -79
- package/plugins/publishings/shipinhao-pub/src/index.ts +16 -8
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +1 -1
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +103 -5
- package/plugins/publishings/sspai-pub/dist/index.js +1 -1
- package/plugins/publishings/substack-pub/dist/index.js +1 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +235 -12
- package/plugins/publishings/surfdash-pub/src/index.ts +127 -6
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +189 -0
- package/plugins/publishings/threads-pub/dist/index.js +1 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +10 -7
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +10 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +3 -4
- package/plugins/publishings/wechatmp-pub/src/page.ts +14 -0
- package/plugins/publishings/weibo-pub/dist/index.js +1 -1
- package/plugins/publishings/weibo-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/x-pub/dist/index.js +1 -1
- package/plugins/publishings/x-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/xhs-pub/dist/index.js +557 -31
- package/plugins/publishings/xhs-pub/dist/profile-check.js +20 -1
- package/plugins/publishings/xhs-pub/src/errors.ts +45 -0
- package/plugins/publishings/xhs-pub/src/flow.ts +773 -45
- package/plugins/publishings/xhs-pub/src/page.ts +33 -0
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +1 -1
- package/plugins/publishings/zenn-pub/dist/index.js +1 -1
|
@@ -12,13 +12,23 @@
|
|
|
12
12
|
* `bun run check:content` in the surfdash checkout. The surfdash site gate is the authoritative
|
|
13
13
|
* validation suite before deployment.
|
|
14
14
|
*
|
|
15
|
+
* Daily-topics sync:
|
|
16
|
+
* Before the site gate and commit, digest posts with all three locale files are mapped into
|
|
17
|
+
* the surfdash site's `scripts/seo/daily-topics.json` (from the posts' own refined frontmatter,
|
|
18
|
+
* no new prose), then `bun run sd seo retitle --write --stamp-claims` runs in the checkout.
|
|
19
|
+
* A build/retitle failure fails the run before anything is committed or pushed. See
|
|
20
|
+
* `./topic-claims` for the file work.
|
|
21
|
+
*
|
|
15
22
|
* Environment variables:
|
|
16
23
|
* - `SURFDASH_LISTEN_BACKFILL`:
|
|
17
24
|
* - `off`: skips the listen-link backfill command.
|
|
18
25
|
* - `SURFDASH_DIGEST_CHECK`:
|
|
19
26
|
* - unset / default: fail-loud on gate failure; commit and push are blocked.
|
|
20
|
-
* - `warn`: echoes gate failures via `echoError` prefixed with `site gate (warn):` and continues
|
|
27
|
+
* - `warn`: echoes gate failures via `echoError` prefixed with `site gate (warn):` and continues.
|
|
21
28
|
* - `off`: bypasses the gate check.
|
|
29
|
+
* - Both escape hatches are IGNORED while this run pushes to surfdash `main`
|
|
30
|
+
* (`SURFDASH_AUTO_PUSH !== '0'` and the checkout is on `main`): a failing gate always
|
|
31
|
+
* blocks there, and `off` still runs the gate.
|
|
22
32
|
* - `SURFDASH_AUTO_PUSH`:
|
|
23
33
|
* - '0': disables auto-commit and push (used in tests and offline runs).
|
|
24
34
|
*/
|
|
@@ -34,8 +44,10 @@ import { echoError } from '@gobing-ai/ts-utils';
|
|
|
34
44
|
// The plugin's public digest-contract surface (2026-10-24).
|
|
35
45
|
import { checkDigestFrontmatter, DIGEST_TAG, type DigestLocale } from './digest-check';
|
|
36
46
|
import { localeIndexPath, PATCH_LOCALES, type PatchPostOutcome, patchPostFiles } from './patch';
|
|
47
|
+
import { buildDailyTopicsEntry, isDigestMarkdown, slugFromPostPath, upsertDailyTopicsEntry } from './topic-claims';
|
|
37
48
|
|
|
38
49
|
export { checkDigestFrontmatter, DIGEST_TAG, type DigestLocale } from './digest-check';
|
|
50
|
+
export { buildDailyTopicsEntry, isDigestMarkdown, slugFromPostPath, upsertDailyTopicsEntry } from './topic-claims';
|
|
39
51
|
|
|
40
52
|
/** Result target name for this plugin. */
|
|
41
53
|
const TARGET = 'surfdash';
|
|
@@ -458,6 +470,78 @@ export async function runListenLinkBackfill(surfdashRoot: string): Promise<strin
|
|
|
458
470
|
return [...new Set(afterPaths.filter((p) => !beforePaths.has(p)))];
|
|
459
471
|
}
|
|
460
472
|
|
|
473
|
+
/** Outcome of {@link runDailyTopicsSync} — `paths` are checkout-relative for the commit pathspec. */
|
|
474
|
+
export type DailyTopicsSyncOutcome = { ok: true; paths: string[] } | { ok: false; error: string };
|
|
475
|
+
|
|
476
|
+
/** Paths the sync's git diff watches: the map file plus everything the retitle may rewrite. */
|
|
477
|
+
const DAILY_TOPICS_GIT_PATHS = ['scripts/seo/daily-topics.json', 'content/posts'] as const;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Maps a digest post's three refined locale posts into the site's daily-topics map and runs
|
|
481
|
+
* the site's retitle over them (`bun run sd seo retitle --write --stamp-claims`).
|
|
482
|
+
*
|
|
483
|
+
* Skips (ok, no paths, logged) when the post is not a digest or not all of zh/en/ja `index.md`
|
|
484
|
+
* exist — the site gate still validates whatever the posts already carry. A failing entry build
|
|
485
|
+
* or retitle run returns `{ ok: false }` so the caller never commits or pushes. Returns the map
|
|
486
|
+
* file plus every path the retitle changed, for the commit pathspec.
|
|
487
|
+
*/
|
|
488
|
+
export async function runDailyTopicsSync(surfdashRoot: string, zhPostPath: string): Promise<DailyTopicsSyncOutcome> {
|
|
489
|
+
const enPath = localeIndexPath(zhPostPath, 'en');
|
|
490
|
+
const jaPath = localeIndexPath(zhPostPath, 'ja');
|
|
491
|
+
if (enPath === undefined || jaPath === undefined) {
|
|
492
|
+
echoError(`daily-topics sync: skipped — ${zhPostPath} is not a zh locale post path`);
|
|
493
|
+
return { ok: true, paths: [] };
|
|
494
|
+
}
|
|
495
|
+
if (!existsSync(zhPostPath)) {
|
|
496
|
+
echoError(`daily-topics sync: skipped — zh post is missing: ${zhPostPath}`);
|
|
497
|
+
return { ok: true, paths: [] };
|
|
498
|
+
}
|
|
499
|
+
const zhPost = readFileSync(zhPostPath, 'utf-8');
|
|
500
|
+
if (!isDigestMarkdown(zhPost)) {
|
|
501
|
+
echoError(`daily-topics sync: skipped — not a digest post (no ${DIGEST_TAG} tag): ${zhPostPath}`);
|
|
502
|
+
return { ok: true, paths: [] };
|
|
503
|
+
}
|
|
504
|
+
if (!existsSync(enPath) || !existsSync(jaPath)) {
|
|
505
|
+
echoError(
|
|
506
|
+
`daily-topics sync: skipped — locale index.md missing (en=${existsSync(enPath)} ja=${existsSync(jaPath)}): ${zhPostPath}`,
|
|
507
|
+
);
|
|
508
|
+
return { ok: true, paths: [] };
|
|
509
|
+
}
|
|
510
|
+
const slug = slugFromPostPath(zhPostPath);
|
|
511
|
+
if (slug === undefined) {
|
|
512
|
+
return { ok: false, error: `daily-topics sync failed: cannot derive slug from ${zhPostPath}` };
|
|
513
|
+
}
|
|
514
|
+
const built = buildDailyTopicsEntry({
|
|
515
|
+
zh: zhPost,
|
|
516
|
+
en: readFileSync(enPath, 'utf-8'),
|
|
517
|
+
ja: readFileSync(jaPath, 'utf-8'),
|
|
518
|
+
});
|
|
519
|
+
if (!built.ok) {
|
|
520
|
+
return { ok: false, error: `daily-topics sync failed: ${built.error}` };
|
|
521
|
+
}
|
|
522
|
+
const mapPath = join(surfdashRoot, 'scripts', 'seo', 'daily-topics.json');
|
|
523
|
+
const before = await spawnCli(['git', 'status', '--porcelain', '--', ...DAILY_TOPICS_GIT_PATHS], surfdashRoot);
|
|
524
|
+
const beforePaths = new Set(parsePorcelainPaths(before.stdout));
|
|
525
|
+
try {
|
|
526
|
+
await upsertDailyTopicsEntry(mapPath, slug, built.entry);
|
|
527
|
+
} catch (error: unknown) {
|
|
528
|
+
return {
|
|
529
|
+
ok: false,
|
|
530
|
+
error: `daily-topics sync failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const retitle = await spawnCli(['bun', 'run', 'sd', 'seo', 'retitle', '--write', '--stamp-claims'], surfdashRoot);
|
|
534
|
+
if (retitle.exitCode !== 0) {
|
|
535
|
+
return {
|
|
536
|
+
ok: false,
|
|
537
|
+
error: `daily-topics sync failed: bun run sd seo retitle --write --stamp-claims (exit ${retitle.exitCode}): ${cliErrorText(retitle)}`,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
const after = await spawnCli(['git', 'status', '--porcelain', '--', ...DAILY_TOPICS_GIT_PATHS], surfdashRoot);
|
|
541
|
+
const changed = parsePorcelainPaths(after.stdout).filter((p) => !beforePaths.has(p));
|
|
542
|
+
return { ok: true, paths: [...new Set([relative(surfdashRoot, mapPath), ...changed])] };
|
|
543
|
+
}
|
|
544
|
+
|
|
461
545
|
/** Outcome of {@link runSiteGate}. */
|
|
462
546
|
export type SiteGateOutcome = { ok: true } | { ok: false; error: string };
|
|
463
547
|
|
|
@@ -499,11 +583,23 @@ function isUnrelatedDatePostFailure(output: string, ownedPaths: readonly string[
|
|
|
499
583
|
return true;
|
|
500
584
|
}
|
|
501
585
|
|
|
586
|
+
/** The checkout's current branch name, or '' when git fails (the caller keeps its existing behavior). */
|
|
587
|
+
async function checkoutBranch(surfdashRoot: string): Promise<string> {
|
|
588
|
+
const branch = await spawnCli(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], surfdashRoot);
|
|
589
|
+
return branch.exitCode === 0 ? branch.stdout.trim() : '';
|
|
590
|
+
}
|
|
591
|
+
|
|
502
592
|
/**
|
|
503
593
|
* Runs the surfdash site gates (`bun run sd check digest` then `bun run check:content`)
|
|
504
594
|
* with cwd = `surfdashRoot` via `spawnCli`.
|
|
505
595
|
*
|
|
506
|
-
*
|
|
596
|
+
* Fail-closed on main pushes: when the checkout is on `main` and this run will push
|
|
597
|
+
* (`SURFDASH_AUTO_PUSH !== '0'`), a failing gate ALWAYS returns `{ ok: false }` — the
|
|
598
|
+
* `warn` / unrelated-date escape hatch logs that it was ignored (this is a push to main)
|
|
599
|
+
* plus the gate output and failing-post hint, and `off` still runs the gate instead of
|
|
600
|
+
* skipping it.
|
|
601
|
+
*
|
|
602
|
+
* Otherwise:
|
|
507
603
|
* - With `SURFDASH_DIGEST_CHECK=warn` (or when every failing post belongs to an unrelated date
|
|
508
604
|
* outside `ownedPaths`): echoes each line of the failure via `echoError` prefixed with
|
|
509
605
|
* `site gate (warn):` and continues.
|
|
@@ -511,8 +607,15 @@ function isUnrelatedDatePostFailure(output: string, ownedPaths: readonly string[
|
|
|
511
607
|
* - Default (unset or any other value): fails loud with command, trimmed output, and post hint.
|
|
512
608
|
*/
|
|
513
609
|
export async function runSiteGate(surfdashRoot: string, ownedPaths: readonly string[] = []): Promise<SiteGateOutcome> {
|
|
610
|
+
const pushingToMain = process.env.SURFDASH_AUTO_PUSH !== '0' && (await checkoutBranch(surfdashRoot)) === 'main';
|
|
514
611
|
if (process.env.SURFDASH_DIGEST_CHECK === 'off') {
|
|
515
|
-
|
|
612
|
+
if (pushingToMain) {
|
|
613
|
+
echoError(
|
|
614
|
+
'site gate: SURFDASH_DIGEST_CHECK=off ignored — this run pushes to surfdash main, so the gate runs fail-closed',
|
|
615
|
+
);
|
|
616
|
+
} else {
|
|
617
|
+
return { ok: true };
|
|
618
|
+
}
|
|
516
619
|
}
|
|
517
620
|
|
|
518
621
|
for (const cmd of SITE_GATE_COMMANDS) {
|
|
@@ -522,7 +625,18 @@ export async function runSiteGate(surfdashRoot: string, ownedPaths: readonly str
|
|
|
522
625
|
const postHint = extractFailingPostHint(output);
|
|
523
626
|
const hint = postHint ? ` [failing post: ${postHint}]` : '';
|
|
524
627
|
const error = `site gate failed: ${cmd.join(' ')} (exit ${spawned.exitCode})${hint}: ${output}`;
|
|
525
|
-
|
|
628
|
+
const escapable =
|
|
629
|
+
process.env.SURFDASH_DIGEST_CHECK === 'warn' || isUnrelatedDatePostFailure(output, ownedPaths);
|
|
630
|
+
if (escapable && pushingToMain) {
|
|
631
|
+
echoError(
|
|
632
|
+
'site gate: warn/unrelated-date escape hatch ignored because this run pushes to surfdash main — failing closed (set SURFDASH_AUTO_PUSH=0 to skip the push entirely)',
|
|
633
|
+
);
|
|
634
|
+
for (const line of error.split('\n')) {
|
|
635
|
+
echoError(`site gate (blocked): ${line}`);
|
|
636
|
+
}
|
|
637
|
+
return { ok: false, error };
|
|
638
|
+
}
|
|
639
|
+
if (escapable) {
|
|
526
640
|
for (const line of error.split('\n')) {
|
|
527
641
|
echoError(`site gate (warn): ${line}`);
|
|
528
642
|
}
|
|
@@ -862,8 +976,13 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
862
976
|
return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
|
|
863
977
|
}
|
|
864
978
|
if (outcome.changed === 0) echoError(`patch: no post bytes changed for ${outcome.slug}`);
|
|
979
|
+
// Daily-topics map + retitle run before the CMS sync so the synced rows carry the retitled
|
|
980
|
+
// frontmatter; a failure here must not commit or push a half-synced post.
|
|
981
|
+
const topics = await runDailyTopicsSync(surfdashRoot, postPath.postPath);
|
|
982
|
+
if (!topics.ok) return fail(topics.error);
|
|
865
983
|
const synced = await syncPost({ postPath: postPath.postPath });
|
|
866
984
|
const commitPaths = new Set(outcome.written.map((path) => relative(surfdashRoot, path)));
|
|
985
|
+
for (const p of topics.paths) commitPaths.add(p);
|
|
867
986
|
for (const locale of PATCH_LOCALES) {
|
|
868
987
|
const indexMd = localeIndexPath(postPath.postPath, locale);
|
|
869
988
|
if (!indexMd) continue;
|
|
@@ -1282,16 +1401,18 @@ async function publishPreparedFile(
|
|
|
1282
1401
|
},
|
|
1283
1402
|
});
|
|
1284
1403
|
}
|
|
1404
|
+
const topics = await runDailyTopicsSync(surfdashRoot, filePath);
|
|
1405
|
+
if (!topics.ok) return failUncertain(topics.error);
|
|
1285
1406
|
const backfilled = await runListenLinkBackfill(surfdashRoot);
|
|
1286
1407
|
const commitPaths = relPostDirs ?? [relPostDir];
|
|
1287
|
-
const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled]);
|
|
1408
|
+
const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled, ...topics.paths]);
|
|
1288
1409
|
if (!gate.ok) return failUncertain(gate.error);
|
|
1289
1410
|
const commitLocales: SupportedLocale[] = relPostDirs === undefined ? [locale] : ['zh', 'en', 'ja'];
|
|
1290
1411
|
const pushed = await pushPostGit(
|
|
1291
1412
|
surfdashRoot,
|
|
1292
1413
|
commitPaths,
|
|
1293
1414
|
`content: daily AI news ${dateStamp} (${commitLocales.join(', ')})`,
|
|
1294
|
-
backfilled,
|
|
1415
|
+
[...backfilled, ...topics.paths],
|
|
1295
1416
|
);
|
|
1296
1417
|
if (!pushed.ok) return failUncertain(pushed.error);
|
|
1297
1418
|
const live = await awaitArticleLive(articleUrl);
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic daily-topics.json upsert for digest posts (zh/en/ja).
|
|
3
|
+
*
|
|
4
|
+
* Headlines, descriptions, and claims are copied from existing post frontmatter —
|
|
5
|
+
* never invented. `claim_basis` is left unset so `sd seo retitle --write --stamp-claims`
|
|
6
|
+
* can stamp it. Upsert is idempotent and always writes a given slug key once, so a
|
|
7
|
+
* file that already had a duplicated key (the surfdash #30 merge failure) is collapsed
|
|
8
|
+
* on rewrite.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { dirname } from 'node:path';
|
|
12
|
+
import { createNodeFileSystem, type FileSystem } from '@gobing-ai/ts-runtime';
|
|
13
|
+
import { DIGEST_TAG, parseFrontmatterScalars } from './digest-check';
|
|
14
|
+
import { PATCH_LOCALES, type PatchLocale, SERIES_NAMES } from './patch';
|
|
15
|
+
|
|
16
|
+
/** One locale's topic-map fields. `claim_basis` is stamped later by retitle. */
|
|
17
|
+
export interface DailyTopicsLocaleEntry {
|
|
18
|
+
headlines: string[];
|
|
19
|
+
description: string;
|
|
20
|
+
key_points: string[];
|
|
21
|
+
claims: string[];
|
|
22
|
+
short_claims: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The three-locale value stored under a day's slug in daily-topics.json. */
|
|
26
|
+
export type DailyTopicsEntry = Record<PatchLocale, DailyTopicsLocaleEntry>;
|
|
27
|
+
|
|
28
|
+
export type BuildDailyTopicsResult = { ok: true; entry: DailyTopicsEntry } | { ok: false; error: string };
|
|
29
|
+
|
|
30
|
+
const escapeRe = (token: string): string => token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
31
|
+
|
|
32
|
+
const titleSepFor = (locale: PatchLocale): string => (locale === 'en' ? ': ' : ':');
|
|
33
|
+
const listSepFor = (locale: PatchLocale): string => (locale === 'en' ? ', ' : '、');
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Slug folder (`20261108-ai-2026-11-08`) from a locale `index.md` (or its directory)
|
|
37
|
+
* under `content/posts/articles/<locale>/`. The slug is not reconstructed from the title:
|
|
38
|
+
* historical map keys are not always `${YYYYMMDD}-ai-${YYYY-MM-DD}`.
|
|
39
|
+
*/
|
|
40
|
+
export function slugFromPostPath(postPath: string): string | undefined {
|
|
41
|
+
const normalized = postPath.replaceAll('\\', '/');
|
|
42
|
+
const match = normalized.match(/(?:^|\/)posts\/articles\/(?:zh|en|ja)\/([^/]+)/);
|
|
43
|
+
return match?.[1];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function tagList(frontmatter: Map<string, string | string[]>): string[] {
|
|
47
|
+
const tags = frontmatter.get('tags');
|
|
48
|
+
if (Array.isArray(tags)) return tags;
|
|
49
|
+
if (typeof tags === 'string' && tags !== '') return [tags];
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** True when the post carries the daily-digest tag. */
|
|
54
|
+
export function isDigestMarkdown(markdown: string): boolean {
|
|
55
|
+
return tagList(parseFrontmatterScalars(markdown)).some((tag) => tag.includes(DIGEST_TAG));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function scalar(frontmatter: Map<string, string | string[]>, key: string): string | undefined {
|
|
59
|
+
const value = frontmatter.get(key);
|
|
60
|
+
if (value === undefined) return undefined;
|
|
61
|
+
return Array.isArray(value) ? value.join(' ') : value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseTitleHeadlines(title: string, locale: PatchLocale): string[] | undefined {
|
|
65
|
+
const series = SERIES_NAMES[locale];
|
|
66
|
+
const titleSep = titleSepFor(locale);
|
|
67
|
+
const listSep = listSepFor(locale);
|
|
68
|
+
const match = title.match(new RegExp(`^${escapeRe(series)} · (\\d{4}-\\d{2}-\\d{2})${escapeRe(titleSep)}(.+)$`));
|
|
69
|
+
if (!match?.[2]) return undefined;
|
|
70
|
+
const heads = match[2].split(listSep).map((head) => head.trim());
|
|
71
|
+
if (heads.length < 2 || heads.some((head) => head === '')) return undefined;
|
|
72
|
+
return heads;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseKeyPointParts(points: string[]): { labels: string[]; sentences: string[] } | undefined {
|
|
76
|
+
const labels: string[] = [];
|
|
77
|
+
const sentences: string[] = [];
|
|
78
|
+
for (const point of points) {
|
|
79
|
+
const sep = point.indexOf(' — ');
|
|
80
|
+
if (sep < 0) return undefined;
|
|
81
|
+
const label = point.slice(0, sep).trim();
|
|
82
|
+
const sentence = point.slice(sep + 3).trim();
|
|
83
|
+
if (label === '' || sentence === '') return undefined;
|
|
84
|
+
labels.push(label);
|
|
85
|
+
sentences.push(sentence);
|
|
86
|
+
}
|
|
87
|
+
return { labels, sentences };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function splitDescriptionParts(description: string, count: number): string[] | undefined {
|
|
91
|
+
for (const pattern of [/;|; /, /;|;/]) {
|
|
92
|
+
const parts = description
|
|
93
|
+
.split(pattern)
|
|
94
|
+
.map((part) => part.trim())
|
|
95
|
+
.filter((part) => part !== '');
|
|
96
|
+
if (parts.length === count) return parts;
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function buildLocaleEntry(markdown: string, locale: PatchLocale): DailyTopicsLocaleEntry | string {
|
|
102
|
+
if (!isDigestMarkdown(markdown)) {
|
|
103
|
+
return `${locale}: missing ${DIGEST_TAG} tag`;
|
|
104
|
+
}
|
|
105
|
+
const frontmatter = parseFrontmatterScalars(markdown);
|
|
106
|
+
const title = scalar(frontmatter, 'title') ?? '';
|
|
107
|
+
const headlines = parseTitleHeadlines(title, locale);
|
|
108
|
+
if (!headlines) {
|
|
109
|
+
return `${locale}: title is not "<series> · YYYY-MM-DD${titleSepFor(locale)}h1${listSepFor(locale)}h2"`;
|
|
110
|
+
}
|
|
111
|
+
const description = (scalar(frontmatter, 'description') ?? scalar(frontmatter, 'seo_description') ?? '').trim();
|
|
112
|
+
if (description === '') {
|
|
113
|
+
return `${locale}: description is empty`;
|
|
114
|
+
}
|
|
115
|
+
const rawPoints = frontmatter.get('key_points');
|
|
116
|
+
if (!Array.isArray(rawPoints) || rawPoints.length === 0) {
|
|
117
|
+
return `${locale}: key_points is missing`;
|
|
118
|
+
}
|
|
119
|
+
const parts = parseKeyPointParts(rawPoints);
|
|
120
|
+
if (!parts) {
|
|
121
|
+
return `${locale}: key_points must be "label — sentence"`;
|
|
122
|
+
}
|
|
123
|
+
if (parts.labels.length !== headlines.length || parts.labels.some((label, i) => label !== headlines[i])) {
|
|
124
|
+
return `${locale}: title headlines do not match key_points labels`;
|
|
125
|
+
}
|
|
126
|
+
const claims = parts.sentences;
|
|
127
|
+
const shortClaims = splitDescriptionParts(description, headlines.length) ?? claims;
|
|
128
|
+
return {
|
|
129
|
+
headlines,
|
|
130
|
+
description,
|
|
131
|
+
key_points: headlines,
|
|
132
|
+
claims,
|
|
133
|
+
short_claims: shortClaims,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Build one day's topic-map entry from the three locale post bodies. Fails rather than
|
|
139
|
+
* invent wording when a title, description, or key_points label cannot be parsed confidently.
|
|
140
|
+
*/
|
|
141
|
+
export function buildDailyTopicsEntry(posts: Record<PatchLocale, string>): BuildDailyTopicsResult {
|
|
142
|
+
const entry = {} as DailyTopicsEntry;
|
|
143
|
+
for (const locale of PATCH_LOCALES) {
|
|
144
|
+
const markdown = posts[locale];
|
|
145
|
+
if (typeof markdown !== 'string' || markdown.trim() === '') {
|
|
146
|
+
return { ok: false, error: `${locale}: post markdown is empty` };
|
|
147
|
+
}
|
|
148
|
+
const built = buildLocaleEntry(markdown, locale);
|
|
149
|
+
if (typeof built === 'string') return { ok: false, error: built };
|
|
150
|
+
entry[locale] = built;
|
|
151
|
+
}
|
|
152
|
+
return { ok: true, entry };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Insert or replace `obj[slug] = entry` and write pretty tab-indented JSON. Parse+serialize
|
|
157
|
+
* collapses a raw file that already contained the same key twice. Never appends a second key.
|
|
158
|
+
* Rejects on unreadable / non-object JSON so the caller can fail closed. Text IO routes
|
|
159
|
+
* through the ts-runtime FileSystem seam (runtime-boundaries no-direct-fs-io).
|
|
160
|
+
*/
|
|
161
|
+
export async function upsertDailyTopicsEntry(
|
|
162
|
+
mapPath: string,
|
|
163
|
+
slug: string,
|
|
164
|
+
entry: DailyTopicsEntry,
|
|
165
|
+
fileSystem: FileSystem = createNodeFileSystem(),
|
|
166
|
+
): Promise<void> {
|
|
167
|
+
if (slug.trim() === '') throw new Error('daily-topics upsert: empty slug');
|
|
168
|
+
let existing: Record<string, unknown> = {};
|
|
169
|
+
if (await fileSystem.exists(mapPath)) {
|
|
170
|
+
const raw = (await fileSystem.readFile(mapPath)).trim();
|
|
171
|
+
if (raw !== '') {
|
|
172
|
+
let parsed: unknown;
|
|
173
|
+
try {
|
|
174
|
+
parsed = JSON.parse(raw);
|
|
175
|
+
} catch (error: unknown) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`daily-topics upsert: invalid JSON in ${mapPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
181
|
+
throw new Error(`daily-topics upsert: ${mapPath} is not a JSON object`);
|
|
182
|
+
}
|
|
183
|
+
existing = parsed as Record<string, unknown>;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
existing[slug] = entry;
|
|
187
|
+
await fileSystem.ensureDir(dirname(mapPath));
|
|
188
|
+
await fileSystem.writeFile(mapPath, `${JSON.stringify(existing, null, '\t')}\n`);
|
|
189
|
+
}
|
|
@@ -12057,7 +12057,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
12057
12057
|
shortVideo: Object.freeze({
|
|
12058
12058
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
12059
12059
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
12060
|
-
shipinhao: Object.freeze({ max:
|
|
12060
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
12061
12061
|
})
|
|
12062
12062
|
})
|
|
12063
12063
|
});
|
|
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
19905
19905
|
shortVideo: Object.freeze({
|
|
19906
19906
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19907
19907
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19908
|
-
shipinhao: Object.freeze({ max:
|
|
19908
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
19909
19909
|
})
|
|
19910
19910
|
})
|
|
19911
19911
|
});
|
|
@@ -22062,6 +22062,12 @@ async function modalState(page) {
|
|
|
22062
22062
|
return "unknown";
|
|
22063
22063
|
}
|
|
22064
22064
|
}
|
|
22065
|
+
async function bestEffortPress(page, key, settleMs = 400) {
|
|
22066
|
+
try {
|
|
22067
|
+
await page.press?.(key);
|
|
22068
|
+
await page.waitForTimeout?.(settleMs);
|
|
22069
|
+
} catch {}
|
|
22070
|
+
}
|
|
22065
22071
|
async function tryFindAttachedSelector(page, selectors, timeoutMs = STEP_TIMEOUT_MS) {
|
|
22066
22072
|
let found;
|
|
22067
22073
|
await waitUntil(async () => {
|
|
@@ -22345,8 +22351,7 @@ async function enrichArticle(page, meta) {
|
|
|
22345
22351
|
await page.locator(cancel.selector ?? "").first().click({ timeout: 2000 });
|
|
22346
22352
|
} catch {}
|
|
22347
22353
|
}
|
|
22348
|
-
await page
|
|
22349
|
-
await page.waitForTimeout?.(SWEEP_SETTLE_MS);
|
|
22354
|
+
await bestEffortPress(page, "Escape", SWEEP_SETTLE_MS);
|
|
22350
22355
|
const state = await modalState(page);
|
|
22351
22356
|
if (state === "open") {
|
|
22352
22357
|
for (const close of [".weui-desktop-dialog__close-btn", ".weui-desktop-dialog__close"]) {
|
|
@@ -22595,8 +22600,7 @@ async function dismissOpenDialog(page) {
|
|
|
22595
22600
|
} catch {}
|
|
22596
22601
|
break;
|
|
22597
22602
|
}
|
|
22598
|
-
await page
|
|
22599
|
-
await page.waitForTimeout?.(400);
|
|
22603
|
+
await bestEffortPress(page, "Escape");
|
|
22600
22604
|
}
|
|
22601
22605
|
var DIALOG_CLOSE = [
|
|
22602
22606
|
".weui-desktop-dialog__wrp .weui-desktop-dialog__close",
|
|
@@ -22619,8 +22623,7 @@ async function closeOpenDialogs(page) {
|
|
|
22619
22623
|
} catch {}
|
|
22620
22624
|
break;
|
|
22621
22625
|
}
|
|
22622
|
-
await page
|
|
22623
|
-
await page.waitForTimeout?.(400);
|
|
22626
|
+
await bestEffortPress(page, "Escape");
|
|
22624
22627
|
}
|
|
22625
22628
|
return await modalState(page) === "closed" ? "closed" : "residual";
|
|
22626
22629
|
}
|
|
@@ -20504,7 +20504,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
20504
20504
|
shortVideo: Object.freeze({
|
|
20505
20505
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20506
20506
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20507
|
-
shipinhao: Object.freeze({ max:
|
|
20507
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
20508
20508
|
})
|
|
20509
20509
|
})
|
|
20510
20510
|
});
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { trySelectors } from '@gobing-ai/publish-harness';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
bestEffortPress,
|
|
4
|
+
clickSelector,
|
|
5
|
+
fillSelector,
|
|
6
|
+
modalState,
|
|
7
|
+
tryFindSelector,
|
|
8
|
+
type WechatPage,
|
|
9
|
+
waitForVisible,
|
|
10
|
+
} from './page';
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* The 文章 operation's `metadata.wechatmp` enrichment rail (2026-09-29, ADR-026; committed-value
|
|
@@ -150,8 +158,7 @@ export async function enrichArticle(page: WechatPage, meta: Record<string, unkno
|
|
|
150
158
|
// The dialog may already be gone; the sweep is best-effort.
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
|
-
await page
|
|
154
|
-
await page.waitForTimeout?.(SWEEP_SETTLE_MS);
|
|
161
|
+
await bestEffortPress(page, 'Escape', SWEEP_SETTLE_MS);
|
|
155
162
|
const state = await modalState(page);
|
|
156
163
|
if (state === 'open') {
|
|
157
164
|
// One explicit close-button pass before giving up: some dialogs ignore Escape.
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
type WechatmpOperation,
|
|
38
38
|
} from './modes';
|
|
39
39
|
import {
|
|
40
|
+
bestEffortPress,
|
|
40
41
|
clickSelector,
|
|
41
42
|
fillSelector,
|
|
42
43
|
findAttachedSelector,
|
|
@@ -166,8 +167,7 @@ async function dismissOpenDialog(page: WechatPage): Promise<void> {
|
|
|
166
167
|
}
|
|
167
168
|
break;
|
|
168
169
|
}
|
|
169
|
-
await page
|
|
170
|
-
await page.waitForTimeout?.(400);
|
|
170
|
+
await bestEffortPress(page, 'Escape');
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/** The close controls a console modal exposes, most specific first (the audio picker shows no 取消).
|
|
@@ -204,8 +204,7 @@ async function closeOpenDialogs(page: WechatPage): Promise<'closed' | 'residual'
|
|
|
204
204
|
}
|
|
205
205
|
break;
|
|
206
206
|
}
|
|
207
|
-
await page
|
|
208
|
-
await page.waitForTimeout?.(400);
|
|
207
|
+
await bestEffortPress(page, 'Escape');
|
|
209
208
|
}
|
|
210
209
|
return (await modalState(page)) === 'closed' ? 'closed' : 'residual';
|
|
211
210
|
}
|
|
@@ -94,6 +94,20 @@ export async function modalState(page: WechatPage): Promise<'closed' | 'open' |
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** Best-effort key press + settle wait for the dialog sweeps. A page that died mid-run (browser
|
|
98
|
+
* crash or close) has no UI left to settle, and every sweep sits on a warning contract — the
|
|
99
|
+
* press must degrade to "nothing left to dismiss", never throw through the warning path
|
|
100
|
+
* (measured: the cover-stale-commit fixture run crashed when Chromium died between the
|
|
101
|
+
* committed-preview read and the Escape). */
|
|
102
|
+
export async function bestEffortPress(page: WechatPage, key: string, settleMs = 400): Promise<void> {
|
|
103
|
+
try {
|
|
104
|
+
await page.press?.(key);
|
|
105
|
+
await page.waitForTimeout?.(settleMs);
|
|
106
|
+
} catch {
|
|
107
|
+
// Page/context/browser already gone — nothing left to dismiss or settle.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
/** A selector with an ATTACHED match (hidden inputs included), or `undefined` at the deadline. */
|
|
98
112
|
async function tryFindAttachedSelector(
|
|
99
113
|
page: WechatPage,
|
|
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
19905
19905
|
shortVideo: Object.freeze({
|
|
19906
19906
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19907
19907
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19908
|
-
shipinhao: Object.freeze({ max:
|
|
19908
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
19909
19909
|
})
|
|
19910
19910
|
})
|
|
19911
19911
|
});
|
|
@@ -20779,7 +20779,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
20779
20779
|
shortVideo: Object.freeze({
|
|
20780
20780
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20781
20781
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20782
|
-
shipinhao: Object.freeze({ max:
|
|
20782
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
20783
20783
|
})
|
|
20784
20784
|
})
|
|
20785
20785
|
});
|
|
@@ -19906,7 +19906,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
19906
19906
|
shortVideo: Object.freeze({
|
|
19907
19907
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19908
19908
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19909
|
-
shipinhao: Object.freeze({ max:
|
|
19909
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
19910
19910
|
})
|
|
19911
19911
|
})
|
|
19912
19912
|
});
|
|
@@ -20779,7 +20779,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
20779
20779
|
shortVideo: Object.freeze({
|
|
20780
20780
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20781
20781
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
20782
|
-
shipinhao: Object.freeze({ max:
|
|
20782
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
20783
20783
|
})
|
|
20784
20784
|
})
|
|
20785
20785
|
});
|