@gobing-ai/knowledge-kit 0.1.16 → 0.1.17
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 +162 -39
- package/package.json +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +8 -8
- package/plugins/kk/publish-presets/itc-main.json +42 -0
- package/plugins/kk/scripts/cover-compositor.ts +54 -8
- package/plugins/kk/scripts/itc-stages.ts +3 -2
- package/plugins/kk/scripts/voice3-publish-window.ts +5 -1
- package/plugins/kk/workflows/kk-daily-publish3.yaml +10 -3
- package/plugins/publishings/bilibili-pub/dist/index.js +89 -16
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/cnblogs-pub/dist/index.js +89 -16
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/csdn-pub/dist/index.js +89 -16
- package/plugins/publishings/csdn-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/infoq-pub/dist/index.js +119 -18
- package/plugins/publishings/infoq-pub/dist/profile-check.js +94 -17
- package/plugins/publishings/infoq-pub/src/index.ts +40 -1
- package/plugins/publishings/jike-pub/dist/index.js +89 -16
- package/plugins/publishings/jike-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/juejin-pub/dist/index.js +116 -19
- package/plugins/publishings/juejin-pub/dist/profile-check.js +93 -17
- package/plugins/publishings/juejin-pub/src/index.ts +41 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +89 -16
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/shipinhao-pub/dist/index.js +89 -16
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/sspai-pub/dist/index.js +89 -16
- package/plugins/publishings/sspai-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/substack-pub/dist/index.js +89 -16
- package/plugins/publishings/substack-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/surfdash-pub/dist/index.js +9 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +17 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +176 -32
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +95 -18
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +14 -2
- package/plugins/publishings/wechatmp-pub/src/flow.ts +155 -21
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +8 -1
- package/plugins/publishings/weibo-pub/dist/index.js +89 -16
- package/plugins/publishings/weibo-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/x-pub/dist/index.js +89 -16
- package/plugins/publishings/x-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/xhs-pub/dist/index.js +89 -16
- package/plugins/publishings/xhs-pub/dist/profile-check.js +89 -16
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +89 -16
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/zenn-pub/dist/index.js +93 -1
- package/plugins/publishings/zenn-pub/src/index.ts +134 -1
|
@@ -20464,8 +20464,11 @@ import {
|
|
|
20464
20464
|
mkdirSync as mkdirSync2,
|
|
20465
20465
|
openSync,
|
|
20466
20466
|
readdirSync as readdirSync2,
|
|
20467
|
+
readlinkSync,
|
|
20467
20468
|
realpathSync as realpathSync2,
|
|
20468
|
-
|
|
20469
|
+
renameSync as renameSync2,
|
|
20470
|
+
rmdirSync,
|
|
20471
|
+
unlinkSync
|
|
20469
20472
|
} from "fs";
|
|
20470
20473
|
function lstat(path) {
|
|
20471
20474
|
try {
|
|
@@ -20500,6 +20503,33 @@ function rmdir(path) {
|
|
|
20500
20503
|
throw error;
|
|
20501
20504
|
}
|
|
20502
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
|
+
}
|
|
20503
20533
|
function chmod(path, mode) {
|
|
20504
20534
|
chmodSync(path, mode);
|
|
20505
20535
|
}
|
|
@@ -20511,14 +20541,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-t
|
|
|
20511
20541
|
|
|
20512
20542
|
// ../../packages/publish-harness/src/profile-lease.ts
|
|
20513
20543
|
import { createHash, randomBytes } from "crypto";
|
|
20514
|
-
import { homedir as homedir3 } from "os";
|
|
20544
|
+
import { homedir as homedir3, hostname } from "os";
|
|
20515
20545
|
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
20516
20546
|
var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
|
|
20517
20547
|
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
20518
20548
|
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
20519
20549
|
var OWNER_FILE = "owner.json";
|
|
20520
20550
|
var HOLDER_PREFIX = "holder-";
|
|
20521
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
|
|
20551
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
20522
20552
|
async function acquireProfileLease(profileDir, options = {}) {
|
|
20523
20553
|
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
20524
20554
|
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
@@ -20686,6 +20716,8 @@ function isProcessAlive(pid) {
|
|
|
20686
20716
|
}
|
|
20687
20717
|
}
|
|
20688
20718
|
function refuseNativeLock(profileDir) {
|
|
20719
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
20720
|
+
return;
|
|
20689
20721
|
for (const name of NATIVE_LOCK_FILES) {
|
|
20690
20722
|
const path = join3(profileDir, name);
|
|
20691
20723
|
if (lstat(path) !== null) {
|
|
@@ -20693,6 +20725,24 @@ function refuseNativeLock(profileDir) {
|
|
|
20693
20725
|
}
|
|
20694
20726
|
}
|
|
20695
20727
|
}
|
|
20728
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
20729
|
+
const lockPath = join3(profileDir, "SingletonLock");
|
|
20730
|
+
const target = readlink(lockPath);
|
|
20731
|
+
if (target === null)
|
|
20732
|
+
return false;
|
|
20733
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
20734
|
+
if (match === null)
|
|
20735
|
+
return false;
|
|
20736
|
+
const [, host, pidText] = match;
|
|
20737
|
+
if (host !== hostname())
|
|
20738
|
+
return false;
|
|
20739
|
+
const pid = Number(pidText);
|
|
20740
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
20741
|
+
return false;
|
|
20742
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
20743
|
+
unlink(join3(profileDir, name));
|
|
20744
|
+
return true;
|
|
20745
|
+
}
|
|
20696
20746
|
function sha256Hex(value) {
|
|
20697
20747
|
return createHash("sha256").update(value).digest("hex");
|
|
20698
20748
|
}
|
|
@@ -20729,6 +20779,27 @@ var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
|
20729
20779
|
var DEFAULT_STEP_TIMEOUT_MS = 30000;
|
|
20730
20780
|
var DEFAULT_POLL_MS = 500;
|
|
20731
20781
|
var ATTACH_POLL_MS = 100;
|
|
20782
|
+
function isInstantBrowserDeath(message) {
|
|
20783
|
+
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20784
|
+
}
|
|
20785
|
+
function classifyLaunchError(error, profileDir, channel) {
|
|
20786
|
+
const message = errorMessage2(error);
|
|
20787
|
+
if (/singleton|already in use|in use by another/i.test(message))
|
|
20788
|
+
return new BrowserProfileBusyError(profileDir, error);
|
|
20789
|
+
if (/playwright install|executable doesn't exist/i.test(message)) {
|
|
20790
|
+
return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
|
|
20791
|
+
}
|
|
20792
|
+
if (isInstantBrowserDeath(message)) {
|
|
20793
|
+
return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
|
|
20794
|
+
}
|
|
20795
|
+
return error instanceof Error ? error : new Error(message);
|
|
20796
|
+
}
|
|
20797
|
+
function quarantineProfileSyncData(profileDir) {
|
|
20798
|
+
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20799
|
+
if (lstat(syncData) === null)
|
|
20800
|
+
return false;
|
|
20801
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
|
|
20802
|
+
}
|
|
20732
20803
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20733
20804
|
return {
|
|
20734
20805
|
async launch(request) {
|
|
@@ -20757,23 +20828,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
|
|
|
20757
20828
|
throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
|
|
20758
20829
|
}
|
|
20759
20830
|
const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
|
|
20831
|
+
const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
|
|
20832
|
+
headless,
|
|
20833
|
+
channel,
|
|
20834
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
20835
|
+
ignoreDefaultArgs: ["--enable-automation"]
|
|
20836
|
+
});
|
|
20760
20837
|
let context;
|
|
20761
20838
|
try {
|
|
20762
|
-
context = await
|
|
20763
|
-
headless,
|
|
20764
|
-
channel,
|
|
20765
|
-
args: ["--disable-blink-features=AutomationControlled"],
|
|
20766
|
-
ignoreDefaultArgs: ["--enable-automation"]
|
|
20767
|
-
});
|
|
20839
|
+
context = await launch();
|
|
20768
20840
|
} catch (error) {
|
|
20769
|
-
|
|
20770
|
-
|
|
20771
|
-
|
|
20772
|
-
|
|
20773
|
-
|
|
20774
|
-
|
|
20841
|
+
if (!isInstantBrowserDeath(errorMessage2(error)))
|
|
20842
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20843
|
+
if (!quarantineProfileSyncData(profileDir))
|
|
20844
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20845
|
+
try {
|
|
20846
|
+
context = await launch();
|
|
20847
|
+
} catch (retryError) {
|
|
20848
|
+
throw classifyLaunchError(retryError, profileDir, channel);
|
|
20775
20849
|
}
|
|
20776
|
-
throw error;
|
|
20777
20850
|
}
|
|
20778
20851
|
try {
|
|
20779
20852
|
await context.addInitScript(() => {
|
|
@@ -20125,8 +20125,11 @@ import {
|
|
|
20125
20125
|
mkdirSync as mkdirSync2,
|
|
20126
20126
|
openSync,
|
|
20127
20127
|
readdirSync as readdirSync2,
|
|
20128
|
+
readlinkSync,
|
|
20128
20129
|
realpathSync as realpathSync2,
|
|
20129
|
-
|
|
20130
|
+
renameSync as renameSync2,
|
|
20131
|
+
rmdirSync,
|
|
20132
|
+
unlinkSync
|
|
20130
20133
|
} from "fs";
|
|
20131
20134
|
function lstat(path) {
|
|
20132
20135
|
try {
|
|
@@ -20161,6 +20164,33 @@ function rmdir(path) {
|
|
|
20161
20164
|
throw error;
|
|
20162
20165
|
}
|
|
20163
20166
|
}
|
|
20167
|
+
function readlink(path) {
|
|
20168
|
+
try {
|
|
20169
|
+
return readlinkSync(path);
|
|
20170
|
+
} catch {
|
|
20171
|
+
return null;
|
|
20172
|
+
}
|
|
20173
|
+
}
|
|
20174
|
+
function unlink(path) {
|
|
20175
|
+
try {
|
|
20176
|
+
unlinkSync(path);
|
|
20177
|
+
return true;
|
|
20178
|
+
} catch (error) {
|
|
20179
|
+
if (error.code === "ENOENT")
|
|
20180
|
+
return false;
|
|
20181
|
+
throw error;
|
|
20182
|
+
}
|
|
20183
|
+
}
|
|
20184
|
+
function rename(from, to) {
|
|
20185
|
+
try {
|
|
20186
|
+
renameSync2(from, to);
|
|
20187
|
+
return true;
|
|
20188
|
+
} catch (error) {
|
|
20189
|
+
if (error.code === "ENOENT")
|
|
20190
|
+
return false;
|
|
20191
|
+
throw error;
|
|
20192
|
+
}
|
|
20193
|
+
}
|
|
20164
20194
|
function chmod(path, mode) {
|
|
20165
20195
|
chmodSync(path, mode);
|
|
20166
20196
|
}
|
|
@@ -20172,14 +20202,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
|
|
|
20172
20202
|
|
|
20173
20203
|
// ../../packages/publish-harness/src/profile-lease.ts
|
|
20174
20204
|
import { createHash, randomBytes } from "crypto";
|
|
20175
|
-
import { homedir as homedir2 } from "os";
|
|
20205
|
+
import { homedir as homedir2, hostname } from "os";
|
|
20176
20206
|
import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
|
|
20177
20207
|
var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
|
|
20178
20208
|
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
20179
20209
|
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
20180
20210
|
var OWNER_FILE = "owner.json";
|
|
20181
20211
|
var HOLDER_PREFIX = "holder-";
|
|
20182
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
|
|
20212
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
20183
20213
|
async function acquireProfileLease(profileDir, options = {}) {
|
|
20184
20214
|
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
20185
20215
|
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
@@ -20347,6 +20377,8 @@ function isProcessAlive(pid) {
|
|
|
20347
20377
|
}
|
|
20348
20378
|
}
|
|
20349
20379
|
function refuseNativeLock(profileDir) {
|
|
20380
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
20381
|
+
return;
|
|
20350
20382
|
for (const name of NATIVE_LOCK_FILES) {
|
|
20351
20383
|
const path = join2(profileDir, name);
|
|
20352
20384
|
if (lstat(path) !== null) {
|
|
@@ -20354,6 +20386,24 @@ function refuseNativeLock(profileDir) {
|
|
|
20354
20386
|
}
|
|
20355
20387
|
}
|
|
20356
20388
|
}
|
|
20389
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
20390
|
+
const lockPath = join2(profileDir, "SingletonLock");
|
|
20391
|
+
const target = readlink(lockPath);
|
|
20392
|
+
if (target === null)
|
|
20393
|
+
return false;
|
|
20394
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
20395
|
+
if (match === null)
|
|
20396
|
+
return false;
|
|
20397
|
+
const [, host, pidText] = match;
|
|
20398
|
+
if (host !== hostname())
|
|
20399
|
+
return false;
|
|
20400
|
+
const pid = Number(pidText);
|
|
20401
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
20402
|
+
return false;
|
|
20403
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
20404
|
+
unlink(join2(profileDir, name));
|
|
20405
|
+
return true;
|
|
20406
|
+
}
|
|
20357
20407
|
function sha256Hex(value) {
|
|
20358
20408
|
return createHash("sha256").update(value).digest("hex");
|
|
20359
20409
|
}
|
|
@@ -20432,6 +20482,27 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
|
20432
20482
|
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20433
20483
|
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20434
20484
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20485
|
+
function isInstantBrowserDeath(message) {
|
|
20486
|
+
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20487
|
+
}
|
|
20488
|
+
function classifyLaunchError(error, profileDir, channel) {
|
|
20489
|
+
const message = errorMessage2(error);
|
|
20490
|
+
if (/singleton|already in use|in use by another/i.test(message))
|
|
20491
|
+
return new BrowserProfileBusyError(profileDir, error);
|
|
20492
|
+
if (/playwright install|executable doesn't exist/i.test(message)) {
|
|
20493
|
+
return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
|
|
20494
|
+
}
|
|
20495
|
+
if (isInstantBrowserDeath(message)) {
|
|
20496
|
+
return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
|
|
20497
|
+
}
|
|
20498
|
+
return error instanceof Error ? error : new Error(message);
|
|
20499
|
+
}
|
|
20500
|
+
function quarantineProfileSyncData(profileDir) {
|
|
20501
|
+
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20502
|
+
if (lstat(syncData) === null)
|
|
20503
|
+
return false;
|
|
20504
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
|
|
20505
|
+
}
|
|
20435
20506
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20436
20507
|
return {
|
|
20437
20508
|
async launch(request) {
|
|
@@ -20460,23 +20531,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
|
|
|
20460
20531
|
throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
|
|
20461
20532
|
}
|
|
20462
20533
|
const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
|
|
20534
|
+
const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
|
|
20535
|
+
headless,
|
|
20536
|
+
channel,
|
|
20537
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
20538
|
+
ignoreDefaultArgs: ["--enable-automation"]
|
|
20539
|
+
});
|
|
20463
20540
|
let context;
|
|
20464
20541
|
try {
|
|
20465
|
-
context = await
|
|
20466
|
-
headless,
|
|
20467
|
-
channel,
|
|
20468
|
-
args: ["--disable-blink-features=AutomationControlled"],
|
|
20469
|
-
ignoreDefaultArgs: ["--enable-automation"]
|
|
20470
|
-
});
|
|
20542
|
+
context = await launch();
|
|
20471
20543
|
} catch (error) {
|
|
20472
|
-
|
|
20473
|
-
|
|
20474
|
-
|
|
20475
|
-
|
|
20476
|
-
|
|
20477
|
-
|
|
20544
|
+
if (!isInstantBrowserDeath(errorMessage2(error)))
|
|
20545
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20546
|
+
if (!quarantineProfileSyncData(profileDir))
|
|
20547
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20548
|
+
try {
|
|
20549
|
+
context = await launch();
|
|
20550
|
+
} catch (retryError) {
|
|
20551
|
+
throw classifyLaunchError(retryError, profileDir, channel);
|
|
20478
20552
|
}
|
|
20479
|
-
throw error;
|
|
20480
20553
|
}
|
|
20481
20554
|
try {
|
|
20482
20555
|
await context.addInitScript(() => {
|
|
@@ -20633,6 +20706,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20633
20706
|
if (command === "login") {
|
|
20634
20707
|
const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
|
|
20635
20708
|
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
20709
|
+
stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
|
|
20636
20710
|
try {
|
|
20637
20711
|
if (url === undefined) {
|
|
20638
20712
|
await loginWithProfile({
|
|
@@ -20446,8 +20446,11 @@ import {
|
|
|
20446
20446
|
mkdirSync as mkdirSync2,
|
|
20447
20447
|
openSync,
|
|
20448
20448
|
readdirSync as readdirSync2,
|
|
20449
|
+
readlinkSync,
|
|
20449
20450
|
realpathSync as realpathSync2,
|
|
20450
|
-
|
|
20451
|
+
renameSync as renameSync2,
|
|
20452
|
+
rmdirSync,
|
|
20453
|
+
unlinkSync
|
|
20451
20454
|
} from "fs";
|
|
20452
20455
|
function lstat(path) {
|
|
20453
20456
|
try {
|
|
@@ -20482,6 +20485,33 @@ function rmdir(path) {
|
|
|
20482
20485
|
throw error;
|
|
20483
20486
|
}
|
|
20484
20487
|
}
|
|
20488
|
+
function readlink(path) {
|
|
20489
|
+
try {
|
|
20490
|
+
return readlinkSync(path);
|
|
20491
|
+
} catch {
|
|
20492
|
+
return null;
|
|
20493
|
+
}
|
|
20494
|
+
}
|
|
20495
|
+
function unlink(path) {
|
|
20496
|
+
try {
|
|
20497
|
+
unlinkSync(path);
|
|
20498
|
+
return true;
|
|
20499
|
+
} catch (error) {
|
|
20500
|
+
if (error.code === "ENOENT")
|
|
20501
|
+
return false;
|
|
20502
|
+
throw error;
|
|
20503
|
+
}
|
|
20504
|
+
}
|
|
20505
|
+
function rename(from, to) {
|
|
20506
|
+
try {
|
|
20507
|
+
renameSync2(from, to);
|
|
20508
|
+
return true;
|
|
20509
|
+
} catch (error) {
|
|
20510
|
+
if (error.code === "ENOENT")
|
|
20511
|
+
return false;
|
|
20512
|
+
throw error;
|
|
20513
|
+
}
|
|
20514
|
+
}
|
|
20485
20515
|
function chmod(path, mode) {
|
|
20486
20516
|
chmodSync(path, mode);
|
|
20487
20517
|
}
|
|
@@ -20493,14 +20523,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-t
|
|
|
20493
20523
|
|
|
20494
20524
|
// ../../packages/publish-harness/src/profile-lease.ts
|
|
20495
20525
|
import { createHash, randomBytes } from "crypto";
|
|
20496
|
-
import { homedir as homedir3 } from "os";
|
|
20526
|
+
import { homedir as homedir3, hostname } from "os";
|
|
20497
20527
|
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
20498
20528
|
var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
|
|
20499
20529
|
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
20500
20530
|
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
20501
20531
|
var OWNER_FILE = "owner.json";
|
|
20502
20532
|
var HOLDER_PREFIX = "holder-";
|
|
20503
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
|
|
20533
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
20504
20534
|
async function acquireProfileLease(profileDir, options = {}) {
|
|
20505
20535
|
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
20506
20536
|
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
@@ -20668,6 +20698,8 @@ function isProcessAlive(pid) {
|
|
|
20668
20698
|
}
|
|
20669
20699
|
}
|
|
20670
20700
|
function refuseNativeLock(profileDir) {
|
|
20701
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
20702
|
+
return;
|
|
20671
20703
|
for (const name of NATIVE_LOCK_FILES) {
|
|
20672
20704
|
const path = join3(profileDir, name);
|
|
20673
20705
|
if (lstat(path) !== null) {
|
|
@@ -20675,6 +20707,24 @@ function refuseNativeLock(profileDir) {
|
|
|
20675
20707
|
}
|
|
20676
20708
|
}
|
|
20677
20709
|
}
|
|
20710
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
20711
|
+
const lockPath = join3(profileDir, "SingletonLock");
|
|
20712
|
+
const target = readlink(lockPath);
|
|
20713
|
+
if (target === null)
|
|
20714
|
+
return false;
|
|
20715
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
20716
|
+
if (match === null)
|
|
20717
|
+
return false;
|
|
20718
|
+
const [, host, pidText] = match;
|
|
20719
|
+
if (host !== hostname())
|
|
20720
|
+
return false;
|
|
20721
|
+
const pid = Number(pidText);
|
|
20722
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
20723
|
+
return false;
|
|
20724
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
20725
|
+
unlink(join3(profileDir, name));
|
|
20726
|
+
return true;
|
|
20727
|
+
}
|
|
20678
20728
|
function sha256Hex(value) {
|
|
20679
20729
|
return createHash("sha256").update(value).digest("hex");
|
|
20680
20730
|
}
|
|
@@ -20709,6 +20759,27 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
|
20709
20759
|
// ../../packages/publish-harness/src/browser.ts
|
|
20710
20760
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20711
20761
|
var DEFAULT_POLL_MS = 500;
|
|
20762
|
+
function isInstantBrowserDeath(message) {
|
|
20763
|
+
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20764
|
+
}
|
|
20765
|
+
function classifyLaunchError(error, profileDir, channel) {
|
|
20766
|
+
const message = errorMessage2(error);
|
|
20767
|
+
if (/singleton|already in use|in use by another/i.test(message))
|
|
20768
|
+
return new BrowserProfileBusyError(profileDir, error);
|
|
20769
|
+
if (/playwright install|executable doesn't exist/i.test(message)) {
|
|
20770
|
+
return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
|
|
20771
|
+
}
|
|
20772
|
+
if (isInstantBrowserDeath(message)) {
|
|
20773
|
+
return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
|
|
20774
|
+
}
|
|
20775
|
+
return error instanceof Error ? error : new Error(message);
|
|
20776
|
+
}
|
|
20777
|
+
function quarantineProfileSyncData(profileDir) {
|
|
20778
|
+
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20779
|
+
if (lstat(syncData) === null)
|
|
20780
|
+
return false;
|
|
20781
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
|
|
20782
|
+
}
|
|
20712
20783
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20713
20784
|
return {
|
|
20714
20785
|
async launch(request) {
|
|
@@ -20737,23 +20808,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
|
|
|
20737
20808
|
throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
|
|
20738
20809
|
}
|
|
20739
20810
|
const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
|
|
20811
|
+
const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
|
|
20812
|
+
headless,
|
|
20813
|
+
channel,
|
|
20814
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
20815
|
+
ignoreDefaultArgs: ["--enable-automation"]
|
|
20816
|
+
});
|
|
20740
20817
|
let context;
|
|
20741
20818
|
try {
|
|
20742
|
-
context = await
|
|
20743
|
-
headless,
|
|
20744
|
-
channel,
|
|
20745
|
-
args: ["--disable-blink-features=AutomationControlled"],
|
|
20746
|
-
ignoreDefaultArgs: ["--enable-automation"]
|
|
20747
|
-
});
|
|
20819
|
+
context = await launch();
|
|
20748
20820
|
} catch (error) {
|
|
20749
|
-
|
|
20750
|
-
|
|
20751
|
-
|
|
20752
|
-
|
|
20753
|
-
|
|
20754
|
-
|
|
20821
|
+
if (!isInstantBrowserDeath(errorMessage2(error)))
|
|
20822
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20823
|
+
if (!quarantineProfileSyncData(profileDir))
|
|
20824
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20825
|
+
try {
|
|
20826
|
+
context = await launch();
|
|
20827
|
+
} catch (retryError) {
|
|
20828
|
+
throw classifyLaunchError(retryError, profileDir, channel);
|
|
20755
20829
|
}
|
|
20756
|
-
throw error;
|
|
20757
20830
|
}
|
|
20758
20831
|
try {
|
|
20759
20832
|
await context.addInitScript(() => {
|
|
@@ -19853,8 +19853,11 @@ import {
|
|
|
19853
19853
|
mkdirSync as mkdirSync2,
|
|
19854
19854
|
openSync,
|
|
19855
19855
|
readdirSync as readdirSync2,
|
|
19856
|
+
readlinkSync,
|
|
19856
19857
|
realpathSync as realpathSync2,
|
|
19857
|
-
|
|
19858
|
+
renameSync as renameSync2,
|
|
19859
|
+
rmdirSync,
|
|
19860
|
+
unlinkSync
|
|
19858
19861
|
} from "fs";
|
|
19859
19862
|
function lstat(path) {
|
|
19860
19863
|
try {
|
|
@@ -19889,6 +19892,33 @@ function rmdir(path) {
|
|
|
19889
19892
|
throw error;
|
|
19890
19893
|
}
|
|
19891
19894
|
}
|
|
19895
|
+
function readlink(path) {
|
|
19896
|
+
try {
|
|
19897
|
+
return readlinkSync(path);
|
|
19898
|
+
} catch {
|
|
19899
|
+
return null;
|
|
19900
|
+
}
|
|
19901
|
+
}
|
|
19902
|
+
function unlink(path) {
|
|
19903
|
+
try {
|
|
19904
|
+
unlinkSync(path);
|
|
19905
|
+
return true;
|
|
19906
|
+
} catch (error) {
|
|
19907
|
+
if (error.code === "ENOENT")
|
|
19908
|
+
return false;
|
|
19909
|
+
throw error;
|
|
19910
|
+
}
|
|
19911
|
+
}
|
|
19912
|
+
function rename(from, to) {
|
|
19913
|
+
try {
|
|
19914
|
+
renameSync2(from, to);
|
|
19915
|
+
return true;
|
|
19916
|
+
} catch (error) {
|
|
19917
|
+
if (error.code === "ENOENT")
|
|
19918
|
+
return false;
|
|
19919
|
+
throw error;
|
|
19920
|
+
}
|
|
19921
|
+
}
|
|
19892
19922
|
function chmod(path, mode) {
|
|
19893
19923
|
chmodSync(path, mode);
|
|
19894
19924
|
}
|
|
@@ -19900,14 +19930,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
|
|
|
19900
19930
|
|
|
19901
19931
|
// ../../packages/publish-harness/src/profile-lease.ts
|
|
19902
19932
|
import { createHash, randomBytes } from "crypto";
|
|
19903
|
-
import { homedir as homedir2 } from "os";
|
|
19933
|
+
import { homedir as homedir2, hostname } from "os";
|
|
19904
19934
|
import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
|
|
19905
19935
|
var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
|
|
19906
19936
|
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
19907
19937
|
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
19908
19938
|
var OWNER_FILE = "owner.json";
|
|
19909
19939
|
var HOLDER_PREFIX = "holder-";
|
|
19910
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
|
|
19940
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
19911
19941
|
async function acquireProfileLease(profileDir, options = {}) {
|
|
19912
19942
|
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
19913
19943
|
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
@@ -20075,6 +20105,8 @@ function isProcessAlive(pid) {
|
|
|
20075
20105
|
}
|
|
20076
20106
|
}
|
|
20077
20107
|
function refuseNativeLock(profileDir) {
|
|
20108
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
20109
|
+
return;
|
|
20078
20110
|
for (const name of NATIVE_LOCK_FILES) {
|
|
20079
20111
|
const path = join2(profileDir, name);
|
|
20080
20112
|
if (lstat(path) !== null) {
|
|
@@ -20082,6 +20114,24 @@ function refuseNativeLock(profileDir) {
|
|
|
20082
20114
|
}
|
|
20083
20115
|
}
|
|
20084
20116
|
}
|
|
20117
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
20118
|
+
const lockPath = join2(profileDir, "SingletonLock");
|
|
20119
|
+
const target = readlink(lockPath);
|
|
20120
|
+
if (target === null)
|
|
20121
|
+
return false;
|
|
20122
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
20123
|
+
if (match === null)
|
|
20124
|
+
return false;
|
|
20125
|
+
const [, host, pidText] = match;
|
|
20126
|
+
if (host !== hostname())
|
|
20127
|
+
return false;
|
|
20128
|
+
const pid = Number(pidText);
|
|
20129
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
20130
|
+
return false;
|
|
20131
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
20132
|
+
unlink(join2(profileDir, name));
|
|
20133
|
+
return true;
|
|
20134
|
+
}
|
|
20085
20135
|
function sha256Hex(value) {
|
|
20086
20136
|
return createHash("sha256").update(value).digest("hex");
|
|
20087
20137
|
}
|
|
@@ -20140,6 +20190,27 @@ var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
|
20140
20190
|
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20141
20191
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20142
20192
|
var DEFAULT_POLL_MS = 500;
|
|
20193
|
+
function isInstantBrowserDeath(message) {
|
|
20194
|
+
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20195
|
+
}
|
|
20196
|
+
function classifyLaunchError(error, profileDir, channel) {
|
|
20197
|
+
const message = errorMessage2(error);
|
|
20198
|
+
if (/singleton|already in use|in use by another/i.test(message))
|
|
20199
|
+
return new BrowserProfileBusyError(profileDir, error);
|
|
20200
|
+
if (/playwright install|executable doesn't exist/i.test(message)) {
|
|
20201
|
+
return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
|
|
20202
|
+
}
|
|
20203
|
+
if (isInstantBrowserDeath(message)) {
|
|
20204
|
+
return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
|
|
20205
|
+
}
|
|
20206
|
+
return error instanceof Error ? error : new Error(message);
|
|
20207
|
+
}
|
|
20208
|
+
function quarantineProfileSyncData(profileDir) {
|
|
20209
|
+
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20210
|
+
if (lstat(syncData) === null)
|
|
20211
|
+
return false;
|
|
20212
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
|
|
20213
|
+
}
|
|
20143
20214
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20144
20215
|
return {
|
|
20145
20216
|
async launch(request) {
|
|
@@ -20168,23 +20239,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
|
|
|
20168
20239
|
throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
|
|
20169
20240
|
}
|
|
20170
20241
|
const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
|
|
20242
|
+
const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
|
|
20243
|
+
headless,
|
|
20244
|
+
channel,
|
|
20245
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
20246
|
+
ignoreDefaultArgs: ["--enable-automation"]
|
|
20247
|
+
});
|
|
20171
20248
|
let context;
|
|
20172
20249
|
try {
|
|
20173
|
-
context = await
|
|
20174
|
-
headless,
|
|
20175
|
-
channel,
|
|
20176
|
-
args: ["--disable-blink-features=AutomationControlled"],
|
|
20177
|
-
ignoreDefaultArgs: ["--enable-automation"]
|
|
20178
|
-
});
|
|
20250
|
+
context = await launch();
|
|
20179
20251
|
} catch (error) {
|
|
20180
|
-
|
|
20181
|
-
|
|
20182
|
-
|
|
20183
|
-
|
|
20184
|
-
|
|
20185
|
-
|
|
20252
|
+
if (!isInstantBrowserDeath(errorMessage2(error)))
|
|
20253
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20254
|
+
if (!quarantineProfileSyncData(profileDir))
|
|
20255
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
20256
|
+
try {
|
|
20257
|
+
context = await launch();
|
|
20258
|
+
} catch (retryError) {
|
|
20259
|
+
throw classifyLaunchError(retryError, profileDir, channel);
|
|
20186
20260
|
}
|
|
20187
|
-
throw error;
|
|
20188
20261
|
}
|
|
20189
20262
|
try {
|
|
20190
20263
|
await context.addInitScript(() => {
|
|
@@ -20341,6 +20414,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20341
20414
|
if (command === "login") {
|
|
20342
20415
|
const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
|
|
20343
20416
|
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
20417
|
+
stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
|
|
20344
20418
|
try {
|
|
20345
20419
|
if (url === undefined) {
|
|
20346
20420
|
await loginWithProfile({
|