@gobing-ai/knowledge-kit 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +162 -39
- package/package.json +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +8 -8
- package/plugins/kk/publish-presets/itc-main.json +42 -0
- package/plugins/kk/scripts/cover-compositor.ts +54 -8
- package/plugins/kk/scripts/itc-stages.ts +3 -2
- package/plugins/kk/scripts/voice3-publish-window.ts +5 -1
- package/plugins/kk/workflows/kk-daily-publish3.yaml +10 -3
- package/plugins/publishings/bilibili-pub/dist/index.js +89 -16
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/cnblogs-pub/dist/index.js +89 -16
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/csdn-pub/dist/index.js +89 -16
- package/plugins/publishings/csdn-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/infoq-pub/dist/index.js +119 -18
- package/plugins/publishings/infoq-pub/dist/profile-check.js +94 -17
- package/plugins/publishings/infoq-pub/src/index.ts +40 -1
- package/plugins/publishings/jike-pub/dist/index.js +89 -16
- package/plugins/publishings/jike-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/juejin-pub/dist/index.js +116 -19
- package/plugins/publishings/juejin-pub/dist/profile-check.js +93 -17
- package/plugins/publishings/juejin-pub/src/index.ts +41 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +89 -16
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/shipinhao-pub/dist/index.js +89 -16
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/sspai-pub/dist/index.js +89 -16
- package/plugins/publishings/sspai-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/substack-pub/dist/index.js +89 -16
- package/plugins/publishings/substack-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/surfdash-pub/dist/index.js +9 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +17 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +176 -32
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +95 -18
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +14 -2
- package/plugins/publishings/wechatmp-pub/src/flow.ts +155 -21
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +8 -1
- package/plugins/publishings/weibo-pub/dist/index.js +89 -16
- package/plugins/publishings/weibo-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/x-pub/dist/index.js +89 -16
- package/plugins/publishings/x-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/xhs-pub/dist/index.js +89 -16
- package/plugins/publishings/xhs-pub/dist/profile-check.js +89 -16
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +89 -16
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/zenn-pub/dist/index.js +93 -1
- package/plugins/publishings/zenn-pub/src/index.ts +134 -1
package/dist/index.js
CHANGED
|
@@ -37906,8 +37906,11 @@ import {
|
|
|
37906
37906
|
mkdirSync as mkdirSync4,
|
|
37907
37907
|
openSync,
|
|
37908
37908
|
readdirSync as readdirSync4,
|
|
37909
|
+
readlinkSync,
|
|
37909
37910
|
realpathSync as realpathSync5,
|
|
37910
|
-
|
|
37911
|
+
renameSync as renameSync3,
|
|
37912
|
+
rmdirSync,
|
|
37913
|
+
unlinkSync as unlinkSync2
|
|
37911
37914
|
} from "fs";
|
|
37912
37915
|
import { join as join8 } from "path";
|
|
37913
37916
|
function lstat(path) {
|
|
@@ -37943,6 +37946,33 @@ function rmdir(path) {
|
|
|
37943
37946
|
throw error;
|
|
37944
37947
|
}
|
|
37945
37948
|
}
|
|
37949
|
+
function readlink(path) {
|
|
37950
|
+
try {
|
|
37951
|
+
return readlinkSync(path);
|
|
37952
|
+
} catch {
|
|
37953
|
+
return null;
|
|
37954
|
+
}
|
|
37955
|
+
}
|
|
37956
|
+
function unlink(path) {
|
|
37957
|
+
try {
|
|
37958
|
+
unlinkSync2(path);
|
|
37959
|
+
return true;
|
|
37960
|
+
} catch (error) {
|
|
37961
|
+
if (error.code === "ENOENT")
|
|
37962
|
+
return false;
|
|
37963
|
+
throw error;
|
|
37964
|
+
}
|
|
37965
|
+
}
|
|
37966
|
+
function rename(from, to) {
|
|
37967
|
+
try {
|
|
37968
|
+
renameSync3(from, to);
|
|
37969
|
+
return true;
|
|
37970
|
+
} catch (error) {
|
|
37971
|
+
if (error.code === "ENOENT")
|
|
37972
|
+
return false;
|
|
37973
|
+
throw error;
|
|
37974
|
+
}
|
|
37975
|
+
}
|
|
37946
37976
|
function chmod(path, mode) {
|
|
37947
37977
|
chmodSync(path, mode);
|
|
37948
37978
|
}
|
|
@@ -38121,7 +38151,7 @@ var init_bot_transaction = __esm(() => {
|
|
|
38121
38151
|
|
|
38122
38152
|
// ../../packages/publish-harness/src/profile-lease.ts
|
|
38123
38153
|
import { createHash, randomBytes } from "crypto";
|
|
38124
|
-
import { homedir as homedir7 } from "os";
|
|
38154
|
+
import { homedir as homedir7, hostname as hostname3 } from "os";
|
|
38125
38155
|
import { basename as basename2, dirname as dirname9, join as join10, resolve as resolve10 } from "path";
|
|
38126
38156
|
async function acquireProfileLease(profileDir, options = {}) {
|
|
38127
38157
|
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
@@ -38290,6 +38320,8 @@ function isProcessAlive(pid) {
|
|
|
38290
38320
|
}
|
|
38291
38321
|
}
|
|
38292
38322
|
function refuseNativeLock(profileDir) {
|
|
38323
|
+
if (reclaimStaleNativeLock(profileDir))
|
|
38324
|
+
return;
|
|
38293
38325
|
for (const name of NATIVE_LOCK_FILES) {
|
|
38294
38326
|
const path = join10(profileDir, name);
|
|
38295
38327
|
if (lstat(path) !== null) {
|
|
@@ -38297,6 +38329,24 @@ function refuseNativeLock(profileDir) {
|
|
|
38297
38329
|
}
|
|
38298
38330
|
}
|
|
38299
38331
|
}
|
|
38332
|
+
function reclaimStaleNativeLock(profileDir) {
|
|
38333
|
+
const lockPath = join10(profileDir, "SingletonLock");
|
|
38334
|
+
const target = readlink(lockPath);
|
|
38335
|
+
if (target === null)
|
|
38336
|
+
return false;
|
|
38337
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
38338
|
+
if (match === null)
|
|
38339
|
+
return false;
|
|
38340
|
+
const [, host, pidText] = match;
|
|
38341
|
+
if (host !== hostname3())
|
|
38342
|
+
return false;
|
|
38343
|
+
const pid = Number(pidText);
|
|
38344
|
+
if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
|
|
38345
|
+
return false;
|
|
38346
|
+
for (const name of NATIVE_LOCK_FILES)
|
|
38347
|
+
unlink(join10(profileDir, name));
|
|
38348
|
+
return true;
|
|
38349
|
+
}
|
|
38300
38350
|
function sha256Hex2(value) {
|
|
38301
38351
|
return createHash("sha256").update(value).digest("hex");
|
|
38302
38352
|
}
|
|
@@ -38306,7 +38356,7 @@ var init_profile_lease = __esm(() => {
|
|
|
38306
38356
|
init_bot();
|
|
38307
38357
|
init_bot_fs();
|
|
38308
38358
|
DEFAULT_BOT_LEASE_ROOT = join10(homedir7(), ".config", "kk", "browser-leases");
|
|
38309
|
-
NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
|
|
38359
|
+
NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
|
|
38310
38360
|
});
|
|
38311
38361
|
|
|
38312
38362
|
// ../../packages/publish-harness/src/bot.ts
|
|
@@ -38883,6 +38933,27 @@ __export(exports_browser, {
|
|
|
38883
38933
|
import { join as join13, resolve as resolve13 } from "path";
|
|
38884
38934
|
import { createInterface } from "readline";
|
|
38885
38935
|
import { parseArgs } from "util";
|
|
38936
|
+
function isInstantBrowserDeath(message) {
|
|
38937
|
+
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
38938
|
+
}
|
|
38939
|
+
function classifyLaunchError(error, profileDir, channel) {
|
|
38940
|
+
const message = errorMessage2(error);
|
|
38941
|
+
if (/singleton|already in use|in use by another/i.test(message))
|
|
38942
|
+
return new BrowserProfileBusyError(profileDir, error);
|
|
38943
|
+
if (/playwright install|executable doesn't exist/i.test(message)) {
|
|
38944
|
+
return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
|
|
38945
|
+
}
|
|
38946
|
+
if (isInstantBrowserDeath(message)) {
|
|
38947
|
+
return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
|
|
38948
|
+
}
|
|
38949
|
+
return error instanceof Error ? error : new Error(message);
|
|
38950
|
+
}
|
|
38951
|
+
function quarantineProfileSyncData(profileDir) {
|
|
38952
|
+
const syncData = join13(profileDir, "Default", "Sync Data");
|
|
38953
|
+
if (lstat(syncData) === null)
|
|
38954
|
+
return false;
|
|
38955
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
|
|
38956
|
+
}
|
|
38886
38957
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
38887
38958
|
return {
|
|
38888
38959
|
async launch(request) {
|
|
@@ -38911,23 +38982,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
|
|
|
38911
38982
|
throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
|
|
38912
38983
|
}
|
|
38913
38984
|
const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
|
|
38985
|
+
const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
|
|
38986
|
+
headless,
|
|
38987
|
+
channel,
|
|
38988
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
38989
|
+
ignoreDefaultArgs: ["--enable-automation"]
|
|
38990
|
+
});
|
|
38914
38991
|
let context;
|
|
38915
38992
|
try {
|
|
38916
|
-
context = await
|
|
38917
|
-
headless,
|
|
38918
|
-
channel,
|
|
38919
|
-
args: ["--disable-blink-features=AutomationControlled"],
|
|
38920
|
-
ignoreDefaultArgs: ["--enable-automation"]
|
|
38921
|
-
});
|
|
38993
|
+
context = await launch();
|
|
38922
38994
|
} catch (error) {
|
|
38923
|
-
|
|
38924
|
-
|
|
38925
|
-
|
|
38926
|
-
|
|
38927
|
-
|
|
38928
|
-
|
|
38995
|
+
if (!isInstantBrowserDeath(errorMessage2(error)))
|
|
38996
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
38997
|
+
if (!quarantineProfileSyncData(profileDir))
|
|
38998
|
+
throw classifyLaunchError(error, profileDir, channel);
|
|
38999
|
+
try {
|
|
39000
|
+
context = await launch();
|
|
39001
|
+
} catch (retryError) {
|
|
39002
|
+
throw classifyLaunchError(retryError, profileDir, channel);
|
|
38929
39003
|
}
|
|
38930
|
-
throw error;
|
|
38931
39004
|
}
|
|
38932
39005
|
try {
|
|
38933
39006
|
await context.addInitScript(() => {
|
|
@@ -39083,6 +39156,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
39083
39156
|
if (command === "login") {
|
|
39084
39157
|
const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
|
|
39085
39158
|
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
39159
|
+
stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
|
|
39086
39160
|
try {
|
|
39087
39161
|
if (url === undefined) {
|
|
39088
39162
|
await loginWithProfile({
|
|
@@ -39319,6 +39393,7 @@ async function loginBot(name, url, options = {}) {
|
|
|
39319
39393
|
context = await launcher.launch({ profileDir: transaction.stageDir, headless: false });
|
|
39320
39394
|
const page = await openBotPage(context);
|
|
39321
39395
|
await navigateBot(page, navigationUrl);
|
|
39396
|
+
await focusBotPage(page);
|
|
39322
39397
|
const confirm = options.confirm ?? confirmBotLogin;
|
|
39323
39398
|
if (!await confirm(options.timeoutMs ?? DEFAULT_BOT_LOGIN_TIMEOUT_MS)) {
|
|
39324
39399
|
throw new BotError("unconfirmed", `login for bot '${name}' was not confirmed \u2014 nothing was saved and the previous profile is unchanged`);
|
|
@@ -39471,6 +39546,7 @@ async function openBot(name, options = {}) {
|
|
|
39471
39546
|
});
|
|
39472
39547
|
const page = await openBotPage(context);
|
|
39473
39548
|
await navigateBot(page, openUrl);
|
|
39549
|
+
await focusBotPage(page);
|
|
39474
39550
|
await closed;
|
|
39475
39551
|
return {
|
|
39476
39552
|
name,
|
|
@@ -39577,6 +39653,14 @@ async function navigateBot(page, url) {
|
|
|
39577
39653
|
throw new BotError("browser", `could not open the supplied login URL (${redactNavigationError(error, url)})`);
|
|
39578
39654
|
}
|
|
39579
39655
|
}
|
|
39656
|
+
async function focusBotPage(page) {
|
|
39657
|
+
const target = page;
|
|
39658
|
+
if (typeof target.bringToFront !== "function")
|
|
39659
|
+
return;
|
|
39660
|
+
await target.bringToFront().catch(() => {
|
|
39661
|
+
return;
|
|
39662
|
+
});
|
|
39663
|
+
}
|
|
39580
39664
|
function redactNavigationError(error, url) {
|
|
39581
39665
|
let detail = error instanceof Error ? error.message : String(error);
|
|
39582
39666
|
detail = detail.split(url).join("<login-url>");
|
|
@@ -39603,7 +39687,7 @@ async function confirmBotLogin(timeoutMs) {
|
|
|
39603
39687
|
if (process.stdin.isTTY !== true) {
|
|
39604
39688
|
throw new BotError("unconfirmed", "no interactive terminal is available \u2014 a generic login needs an affirmative confirmation (site adapters are the non-interactive route)");
|
|
39605
39689
|
}
|
|
39606
|
-
echo(`Sign in to the
|
|
39690
|
+
echo(`Sign in to the browser window that just came to the front (click into its email field first if the window lost focus), then type y + Enter within ${Math.round(timeoutMs / 1000)}s to save this bot session (anything else cancels).`);
|
|
39607
39691
|
return await new Promise((resolve, reject) => {
|
|
39608
39692
|
const reader = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
39609
39693
|
let settled = false;
|
|
@@ -51417,10 +51501,12 @@ function slugifyTopicName(name) {
|
|
|
51417
51501
|
return slug;
|
|
51418
51502
|
}
|
|
51419
51503
|
function expandHome3(value, homeDir) {
|
|
51420
|
-
if (value === "~")
|
|
51504
|
+
if (value === "~" || value === "$HOME")
|
|
51421
51505
|
return homeDir;
|
|
51422
51506
|
if (value.startsWith("~/"))
|
|
51423
51507
|
return join20(homeDir, value.slice(2));
|
|
51508
|
+
if (value.startsWith("$HOME/"))
|
|
51509
|
+
return join20(homeDir, value.slice("$HOME/".length));
|
|
51424
51510
|
return value;
|
|
51425
51511
|
}
|
|
51426
51512
|
function canonicalJson(value) {
|
|
@@ -51851,7 +51937,7 @@ var PublishPresetTargetSchema = object2({
|
|
|
51851
51937
|
variant: string2().min(1).optional(),
|
|
51852
51938
|
tier: number2().int().min(0).max(3).optional(),
|
|
51853
51939
|
window: PublishWindowSchema.optional(),
|
|
51854
|
-
mode: _enum2(["off", "dummy", "draft"]).optional(),
|
|
51940
|
+
mode: _enum2(["off", "dummy", "draft", "live"]).optional(),
|
|
51855
51941
|
required: boolean2().optional(),
|
|
51856
51942
|
options: record(string2(), unknown()).optional()
|
|
51857
51943
|
}).strict();
|
|
@@ -51874,15 +51960,7 @@ var ItcPlanRequestSchema = object2({
|
|
|
51874
51960
|
});
|
|
51875
51961
|
var SLUG_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
51876
51962
|
async function resolveDefaultPackageRoot(fs) {
|
|
51877
|
-
|
|
51878
|
-
for (;; ) {
|
|
51879
|
-
if (await fs.exists(join21(dir, "plugins/kk/publish-presets")))
|
|
51880
|
-
return dir;
|
|
51881
|
-
const parent = resolve21(dir, "..");
|
|
51882
|
-
if (parent === dir)
|
|
51883
|
-
return process.cwd();
|
|
51884
|
-
dir = parent;
|
|
51885
|
-
}
|
|
51963
|
+
return resolvePackageRoot(fs);
|
|
51886
51964
|
}
|
|
51887
51965
|
function parseTargetTokens(raw) {
|
|
51888
51966
|
const tokens = raw.split(",").map((t) => t.trim()).filter(Boolean);
|
|
@@ -52081,6 +52159,7 @@ async function buildItcPublishPlan(request, plugins, fs = createNodeFileSystem()
|
|
|
52081
52159
|
const fanoutMap = new Map;
|
|
52082
52160
|
const browser = [];
|
|
52083
52161
|
const targetDetails = [];
|
|
52162
|
+
const warnings = [];
|
|
52084
52163
|
for (const targetReq of uniqueTargets) {
|
|
52085
52164
|
const plugin = pluginsByName.get(targetReq.plugin);
|
|
52086
52165
|
if (!plugin?.publishing) {
|
|
@@ -52100,7 +52179,8 @@ async function buildItcPublishPlan(request, plugins, fs = createNodeFileSystem()
|
|
|
52100
52179
|
throw new Error(`target ${targetReq.plugin} has no draft mode; it needs publish_live=true`);
|
|
52101
52180
|
}
|
|
52102
52181
|
if (profile.requires?.cover && !hasCover) {
|
|
52103
|
-
|
|
52182
|
+
warnings.push(`skipped ${targetReq.plugin}: needs a cover image at 4-illustrations/cover.* in ${request.workDir}`);
|
|
52183
|
+
continue;
|
|
52104
52184
|
}
|
|
52105
52185
|
if (profile.requires?.orderedImages && !await hasOrderedImages(fs, request.workDir)) {
|
|
52106
52186
|
throw new Error(`target ${targetReq.plugin} requires ordered metadata.images with real paths; a hero cover alone does not satisfy that requirement`);
|
|
@@ -52149,6 +52229,7 @@ async function buildItcPublishPlan(request, plugins, fs = createNodeFileSystem()
|
|
|
52149
52229
|
...request.origin !== undefined ? { origin: request.origin } : {},
|
|
52150
52230
|
...request.presetName !== undefined ? { presetName: request.presetName } : {},
|
|
52151
52231
|
...request.presetDigest !== undefined ? { presetDigest: request.presetDigest } : {},
|
|
52232
|
+
...warnings.length > 0 ? { warnings } : {},
|
|
52152
52233
|
live: request.live,
|
|
52153
52234
|
sourceLocale: request.sourceLocale,
|
|
52154
52235
|
variants,
|
|
@@ -52343,6 +52424,8 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
52343
52424
|
const planPath = join22(publishDir, "publish-plan.json");
|
|
52344
52425
|
await fs.writeFile(planPath, `${JSON.stringify(plan, null, 2)}
|
|
52345
52426
|
`);
|
|
52427
|
+
for (const warning of plan.warnings ?? [])
|
|
52428
|
+
echoError(`itc-materialize-plan: ${warning}`);
|
|
52346
52429
|
await prepareTargetPayloads(fs, workDir, plan, plugins);
|
|
52347
52430
|
return 0;
|
|
52348
52431
|
} catch (err) {
|
|
@@ -52359,7 +52442,7 @@ async function readOptionsSnapshot(fs, workDir) {
|
|
|
52359
52442
|
async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
52360
52443
|
const publishDir = join22(workDir, "4-publish");
|
|
52361
52444
|
if (!plan.targets || plan.targets.length === 0)
|
|
52362
|
-
return;
|
|
52445
|
+
return plan;
|
|
52363
52446
|
const planned = new Set(plan.targets.map((t) => t.plugin));
|
|
52364
52447
|
const modeKeys = new Set(["operation", "published", "publishStatus", "private", "mode"]);
|
|
52365
52448
|
for (const plugin of plugins) {
|
|
@@ -52372,8 +52455,10 @@ async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
|
52372
52455
|
}
|
|
52373
52456
|
}
|
|
52374
52457
|
}
|
|
52458
|
+
const variants = plan.variants ?? {};
|
|
52459
|
+
let written = false;
|
|
52375
52460
|
for (const target of plan.targets) {
|
|
52376
|
-
const variantEntry =
|
|
52461
|
+
const variantEntry = variants[target.variant];
|
|
52377
52462
|
const baseFile = variantEntry?.file ?? "content.json";
|
|
52378
52463
|
let basePath = join22(publishDir, baseFile);
|
|
52379
52464
|
if (!await fs.exists(basePath)) {
|
|
@@ -52401,9 +52486,13 @@ async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
|
52401
52486
|
const payloadDigest = createHash6("sha256").update(contentStr).digest("hex");
|
|
52402
52487
|
target.payloadPath = `4-publish/${targetFileName}`;
|
|
52403
52488
|
target.payloadDigest = payloadDigest;
|
|
52489
|
+
written = true;
|
|
52404
52490
|
}
|
|
52405
|
-
|
|
52491
|
+
if (written) {
|
|
52492
|
+
await fs.writeFile(join22(publishDir, "publish-plan.json"), `${JSON.stringify(plan, null, 2)}
|
|
52406
52493
|
`);
|
|
52494
|
+
}
|
|
52495
|
+
return plan;
|
|
52407
52496
|
}
|
|
52408
52497
|
async function probePlugin(plugin, executor = new NodeProcessExecutor) {
|
|
52409
52498
|
if (!plugin.check)
|
|
@@ -52440,22 +52529,43 @@ async function itcCheckTargets(args, fs = createNodeFileSystem(), executor = new
|
|
|
52440
52529
|
const planPath = join22(workDir, "4-publish/publish-plan.json");
|
|
52441
52530
|
if (!await fs.exists(planPath))
|
|
52442
52531
|
return 0;
|
|
52443
|
-
|
|
52532
|
+
let plan;
|
|
52533
|
+
try {
|
|
52534
|
+
plan = JSON.parse(await fs.readFile(planPath));
|
|
52535
|
+
} catch (error) {
|
|
52536
|
+
echoError(`itc-check-targets: unreadable plan at ${planPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
52537
|
+
return 1;
|
|
52538
|
+
}
|
|
52444
52539
|
if (!plan.targets || plan.targets.length === 0)
|
|
52445
52540
|
return 0;
|
|
52446
52541
|
const { plugins } = discoverAllPlugins();
|
|
52447
52542
|
const byName = new Map(plugins.map((p) => [p.name, p]));
|
|
52543
|
+
const probes = [];
|
|
52448
52544
|
for (const target of plan.targets) {
|
|
52545
|
+
if (probes.some((row) => row.plugin === target.plugin))
|
|
52546
|
+
continue;
|
|
52449
52547
|
const plugin = byName.get(target.plugin);
|
|
52450
|
-
if (
|
|
52548
|
+
if (plugin === undefined) {
|
|
52549
|
+
probes.push({ plugin: target.plugin, ok: false, detail: "plugin not installed" });
|
|
52550
|
+
continue;
|
|
52551
|
+
}
|
|
52552
|
+
if (!plugin.check)
|
|
52451
52553
|
continue;
|
|
52452
52554
|
const probe = await probePlugin(plugin, executor);
|
|
52555
|
+
probes.push({ plugin: target.plugin, ok: probe.ok, ...probe.detail ? { detail: probe.detail } : {} });
|
|
52453
52556
|
if (!probe.ok) {
|
|
52454
52557
|
const botName = plugin.browserSession?.profileName ?? plugin.name;
|
|
52455
|
-
echoError(
|
|
52456
|
-
return 1;
|
|
52558
|
+
echoError(`channel probe for '${target.plugin}': ${probe.detail ?? `run \`kk bot open/login ${botName}\` to authenticate`}`);
|
|
52457
52559
|
}
|
|
52458
52560
|
}
|
|
52561
|
+
try {
|
|
52562
|
+
await fs.ensureDir(join22(workDir, "4-publish"));
|
|
52563
|
+
await fs.writeFile(join22(workDir, "4-publish/check-targets.json"), `${JSON.stringify({ schemaVersion: 1, plugins: probes }, null, 2)}
|
|
52564
|
+
`);
|
|
52565
|
+
} catch (error) {
|
|
52566
|
+
echoError(`itc-check-targets: cannot write probes: ${error instanceof Error ? error.message : String(error)}`);
|
|
52567
|
+
return 1;
|
|
52568
|
+
}
|
|
52459
52569
|
return 0;
|
|
52460
52570
|
}
|
|
52461
52571
|
async function sendRows(options) {
|
|
@@ -52657,7 +52767,7 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52657
52767
|
const planPath = join22(publishDir, "publish-plan.json");
|
|
52658
52768
|
if (!await fs.exists(planPath))
|
|
52659
52769
|
return 0;
|
|
52660
|
-
|
|
52770
|
+
let plan = JSON.parse(await fs.readFile(planPath));
|
|
52661
52771
|
if (!plan.targets || plan.targets.length === 0)
|
|
52662
52772
|
return 0;
|
|
52663
52773
|
const parentRunId = (await readOptionsSnapshot(fs, workDir))?.parentRunId;
|
|
@@ -52665,11 +52775,22 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52665
52775
|
echoError(`itc-send-targets: ${join22(workDir, "itc-options.json")} has no parentRunId`);
|
|
52666
52776
|
return 1;
|
|
52667
52777
|
}
|
|
52778
|
+
const { plugins } = discoverAllPlugins();
|
|
52779
|
+
plan = await prepareTargetPayloads(fs, workDir, plan, plugins);
|
|
52780
|
+
const targets = plan.targets ?? [];
|
|
52781
|
+
for (const target of targets) {
|
|
52782
|
+
const entry = plan.variants?.[target.variant];
|
|
52783
|
+
if (entry?.adapt !== true)
|
|
52784
|
+
continue;
|
|
52785
|
+
if (await fs.exists(join22(publishDir, entry.file)))
|
|
52786
|
+
continue;
|
|
52787
|
+
echoError(`itc-send-targets: variant ${target.variant} has no ${entry.file}; '${target.plugin}' receives the ${plan.sourceLocale} source article`);
|
|
52788
|
+
}
|
|
52668
52789
|
const receiptsDir = join22(publishDir, "receipts");
|
|
52669
52790
|
await fs.ensureDir(receiptsDir);
|
|
52670
52791
|
const planRaw = await fs.readFile(planPath);
|
|
52671
52792
|
const planDigest = createHash6("sha256").update(planRaw).digest("hex");
|
|
52672
|
-
const rows =
|
|
52793
|
+
const rows = targets.map((target) => ({
|
|
52673
52794
|
key: target.plugin,
|
|
52674
52795
|
plugin: target.plugin,
|
|
52675
52796
|
profile: target.profile,
|
|
@@ -53023,6 +53144,8 @@ async function runItcPublishPlan(args, fs) {
|
|
|
53023
53144
|
await fs.ensureDir(outDir);
|
|
53024
53145
|
await fs.writeFile(join23(outDir, "publish-plan.json"), `${JSON.stringify(plan, null, 4)}
|
|
53025
53146
|
`);
|
|
53147
|
+
for (const warning of plan.warnings ?? [])
|
|
53148
|
+
echoError(`itc-publish-plan: ${warning}`);
|
|
53026
53149
|
return 0;
|
|
53027
53150
|
} catch (err) {
|
|
53028
53151
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -53557,7 +53680,7 @@ async function composePlan(fs, input) {
|
|
|
53557
53680
|
if (liveToken !== undefined && target.mode === "dummy") {
|
|
53558
53681
|
throw new Error(`channel '${liveToken}' is dummy-only and cannot be promoted to live`);
|
|
53559
53682
|
}
|
|
53560
|
-
const mode = input.dummy ? "dummy" : liveToken !== undefined ? "live" : target.mode === "dummy" ? "dummy" : "draft";
|
|
53683
|
+
const mode = input.dummy ? "dummy" : liveToken !== undefined || target.mode === "live" ? "live" : target.mode === "dummy" ? "dummy" : "draft";
|
|
53561
53684
|
if (mode === "live" && safety === undefined) {
|
|
53562
53685
|
throw new Error(`bundle has no final-variant safety evidence; run the variants safety gate (kk-daily-safety scope=variants) before a live launch`);
|
|
53563
53686
|
}
|
package/package.json
CHANGED
package/plugins/kk/plugin.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"variant": "article",
|
|
9
9
|
"tier": 0,
|
|
10
10
|
"window": "after-generate",
|
|
11
|
-
"mode": "
|
|
11
|
+
"mode": "live",
|
|
12
12
|
"required": true
|
|
13
13
|
},
|
|
14
14
|
{
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"variant": "episode",
|
|
18
18
|
"tier": 0,
|
|
19
19
|
"window": "after-generate",
|
|
20
|
-
"mode": "
|
|
20
|
+
"mode": "live",
|
|
21
21
|
"required": true
|
|
22
22
|
},
|
|
23
23
|
{
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"variant": "episode",
|
|
27
27
|
"tier": 1,
|
|
28
28
|
"window": "after-generate",
|
|
29
|
-
"mode": "
|
|
29
|
+
"mode": "live"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"plugin": "xhs-pub",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"variant": "episode",
|
|
35
35
|
"tier": 1,
|
|
36
36
|
"window": "after-generate",
|
|
37
|
-
"mode": "
|
|
37
|
+
"mode": "live"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"plugin": "shipinhao-pub",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"variant": "episode",
|
|
43
43
|
"tier": 1,
|
|
44
44
|
"window": "after-generate",
|
|
45
|
-
"mode": "
|
|
45
|
+
"mode": "live"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
"plugin": "wechatmp-pub",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"variant": "article",
|
|
51
51
|
"tier": 2,
|
|
52
52
|
"window": "after-generate",
|
|
53
|
-
"mode": "
|
|
53
|
+
"mode": "live",
|
|
54
54
|
"options": {
|
|
55
55
|
"collection": "每日AI资讯"
|
|
56
56
|
}
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"variant": "cards",
|
|
70
70
|
"tier": 3,
|
|
71
71
|
"window": "after-generate",
|
|
72
|
-
"mode": "
|
|
72
|
+
"mode": "live"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"plugin": "weibo-pub",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"variant": "article",
|
|
78
78
|
"tier": 2,
|
|
79
79
|
"window": "cn-peak",
|
|
80
|
-
"mode": "
|
|
80
|
+
"mode": "live"
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
"plugin": "x-pub",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "itc-main",
|
|
4
|
+
"targets": [
|
|
5
|
+
{
|
|
6
|
+
"plugin": "surfdash-pub",
|
|
7
|
+
"profile": "article"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"plugin": "infoq-pub",
|
|
11
|
+
"profile": "article"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"plugin": "juejin-pub",
|
|
15
|
+
"profile": "article"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"plugin": "wechatmp-pub",
|
|
19
|
+
"profile": "article"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"plugin": "x-pub",
|
|
23
|
+
"profile": "article-zh"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"plugin": "zenn-pub",
|
|
27
|
+
"profile": "article"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"plugin": "qiita-pub",
|
|
31
|
+
"profile": "article"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"plugin": "medium-pub",
|
|
35
|
+
"profile": "article"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"plugin": "substack-pub",
|
|
39
|
+
"profile": "article"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -12,6 +12,13 @@ import { join, resolve } from 'node:path';
|
|
|
12
12
|
|
|
13
13
|
export interface CoverCompositorOptions {
|
|
14
14
|
backgroundImagePath: string;
|
|
15
|
+
/**
|
|
16
|
+
* Background as a `data:` URI. `compositeCover` always sets it: `sips` cannot rasterize an
|
|
17
|
+
* SVG `<image href="file://…">`, so the file-URL form silently rendered only the overlay
|
|
18
|
+
* chrome (the placeholder-looking cover that shipped on 2026-11-11) plus a lost headline.
|
|
19
|
+
* The field is optional only so the pure template probes can exercise the legacy form.
|
|
20
|
+
*/
|
|
21
|
+
backgroundUri?: string;
|
|
15
22
|
headline: string;
|
|
16
23
|
leadStoryTitle?: string;
|
|
17
24
|
/** Defaults to the repo `assets/general/xhxs.svg`; a missing asset omits the badge. */
|
|
@@ -53,6 +60,29 @@ export function wrapHeadline(headline: string): string[] {
|
|
|
53
60
|
return [source[0], `${second.slice(0, HEADLINE_LINE_CAP - 1)}…`];
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Estimated rendered width in px for the mixed CJK/Latin headline: `sips` has no text metrics we
|
|
65
|
+
* can read back, so each code point is charged its rough advance (CJK ≈ 1em, Latin ≈ 0.55em,
|
|
66
|
+
* space ≈ 0.28em). Used only to shrink a line until it fits — a clipped headline is worse than a
|
|
67
|
+
* smaller one (the 2026-11-12 regeneration clipped "Anthropic" at the canvas edge).
|
|
68
|
+
*/
|
|
69
|
+
function estimateWidth(text: string, fontSize: number): number {
|
|
70
|
+
let em = 0;
|
|
71
|
+
for (const ch of text) {
|
|
72
|
+
if (/\s/.test(ch)) em += 0.28;
|
|
73
|
+
else if (/[\u2E80-\u9FFF\uF900-\uFAFF\uFF00-\uFF60\u3000-\u303F]/.test(ch)) em += 1;
|
|
74
|
+
else em += 0.55;
|
|
75
|
+
}
|
|
76
|
+
return em * fontSize;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Largest size <= `baseSize` at which `text` fits `maxWidth`, floored so it stays legible. */
|
|
80
|
+
export function fitFontSize(text: string, baseSize: number, maxWidth: number, floorSize = 24): number {
|
|
81
|
+
let size = baseSize;
|
|
82
|
+
while (size > floorSize && estimateWidth(text, size) > maxWidth) size -= 1;
|
|
83
|
+
return size;
|
|
84
|
+
}
|
|
85
|
+
|
|
56
86
|
/** Fixed-width chunker for CJK headlines — code points, not UTF-16 units. */
|
|
57
87
|
function chunk(text: string): string[] {
|
|
58
88
|
const chars = Array.from(text);
|
|
@@ -90,11 +120,19 @@ export function buildCoverSvg(options: CoverCompositorOptions): string {
|
|
|
90
120
|
const lines = wrapHeadline(options.headline);
|
|
91
121
|
const logo = logoBadgeSvg(options.logoPath ?? 'assets/general/xhxs.svg', 48, 40, 72, 50);
|
|
92
122
|
|
|
123
|
+
// 2026-11-12 regression: `sips` drops EVERY `<text>` that carries an SVG filter, so the
|
|
124
|
+
// headline never rasterized (both the 11-11 and 11-12 covers shipped chrome with no headline).
|
|
125
|
+
// Contrast comes from the bottom scrim plus a geometric shadow — the same text drawn once in
|
|
126
|
+
// dark behind the visible line — because that is plain geometry, not a filter.
|
|
127
|
+
const line = (text: string, y: number, size: number, weight: number, fill: string): string =>
|
|
128
|
+
`<text x="48" y="${y + 3}" font-family="${FONT_STACK}" font-size="${size}" font-weight="${weight}" fill="#000000" fill-opacity="0.72">${esc(text)}</text>
|
|
129
|
+
<text x="48" y="${y}" font-family="${FONT_STACK}" font-size="${size}" font-weight="${weight}" fill="${fill}">${esc(text)}</text>`;
|
|
130
|
+
const textWidth = width - 96;
|
|
93
131
|
const typography =
|
|
94
132
|
lines.length === 1
|
|
95
|
-
?
|
|
96
|
-
:
|
|
97
|
-
|
|
133
|
+
? line(lines[0], 500, fitFontSize(lines[0], 46, textWidth), 800, '#FFFFFF')
|
|
134
|
+
: `${line(lines[0], 472, fitFontSize(lines[0], 46, textWidth), 800, '#FFFFFF')}
|
|
135
|
+
${line(lines[1], 532, fitFontSize(lines[1], 32, textWidth), 700, '#FFB800')}`;
|
|
98
136
|
|
|
99
137
|
const badge =
|
|
100
138
|
logo !== ''
|
|
@@ -103,15 +141,12 @@ export function buildCoverSvg(options: CoverCompositorOptions): string {
|
|
|
103
141
|
: '';
|
|
104
142
|
|
|
105
143
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
|
106
|
-
<image href="${encodeURI(`file://${resolve(options.backgroundImagePath)}`)}" x="0" y="0" width="${width}" height="${height}" preserveAspectRatio="xMidYMid slice" />
|
|
144
|
+
<image href="${options.backgroundUri ?? encodeURI(`file://${resolve(options.backgroundImagePath)}`)}" x="0" y="0" width="${width}" height="${height}" preserveAspectRatio="xMidYMid slice" />
|
|
107
145
|
<defs>
|
|
108
146
|
<linearGradient id="bottomScrim" x1="0" y1="0" x2="0" y2="1">
|
|
109
147
|
<stop offset="0" stop-color="#0a1424" stop-opacity="0" />
|
|
110
148
|
<stop offset="1" stop-color="#0a1424" stop-opacity="0.92" />
|
|
111
149
|
</linearGradient>
|
|
112
|
-
<filter id="textShadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
113
|
-
<feDropShadow dx="0" dy="3" stdDeviation="6" flood-color="#000000" flood-opacity="0.85" />
|
|
114
|
-
</filter>
|
|
115
150
|
</defs>
|
|
116
151
|
<rect x="0" y="${Math.round(height * 0.45)}" width="${width}" height="${height - Math.round(height * 0.45)}" fill="url(#bottomScrim)" />
|
|
117
152
|
${badge}
|
|
@@ -126,9 +161,20 @@ export function buildCoverSvg(options: CoverCompositorOptions): string {
|
|
|
126
161
|
* native image dependency). Fail-fast: a missing `sips` or nonzero transcode throws with an
|
|
127
162
|
* actionable message — the daily run must not publish a half-composited cover.
|
|
128
163
|
*/
|
|
164
|
+
/** Inline the background as a data URI so `sips` actually rasterizes it (see the option doc). */
|
|
165
|
+
function backgroundDataUri(path: string): string {
|
|
166
|
+
const lower = path.toLowerCase();
|
|
167
|
+
const mime = lower.endsWith('.jpg') || lower.endsWith('.jpeg') ? 'image/jpeg' : 'image/png';
|
|
168
|
+
return `data:${mime};base64,${readFileSync(path).toString('base64')}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
129
171
|
export function compositeCover(options: CoverCompositorOptions): string {
|
|
130
172
|
const svgPath = join(tmpdir(), `cover-composite-${Date.now()}.svg`);
|
|
131
|
-
writeFileSync(
|
|
173
|
+
writeFileSync(
|
|
174
|
+
svgPath,
|
|
175
|
+
buildCoverSvg({ ...options, backgroundUri: backgroundDataUri(options.backgroundImagePath) }),
|
|
176
|
+
'utf-8',
|
|
177
|
+
);
|
|
132
178
|
try {
|
|
133
179
|
const sips = spawnSync('sips', ['-s', 'format', 'png', svgPath, '--out', options.outputPath], {
|
|
134
180
|
stdio: 'ignore',
|