@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
|
@@ -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 = [];
|
|
@@ -25628,11 +25903,11 @@ function resolveBrowserProfileDir(channel, override) {
|
|
|
25628
25903
|
if (override && override.trim().length > 0) {
|
|
25629
25904
|
const trimmed = override.trim();
|
|
25630
25905
|
if (trimmed.startsWith("~/")) {
|
|
25631
|
-
return
|
|
25906
|
+
return join4(homedir4(), trimmed.slice(2));
|
|
25632
25907
|
}
|
|
25633
|
-
return
|
|
25908
|
+
return resolve4(trimmed);
|
|
25634
25909
|
}
|
|
25635
|
-
return
|
|
25910
|
+
return join4(homedir4(), ".config", "kk", "browser-profiles", channel);
|
|
25636
25911
|
}
|
|
25637
25912
|
async function trySelectors(page, selectors, options = {}) {
|
|
25638
25913
|
const timeout = options.timeout ?? 2000;
|
|
@@ -25858,268 +26133,6 @@ function sleep(ms) {
|
|
|
25858
26133
|
}
|
|
25859
26134
|
// ../../packages/publish-harness/src/browser.ts
|
|
25860
26135
|
init_dist();
|
|
25861
|
-
|
|
25862
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
25863
|
-
import { homedir as homedir4 } from "os";
|
|
25864
|
-
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
25865
|
-
|
|
25866
|
-
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
25867
|
-
import { homedir as homedir2 } from "os";
|
|
25868
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
25869
|
-
var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-transactions");
|
|
25870
|
-
|
|
25871
|
-
// ../../packages/publish-harness/src/profile-lease.ts
|
|
25872
|
-
import { createHash, randomBytes } from "crypto";
|
|
25873
|
-
import { homedir as homedir3, hostname } from "os";
|
|
25874
|
-
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
25875
|
-
var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
|
|
25876
|
-
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
25877
|
-
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
25878
|
-
var OWNER_FILE = "owner.json";
|
|
25879
|
-
var HOLDER_PREFIX = "holder-";
|
|
25880
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
25881
|
-
async function acquireProfileLease(profileDir, options = {}) {
|
|
25882
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25883
|
-
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
25884
|
-
const logicalPath = canonicalize(profileDir);
|
|
25885
|
-
refuseNativeLock(logicalPath);
|
|
25886
|
-
const id = sha256Hex(logicalPath);
|
|
25887
|
-
const leaseDir = join3(leaseRoot, id);
|
|
25888
|
-
await fileSystem.ensureDir(leaseRoot);
|
|
25889
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25890
|
-
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
25891
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25892
|
-
}
|
|
25893
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25894
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25895
|
-
}
|
|
25896
|
-
}
|
|
25897
|
-
const token = randomBytes(16).toString("hex");
|
|
25898
|
-
const owner = {
|
|
25899
|
-
schemaVersion: 1,
|
|
25900
|
-
id,
|
|
25901
|
-
token,
|
|
25902
|
-
logicalPath,
|
|
25903
|
-
physicalPath: null,
|
|
25904
|
-
pid: process.pid,
|
|
25905
|
-
createdAt: new Date().toISOString()
|
|
25906
|
-
};
|
|
25907
|
-
await writeOwner(fileSystem, leaseDir, owner);
|
|
25908
|
-
return {
|
|
25909
|
-
id,
|
|
25910
|
-
token,
|
|
25911
|
-
profileDir: logicalPath,
|
|
25912
|
-
leaseDir,
|
|
25913
|
-
async release() {
|
|
25914
|
-
await releaseOwnedLease(fileSystem, leaseDir, owner);
|
|
25915
|
-
},
|
|
25916
|
-
async delegatedEnv(physicalProfileDir) {
|
|
25917
|
-
await writeOwner(fileSystem, leaseDir, { ...owner, physicalPath: canonicalize(physicalProfileDir) });
|
|
25918
|
-
return { [KK_BOT_LEASE_PATH]: leaseDir, [KK_BOT_LEASE_TOKEN]: token };
|
|
25919
|
-
}
|
|
25920
|
-
};
|
|
25921
|
-
}
|
|
25922
|
-
async function enterDelegatedLease(env, physicalProfileDir, options = {}) {
|
|
25923
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25924
|
-
const leaseDir = env[KK_BOT_LEASE_PATH];
|
|
25925
|
-
const token = env[KK_BOT_LEASE_TOKEN];
|
|
25926
|
-
if (leaseDir === undefined || leaseDir === "" || token === undefined || token === "") {
|
|
25927
|
-
throw new BotError("usage", `no delegated lease present (${KK_BOT_LEASE_PATH}/${KK_BOT_LEASE_TOKEN})`);
|
|
25928
|
-
}
|
|
25929
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
25930
|
-
if (owner === null)
|
|
25931
|
-
throw new BotError("busy", `delegated lease ${leaseDir} has no owner record`);
|
|
25932
|
-
if (owner.token !== token)
|
|
25933
|
-
throw new BotError("busy", `delegated lease ${leaseDir} token does not match its owner`);
|
|
25934
|
-
const physicalPath = canonicalize(physicalProfileDir);
|
|
25935
|
-
if (owner.physicalPath !== null && owner.physicalPath !== physicalPath) {
|
|
25936
|
-
throw new BotError("busy", `delegated lease ${leaseDir} is bound to ${owner.physicalPath}, not ${physicalPath}`);
|
|
25937
|
-
}
|
|
25938
|
-
const holderPath = join3(leaseDir, `${HOLDER_PREFIX}${process.pid}.json`);
|
|
25939
|
-
await fileSystem.writeFile(holderPath, `${JSON.stringify({ pid: process.pid, physicalPath, enteredAt: new Date().toISOString() }, null, 2)}
|
|
25940
|
-
`);
|
|
25941
|
-
chmod(holderPath, 384);
|
|
25942
|
-
return {
|
|
25943
|
-
pid: process.pid,
|
|
25944
|
-
leaseDir,
|
|
25945
|
-
async release() {
|
|
25946
|
-
await fileSystem.deleteFile(holderPath);
|
|
25947
|
-
}
|
|
25948
|
-
};
|
|
25949
|
-
}
|
|
25950
|
-
async function verifyLeaseHeld(lease, options = {}) {
|
|
25951
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25952
|
-
const owner = await readOwner(fileSystem, lease.leaseDir);
|
|
25953
|
-
if (owner === null || owner.token !== lease.token || owner.id !== lease.id) {
|
|
25954
|
-
throw new BotError("busy", `browser lease ${lease.leaseDir} is not held by this invocation any more \u2014 refusing to borrow it`);
|
|
25955
|
-
}
|
|
25956
|
-
}
|
|
25957
|
-
function canonicalize(profileDir) {
|
|
25958
|
-
let probe = resolve3(profileDir);
|
|
25959
|
-
const tail = [];
|
|
25960
|
-
for (;; ) {
|
|
25961
|
-
if (lstat(probe) !== null) {
|
|
25962
|
-
let canonical;
|
|
25963
|
-
try {
|
|
25964
|
-
canonical = realpath(probe);
|
|
25965
|
-
} catch {
|
|
25966
|
-
canonical = probe;
|
|
25967
|
-
}
|
|
25968
|
-
return tail.length === 0 ? canonical : join3(canonical, ...tail);
|
|
25969
|
-
}
|
|
25970
|
-
const parent = dirname3(probe);
|
|
25971
|
-
if (parent === probe)
|
|
25972
|
-
return join3(probe, ...tail);
|
|
25973
|
-
tail.unshift(basename(probe));
|
|
25974
|
-
probe = parent;
|
|
25975
|
-
}
|
|
25976
|
-
}
|
|
25977
|
-
async function releaseOwnedLease(fileSystem, leaseDir, expected) {
|
|
25978
|
-
const current = await readOwner(fileSystem, leaseDir);
|
|
25979
|
-
if (current === null || current.token !== expected.token || current.id !== expected.id) {
|
|
25980
|
-
throw new BotError("busy", `lease ${leaseDir} is not owned by this invocation \u2014 refusing to release`);
|
|
25981
|
-
}
|
|
25982
|
-
const live = await liveChildHolders(fileSystem, leaseDir);
|
|
25983
|
-
if (live.length > 0) {
|
|
25984
|
-
throw new BotError("busy", `lease ${leaseDir} still has live child holders (pids ${live.join(", ")}) \u2014 stop them before releasing`);
|
|
25985
|
-
}
|
|
25986
|
-
await fileSystem.deleteFile(join3(leaseDir, OWNER_FILE));
|
|
25987
|
-
rmdir(leaseDir);
|
|
25988
|
-
}
|
|
25989
|
-
async function readOwner(fileSystem, leaseDir) {
|
|
25990
|
-
try {
|
|
25991
|
-
return JSON.parse(await fileSystem.readFile(join3(leaseDir, OWNER_FILE)));
|
|
25992
|
-
} catch {
|
|
25993
|
-
return null;
|
|
25994
|
-
}
|
|
25995
|
-
}
|
|
25996
|
-
async function writeOwner(fileSystem, leaseDir, owner) {
|
|
25997
|
-
const path = join3(leaseDir, OWNER_FILE);
|
|
25998
|
-
await fileSystem.writeFile(path, `${JSON.stringify(owner, null, 2)}
|
|
25999
|
-
`);
|
|
26000
|
-
chmod(path, 384);
|
|
26001
|
-
}
|
|
26002
|
-
async function busyGuidance(fileSystem, leaseDir) {
|
|
26003
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26004
|
-
if (owner === null) {
|
|
26005
|
-
const residue = await holderResidue(fileSystem, leaseDir);
|
|
26006
|
-
if (residue !== null) {
|
|
26007
|
-
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`;
|
|
26008
|
-
}
|
|
26009
|
-
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`;
|
|
26010
|
-
}
|
|
26011
|
-
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
26012
|
-
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}`;
|
|
26013
|
-
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
26014
|
-
}
|
|
26015
|
-
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
26016
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26017
|
-
if (owner === null || isProcessAlive(owner.pid))
|
|
26018
|
-
return false;
|
|
26019
|
-
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
26020
|
-
return false;
|
|
26021
|
-
const target = staleLeaseDir(leaseDir);
|
|
26022
|
-
try {
|
|
26023
|
-
rename(leaseDir, target);
|
|
26024
|
-
} catch {
|
|
26025
|
-
return false;
|
|
26026
|
-
}
|
|
26027
|
-
const moved = await readOwner(fileSystem, target);
|
|
26028
|
-
if (moved !== null && moved.token !== owner.token) {
|
|
26029
|
-
try {
|
|
26030
|
-
rename(target, leaseDir);
|
|
26031
|
-
} catch {}
|
|
26032
|
-
return false;
|
|
26033
|
-
}
|
|
26034
|
-
return true;
|
|
26035
|
-
}
|
|
26036
|
-
function staleLeaseDir(leaseDir) {
|
|
26037
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
26038
|
-
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
26039
|
-
}
|
|
26040
|
-
async function holderResidue(fileSystem, leaseDir) {
|
|
26041
|
-
try {
|
|
26042
|
-
const entries = await fileSystem.readDir(leaseDir);
|
|
26043
|
-
const holders = entries.filter((name) => name.startsWith(HOLDER_PREFIX) && name.endsWith(".json"));
|
|
26044
|
-
return holders.length > 0 ? holders.length : null;
|
|
26045
|
-
} catch {
|
|
26046
|
-
return null;
|
|
26047
|
-
}
|
|
26048
|
-
}
|
|
26049
|
-
async function liveChildHolders(fileSystem, leaseDir) {
|
|
26050
|
-
let entries;
|
|
26051
|
-
try {
|
|
26052
|
-
entries = await fileSystem.readDir(leaseDir);
|
|
26053
|
-
} catch {
|
|
26054
|
-
return [];
|
|
26055
|
-
}
|
|
26056
|
-
const pids = [];
|
|
26057
|
-
for (const name of entries) {
|
|
26058
|
-
if (!name.startsWith(HOLDER_PREFIX) || !name.endsWith(".json"))
|
|
26059
|
-
continue;
|
|
26060
|
-
let record;
|
|
26061
|
-
try {
|
|
26062
|
-
record = JSON.parse(await fileSystem.readFile(join3(leaseDir, name)));
|
|
26063
|
-
} catch {
|
|
26064
|
-
continue;
|
|
26065
|
-
}
|
|
26066
|
-
if (typeof record.pid === "number" && isProcessAlive(record.pid))
|
|
26067
|
-
pids.push(record.pid);
|
|
26068
|
-
}
|
|
26069
|
-
return pids;
|
|
26070
|
-
}
|
|
26071
|
-
function isProcessAlive(pid) {
|
|
26072
|
-
try {
|
|
26073
|
-
process.kill(pid, 0);
|
|
26074
|
-
return true;
|
|
26075
|
-
} catch (error) {
|
|
26076
|
-
return error.code === "EPERM";
|
|
26077
|
-
}
|
|
26078
|
-
}
|
|
26079
|
-
function refuseNativeLock(profileDir) {
|
|
26080
|
-
if (reclaimStaleNativeLock(profileDir))
|
|
26081
|
-
return;
|
|
26082
|
-
for (const name of NATIVE_LOCK_FILES) {
|
|
26083
|
-
const path = join3(profileDir, name);
|
|
26084
|
-
if (lstat(path) !== null) {
|
|
26085
|
-
throw new BotError("busy", `native Chromium ownership present at ${path} \u2014 confirm no browser is using ${profileDir} before retrying`);
|
|
26086
|
-
}
|
|
26087
|
-
}
|
|
26088
|
-
}
|
|
26089
|
-
function reclaimStaleNativeLock(profileDir) {
|
|
26090
|
-
const lockPath = join3(profileDir, "SingletonLock");
|
|
26091
|
-
const target = readlink(lockPath);
|
|
26092
|
-
if (target === null)
|
|
26093
|
-
return false;
|
|
26094
|
-
const match = /^(.*)-(\d+)$/.exec(target);
|
|
26095
|
-
if (match === null)
|
|
26096
|
-
return false;
|
|
26097
|
-
const [, host, pidText] = match;
|
|
26098
|
-
if (host !== hostname())
|
|
26099
|
-
return false;
|
|
26100
|
-
const pid = Number(pidText);
|
|
26101
|
-
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
26102
|
-
return false;
|
|
26103
|
-
for (const name of NATIVE_LOCK_FILES)
|
|
26104
|
-
unlink(join3(profileDir, name));
|
|
26105
|
-
return true;
|
|
26106
|
-
}
|
|
26107
|
-
function sha256Hex(value) {
|
|
26108
|
-
return createHash("sha256").update(value).digest("hex");
|
|
26109
|
-
}
|
|
26110
|
-
|
|
26111
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
26112
|
-
var DEFAULT_BOT_PROFILE_ROOT = join4(homedir4(), ".config", "kk", "browser-profiles");
|
|
26113
|
-
class BotError extends Error {
|
|
26114
|
-
code;
|
|
26115
|
-
details;
|
|
26116
|
-
constructor(code, message, details = {}) {
|
|
26117
|
-
super(message);
|
|
26118
|
-
this.name = "BotError";
|
|
26119
|
-
this.code = code;
|
|
26120
|
-
this.details = details;
|
|
26121
|
-
}
|
|
26122
|
-
}
|
|
26123
26136
|
// ../../packages/publish-harness/src/profile-dir.ts
|
|
26124
26137
|
import { mkdir as mkdir2, stat } from "fs/promises";
|
|
26125
26138
|
async function ensureProfileDir2(profileDir, headless) {
|