@gobing-ai/knowledge-kit 0.1.25 → 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 +6043 -4620
- 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/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +423 -141
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +114 -82
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +114 -82
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/csdn-pub/dist/index.js +114 -82
- package/plugins/publishings/csdn-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/infoq-pub/dist/index.js +114 -82
- package/plugins/publishings/infoq-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/jike-pub/dist/index.js +114 -82
- package/plugins/publishings/jike-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/juejin-pub/dist/index.js +114 -82
- package/plugins/publishings/juejin-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +165 -93
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +51 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +114 -82
- package/plugins/publishings/medium-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +305 -87
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +145 -5
- 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 +114 -82
- package/plugins/publishings/sspai-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/substack-pub/dist/index.js +114 -82
- package/plugins/publishings/substack-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/surfdash-pub/dist/index.js +96 -20
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +119 -83
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +149 -86
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +68 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +273 -91
- package/plugins/publishings/weibo-pub/dist/profile-check.js +178 -11
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +136 -10
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +114 -82
- package/plugins/publishings/x-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xhs-pub/dist/index.js +114 -82
- package/plugins/publishings/xhs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +114 -82
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +34 -3
|
@@ -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";
|
|
@@ -20540,7 +20673,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20540
20673
|
const leaseDir = join3(leaseRoot, id);
|
|
20541
20674
|
await fileSystem.ensureDir(leaseRoot);
|
|
20542
20675
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20543
|
-
|
|
20676
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20677
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20678
|
+
}
|
|
20679
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20680
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20681
|
+
}
|
|
20544
20682
|
}
|
|
20545
20683
|
const token = randomBytes(16).toString("hex");
|
|
20546
20684
|
const owner = {
|
|
@@ -20656,9 +20794,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20656
20794
|
}
|
|
20657
20795
|
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`;
|
|
20658
20796
|
}
|
|
20659
|
-
const
|
|
20797
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20798
|
+
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}`;
|
|
20660
20799
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20661
20800
|
}
|
|
20801
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20802
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20803
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20804
|
+
return false;
|
|
20805
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20806
|
+
return false;
|
|
20807
|
+
const target = staleLeaseDir(leaseDir);
|
|
20808
|
+
try {
|
|
20809
|
+
rename(leaseDir, target);
|
|
20810
|
+
} catch {
|
|
20811
|
+
return false;
|
|
20812
|
+
}
|
|
20813
|
+
const moved = await readOwner(fileSystem, target);
|
|
20814
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20815
|
+
try {
|
|
20816
|
+
rename(target, leaseDir);
|
|
20817
|
+
} catch {}
|
|
20818
|
+
return false;
|
|
20819
|
+
}
|
|
20820
|
+
return true;
|
|
20821
|
+
}
|
|
20822
|
+
function staleLeaseDir(leaseDir) {
|
|
20823
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20824
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20825
|
+
}
|
|
20662
20826
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20663
20827
|
try {
|
|
20664
20828
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20782,7 +20946,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20782
20946
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20783
20947
|
if (lstat(syncData) === null)
|
|
20784
20948
|
return false;
|
|
20785
|
-
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)}`);
|
|
20786
20950
|
}
|
|
20787
20951
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20788
20952
|
return {
|
|
@@ -20957,6 +21121,9 @@ function errorMessage2(error) {
|
|
|
20957
21121
|
return error instanceof Error ? error.message : String(error);
|
|
20958
21122
|
}
|
|
20959
21123
|
|
|
21124
|
+
// ../../plugins/publishings/shipinhao-pub/src/flow.ts
|
|
21125
|
+
init_dist();
|
|
21126
|
+
|
|
20960
21127
|
// ../../plugins/publishings/shipinhao-pub/src/selectors.ts
|
|
20961
21128
|
var SHP_TARGET = "shipinhao";
|
|
20962
21129
|
var SHP_HOME_URL = "https://channels.weixin.qq.com/platform";
|
|
@@ -21082,7 +21249,18 @@ var SHP_CONFIG = {
|
|
|
21082
21249
|
isAuthenticated: isShipinhaoAuthenticated,
|
|
21083
21250
|
loginTimeoutMs: SHP_LOGIN_TIMEOUT_MS,
|
|
21084
21251
|
checkHeadedOnly: true,
|
|
21085
|
-
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
|
+
}
|
|
21086
21264
|
};
|
|
21087
21265
|
|
|
21088
21266
|
// ../../plugins/publishings/shipinhao-pub/src/audio-flow.ts
|
|
@@ -21365,6 +21543,42 @@ async function pendingAudioFlow(input, metadata) {
|
|
|
21365
21543
|
});
|
|
21366
21544
|
}
|
|
21367
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
|
+
|
|
21368
21582
|
// ../../plugins/publishings/shipinhao-pub/src/flow.ts
|
|
21369
21583
|
var STEP_TIMEOUT_MS = 30000;
|
|
21370
21584
|
var PREFLIGHT_TIMEOUT_MS = 180000;
|
|
@@ -21890,7 +22104,7 @@ class ShipinhaoBrowserTransport {
|
|
|
21890
22104
|
constructor(operation = "shortVideo", driver = "script", deps = {}) {
|
|
21891
22105
|
this.operation = operation;
|
|
21892
22106
|
this.driver = driver;
|
|
21893
|
-
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
22107
|
+
this.launcher = stateRestoringLauncher(deps.launcher ?? kkBrowserLauncher);
|
|
21894
22108
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21895
22109
|
this.preflightTimeoutMs = deps.preflightTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21896
22110
|
}
|
|
@@ -21933,7 +22147,11 @@ class ShipinhaoBrowserTransport {
|
|
|
21933
22147
|
const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? metadataRecord.coverImage);
|
|
21934
22148
|
if (cover.error !== undefined)
|
|
21935
22149
|
return fail(SHP_TARGET, cover.error);
|
|
21936
|
-
|
|
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;
|
|
21937
22155
|
} else {
|
|
21938
22156
|
const images = await resolveImagesPath(metadataRecord.images);
|
|
21939
22157
|
if (images.error !== undefined)
|
|
@@ -22312,7 +22530,7 @@ function getPublishTransport(operation = "shortVideo", driver = "script") {
|
|
|
22312
22530
|
return new ShipinhaoBrowserTransport(operation, driver);
|
|
22313
22531
|
}
|
|
22314
22532
|
async function writePublishResult(outputPath, result) {
|
|
22315
|
-
const outDir =
|
|
22533
|
+
const outDir = dirname5(outputPath);
|
|
22316
22534
|
if (outDir && outDir !== ".")
|
|
22317
22535
|
await createNodeFileSystem().ensureDir(outDir);
|
|
22318
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";
|
|
@@ -19947,7 +19950,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
19947
19950
|
const leaseDir = join2(leaseRoot, id);
|
|
19948
19951
|
await fileSystem.ensureDir(leaseRoot);
|
|
19949
19952
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19950
|
-
|
|
19953
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
19954
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19955
|
+
}
|
|
19956
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19957
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19958
|
+
}
|
|
19951
19959
|
}
|
|
19952
19960
|
const token = randomBytes(16).toString("hex");
|
|
19953
19961
|
const owner = {
|
|
@@ -20063,9 +20071,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20063
20071
|
}
|
|
20064
20072
|
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`;
|
|
20065
20073
|
}
|
|
20066
|
-
const
|
|
20074
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20075
|
+
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}`;
|
|
20067
20076
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20068
20077
|
}
|
|
20078
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20079
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20080
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20081
|
+
return false;
|
|
20082
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20083
|
+
return false;
|
|
20084
|
+
const target = staleLeaseDir(leaseDir);
|
|
20085
|
+
try {
|
|
20086
|
+
rename(leaseDir, target);
|
|
20087
|
+
} catch {
|
|
20088
|
+
return false;
|
|
20089
|
+
}
|
|
20090
|
+
const moved = await readOwner(fileSystem, target);
|
|
20091
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20092
|
+
try {
|
|
20093
|
+
rename(target, leaseDir);
|
|
20094
|
+
} catch {}
|
|
20095
|
+
return false;
|
|
20096
|
+
}
|
|
20097
|
+
return true;
|
|
20098
|
+
}
|
|
20099
|
+
function staleLeaseDir(leaseDir) {
|
|
20100
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20101
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20102
|
+
}
|
|
20069
20103
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20070
20104
|
try {
|
|
20071
20105
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20156,6 +20190,101 @@ class BotError extends Error {
|
|
|
20156
20190
|
this.details = details;
|
|
20157
20191
|
}
|
|
20158
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
|
+
}
|
|
20159
20288
|
// ../../packages/publish-harness/src/index.ts
|
|
20160
20289
|
import { homedir as homedir4 } from "os";
|
|
20161
20290
|
import { join as join4, resolve as resolve4 } from "path";
|
|
@@ -20213,7 +20342,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20213
20342
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20214
20343
|
if (lstat(syncData) === null)
|
|
20215
20344
|
return false;
|
|
20216
|
-
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)}`);
|
|
20217
20346
|
}
|
|
20218
20347
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20219
20348
|
return {
|
|
@@ -20650,10 +20779,21 @@ var SHP_CONFIG = {
|
|
|
20650
20779
|
isAuthenticated: isShipinhaoAuthenticated,
|
|
20651
20780
|
loginTimeoutMs: SHP_LOGIN_TIMEOUT_MS,
|
|
20652
20781
|
checkHeadedOnly: true,
|
|
20653
|
-
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
|
+
}
|
|
20654
20794
|
};
|
|
20655
20795
|
|
|
20656
20796
|
// ../../plugins/publishings/shipinhao-pub/src/profile-check.ts
|
|
20657
20797
|
if (import.meta.main) {
|
|
20658
|
-
process.exit(await runProfileCli(SHP_CONFIG, Bun.argv.slice(2)));
|
|
20798
|
+
process.exit(await runProfileCli(SHP_CONFIG, Bun.argv.slice(2), { launcher: stateRestoringLauncher(kkBrowserLauncher) }));
|
|
20659
20799
|
}
|