@gobing-ai/knowledge-kit 0.1.15 → 0.1.16

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.
Files changed (103) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +1603 -1
  3. package/package.json +1 -1
  4. package/plugins/generations/content-gen/dist/index.js +58 -52
  5. package/plugins/generations/content-gen/src/storm.ts +94 -61
  6. package/plugins/generations/core-facts-gen/dist/index.js +1 -1
  7. package/plugins/generations/daily-article-gen/dist/index.js +1 -1
  8. package/plugins/generations/dailynews-gen/dist/index.js +1 -1
  9. package/plugins/generations/episode-plan-gen/dist/index.js +1 -1
  10. package/plugins/generations/gemini-tts/dist/index.js +1 -1
  11. package/plugins/generations/image-gen/README.md +31 -10
  12. package/plugins/generations/image-gen/assets/sample/cover__quasi-news-podcast.jpg +0 -0
  13. package/plugins/generations/image-gen/assets/sample/daily-news-cover__quasi-news-podcast.jpg +0 -0
  14. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__clean-webapp-ui.jpg +0 -0
  15. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__cute.jpg +0 -0
  16. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__daily-news.jpg +0 -0
  17. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__editorial.jpg +0 -0
  18. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__fresh.jpg +0 -0
  19. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__minimalist.jpg +0 -0
  20. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__photorealistic.jpg +0 -0
  21. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__quasi-news-podcast.jpg +0 -0
  22. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__sketch.jpg +0 -0
  23. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__technical-diagram.jpg +0 -0
  24. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__vibrant.jpg +0 -0
  25. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__warm.jpg +0 -0
  26. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__xhs-knowledge.jpg +0 -0
  27. package/plugins/generations/image-gen/assets/sample/free__quasi-news-podcast.jpg +0 -0
  28. package/plugins/generations/image-gen/assets/sample/illustration__quasi-news-podcast.jpg +0 -0
  29. package/plugins/generations/image-gen/assets/sample/xhs-card__quasi-news-podcast.jpg +0 -0
  30. package/plugins/generations/image-gen/dist/index.js +1 -1
  31. package/plugins/generations/image-gen/presets/formats/daily-news-podcast-cover.yaml +18 -0
  32. package/plugins/generations/image-gen/presets/styles/quasi-news-podcast.yaml +9 -0
  33. package/plugins/generations/news-report-gen/dist/index.js +1 -1
  34. package/plugins/generations/voice-gen/dist/index.js +1 -1
  35. package/plugins/generations/voxcpm-tts/dist/index.js +1 -1
  36. package/plugins/ingestions/aihot-ingest/dist/index.js +1 -1
  37. package/plugins/ingestions/horizon-ingest/dist/index.js +1 -1
  38. package/plugins/ingestions/last30days-ingest/dist/index.js +1 -1
  39. package/plugins/ingestions/web-search/dist/index.js +1 -1
  40. package/plugins/kk/plugin.json +1 -1
  41. package/plugins/kk/publish-presets/daily-ai-voice-migration.json +12 -3
  42. package/plugins/kk/publish-presets/daily-ai-voice.json +11 -3
  43. package/plugins/kk/scripts/cover-compositor.ts +152 -0
  44. package/plugins/kk/scripts/daily-cover-mock.ts +164 -0
  45. package/plugins/kk/scripts/daily-scheduled-run.ts +188 -3
  46. package/plugins/kk/scripts/daily-stages.ts +134 -26
  47. package/plugins/kk/scripts/daily-triage-core.ts +451 -0
  48. package/plugins/kk/scripts/daily-triage.ts +74 -0
  49. package/plugins/kk/scripts/kk-workflow-stages.ts +31 -2
  50. package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +16 -10
  51. package/plugins/kk/skills/news-editorial/SKILL.md +3 -3
  52. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +2 -1
  53. package/plugins/kk/skills/publish/SKILL.md +1 -1
  54. package/plugins/kk/skills/wiki-authoring/SKILL.md +53 -0
  55. package/plugins/kk/skills/wiki-authoring/references/page-shapes.md +44 -0
  56. package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +3 -3
  57. package/plugins/kk/workflows/kk-daily-safety.yaml +32 -7
  58. package/plugins/publishings/bilibili-pub/dist/index.js +1 -1
  59. package/plugins/publishings/cnblogs-pub/dist/index.js +1 -1
  60. package/plugins/publishings/csdn-pub/dist/index.js +1 -1
  61. package/plugins/publishings/csdn-pub/dist/profile-check.js +1 -1
  62. package/plugins/publishings/emdash-pub/dist/index.js +1 -1
  63. package/plugins/publishings/infoq-pub/dist/index.js +1 -1
  64. package/plugins/publishings/infoq-pub/dist/profile-check.js +1 -1
  65. package/plugins/publishings/jike-pub/dist/index.js +1 -1
  66. package/plugins/publishings/jike-pub/dist/profile-check.js +1 -1
  67. package/plugins/publishings/juejin-pub/dist/index.js +1 -1
  68. package/plugins/publishings/juejin-pub/dist/profile-check.js +1 -1
  69. package/plugins/publishings/linkedin-pub/dist/index.js +1 -1
  70. package/plugins/publishings/linkedin-pub/dist/profile-check.js +1 -1
  71. package/plugins/publishings/medium-pub/dist/index.js +1 -1
  72. package/plugins/publishings/podcast-pub/dist/index.js +1 -1
  73. package/plugins/publishings/qiita-pub/dist/index.js +1 -1
  74. package/plugins/publishings/shipinhao-pub/dist/index.js +222 -50
  75. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +48 -1
  76. package/plugins/publishings/shipinhao-pub/plugin.json +2 -2
  77. package/plugins/publishings/shipinhao-pub/src/flow.ts +335 -79
  78. package/plugins/publishings/shipinhao-pub/src/index.ts +16 -8
  79. package/plugins/publishings/shipinhao-pub/src/profile-check.ts +1 -1
  80. package/plugins/publishings/shipinhao-pub/src/selectors.ts +103 -5
  81. package/plugins/publishings/sspai-pub/dist/index.js +1 -1
  82. package/plugins/publishings/substack-pub/dist/index.js +1 -1
  83. package/plugins/publishings/substack-pub/dist/profile-check.js +1 -1
  84. package/plugins/publishings/surfdash-pub/dist/index.js +235 -12
  85. package/plugins/publishings/surfdash-pub/src/index.ts +127 -6
  86. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +189 -0
  87. package/plugins/publishings/threads-pub/dist/index.js +1 -1
  88. package/plugins/publishings/wechatmp-pub/dist/index.js +10 -7
  89. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +1 -1
  90. package/plugins/publishings/wechatmp-pub/src/enrich.ts +10 -3
  91. package/plugins/publishings/wechatmp-pub/src/flow.ts +3 -4
  92. package/plugins/publishings/wechatmp-pub/src/page.ts +14 -0
  93. package/plugins/publishings/weibo-pub/dist/index.js +1 -1
  94. package/plugins/publishings/weibo-pub/dist/profile-check.js +1 -1
  95. package/plugins/publishings/x-pub/dist/index.js +1 -1
  96. package/plugins/publishings/x-pub/dist/profile-check.js +1 -1
  97. package/plugins/publishings/xhs-pub/dist/index.js +557 -31
  98. package/plugins/publishings/xhs-pub/dist/profile-check.js +20 -1
  99. package/plugins/publishings/xhs-pub/src/errors.ts +45 -0
  100. package/plugins/publishings/xhs-pub/src/flow.ts +773 -45
  101. package/plugins/publishings/xhs-pub/src/page.ts +33 -0
  102. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +1 -1
  103. package/plugins/publishings/zenn-pub/dist/index.js +1 -1
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
19905
19905
  shortVideo: Object.freeze({
19906
19906
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19907
19907
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19908
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
19908
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
19909
19909
  })
19910
19910
  })
19911
19911
  });
@@ -21083,6 +21083,39 @@ function createAutomationGuard(options) {
21083
21083
  };
21084
21084
  }
21085
21085
 
21086
+ // ../../plugins/publishings/xhs-pub/src/errors.ts
21087
+ class PublishError extends Error {
21088
+ name;
21089
+ constructor(message, name = "PublishError") {
21090
+ super(message);
21091
+ this.name = name;
21092
+ }
21093
+ }
21094
+
21095
+ class AccountRiskControlError extends PublishError {
21096
+ constructor(message) {
21097
+ super(message, "AccountRiskControlError");
21098
+ }
21099
+ }
21100
+
21101
+ class TitleTooLongError extends PublishError {
21102
+ constructor(message) {
21103
+ super(message, "TitleTooLongError");
21104
+ }
21105
+ }
21106
+
21107
+ class ContentTooLongError extends PublishError {
21108
+ constructor(message) {
21109
+ super(message, "ContentTooLongError");
21110
+ }
21111
+ }
21112
+
21113
+ class DraftVerifyError extends PublishError {
21114
+ constructor(message) {
21115
+ super(message, "DraftVerifyError");
21116
+ }
21117
+ }
21118
+
21086
21119
  // ../../plugins/publishings/xhs-pub/src/modes.ts
21087
21120
  import { isAbsolute as isAbsolute2 } from "path";
21088
21121
  var TARGET = "xhs";
@@ -21370,6 +21403,25 @@ function wrapPlaywrightPage(raw, shadow) {
21370
21403
  }
21371
21404
  return pw.waitForEvent(event, options);
21372
21405
  },
21406
+ on: (event, handler) => {
21407
+ const raw2 = raw;
21408
+ raw2.on?.(event, handler);
21409
+ },
21410
+ off: (event, handler) => {
21411
+ const raw2 = raw;
21412
+ raw2.off?.(event, handler);
21413
+ },
21414
+ onContextResponse: (handler) => {
21415
+ const raw2 = raw;
21416
+ const ctx = raw2.context?.();
21417
+ ctx?.on?.("response", handler);
21418
+ },
21419
+ offContextResponse: (handler) => {
21420
+ const raw2 = raw;
21421
+ const ctx = raw2.context?.();
21422
+ ctx?.off?.("response", handler);
21423
+ },
21424
+ boundingBoxesOnScreen: (selector) => onScreen(selector).then((found) => found.map((entry) => entry.box)),
21373
21425
  mouse: {
21374
21426
  click: (x, y) => pw.mouse.click(x, y)
21375
21427
  }
@@ -21411,13 +21463,11 @@ var NOTE_BODY = [
21411
21463
  ".ql-editor"
21412
21464
  ];
21413
21465
  var NOTE_THUMBNAIL = ["img.preivew-image", ".img-preview img"];
21414
- var IMAGE_FILE_INPUT = [
21415
- 'input[type="file"][accept*=".jpg"]',
21416
- 'input[type="file"].upload-input',
21417
- 'input[type="file"]'
21418
- ];
21419
21466
  var VIDEO_FILE_INPUT = ['input[type="file"][accept*=".mp4"]', 'input[type="file"].upload-input'];
21420
21467
  var VIDEO_EDITOR = ["div.tiptap.ProseMirror", 'div.tiptap[contenteditable="true"]', ".ProseMirror"];
21468
+ var IMAGE_MODE_SETTLE_MS = 1500;
21469
+ var CONSOLE_SETTLE_MS = 9000;
21470
+ var CONSOLE_SETTLE_QUIET_MS = 2000;
21421
21471
  var ARTICLE_NEW = ["text=\u65B0\u7684\u521B\u4F5C", 'button:has-text("\u65B0\u7684\u521B\u4F5C")'];
21422
21472
  var ARTICLE_EDITOR = ["div.tiptap.ProseMirror.ProseMirror-focused", "div.tiptap.ProseMirror", ".ProseMirror"];
21423
21473
  var ARTICLE_LAYOUT = ['button:has-text("\u4E00\u952E\u6392\u7248")', "div.ailayout-btn_wrp", "div.ailayout-btn_label"];
@@ -21427,6 +21477,9 @@ var PODCAST_AUDIO_INPUT = ['input[type="file"][accept*=".mp3"]', 'input[type="fi
21427
21477
  var PODCAST_MODAL_ADVANCE = ["\u53BB\u53D1\u5E03"];
21428
21478
  var PODCAST_COVER_ZONE = '.d-modal div:has-text("\u8BBE\u7F6E\u5C01\u9762")';
21429
21479
  var PODCAST_UPLOAD_ACK = "\u4E0A\u4F20\u6210\u529F";
21480
+ var PODCAST_TITLE_SELECTORS = ["input.d-text", 'input[placeholder*="\u6807\u9898"]', 'textarea[placeholder*="\u6807\u9898"]'];
21481
+ var PODCAST_COLLECTION_SELECTORS = ['button:has-text("\u52A0\u5165\u64AD\u5BA2\u5408\u96C6")', "text=\u52A0\u5165\u64AD\u5BA2\u5408\u96C6", "text=\u5408\u96C6"];
21482
+ var PODCAST_COLLECTION_DEFAULT = "\u54B8\u8BDD\u54B8\u8BF4\u4E4B\u6BCF\u65E5AI\u4E71\u7096";
21430
21483
  var DRAFT_LABELS = ["\u6682\u5B58\u79BB\u5F00", "\u5B58\u8349\u7A3F", "\u4FDD\u5B58\u8349\u7A3F"];
21431
21484
  var PUBLISH_LABELS = ["\u53D1\u5E03"];
21432
21485
  var PUBLISH_CONFIRM = ["\u53D1\u5E03\u6210\u529F", "\u5DF2\u53D1\u5E03"];
@@ -21479,6 +21532,157 @@ async function clickLightControl(page, labels, timeoutMs, what) {
21479
21532
  await page.locator(selector).first().click({ timeout: timeoutMs });
21480
21533
  return { ok: true, label: label ?? "", selector };
21481
21534
  }
21535
+ async function invokeHostSave(page) {
21536
+ try {
21537
+ const verdict = await page.evaluate(`(() => {
21538
+ const hosts = Array.from(document.querySelectorAll('xhs-publish-btn')).filter((el) => {
21539
+ const r = el.getBoundingClientRect();
21540
+ return r.width > 0 && r.height > 0;
21541
+ });
21542
+ for (const el of hosts) {
21543
+ for (const name of ['_onSave', '_onSaveDraft', '_onDraft']) {
21544
+ const fn = el[name];
21545
+ if (typeof fn === 'function') { fn.call(el); return 'kk-host-save:' + name; }
21546
+ }
21547
+ }
21548
+ return 'kk-host-save-none';
21549
+ })()`);
21550
+ const called = typeof verdict === "string" ? verdict : "";
21551
+ return called.startsWith("kk-host-save:") ? called.slice("kk-host-save:".length) : null;
21552
+ } catch {
21553
+ return null;
21554
+ }
21555
+ }
21556
+ var CAPTURE_INJECT_EXPR = `/* kk-capture-inject */ (() => {
21557
+ const w = window;
21558
+ if (w.__kkXhsArmed) return 'kk-capture-armed';
21559
+ w.__kkXhsArmed = true;
21560
+ w.__kkXhsOutcome = null;
21561
+ const signatures = [
21562
+ /HTTPBizError/,
21563
+ /"code"\\s*:\\s*-913\\d/,
21564
+ /\u7981\u6B62\u53D1\u7B14\u8BB0/,
21565
+ /note_id/,
21566
+ /\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/,
21567
+ ];
21568
+ const matches = (text) => signatures.some((re) => re.test(text));
21569
+ const record = (source, text) => {
21570
+ if (w.__kkXhsOutcome) return;
21571
+ const asString = String(text || '');
21572
+ if (!asString || !matches(asString)) return;
21573
+ w.__kkXhsOutcome = { source: source, text: asString.slice(0, 800) };
21574
+ };
21575
+ const proto = XMLHttpRequest.prototype;
21576
+ if (!proto.__kkPatched) {
21577
+ proto.__kkPatched = true;
21578
+ const open = proto.open;
21579
+ const send = proto.send;
21580
+ proto.open = function (method, url) { this.__kkUrl = url; return open.apply(this, arguments); };
21581
+ proto.send = function () {
21582
+ this.addEventListener('loadend', () => {
21583
+ try { record('xhr', (this.__kkUrl || '') + ' ' + this.responseText); } catch (e) {}
21584
+ });
21585
+ return send.apply(this, arguments);
21586
+ };
21587
+ }
21588
+ if (typeof w.fetch === 'function' && !w.fetch.__kkPatched) {
21589
+ const original = w.fetch;
21590
+ w.fetch = function () {
21591
+ return original.apply(this, arguments).then((response) => {
21592
+ try {
21593
+ response.clone().text().then((text) => record('fetch', (response.url || '') + ' ' + text)).catch(() => {});
21594
+ } catch (e) {}
21595
+ return response;
21596
+ });
21597
+ };
21598
+ w.fetch.__kkPatched = true;
21599
+ }
21600
+ if (!console.__kkPatched) {
21601
+ console.__kkPatched = true;
21602
+ for (const key of ['error', 'warn', 'log']) {
21603
+ const original = console[key].bind(console);
21604
+ console[key] = function () {
21605
+ try { record('console', Array.prototype.map.call(arguments, String).join(' ')); } catch (e) {}
21606
+ original.apply(console, arguments);
21607
+ };
21608
+ }
21609
+ }
21610
+ if (typeof MutationObserver === 'function' && document.body && !w.__kkXhsToastObs) {
21611
+ const toastRisk = /\u8FDD\u53CD|\u8FDD\u89C4|\u7981\u6B62\u53D1\u7B14\u8BB0|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/;
21612
+ const obs = new MutationObserver((muts) => {
21613
+ if (w.__kkXhsOutcome) return;
21614
+ for (const m of muts) {
21615
+ for (const n of m.addedNodes || []) {
21616
+ if (!n || n.nodeType !== 1) continue;
21617
+ const txt = String(n.textContent || '').trim();
21618
+ if (txt.length === 0 || txt.length > 300) continue;
21619
+ if (!toastRisk.test(txt)) continue;
21620
+ record('toast', txt);
21621
+ }
21622
+ }
21623
+ });
21624
+ obs.observe(document.body, { childList: true, subtree: true });
21625
+ w.__kkXhsToastObs = true;
21626
+ }
21627
+ return 'kk-capture-armed';
21628
+ })()`;
21629
+ var CAPTURE_READ_EXPR = `/* kk-capture-read */ (() => {
21630
+ const captured = window.__kkXhsOutcome;
21631
+ return captured ? JSON.stringify(captured) : 'kk-capture-none';
21632
+ })()`;
21633
+ async function armOutcomeCapture(page) {
21634
+ try {
21635
+ await page.evaluate(CAPTURE_INJECT_EXPR);
21636
+ } catch {}
21637
+ }
21638
+ async function readOutcomeCapture(page) {
21639
+ try {
21640
+ const read = await page.evaluate(CAPTURE_READ_EXPR);
21641
+ if (typeof read !== "string" || !read.startsWith("{"))
21642
+ return null;
21643
+ const parsed = JSON.parse(read);
21644
+ return typeof parsed.source === "string" && typeof parsed.text === "string" ? { source: parsed.source, text: parsed.text } : null;
21645
+ } catch {
21646
+ return null;
21647
+ }
21648
+ }
21649
+ var RISK_SIGNATURE = /\u7981\u6B62\u53D1\u7B14\u8BB0|\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/;
21650
+ var CODE_SIGNATURE = /"code"\s*:\s*(-?\d+)/;
21651
+ var NOTE_ID_SIGNATURE = /"note_id"\s*:\s*"([^"]+)"/;
21652
+ function classifyOutcome(text) {
21653
+ const code = CODE_SIGNATURE.exec(text)?.[1] ?? null;
21654
+ const noteId = NOTE_ID_SIGNATURE.exec(text)?.[1] ?? null;
21655
+ if (code !== null && /^-913\d$/.test(code) || RISK_SIGNATURE.test(text)) {
21656
+ return { verdict: "risk", code, noteId };
21657
+ }
21658
+ if (noteId !== null && (code === null || code === "0"))
21659
+ return { verdict: "ok", code, noteId };
21660
+ return { verdict: "biz", code, noteId };
21661
+ }
21662
+ function assertCapturedOutcome(capture) {
21663
+ if (capture === null)
21664
+ return;
21665
+ const { verdict, code } = classifyOutcome(capture.text);
21666
+ if (verdict === "risk") {
21667
+ throw new AccountRiskControlError(`AccountRiskControlError: the ${capture.source} response matched risk-control signatures (code ${code ?? "unknown"}, matched: ${RISK_SIGNATURE.exec(capture.text)?.[0] ?? "-913x code"}) \u2014 the account is restricted from posting on ${TARGET}; not retryable`);
21668
+ }
21669
+ if (verdict === "biz") {
21670
+ throw new PublishError(`PublishError: the ${capture.source} response reported a platform error (code ${code ?? "unknown"}): ${capture.text.slice(0, 200)}`);
21671
+ }
21672
+ }
21673
+ function captureMetadata(capture) {
21674
+ if (capture === null)
21675
+ return {};
21676
+ const { verdict, code, noteId } = classifyOutcome(capture.text);
21677
+ return {
21678
+ serverCapture: {
21679
+ source: capture.source,
21680
+ verdict,
21681
+ ...code !== null ? { code } : {},
21682
+ ...noteId !== null ? { noteId } : {}
21683
+ }
21684
+ };
21685
+ }
21482
21686
  async function clickActionControl(operation, deps, labels, what) {
21483
21687
  let lastError = "";
21484
21688
  for (const path of MODE_ACTION_PATHS[operation]) {
@@ -21550,33 +21754,155 @@ async function draftSignalEvidence(page, baseline) {
21550
21754
  async function applyNoteTitle(deps) {
21551
21755
  const selector = await findSelector(deps.page, NOTE_TITLE, "title input", deps.stepTimeoutMs);
21552
21756
  await deps.page.locator(selector).first().fill(deps.content.title ?? "");
21757
+ await assertPlatformCounter(deps.page, TITLE_COUNTER_EXPR, XHS_NOTE_TITLE_MAX, "title");
21553
21758
  }
21554
- async function typeNoteBody(deps, selectors, what) {
21759
+ async function typeNoteBody(deps, selectors, what, text) {
21555
21760
  const selector = await findSelector(deps.page, selectors, what, deps.stepTimeoutMs);
21556
21761
  const body = deps.page.locator(selector).first();
21557
- const text = deps.content.body ?? "";
21762
+ const value = text ?? deps.content.body ?? "";
21558
21763
  if (typeof body.type === "function") {
21559
21764
  await body.click();
21560
- await body.type(text, { delay: 5 });
21561
- return;
21765
+ await body.type(value, { delay: 5 });
21766
+ } else {
21767
+ await body.fill(value);
21768
+ }
21769
+ await assertPlatformCounter(deps.page, BODY_COUNTER_EXPR, XHS_NOTE_BODY_MAX, "body");
21770
+ }
21771
+ var TITLE_COUNTER_EXPR = `/* kk-counter-title */ (() => {
21772
+ const el = document.querySelector('div.title-container div.max_suffix');
21773
+ if (el && el.textContent && el.textContent.trim()) return el.textContent.trim();
21774
+ for (const node of document.querySelectorAll('div.title-container *')) {
21775
+ const t = (node.textContent || '').trim();
21776
+ if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return t;
21777
+ }
21778
+ return 'kk-counter-none';
21779
+ })()`;
21780
+ var BODY_COUNTER_EXPR = `/* kk-counter-body */ (() => {
21781
+ const err = document.querySelector('div.edit-container div.length-error');
21782
+ if (err && err.textContent && err.textContent.trim()) return err.textContent.trim();
21783
+ for (const node of document.querySelectorAll('div.edit-container *')) {
21784
+ const t = (node.textContent || '').trim();
21785
+ if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return t;
21786
+ }
21787
+ return 'kk-counter-none';
21788
+ })()`;
21789
+ function counterUnits(counter) {
21790
+ const current = Number.parseInt(counter.split("/")[0] ?? "", 10);
21791
+ return Number.isFinite(current) ? current : null;
21792
+ }
21793
+ async function readPlatformCounter(page, expression) {
21794
+ try {
21795
+ const read = await page.evaluate(expression);
21796
+ if (typeof read !== "string" || read.includes("kk-counter-none"))
21797
+ return null;
21798
+ return read.trim();
21799
+ } catch {
21800
+ return null;
21562
21801
  }
21563
- await body.fill(text);
21564
21802
  }
21565
- async function confirmThumbnails(deps, expected) {
21803
+ async function assertPlatformCounter(page, expression, max, what) {
21804
+ const counter = await readPlatformCounter(page, expression);
21805
+ if (counter === null)
21806
+ return;
21807
+ const units = counterUnits(counter);
21808
+ if (units === null || units <= max)
21809
+ return;
21810
+ const message = `the ${what} counter reads '${counter}' \u2014 ${units} units over the platform limit of ${max}; shorten the ${what} before saving (xhs counts units: 2 half-width chars = 1 unit)`;
21811
+ throw what === "title" ? new TitleTooLongError(`TitleTooLongError: ${message}`) : new ContentTooLongError(`ContentTooLongError: ${message}`);
21812
+ }
21813
+ function trackSpectrumUploads(page) {
21814
+ let count = 0;
21815
+ let anySeen = 0;
21816
+ const handler = (payload) => {
21817
+ anySeen += 1;
21818
+ const response = payload;
21819
+ if (response.status() === 200 && /ros-upload\.xiaohongshu\.com\/spectrum\//.test(response.url())) {
21820
+ count += 1;
21821
+ }
21822
+ };
21823
+ page.onContextResponse?.(handler);
21824
+ return {
21825
+ completions: async () => count,
21826
+ seen: () => anySeen,
21827
+ dispose: () => page.offContextResponse?.(handler)
21828
+ };
21829
+ }
21830
+ async function confirmThumbnails(deps, expected, uploads) {
21566
21831
  const selector = await findSelector(deps.page, NOTE_THUMBNAIL, "thumbnail wait", deps.stepTimeoutMs);
21567
- const matches = await waitUntil(() => deps.page.locator(selector).count().then((count) => count >= expected), deps.stepTimeoutMs);
21832
+ const allDurable = async () => {
21833
+ const verdict = await deps.page.evaluate(`(() => {
21834
+ const imgs = Array.from(document.querySelectorAll("${selector}"));
21835
+ if (imgs.length < ${expected}) return 'kk-thumb-pending';
21836
+ return imgs.every((img) => /^https?:/.test(img.getAttribute("src") || ""))
21837
+ ? 'kk-thumb-all-durable'
21838
+ : 'kk-thumb-pending';
21839
+ })()`);
21840
+ if (verdict === "kk-thumb-all-durable")
21841
+ return true;
21842
+ return await uploads.completions() >= expected;
21843
+ };
21844
+ const matches = await waitUntil(allDurable, deps.stepTimeoutMs);
21568
21845
  const observed = await deps.page.locator(selector).count();
21569
21846
  if (!matches || observed !== expected) {
21570
- throw new Error(`thumbnail count: expected ${expected}, observed ${observed}`);
21847
+ const pending = await deps.page.evaluate(`/* kk-count-local-srcs */ (() => {
21848
+ return Array.from(document.querySelectorAll("${selector}"))
21849
+ .filter((img) => !/^https?:/.test(img.getAttribute("src") || "")).length;
21850
+ })()`);
21851
+ throw new Error(`thumbnail count: expected ${expected} durable previews, observed ${observed} previews with ${String(pending)} still on a local (blob/data) src, wire completions ${await uploads.completions()} [flow-20261110b] \u2014 the ${deps.stepTimeoutMs}ms window expired before the console finished uploading`);
21852
+ }
21853
+ return { completions: await uploads.completions() };
21854
+ }
21855
+ async function enterImageMode(deps, label) {
21856
+ if (!deps.page.clickAt || !deps.page.boundingBoxesOnScreen) {
21857
+ throw new Error("mode entry (image): this driver cannot read viewport boxes or click coordinates");
21858
+ }
21859
+ await settleConsole(deps);
21860
+ const selector = `text=${label}`;
21861
+ const deadline = Date.now() + deps.stepTimeoutMs;
21862
+ while (Date.now() < deadline) {
21863
+ const boxes = await deps.page.boundingBoxesOnScreen(selector).catch(() => []);
21864
+ const box = boxes[0];
21865
+ if (box) {
21866
+ await deps.page.clickAt(box.x + box.width / 2, box.y + box.height / 2);
21867
+ await findSelector(deps.page, ["text=\u4E0A\u4F20\u56FE\u7247\uFF0C\u6216\u5199\u6587\u5B57\u751F\u6210\u56FE\u7247"], "image editor settle", deps.stepTimeoutMs);
21868
+ await new Promise((resolve) => setTimeout(resolve, IMAGE_MODE_SETTLE_MS));
21869
+ return;
21870
+ }
21871
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
21872
+ }
21873
+ throw new Error(`mode entry: no on-screen '${label}' tab found within ${deps.stepTimeoutMs}ms \u2014 the mode was not entered`);
21874
+ }
21875
+ async function settleConsole(deps) {
21876
+ let lastResponseAt = Date.now();
21877
+ deps.page.onContextResponse?.(() => {
21878
+ lastResponseAt = Date.now();
21879
+ });
21880
+ try {
21881
+ const start = Date.now();
21882
+ while (Date.now() - start < CONSOLE_SETTLE_MS) {
21883
+ if (Date.now() - lastResponseAt >= CONSOLE_SETTLE_QUIET_MS)
21884
+ return;
21885
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
21886
+ }
21887
+ } finally {
21888
+ deps.page.offContextResponse?.(() => {
21889
+ lastResponseAt = Date.now();
21890
+ });
21571
21891
  }
21572
21892
  }
21573
21893
  async function composeImageText(input, deps) {
21574
- await enterMode(deps, input.operation);
21575
- const fileSelector = await findAttachedSelector(deps.page, IMAGE_FILE_INPUT, "image file input", deps.stepTimeoutMs);
21576
- await deps.page.setInputFiles(fileSelector, input.images);
21577
- await confirmThumbnails(deps, input.images.length);
21578
- await applyNoteTitle(deps);
21579
- await typeNoteBody(deps, NOTE_BODY, "note body");
21894
+ await enterImageMode(deps, input.operation);
21895
+ const fileSelector = await findAttachedSelector(deps.page, ['input[type="file"]'], "image file input", deps.stepTimeoutMs);
21896
+ const uploads = trackSpectrumUploads(deps.page);
21897
+ try {
21898
+ await deps.page.setInputFiles(fileSelector, input.images);
21899
+ const confirmed = await confirmThumbnails(deps, input.images.length, uploads);
21900
+ await applyNoteTitle(deps);
21901
+ await typeNoteBody(deps, NOTE_BODY, "note body");
21902
+ return confirmed.completions;
21903
+ } finally {
21904
+ uploads.dispose();
21905
+ }
21580
21906
  }
21581
21907
  async function composeVideo(input, deps) {
21582
21908
  await enterMode(deps, input.operation);
@@ -21684,6 +22010,50 @@ async function composePodcast(input, deps) {
21684
22010
  await uploadPodcastCover(deps, input.cover);
21685
22011
  await podcastAdvanceReady(deps);
21686
22012
  await leavePodcastModal(deps);
22013
+ await applyPodcastFields(deps);
22014
+ }
22015
+ function podcastCollection(content) {
22016
+ const declared = content.metadata?.collection;
22017
+ return typeof declared === "string" && declared.trim().length > 0 ? declared.trim() : PODCAST_COLLECTION_DEFAULT;
22018
+ }
22019
+ function clipLine(text, cap) {
22020
+ return text.length > cap ? `${text.slice(0, cap - 1)}\u2026` : text;
22021
+ }
22022
+ function derivePodcastBody(content, max = XHS_NOTE_BODY_MAX) {
22023
+ const lines = (content.body ?? "").split(`
22024
+ `).map((line) => line.trim()).filter((line) => line.length > 0);
22025
+ const prose = lines.filter((line) => !line.startsWith("#"));
22026
+ const introSource = prose[0] ?? content.title ?? "";
22027
+ const intro = clipLine(introSource, 80);
22028
+ const closing = prose.length > 1 ? clipLine(prose[prose.length - 1] ?? "", 60) : "";
22029
+ const budget = max - (closing.length > 0 ? closing.length + 1 : 0);
22030
+ const parts = [intro];
22031
+ let used = intro.length;
22032
+ for (const line of lines.filter((line) => line.startsWith("## "))) {
22033
+ const bullet = `\xB7 ${line.slice(3).trim()}`;
22034
+ if (used + bullet.length + 1 > budget)
22035
+ break;
22036
+ parts.push(bullet);
22037
+ used += bullet.length + 1;
22038
+ }
22039
+ if (closing.length > 0)
22040
+ parts.push(closing);
22041
+ return parts.join(`
22042
+ `).slice(0, max);
22043
+ }
22044
+ async function applyPodcastFields(deps) {
22045
+ const title = deps.content.title ?? "";
22046
+ if (title.length > 0) {
22047
+ const selector = await findSelector(deps.page, PODCAST_TITLE_SELECTORS, "podcast title input", deps.stepTimeoutMs);
22048
+ await deps.page.locator(selector).first().fill(title);
22049
+ }
22050
+ await assertPlatformCounter(deps.page, TITLE_COUNTER_EXPR, XHS_NOTE_TITLE_MAX, "title");
22051
+ const body = derivePodcastBody(deps.content, XHS_NOTE_BODY_MAX);
22052
+ await typeNoteBody(deps, NOTE_BODY, "podcast body", body);
22053
+ const collection = podcastCollection(deps.content);
22054
+ const chip = await findSelector(deps.page, PODCAST_COLLECTION_SELECTORS, "\u52A0\u5165\u64AD\u5BA2\u5408\u96C6 control", deps.stepTimeoutMs);
22055
+ await deps.page.locator(chip).first().click({ timeout: deps.stepTimeoutMs });
22056
+ await deps.page.locator(`text=${collection}`).first().click({ timeout: deps.stepTimeoutMs });
21687
22057
  }
21688
22058
  async function uploadPodcastCover(deps, cover) {
21689
22059
  const zone = deps.page.locator(PODCAST_COVER_ZONE).first();
@@ -21770,17 +22140,16 @@ async function podcastAdvanceReady(deps) {
21770
22140
  async function compose(input, deps) {
21771
22141
  switch (input.operation) {
21772
22142
  case "\u4E0A\u4F20\u56FE\u6587":
21773
- await composeImageText(input, deps);
21774
- return;
22143
+ return { wireCompletions: await composeImageText(input, deps) };
21775
22144
  case "\u4E0A\u4F20\u89C6\u9891":
21776
22145
  await composeVideo(input, deps);
21777
- return;
22146
+ return {};
21778
22147
  case "\u5199\u957F\u6587":
21779
22148
  await composeArticle(deps);
21780
- return;
22149
+ return {};
21781
22150
  case "\u53D1\u64AD\u5BA2":
21782
22151
  await composePodcast(input, deps);
21783
- return;
22152
+ return {};
21784
22153
  }
21785
22154
  }
21786
22155
  function baseMetadata(input, deps) {
@@ -21797,21 +22166,35 @@ async function saveDraft(input, deps) {
21797
22166
  let clicked = null;
21798
22167
  let signal = null;
21799
22168
  let attempts = 0;
22169
+ let capture = null;
22170
+ await armOutcomeCapture(deps.page);
21800
22171
  while (signal === null && attempts < deps.submitAttempts) {
21801
22172
  attempts += 1;
21802
22173
  await sleep2(deps.submitSettleMs);
21803
- const control = await clickActionControl(input.operation, deps, DRAFT_LABELS, "draft control");
22174
+ const method = await invokeHostSave(deps.page);
22175
+ const control = method !== null ? { ok: true, path: "shadow", label: `_onSave:${method}`, click: "shadow-host-method" } : await clickActionControl(input.operation, deps, DRAFT_LABELS, "draft control");
21804
22176
  if (!control.ok)
21805
22177
  return fail(control.error);
21806
22178
  clicked = control;
21807
- const outcome = await expectOutcome(() => draftSignalEvidence(deps.page, deps.draftBaseline), {
22179
+ const outcome = await expectOutcome(async () => {
22180
+ if (capture === null)
22181
+ capture = await readOutcomeCapture(deps.page);
22182
+ return draftSignalEvidence(deps.page, deps.draftBaseline);
22183
+ }, {
21808
22184
  timeoutMs: deps.submitSettleMs,
21809
22185
  label: `draft confirmation '${control.label}'`,
21810
22186
  pollMs: POLL_MS
21811
22187
  });
21812
22188
  if (outcome.ok)
21813
22189
  signal = outcome.evidence;
22190
+ else {
22191
+ capture = capture ?? await readOutcomeCapture(deps.page);
22192
+ assertCapturedOutcome(capture);
22193
+ }
21814
22194
  }
22195
+ if (capture === null)
22196
+ capture = await readOutcomeCapture(deps.page);
22197
+ assertCapturedOutcome(capture);
21815
22198
  const draftCountAfter = await readDraftCount(deps.page);
21816
22199
  if (signal === null || clicked === null) {
21817
22200
  return fail(`draft confirmation: '${clicked?.label ?? DRAFT_LABELS[0]}' was clicked ${attempts}\xD7 but neither a fresh ${TARGET} save timestamp, a moved draft counter, nor a scoped '${DRAFT_TOASTS[0]}' toast was observed within ${deps.submitSettleMs}ms (before=${String(deps.draftBaseline.count)}, after=${String(draftCountAfter)})`);
@@ -21828,22 +22211,30 @@ async function saveDraft(input, deps) {
21828
22211
  draftAttempts: attempts,
21829
22212
  draftSignal: signal,
21830
22213
  draftCountBefore: deps.draftBaseline.count,
21831
- draftCountAfter
22214
+ draftCountAfter,
22215
+ ...captureMetadata(capture)
21832
22216
  }
21833
22217
  });
21834
22218
  }
21835
22219
  async function publishNote(input, deps) {
21836
22220
  await sleep2(deps.submitSettleMs);
22221
+ let capture = null;
22222
+ await armOutcomeCapture(deps.page);
21837
22223
  const submitted = await clickActionControl(input.operation, deps, PUBLISH_LABELS, "publish control");
21838
22224
  if (!submitted.ok)
21839
22225
  return fail(submitted.error);
21840
22226
  const urlBeforeSubmit = deps.page.url();
21841
22227
  const confirmed = await waitUntil(async () => {
22228
+ if (capture === null)
22229
+ capture = await readOutcomeCapture(deps.page);
22230
+ assertCapturedOutcome(capture);
21842
22231
  if (deps.page.url().includes(PUBLISHED_MARKER))
21843
22232
  return true;
21844
22233
  return await readScopedSignal(asPlaywrightPage(deps.page), PUBLISH_CONFIRM) !== null;
21845
22234
  }, deps.stepTimeoutMs);
21846
22235
  if (!confirmed) {
22236
+ capture = capture ?? await readOutcomeCapture(deps.page);
22237
+ assertCapturedOutcome(capture);
21847
22238
  return fail(`publish submission: state unknown \u2014 the '${submitted.label}' click (${submitted.click}) was sent from ${urlBeforeSubmit} but no success state was observed (now ${deps.page.url()}). Check the ${TARGET} creator note manager before retrying: a retry could duplicate the post.`);
21848
22239
  }
21849
22240
  const url = deps.page.url();
@@ -21857,13 +22248,148 @@ async function publishNote(input, deps) {
21857
22248
  publishControl: submitted.label,
21858
22249
  publishPath: submitted.path,
21859
22250
  publishClick: submitted.click,
21860
- publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast"
22251
+ publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast",
22252
+ ...captureMetadata(capture)
21861
22253
  }
21862
22254
  });
21863
22255
  }
22256
+ function draftExpectation(input, deps) {
22257
+ switch (input.operation) {
22258
+ case "\u4E0A\u4F20\u56FE\u6587":
22259
+ return {
22260
+ slots: input.images.length,
22261
+ title: true,
22262
+ body: (deps.content.body ?? "").trim().length > 0,
22263
+ collection: null
22264
+ };
22265
+ case "\u4E0A\u4F20\u89C6\u9891":
22266
+ return { slots: null, title: true, body: (deps.content.body ?? "").trim().length > 0, collection: null };
22267
+ case "\u5199\u957F\u6587":
22268
+ return { slots: null, title: false, body: true, collection: null };
22269
+ case "\u53D1\u64AD\u5BA2":
22270
+ return { slots: null, title: true, body: true, collection: podcastCollection(deps.content) };
22271
+ }
22272
+ }
22273
+ var DRAFT_NAV_SELECTOR = "text=\u8349\u7A3F\u7BB1";
22274
+ var DRAFT_EDIT_SELECTOR = "text=\u7F16\u8F91";
22275
+ var VERIFY_SLOTS_EXPR = `/* kk-verify-slots */ (() => JSON.stringify({ count: document.querySelectorAll('img.preivew-image').length }))()`;
22276
+ var VERIFY_SRCS_EXPR = `/* kk-verify-srcs */ (() => JSON.stringify(Array.from(document.querySelectorAll('img.preivew-image')).map((img) => img.getAttribute('src') || '')))()`;
22277
+ var VERIFY_TITLE_EXPR = `/* kk-verify-title */ (() => {
22278
+ const input = document.querySelector('input.d-text') || document.querySelector('textarea[placeholder*="\u6807\u9898"]');
22279
+ return input ? (input.value || '') : '';
22280
+ })()`;
22281
+ var VERIFY_BODY_EXPR = `/* kk-verify-body */ (() => {
22282
+ for (const node of document.querySelectorAll('div.edit-container *')) {
22283
+ const t = (node.textContent || '').trim();
22284
+ if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return JSON.stringify({ counter: t });
22285
+ }
22286
+ const editor = document.querySelector('div.tiptap, .ProseMirror, .ql-editor');
22287
+ return JSON.stringify({ textLen: (editor?.textContent || '').trim().length });
22288
+ })()`;
22289
+ function collectionProbeExpr(collection) {
22290
+ const literal = JSON.stringify(collection);
22291
+ return `/* kk-verify-collection */ (() => (document.body.innerText.includes(${literal}) ? 'kk-verify-collection:yes' : 'kk-verify-collection:no'))()`;
22292
+ }
22293
+ async function verifyDraft(input, deps, wired) {
22294
+ const expectation = draftExpectation(input, deps);
22295
+ const nav = deps.page.locator(DRAFT_NAV_SELECTOR);
22296
+ const navAppeared = await waitUntil(async () => await nav.count().catch(() => 0) > 0, deps.stepTimeoutMs, POLL_MS);
22297
+ if (!navAppeared) {
22298
+ throw new DraftVerifyError(`DraftVerifyError: could not reopen the saved draft \u2014 '${DRAFT_NAV_SELECTOR}' matched nothing within ${deps.stepTimeoutMs}ms after the save; verify the draft box manually in profile ${deps.profileDir}`);
22299
+ }
22300
+ const navBox = (await deps.page.boundingBoxesOnScreen?.(DRAFT_NAV_SELECTOR).catch(() => []))?.[0];
22301
+ if (navBox && deps.page.clickAt) {
22302
+ await deps.page.clickAt(navBox.x + navBox.width / 2, navBox.y + navBox.height / 2);
22303
+ } else {
22304
+ await nav.first().click({ timeout: deps.stepTimeoutMs });
22305
+ }
22306
+ const edit = deps.page.locator(DRAFT_EDIT_SELECTOR);
22307
+ if (await edit.count().catch(() => 0) === 0) {
22308
+ throw new DraftVerifyError(`DraftVerifyError: the draft list shows no '${DRAFT_EDIT_SELECTOR}' control to reopen the saved note (2026-11-11 evidence: \u7F16\u8F91 1/18 on the draft list)`);
22309
+ }
22310
+ const editBox = (await deps.page.boundingBoxesOnScreen?.(DRAFT_EDIT_SELECTOR).catch(() => []))?.[0];
22311
+ if (editBox && deps.page.clickAt) {
22312
+ await deps.page.clickAt(editBox.x + editBox.width / 2, editBox.y + editBox.height / 2);
22313
+ } else {
22314
+ await edit.first().click({ timeout: deps.stepTimeoutMs });
22315
+ }
22316
+ const editorReady = await waitUntil(async () => {
22317
+ const slotsRead = await deps.page.evaluate(VERIFY_SLOTS_EXPR).catch(() => null);
22318
+ const titleRead = await deps.page.evaluate(VERIFY_TITLE_EXPR).catch(() => null);
22319
+ const bodyRead = await deps.page.evaluate(VERIFY_BODY_EXPR).catch(() => null);
22320
+ const count = typeof slotsRead === "string" ? JSON.parse(slotsRead).count : 0;
22321
+ const title = typeof titleRead === "string" ? titleRead : "";
22322
+ const body = typeof bodyRead === "string" ? JSON.parse(bodyRead) : {};
22323
+ const slotsVisible = expectation.slots !== null && (count ?? 0) > 0;
22324
+ const titleVisible = expectation.title && title.length > 0;
22325
+ const bodyVisible = expectation.body && (body.counter !== undefined || (body.textLen ?? 0) > 0);
22326
+ return Boolean(slotsVisible || titleVisible || bodyVisible);
22327
+ }, deps.stepTimeoutMs, POLL_MS);
22328
+ const problems = [];
22329
+ if (!editorReady) {
22330
+ problems.push("the reopened editor never rendered content within the step window (0 thumbnails, empty title)");
22331
+ }
22332
+ if (expectation.slots !== null) {
22333
+ const slotsRead = await deps.page.evaluate(VERIFY_SLOTS_EXPR);
22334
+ const count = typeof slotsRead === "string" ? JSON.parse(slotsRead).count : null;
22335
+ if (count !== expectation.slots) {
22336
+ problems.push(`expected ${expectation.slots} thumbnails on the reopened draft, the editor shows ${String(count)}`);
22337
+ } else {
22338
+ const srcsRead = await deps.page.evaluate(VERIFY_SRCS_EXPR);
22339
+ const srcs = typeof srcsRead === "string" ? JSON.parse(srcsRead) : [];
22340
+ const local = srcs.map((src, index) => src.startsWith("https://") ? null : index + 1).filter((slot) => slot !== null);
22341
+ const wireDone = expectation.slots !== null && (wired?.wireCompletions ?? 0) >= expectation.slots && count === expectation.slots;
22342
+ if (local.length > 0 && !wireDone) {
22343
+ problems.push(`slots ${local.join(", ")} still carry a non-https (blob/data/local) src \u2014 the server-side copy is missing`);
22344
+ }
22345
+ }
22346
+ }
22347
+ if (expectation.title) {
22348
+ const editorTitle = String(await deps.page.evaluate(VERIFY_TITLE_EXPR) ?? "");
22349
+ if (editorTitle !== (deps.content.title ?? "")) {
22350
+ problems.push(`title mismatch: content '${deps.content.title ?? ""}' vs reopened draft '${editorTitle}'`);
22351
+ }
22352
+ }
22353
+ if (expectation.body) {
22354
+ const bodyRead = await deps.page.evaluate(VERIFY_BODY_EXPR);
22355
+ const parsed = typeof bodyRead === "string" ? JSON.parse(bodyRead) : {};
22356
+ const units = parsed.counter !== undefined ? counterUnits(parsed.counter) : null;
22357
+ if (!((units ?? 0) > 0) && !((parsed.textLen ?? 0) > 0)) {
22358
+ problems.push("body: the reopened draft shows neither a readable N/M counter nor editor text");
22359
+ }
22360
+ }
22361
+ if (expectation.collection !== null) {
22362
+ const verdict = await deps.page.evaluate(collectionProbeExpr(expectation.collection));
22363
+ if (verdict !== "kk-verify-collection:yes") {
22364
+ problems.push(`collection: the reopened podcast draft does not show '${expectation.collection}'`);
22365
+ }
22366
+ }
22367
+ await deps.page.goto(PUBLISH_URL);
22368
+ if (problems.length > 0) {
22369
+ throw new DraftVerifyError(`DraftVerifyError: the saved draft does not verify after reopen \u2014 ${problems.join("; ")}`);
22370
+ }
22371
+ return {
22372
+ ...expectation.slots !== null ? { slots: expectation.slots } : {},
22373
+ ...expectation.title ? { titleChecked: true } : {},
22374
+ ...expectation.body ? { bodyChecked: true } : {},
22375
+ ...expectation.collection !== null ? { collection: expectation.collection } : {}
22376
+ };
22377
+ }
21864
22378
  async function runMode(input, deps) {
21865
- await compose(input, deps);
21866
- return deps.publishStatus === "public" ? publishNote(input, deps) : saveDraft(input, deps);
22379
+ const wired = await compose(input, deps);
22380
+ if (deps.publishStatus === "public")
22381
+ return publishNote(input, deps);
22382
+ const saved = await saveDraft(input, deps);
22383
+ if (!saved.ok)
22384
+ return saved;
22385
+ let verified;
22386
+ try {
22387
+ verified = await verifyDraft(input, deps, wired);
22388
+ } catch (error) {
22389
+ const reason = error instanceof Error ? error.message : String(error);
22390
+ return fail(`draft saved but the reopen verification failed: ${reason}`);
22391
+ }
22392
+ return ResultSchema.parse({ ...saved, metadata: { ...saved.metadata, draftVerified: verified } });
21867
22393
  }
21868
22394
 
21869
22395
  // ../../plugins/publishings/xhs-pub/src/index.ts