@gobing-ai/knowledge-kit 0.1.24 → 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 +416 -79
- package/package.json +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +47 -6
- package/plugins/generations/episode-plan-gen/src/index.ts +71 -7
- package/plugins/generations/music-gen/dist/index.js +17 -13
- package/plugins/generations/music-gen/src/audio/measure.ts +25 -20
- package/plugins/kk/decisions/extract/ai-news.yaml +8 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +4 -4
- package/plugins/kk/publish-presets/itc-main.json +39 -23
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +880 -131
- package/plugins/kk/scripts/kk-workflow-stages.ts +58 -3
- package/plugins/kk/skills/content-safety/references/platforms/apple-podcasts.md +12 -5
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +8 -0
- package/plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md +5 -0
- package/plugins/kk/skills/daily-news-cover/SKILL.md +96 -0
- package/plugins/kk/skills/daily-news-illustrations/SKILL.md +123 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +25 -6
- package/plugins/kk/skills/news-editorial/references/daily-visual-composition.md +150 -0
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +1 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +13 -1
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +6 -3
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -4
- package/plugins/kk/workflows/kk-news-generate.yaml +71 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +35 -3
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +35 -3
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/csdn-pub/dist/index.js +35 -3
- package/plugins/publishings/csdn-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/infoq-pub/dist/index.js +35 -3
- package/plugins/publishings/infoq-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/jike-pub/dist/index.js +35 -3
- package/plugins/publishings/jike-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/juejin-pub/dist/index.js +35 -3
- package/plugins/publishings/juejin-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +86 -14
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +52 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +9229 -279
- package/plugins/publishings/medium-pub/dist/profile-check.js +21205 -0
- package/plugins/publishings/medium-pub/package.json +3 -1
- package/plugins/publishings/medium-pub/plugin.json +6 -1
- package/plugins/publishings/medium-pub/src/browser-rail.ts +280 -0
- package/plugins/publishings/medium-pub/src/index.ts +17 -1
- package/plugins/publishings/medium-pub/src/profile-check.ts +27 -0
- package/plugins/publishings/shipinhao-pub/dist/index.js +38 -4
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +37 -4
- package/plugins/publishings/shipinhao-pub/src/flow.ts +5 -0
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +11 -4
- package/plugins/publishings/sspai-pub/dist/index.js +35 -3
- package/plugins/publishings/sspai-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/substack-pub/dist/index.js +35 -3
- package/plugins/publishings/substack-pub/dist/profile-check.js +35 -3
- 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 +35 -3
- package/plugins/publishings/threads-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/wechatmp-pub/dist/index.js +326 -44
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +69 -4
- package/plugins/publishings/wechatmp-pub/src/flow.ts +447 -53
- package/plugins/publishings/wechatmp-pub/src/index.ts +68 -2
- package/plugins/publishings/wechatmp-pub/src/page.ts +8 -0
- package/plugins/publishings/weibo-pub/dist/index.js +58 -9
- package/plugins/publishings/weibo-pub/dist/profile-check.js +57 -9
- 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 +35 -3
- package/plugins/publishings/x-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/xhs-pub/dist/index.js +35 -3
- package/plugins/publishings/xhs-pub/dist/profile-check.js +35 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +35 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +35 -3
|
@@ -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;
|
|
@@ -298,7 +361,10 @@ export const wechatSessionConfig: ChannelBrowserConfig = {
|
|
|
298
361
|
* trying.
|
|
299
362
|
*/
|
|
300
363
|
async function defaultOpenConsole(profileDir: string): Promise<OpenedConsole> {
|
|
301
|
-
|
|
364
|
+
// Headless is the unattended default (ADR-026). `WECHATMP_HEADLESS=false` is the operator repro
|
|
365
|
+
// switch: the 音频 upload dialog's progress text is rendered by the console, and a headed pass is
|
|
366
|
+
// the only way to see what it actually shows when the upload never reads 100% (2026-11-23).
|
|
367
|
+
const { page, context } = await openWithState(profileDir, process.env.WECHATMP_HEADLESS !== 'false');
|
|
302
368
|
return {
|
|
303
369
|
...wrapPlaywrightContext(context, page),
|
|
304
370
|
persistSession: () => persistWechatSessionState(context, profileDir),
|
|
@@ -55,6 +55,11 @@ export interface WechatPage {
|
|
|
55
55
|
press?(key: string): Promise<void>;
|
|
56
56
|
/** The page's frames, for naming what a failed read actually contained. */
|
|
57
57
|
frames?(): WechatFrame[];
|
|
58
|
+
/**
|
|
59
|
+
* Save a PNG of the page. Diagnostics only: a console dialog that fails to reach a state the
|
|
60
|
+
* text probes can read is otherwise unobservable (the 2026-11-23 音频 upload stall).
|
|
61
|
+
*/
|
|
62
|
+
screenshot?(path: string): Promise<void>;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
/** One frame of the console page: enough to name it and count a signal inside it. */
|
|
@@ -353,6 +358,9 @@ export function wrapPlaywrightPage(raw: unknown): WechatPage {
|
|
|
353
358
|
},
|
|
354
359
|
}),
|
|
355
360
|
setInputFiles: (selector, paths) => pw.setInputFiles(selector, paths),
|
|
361
|
+
screenshot: async (path) => {
|
|
362
|
+
await (raw as Page).screenshot({ path });
|
|
363
|
+
},
|
|
356
364
|
url: () => pw.url(),
|
|
357
365
|
evaluate: (expression) => pw.evaluate(expression),
|
|
358
366
|
waitForTimeout: (ms) => pw.waitForTimeout(ms),
|
|
@@ -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,7 +20679,34 @@ 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
|
-
|
|
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}`;
|
|
20684
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
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")}`;
|
|
20678
20710
|
}
|
|
20679
20711
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20680
20712
|
try {
|
|
@@ -20900,7 +20932,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20900
20932
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20901
20933
|
}
|
|
20902
20934
|
async function checkChannelSession(config, opts) {
|
|
20903
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20935
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20904
20936
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20905
20937
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20906
20938
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -21032,6 +21064,7 @@ var TARGET = "weibo";
|
|
|
21032
21064
|
var WEIBO_HOME_URL = "https://weibo.com";
|
|
21033
21065
|
var WEIBO_ARTICLE_URL = "https://card.weibo.com/article/v3/editor";
|
|
21034
21066
|
var WEIBO_MOBILE_COMPOSE_URL = "https://m.weibo.cn/compose/";
|
|
21067
|
+
var MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
21035
21068
|
var LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
21036
21069
|
var WEIBO_OPERATIONS = ["post", "article"];
|
|
21037
21070
|
var WEIBO_POST_SELECTORS = {
|
|
@@ -21105,16 +21138,31 @@ function resolveDriver(options) {
|
|
|
21105
21138
|
}
|
|
21106
21139
|
return { driver: "script" };
|
|
21107
21140
|
}
|
|
21108
|
-
|
|
21109
|
-
if (LOGIN_URL_RE.test(
|
|
21141
|
+
function weiboSurfaceReady(facts) {
|
|
21142
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21110
21143
|
return false;
|
|
21111
|
-
if (
|
|
21144
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url)))
|
|
21112
21145
|
return true;
|
|
21113
|
-
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);
|
|
21114
21162
|
};
|
|
21115
21163
|
var WEIBO_CONFIG = {
|
|
21116
21164
|
channel: TARGET,
|
|
21117
|
-
homeUrl:
|
|
21165
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21118
21166
|
isAuthenticated: isWeiboAuthenticated,
|
|
21119
21167
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21120
21168
|
checkHeadedOnly: false
|
|
@@ -21799,5 +21847,6 @@ export {
|
|
|
21799
21847
|
main2 as main,
|
|
21800
21848
|
picIdFromImageUrl,
|
|
21801
21849
|
processPublishIO,
|
|
21802
|
-
resolveOperation
|
|
21850
|
+
resolveOperation,
|
|
21851
|
+
weiboSurfaceReady
|
|
21803
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,7 +20340,34 @@ 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
|
-
|
|
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}`;
|
|
20345
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
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")}`;
|
|
20339
20371
|
}
|
|
20340
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20341
20373
|
try {
|
|
@@ -20604,7 +20636,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20604
20636
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20605
20637
|
}
|
|
20606
20638
|
async function checkChannelSession(config, opts) {
|
|
20607
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20639
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20608
20640
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20609
20641
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20610
20642
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -21112,7 +21144,8 @@ var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
|
21112
21144
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
21113
21145
|
// ../../plugins/publishings/weibo-pub/src/index.ts
|
|
21114
21146
|
var TARGET = "weibo";
|
|
21115
|
-
var
|
|
21147
|
+
var WEIBO_MOBILE_COMPOSE_URL = "https://m.weibo.cn/compose/";
|
|
21148
|
+
var MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
21116
21149
|
var LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
21117
21150
|
var WEIBO_POST_SELECTORS = {
|
|
21118
21151
|
composer: ['textarea[placeholder*="\u5206\u4EAB\u65B0\u9C9C\u4E8B"]', 'textarea[placeholder*="\u65B0\u9C9C\u4E8B"]', "textarea"],
|
|
@@ -21135,16 +21168,31 @@ var LOGIN_TIMEOUT_MS = 180000;
|
|
|
21135
21168
|
var POST_IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"]);
|
|
21136
21169
|
var MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
21137
21170
|
var ARTICLE_COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21138
|
-
|
|
21139
|
-
if (LOGIN_URL_RE.test(
|
|
21171
|
+
function weiboSurfaceReady(facts) {
|
|
21172
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21140
21173
|
return false;
|
|
21141
|
-
if (
|
|
21174
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url)))
|
|
21142
21175
|
return true;
|
|
21143
|
-
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);
|
|
21144
21192
|
};
|
|
21145
21193
|
var WEIBO_CONFIG = {
|
|
21146
21194
|
channel: TARGET,
|
|
21147
|
-
homeUrl:
|
|
21195
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21148
21196
|
isAuthenticated: isWeiboAuthenticated,
|
|
21149
21197
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21150
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,7 +20704,34 @@ 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
|
-
|
|
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}`;
|
|
20709
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
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")}`;
|
|
20703
20735
|
}
|
|
20704
20736
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20705
20737
|
try {
|
|
@@ -20925,7 +20957,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20925
20957
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20926
20958
|
}
|
|
20927
20959
|
async function checkChannelSession(config, opts) {
|
|
20928
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20960
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20929
20961
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20930
20962
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20931
20963
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -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,7 +20340,34 @@ 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
|
-
|
|
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}`;
|
|
20345
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
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")}`;
|
|
20339
20371
|
}
|
|
20340
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20341
20373
|
try {
|
|
@@ -20604,7 +20636,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20604
20636
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20605
20637
|
}
|
|
20606
20638
|
async function checkChannelSession(config, opts) {
|
|
20607
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20639
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20608
20640
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20609
20641
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20610
20642
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -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,7 +20679,34 @@ 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
|
-
|
|
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}`;
|
|
20684
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
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")}`;
|
|
20678
20710
|
}
|
|
20679
20711
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20680
20712
|
try {
|
|
@@ -20900,7 +20932,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20900
20932
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20901
20933
|
}
|
|
20902
20934
|
async function checkChannelSession(config, opts) {
|
|
20903
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20935
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20904
20936
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20905
20937
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20906
20938
|
const deadline = Date.now() + timeoutMs;
|