@gobing-ai/knowledge-kit 0.1.25 → 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 +115 -21
- package/package.json +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +416 -134
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +33 -2
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/index.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/csdn-pub/dist/index.js +33 -2
- package/plugins/publishings/csdn-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/infoq-pub/dist/index.js +33 -2
- package/plugins/publishings/infoq-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/jike-pub/dist/index.js +33 -2
- package/plugins/publishings/jike-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/juejin-pub/dist/index.js +33 -2
- package/plugins/publishings/juejin-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +84 -13
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +50 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +33 -2
- package/plugins/publishings/medium-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/index.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/sspai-pub/dist/index.js +33 -2
- package/plugins/publishings/sspai-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/substack-pub/dist/index.js +33 -2
- package/plugins/publishings/substack-pub/dist/profile-check.js +33 -2
- 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 +33 -2
- package/plugins/publishings/threads-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +65 -3
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +67 -3
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +56 -8
- package/plugins/publishings/weibo-pub/dist/profile-check.js +55 -8
- 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 +33 -2
- package/plugins/publishings/x-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xhs-pub/dist/index.js +33 -2
- package/plugins/publishings/xhs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +33 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +33 -2
|
@@ -12400,8 +12400,10 @@ async function patchPostFiles(request) {
|
|
|
12400
12400
|
const written = [];
|
|
12401
12401
|
const absent = [];
|
|
12402
12402
|
const images = {};
|
|
12403
|
+
const coverSkipped = [];
|
|
12403
12404
|
let changed = 0;
|
|
12404
12405
|
let uploadedFallbackCover;
|
|
12406
|
+
let uploadError;
|
|
12405
12407
|
for (const locale of PATCH_LOCALES) {
|
|
12406
12408
|
const indexMd = localeIndexPath(request.postPath, locale);
|
|
12407
12409
|
if (indexMd === undefined || !await fs.exists(indexMd)) {
|
|
@@ -12424,18 +12426,29 @@ async function patchPostFiles(request) {
|
|
|
12424
12426
|
md = upsertFrontmatterKey(md, "og_image", existingImage);
|
|
12425
12427
|
images[locale] = existingImage;
|
|
12426
12428
|
} else if (request.uploadLocalCover !== undefined && request.localCover !== "" && await fs.exists(request.localCover)) {
|
|
12427
|
-
if (uploadedFallbackCover === undefined) {
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
|
|
12429
|
+
if (uploadedFallbackCover === undefined && uploadError === undefined) {
|
|
12430
|
+
let uploaded;
|
|
12431
|
+
try {
|
|
12432
|
+
uploaded = await request.uploadLocalCover(request.localCover);
|
|
12433
|
+
} catch (error) {
|
|
12434
|
+
uploadError = error instanceof Error ? error.message : String(error);
|
|
12431
12435
|
}
|
|
12432
|
-
|
|
12436
|
+
if (uploaded !== undefined) {
|
|
12437
|
+
if (!/^https:\/\//.test(uploaded)) {
|
|
12438
|
+
throw new Error(`uploaded cover must be an absolute https:// URL, got: ${uploaded}`);
|
|
12439
|
+
}
|
|
12440
|
+
uploadedFallbackCover = uploaded;
|
|
12441
|
+
}
|
|
12442
|
+
}
|
|
12443
|
+
if (uploadedFallbackCover === undefined) {
|
|
12444
|
+
coverSkipped.push(locale);
|
|
12445
|
+
} else {
|
|
12446
|
+
md = upsertFrontmatterKey(md, "image", uploadedFallbackCover);
|
|
12447
|
+
md = upsertFrontmatterKey(md, "og_image", uploadedFallbackCover);
|
|
12448
|
+
images[locale] = uploadedFallbackCover;
|
|
12433
12449
|
}
|
|
12434
|
-
md = upsertFrontmatterKey(md, "image", uploadedFallbackCover);
|
|
12435
|
-
md = upsertFrontmatterKey(md, "og_image", uploadedFallbackCover);
|
|
12436
|
-
images[locale] = uploadedFallbackCover;
|
|
12437
12450
|
} else {
|
|
12438
|
-
|
|
12451
|
+
coverSkipped.push(locale);
|
|
12439
12452
|
}
|
|
12440
12453
|
if (locale === "zh" && (request.episodeTitle ?? "") !== "") {
|
|
12441
12454
|
md = upsertFrontmatterKey(md, "episode_title", request.episodeTitle);
|
|
@@ -12461,7 +12474,22 @@ ${link}
|
|
|
12461
12474
|
changed += 1;
|
|
12462
12475
|
}
|
|
12463
12476
|
}
|
|
12464
|
-
|
|
12477
|
+
const applied = PATCH_LOCALES.filter((locale) => images[locale] !== undefined);
|
|
12478
|
+
return {
|
|
12479
|
+
written,
|
|
12480
|
+
changed,
|
|
12481
|
+
absent,
|
|
12482
|
+
images,
|
|
12483
|
+
slug: basename(dirname2(request.postPath)),
|
|
12484
|
+
coverPatch: {
|
|
12485
|
+
status: coverSkipped.length === 0 ? "applied" : "skipped",
|
|
12486
|
+
applied,
|
|
12487
|
+
skipped: coverSkipped,
|
|
12488
|
+
reason: coverSkipped.length === 0 ? "" : `${coverSkipped.join("/")} post has no remote https:// cover: coverUrl is empty, the frontmatter has no https:// image key and no local cover was uploadable${uploadError === undefined ? "" : ` (local cover upload failed: ${uploadError})`}`,
|
|
12489
|
+
...uploadError === undefined ? {} : { uploadError },
|
|
12490
|
+
pageUrl: request.pageUrl ?? ""
|
|
12491
|
+
}
|
|
12492
|
+
};
|
|
12465
12493
|
}
|
|
12466
12494
|
|
|
12467
12495
|
// ../../plugins/publishings/surfdash-pub/src/digest-check.ts
|
|
@@ -13545,6 +13573,7 @@ async function patchPost(options) {
|
|
|
13545
13573
|
localCover: strOption(options, "localCover"),
|
|
13546
13574
|
dateIso: strOption(options, "dateIso"),
|
|
13547
13575
|
episodeTitle: strOption(options, "episodeTitle"),
|
|
13576
|
+
pageUrl: strOption(options, "pageUrl"),
|
|
13548
13577
|
uploadLocalCover: uploadCoverToMicrofeed
|
|
13549
13578
|
});
|
|
13550
13579
|
} catch (error) {
|
|
@@ -13552,6 +13581,9 @@ async function patchPost(options) {
|
|
|
13552
13581
|
}
|
|
13553
13582
|
if (outcome.changed === 0)
|
|
13554
13583
|
echoError(`patch: no post bytes changed for ${outcome.slug}`);
|
|
13584
|
+
if (outcome.coverPatch.status === "skipped") {
|
|
13585
|
+
echoError(`patch: cover patch skipped for ${outcome.slug} \u2014 ${outcome.coverPatch.reason} (page ${outcome.coverPatch.pageUrl === "" ? "unknown" : outcome.coverPatch.pageUrl})`);
|
|
13586
|
+
}
|
|
13555
13587
|
const synced = await syncPost({ postPath: postPath.postPath });
|
|
13556
13588
|
const commitPaths = new Set(outcome.written.map((path) => relative(surfdashRoot, path)));
|
|
13557
13589
|
if (process.env.SURFDASH_AUTO_PUSH !== "0") {
|
|
@@ -13571,7 +13603,8 @@ async function patchPost(options) {
|
|
|
13571
13603
|
locales: Object.keys(outcome.images),
|
|
13572
13604
|
absentLocales: outcome.absent,
|
|
13573
13605
|
cmsResync: synced.ok ? "ok" : "failed",
|
|
13574
|
-
gitCommit: commit.hash
|
|
13606
|
+
gitCommit: commit.hash,
|
|
13607
|
+
coverPatch: outcome.coverPatch
|
|
13575
13608
|
};
|
|
13576
13609
|
if (!synced.ok) {
|
|
13577
13610
|
return ResultSchema.parse({
|
|
@@ -13584,7 +13617,7 @@ async function patchPost(options) {
|
|
|
13584
13617
|
return ResultSchema.parse({
|
|
13585
13618
|
ok: true,
|
|
13586
13619
|
target: TARGET,
|
|
13587
|
-
message: `patched ${outcome.changed} post(s) for ${outcome.slug}`,
|
|
13620
|
+
message: outcome.coverPatch.status === "skipped" ? `patched ${outcome.changed} post(s) for ${outcome.slug}; cover patch skipped \u2014 ${outcome.coverPatch.reason}` : `patched ${outcome.changed} post(s) for ${outcome.slug}`,
|
|
13588
13621
|
metadata
|
|
13589
13622
|
});
|
|
13590
13623
|
}
|
|
@@ -13858,7 +13891,8 @@ async function preparePost(payload) {
|
|
|
13858
13891
|
filePath,
|
|
13859
13892
|
relPostDir: join("content", "posts", "articles", locale, slug),
|
|
13860
13893
|
relPostDirs: mintedDirs,
|
|
13861
|
-
articleUrl
|
|
13894
|
+
articleUrl,
|
|
13895
|
+
...coverUrl !== undefined ? { coverUrl } : {}
|
|
13862
13896
|
}
|
|
13863
13897
|
};
|
|
13864
13898
|
}
|
|
@@ -13874,13 +13908,15 @@ async function preparePostResult(payload) {
|
|
|
13874
13908
|
postPath: outcome.prepared.filePath,
|
|
13875
13909
|
articleUrl: outcome.prepared.articleUrl,
|
|
13876
13910
|
dateStamp: outcome.prepared.dateStamp,
|
|
13877
|
-
slug: outcome.prepared.slug
|
|
13911
|
+
slug: outcome.prepared.slug,
|
|
13912
|
+
...outcome.prepared.coverUrl !== undefined ? { coverUrl: outcome.prepared.coverUrl } : {}
|
|
13878
13913
|
}
|
|
13879
13914
|
});
|
|
13880
13915
|
}
|
|
13881
13916
|
async function publishPreparedFile(prepared, identity) {
|
|
13882
13917
|
const postsurfingBin = process.env.POSTSURFING_BIN ?? "postsurfing";
|
|
13883
|
-
const { surfdashRoot, locale, dateStamp, filePath, relPostDir, relPostDirs, articleUrl } = prepared;
|
|
13918
|
+
const { surfdashRoot, locale, dateStamp, filePath, relPostDir, relPostDirs, articleUrl, coverUrl } = prepared;
|
|
13919
|
+
const coverMetadata = coverUrl === undefined ? {} : { coverUrl };
|
|
13884
13920
|
const identityMetadata = identity ? {
|
|
13885
13921
|
runDate: identity.runDate,
|
|
13886
13922
|
localeFingerprint: identity.fingerprint,
|
|
@@ -13915,6 +13951,7 @@ async function publishPreparedFile(prepared, identity) {
|
|
|
13915
13951
|
metadata: {
|
|
13916
13952
|
postPath: filePath,
|
|
13917
13953
|
...identityMetadata,
|
|
13954
|
+
...coverMetadata,
|
|
13918
13955
|
refinedTitle: refined?.title,
|
|
13919
13956
|
refinedCanonical: refined?.canonical
|
|
13920
13957
|
}
|
|
@@ -13938,6 +13975,7 @@ async function publishPreparedFile(prepared, identity) {
|
|
|
13938
13975
|
metadata: {
|
|
13939
13976
|
postPath: filePath,
|
|
13940
13977
|
...identityMetadata,
|
|
13978
|
+
...coverMetadata,
|
|
13941
13979
|
gitCommit: pushed.hash,
|
|
13942
13980
|
live,
|
|
13943
13981
|
refinedTitle: refined?.title
|
|
@@ -85,6 +85,8 @@ interface SurfdashPubOptions {
|
|
|
85
85
|
dateIso?: unknown;
|
|
86
86
|
/** `patch`: the episode's frozen identity title (0385 R4); the zh post's `episode_title`. */
|
|
87
87
|
episodeTitle?: unknown;
|
|
88
|
+
/** `patch`: the live page URL, named in the cover-skip warning (0432 R2). */
|
|
89
|
+
pageUrl?: unknown;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
/**
|
|
@@ -1010,10 +1012,10 @@ async function syncPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1010
1012
|
}
|
|
1011
1013
|
}
|
|
1012
1014
|
|
|
1013
|
-
/** `options.<key>` when it is a string, trimmed; else ''. `patch`'s
|
|
1015
|
+
/** `options.<key>` when it is a string, trimmed; else ''. `patch`'s optional fields read this way. */
|
|
1014
1016
|
function strOption(
|
|
1015
1017
|
options: SurfdashPubOptions,
|
|
1016
|
-
key: 'coverUrl' | 'showNotesUrl' | 'localCover' | 'dateIso' | 'episodeTitle',
|
|
1018
|
+
key: 'coverUrl' | 'showNotesUrl' | 'localCover' | 'dateIso' | 'episodeTitle' | 'pageUrl',
|
|
1017
1019
|
): string {
|
|
1018
1020
|
const raw = options[key];
|
|
1019
1021
|
return typeof raw === 'string' ? raw.trim() : '';
|
|
@@ -1050,12 +1052,20 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1050
1052
|
localCover: strOption(options, 'localCover'),
|
|
1051
1053
|
dateIso: strOption(options, 'dateIso'),
|
|
1052
1054
|
episodeTitle: strOption(options, 'episodeTitle'),
|
|
1055
|
+
pageUrl: strOption(options, 'pageUrl'),
|
|
1053
1056
|
uploadLocalCover: uploadCoverToMicrofeed,
|
|
1054
1057
|
});
|
|
1055
1058
|
} catch (error: unknown) {
|
|
1056
1059
|
return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1057
1060
|
}
|
|
1058
1061
|
if (outcome.changed === 0) echoError(`patch: no post bytes changed for ${outcome.slug}`);
|
|
1062
|
+
if (outcome.coverPatch.status === 'skipped') {
|
|
1063
|
+
// 0432 R2: a live page whose cover could not be sourced is a warning with its URL, never a
|
|
1064
|
+
// failed target — the CMS row still serves the og:image this patch wanted to write.
|
|
1065
|
+
echoError(
|
|
1066
|
+
`patch: cover patch skipped for ${outcome.slug} — ${outcome.coverPatch.reason} (page ${outcome.coverPatch.pageUrl === '' ? 'unknown' : outcome.coverPatch.pageUrl})`,
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1059
1069
|
const synced = await syncPost({ postPath: postPath.postPath });
|
|
1060
1070
|
const commitPaths = new Set(outcome.written.map((path) => relative(surfdashRoot, path)));
|
|
1061
1071
|
if (process.env.SURFDASH_AUTO_PUSH !== '0') {
|
|
@@ -1078,6 +1088,7 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1078
1088
|
absentLocales: outcome.absent,
|
|
1079
1089
|
cmsResync: synced.ok ? 'ok' : 'failed',
|
|
1080
1090
|
gitCommit: commit.hash,
|
|
1091
|
+
coverPatch: outcome.coverPatch,
|
|
1081
1092
|
};
|
|
1082
1093
|
if (!synced.ok) {
|
|
1083
1094
|
// The posts are patched and committed; only the CMS rows keep the unservable cover. Reported
|
|
@@ -1093,7 +1104,10 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1093
1104
|
return ResultSchema.parse({
|
|
1094
1105
|
ok: true,
|
|
1095
1106
|
target: TARGET,
|
|
1096
|
-
message:
|
|
1107
|
+
message:
|
|
1108
|
+
outcome.coverPatch.status === 'skipped'
|
|
1109
|
+
? `patched ${outcome.changed} post(s) for ${outcome.slug}; cover patch skipped — ${outcome.coverPatch.reason}`
|
|
1110
|
+
: `patched ${outcome.changed} post(s) for ${outcome.slug}`,
|
|
1097
1111
|
metadata,
|
|
1098
1112
|
});
|
|
1099
1113
|
}
|
|
@@ -1108,6 +1122,12 @@ interface PreparedPost {
|
|
|
1108
1122
|
/** Prepared daily publishes carry all translated sibling directories into the deploy commit. */
|
|
1109
1123
|
relPostDirs?: string[];
|
|
1110
1124
|
articleUrl: string;
|
|
1125
|
+
/**
|
|
1126
|
+
* The `https://` cover this prepare uploaded for the post (0432 R1). Reported in the publish
|
|
1127
|
+
* result so the post-publish patch can heal `image`/`og_image` from the SURFDASH side when the
|
|
1128
|
+
* podcast row never ran — that row used to be the run's only known cover source.
|
|
1129
|
+
*/
|
|
1130
|
+
coverUrl?: string;
|
|
1111
1131
|
}
|
|
1112
1132
|
|
|
1113
1133
|
interface PreparedLocaleIdentity {
|
|
@@ -1484,6 +1504,7 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1484
1504
|
relPostDir: join('content', 'posts', 'articles', locale, slug),
|
|
1485
1505
|
relPostDirs: mintedDirs,
|
|
1486
1506
|
articleUrl,
|
|
1507
|
+
...(coverUrl !== undefined ? { coverUrl } : {}),
|
|
1487
1508
|
},
|
|
1488
1509
|
};
|
|
1489
1510
|
}
|
|
@@ -1501,6 +1522,7 @@ async function preparePostResult(payload: PublishTransportPayload): Promise<Resu
|
|
|
1501
1522
|
articleUrl: outcome.prepared.articleUrl,
|
|
1502
1523
|
dateStamp: outcome.prepared.dateStamp,
|
|
1503
1524
|
slug: outcome.prepared.slug,
|
|
1525
|
+
...(outcome.prepared.coverUrl !== undefined ? { coverUrl: outcome.prepared.coverUrl } : {}),
|
|
1504
1526
|
},
|
|
1505
1527
|
});
|
|
1506
1528
|
}
|
|
@@ -1511,7 +1533,10 @@ async function publishPreparedFile(
|
|
|
1511
1533
|
identity?: Pick<PreparedLocaleIdentity, 'runDate' | 'fingerprint'> & { postSha256?: string },
|
|
1512
1534
|
): Promise<Result> {
|
|
1513
1535
|
const postsurfingBin = process.env.POSTSURFING_BIN ?? 'postsurfing';
|
|
1514
|
-
const { surfdashRoot, locale, dateStamp, filePath, relPostDir, relPostDirs, articleUrl } = prepared;
|
|
1536
|
+
const { surfdashRoot, locale, dateStamp, filePath, relPostDir, relPostDirs, articleUrl, coverUrl } = prepared;
|
|
1537
|
+
// 0432 R1: the cover this publish hosted is what the patch heals from when the podcast row is
|
|
1538
|
+
// held, so it travels with the receipt instead of being re-derived (and lost) downstream.
|
|
1539
|
+
const coverMetadata = coverUrl === undefined ? {} : { coverUrl };
|
|
1515
1540
|
const identityMetadata = identity
|
|
1516
1541
|
? {
|
|
1517
1542
|
runDate: identity.runDate,
|
|
@@ -1571,6 +1596,7 @@ async function publishPreparedFile(
|
|
|
1571
1596
|
metadata: {
|
|
1572
1597
|
postPath: filePath,
|
|
1573
1598
|
...identityMetadata,
|
|
1599
|
+
...coverMetadata,
|
|
1574
1600
|
refinedTitle: refined?.title,
|
|
1575
1601
|
refinedCanonical: refined?.canonical,
|
|
1576
1602
|
},
|
|
@@ -1601,6 +1627,7 @@ async function publishPreparedFile(
|
|
|
1601
1627
|
metadata: {
|
|
1602
1628
|
postPath: filePath,
|
|
1603
1629
|
...identityMetadata,
|
|
1630
|
+
...coverMetadata,
|
|
1604
1631
|
gitCommit: pushed.hash,
|
|
1605
1632
|
live,
|
|
1606
1633
|
refinedTitle: refined?.title,
|
|
@@ -39,6 +39,36 @@ export interface PatchPostRequest {
|
|
|
39
39
|
episodeTitle?: string;
|
|
40
40
|
/** Optional uploader converting a local cover into an `https://` remote URL (e.g. Microfeed R2). */
|
|
41
41
|
uploadLocalCover?: (filePath: string) => Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* The live page these posts serve (0432), named in the cover-skip diagnostic so an operator can
|
|
44
|
+
* check the page instead of hunting the slug. Optional: a caller that does not know it (a
|
|
45
|
+
* fixture, an offline replay) records an empty one rather than inventing a URL.
|
|
46
|
+
*/
|
|
47
|
+
pageUrl?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The remote-cover verdict of one patch pass (0432).
|
|
52
|
+
*
|
|
53
|
+
* A post whose cover cannot be sourced is NOT a failure: the page is already live and its og:image
|
|
54
|
+
* resolves from the CMS row, so the patch only lacks a URL to write into `image`/`og_image`. It
|
|
55
|
+
* records `skipped` with the reason and the page URL instead of throwing — a live, correct page was
|
|
56
|
+
* being reported as a failed target (2026-11-24 dogfood) because the only https cover the run knew
|
|
57
|
+
* about was the one `podcast-pub` hosts, and that row was held by the safety verdict.
|
|
58
|
+
*/
|
|
59
|
+
export interface CoverPatchOutcome {
|
|
60
|
+
/** `applied` when every locale that has a post carries a remote cover; `skipped` otherwise. */
|
|
61
|
+
status: 'applied' | 'skipped';
|
|
62
|
+
/** Locales whose post carries a remote https cover after this pass (written or kept). */
|
|
63
|
+
applied: PatchLocale[];
|
|
64
|
+
/** Locales left on their local/relative image because no https source existed. */
|
|
65
|
+
skipped: PatchLocale[];
|
|
66
|
+
/** Operator-facing reason naming the skipped locales; '' when nothing was skipped. */
|
|
67
|
+
reason: string;
|
|
68
|
+
/** The published page the skip concerns (`request.pageUrl`); '' when the caller supplied none. */
|
|
69
|
+
pageUrl: string;
|
|
70
|
+
/** Why the local-cover upload produced no URL (env/presign/network), absent when it was never tried. */
|
|
71
|
+
uploadError?: string;
|
|
42
72
|
}
|
|
43
73
|
|
|
44
74
|
/** What the file pass changed; the caller commits exactly {@link PatchPostOutcome.written}. */
|
|
@@ -53,6 +83,8 @@ export interface PatchPostOutcome {
|
|
|
53
83
|
images: Record<string, string>;
|
|
54
84
|
/** The primary post's directory name, for the commit message. */
|
|
55
85
|
slug: string;
|
|
86
|
+
/** What happened to the remote cover this pass (0432); never a fatal outcome by itself. */
|
|
87
|
+
coverPatch: CoverPatchOutcome;
|
|
56
88
|
}
|
|
57
89
|
|
|
58
90
|
/**
|
|
@@ -130,8 +162,13 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
130
162
|
const written: string[] = [];
|
|
131
163
|
const absent: PatchLocale[] = [];
|
|
132
164
|
const images: Record<string, string> = {};
|
|
165
|
+
const coverSkipped: PatchLocale[] = [];
|
|
133
166
|
let changed = 0;
|
|
134
167
|
let uploadedFallbackCover: string | undefined;
|
|
168
|
+
// 0432 R2/P3: the local upload is an environment step (base URL, key, presign, network). Its
|
|
169
|
+
// failure leaves no sourceable cover, which is the recorded warning below — never a failed
|
|
170
|
+
// target on a page that is already live.
|
|
171
|
+
let uploadError: string | undefined;
|
|
135
172
|
for (const locale of PATCH_LOCALES) {
|
|
136
173
|
const indexMd = localeIndexPath(request.postPath, locale);
|
|
137
174
|
if (indexMd === undefined || !(await fs.exists(indexMd))) {
|
|
@@ -160,20 +197,34 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
160
197
|
request.localCover !== '' &&
|
|
161
198
|
(await fs.exists(request.localCover))
|
|
162
199
|
) {
|
|
163
|
-
if (uploadedFallbackCover === undefined) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
200
|
+
if (uploadedFallbackCover === undefined && uploadError === undefined) {
|
|
201
|
+
let uploaded: string | undefined;
|
|
202
|
+
try {
|
|
203
|
+
uploaded = await request.uploadLocalCover(request.localCover);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
uploadError = error instanceof Error ? error.message : String(error);
|
|
206
|
+
}
|
|
207
|
+
if (uploaded !== undefined) {
|
|
208
|
+
// A non-https RESULT is an argument defect, not an environment failure: it stays loud.
|
|
209
|
+
if (!/^https:\/\//.test(uploaded)) {
|
|
210
|
+
throw new Error(`uploaded cover must be an absolute https:// URL, got: ${uploaded}`);
|
|
211
|
+
}
|
|
212
|
+
uploadedFallbackCover = uploaded;
|
|
167
213
|
}
|
|
168
|
-
uploadedFallbackCover = uploaded;
|
|
169
214
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
215
|
+
if (uploadedFallbackCover === undefined) {
|
|
216
|
+
coverSkipped.push(locale);
|
|
217
|
+
} else {
|
|
218
|
+
md = upsertFrontmatterKey(md, 'image', uploadedFallbackCover);
|
|
219
|
+
md = upsertFrontmatterKey(md, 'og_image', uploadedFallbackCover);
|
|
220
|
+
images[locale] = uploadedFallbackCover;
|
|
221
|
+
}
|
|
173
222
|
} else {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
223
|
+
// 0432 R2: no https cover anywhere (the podcast row never uploaded one, the frontmatter
|
|
224
|
+
// has none and no local cover is uploadable). The page is live and its og:image resolves,
|
|
225
|
+
// so this is a recorded warning on an otherwise successful patch — never a failed target.
|
|
226
|
+
// The episode identity and the cross-link below are still written.
|
|
227
|
+
coverSkipped.push(locale);
|
|
177
228
|
}
|
|
178
229
|
if (locale === 'zh' && (request.episodeTitle ?? '') !== '') {
|
|
179
230
|
// The article states the episode identity the podcast ships (0385). The site renders it
|
|
@@ -204,5 +255,23 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
204
255
|
changed += 1;
|
|
205
256
|
}
|
|
206
257
|
}
|
|
207
|
-
|
|
258
|
+
const applied = PATCH_LOCALES.filter((locale) => images[locale] !== undefined);
|
|
259
|
+
return {
|
|
260
|
+
written,
|
|
261
|
+
changed,
|
|
262
|
+
absent,
|
|
263
|
+
images,
|
|
264
|
+
slug: basename(dirname(request.postPath)),
|
|
265
|
+
coverPatch: {
|
|
266
|
+
status: coverSkipped.length === 0 ? 'applied' : 'skipped',
|
|
267
|
+
applied,
|
|
268
|
+
skipped: coverSkipped,
|
|
269
|
+
reason:
|
|
270
|
+
coverSkipped.length === 0
|
|
271
|
+
? ''
|
|
272
|
+
: `${coverSkipped.join('/')} post has no remote https:// cover: coverUrl is empty, the frontmatter has no https:// image key and no local cover was uploadable${uploadError === undefined ? '' : ` (local cover upload failed: ${uploadError})`}`,
|
|
273
|
+
...(uploadError === undefined ? {} : { uploadError }),
|
|
274
|
+
pageUrl: request.pageUrl ?? '',
|
|
275
|
+
},
|
|
276
|
+
};
|
|
208
277
|
}
|
|
@@ -20560,7 +20560,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20560
20560
|
const leaseDir = join3(leaseRoot, id);
|
|
20561
20561
|
await fileSystem.ensureDir(leaseRoot);
|
|
20562
20562
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20563
|
-
|
|
20563
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20564
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20565
|
+
}
|
|
20566
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20567
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20568
|
+
}
|
|
20564
20569
|
}
|
|
20565
20570
|
const token = randomBytes(16).toString("hex");
|
|
20566
20571
|
const owner = {
|
|
@@ -20676,9 +20681,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20676
20681
|
}
|
|
20677
20682
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20678
20683
|
}
|
|
20679
|
-
const
|
|
20684
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20685
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20680
20686
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20681
20687
|
}
|
|
20688
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20689
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20690
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20691
|
+
return false;
|
|
20692
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20693
|
+
return false;
|
|
20694
|
+
const target = staleLeaseDir(leaseDir);
|
|
20695
|
+
try {
|
|
20696
|
+
rename(leaseDir, target);
|
|
20697
|
+
} catch {
|
|
20698
|
+
return false;
|
|
20699
|
+
}
|
|
20700
|
+
const moved = await readOwner(fileSystem, target);
|
|
20701
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20702
|
+
try {
|
|
20703
|
+
rename(target, leaseDir);
|
|
20704
|
+
} catch {}
|
|
20705
|
+
return false;
|
|
20706
|
+
}
|
|
20707
|
+
return true;
|
|
20708
|
+
}
|
|
20709
|
+
function staleLeaseDir(leaseDir) {
|
|
20710
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20711
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20712
|
+
}
|
|
20682
20713
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20683
20714
|
try {
|
|
20684
20715
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20219
20219
|
const leaseDir = join2(leaseRoot, id);
|
|
20220
20220
|
await fileSystem.ensureDir(leaseRoot);
|
|
20221
20221
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20222
|
-
|
|
20222
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20223
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20224
|
+
}
|
|
20225
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20226
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20227
|
+
}
|
|
20223
20228
|
}
|
|
20224
20229
|
const token = randomBytes(16).toString("hex");
|
|
20225
20230
|
const owner = {
|
|
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20335
20340
|
}
|
|
20336
20341
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20337
20342
|
}
|
|
20338
|
-
const
|
|
20343
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20344
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20339
20345
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20340
20346
|
}
|
|
20347
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20348
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20349
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20350
|
+
return false;
|
|
20351
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20352
|
+
return false;
|
|
20353
|
+
const target = staleLeaseDir(leaseDir);
|
|
20354
|
+
try {
|
|
20355
|
+
rename(leaseDir, target);
|
|
20356
|
+
} catch {
|
|
20357
|
+
return false;
|
|
20358
|
+
}
|
|
20359
|
+
const moved = await readOwner(fileSystem, target);
|
|
20360
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20361
|
+
try {
|
|
20362
|
+
rename(target, leaseDir);
|
|
20363
|
+
} catch {}
|
|
20364
|
+
return false;
|
|
20365
|
+
}
|
|
20366
|
+
return true;
|
|
20367
|
+
}
|
|
20368
|
+
function staleLeaseDir(leaseDir) {
|
|
20369
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20370
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20371
|
+
}
|
|
20341
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20342
20373
|
try {
|
|
20343
20374
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20582,7 +20582,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20582
20582
|
const leaseDir = join3(leaseRoot, id);
|
|
20583
20583
|
await fileSystem.ensureDir(leaseRoot);
|
|
20584
20584
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20585
|
-
|
|
20585
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20586
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20587
|
+
}
|
|
20588
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20589
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20590
|
+
}
|
|
20586
20591
|
}
|
|
20587
20592
|
const token = randomBytes(16).toString("hex");
|
|
20588
20593
|
const owner = {
|
|
@@ -20698,9 +20703,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20698
20703
|
}
|
|
20699
20704
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20700
20705
|
}
|
|
20701
|
-
const
|
|
20706
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20707
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20702
20708
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20703
20709
|
}
|
|
20710
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20711
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20712
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20713
|
+
return false;
|
|
20714
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20715
|
+
return false;
|
|
20716
|
+
const target = staleLeaseDir(leaseDir);
|
|
20717
|
+
try {
|
|
20718
|
+
rename(leaseDir, target);
|
|
20719
|
+
} catch {
|
|
20720
|
+
return false;
|
|
20721
|
+
}
|
|
20722
|
+
const moved = await readOwner(fileSystem, target);
|
|
20723
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20724
|
+
try {
|
|
20725
|
+
rename(target, leaseDir);
|
|
20726
|
+
} catch {}
|
|
20727
|
+
return false;
|
|
20728
|
+
}
|
|
20729
|
+
return true;
|
|
20730
|
+
}
|
|
20731
|
+
function staleLeaseDir(leaseDir) {
|
|
20732
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20733
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20734
|
+
}
|
|
20704
20735
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20705
20736
|
try {
|
|
20706
20737
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -25389,6 +25420,30 @@ async function openWithState(profileDir, headless, url = CONSOLE_URL) {
|
|
|
25389
25420
|
throw error;
|
|
25390
25421
|
}
|
|
25391
25422
|
}
|
|
25423
|
+
function cookieIdentity(cookie) {
|
|
25424
|
+
return `${cookie.domain ?? ""}\x00${cookie.path ?? "/"}\x00${cookie.name}`;
|
|
25425
|
+
}
|
|
25426
|
+
function isLiveCookie(cookie, nowMs) {
|
|
25427
|
+
return cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs;
|
|
25428
|
+
}
|
|
25429
|
+
function selectRestoreCookies(saved, profile, nowMs = Date.now()) {
|
|
25430
|
+
const live = new Set(profile.filter((cookie) => isLiveCookie(cookie, nowMs)).map(cookieIdentity));
|
|
25431
|
+
const inject = [];
|
|
25432
|
+
let shadowed = 0;
|
|
25433
|
+
let expired = 0;
|
|
25434
|
+
for (const cookie of saved) {
|
|
25435
|
+
if (!isLiveCookie(cookie, nowMs)) {
|
|
25436
|
+
expired += 1;
|
|
25437
|
+
continue;
|
|
25438
|
+
}
|
|
25439
|
+
if (live.has(cookieIdentity(cookie))) {
|
|
25440
|
+
shadowed += 1;
|
|
25441
|
+
continue;
|
|
25442
|
+
}
|
|
25443
|
+
inject.push(cookie);
|
|
25444
|
+
}
|
|
25445
|
+
return { inject, shadowed, expired };
|
|
25446
|
+
}
|
|
25392
25447
|
async function restoreWechatSessionState(context, page, profileDir) {
|
|
25393
25448
|
const stateFile = storageStatePath(profileDir);
|
|
25394
25449
|
let state;
|
|
@@ -25401,7 +25456,13 @@ async function restoreWechatSessionState(context, page, profileDir) {
|
|
|
25401
25456
|
if (!cookies || cookies.length === 0) {
|
|
25402
25457
|
throw new BrowserProfileMissingError(`no saved console session state (${stateFile}) \u2014 run \`bun src/profile-check.ts login\` once`);
|
|
25403
25458
|
}
|
|
25404
|
-
await context.
|
|
25459
|
+
const profileCookies = await context.cookies().catch(() => []);
|
|
25460
|
+
const selection = selectRestoreCookies(cookies, profileCookies);
|
|
25461
|
+
if (selection.shadowed > 0 || selection.expired > 0) {
|
|
25462
|
+
echoError(`wechatmp-pub: kept ${selection.shadowed} session cookie(s) from the profile itself and skipped ` + `${selection.expired} expired saved cookie(s) \u2014 the saved state is older than this profile`);
|
|
25463
|
+
}
|
|
25464
|
+
if (selection.inject.length > 0)
|
|
25465
|
+
await context.addCookies(selection.inject);
|
|
25405
25466
|
for (const entry of state?.origins ?? []) {
|
|
25406
25467
|
const items = entry.localStorage ?? [];
|
|
25407
25468
|
if (entry.origin === undefined || entry.origin.length === 0 || items.length === 0)
|
|
@@ -25591,6 +25652,7 @@ export {
|
|
|
25591
25652
|
processPublishIO,
|
|
25592
25653
|
restoreWechatSessionState,
|
|
25593
25654
|
runMode,
|
|
25655
|
+
selectRestoreCookies,
|
|
25594
25656
|
storageStatePath,
|
|
25595
25657
|
wechatBrowserLauncher,
|
|
25596
25658
|
wechatSessionConfig,
|