@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
|
@@ -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);
|
|
@@ -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);
|
|
@@ -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);
|
|
@@ -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);
|
|
@@ -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);
|
|
@@ -21009,6 +21040,7 @@ var MAX_IMAGES = 1;
|
|
|
21009
21040
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
|
|
21010
21041
|
var LINKEDIN_POST_SELECTORS = {
|
|
21011
21042
|
shareTrigger: [
|
|
21043
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
21012
21044
|
'button:has-text("Start a post")',
|
|
21013
21045
|
'div[role="button"]:has-text("Start a post")',
|
|
21014
21046
|
'text="Start a post"',
|
|
@@ -21022,8 +21054,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21022
21054
|
'div[role="textbox"].tiptap',
|
|
21023
21055
|
".tiptap.ProseMirror",
|
|
21024
21056
|
'[role="dialog"] div[role="textbox"]',
|
|
21025
|
-
'div.editor-content[contenteditable="true"]'
|
|
21026
|
-
'div[role="textbox"][contenteditable="true"]'
|
|
21057
|
+
'div.editor-content[contenteditable="true"]'
|
|
21027
21058
|
],
|
|
21028
21059
|
mediaButton: [
|
|
21029
21060
|
'button[aria-label="Media"]',
|
|
@@ -21046,6 +21077,7 @@ var PREVIEW_TIMEOUT_MS = 5000;
|
|
|
21046
21077
|
var PREVIEW_POLL_MS = 250;
|
|
21047
21078
|
var LINK_PREVIEW_TIMEOUT_MS = 1e4;
|
|
21048
21079
|
var STEP_TIMEOUT_MS = 30000;
|
|
21080
|
+
var PREFLIGHT_TIMEOUT_MS = 90000;
|
|
21049
21081
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21050
21082
|
var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
|
|
21051
21083
|
var EXCERPT_CHARS = 30;
|
|
@@ -21060,6 +21092,24 @@ function stageFail(error, stage, metadata, evidence) {
|
|
|
21060
21092
|
metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence: boundedDetail(evidence) } }
|
|
21061
21093
|
});
|
|
21062
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
|
+
}
|
|
21063
21113
|
function boundedDetail(detail) {
|
|
21064
21114
|
return detail.replace(/\s+/g, " ").trim().slice(0, 300);
|
|
21065
21115
|
}
|
|
@@ -21105,11 +21155,24 @@ var isLinkedinAuthenticated = async (page) => {
|
|
|
21105
21155
|
return false;
|
|
21106
21156
|
}
|
|
21107
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
|
+
}
|
|
21108
21162
|
var LINKEDIN_CONFIG = {
|
|
21109
21163
|
channel: TARGET,
|
|
21110
21164
|
homeUrl: LINKEDIN_HOME_URL,
|
|
21111
21165
|
isAuthenticated: isLinkedinAuthenticated,
|
|
21112
|
-
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
|
+
}
|
|
21113
21176
|
};
|
|
21114
21177
|
async function resolveImages(options, content) {
|
|
21115
21178
|
const rawImages = options?.images ?? content?.metadata?.images;
|
|
@@ -21146,11 +21209,13 @@ class LinkedinBrowserTransport {
|
|
|
21146
21209
|
operation;
|
|
21147
21210
|
launcher;
|
|
21148
21211
|
stepTimeoutMs;
|
|
21212
|
+
preflightTimeoutMs;
|
|
21149
21213
|
constructor(operation = "post", driver = "script", deps = {}) {
|
|
21150
21214
|
this.operation = operation;
|
|
21151
21215
|
this.driver = driver;
|
|
21152
21216
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21153
21217
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21218
|
+
this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21154
21219
|
}
|
|
21155
21220
|
async publish(payload) {
|
|
21156
21221
|
if (this.driver !== "script") {
|
|
@@ -21179,8 +21244,8 @@ class LinkedinBrowserTransport {
|
|
|
21179
21244
|
const session = await checkChannelSession(LINKEDIN_CONFIG, {
|
|
21180
21245
|
profileDir,
|
|
21181
21246
|
launcher: this.launcher,
|
|
21182
|
-
|
|
21183
|
-
timeoutMs: this.
|
|
21247
|
+
headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
|
|
21248
|
+
timeoutMs: this.preflightTimeoutMs
|
|
21184
21249
|
});
|
|
21185
21250
|
if (session.status !== "verified") {
|
|
21186
21251
|
return fail(`${TARGET} session preflight refused \u2014 run: ${LINKEDIN_LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
|
|
@@ -21208,9 +21273,9 @@ class LinkedinBrowserTransport {
|
|
|
21208
21273
|
label: "linkedin share box"
|
|
21209
21274
|
});
|
|
21210
21275
|
} catch {
|
|
21211
|
-
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);
|
|
21212
21277
|
}
|
|
21213
|
-
await page.locator(triggerSelector).first().click();
|
|
21278
|
+
await page.locator(triggerSelector).filter({ visible: true }).first().click();
|
|
21214
21279
|
let composerSelector;
|
|
21215
21280
|
try {
|
|
21216
21281
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
@@ -21223,14 +21288,18 @@ class LinkedinBrowserTransport {
|
|
|
21223
21288
|
label: "linkedin share box retry"
|
|
21224
21289
|
}).catch(() => null);
|
|
21225
21290
|
if (retryTrigger !== null)
|
|
21226
|
-
await page.locator(retryTrigger).first().click().catch(() => {});
|
|
21291
|
+
await page.locator(retryTrigger).filter({ visible: true }).first().click().catch(() => {});
|
|
21227
21292
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
21228
21293
|
timeoutMs: this.stepTimeoutMs,
|
|
21229
21294
|
label: "linkedin composer (after retry)"
|
|
21230
21295
|
}).catch(() => "");
|
|
21231
21296
|
}
|
|
21232
21297
|
if (composerSelector === "") {
|
|
21233
|
-
|
|
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" } });
|
|
21234
21303
|
}
|
|
21235
21304
|
const composer = page.locator(composerSelector).first();
|
|
21236
21305
|
if (typeof composer.pressSequentially === "function") {
|
|
@@ -21241,12 +21310,12 @@ class LinkedinBrowserTransport {
|
|
|
21241
21310
|
}
|
|
21242
21311
|
const readback = await this.requireReadback(page, composerSelector, text);
|
|
21243
21312
|
if (!readback.ok)
|
|
21244
|
-
return
|
|
21313
|
+
return preSubmitFail(readback.error, "text-readback", metadata);
|
|
21245
21314
|
const [image] = images;
|
|
21246
21315
|
if (image !== undefined) {
|
|
21247
21316
|
const uploaded = await this.uploadImage(page, image);
|
|
21248
21317
|
if (!uploaded.ok)
|
|
21249
|
-
return
|
|
21318
|
+
return preSubmitFail(uploaded.error, "image-upload", metadata);
|
|
21250
21319
|
} else {
|
|
21251
21320
|
await this.waitForLinkPreview(page, composerSelector, text);
|
|
21252
21321
|
}
|
|
@@ -21540,6 +21609,7 @@ if (import.meta.main) {
|
|
|
21540
21609
|
process.exit(await main2());
|
|
21541
21610
|
}
|
|
21542
21611
|
export {
|
|
21612
|
+
LINKEDIN_AUTH_COOKIE,
|
|
21543
21613
|
LINKEDIN_CONFIG,
|
|
21544
21614
|
LINKEDIN_HOME_URL,
|
|
21545
21615
|
LINKEDIN_LOGIN_INSTRUCTION,
|
|
@@ -21549,6 +21619,7 @@ export {
|
|
|
21549
21619
|
LinkedinBrowserTransport,
|
|
21550
21620
|
MAX_TEXT_CHARS,
|
|
21551
21621
|
getPublishTransport,
|
|
21622
|
+
hasLinkedinAuthCookie,
|
|
21552
21623
|
isLinkedinAuthenticated,
|
|
21553
21624
|
main2 as main,
|
|
21554
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,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);
|
|
@@ -21118,6 +21149,7 @@ var LINKEDIN_LOGIN_URL_RE = /(\/authwall|\/login|\/checkpoint)/;
|
|
|
21118
21149
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
|
|
21119
21150
|
var LINKEDIN_POST_SELECTORS = {
|
|
21120
21151
|
shareTrigger: [
|
|
21152
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
21121
21153
|
'button:has-text("Start a post")',
|
|
21122
21154
|
'div[role="button"]:has-text("Start a post")',
|
|
21123
21155
|
'text="Start a post"',
|
|
@@ -21131,8 +21163,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21131
21163
|
'div[role="textbox"].tiptap',
|
|
21132
21164
|
".tiptap.ProseMirror",
|
|
21133
21165
|
'[role="dialog"] div[role="textbox"]',
|
|
21134
|
-
'div.editor-content[contenteditable="true"]'
|
|
21135
|
-
'div[role="textbox"][contenteditable="true"]'
|
|
21166
|
+
'div.editor-content[contenteditable="true"]'
|
|
21136
21167
|
],
|
|
21137
21168
|
mediaButton: [
|
|
21138
21169
|
'button[aria-label="Media"]',
|
|
@@ -21148,6 +21179,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21148
21179
|
]
|
|
21149
21180
|
};
|
|
21150
21181
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21182
|
+
var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
|
|
21151
21183
|
var isLinkedinAuthenticated = async (page) => {
|
|
21152
21184
|
if (LINKEDIN_LOGIN_URL_RE.test(page.url()))
|
|
21153
21185
|
return false;
|
|
@@ -21160,11 +21192,24 @@ var isLinkedinAuthenticated = async (page) => {
|
|
|
21160
21192
|
return false;
|
|
21161
21193
|
}
|
|
21162
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
|
+
}
|
|
21163
21199
|
var LINKEDIN_CONFIG = {
|
|
21164
21200
|
channel: TARGET,
|
|
21165
21201
|
homeUrl: LINKEDIN_HOME_URL,
|
|
21166
21202
|
isAuthenticated: isLinkedinAuthenticated,
|
|
21167
|
-
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
|
+
}
|
|
21168
21213
|
};
|
|
21169
21214
|
if (false) {}
|
|
21170
21215
|
|