@gobing-ai/knowledge-kit 0.1.19 → 0.1.20
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/daily-voice/index.js +40 -7
- package/dist/index.js +1379 -378
- package/package.json +1 -1
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +32 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +385 -31
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +7 -0
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +46 -2
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
withProfilePage,
|
|
52
52
|
} from '@gobing-ai/ts-browser-automation';
|
|
53
53
|
import type { Locator, Page } from 'playwright';
|
|
54
|
+
import { runAudioPostFlow } from './audio-flow';
|
|
54
55
|
import {
|
|
55
56
|
isShipinhaoAuthenticated,
|
|
56
57
|
readRootSnapshot,
|
|
@@ -72,7 +73,20 @@ import {
|
|
|
72
73
|
type ShipinhaoRootSnapshot,
|
|
73
74
|
} from './selectors';
|
|
74
75
|
|
|
76
|
+
/** Steps (fill, upload, dialog) keep the shared 30s rail. */
|
|
75
77
|
const STEP_TIMEOUT_MS = 30_000;
|
|
78
|
+
/**
|
|
79
|
+
* The read-only session preflight is a cold headless launch plus a readiness poll; the shipped
|
|
80
|
+
* probe verifies the same profile with a 120s budget (`profile-check check --timeout 120000`) while
|
|
81
|
+
* this call was capped at the 30s STEP budget, so a healthy session that takes 40-60s to paint read
|
|
82
|
+
* as `Authentication was not confirmed` (2026-11-13: check verified, publish refused).
|
|
83
|
+
*/
|
|
84
|
+
const PREFLIGHT_TIMEOUT_MS = 180_000;
|
|
85
|
+
/**
|
|
86
|
+
* Per-poll budget for the 合集 control probe inside the selection loop: the row either exists or
|
|
87
|
+
* does not, so a long wait per attempt only delays the typed refusal (2026-11-16).
|
|
88
|
+
*/
|
|
89
|
+
const COLLECTION_PROBE_MS = 2_000;
|
|
76
90
|
/**
|
|
77
91
|
* KK v1 local-media size bound (task 0296 Design freeze): 2 GiB, applied to every media kind. A
|
|
78
92
|
* project-scoped product bound, not a platform limit — Channels' own ceiling is unpinned.
|
|
@@ -567,6 +581,22 @@ function resolveOriginal(
|
|
|
567
581
|
return { original: raw };
|
|
568
582
|
}
|
|
569
583
|
|
|
584
|
+
/**
|
|
585
|
+
* Pre-browser 合集 gate (2026-11-16): an optional non-empty collection title, applied to the AUDIO
|
|
586
|
+
* post only. A collection that cannot be committed is a typed failure *before* the submit click —
|
|
587
|
+
* the operator asked for the episode to live in 合集 `每日AI乱炖`, so publishing without it is not
|
|
588
|
+
* a degraded success, it is the wrong result.
|
|
589
|
+
*/
|
|
590
|
+
function resolveCollection(
|
|
591
|
+
raw: unknown,
|
|
592
|
+
): { collection?: string; error?: undefined } | { collection?: undefined; error: string } {
|
|
593
|
+
if (raw === undefined) return {};
|
|
594
|
+
if (typeof raw !== 'string' || raw.trim().length === 0) {
|
|
595
|
+
return { error: `collection must be a nonempty string when present, got '${bounded(raw)}'` };
|
|
596
|
+
}
|
|
597
|
+
return { collection: raw.trim() };
|
|
598
|
+
}
|
|
599
|
+
|
|
570
600
|
/**
|
|
571
601
|
* Unsupported requested fields, per operation: fields that mean nothing to the requested flow —
|
|
572
602
|
* images/videoPath outside their own operation, coverPath for 图文 — are typed unsupported-field
|
|
@@ -575,11 +605,14 @@ function resolveOriginal(
|
|
|
575
605
|
* `coverPath` (except on image) are implemented and validated in their resolvers.
|
|
576
606
|
*/
|
|
577
607
|
function unsupportedFields(payload: PublishTransportPayload, operation: ShipinhaoOperationName): readonly string[] {
|
|
608
|
+
// `collection` is implemented for AUDIO only (2026-11-16): the other three kinds must keep
|
|
609
|
+
// their exact current behaviour, so a collection request on them is refused by name instead of
|
|
610
|
+
// silently ignored.
|
|
578
611
|
const perOperation: Record<ShipinhaoOperationName, readonly string[]> = {
|
|
579
|
-
shortVideo: ['images', 'categories', 'publishTime', 'scheduling'],
|
|
612
|
+
shortVideo: ['images', 'categories', 'publishTime', 'scheduling', 'collection'],
|
|
580
613
|
audio: ['videoPath', 'images', 'categories', 'publishTime', 'scheduling'],
|
|
581
|
-
music: ['videoPath', 'images', 'categories', 'publishTime', 'scheduling'],
|
|
582
|
-
image: ['videoPath', 'coverPath', 'categories', 'publishTime', 'scheduling'],
|
|
614
|
+
music: ['videoPath', 'images', 'categories', 'publishTime', 'scheduling', 'collection'],
|
|
615
|
+
image: ['videoPath', 'coverPath', 'categories', 'publishTime', 'scheduling', 'collection'],
|
|
583
616
|
};
|
|
584
617
|
const refused: string[] = [];
|
|
585
618
|
for (const [container, source] of [
|
|
@@ -620,6 +653,55 @@ function editingFormReadyScript(mode: 'wujie' | 'direct', titleSelector: string,
|
|
|
620
653
|
})()`;
|
|
621
654
|
}
|
|
622
655
|
|
|
656
|
+
/**
|
|
657
|
+
* 合集 (collection) control, one parameterised page script (2026-11-16).
|
|
658
|
+
*
|
|
659
|
+
* The audio form's collection row ships without a stable class, so this works from text alone:
|
|
660
|
+
* `click-entry` finds the rendered row whose own text starts with the 合集 label and clicks it,
|
|
661
|
+
* `click-option` picks the option whose own text equals the requested collection (exact, never by
|
|
662
|
+
* index) — a native `<select>` is served by assigning the matching option's value — and `read`
|
|
663
|
+
* re-reads the row afterwards so a click that did not commit is never mistaken for a selection.
|
|
664
|
+
*/
|
|
665
|
+
function collectionScript(
|
|
666
|
+
mode: 'wujie' | 'direct',
|
|
667
|
+
action: 'click-entry' | 'click-option' | 'read',
|
|
668
|
+
label: string,
|
|
669
|
+
name: string,
|
|
670
|
+
): string {
|
|
671
|
+
return `${rootScriptPrefix(mode)} // kk-shp-collection
|
|
672
|
+
const label = ${JSON.stringify(label)};
|
|
673
|
+
const name = ${JSON.stringify(name)};
|
|
674
|
+
const action = ${JSON.stringify(action)};
|
|
675
|
+
const roots = [document, root].filter(Boolean);
|
|
676
|
+
const ownText = (el) => Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => (n.textContent || '').trim()).join(' ').trim();
|
|
677
|
+
const rendered = (el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0; };
|
|
678
|
+
const all = [];
|
|
679
|
+
for (const scope of roots) {
|
|
680
|
+
if (!scope || !scope.querySelectorAll) continue;
|
|
681
|
+
for (const el of scope.querySelectorAll('*')) all.push(el);
|
|
682
|
+
}
|
|
683
|
+
const row = all.find((el) => rendered(el) && ownText(el).startsWith(label));
|
|
684
|
+
if (action === 'click-entry') {
|
|
685
|
+
if (!row) return JSON.stringify({ ok: false, reason: 'entry-absent' });
|
|
686
|
+
const target = row.closest('button, div, li, label') || row;
|
|
687
|
+
target.click();
|
|
688
|
+
return JSON.stringify({ ok: true, text: String(row.textContent || '').trim().slice(0, 80) });
|
|
689
|
+
}
|
|
690
|
+
if (action === 'click-option') {
|
|
691
|
+
const exact = all.filter((el) => rendered(el) && ownText(el) === name);
|
|
692
|
+
if (exact.length > 0) {
|
|
693
|
+
const option = exact[exact.length - 1];
|
|
694
|
+
(option.closest('li, div, label, button') || option).click();
|
|
695
|
+
return JSON.stringify({ ok: true, how: 'text' });
|
|
696
|
+
}
|
|
697
|
+
const near = all.filter((el) => rendered(el) && ownText(el).includes(name)).map((el) => ownText(el).slice(0, 40));
|
|
698
|
+
return JSON.stringify({ ok: false, reason: 'option-absent', seen: [...new Set(near)].slice(0, 8) });
|
|
699
|
+
}
|
|
700
|
+
const state = row === undefined ? '' : String(row.textContent || '').trim().slice(0, 120);
|
|
701
|
+
return JSON.stringify({ ok: state.includes(name), text: state });
|
|
702
|
+
})()`;
|
|
703
|
+
}
|
|
704
|
+
|
|
623
705
|
/**
|
|
624
706
|
* 声明原创 entry checkbox locator, vendor scoring ported verbatim (shipinhao.js:2233-2261):
|
|
625
707
|
* 原创/original attribute evidence, an associated 原创 label, or a short 原创 ancestor text;
|
|
@@ -830,15 +912,17 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
830
912
|
private readonly operation: ShipinhaoOperationName;
|
|
831
913
|
private readonly launcher: BrowserLauncher;
|
|
832
914
|
private readonly stepTimeoutMs: number;
|
|
915
|
+
private readonly preflightTimeoutMs: number;
|
|
833
916
|
constructor(
|
|
834
917
|
operation: ShipinhaoOperationName = 'shortVideo',
|
|
835
918
|
driver: BrowserDriver = 'script',
|
|
836
|
-
deps: { launcher?: BrowserLauncher; stepTimeoutMs?: number } = {},
|
|
919
|
+
deps: { launcher?: BrowserLauncher; stepTimeoutMs?: number; preflightTimeoutMs?: number } = {},
|
|
837
920
|
) {
|
|
838
921
|
this.operation = operation;
|
|
839
922
|
this.driver = driver;
|
|
840
923
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
841
924
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
925
|
+
this.preflightTimeoutMs = deps.preflightTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
842
926
|
}
|
|
843
927
|
|
|
844
928
|
/**
|
|
@@ -902,7 +986,14 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
902
986
|
const audio = await resolveAudioPath(metadataRecord.audio ?? metadataRecord.audioFile);
|
|
903
987
|
if (audio.error !== undefined) return fail(SHP_TARGET, audio.error);
|
|
904
988
|
media = [audio.path as string];
|
|
905
|
-
|
|
989
|
+
// 封面 source ladder: an explicit coverPath, else the bundle's own cover image. WHY the
|
|
990
|
+
// fallback (2026-11-16): the publish matrix builds the payload through ContentSchema,
|
|
991
|
+
// which strips the variant's top-level `options` block, so a daily episode arrives with
|
|
992
|
+
// `metadata.coverImage` only — and the 音频 form REFUSES to submit without a 封面
|
|
993
|
+
// (「请上传封面」), which is how every earlier audio publish ended `unknown`.
|
|
994
|
+
const cover = await resolveCoverPath(
|
|
995
|
+
payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? metadataRecord.coverImage,
|
|
996
|
+
);
|
|
906
997
|
if (cover.error !== undefined) return fail(SHP_TARGET, cover.error);
|
|
907
998
|
coverPath = cover.path;
|
|
908
999
|
} else {
|
|
@@ -914,6 +1005,8 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
914
1005
|
if (tags.error !== undefined) return fail(SHP_TARGET, tags.error);
|
|
915
1006
|
const original = resolveOriginal(payload.content.metadata?.original);
|
|
916
1007
|
if (original.error !== undefined) return fail(SHP_TARGET, original.error);
|
|
1008
|
+
const collection = resolveCollection(payload.options?.collection ?? payload.content.metadata?.collection);
|
|
1009
|
+
if (collection.error !== undefined) return fail(SHP_TARGET, collection.error);
|
|
917
1010
|
const unsupported = unsupportedFields(payload, this.operation);
|
|
918
1011
|
if (unsupported.length > 0) {
|
|
919
1012
|
return fail(
|
|
@@ -930,15 +1023,24 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
930
1023
|
const session = await checkChannelSession(SHP_CONFIG, {
|
|
931
1024
|
profileDir,
|
|
932
1025
|
launcher: this.launcher,
|
|
933
|
-
|
|
934
|
-
|
|
1026
|
+
// Headless first, then one read-only headed pass (same rail as xhs-pub): shipinhao's
|
|
1027
|
+
// dashboard regularly paints past a 30-90s headless poll on a healthy session, and the
|
|
1028
|
+
// shipped probe (`profile-check check`) has always used this fallback — the publish
|
|
1029
|
+
// preflight was the only caller that disabled it, so `check` verified what `publish`
|
|
1030
|
+
// refused (2026-11-13).
|
|
1031
|
+
timeoutMs: this.preflightTimeoutMs,
|
|
935
1032
|
});
|
|
936
1033
|
if (session.status !== 'verified') {
|
|
937
1034
|
// The recovery command leads the message: `fail()` bounds the line, and the operator's
|
|
938
|
-
// next action must never be the part that gets truncated.
|
|
939
|
-
|
|
1035
|
+
// next action must never be the part that gets truncated. Effect none: no console visit
|
|
1036
|
+
// happened, so the bounded retry may resend it.
|
|
1037
|
+
return stageFail(
|
|
940
1038
|
SHP_TARGET,
|
|
941
1039
|
`${SHP_TARGET} session preflight refused — run: ${SHP_LOGIN_INSTRUCTION} — detail: ${session.detail}`,
|
|
1040
|
+
'session-preflight',
|
|
1041
|
+
{ operation: this.operation, publishStatus: 'draft' },
|
|
1042
|
+
undefined,
|
|
1043
|
+
'none',
|
|
942
1044
|
);
|
|
943
1045
|
}
|
|
944
1046
|
|
|
@@ -956,19 +1058,39 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
956
1058
|
// bounded step like every other one, not the 180s interactive login wait.
|
|
957
1059
|
timeoutMs: this.stepTimeoutMs,
|
|
958
1060
|
},
|
|
959
|
-
async ({ page }) =>
|
|
960
|
-
|
|
1061
|
+
async ({ page }) => {
|
|
1062
|
+
// 音频 has its own surface (`/platform/post/createAudio`); driving it through the
|
|
1063
|
+
// video rails is what made every audio publish end `uncertain` (2026-11-15).
|
|
1064
|
+
// shortVideo/image/music keep the flow below untouched.
|
|
1065
|
+
if (this.operation === 'audio') {
|
|
1066
|
+
return runAudioPostFlow({
|
|
1067
|
+
page,
|
|
1068
|
+
title,
|
|
1069
|
+
body,
|
|
1070
|
+
tags: tags.tags as readonly string[],
|
|
1071
|
+
media,
|
|
1072
|
+
coverPath,
|
|
1073
|
+
collection: collection.collection,
|
|
1074
|
+
publishPublic: requested === 'public',
|
|
1075
|
+
operation: this.operation,
|
|
1076
|
+
profileDir,
|
|
1077
|
+
stepTimeoutMs: this.stepTimeoutMs,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
return this.runPostFlow(
|
|
961
1081
|
page,
|
|
962
1082
|
POST_FLOW_SPECS[this.operation],
|
|
963
1083
|
title,
|
|
964
1084
|
body,
|
|
965
1085
|
tags.tags as readonly string[],
|
|
966
1086
|
original.original === true,
|
|
1087
|
+
collection.collection,
|
|
967
1088
|
media,
|
|
968
1089
|
coverPath,
|
|
969
1090
|
requested === 'public',
|
|
970
1091
|
profileDir,
|
|
971
|
-
)
|
|
1092
|
+
);
|
|
1093
|
+
},
|
|
972
1094
|
);
|
|
973
1095
|
} catch (error) {
|
|
974
1096
|
// Same ordering rule as the preflight refusal: the recovery command is never the tail
|
|
@@ -999,6 +1121,7 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
999
1121
|
body: string,
|
|
1000
1122
|
tags: readonly string[],
|
|
1001
1123
|
declareOriginal: boolean,
|
|
1124
|
+
collection: string | undefined,
|
|
1002
1125
|
media: readonly string[],
|
|
1003
1126
|
coverPath: string | undefined,
|
|
1004
1127
|
publishPublic: boolean,
|
|
@@ -1011,6 +1134,7 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
1011
1134
|
publishStatus,
|
|
1012
1135
|
profileDir,
|
|
1013
1136
|
...(declareOriginal ? { original: true } : {}),
|
|
1137
|
+
...(collection !== undefined ? { collection } : {}),
|
|
1014
1138
|
};
|
|
1015
1139
|
|
|
1016
1140
|
// Dashboard click-through: the entry button opens the unified /platform/post/create
|
|
@@ -1228,6 +1352,15 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
1228
1352
|
);
|
|
1229
1353
|
}
|
|
1230
1354
|
|
|
1355
|
+
// 合集: AUDIO only, and only when requested (2026-11-16). Ordered after the description —
|
|
1356
|
+
// the row renders with the rest of the post-upload rails on that form — and before the
|
|
1357
|
+
// declaration/cover/submit so a collection that cannot be committed refuses while nothing
|
|
1358
|
+
// has been published yet.
|
|
1359
|
+
if (collection !== undefined) {
|
|
1360
|
+
const collected = await this.selectCollectionFlow(page, mode, spec, collection, metadata);
|
|
1361
|
+
if (collected !== undefined) return collected;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1231
1364
|
// 声明原创: ONLY on the explicit operator assertion (metadata.original === true); the
|
|
1232
1365
|
// vendor's unconditional run and log-only degradation (shipinhao.js:10-14, 2270-2310) are
|
|
1233
1366
|
// deliberately not mirrored. Ordering matches the vendor: after description, before cover
|
|
@@ -1367,6 +1500,88 @@ export class ShipinhaoBrowserTransport implements PublishTransport {
|
|
|
1367
1500
|
});
|
|
1368
1501
|
}
|
|
1369
1502
|
|
|
1503
|
+
/**
|
|
1504
|
+
* 合集 selection for the AUDIO post (2026-11-16): open the row, click the option by exact text,
|
|
1505
|
+
* then require the row to read back the requested collection. Every step type-fails — a missing
|
|
1506
|
+
* row, an absent option or a click that did not commit — because the operator's requirement is
|
|
1507
|
+
* that the episode lives in that collection: publishing without it is the wrong result, not a
|
|
1508
|
+
* degraded one.
|
|
1509
|
+
*/
|
|
1510
|
+
private async selectCollectionFlow(
|
|
1511
|
+
page: Page,
|
|
1512
|
+
mode: 'wujie' | 'direct',
|
|
1513
|
+
spec: PostFlowSpec,
|
|
1514
|
+
collection: string,
|
|
1515
|
+
metadata: Record<string, unknown>,
|
|
1516
|
+
): Promise<Result | undefined> {
|
|
1517
|
+
const failCollection = (message: string, stage: string, evidence?: string): Result =>
|
|
1518
|
+
stageFail(SHP_TARGET, message, stage, metadata, evidence);
|
|
1519
|
+
const label = spec.selectors.collectionLabel;
|
|
1520
|
+
const read = (raw: string): { ok: boolean; reason?: string; text?: string; seen?: string[] } => {
|
|
1521
|
+
try {
|
|
1522
|
+
return JSON.parse(raw) as { ok: boolean; reason?: string; text?: string; seen?: string[] };
|
|
1523
|
+
} catch {
|
|
1524
|
+
return { ok: false, reason: 'unreadable-probe' };
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
const entry = read(String(await page.evaluate(collectionScript(mode, 'click-entry', label, collection))));
|
|
1528
|
+
if (!entry.ok) {
|
|
1529
|
+
return failCollection(
|
|
1530
|
+
`shipinhao 合集 (collection) row not found on the ${this.operation} form — refusing to publish outside the requested 合集 '${collection}'`,
|
|
1531
|
+
'collection-select',
|
|
1532
|
+
entry.reason,
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
const option = await expectOutcome(
|
|
1536
|
+
async () => {
|
|
1537
|
+
const picked = read(
|
|
1538
|
+
String(await page.evaluate(collectionScript(mode, 'click-option', label, collection))),
|
|
1539
|
+
);
|
|
1540
|
+
if (picked.ok) return 'option clicked';
|
|
1541
|
+
// A native `<select>` renders no clickable option node: Playwright's own selectOption
|
|
1542
|
+
// is the write path for it (no page-script value assignment — the flow never writes
|
|
1543
|
+
// `.value`). It pierces open shadow roots, and a select without that label throws, so
|
|
1544
|
+
// a missing collection stays a typed refusal.
|
|
1545
|
+
const selects = page.locator('select');
|
|
1546
|
+
const count = await selects.count();
|
|
1547
|
+
for (let i = 0; i < count; i++) {
|
|
1548
|
+
try {
|
|
1549
|
+
await selects.nth(i).selectOption({ label: collection }, { timeout: COLLECTION_PROBE_MS });
|
|
1550
|
+
return 'option selected';
|
|
1551
|
+
} catch {
|
|
1552
|
+
// Not this select — keep looking; the refusal below still fires.
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
return null;
|
|
1556
|
+
},
|
|
1557
|
+
{ timeoutMs: this.stepTimeoutMs, label: 'shipinhao 合集 option' },
|
|
1558
|
+
);
|
|
1559
|
+
if (!option.ok) {
|
|
1560
|
+
const seen = read(String(await page.evaluate(collectionScript(mode, 'click-option', label, collection))));
|
|
1561
|
+
return failCollection(
|
|
1562
|
+
`shipinhao 合集 '${collection}' is not among the collections the account offers — refusing to publish outside it`,
|
|
1563
|
+
'collection-select',
|
|
1564
|
+
`${option.error}; seen: ${(seen.seen ?? []).join(' | ')}`,
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
const commit = await expectOutcome(
|
|
1568
|
+
async () => {
|
|
1569
|
+
const state = read(String(await page.evaluate(collectionScript(mode, 'read', label, collection))));
|
|
1570
|
+
return state.ok ? 'collection read back' : null;
|
|
1571
|
+
},
|
|
1572
|
+
{ timeoutMs: this.stepTimeoutMs, label: 'shipinhao 合集 readback' },
|
|
1573
|
+
);
|
|
1574
|
+
if (!commit.ok) {
|
|
1575
|
+
const state = read(String(await page.evaluate(collectionScript(mode, 'read', label, collection))));
|
|
1576
|
+
return failCollection(
|
|
1577
|
+
`shipinhao 合集 '${collection}' was clicked but the form does not show it committed — refusing to submit`,
|
|
1578
|
+
'collection-readback',
|
|
1579
|
+
`row text: ${state.text ?? '<absent>'} — ${commit.error}`,
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
return undefined;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1370
1585
|
/**
|
|
1371
1586
|
* The requested-only 声明原创 sequence; returns a typed-failure `Result`, or `undefined` when
|
|
1372
1587
|
* the declaration committed with verified state: entry checkbox clicked and read back checked
|
|
@@ -243,6 +243,19 @@ export const SHP_VIDEO_SELECTORS = {
|
|
|
243
243
|
* on an explicit `publishStatus: 'public'`.
|
|
244
244
|
*/
|
|
245
245
|
publishButton: ['button:text-is("发表")', '[role="button"]:text-is("发表")'],
|
|
246
|
+
/**
|
|
247
|
+
* The 合集 (collection) entry on the AUDIO post form (2026-11-16, operator requirement: the daily
|
|
248
|
+
* episode belongs to 合集 `每日AI乱炖`). Matched by its own visible text, because the row ships
|
|
249
|
+
* without a stable class in the creator form; the flow then opens it and picks the option by
|
|
250
|
+
* exact text (`collectionOptionText`), never by index.
|
|
251
|
+
*
|
|
252
|
+
* Audio-only by contract: `collection` is listed in `unsupportedFields` for the other three
|
|
253
|
+
* post kinds, so 视频/图文/音乐 keep their exact current behaviour and a collection request on
|
|
254
|
+
* them is refused before a browser opens.
|
|
255
|
+
*/
|
|
256
|
+
collectionEntry: ['button:has-text("合集")', 'div:has-text("合集")', 'span:has-text("合集")'],
|
|
257
|
+
/** Label the entry row is expected to carry once a collection is committed (readback gate). */
|
|
258
|
+
collectionLabel: '合集',
|
|
246
259
|
} as const;
|
|
247
260
|
|
|
248
261
|
/** Keys of the selector map, for typed probes. */
|
|
@@ -12755,8 +12755,8 @@ function buildLocaleEntry(markdown, locale) {
|
|
|
12755
12755
|
if (!parts) {
|
|
12756
12756
|
return `${locale}: key_points must be "label \u2014 sentence"`;
|
|
12757
12757
|
}
|
|
12758
|
-
if (
|
|
12759
|
-
return `${locale}: title headlines do not match key_points labels`;
|
|
12758
|
+
if (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i])) {
|
|
12759
|
+
return `${locale}: title headlines do not match the leading key_points labels`;
|
|
12760
12760
|
}
|
|
12761
12761
|
const claims = parts.sentences;
|
|
12762
12762
|
const shortClaims = splitDescriptionParts(description, headlines.length) ?? claims;
|
|
@@ -12801,11 +12801,25 @@ async function upsertDailyTopicsEntry(mapPath, slug, entry, fileSystem = createN
|
|
|
12801
12801
|
existing = parsed;
|
|
12802
12802
|
}
|
|
12803
12803
|
}
|
|
12804
|
-
existing[slug]
|
|
12804
|
+
const prior = existing[slug];
|
|
12805
|
+
existing[slug] = prior === null || typeof prior !== "object" || Array.isArray(prior) ? entry : keepCurated(prior, entry);
|
|
12805
12806
|
await fileSystem.ensureDir(dirname3(mapPath));
|
|
12806
12807
|
await fileSystem.writeFile(mapPath, `${JSON.stringify(existing, null, "\t")}
|
|
12807
12808
|
`);
|
|
12808
12809
|
}
|
|
12810
|
+
function keepCurated(curated, derived) {
|
|
12811
|
+
const merged = { ...derived, ...curated };
|
|
12812
|
+
const isEmpty = (value) => value === undefined || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
12813
|
+
for (const [key, value] of Object.entries(derived)) {
|
|
12814
|
+
const current = curated[key];
|
|
12815
|
+
if (isEmpty(current))
|
|
12816
|
+
continue;
|
|
12817
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && !isEmpty(current)) {
|
|
12818
|
+
merged[key] = keepCurated(current, value);
|
|
12819
|
+
}
|
|
12820
|
+
}
|
|
12821
|
+
return merged;
|
|
12822
|
+
}
|
|
12809
12823
|
|
|
12810
12824
|
// ../../plugins/publishings/surfdash-pub/src/index.ts
|
|
12811
12825
|
var TARGET = "surfdash";
|
|
@@ -13008,6 +13022,32 @@ function digestCheckGate(filePath, locale) {
|
|
|
13008
13022
|
}
|
|
13009
13023
|
return `digest frontmatter check failed: ${problems.join("; ")}`;
|
|
13010
13024
|
}
|
|
13025
|
+
function localeSiblings(postPath) {
|
|
13026
|
+
const segments = postPath.split(sep2);
|
|
13027
|
+
let index = -1;
|
|
13028
|
+
for (let i = segments.length - 1;i >= 0; i--) {
|
|
13029
|
+
if (segments[i] === "zh" || segments[i] === "en" || segments[i] === "ja") {
|
|
13030
|
+
index = i;
|
|
13031
|
+
break;
|
|
13032
|
+
}
|
|
13033
|
+
}
|
|
13034
|
+
if (index < 0)
|
|
13035
|
+
return [];
|
|
13036
|
+
return PATCH_LOCALES.map((locale) => ({
|
|
13037
|
+
filePath: [...segments.slice(0, index), locale, ...segments.slice(index + 1)].join(sep2),
|
|
13038
|
+
locale
|
|
13039
|
+
}));
|
|
13040
|
+
}
|
|
13041
|
+
function digestCheckLocaleSet(postPath) {
|
|
13042
|
+
for (const { filePath, locale } of localeSiblings(postPath)) {
|
|
13043
|
+
if (!existsSync2(filePath))
|
|
13044
|
+
continue;
|
|
13045
|
+
const problem = digestCheckGate(filePath, locale);
|
|
13046
|
+
if (problem)
|
|
13047
|
+
return `${locale}: ${problem}`;
|
|
13048
|
+
}
|
|
13049
|
+
return;
|
|
13050
|
+
}
|
|
13011
13051
|
function parsePorcelainPaths(stdout) {
|
|
13012
13052
|
return stdout.split(`
|
|
13013
13053
|
`).map((line) => line.trimEnd()).filter((line) => line.length > 3).map((line) => {
|
|
@@ -13091,7 +13131,9 @@ async function runDailyTopicsSync(surfdashRoot, zhPostPath) {
|
|
|
13091
13131
|
}
|
|
13092
13132
|
var SITE_GATE_COMMANDS = [
|
|
13093
13133
|
["bun", "run", "sd", "check", "digest"],
|
|
13094
|
-
["bun", "run", "check:content"]
|
|
13134
|
+
["bun", "run", "check:content"],
|
|
13135
|
+
["bun", "run", "check:body"],
|
|
13136
|
+
["bun", "run", "check:seo"]
|
|
13095
13137
|
];
|
|
13096
13138
|
function extractFailingPostHint(text) {
|
|
13097
13139
|
const match = text.match(/(?:content[\\/])?posts[\\/][^\s:)]+/);
|
|
@@ -13353,9 +13395,8 @@ async function syncPost(options) {
|
|
|
13353
13395
|
if (spawned.exitCode !== 0) {
|
|
13354
13396
|
return fail(`publish-orchestrator sync failed (exit ${spawned.exitCode}): ${withEmdashTokenHint(cliErrorText(spawned))}`);
|
|
13355
13397
|
}
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
const digestProblem = digestCheckGate(postPath.postPath, localeInPath[1]);
|
|
13398
|
+
if (/[\\/]content[\\/]posts[\\/]articles[\\/](?:zh|en|ja)[\\/]/.test(postPath.postPath)) {
|
|
13399
|
+
const digestProblem = digestCheckLocaleSet(postPath.postPath);
|
|
13359
13400
|
if (digestProblem)
|
|
13360
13401
|
return fail(digestProblem);
|
|
13361
13402
|
}
|
|
@@ -13694,7 +13735,7 @@ async function publishPreparedFile(prepared, identity) {
|
|
|
13694
13735
|
const notRefined = requireRefined(filePath);
|
|
13695
13736
|
if (notRefined)
|
|
13696
13737
|
return failUncertain(notRefined);
|
|
13697
|
-
const digestProblem =
|
|
13738
|
+
const digestProblem = digestCheckLocaleSet(filePath);
|
|
13698
13739
|
if (digestProblem)
|
|
13699
13740
|
return failUncertain(digestProblem);
|
|
13700
13741
|
const refined = readRefinedSnapshot(filePath);
|
|
@@ -13883,6 +13924,7 @@ export {
|
|
|
13883
13924
|
commitPostPaths,
|
|
13884
13925
|
contentTags,
|
|
13885
13926
|
digestCheckGate,
|
|
13927
|
+
digestCheckLocaleSet,
|
|
13886
13928
|
extractFailingPostHint,
|
|
13887
13929
|
fastForwardToOrigin,
|
|
13888
13930
|
getPublishTransport,
|
|
@@ -434,6 +434,46 @@ export function digestCheckGate(filePath: string, locale: DigestLocale): string
|
|
|
434
434
|
return `digest frontmatter check failed: ${problems.join('; ')}`;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Every locale file of one post that exists on disk, in `PATCH_LOCALES` order.
|
|
439
|
+
* The locale is the last `zh`/`en`/`ja` directory in the path; no such segment → []
|
|
440
|
+
* (a path outside the locale tree has no set to check).
|
|
441
|
+
*/
|
|
442
|
+
function localeSiblings(postPath: string): Array<{ filePath: string; locale: DigestLocale }> {
|
|
443
|
+
const segments = postPath.split(sep);
|
|
444
|
+
let index = -1;
|
|
445
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
446
|
+
if (segments[i] === 'zh' || segments[i] === 'en' || segments[i] === 'ja') {
|
|
447
|
+
index = i;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (index < 0) return [];
|
|
452
|
+
return PATCH_LOCALES.map((locale) => ({
|
|
453
|
+
filePath: [...segments.slice(0, index), locale, ...segments.slice(index + 1)].join(sep),
|
|
454
|
+
locale,
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Digest gate over the whole locale set instead of the primary file alone (2026-11-16, GH #191).
|
|
460
|
+
*
|
|
461
|
+
* An untranslated sibling — the zh title, description and key points sitting under `/en/` or `/ja/`
|
|
462
|
+
* — passes a zh-only check here and then fails the site's check-digest three ways: the locale's own
|
|
463
|
+
* series name, the body language, and the regenerated-frontmatter drift. `sync` hands all three
|
|
464
|
+
* locales to the CMS and a prepared publish commits all three, so every existing file is checked.
|
|
465
|
+
* Missing files stay skipped (the pre-translation `prepare` path has no siblings yet), and
|
|
466
|
+
* `SURFDASH_DIGEST_CHECK` keeps governing the gate itself.
|
|
467
|
+
*/
|
|
468
|
+
export function digestCheckLocaleSet(postPath: string): string | undefined {
|
|
469
|
+
for (const { filePath, locale } of localeSiblings(postPath)) {
|
|
470
|
+
if (!existsSync(filePath)) continue;
|
|
471
|
+
const problem = digestCheckGate(filePath, locale);
|
|
472
|
+
if (problem) return `${locale}: ${problem}`;
|
|
473
|
+
}
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
|
|
437
477
|
/**
|
|
438
478
|
* Helper to parse file paths from `git status --porcelain` output.
|
|
439
479
|
*/
|
|
@@ -560,10 +600,20 @@ export async function runDailyTopicsSync(surfdashRoot: string, zhPostPath: strin
|
|
|
560
600
|
/** Outcome of {@link runSiteGate}. */
|
|
561
601
|
export type SiteGateOutcome = { ok: true } | { ok: false; error: string };
|
|
562
602
|
|
|
563
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* Commands executed by the surfdash site gate before commit and push to main.
|
|
605
|
+
*
|
|
606
|
+
* This list must stay equal to the content suite surfdash's own deploy gate runs
|
|
607
|
+
* (`bun run check:all` = check:content + check:body + check:seo) plus the digest reporter.
|
|
608
|
+
* It used to stop at `check:content`, so a body-rule violation or a localized cover asset that
|
|
609
|
+
* `check:seo` reports as `image-asset-missing` passed here and failed the site's CI right after
|
|
610
|
+
* the push (GH #191, `docs(articles): add more articles`, 2026-11-15).
|
|
611
|
+
*/
|
|
564
612
|
const SITE_GATE_COMMANDS: readonly (readonly string[])[] = [
|
|
565
613
|
['bun', 'run', 'sd', 'check', 'digest'],
|
|
566
614
|
['bun', 'run', 'check:content'],
|
|
615
|
+
['bun', 'run', 'check:body'],
|
|
616
|
+
['bun', 'run', 'check:seo'],
|
|
567
617
|
];
|
|
568
618
|
|
|
569
619
|
/**
|
|
@@ -932,11 +982,11 @@ async function syncPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
932
982
|
`publish-orchestrator sync failed (exit ${spawned.exitCode}): ${withEmdashTokenHint(cliErrorText(spawned))}`,
|
|
933
983
|
);
|
|
934
984
|
}
|
|
935
|
-
// Digest contract (2026-10-24):
|
|
936
|
-
//
|
|
937
|
-
|
|
938
|
-
if (
|
|
939
|
-
const digestProblem =
|
|
985
|
+
// Digest contract (2026-10-24; locale set 2026-11-16): the orchestrator syncs all three
|
|
986
|
+
// locale files to the CMS, so verify the synced post AND its siblings. Paths outside
|
|
987
|
+
// content/posts/articles/<zh|en|ja>/ carry no digest series to check.
|
|
988
|
+
if (/[\\/]content[\\/]posts[\\/]articles[\\/](?:zh|en|ja)[\\/]/.test(postPath.postPath)) {
|
|
989
|
+
const digestProblem = digestCheckLocaleSet(postPath.postPath);
|
|
940
990
|
if (digestProblem) return fail(digestProblem);
|
|
941
991
|
}
|
|
942
992
|
return ResultSchema.parse({
|
|
@@ -1389,8 +1439,9 @@ async function publishPreparedFile(
|
|
|
1389
1439
|
// Contract check (ADR-008): the site, not this plugin, owns SEO metadata.
|
|
1390
1440
|
const notRefined = requireRefined(filePath);
|
|
1391
1441
|
if (notRefined) return failUncertain(notRefined);
|
|
1392
|
-
// Digest contract (2026-10-24): the refined values themselves must
|
|
1393
|
-
|
|
1442
|
+
// Digest contract (2026-10-24; locale set 2026-11-16): the refined values themselves must
|
|
1443
|
+
// hold for every locale this publish commits, before any push.
|
|
1444
|
+
const digestProblem = digestCheckLocaleSet(filePath);
|
|
1394
1445
|
if (digestProblem) return failUncertain(digestProblem);
|
|
1395
1446
|
const refined = readRefinedSnapshot(filePath);
|
|
1396
1447
|
|
|
@@ -120,8 +120,12 @@ function buildLocaleEntry(markdown: string, locale: PatchLocale): DailyTopicsLoc
|
|
|
120
120
|
if (!parts) {
|
|
121
121
|
return `${locale}: key_points must be "label — sentence"`;
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
// The title names the TOP stories; the key-point box carries up to four. The site's own
|
|
124
|
+
// generator emits exactly that shape (`scripts/commands/seo/retitle.ts`: title = "top story 1,
|
|
125
|
+
// story 2", key_points = up to four bullets), so demanding a one-to-one match made every
|
|
126
|
+
// crefitable digest fail the sync. The title must be the leading labels, in order.
|
|
127
|
+
if (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i])) {
|
|
128
|
+
return `${locale}: title headlines do not match the leading key_points labels`;
|
|
125
129
|
}
|
|
126
130
|
const claims = parts.sentences;
|
|
127
131
|
const shortClaims = splitDescriptionParts(description, headlines.length) ?? claims;
|
|
@@ -183,7 +187,34 @@ export async function upsertDailyTopicsEntry(
|
|
|
183
187
|
existing = parsed as Record<string, unknown>;
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
|
-
|
|
190
|
+
// A curated entry WINS. The site's runbook (docs/runbook-seo-geo-operations.md §10) sanctions
|
|
191
|
+
// editing a slug's claims/short_claims by hand, and re-deriving them from the posts on every
|
|
192
|
+
// publish silently reverted that fix (2026-11-16: a curated 20261116 entry was replaced, retitle
|
|
193
|
+
// then re-broke the descriptions, and the gate failed again on the next attempt). Derivation only
|
|
194
|
+
// fills what the map does not already state.
|
|
195
|
+
const prior = existing[slug];
|
|
196
|
+
existing[slug] =
|
|
197
|
+
prior === null || typeof prior !== 'object' || Array.isArray(prior)
|
|
198
|
+
? entry
|
|
199
|
+
: keepCurated(prior as Record<string, unknown>, entry as unknown as Record<string, unknown>);
|
|
187
200
|
await fileSystem.ensureDir(dirname(mapPath));
|
|
188
201
|
await fileSystem.writeFile(mapPath, `${JSON.stringify(existing, null, '\t')}\n`);
|
|
189
202
|
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Merges a derived entry under an existing one, keeping every non-empty curated value and taking the
|
|
206
|
+
* derived value only where the map states nothing (a missing locale, a new field).
|
|
207
|
+
*/
|
|
208
|
+
function keepCurated(curated: Record<string, unknown>, derived: Record<string, unknown>): Record<string, unknown> {
|
|
209
|
+
const merged: Record<string, unknown> = { ...derived, ...curated };
|
|
210
|
+
const isEmpty = (value: unknown): boolean =>
|
|
211
|
+
value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0);
|
|
212
|
+
for (const [key, value] of Object.entries(derived)) {
|
|
213
|
+
const current = curated[key];
|
|
214
|
+
if (isEmpty(current)) continue;
|
|
215
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value) && !isEmpty(current)) {
|
|
216
|
+
merged[key] = keepCurated(current as Record<string, unknown>, value as Record<string, unknown>);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return merged;
|
|
220
|
+
}
|