@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
|
@@ -25316,7 +25316,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
|
|
|
25316
25316
|
})
|
|
25317
25317
|
});
|
|
25318
25318
|
var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
|
|
25319
|
-
var VideoRenderProviderSchema = _enum([
|
|
25319
|
+
var VideoRenderProviderSchema = _enum([
|
|
25320
|
+
"local-ken-burns",
|
|
25321
|
+
"wan21-i2v",
|
|
25322
|
+
"comfyui-minimax-h3",
|
|
25323
|
+
"musetalk",
|
|
25324
|
+
"echomimic-v2"
|
|
25325
|
+
]);
|
|
25326
|
+
var RenderProvenanceSchema = object({
|
|
25327
|
+
cache: _enum(["drive", "local"]),
|
|
25328
|
+
comfyuiCommit: string2().min(1).optional(),
|
|
25329
|
+
comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
|
|
25330
|
+
modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
|
|
25331
|
+
});
|
|
25320
25332
|
var videoGenContentSchema = ContentSchema.extend({
|
|
25321
25333
|
format: literal("video"),
|
|
25322
25334
|
metadata: looseObject({
|
|
@@ -25329,6 +25341,7 @@ var videoGenContentSchema = ContentSchema.extend({
|
|
|
25329
25341
|
durationSec: number2().positive(),
|
|
25330
25342
|
visualMode: VideoVisualModeSchema,
|
|
25331
25343
|
renderProvider: VideoRenderProviderSchema,
|
|
25344
|
+
renderProvenance: RenderProvenanceSchema.optional(),
|
|
25332
25345
|
fallbackUsed: boolean2().optional(),
|
|
25333
25346
|
warnings: array(string2()).optional(),
|
|
25334
25347
|
ccuEstimated: number2().nonnegative().optional(),
|
|
@@ -25524,13 +25537,17 @@ var CJK_TERMINATORS = new Set(["\u3002", "\uFF01", "\uFF1F"]);
|
|
|
25524
25537
|
var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
25525
25538
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
25526
25539
|
// ../../packages/publish-harness/src/index.ts
|
|
25527
|
-
import { homedir } from "os";
|
|
25528
|
-
import { join, resolve } from "path";
|
|
25540
|
+
import { homedir as homedir4 } from "os";
|
|
25541
|
+
import { join as join4, resolve as resolve4 } from "path";
|
|
25529
25542
|
|
|
25530
25543
|
// ../../packages/publish-harness/src/session-state.ts
|
|
25531
25544
|
import { randomUUID } from "crypto";
|
|
25532
25545
|
init_dist();
|
|
25533
25546
|
|
|
25547
|
+
// ../../packages/publish-harness/src/bot.ts
|
|
25548
|
+
import { homedir as homedir3 } from "os";
|
|
25549
|
+
import { isAbsolute, join as join3, relative, resolve as resolve3, sep } from "path";
|
|
25550
|
+
|
|
25534
25551
|
// ../../packages/publish-harness/src/bot-fs.ts
|
|
25535
25552
|
import {
|
|
25536
25553
|
chmodSync,
|
|
@@ -25613,6 +25630,264 @@ function createExclusiveFile(path) {
|
|
|
25613
25630
|
closeSync(openSync(path, "wx", 384));
|
|
25614
25631
|
}
|
|
25615
25632
|
|
|
25633
|
+
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
25634
|
+
import { homedir } from "os";
|
|
25635
|
+
import { dirname as dirname2, join, resolve } from "path";
|
|
25636
|
+
var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-transactions");
|
|
25637
|
+
|
|
25638
|
+
// ../../packages/publish-harness/src/profile-lease.ts
|
|
25639
|
+
import { createHash, randomBytes } from "crypto";
|
|
25640
|
+
import { homedir as homedir2, hostname } from "os";
|
|
25641
|
+
import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
|
|
25642
|
+
var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
|
|
25643
|
+
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
25644
|
+
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
25645
|
+
var OWNER_FILE = "owner.json";
|
|
25646
|
+
var HOLDER_PREFIX = "holder-";
|
|
25647
|
+
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
25648
|
+
async function acquireProfileLease(profileDir, options = {}) {
|
|
25649
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25650
|
+
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
25651
|
+
const logicalPath = canonicalize(profileDir);
|
|
25652
|
+
refuseNativeLock(logicalPath);
|
|
25653
|
+
const id = sha256Hex(logicalPath);
|
|
25654
|
+
const leaseDir = join2(leaseRoot, id);
|
|
25655
|
+
await fileSystem.ensureDir(leaseRoot);
|
|
25656
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25657
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
25658
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25659
|
+
}
|
|
25660
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
25661
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
25662
|
+
}
|
|
25663
|
+
}
|
|
25664
|
+
const token = randomBytes(16).toString("hex");
|
|
25665
|
+
const owner = {
|
|
25666
|
+
schemaVersion: 1,
|
|
25667
|
+
id,
|
|
25668
|
+
token,
|
|
25669
|
+
logicalPath,
|
|
25670
|
+
physicalPath: null,
|
|
25671
|
+
pid: process.pid,
|
|
25672
|
+
createdAt: new Date().toISOString()
|
|
25673
|
+
};
|
|
25674
|
+
await writeOwner(fileSystem, leaseDir, owner);
|
|
25675
|
+
return {
|
|
25676
|
+
id,
|
|
25677
|
+
token,
|
|
25678
|
+
profileDir: logicalPath,
|
|
25679
|
+
leaseDir,
|
|
25680
|
+
async release() {
|
|
25681
|
+
await releaseOwnedLease(fileSystem, leaseDir, owner);
|
|
25682
|
+
},
|
|
25683
|
+
async delegatedEnv(physicalProfileDir) {
|
|
25684
|
+
await writeOwner(fileSystem, leaseDir, { ...owner, physicalPath: canonicalize(physicalProfileDir) });
|
|
25685
|
+
return { [KK_BOT_LEASE_PATH]: leaseDir, [KK_BOT_LEASE_TOKEN]: token };
|
|
25686
|
+
}
|
|
25687
|
+
};
|
|
25688
|
+
}
|
|
25689
|
+
async function enterDelegatedLease(env, physicalProfileDir, options = {}) {
|
|
25690
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25691
|
+
const leaseDir = env[KK_BOT_LEASE_PATH];
|
|
25692
|
+
const token = env[KK_BOT_LEASE_TOKEN];
|
|
25693
|
+
if (leaseDir === undefined || leaseDir === "" || token === undefined || token === "") {
|
|
25694
|
+
throw new BotError("usage", `no delegated lease present (${KK_BOT_LEASE_PATH}/${KK_BOT_LEASE_TOKEN})`);
|
|
25695
|
+
}
|
|
25696
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25697
|
+
if (owner === null)
|
|
25698
|
+
throw new BotError("busy", `delegated lease ${leaseDir} has no owner record`);
|
|
25699
|
+
if (owner.token !== token)
|
|
25700
|
+
throw new BotError("busy", `delegated lease ${leaseDir} token does not match its owner`);
|
|
25701
|
+
const physicalPath = canonicalize(physicalProfileDir);
|
|
25702
|
+
if (owner.physicalPath !== null && owner.physicalPath !== physicalPath) {
|
|
25703
|
+
throw new BotError("busy", `delegated lease ${leaseDir} is bound to ${owner.physicalPath}, not ${physicalPath}`);
|
|
25704
|
+
}
|
|
25705
|
+
const holderPath = join2(leaseDir, `${HOLDER_PREFIX}${process.pid}.json`);
|
|
25706
|
+
await fileSystem.writeFile(holderPath, `${JSON.stringify({ pid: process.pid, physicalPath, enteredAt: new Date().toISOString() }, null, 2)}
|
|
25707
|
+
`);
|
|
25708
|
+
chmod(holderPath, 384);
|
|
25709
|
+
return {
|
|
25710
|
+
pid: process.pid,
|
|
25711
|
+
leaseDir,
|
|
25712
|
+
async release() {
|
|
25713
|
+
await fileSystem.deleteFile(holderPath);
|
|
25714
|
+
}
|
|
25715
|
+
};
|
|
25716
|
+
}
|
|
25717
|
+
async function verifyLeaseHeld(lease, options = {}) {
|
|
25718
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25719
|
+
const owner = await readOwner(fileSystem, lease.leaseDir);
|
|
25720
|
+
if (owner === null || owner.token !== lease.token || owner.id !== lease.id) {
|
|
25721
|
+
throw new BotError("busy", `browser lease ${lease.leaseDir} is not held by this invocation any more \u2014 refusing to borrow it`);
|
|
25722
|
+
}
|
|
25723
|
+
}
|
|
25724
|
+
function canonicalize(profileDir) {
|
|
25725
|
+
let probe = resolve2(profileDir);
|
|
25726
|
+
const tail = [];
|
|
25727
|
+
for (;; ) {
|
|
25728
|
+
if (lstat(probe) !== null) {
|
|
25729
|
+
let canonical;
|
|
25730
|
+
try {
|
|
25731
|
+
canonical = realpath(probe);
|
|
25732
|
+
} catch {
|
|
25733
|
+
canonical = probe;
|
|
25734
|
+
}
|
|
25735
|
+
return tail.length === 0 ? canonical : join2(canonical, ...tail);
|
|
25736
|
+
}
|
|
25737
|
+
const parent = dirname3(probe);
|
|
25738
|
+
if (parent === probe)
|
|
25739
|
+
return join2(probe, ...tail);
|
|
25740
|
+
tail.unshift(basename(probe));
|
|
25741
|
+
probe = parent;
|
|
25742
|
+
}
|
|
25743
|
+
}
|
|
25744
|
+
async function releaseOwnedLease(fileSystem, leaseDir, expected) {
|
|
25745
|
+
const current = await readOwner(fileSystem, leaseDir);
|
|
25746
|
+
if (current === null || current.token !== expected.token || current.id !== expected.id) {
|
|
25747
|
+
throw new BotError("busy", `lease ${leaseDir} is not owned by this invocation \u2014 refusing to release`);
|
|
25748
|
+
}
|
|
25749
|
+
const live = await liveChildHolders(fileSystem, leaseDir);
|
|
25750
|
+
if (live.length > 0) {
|
|
25751
|
+
throw new BotError("busy", `lease ${leaseDir} still has live child holders (pids ${live.join(", ")}) \u2014 stop them before releasing`);
|
|
25752
|
+
}
|
|
25753
|
+
await fileSystem.deleteFile(join2(leaseDir, OWNER_FILE));
|
|
25754
|
+
rmdir(leaseDir);
|
|
25755
|
+
}
|
|
25756
|
+
async function readOwner(fileSystem, leaseDir) {
|
|
25757
|
+
try {
|
|
25758
|
+
return JSON.parse(await fileSystem.readFile(join2(leaseDir, OWNER_FILE)));
|
|
25759
|
+
} catch {
|
|
25760
|
+
return null;
|
|
25761
|
+
}
|
|
25762
|
+
}
|
|
25763
|
+
async function writeOwner(fileSystem, leaseDir, owner) {
|
|
25764
|
+
const path = join2(leaseDir, OWNER_FILE);
|
|
25765
|
+
await fileSystem.writeFile(path, `${JSON.stringify(owner, null, 2)}
|
|
25766
|
+
`);
|
|
25767
|
+
chmod(path, 384);
|
|
25768
|
+
}
|
|
25769
|
+
async function busyGuidance(fileSystem, leaseDir) {
|
|
25770
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25771
|
+
if (owner === null) {
|
|
25772
|
+
const residue = await holderResidue(fileSystem, leaseDir);
|
|
25773
|
+
if (residue !== null) {
|
|
25774
|
+
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`;
|
|
25775
|
+
}
|
|
25776
|
+
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`;
|
|
25777
|
+
}
|
|
25778
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
25779
|
+
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}`;
|
|
25780
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
25781
|
+
}
|
|
25782
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
25783
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
25784
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
25785
|
+
return false;
|
|
25786
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
25787
|
+
return false;
|
|
25788
|
+
const target = staleLeaseDir(leaseDir);
|
|
25789
|
+
try {
|
|
25790
|
+
rename(leaseDir, target);
|
|
25791
|
+
} catch {
|
|
25792
|
+
return false;
|
|
25793
|
+
}
|
|
25794
|
+
const moved = await readOwner(fileSystem, target);
|
|
25795
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
25796
|
+
try {
|
|
25797
|
+
rename(target, leaseDir);
|
|
25798
|
+
} catch {}
|
|
25799
|
+
return false;
|
|
25800
|
+
}
|
|
25801
|
+
return true;
|
|
25802
|
+
}
|
|
25803
|
+
function staleLeaseDir(leaseDir) {
|
|
25804
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
25805
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
25806
|
+
}
|
|
25807
|
+
async function holderResidue(fileSystem, leaseDir) {
|
|
25808
|
+
try {
|
|
25809
|
+
const entries = await fileSystem.readDir(leaseDir);
|
|
25810
|
+
const holders = entries.filter((name) => name.startsWith(HOLDER_PREFIX) && name.endsWith(".json"));
|
|
25811
|
+
return holders.length > 0 ? holders.length : null;
|
|
25812
|
+
} catch {
|
|
25813
|
+
return null;
|
|
25814
|
+
}
|
|
25815
|
+
}
|
|
25816
|
+
async function liveChildHolders(fileSystem, leaseDir) {
|
|
25817
|
+
let entries;
|
|
25818
|
+
try {
|
|
25819
|
+
entries = await fileSystem.readDir(leaseDir);
|
|
25820
|
+
} catch {
|
|
25821
|
+
return [];
|
|
25822
|
+
}
|
|
25823
|
+
const pids = [];
|
|
25824
|
+
for (const name of entries) {
|
|
25825
|
+
if (!name.startsWith(HOLDER_PREFIX) || !name.endsWith(".json"))
|
|
25826
|
+
continue;
|
|
25827
|
+
let record;
|
|
25828
|
+
try {
|
|
25829
|
+
record = JSON.parse(await fileSystem.readFile(join2(leaseDir, name)));
|
|
25830
|
+
} catch {
|
|
25831
|
+
continue;
|
|
25832
|
+
}
|
|
25833
|
+
if (typeof record.pid === "number" && isProcessAlive(record.pid))
|
|
25834
|
+
pids.push(record.pid);
|
|
25835
|
+
}
|
|
25836
|
+
return pids;
|
|
25837
|
+
}
|
|
25838
|
+
function isProcessAlive(pid) {
|
|
25839
|
+
try {
|
|
25840
|
+
process.kill(pid, 0);
|
|
25841
|
+
return true;
|
|
25842
|
+
} catch (error) {
|
|
25843
|
+
return error.code === "EPERM";
|
|
25844
|
+
}
|
|
25845
|
+
}
|
|
25846
|
+
function refuseNativeLock(profileDir) {
|
|
25847
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
25848
|
+
return;
|
|
25849
|
+
for (const name of NATIVE_LOCK_FILES) {
|
|
25850
|
+
const path = join2(profileDir, name);
|
|
25851
|
+
if (lstat(path) !== null) {
|
|
25852
|
+
throw new BotError("busy", `native Chromium ownership present at ${path} \u2014 confirm no browser is using ${profileDir} before retrying`);
|
|
25853
|
+
}
|
|
25854
|
+
}
|
|
25855
|
+
}
|
|
25856
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
25857
|
+
const lockPath = join2(profileDir, "SingletonLock");
|
|
25858
|
+
const target = readlink(lockPath);
|
|
25859
|
+
if (target === null)
|
|
25860
|
+
return false;
|
|
25861
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
25862
|
+
if (match === null)
|
|
25863
|
+
return false;
|
|
25864
|
+
const [, host, pidText] = match;
|
|
25865
|
+
if (host !== hostname())
|
|
25866
|
+
return false;
|
|
25867
|
+
const pid = Number(pidText);
|
|
25868
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
25869
|
+
return false;
|
|
25870
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
25871
|
+
unlink(join2(profileDir, name));
|
|
25872
|
+
return true;
|
|
25873
|
+
}
|
|
25874
|
+
function sha256Hex(value) {
|
|
25875
|
+
return createHash("sha256").update(value).digest("hex");
|
|
25876
|
+
}
|
|
25877
|
+
|
|
25878
|
+
// ../../packages/publish-harness/src/bot.ts
|
|
25879
|
+
var DEFAULT_BOT_PROFILE_ROOT = join3(homedir3(), ".config", "kk", "browser-profiles");
|
|
25880
|
+
class BotError extends Error {
|
|
25881
|
+
code;
|
|
25882
|
+
details;
|
|
25883
|
+
constructor(code, message, details = {}) {
|
|
25884
|
+
super(message);
|
|
25885
|
+
this.name = "BotError";
|
|
25886
|
+
this.code = code;
|
|
25887
|
+
this.details = details;
|
|
25888
|
+
}
|
|
25889
|
+
}
|
|
25890
|
+
|
|
25616
25891
|
// ../../packages/publish-harness/src/session-state.ts
|
|
25617
25892
|
function channelStorageStatePath(profileDir) {
|
|
25618
25893
|
return `${profileDir}/storage-state.json`;
|
|
@@ -25760,11 +26035,11 @@ function resolveBrowserProfileDir(channel, override) {
|
|
|
25760
26035
|
if (override && override.trim().length > 0) {
|
|
25761
26036
|
const trimmed = override.trim();
|
|
25762
26037
|
if (trimmed.startsWith("~/")) {
|
|
25763
|
-
return
|
|
26038
|
+
return join4(homedir4(), trimmed.slice(2));
|
|
25764
26039
|
}
|
|
25765
|
-
return
|
|
26040
|
+
return resolve4(trimmed);
|
|
25766
26041
|
}
|
|
25767
|
-
return
|
|
26042
|
+
return join4(homedir4(), ".config", "kk", "browser-profiles", channel);
|
|
25768
26043
|
}
|
|
25769
26044
|
|
|
25770
26045
|
// ../../plugins/publishings/shipinhao-pub/src/index.ts
|
|
@@ -25969,268 +26244,6 @@ function sleep(ms) {
|
|
|
25969
26244
|
}
|
|
25970
26245
|
// ../../packages/publish-harness/src/browser.ts
|
|
25971
26246
|
init_dist();
|
|
25972
|
-
|
|
25973
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
25974
|
-
import { homedir as homedir4 } from "os";
|
|
25975
|
-
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
25976
|
-
|
|
25977
|
-
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
25978
|
-
import { homedir as homedir2 } from "os";
|
|
25979
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
25980
|
-
var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-transactions");
|
|
25981
|
-
|
|
25982
|
-
// ../../packages/publish-harness/src/profile-lease.ts
|
|
25983
|
-
import { createHash, randomBytes } from "crypto";
|
|
25984
|
-
import { homedir as homedir3, hostname } from "os";
|
|
25985
|
-
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
25986
|
-
var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
|
|
25987
|
-
var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
|
|
25988
|
-
var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
|
|
25989
|
-
var OWNER_FILE = "owner.json";
|
|
25990
|
-
var HOLDER_PREFIX = "holder-";
|
|
25991
|
-
var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
25992
|
-
async function acquireProfileLease(profileDir, options = {}) {
|
|
25993
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
25994
|
-
const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
|
|
25995
|
-
const logicalPath = canonicalize(profileDir);
|
|
25996
|
-
refuseNativeLock(logicalPath);
|
|
25997
|
-
const id = sha256Hex(logicalPath);
|
|
25998
|
-
const leaseDir = join3(leaseRoot, id);
|
|
25999
|
-
await fileSystem.ensureDir(leaseRoot);
|
|
26000
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
26001
|
-
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
26002
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
26003
|
-
}
|
|
26004
|
-
if (!mkdirExclusive(leaseDir, 448)) {
|
|
26005
|
-
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
26006
|
-
}
|
|
26007
|
-
}
|
|
26008
|
-
const token = randomBytes(16).toString("hex");
|
|
26009
|
-
const owner = {
|
|
26010
|
-
schemaVersion: 1,
|
|
26011
|
-
id,
|
|
26012
|
-
token,
|
|
26013
|
-
logicalPath,
|
|
26014
|
-
physicalPath: null,
|
|
26015
|
-
pid: process.pid,
|
|
26016
|
-
createdAt: new Date().toISOString()
|
|
26017
|
-
};
|
|
26018
|
-
await writeOwner(fileSystem, leaseDir, owner);
|
|
26019
|
-
return {
|
|
26020
|
-
id,
|
|
26021
|
-
token,
|
|
26022
|
-
profileDir: logicalPath,
|
|
26023
|
-
leaseDir,
|
|
26024
|
-
async release() {
|
|
26025
|
-
await releaseOwnedLease(fileSystem, leaseDir, owner);
|
|
26026
|
-
},
|
|
26027
|
-
async delegatedEnv(physicalProfileDir) {
|
|
26028
|
-
await writeOwner(fileSystem, leaseDir, { ...owner, physicalPath: canonicalize(physicalProfileDir) });
|
|
26029
|
-
return { [KK_BOT_LEASE_PATH]: leaseDir, [KK_BOT_LEASE_TOKEN]: token };
|
|
26030
|
-
}
|
|
26031
|
-
};
|
|
26032
|
-
}
|
|
26033
|
-
async function enterDelegatedLease(env, physicalProfileDir, options = {}) {
|
|
26034
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
26035
|
-
const leaseDir = env[KK_BOT_LEASE_PATH];
|
|
26036
|
-
const token = env[KK_BOT_LEASE_TOKEN];
|
|
26037
|
-
if (leaseDir === undefined || leaseDir === "" || token === undefined || token === "") {
|
|
26038
|
-
throw new BotError("usage", `no delegated lease present (${KK_BOT_LEASE_PATH}/${KK_BOT_LEASE_TOKEN})`);
|
|
26039
|
-
}
|
|
26040
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26041
|
-
if (owner === null)
|
|
26042
|
-
throw new BotError("busy", `delegated lease ${leaseDir} has no owner record`);
|
|
26043
|
-
if (owner.token !== token)
|
|
26044
|
-
throw new BotError("busy", `delegated lease ${leaseDir} token does not match its owner`);
|
|
26045
|
-
const physicalPath = canonicalize(physicalProfileDir);
|
|
26046
|
-
if (owner.physicalPath !== null && owner.physicalPath !== physicalPath) {
|
|
26047
|
-
throw new BotError("busy", `delegated lease ${leaseDir} is bound to ${owner.physicalPath}, not ${physicalPath}`);
|
|
26048
|
-
}
|
|
26049
|
-
const holderPath = join3(leaseDir, `${HOLDER_PREFIX}${process.pid}.json`);
|
|
26050
|
-
await fileSystem.writeFile(holderPath, `${JSON.stringify({ pid: process.pid, physicalPath, enteredAt: new Date().toISOString() }, null, 2)}
|
|
26051
|
-
`);
|
|
26052
|
-
chmod(holderPath, 384);
|
|
26053
|
-
return {
|
|
26054
|
-
pid: process.pid,
|
|
26055
|
-
leaseDir,
|
|
26056
|
-
async release() {
|
|
26057
|
-
await fileSystem.deleteFile(holderPath);
|
|
26058
|
-
}
|
|
26059
|
-
};
|
|
26060
|
-
}
|
|
26061
|
-
async function verifyLeaseHeld(lease, options = {}) {
|
|
26062
|
-
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
26063
|
-
const owner = await readOwner(fileSystem, lease.leaseDir);
|
|
26064
|
-
if (owner === null || owner.token !== lease.token || owner.id !== lease.id) {
|
|
26065
|
-
throw new BotError("busy", `browser lease ${lease.leaseDir} is not held by this invocation any more \u2014 refusing to borrow it`);
|
|
26066
|
-
}
|
|
26067
|
-
}
|
|
26068
|
-
function canonicalize(profileDir) {
|
|
26069
|
-
let probe = resolve3(profileDir);
|
|
26070
|
-
const tail = [];
|
|
26071
|
-
for (;; ) {
|
|
26072
|
-
if (lstat(probe) !== null) {
|
|
26073
|
-
let canonical;
|
|
26074
|
-
try {
|
|
26075
|
-
canonical = realpath(probe);
|
|
26076
|
-
} catch {
|
|
26077
|
-
canonical = probe;
|
|
26078
|
-
}
|
|
26079
|
-
return tail.length === 0 ? canonical : join3(canonical, ...tail);
|
|
26080
|
-
}
|
|
26081
|
-
const parent = dirname3(probe);
|
|
26082
|
-
if (parent === probe)
|
|
26083
|
-
return join3(probe, ...tail);
|
|
26084
|
-
tail.unshift(basename(probe));
|
|
26085
|
-
probe = parent;
|
|
26086
|
-
}
|
|
26087
|
-
}
|
|
26088
|
-
async function releaseOwnedLease(fileSystem, leaseDir, expected) {
|
|
26089
|
-
const current = await readOwner(fileSystem, leaseDir);
|
|
26090
|
-
if (current === null || current.token !== expected.token || current.id !== expected.id) {
|
|
26091
|
-
throw new BotError("busy", `lease ${leaseDir} is not owned by this invocation \u2014 refusing to release`);
|
|
26092
|
-
}
|
|
26093
|
-
const live = await liveChildHolders(fileSystem, leaseDir);
|
|
26094
|
-
if (live.length > 0) {
|
|
26095
|
-
throw new BotError("busy", `lease ${leaseDir} still has live child holders (pids ${live.join(", ")}) \u2014 stop them before releasing`);
|
|
26096
|
-
}
|
|
26097
|
-
await fileSystem.deleteFile(join3(leaseDir, OWNER_FILE));
|
|
26098
|
-
rmdir(leaseDir);
|
|
26099
|
-
}
|
|
26100
|
-
async function readOwner(fileSystem, leaseDir) {
|
|
26101
|
-
try {
|
|
26102
|
-
return JSON.parse(await fileSystem.readFile(join3(leaseDir, OWNER_FILE)));
|
|
26103
|
-
} catch {
|
|
26104
|
-
return null;
|
|
26105
|
-
}
|
|
26106
|
-
}
|
|
26107
|
-
async function writeOwner(fileSystem, leaseDir, owner) {
|
|
26108
|
-
const path = join3(leaseDir, OWNER_FILE);
|
|
26109
|
-
await fileSystem.writeFile(path, `${JSON.stringify(owner, null, 2)}
|
|
26110
|
-
`);
|
|
26111
|
-
chmod(path, 384);
|
|
26112
|
-
}
|
|
26113
|
-
async function busyGuidance(fileSystem, leaseDir) {
|
|
26114
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26115
|
-
if (owner === null) {
|
|
26116
|
-
const residue = await holderResidue(fileSystem, leaseDir);
|
|
26117
|
-
if (residue !== null) {
|
|
26118
|
-
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`;
|
|
26119
|
-
}
|
|
26120
|
-
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`;
|
|
26121
|
-
}
|
|
26122
|
-
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
26123
|
-
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}`;
|
|
26124
|
-
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
26125
|
-
}
|
|
26126
|
-
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
26127
|
-
const owner = await readOwner(fileSystem, leaseDir);
|
|
26128
|
-
if (owner === null || isProcessAlive(owner.pid))
|
|
26129
|
-
return false;
|
|
26130
|
-
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
26131
|
-
return false;
|
|
26132
|
-
const target = staleLeaseDir(leaseDir);
|
|
26133
|
-
try {
|
|
26134
|
-
rename(leaseDir, target);
|
|
26135
|
-
} catch {
|
|
26136
|
-
return false;
|
|
26137
|
-
}
|
|
26138
|
-
const moved = await readOwner(fileSystem, target);
|
|
26139
|
-
if (moved !== null && moved.token !== owner.token) {
|
|
26140
|
-
try {
|
|
26141
|
-
rename(target, leaseDir);
|
|
26142
|
-
} catch {}
|
|
26143
|
-
return false;
|
|
26144
|
-
}
|
|
26145
|
-
return true;
|
|
26146
|
-
}
|
|
26147
|
-
function staleLeaseDir(leaseDir) {
|
|
26148
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
26149
|
-
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
26150
|
-
}
|
|
26151
|
-
async function holderResidue(fileSystem, leaseDir) {
|
|
26152
|
-
try {
|
|
26153
|
-
const entries = await fileSystem.readDir(leaseDir);
|
|
26154
|
-
const holders = entries.filter((name) => name.startsWith(HOLDER_PREFIX) && name.endsWith(".json"));
|
|
26155
|
-
return holders.length > 0 ? holders.length : null;
|
|
26156
|
-
} catch {
|
|
26157
|
-
return null;
|
|
26158
|
-
}
|
|
26159
|
-
}
|
|
26160
|
-
async function liveChildHolders(fileSystem, leaseDir) {
|
|
26161
|
-
let entries;
|
|
26162
|
-
try {
|
|
26163
|
-
entries = await fileSystem.readDir(leaseDir);
|
|
26164
|
-
} catch {
|
|
26165
|
-
return [];
|
|
26166
|
-
}
|
|
26167
|
-
const pids = [];
|
|
26168
|
-
for (const name of entries) {
|
|
26169
|
-
if (!name.startsWith(HOLDER_PREFIX) || !name.endsWith(".json"))
|
|
26170
|
-
continue;
|
|
26171
|
-
let record;
|
|
26172
|
-
try {
|
|
26173
|
-
record = JSON.parse(await fileSystem.readFile(join3(leaseDir, name)));
|
|
26174
|
-
} catch {
|
|
26175
|
-
continue;
|
|
26176
|
-
}
|
|
26177
|
-
if (typeof record.pid === "number" && isProcessAlive(record.pid))
|
|
26178
|
-
pids.push(record.pid);
|
|
26179
|
-
}
|
|
26180
|
-
return pids;
|
|
26181
|
-
}
|
|
26182
|
-
function isProcessAlive(pid) {
|
|
26183
|
-
try {
|
|
26184
|
-
process.kill(pid, 0);
|
|
26185
|
-
return true;
|
|
26186
|
-
} catch (error) {
|
|
26187
|
-
return error.code === "EPERM";
|
|
26188
|
-
}
|
|
26189
|
-
}
|
|
26190
|
-
function refuseNativeLock(profileDir) {
|
|
26191
|
-
if (reclaimStaleNativeLock(profileDir))
|
|
26192
|
-
return;
|
|
26193
|
-
for (const name of NATIVE_LOCK_FILES) {
|
|
26194
|
-
const path = join3(profileDir, name);
|
|
26195
|
-
if (lstat(path) !== null) {
|
|
26196
|
-
throw new BotError("busy", `native Chromium ownership present at ${path} \u2014 confirm no browser is using ${profileDir} before retrying`);
|
|
26197
|
-
}
|
|
26198
|
-
}
|
|
26199
|
-
}
|
|
26200
|
-
function reclaimStaleNativeLock(profileDir) {
|
|
26201
|
-
const lockPath = join3(profileDir, "SingletonLock");
|
|
26202
|
-
const target = readlink(lockPath);
|
|
26203
|
-
if (target === null)
|
|
26204
|
-
return false;
|
|
26205
|
-
const match = /^(.*)-(\d+)$/.exec(target);
|
|
26206
|
-
if (match === null)
|
|
26207
|
-
return false;
|
|
26208
|
-
const [, host, pidText] = match;
|
|
26209
|
-
if (host !== hostname())
|
|
26210
|
-
return false;
|
|
26211
|
-
const pid = Number(pidText);
|
|
26212
|
-
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
26213
|
-
return false;
|
|
26214
|
-
for (const name of NATIVE_LOCK_FILES)
|
|
26215
|
-
unlink(join3(profileDir, name));
|
|
26216
|
-
return true;
|
|
26217
|
-
}
|
|
26218
|
-
function sha256Hex(value) {
|
|
26219
|
-
return createHash("sha256").update(value).digest("hex");
|
|
26220
|
-
}
|
|
26221
|
-
|
|
26222
|
-
// ../../packages/publish-harness/src/bot.ts
|
|
26223
|
-
var DEFAULT_BOT_PROFILE_ROOT = join4(homedir4(), ".config", "kk", "browser-profiles");
|
|
26224
|
-
class BotError extends Error {
|
|
26225
|
-
code;
|
|
26226
|
-
details;
|
|
26227
|
-
constructor(code, message, details = {}) {
|
|
26228
|
-
super(message);
|
|
26229
|
-
this.name = "BotError";
|
|
26230
|
-
this.code = code;
|
|
26231
|
-
this.details = details;
|
|
26232
|
-
}
|
|
26233
|
-
}
|
|
26234
26247
|
// ../../packages/publish-harness/src/profile-dir.ts
|
|
26235
26248
|
import { mkdir as mkdir2, stat } from "fs/promises";
|
|
26236
26249
|
async function ensureProfileDir2(profileDir, headless) {
|