@gobing-ai/knowledge-kit 0.1.29 → 0.1.30
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/api.js +8724 -3861
- package/dist/board/collect/index.js +69 -1
- package/dist/board/daily-voice/index.js +474 -265
- package/dist/board/itc/index.js +69 -1
- package/dist/board/wiki/index.css +1305 -0
- package/dist/board/wiki/index.js +1621 -0
- package/dist/index.js +34689 -28532
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +14 -1
- package/plugins/generations/core-facts-gen/dist/index.js +14 -1
- package/plugins/generations/daily-article-gen/dist/index.js +14 -1
- package/plugins/generations/dailynews-gen/dist/index.js +14 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +32 -2
- package/plugins/generations/episode-plan-gen/src/index.ts +19 -1
- package/plugins/generations/gemini-tts/dist/index.js +14 -1
- package/plugins/generations/image-gen/dist/index.js +14 -1
- package/plugins/generations/music-gen/dist/index.js +15 -2
- package/plugins/generations/news-report-gen/dist/index.js +14 -1
- package/plugins/generations/vibe-voice-tts/dist/index.js +14 -1
- package/plugins/generations/video-gen/README.md +245 -8
- package/plugins/generations/video-gen/dist/index.js +22447 -4763
- package/plugins/generations/video-gen/package.json +1 -0
- package/plugins/generations/video-gen/presets/formats/avatar.yaml +5 -0
- package/plugins/generations/video-gen/presets/formats/editorial.yaml +6 -0
- package/plugins/generations/video-gen/presets/formats/hybrid-pip.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/daily-ai.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/neutral.yaml +3 -0
- package/plugins/generations/video-gen/python/colab_comfyui_h3.py +322 -0
- package/plugins/generations/video-gen/python/comfyui-h3-i2v-api.json +47 -0
- package/plugins/generations/video-gen/python/comfyui-h3-models.json +32 -0
- package/plugins/generations/video-gen/python/comfyui_model_cache.py +388 -0
- package/plugins/generations/video-gen/python/drive_client.py +187 -0
- package/plugins/generations/video-gen/src/brief-cli.ts +65 -0
- package/plugins/generations/video-gen/src/brief.ts +464 -0
- package/plugins/generations/video-gen/src/ccu-ledger.ts +206 -3
- package/plugins/generations/video-gen/src/colab-runner.ts +346 -35
- package/plugins/generations/video-gen/src/index.ts +141 -109
- package/plugins/generations/video-gen/src/inputs.ts +162 -4
- package/plugins/generations/video-gen/src/layout.ts +33 -0
- package/plugins/generations/video-gen/src/props.ts +27 -3
- package/plugins/generations/video-gen/src/remotion/AvatarReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/EditorialReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/Root.tsx +2 -0
- package/plugins/generations/video-gen/src/remotion/engine.ts +3 -7
- package/plugins/generations/video-gen/src/render.ts +25 -0
- package/plugins/generations/video-gen/src/request.ts +150 -20
- package/plugins/generations/video-gen/src/visual-provider.ts +116 -3
- package/plugins/generations/voice-gen/dist/index.js +14 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +14 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +14 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +14 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +14 -1
- package/plugins/ingestions/web-search/dist/index.js +14 -1
- package/plugins/kk/config.example.yaml +1 -1
- package/plugins/kk/mcp-tools.yaml +47 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/itc-surfdash-locales.json +42 -0
- package/plugins/kk/scripts/daily-stages.ts +87 -6
- package/plugins/kk/scripts/kk-workflow-stages.ts +64 -9
- package/plugins/kk/scripts/video-stages.ts +332 -0
- package/plugins/kk/scripts/wiki-normalize-audio.ts +354 -0
- package/plugins/kk/scripts/wiki-normalize-document.ts +495 -0
- package/plugins/kk/scripts/wiki-normalize-stages.ts +96 -0
- package/plugins/kk/scripts/wiki-stage-runtime.ts +39 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +2 -1
- package/plugins/kk/workflows/kk-collect.yaml +10 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +70 -8
- package/plugins/kk/workflows/kk-smart-seo.yaml +8 -0
- package/plugins/kk/workflows/kk-storm-research.yaml +10 -0
- package/plugins/kk/workflows/kk-video-generate.yaml +169 -0
- package/plugins/kk/workflows/kk-wiki-digest.yaml +49 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +281 -268
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/cnblogs-pub/dist/index.js +281 -268
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/csdn-pub/dist/index.js +281 -268
- package/plugins/publishings/csdn-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/emdash-pub/dist/index.js +33 -3
- package/plugins/publishings/infoq-pub/dist/index.js +281 -268
- package/plugins/publishings/infoq-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/jike-pub/dist/index.js +281 -268
- package/plugins/publishings/jike-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/juejin-pub/dist/index.js +281 -268
- package/plugins/publishings/juejin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +281 -268
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/medium-pub/dist/index.js +281 -268
- package/plugins/publishings/medium-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/podcast-pub/dist/index.js +39 -9
- package/plugins/publishings/qiita-pub/dist/index.js +33 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +281 -268
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +175 -0
- package/plugins/publishings/sspai-pub/dist/index.js +281 -268
- package/plugins/publishings/sspai-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/substack-pub/dist/index.js +281 -268
- package/plugins/publishings/substack-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +99 -39
- package/plugins/publishings/surfdash-pub/plugin.json +54 -0
- package/plugins/publishings/surfdash-pub/src/index.ts +36 -5
- package/plugins/publishings/threads-pub/dist/index.js +281 -268
- package/plugins/publishings/threads-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +665 -451
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +215 -3
- package/plugins/publishings/weibo-pub/dist/index.js +281 -268
- package/plugins/publishings/weibo-pub/dist/profile-check.js +189 -1
- package/plugins/publishings/x-pub/dist/index.js +281 -268
- package/plugins/publishings/x-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/xhs-pub/dist/index.js +281 -268
- package/plugins/publishings/xhs-pub/dist/profile-check.js +119 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +281 -268
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/youtube-pub/dist/index.js +14 -1
- package/plugins/publishings/zenn-pub/dist/index.js +37 -7
|
@@ -1296,6 +1296,9 @@ type PrepareOutcome = { ok: true; prepared: PreparedPost } | { ok: false; result
|
|
|
1296
1296
|
/** The non-primary locales a digest post carries (`metadata.surfdash.locales`); zh is the primary. */
|
|
1297
1297
|
const LOCAL_DRAFTS = ['en', 'ja'] as const;
|
|
1298
1298
|
|
|
1299
|
+
/** Every locale the site serves, primary first. */
|
|
1300
|
+
const SUPPORTED_LOCALES = ['zh', 'en', 'ja'] as const;
|
|
1301
|
+
|
|
1299
1302
|
/** One localized sibling's authored text, as the workflow's `localize` step delivers it. */
|
|
1300
1303
|
interface LocaleDraft {
|
|
1301
1304
|
title: string;
|
|
@@ -1370,11 +1373,35 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1370
1373
|
};
|
|
1371
1374
|
}
|
|
1372
1375
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
+
// 0461 R2: an explicitly supplied Content locale selects the single file this prepare mints and
|
|
1377
|
+
// its canonical URL; only an ABSENT locale falls back to the environment/default (the daily
|
|
1378
|
+
// digest's contract). A supplied but unsupported value is a caller error — refused before any
|
|
1379
|
+
// write or spawn so a mistyped locale can never post source text under another locale's identity.
|
|
1380
|
+
// A digest is inherently the primary locale plus its bundled en/ja translations (0409), so it
|
|
1381
|
+
// keeps the env/default primary; only a non-digest lets an explicit locale pick the destination.
|
|
1382
|
+
const suppliedLocale = payload.content.metadata?.locale;
|
|
1383
|
+
if (
|
|
1384
|
+
suppliedLocale !== undefined &&
|
|
1385
|
+
(typeof suppliedLocale !== 'string' || !SUPPORTED_LOCALES.includes(suppliedLocale as SupportedLocale))
|
|
1386
|
+
) {
|
|
1387
|
+
return {
|
|
1388
|
+
ok: false,
|
|
1389
|
+
result: failNotSent(
|
|
1390
|
+
`metadata.locale must be one of ${SUPPORTED_LOCALES.join('/')}, got ${JSON.stringify(suppliedLocale)}`,
|
|
1391
|
+
),
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
const explicitLocale = suppliedLocale !== undefined && !isDigestContent(payload.content);
|
|
1395
|
+
let locale: SupportedLocale;
|
|
1396
|
+
if (explicitLocale) {
|
|
1397
|
+
locale = suppliedLocale as SupportedLocale;
|
|
1398
|
+
} else {
|
|
1399
|
+
const rawLocale = process.env.SURFDASH_LOCALE ?? 'zh';
|
|
1400
|
+
if (!SUPPORTED_LOCALES.includes(rawLocale as SupportedLocale)) {
|
|
1401
|
+
return { ok: false, result: failNotSent(`SURFDASH_LOCALE must be one of zh/en/ja, got '${rawLocale}'`) };
|
|
1402
|
+
}
|
|
1403
|
+
locale = rawLocale as SupportedLocale;
|
|
1376
1404
|
}
|
|
1377
|
-
const locale = rawLocale as SupportedLocale;
|
|
1378
1405
|
// dateStamp source: explicit metadata.runDate, else the payload's own metadata.date —
|
|
1379
1406
|
// never the wall clock, which around midnight local time mints `tomorrow` slugs.
|
|
1380
1407
|
const runDate =
|
|
@@ -1463,7 +1490,11 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1463
1490
|
// generator defaults and flips an already-published day back to a draft. Keep the file and
|
|
1464
1491
|
// reuse it; only genuinely fresh days (no marker) get minted (2026-11-05 tier-0 rerun).
|
|
1465
1492
|
await mintLocalePost({ postDir, content: payload.content, coverUrl, locale, publishDate });
|
|
1466
|
-
|
|
1493
|
+
// An explicit locale on a non-digest prepares exactly one file (0461 R2): a sibling map in the
|
|
1494
|
+
// same Content must not write the other locale dirs. Digests and the env/default path keep the
|
|
1495
|
+
// 0409 bundled-sibling contract.
|
|
1496
|
+
const siblingLocales = explicitLocale ? [] : LOCAL_DRAFTS;
|
|
1497
|
+
for (const draftLocale of siblingLocales) {
|
|
1467
1498
|
const draft = drafts[draftLocale];
|
|
1468
1499
|
if (draft === undefined) continue;
|
|
1469
1500
|
const siblingDir = resolve(articlesRoot, draftLocale, slug);
|
|
@@ -25286,7 +25286,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
|
|
|
25286
25286
|
})
|
|
25287
25287
|
});
|
|
25288
25288
|
var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
|
|
25289
|
-
var VideoRenderProviderSchema = _enum([
|
|
25289
|
+
var VideoRenderProviderSchema = _enum([
|
|
25290
|
+
"local-ken-burns",
|
|
25291
|
+
"wan21-i2v",
|
|
25292
|
+
"comfyui-minimax-h3",
|
|
25293
|
+
"musetalk",
|
|
25294
|
+
"echomimic-v2"
|
|
25295
|
+
]);
|
|
25296
|
+
var RenderProvenanceSchema = object({
|
|
25297
|
+
cache: _enum(["drive", "local"]),
|
|
25298
|
+
comfyuiCommit: string2().min(1).optional(),
|
|
25299
|
+
comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
|
|
25300
|
+
modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
|
|
25301
|
+
});
|
|
25290
25302
|
var videoGenContentSchema = ContentSchema.extend({
|
|
25291
25303
|
format: literal("video"),
|
|
25292
25304
|
metadata: looseObject({
|
|
@@ -25299,6 +25311,7 @@ var videoGenContentSchema = ContentSchema.extend({
|
|
|
25299
25311
|
durationSec: number2().positive(),
|
|
25300
25312
|
visualMode: VideoVisualModeSchema,
|
|
25301
25313
|
renderProvider: VideoRenderProviderSchema,
|
|
25314
|
+
renderProvenance: RenderProvenanceSchema.optional(),
|
|
25302
25315
|
fallbackUsed: boolean2().optional(),
|
|
25303
25316
|
warnings: array(string2()).optional(),
|
|
25304
25317
|
ccuEstimated: number2().nonnegative().optional(),
|
|
@@ -25493,8 +25506,12 @@ var CJK_TERMINATORS = new Set(["\u3002", "\uFF01", "\uFF1F"]);
|
|
|
25493
25506
|
var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
25494
25507
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
25495
25508
|
// ../../packages/publish-harness/src/index.ts
|
|
25496
|
-
import { homedir } from "os";
|
|
25497
|
-
import { join, resolve } from "path";
|
|
25509
|
+
import { homedir as homedir4 } from "os";
|
|
25510
|
+
import { join as join4, resolve as resolve4 } from "path";
|
|
25511
|
+
|
|
25512
|
+
// ../../packages/publish-harness/src/bot.ts
|
|
25513
|
+
import { homedir as homedir3 } from "os";
|
|
25514
|
+
import { isAbsolute, join as join3, relative, resolve as resolve3, sep } from "path";
|
|
25498
25515
|
|
|
25499
25516
|
// ../../packages/publish-harness/src/bot-fs.ts
|
|
25500
25517
|
import {
|
|
@@ -25575,6 +25592,264 @@ function chmod(path, mode) {
|
|
|
25575
25592
|
chmodSync(path, mode);
|
|
25576
25593
|
}
|
|
25577
25594
|
|
|
25595
|
+
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
25596
|
+
import { homedir } from "os";
|
|
25597
|
+
import { dirname as dirname2, join, resolve } from "path";
|
|
25598
|
+
var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-transactions");
|
|
25599
|
+
|
|
25600
|
+
// ../../packages/publish-harness/src/profile-lease.ts
|
|
25601
|
+
import { createHash, randomBytes } from "crypto";
|
|
25602
|
+
import { homedir as homedir2, hostname } from "os";
|
|
25603
|
+
import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
|
|
25604
|
+
var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
|
|
25605
|
+
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
25606
|
+
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
25607
|
+
var OWNER_FILE = "owner.json";
|
|
25608
|
+
var HOLDER_PREFIX = "holder-";
|
|
25609
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
25610
|
+
async function acquireProfileLease(profileDir, options = {}) {
|
|
25611
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25612
|
+
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
25613
|
+
const logicalPath = canonicalize(profileDir);
|
|
25614
|
+
refuseNativeLock(logicalPath);
|
|
25615
|
+
const id = sha256Hex(logicalPath);
|
|
25616
|
+
const leaseDir = join2(leaseRoot, id);
|
|
25617
|
+
await fileSystem.ensureDir(leaseRoot);
|
|
25618
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25619
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
25620
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25621
|
+
}
|
|
25622
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25623
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25624
|
+
}
|
|
25625
|
+
}
|
|
25626
|
+
const token = randomBytes(16).toString("hex");
|
|
25627
|
+
const owner = {
|
|
25628
|
+
schemaVersion: 1,
|
|
25629
|
+
id,
|
|
25630
|
+
token,
|
|
25631
|
+
logicalPath,
|
|
25632
|
+
physicalPath: null,
|
|
25633
|
+
pid: process.pid,
|
|
25634
|
+
createdAt: new Date().toISOString()
|
|
25635
|
+
};
|
|
25636
|
+
await writeOwner(fileSystem, leaseDir, owner);
|
|
25637
|
+
return {
|
|
25638
|
+
id,
|
|
25639
|
+
token,
|
|
25640
|
+
profileDir: logicalPath,
|
|
25641
|
+
leaseDir,
|
|
25642
|
+
async release() {
|
|
25643
|
+
await releaseOwnedLease(fileSystem, leaseDir, owner);
|
|
25644
|
+
},
|
|
25645
|
+
async delegatedEnv(physicalProfileDir) {
|
|
25646
|
+
await writeOwner(fileSystem, leaseDir, { ...owner, physicalPath: canonicalize(physicalProfileDir) });
|
|
25647
|
+
return { [KK_BOT_LEASE_PATH]: leaseDir, [KK_BOT_LEASE_TOKEN]: token };
|
|
25648
|
+
}
|
|
25649
|
+
};
|
|
25650
|
+
}
|
|
25651
|
+
async function enterDelegatedLease(env, physicalProfileDir, options = {}) {
|
|
25652
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25653
|
+
const leaseDir = env[KK_BOT_LEASE_PATH];
|
|
25654
|
+
const token = env[KK_BOT_LEASE_TOKEN];
|
|
25655
|
+
if (leaseDir === undefined || leaseDir === "" || token === undefined || token === "") {
|
|
25656
|
+
throw new BotError("usage", `no delegated lease present (${KK_BOT_LEASE_PATH}/${KK_BOT_LEASE_TOKEN})`);
|
|
25657
|
+
}
|
|
25658
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25659
|
+
if (owner === null)
|
|
25660
|
+
throw new BotError("busy", `delegated lease ${leaseDir} has no owner record`);
|
|
25661
|
+
if (owner.token !== token)
|
|
25662
|
+
throw new BotError("busy", `delegated lease ${leaseDir} token does not match its owner`);
|
|
25663
|
+
const physicalPath = canonicalize(physicalProfileDir);
|
|
25664
|
+
if (owner.physicalPath !== null && owner.physicalPath !== physicalPath) {
|
|
25665
|
+
throw new BotError("busy", `delegated lease ${leaseDir} is bound to ${owner.physicalPath}, not ${physicalPath}`);
|
|
25666
|
+
}
|
|
25667
|
+
const holderPath = join2(leaseDir, `${HOLDER_PREFIX}${process.pid}.json`);
|
|
25668
|
+
await fileSystem.writeFile(holderPath, `${JSON.stringify({ pid: process.pid, physicalPath, enteredAt: new Date().toISOString() }, null, 2)}
|
|
25669
|
+
`);
|
|
25670
|
+
chmod(holderPath, 384);
|
|
25671
|
+
return {
|
|
25672
|
+
pid: process.pid,
|
|
25673
|
+
leaseDir,
|
|
25674
|
+
async release() {
|
|
25675
|
+
await fileSystem.deleteFile(holderPath);
|
|
25676
|
+
}
|
|
25677
|
+
};
|
|
25678
|
+
}
|
|
25679
|
+
async function verifyLeaseHeld(lease, options = {}) {
|
|
25680
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25681
|
+
const owner = await readOwner(fileSystem, lease.leaseDir);
|
|
25682
|
+
if (owner === null || owner.token !== lease.token || owner.id !== lease.id) {
|
|
25683
|
+
throw new BotError("busy", `browser lease ${lease.leaseDir} is not held by this invocation any more \u2014 refusing to borrow it`);
|
|
25684
|
+
}
|
|
25685
|
+
}
|
|
25686
|
+
function canonicalize(profileDir) {
|
|
25687
|
+
let probe = resolve2(profileDir);
|
|
25688
|
+
const tail = [];
|
|
25689
|
+
for (;; ) {
|
|
25690
|
+
if (lstat(probe) !== null) {
|
|
25691
|
+
let canonical;
|
|
25692
|
+
try {
|
|
25693
|
+
canonical = realpath(probe);
|
|
25694
|
+
} catch {
|
|
25695
|
+
canonical = probe;
|
|
25696
|
+
}
|
|
25697
|
+
return tail.length === 0 ? canonical : join2(canonical, ...tail);
|
|
25698
|
+
}
|
|
25699
|
+
const parent = dirname3(probe);
|
|
25700
|
+
if (parent === probe)
|
|
25701
|
+
return join2(probe, ...tail);
|
|
25702
|
+
tail.unshift(basename(probe));
|
|
25703
|
+
probe = parent;
|
|
25704
|
+
}
|
|
25705
|
+
}
|
|
25706
|
+
async function releaseOwnedLease(fileSystem, leaseDir, expected) {
|
|
25707
|
+
const current = await readOwner(fileSystem, leaseDir);
|
|
25708
|
+
if (current === null || current.token !== expected.token || current.id !== expected.id) {
|
|
25709
|
+
throw new BotError("busy", `lease ${leaseDir} is not owned by this invocation \u2014 refusing to release`);
|
|
25710
|
+
}
|
|
25711
|
+
const live = await liveChildHolders(fileSystem, leaseDir);
|
|
25712
|
+
if (live.length > 0) {
|
|
25713
|
+
throw new BotError("busy", `lease ${leaseDir} still has live child holders (pids ${live.join(", ")}) \u2014 stop them before releasing`);
|
|
25714
|
+
}
|
|
25715
|
+
await fileSystem.deleteFile(join2(leaseDir, OWNER_FILE));
|
|
25716
|
+
rmdir(leaseDir);
|
|
25717
|
+
}
|
|
25718
|
+
async function readOwner(fileSystem, leaseDir) {
|
|
25719
|
+
try {
|
|
25720
|
+
return JSON.parse(await fileSystem.readFile(join2(leaseDir, OWNER_FILE)));
|
|
25721
|
+
} catch {
|
|
25722
|
+
return null;
|
|
25723
|
+
}
|
|
25724
|
+
}
|
|
25725
|
+
async function writeOwner(fileSystem, leaseDir, owner) {
|
|
25726
|
+
const path = join2(leaseDir, OWNER_FILE);
|
|
25727
|
+
await fileSystem.writeFile(path, `${JSON.stringify(owner, null, 2)}
|
|
25728
|
+
`);
|
|
25729
|
+
chmod(path, 384);
|
|
25730
|
+
}
|
|
25731
|
+
async function busyGuidance(fileSystem, leaseDir) {
|
|
25732
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25733
|
+
if (owner === null) {
|
|
25734
|
+
const residue = await holderResidue(fileSystem, leaseDir);
|
|
25735
|
+
if (residue !== null) {
|
|
25736
|
+
return `browser lease ${leaseDir} has no owner but ${residue} child holder record(s) remain \u2014 ` + "a previous parent released after its children stopped; confirm no kk browser still uses this " + `profile, then remove ${leaseDir} manually`;
|
|
25737
|
+
}
|
|
25738
|
+
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`;
|
|
25739
|
+
}
|
|
25740
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
25741
|
+
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}`;
|
|
25742
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
25743
|
+
}
|
|
25744
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
25745
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25746
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
25747
|
+
return false;
|
|
25748
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
25749
|
+
return false;
|
|
25750
|
+
const target = staleLeaseDir(leaseDir);
|
|
25751
|
+
try {
|
|
25752
|
+
rename(leaseDir, target);
|
|
25753
|
+
} catch {
|
|
25754
|
+
return false;
|
|
25755
|
+
}
|
|
25756
|
+
const moved = await readOwner(fileSystem, target);
|
|
25757
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
25758
|
+
try {
|
|
25759
|
+
rename(target, leaseDir);
|
|
25760
|
+
} catch {}
|
|
25761
|
+
return false;
|
|
25762
|
+
}
|
|
25763
|
+
return true;
|
|
25764
|
+
}
|
|
25765
|
+
function staleLeaseDir(leaseDir) {
|
|
25766
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
25767
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
25768
|
+
}
|
|
25769
|
+
async function holderResidue(fileSystem, leaseDir) {
|
|
25770
|
+
try {
|
|
25771
|
+
const entries = await fileSystem.readDir(leaseDir);
|
|
25772
|
+
const holders = entries.filter((name) => name.startsWith(HOLDER_PREFIX) && name.endsWith(".json"));
|
|
25773
|
+
return holders.length > 0 ? holders.length : null;
|
|
25774
|
+
} catch {
|
|
25775
|
+
return null;
|
|
25776
|
+
}
|
|
25777
|
+
}
|
|
25778
|
+
async function liveChildHolders(fileSystem, leaseDir) {
|
|
25779
|
+
let entries;
|
|
25780
|
+
try {
|
|
25781
|
+
entries = await fileSystem.readDir(leaseDir);
|
|
25782
|
+
} catch {
|
|
25783
|
+
return [];
|
|
25784
|
+
}
|
|
25785
|
+
const pids = [];
|
|
25786
|
+
for (const name of entries) {
|
|
25787
|
+
if (!name.startsWith(HOLDER_PREFIX) || !name.endsWith(".json"))
|
|
25788
|
+
continue;
|
|
25789
|
+
let record;
|
|
25790
|
+
try {
|
|
25791
|
+
record = JSON.parse(await fileSystem.readFile(join2(leaseDir, name)));
|
|
25792
|
+
} catch {
|
|
25793
|
+
continue;
|
|
25794
|
+
}
|
|
25795
|
+
if (typeof record.pid === "number" && isProcessAlive(record.pid))
|
|
25796
|
+
pids.push(record.pid);
|
|
25797
|
+
}
|
|
25798
|
+
return pids;
|
|
25799
|
+
}
|
|
25800
|
+
function isProcessAlive(pid) {
|
|
25801
|
+
try {
|
|
25802
|
+
process.kill(pid, 0);
|
|
25803
|
+
return true;
|
|
25804
|
+
} catch (error) {
|
|
25805
|
+
return error.code === "EPERM";
|
|
25806
|
+
}
|
|
25807
|
+
}
|
|
25808
|
+
function refuseNativeLock(profileDir) {
|
|
25809
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
25810
|
+
return;
|
|
25811
|
+
for (const name of NATIVE_LOCK_FILES) {
|
|
25812
|
+
const path = join2(profileDir, name);
|
|
25813
|
+
if (lstat(path) !== null) {
|
|
25814
|
+
throw new BotError("busy", `native Chromium ownership present at ${path} \u2014 confirm no browser is using ${profileDir} before retrying`);
|
|
25815
|
+
}
|
|
25816
|
+
}
|
|
25817
|
+
}
|
|
25818
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
25819
|
+
const lockPath = join2(profileDir, "SingletonLock");
|
|
25820
|
+
const target = readlink(lockPath);
|
|
25821
|
+
if (target === null)
|
|
25822
|
+
return false;
|
|
25823
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
25824
|
+
if (match === null)
|
|
25825
|
+
return false;
|
|
25826
|
+
const [, host, pidText] = match;
|
|
25827
|
+
if (host !== hostname())
|
|
25828
|
+
return false;
|
|
25829
|
+
const pid = Number(pidText);
|
|
25830
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
25831
|
+
return false;
|
|
25832
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
25833
|
+
unlink(join2(profileDir, name));
|
|
25834
|
+
return true;
|
|
25835
|
+
}
|
|
25836
|
+
function sha256Hex(value) {
|
|
25837
|
+
return createHash("sha256").update(value).digest("hex");
|
|
25838
|
+
}
|
|
25839
|
+
|
|
25840
|
+
// ../../packages/publish-harness/src/bot.ts
|
|
25841
|
+
var DEFAULT_BOT_PROFILE_ROOT = join3(homedir3(), ".config", "kk", "browser-profiles");
|
|
25842
|
+
class BotError extends Error {
|
|
25843
|
+
code;
|
|
25844
|
+
details;
|
|
25845
|
+
constructor(code, message, details = {}) {
|
|
25846
|
+
super(message);
|
|
25847
|
+
this.name = "BotError";
|
|
25848
|
+
this.code = code;
|
|
25849
|
+
this.details = details;
|
|
25850
|
+
}
|
|
25851
|
+
}
|
|
25852
|
+
|
|
25578
25853
|
// ../../packages/publish-harness/src/index.ts
|
|
25579
25854
|
class FakeTransportCore {
|
|
25580
25855
|
callLogs = [];
|
|
@@ -25624,11 +25899,11 @@ function resolveBrowserProfileDir(channel, override) {
|
|
|
25624
25899
|
if (override && override.trim().length > 0) {
|
|
25625
25900
|
const trimmed = override.trim();
|
|
25626
25901
|
if (trimmed.startsWith("~/")) {
|
|
25627
|
-
return
|
|
25902
|
+
return join4(homedir4(), trimmed.slice(2));
|
|
25628
25903
|
}
|
|
25629
|
-
return
|
|
25904
|
+
return resolve4(trimmed);
|
|
25630
25905
|
}
|
|
25631
|
-
return
|
|
25906
|
+
return join4(homedir4(), ".config", "kk", "browser-profiles", channel);
|
|
25632
25907
|
}
|
|
25633
25908
|
async function trySelectors(page, selectors, options = {}) {
|
|
25634
25909
|
const timeout = options.timeout ?? 2000;
|
|
@@ -25857,268 +26132,6 @@ function sleep(ms) {
|
|
|
25857
26132
|
}
|
|
25858
26133
|
// ../../packages/publish-harness/src/browser.ts
|
|
25859
26134
|
init_dist();
|
|
25860
|
-
|
|
25861
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
25862
|
-
import { homedir as homedir4 } from "os";
|
|
25863
|
-
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
25864
|
-
|
|
25865
|
-
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
25866
|
-
import { homedir as homedir2 } from "os";
|
|
25867
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
25868
|
-
var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-transactions");
|
|
25869
|
-
|
|
25870
|
-
// ../../packages/publish-harness/src/profile-lease.ts
|
|
25871
|
-
import { createHash, randomBytes } from "crypto";
|
|
25872
|
-
import { homedir as homedir3, hostname } from "os";
|
|
25873
|
-
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
25874
|
-
var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
|
|
25875
|
-
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
25876
|
-
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
25877
|
-
var OWNER_FILE = "owner.json";
|
|
25878
|
-
var HOLDER_PREFIX = "holder-";
|
|
25879
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
25880
|
-
async function acquireProfileLease(profileDir, options = {}) {
|
|
25881
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25882
|
-
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
25883
|
-
const logicalPath = canonicalize(profileDir);
|
|
25884
|
-
refuseNativeLock(logicalPath);
|
|
25885
|
-
const id = sha256Hex(logicalPath);
|
|
25886
|
-
const leaseDir = join3(leaseRoot, id);
|
|
25887
|
-
await fileSystem.ensureDir(leaseRoot);
|
|
25888
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25889
|
-
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
25890
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25891
|
-
}
|
|
25892
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25893
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25894
|
-
}
|
|
25895
|
-
}
|
|
25896
|
-
const token = randomBytes(16).toString("hex");
|
|
25897
|
-
const owner = {
|
|
25898
|
-
schemaVersion: 1,
|
|
25899
|
-
id,
|
|
25900
|
-
token,
|
|
25901
|
-
logicalPath,
|
|
25902
|
-
physicalPath: null,
|
|
25903
|
-
pid: process.pid,
|
|
25904
|
-
createdAt: new Date().toISOString()
|
|
25905
|
-
};
|
|
25906
|
-
await writeOwner(fileSystem, leaseDir, owner);
|
|
25907
|
-
return {
|
|
25908
|
-
id,
|
|
25909
|
-
token,
|
|
25910
|
-
profileDir: logicalPath,
|
|
25911
|
-
leaseDir,
|
|
25912
|
-
async release() {
|
|
25913
|
-
await releaseOwnedLease(fileSystem, leaseDir, owner);
|
|
25914
|
-
},
|
|
25915
|
-
async delegatedEnv(physicalProfileDir) {
|
|
25916
|
-
await writeOwner(fileSystem, leaseDir, { ...owner, physicalPath: canonicalize(physicalProfileDir) });
|
|
25917
|
-
return { [KK_BOT_LEASE_PATH]: leaseDir, [KK_BOT_LEASE_TOKEN]: token };
|
|
25918
|
-
}
|
|
25919
|
-
};
|
|
25920
|
-
}
|
|
25921
|
-
async function enterDelegatedLease(env, physicalProfileDir, options = {}) {
|
|
25922
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25923
|
-
const leaseDir = env[KK_BOT_LEASE_PATH];
|
|
25924
|
-
const token = env[KK_BOT_LEASE_TOKEN];
|
|
25925
|
-
if (leaseDir === undefined || leaseDir === "" || token === undefined || token === "") {
|
|
25926
|
-
throw new BotError("usage", `no delegated lease present (${KK_BOT_LEASE_PATH}/${KK_BOT_LEASE_TOKEN})`);
|
|
25927
|
-
}
|
|
25928
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
25929
|
-
if (owner === null)
|
|
25930
|
-
throw new BotError("busy", `delegated lease ${leaseDir} has no owner record`);
|
|
25931
|
-
if (owner.token !== token)
|
|
25932
|
-
throw new BotError("busy", `delegated lease ${leaseDir} token does not match its owner`);
|
|
25933
|
-
const physicalPath = canonicalize(physicalProfileDir);
|
|
25934
|
-
if (owner.physicalPath !== null && owner.physicalPath !== physicalPath) {
|
|
25935
|
-
throw new BotError("busy", `delegated lease ${leaseDir} is bound to ${owner.physicalPath}, not ${physicalPath}`);
|
|
25936
|
-
}
|
|
25937
|
-
const holderPath = join3(leaseDir, `${HOLDER_PREFIX}${process.pid}.json`);
|
|
25938
|
-
await fileSystem.writeFile(holderPath, `${JSON.stringify({ pid: process.pid, physicalPath, enteredAt: new Date().toISOString() }, null, 2)}
|
|
25939
|
-
`);
|
|
25940
|
-
chmod(holderPath, 384);
|
|
25941
|
-
return {
|
|
25942
|
-
pid: process.pid,
|
|
25943
|
-
leaseDir,
|
|
25944
|
-
async release() {
|
|
25945
|
-
await fileSystem.deleteFile(holderPath);
|
|
25946
|
-
}
|
|
25947
|
-
};
|
|
25948
|
-
}
|
|
25949
|
-
async function verifyLeaseHeld(lease, options = {}) {
|
|
25950
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25951
|
-
const owner = await readOwner(fileSystem, lease.leaseDir);
|
|
25952
|
-
if (owner === null || owner.token !== lease.token || owner.id !== lease.id) {
|
|
25953
|
-
throw new BotError("busy", `browser lease ${lease.leaseDir} is not held by this invocation any more \u2014 refusing to borrow it`);
|
|
25954
|
-
}
|
|
25955
|
-
}
|
|
25956
|
-
function canonicalize(profileDir) {
|
|
25957
|
-
let probe = resolve3(profileDir);
|
|
25958
|
-
const tail = [];
|
|
25959
|
-
for (;; ) {
|
|
25960
|
-
if (lstat(probe) !== null) {
|
|
25961
|
-
let canonical;
|
|
25962
|
-
try {
|
|
25963
|
-
canonical = realpath(probe);
|
|
25964
|
-
} catch {
|
|
25965
|
-
canonical = probe;
|
|
25966
|
-
}
|
|
25967
|
-
return tail.length === 0 ? canonical : join3(canonical, ...tail);
|
|
25968
|
-
}
|
|
25969
|
-
const parent = dirname3(probe);
|
|
25970
|
-
if (parent === probe)
|
|
25971
|
-
return join3(probe, ...tail);
|
|
25972
|
-
tail.unshift(basename(probe));
|
|
25973
|
-
probe = parent;
|
|
25974
|
-
}
|
|
25975
|
-
}
|
|
25976
|
-
async function releaseOwnedLease(fileSystem, leaseDir, expected) {
|
|
25977
|
-
const current = await readOwner(fileSystem, leaseDir);
|
|
25978
|
-
if (current === null || current.token !== expected.token || current.id !== expected.id) {
|
|
25979
|
-
throw new BotError("busy", `lease ${leaseDir} is not owned by this invocation \u2014 refusing to release`);
|
|
25980
|
-
}
|
|
25981
|
-
const live = await liveChildHolders(fileSystem, leaseDir);
|
|
25982
|
-
if (live.length > 0) {
|
|
25983
|
-
throw new BotError("busy", `lease ${leaseDir} still has live child holders (pids ${live.join(", ")}) \u2014 stop them before releasing`);
|
|
25984
|
-
}
|
|
25985
|
-
await fileSystem.deleteFile(join3(leaseDir, OWNER_FILE));
|
|
25986
|
-
rmdir(leaseDir);
|
|
25987
|
-
}
|
|
25988
|
-
async function readOwner(fileSystem, leaseDir) {
|
|
25989
|
-
try {
|
|
25990
|
-
return JSON.parse(await fileSystem.readFile(join3(leaseDir, OWNER_FILE)));
|
|
25991
|
-
} catch {
|
|
25992
|
-
return null;
|
|
25993
|
-
}
|
|
25994
|
-
}
|
|
25995
|
-
async function writeOwner(fileSystem, leaseDir, owner) {
|
|
25996
|
-
const path = join3(leaseDir, OWNER_FILE);
|
|
25997
|
-
await fileSystem.writeFile(path, `${JSON.stringify(owner, null, 2)}
|
|
25998
|
-
`);
|
|
25999
|
-
chmod(path, 384);
|
|
26000
|
-
}
|
|
26001
|
-
async function busyGuidance(fileSystem, leaseDir) {
|
|
26002
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26003
|
-
if (owner === null) {
|
|
26004
|
-
const residue = await holderResidue(fileSystem, leaseDir);
|
|
26005
|
-
if (residue !== null) {
|
|
26006
|
-
return `browser lease ${leaseDir} has no owner but ${residue} child holder record(s) remain \u2014 ` + "a previous parent released after its children stopped; confirm no kk browser still uses this " + `profile, then remove ${leaseDir} manually`;
|
|
26007
|
-
}
|
|
26008
|
-
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`;
|
|
26009
|
-
}
|
|
26010
|
-
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
26011
|
-
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}`;
|
|
26012
|
-
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
26013
|
-
}
|
|
26014
|
-
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
26015
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26016
|
-
if (owner === null || isProcessAlive(owner.pid))
|
|
26017
|
-
return false;
|
|
26018
|
-
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
26019
|
-
return false;
|
|
26020
|
-
const target = staleLeaseDir(leaseDir);
|
|
26021
|
-
try {
|
|
26022
|
-
rename(leaseDir, target);
|
|
26023
|
-
} catch {
|
|
26024
|
-
return false;
|
|
26025
|
-
}
|
|
26026
|
-
const moved = await readOwner(fileSystem, target);
|
|
26027
|
-
if (moved !== null && moved.token !== owner.token) {
|
|
26028
|
-
try {
|
|
26029
|
-
rename(target, leaseDir);
|
|
26030
|
-
} catch {}
|
|
26031
|
-
return false;
|
|
26032
|
-
}
|
|
26033
|
-
return true;
|
|
26034
|
-
}
|
|
26035
|
-
function staleLeaseDir(leaseDir) {
|
|
26036
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
26037
|
-
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
26038
|
-
}
|
|
26039
|
-
async function holderResidue(fileSystem, leaseDir) {
|
|
26040
|
-
try {
|
|
26041
|
-
const entries = await fileSystem.readDir(leaseDir);
|
|
26042
|
-
const holders = entries.filter((name) => name.startsWith(HOLDER_PREFIX) && name.endsWith(".json"));
|
|
26043
|
-
return holders.length > 0 ? holders.length : null;
|
|
26044
|
-
} catch {
|
|
26045
|
-
return null;
|
|
26046
|
-
}
|
|
26047
|
-
}
|
|
26048
|
-
async function liveChildHolders(fileSystem, leaseDir) {
|
|
26049
|
-
let entries;
|
|
26050
|
-
try {
|
|
26051
|
-
entries = await fileSystem.readDir(leaseDir);
|
|
26052
|
-
} catch {
|
|
26053
|
-
return [];
|
|
26054
|
-
}
|
|
26055
|
-
const pids = [];
|
|
26056
|
-
for (const name of entries) {
|
|
26057
|
-
if (!name.startsWith(HOLDER_PREFIX) || !name.endsWith(".json"))
|
|
26058
|
-
continue;
|
|
26059
|
-
let record;
|
|
26060
|
-
try {
|
|
26061
|
-
record = JSON.parse(await fileSystem.readFile(join3(leaseDir, name)));
|
|
26062
|
-
} catch {
|
|
26063
|
-
continue;
|
|
26064
|
-
}
|
|
26065
|
-
if (typeof record.pid === "number" && isProcessAlive(record.pid))
|
|
26066
|
-
pids.push(record.pid);
|
|
26067
|
-
}
|
|
26068
|
-
return pids;
|
|
26069
|
-
}
|
|
26070
|
-
function isProcessAlive(pid) {
|
|
26071
|
-
try {
|
|
26072
|
-
process.kill(pid, 0);
|
|
26073
|
-
return true;
|
|
26074
|
-
} catch (error) {
|
|
26075
|
-
return error.code === "EPERM";
|
|
26076
|
-
}
|
|
26077
|
-
}
|
|
26078
|
-
function refuseNativeLock(profileDir) {
|
|
26079
|
-
if (reclaimStaleNativeLock(profileDir))
|
|
26080
|
-
return;
|
|
26081
|
-
for (const name of NATIVE_LOCK_FILES) {
|
|
26082
|
-
const path = join3(profileDir, name);
|
|
26083
|
-
if (lstat(path) !== null) {
|
|
26084
|
-
throw new BotError("busy", `native Chromium ownership present at ${path} \u2014 confirm no browser is using ${profileDir} before retrying`);
|
|
26085
|
-
}
|
|
26086
|
-
}
|
|
26087
|
-
}
|
|
26088
|
-
function reclaimStaleNativeLock(profileDir) {
|
|
26089
|
-
const lockPath = join3(profileDir, "SingletonLock");
|
|
26090
|
-
const target = readlink(lockPath);
|
|
26091
|
-
if (target === null)
|
|
26092
|
-
return false;
|
|
26093
|
-
const match = /^(.*)-(\d+)$/.exec(target);
|
|
26094
|
-
if (match === null)
|
|
26095
|
-
return false;
|
|
26096
|
-
const [, host, pidText] = match;
|
|
26097
|
-
if (host !== hostname())
|
|
26098
|
-
return false;
|
|
26099
|
-
const pid = Number(pidText);
|
|
26100
|
-
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
26101
|
-
return false;
|
|
26102
|
-
for (const name of NATIVE_LOCK_FILES)
|
|
26103
|
-
unlink(join3(profileDir, name));
|
|
26104
|
-
return true;
|
|
26105
|
-
}
|
|
26106
|
-
function sha256Hex(value) {
|
|
26107
|
-
return createHash("sha256").update(value).digest("hex");
|
|
26108
|
-
}
|
|
26109
|
-
|
|
26110
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
26111
|
-
var DEFAULT_BOT_PROFILE_ROOT = join4(homedir4(), ".config", "kk", "browser-profiles");
|
|
26112
|
-
class BotError extends Error {
|
|
26113
|
-
code;
|
|
26114
|
-
details;
|
|
26115
|
-
constructor(code, message, details = {}) {
|
|
26116
|
-
super(message);
|
|
26117
|
-
this.name = "BotError";
|
|
26118
|
-
this.code = code;
|
|
26119
|
-
this.details = details;
|
|
26120
|
-
}
|
|
26121
|
-
}
|
|
26122
26135
|
// ../../packages/publish-harness/src/profile-dir.ts
|
|
26123
26136
|
import { mkdir as mkdir2, stat } from "fs/promises";
|
|
26124
26137
|
async function ensureProfileDir2(profileDir, headless) {
|