@gobing-ai/knowledge-kit 0.1.22 → 0.1.23

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 (59) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +165 -91
  3. package/package.json +1 -1
  4. package/plugins/generations/gemini-tts/dist/index.js +47 -7
  5. package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
  6. package/plugins/generations/music-gen/README.md +2 -2
  7. package/plugins/generations/music-gen/dist/index.js +46 -10
  8. package/plugins/generations/music-gen/presets/formats/song.yaml +6 -1
  9. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +6 -1
  10. package/plugins/generations/music-gen/src/adapter/instance.ts +34 -11
  11. package/plugins/generations/music-gen/src/presets.ts +36 -3
  12. package/plugins/generations/omni-voice-gen/uv.toml +5 -0
  13. package/plugins/generations/vibe-voice-tts/README.md +64 -0
  14. package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
  15. package/plugins/generations/vibe-voice-tts/package.json +16 -0
  16. package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
  17. package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
  18. package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
  19. package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
  20. package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
  21. package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
  22. package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
  23. package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
  24. package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
  25. package/plugins/generations/voice-gen/dist/index.js +31 -1
  26. package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
  27. package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
  28. package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
  29. package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
  30. package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
  31. package/plugins/generations/voxcpm-tts/uv.toml +5 -0
  32. package/plugins/kk/README.md +21 -0
  33. package/plugins/kk/decisions/kk-safety.yaml +5 -2
  34. package/plugins/kk/plugin.json +1 -1
  35. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +12 -1
  36. package/plugins/kk/scripts/daily-stages.ts +274 -40
  37. package/plugins/kk/scripts/kk-workflow-stages.ts +74 -11
  38. package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
  39. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +4 -3
  40. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -5
  41. package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
  42. package/plugins/kk/workflows/kk-music.yaml +20 -16
  43. package/plugins/kk/workflows/kk-news-generate.yaml +23 -3
  44. package/plugins/kk/workflows/kk-publish.yaml +4 -1
  45. package/plugins/publishings/linkedin-pub/dist/index.js +51 -9
  46. package/plugins/publishings/linkedin-pub/dist/profile-check.js +5 -0
  47. package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
  48. package/plugins/publishings/surfdash-pub/dist/index.js +8 -4
  49. package/plugins/publishings/surfdash-pub/src/index.ts +7 -1
  50. package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
  51. package/plugins/publishings/threads-pub/dist/index.js +47 -5
  52. package/plugins/publishings/threads-pub/dist/profile-check.js +7 -1
  53. package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
  54. package/plugins/publishings/wechatmp-pub/dist/index.js +94 -34
  55. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
  56. package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
  57. package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
  58. package/plugins/publishings/x-pub/dist/index.js +84 -9
  59. package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
@@ -2585,6 +2585,11 @@ async function runCgiDraft(input: ModeInput, deps: ModeRunDeps): Promise<Result
2585
2585
  publishStatus: deps.publishStatus,
2586
2586
  stage: error.stage,
2587
2587
  ...(error.metadata.ambiguousSubmission === true ? { ambiguousSubmission: true } : {}),
2588
+ // 0406 R4: the duplicate refusal dispatched nothing, so the row is honestly
2589
+ // `effect: none` — a bounded retry (not an operator resend) is the right next step.
2590
+ ...(error.code === 'duplicate-draft'
2591
+ ? { itcDelivery: { schemaVersion: 1, effect: 'none' as const } }
2592
+ : {}),
2588
2593
  },
2589
2594
  });
2590
2595
  }
@@ -2945,6 +2950,29 @@ export async function insertAudioMaterial(
2945
2950
  );
2946
2951
  }
2947
2952
  }
2953
+ if (!closed) {
2954
+ // 2026-11-20: the `完成` walk can leave the picker on screen (a
2955
+ // crop-confirm page whose 确定 sits outside the chooser subtree). Close
2956
+ // the PICKER only — the audio dialog behind it still holds the uploaded
2957
+ // file and the material title, so a global dialog sweep would discard
2958
+ // the audio we came for.
2959
+ const pickerClose = await tryFindSelector(
2960
+ page,
2961
+ [
2962
+ `${chooser} .weui-desktop-dialog__close-btn`,
2963
+ `${chooser} .weui-desktop-dialog__close`,
2964
+ `${chooser} button:has-text("取消")`,
2965
+ ],
2966
+ 3_000,
2967
+ );
2968
+ if (pickerClose !== undefined) {
2969
+ await clickSelector(page, pickerClose, 3_000);
2970
+ closed = await waitUntil(
2971
+ async () => !(await page.locator(chooser).first().isVisible()),
2972
+ 10_000,
2973
+ );
2974
+ }
2975
+ }
2948
2976
  if (!closed) {
2949
2977
  // Live 2026-11-09 this stall is real — capture WHAT is on screen (the
2950
2978
  // confirm dialog may not nest under the chooser selector, which would
@@ -21055,7 +21055,8 @@ function editorTextScript(selector) {
21055
21055
  init_dist();
21056
21056
 
21057
21057
  // ../../plugins/publishings/x-pub/src/post-rail.ts
21058
- import { extname, isAbsolute as isAbsolute2 } from "path";
21058
+ import { tmpdir } from "os";
21059
+ import { extname, isAbsolute as isAbsolute2, join as join6 } from "path";
21059
21060
  var TARGET = "x";
21060
21061
  var LOGIN_INSTRUCTION = "bun plugins/publishings/x-pub/src/profile-check.ts login";
21061
21062
  var STEP_TIMEOUT_MS = 30000;
@@ -21066,6 +21067,8 @@ var X_POST_URL = "https://x.com/home";
21066
21067
  var X_NEW_POST_BUTTON = '[data-testid="SideNav_NewTweet_Button"]';
21067
21068
  var X_COMPOSE_PATH = "/compose/post";
21068
21069
  var X_POST_SUBMIT = '[data-testid="tweetButton"]';
21070
+ var X_POST_SUBMIT_INLINE = '[data-testid="tweetButtonInline"]';
21071
+ var X_POST_SUBMITS = [X_POST_SUBMIT, X_POST_SUBMIT_INLINE];
21069
21072
  var POST_SELECTORS = {
21070
21073
  text: ['[data-testid="tweetTextarea_0"]'],
21071
21074
  mediaButton: ['button[aria-label="Add photos or video"]', '[aria-label*="Add photos" i]'],
@@ -21190,9 +21193,7 @@ class XPostBrowserTransport {
21190
21193
  }
21191
21194
  async typeAndEnable(page, text) {
21192
21195
  const textBox = page.locator(POST_SELECTORS.text[0]).first();
21193
- const submit = page.locator(X_POST_SUBMIT).first();
21194
21196
  for (let attempt = 1;attempt <= 3; attempt++) {
21195
- await page.keyboard.press("Escape").catch(() => {});
21196
21197
  await page.waitForTimeout(250);
21197
21198
  const focused = await textBox.click({ force: true }).then(() => true, () => textBox.focus().then(() => true).catch(() => false));
21198
21199
  if (!focused)
@@ -21201,7 +21202,13 @@ class XPostBrowserTransport {
21201
21202
  await textBox.press("ControlOrMeta+a").catch(() => {});
21202
21203
  await textBox.press("Backspace").catch(() => {});
21203
21204
  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
+ const enabled = await expectOutcome(async () => {
21206
+ for (const selector of X_POST_SUBMITS) {
21207
+ if (await page.locator(selector).first().isEnabled().catch(() => false))
21208
+ return "post enabled";
21209
+ }
21210
+ return null;
21211
+ }, { timeoutMs: Math.min(1e4, this.stepTimeoutMs), label: `x post enabled (attempt ${attempt})` });
21205
21212
  if (enabled.ok)
21206
21213
  return null;
21207
21214
  }
@@ -21237,10 +21244,58 @@ class XPostBrowserTransport {
21237
21244
  if (!attached.ok)
21238
21245
  return fail(`x post image was uploaded but never rendered: ${attached.error}`);
21239
21246
  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();
21247
+ if (!reEnabled.ok) {
21248
+ const observable = page;
21249
+ const evidence = await (observable.evaluate === undefined ? Promise.resolve(null) : observable.evaluate(`(() => {
21250
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
21251
+ const submit = document.querySelector('${X_POST_SUBMIT}');
21252
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
21253
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
21254
+ const images = [...document.querySelectorAll('[data-testid="attachments"] img, [data-testid="tweetPhoto"] img')].length;
21255
+ return JSON.stringify({
21256
+ textLen: (editor?.textContent || '').trim().length,
21257
+ submitDisabled: submit?.getAttribute('aria-disabled') ?? (submit?.disabled === true ? 'true' : 'false'),
21258
+ images,
21259
+ alerts,
21260
+ });
21261
+ })()`).catch(() => null));
21262
+ return fail(`x post submit stayed disabled after the media: ${reEnabled.error}${evidence ? ` \u2014 composer ${String(evidence)}` : ""}`);
21263
+ }
21264
+ }
21265
+ const submit = await (async () => {
21266
+ let enabledFallback = null;
21267
+ for (const selector of X_POST_SUBMITS) {
21268
+ const candidate = page.locator(selector).first();
21269
+ const enabled = await candidate.isEnabled().catch(() => false);
21270
+ if (!enabled)
21271
+ continue;
21272
+ const visible = await candidate.isVisible().catch(() => false);
21273
+ if (visible)
21274
+ return candidate;
21275
+ enabledFallback ??= candidate;
21276
+ }
21277
+ return enabledFallback;
21278
+ })();
21279
+ if (submit === null)
21280
+ return fail("x post submit was enabled a moment ago but no clickable control remained");
21281
+ await submit.click();
21282
+ await page.waitForTimeout(2500);
21283
+ const observable = page;
21284
+ const afterClick = await (observable.evaluate === undefined ? Promise.resolve(null) : observable.evaluate(`(() => {
21285
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
21286
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
21287
+ const dialogs = [...document.querySelectorAll('[role="dialog"]')]
21288
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 120)).filter(Boolean).slice(0, 2);
21289
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
21290
+ return JSON.stringify({
21291
+ path: location.pathname,
21292
+ textLen: (editor?.textContent || '').trim().length,
21293
+ alerts,
21294
+ dialogs,
21295
+ });
21296
+ })()`).catch(() => null));
21297
+ const shot = join6(tmpdir(), `kk-x-post-${Date.now()}.png`);
21298
+ const shotOk = await (observable.screenshot === undefined ? Promise.resolve(false) : observable.screenshot({ path: shot }).then(() => true).catch(() => false));
21244
21299
  const receipt = await expectOutcome(async () => {
21245
21300
  const id = await this.newestStatusId(page, handle);
21246
21301
  if (id === null)
@@ -21249,8 +21304,28 @@ class XPostBrowserTransport {
21249
21304
  return null;
21250
21305
  return `https://x.com${handle}/status/${id}`;
21251
21306
  }, { timeoutMs: this.stepTimeoutMs, label: "x status receipt" });
21307
+ const sentToast = /post was sent|\u5DF2\u53D1\u5E03|\u53D1\u9001\u6210\u529F|\u5DF2\u53D1\u9001/i.test(String(afterClick ?? ""));
21308
+ if (!receipt.ok && sentToast) {
21309
+ return ResultSchema.parse({
21310
+ ok: true,
21311
+ target: TARGET,
21312
+ url: `https://x.com${handle}`,
21313
+ message: `x post sent \u2014 X confirmed it in the composer toast; the profile timeline had not rendered it yet, so no status id was recorded`,
21314
+ metadata: { ...metadata, confirmedBy: "post-sent-toast" }
21315
+ });
21316
+ }
21252
21317
  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`);
21318
+ const evidence = await (observable.evaluate === undefined ? Promise.resolve(null) : observable.evaluate(`(() => {
21319
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
21320
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
21321
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
21322
+ return JSON.stringify({
21323
+ url: location.pathname,
21324
+ textLen: (editor?.textContent || '').trim().length,
21325
+ alerts,
21326
+ });
21327
+ })()`).catch(() => null));
21328
+ 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${afterClick ? ` \u2014 after click ${afterClick}` : ""}${shotOk ? ` \u2014 screenshot ${shot}` : ""}${evidence ? ` \u2014 console ${evidence}` : ""}`);
21254
21329
  }
21255
21330
  const id = /\/status\/(\d+)/.exec(receipt.evidence)?.[1];
21256
21331
  return ResultSchema.parse({
@@ -16,7 +16,8 @@
16
16
  * `fill()` leaves Post disabled), media `button[aria-label="Add photos or video"]` then
17
17
  * `input[data-testid="fileInput"]`, submit `[data-testid="tweetButton"]`.
18
18
  */
19
- import { extname, isAbsolute } from 'node:path';
19
+ import { tmpdir } from 'node:os';
20
+ import { extname, isAbsolute, join } from 'node:path';
20
21
  import type { Result } from '@gobing-ai/kk-core';
21
22
  import { ResultSchema } from '@gobing-ai/kk-core';
22
23
  import { type PublishTransport, type PublishTransportPayload, trySelectors } from '@gobing-ai/publish-harness';
@@ -47,8 +48,15 @@ export const X_POST_URL = 'https://x.com/home';
47
48
  export const X_NEW_POST_BUTTON = '[data-testid="SideNav_NewTweet_Button"]';
48
49
  /** Composer page the nav button lands on. */
49
50
  export const X_COMPOSE_PATH = '/compose/post';
50
- /** Page-scoped submit (the composer is a page, not a dialog). */
51
+ /**
52
+ * Submit controls, measured 2026-11-20 on `/compose/post`: the **page** composer carries
53
+ * `[data-testid="tweetButton"]`, and the inline composer on `/home` carries
54
+ * `[data-testid="tweetButtonInline"]`. Both start `disabled`/`aria-disabled="true"` and enable as soon
55
+ * as the editor holds text, so the rail must accept either rather than assume the page one survives.
56
+ */
51
57
  export const X_POST_SUBMIT = '[data-testid="tweetButton"]';
58
+ export const X_POST_SUBMIT_INLINE = '[data-testid="tweetButtonInline"]';
59
+ export const X_POST_SUBMITS: readonly string[] = [X_POST_SUBMIT, X_POST_SUBMIT_INLINE];
52
60
 
53
61
  /** Composer controls, all page-scoped (measured 2026-11-16). */
54
62
  export const POST_SELECTORS = {
@@ -211,15 +219,18 @@ export class XPostBrowserTransport implements PublishTransport {
211
219
  return composer.ok ? null : `x composer never opened at ${X_COMPOSE_PATH}: ${composer.error}`;
212
220
  }
213
221
 
214
- /** Types the text and requires the Post control to enable (bounded three attempts). */
222
+ /**
223
+ * Types the text and requires the Post control to enable (bounded three attempts).
224
+ *
225
+ * Measured 2026-11-20: **Escape on `/compose/post` navigates to `/home`** — the compose surface is a
226
+ * page there, not an overlay — so the old "press Escape to clear the mask" first move threw the
227
+ * run off the page whose submit it then waited on (`[data-testid="tweetButton"]` is page-scoped and
228
+ * disappears), and every attempt ended as "post submit never enabled". A mask, when it exists, is
229
+ * cleared by the forced editor click below, which never navigates.
230
+ */
215
231
  private async typeAndEnable(page: Page, text: string): Promise<string | null> {
216
232
  const textBox = page.locator(POST_SELECTORS.text[0]).first();
217
- const submit = page.locator(X_POST_SUBMIT).first();
218
233
  for (let attempt = 1; attempt <= 3; attempt++) {
219
- // X can leave a `[data-testid="mask"]` layer over the composer (it opens the compose
220
- // surface as an overlay after an in-app navigation), which swallows pointer events. A
221
- // forced click, and focus as the fallback, reach the editor without dismissing it.
222
- await page.keyboard.press('Escape').catch(() => {});
223
234
  await page.waitForTimeout(250);
224
235
  const focused = await textBox.click({ force: true }).then(
225
236
  () => true,
@@ -235,7 +246,23 @@ export class XPostBrowserTransport implements PublishTransport {
235
246
  await textBox.press('Backspace').catch(() => {});
236
247
  await textBox.pressSequentially(text, { delay: 8 });
237
248
  const enabled = await expectOutcome(
238
- async () => ((await submit.isEnabled().catch(() => false)) ? 'post enabled' : null),
249
+ async () => {
250
+ // Whichever submit control this surface renders: the page composer's
251
+ // `tweetButton`, or the inline composer's `tweetButtonInline` on /home. Asked by
252
+ // enablement, never by attachment — the page-scoped control is gone the moment the
253
+ // surface navigates, and an absent control simply reads disabled.
254
+ for (const selector of X_POST_SUBMITS) {
255
+ if (
256
+ await page
257
+ .locator(selector)
258
+ .first()
259
+ .isEnabled()
260
+ .catch(() => false)
261
+ )
262
+ return 'post enabled';
263
+ }
264
+ return null;
265
+ },
239
266
  // One step, capped at 10s: a caller may shrink the step (tests), never stretch it.
240
267
  { timeoutMs: Math.min(10_000, this.stepTimeoutMs), label: `x post enabled (attempt ${attempt})` },
241
268
  );
@@ -303,10 +330,93 @@ export class XPostBrowserTransport implements PublishTransport {
303
330
  // Four steps: X transcodes the image and only then re-enables Post (30s step → 120s).
304
331
  { timeoutMs: this.stepTimeoutMs * 4, label: 'x post submit enabled after media' },
305
332
  );
306
- if (!reEnabled.ok) return fail(`x post submit stayed disabled after the media: ${reEnabled.error}`);
333
+ if (!reEnabled.ok) {
334
+ // The submit state is a projection of what X thinks the composer holds: an empty
335
+ // editor (a re-mount dropped the typed text), a rejected upload, or an account
336
+ // banner all look identical as "disabled". Report the evidence instead of the
337
+ // symptom — the first live failure (2026-11-20) named only the timeout.
338
+ const observable = page as unknown as { evaluate?: (script: string) => Promise<unknown> };
339
+ const evidence = await (observable.evaluate === undefined
340
+ ? Promise.resolve(null)
341
+ : observable
342
+ .evaluate(`(() => {
343
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
344
+ const submit = document.querySelector('${X_POST_SUBMIT}');
345
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
346
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
347
+ const images = [...document.querySelectorAll('[data-testid="attachments"] img, [data-testid="tweetPhoto"] img')].length;
348
+ return JSON.stringify({
349
+ textLen: (editor?.textContent || '').trim().length,
350
+ submitDisabled: submit?.getAttribute('aria-disabled') ?? (submit?.disabled === true ? 'true' : 'false'),
351
+ images,
352
+ alerts,
353
+ });
354
+ })()`)
355
+ .catch(() => null));
356
+ return fail(
357
+ `x post submit stayed disabled after the media: ${reEnabled.error}${evidence ? ` — composer ${String(evidence)}` : ''}`,
358
+ );
359
+ }
307
360
  }
308
361
 
309
- await page.locator(X_POST_SUBMIT).first().click();
362
+ // Click the submit that is actually VISIBLE and ENABLED, across both surfaces. The module
363
+ // header already warns that the composer page carries a hidden template whose button never
364
+ // enables; `.first()` on `tweetButton` can pick that twin and swallow the click, which reads
365
+ // downstream as "Post was clicked but no new status id appeared" (measured 2026-11-20: two
366
+ // runs, no status on the profile, no error either).
367
+ const submit = await (async () => {
368
+ let enabledFallback: ReturnType<typeof page.locator> | null = null;
369
+ for (const selector of X_POST_SUBMITS) {
370
+ const candidate = page.locator(selector).first();
371
+ const enabled = await candidate.isEnabled().catch(() => false);
372
+ if (!enabled) continue;
373
+ // A visible, enabled control is the real one; the composer page also renders a hidden
374
+ // template whose button is enabled-looking but never posts. Preferring visibility and
375
+ // accepting enabled-only when visibility cannot be established keeps a surface whose
376
+ // button reports no layout (and the test double) working.
377
+ const visible = await candidate.isVisible().catch(() => false);
378
+ if (visible) return candidate;
379
+ enabledFallback ??= candidate;
380
+ }
381
+ return enabledFallback;
382
+ })();
383
+ if (submit === null) return fail('x post submit was enabled a moment ago but no clickable control remained');
384
+ await submit.click();
385
+ // Capture the composer's immediate reaction. The receipt step navigates to the profile, so
386
+ // any validation toast, "Posting…" state or blocking modal is gone by the time it reports —
387
+ // which is exactly how two silent failures happened on 2026-11-20. A screenshot is the
388
+ // cheapest decisive evidence: X says WHY it refused, in the UI, once.
389
+ await page.waitForTimeout(2_500);
390
+ // The double in `tests/post-rail.test.ts` models only the surface the rail clicks and reads;
391
+ // evaluate/screenshot are evidence-only, so a page without them must still publish.
392
+ const observable = page as unknown as {
393
+ evaluate?: (script: string) => Promise<unknown>;
394
+ screenshot?: (options: { path: string }) => Promise<unknown>;
395
+ };
396
+ const afterClick = await (observable.evaluate === undefined
397
+ ? Promise.resolve(null)
398
+ : observable
399
+ .evaluate(`(() => {
400
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
401
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
402
+ const dialogs = [...document.querySelectorAll('[role="dialog"]')]
403
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 120)).filter(Boolean).slice(0, 2);
404
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
405
+ return JSON.stringify({
406
+ path: location.pathname,
407
+ textLen: (editor?.textContent || '').trim().length,
408
+ alerts,
409
+ dialogs,
410
+ });
411
+ })()`)
412
+ .catch(() => null));
413
+ const shot = join(tmpdir(), `kk-x-post-${Date.now()}.png`);
414
+ const shotOk = await (observable.screenshot === undefined
415
+ ? Promise.resolve(false)
416
+ : observable
417
+ .screenshot({ path: shot })
418
+ .then(() => true)
419
+ .catch(() => false));
310
420
  const receipt = await expectOutcome(
311
421
  async () => {
312
422
  const id = await this.newestStatusId(page, handle);
@@ -316,9 +426,41 @@ export class XPostBrowserTransport implements PublishTransport {
316
426
  },
317
427
  { timeoutMs: this.stepTimeoutMs, label: 'x status receipt' },
318
428
  );
429
+ // X's own confirmation toast is a receipt in its own right. The profile-timeline poll above
430
+ // is the *preferred* evidence because it yields the status id, but the timeline can lag or
431
+ // refuse to render for a session that still posts fine (measured 2026-11-20: the toast read
432
+ // "Your post was sent. You have 1 hour to make any edits.", the profile showed nothing within
433
+ // 30 s, and the row failed — so a retry posted the same text AGAIN). Confirming on the toast
434
+ // turns a duplicate-generating "failure" into an honest success with no status id.
435
+ const sentToast = /post was sent|已发布|发送成功|已发送/i.test(String(afterClick ?? ''));
436
+ if (!receipt.ok && sentToast) {
437
+ return ResultSchema.parse({
438
+ ok: true,
439
+ target: TARGET,
440
+ url: `https://x.com${handle}`,
441
+ message: `x post sent — X confirmed it in the composer toast; the profile timeline had not rendered it yet, so no status id was recorded`,
442
+ metadata: { ...metadata, confirmedBy: 'post-sent-toast' },
443
+ });
444
+ }
319
445
  if (!receipt.ok) {
446
+ // Name what the console said, not just that nothing appeared: a validation toast, a
447
+ // duplicate guard, an alt-text prompt and a swallowed click all look identical here.
448
+ const evidence = await (observable.evaluate === undefined
449
+ ? Promise.resolve(null)
450
+ : observable
451
+ .evaluate(`(() => {
452
+ const alerts = [...document.querySelectorAll('[data-testid="toast"], [role="alert"], [data-testid="error-detail"]')]
453
+ .map((n) => (n.textContent || '').replace(/\\s+/g, ' ').trim()).filter(Boolean).slice(0, 3);
454
+ const editor = document.querySelector('[data-testid="tweetTextarea_0"]');
455
+ return JSON.stringify({
456
+ url: location.pathname,
457
+ textLen: (editor?.textContent || '').trim().length,
458
+ alerts,
459
+ });
460
+ })()`)
461
+ .catch(() => null));
320
462
  return fail(
321
- `x post receipt not confirmed — Post was clicked but no new status id appeared on the profile (${receipt.error}); an unobserved submit is never reported as published`,
463
+ `x post receipt not confirmed — Post was clicked but no new status id appeared on the profile (${receipt.error}); an unobserved submit is never reported as published${afterClick ? ` — after click ${afterClick}` : ''}${shotOk ? ` — screenshot ${shot}` : ''}${evidence ? ` — console ${evidence}` : ''}`,
322
464
  );
323
465
  }
324
466
  const id = /\/status\/(\d+)/.exec(receipt.evidence)?.[1];