@gobing-ai/knowledge-kit 0.1.25 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +10 -0
- package/dist/board/daily-voice/index.js +1327 -2168
- package/dist/board/itc/index.js +10 -0
- package/dist/index.js +6043 -4620
- package/package.json +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +4 -1
- package/plugins/ingestions/aihot-ingest/src/rss.ts +22 -11
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +423 -141
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +114 -82
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +114 -82
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/csdn-pub/dist/index.js +114 -82
- package/plugins/publishings/csdn-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/infoq-pub/dist/index.js +114 -82
- package/plugins/publishings/infoq-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/jike-pub/dist/index.js +114 -82
- package/plugins/publishings/jike-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/juejin-pub/dist/index.js +114 -82
- package/plugins/publishings/juejin-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +165 -93
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +51 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +114 -82
- package/plugins/publishings/medium-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +305 -87
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +145 -5
- package/plugins/publishings/shipinhao-pub/src/cover-crop.ts +60 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +15 -2
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +15 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +22 -1
- package/plugins/publishings/sspai-pub/dist/index.js +114 -82
- package/plugins/publishings/sspai-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/substack-pub/dist/index.js +114 -82
- package/plugins/publishings/substack-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/surfdash-pub/dist/index.js +96 -20
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +119 -83
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +149 -86
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +68 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +273 -91
- package/plugins/publishings/weibo-pub/dist/profile-check.js +178 -11
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +136 -10
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +114 -82
- package/plugins/publishings/x-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xhs-pub/dist/index.js +114 -82
- package/plugins/publishings/xhs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +114 -82
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +34 -3
|
@@ -20171,6 +20171,86 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
|
|
|
20171
20171
|
import { homedir } from "os";
|
|
20172
20172
|
import { join, resolve } from "path";
|
|
20173
20173
|
|
|
20174
|
+
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20175
|
+
import {
|
|
20176
|
+
chmodSync,
|
|
20177
|
+
closeSync,
|
|
20178
|
+
copyFileSync,
|
|
20179
|
+
lstatSync,
|
|
20180
|
+
mkdirSync as mkdirSync2,
|
|
20181
|
+
openSync,
|
|
20182
|
+
readdirSync as readdirSync2,
|
|
20183
|
+
readlinkSync,
|
|
20184
|
+
realpathSync as realpathSync2,
|
|
20185
|
+
renameSync as renameSync2,
|
|
20186
|
+
rmdirSync,
|
|
20187
|
+
unlinkSync
|
|
20188
|
+
} from "fs";
|
|
20189
|
+
function lstat(path) {
|
|
20190
|
+
try {
|
|
20191
|
+
return lstatSync(path);
|
|
20192
|
+
} catch (error) {
|
|
20193
|
+
if (error.code === "ENOENT")
|
|
20194
|
+
return null;
|
|
20195
|
+
throw error;
|
|
20196
|
+
}
|
|
20197
|
+
}
|
|
20198
|
+
function realpath(path) {
|
|
20199
|
+
return realpathSync2(path);
|
|
20200
|
+
}
|
|
20201
|
+
function mkdirExclusive(path, mode = 448) {
|
|
20202
|
+
try {
|
|
20203
|
+
mkdirSync2(path, { mode });
|
|
20204
|
+
return true;
|
|
20205
|
+
} catch (error) {
|
|
20206
|
+
if (error.code === "EEXIST")
|
|
20207
|
+
return false;
|
|
20208
|
+
throw error;
|
|
20209
|
+
}
|
|
20210
|
+
}
|
|
20211
|
+
function rmdir(path) {
|
|
20212
|
+
try {
|
|
20213
|
+
rmdirSync(path);
|
|
20214
|
+
return true;
|
|
20215
|
+
} catch (error) {
|
|
20216
|
+
const code = error.code;
|
|
20217
|
+
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20218
|
+
return false;
|
|
20219
|
+
throw error;
|
|
20220
|
+
}
|
|
20221
|
+
}
|
|
20222
|
+
function readlink(path) {
|
|
20223
|
+
try {
|
|
20224
|
+
return readlinkSync(path);
|
|
20225
|
+
} catch {
|
|
20226
|
+
return null;
|
|
20227
|
+
}
|
|
20228
|
+
}
|
|
20229
|
+
function unlink(path) {
|
|
20230
|
+
try {
|
|
20231
|
+
unlinkSync(path);
|
|
20232
|
+
return true;
|
|
20233
|
+
} catch (error) {
|
|
20234
|
+
if (error.code === "ENOENT")
|
|
20235
|
+
return false;
|
|
20236
|
+
throw error;
|
|
20237
|
+
}
|
|
20238
|
+
}
|
|
20239
|
+
function rename(from, to) {
|
|
20240
|
+
try {
|
|
20241
|
+
renameSync2(from, to);
|
|
20242
|
+
return true;
|
|
20243
|
+
} catch (error) {
|
|
20244
|
+
if (error.code === "ENOENT")
|
|
20245
|
+
return false;
|
|
20246
|
+
throw error;
|
|
20247
|
+
}
|
|
20248
|
+
}
|
|
20249
|
+
function chmod(path, mode) {
|
|
20250
|
+
chmodSync(path, mode);
|
|
20251
|
+
}
|
|
20252
|
+
|
|
20253
|
+
// ../../packages/publish-harness/src/index.ts
|
|
20174
20254
|
class FakeTransportCore {
|
|
20175
20255
|
callLogs = [];
|
|
20176
20256
|
nextResult;
|
|
@@ -20455,85 +20535,6 @@ init_dist();
|
|
|
20455
20535
|
import { homedir as homedir4 } from "os";
|
|
20456
20536
|
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
20457
20537
|
|
|
20458
|
-
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20459
|
-
import {
|
|
20460
|
-
chmodSync,
|
|
20461
|
-
closeSync,
|
|
20462
|
-
copyFileSync,
|
|
20463
|
-
lstatSync,
|
|
20464
|
-
mkdirSync as mkdirSync2,
|
|
20465
|
-
openSync,
|
|
20466
|
-
readdirSync as readdirSync2,
|
|
20467
|
-
readlinkSync,
|
|
20468
|
-
realpathSync as realpathSync2,
|
|
20469
|
-
renameSync as renameSync2,
|
|
20470
|
-
rmdirSync,
|
|
20471
|
-
unlinkSync
|
|
20472
|
-
} from "fs";
|
|
20473
|
-
function lstat(path) {
|
|
20474
|
-
try {
|
|
20475
|
-
return lstatSync(path);
|
|
20476
|
-
} catch (error) {
|
|
20477
|
-
if (error.code === "ENOENT")
|
|
20478
|
-
return null;
|
|
20479
|
-
throw error;
|
|
20480
|
-
}
|
|
20481
|
-
}
|
|
20482
|
-
function realpath(path) {
|
|
20483
|
-
return realpathSync2(path);
|
|
20484
|
-
}
|
|
20485
|
-
function mkdirExclusive(path, mode = 448) {
|
|
20486
|
-
try {
|
|
20487
|
-
mkdirSync2(path, { mode });
|
|
20488
|
-
return true;
|
|
20489
|
-
} catch (error) {
|
|
20490
|
-
if (error.code === "EEXIST")
|
|
20491
|
-
return false;
|
|
20492
|
-
throw error;
|
|
20493
|
-
}
|
|
20494
|
-
}
|
|
20495
|
-
function rmdir(path) {
|
|
20496
|
-
try {
|
|
20497
|
-
rmdirSync(path);
|
|
20498
|
-
return true;
|
|
20499
|
-
} catch (error) {
|
|
20500
|
-
const code = error.code;
|
|
20501
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20502
|
-
return false;
|
|
20503
|
-
throw error;
|
|
20504
|
-
}
|
|
20505
|
-
}
|
|
20506
|
-
function readlink(path) {
|
|
20507
|
-
try {
|
|
20508
|
-
return readlinkSync(path);
|
|
20509
|
-
} catch {
|
|
20510
|
-
return null;
|
|
20511
|
-
}
|
|
20512
|
-
}
|
|
20513
|
-
function unlink(path) {
|
|
20514
|
-
try {
|
|
20515
|
-
unlinkSync(path);
|
|
20516
|
-
return true;
|
|
20517
|
-
} catch (error) {
|
|
20518
|
-
if (error.code === "ENOENT")
|
|
20519
|
-
return false;
|
|
20520
|
-
throw error;
|
|
20521
|
-
}
|
|
20522
|
-
}
|
|
20523
|
-
function rename(from, to) {
|
|
20524
|
-
try {
|
|
20525
|
-
renameSync2(from, to);
|
|
20526
|
-
return true;
|
|
20527
|
-
} catch (error) {
|
|
20528
|
-
if (error.code === "ENOENT")
|
|
20529
|
-
return false;
|
|
20530
|
-
throw error;
|
|
20531
|
-
}
|
|
20532
|
-
}
|
|
20533
|
-
function chmod(path, mode) {
|
|
20534
|
-
chmodSync(path, mode);
|
|
20535
|
-
}
|
|
20536
|
-
|
|
20537
20538
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20538
20539
|
import { homedir as homedir2 } from "os";
|
|
20539
20540
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
@@ -20558,7 +20559,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20558
20559
|
const leaseDir = join3(leaseRoot, id);
|
|
20559
20560
|
await fileSystem.ensureDir(leaseRoot);
|
|
20560
20561
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20561
|
-
|
|
20562
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20563
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20564
|
+
}
|
|
20565
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20566
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20567
|
+
}
|
|
20562
20568
|
}
|
|
20563
20569
|
const token = randomBytes(16).toString("hex");
|
|
20564
20570
|
const owner = {
|
|
@@ -20674,9 +20680,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20674
20680
|
}
|
|
20675
20681
|
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
20682
|
}
|
|
20677
|
-
const
|
|
20683
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20684
|
+
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
20685
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20679
20686
|
}
|
|
20687
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20688
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20689
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20690
|
+
return false;
|
|
20691
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20692
|
+
return false;
|
|
20693
|
+
const target = staleLeaseDir(leaseDir);
|
|
20694
|
+
try {
|
|
20695
|
+
rename(leaseDir, target);
|
|
20696
|
+
} catch {
|
|
20697
|
+
return false;
|
|
20698
|
+
}
|
|
20699
|
+
const moved = await readOwner(fileSystem, target);
|
|
20700
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20701
|
+
try {
|
|
20702
|
+
rename(target, leaseDir);
|
|
20703
|
+
} catch {}
|
|
20704
|
+
return false;
|
|
20705
|
+
}
|
|
20706
|
+
return true;
|
|
20707
|
+
}
|
|
20708
|
+
function staleLeaseDir(leaseDir) {
|
|
20709
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20710
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20711
|
+
}
|
|
20680
20712
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20681
20713
|
try {
|
|
20682
20714
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20802,7 +20834,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20802
20834
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20803
20835
|
if (lstat(syncData) === null)
|
|
20804
20836
|
return false;
|
|
20805
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20837
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20806
20838
|
}
|
|
20807
20839
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20808
20840
|
return {
|
|
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20219
20219
|
const leaseDir = join2(leaseRoot, id);
|
|
20220
20220
|
await fileSystem.ensureDir(leaseRoot);
|
|
20221
20221
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20222
|
-
|
|
20222
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20223
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20224
|
+
}
|
|
20225
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20226
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20227
|
+
}
|
|
20223
20228
|
}
|
|
20224
20229
|
const token = randomBytes(16).toString("hex");
|
|
20225
20230
|
const owner = {
|
|
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20335
20340
|
}
|
|
20336
20341
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20337
20342
|
}
|
|
20338
|
-
const
|
|
20343
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20344
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20339
20345
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20340
20346
|
}
|
|
20347
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20348
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20349
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20350
|
+
return false;
|
|
20351
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20352
|
+
return false;
|
|
20353
|
+
const target = staleLeaseDir(leaseDir);
|
|
20354
|
+
try {
|
|
20355
|
+
rename(leaseDir, target);
|
|
20356
|
+
} catch {
|
|
20357
|
+
return false;
|
|
20358
|
+
}
|
|
20359
|
+
const moved = await readOwner(fileSystem, target);
|
|
20360
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20361
|
+
try {
|
|
20362
|
+
rename(target, leaseDir);
|
|
20363
|
+
} catch {}
|
|
20364
|
+
return false;
|
|
20365
|
+
}
|
|
20366
|
+
return true;
|
|
20367
|
+
}
|
|
20368
|
+
function staleLeaseDir(leaseDir) {
|
|
20369
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20370
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20371
|
+
}
|
|
20341
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20342
20373
|
try {
|
|
20343
20374
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20506,7 +20537,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20506
20537
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20507
20538
|
if (lstat(syncData) === null)
|
|
20508
20539
|
return false;
|
|
20509
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20540
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20510
20541
|
}
|
|
20511
20542
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20512
20543
|
return {
|
|
@@ -20171,6 +20171,86 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
|
|
|
20171
20171
|
import { homedir } from "os";
|
|
20172
20172
|
import { join, resolve } from "path";
|
|
20173
20173
|
|
|
20174
|
+
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20175
|
+
import {
|
|
20176
|
+
chmodSync,
|
|
20177
|
+
closeSync,
|
|
20178
|
+
copyFileSync,
|
|
20179
|
+
lstatSync,
|
|
20180
|
+
mkdirSync as mkdirSync2,
|
|
20181
|
+
openSync,
|
|
20182
|
+
readdirSync as readdirSync2,
|
|
20183
|
+
readlinkSync,
|
|
20184
|
+
realpathSync as realpathSync2,
|
|
20185
|
+
renameSync as renameSync2,
|
|
20186
|
+
rmdirSync,
|
|
20187
|
+
unlinkSync
|
|
20188
|
+
} from "fs";
|
|
20189
|
+
function lstat(path) {
|
|
20190
|
+
try {
|
|
20191
|
+
return lstatSync(path);
|
|
20192
|
+
} catch (error) {
|
|
20193
|
+
if (error.code === "ENOENT")
|
|
20194
|
+
return null;
|
|
20195
|
+
throw error;
|
|
20196
|
+
}
|
|
20197
|
+
}
|
|
20198
|
+
function realpath(path) {
|
|
20199
|
+
return realpathSync2(path);
|
|
20200
|
+
}
|
|
20201
|
+
function mkdirExclusive(path, mode = 448) {
|
|
20202
|
+
try {
|
|
20203
|
+
mkdirSync2(path, { mode });
|
|
20204
|
+
return true;
|
|
20205
|
+
} catch (error) {
|
|
20206
|
+
if (error.code === "EEXIST")
|
|
20207
|
+
return false;
|
|
20208
|
+
throw error;
|
|
20209
|
+
}
|
|
20210
|
+
}
|
|
20211
|
+
function rmdir(path) {
|
|
20212
|
+
try {
|
|
20213
|
+
rmdirSync(path);
|
|
20214
|
+
return true;
|
|
20215
|
+
} catch (error) {
|
|
20216
|
+
const code = error.code;
|
|
20217
|
+
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20218
|
+
return false;
|
|
20219
|
+
throw error;
|
|
20220
|
+
}
|
|
20221
|
+
}
|
|
20222
|
+
function readlink(path) {
|
|
20223
|
+
try {
|
|
20224
|
+
return readlinkSync(path);
|
|
20225
|
+
} catch {
|
|
20226
|
+
return null;
|
|
20227
|
+
}
|
|
20228
|
+
}
|
|
20229
|
+
function unlink(path) {
|
|
20230
|
+
try {
|
|
20231
|
+
unlinkSync(path);
|
|
20232
|
+
return true;
|
|
20233
|
+
} catch (error) {
|
|
20234
|
+
if (error.code === "ENOENT")
|
|
20235
|
+
return false;
|
|
20236
|
+
throw error;
|
|
20237
|
+
}
|
|
20238
|
+
}
|
|
20239
|
+
function rename(from, to) {
|
|
20240
|
+
try {
|
|
20241
|
+
renameSync2(from, to);
|
|
20242
|
+
return true;
|
|
20243
|
+
} catch (error) {
|
|
20244
|
+
if (error.code === "ENOENT")
|
|
20245
|
+
return false;
|
|
20246
|
+
throw error;
|
|
20247
|
+
}
|
|
20248
|
+
}
|
|
20249
|
+
function chmod(path, mode) {
|
|
20250
|
+
chmodSync(path, mode);
|
|
20251
|
+
}
|
|
20252
|
+
|
|
20253
|
+
// ../../packages/publish-harness/src/index.ts
|
|
20174
20254
|
class FakeTransportCore {
|
|
20175
20255
|
callLogs = [];
|
|
20176
20256
|
nextResult;
|
|
@@ -20455,85 +20535,6 @@ init_dist();
|
|
|
20455
20535
|
import { homedir as homedir4 } from "os";
|
|
20456
20536
|
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
20457
20537
|
|
|
20458
|
-
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20459
|
-
import {
|
|
20460
|
-
chmodSync,
|
|
20461
|
-
closeSync,
|
|
20462
|
-
copyFileSync,
|
|
20463
|
-
lstatSync,
|
|
20464
|
-
mkdirSync as mkdirSync2,
|
|
20465
|
-
openSync,
|
|
20466
|
-
readdirSync as readdirSync2,
|
|
20467
|
-
readlinkSync,
|
|
20468
|
-
realpathSync as realpathSync2,
|
|
20469
|
-
renameSync as renameSync2,
|
|
20470
|
-
rmdirSync,
|
|
20471
|
-
unlinkSync
|
|
20472
|
-
} from "fs";
|
|
20473
|
-
function lstat(path) {
|
|
20474
|
-
try {
|
|
20475
|
-
return lstatSync(path);
|
|
20476
|
-
} catch (error) {
|
|
20477
|
-
if (error.code === "ENOENT")
|
|
20478
|
-
return null;
|
|
20479
|
-
throw error;
|
|
20480
|
-
}
|
|
20481
|
-
}
|
|
20482
|
-
function realpath(path) {
|
|
20483
|
-
return realpathSync2(path);
|
|
20484
|
-
}
|
|
20485
|
-
function mkdirExclusive(path, mode = 448) {
|
|
20486
|
-
try {
|
|
20487
|
-
mkdirSync2(path, { mode });
|
|
20488
|
-
return true;
|
|
20489
|
-
} catch (error) {
|
|
20490
|
-
if (error.code === "EEXIST")
|
|
20491
|
-
return false;
|
|
20492
|
-
throw error;
|
|
20493
|
-
}
|
|
20494
|
-
}
|
|
20495
|
-
function rmdir(path) {
|
|
20496
|
-
try {
|
|
20497
|
-
rmdirSync(path);
|
|
20498
|
-
return true;
|
|
20499
|
-
} catch (error) {
|
|
20500
|
-
const code = error.code;
|
|
20501
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20502
|
-
return false;
|
|
20503
|
-
throw error;
|
|
20504
|
-
}
|
|
20505
|
-
}
|
|
20506
|
-
function readlink(path) {
|
|
20507
|
-
try {
|
|
20508
|
-
return readlinkSync(path);
|
|
20509
|
-
} catch {
|
|
20510
|
-
return null;
|
|
20511
|
-
}
|
|
20512
|
-
}
|
|
20513
|
-
function unlink(path) {
|
|
20514
|
-
try {
|
|
20515
|
-
unlinkSync(path);
|
|
20516
|
-
return true;
|
|
20517
|
-
} catch (error) {
|
|
20518
|
-
if (error.code === "ENOENT")
|
|
20519
|
-
return false;
|
|
20520
|
-
throw error;
|
|
20521
|
-
}
|
|
20522
|
-
}
|
|
20523
|
-
function rename(from, to) {
|
|
20524
|
-
try {
|
|
20525
|
-
renameSync2(from, to);
|
|
20526
|
-
return true;
|
|
20527
|
-
} catch (error) {
|
|
20528
|
-
if (error.code === "ENOENT")
|
|
20529
|
-
return false;
|
|
20530
|
-
throw error;
|
|
20531
|
-
}
|
|
20532
|
-
}
|
|
20533
|
-
function chmod(path, mode) {
|
|
20534
|
-
chmodSync(path, mode);
|
|
20535
|
-
}
|
|
20536
|
-
|
|
20537
20538
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20538
20539
|
import { homedir as homedir2 } from "os";
|
|
20539
20540
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
@@ -20558,7 +20559,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20558
20559
|
const leaseDir = join3(leaseRoot, id);
|
|
20559
20560
|
await fileSystem.ensureDir(leaseRoot);
|
|
20560
20561
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20561
|
-
|
|
20562
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20563
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20564
|
+
}
|
|
20565
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20566
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20567
|
+
}
|
|
20562
20568
|
}
|
|
20563
20569
|
const token = randomBytes(16).toString("hex");
|
|
20564
20570
|
const owner = {
|
|
@@ -20674,9 +20680,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20674
20680
|
}
|
|
20675
20681
|
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
20682
|
}
|
|
20677
|
-
const
|
|
20683
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20684
|
+
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
20685
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20679
20686
|
}
|
|
20687
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20688
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20689
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20690
|
+
return false;
|
|
20691
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20692
|
+
return false;
|
|
20693
|
+
const target = staleLeaseDir(leaseDir);
|
|
20694
|
+
try {
|
|
20695
|
+
rename(leaseDir, target);
|
|
20696
|
+
} catch {
|
|
20697
|
+
return false;
|
|
20698
|
+
}
|
|
20699
|
+
const moved = await readOwner(fileSystem, target);
|
|
20700
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20701
|
+
try {
|
|
20702
|
+
rename(target, leaseDir);
|
|
20703
|
+
} catch {}
|
|
20704
|
+
return false;
|
|
20705
|
+
}
|
|
20706
|
+
return true;
|
|
20707
|
+
}
|
|
20708
|
+
function staleLeaseDir(leaseDir) {
|
|
20709
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20710
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20711
|
+
}
|
|
20680
20712
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20681
20713
|
try {
|
|
20682
20714
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20802,7 +20834,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20802
20834
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20803
20835
|
if (lstat(syncData) === null)
|
|
20804
20836
|
return false;
|
|
20805
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20837
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20806
20838
|
}
|
|
20807
20839
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20808
20840
|
return {
|
|
@@ -21009,6 +21041,7 @@ var MAX_IMAGES = 1;
|
|
|
21009
21041
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
|
|
21010
21042
|
var LINKEDIN_POST_SELECTORS = {
|
|
21011
21043
|
shareTrigger: [
|
|
21044
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
21012
21045
|
'button:has-text("Start a post")',
|
|
21013
21046
|
'div[role="button"]:has-text("Start a post")',
|
|
21014
21047
|
'text="Start a post"',
|
|
@@ -21022,8 +21055,7 @@ var LINKEDIN_POST_SELECTORS = {
|
|
|
21022
21055
|
'div[role="textbox"].tiptap',
|
|
21023
21056
|
".tiptap.ProseMirror",
|
|
21024
21057
|
'[role="dialog"] div[role="textbox"]',
|
|
21025
|
-
'div.editor-content[contenteditable="true"]'
|
|
21026
|
-
'div[role="textbox"][contenteditable="true"]'
|
|
21058
|
+
'div.editor-content[contenteditable="true"]'
|
|
21027
21059
|
],
|
|
21028
21060
|
mediaButton: [
|
|
21029
21061
|
'button[aria-label="Media"]',
|
|
@@ -21046,6 +21078,7 @@ var PREVIEW_TIMEOUT_MS = 5000;
|
|
|
21046
21078
|
var PREVIEW_POLL_MS = 250;
|
|
21047
21079
|
var LINK_PREVIEW_TIMEOUT_MS = 1e4;
|
|
21048
21080
|
var STEP_TIMEOUT_MS = 30000;
|
|
21081
|
+
var PREFLIGHT_TIMEOUT_MS = 90000;
|
|
21049
21082
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21050
21083
|
var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
|
|
21051
21084
|
var EXCERPT_CHARS = 30;
|
|
@@ -21060,6 +21093,24 @@ function stageFail(error, stage, metadata, evidence) {
|
|
|
21060
21093
|
metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence: boundedDetail(evidence) } }
|
|
21061
21094
|
});
|
|
21062
21095
|
}
|
|
21096
|
+
function preSubmitFail(error, stage, metadata) {
|
|
21097
|
+
return stageFail(error, stage, { ...metadata, itcDelivery: { schemaVersion: 1, effect: "none" } });
|
|
21098
|
+
}
|
|
21099
|
+
async function probeComposer(page, trigger) {
|
|
21100
|
+
const count = (locator) => locator.count().catch(() => -1);
|
|
21101
|
+
const triggerLocator = page.locator(trigger);
|
|
21102
|
+
const candidates = {};
|
|
21103
|
+
for (const selector of LINKEDIN_POST_SELECTORS.composer)
|
|
21104
|
+
candidates[selector] = await count(page.locator(selector));
|
|
21105
|
+
return {
|
|
21106
|
+
trigger,
|
|
21107
|
+
triggerMatches: await count(triggerLocator),
|
|
21108
|
+
triggerVisible: await count(triggerLocator.filter({ visible: true })),
|
|
21109
|
+
candidates,
|
|
21110
|
+
url: page.url(),
|
|
21111
|
+
frames: typeof page.frames === "function" ? page.frames().length : 0
|
|
21112
|
+
};
|
|
21113
|
+
}
|
|
21063
21114
|
function boundedDetail(detail) {
|
|
21064
21115
|
return detail.replace(/\s+/g, " ").trim().slice(0, 300);
|
|
21065
21116
|
}
|
|
@@ -21105,11 +21156,24 @@ var isLinkedinAuthenticated = async (page) => {
|
|
|
21105
21156
|
return false;
|
|
21106
21157
|
}
|
|
21107
21158
|
};
|
|
21159
|
+
var LINKEDIN_AUTH_COOKIE = "li_at";
|
|
21160
|
+
function hasLinkedinAuthCookie(cookies, nowMs = Date.now()) {
|
|
21161
|
+
return cookies.some((cookie) => cookie.name === LINKEDIN_AUTH_COOKIE && (cookie.value ?? "") !== "" && (cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs));
|
|
21162
|
+
}
|
|
21108
21163
|
var LINKEDIN_CONFIG = {
|
|
21109
21164
|
channel: TARGET,
|
|
21110
21165
|
homeUrl: LINKEDIN_HOME_URL,
|
|
21111
21166
|
isAuthenticated: isLinkedinAuthenticated,
|
|
21112
|
-
loginTimeoutMs: LOGIN_TIMEOUT_MS
|
|
21167
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21168
|
+
checkHeadedOnly: true,
|
|
21169
|
+
sessionState: {
|
|
21170
|
+
onAuthenticated: async ({ context }) => {
|
|
21171
|
+
const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => []);
|
|
21172
|
+
if (hasLinkedinAuthCookie(cookies))
|
|
21173
|
+
return;
|
|
21174
|
+
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`);
|
|
21175
|
+
}
|
|
21176
|
+
}
|
|
21113
21177
|
};
|
|
21114
21178
|
async function resolveImages(options, content) {
|
|
21115
21179
|
const rawImages = options?.images ?? content?.metadata?.images;
|
|
@@ -21146,11 +21210,13 @@ class LinkedinBrowserTransport {
|
|
|
21146
21210
|
operation;
|
|
21147
21211
|
launcher;
|
|
21148
21212
|
stepTimeoutMs;
|
|
21213
|
+
preflightTimeoutMs;
|
|
21149
21214
|
constructor(operation = "post", driver = "script", deps = {}) {
|
|
21150
21215
|
this.operation = operation;
|
|
21151
21216
|
this.driver = driver;
|
|
21152
21217
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21153
21218
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21219
|
+
this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21154
21220
|
}
|
|
21155
21221
|
async publish(payload) {
|
|
21156
21222
|
if (this.driver !== "script") {
|
|
@@ -21179,8 +21245,8 @@ class LinkedinBrowserTransport {
|
|
|
21179
21245
|
const session = await checkChannelSession(LINKEDIN_CONFIG, {
|
|
21180
21246
|
profileDir,
|
|
21181
21247
|
launcher: this.launcher,
|
|
21182
|
-
|
|
21183
|
-
timeoutMs: this.
|
|
21248
|
+
headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
|
|
21249
|
+
timeoutMs: this.preflightTimeoutMs
|
|
21184
21250
|
});
|
|
21185
21251
|
if (session.status !== "verified") {
|
|
21186
21252
|
return fail(`${TARGET} session preflight refused \u2014 run: ${LINKEDIN_LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
|
|
@@ -21208,9 +21274,9 @@ class LinkedinBrowserTransport {
|
|
|
21208
21274
|
label: "linkedin share box"
|
|
21209
21275
|
});
|
|
21210
21276
|
} catch {
|
|
21211
|
-
return
|
|
21277
|
+
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
21278
|
}
|
|
21213
|
-
await page.locator(triggerSelector).first().click();
|
|
21279
|
+
await page.locator(triggerSelector).filter({ visible: true }).first().click();
|
|
21214
21280
|
let composerSelector;
|
|
21215
21281
|
try {
|
|
21216
21282
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
@@ -21223,14 +21289,18 @@ class LinkedinBrowserTransport {
|
|
|
21223
21289
|
label: "linkedin share box retry"
|
|
21224
21290
|
}).catch(() => null);
|
|
21225
21291
|
if (retryTrigger !== null)
|
|
21226
|
-
await page.locator(retryTrigger).first().click().catch(() => {});
|
|
21292
|
+
await page.locator(retryTrigger).filter({ visible: true }).first().click().catch(() => {});
|
|
21227
21293
|
composerSelector = await resolveSelector(page, LINKEDIN_POST_SELECTORS.composer, {
|
|
21228
21294
|
timeoutMs: this.stepTimeoutMs,
|
|
21229
21295
|
label: "linkedin composer (after retry)"
|
|
21230
21296
|
}).catch(() => "");
|
|
21231
21297
|
}
|
|
21232
21298
|
if (composerSelector === "") {
|
|
21233
|
-
|
|
21299
|
+
const probe = await probeComposer(page, triggerSelector);
|
|
21300
|
+
const counts = Object.values(probe.candidates);
|
|
21301
|
+
const found = counts.every((n) => n === 0) ? "all 0" : counts.map((n, i) => `#${i}=${n}`).join(",");
|
|
21302
|
+
await Promise.resolve().then(() => page.screenshot({ path: "/tmp/kk-linkedin-composer-latest.png" })).catch(() => null);
|
|
21303
|
+
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
21304
|
}
|
|
21235
21305
|
const composer = page.locator(composerSelector).first();
|
|
21236
21306
|
if (typeof composer.pressSequentially === "function") {
|
|
@@ -21241,12 +21311,12 @@ class LinkedinBrowserTransport {
|
|
|
21241
21311
|
}
|
|
21242
21312
|
const readback = await this.requireReadback(page, composerSelector, text);
|
|
21243
21313
|
if (!readback.ok)
|
|
21244
|
-
return
|
|
21314
|
+
return preSubmitFail(readback.error, "text-readback", metadata);
|
|
21245
21315
|
const [image] = images;
|
|
21246
21316
|
if (image !== undefined) {
|
|
21247
21317
|
const uploaded = await this.uploadImage(page, image);
|
|
21248
21318
|
if (!uploaded.ok)
|
|
21249
|
-
return
|
|
21319
|
+
return preSubmitFail(uploaded.error, "image-upload", metadata);
|
|
21250
21320
|
} else {
|
|
21251
21321
|
await this.waitForLinkPreview(page, composerSelector, text);
|
|
21252
21322
|
}
|
|
@@ -21540,6 +21610,7 @@ if (import.meta.main) {
|
|
|
21540
21610
|
process.exit(await main2());
|
|
21541
21611
|
}
|
|
21542
21612
|
export {
|
|
21613
|
+
LINKEDIN_AUTH_COOKIE,
|
|
21543
21614
|
LINKEDIN_CONFIG,
|
|
21544
21615
|
LINKEDIN_HOME_URL,
|
|
21545
21616
|
LINKEDIN_LOGIN_INSTRUCTION,
|
|
@@ -21549,6 +21620,7 @@ export {
|
|
|
21549
21620
|
LinkedinBrowserTransport,
|
|
21550
21621
|
MAX_TEXT_CHARS,
|
|
21551
21622
|
getPublishTransport,
|
|
21623
|
+
hasLinkedinAuthCookie,
|
|
21552
21624
|
isLinkedinAuthenticated,
|
|
21553
21625
|
main2 as main,
|
|
21554
21626
|
processPublishIO,
|