@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
|
@@ -20231,7 +20231,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20231
20231
|
const leaseDir = join2(leaseRoot, id);
|
|
20232
20232
|
await fileSystem.ensureDir(leaseRoot);
|
|
20233
20233
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20234
|
-
|
|
20234
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20235
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20236
|
+
}
|
|
20237
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20238
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20239
|
+
}
|
|
20235
20240
|
}
|
|
20236
20241
|
const token = randomBytes(16).toString("hex");
|
|
20237
20242
|
const owner = {
|
|
@@ -20347,9 +20352,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20347
20352
|
}
|
|
20348
20353
|
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`;
|
|
20349
20354
|
}
|
|
20350
|
-
const
|
|
20355
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20356
|
+
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}`;
|
|
20351
20357
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20352
20358
|
}
|
|
20359
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20360
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20361
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20362
|
+
return false;
|
|
20363
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20364
|
+
return false;
|
|
20365
|
+
const target = staleLeaseDir(leaseDir);
|
|
20366
|
+
try {
|
|
20367
|
+
rename(leaseDir, target);
|
|
20368
|
+
} catch {
|
|
20369
|
+
return false;
|
|
20370
|
+
}
|
|
20371
|
+
const moved = await readOwner(fileSystem, target);
|
|
20372
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20373
|
+
try {
|
|
20374
|
+
rename(target, leaseDir);
|
|
20375
|
+
} catch {}
|
|
20376
|
+
return false;
|
|
20377
|
+
}
|
|
20378
|
+
return true;
|
|
20379
|
+
}
|
|
20380
|
+
function staleLeaseDir(leaseDir) {
|
|
20381
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20382
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20383
|
+
}
|
|
20353
20384
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20354
20385
|
try {
|
|
20355
20386
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -21114,6 +21145,9 @@ if (false) {}
|
|
|
21114
21145
|
var CJK_TERMINATORS = new Set(["\u3002", "\uFF01", "\uFF1F"]);
|
|
21115
21146
|
var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
21116
21147
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
21148
|
+
// ../../plugins/publishings/wechatmp-pub/src/index.ts
|
|
21149
|
+
init_dist();
|
|
21150
|
+
|
|
21117
21151
|
// ../../plugins/publishings/wechatmp-pub/src/cgi.ts
|
|
21118
21152
|
var MP_ORIGIN = "https://mp.weixin.qq.com";
|
|
21119
21153
|
var FILETRANSFER_URL = `${MP_ORIGIN}/cgi-bin/filetransfer`;
|
|
@@ -21245,6 +21279,30 @@ async function openWithState(profileDir, headless, url = CONSOLE_URL) {
|
|
|
21245
21279
|
throw error;
|
|
21246
21280
|
}
|
|
21247
21281
|
}
|
|
21282
|
+
function cookieIdentity(cookie) {
|
|
21283
|
+
return `${cookie.domain ?? ""}\x00${cookie.path ?? "/"}\x00${cookie.name}`;
|
|
21284
|
+
}
|
|
21285
|
+
function isLiveCookie(cookie, nowMs) {
|
|
21286
|
+
return cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs;
|
|
21287
|
+
}
|
|
21288
|
+
function selectRestoreCookies(saved, profile, nowMs = Date.now()) {
|
|
21289
|
+
const live = new Set(profile.filter((cookie) => isLiveCookie(cookie, nowMs)).map(cookieIdentity));
|
|
21290
|
+
const inject = [];
|
|
21291
|
+
let shadowed = 0;
|
|
21292
|
+
let expired = 0;
|
|
21293
|
+
for (const cookie of saved) {
|
|
21294
|
+
if (!isLiveCookie(cookie, nowMs)) {
|
|
21295
|
+
expired += 1;
|
|
21296
|
+
continue;
|
|
21297
|
+
}
|
|
21298
|
+
if (live.has(cookieIdentity(cookie))) {
|
|
21299
|
+
shadowed += 1;
|
|
21300
|
+
continue;
|
|
21301
|
+
}
|
|
21302
|
+
inject.push(cookie);
|
|
21303
|
+
}
|
|
21304
|
+
return { inject, shadowed, expired };
|
|
21305
|
+
}
|
|
21248
21306
|
async function restoreWechatSessionState(context, page, profileDir) {
|
|
21249
21307
|
const stateFile = storageStatePath(profileDir);
|
|
21250
21308
|
let state;
|
|
@@ -21257,7 +21315,13 @@ async function restoreWechatSessionState(context, page, profileDir) {
|
|
|
21257
21315
|
if (!cookies || cookies.length === 0) {
|
|
21258
21316
|
throw new BrowserProfileMissingError(`no saved console session state (${stateFile}) \u2014 run \`bun src/profile-check.ts login\` once`);
|
|
21259
21317
|
}
|
|
21260
|
-
await context.
|
|
21318
|
+
const profileCookies = await context.cookies().catch(() => []);
|
|
21319
|
+
const selection = selectRestoreCookies(cookies, profileCookies);
|
|
21320
|
+
if (selection.shadowed > 0 || selection.expired > 0) {
|
|
21321
|
+
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`);
|
|
21322
|
+
}
|
|
21323
|
+
if (selection.inject.length > 0)
|
|
21324
|
+
await context.addCookies(selection.inject);
|
|
21261
21325
|
for (const entry of state?.origins ?? []) {
|
|
21262
21326
|
const items = entry.localStorage ?? [];
|
|
21263
21327
|
if (entry.origin === undefined || entry.origin.length === 0 || items.length === 0)
|
|
@@ -208,6 +208,56 @@ async function openWithState(
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Identity of one cookie inside a browser store: the trio the browser itself keys on. Values are
|
|
213
|
+
* never compared, printed or returned — only used as the payload of an `addCookies` call.
|
|
214
|
+
*/
|
|
215
|
+
function cookieIdentity(cookie: { name: string; domain?: string; path?: string }): string {
|
|
216
|
+
return `${cookie.domain ?? ''}\u0000${cookie.path ?? '/'}\u0000${cookie.name}`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** `true` while the browser would still send it (Playwright reports a session cookie as `expires: -1`). */
|
|
220
|
+
function isLiveCookie(cookie: { expires?: number }, nowMs: number): boolean {
|
|
221
|
+
return cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* What a restore may actually inject (0436 R2, AC2). The saved `storage-state.json` is a fallback
|
|
226
|
+
* for what the profile's own store LOST, never an override of what it still holds:
|
|
227
|
+
*
|
|
228
|
+
* 1. a saved cookie the profile still holds live is dropped — the 2026-11-24 measurement was
|
|
229
|
+
* exactly this shape (state dated 11-23 17:33, profile `wxuin` fresh from a 21:03 sign-in), and
|
|
230
|
+
* replaying the older snapshot over the live one is what made every later `check` refuse a
|
|
231
|
+
* session the browser actually had;
|
|
232
|
+
* 2. a saved cookie that has itself expired is dropped — it can only produce a signed-out console;
|
|
233
|
+
* 3. everything else is injected, which is the reason the file exists: mp.weixin.qq.com grant
|
|
234
|
+
* cookies do not survive a Chromium restart although the store keeps the session id.
|
|
235
|
+
*
|
|
236
|
+
* Counts come back so the operator gets one bounded line; names and values never do.
|
|
237
|
+
*/
|
|
238
|
+
export function selectRestoreCookies(
|
|
239
|
+
saved: readonly Cookie[],
|
|
240
|
+
profile: readonly Cookie[],
|
|
241
|
+
nowMs: number = Date.now(),
|
|
242
|
+
): { inject: Cookie[]; shadowed: number; expired: number } {
|
|
243
|
+
const live = new Set(profile.filter((cookie) => isLiveCookie(cookie, nowMs)).map(cookieIdentity));
|
|
244
|
+
const inject: Cookie[] = [];
|
|
245
|
+
let shadowed = 0;
|
|
246
|
+
let expired = 0;
|
|
247
|
+
for (const cookie of saved) {
|
|
248
|
+
if (!isLiveCookie(cookie, nowMs)) {
|
|
249
|
+
expired += 1;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (live.has(cookieIdentity(cookie))) {
|
|
253
|
+
shadowed += 1;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
inject.push(cookie);
|
|
257
|
+
}
|
|
258
|
+
return { inject, shadowed, expired };
|
|
259
|
+
}
|
|
260
|
+
|
|
211
261
|
/**
|
|
212
262
|
* Re-inject the durable login captured at login time onto a freshly launched context. A missing or
|
|
213
263
|
* corrupt `storage-state.json` refuses with `BrowserProfileMissingError` — nothing is fabricated.
|
|
@@ -216,6 +266,10 @@ async function openWithState(
|
|
|
216
266
|
* mp.weixin.qq.com (its `origins` half), and discarding it lands the console on its login page even
|
|
217
267
|
* though every cookie was accepted — observed live 2026-10-05, where `check` reported OK while the
|
|
218
268
|
* flow sat on a QR page. Replay each origin's storage before the caller navigates.
|
|
269
|
+
*
|
|
270
|
+
* 0436 R2: only the cookies {@link selectRestoreCookies} selects are replayed, so a state file older
|
|
271
|
+
* than the profile's own cookies can no longer mask a fresh console session. An unreadable jar is
|
|
272
|
+
* treated as empty — the saved state is then the only source, which is the pre-0436 behaviour.
|
|
219
273
|
*/
|
|
220
274
|
export async function restoreWechatSessionState(
|
|
221
275
|
context: BrowserContext,
|
|
@@ -237,7 +291,16 @@ export async function restoreWechatSessionState(
|
|
|
237
291
|
`no saved console session state (${stateFile}) — run \`bun src/profile-check.ts login\` once`,
|
|
238
292
|
);
|
|
239
293
|
}
|
|
240
|
-
await context.
|
|
294
|
+
const profileCookies = await context.cookies().catch(() => [] as Cookie[]);
|
|
295
|
+
const selection = selectRestoreCookies(cookies, profileCookies);
|
|
296
|
+
if (selection.shadowed > 0 || selection.expired > 0) {
|
|
297
|
+
// Bounded and name-free: the operator sees WHY the snapshot was not replayed in full.
|
|
298
|
+
echoError(
|
|
299
|
+
`wechatmp-pub: kept ${selection.shadowed} session cookie(s) from the profile itself and skipped ` +
|
|
300
|
+
`${selection.expired} expired saved cookie(s) — the saved state is older than this profile`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
if (selection.inject.length > 0) await context.addCookies(selection.inject);
|
|
241
304
|
for (const entry of state?.origins ?? []) {
|
|
242
305
|
const items = entry.localStorage ?? [];
|
|
243
306
|
if (entry.origin === undefined || entry.origin.length === 0 || items.length === 0) continue;
|
|
@@ -20558,7 +20558,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20558
20558
|
const leaseDir = join3(leaseRoot, id);
|
|
20559
20559
|
await fileSystem.ensureDir(leaseRoot);
|
|
20560
20560
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20561
|
-
|
|
20561
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20562
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20563
|
+
}
|
|
20564
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20565
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20566
|
+
}
|
|
20562
20567
|
}
|
|
20563
20568
|
const token = randomBytes(16).toString("hex");
|
|
20564
20569
|
const owner = {
|
|
@@ -20674,9 +20679,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20674
20679
|
}
|
|
20675
20680
|
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`;
|
|
20676
20681
|
}
|
|
20677
|
-
const
|
|
20682
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20683
|
+
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}`;
|
|
20678
20684
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20679
20685
|
}
|
|
20686
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20687
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20688
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20689
|
+
return false;
|
|
20690
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20691
|
+
return false;
|
|
20692
|
+
const target = staleLeaseDir(leaseDir);
|
|
20693
|
+
try {
|
|
20694
|
+
rename(leaseDir, target);
|
|
20695
|
+
} catch {
|
|
20696
|
+
return false;
|
|
20697
|
+
}
|
|
20698
|
+
const moved = await readOwner(fileSystem, target);
|
|
20699
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20700
|
+
try {
|
|
20701
|
+
rename(target, leaseDir);
|
|
20702
|
+
} catch {}
|
|
20703
|
+
return false;
|
|
20704
|
+
}
|
|
20705
|
+
return true;
|
|
20706
|
+
}
|
|
20707
|
+
function staleLeaseDir(leaseDir) {
|
|
20708
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20709
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20710
|
+
}
|
|
20680
20711
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20681
20712
|
try {
|
|
20682
20713
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -21033,6 +21064,7 @@ var TARGET = "weibo";
|
|
|
21033
21064
|
var WEIBO_HOME_URL = "https://weibo.com";
|
|
21034
21065
|
var WEIBO_ARTICLE_URL = "https://card.weibo.com/article/v3/editor";
|
|
21035
21066
|
var WEIBO_MOBILE_COMPOSE_URL = "https://m.weibo.cn/compose/";
|
|
21067
|
+
var MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
21036
21068
|
var LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
21037
21069
|
var WEIBO_OPERATIONS = ["post", "article"];
|
|
21038
21070
|
var WEIBO_POST_SELECTORS = {
|
|
@@ -21106,16 +21138,31 @@ function resolveDriver(options) {
|
|
|
21106
21138
|
}
|
|
21107
21139
|
return { driver: "script" };
|
|
21108
21140
|
}
|
|
21109
|
-
|
|
21110
|
-
if (LOGIN_URL_RE.test(
|
|
21141
|
+
function weiboSurfaceReady(facts) {
|
|
21142
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21111
21143
|
return false;
|
|
21112
|
-
if (
|
|
21144
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url)))
|
|
21113
21145
|
return true;
|
|
21114
|
-
return
|
|
21146
|
+
return facts.articleTitle;
|
|
21147
|
+
}
|
|
21148
|
+
var isWeiboAuthenticated = async (page) => {
|
|
21149
|
+
const facts = { url: page.url(), composer: false, composerLabelled: false, articleTitle: false };
|
|
21150
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21151
|
+
return false;
|
|
21152
|
+
if ((await trySelectors(page, WEIBO_POST_SELECTORS.composer, { visible: false })).found) {
|
|
21153
|
+
facts.composer = true;
|
|
21154
|
+
facts.composerLabelled = (await trySelectors(page, WEIBO_POST_SELECTORS.composer.filter((s) => s.includes("placeholder")), {
|
|
21155
|
+
visible: false
|
|
21156
|
+
})).found;
|
|
21157
|
+
if (weiboSurfaceReady(facts))
|
|
21158
|
+
return true;
|
|
21159
|
+
}
|
|
21160
|
+
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
21161
|
+
return weiboSurfaceReady(facts);
|
|
21115
21162
|
};
|
|
21116
21163
|
var WEIBO_CONFIG = {
|
|
21117
21164
|
channel: TARGET,
|
|
21118
|
-
homeUrl:
|
|
21165
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21119
21166
|
isAuthenticated: isWeiboAuthenticated,
|
|
21120
21167
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21121
21168
|
checkHeadedOnly: false
|
|
@@ -21800,5 +21847,6 @@ export {
|
|
|
21800
21847
|
main2 as main,
|
|
21801
21848
|
picIdFromImageUrl,
|
|
21802
21849
|
processPublishIO,
|
|
21803
|
-
resolveOperation
|
|
21850
|
+
resolveOperation,
|
|
21851
|
+
weiboSurfaceReady
|
|
21804
21852
|
};
|
|
@@ -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);
|
|
@@ -21113,7 +21144,8 @@ var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
|
21113
21144
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
21114
21145
|
// ../../plugins/publishings/weibo-pub/src/index.ts
|
|
21115
21146
|
var TARGET = "weibo";
|
|
21116
|
-
var
|
|
21147
|
+
var WEIBO_MOBILE_COMPOSE_URL = "https://m.weibo.cn/compose/";
|
|
21148
|
+
var MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
21117
21149
|
var LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
21118
21150
|
var WEIBO_POST_SELECTORS = {
|
|
21119
21151
|
composer: ['textarea[placeholder*="\u5206\u4EAB\u65B0\u9C9C\u4E8B"]', 'textarea[placeholder*="\u65B0\u9C9C\u4E8B"]', "textarea"],
|
|
@@ -21136,16 +21168,31 @@ var LOGIN_TIMEOUT_MS = 180000;
|
|
|
21136
21168
|
var POST_IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"]);
|
|
21137
21169
|
var MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
21138
21170
|
var ARTICLE_COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21139
|
-
|
|
21140
|
-
if (LOGIN_URL_RE.test(
|
|
21171
|
+
function weiboSurfaceReady(facts) {
|
|
21172
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21141
21173
|
return false;
|
|
21142
|
-
if (
|
|
21174
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url)))
|
|
21143
21175
|
return true;
|
|
21144
|
-
return
|
|
21176
|
+
return facts.articleTitle;
|
|
21177
|
+
}
|
|
21178
|
+
var isWeiboAuthenticated = async (page) => {
|
|
21179
|
+
const facts = { url: page.url(), composer: false, composerLabelled: false, articleTitle: false };
|
|
21180
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21181
|
+
return false;
|
|
21182
|
+
if ((await trySelectors(page, WEIBO_POST_SELECTORS.composer, { visible: false })).found) {
|
|
21183
|
+
facts.composer = true;
|
|
21184
|
+
facts.composerLabelled = (await trySelectors(page, WEIBO_POST_SELECTORS.composer.filter((s) => s.includes("placeholder")), {
|
|
21185
|
+
visible: false
|
|
21186
|
+
})).found;
|
|
21187
|
+
if (weiboSurfaceReady(facts))
|
|
21188
|
+
return true;
|
|
21189
|
+
}
|
|
21190
|
+
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
21191
|
+
return weiboSurfaceReady(facts);
|
|
21145
21192
|
};
|
|
21146
21193
|
var WEIBO_CONFIG = {
|
|
21147
21194
|
channel: TARGET,
|
|
21148
|
-
homeUrl:
|
|
21195
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21149
21196
|
isAuthenticated: isWeiboAuthenticated,
|
|
21150
21197
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21151
21198
|
checkHeadedOnly: false
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"description": "post and 头条文章 article via a script browser transport (ts-browser-automation), draft by default",
|
|
8
8
|
"browserSession": {
|
|
9
9
|
"profileName": "weibo",
|
|
10
|
-
"homeUrl": "https://weibo.
|
|
10
|
+
"homeUrl": "https://m.weibo.cn/compose/"
|
|
11
11
|
},
|
|
12
12
|
"publishing": {
|
|
13
13
|
"defaultProfile": "article",
|
|
@@ -49,6 +49,9 @@ export const WEIBO_ARTICLE_URL = 'https://card.weibo.com/article/v3/editor';
|
|
|
49
49
|
* image through `input[type="file"]` natively, which an episode announcement needs.
|
|
50
50
|
*/
|
|
51
51
|
export const WEIBO_MOBILE_COMPOSE_URL = 'https://m.weibo.cn/compose/';
|
|
52
|
+
|
|
53
|
+
/** The mobile composer host — the only page where the bare `textarea` fallback is trusted. */
|
|
54
|
+
const MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
52
55
|
/** Login and passport redirects: while the browser sits on one, the composer never renders. */
|
|
53
56
|
export const LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
54
57
|
|
|
@@ -208,25 +211,90 @@ function resolveDriver(
|
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
|
|
214
|
+
* What one weibo page actually rendered, as the readiness gate reads it (0436 R3). Plain facts, so
|
|
215
|
+
* the accept/reject decision is testable without a browser and the one deliberate conjunction below
|
|
216
|
+
* is visible in a single line.
|
|
217
|
+
*/
|
|
218
|
+
export interface WeiboSurfaceFacts {
|
|
219
|
+
/** Final URL after the navigation: a login/passport redirect means there is no session. */
|
|
220
|
+
url: string;
|
|
221
|
+
/** The composer textarea the post flow fills. */
|
|
222
|
+
composer: boolean;
|
|
223
|
+
/** Whether that textarea matched a composer PLACEHOLDER (`分享新鲜事`), not the bare fallback. */
|
|
224
|
+
composerLabelled: boolean;
|
|
225
|
+
/** The 头条文章 title field the article flow fills. */
|
|
226
|
+
articleTitle: boolean;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The readiness decision for one surface (0436 R3).
|
|
231
|
+
*
|
|
232
|
+
* The post leg needs the composer the flow FILLS, and nothing else: `runPostFlow` submits through
|
|
233
|
+
* the page's own mobile API (`POST /api/statuses/update`, measured 0246), so the render of a send
|
|
234
|
+
* control is not evidence of a session and demanding one would refuse a valid console that lacks it
|
|
235
|
+
* (0436 review). The article leg keeps its title field — that flow's post-goto confirmation runs on
|
|
236
|
+
* the card.weibo.com editor.
|
|
237
|
+
*/
|
|
238
|
+
export function weiboSurfaceReady(facts: WeiboSurfaceFacts): boolean {
|
|
239
|
+
if (LOGIN_URL_RE.test(facts.url)) return false;
|
|
240
|
+
// A labelled composer is the session evidence; the bare `textarea` fallback also matches a
|
|
241
|
+
// search box, so it only counts when the page IS the mobile composer.
|
|
242
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url))) return true;
|
|
243
|
+
return facts.articleTitle;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Weibo-owned readiness predicate: no login redirect and either the post composer (with the send
|
|
248
|
+
* control the flow clicks) or the 头条文章 editor reachable. Shared by the publish preflight and the
|
|
249
|
+
* operator profile CLI, so both apply one gate (R6, R7). Both surfaces are accepted because the
|
|
250
|
+
* preflight opens the post composer while the article flow's post-goto confirmation opens the
|
|
251
|
+
* editor.
|
|
252
|
+
*
|
|
253
|
+
* Re-measured 2026-11-24 (0436 R3): both the headless and the headed check refused a profile whose
|
|
254
|
+
* `SUB`/`SUBP` cookies were live until 2027-11-24 — on the desktop home page. The selectors that
|
|
255
|
+
* have to hold are the ones the post flow itself drives, so the session check now opens that
|
|
256
|
+
* surface (see {@link WEIBO_CONFIG}) instead of a home feed this account may never render.
|
|
215
257
|
*/
|
|
216
258
|
export const isWeiboAuthenticated: IsAuthenticatedPredicate = async (page) => {
|
|
217
|
-
|
|
218
|
-
if ((
|
|
219
|
-
|
|
259
|
+
const facts: WeiboSurfaceFacts = { url: page.url(), composer: false, composerLabelled: false, articleTitle: false };
|
|
260
|
+
if (LOGIN_URL_RE.test(facts.url)) return false;
|
|
261
|
+
if ((await trySelectors(page, WEIBO_POST_SELECTORS.composer, { visible: false })).found) {
|
|
262
|
+
facts.composer = true;
|
|
263
|
+
// The placeholder is what distinguishes the compose box from the bare `textarea` fallback
|
|
264
|
+
// (which also matches a search box) — not the send button, which the flow never clicks
|
|
265
|
+
// because it submits through the mobile API.
|
|
266
|
+
facts.composerLabelled = (
|
|
267
|
+
await trySelectors(
|
|
268
|
+
page,
|
|
269
|
+
WEIBO_POST_SELECTORS.composer.filter((s) => s.includes('placeholder')),
|
|
270
|
+
{
|
|
271
|
+
visible: false,
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
).found;
|
|
275
|
+
if (weiboSurfaceReady(facts)) return true;
|
|
276
|
+
}
|
|
277
|
+
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
278
|
+
return weiboSurfaceReady(facts);
|
|
220
279
|
};
|
|
221
280
|
|
|
222
281
|
/**
|
|
223
282
|
* Site-owned config for the shared session check and operator CLI (ADR-032). The publish preflight
|
|
224
283
|
* never forwards `checkHeadedOnly`: it is the operator CLI's setting, and a refusal must never
|
|
225
284
|
* escalate to a headed window on its own (R6).
|
|
285
|
+
*
|
|
286
|
+
* `homeUrl` is the surface the post flow drives, not the desktop feed (0436 R3): measured 2026-11-24,
|
|
287
|
+
* `https://weibo.com` refused both the headless and the headed pass on a profile with live
|
|
288
|
+
* `SUB`/`SUBP` cookies, while `post` can only post through the mobile composer — a server-rendered
|
|
289
|
+
* page measured 2026-10-12 (task 0246). Checking where the flow goes is what makes `verified` mean
|
|
290
|
+
* "this channel can post"; the article leg keeps its own gate (the editor's title field).
|
|
291
|
+
*
|
|
292
|
+
* `checkHeadedOnly` stays `false`: the headed pass refused exactly like the headless one on that
|
|
293
|
+
* same measurement, so a headless refusal here is not a headless-only artifact.
|
|
226
294
|
*/
|
|
227
295
|
export const WEIBO_CONFIG: ChannelBrowserConfig = {
|
|
228
296
|
channel: TARGET,
|
|
229
|
-
homeUrl:
|
|
297
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
230
298
|
isAuthenticated: isWeiboAuthenticated,
|
|
231
299
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
232
300
|
checkHeadedOnly: false,
|
|
@@ -20583,7 +20583,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20583
20583
|
const leaseDir = join3(leaseRoot, id);
|
|
20584
20584
|
await fileSystem.ensureDir(leaseRoot);
|
|
20585
20585
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20586
|
-
|
|
20586
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20587
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20588
|
+
}
|
|
20589
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20590
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20591
|
+
}
|
|
20587
20592
|
}
|
|
20588
20593
|
const token = randomBytes(16).toString("hex");
|
|
20589
20594
|
const owner = {
|
|
@@ -20699,9 +20704,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20699
20704
|
}
|
|
20700
20705
|
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`;
|
|
20701
20706
|
}
|
|
20702
|
-
const
|
|
20707
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20708
|
+
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}`;
|
|
20703
20709
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20704
20710
|
}
|
|
20711
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20712
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20713
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20714
|
+
return false;
|
|
20715
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20716
|
+
return false;
|
|
20717
|
+
const target = staleLeaseDir(leaseDir);
|
|
20718
|
+
try {
|
|
20719
|
+
rename(leaseDir, target);
|
|
20720
|
+
} catch {
|
|
20721
|
+
return false;
|
|
20722
|
+
}
|
|
20723
|
+
const moved = await readOwner(fileSystem, target);
|
|
20724
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20725
|
+
try {
|
|
20726
|
+
rename(target, leaseDir);
|
|
20727
|
+
} catch {}
|
|
20728
|
+
return false;
|
|
20729
|
+
}
|
|
20730
|
+
return true;
|
|
20731
|
+
}
|
|
20732
|
+
function staleLeaseDir(leaseDir) {
|
|
20733
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20734
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20735
|
+
}
|
|
20705
20736
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20706
20737
|
try {
|
|
20707
20738
|
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);
|