@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.
Files changed (95) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/daily-voice/index.js +40 -7
  3. package/dist/index.js +8428 -4448
  4. package/package.json +1 -1
  5. package/plugins/generations/image-gen/README.md +31 -31
  6. package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
  7. package/plugins/generations/image-gen/config.example.yaml +3 -0
  8. package/plugins/generations/image-gen/dist/index.js +154 -14
  9. package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
  10. package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
  11. package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
  12. package/plugins/generations/image-gen/src/presets.ts +6 -5
  13. package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
  14. package/plugins/generations/image-gen/src/providers/types.ts +11 -1
  15. package/plugins/kk/config.example.yaml +7 -2
  16. package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
  17. package/plugins/kk/plugin.json +1 -1
  18. package/plugins/kk/publish-presets/chinese-article.json +8 -2
  19. package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
  20. package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
  21. package/plugins/kk/publish-presets/itc-main.json +36 -9
  22. package/plugins/kk/publish-presets/technical-article.json +8 -2
  23. package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
  24. package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
  25. package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
  26. package/plugins/kk/scripts/daily-stages.ts +238 -14
  27. package/plugins/kk/scripts/daily-triage-core.ts +43 -25
  28. package/plugins/kk/scripts/daily-triage.ts +1 -1
  29. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  30. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  31. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  32. package/plugins/kk/skills/publish/SKILL.md +15 -2
  33. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  34. package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
  35. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  36. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
  37. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
  38. package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
  39. package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
  40. package/plugins/kk/workflows/kk-publish.yaml +236 -0
  41. package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
  42. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
  43. package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
  44. package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
  45. package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
  46. package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
  47. package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
  48. package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
  49. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  50. package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
  51. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
  52. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  53. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
  54. package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
  55. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  56. package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
  57. package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
  58. package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
  59. package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
  60. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
  61. package/plugins/publishings/threads-pub/dist/index.js +9196 -296
  62. package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
  63. package/plugins/publishings/threads-pub/package.json +3 -1
  64. package/plugins/publishings/threads-pub/plugin.json +6 -1
  65. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  66. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  67. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  68. package/plugins/publishings/wechatmp-pub/dist/index.js +454 -81
  69. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
  70. package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
  71. package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
  72. package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
  73. package/plugins/publishings/weibo-pub/dist/index.js +136 -22
  74. package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
  75. package/plugins/publishings/weibo-pub/src/index.ts +208 -22
  76. package/plugins/publishings/x-pub/dist/index.js +263 -43
  77. package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
  78. package/plugins/publishings/x-pub/src/index.ts +15 -1
  79. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
  80. package/plugins/publishings/xhs-pub/dist/index.js +193 -201
  81. package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
  82. package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
  83. package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
  84. package/plugins/publishings/xhs-pub/src/index.ts +65 -59
  85. package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
  86. package/plugins/publishings/xhs-pub/src/page.ts +2 -2
  87. package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
  88. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
  89. package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
  90. package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
  91. package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
  92. package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
  93. package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
  94. package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
  95. package/plugins/kk/workflows/kk-itc.yaml +0 -291
@@ -21039,9 +21039,10 @@ var WEIBO_ARTICLE_SELECTORS = {
21039
21039
  ],
21040
21040
  fileInput: ['input[type="file"][accept*="image"]', 'input[type="file"]'],
21041
21041
  saveDraft: ['button:has-text("\u4FDD\u5B58\u8349\u7A3F")', 'a:has-text("\u4FDD\u5B58\u8349\u7A3F")'],
21042
- publish: ['button:has-text("\u53D1\u5E03")', 'button:has-text("\u53D1\u8868")']
21042
+ publish: ['button:has-text("\u53D1\u5E03")', 'button:has-text("\u53D1\u8868")', 'button:has-text("\u4E0B\u4E00\u6B65")']
21043
21043
  };
21044
21044
  var STEP_TIMEOUT_MS = 30000;
21045
+ var COVER_TIMEOUT_MS = 60000;
21045
21046
  var LOGIN_TIMEOUT_MS = 180000;
21046
21047
  var LOGIN_INSTRUCTION = "bun plugins/publishings/weibo-pub/src/profile-check.ts login";
21047
21048
  var POST_IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"]);
@@ -21051,6 +21052,14 @@ var EXCERPT_CHARS = 30;
21051
21052
  function fail(error) {
21052
21053
  return ResultSchema.parse({ ok: false, target: TARGET, error: boundedDetail(error) });
21053
21054
  }
21055
+ function refuse(error) {
21056
+ return ResultSchema.parse({
21057
+ ok: false,
21058
+ target: TARGET,
21059
+ error: boundedDetail(error),
21060
+ metadata: { itcDelivery: { schemaVersion: 1, effect: "none" } }
21061
+ });
21062
+ }
21054
21063
  function boundedDetail(detail) {
21055
21064
  return detail.replace(/\s+/g, " ").trim().slice(0, 300);
21056
21065
  }
@@ -21137,34 +21146,36 @@ class WeiboBrowserTransport {
21137
21146
  operation;
21138
21147
  launcher;
21139
21148
  stepTimeoutMs;
21149
+ coverTimeoutMs;
21140
21150
  constructor(operation = "post", driver = "script", deps = {}) {
21141
21151
  this.operation = operation;
21142
21152
  this.driver = driver;
21143
21153
  this.launcher = deps.launcher ?? kkBrowserLauncher;
21144
21154
  this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21155
+ this.coverTimeoutMs = deps.coverTimeoutMs ?? COVER_TIMEOUT_MS;
21145
21156
  }
21146
21157
  async publish(payload) {
21147
21158
  if (!WEIBO_OPERATIONS.includes(this.operation)) {
21148
- return fail(`unsupported operation '${bounded(this.operation)}' for weibo: expected one of ${WEIBO_OPERATIONS.join(", ")}`);
21159
+ return refuse(`unsupported operation '${bounded(this.operation)}' for weibo: expected one of ${WEIBO_OPERATIONS.join(", ")}`);
21149
21160
  }
21150
21161
  if (this.driver !== "script") {
21151
- return fail(`unsupported driver '${bounded(this.driver)}' for weibo: expected one of script (the weibo-pub browser flow has no agent path)`);
21162
+ return refuse(`unsupported driver '${bounded(this.driver)}' for weibo: expected one of script (the weibo-pub browser flow has no agent path)`);
21152
21163
  }
21153
21164
  const requested = payload.content.metadata?.publishStatus;
21154
21165
  if (requested !== undefined && requested !== "draft" && requested !== "public") {
21155
- return fail(`unknown publishStatus '${bounded(requested)}' (expected absent, 'draft' or 'public')`);
21166
+ return refuse(`unknown publishStatus '${bounded(requested)}' (expected absent, 'draft' or 'public')`);
21156
21167
  }
21157
21168
  const publishStatus = requested === "public" ? "public" : "draft";
21158
21169
  if (this.operation === "post" && publishStatus !== "public") {
21159
- return fail("weibo post has no draft; set publishStatus: public");
21170
+ return refuse("weibo post has no draft; set publishStatus: public");
21160
21171
  }
21161
21172
  const text = payload.content.body.trim() || payload.content.title?.trim() || "";
21162
21173
  if (this.operation === "post" && text.length === 0) {
21163
- return fail("weibo post requires Content.body or Content.title");
21174
+ return refuse("weibo post requires Content.body or Content.title");
21164
21175
  }
21165
21176
  const cover = await resolveCover(payload.options, payload.content, this.operation);
21166
21177
  if (cover !== undefined && "error" in cover)
21167
- return fail(cover.error);
21178
+ return refuse(cover.error);
21168
21179
  const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
21169
21180
  const profileDir = resolveChannelProfileDir(TARGET, override);
21170
21181
  const session = await checkChannelSession(WEIBO_CONFIG, {
@@ -21174,7 +21185,7 @@ class WeiboBrowserTransport {
21174
21185
  timeoutMs: this.stepTimeoutMs
21175
21186
  });
21176
21187
  if (session.status !== "verified") {
21177
- return fail(`${TARGET} session preflight refused \u2014 run: ${LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
21188
+ return refuse(`${TARGET} session preflight refused \u2014 run: ${LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
21178
21189
  }
21179
21190
  try {
21180
21191
  return await withProfilePage({
@@ -21193,7 +21204,10 @@ class WeiboBrowserTransport {
21193
21204
  async runArticleFlow(page, content, publishStatus, coverPath, profileDir) {
21194
21205
  const metadata = { operation: "article", driver: this.driver, publishStatus, profileDir };
21195
21206
  const title = content.title ?? "Untitled";
21196
- await page.evaluate(ensureArticleDraftScript());
21207
+ const blank = await page.evaluate(ensureArticleDraftScript());
21208
+ if (blank !== true) {
21209
+ return refuse("weibo article editor never reset to a blank draft \u2014 the auto-restored draft still carries a title or a cover, so filling and cover-attaching would land on the wrong article; open the editor, start \u5199\u6587\u7AE0, then retry");
21210
+ }
21197
21211
  const editorUrl = page.url();
21198
21212
  const toastsBefore = await this.readToasts(page);
21199
21213
  const titleSelector = await resolveSelector(page, WEIBO_ARTICLE_SELECTORS.title, {
@@ -21211,6 +21225,9 @@ class WeiboBrowserTransport {
21211
21225
  const preAttached = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.fileInput, { visible: false })).found;
21212
21226
  if (!preAttached) {
21213
21227
  await page.evaluate(openCoverLibraryScript());
21228
+ const modal = await expectOutcome(async () => String(await page.evaluate('() => document.querySelectorAll(".n-modal").length')) !== "0" ? "open" : null, { timeoutMs: 15000, label: "weibo cover modal" });
21229
+ if (!modal.ok)
21230
+ return refuse(`weibo cover modal never opened (no .n-modal after 15s)`);
21214
21231
  }
21215
21232
  const fileInputSelector = await resolveSelector(page, WEIBO_ARTICLE_SELECTORS.fileInput, {
21216
21233
  timeoutMs: this.stepTimeoutMs,
@@ -21221,18 +21238,20 @@ class WeiboBrowserTransport {
21221
21238
  await page.evaluate(confirmCoverModalScript());
21222
21239
  }
21223
21240
  const attached = await expectOutcome(() => this.probeCoverAttached(page, bodySelector, baseline), {
21224
- timeoutMs: this.stepTimeoutMs,
21241
+ timeoutMs: this.coverTimeoutMs,
21225
21242
  label: "weibo article cover attachment"
21226
21243
  });
21227
- if (!attached.ok)
21228
- return fail(attached.error);
21244
+ if (!attached.ok) {
21245
+ await this.dumpDebug(page, "cover-failure");
21246
+ return refuse(attached.error);
21247
+ }
21229
21248
  }
21230
21249
  const titleReadback = await this.requireReadback(page, titleSelector, title, "article title readback");
21231
21250
  if (!titleReadback.ok)
21232
- return fail(titleReadback.error);
21251
+ return refuse(titleReadback.error);
21233
21252
  const bodyReadback = await this.requireReadback(page, bodySelector, content.body, "article body readback");
21234
21253
  if (!bodyReadback.ok)
21235
- return fail(bodyReadback.error);
21254
+ return refuse(bodyReadback.error);
21236
21255
  if (publishStatus === "draft") {
21237
21256
  const saveSelector = await resolveSelector(page, WEIBO_ARTICLE_SELECTORS.saveDraft, {
21238
21257
  timeoutMs: this.stepTimeoutMs,
@@ -21258,12 +21277,15 @@ class WeiboBrowserTransport {
21258
21277
  label: "article publish control"
21259
21278
  });
21260
21279
  await page.locator(publishSelector).first().click();
21280
+ await expectOutcome(async () => String(await page.evaluate(confirmPublishScript())) === "clicked" ? "clicked" : null, { timeoutMs: 5000, label: "weibo publish confirmation" });
21261
21281
  const live = await expectOutcome(() => this.probeArticleLive(page), {
21262
21282
  timeoutMs: this.stepTimeoutMs,
21263
21283
  label: `weibo article publish '${publishSelector}'`
21264
21284
  });
21265
- if (!live.ok)
21285
+ if (!live.ok) {
21286
+ await this.dumpDebug(page, "publish-failure");
21266
21287
  return fail(live.error);
21288
+ }
21267
21289
  return ResultSchema.parse({
21268
21290
  ok: true,
21269
21291
  target: TARGET,
@@ -21290,6 +21312,8 @@ class WeiboBrowserTransport {
21290
21312
  label: "post image input"
21291
21313
  });
21292
21314
  const baseline = await this.countImages(page, composerSelector);
21315
+ const beforeSrcs = new Set(await readImageSrcs(page));
21316
+ const picIdResponse = awaitUploadedPicId(page, this.stepTimeoutMs);
21293
21317
  await uploadFile(page, fileInputSelector, coverPath, { timeoutMs: this.stepTimeoutMs });
21294
21318
  const attached = await expectOutcome(() => this.probeCoverAttached(page, composerSelector, baseline), {
21295
21319
  timeoutMs: this.stepTimeoutMs,
@@ -21298,6 +21322,20 @@ class WeiboBrowserTransport {
21298
21322
  if (!attached.ok)
21299
21323
  return fail(attached.error);
21300
21324
  picId = String(await page.evaluate(picIdScript())).trim();
21325
+ if (picId.length === 0)
21326
+ picId = await picIdResponse;
21327
+ if (picId.length === 0) {
21328
+ const afterSrcs = await readImageSrcs(page);
21329
+ for (const src of afterSrcs) {
21330
+ if (beforeSrcs.has(src))
21331
+ continue;
21332
+ const derived = picIdFromImageUrl(src);
21333
+ if (derived !== "") {
21334
+ picId = derived;
21335
+ break;
21336
+ }
21337
+ }
21338
+ }
21301
21339
  if (picId.length === 0) {
21302
21340
  return fail("weibo image uploaded but its id could not be read from the composer \u2014 refusing to post a text-only status while claiming an image");
21303
21341
  }
@@ -21336,6 +21374,28 @@ class WeiboBrowserTransport {
21336
21374
  const value = Number(await page.evaluate(coverCountScript(selector)));
21337
21375
  return Number.isFinite(value) ? value : 0;
21338
21376
  }
21377
+ async dumpDebug(page, label) {
21378
+ const dir = process.env.KK_WEIBO_DEBUG_DIR;
21379
+ if (dir === undefined || dir.trim() === "")
21380
+ return;
21381
+ try {
21382
+ const fs = createNodeFileSystem();
21383
+ await fs.ensureDir(dir);
21384
+ const state = await page.evaluate(`(() => ({
21385
+ url: location.href,
21386
+ modals: document.querySelectorAll('.n-modal').length,
21387
+ coverEmpty: document.querySelectorAll('div.cover-empty, [class*="cover-empty"]').length,
21388
+ coverPreview: document.querySelectorAll('.cover-preview').length,
21389
+ coverImg: document.querySelectorAll('img.cover-img').length,
21390
+ previews: document.querySelectorAll('.n-image-preview-container').length,
21391
+ dialog: (document.querySelector('.n-modal')?.textContent ?? '').replace(/\\s+/g, ' ').trim().slice(0, 300),
21392
+ buttons: [...document.querySelectorAll('.n-modal button, section button')].slice(0, 30).map((b) => (b.textContent ?? '').trim()),
21393
+ }))()`);
21394
+ await fs.writeFile(`${dir}/${label}.json`, `${String(state)}
21395
+ `);
21396
+ await page.screenshot({ path: `${dir}/${label}.png` });
21397
+ } catch {}
21398
+ }
21339
21399
  async probeCoverAttached(page, selector, baseline) {
21340
21400
  const count = await this.countImages(page, selector);
21341
21401
  if (count > baseline)
@@ -21392,6 +21452,15 @@ function statusIdFrom(url) {
21392
21452
  function liveArticleUrl(url) {
21393
21453
  return /(?:\/ttarticle\/p\/show\?id=|\/article\/(?:show|detail)\/)[A-Za-z0-9]+/.test(url) ? url : null;
21394
21454
  }
21455
+ function confirmPublishScript() {
21456
+ return `(() => { // kk-weibo-confirm-publish
21457
+ const buttons = [...document.querySelectorAll('.n-modal button, .n-dialog button, [role="dialog"] button')];
21458
+ const btn = buttons.find((b) => /^(\u53D1\u5E03|\u53D1\u8868)$/.test((b.textContent ?? '').trim()) && !b.disabled);
21459
+ if (!btn) return 'none';
21460
+ btn.click();
21461
+ return 'clicked';
21462
+ })()`;
21463
+ }
21395
21464
  function apiSubmitScript(text, picId) {
21396
21465
  return `(async () => { // kk-weibo-submit
21397
21466
  const cfg = (window.config || {});
@@ -21458,10 +21527,36 @@ function picIdScript() {
21458
21527
  for (const value of candidates) {
21459
21528
  if (typeof value === 'string' && value.length > 0) return value;
21460
21529
  }
21461
- const img = document.querySelector('img[src*="sinaimg"]');
21462
- return img === null ? '' : '';
21530
+ return '';
21463
21531
  })()`;
21464
21532
  }
21533
+ function imageSrcsScript() {
21534
+ return `(() => { // kk-weibo-images
21535
+ return JSON.stringify(Array.from(document.querySelectorAll('img')).map((i) => i.getAttribute('src') || '').filter((s) => s !== ''));
21536
+ })()`;
21537
+ }
21538
+ var WEIBO_UPLOAD_PIC_PATH = "/api/statuses/uploadPic";
21539
+ async function awaitUploadedPicId(page, timeoutMs) {
21540
+ try {
21541
+ const response = await page.waitForResponse((res) => res.url().includes(WEIBO_UPLOAD_PIC_PATH) && res.status() === 200, { timeout: timeoutMs });
21542
+ const body = await response.json();
21543
+ return typeof body.pic_id === "string" ? body.pic_id : "";
21544
+ } catch {
21545
+ return "";
21546
+ }
21547
+ }
21548
+ async function readImageSrcs(page) {
21549
+ try {
21550
+ const raw = JSON.parse(String(await page.evaluate(imageSrcsScript())));
21551
+ return Array.isArray(raw) ? raw.filter((entry) => typeof entry === "string") : [];
21552
+ } catch {
21553
+ return [];
21554
+ }
21555
+ }
21556
+ function picIdFromImageUrl(url) {
21557
+ const match = /sinaimg\.cn\/[^/]+\/([0-9A-Za-z]{20,})\.(?:jpg|jpeg|png|gif|webp)/i.exec(url);
21558
+ return match?.[1] ?? "";
21559
+ }
21465
21560
  function dialogTextScript() {
21466
21561
  return `(() => { // kk-weibo-dialog
21467
21562
  const nodes = document.querySelectorAll('[role="dialog"], [class*="dialog" i], [class*="modal" i], [class*="verify" i], [class*="captcha" i]');
@@ -21496,19 +21591,28 @@ function ensureArticleDraftScript() {
21496
21591
  return `(async () => { // kk-weibo-draft-init
21497
21592
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21498
21593
  const spin = () => document.querySelectorAll('.wb-editor-spin').length > 0;
21499
- const titleEl = document.querySelector('input[placeholder*="\u6807\u9898"], textarea[placeholder*="\u6807\u9898"]');
21500
- const titleVal = titleEl && titleEl.value ? String(titleEl.value).trim() : '';
21501
- const hasCover = document.querySelectorAll('.cover-preview, img.cover-img').length > 0;
21502
- if (spin() || titleVal.length > 0 || hasCover) {
21594
+ const titleEl = () => document.querySelector('input[placeholder*="\u6807\u9898"], textarea[placeholder*="\u6807\u9898"]');
21595
+ const titleVal = () => (titleEl() && titleEl().value ? String(titleEl().value).trim() : '');
21596
+ const hasCover = () => document.querySelectorAll('.cover-preview, img.cover-img').length > 0;
21597
+ const isBlank = () => titleVal().length === 0 && !hasCover();
21598
+ if (spin() || !isBlank()) {
21599
+ let clicked = false;
21503
21600
  for (const btn of document.querySelectorAll('button')) {
21504
21601
  const t = (btn.textContent || '').trim();
21505
21602
  if (t === '\u5199\u6587\u7AE0' || t.includes('\u521B\u4F5C\u4E00\u7BC7\u65B0\u6587\u7AE0')) {
21506
21603
  btn.click();
21604
+ clicked = true;
21507
21605
  break;
21508
21606
  }
21509
21607
  }
21608
+ if (!clicked) return false;
21510
21609
  await sleep(600);
21511
21610
  for (let i = 0; i < 15 && spin(); i += 1) await sleep(200);
21611
+ // The editor auto-restores the last draft (often one a failed run left with a cover). Wait
21612
+ // for the blank pane, and report the failure instead of filling the old draft: a cover the
21613
+ // restored draft already carries would satisfy the attachment probe on the WRONG image.
21614
+ for (let i = 0; i < 40 && !isBlank(); i += 1) await sleep(250);
21615
+ if (!isBlank()) return false;
21512
21616
  }
21513
21617
  return true;
21514
21618
  })()`;
@@ -21544,14 +21648,22 @@ function confirmCoverModalScript() {
21544
21648
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21545
21649
  if (!document.querySelector('.n-modal')) return true;
21546
21650
  await sleep(1500);
21651
+ // Pick the LAST library image: the \u56FE\u7247\u5E93 grid lists newest uploads last, and the first
21652
+ // <img> in the dialog is the \u624B\u673A\u4F20\u56FE QR art, not a selectable item (2026-11-12: clicking it left
21653
+ // \u4E0B\u4E00\u6B65 with nothing selected, so the cover never attached).
21547
21654
  let item = null;
21548
21655
  for (let i = 0; i < 25; i += 1) {
21549
- item = document.querySelector('.n-modal .image-item, .n-modal img[src]');
21656
+ const items = Array.from(document.querySelectorAll('.n-modal .image-item'));
21657
+ const imgs = Array.from(document.querySelectorAll('.n-modal img[src]')).filter(
21658
+ (img) => !img.closest('[class*="qrcode"], [class*="mobile"], [class*="upload"]'),
21659
+ );
21660
+ item = items.at(-1) ?? imgs.at(-1) ?? null;
21550
21661
  if (item) break;
21551
21662
  await sleep(200);
21552
21663
  }
21553
21664
  if (item instanceof HTMLElement && !item.classList.contains('is-selected')) {
21554
21665
  item.click();
21666
+ await sleep(800);
21555
21667
  }
21556
21668
  for (let i = 0; i < 15; i += 1) {
21557
21669
  const nextBtn = Array.from(document.querySelectorAll('.n-modal button')).find(
@@ -21670,10 +21782,12 @@ export {
21670
21782
  WEIBO_MOBILE_COMPOSE_URL,
21671
21783
  WEIBO_OPERATIONS,
21672
21784
  WEIBO_POST_SELECTORS,
21785
+ WEIBO_UPLOAD_PIC_PATH,
21673
21786
  WeiboBrowserTransport,
21674
21787
  getPublishTransport,
21675
21788
  isWeiboAuthenticated,
21676
21789
  main2 as main,
21790
+ picIdFromImageUrl,
21677
21791
  processPublishIO,
21678
21792
  resolveOperation
21679
21793
  };
@@ -20482,6 +20482,7 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20482
20482
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20483
20483
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20484
20484
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20485
+ var DEFAULT_POLL_MS = 500;
20485
20486
  function isInstantBrowserDeath(message) {
20486
20487
  return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20487
20488
  }
@@ -20647,6 +20648,16 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
20647
20648
  return 1;
20648
20649
  }
20649
20650
  const page = context.pages()[0] ?? await context.newPage();
20651
+ const onOpen = config.sessionState?.onOpen;
20652
+ if (onOpen !== undefined) {
20653
+ try {
20654
+ await onOpen({ context, page, profileDir: request.profileDir });
20655
+ } catch (error) {
20656
+ await context.close().catch(() => {});
20657
+ stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
20658
+ return 1;
20659
+ }
20660
+ }
20650
20661
  try {
20651
20662
  await page.goto(request.url, { waitUntil: "commit", timeout: DEFAULT_OPEN_NAV_TIMEOUT_MS });
20652
20663
  } catch (error) {
@@ -20658,6 +20669,36 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
20658
20669
  stdout(`${config.channel} profile open closed: ${request.profileDir}`);
20659
20670
  return 0;
20660
20671
  }
20672
+ async function loginWithAuthenticatedPage(config, opts) {
20673
+ const context = await opts.launcher.launch({ profileDir: opts.profileDir, headless: false });
20674
+ const sessionCaptured = config.sessionState?.onAuthenticated !== undefined;
20675
+ let captured = false;
20676
+ let facts = {};
20677
+ try {
20678
+ const page = context.pages()[0] ?? await context.newPage();
20679
+ await page.goto(opts.url);
20680
+ if (!await waitUntil(() => Promise.resolve(config.isAuthenticated(page)), opts.timeoutMs)) {
20681
+ 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.");
20682
+ }
20683
+ await config.sessionState?.onAuthenticated?.({ context, page, profileDir: opts.profileDir });
20684
+ captured = sessionCaptured;
20685
+ if (opts.captureFacts) {
20686
+ facts = {
20687
+ ...await captureSessionFacts(context, config.homeUrl),
20688
+ ...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
20689
+ };
20690
+ }
20691
+ } finally {
20692
+ try {
20693
+ await context.close();
20694
+ } catch {
20695
+ if (captured) {
20696
+ echoError(`${config.channel} browser context close failed after the authenticated session capture; saved state preserved`);
20697
+ }
20698
+ }
20699
+ }
20700
+ return facts;
20701
+ }
20661
20702
  async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20662
20703
  const stdout = deps.stdout ?? ((line) => {
20663
20704
  echo(line);
@@ -20708,7 +20749,8 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20708
20749
  const launcher = deps.launcher ?? kkBrowserLauncher;
20709
20750
  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`);
20710
20751
  try {
20711
- if (url === undefined) {
20752
+ const captureFacts = url !== undefined;
20753
+ if (!captureFacts && config.sessionState?.onAuthenticated === undefined) {
20712
20754
  await loginWithProfile({
20713
20755
  profileDir,
20714
20756
  url: config.homeUrl,
@@ -20719,18 +20761,16 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20719
20761
  stdout(`${config.channel} profile login verified: ${profileDir}`);
20720
20762
  return 0;
20721
20763
  }
20722
- const facts = await withProfilePage({
20764
+ const facts = await loginWithAuthenticatedPage(config, {
20723
20765
  profileDir,
20724
- headless: false,
20725
- url,
20726
- isAuthenticated: config.isAuthenticated,
20766
+ url: url ?? config.homeUrl,
20727
20767
  timeoutMs: loginTimeoutMs,
20728
- launcher
20729
- }, async ({ context, page }) => ({
20730
- ...await captureSessionFacts(context, config.homeUrl),
20731
- ...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
20732
- }));
20768
+ launcher,
20769
+ captureFacts
20770
+ });
20733
20771
  stdout(`${config.channel} profile login verified: ${profileDir}`);
20772
+ if (url === undefined)
20773
+ return 0;
20734
20774
  stdout(JSON.stringify({
20735
20775
  status: "verified",
20736
20776
  profileDir,
@@ -20753,6 +20793,16 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20753
20793
  stdout(JSON.stringify(result));
20754
20794
  return result.status === "verified" ? 0 : 1;
20755
20795
  }
20796
+ async function waitUntil(predicate, timeoutMs, pollMs = DEFAULT_POLL_MS) {
20797
+ const deadline = Date.now() + timeoutMs;
20798
+ while (Date.now() < deadline) {
20799
+ if (await predicate()) {
20800
+ return true;
20801
+ }
20802
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
20803
+ }
20804
+ return predicate();
20805
+ }
20756
20806
  async function captureSessionFacts(context, url) {
20757
20807
  let cookies;
20758
20808
  try {
@@ -21069,7 +21119,7 @@ var WEIBO_ARTICLE_SELECTORS = {
21069
21119
  ],
21070
21120
  fileInput: ['input[type="file"][accept*="image"]', 'input[type="file"]'],
21071
21121
  saveDraft: ['button:has-text("\u4FDD\u5B58\u8349\u7A3F")', 'a:has-text("\u4FDD\u5B58\u8349\u7A3F")'],
21072
- publish: ['button:has-text("\u53D1\u5E03")', 'button:has-text("\u53D1\u8868")']
21122
+ publish: ['button:has-text("\u53D1\u5E03")', 'button:has-text("\u53D1\u8868")', 'button:has-text("\u4E0B\u4E00\u6B65")']
21073
21123
  };
21074
21124
  var LOGIN_TIMEOUT_MS = 180000;
21075
21125
  var POST_IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"]);