@gobing-ai/knowledge-kit 0.1.27 → 0.1.28
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/collect/index.js +10 -0
- package/dist/board/daily-voice/index.js +1327 -2168
- package/dist/board/itc/index.js +10 -0
- package/dist/index.js +5980 -4651
- package/package.json +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +4 -1
- package/plugins/ingestions/aihot-ingest/src/rss.ts +22 -11
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/daily-stages.ts +7 -7
- package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +81 -80
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +81 -80
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/csdn-pub/dist/index.js +81 -80
- package/plugins/publishings/csdn-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/infoq-pub/dist/index.js +81 -80
- package/plugins/publishings/infoq-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/jike-pub/dist/index.js +81 -80
- package/plugins/publishings/jike-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/juejin-pub/dist/index.js +81 -80
- package/plugins/publishings/juejin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +81 -80
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/medium-pub/dist/index.js +81 -80
- package/plugins/publishings/medium-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/shipinhao-pub/dist/index.js +272 -85
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +112 -3
- package/plugins/publishings/shipinhao-pub/src/cover-crop.ts +60 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +15 -2
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +15 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +22 -1
- package/plugins/publishings/sspai-pub/dist/index.js +81 -80
- package/plugins/publishings/sspai-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/substack-pub/dist/index.js +81 -80
- package/plugins/publishings/substack-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +43 -5
- package/plugins/publishings/threads-pub/dist/index.js +86 -81
- package/plugins/publishings/threads-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +84 -83
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/weibo-pub/dist/index.js +217 -83
- package/plugins/publishings/weibo-pub/dist/profile-check.js +123 -3
- package/plugins/publishings/weibo-pub/src/index.ts +60 -2
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +81 -80
- package/plugins/publishings/x-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/xhs-pub/dist/index.js +81 -80
- package/plugins/publishings/xhs-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +81 -80
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +1 -1
|
@@ -19397,6 +19397,7 @@ function ownProcessGroupLifecycle(ownership) {
|
|
|
19397
19397
|
var MAX_TIMEOUT_MS = 2147483647, DEFAULT_KILL_GRACE_MS = 5000, GROUP_POLL_INTERVAL_MS = 25, GROUP_KILL_PATIENCE_MS = 2000;
|
|
19398
19398
|
|
|
19399
19399
|
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/process-executor.js
|
|
19400
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
19400
19401
|
import { isatty } from "tty";
|
|
19401
19402
|
function processEventSeverity(reason, exitCode) {
|
|
19402
19403
|
if (reason === "error")
|
|
@@ -19701,6 +19702,30 @@ class BunPipeProcess {
|
|
|
19701
19702
|
this.subprocess.kill(signal);
|
|
19702
19703
|
}
|
|
19703
19704
|
}
|
|
19705
|
+
|
|
19706
|
+
class NodeSyncProcessExecutor {
|
|
19707
|
+
runSync(options) {
|
|
19708
|
+
const args = options.args ?? [];
|
|
19709
|
+
const startedAt = Date.now();
|
|
19710
|
+
const result = spawnSync2(options.command, args, {
|
|
19711
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19712
|
+
...options.cwd !== undefined ? { cwd: options.cwd } : {},
|
|
19713
|
+
...options.env !== undefined ? { env: options.env } : {}
|
|
19714
|
+
});
|
|
19715
|
+
const exitCode = result.status ?? 1;
|
|
19716
|
+
if (options.rejectOnError === true && exitCode !== 0) {
|
|
19717
|
+
throw new Error(`${options.command} ${args.join(" ")} failed with exit code ${exitCode}: ${stripFinalNewline2(asString(result.stderr))}`);
|
|
19718
|
+
}
|
|
19719
|
+
return {
|
|
19720
|
+
command: options.command,
|
|
19721
|
+
args,
|
|
19722
|
+
exitCode,
|
|
19723
|
+
stdout: stripFinalNewline2(asString(result.stdout)),
|
|
19724
|
+
stderr: stripFinalNewline2(asString(result.stderr)),
|
|
19725
|
+
durationMs: Date.now() - startedAt
|
|
19726
|
+
};
|
|
19727
|
+
}
|
|
19728
|
+
}
|
|
19704
19729
|
function buildExecaOptions(opts) {
|
|
19705
19730
|
const mode = opts.forceBuffered ? "buffered" : opts.outputPolicy?.mode ?? "buffered";
|
|
19706
19731
|
const streamToTerminal = mode === "stream" && (opts.outputPolicy?.mode === "stream" ? opts.outputPolicy.isTTY ?? process.stdout.isTTY ?? isatty(1) : false);
|
|
@@ -19754,6 +19779,11 @@ function asString(value) {
|
|
|
19754
19779
|
return value.map(String).join("");
|
|
19755
19780
|
return "";
|
|
19756
19781
|
}
|
|
19782
|
+
function stripFinalNewline2(value) {
|
|
19783
|
+
return value.endsWith(`\r
|
|
19784
|
+
`) ? value.slice(0, -2) : value.endsWith(`
|
|
19785
|
+
`) ? value.slice(0, -1) : value;
|
|
19786
|
+
}
|
|
19757
19787
|
function isReadableStream3(value) {
|
|
19758
19788
|
return value instanceof ReadableStream;
|
|
19759
19789
|
}
|
|
@@ -19829,7 +19859,7 @@ var init_runtime_node_bun = __esm(() => {
|
|
|
19829
19859
|
});
|
|
19830
19860
|
|
|
19831
19861
|
// ../../plugins/publishings/shipinhao-pub/src/index.ts
|
|
19832
|
-
import { dirname as
|
|
19862
|
+
import { dirname as dirname5 } from "path";
|
|
19833
19863
|
import { parseArgs } from "util";
|
|
19834
19864
|
|
|
19835
19865
|
// ../../packages/kk-core/src/content-limits.ts
|
|
@@ -20160,6 +20190,7 @@ function getProcessCwd() {
|
|
|
20160
20190
|
|
|
20161
20191
|
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/index.js
|
|
20162
20192
|
init_runtime_node_bun();
|
|
20193
|
+
init_process_executor();
|
|
20163
20194
|
|
|
20164
20195
|
// ../../packages/kk-core/src/render-md.ts
|
|
20165
20196
|
if (false) {}
|
|
@@ -20171,6 +20202,187 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
|
|
|
20171
20202
|
import { homedir } from "os";
|
|
20172
20203
|
import { join, resolve } from "path";
|
|
20173
20204
|
|
|
20205
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20206
|
+
import { randomUUID } from "crypto";
|
|
20207
|
+
init_dist();
|
|
20208
|
+
|
|
20209
|
+
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20210
|
+
import {
|
|
20211
|
+
chmodSync,
|
|
20212
|
+
closeSync,
|
|
20213
|
+
copyFileSync,
|
|
20214
|
+
lstatSync,
|
|
20215
|
+
mkdirSync as mkdirSync2,
|
|
20216
|
+
openSync,
|
|
20217
|
+
readdirSync as readdirSync2,
|
|
20218
|
+
readlinkSync,
|
|
20219
|
+
realpathSync as realpathSync2,
|
|
20220
|
+
renameSync as renameSync2,
|
|
20221
|
+
rmdirSync,
|
|
20222
|
+
unlinkSync
|
|
20223
|
+
} from "fs";
|
|
20224
|
+
function lstat(path) {
|
|
20225
|
+
try {
|
|
20226
|
+
return lstatSync(path);
|
|
20227
|
+
} catch (error) {
|
|
20228
|
+
if (error.code === "ENOENT")
|
|
20229
|
+
return null;
|
|
20230
|
+
throw error;
|
|
20231
|
+
}
|
|
20232
|
+
}
|
|
20233
|
+
function realpath(path) {
|
|
20234
|
+
return realpathSync2(path);
|
|
20235
|
+
}
|
|
20236
|
+
function mkdirExclusive(path, mode = 448) {
|
|
20237
|
+
try {
|
|
20238
|
+
mkdirSync2(path, { mode });
|
|
20239
|
+
return true;
|
|
20240
|
+
} catch (error) {
|
|
20241
|
+
if (error.code === "EEXIST")
|
|
20242
|
+
return false;
|
|
20243
|
+
throw error;
|
|
20244
|
+
}
|
|
20245
|
+
}
|
|
20246
|
+
function rmdir(path) {
|
|
20247
|
+
try {
|
|
20248
|
+
rmdirSync(path);
|
|
20249
|
+
return true;
|
|
20250
|
+
} catch (error) {
|
|
20251
|
+
const code = error.code;
|
|
20252
|
+
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20253
|
+
return false;
|
|
20254
|
+
throw error;
|
|
20255
|
+
}
|
|
20256
|
+
}
|
|
20257
|
+
function readlink(path) {
|
|
20258
|
+
try {
|
|
20259
|
+
return readlinkSync(path);
|
|
20260
|
+
} catch {
|
|
20261
|
+
return null;
|
|
20262
|
+
}
|
|
20263
|
+
}
|
|
20264
|
+
function unlink(path) {
|
|
20265
|
+
try {
|
|
20266
|
+
unlinkSync(path);
|
|
20267
|
+
return true;
|
|
20268
|
+
} catch (error) {
|
|
20269
|
+
if (error.code === "ENOENT")
|
|
20270
|
+
return false;
|
|
20271
|
+
throw error;
|
|
20272
|
+
}
|
|
20273
|
+
}
|
|
20274
|
+
function rename(from, to) {
|
|
20275
|
+
try {
|
|
20276
|
+
renameSync2(from, to);
|
|
20277
|
+
return true;
|
|
20278
|
+
} catch (error) {
|
|
20279
|
+
if (error.code === "ENOENT")
|
|
20280
|
+
return false;
|
|
20281
|
+
throw error;
|
|
20282
|
+
}
|
|
20283
|
+
}
|
|
20284
|
+
function chmod(path, mode) {
|
|
20285
|
+
chmodSync(path, mode);
|
|
20286
|
+
}
|
|
20287
|
+
function createExclusiveFile(path) {
|
|
20288
|
+
closeSync(openSync(path, "wx", 384));
|
|
20289
|
+
}
|
|
20290
|
+
|
|
20291
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20292
|
+
function channelStorageStatePath(profileDir) {
|
|
20293
|
+
return `${profileDir}/storage-state.json`;
|
|
20294
|
+
}
|
|
20295
|
+
var DEFAULT_CHANNEL_STATE_SETTLE_MS = 3000;
|
|
20296
|
+
async function readSavedState(profileDir) {
|
|
20297
|
+
const fs = createNodeFileSystem();
|
|
20298
|
+
const file = channelStorageStatePath(profileDir);
|
|
20299
|
+
try {
|
|
20300
|
+
if (!await fs.exists(file))
|
|
20301
|
+
return { corrupt: false };
|
|
20302
|
+
return { state: JSON.parse(await fs.readFile(file)), corrupt: false };
|
|
20303
|
+
} catch {
|
|
20304
|
+
return { corrupt: true };
|
|
20305
|
+
}
|
|
20306
|
+
}
|
|
20307
|
+
async function persistChannelSessionState(context, profileDir) {
|
|
20308
|
+
const target = channelStorageStatePath(profileDir);
|
|
20309
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
20310
|
+
const fs = createNodeFileSystem();
|
|
20311
|
+
let reserved = false;
|
|
20312
|
+
try {
|
|
20313
|
+
createExclusiveFile(temporary);
|
|
20314
|
+
reserved = true;
|
|
20315
|
+
await context.storageState({ path: temporary });
|
|
20316
|
+
chmod(temporary, 384);
|
|
20317
|
+
await fs.rename(temporary, target);
|
|
20318
|
+
} finally {
|
|
20319
|
+
if (reserved) {
|
|
20320
|
+
await Promise.resolve().then(() => fs.deleteFile(temporary)).catch(() => {
|
|
20321
|
+
return;
|
|
20322
|
+
});
|
|
20323
|
+
}
|
|
20324
|
+
}
|
|
20325
|
+
}
|
|
20326
|
+
async function restoreChannelSessionState(context, page, profileDir) {
|
|
20327
|
+
const { state, corrupt } = await readSavedState(profileDir);
|
|
20328
|
+
if (corrupt) {
|
|
20329
|
+
throw new Error(`the channel saved session state is unreadable (${channelStorageStatePath(profileDir)})`);
|
|
20330
|
+
}
|
|
20331
|
+
const saved = state?.cookies ?? [];
|
|
20332
|
+
if (saved.length === 0)
|
|
20333
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20334
|
+
if (typeof context.cookies !== "function" || typeof context.addCookies !== "function") {
|
|
20335
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20336
|
+
}
|
|
20337
|
+
const nowSeconds = Date.now() / 1000;
|
|
20338
|
+
const current = await context.cookies().catch(() => []);
|
|
20339
|
+
const alive = saved.filter((cookie) => cookie.expires === undefined || cookie.expires === -1 || cookie.expires > nowSeconds);
|
|
20340
|
+
const skippedExpired = saved.length - alive.length;
|
|
20341
|
+
const held = new Set(current.map((cookie) => `${cookie.domain}|${cookie.name}`));
|
|
20342
|
+
const shadowed = alive.filter((cookie) => held.has(`${cookie.domain}|${cookie.name}`)).length;
|
|
20343
|
+
const inject = alive.filter((cookie) => !held.has(`${cookie.domain}|${cookie.name}`));
|
|
20344
|
+
if (inject.length > 0)
|
|
20345
|
+
await context.addCookies(inject);
|
|
20346
|
+
if (page !== undefined) {
|
|
20347
|
+
for (const entry of state?.origins ?? []) {
|
|
20348
|
+
if (entry.origin === undefined || (entry.localStorage ?? []).length === 0)
|
|
20349
|
+
continue;
|
|
20350
|
+
await page.evaluate(({ origin, items }) => {
|
|
20351
|
+
const page = globalThis;
|
|
20352
|
+
if (page.location.origin !== origin)
|
|
20353
|
+
return;
|
|
20354
|
+
for (const item of items)
|
|
20355
|
+
page.localStorage.setItem(item.name, item.value);
|
|
20356
|
+
}, { origin: entry.origin, items: entry.localStorage ?? [] }).catch(() => {
|
|
20357
|
+
return;
|
|
20358
|
+
});
|
|
20359
|
+
}
|
|
20360
|
+
}
|
|
20361
|
+
return { restored: inject.length > 0, skippedExpired, shadowed };
|
|
20362
|
+
}
|
|
20363
|
+
function stateRestoringLauncher(base) {
|
|
20364
|
+
return {
|
|
20365
|
+
async launch(request) {
|
|
20366
|
+
const context = await base.launch(request);
|
|
20367
|
+
try {
|
|
20368
|
+
const pages = typeof context.pages === "function" ? context.pages() : [];
|
|
20369
|
+
const page = pages[0];
|
|
20370
|
+
const outcome = await restoreChannelSessionState(context, page, request.profileDir);
|
|
20371
|
+
if (outcome.skippedExpired > 0 || outcome.shadowed > 0) {
|
|
20372
|
+
echoError(`channel session: replayed ${outcome.restored ? "a" : "no"} saved session (${outcome.skippedExpired} expired, ${outcome.shadowed} shadowed by the profile)`);
|
|
20373
|
+
}
|
|
20374
|
+
} catch (error) {
|
|
20375
|
+
await Promise.resolve().then(() => context.close()).catch(() => {
|
|
20376
|
+
return;
|
|
20377
|
+
});
|
|
20378
|
+
throw error;
|
|
20379
|
+
}
|
|
20380
|
+
return context;
|
|
20381
|
+
}
|
|
20382
|
+
};
|
|
20383
|
+
}
|
|
20384
|
+
|
|
20385
|
+
// ../../packages/publish-harness/src/index.ts
|
|
20174
20386
|
class FakeTransportCore {
|
|
20175
20387
|
callLogs = [];
|
|
20176
20388
|
nextResult;
|
|
@@ -20437,85 +20649,6 @@ init_dist();
|
|
|
20437
20649
|
import { homedir as homedir4 } from "os";
|
|
20438
20650
|
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
20439
20651
|
|
|
20440
|
-
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20441
|
-
import {
|
|
20442
|
-
chmodSync,
|
|
20443
|
-
closeSync,
|
|
20444
|
-
copyFileSync,
|
|
20445
|
-
lstatSync,
|
|
20446
|
-
mkdirSync as mkdirSync2,
|
|
20447
|
-
openSync,
|
|
20448
|
-
readdirSync as readdirSync2,
|
|
20449
|
-
readlinkSync,
|
|
20450
|
-
realpathSync as realpathSync2,
|
|
20451
|
-
renameSync as renameSync2,
|
|
20452
|
-
rmdirSync,
|
|
20453
|
-
unlinkSync
|
|
20454
|
-
} from "fs";
|
|
20455
|
-
function lstat(path) {
|
|
20456
|
-
try {
|
|
20457
|
-
return lstatSync(path);
|
|
20458
|
-
} catch (error) {
|
|
20459
|
-
if (error.code === "ENOENT")
|
|
20460
|
-
return null;
|
|
20461
|
-
throw error;
|
|
20462
|
-
}
|
|
20463
|
-
}
|
|
20464
|
-
function realpath(path) {
|
|
20465
|
-
return realpathSync2(path);
|
|
20466
|
-
}
|
|
20467
|
-
function mkdirExclusive(path, mode = 448) {
|
|
20468
|
-
try {
|
|
20469
|
-
mkdirSync2(path, { mode });
|
|
20470
|
-
return true;
|
|
20471
|
-
} catch (error) {
|
|
20472
|
-
if (error.code === "EEXIST")
|
|
20473
|
-
return false;
|
|
20474
|
-
throw error;
|
|
20475
|
-
}
|
|
20476
|
-
}
|
|
20477
|
-
function rmdir(path) {
|
|
20478
|
-
try {
|
|
20479
|
-
rmdirSync(path);
|
|
20480
|
-
return true;
|
|
20481
|
-
} catch (error) {
|
|
20482
|
-
const code = error.code;
|
|
20483
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20484
|
-
return false;
|
|
20485
|
-
throw error;
|
|
20486
|
-
}
|
|
20487
|
-
}
|
|
20488
|
-
function readlink(path) {
|
|
20489
|
-
try {
|
|
20490
|
-
return readlinkSync(path);
|
|
20491
|
-
} catch {
|
|
20492
|
-
return null;
|
|
20493
|
-
}
|
|
20494
|
-
}
|
|
20495
|
-
function unlink(path) {
|
|
20496
|
-
try {
|
|
20497
|
-
unlinkSync(path);
|
|
20498
|
-
return true;
|
|
20499
|
-
} catch (error) {
|
|
20500
|
-
if (error.code === "ENOENT")
|
|
20501
|
-
return false;
|
|
20502
|
-
throw error;
|
|
20503
|
-
}
|
|
20504
|
-
}
|
|
20505
|
-
function rename(from, to) {
|
|
20506
|
-
try {
|
|
20507
|
-
renameSync2(from, to);
|
|
20508
|
-
return true;
|
|
20509
|
-
} catch (error) {
|
|
20510
|
-
if (error.code === "ENOENT")
|
|
20511
|
-
return false;
|
|
20512
|
-
throw error;
|
|
20513
|
-
}
|
|
20514
|
-
}
|
|
20515
|
-
function chmod(path, mode) {
|
|
20516
|
-
chmodSync(path, mode);
|
|
20517
|
-
}
|
|
20518
|
-
|
|
20519
20652
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20520
20653
|
import { homedir as homedir2 } from "os";
|
|
20521
20654
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
@@ -20813,7 +20946,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20813
20946
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20814
20947
|
if (lstat(syncData) === null)
|
|
20815
20948
|
return false;
|
|
20816
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20949
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20817
20950
|
}
|
|
20818
20951
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20819
20952
|
return {
|
|
@@ -20988,6 +21121,9 @@ function errorMessage2(error) {
|
|
|
20988
21121
|
return error instanceof Error ? error.message : String(error);
|
|
20989
21122
|
}
|
|
20990
21123
|
|
|
21124
|
+
// ../../plugins/publishings/shipinhao-pub/src/flow.ts
|
|
21125
|
+
init_dist();
|
|
21126
|
+
|
|
20991
21127
|
// ../../plugins/publishings/shipinhao-pub/src/selectors.ts
|
|
20992
21128
|
var SHP_TARGET = "shipinhao";
|
|
20993
21129
|
var SHP_HOME_URL = "https://channels.weixin.qq.com/platform";
|
|
@@ -21113,7 +21249,18 @@ var SHP_CONFIG = {
|
|
|
21113
21249
|
isAuthenticated: isShipinhaoAuthenticated,
|
|
21114
21250
|
loginTimeoutMs: SHP_LOGIN_TIMEOUT_MS,
|
|
21115
21251
|
checkHeadedOnly: true,
|
|
21116
|
-
checkTimeoutMs: 180000
|
|
21252
|
+
checkTimeoutMs: 180000,
|
|
21253
|
+
sessionState: {
|
|
21254
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
21255
|
+
await page.waitForTimeout(DEFAULT_CHANNEL_STATE_SETTLE_MS);
|
|
21256
|
+
try {
|
|
21257
|
+
await persistChannelSessionState(context, profileDir);
|
|
21258
|
+
} catch {
|
|
21259
|
+
throw new Error("shipinhao authenticated session snapshot failed");
|
|
21260
|
+
}
|
|
21261
|
+
},
|
|
21262
|
+
onOpen: ({ context, page, profileDir }) => restoreChannelSessionState(context, page, profileDir).then()
|
|
21263
|
+
}
|
|
21117
21264
|
};
|
|
21118
21265
|
|
|
21119
21266
|
// ../../plugins/publishings/shipinhao-pub/src/audio-flow.ts
|
|
@@ -21396,6 +21543,42 @@ async function pendingAudioFlow(input, metadata) {
|
|
|
21396
21543
|
});
|
|
21397
21544
|
}
|
|
21398
21545
|
|
|
21546
|
+
// ../../plugins/publishings/shipinhao-pub/src/cover-crop.ts
|
|
21547
|
+
import { dirname as dirname4, join as join6 } from "path";
|
|
21548
|
+
var defaultRun = (args) => {
|
|
21549
|
+
const result = new NodeSyncProcessExecutor().runSync({ command: "sips", args });
|
|
21550
|
+
return { status: result.exitCode, stdout: result.stdout, stderr: result.stderr };
|
|
21551
|
+
};
|
|
21552
|
+
function parseSipsDims(output) {
|
|
21553
|
+
const width = /pixelWidth:\s*(\d+)/.exec(output)?.[1];
|
|
21554
|
+
const height = /pixelHeight:\s*(\d+)/.exec(output)?.[1];
|
|
21555
|
+
if (width === undefined || height === undefined)
|
|
21556
|
+
return;
|
|
21557
|
+
const parsed = { width: Number(width), height: Number(height) };
|
|
21558
|
+
return parsed.width > 0 && parsed.height > 0 ? parsed : undefined;
|
|
21559
|
+
}
|
|
21560
|
+
function squareCoverPath(sourcePath) {
|
|
21561
|
+
const dot = sourcePath.lastIndexOf(".");
|
|
21562
|
+
const stem = dot <= 0 ? sourcePath : sourcePath.slice(0, dot);
|
|
21563
|
+
return join6(dirname4(sourcePath), `${stem.split("/").pop()}-1x1.png`);
|
|
21564
|
+
}
|
|
21565
|
+
function centerSquareCover(sourcePath, run = defaultRun) {
|
|
21566
|
+
const probe = run(["-g", "pixelWidth", "-g", "pixelHeight", sourcePath]);
|
|
21567
|
+
if (probe.status !== 0)
|
|
21568
|
+
return { error: `sips could not read ${sourcePath}: ${probe.stderr ?? ""}`.trim() };
|
|
21569
|
+
const dims = parseSipsDims(probe.stdout ?? "");
|
|
21570
|
+
if (dims === undefined)
|
|
21571
|
+
return { error: `sips reported no pixel dimensions for ${sourcePath}` };
|
|
21572
|
+
const side = Math.min(dims.width, dims.height);
|
|
21573
|
+
if (dims.width === side && dims.height === side)
|
|
21574
|
+
return { path: sourcePath };
|
|
21575
|
+
const out = squareCoverPath(sourcePath);
|
|
21576
|
+
const crop = run(["-c", String(side), String(side), sourcePath, "--out", out]);
|
|
21577
|
+
if (crop.status !== 0)
|
|
21578
|
+
return { error: `sips centre crop failed: ${crop.stderr ?? ""}`.trim() };
|
|
21579
|
+
return { path: out };
|
|
21580
|
+
}
|
|
21581
|
+
|
|
21399
21582
|
// ../../plugins/publishings/shipinhao-pub/src/flow.ts
|
|
21400
21583
|
var STEP_TIMEOUT_MS = 30000;
|
|
21401
21584
|
var PREFLIGHT_TIMEOUT_MS = 180000;
|
|
@@ -21921,7 +22104,7 @@ class ShipinhaoBrowserTransport {
|
|
|
21921
22104
|
constructor(operation = "shortVideo", driver = "script", deps = {}) {
|
|
21922
22105
|
this.operation = operation;
|
|
21923
22106
|
this.driver = driver;
|
|
21924
|
-
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
22107
|
+
this.launcher = stateRestoringLauncher(deps.launcher ?? kkBrowserLauncher);
|
|
21925
22108
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21926
22109
|
this.preflightTimeoutMs = deps.preflightTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21927
22110
|
}
|
|
@@ -21964,7 +22147,11 @@ class ShipinhaoBrowserTransport {
|
|
|
21964
22147
|
const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? metadataRecord.coverImage);
|
|
21965
22148
|
if (cover.error !== undefined)
|
|
21966
22149
|
return fail(SHP_TARGET, cover.error);
|
|
21967
|
-
|
|
22150
|
+
const square = centerSquareCover(cover.path);
|
|
22151
|
+
if ("error" in square) {
|
|
22152
|
+
echoError(`shipinhao-pub: square \u5C01\u9762 not derived (${square.error}) \u2014 keeping the original`);
|
|
22153
|
+
}
|
|
22154
|
+
coverPath = "path" in square ? square.path : cover.path;
|
|
21968
22155
|
} else {
|
|
21969
22156
|
const images = await resolveImagesPath(metadataRecord.images);
|
|
21970
22157
|
if (images.error !== undefined)
|
|
@@ -22343,7 +22530,7 @@ function getPublishTransport(operation = "shortVideo", driver = "script") {
|
|
|
22343
22530
|
return new ShipinhaoBrowserTransport(operation, driver);
|
|
22344
22531
|
}
|
|
22345
22532
|
async function writePublishResult(outputPath, result) {
|
|
22346
|
-
const outDir =
|
|
22533
|
+
const outDir = dirname5(outputPath);
|
|
22347
22534
|
if (outDir && outDir !== ".")
|
|
22348
22535
|
await createNodeFileSystem().ensureDir(outDir);
|
|
22349
22536
|
await createNodeFileSystem().writeFile(outputPath, JSON.stringify(result, null, 2));
|
|
@@ -19922,6 +19922,9 @@ function rename(from, to) {
|
|
|
19922
19922
|
function chmod(path, mode) {
|
|
19923
19923
|
chmodSync(path, mode);
|
|
19924
19924
|
}
|
|
19925
|
+
function createExclusiveFile(path) {
|
|
19926
|
+
closeSync(openSync(path, "wx", 384));
|
|
19927
|
+
}
|
|
19925
19928
|
|
|
19926
19929
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
19927
19930
|
import { homedir } from "os";
|
|
@@ -20187,6 +20190,101 @@ class BotError extends Error {
|
|
|
20187
20190
|
this.details = details;
|
|
20188
20191
|
}
|
|
20189
20192
|
}
|
|
20193
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20194
|
+
import { randomUUID } from "crypto";
|
|
20195
|
+
init_dist();
|
|
20196
|
+
function channelStorageStatePath(profileDir) {
|
|
20197
|
+
return `${profileDir}/storage-state.json`;
|
|
20198
|
+
}
|
|
20199
|
+
var DEFAULT_CHANNEL_STATE_SETTLE_MS = 3000;
|
|
20200
|
+
async function readSavedState(profileDir) {
|
|
20201
|
+
const fs = createNodeFileSystem();
|
|
20202
|
+
const file = channelStorageStatePath(profileDir);
|
|
20203
|
+
try {
|
|
20204
|
+
if (!await fs.exists(file))
|
|
20205
|
+
return { corrupt: false };
|
|
20206
|
+
return { state: JSON.parse(await fs.readFile(file)), corrupt: false };
|
|
20207
|
+
} catch {
|
|
20208
|
+
return { corrupt: true };
|
|
20209
|
+
}
|
|
20210
|
+
}
|
|
20211
|
+
async function persistChannelSessionState(context, profileDir) {
|
|
20212
|
+
const target = channelStorageStatePath(profileDir);
|
|
20213
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
20214
|
+
const fs = createNodeFileSystem();
|
|
20215
|
+
let reserved = false;
|
|
20216
|
+
try {
|
|
20217
|
+
createExclusiveFile(temporary);
|
|
20218
|
+
reserved = true;
|
|
20219
|
+
await context.storageState({ path: temporary });
|
|
20220
|
+
chmod(temporary, 384);
|
|
20221
|
+
await fs.rename(temporary, target);
|
|
20222
|
+
} finally {
|
|
20223
|
+
if (reserved) {
|
|
20224
|
+
await Promise.resolve().then(() => fs.deleteFile(temporary)).catch(() => {
|
|
20225
|
+
return;
|
|
20226
|
+
});
|
|
20227
|
+
}
|
|
20228
|
+
}
|
|
20229
|
+
}
|
|
20230
|
+
async function restoreChannelSessionState(context, page, profileDir) {
|
|
20231
|
+
const { state, corrupt } = await readSavedState(profileDir);
|
|
20232
|
+
if (corrupt) {
|
|
20233
|
+
throw new Error(`the channel saved session state is unreadable (${channelStorageStatePath(profileDir)})`);
|
|
20234
|
+
}
|
|
20235
|
+
const saved = state?.cookies ?? [];
|
|
20236
|
+
if (saved.length === 0)
|
|
20237
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20238
|
+
if (typeof context.cookies !== "function" || typeof context.addCookies !== "function") {
|
|
20239
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20240
|
+
}
|
|
20241
|
+
const nowSeconds = Date.now() / 1000;
|
|
20242
|
+
const current = await context.cookies().catch(() => []);
|
|
20243
|
+
const alive = saved.filter((cookie) => cookie.expires === undefined || cookie.expires === -1 || cookie.expires > nowSeconds);
|
|
20244
|
+
const skippedExpired = saved.length - alive.length;
|
|
20245
|
+
const held = new Set(current.map((cookie) => `${cookie.domain}|${cookie.name}`));
|
|
20246
|
+
const shadowed = alive.filter((cookie) => held.has(`${cookie.domain}|${cookie.name}`)).length;
|
|
20247
|
+
const inject = alive.filter((cookie) => !held.has(`${cookie.domain}|${cookie.name}`));
|
|
20248
|
+
if (inject.length > 0)
|
|
20249
|
+
await context.addCookies(inject);
|
|
20250
|
+
if (page !== undefined) {
|
|
20251
|
+
for (const entry of state?.origins ?? []) {
|
|
20252
|
+
if (entry.origin === undefined || (entry.localStorage ?? []).length === 0)
|
|
20253
|
+
continue;
|
|
20254
|
+
await page.evaluate(({ origin, items }) => {
|
|
20255
|
+
const page = globalThis;
|
|
20256
|
+
if (page.location.origin !== origin)
|
|
20257
|
+
return;
|
|
20258
|
+
for (const item of items)
|
|
20259
|
+
page.localStorage.setItem(item.name, item.value);
|
|
20260
|
+
}, { origin: entry.origin, items: entry.localStorage ?? [] }).catch(() => {
|
|
20261
|
+
return;
|
|
20262
|
+
});
|
|
20263
|
+
}
|
|
20264
|
+
}
|
|
20265
|
+
return { restored: inject.length > 0, skippedExpired, shadowed };
|
|
20266
|
+
}
|
|
20267
|
+
function stateRestoringLauncher(base) {
|
|
20268
|
+
return {
|
|
20269
|
+
async launch(request) {
|
|
20270
|
+
const context = await base.launch(request);
|
|
20271
|
+
try {
|
|
20272
|
+
const pages = typeof context.pages === "function" ? context.pages() : [];
|
|
20273
|
+
const page = pages[0];
|
|
20274
|
+
const outcome = await restoreChannelSessionState(context, page, request.profileDir);
|
|
20275
|
+
if (outcome.skippedExpired > 0 || outcome.shadowed > 0) {
|
|
20276
|
+
echoError(`channel session: replayed ${outcome.restored ? "a" : "no"} saved session (${outcome.skippedExpired} expired, ${outcome.shadowed} shadowed by the profile)`);
|
|
20277
|
+
}
|
|
20278
|
+
} catch (error) {
|
|
20279
|
+
await Promise.resolve().then(() => context.close()).catch(() => {
|
|
20280
|
+
return;
|
|
20281
|
+
});
|
|
20282
|
+
throw error;
|
|
20283
|
+
}
|
|
20284
|
+
return context;
|
|
20285
|
+
}
|
|
20286
|
+
};
|
|
20287
|
+
}
|
|
20190
20288
|
// ../../packages/publish-harness/src/index.ts
|
|
20191
20289
|
import { homedir as homedir4 } from "os";
|
|
20192
20290
|
import { join as join4, resolve as resolve4 } from "path";
|
|
@@ -20244,7 +20342,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20244
20342
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20245
20343
|
if (lstat(syncData) === null)
|
|
20246
20344
|
return false;
|
|
20247
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20345
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20248
20346
|
}
|
|
20249
20347
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20250
20348
|
return {
|
|
@@ -20681,10 +20779,21 @@ var SHP_CONFIG = {
|
|
|
20681
20779
|
isAuthenticated: isShipinhaoAuthenticated,
|
|
20682
20780
|
loginTimeoutMs: SHP_LOGIN_TIMEOUT_MS,
|
|
20683
20781
|
checkHeadedOnly: true,
|
|
20684
|
-
checkTimeoutMs: 180000
|
|
20782
|
+
checkTimeoutMs: 180000,
|
|
20783
|
+
sessionState: {
|
|
20784
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
20785
|
+
await page.waitForTimeout(DEFAULT_CHANNEL_STATE_SETTLE_MS);
|
|
20786
|
+
try {
|
|
20787
|
+
await persistChannelSessionState(context, profileDir);
|
|
20788
|
+
} catch {
|
|
20789
|
+
throw new Error("shipinhao authenticated session snapshot failed");
|
|
20790
|
+
}
|
|
20791
|
+
},
|
|
20792
|
+
onOpen: ({ context, page, profileDir }) => restoreChannelSessionState(context, page, profileDir).then()
|
|
20793
|
+
}
|
|
20685
20794
|
};
|
|
20686
20795
|
|
|
20687
20796
|
// ../../plugins/publishings/shipinhao-pub/src/profile-check.ts
|
|
20688
20797
|
if (import.meta.main) {
|
|
20689
|
-
process.exit(await runProfileCli(SHP_CONFIG, Bun.argv.slice(2)));
|
|
20798
|
+
process.exit(await runProfileCli(SHP_CONFIG, Bun.argv.slice(2), { launcher: stateRestoringLauncher(kkBrowserLauncher) }));
|
|
20690
20799
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 1:1 audio cover for the 音频 rail (2026-11-26, operator decision).
|
|
3
|
+
*
|
|
4
|
+
* The daily bundle ships one landscape cover (1344×576) and the 音频 form requires a square 封面:
|
|
5
|
+
* it opens its own crop dialog, and that dialog is what refused every backfill with 「请上传封面」
|
|
6
|
+
* (measured 2026-11-26 on 20261121: the upload settled, the dialog confirmed, the form still said
|
|
7
|
+
* the cover was missing). Cropping here removes the dialog from the critical path: the widest square
|
|
8
|
+
* that fits is cut from the CENTER of the existing artwork — never stretched, never upscaled.
|
|
9
|
+
*
|
|
10
|
+
* `sips` is the repo's image tool (see `plugins/kk/scripts/cover-compositor.ts`, ADR-046) and is
|
|
11
|
+
* macOS-only; a host without it returns an error and the caller keeps the old dialog path, so a
|
|
12
|
+
* Linux CI run degrades instead of failing.
|
|
13
|
+
*
|
|
14
|
+
* shortcut: PNG/JPEG only and no content-aware framing — a cover whose headline sits at the edges
|
|
15
|
+
* loses it to the centre cut; authoring a square audio cover in the bundle is the upgrade.
|
|
16
|
+
*/
|
|
17
|
+
import { dirname, join } from 'node:path';
|
|
18
|
+
import { NodeSyncProcessExecutor } from '@gobing-ai/ts-runtime';
|
|
19
|
+
|
|
20
|
+
/** One `sips` invocation, injectable so the crop maths is testable without the binary. */
|
|
21
|
+
export type SipsRun = (args: string[]) => { status: number | null; stdout?: string; stderr?: string };
|
|
22
|
+
|
|
23
|
+
const defaultRun: SipsRun = (args) => {
|
|
24
|
+
const result = new NodeSyncProcessExecutor().runSync({ command: 'sips', args });
|
|
25
|
+
return { status: result.exitCode, stdout: result.stdout, stderr: result.stderr };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Reads `pixelWidth`/`pixelHeight` out of `sips -g` output; `undefined` when either is missing. */
|
|
29
|
+
export function parseSipsDims(output: string): { width: number; height: number } | undefined {
|
|
30
|
+
const width = /pixelWidth:\s*(\d+)/.exec(output)?.[1];
|
|
31
|
+
const height = /pixelHeight:\s*(\d+)/.exec(output)?.[1];
|
|
32
|
+
if (width === undefined || height === undefined) return undefined;
|
|
33
|
+
const parsed = { width: Number(width), height: Number(height) };
|
|
34
|
+
return parsed.width > 0 && parsed.height > 0 ? parsed : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Output beside the source (the run directory is disposable): `cover.png` → `cover-1x1.png`. */
|
|
38
|
+
export function squareCoverPath(sourcePath: string): string {
|
|
39
|
+
const dot = sourcePath.lastIndexOf('.');
|
|
40
|
+
const stem = dot <= 0 ? sourcePath : sourcePath.slice(0, dot);
|
|
41
|
+
return join(dirname(sourcePath), `${stem.split('/').pop()}-1x1.png`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Centred square crop of `sourcePath`. Returns the cropped file, or an `error` the caller treats as
|
|
46
|
+
* "keep the original" (an already-square cover needs no crop and returns the source unchanged).
|
|
47
|
+
*/
|
|
48
|
+
export function centerSquareCover(sourcePath: string, run: SipsRun = defaultRun): { path: string } | { error: string } {
|
|
49
|
+
const probe = run(['-g', 'pixelWidth', '-g', 'pixelHeight', sourcePath]);
|
|
50
|
+
if (probe.status !== 0) return { error: `sips could not read ${sourcePath}: ${probe.stderr ?? ''}`.trim() };
|
|
51
|
+
const dims = parseSipsDims(probe.stdout ?? '');
|
|
52
|
+
if (dims === undefined) return { error: `sips reported no pixel dimensions for ${sourcePath}` };
|
|
53
|
+
const side = Math.min(dims.width, dims.height);
|
|
54
|
+
if (dims.width === side && dims.height === side) return { path: sourcePath };
|
|
55
|
+
const out = squareCoverPath(sourcePath);
|
|
56
|
+
// `-c <height> <width>` crops to the centre, which is the widest square that fits.
|
|
57
|
+
const crop = run(['-c', String(side), String(side), sourcePath, '--out', out]);
|
|
58
|
+
if (crop.status !== 0) return { error: `sips centre crop failed: ${crop.stderr ?? ''}`.trim() };
|
|
59
|
+
return { path: out };
|
|
60
|
+
}
|