@gobing-ai/knowledge-kit 0.1.19 → 0.1.22

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 (147) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/collect/index.js +1 -0
  3. package/dist/board/daily-voice/index.js +1315 -264
  4. package/dist/board/itc/index.js +1 -0
  5. package/dist/index.js +14674 -8775
  6. package/package.json +1 -1
  7. package/plugins/generations/dailynews-gen/dist/index.js +285 -16
  8. package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
  9. package/plugins/generations/dailynews-gen/src/index.ts +23 -4
  10. package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
  11. package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
  12. package/plugins/generations/image-gen/README.md +31 -31
  13. package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
  14. package/plugins/generations/image-gen/config.example.yaml +3 -0
  15. package/plugins/generations/image-gen/dist/index.js +154 -14
  16. package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
  17. package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
  18. package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
  19. package/plugins/generations/image-gen/src/presets.ts +6 -5
  20. package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
  21. package/plugins/generations/image-gen/src/providers/types.ts +11 -1
  22. package/plugins/generations/music-gen/README.md +277 -0
  23. package/plugins/generations/music-gen/dist/index.js +23544 -0
  24. package/plugins/generations/music-gen/package.json +24 -0
  25. package/plugins/generations/music-gen/plugin.json +23 -0
  26. package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
  27. package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
  28. package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
  29. package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
  30. package/plugins/generations/music-gen/presets/formats/song.yaml +31 -0
  31. package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
  32. package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
  33. package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
  34. package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
  35. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +30 -0
  36. package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
  37. package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
  38. package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
  39. package/plugins/generations/music-gen/src/adapter/instance.ts +904 -0
  40. package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
  41. package/plugins/generations/music-gen/src/artifact.ts +223 -0
  42. package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
  43. package/plugins/generations/music-gen/src/audio/master.ts +267 -0
  44. package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
  45. package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
  46. package/plugins/generations/music-gen/src/audio.ts +122 -0
  47. package/plugins/generations/music-gen/src/brief.ts +191 -0
  48. package/plugins/generations/music-gen/src/config.ts +451 -0
  49. package/plugins/generations/music-gen/src/content.ts +199 -0
  50. package/plugins/generations/music-gen/src/digest.ts +100 -0
  51. package/plugins/generations/music-gen/src/index.ts +147 -0
  52. package/plugins/generations/music-gen/src/job.ts +131 -0
  53. package/plugins/generations/music-gen/src/plugin.ts +371 -0
  54. package/plugins/generations/music-gen/src/presets.ts +918 -0
  55. package/plugins/generations/music-gen/src/render.ts +87 -0
  56. package/plugins/generations/music-gen/src/request.ts +102 -0
  57. package/plugins/generations/music-gen/src/spend.ts +495 -0
  58. package/plugins/generations/music-gen/tsconfig.json +8 -0
  59. package/plugins/kk/config.example.yaml +3 -0
  60. package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
  61. package/plugins/kk/plugin.json +1 -1
  62. package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
  63. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
  64. package/plugins/kk/scripts/cover-compositor.ts +380 -32
  65. package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
  66. package/plugins/kk/scripts/daily-stages.ts +897 -34
  67. package/plugins/kk/scripts/episode-identity.ts +180 -0
  68. package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
  69. package/plugins/kk/scripts/music-stages.ts +624 -0
  70. package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
  71. package/plugins/kk/scripts/source-citation.ts +187 -0
  72. package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
  73. package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
  74. package/plugins/kk/skills/content-judge/SKILL.md +11 -6
  75. package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
  76. package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
  77. package/plugins/kk/skills/content-safety/SKILL.md +12 -0
  78. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  79. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  80. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  81. package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
  82. package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
  83. package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
  84. package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
  85. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
  86. package/plugins/kk/skills/publish/SKILL.md +11 -0
  87. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  88. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  89. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +10 -9
  90. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +11 -9
  91. package/plugins/kk/workflows/kk-music.yaml +328 -0
  92. package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
  93. package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
  94. package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
  95. package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
  96. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
  97. package/plugins/publishings/csdn-pub/dist/index.js +11 -1
  98. package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
  99. package/plugins/publishings/infoq-pub/dist/index.js +11 -1
  100. package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
  101. package/plugins/publishings/jike-pub/dist/index.js +11 -1
  102. package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
  103. package/plugins/publishings/juejin-pub/dist/index.js +11 -1
  104. package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
  105. package/plugins/publishings/linkedin-pub/dist/index.js +54 -7
  106. package/plugins/publishings/linkedin-pub/dist/profile-check.js +43 -6
  107. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  108. package/plugins/publishings/podcast-pub/dist/index.js +586 -20
  109. package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
  110. package/plugins/publishings/podcast-pub/src/index.ts +257 -5
  111. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
  112. package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
  113. package/plugins/publishings/shipinhao-pub/dist/index.js +437 -32
  114. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +14 -2
  115. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  116. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +492 -0
  117. package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
  118. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  119. package/plugins/publishings/sspai-pub/dist/index.js +11 -1
  120. package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
  121. package/plugins/publishings/substack-pub/dist/index.js +11 -1
  122. package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
  123. package/plugins/publishings/surfdash-pub/dist/index.js +122 -28
  124. package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
  125. package/plugins/publishings/surfdash-pub/src/index.ts +159 -25
  126. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +37 -4
  127. package/plugins/publishings/threads-pub/dist/index.js +9206 -296
  128. package/plugins/publishings/threads-pub/dist/profile-check.js +21149 -0
  129. package/plugins/publishings/threads-pub/package.json +3 -1
  130. package/plugins/publishings/threads-pub/plugin.json +6 -1
  131. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  132. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  133. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  134. package/plugins/publishings/wechatmp-pub/dist/index.js +18 -1
  135. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
  136. package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
  137. package/plugins/publishings/weibo-pub/dist/index.js +57 -3
  138. package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
  139. package/plugins/publishings/weibo-pub/src/index.ts +74 -2
  140. package/plugins/publishings/x-pub/dist/index.js +274 -44
  141. package/plugins/publishings/x-pub/dist/profile-check.js +14 -2
  142. package/plugins/publishings/x-pub/src/index.ts +15 -1
  143. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
  144. package/plugins/publishings/xhs-pub/dist/index.js +11 -1
  145. package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
  146. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
  147. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
@@ -20482,6 +20482,9 @@ 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 VERDICT_PRINT_MARGIN_MS = 2000;
20486
+ var MIN_PASS_BUDGET_MS = 5000;
20487
+ var PASS_LAUNCH_RESERVE_MS = 20000;
20485
20488
  var DEFAULT_POLL_MS = 500;
20486
20489
  function isInstantBrowserDeath(message) {
20487
20490
  return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
@@ -20604,14 +20607,21 @@ async function checkChannelSession(config, opts) {
20604
20607
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
20605
20608
  const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
20606
20609
  let lastDetail = `${config.channel} readiness was never probed`;
20610
+ const deadline = Date.now() + timeoutMs;
20611
+ const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
20612
+ const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
20613
+ const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
20607
20614
  for (const headless of passes) {
20615
+ const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
20616
+ if (remainingMs < minPassMs)
20617
+ break;
20608
20618
  try {
20609
20619
  await withProfilePage({
20610
20620
  profileDir: opts.profileDir,
20611
20621
  headless,
20612
20622
  url: config.homeUrl,
20613
20623
  isAuthenticated: config.isAuthenticated,
20614
- timeoutMs,
20624
+ timeoutMs: remainingMs,
20615
20625
  launcher: opts.launcher ?? kkBrowserLauncher
20616
20626
  }, async () => true);
20617
20627
  return {
@@ -542,6 +542,8 @@ export class WeiboBrowserTransport implements PublishTransport {
542
542
  label: 'post image input',
543
543
  });
544
544
  const baseline = await this.countImages(page, composerSelector);
545
+ const beforeSrcs = new Set<string>(await readImageSrcs(page));
546
+ const picIdResponse = awaitUploadedPicId(page, this.stepTimeoutMs);
545
547
  await uploadFile(page, fileInputSelector, coverPath, { timeoutMs: this.stepTimeoutMs });
546
548
  const attached = await expectOutcome(() => this.probeCoverAttached(page, composerSelector, baseline), {
547
549
  timeoutMs: this.stepTimeoutMs,
@@ -552,6 +554,19 @@ export class WeiboBrowserTransport implements PublishTransport {
552
554
  // whose id cannot be read is refused rather than posted as a text-only status while
553
555
  // claiming an image (R9 is fail-closed like every other rail).
554
556
  picId = String(await page.evaluate(picIdScript())).trim();
557
+ if (picId.length === 0) picId = await picIdResponse;
558
+ if (picId.length === 0) {
559
+ // Fall back to the uploaded image's own key, read off its fresh sinaimg URL.
560
+ const afterSrcs = await readImageSrcs(page);
561
+ for (const src of afterSrcs) {
562
+ if (beforeSrcs.has(src)) continue;
563
+ const derived = picIdFromImageUrl(src);
564
+ if (derived !== '') {
565
+ picId = derived;
566
+ break;
567
+ }
568
+ }
569
+ }
555
570
  if (picId.length === 0) {
556
571
  return fail(
557
572
  'weibo image uploaded but its id could not be read from the composer — refusing to post a text-only status while claiming an image',
@@ -841,11 +856,68 @@ function picIdScript(): string {
841
856
  for (const value of candidates) {
842
857
  if (typeof value === 'string' && value.length > 0) return value;
843
858
  }
844
- const img = document.querySelector('img[src*="sinaimg"]');
845
- return img === null ? '' : '';
859
+ return '';
860
+ })()`;
861
+ }
862
+
863
+ /**
864
+ * Every `<img>` src on the page — the baseline for "which image did this upload add".
865
+ *
866
+ * MEASURED 2026-11-16: the composer keeps no pic id in `window.config`/`$render_data` (those were
867
+ * never observed populated), but the upload itself publishes the image under its own key —
868
+ * `https://wx4.sinaimg.cn/bmiddle/006pHqcMly1ij4wmw8zq6j30u0140ngx.jpg` — and that path segment IS
869
+ * the `pic_id` the submit API takes. So the id is derived from the NEW image's URL, by diffing
870
+ * against the pre-upload set; nothing is guessed from a stale page.
871
+ */
872
+ function imageSrcsScript(): string {
873
+ return `(() => { // kk-weibo-images
874
+ return JSON.stringify(Array.from(document.querySelectorAll('img')).map((i) => i.getAttribute('src') || '').filter((s) => s !== ''));
846
875
  })()`;
847
876
  }
848
877
 
878
+ /** The platform's own image-upload endpoint (measured 2026-11-16 on m.weibo.cn/compose). */
879
+ export const WEIBO_UPLOAD_PIC_PATH = '/api/statuses/uploadPic';
880
+
881
+ /**
882
+ * Waits for the upload's own JSON response and returns its `pic_id`.
883
+ *
884
+ * MEASURED 2026-11-16 on `m.weibo.cn/compose/`: the composer keeps no pic id in
885
+ * `window.config`/`$render_data` (those were the old guess and are never populated), and the
886
+ * uploaded thumbnail renders as a `blob:` URL — so nothing on the DOM carries the id. The upload
887
+ * request itself answers with it:
888
+ * POST https://m.weibo.cn/api/statuses/uploadPic
889
+ * {"pic_id":"006pHqcMly8ij4wpdhpzyj30u0140ngx","thumbnail_pic":"…","bmiddle_pic":"…","original_pic":"…"}
890
+ * Intercept the response instead of inferring the id.
891
+ */
892
+ async function awaitUploadedPicId(page: Page, timeoutMs: number): Promise<string> {
893
+ try {
894
+ const response = await page.waitForResponse(
895
+ (res) => res.url().includes(WEIBO_UPLOAD_PIC_PATH) && res.status() === 200,
896
+ { timeout: timeoutMs },
897
+ );
898
+ const body = (await response.json()) as { pic_id?: unknown };
899
+ return typeof body.pic_id === 'string' ? body.pic_id : '';
900
+ } catch {
901
+ return '';
902
+ }
903
+ }
904
+
905
+ /** Every image src, tolerantly: a page that cannot answer yields none (never a throw). */
906
+ async function readImageSrcs(page: Page): Promise<string[]> {
907
+ try {
908
+ const raw = JSON.parse(String(await page.evaluate(imageSrcsScript()))) as unknown;
909
+ return Array.isArray(raw) ? raw.filter((entry): entry is string => typeof entry === 'string') : [];
910
+ } catch {
911
+ return [];
912
+ }
913
+ }
914
+
915
+ /** The Weibo image key inside a sinaimg URL: the last path segment without its extension. */
916
+ export function picIdFromImageUrl(url: string): string {
917
+ const match = /sinaimg\.cn\/[^/]+\/([0-9A-Za-z]{20,})\.(?:jpg|jpeg|png|gif|webp)/i.exec(url);
918
+ return match?.[1] ?? '';
919
+ }
920
+
849
921
  /** The first visible dialog/modal/verification text on the page, bounded; '' when none. */
850
922
  function dialogTextScript(): string {
851
923
  return `(() => { // kk-weibo-dialog
@@ -19830,7 +19830,7 @@ var init_runtime_node_bun = __esm(() => {
19830
19830
 
19831
19831
  // ../../plugins/publishings/x-pub/src/index.ts
19832
19832
  import { createHmac, randomBytes as randomBytes2 } from "crypto";
19833
- import { dirname as dirname4, extname, isAbsolute as isAbsolute2 } from "path";
19833
+ import { dirname as dirname4, extname as extname2, isAbsolute as isAbsolute3 } from "path";
19834
19834
  import { parseArgs } from "util";
19835
19835
 
19836
19836
  // ../../packages/kk-core/src/content-limits.ts
@@ -20801,6 +20801,9 @@ async function ensureProfileDir2(profileDir, headless) {
20801
20801
  var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20802
20802
  // ../../packages/publish-harness/src/browser.ts
20803
20803
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20804
+ var VERDICT_PRINT_MARGIN_MS = 2000;
20805
+ var MIN_PASS_BUDGET_MS = 5000;
20806
+ var PASS_LAUNCH_RESERVE_MS = 20000;
20804
20807
  var DEFAULT_STEP_TIMEOUT_MS = 30000;
20805
20808
  var DEFAULT_POLL_MS = 500;
20806
20809
  var ATTACH_POLL_MS = 100;
@@ -20925,14 +20928,21 @@ async function checkChannelSession(config, opts) {
20925
20928
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
20926
20929
  const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
20927
20930
  let lastDetail = `${config.channel} readiness was never probed`;
20931
+ const deadline = Date.now() + timeoutMs;
20932
+ const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
20933
+ const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
20934
+ const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
20928
20935
  for (const headless of passes) {
20936
+ const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
20937
+ if (remainingMs < minPassMs)
20938
+ break;
20929
20939
  try {
20930
20940
  await withProfilePage({
20931
20941
  profileDir: opts.profileDir,
20932
20942
  headless,
20933
20943
  url: config.homeUrl,
20934
20944
  isAuthenticated: config.isAuthenticated,
20935
- timeoutMs,
20945
+ timeoutMs: remainingMs,
20936
20946
  launcher: opts.launcher ?? kkBrowserLauncher
20937
20947
  }, async () => true);
20938
20948
  return {
@@ -21043,12 +21053,224 @@ function editorTextScript(selector) {
21043
21053
 
21044
21054
  // ../../plugins/publishings/x-pub/src/index.ts
21045
21055
  init_dist();
21046
- var REQUEST_TIMEOUT_MS = 120000;
21056
+
21057
+ // ../../plugins/publishings/x-pub/src/post-rail.ts
21058
+ import { extname, isAbsolute as isAbsolute2 } from "path";
21047
21059
  var TARGET = "x";
21060
+ var LOGIN_INSTRUCTION = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21061
+ var STEP_TIMEOUT_MS = 30000;
21062
+ var LOGIN_TIMEOUT_MS = 180000;
21063
+ var LOGIN_URL_RE = /\/(?:i\/flow\/login|login|account\/access)/;
21064
+ var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21065
+ var X_POST_URL = "https://x.com/home";
21066
+ var X_NEW_POST_BUTTON = '[data-testid="SideNav_NewTweet_Button"]';
21067
+ var X_COMPOSE_PATH = "/compose/post";
21068
+ var X_POST_SUBMIT = '[data-testid="tweetButton"]';
21069
+ var POST_SELECTORS = {
21070
+ text: ['[data-testid="tweetTextarea_0"]'],
21071
+ mediaButton: ['button[aria-label="Add photos or video"]', '[aria-label*="Add photos" i]'],
21072
+ fileInput: ['input[data-testid="fileInput"]', '[data-testid="fileInput"]'],
21073
+ mediaPreview: ['[data-testid="attachments"]', '[aria-label*="Media" i]'],
21074
+ profileLink: ['a[data-testid="AppTabBar_Profile_Link"]']
21075
+ };
21076
+ var isPostAuthenticated = async (page) => {
21077
+ if (LOGIN_URL_RE.test(page.url()))
21078
+ return false;
21079
+ return (await trySelectors(page, [X_NEW_POST_BUTTON], { visible: false })).found;
21080
+ };
21081
+ var POST_CONFIG = {
21082
+ channel: TARGET,
21083
+ homeUrl: X_POST_URL,
21084
+ isAuthenticated: isPostAuthenticated,
21085
+ loginTimeoutMs: LOGIN_TIMEOUT_MS,
21086
+ checkHeadedOnly: true
21087
+ };
21088
+ function fail(error) {
21089
+ return ResultSchema.parse({ ok: false, target: TARGET, error, effect: "none" });
21090
+ }
21091
+ function needsLogin(error) {
21092
+ const text = error instanceof Error ? error.message : String(error);
21093
+ return /login|sign in|logged out/i.test(text);
21094
+ }
21095
+ function errorMessage3(error) {
21096
+ return error instanceof Error ? error.message : String(error);
21097
+ }
21098
+ async function resolveCover(raw, fs = createNodeFileSystem()) {
21099
+ if (raw === undefined)
21100
+ return;
21101
+ if (typeof raw !== "string" || raw.trim() === "") {
21102
+ return { error: `x post cover must be a non-empty local path, got '${String(raw)}'` };
21103
+ }
21104
+ if (!isAbsolute2(raw))
21105
+ return { error: `x post cover must be an absolute path, got '${raw}'` };
21106
+ if (!COVER_EXTS.has(extname(raw).toLowerCase())) {
21107
+ return { error: `x post cover must be .png/.jpg/.jpeg/.webp, got '${extname(raw) || "(none)"}'` };
21108
+ }
21109
+ if (!await fs.exists(raw))
21110
+ return { error: `x post cover does not exist: ${raw}` };
21111
+ return { path: raw };
21112
+ }
21113
+
21114
+ class XPostBrowserTransport {
21115
+ kind = "browser";
21116
+ launcher;
21117
+ stepTimeoutMs;
21118
+ constructor(deps = {}) {
21119
+ this.launcher = deps.launcher ?? kkBrowserLauncher;
21120
+ this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21121
+ }
21122
+ async publish(payload) {
21123
+ const requested = payload.content.metadata?.publishStatus;
21124
+ if (requested === "draft") {
21125
+ return fail("x post has no draft: the compose surface publishes immediately \u2014 plan this target dummy/off or launch it live");
21126
+ }
21127
+ if (requested !== undefined && requested !== "public") {
21128
+ return fail(`unknown publishStatus '${requested}' for x post: expected 'public' or absent`);
21129
+ }
21130
+ const text = (payload.content.body ?? payload.content.title ?? "").trim();
21131
+ if (text === "")
21132
+ return fail("x post requires non-empty Content.body or Content.title");
21133
+ const cover = await resolveCover(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? payload.content.metadata?.coverImage);
21134
+ if (cover !== undefined && "error" in cover)
21135
+ return fail(cover.error);
21136
+ const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
21137
+ const profileDir = resolveChannelProfileDir(POST_CONFIG.channel, override);
21138
+ const session = await checkChannelSession(POST_CONFIG, {
21139
+ profileDir,
21140
+ launcher: this.launcher,
21141
+ headedOnly: true,
21142
+ timeoutMs: this.stepTimeoutMs
21143
+ });
21144
+ if (session.status !== "verified") {
21145
+ return fail(`${TARGET} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
21146
+ }
21147
+ try {
21148
+ return await withProfilePage({
21149
+ profileDir,
21150
+ url: X_POST_URL,
21151
+ isAuthenticated: isPostAuthenticated,
21152
+ headless: payload.options?.headless === true,
21153
+ launcher: this.launcher,
21154
+ timeoutMs: this.stepTimeoutMs
21155
+ }, async ({ page }) => this.runPostFlow(page, text, cover !== undefined && "path" in cover ? cover.path : undefined, profileDir));
21156
+ } catch (error) {
21157
+ const hint = needsLogin(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION}` : "";
21158
+ return fail(`${errorMessage3(error)}${hint}`);
21159
+ }
21160
+ }
21161
+ async newestStatusId(page, handleHref) {
21162
+ const target = `https://x.com${handleHref}`;
21163
+ if (!page.url().startsWith(target)) {
21164
+ await page.goto(target, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
21165
+ } else {
21166
+ await page.reload({ waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs }).catch(() => {});
21167
+ }
21168
+ const link = page.locator('[data-testid="tweet"] a[href*="/status/"]').first();
21169
+ if (await link.count() === 0)
21170
+ return null;
21171
+ const href = await link.getAttribute("href").catch(() => null);
21172
+ return href === null ? null : /\/status\/(\d+)/.exec(href)?.[1] ?? null;
21173
+ }
21174
+ async openComposer(page) {
21175
+ if (!page.url().includes(X_COMPOSE_PATH)) {
21176
+ if (!page.url().startsWith("https://x.com/home")) {
21177
+ await page.goto(X_POST_URL, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
21178
+ }
21179
+ const opener = await expectOutcome(async () => await page.locator(X_NEW_POST_BUTTON).count() > 0 ? "post button rendered" : null, { timeoutMs: this.stepTimeoutMs, label: "x nav post button" });
21180
+ if (!opener.ok)
21181
+ return `x home never rendered the Post button: ${opener.error}`;
21182
+ await page.locator(X_NEW_POST_BUTTON).first().click();
21183
+ }
21184
+ const composer = await expectOutcome(async () => {
21185
+ if (!page.url().includes(X_COMPOSE_PATH))
21186
+ return null;
21187
+ return await page.locator(POST_SELECTORS.text[0]).count() > 0 ? "composer open" : null;
21188
+ }, { timeoutMs: this.stepTimeoutMs, label: "x compose/post surface" });
21189
+ return composer.ok ? null : `x composer never opened at ${X_COMPOSE_PATH}: ${composer.error}`;
21190
+ }
21191
+ async typeAndEnable(page, text) {
21192
+ const textBox = page.locator(POST_SELECTORS.text[0]).first();
21193
+ const submit = page.locator(X_POST_SUBMIT).first();
21194
+ for (let attempt = 1;attempt <= 3; attempt++) {
21195
+ await page.keyboard.press("Escape").catch(() => {});
21196
+ await page.waitForTimeout(250);
21197
+ const focused = await textBox.click({ force: true }).then(() => true, () => textBox.focus().then(() => true).catch(() => false));
21198
+ if (!focused)
21199
+ return "x composer editor could not be focused";
21200
+ await page.waitForTimeout(300);
21201
+ await textBox.press("ControlOrMeta+a").catch(() => {});
21202
+ await textBox.press("Backspace").catch(() => {});
21203
+ await textBox.pressSequentially(text, { delay: 8 });
21204
+ const enabled = await expectOutcome(async () => await submit.isEnabled().catch(() => false) ? "post enabled" : null, { timeoutMs: Math.min(1e4, this.stepTimeoutMs), label: `x post enabled (attempt ${attempt})` });
21205
+ if (enabled.ok)
21206
+ return null;
21207
+ }
21208
+ return "x post submit never enabled \u2014 the editor did not accept the text in three attempts";
21209
+ }
21210
+ async runPostFlow(page, text, coverPath, profileDir) {
21211
+ const metadata = { operation: "post", driver: "script", publishStatus: "public", profileDir };
21212
+ const handle = await page.locator(POST_SELECTORS.profileLink[0]).first().getAttribute("href").catch(() => null);
21213
+ if (handle === null || handle.trim() === "") {
21214
+ return fail("x post could not read the profile link, so the status id cannot be confirmed");
21215
+ }
21216
+ const baselineId = await this.newestStatusId(page, handle).catch(() => null);
21217
+ const opened = await this.openComposer(page);
21218
+ if (opened !== null)
21219
+ return fail(opened);
21220
+ const typed = await this.typeAndEnable(page, text);
21221
+ if (typed !== null)
21222
+ return fail(`${typed}; refusing to claim a publish`);
21223
+ if (coverPath !== undefined) {
21224
+ const media = await expectOutcome(async () => {
21225
+ const found = await trySelectors(page, POST_SELECTORS.mediaButton);
21226
+ return found.found ? found.selector ?? POST_SELECTORS.mediaButton[0] : null;
21227
+ }, { timeoutMs: this.stepTimeoutMs, label: "x media button" });
21228
+ if (!media.ok)
21229
+ return fail(`x media control never attached: ${media.error}`);
21230
+ await page.locator(media.evidence).first().click();
21231
+ const input = await resolveSelector(page, POST_SELECTORS.fileInput, {
21232
+ timeoutMs: this.stepTimeoutMs,
21233
+ label: "x post media input"
21234
+ });
21235
+ await uploadFile(page, input, coverPath, { timeoutMs: this.stepTimeoutMs });
21236
+ const attached = await expectOutcome(async () => await page.locator(POST_SELECTORS.mediaPreview[0]).count() > 0 ? "media attached" : null, { timeoutMs: this.stepTimeoutMs, label: "x post media" });
21237
+ if (!attached.ok)
21238
+ return fail(`x post image was uploaded but never rendered: ${attached.error}`);
21239
+ const reEnabled = await expectOutcome(async () => await page.locator(X_POST_SUBMIT).first().isEnabled().catch(() => false) ? "post re-enabled" : null, { timeoutMs: this.stepTimeoutMs * 4, label: "x post submit enabled after media" });
21240
+ if (!reEnabled.ok)
21241
+ return fail(`x post submit stayed disabled after the media: ${reEnabled.error}`);
21242
+ }
21243
+ await page.locator(X_POST_SUBMIT).first().click();
21244
+ const receipt = await expectOutcome(async () => {
21245
+ const id = await this.newestStatusId(page, handle);
21246
+ if (id === null)
21247
+ return null;
21248
+ if (baselineId !== null && id === baselineId)
21249
+ return null;
21250
+ return `https://x.com${handle}/status/${id}`;
21251
+ }, { timeoutMs: this.stepTimeoutMs, label: "x status receipt" });
21252
+ if (!receipt.ok) {
21253
+ return fail(`x post receipt not confirmed \u2014 Post was clicked but no new status id appeared on the profile (${receipt.error}); an unobserved submit is never reported as published`);
21254
+ }
21255
+ const id = /\/status\/(\d+)/.exec(receipt.evidence)?.[1];
21256
+ return ResultSchema.parse({
21257
+ ok: true,
21258
+ target: TARGET,
21259
+ ...id === undefined ? {} : { id },
21260
+ url: receipt.evidence,
21261
+ message: `x post published and confirmed in profile ${profileDir}`,
21262
+ metadata: { ...metadata, confirmedBy: "profile-timeline" }
21263
+ });
21264
+ }
21265
+ }
21266
+
21267
+ // ../../plugins/publishings/x-pub/src/index.ts
21268
+ var REQUEST_TIMEOUT_MS = 120000;
21269
+ var TARGET2 = "x";
21048
21270
  var TWEETS_URL = "https://api.twitter.com/2/tweets";
21049
21271
  var TOKEN_ENVS = ["X_API_KEY", "X_API_SECRET", "X_ACCESS_TOKEN", "X_ACCESS_TOKEN_SECRET"];
21050
- function fail(error) {
21051
- return ResultSchema.parse({ ok: false, target: TARGET, error });
21272
+ function fail2(error) {
21273
+ return ResultSchema.parse({ ok: false, target: TARGET2, error });
21052
21274
  }
21053
21275
  function percentEncode(value) {
21054
21276
  return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
@@ -21085,21 +21307,21 @@ class XPostApiTransport {
21085
21307
  async publish(payload) {
21086
21308
  const requestedStatus = payload.content.metadata?.publishStatus;
21087
21309
  if (requestedStatus === "draft") {
21088
- return fail("x post has no draft: the post API publishes immediately \u2014 plan this target dummy/off or launch it live");
21310
+ return fail2("x post has no draft: the post API publishes immediately \u2014 plan this target dummy/off or launch it live");
21089
21311
  }
21090
21312
  if (requestedStatus !== undefined && requestedStatus !== "public") {
21091
- return fail(`unknown publishStatus '${String(requestedStatus)}' (expected absent, 'draft' or 'public')`);
21313
+ return fail2(`unknown publishStatus '${String(requestedStatus)}' (expected absent, 'draft' or 'public')`);
21092
21314
  }
21093
21315
  const missing = TOKEN_ENVS.filter((key) => {
21094
21316
  const value = process.env[key];
21095
21317
  return !value || value.trim().length === 0;
21096
21318
  });
21097
21319
  if (missing.length > 0) {
21098
- return fail(`${missing.join(", ")} environment variable${missing.length > 1 ? "s are" : " is"} required: X developer user-context credentials. post does not fall back to a browser (X Automation Rules).`);
21320
+ return fail2(`${missing.join(", ")} environment variable${missing.length > 1 ? "s are" : " is"} required: X developer user-context credentials. post does not fall back to a browser (X Automation Rules).`);
21099
21321
  }
21100
21322
  const text = payload.content.body.trim() || payload.content.title?.trim() || "";
21101
21323
  if (text.length === 0) {
21102
- return fail("X post requires Content.body or Content.title");
21324
+ return fail2("X post requires Content.body or Content.title");
21103
21325
  }
21104
21326
  try {
21105
21327
  const authorization = oauth1Header({
@@ -21121,29 +21343,29 @@ class XPostApiTransport {
21121
21343
  });
21122
21344
  if (!response.ok) {
21123
21345
  const errorText = (await response.text()).slice(0, 1000);
21124
- return fail(`X POST /2/tweets failed (HTTP ${response.status}): ${errorText.trim() || response.statusText}`);
21346
+ return fail2(`X POST /2/tweets failed (HTTP ${response.status}): ${errorText.trim() || response.statusText}`);
21125
21347
  }
21126
21348
  const json = await response.json();
21127
21349
  if (typeof json.data?.id !== "string") {
21128
- return fail("X POST /2/tweets response missing data.id");
21350
+ return fail2("X POST /2/tweets response missing data.id");
21129
21351
  }
21130
21352
  return ResultSchema.parse({
21131
21353
  ok: true,
21132
- target: TARGET,
21354
+ target: TARGET2,
21133
21355
  id: json.data.id,
21134
21356
  url: `https://x.com/i/web/status/${json.data.id}`,
21135
21357
  message: "Posted via X API v2",
21136
21358
  metadata: { operation: "post" }
21137
21359
  });
21138
21360
  } catch (err) {
21139
- return fail(`X post transport error: ${err instanceof Error ? err.message : String(err)}`);
21361
+ return fail2(`X post transport error: ${err instanceof Error ? err.message : String(err)}`);
21140
21362
  }
21141
21363
  }
21142
21364
  }
21143
21365
  var ARTICLE_CHANNEL = "x";
21144
21366
  var X_ARTICLES_URL = "https://x.com/compose/articles";
21145
21367
  var ARTICLE_EDIT_RE = /\/compose\/articles\/edit\/(\d+)/;
21146
- var LOGIN_URL_RE = /(\/i\/flow\/login|\/login)/;
21368
+ var LOGIN_URL_RE2 = /(\/i\/flow\/login|\/login)/;
21147
21369
  var ARTICLE_SELECTORS = {
21148
21370
  write: ['[data-testid="empty_state_button_text"]', 'button:has-text("Write")', '[aria-label*="Write" i]'],
21149
21371
  title: ['textarea[placeholder="Add a title"]', '[data-testid="twitter-article-title"]'],
@@ -21152,13 +21374,13 @@ var ARTICLE_SELECTORS = {
21152
21374
  fileInput: ['[data-testid="fileInput"]', 'input[type="file"][accept*="image"]'],
21153
21375
  publish: ['[data-testid="publishButton"]', 'button:has-text("Publish")']
21154
21376
  };
21155
- var STEP_TIMEOUT_MS = 30000;
21156
- var LOGIN_TIMEOUT_MS = 180000;
21157
- var LOGIN_INSTRUCTION = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21377
+ var STEP_TIMEOUT_MS2 = 30000;
21378
+ var LOGIN_TIMEOUT_MS2 = 180000;
21379
+ var LOGIN_INSTRUCTION2 = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21158
21380
  var LIVE_URL_ID_RE = /\/articles?\/(\d+)/;
21159
- var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21381
+ var COVER_EXTS2 = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21160
21382
  var isArticleAuthenticated = async (page) => {
21161
- if (LOGIN_URL_RE.test(page.url()))
21383
+ if (LOGIN_URL_RE2.test(page.url()))
21162
21384
  return false;
21163
21385
  if ((await trySelectors(page, ARTICLE_SELECTORS.write, { visible: false })).found)
21164
21386
  return true;
@@ -21168,26 +21390,26 @@ var ARTICLE_CONFIG = {
21168
21390
  channel: ARTICLE_CHANNEL,
21169
21391
  homeUrl: X_ARTICLES_URL,
21170
21392
  isAuthenticated: isArticleAuthenticated,
21171
- loginTimeoutMs: LOGIN_TIMEOUT_MS,
21393
+ loginTimeoutMs: LOGIN_TIMEOUT_MS2,
21172
21394
  checkHeadedOnly: true
21173
21395
  };
21174
- function errorMessage3(error) {
21396
+ function errorMessage4(error) {
21175
21397
  return error instanceof Error ? error.message : String(error);
21176
21398
  }
21177
- function needsLogin(error) {
21399
+ function needsLogin2(error) {
21178
21400
  return error instanceof LoginTimeoutError || error instanceof BrowserProfileMissingError;
21179
21401
  }
21180
- async function resolveCover(options, content) {
21402
+ async function resolveCover2(options, content) {
21181
21403
  const raw = options?.coverPath ?? content.metadata?.coverImage;
21182
21404
  if (raw === undefined)
21183
21405
  return;
21184
21406
  if (typeof raw !== "string" || raw.trim().length === 0) {
21185
21407
  return { error: `cover path must be a non-empty local file path, got '${String(raw)}'` };
21186
21408
  }
21187
- if (!isAbsolute2(raw)) {
21409
+ if (!isAbsolute3(raw)) {
21188
21410
  return { error: `cover path must be an absolute path, got '${raw}'` };
21189
21411
  }
21190
- if (!COVER_EXTS.has(extname(raw).toLowerCase())) {
21412
+ if (!COVER_EXTS2.has(extname2(raw).toLowerCase())) {
21191
21413
  return { error: `cover path must be a .png, .jpg, .jpeg or .webp file, got '${raw}'` };
21192
21414
  }
21193
21415
  if (!await createNodeFileSystem().exists(raw)) {
@@ -21204,19 +21426,19 @@ class XArticleBrowserTransport {
21204
21426
  constructor(driver = "script", deps = {}) {
21205
21427
  this.driver = driver;
21206
21428
  this.launcher = deps.launcher ?? kkBrowserLauncher;
21207
- this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21429
+ this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS2;
21208
21430
  }
21209
21431
  async publish(payload) {
21210
21432
  if (this.driver !== "script") {
21211
- return fail(`unsupported driver '${this.driver}' for x article`);
21433
+ return fail2(`unsupported driver '${this.driver}' for x article`);
21212
21434
  }
21213
21435
  const requested = payload.content.metadata?.publishStatus;
21214
21436
  if (requested !== undefined && requested !== "draft" && requested !== "public") {
21215
- return fail(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
21437
+ return fail2(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
21216
21438
  }
21217
- const cover = await resolveCover(payload.options, payload.content);
21439
+ const cover = await resolveCover2(payload.options, payload.content);
21218
21440
  if (cover !== undefined && "error" in cover)
21219
- return fail(cover.error);
21441
+ return fail2(cover.error);
21220
21442
  const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
21221
21443
  const profileDir = resolveChannelProfileDir(ARTICLE_CHANNEL, override);
21222
21444
  const session = await checkChannelSession(ARTICLE_CONFIG, {
@@ -21226,7 +21448,7 @@ class XArticleBrowserTransport {
21226
21448
  timeoutMs: this.stepTimeoutMs
21227
21449
  });
21228
21450
  if (session.status !== "verified") {
21229
- return fail(`${TARGET} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
21451
+ return fail2(`${TARGET2} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION2}`);
21230
21452
  }
21231
21453
  const publishStatus = requested === "public" ? "public" : "draft";
21232
21454
  try {
@@ -21239,8 +21461,8 @@ class XArticleBrowserTransport {
21239
21461
  timeoutMs: this.stepTimeoutMs
21240
21462
  }, async ({ page }) => this.runArticleFlow(page, payload.content, publishStatus, cover?.path, profileDir));
21241
21463
  } catch (error) {
21242
- const hint = needsLogin(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION}` : "";
21243
- return fail(`${errorMessage3(error)}${hint}`);
21464
+ const hint = needsLogin2(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION2}` : "";
21465
+ return fail2(`${errorMessage4(error)}${hint}`);
21244
21466
  }
21245
21467
  }
21246
21468
  async runArticleFlow(page, content, publishStatus, coverPath, profileDir) {
@@ -21273,22 +21495,22 @@ class XArticleBrowserTransport {
21273
21495
  await page.locator('[role="dialog"] button:has-text("Apply") >> visible=true').first().click({ timeout: this.stepTimeoutMs });
21274
21496
  const attached = await expectOutcome(async () => await page.evaluate(coverAttachedScript()) === true ? "cover image rendered in composer" : null, { timeoutMs: this.stepTimeoutMs, label: "cover attachment" });
21275
21497
  if (!attached.ok)
21276
- return fail(attached.error);
21498
+ return fail2(attached.error);
21277
21499
  }
21278
21500
  const draft = await expectOutcome(() => probeDraft(page), {
21279
21501
  timeoutMs: this.stepTimeoutMs,
21280
21502
  label: "x article draft"
21281
21503
  });
21282
21504
  if (!draft.ok)
21283
- return fail(draft.error);
21505
+ return fail2(draft.error);
21284
21506
  const id = ARTICLE_EDIT_RE.exec(draft.evidence)?.[1];
21285
21507
  if (publishStatus === "draft") {
21286
21508
  return ResultSchema.parse({
21287
21509
  ok: true,
21288
- target: TARGET,
21510
+ target: TARGET2,
21289
21511
  ...id === undefined ? {} : { id },
21290
21512
  url: draft.evidence,
21291
- message: `${TARGET} article draft saved (unpublished) in profile ${profileDir}`,
21513
+ message: `${TARGET2} article draft saved (unpublished) in profile ${profileDir}`,
21292
21514
  metadata
21293
21515
  });
21294
21516
  }
@@ -21302,13 +21524,13 @@ class XArticleBrowserTransport {
21302
21524
  label: `x article publish '${publishSelector}'`
21303
21525
  });
21304
21526
  if (!live.ok)
21305
- return fail(live.error);
21527
+ return fail2(live.error);
21306
21528
  return ResultSchema.parse({
21307
21529
  ok: true,
21308
- target: TARGET,
21530
+ target: TARGET2,
21309
21531
  ...id === undefined ? {} : { id },
21310
21532
  url: live.evidence,
21311
- message: `${TARGET} article published live in profile ${profileDir}`,
21533
+ message: `${TARGET2} article published live in profile ${profileDir}`,
21312
21534
  metadata
21313
21535
  });
21314
21536
  }
@@ -21328,7 +21550,9 @@ function getPublishTransport(operation = "post") {
21328
21550
  if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === "fake") {
21329
21551
  return operation === "article" ? new FakeBrowserTransport("script") : new FakeFileCliTransport;
21330
21552
  }
21331
- return operation === "article" ? new XArticleBrowserTransport : new XPostApiTransport;
21553
+ if (operation === "article")
21554
+ return new XArticleBrowserTransport;
21555
+ return process.env.X_POST_TRANSPORT === "api" ? new XPostApiTransport : new XPostBrowserTransport;
21332
21556
  }
21333
21557
  async function writePublishResult(outputPath, result) {
21334
21558
  const outDir = dirname4(outputPath);
@@ -21348,12 +21572,12 @@ async function processPublishIO(inputPath, outputPath, transport) {
21348
21572
  }
21349
21573
  } catch (error) {
21350
21574
  const message = `Invalid Content input: ${error instanceof Error ? error.message : String(error)}`;
21351
- await writePublishResult(outputPath, fail(message));
21575
+ await writePublishResult(outputPath, fail2(message));
21352
21576
  throw new Error(message);
21353
21577
  }
21354
21578
  const mode = resolveOperation(options, content);
21355
21579
  if (mode.error !== undefined) {
21356
- await writePublishResult(outputPath, fail(mode.error));
21580
+ await writePublishResult(outputPath, fail2(mode.error));
21357
21581
  throw new Error(mode.error);
21358
21582
  }
21359
21583
  const operation = mode.operation;
@@ -21391,13 +21615,19 @@ export {
21391
21615
  ARTICLE_CONFIG,
21392
21616
  ARTICLE_EDIT_RE,
21393
21617
  ARTICLE_SELECTORS,
21394
- LOGIN_URL_RE,
21618
+ LOGIN_URL_RE2 as LOGIN_URL_RE,
21619
+ POST_CONFIG,
21620
+ POST_SELECTORS,
21395
21621
  XArticleBrowserTransport,
21396
21622
  XPostApiTransport,
21397
21623
  X_ARTICLES_URL,
21624
+ X_NEW_POST_BUTTON,
21398
21625
  X_OPERATIONS,
21626
+ X_POST_SUBMIT,
21627
+ X_POST_URL,
21399
21628
  getPublishTransport,
21400
21629
  isArticleAuthenticated,
21630
+ isPostAuthenticated,
21401
21631
  main2 as main,
21402
21632
  oauth1Header,
21403
21633
  processPublishIO,