@gobing-ai/knowledge-kit 0.1.25 → 0.1.28
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/collect/index.js +10 -0
- package/dist/board/daily-voice/index.js +1327 -2168
- package/dist/board/itc/index.js +10 -0
- package/dist/index.js +6043 -4620
- package/package.json +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +4 -1
- package/plugins/ingestions/aihot-ingest/src/rss.ts +22 -11
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +423 -141
- 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/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +114 -82
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +114 -82
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/csdn-pub/dist/index.js +114 -82
- package/plugins/publishings/csdn-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/infoq-pub/dist/index.js +114 -82
- package/plugins/publishings/infoq-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/jike-pub/dist/index.js +114 -82
- package/plugins/publishings/jike-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/juejin-pub/dist/index.js +114 -82
- package/plugins/publishings/juejin-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +165 -93
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +51 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +114 -82
- package/plugins/publishings/medium-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +305 -87
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +145 -5
- package/plugins/publishings/shipinhao-pub/src/cover-crop.ts +60 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +15 -2
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +15 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +22 -1
- package/plugins/publishings/sspai-pub/dist/index.js +114 -82
- package/plugins/publishings/sspai-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/substack-pub/dist/index.js +114 -82
- package/plugins/publishings/substack-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/surfdash-pub/dist/index.js +96 -20
- 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 +119 -83
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +149 -86
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +68 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +273 -91
- package/plugins/publishings/weibo-pub/dist/profile-check.js +178 -11
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +136 -10
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +114 -82
- package/plugins/publishings/x-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xhs-pub/dist/index.js +114 -82
- package/plugins/publishings/xhs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +114 -82
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +34 -3
|
@@ -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
|
}
|
|
@@ -20171,6 +20171,86 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
|
|
|
20171
20171
|
import { homedir } from "os";
|
|
20172
20172
|
import { join, resolve } from "path";
|
|
20173
20173
|
|
|
20174
|
+
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20175
|
+
import {
|
|
20176
|
+
chmodSync,
|
|
20177
|
+
closeSync,
|
|
20178
|
+
copyFileSync,
|
|
20179
|
+
lstatSync,
|
|
20180
|
+
mkdirSync as mkdirSync2,
|
|
20181
|
+
openSync,
|
|
20182
|
+
readdirSync as readdirSync2,
|
|
20183
|
+
readlinkSync,
|
|
20184
|
+
realpathSync as realpathSync2,
|
|
20185
|
+
renameSync as renameSync2,
|
|
20186
|
+
rmdirSync,
|
|
20187
|
+
unlinkSync
|
|
20188
|
+
} from "fs";
|
|
20189
|
+
function lstat(path) {
|
|
20190
|
+
try {
|
|
20191
|
+
return lstatSync(path);
|
|
20192
|
+
} catch (error) {
|
|
20193
|
+
if (error.code === "ENOENT")
|
|
20194
|
+
return null;
|
|
20195
|
+
throw error;
|
|
20196
|
+
}
|
|
20197
|
+
}
|
|
20198
|
+
function realpath(path) {
|
|
20199
|
+
return realpathSync2(path);
|
|
20200
|
+
}
|
|
20201
|
+
function mkdirExclusive(path, mode = 448) {
|
|
20202
|
+
try {
|
|
20203
|
+
mkdirSync2(path, { mode });
|
|
20204
|
+
return true;
|
|
20205
|
+
} catch (error) {
|
|
20206
|
+
if (error.code === "EEXIST")
|
|
20207
|
+
return false;
|
|
20208
|
+
throw error;
|
|
20209
|
+
}
|
|
20210
|
+
}
|
|
20211
|
+
function rmdir(path) {
|
|
20212
|
+
try {
|
|
20213
|
+
rmdirSync(path);
|
|
20214
|
+
return true;
|
|
20215
|
+
} catch (error) {
|
|
20216
|
+
const code = error.code;
|
|
20217
|
+
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20218
|
+
return false;
|
|
20219
|
+
throw error;
|
|
20220
|
+
}
|
|
20221
|
+
}
|
|
20222
|
+
function readlink(path) {
|
|
20223
|
+
try {
|
|
20224
|
+
return readlinkSync(path);
|
|
20225
|
+
} catch {
|
|
20226
|
+
return null;
|
|
20227
|
+
}
|
|
20228
|
+
}
|
|
20229
|
+
function unlink(path) {
|
|
20230
|
+
try {
|
|
20231
|
+
unlinkSync(path);
|
|
20232
|
+
return true;
|
|
20233
|
+
} catch (error) {
|
|
20234
|
+
if (error.code === "ENOENT")
|
|
20235
|
+
return false;
|
|
20236
|
+
throw error;
|
|
20237
|
+
}
|
|
20238
|
+
}
|
|
20239
|
+
function rename(from, to) {
|
|
20240
|
+
try {
|
|
20241
|
+
renameSync2(from, to);
|
|
20242
|
+
return true;
|
|
20243
|
+
} catch (error) {
|
|
20244
|
+
if (error.code === "ENOENT")
|
|
20245
|
+
return false;
|
|
20246
|
+
throw error;
|
|
20247
|
+
}
|
|
20248
|
+
}
|
|
20249
|
+
function chmod(path, mode) {
|
|
20250
|
+
chmodSync(path, mode);
|
|
20251
|
+
}
|
|
20252
|
+
|
|
20253
|
+
// ../../packages/publish-harness/src/index.ts
|
|
20174
20254
|
class FakeTransportCore {
|
|
20175
20255
|
callLogs = [];
|
|
20176
20256
|
nextResult;
|
|
@@ -20457,85 +20537,6 @@ init_dist();
|
|
|
20457
20537
|
import { homedir as homedir4 } from "os";
|
|
20458
20538
|
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
20459
20539
|
|
|
20460
|
-
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20461
|
-
import {
|
|
20462
|
-
chmodSync,
|
|
20463
|
-
closeSync,
|
|
20464
|
-
copyFileSync,
|
|
20465
|
-
lstatSync,
|
|
20466
|
-
mkdirSync as mkdirSync2,
|
|
20467
|
-
openSync,
|
|
20468
|
-
readdirSync as readdirSync2,
|
|
20469
|
-
readlinkSync,
|
|
20470
|
-
realpathSync as realpathSync2,
|
|
20471
|
-
renameSync as renameSync2,
|
|
20472
|
-
rmdirSync,
|
|
20473
|
-
unlinkSync
|
|
20474
|
-
} from "fs";
|
|
20475
|
-
function lstat(path) {
|
|
20476
|
-
try {
|
|
20477
|
-
return lstatSync(path);
|
|
20478
|
-
} catch (error) {
|
|
20479
|
-
if (error.code === "ENOENT")
|
|
20480
|
-
return null;
|
|
20481
|
-
throw error;
|
|
20482
|
-
}
|
|
20483
|
-
}
|
|
20484
|
-
function realpath(path) {
|
|
20485
|
-
return realpathSync2(path);
|
|
20486
|
-
}
|
|
20487
|
-
function mkdirExclusive(path, mode = 448) {
|
|
20488
|
-
try {
|
|
20489
|
-
mkdirSync2(path, { mode });
|
|
20490
|
-
return true;
|
|
20491
|
-
} catch (error) {
|
|
20492
|
-
if (error.code === "EEXIST")
|
|
20493
|
-
return false;
|
|
20494
|
-
throw error;
|
|
20495
|
-
}
|
|
20496
|
-
}
|
|
20497
|
-
function rmdir(path) {
|
|
20498
|
-
try {
|
|
20499
|
-
rmdirSync(path);
|
|
20500
|
-
return true;
|
|
20501
|
-
} catch (error) {
|
|
20502
|
-
const code = error.code;
|
|
20503
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20504
|
-
return false;
|
|
20505
|
-
throw error;
|
|
20506
|
-
}
|
|
20507
|
-
}
|
|
20508
|
-
function readlink(path) {
|
|
20509
|
-
try {
|
|
20510
|
-
return readlinkSync(path);
|
|
20511
|
-
} catch {
|
|
20512
|
-
return null;
|
|
20513
|
-
}
|
|
20514
|
-
}
|
|
20515
|
-
function unlink(path) {
|
|
20516
|
-
try {
|
|
20517
|
-
unlinkSync(path);
|
|
20518
|
-
return true;
|
|
20519
|
-
} catch (error) {
|
|
20520
|
-
if (error.code === "ENOENT")
|
|
20521
|
-
return false;
|
|
20522
|
-
throw error;
|
|
20523
|
-
}
|
|
20524
|
-
}
|
|
20525
|
-
function rename(from, to) {
|
|
20526
|
-
try {
|
|
20527
|
-
renameSync2(from, to);
|
|
20528
|
-
return true;
|
|
20529
|
-
} catch (error) {
|
|
20530
|
-
if (error.code === "ENOENT")
|
|
20531
|
-
return false;
|
|
20532
|
-
throw error;
|
|
20533
|
-
}
|
|
20534
|
-
}
|
|
20535
|
-
function chmod(path, mode) {
|
|
20536
|
-
chmodSync(path, mode);
|
|
20537
|
-
}
|
|
20538
|
-
|
|
20539
20540
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20540
20541
|
import { homedir as homedir2 } from "os";
|
|
20541
20542
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
@@ -20560,7 +20561,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20560
20561
|
const leaseDir = join3(leaseRoot, id);
|
|
20561
20562
|
await fileSystem.ensureDir(leaseRoot);
|
|
20562
20563
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20563
|
-
|
|
20564
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20565
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20566
|
+
}
|
|
20567
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20568
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20569
|
+
}
|
|
20564
20570
|
}
|
|
20565
20571
|
const token = randomBytes(16).toString("hex");
|
|
20566
20572
|
const owner = {
|
|
@@ -20676,9 +20682,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20676
20682
|
}
|
|
20677
20683
|
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
20684
|
}
|
|
20679
|
-
const
|
|
20685
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20686
|
+
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
20687
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20681
20688
|
}
|
|
20689
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20690
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20691
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20692
|
+
return false;
|
|
20693
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20694
|
+
return false;
|
|
20695
|
+
const target = staleLeaseDir(leaseDir);
|
|
20696
|
+
try {
|
|
20697
|
+
rename(leaseDir, target);
|
|
20698
|
+
} catch {
|
|
20699
|
+
return false;
|
|
20700
|
+
}
|
|
20701
|
+
const moved = await readOwner(fileSystem, target);
|
|
20702
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20703
|
+
try {
|
|
20704
|
+
rename(target, leaseDir);
|
|
20705
|
+
} catch {}
|
|
20706
|
+
return false;
|
|
20707
|
+
}
|
|
20708
|
+
return true;
|
|
20709
|
+
}
|
|
20710
|
+
function staleLeaseDir(leaseDir) {
|
|
20711
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20712
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20713
|
+
}
|
|
20682
20714
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20683
20715
|
try {
|
|
20684
20716
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20804,7 +20836,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20804
20836
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20805
20837
|
if (lstat(syncData) === null)
|
|
20806
20838
|
return false;
|
|
20807
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20839
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20808
20840
|
}
|
|
20809
20841
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20810
20842
|
return {
|
|
@@ -21277,6 +21309,8 @@ var TARGET2 = "threads";
|
|
|
21277
21309
|
var THREADS_API_BASE = "https://graph.threads.net/v1.0";
|
|
21278
21310
|
var TOKEN_ENVS = ["THREADS_ACCESS_TOKEN", "THREADS_USER_ID"];
|
|
21279
21311
|
var MAX_TEXT_CHARS = 500;
|
|
21312
|
+
var FIRST_URL_RE = /https?:\/\/[^\s<>"'`]+/;
|
|
21313
|
+
var TRAILING_PUNCT_RE = /[),.;:!?\uFF0C\u3002\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300B\u300D\u300F]+$/;
|
|
21280
21314
|
var THREADS_OPERATIONS = ["post"];
|
|
21281
21315
|
function redact(message) {
|
|
21282
21316
|
let out = message;
|
|
@@ -21381,10 +21415,12 @@ class ThreadsPostApiTransport {
|
|
|
21381
21415
|
}
|
|
21382
21416
|
const token = process.env.THREADS_ACCESS_TOKEN ?? "";
|
|
21383
21417
|
const userId = process.env.THREADS_USER_ID ?? "";
|
|
21418
|
+
const linkUrl = text.match(FIRST_URL_RE)?.[0]?.replace(TRAILING_PUNCT_RE, "");
|
|
21384
21419
|
const container = await this.postForm("threads container", `${THREADS_API_BASE}/${userId}/threads`, {
|
|
21385
21420
|
media_type: "TEXT",
|
|
21386
21421
|
text,
|
|
21387
|
-
access_token: token
|
|
21422
|
+
access_token: token,
|
|
21423
|
+
...linkUrl === undefined || linkUrl.length === 0 ? {} : { link_attachment: linkUrl }
|
|
21388
21424
|
});
|
|
21389
21425
|
if ("error" in container)
|
|
21390
21426
|
return fail2(container.error);
|
|
@@ -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);
|
|
@@ -20506,7 +20537,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20506
20537
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20507
20538
|
if (lstat(syncData) === null)
|
|
20508
20539
|
return false;
|
|
20509
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20540
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20510
20541
|
}
|
|
20511
20542
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20512
20543
|
return {
|
|
@@ -22,6 +22,10 @@ const TOKEN_ENVS = ['THREADS_ACCESS_TOKEN', 'THREADS_USER_ID'] as const;
|
|
|
22
22
|
*/
|
|
23
23
|
const MAX_TEXT_CHARS = 500;
|
|
24
24
|
|
|
25
|
+
/** The first http(s) URL in the copy, and the punctuation that ends a sentence rather than a link. */
|
|
26
|
+
const FIRST_URL_RE = /https?:\/\/[^\s<>"'`]+/;
|
|
27
|
+
const TRAILING_PUNCT_RE = /[),.;:!?,。;:!?)》」』]+$/;
|
|
28
|
+
|
|
25
29
|
/** Declared operations (ADR-029 dispatch): threads-pub posts text only. */
|
|
26
30
|
export const THREADS_OPERATIONS = ['post'] as const;
|
|
27
31
|
export type ThreadsOperation = (typeof THREADS_OPERATIONS)[number];
|
|
@@ -184,10 +188,16 @@ export class ThreadsPostApiTransport implements PublishTransport {
|
|
|
184
188
|
|
|
185
189
|
const token = process.env.THREADS_ACCESS_TOKEN ?? '';
|
|
186
190
|
const userId = process.env.THREADS_USER_ID ?? '';
|
|
191
|
+
// Meta's opt-in card parameter. Passing it makes the preview deterministic: the implicit
|
|
192
|
+
// "first URL in the text becomes the card" rule did not fire for our `…完整节目:<url>` copy
|
|
193
|
+
// (measured 2026-11-25 — Threads stored `link_preview_attachment: null` and rendered a bare
|
|
194
|
+
// link, while the identical text carded on X and the page's og:* tags were crawler-clean).
|
|
195
|
+
const linkUrl = text.match(FIRST_URL_RE)?.[0]?.replace(TRAILING_PUNCT_RE, '');
|
|
187
196
|
const container = await this.postForm('threads container', `${THREADS_API_BASE}/${userId}/threads`, {
|
|
188
197
|
media_type: 'TEXT',
|
|
189
198
|
text,
|
|
190
199
|
access_token: token,
|
|
200
|
+
...(linkUrl === undefined || linkUrl.length === 0 ? {} : { link_attachment: linkUrl }),
|
|
191
201
|
});
|
|
192
202
|
if ('error' in container) return fail(container.error);
|
|
193
203
|
|