@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
|
@@ -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;
|
|
@@ -21008,6 +21040,7 @@ var MAX_IMAGES = 1;
|
|
|
21008
21040
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
|
|
21009
21041
|
var LINKEDIN_POST_SELECTORS = {
|
|
21010
21042
|
shareTrigger: [
|
|
21043
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
21011
21044
|
'button:has-text("Start a post")',
|
|
21012
21045
|
'div[role="button"]:has-text("Start a post")',
|
|
21013
21046
|
'text="Start a post"',
|
|
@@ -21021,8 +21054,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21021
21054
|
'div[role="textbox"].tiptap',
|
|
21022
21055
|
".tiptap.ProseMirror",
|
|
21023
21056
|
'[role="dialog"] div[role="textbox"]',
|
|
21024
|
-
'div.editor-content[contenteditable="true"]'
|
|
21025
|
-
'div[role="textbox"][contenteditable="true"]'
|
|
21057
|
+
'div.editor-content[contenteditable="true"]'
|
|
21026
21058
|
],
|
|
21027
21059
|
mediaButton: [
|
|
21028
21060
|
'button[aria-label="Media"]',
|
|
@@ -21045,6 +21077,7 @@ var PREVIEW_TIMEOUT_MS = 5000;
|
|
|
21045
21077
|
var PREVIEW_POLL_MS = 250;
|
|
21046
21078
|
var LINK_PREVIEW_TIMEOUT_MS = 1e4;
|
|
21047
21079
|
var STEP_TIMEOUT_MS = 30000;
|
|
21080
|
+
var PREFLIGHT_TIMEOUT_MS = 90000;
|
|
21048
21081
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21049
21082
|
var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
|
|
21050
21083
|
var EXCERPT_CHARS = 30;
|
|
@@ -21059,6 +21092,24 @@ function stageFail(error, stage, metadata, evidence) {
|
|
|
21059
21092
|
metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence: boundedDetail(evidence) } }
|
|
21060
21093
|
});
|
|
21061
21094
|
}
|
|
21095
|
+
function preSubmitFail(error, stage, metadata) {
|
|
21096
|
+
return stageFail(error, stage, { ...metadata, itcDelivery: { schemaVersion: 1, effect: "none" } });
|
|
21097
|
+
}
|
|
21098
|
+
async function probeComposer(page, trigger) {
|
|
21099
|
+
const count = (locator) => locator.count().catch(() => -1);
|
|
21100
|
+
const triggerLocator = page.locator(trigger);
|
|
21101
|
+
const candidates = {};
|
|
21102
|
+
for (const selector of LINKEDIN_POST_SELECTORS.composer)
|
|
21103
|
+
candidates[selector] = await count(page.locator(selector));
|
|
21104
|
+
return {
|
|
21105
|
+
trigger,
|
|
21106
|
+
triggerMatches: await count(triggerLocator),
|
|
21107
|
+
triggerVisible: await count(triggerLocator.filter({ visible: true })),
|
|
21108
|
+
candidates,
|
|
21109
|
+
url: page.url(),
|
|
21110
|
+
frames: typeof page.frames === "function" ? page.frames().length : 0
|
|
21111
|
+
};
|
|
21112
|
+
}
|
|
21062
21113
|
function boundedDetail(detail) {
|
|
21063
21114
|
return detail.replace(/\s+/g, " ").trim().slice(0, 300);
|
|
21064
21115
|
}
|
|
@@ -21104,11 +21155,24 @@ var isLinkedinAuthenticated = async (page) => {
|
|
|
21104
21155
|
return false;
|
|
21105
21156
|
}
|
|
21106
21157
|
};
|
|
21158
|
+
var LINKEDIN_AUTH_COOKIE = "li_at";
|
|
21159
|
+
function hasLinkedinAuthCookie(cookies, nowMs = Date.now()) {
|
|
21160
|
+
return cookies.some((cookie) => cookie.name === LINKEDIN_AUTH_COOKIE && (cookie.value ?? "") !== "" && (cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs));
|
|
21161
|
+
}
|
|
21107
21162
|
var LINKEDIN_CONFIG = {
|
|
21108
21163
|
channel: TARGET,
|
|
21109
21164
|
homeUrl: LINKEDIN_HOME_URL,
|
|
21110
21165
|
isAuthenticated: isLinkedinAuthenticated,
|
|
21111
|
-
loginTimeoutMs: LOGIN_TIMEOUT_MS
|
|
21166
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21167
|
+
checkHeadedOnly: true,
|
|
21168
|
+
sessionState: {
|
|
21169
|
+
onAuthenticated: async ({ context }) => {
|
|
21170
|
+
const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => []);
|
|
21171
|
+
if (hasLinkedinAuthCookie(cookies))
|
|
21172
|
+
return;
|
|
21173
|
+
throw new Error(`the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` + `saved \u2014 confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`);
|
|
21174
|
+
}
|
|
21175
|
+
}
|
|
21112
21176
|
};
|
|
21113
21177
|
async function resolveImages(options, content) {
|
|
21114
21178
|
const rawImages = options?.images ?? content?.metadata?.images;
|
|
@@ -21145,11 +21209,13 @@ class LinkedinBrowserTransport {
|
|
|
21145
21209
|
operation;
|
|
21146
21210
|
launcher;
|
|
21147
21211
|
stepTimeoutMs;
|
|
21212
|
+
preflightTimeoutMs;
|
|
21148
21213
|
constructor(operation = "post", driver = "script", deps = {}) {
|
|
21149
21214
|
this.operation = operation;
|
|
21150
21215
|
this.driver = driver;
|
|
21151
21216
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21152
21217
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21218
|
+
this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21153
21219
|
}
|
|
21154
21220
|
async publish(payload) {
|
|
21155
21221
|
if (this.driver !== "script") {
|
|
@@ -21178,8 +21244,8 @@ class LinkedinBrowserTransport {
|
|
|
21178
21244
|
const session = await checkChannelSession(LINKEDIN_CONFIG, {
|
|
21179
21245
|
profileDir,
|
|
21180
21246
|
launcher: this.launcher,
|
|
21181
|
-
|
|
21182
|
-
timeoutMs: this.
|
|
21247
|
+
headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
|
|
21248
|
+
timeoutMs: this.preflightTimeoutMs
|
|
21183
21249
|
});
|
|
21184
21250
|
if (session.status !== "verified") {
|
|
21185
21251
|
return fail(`${TARGET} session preflight refused \u2014 run: ${LINKEDIN_LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
|
|
@@ -21207,9 +21273,9 @@ class LinkedinBrowserTransport {
|
|
|
21207
21273
|
label: "linkedin share box"
|
|
21208
21274
|
});
|
|
21209
21275
|
} catch {
|
|
21210
|
-
return
|
|
21276
|
+
return preSubmitFail(`linkedin share box not found on ${LINKEDIN_HOME_URL} (session may be logged out, or the selector drifted) \u2014 run: ${LINKEDIN_LOGIN_INSTRUCTION}`, "share-trigger", metadata);
|
|
21211
21277
|
}
|
|
21212
|
-
await page.locator(triggerSelector).first().click();
|
|
21278
|
+
await page.locator(triggerSelector).filter({ visible: true }).first().click();
|
|
21213
21279
|
let composerSelector;
|
|
21214
21280
|
try {
|
|
21215
21281
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
@@ -21222,14 +21288,18 @@ class LinkedinBrowserTransport {
|
|
|
21222
21288
|
label: "linkedin share box retry"
|
|
21223
21289
|
}).catch(() => null);
|
|
21224
21290
|
if (retryTrigger !== null)
|
|
21225
|
-
await page.locator(retryTrigger).first().click().catch(() => {});
|
|
21291
|
+
await page.locator(retryTrigger).filter({ visible: true }).first().click().catch(() => {});
|
|
21226
21292
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
21227
21293
|
timeoutMs: this.stepTimeoutMs,
|
|
21228
21294
|
label: "linkedin composer (after retry)"
|
|
21229
21295
|
}).catch(() => "");
|
|
21230
21296
|
}
|
|
21231
21297
|
if (composerSelector === "") {
|
|
21232
|
-
|
|
21298
|
+
const probe = await probeComposer(page, triggerSelector);
|
|
21299
|
+
const counts = Object.values(probe.candidates);
|
|
21300
|
+
const found = counts.every((n) => n === 0) ? "all 0" : counts.map((n, i) => `#${i}=${n}`).join(",");
|
|
21301
|
+
await Promise.resolve().then(() => page.screenshot({ path: "/tmp/kk-linkedin-composer-latest.png" })).catch(() => null);
|
|
21302
|
+
return stageFail(`linkedin composer did not open after the share box, twice \u2014 trigger ${probe.trigger} (matches ${probe.triggerMatches}, visible ${probe.triggerVisible}); composer candidates ${found}; url ${probe.url}; frames ${probe.frames} \u2014 run: ${LINKEDIN_LOGIN_INSTRUCTION}`, "composer", { ...metadata, composerProbe: probe, itcDelivery: { schemaVersion: 1, effect: "none" } });
|
|
21233
21303
|
}
|
|
21234
21304
|
const composer = page.locator(composerSelector).first();
|
|
21235
21305
|
if (typeof composer.pressSequentially === "function") {
|
|
@@ -21240,12 +21310,12 @@ class LinkedinBrowserTransport {
|
|
|
21240
21310
|
}
|
|
21241
21311
|
const readback = await this.requireReadback(page, composerSelector, text);
|
|
21242
21312
|
if (!readback.ok)
|
|
21243
|
-
return
|
|
21313
|
+
return preSubmitFail(readback.error, "text-readback", metadata);
|
|
21244
21314
|
const [image] = images;
|
|
21245
21315
|
if (image !== undefined) {
|
|
21246
21316
|
const uploaded = await this.uploadImage(page, image);
|
|
21247
21317
|
if (!uploaded.ok)
|
|
21248
|
-
return
|
|
21318
|
+
return preSubmitFail(uploaded.error, "image-upload", metadata);
|
|
21249
21319
|
} else {
|
|
21250
21320
|
await this.waitForLinkPreview(page, composerSelector, text);
|
|
21251
21321
|
}
|
|
@@ -21539,6 +21609,7 @@ if (import.meta.main) {
|
|
|
21539
21609
|
process.exit(await main2());
|
|
21540
21610
|
}
|
|
21541
21611
|
export {
|
|
21612
|
+
LINKEDIN_AUTH_COOKIE,
|
|
21542
21613
|
LINKEDIN_CONFIG,
|
|
21543
21614
|
LINKEDIN_HOME_URL,
|
|
21544
21615
|
LINKEDIN_LOGIN_INSTRUCTION,
|
|
@@ -21548,6 +21619,7 @@ export {
|
|
|
21548
21619
|
LinkedinBrowserTransport,
|
|
21549
21620
|
MAX_TEXT_CHARS,
|
|
21550
21621
|
getPublishTransport,
|
|
21622
|
+
hasLinkedinAuthCookie,
|
|
21551
21623
|
isLinkedinAuthenticated,
|
|
21552
21624
|
main2 as main,
|
|
21553
21625
|
processPublishIO,
|
|
@@ -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;
|
|
@@ -21117,6 +21149,7 @@ var LINKEDIN_LOGIN_URL_RE = /(\/authwall|\/login|\/checkpoint)/;
|
|
|
21117
21149
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
|
|
21118
21150
|
var LINKEDIN_POST_SELECTORS = {
|
|
21119
21151
|
shareTrigger: [
|
|
21152
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
21120
21153
|
'button:has-text("Start a post")',
|
|
21121
21154
|
'div[role="button"]:has-text("Start a post")',
|
|
21122
21155
|
'text="Start a post"',
|
|
@@ -21130,8 +21163,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21130
21163
|
'div[role="textbox"].tiptap',
|
|
21131
21164
|
".tiptap.ProseMirror",
|
|
21132
21165
|
'[role="dialog"] div[role="textbox"]',
|
|
21133
|
-
'div.editor-content[contenteditable="true"]'
|
|
21134
|
-
'div[role="textbox"][contenteditable="true"]'
|
|
21166
|
+
'div.editor-content[contenteditable="true"]'
|
|
21135
21167
|
],
|
|
21136
21168
|
mediaButton: [
|
|
21137
21169
|
'button[aria-label="Media"]',
|
|
@@ -21147,6 +21179,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21147
21179
|
]
|
|
21148
21180
|
};
|
|
21149
21181
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21182
|
+
var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
|
|
21150
21183
|
var isLinkedinAuthenticated = async (page) => {
|
|
21151
21184
|
if (LINKEDIN_LOGIN_URL_RE.test(page.url()))
|
|
21152
21185
|
return false;
|
|
@@ -21159,11 +21192,24 @@ var isLinkedinAuthenticated = async (page) => {
|
|
|
21159
21192
|
return false;
|
|
21160
21193
|
}
|
|
21161
21194
|
};
|
|
21195
|
+
var LINKEDIN_AUTH_COOKIE = "li_at";
|
|
21196
|
+
function hasLinkedinAuthCookie(cookies, nowMs = Date.now()) {
|
|
21197
|
+
return cookies.some((cookie) => cookie.name === LINKEDIN_AUTH_COOKIE && (cookie.value ?? "") !== "" && (cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs));
|
|
21198
|
+
}
|
|
21162
21199
|
var LINKEDIN_CONFIG = {
|
|
21163
21200
|
channel: TARGET,
|
|
21164
21201
|
homeUrl: LINKEDIN_HOME_URL,
|
|
21165
21202
|
isAuthenticated: isLinkedinAuthenticated,
|
|
21166
|
-
loginTimeoutMs: LOGIN_TIMEOUT_MS
|
|
21203
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21204
|
+
checkHeadedOnly: true,
|
|
21205
|
+
sessionState: {
|
|
21206
|
+
onAuthenticated: async ({ context }) => {
|
|
21207
|
+
const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => []);
|
|
21208
|
+
if (hasLinkedinAuthCookie(cookies))
|
|
21209
|
+
return;
|
|
21210
|
+
throw new Error(`the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` + `saved \u2014 confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`);
|
|
21211
|
+
}
|
|
21212
|
+
}
|
|
21167
21213
|
};
|
|
21168
21214
|
if (false) {}
|
|
21169
21215
|
|
|
@@ -85,6 +85,10 @@ export const LINKEDIN_POST_SELECTORS = {
|
|
|
85
85
|
// clicking THAT does not open the composer (the run then timed out in the composer stage and
|
|
86
86
|
// reported "composer did not open … selector drift"). The has-text forms hit the clickable
|
|
87
87
|
// ancestor; the text form stays last for the previous UI.
|
|
88
|
+
// Measured 2026-11-25 (0437 recon, `.spur/run/dogfood/2026-11-25-linkedin/`): no `<button>` carries
|
|
89
|
+
// the text any more — the one visible trigger is `div[role=button][aria-label="Start a post"]`
|
|
90
|
+
// with obfuscated classes. The exact aria form leads so no descendant-text match can win.
|
|
91
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
88
92
|
'button:has-text("Start a post")',
|
|
89
93
|
'div[role="button"]:has-text("Start a post")',
|
|
90
94
|
'text="Start a post"',
|
|
@@ -101,7 +105,6 @@ export const LINKEDIN_POST_SELECTORS = {
|
|
|
101
105
|
'.tiptap.ProseMirror',
|
|
102
106
|
'[role="dialog"] div[role="textbox"]',
|
|
103
107
|
'div.editor-content[contenteditable="true"]',
|
|
104
|
-
'div[role="textbox"][contenteditable="true"]',
|
|
105
108
|
],
|
|
106
109
|
mediaButton: [
|
|
107
110
|
'button[aria-label="Media"]',
|
|
@@ -134,6 +137,15 @@ const PREVIEW_POLL_MS = 250;
|
|
|
134
137
|
const LINK_PREVIEW_TIMEOUT_MS = 10_000;
|
|
135
138
|
|
|
136
139
|
const STEP_TIMEOUT_MS = 30_000;
|
|
140
|
+
/**
|
|
141
|
+
* Default budget for the read-only session preflight. The harness subtracts a print margin and a
|
|
142
|
+
* launch reserve from whatever it is given, so the 30 s STEP_TIMEOUT_MS became an ~18 s pass — and on
|
|
143
|
+
* 2026-11-24 that was short enough that a freshly signed-in profile reported "not confirmed", after
|
|
144
|
+
* which LinkedIn cleared `li_at` and the sign-in was lost. 90 s covers a cold headed feed load.
|
|
145
|
+
* An explicit `stepTimeoutMs` dep overrides it, so tests and callers that tune the step budget also
|
|
146
|
+
* tune the preflight.
|
|
147
|
+
*/
|
|
148
|
+
const PREFLIGHT_TIMEOUT_MS = 90_000;
|
|
137
149
|
const LOGIN_TIMEOUT_MS = 180_000;
|
|
138
150
|
/** Operator recovery command every session failure names — never a cookie, DOM dump or stack. */
|
|
139
151
|
export const LINKEDIN_LOGIN_INSTRUCTION = 'bun plugins/publishings/linkedin-pub/src/profile-check.ts login';
|
|
@@ -154,6 +166,45 @@ function stageFail(error: string, stage: string, metadata: Record<string, unknow
|
|
|
154
166
|
});
|
|
155
167
|
}
|
|
156
168
|
|
|
169
|
+
/**
|
|
170
|
+
* A stage failure raised before the Post click: nothing reached LinkedIn, so the receipt is
|
|
171
|
+
* `failed/none` and `--retry` resends without `--confirm-none` (0437 R4; same marker as
|
|
172
|
+
* `weibo-pub`'s `refuse`). Never used at or after the Post click — those stay `effect: unknown`.
|
|
173
|
+
*/
|
|
174
|
+
function preSubmitFail(error: string, stage: string, metadata: Record<string, unknown>): Result {
|
|
175
|
+
return stageFail(error, stage, { ...metadata, itcDelivery: { schemaVersion: 1, effect: 'none' } });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* What the page held when the composer never opened (0437 R2): match counts of the trigger that was
|
|
180
|
+
* clicked, every composer candidate's count, the url and the frame count — so the next drift is
|
|
181
|
+
* diagnosable from the receipt alone. Counts only: no DOM text ever leaves the page.
|
|
182
|
+
*/
|
|
183
|
+
async function probeComposer(
|
|
184
|
+
page: Page,
|
|
185
|
+
trigger: string,
|
|
186
|
+
): Promise<{
|
|
187
|
+
trigger: string;
|
|
188
|
+
triggerMatches: number;
|
|
189
|
+
triggerVisible: number;
|
|
190
|
+
candidates: Record<string, number>;
|
|
191
|
+
url: string;
|
|
192
|
+
frames: number;
|
|
193
|
+
}> {
|
|
194
|
+
const count = (locator: { count(): Promise<number> }) => locator.count().catch(() => -1);
|
|
195
|
+
const triggerLocator = page.locator(trigger);
|
|
196
|
+
const candidates: Record<string, number> = {};
|
|
197
|
+
for (const selector of LINKEDIN_POST_SELECTORS.composer) candidates[selector] = await count(page.locator(selector));
|
|
198
|
+
return {
|
|
199
|
+
trigger,
|
|
200
|
+
triggerMatches: await count(triggerLocator),
|
|
201
|
+
triggerVisible: await count(triggerLocator.filter({ visible: true })),
|
|
202
|
+
candidates,
|
|
203
|
+
url: page.url(),
|
|
204
|
+
frames: typeof page.frames === 'function' ? page.frames().length : 0,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
157
208
|
/** One short line, bounded: no DOM dump, cookie, token or stack ever reaches the Result. */
|
|
158
209
|
function boundedDetail(detail: string): string {
|
|
159
210
|
return detail.replace(/\s+/g, ' ').trim().slice(0, 300);
|
|
@@ -229,6 +280,36 @@ export const isLinkedinAuthenticated: IsAuthenticatedPredicate = async (page) =>
|
|
|
229
280
|
}
|
|
230
281
|
};
|
|
231
282
|
|
|
283
|
+
/**
|
|
284
|
+
* LinkedIn's session ticket. The readiness predicate only sees the rendered page, so a profile can
|
|
285
|
+
* pass it and still carry no session at all — the measured 2026-11-24 shape was `li_at` at 0 rows
|
|
286
|
+
* (`select count(*) from cookies where name='li_at'`) after two separate operator sign-ins. Name
|
|
287
|
+
* only: this module never reads, logs or returns the value.
|
|
288
|
+
*/
|
|
289
|
+
export const LINKEDIN_AUTH_COOKIE = 'li_at';
|
|
290
|
+
|
|
291
|
+
/** The cookie facts this assertion reads — everything but the value. */
|
|
292
|
+
export interface StoredCookie {
|
|
293
|
+
name: string;
|
|
294
|
+
value?: string;
|
|
295
|
+
/** Seconds since the epoch; Playwright reports a session cookie as `-1`. */
|
|
296
|
+
expires?: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* `true` when the jar holds a usable {@link LINKEDIN_AUTH_COOKIE} (0436 R4). A non-empty value that
|
|
301
|
+
* has not expired is the whole test: an expired or empty ticket cannot authenticate anything, so
|
|
302
|
+
* reporting a login from it would leave exactly the profile every later check calls "expired".
|
|
303
|
+
*/
|
|
304
|
+
export function hasLinkedinAuthCookie(cookies: readonly StoredCookie[], nowMs: number = Date.now()): boolean {
|
|
305
|
+
return cookies.some(
|
|
306
|
+
(cookie) =>
|
|
307
|
+
cookie.name === LINKEDIN_AUTH_COOKIE &&
|
|
308
|
+
(cookie.value ?? '') !== '' &&
|
|
309
|
+
(cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
232
313
|
/**
|
|
233
314
|
* Site-owned config for the shared session check and operator CLI (ADR-032). The publish preflight
|
|
234
315
|
* never forwards a headed fallback: it is the operator CLI's setting, and a refusal must never
|
|
@@ -239,6 +320,28 @@ export const LINKEDIN_CONFIG: ChannelBrowserConfig = {
|
|
|
239
320
|
homeUrl: LINKEDIN_HOME_URL,
|
|
240
321
|
isAuthenticated: isLinkedinAuthenticated,
|
|
241
322
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
323
|
+
// Headless with a SIGNED-IN profile lands on the login wall (measured 2026-11-24: `check`
|
|
324
|
+
// refused in 68 s while `check --headed` verified on the same profile, and the same pair of
|
|
325
|
+
// launches repeated after two operator sign-ins). A headless preflight pass is therefore a
|
|
326
|
+
// guaranteed burn, and the post flow is headed anyway — so the preflight probes headed, the
|
|
327
|
+
// same shape medium-pub carries for its Cloudflare interstitial.
|
|
328
|
+
checkHeadedOnly: true,
|
|
329
|
+
// This channel has no `storageState` artifact — the profile's own cookie store is the session —
|
|
330
|
+
// so the hook is used as the post-login ASSERTION instead of a capture: a sign-in the page
|
|
331
|
+
// predicate accepted but that stored no auth ticket fails here, at the login that produced it,
|
|
332
|
+
// rather than silently leaving a profile every later `check` refuses (0436 R4). A hook throw
|
|
333
|
+
// already fails the verb and suppresses the `verified` verdict, so the bot parent promotes
|
|
334
|
+
// nothing. No cookie name/value pair is ever logged: the message names the cookie only.
|
|
335
|
+
sessionState: {
|
|
336
|
+
onAuthenticated: async ({ context }) => {
|
|
337
|
+
const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => [] as StoredCookie[]);
|
|
338
|
+
if (hasLinkedinAuthCookie(cookies)) return;
|
|
339
|
+
throw new Error(
|
|
340
|
+
`the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` +
|
|
341
|
+
`saved — confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`,
|
|
342
|
+
);
|
|
343
|
+
},
|
|
344
|
+
},
|
|
242
345
|
};
|
|
243
346
|
|
|
244
347
|
/**
|
|
@@ -294,6 +397,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
294
397
|
private readonly operation: LinkedinOperation;
|
|
295
398
|
private readonly launcher: BrowserLauncher;
|
|
296
399
|
private readonly stepTimeoutMs: number;
|
|
400
|
+
private readonly preflightTimeoutMs: number;
|
|
297
401
|
constructor(
|
|
298
402
|
operation: LinkedinOperation = 'post',
|
|
299
403
|
driver: BrowserDriver = 'script',
|
|
@@ -303,6 +407,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
303
407
|
this.driver = driver;
|
|
304
408
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
305
409
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
410
|
+
this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
306
411
|
}
|
|
307
412
|
|
|
308
413
|
/**
|
|
@@ -347,8 +452,9 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
347
452
|
const session = await checkChannelSession(LINKEDIN_CONFIG, {
|
|
348
453
|
profileDir,
|
|
349
454
|
launcher: this.launcher,
|
|
350
|
-
|
|
351
|
-
|
|
455
|
+
// Headed, not headless: see LINKEDIN_CONFIG.checkHeadedOnly (measured 2026-11-24).
|
|
456
|
+
headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
|
|
457
|
+
timeoutMs: this.preflightTimeoutMs,
|
|
352
458
|
});
|
|
353
459
|
if (session.status !== 'verified') {
|
|
354
460
|
// The recovery command leads the message: `fail()` bounds the line, and the operator's
|
|
@@ -409,13 +515,15 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
409
515
|
label: 'linkedin share box',
|
|
410
516
|
});
|
|
411
517
|
} catch {
|
|
412
|
-
return
|
|
518
|
+
return preSubmitFail(
|
|
413
519
|
`linkedin share box not found on ${LINKEDIN_HOME_URL} (session may be logged out, or the selector drifted) — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
|
|
414
520
|
'share-trigger',
|
|
415
521
|
metadata,
|
|
416
522
|
);
|
|
417
523
|
}
|
|
418
|
-
|
|
524
|
+
// Visible match only (0437 R1): `resolveSelector` resolves attached nodes, so a hidden duplicate
|
|
525
|
+
// can resolve first and swallow the click while the composer never opens.
|
|
526
|
+
await page.locator(triggerSelector).filter({ visible: true }).first().click();
|
|
419
527
|
|
|
420
528
|
// Modal editor. A missing editor after the click is the same loud typed refusal family.
|
|
421
529
|
// The share box is a React target that can be clicked before the feed finishes hydrating
|
|
@@ -435,6 +543,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
435
543
|
if (retryTrigger !== null)
|
|
436
544
|
await page
|
|
437
545
|
.locator(retryTrigger)
|
|
546
|
+
.filter({ visible: true })
|
|
438
547
|
.first()
|
|
439
548
|
.click()
|
|
440
549
|
.catch(() => {});
|
|
@@ -444,10 +553,18 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
444
553
|
}).catch(() => '');
|
|
445
554
|
}
|
|
446
555
|
if (composerSelector === '') {
|
|
556
|
+
const probe = await probeComposer(page, triggerSelector);
|
|
557
|
+
const counts = Object.values(probe.candidates);
|
|
558
|
+
const found = counts.every((n) => n === 0) ? 'all 0' : counts.map((n, i) => `#${i}=${n}`).join(',');
|
|
559
|
+
// Counts lead and the login hint trails inside the 300-char bound; the full selector→count
|
|
560
|
+
// map rides in `metadata.composerProbe`. The screenshot is the visual twin of the send stage's.
|
|
561
|
+
await Promise.resolve()
|
|
562
|
+
.then(() => page.screenshot({ path: '/tmp/kk-linkedin-composer-latest.png' }))
|
|
563
|
+
.catch(() => null);
|
|
447
564
|
return stageFail(
|
|
448
|
-
`linkedin composer did not open after the share box, twice (
|
|
565
|
+
`linkedin composer did not open after the share box, twice — trigger ${probe.trigger} (matches ${probe.triggerMatches}, visible ${probe.triggerVisible}); composer candidates ${found}; url ${probe.url}; frames ${probe.frames} — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
|
|
449
566
|
'composer',
|
|
450
|
-
metadata,
|
|
567
|
+
{ ...metadata, composerProbe: probe, itcDelivery: { schemaVersion: 1, effect: 'none' } },
|
|
451
568
|
);
|
|
452
569
|
}
|
|
453
570
|
const composer = page.locator(composerSelector).first();
|
|
@@ -463,7 +580,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
463
580
|
|
|
464
581
|
// Readback before anything else: a field the editor dropped must never be submitted.
|
|
465
582
|
const readback = await this.requireReadback(page, composerSelector, text);
|
|
466
|
-
if (!readback.ok) return
|
|
583
|
+
if (!readback.ok) return preSubmitFail(readback.error, 'text-readback', metadata);
|
|
467
584
|
|
|
468
585
|
// Image upload: confirmed landed; an unconfirmed upload refuses before submit — never a
|
|
469
586
|
// silent text-only post while an image was requested. When posting a URL with no image,
|
|
@@ -471,7 +588,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
471
588
|
const [image] = images;
|
|
472
589
|
if (image !== undefined) {
|
|
473
590
|
const uploaded = await this.uploadImage(page, image);
|
|
474
|
-
if (!uploaded.ok) return
|
|
591
|
+
if (!uploaded.ok) return preSubmitFail(uploaded.error, 'image-upload', metadata);
|
|
475
592
|
} else {
|
|
476
593
|
await this.waitForLinkPreview(page, composerSelector, text);
|
|
477
594
|
}
|