@gobing-ai/knowledge-kit 0.1.19 → 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 (54) 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 +1379 -378
  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 +3 -0
  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/daily-ai-voice.json +48 -7
  19. package/plugins/kk/scripts/daily-stages.ts +238 -14
  20. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  21. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  22. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  23. package/plugins/kk/skills/publish/SKILL.md +11 -0
  24. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  25. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  26. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
  27. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
  28. package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
  29. package/plugins/publishings/linkedin-pub/dist/profile-check.js +32 -5
  30. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  31. package/plugins/publishings/shipinhao-pub/dist/index.js +385 -31
  32. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +3 -1
  33. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  34. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
  35. package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
  36. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  37. package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
  38. package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
  39. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
  40. package/plugins/publishings/threads-pub/dist/index.js +9196 -296
  41. package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
  42. package/plugins/publishings/threads-pub/package.json +3 -1
  43. package/plugins/publishings/threads-pub/plugin.json +6 -1
  44. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  45. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  46. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  47. package/plugins/publishings/wechatmp-pub/dist/index.js +7 -0
  48. package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
  49. package/plugins/publishings/weibo-pub/dist/index.js +46 -2
  50. package/plugins/publishings/weibo-pub/src/index.ts +74 -2
  51. package/plugins/publishings/x-pub/dist/index.js +263 -43
  52. package/plugins/publishings/x-pub/dist/profile-check.js +3 -1
  53. package/plugins/publishings/x-pub/src/index.ts +15 -1
  54. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
@@ -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
@@ -21043,12 +21043,224 @@ function editorTextScript(selector) {
21043
21043
 
21044
21044
  // ../../plugins/publishings/x-pub/src/index.ts
21045
21045
  init_dist();
21046
- var REQUEST_TIMEOUT_MS = 120000;
21046
+
21047
+ // ../../plugins/publishings/x-pub/src/post-rail.ts
21048
+ import { extname, isAbsolute as isAbsolute2 } from "path";
21047
21049
  var TARGET = "x";
21050
+ var LOGIN_INSTRUCTION = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21051
+ var STEP_TIMEOUT_MS = 30000;
21052
+ var LOGIN_TIMEOUT_MS = 180000;
21053
+ var LOGIN_URL_RE = /\/(?:i\/flow\/login|login|account\/access)/;
21054
+ var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21055
+ var X_POST_URL = "https://x.com/home";
21056
+ var X_NEW_POST_BUTTON = '[data-testid="SideNav_NewTweet_Button"]';
21057
+ var X_COMPOSE_PATH = "/compose/post";
21058
+ var X_POST_SUBMIT = '[data-testid="tweetButton"]';
21059
+ var POST_SELECTORS = {
21060
+ text: ['[data-testid="tweetTextarea_0"]'],
21061
+ mediaButton: ['button[aria-label="Add photos or video"]', '[aria-label*="Add photos" i]'],
21062
+ fileInput: ['input[data-testid="fileInput"]', '[data-testid="fileInput"]'],
21063
+ mediaPreview: ['[data-testid="attachments"]', '[aria-label*="Media" i]'],
21064
+ profileLink: ['a[data-testid="AppTabBar_Profile_Link"]']
21065
+ };
21066
+ var isPostAuthenticated = async (page) => {
21067
+ if (LOGIN_URL_RE.test(page.url()))
21068
+ return false;
21069
+ return (await trySelectors(page, [X_NEW_POST_BUTTON], { visible: false })).found;
21070
+ };
21071
+ var POST_CONFIG = {
21072
+ channel: TARGET,
21073
+ homeUrl: X_POST_URL,
21074
+ isAuthenticated: isPostAuthenticated,
21075
+ loginTimeoutMs: LOGIN_TIMEOUT_MS,
21076
+ checkHeadedOnly: true
21077
+ };
21078
+ function fail(error) {
21079
+ return ResultSchema.parse({ ok: false, target: TARGET, error, effect: "none" });
21080
+ }
21081
+ function needsLogin(error) {
21082
+ const text = error instanceof Error ? error.message : String(error);
21083
+ return /login|sign in|logged out/i.test(text);
21084
+ }
21085
+ function errorMessage3(error) {
21086
+ return error instanceof Error ? error.message : String(error);
21087
+ }
21088
+ async function resolveCover(raw, fs = createNodeFileSystem()) {
21089
+ if (raw === undefined)
21090
+ return;
21091
+ if (typeof raw !== "string" || raw.trim() === "") {
21092
+ return { error: `x post cover must be a non-empty local path, got '${String(raw)}'` };
21093
+ }
21094
+ if (!isAbsolute2(raw))
21095
+ return { error: `x post cover must be an absolute path, got '${raw}'` };
21096
+ if (!COVER_EXTS.has(extname(raw).toLowerCase())) {
21097
+ return { error: `x post cover must be .png/.jpg/.jpeg/.webp, got '${extname(raw) || "(none)"}'` };
21098
+ }
21099
+ if (!await fs.exists(raw))
21100
+ return { error: `x post cover does not exist: ${raw}` };
21101
+ return { path: raw };
21102
+ }
21103
+
21104
+ class XPostBrowserTransport {
21105
+ kind = "browser";
21106
+ launcher;
21107
+ stepTimeoutMs;
21108
+ constructor(deps = {}) {
21109
+ this.launcher = deps.launcher ?? kkBrowserLauncher;
21110
+ this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21111
+ }
21112
+ async publish(payload) {
21113
+ const requested = payload.content.metadata?.publishStatus;
21114
+ if (requested === "draft") {
21115
+ return fail("x post has no draft: the compose surface publishes immediately \u2014 plan this target dummy/off or launch it live");
21116
+ }
21117
+ if (requested !== undefined && requested !== "public") {
21118
+ return fail(`unknown publishStatus '${requested}' for x post: expected 'public' or absent`);
21119
+ }
21120
+ const text = (payload.content.body ?? payload.content.title ?? "").trim();
21121
+ if (text === "")
21122
+ return fail("x post requires non-empty Content.body or Content.title");
21123
+ const cover = await resolveCover(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? payload.content.metadata?.coverImage);
21124
+ if (cover !== undefined && "error" in cover)
21125
+ return fail(cover.error);
21126
+ const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
21127
+ const profileDir = resolveChannelProfileDir(POST_CONFIG.channel, override);
21128
+ const session = await checkChannelSession(POST_CONFIG, {
21129
+ profileDir,
21130
+ launcher: this.launcher,
21131
+ headedOnly: true,
21132
+ timeoutMs: this.stepTimeoutMs
21133
+ });
21134
+ if (session.status !== "verified") {
21135
+ return fail(`${TARGET} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
21136
+ }
21137
+ try {
21138
+ return await withProfilePage({
21139
+ profileDir,
21140
+ url: X_POST_URL,
21141
+ isAuthenticated: isPostAuthenticated,
21142
+ headless: payload.options?.headless === true,
21143
+ launcher: this.launcher,
21144
+ timeoutMs: this.stepTimeoutMs
21145
+ }, async ({ page }) => this.runPostFlow(page, text, cover !== undefined && "path" in cover ? cover.path : undefined, profileDir));
21146
+ } catch (error) {
21147
+ const hint = needsLogin(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION}` : "";
21148
+ return fail(`${errorMessage3(error)}${hint}`);
21149
+ }
21150
+ }
21151
+ async newestStatusId(page, handleHref) {
21152
+ const target = `https://x.com${handleHref}`;
21153
+ if (!page.url().startsWith(target)) {
21154
+ await page.goto(target, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
21155
+ } else {
21156
+ await page.reload({ waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs }).catch(() => {});
21157
+ }
21158
+ const link = page.locator('[data-testid="tweet"] a[href*="/status/"]').first();
21159
+ if (await link.count() === 0)
21160
+ return null;
21161
+ const href = await link.getAttribute("href").catch(() => null);
21162
+ return href === null ? null : /\/status\/(\d+)/.exec(href)?.[1] ?? null;
21163
+ }
21164
+ async openComposer(page) {
21165
+ if (!page.url().includes(X_COMPOSE_PATH)) {
21166
+ if (!page.url().startsWith("https://x.com/home")) {
21167
+ await page.goto(X_POST_URL, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
21168
+ }
21169
+ 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" });
21170
+ if (!opener.ok)
21171
+ return `x home never rendered the Post button: ${opener.error}`;
21172
+ await page.locator(X_NEW_POST_BUTTON).first().click();
21173
+ }
21174
+ const composer = await expectOutcome(async () => {
21175
+ if (!page.url().includes(X_COMPOSE_PATH))
21176
+ return null;
21177
+ return await page.locator(POST_SELECTORS.text[0]).count() > 0 ? "composer open" : null;
21178
+ }, { timeoutMs: this.stepTimeoutMs, label: "x compose/post surface" });
21179
+ return composer.ok ? null : `x composer never opened at ${X_COMPOSE_PATH}: ${composer.error}`;
21180
+ }
21181
+ async typeAndEnable(page, text) {
21182
+ const textBox = page.locator(POST_SELECTORS.text[0]).first();
21183
+ const submit = page.locator(X_POST_SUBMIT).first();
21184
+ for (let attempt = 1;attempt <= 3; attempt++) {
21185
+ await page.keyboard.press("Escape").catch(() => {});
21186
+ await page.waitForTimeout(250);
21187
+ const focused = await textBox.click({ force: true }).then(() => true, () => textBox.focus().then(() => true).catch(() => false));
21188
+ if (!focused)
21189
+ return "x composer editor could not be focused";
21190
+ await page.waitForTimeout(300);
21191
+ await textBox.press("ControlOrMeta+a").catch(() => {});
21192
+ await textBox.press("Backspace").catch(() => {});
21193
+ await textBox.pressSequentially(text, { delay: 8 });
21194
+ 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})` });
21195
+ if (enabled.ok)
21196
+ return null;
21197
+ }
21198
+ return "x post submit never enabled \u2014 the editor did not accept the text in three attempts";
21199
+ }
21200
+ async runPostFlow(page, text, coverPath, profileDir) {
21201
+ const metadata = { operation: "post", driver: "script", publishStatus: "public", profileDir };
21202
+ const handle = await page.locator(POST_SELECTORS.profileLink[0]).first().getAttribute("href").catch(() => null);
21203
+ if (handle === null || handle.trim() === "") {
21204
+ return fail("x post could not read the profile link, so the status id cannot be confirmed");
21205
+ }
21206
+ const baselineId = await this.newestStatusId(page, handle).catch(() => null);
21207
+ const opened = await this.openComposer(page);
21208
+ if (opened !== null)
21209
+ return fail(opened);
21210
+ const typed = await this.typeAndEnable(page, text);
21211
+ if (typed !== null)
21212
+ return fail(`${typed}; refusing to claim a publish`);
21213
+ if (coverPath !== undefined) {
21214
+ const media = await expectOutcome(async () => {
21215
+ const found = await trySelectors(page, POST_SELECTORS.mediaButton);
21216
+ return found.found ? found.selector ?? POST_SELECTORS.mediaButton[0] : null;
21217
+ }, { timeoutMs: this.stepTimeoutMs, label: "x media button" });
21218
+ if (!media.ok)
21219
+ return fail(`x media control never attached: ${media.error}`);
21220
+ await page.locator(media.evidence).first().click();
21221
+ const input = await resolveSelector(page, POST_SELECTORS.fileInput, {
21222
+ timeoutMs: this.stepTimeoutMs,
21223
+ label: "x post media input"
21224
+ });
21225
+ await uploadFile(page, input, coverPath, { timeoutMs: this.stepTimeoutMs });
21226
+ const attached = await expectOutcome(async () => await page.locator(POST_SELECTORS.mediaPreview[0]).count() > 0 ? "media attached" : null, { timeoutMs: this.stepTimeoutMs, label: "x post media" });
21227
+ if (!attached.ok)
21228
+ return fail(`x post image was uploaded but never rendered: ${attached.error}`);
21229
+ 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" });
21230
+ if (!reEnabled.ok)
21231
+ return fail(`x post submit stayed disabled after the media: ${reEnabled.error}`);
21232
+ }
21233
+ await page.locator(X_POST_SUBMIT).first().click();
21234
+ const receipt = await expectOutcome(async () => {
21235
+ const id = await this.newestStatusId(page, handle);
21236
+ if (id === null)
21237
+ return null;
21238
+ if (baselineId !== null && id === baselineId)
21239
+ return null;
21240
+ return `https://x.com${handle}/status/${id}`;
21241
+ }, { timeoutMs: this.stepTimeoutMs, label: "x status receipt" });
21242
+ if (!receipt.ok) {
21243
+ 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`);
21244
+ }
21245
+ const id = /\/status\/(\d+)/.exec(receipt.evidence)?.[1];
21246
+ return ResultSchema.parse({
21247
+ ok: true,
21248
+ target: TARGET,
21249
+ ...id === undefined ? {} : { id },
21250
+ url: receipt.evidence,
21251
+ message: `x post published and confirmed in profile ${profileDir}`,
21252
+ metadata: { ...metadata, confirmedBy: "profile-timeline" }
21253
+ });
21254
+ }
21255
+ }
21256
+
21257
+ // ../../plugins/publishings/x-pub/src/index.ts
21258
+ var REQUEST_TIMEOUT_MS = 120000;
21259
+ var TARGET2 = "x";
21048
21260
  var TWEETS_URL = "https://api.twitter.com/2/tweets";
21049
21261
  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 });
21262
+ function fail2(error) {
21263
+ return ResultSchema.parse({ ok: false, target: TARGET2, error });
21052
21264
  }
21053
21265
  function percentEncode(value) {
21054
21266
  return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
@@ -21085,21 +21297,21 @@ class XPostApiTransport {
21085
21297
  async publish(payload) {
21086
21298
  const requestedStatus = payload.content.metadata?.publishStatus;
21087
21299
  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");
21300
+ return fail2("x post has no draft: the post API publishes immediately \u2014 plan this target dummy/off or launch it live");
21089
21301
  }
21090
21302
  if (requestedStatus !== undefined && requestedStatus !== "public") {
21091
- return fail(`unknown publishStatus '${String(requestedStatus)}' (expected absent, 'draft' or 'public')`);
21303
+ return fail2(`unknown publishStatus '${String(requestedStatus)}' (expected absent, 'draft' or 'public')`);
21092
21304
  }
21093
21305
  const missing = TOKEN_ENVS.filter((key) => {
21094
21306
  const value = process.env[key];
21095
21307
  return !value || value.trim().length === 0;
21096
21308
  });
21097
21309
  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).`);
21310
+ 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
21311
  }
21100
21312
  const text = payload.content.body.trim() || payload.content.title?.trim() || "";
21101
21313
  if (text.length === 0) {
21102
- return fail("X post requires Content.body or Content.title");
21314
+ return fail2("X post requires Content.body or Content.title");
21103
21315
  }
21104
21316
  try {
21105
21317
  const authorization = oauth1Header({
@@ -21121,29 +21333,29 @@ class XPostApiTransport {
21121
21333
  });
21122
21334
  if (!response.ok) {
21123
21335
  const errorText = (await response.text()).slice(0, 1000);
21124
- return fail(`X POST /2/tweets failed (HTTP ${response.status}): ${errorText.trim() || response.statusText}`);
21336
+ return fail2(`X POST /2/tweets failed (HTTP ${response.status}): ${errorText.trim() || response.statusText}`);
21125
21337
  }
21126
21338
  const json = await response.json();
21127
21339
  if (typeof json.data?.id !== "string") {
21128
- return fail("X POST /2/tweets response missing data.id");
21340
+ return fail2("X POST /2/tweets response missing data.id");
21129
21341
  }
21130
21342
  return ResultSchema.parse({
21131
21343
  ok: true,
21132
- target: TARGET,
21344
+ target: TARGET2,
21133
21345
  id: json.data.id,
21134
21346
  url: `https://x.com/i/web/status/${json.data.id}`,
21135
21347
  message: "Posted via X API v2",
21136
21348
  metadata: { operation: "post" }
21137
21349
  });
21138
21350
  } catch (err) {
21139
- return fail(`X post transport error: ${err instanceof Error ? err.message : String(err)}`);
21351
+ return fail2(`X post transport error: ${err instanceof Error ? err.message : String(err)}`);
21140
21352
  }
21141
21353
  }
21142
21354
  }
21143
21355
  var ARTICLE_CHANNEL = "x";
21144
21356
  var X_ARTICLES_URL = "https://x.com/compose/articles";
21145
21357
  var ARTICLE_EDIT_RE = /\/compose\/articles\/edit\/(\d+)/;
21146
- var LOGIN_URL_RE = /(\/i\/flow\/login|\/login)/;
21358
+ var LOGIN_URL_RE2 = /(\/i\/flow\/login|\/login)/;
21147
21359
  var ARTICLE_SELECTORS = {
21148
21360
  write: ['[data-testid="empty_state_button_text"]', 'button:has-text("Write")', '[aria-label*="Write" i]'],
21149
21361
  title: ['textarea[placeholder="Add a title"]', '[data-testid="twitter-article-title"]'],
@@ -21152,13 +21364,13 @@ var ARTICLE_SELECTORS = {
21152
21364
  fileInput: ['[data-testid="fileInput"]', 'input[type="file"][accept*="image"]'],
21153
21365
  publish: ['[data-testid="publishButton"]', 'button:has-text("Publish")']
21154
21366
  };
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";
21367
+ var STEP_TIMEOUT_MS2 = 30000;
21368
+ var LOGIN_TIMEOUT_MS2 = 180000;
21369
+ var LOGIN_INSTRUCTION2 = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21158
21370
  var LIVE_URL_ID_RE = /\/articles?\/(\d+)/;
21159
- var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21371
+ var COVER_EXTS2 = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21160
21372
  var isArticleAuthenticated = async (page) => {
21161
- if (LOGIN_URL_RE.test(page.url()))
21373
+ if (LOGIN_URL_RE2.test(page.url()))
21162
21374
  return false;
21163
21375
  if ((await trySelectors(page, ARTICLE_SELECTORS.write, { visible: false })).found)
21164
21376
  return true;
@@ -21168,26 +21380,26 @@ var ARTICLE_CONFIG = {
21168
21380
  channel: ARTICLE_CHANNEL,
21169
21381
  homeUrl: X_ARTICLES_URL,
21170
21382
  isAuthenticated: isArticleAuthenticated,
21171
- loginTimeoutMs: LOGIN_TIMEOUT_MS,
21383
+ loginTimeoutMs: LOGIN_TIMEOUT_MS2,
21172
21384
  checkHeadedOnly: true
21173
21385
  };
21174
- function errorMessage3(error) {
21386
+ function errorMessage4(error) {
21175
21387
  return error instanceof Error ? error.message : String(error);
21176
21388
  }
21177
- function needsLogin(error) {
21389
+ function needsLogin2(error) {
21178
21390
  return error instanceof LoginTimeoutError || error instanceof BrowserProfileMissingError;
21179
21391
  }
21180
- async function resolveCover(options, content) {
21392
+ async function resolveCover2(options, content) {
21181
21393
  const raw = options?.coverPath ?? content.metadata?.coverImage;
21182
21394
  if (raw === undefined)
21183
21395
  return;
21184
21396
  if (typeof raw !== "string" || raw.trim().length === 0) {
21185
21397
  return { error: `cover path must be a non-empty local file path, got '${String(raw)}'` };
21186
21398
  }
21187
- if (!isAbsolute2(raw)) {
21399
+ if (!isAbsolute3(raw)) {
21188
21400
  return { error: `cover path must be an absolute path, got '${raw}'` };
21189
21401
  }
21190
- if (!COVER_EXTS.has(extname(raw).toLowerCase())) {
21402
+ if (!COVER_EXTS2.has(extname2(raw).toLowerCase())) {
21191
21403
  return { error: `cover path must be a .png, .jpg, .jpeg or .webp file, got '${raw}'` };
21192
21404
  }
21193
21405
  if (!await createNodeFileSystem().exists(raw)) {
@@ -21204,19 +21416,19 @@ class XArticleBrowserTransport {
21204
21416
  constructor(driver = "script", deps = {}) {
21205
21417
  this.driver = driver;
21206
21418
  this.launcher = deps.launcher ?? kkBrowserLauncher;
21207
- this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21419
+ this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS2;
21208
21420
  }
21209
21421
  async publish(payload) {
21210
21422
  if (this.driver !== "script") {
21211
- return fail(`unsupported driver '${this.driver}' for x article`);
21423
+ return fail2(`unsupported driver '${this.driver}' for x article`);
21212
21424
  }
21213
21425
  const requested = payload.content.metadata?.publishStatus;
21214
21426
  if (requested !== undefined && requested !== "draft" && requested !== "public") {
21215
- return fail(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
21427
+ return fail2(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
21216
21428
  }
21217
- const cover = await resolveCover(payload.options, payload.content);
21429
+ const cover = await resolveCover2(payload.options, payload.content);
21218
21430
  if (cover !== undefined && "error" in cover)
21219
- return fail(cover.error);
21431
+ return fail2(cover.error);
21220
21432
  const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
21221
21433
  const profileDir = resolveChannelProfileDir(ARTICLE_CHANNEL, override);
21222
21434
  const session = await checkChannelSession(ARTICLE_CONFIG, {
@@ -21226,7 +21438,7 @@ class XArticleBrowserTransport {
21226
21438
  timeoutMs: this.stepTimeoutMs
21227
21439
  });
21228
21440
  if (session.status !== "verified") {
21229
- return fail(`${TARGET} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
21441
+ return fail2(`${TARGET2} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION2}`);
21230
21442
  }
21231
21443
  const publishStatus = requested === "public" ? "public" : "draft";
21232
21444
  try {
@@ -21239,8 +21451,8 @@ class XArticleBrowserTransport {
21239
21451
  timeoutMs: this.stepTimeoutMs
21240
21452
  }, async ({ page }) => this.runArticleFlow(page, payload.content, publishStatus, cover?.path, profileDir));
21241
21453
  } catch (error) {
21242
- const hint = needsLogin(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION}` : "";
21243
- return fail(`${errorMessage3(error)}${hint}`);
21454
+ const hint = needsLogin2(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION2}` : "";
21455
+ return fail2(`${errorMessage4(error)}${hint}`);
21244
21456
  }
21245
21457
  }
21246
21458
  async runArticleFlow(page, content, publishStatus, coverPath, profileDir) {
@@ -21273,22 +21485,22 @@ class XArticleBrowserTransport {
21273
21485
  await page.locator('[role="dialog"] button:has-text("Apply") >> visible=true').first().click({ timeout: this.stepTimeoutMs });
21274
21486
  const attached = await expectOutcome(async () => await page.evaluate(coverAttachedScript()) === true ? "cover image rendered in composer" : null, { timeoutMs: this.stepTimeoutMs, label: "cover attachment" });
21275
21487
  if (!attached.ok)
21276
- return fail(attached.error);
21488
+ return fail2(attached.error);
21277
21489
  }
21278
21490
  const draft = await expectOutcome(() => probeDraft(page), {
21279
21491
  timeoutMs: this.stepTimeoutMs,
21280
21492
  label: "x article draft"
21281
21493
  });
21282
21494
  if (!draft.ok)
21283
- return fail(draft.error);
21495
+ return fail2(draft.error);
21284
21496
  const id = ARTICLE_EDIT_RE.exec(draft.evidence)?.[1];
21285
21497
  if (publishStatus === "draft") {
21286
21498
  return ResultSchema.parse({
21287
21499
  ok: true,
21288
- target: TARGET,
21500
+ target: TARGET2,
21289
21501
  ...id === undefined ? {} : { id },
21290
21502
  url: draft.evidence,
21291
- message: `${TARGET} article draft saved (unpublished) in profile ${profileDir}`,
21503
+ message: `${TARGET2} article draft saved (unpublished) in profile ${profileDir}`,
21292
21504
  metadata
21293
21505
  });
21294
21506
  }
@@ -21302,13 +21514,13 @@ class XArticleBrowserTransport {
21302
21514
  label: `x article publish '${publishSelector}'`
21303
21515
  });
21304
21516
  if (!live.ok)
21305
- return fail(live.error);
21517
+ return fail2(live.error);
21306
21518
  return ResultSchema.parse({
21307
21519
  ok: true,
21308
- target: TARGET,
21520
+ target: TARGET2,
21309
21521
  ...id === undefined ? {} : { id },
21310
21522
  url: live.evidence,
21311
- message: `${TARGET} article published live in profile ${profileDir}`,
21523
+ message: `${TARGET2} article published live in profile ${profileDir}`,
21312
21524
  metadata
21313
21525
  });
21314
21526
  }
@@ -21328,7 +21540,9 @@ function getPublishTransport(operation = "post") {
21328
21540
  if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === "fake") {
21329
21541
  return operation === "article" ? new FakeBrowserTransport("script") : new FakeFileCliTransport;
21330
21542
  }
21331
- return operation === "article" ? new XArticleBrowserTransport : new XPostApiTransport;
21543
+ if (operation === "article")
21544
+ return new XArticleBrowserTransport;
21545
+ return process.env.X_POST_TRANSPORT === "api" ? new XPostApiTransport : new XPostBrowserTransport;
21332
21546
  }
21333
21547
  async function writePublishResult(outputPath, result) {
21334
21548
  const outDir = dirname4(outputPath);
@@ -21348,12 +21562,12 @@ async function processPublishIO(inputPath, outputPath, transport) {
21348
21562
  }
21349
21563
  } catch (error) {
21350
21564
  const message = `Invalid Content input: ${error instanceof Error ? error.message : String(error)}`;
21351
- await writePublishResult(outputPath, fail(message));
21565
+ await writePublishResult(outputPath, fail2(message));
21352
21566
  throw new Error(message);
21353
21567
  }
21354
21568
  const mode = resolveOperation(options, content);
21355
21569
  if (mode.error !== undefined) {
21356
- await writePublishResult(outputPath, fail(mode.error));
21570
+ await writePublishResult(outputPath, fail2(mode.error));
21357
21571
  throw new Error(mode.error);
21358
21572
  }
21359
21573
  const operation = mode.operation;
@@ -21391,13 +21605,19 @@ export {
21391
21605
  ARTICLE_CONFIG,
21392
21606
  ARTICLE_EDIT_RE,
21393
21607
  ARTICLE_SELECTORS,
21394
- LOGIN_URL_RE,
21608
+ LOGIN_URL_RE2 as LOGIN_URL_RE,
21609
+ POST_CONFIG,
21610
+ POST_SELECTORS,
21395
21611
  XArticleBrowserTransport,
21396
21612
  XPostApiTransport,
21397
21613
  X_ARTICLES_URL,
21614
+ X_NEW_POST_BUTTON,
21398
21615
  X_OPERATIONS,
21616
+ X_POST_SUBMIT,
21617
+ X_POST_URL,
21399
21618
  getPublishTransport,
21400
21619
  isArticleAuthenticated,
21620
+ isPostAuthenticated,
21401
21621
  main2 as main,
21402
21622
  oauth1Header,
21403
21623
  processPublishIO,
@@ -21100,6 +21100,8 @@ if (false) {}
21100
21100
  var CJK_TERMINATORS = new Set(["\u3002", "\uFF01", "\uFF1F"]);
21101
21101
  var LATIN_TERMINATORS = new Set([".", "!", "?"]);
21102
21102
  var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
21103
+ // ../../plugins/publishings/x-pub/src/post-rail.ts
21104
+ var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21103
21105
  // ../../plugins/publishings/x-pub/src/index.ts
21104
21106
  var ARTICLE_CHANNEL = "x";
21105
21107
  var X_ARTICLES_URL = "https://x.com/compose/articles";
@@ -21113,7 +21115,7 @@ var ARTICLE_SELECTORS = {
21113
21115
  publish: ['[data-testid="publishButton"]', 'button:has-text("Publish")']
21114
21116
  };
21115
21117
  var LOGIN_TIMEOUT_MS = 180000;
21116
- var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21118
+ var COVER_EXTS2 = new Set([".png", ".jpg", ".jpeg", ".webp"]);
21117
21119
  var isArticleAuthenticated = async (page) => {
21118
21120
  if (LOGIN_URL_RE.test(page.url()))
21119
21121
  return false;
@@ -31,6 +31,16 @@ import {
31
31
  import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
32
32
  import { echoError } from '@gobing-ai/ts-utils';
33
33
  import type { Page } from 'playwright';
34
+ import { XPostBrowserTransport } from './post-rail';
35
+
36
+ export {
37
+ isPostAuthenticated,
38
+ POST_CONFIG,
39
+ POST_SELECTORS,
40
+ X_NEW_POST_BUTTON,
41
+ X_POST_SUBMIT,
42
+ X_POST_URL,
43
+ } from './post-rail';
34
44
 
35
45
  /** Per-request timeout (ms) for the X API call — Bun's `fetch` has no default deadline (R5). */
36
46
  const REQUEST_TIMEOUT_MS = 120_000;
@@ -463,7 +473,11 @@ export function getPublishTransport(operation: 'post' | 'article' = 'post'): Pub
463
473
  if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === 'fake') {
464
474
  return operation === 'article' ? new FakeBrowserTransport('script') : new FakeFileCliTransport();
465
475
  }
466
- return operation === 'article' ? new XArticleBrowserTransport() : new XPostApiTransport();
476
+ if (operation === 'article') return new XArticleBrowserTransport();
477
+ // kk bot first (2026-11-16 operator decision): the post rail drives the signed-in composer, so no
478
+ // X API credentials are needed. `X_POST_TRANSPORT=api` keeps the official API for callers that
479
+ // hold them.
480
+ return process.env.X_POST_TRANSPORT === 'api' ? new XPostApiTransport() : new XPostBrowserTransport();
467
481
  }
468
482
 
469
483
  async function writePublishResult(outputPath: string, result: Result): Promise<void> {