@gobing-ai/knowledge-kit 0.1.17 → 0.1.20
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/daily-voice/index.js +40 -7
- package/dist/index.js +8428 -4448
- package/package.json +1 -1
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/kk/config.example.yaml +7 -2
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/chinese-article.json +8 -2
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
- package/plugins/kk/publish-presets/itc-main.json +36 -9
- package/plugins/kk/publish-presets/technical-article.json +8 -2
- package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
- package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
- package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/scripts/daily-triage-core.ts +43 -25
- package/plugins/kk/scripts/daily-triage.ts +1 -1
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/publish/SKILL.md +15 -2
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
- package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
- package/plugins/kk/workflows/kk-publish.yaml +236 -0
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +454 -81
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
- package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
- package/plugins/publishings/weibo-pub/dist/index.js +136 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
- package/plugins/publishings/weibo-pub/src/index.ts +208 -22
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- package/plugins/publishings/xhs-pub/dist/index.js +193 -201
- package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
- package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
- package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
- package/plugins/publishings/xhs-pub/src/index.ts +65 -59
- package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
- package/plugins/publishings/xhs-pub/src/page.ts +2 -2
- package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
- package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
- package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
- package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
- package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
- package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
- package/plugins/kk/workflows/kk-itc.yaml +0 -291
|
@@ -19832,10 +19832,12 @@ var init_runtime_node_bun = __esm(() => {
|
|
|
19832
19832
|
});
|
|
19833
19833
|
|
|
19834
19834
|
// ../../plugins/publishings/xhs-pub/src/profile-check.ts
|
|
19835
|
-
import {
|
|
19835
|
+
import { join as join7 } from "path";
|
|
19836
|
+
import { parseArgs as parseArgs2 } from "util";
|
|
19836
19837
|
|
|
19837
19838
|
// ../../packages/publish-harness/src/browser.ts
|
|
19838
19839
|
import { join as join5, resolve as resolve5 } from "path";
|
|
19840
|
+
import { parseArgs } from "util";
|
|
19839
19841
|
|
|
19840
19842
|
// ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.32+0f5f0476d0d466a6/node_modules/@gobing-ai/ts-browser-automation/dist/errors.js
|
|
19841
19843
|
class BrowserAutomationError extends Error {
|
|
@@ -20026,12 +20028,6 @@ function getDefaultLauncher() {
|
|
|
20026
20028
|
defaultLauncher = createPersistentLauncher();
|
|
20027
20029
|
return defaultLauncher;
|
|
20028
20030
|
}
|
|
20029
|
-
async function openPersistentBrowser(options) {
|
|
20030
|
-
return (options.launcher ?? getDefaultLauncher()).launch({
|
|
20031
|
-
profileDir: resolveProfileDir(options.profileDir),
|
|
20032
|
-
headless: options.headless
|
|
20033
|
-
});
|
|
20034
|
-
}
|
|
20035
20031
|
async function loginWithProfile(options) {
|
|
20036
20032
|
assertNotAborted(options.signal);
|
|
20037
20033
|
assertFiniteTimeoutMs(options.timeoutMs);
|
|
@@ -20417,7 +20413,24 @@ function sha256Hex(value) {
|
|
|
20417
20413
|
}
|
|
20418
20414
|
|
|
20419
20415
|
// ../../packages/publish-harness/src/bot.ts
|
|
20416
|
+
var BOT_SCHEMA_VERSION = 1;
|
|
20417
|
+
var BOT_METADATA_FILE = "bot.json";
|
|
20420
20418
|
var DEFAULT_BOT_PROFILE_ROOT = join3(homedir3(), ".config", "kk", "browser-profiles");
|
|
20419
|
+
var ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
20420
|
+
var MAX_IDENTITY_LENGTH = 128;
|
|
20421
|
+
var CONTROL_CHARACTERS = /\p{Cc}/u;
|
|
20422
|
+
function isSessionFactDate(value) {
|
|
20423
|
+
return typeof value === "string" && ISO_DATE_TIME.test(value) && Number.isFinite(Date.parse(value));
|
|
20424
|
+
}
|
|
20425
|
+
function isSessionFactIdentity(value) {
|
|
20426
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_IDENTITY_LENGTH && !CONTROL_CHARACTERS.test(value);
|
|
20427
|
+
}
|
|
20428
|
+
function normalizeSessionIdentity(value) {
|
|
20429
|
+
if (typeof value !== "string")
|
|
20430
|
+
return;
|
|
20431
|
+
const cleaned = value.replace(/\p{Cc}/gu, "").trim().slice(0, MAX_IDENTITY_LENGTH);
|
|
20432
|
+
return cleaned.length === 0 ? undefined : cleaned;
|
|
20433
|
+
}
|
|
20421
20434
|
class BotError extends Error {
|
|
20422
20435
|
code;
|
|
20423
20436
|
details;
|
|
@@ -20428,6 +20441,93 @@ class BotError extends Error {
|
|
|
20428
20441
|
this.details = details;
|
|
20429
20442
|
}
|
|
20430
20443
|
}
|
|
20444
|
+
function isStoredDefaultUrl(value, allowQuery) {
|
|
20445
|
+
let url;
|
|
20446
|
+
try {
|
|
20447
|
+
url = new URL(value);
|
|
20448
|
+
} catch {
|
|
20449
|
+
return false;
|
|
20450
|
+
}
|
|
20451
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
20452
|
+
return false;
|
|
20453
|
+
if (url.username !== "" || url.password !== "")
|
|
20454
|
+
return false;
|
|
20455
|
+
if (url.hash !== "")
|
|
20456
|
+
return false;
|
|
20457
|
+
if (!allowQuery && url.search !== "")
|
|
20458
|
+
return false;
|
|
20459
|
+
const stored = `${url.origin}${url.pathname}${allowQuery ? url.search : ""}`;
|
|
20460
|
+
return stored === value;
|
|
20461
|
+
}
|
|
20462
|
+
function parseBotMetadata(raw, source = "bot metadata") {
|
|
20463
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
20464
|
+
throw new BotError("persistence", `${source}: expected a JSON object`);
|
|
20465
|
+
}
|
|
20466
|
+
const record = raw;
|
|
20467
|
+
if (record.schemaVersion !== BOT_SCHEMA_VERSION) {
|
|
20468
|
+
throw new BotError("persistence", `${source}: unsupported schemaVersion ${JSON.stringify(record.schemaVersion)}`);
|
|
20469
|
+
}
|
|
20470
|
+
const evidence = record.authenticationEvidence;
|
|
20471
|
+
if (evidence !== "operator-confirmed" && evidence !== "site-verified") {
|
|
20472
|
+
throw new BotError("persistence", `${source}: authenticationEvidence must be operator-confirmed|site-verified`);
|
|
20473
|
+
}
|
|
20474
|
+
let pluginName;
|
|
20475
|
+
if (record.pluginName !== undefined) {
|
|
20476
|
+
if (typeof record.pluginName !== "string" || record.pluginName.length === 0) {
|
|
20477
|
+
throw new BotError("persistence", `${source}: pluginName must be a non-empty string`);
|
|
20478
|
+
}
|
|
20479
|
+
pluginName = record.pluginName;
|
|
20480
|
+
}
|
|
20481
|
+
const allowQuery = pluginName !== undefined;
|
|
20482
|
+
if (typeof record.defaultUrl !== "string" || !isStoredDefaultUrl(record.defaultUrl, allowQuery)) {
|
|
20483
|
+
throw new BotError("persistence", `${source}: defaultUrl must be an http(s) origin+pathname` + (allowQuery ? " with at most a plugin-fixed query" : ""));
|
|
20484
|
+
}
|
|
20485
|
+
const metadata = {
|
|
20486
|
+
schemaVersion: BOT_SCHEMA_VERSION,
|
|
20487
|
+
defaultUrl: record.defaultUrl,
|
|
20488
|
+
authenticationEvidence: evidence
|
|
20489
|
+
};
|
|
20490
|
+
if (pluginName !== undefined) {
|
|
20491
|
+
metadata.pluginName = pluginName;
|
|
20492
|
+
}
|
|
20493
|
+
if (record.lastLoginAt !== undefined) {
|
|
20494
|
+
if (!isSessionFactDate(record.lastLoginAt)) {
|
|
20495
|
+
throw new BotError("persistence", `${source}: lastLoginAt must be an ISO 8601 date-time`);
|
|
20496
|
+
}
|
|
20497
|
+
metadata.lastLoginAt = record.lastLoginAt;
|
|
20498
|
+
}
|
|
20499
|
+
if (record.expiresAt !== undefined) {
|
|
20500
|
+
if (!isSessionFactDate(record.expiresAt)) {
|
|
20501
|
+
throw new BotError("persistence", `${source}: expiresAt must be an ISO 8601 date-time`);
|
|
20502
|
+
}
|
|
20503
|
+
metadata.expiresAt = record.expiresAt;
|
|
20504
|
+
}
|
|
20505
|
+
if (record.identity !== undefined) {
|
|
20506
|
+
if (!isSessionFactIdentity(record.identity)) {
|
|
20507
|
+
throw new BotError("persistence", `${source}: identity must be a non-empty string of at most 128 characters without control characters`);
|
|
20508
|
+
}
|
|
20509
|
+
metadata.identity = record.identity;
|
|
20510
|
+
}
|
|
20511
|
+
return metadata;
|
|
20512
|
+
}
|
|
20513
|
+
async function readBotMetadata(fileSystem, metadataPath) {
|
|
20514
|
+
if (!await fileSystem.exists(metadataPath))
|
|
20515
|
+
return null;
|
|
20516
|
+
let text;
|
|
20517
|
+
try {
|
|
20518
|
+
text = await fileSystem.readFile(metadataPath);
|
|
20519
|
+
} catch (error) {
|
|
20520
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
20521
|
+
throw new BotError("persistence", `${metadataPath}: cannot read bot metadata: ${detail}`);
|
|
20522
|
+
}
|
|
20523
|
+
let raw;
|
|
20524
|
+
try {
|
|
20525
|
+
raw = JSON.parse(text);
|
|
20526
|
+
} catch {
|
|
20527
|
+
throw new BotError("persistence", `${metadataPath}: corrupt bot metadata (not valid JSON)`);
|
|
20528
|
+
}
|
|
20529
|
+
return parseBotMetadata(raw, metadataPath);
|
|
20530
|
+
}
|
|
20431
20531
|
// ../../packages/publish-harness/src/index.ts
|
|
20432
20532
|
import { homedir as homedir4 } from "os";
|
|
20433
20533
|
import { join as join4, resolve as resolve4 } from "path";
|
|
@@ -20478,8 +20578,12 @@ async function ensureProfileDir2(profileDir, headless) {
|
|
|
20478
20578
|
}
|
|
20479
20579
|
// ../../packages/publish-harness/src/browser-anti-detection.ts
|
|
20480
20580
|
var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
20581
|
+
|
|
20481
20582
|
// ../../packages/publish-harness/src/browser.ts
|
|
20583
|
+
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20584
|
+
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20482
20585
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20586
|
+
var DEFAULT_POLL_MS = 500;
|
|
20483
20587
|
function isInstantBrowserDeath(message) {
|
|
20484
20588
|
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20485
20589
|
}
|
|
@@ -20629,6 +20733,177 @@ async function checkChannelSession(config, opts) {
|
|
|
20629
20733
|
}
|
|
20630
20734
|
return { status: "refused", profileDir: opts.profileDir, detail: lastDetail };
|
|
20631
20735
|
}
|
|
20736
|
+
async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
20737
|
+
if (lstat(request.profileDir) === null) {
|
|
20738
|
+
stdout(`${config.channel} profile open failed: no profile at ${request.profileDir} \u2014 run the login command first`);
|
|
20739
|
+
return 1;
|
|
20740
|
+
}
|
|
20741
|
+
let context;
|
|
20742
|
+
try {
|
|
20743
|
+
context = await (deps.launcher ?? kkBrowserLauncher).launch({
|
|
20744
|
+
profileDir: request.profileDir,
|
|
20745
|
+
headless: false
|
|
20746
|
+
});
|
|
20747
|
+
} catch (error) {
|
|
20748
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20749
|
+
return 1;
|
|
20750
|
+
}
|
|
20751
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
20752
|
+
const onOpen = config.sessionState?.onOpen;
|
|
20753
|
+
if (onOpen !== undefined) {
|
|
20754
|
+
try {
|
|
20755
|
+
await onOpen({ context, page, profileDir: request.profileDir });
|
|
20756
|
+
} catch (error) {
|
|
20757
|
+
await context.close().catch(() => {});
|
|
20758
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20759
|
+
return 1;
|
|
20760
|
+
}
|
|
20761
|
+
}
|
|
20762
|
+
try {
|
|
20763
|
+
await page.goto(request.url, { waitUntil: "commit", timeout: DEFAULT_OPEN_NAV_TIMEOUT_MS });
|
|
20764
|
+
} catch (error) {
|
|
20765
|
+
stdout(`${config.channel} profile open navigation failed: ${errorMessage2(error)}`);
|
|
20766
|
+
}
|
|
20767
|
+
await new Promise((resolveClose) => {
|
|
20768
|
+
context.once("close", () => resolveClose());
|
|
20769
|
+
});
|
|
20770
|
+
stdout(`${config.channel} profile open closed: ${request.profileDir}`);
|
|
20771
|
+
return 0;
|
|
20772
|
+
}
|
|
20773
|
+
async function loginWithAuthenticatedPage(config, opts) {
|
|
20774
|
+
const context = await opts.launcher.launch({ profileDir: opts.profileDir, headless: false });
|
|
20775
|
+
const sessionCaptured = config.sessionState?.onAuthenticated !== undefined;
|
|
20776
|
+
let captured = false;
|
|
20777
|
+
let facts = {};
|
|
20778
|
+
try {
|
|
20779
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
20780
|
+
await page.goto(opts.url);
|
|
20781
|
+
if (!await waitUntil(() => Promise.resolve(config.isAuthenticated(page)), opts.timeoutMs)) {
|
|
20782
|
+
throw new Error(`Authentication was not confirmed within ${opts.timeoutMs}ms \u2014 the profile's site session has likely ` + "expired or the sign-in was not completed: run the login command again to sign in again.");
|
|
20783
|
+
}
|
|
20784
|
+
await config.sessionState?.onAuthenticated?.({ context, page, profileDir: opts.profileDir });
|
|
20785
|
+
captured = sessionCaptured;
|
|
20786
|
+
if (opts.captureFacts) {
|
|
20787
|
+
facts = {
|
|
20788
|
+
...await captureSessionFacts(context, config.homeUrl),
|
|
20789
|
+
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
20790
|
+
};
|
|
20791
|
+
}
|
|
20792
|
+
} finally {
|
|
20793
|
+
try {
|
|
20794
|
+
await context.close();
|
|
20795
|
+
} catch {
|
|
20796
|
+
if (captured) {
|
|
20797
|
+
echoError(`${config.channel} browser context close failed after the authenticated session capture; saved state preserved`);
|
|
20798
|
+
}
|
|
20799
|
+
}
|
|
20800
|
+
}
|
|
20801
|
+
return facts;
|
|
20802
|
+
}
|
|
20803
|
+
async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
20804
|
+
const stdout = deps.stdout ?? ((line) => {
|
|
20805
|
+
echo(line);
|
|
20806
|
+
});
|
|
20807
|
+
const usage = `usage: ${config.channel} profile-check [login|check|open] [--profile <dir>] [--url <url>] [--timeout <ms>] [--headed]`;
|
|
20808
|
+
let command;
|
|
20809
|
+
let profileDir;
|
|
20810
|
+
let timeoutMs;
|
|
20811
|
+
let headed = false;
|
|
20812
|
+
let url;
|
|
20813
|
+
try {
|
|
20814
|
+
const { positionals, values } = parseArgs({
|
|
20815
|
+
args: argv,
|
|
20816
|
+
allowPositionals: true,
|
|
20817
|
+
options: {
|
|
20818
|
+
profile: { type: "string" },
|
|
20819
|
+
timeout: { type: "string" },
|
|
20820
|
+
headed: { type: "boolean" },
|
|
20821
|
+
url: { type: "string" }
|
|
20822
|
+
}
|
|
20823
|
+
});
|
|
20824
|
+
command = positionals[0] ?? "check";
|
|
20825
|
+
headed = values.headed === true;
|
|
20826
|
+
url = values.url;
|
|
20827
|
+
if (command !== "login" && command !== "check" && command !== "open") {
|
|
20828
|
+
throw new Error(`unknown command '${command}'`);
|
|
20829
|
+
}
|
|
20830
|
+
if (command === "open" && (values.profile === undefined || url === undefined)) {
|
|
20831
|
+
throw new Error("open requires an explicit --profile <dir> and --url <url>");
|
|
20832
|
+
}
|
|
20833
|
+
if (values.timeout !== undefined) {
|
|
20834
|
+
timeoutMs = Number(values.timeout);
|
|
20835
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
20836
|
+
throw new Error(`--timeout must be a non-negative number of ms, got '${values.timeout}'`);
|
|
20837
|
+
}
|
|
20838
|
+
}
|
|
20839
|
+
profileDir = resolveChannelProfileDir(config.channel, values.profile);
|
|
20840
|
+
} catch (error) {
|
|
20841
|
+
stdout(`${config.channel} profile-check: ${errorMessage2(error)} \u2014 ${usage}`);
|
|
20842
|
+
stdout(JSON.stringify({ status: "error", detail: errorMessage2(error) }));
|
|
20843
|
+
return 2;
|
|
20844
|
+
}
|
|
20845
|
+
if (command === "open") {
|
|
20846
|
+
return openChannelSession(config, { profileDir, url: url ?? "" }, deps, stdout);
|
|
20847
|
+
}
|
|
20848
|
+
if (command === "login") {
|
|
20849
|
+
const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
|
|
20850
|
+
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
20851
|
+
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`);
|
|
20852
|
+
try {
|
|
20853
|
+
const captureFacts = url !== undefined;
|
|
20854
|
+
if (!captureFacts && config.sessionState?.onAuthenticated === undefined) {
|
|
20855
|
+
await loginWithProfile({
|
|
20856
|
+
profileDir,
|
|
20857
|
+
url: config.homeUrl,
|
|
20858
|
+
isAuthenticated: config.isAuthenticated,
|
|
20859
|
+
timeoutMs: loginTimeoutMs,
|
|
20860
|
+
launcher
|
|
20861
|
+
});
|
|
20862
|
+
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20863
|
+
return 0;
|
|
20864
|
+
}
|
|
20865
|
+
const facts = await loginWithAuthenticatedPage(config, {
|
|
20866
|
+
profileDir,
|
|
20867
|
+
url: url ?? config.homeUrl,
|
|
20868
|
+
timeoutMs: loginTimeoutMs,
|
|
20869
|
+
launcher,
|
|
20870
|
+
captureFacts
|
|
20871
|
+
});
|
|
20872
|
+
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20873
|
+
if (url === undefined)
|
|
20874
|
+
return 0;
|
|
20875
|
+
stdout(JSON.stringify({
|
|
20876
|
+
status: "verified",
|
|
20877
|
+
profileDir,
|
|
20878
|
+
defaultUrl: config.homeUrl,
|
|
20879
|
+
...facts.expiresAt === undefined ? {} : { expiresAt: facts.expiresAt },
|
|
20880
|
+
...facts.identity === undefined ? {} : { identity: facts.identity }
|
|
20881
|
+
}));
|
|
20882
|
+
return 0;
|
|
20883
|
+
} catch (error) {
|
|
20884
|
+
stdout(`${config.channel} profile login failed: ${errorMessage2(error)}`);
|
|
20885
|
+
return 1;
|
|
20886
|
+
}
|
|
20887
|
+
}
|
|
20888
|
+
const result = await checkChannelSession(config, {
|
|
20889
|
+
profileDir,
|
|
20890
|
+
launcher: deps.launcher,
|
|
20891
|
+
headedOnly: headed || config.checkHeadedOnly === true,
|
|
20892
|
+
timeoutMs
|
|
20893
|
+
});
|
|
20894
|
+
stdout(JSON.stringify(result));
|
|
20895
|
+
return result.status === "verified" ? 0 : 1;
|
|
20896
|
+
}
|
|
20897
|
+
async function waitUntil(predicate, timeoutMs, pollMs = DEFAULT_POLL_MS) {
|
|
20898
|
+
const deadline = Date.now() + timeoutMs;
|
|
20899
|
+
while (Date.now() < deadline) {
|
|
20900
|
+
if (await predicate()) {
|
|
20901
|
+
return true;
|
|
20902
|
+
}
|
|
20903
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
20904
|
+
}
|
|
20905
|
+
return predicate();
|
|
20906
|
+
}
|
|
20632
20907
|
var cdpNodeText = (node) => node.nodeName === "#text" ? node.nodeValue ?? "" : (node.children ?? []).map(cdpNodeText).join("");
|
|
20633
20908
|
async function findShadowControl(session, labels) {
|
|
20634
20909
|
const document = await session.send("DOM.getDocument", { depth: -1, pierce: true });
|
|
@@ -20674,6 +20949,29 @@ async function createShadowFinder(context, page) {
|
|
|
20674
20949
|
return;
|
|
20675
20950
|
}
|
|
20676
20951
|
}
|
|
20952
|
+
async function captureSessionFacts(context, url) {
|
|
20953
|
+
let cookies;
|
|
20954
|
+
try {
|
|
20955
|
+
cookies = await context.cookies(url);
|
|
20956
|
+
} catch {
|
|
20957
|
+
return {};
|
|
20958
|
+
}
|
|
20959
|
+
let earliest;
|
|
20960
|
+
for (const cookie of cookies) {
|
|
20961
|
+
if (!cookie.httpOnly || cookie.expires <= 0)
|
|
20962
|
+
continue;
|
|
20963
|
+
if (earliest === undefined || cookie.expires < earliest)
|
|
20964
|
+
earliest = cookie.expires;
|
|
20965
|
+
}
|
|
20966
|
+
return earliest === undefined ? {} : { expiresAt: new Date(earliest * 1000).toISOString() };
|
|
20967
|
+
}
|
|
20968
|
+
async function readIdentityOrUndefined(readIdentity, page) {
|
|
20969
|
+
try {
|
|
20970
|
+
return normalizeSessionIdentity(await readIdentity(page));
|
|
20971
|
+
} catch {
|
|
20972
|
+
return;
|
|
20973
|
+
}
|
|
20974
|
+
}
|
|
20677
20975
|
function errorMessage2(error) {
|
|
20678
20976
|
return error instanceof Error ? error.message : String(error);
|
|
20679
20977
|
}
|
|
@@ -21125,7 +21423,7 @@ function wrapPlaywrightPage(raw, shadow) {
|
|
|
21125
21423
|
// ../../plugins/publishings/xhs-pub/src/index.ts
|
|
21126
21424
|
var CHANNEL = "xhs";
|
|
21127
21425
|
var LOGIN_TIMEOUT_MS = 120000;
|
|
21128
|
-
var PREFLIGHT_TIMEOUT_MS =
|
|
21426
|
+
var PREFLIGHT_TIMEOUT_MS = 90000;
|
|
21129
21427
|
var AUTH_GATE = ["div.creator-tab", "text=\u4E0A\u4F20\u56FE\u6587"];
|
|
21130
21428
|
async function createShadowProbe(context, page) {
|
|
21131
21429
|
const find = await createShadowFinder(context, page);
|
|
@@ -21164,44 +21462,17 @@ async function checkXhsProfileSession(opts) {
|
|
|
21164
21462
|
profileDir: opts.profileDir,
|
|
21165
21463
|
launcher: opts.launcher,
|
|
21166
21464
|
timeoutMs: opts.timeoutMs ?? PREFLIGHT_TIMEOUT_MS,
|
|
21167
|
-
headedOnly:
|
|
21465
|
+
headedOnly: true
|
|
21168
21466
|
});
|
|
21169
21467
|
}
|
|
21170
21468
|
if (false) {}
|
|
21171
21469
|
|
|
21172
21470
|
// ../../plugins/publishings/xhs-pub/src/profile-check.ts
|
|
21173
|
-
async function loginProfile(opts) {
|
|
21174
|
-
await loginWithProfile({
|
|
21175
|
-
profileDir: opts.profileDir,
|
|
21176
|
-
url: PUBLISH_URL,
|
|
21177
|
-
isAuthenticated: (page) => isXhsConsoleReady(wrapPlaywrightPage(page)),
|
|
21178
|
-
timeoutMs: opts.timeoutMs ?? LOGIN_TIMEOUT_MS,
|
|
21179
|
-
launcher: opts.launcher ?? kkBrowserLauncher
|
|
21180
|
-
});
|
|
21181
|
-
}
|
|
21182
21471
|
function usageError(message) {
|
|
21183
21472
|
echoError(`profile-check: ${message} \u2014 usage: profile-check.ts [login|check|open] [--profile <dir>] [--url <url>] [--timeout <ms>] [--headed]`);
|
|
21184
21473
|
echo(JSON.stringify({ status: "error", detail: message }));
|
|
21185
21474
|
return 2;
|
|
21186
21475
|
}
|
|
21187
|
-
async function openXhsSession(opts) {
|
|
21188
|
-
if (!await createNodeFileSystem().exists(opts.profileDir)) {
|
|
21189
|
-
throw new Error(`no profile at ${opts.profileDir} \u2014 run the login command first`);
|
|
21190
|
-
}
|
|
21191
|
-
const raw = await openPersistentBrowser({
|
|
21192
|
-
profileDir: opts.profileDir,
|
|
21193
|
-
headless: false,
|
|
21194
|
-
launcher: opts.launcher ?? kkBrowserLauncher
|
|
21195
|
-
});
|
|
21196
|
-
const context = raw;
|
|
21197
|
-
const page = context.pages()[0] ?? await context.newPage();
|
|
21198
|
-
try {
|
|
21199
|
-
await page.goto(opts.url ?? PUBLISH_URL, { waitUntil: "commit", timeout: 30000 });
|
|
21200
|
-
} catch {}
|
|
21201
|
-
await new Promise((resolveClose) => {
|
|
21202
|
-
context.once("close", resolveClose);
|
|
21203
|
-
});
|
|
21204
|
-
}
|
|
21205
21476
|
async function main2(argv = process.argv.slice(2), launcher, guard = createAutomationGuard()) {
|
|
21206
21477
|
let command;
|
|
21207
21478
|
let profileDir;
|
|
@@ -21209,7 +21480,7 @@ async function main2(argv = process.argv.slice(2), launcher, guard = createAutom
|
|
|
21209
21480
|
let headed = false;
|
|
21210
21481
|
let sessionUrl;
|
|
21211
21482
|
try {
|
|
21212
|
-
const { positionals, values } =
|
|
21483
|
+
const { positionals, values } = parseArgs2({
|
|
21213
21484
|
args: argv,
|
|
21214
21485
|
allowPositionals: true,
|
|
21215
21486
|
options: {
|
|
@@ -21220,74 +21491,98 @@ async function main2(argv = process.argv.slice(2), launcher, guard = createAutom
|
|
|
21220
21491
|
}
|
|
21221
21492
|
});
|
|
21222
21493
|
command = positionals[0] ?? "check";
|
|
21223
|
-
|
|
21224
|
-
|
|
21494
|
+
if (!["login", "check", "open"].includes(command) || positionals.length > 1)
|
|
21495
|
+
throw new Error(`unknown command '${positionals.join(" ")}'`);
|
|
21496
|
+
if (command === "open" && values.profile === undefined)
|
|
21225
21497
|
throw new Error("open requires an explicit --profile <dir>");
|
|
21226
|
-
|
|
21498
|
+
headed = values.headed === true;
|
|
21227
21499
|
sessionUrl = values.url;
|
|
21228
21500
|
if (values.timeout !== undefined) {
|
|
21229
21501
|
timeoutMs = Number(values.timeout);
|
|
21230
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs < 0)
|
|
21502
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0)
|
|
21231
21503
|
throw new Error(`--timeout must be a non-negative number of ms, got '${values.timeout}'`);
|
|
21232
|
-
}
|
|
21233
21504
|
}
|
|
21234
21505
|
profileDir = resolveChannelProfileDir(CHANNEL, values.profile);
|
|
21235
21506
|
} catch (error) {
|
|
21236
21507
|
return usageError(error instanceof Error ? error.message : String(error));
|
|
21237
21508
|
}
|
|
21238
|
-
if (command === "login") {
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21509
|
+
if (command === "login" || command === "open") {
|
|
21510
|
+
let openDetail = "";
|
|
21511
|
+
const code = await runProfileCli({
|
|
21512
|
+
channel: CHANNEL,
|
|
21513
|
+
homeUrl: PUBLISH_URL,
|
|
21514
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21515
|
+
checkHeadedOnly: true,
|
|
21516
|
+
isAuthenticated: (page) => isXhsConsoleReady(wrapPlaywrightPage(page))
|
|
21517
|
+
}, command === "open" && sessionUrl === undefined ? [...argv, "--url", PUBLISH_URL] : argv, {
|
|
21518
|
+
launcher,
|
|
21519
|
+
stdout: (line) => {
|
|
21520
|
+
echo(line);
|
|
21521
|
+
if (line.includes("login failed:"))
|
|
21522
|
+
echoError(line);
|
|
21523
|
+
if (command === "open")
|
|
21524
|
+
openDetail = line.replace(/^xhs profile open failed: /, "");
|
|
21244
21525
|
}
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
|
|
21526
|
+
});
|
|
21527
|
+
if (command === "open") {
|
|
21528
|
+
const detail = code === 0 ? `xhs profile session closed by the operator: ${profileDir}` : `xhs profile open refused: ${openDetail}`;
|
|
21529
|
+
echo(JSON.stringify({ status: code === 0 ? "verified" : "refused", profileDir, detail }));
|
|
21530
|
+
if (code !== 0)
|
|
21531
|
+
echoError(detail);
|
|
21532
|
+
}
|
|
21533
|
+
return code;
|
|
21534
|
+
}
|
|
21535
|
+
let outcome;
|
|
21536
|
+
if (headed) {
|
|
21537
|
+
const cap = guard.allow("check");
|
|
21538
|
+
if (!cap.allowed)
|
|
21539
|
+
outcome = { status: "refused", profileDir, detail: `xhs readiness refused: ${cap.reason}` };
|
|
21540
|
+
else {
|
|
21541
|
+
guard.record("check");
|
|
21542
|
+
outcome = await checkXhsProfileSession({ profileDir, timeoutMs, launcher });
|
|
21249
21543
|
}
|
|
21250
|
-
}
|
|
21251
|
-
|
|
21544
|
+
} else {
|
|
21545
|
+
const fileSystem = createNodeFileSystem();
|
|
21252
21546
|
try {
|
|
21253
|
-
await
|
|
21547
|
+
const profile = await fileSystem.stat(profileDir);
|
|
21548
|
+
if (profile === null) {
|
|
21549
|
+
outcome = {
|
|
21550
|
+
status: "refused",
|
|
21551
|
+
profileDir,
|
|
21552
|
+
detail: `offline: no profile at ${profileDir} \u2014 run kk bot login xhs`
|
|
21553
|
+
};
|
|
21554
|
+
} else if (!profile.isDirectory()) {
|
|
21555
|
+
outcome = {
|
|
21556
|
+
status: "refused",
|
|
21557
|
+
profileDir,
|
|
21558
|
+
detail: `offline: profile ${profileDir} is not a directory \u2014 run kk bot login xhs`
|
|
21559
|
+
};
|
|
21560
|
+
} else {
|
|
21561
|
+
const metadata = await readBotMetadata(fileSystem, join7(profileDir, BOT_METADATA_FILE));
|
|
21562
|
+
const expiresAt = metadata?.expiresAt;
|
|
21563
|
+
const expired = expiresAt !== undefined && Date.parse(expiresAt) <= Date.now();
|
|
21564
|
+
outcome = {
|
|
21565
|
+
status: expired ? "refused" : "verified",
|
|
21566
|
+
profileDir,
|
|
21567
|
+
detail: `offline: ${expiresAt === undefined ? "expiry unknown" : `${expired ? "expired" : "expires"} ${expiresAt}`}${expired ? " \u2014 run kk bot login xhs" : ""}`
|
|
21568
|
+
};
|
|
21569
|
+
}
|
|
21254
21570
|
} catch (error) {
|
|
21255
|
-
|
|
21256
|
-
|
|
21257
|
-
|
|
21258
|
-
|
|
21571
|
+
outcome = {
|
|
21572
|
+
status: "refused",
|
|
21573
|
+
profileDir,
|
|
21574
|
+
detail: `offline: ${error instanceof Error ? error.message : String(error)}`
|
|
21575
|
+
};
|
|
21259
21576
|
}
|
|
21260
|
-
echo(JSON.stringify({
|
|
21261
|
-
status: "verified",
|
|
21262
|
-
profileDir,
|
|
21263
|
-
detail: `xhs profile session closed by the operator: ${profileDir}`
|
|
21264
|
-
}));
|
|
21265
|
-
return 0;
|
|
21266
|
-
}
|
|
21267
|
-
if (command !== "check") {
|
|
21268
|
-
return usageError(`unknown command '${command}'`);
|
|
21269
21577
|
}
|
|
21270
|
-
const cap = guard.allow("check");
|
|
21271
|
-
if (!cap.allowed) {
|
|
21272
|
-
echo(JSON.stringify({ status: "refused", profileDir, detail: `xhs readiness refused: ${cap.reason}` }));
|
|
21273
|
-
echoError(cap.reason);
|
|
21274
|
-
return 1;
|
|
21275
|
-
}
|
|
21276
|
-
guard.record("check");
|
|
21277
|
-
const outcome = await checkXhsProfileSession({ profileDir, timeoutMs, launcher, headedOnly: headed });
|
|
21278
21578
|
echo(JSON.stringify(outcome));
|
|
21279
|
-
if (outcome.status !== "verified")
|
|
21579
|
+
if (outcome.status !== "verified")
|
|
21280
21580
|
echoError(outcome.detail);
|
|
21281
|
-
|
|
21282
|
-
}
|
|
21283
|
-
return 0;
|
|
21581
|
+
return outcome.status === "verified" ? 0 : 1;
|
|
21284
21582
|
}
|
|
21285
|
-
if (import.meta.main)
|
|
21583
|
+
if (import.meta.main)
|
|
21286
21584
|
process.exit(await main2());
|
|
21287
|
-
}
|
|
21288
21585
|
export {
|
|
21289
21586
|
checkXhsProfileSession as checkProfileSession,
|
|
21290
|
-
|
|
21291
|
-
main2 as main,
|
|
21292
|
-
openXhsSession
|
|
21587
|
+
main2 as main
|
|
21293
21588
|
};
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
* a small state file.
|
|
9
9
|
*
|
|
10
10
|
* Semantics that matter:
|
|
11
|
-
* - The `publish` budget is consumed at the headed launch,
|
|
12
|
-
*
|
|
13
|
-
* headed console visits, not attempts.
|
|
11
|
+
* - The `publish` budget is consumed at the single headed launch, including session-readiness
|
|
12
|
+
* refusal. Offline checks spend nothing; explicit headed checks consume the check budget.
|
|
14
13
|
* - `login` is deliberately uncapped. It is operator-interactive by construction (a human types the
|
|
15
14
|
* credentials into the opened window), so capping it would only block recovery.
|
|
16
15
|
* - An unreadable or unparsable state file is REFUSED, not treated as empty: the guard cannot prove
|