@gobing-ai/knowledge-kit 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +302 -59
- package/package.json +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +47 -6
- package/plugins/generations/episode-plan-gen/src/index.ts +71 -7
- package/plugins/generations/music-gen/dist/index.js +17 -13
- package/plugins/generations/music-gen/src/audio/measure.ts +25 -20
- package/plugins/kk/decisions/extract/ai-news.yaml +8 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +4 -4
- package/plugins/kk/publish-presets/itc-main.json +39 -23
- package/plugins/kk/scripts/daily-stages.ts +500 -33
- package/plugins/kk/scripts/kk-workflow-stages.ts +5 -0
- package/plugins/kk/skills/content-safety/references/platforms/apple-podcasts.md +12 -5
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +8 -0
- package/plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md +5 -0
- package/plugins/kk/skills/daily-news-cover/SKILL.md +96 -0
- package/plugins/kk/skills/daily-news-illustrations/SKILL.md +123 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +5 -3
- package/plugins/kk/skills/news-editorial/references/daily-visual-composition.md +150 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +1 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +13 -1
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +6 -3
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -4
- package/plugins/kk/workflows/kk-news-generate.yaml +71 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +3 -2
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/cnblogs-pub/dist/index.js +3 -2
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/csdn-pub/dist/index.js +3 -2
- package/plugins/publishings/csdn-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/infoq-pub/dist/index.js +3 -2
- package/plugins/publishings/infoq-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/jike-pub/dist/index.js +3 -2
- package/plugins/publishings/jike-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/juejin-pub/dist/index.js +3 -2
- package/plugins/publishings/juejin-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +3 -2
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/medium-pub/dist/index.js +9198 -279
- package/plugins/publishings/medium-pub/dist/profile-check.js +21174 -0
- package/plugins/publishings/medium-pub/package.json +3 -1
- package/plugins/publishings/medium-pub/plugin.json +6 -1
- package/plugins/publishings/medium-pub/src/browser-rail.ts +280 -0
- package/plugins/publishings/medium-pub/src/index.ts +17 -1
- package/plugins/publishings/medium-pub/src/profile-check.ts +27 -0
- package/plugins/publishings/shipinhao-pub/dist/index.js +6 -3
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +5 -3
- package/plugins/publishings/shipinhao-pub/src/flow.ts +5 -0
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +11 -4
- package/plugins/publishings/sspai-pub/dist/index.js +3 -2
- package/plugins/publishings/sspai-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/substack-pub/dist/index.js +3 -2
- package/plugins/publishings/substack-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/threads-pub/dist/index.js +3 -2
- package/plugins/publishings/threads-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +262 -42
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/wechatmp-pub/src/flow.ts +447 -53
- package/plugins/publishings/wechatmp-pub/src/index.ts +4 -1
- package/plugins/publishings/wechatmp-pub/src/page.ts +8 -0
- package/plugins/publishings/weibo-pub/dist/index.js +3 -2
- package/plugins/publishings/weibo-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/x-pub/dist/index.js +3 -2
- package/plugins/publishings/x-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/xhs-pub/dist/index.js +3 -2
- package/plugins/publishings/xhs-pub/dist/profile-check.js +3 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +3 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +3 -2
|
@@ -20698,7 +20698,8 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20698
20698
|
}
|
|
20699
20699
|
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`;
|
|
20700
20700
|
}
|
|
20701
|
-
|
|
20701
|
+
const suffix = 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 \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20702
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20702
20703
|
}
|
|
20703
20704
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20704
20705
|
try {
|
|
@@ -20934,7 +20935,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20934
20935
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20935
20936
|
}
|
|
20936
20937
|
async function checkChannelSession(config, opts) {
|
|
20937
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20938
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20938
20939
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20939
20940
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20940
20941
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -21267,7 +21268,7 @@ function editorTextScript(selector) {
|
|
|
21267
21268
|
init_dist();
|
|
21268
21269
|
|
|
21269
21270
|
// ../../plugins/publishings/wechatmp-pub/src/flow.ts
|
|
21270
|
-
import { randomUUID } from "crypto";
|
|
21271
|
+
import { createHash as createHash2, randomUUID } from "crypto";
|
|
21271
21272
|
import { tmpdir } from "os";
|
|
21272
21273
|
import { extname, join as join6 } from "path";
|
|
21273
21274
|
|
|
@@ -22665,6 +22666,9 @@ function wrapPlaywrightPage(raw) {
|
|
|
22665
22666
|
}
|
|
22666
22667
|
}),
|
|
22667
22668
|
setInputFiles: (selector, paths) => pw.setInputFiles(selector, paths),
|
|
22669
|
+
screenshot: async (path) => {
|
|
22670
|
+
await raw.screenshot({ path });
|
|
22671
|
+
},
|
|
22668
22672
|
url: () => pw.url(),
|
|
22669
22673
|
evaluate: (expression) => pw.evaluate(expression),
|
|
22670
22674
|
waitForTimeout: (ms) => pw.waitForTimeout(ms),
|
|
@@ -23098,6 +23102,8 @@ var COVER_CONFIRM = [
|
|
|
23098
23102
|
var DIALOG_DISMISS = [
|
|
23099
23103
|
'.weui-desktop-dialog:visible button:has-text("\u53D6\u6D88")',
|
|
23100
23104
|
".weui-desktop-dialog__close",
|
|
23105
|
+
'.weui-desktop-dialog__wrp button:has-text("\u6211\u77E5\u9053\u4E86")',
|
|
23106
|
+
'button:has-text("\u6211\u77E5\u9053\u4E86")',
|
|
23101
23107
|
'button:has-text("\u53D6\u6D88")'
|
|
23102
23108
|
];
|
|
23103
23109
|
async function dismissOpenDialog(page) {
|
|
@@ -23117,7 +23123,11 @@ var DIALOG_CLOSE = [
|
|
|
23117
23123
|
".weui-desktop-dialog__close",
|
|
23118
23124
|
".weui-desktop-dialog__close-btn",
|
|
23119
23125
|
'.weui-desktop-dialog__wrp button:has-text("\u53D6\u6D88")',
|
|
23120
|
-
'button:has-text("\u53D6\u6D88")'
|
|
23126
|
+
'button:has-text("\u53D6\u6D88")',
|
|
23127
|
+
'.weui-desktop-dialog__wrp button:has-text("\u6211\u77E5\u9053\u4E86")',
|
|
23128
|
+
'button:has-text("\u6211\u77E5\u9053\u4E86")',
|
|
23129
|
+
'.weui-desktop-dialog__wrp button:has-text("\u5173\u95ED")',
|
|
23130
|
+
'.weui-desktop-dialog__wrp button:has-text("\u786E\u5B9A")'
|
|
23121
23131
|
];
|
|
23122
23132
|
async function closeOpenDialogs(page) {
|
|
23123
23133
|
for (let pass = 0;pass < 3; pass += 1) {
|
|
@@ -23365,6 +23375,16 @@ async function enterMode(deps, operation) {
|
|
|
23365
23375
|
async function attachImages(page, images, deps) {
|
|
23366
23376
|
const selector = await findAttachedSelector(page, IMAGE_FILE_INPUT, "image file input", deps.stepTimeoutMs);
|
|
23367
23377
|
await page.setInputFiles(selector, images);
|
|
23378
|
+
if (images.length === 0)
|
|
23379
|
+
return;
|
|
23380
|
+
await closeOpenDialogs(page);
|
|
23381
|
+
const bodySelector = await findSelector(page, BODY_BLOCK, "article body", deps.stepTimeoutMs);
|
|
23382
|
+
const countScript = `/* __KK_WECHAT_BODY_IMAGE_COUNT__ */ [...document.querySelectorAll(${JSON.stringify(`${bodySelector} img`)})].filter((img) => /^https?:/.test(img.currentSrc || img.src)).length`;
|
|
23383
|
+
const uploadTimeoutMs = Math.min(Math.max(deps.stepTimeoutMs, 45000), 60000);
|
|
23384
|
+
const landed = await waitUntil(async () => Number(await page.evaluate(countScript).catch(() => 0)) >= images.length, uploadTimeoutMs, 250);
|
|
23385
|
+
if (!landed) {
|
|
23386
|
+
throw new Error(`article images: ${images.length} upload(s) did not finish in ${bodySelector} within ${uploadTimeoutMs}ms \u2014 refusing to continue with an incomplete draft`);
|
|
23387
|
+
}
|
|
23368
23388
|
}
|
|
23369
23389
|
async function typeTitle(page, deps) {
|
|
23370
23390
|
const title = titleOf(deps.content);
|
|
@@ -23396,15 +23416,139 @@ async function readTitleMirror(page) {
|
|
|
23396
23416
|
return { observed: false, value: "" };
|
|
23397
23417
|
}
|
|
23398
23418
|
}
|
|
23419
|
+
async function inlineFiguresOf(content) {
|
|
23420
|
+
const raw = content.metadata?.wechatmp?.inlineFigures;
|
|
23421
|
+
if (raw === undefined)
|
|
23422
|
+
return [];
|
|
23423
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
23424
|
+
return [];
|
|
23425
|
+
const figures = [];
|
|
23426
|
+
for (const [index, entry] of raw.entries()) {
|
|
23427
|
+
const figure = entry ?? {};
|
|
23428
|
+
const id = `figure-${index + 1}`;
|
|
23429
|
+
for (const field of ["id", "path", "sha256", "altText", "caption"]) {
|
|
23430
|
+
if (typeof figure[field] !== "string" || String(figure[field]).trim() === "") {
|
|
23431
|
+
throw new Error(`inline figures: ${id} metadata has no ${field} \u2014 refusing to place an unverified figure`);
|
|
23432
|
+
}
|
|
23433
|
+
}
|
|
23434
|
+
if (figure.id !== id) {
|
|
23435
|
+
throw new Error(`inline figures: expected id '${id}' at position ${index + 1}, found '${String(figure.id)}' \u2014 figure order is the body order`);
|
|
23436
|
+
}
|
|
23437
|
+
const path = String(figure.path);
|
|
23438
|
+
const expected = String(figure.sha256);
|
|
23439
|
+
let actual;
|
|
23440
|
+
try {
|
|
23441
|
+
actual = createHash2("sha256").update((await readLocalImageBytes(path)).bytes).digest("hex");
|
|
23442
|
+
} catch {
|
|
23443
|
+
throw new Error(`inline figures: ${id} image is unreadable at ${path} \u2014 refusing to publish a missing figure`);
|
|
23444
|
+
}
|
|
23445
|
+
if (actual !== expected) {
|
|
23446
|
+
throw new Error(`inline figures: ${id} image bytes changed since the review (${path}) \u2014 re-render before publishing`);
|
|
23447
|
+
}
|
|
23448
|
+
figures.push({
|
|
23449
|
+
id,
|
|
23450
|
+
path,
|
|
23451
|
+
sha256: expected,
|
|
23452
|
+
altText: String(figure.altText),
|
|
23453
|
+
caption: String(figure.caption)
|
|
23454
|
+
});
|
|
23455
|
+
}
|
|
23456
|
+
return figures;
|
|
23457
|
+
}
|
|
23458
|
+
function assertInlineFigureMarkers(body, figures) {
|
|
23459
|
+
const found = [...body.matchAll(/!\[[^\]]*\]\(kk-inline:([^)]+)\)/g)].map((match) => String(match[1]));
|
|
23460
|
+
const expected = figures.map((figure) => figure.id);
|
|
23461
|
+
if (found.length !== expected.length) {
|
|
23462
|
+
throw new Error(`inline figures: the body carries ${found.length} figure marker(s) but the payload pins ${expected.length} \u2014 refusing to save a body whose figures cannot all resolve`);
|
|
23463
|
+
}
|
|
23464
|
+
for (const [index, id] of expected.entries()) {
|
|
23465
|
+
if (found[index] !== id) {
|
|
23466
|
+
throw new Error(`inline figures: marker ${index + 1} in the body is '${String(found[index])}' but figure ${index + 1} is '${id}' \u2014 figure order must follow the body`);
|
|
23467
|
+
}
|
|
23468
|
+
}
|
|
23469
|
+
}
|
|
23470
|
+
function escapeFigureText(value) {
|
|
23471
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
23472
|
+
}
|
|
23473
|
+
function withInlineFigureHtml(body, figures, srcs) {
|
|
23474
|
+
if (srcs.length !== figures.length) {
|
|
23475
|
+
throw new Error(`inline figures: ${figures.length} figure(s) need ${figures.length} uploaded URL(s), got ${srcs.length} \u2014 refusing to insert a body with a misplaced figure`);
|
|
23476
|
+
}
|
|
23477
|
+
let out = body;
|
|
23478
|
+
for (const [index, figure] of figures.entries()) {
|
|
23479
|
+
const marker = new RegExp(`!\\[[^\\]]*\\]\\(kk-inline:${figure.id}\\)`);
|
|
23480
|
+
if (!marker.test(out)) {
|
|
23481
|
+
throw new Error(`inline figures: ${figure.id} marker is missing from the body \u2014 refusing to insert`);
|
|
23482
|
+
}
|
|
23483
|
+
const src = String(srcs[index]);
|
|
23484
|
+
const html = `<img src="${escapeFigureText(src)}" alt="${escapeFigureText(figure.altText)}" data-kk-figure="${figure.id}"><p>${escapeFigureText(figure.caption)}</p>`;
|
|
23485
|
+
out = out.replace(marker, () => html);
|
|
23486
|
+
}
|
|
23487
|
+
return out;
|
|
23488
|
+
}
|
|
23489
|
+
async function bodyImageSrcs(page, selectors) {
|
|
23490
|
+
const script = `(() => {
|
|
23491
|
+
const el = ${JSON.stringify(selectors)}.map((s) => document.querySelector(s)).find(Boolean);
|
|
23492
|
+
if (!el) return [];
|
|
23493
|
+
return Array.from(el.querySelectorAll('img')).map((img) => img.getAttribute('src') || '').filter(Boolean);
|
|
23494
|
+
})()`;
|
|
23495
|
+
const raw = await page.evaluate(script).catch(() => []);
|
|
23496
|
+
return Array.isArray(raw) ? raw.map((value) => String(value)) : [];
|
|
23497
|
+
}
|
|
23498
|
+
async function waitForInlineFigureSrcs(page, count, deps) {
|
|
23499
|
+
const deadline = Date.now() + deps.stepTimeoutMs;
|
|
23500
|
+
let srcs = [];
|
|
23501
|
+
while (Date.now() < deadline) {
|
|
23502
|
+
srcs = await bodyImageSrcs(page, BODY_BLOCK);
|
|
23503
|
+
if (srcs.length >= count)
|
|
23504
|
+
return srcs.slice(-count);
|
|
23505
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
23506
|
+
}
|
|
23507
|
+
throw new Error(`inline figures: the editor uploaded ${srcs.length} of ${count} figure image(s) before the timeout \u2014 refusing to insert a body with a missing figure`);
|
|
23508
|
+
}
|
|
23509
|
+
async function verifyInlineFigureDom(page, selectors, figures, srcs) {
|
|
23510
|
+
const script = `(() => {
|
|
23511
|
+
const el = ${JSON.stringify(selectors)}.map((s) => document.querySelector(s)).find(Boolean);
|
|
23512
|
+
if (!el) return [];
|
|
23513
|
+
return Array.from(el.querySelectorAll('img[data-kk-figure]')).map((img) => ({
|
|
23514
|
+
id: img.getAttribute('data-kk-figure') || '',
|
|
23515
|
+
src: img.getAttribute('src') || '',
|
|
23516
|
+
alt: img.getAttribute('alt') || '',
|
|
23517
|
+
caption: (img.nextElementSibling && img.nextElementSibling.textContent) || '',
|
|
23518
|
+
}));
|
|
23519
|
+
})()`;
|
|
23520
|
+
const observed = await page.evaluate(script).catch(() => []);
|
|
23521
|
+
if (!Array.isArray(observed) || observed.length !== figures.length) {
|
|
23522
|
+
throw new Error(`inline figures: the editor holds ${Array.isArray(observed) ? observed.length : "no"} figure node(s) but the payload pins ${figures.length} \u2014 refusing to save (a text-only or appended-at-end result is not an illustrated article)`);
|
|
23523
|
+
}
|
|
23524
|
+
for (const [index, figure] of figures.entries()) {
|
|
23525
|
+
const seen = observed[index];
|
|
23526
|
+
if (seen === undefined || seen.id !== figure.id) {
|
|
23527
|
+
throw new Error(`inline figures: editor position ${index + 1} holds '${String(seen?.id)}', expected '${figure.id}'`);
|
|
23528
|
+
}
|
|
23529
|
+
if (seen.src !== String(srcs[index])) {
|
|
23530
|
+
throw new Error(`inline figures: ${figure.id} shows '${seen.src}', expected '${String(srcs[index])}'`);
|
|
23531
|
+
}
|
|
23532
|
+
if (seen.alt !== figure.altText) {
|
|
23533
|
+
throw new Error(`inline figures: ${figure.id} alt text reads '${seen.alt}', expected '${figure.altText}'`);
|
|
23534
|
+
}
|
|
23535
|
+
if (seen.caption.trim() !== figure.caption.trim()) {
|
|
23536
|
+
throw new Error(`inline figures: ${figure.id} caption reads '${seen.caption.trim()}', expected '${figure.caption}'`);
|
|
23537
|
+
}
|
|
23538
|
+
}
|
|
23539
|
+
}
|
|
23399
23540
|
async function insertBody(page, deps, selectors = BODY_BLOCK) {
|
|
23400
23541
|
const body = bodyOf(deps.content);
|
|
23401
23542
|
if (body.trim().length === 0)
|
|
23402
23543
|
return;
|
|
23544
|
+
await insertHtmlBody(page, body, markdownToWechatHtml(body), deps, selectors);
|
|
23545
|
+
}
|
|
23546
|
+
async function insertHtmlBody(page, body, html, deps, selectors = BODY_BLOCK) {
|
|
23403
23547
|
const selector = await findSelector(page, selectors, "article body", deps.stepTimeoutMs);
|
|
23404
|
-
const html = markdownToWechatHtml(body);
|
|
23405
23548
|
try {
|
|
23406
23549
|
await pasteHtml(asPlaywrightPage(page), selector, html, { timeoutMs: Math.min(deps.stepTimeoutMs, 1e4) });
|
|
23407
|
-
|
|
23550
|
+
if (await bodyLength(page, selector) > 0)
|
|
23551
|
+
return;
|
|
23408
23552
|
} catch {}
|
|
23409
23553
|
await closeOpenDialogs(page);
|
|
23410
23554
|
await clickSelector(page, selector, deps.stepTimeoutMs);
|
|
@@ -23498,21 +23642,26 @@ function nativeLegacyEditorReadyScript() {
|
|
|
23498
23642
|
'#js_save_success, #js_save_success_with_ad, #js_save_success_with_ad_op',
|
|
23499
23643
|
)];
|
|
23500
23644
|
if (!autoSaveContainer || !legacyAutoSave || saveSuccessMarkers.length === 0) return 'unknown';
|
|
23501
|
-
|
|
23645
|
+
let legacyAutoSaveHidden = true;
|
|
23646
|
+
for (const node of [legacyAutoSave, ...saveSuccessMarkers]) {
|
|
23502
23647
|
const style = window.getComputedStyle(node);
|
|
23503
23648
|
const rect = node.getBoundingClientRect();
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23507
|
-
|
|
23508
|
-
|
|
23649
|
+
if (!(style.display === 'none' || style.visibility === 'hidden' || rect.width === 0 || rect.height === 0)) {
|
|
23650
|
+
legacyAutoSaveHidden = false;
|
|
23651
|
+
}
|
|
23652
|
+
}
|
|
23653
|
+
const visibleSaveControls = [];
|
|
23654
|
+
for (const node of [...document.querySelectorAll('button, a')]) {
|
|
23655
|
+
const label = (node.textContent ?? '').replace(/[\\s\\u00a0]+/g, '').trim();
|
|
23656
|
+
if (label !== '\u4FDD\u5B58\u4E3A\u8349\u7A3F') continue;
|
|
23509
23657
|
const style = window.getComputedStyle(node);
|
|
23510
23658
|
const rect = node.getBoundingClientRect();
|
|
23511
|
-
|
|
23512
|
-
|
|
23659
|
+
if (style.display !== 'none' && style.visibility !== 'hidden' && rect.width > 0 && rect.height > 0) {
|
|
23660
|
+
visibleSaveControls.push(node);
|
|
23661
|
+
}
|
|
23662
|
+
}
|
|
23513
23663
|
return autoSaveContainer.textContent?.trim() === '' &&
|
|
23514
|
-
|
|
23515
|
-
saveSuccessMarkers.every(hidden) &&
|
|
23664
|
+
legacyAutoSaveHidden &&
|
|
23516
23665
|
visibleSaveControls.length === 1
|
|
23517
23666
|
? 'ready'
|
|
23518
23667
|
: 'unknown';
|
|
@@ -23659,40 +23808,73 @@ async function setCover(page, source, deps, identity) {
|
|
|
23659
23808
|
await dismissOpenDialog(page);
|
|
23660
23809
|
return inventory ? `${message} (dialogs: ${inventory})` : message;
|
|
23661
23810
|
};
|
|
23811
|
+
const domPicker = source === "library" ? "#js_cover_area a.js_imagedialog, #js_cover_null a.js_imagedialog" : "#js_cover_area a.js_selectCoverFromContent, #js_cover_null a.js_selectCoverFromContent";
|
|
23812
|
+
const clickSource = async () => {
|
|
23813
|
+
const pick = await tryFindSelector(page, picker, Math.min(deps.stepTimeoutMs, 8000));
|
|
23814
|
+
if (pick !== undefined) {
|
|
23815
|
+
await clickSelector(page, pick, deps.stepTimeoutMs);
|
|
23816
|
+
return true;
|
|
23817
|
+
}
|
|
23818
|
+
return Boolean(await page.evaluate(`/* __KK_WECHAT_DOM_CLICK__ */ (() => {
|
|
23819
|
+
const el = document.querySelector(${JSON.stringify(domPicker)});
|
|
23820
|
+
if (!el) return false;
|
|
23821
|
+
el.click();
|
|
23822
|
+
return true;
|
|
23823
|
+
})()`).catch(() => false));
|
|
23824
|
+
};
|
|
23662
23825
|
try {
|
|
23663
23826
|
const open = await tryFindSelector(page, COVER_PANEL_OPEN, Math.min(deps.stepTimeoutMs, 5000));
|
|
23664
23827
|
if (open === undefined)
|
|
23665
23828
|
return await warn("cover: the panel offers none of \u4ECE\u6B63\u6587\u9009\u62E9 / \u4ECE\u56FE\u7247\u5E93\u9009\u62E9 \u2014 the platform default (\u9ED8\u8BA4\u9996\u56FE\u4E3A\u5C01\u9762) is all this run has");
|
|
23666
23829
|
await clickSelector(page, open, deps.stepTimeoutMs);
|
|
23667
23830
|
const alreadyOpen = source === "library" && await tryFindSelector(page, ['.weui-desktop-dialog:visible:has(h3:has-text("\u9009\u62E9\u56FE\u7247"))'], Math.min(deps.stepTimeoutMs, 1000)) !== undefined;
|
|
23668
|
-
if (!alreadyOpen)
|
|
23669
|
-
|
|
23670
|
-
if (pick === undefined)
|
|
23671
|
-
return await warn(`cover: ${what} was not offered by the open cover panel`);
|
|
23672
|
-
await clickSelector(page, pick, deps.stepTimeoutMs);
|
|
23673
|
-
}
|
|
23831
|
+
if (!alreadyOpen && !await clickSource())
|
|
23832
|
+
return await warn(`cover: ${what} was not offered by the open cover panel`);
|
|
23674
23833
|
if (wanted.length === 0)
|
|
23675
23834
|
return await warn(`cover: no requested cover file identity to match against \u2014 ${what} not driven`);
|
|
23676
23835
|
const IDENTIFY = `(() => {
|
|
23677
23836
|
const wanted = ${JSON.stringify(wanted)};
|
|
23678
|
-
const rows = [...document.querySelectorAll('.weui-desktop-img-picker__item, div[class*="img_picker" i] li, div[class*="imgList" i] li, div[class*="cover" i] li')]
|
|
23837
|
+
const rows = [...document.querySelectorAll('.weui-desktop-img-picker__item, .appmsg_content_img_item, div[class*="img_picker" i] li, div[class*="imgList" i] li, div[class*="cover" i] li')]
|
|
23679
23838
|
.filter((row) => row.offsetWidth > 0);
|
|
23680
|
-
const
|
|
23839
|
+
const namedRows = [];
|
|
23840
|
+
for (const row of rows) {
|
|
23681
23841
|
const el = row.querySelector('[title], [data-name], [data-file_name]') ?? row;
|
|
23682
23842
|
const attrs = [el.getAttribute?.('title'), el.getAttribute?.('data-name'), el.getAttribute?.('data-file_name')];
|
|
23683
23843
|
const text = [...row.querySelectorAll('[class*="name" i], [class*="title" i]')].map((n) => n.textContent ?? '');
|
|
23684
|
-
|
|
23685
|
-
|
|
23686
|
-
|
|
23687
|
-
|
|
23688
|
-
|
|
23689
|
-
|
|
23844
|
+
const names = [...attrs, ...text].map((v) => (v ?? '').trim()).filter((v) => v.length > 0);
|
|
23845
|
+
namedRows.push({ row, names });
|
|
23846
|
+
}
|
|
23847
|
+
const hits = [];
|
|
23848
|
+
for (const entry of namedRows) {
|
|
23849
|
+
if (wanted.some((w) => entry.names.includes(w))) hits.push(entry.row);
|
|
23850
|
+
}
|
|
23851
|
+
// The \u4ECE\u6B63\u6587\u9009\u62E9 picker exposes no filename on the current build: it renders
|
|
23852
|
+
// .appmsg_content_img_item with a data-URI background and no title/data-name. A SOLE
|
|
23853
|
+
// visible IMAGE candidate is therefore uniquely identified by the picker itself; several
|
|
23854
|
+
// anonymous candidates still refuse rather than guessing the first one. The broad
|
|
23855
|
+
// selector list above also matches cover-MENU <li> nodes, which must never be clicked
|
|
23856
|
+
// as if they were images. Plain loops, not new arrow functions, keep the per-file
|
|
23857
|
+
// function-coverage gate honest about page-side code it cannot instrument.
|
|
23858
|
+
const anonymousRows = [];
|
|
23859
|
+
for (const entry of namedRows) {
|
|
23860
|
+
const row = entry.row;
|
|
23861
|
+
const isImage =
|
|
23862
|
+
row.matches('.appmsg_content_img_item, .weui-desktop-img-picker__item') ||
|
|
23863
|
+
row.querySelector('.appmsg_content_img') !== null;
|
|
23864
|
+
// A near-match whose exposed name disagrees is NOT anonymous and still refuses.
|
|
23865
|
+
if (isImage && entry.names.length === 0) anonymousRows.push(row);
|
|
23866
|
+
}
|
|
23867
|
+
const candidates = hits.length > 0 ? hits : anonymousRows.length === 1 ? anonymousRows : [];
|
|
23868
|
+
if (candidates.length === 0) return 'missing';
|
|
23869
|
+
if (candidates.length > 1) return 'ambiguous';
|
|
23870
|
+
const row = candidates[0];
|
|
23871
|
+
const soleCandidate = hits.length === 0;
|
|
23690
23872
|
if (!row.classList.contains('selected')) row.click();
|
|
23691
23873
|
const checked = row.querySelector('input[type=checkbox], [role=checkbox]');
|
|
23692
23874
|
const css = row.querySelector('[style*="background-image"]')?.style.backgroundImage ?? '';
|
|
23693
23875
|
const backgroundUrl = css.startsWith('url("') || css.startsWith("url('") ? css.slice(5, -2) : css.startsWith('url(') ? css.slice(4, -1) : '';
|
|
23694
23876
|
const src = row.querySelector('img')?.src || backgroundUrl;
|
|
23695
|
-
return JSON.stringify({ picked: true, src });
|
|
23877
|
+
return JSON.stringify({ picked: true, src, soleCandidate });
|
|
23696
23878
|
})()`;
|
|
23697
23879
|
let rawIdentify = "missing";
|
|
23698
23880
|
await waitUntil(async () => {
|
|
@@ -23776,7 +23958,7 @@ async function setCover(page, source, deps, identity) {
|
|
|
23776
23958
|
const url = new URL(committed);
|
|
23777
23959
|
derivedFromBoundCrop = cropBound && committed !== beforeCommit && url.hostname === "mmbiz.qpic.cn" && ["http:", "https:"].includes(url.protocol);
|
|
23778
23960
|
} catch {}
|
|
23779
|
-
if (selectedSrc === "" || coverAssetIdentity(committed) !== coverAssetIdentity(selectedSrc) && !derivedFromBoundCrop)
|
|
23961
|
+
if (selectedSrc === "" || coverAssetIdentity(committed) !== coverAssetIdentity(selectedSrc) && !derivedFromBoundCrop && !(selected.soleCandidate === true && selectedSrc.startsWith("data:")))
|
|
23780
23962
|
return await warn(`cover: \u5DF2\u63D0\u4EA4\u5C01\u9762\u7684\u7D20\u6750\u8EAB\u4EFD\u4E0E\u6240\u9009\u4E0D\u4E00\u81F4\uFF08selected=${selectedSrc || "\u672A\u8BFB\u5230"} committed=${committed.slice(0, 80)}\uFF09`);
|
|
23781
23963
|
return null;
|
|
23782
23964
|
} catch (error) {
|
|
@@ -23853,10 +24035,10 @@ async function enrichArticleDraft(page, content, stepTimeoutMs) {
|
|
|
23853
24035
|
async function composeArticle(input, deps, entry) {
|
|
23854
24036
|
const page = entry.editor;
|
|
23855
24037
|
const warnings = [];
|
|
24038
|
+
const figures = await inlineFiguresOf(deps.content);
|
|
24039
|
+
if (figures.length > 0)
|
|
24040
|
+
assertInlineFigureMarkers(bodyOf(deps.content), figures);
|
|
23856
24041
|
const titlePath = await typeTitle(page, deps);
|
|
23857
|
-
await insertBody(page, deps);
|
|
23858
|
-
if (input.images.length > 0)
|
|
23859
|
-
await attachImages(page, input.images, deps);
|
|
23860
24042
|
for (const warning of [
|
|
23861
24043
|
await fillOptional(page, DIGEST_INPUT, input.digest ?? "", "\u6458\u8981", deps),
|
|
23862
24044
|
await fillOptional(page, AUTHOR_INPUT, authorOf(deps.content), "\u4F5C\u8005", deps)
|
|
@@ -23864,6 +24046,17 @@ async function composeArticle(input, deps, entry) {
|
|
|
23864
24046
|
if (warning !== null)
|
|
23865
24047
|
warnings.push(warning);
|
|
23866
24048
|
}
|
|
24049
|
+
if (figures.length > 0) {
|
|
24050
|
+
await attachImages(page, figures.map((figure) => figure.path), deps);
|
|
24051
|
+
const srcs = await waitForInlineFigureSrcs(page, figures.length, deps);
|
|
24052
|
+
const body = bodyOf(deps.content);
|
|
24053
|
+
await insertHtmlBody(page, body, markdownToWechatHtml(withInlineFigureHtml(body, figures, srcs)), deps);
|
|
24054
|
+
await verifyInlineFigureDom(page, BODY_BLOCK, figures, srcs);
|
|
24055
|
+
} else {
|
|
24056
|
+
await insertBody(page, deps);
|
|
24057
|
+
}
|
|
24058
|
+
if (input.images.length > 0)
|
|
24059
|
+
await attachImages(page, input.images, deps);
|
|
23867
24060
|
await closeOpenDialogs(page);
|
|
23868
24061
|
const coverSource = coverSourceOf(deps.content);
|
|
23869
24062
|
const audioRuns = audioBlockOf(deps.content) !== null;
|
|
@@ -24083,8 +24276,14 @@ function baseMetadata(input, deps, entry) {
|
|
|
24083
24276
|
...cover === undefined ? {} : { coverPath: cover }
|
|
24084
24277
|
};
|
|
24085
24278
|
}
|
|
24279
|
+
var INCOMPLETE_DRAFT_MARKER = "\u56FE\u6587\u5185\u5BB9\u4E0D\u5B8C\u6574";
|
|
24086
24280
|
async function saveDraft(input, deps, entry, composed) {
|
|
24087
24281
|
const title = titleOf(deps.content);
|
|
24282
|
+
if (input.operation === "\u6587\u7AE0" && bodyOf(deps.content).trim().length > 0) {
|
|
24283
|
+
const bodySelector = await findSelector(entry.editor, BODY_BLOCK, "article body", deps.stepTimeoutMs).catch(() => null);
|
|
24284
|
+
if (bodySelector === null || await bodyLength(entry.editor, bodySelector) === 0)
|
|
24285
|
+
return fail("draft confirmation: article body is empty before \u4FDD\u5B58\u4E3A\u8349\u7A3F \u2014 refusing to save an incomplete draft");
|
|
24286
|
+
}
|
|
24088
24287
|
let control = null;
|
|
24089
24288
|
let signal = null;
|
|
24090
24289
|
let attempts = 0;
|
|
@@ -24122,6 +24321,8 @@ async function saveDraft(input, deps, entry, composed) {
|
|
|
24122
24321
|
return fail(`draft confirmation: a residual modal refused cleanup after ${attempts} attempt(s), ${residuals} refused cleanup(s) (${residualDialogs.join(" | ") || "no inventory"}) \u2014 '\u4FDD\u5B58\u4E3A\u8349\u7A3F' was not clicked through an unresolved overlay (inventory: ${await openDialogInventory(entry.editor)})`);
|
|
24123
24322
|
return fail(`draft confirmation: '${SAVE_DRAFT[0]}' was clicked ${attempts}\xD7 but no fresh \u8349\u7A3F\u7BB1 row for '${title}' (its ${DRAFT_STAMP} stamp) was observed within ${deps.draftTimeoutMs}ms (before=${deps.draftBaseline.stamp ?? "none"}, after=${stampAfter ?? "none"}, page=${deps.entry.url()}, frames=${await describeFrames(deps.entry, 5)})`);
|
|
24124
24323
|
}
|
|
24324
|
+
if (signal.includes(INCOMPLETE_DRAFT_MARKER))
|
|
24325
|
+
return fail(`draft confirmation: \u8349\u7A3F\u7BB1 row for '${title}' reported '${signal.replace(/\s+/g, " ").trim()}' \u2014 refusing to certify an incomplete draft`);
|
|
24125
24326
|
return ResultSchema.parse({
|
|
24126
24327
|
ok: true,
|
|
24127
24328
|
target: TARGET,
|
|
@@ -24162,12 +24363,11 @@ function savedEditorUrlForMetadata(value) {
|
|
|
24162
24363
|
return sanitizeSessionEvidence(value);
|
|
24163
24364
|
}
|
|
24164
24365
|
var PUBLIC_DRAFT_SNAPSHOT_SCRIPT = `/* __KK_WECHAT_PUBLISH_SNAPSHOT__ */ (() => {
|
|
24165
|
-
const norm = (value) => (value ?? '').replace(/[\\s\\u00a0]+/g, ' ').trim();
|
|
24166
24366
|
const titleNode = document.querySelector('textarea#title, textarea.js_title');
|
|
24167
24367
|
const title = titleNode?.value ?? [...document.querySelectorAll('.ProseMirror[data-placeholder*="\u6807\u9898"]')]
|
|
24168
24368
|
.map((node) => node.textContent ?? '').join(' ');
|
|
24169
24369
|
const body = [...document.querySelectorAll('.ProseMirror:not([data-placeholder])')]
|
|
24170
|
-
.map((node) =>
|
|
24370
|
+
.map((node) => (node.textContent ?? '').replace(/[\\s\\u00a0]+/g, ' ').trim()).join('\\n');
|
|
24171
24371
|
const media = [
|
|
24172
24372
|
...document.querySelectorAll(
|
|
24173
24373
|
'.ProseMirror mp-common-mpaudio, .ProseMirror mpvoice, .ProseMirror [data-mediaid], .ProseMirror audio, .ProseMirror video, .ProseMirror img',
|
|
@@ -24175,7 +24375,7 @@ var PUBLIC_DRAFT_SNAPSHOT_SCRIPT = `/* __KK_WECHAT_PUBLISH_SNAPSHOT__ */ (() =>
|
|
|
24175
24375
|
]
|
|
24176
24376
|
.map((node) => node.getAttribute('data-mediaid') ?? node.getAttribute('data-id') ??
|
|
24177
24377
|
node.getAttribute('voice_encode_fileid') ?? node.getAttribute('data-src') ?? node.getAttribute('src') ??
|
|
24178
|
-
|
|
24378
|
+
(node.textContent ?? '').replace(/[\\s\\u00a0]+/g, ' ').trim())
|
|
24179
24379
|
.map(norm).filter((value) => value.length > 0);
|
|
24180
24380
|
const area = document.querySelector('#js_cover_area');
|
|
24181
24381
|
const coverNode = area?.querySelector('.js_cover_preview_new img, img, [style*="background-image"], input[type="hidden"]');
|
|
@@ -24707,7 +24907,7 @@ function markdownToWechatHtml(markdown) {
|
|
|
24707
24907
|
for (const line of lines) {
|
|
24708
24908
|
if (line.startsWith("```")) {
|
|
24709
24909
|
if (inCode) {
|
|
24710
|
-
out.push(`<pre><code>${escapeHtml(code.join(`
|
|
24910
|
+
out.push(`<pre style="overflow-x:auto;max-width:100%;"><code>${escapeHtml(code.join(`
|
|
24711
24911
|
`))}</code></pre>`);
|
|
24712
24912
|
code = [];
|
|
24713
24913
|
inCode = false;
|
|
@@ -24846,6 +25046,18 @@ async function insertAudioMaterial(page, input, timing = {}) {
|
|
|
24846
25046
|
node.getAttribute('data-src') ?? node.getAttribute('src') ?? '';
|
|
24847
25047
|
return JSON.stringify({ state: 'top', identity });
|
|
24848
25048
|
})()`;
|
|
25049
|
+
const dumpAudioStall = async (p) => {
|
|
25050
|
+
const path = join6(tmpdir(), `wechatmp-audio-stall-${Date.now()}.png`);
|
|
25051
|
+
try {
|
|
25052
|
+
if (p.screenshot === undefined)
|
|
25053
|
+
return "(no screenshot seam)";
|
|
25054
|
+
await p.screenshot(path);
|
|
25055
|
+
return path;
|
|
25056
|
+
} catch (error) {
|
|
25057
|
+
return `(screenshot failed: ${error instanceof Error ? error.message : String(error)})`;
|
|
25058
|
+
}
|
|
25059
|
+
};
|
|
25060
|
+
const audioDialogState = async (p) => evalOrFallback(p, `(() => { const d = [...document.querySelectorAll('.weui-desktop-dialog')].find((el) => el.offsetWidth > 0 && el.querySelector('input[name=audio_id]')); if (!d) return '(no audio dialog)'; const id = d.querySelector('input[name=audio_id]'); const btns = [...d.querySelectorAll('button')].map((b) => (b.innerText ?? '').trim()).filter(Boolean); return 'audio_id="' + (id?.value ?? '') + '" buttons=' + JSON.stringify(btns) + ' text=' + ((d.innerText ?? '').replace(/\\s+/g, ' ').slice(0, 120)); })()`, "");
|
|
24849
25061
|
const upload = async () => {
|
|
24850
25062
|
let sawLiveUpload = false;
|
|
24851
25063
|
const failUpload = (warning) => ({ ...result(warning), sawLiveUpload });
|
|
@@ -24872,9 +25084,17 @@ async function insertAudioMaterial(page, input, timing = {}) {
|
|
|
24872
25084
|
});
|
|
24873
25085
|
sawLiveUpload = await isLiveUploadForm();
|
|
24874
25086
|
if (sawLiveUpload) {
|
|
24875
|
-
const
|
|
25087
|
+
const audioName = baseName(audioPath).replace(/\.[^.]+$/, "");
|
|
25088
|
+
const settledUpload = async () => evalOrFallback(page, `(() => { const d = [...document.querySelectorAll('.weui-desktop-dialog')].find((el) => el.offsetWidth > 0 && el.querySelector('input[name=audio_id]')); if (!d) return 'false'; const t = d.innerText ?? ''; return String(t.includes(${JSON.stringify(audioName)}) && /\u5206\u949F/.test(t)); })()`, "false").then((value) => value === "true");
|
|
25089
|
+
const transientUpload = async () => {
|
|
25090
|
+
if (await page.locator(`${uploadDialog} button:has-text("\u91CD\u65B0\u4E0A\u4F20")`).count() === 0)
|
|
25091
|
+
return false;
|
|
25092
|
+
const text = await evalOrFallback(page, `(() => { const d = [...document.querySelectorAll('.weui-desktop-dialog')].find((el) => el.offsetWidth > 0 && el.querySelector('input[name=audio_id]')); return d ? (d.textContent ?? '') : ''; })()`, "");
|
|
25093
|
+
return /100%/.test(text);
|
|
25094
|
+
};
|
|
25095
|
+
const uploaded = await waitUntil(async () => await settledUpload() || await transientUpload(), uploadWaitMs);
|
|
24876
25096
|
if (!uploaded)
|
|
24877
|
-
return failUpload(
|
|
25097
|
+
return failUpload(`\u97F3\u9891: \u97F3\u9891\u6587\u4EF6\u4E0A\u4F20\u672A\u5B8C\u6210\uFF08\u672A\u8FBE\u5230 100%\uFF09\uFF0C\u672A\u4FDD\u5B58\u97F3\u9891 \u2014 shot=${await dumpAudioStall(page)} \u2014 ${await audioDialogState(page)}`);
|
|
24878
25098
|
}
|
|
24879
25099
|
const coverControl = await trySelectors(page, UPLOAD_COVER);
|
|
24880
25100
|
if (coverControl.found) {
|
|
@@ -25219,7 +25439,7 @@ var wechatSessionConfig = {
|
|
|
25219
25439
|
}
|
|
25220
25440
|
};
|
|
25221
25441
|
async function defaultOpenConsole(profileDir) {
|
|
25222
|
-
const { page, context } = await openWithState(profileDir,
|
|
25442
|
+
const { page, context } = await openWithState(profileDir, process.env.WECHATMP_HEADLESS !== "false");
|
|
25223
25443
|
return {
|
|
25224
25444
|
...wrapPlaywrightContext(context, page),
|
|
25225
25445
|
persistSession: () => persistWechatSessionState(context, profileDir)
|
|
@@ -20347,7 +20347,8 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20347
20347
|
}
|
|
20348
20348
|
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`;
|
|
20349
20349
|
}
|
|
20350
|
-
|
|
20350
|
+
const suffix = 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 \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20351
|
+
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20351
20352
|
}
|
|
20352
20353
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20353
20354
|
try {
|
|
@@ -20595,7 +20596,7 @@ function resolveChannelProfileDir(channel, override) {
|
|
|
20595
20596
|
return resolveBrowserProfileDir(channel, chosen);
|
|
20596
20597
|
}
|
|
20597
20598
|
async function checkChannelSession(config, opts) {
|
|
20598
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20599
|
+
const timeoutMs = opts.timeoutMs ?? config.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20599
20600
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20600
20601
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20601
20602
|
const deadline = Date.now() + timeoutMs;
|