@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
@@ -20189,6 +20189,9 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20189
20189
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20190
20190
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20191
20191
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20192
+ var VERDICT_PRINT_MARGIN_MS = 2000;
20193
+ var MIN_PASS_BUDGET_MS = 5000;
20194
+ var PASS_LAUNCH_RESERVE_MS = 20000;
20192
20195
  var DEFAULT_POLL_MS = 500;
20193
20196
  function isInstantBrowserDeath(message) {
20194
20197
  return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
@@ -20311,14 +20314,21 @@ async function checkChannelSession(config, opts) {
20311
20314
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
20312
20315
  const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
20313
20316
  let lastDetail = `${config.channel} readiness was never probed`;
20317
+ const deadline = Date.now() + timeoutMs;
20318
+ const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
20319
+ const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
20320
+ const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
20314
20321
  for (const headless of passes) {
20322
+ const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
20323
+ if (remainingMs < minPassMs)
20324
+ break;
20315
20325
  try {
20316
20326
  await withProfilePage({
20317
20327
  profileDir: opts.profileDir,
20318
20328
  headless,
20319
20329
  url: config.homeUrl,
20320
20330
  isAuthenticated: config.isAuthenticated,
20321
- timeoutMs,
20331
+ timeoutMs: remainingMs,
20322
20332
  launcher: opts.launcher ?? kkBrowserLauncher
20323
20333
  }, async () => true);
20324
20334
  return {
@@ -20604,7 +20614,9 @@ var SHP_VIDEO_SELECTORS = {
20604
20614
  originalAgreementCheckbox: 'div.declare-body-wrapper input[type="checkbox"].ant-checkbox-input',
20605
20615
  originalConfirmLabel: "\u58F0\u660E\u539F\u521B",
20606
20616
  saveButton: ['button:text-is("\u4FDD\u5B58\u8349\u7A3F")'],
20607
- publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")']
20617
+ publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")'],
20618
+ collectionEntry: ['button:has-text("\u5408\u96C6")', 'div:has-text("\u5408\u96C6")', 'span:has-text("\u5408\u96C6")'],
20619
+ collectionLabel: "\u5408\u96C6"
20608
20620
  };
20609
20621
  var SHP_AUDIO_SELECTORS = {
20610
20622
  ...SHP_VIDEO_SELECTORS,
@@ -4,7 +4,7 @@
4
4
  "entry": "./dist/index.js",
5
5
  "check": "./dist/profile-check.js",
6
6
  "version": "1.0.0",
7
- "description": "shipinhao (channels.weixin.qq.com) publish via a script browser transport with wujie-app shadowRoot traversal; four post kinds (shortVideo 视频, audio 音频, image 图文, music 音乐 — audio is the first deliverable); draft by default, public only on an explicit publishStatus with a fresh works receipt, requested-only 声明原创 declaration",
7
+ "description": "shipinhao (channels.weixin.qq.com) publish via a script browser transport with wujie-app shadowRoot traversal; four post kinds (shortVideo 视频, audio 音频, image 图文, music 音乐 — audio is the first deliverable and rides its own /platform/post/createAudio surface: required 封面, optional 合集, no draft); draft by default for the video rails, public only on an explicit publishStatus with a fresh works receipt, requested-only 声明原创 declaration",
8
8
  "browserSession": {
9
9
  "profileName": "shipinhao",
10
10
  "homeUrl": "https://channels.weixin.qq.com/platform"
@@ -0,0 +1,492 @@
1
+ /**
2
+ * shipinhao 音频 (audio) post flow — the dedicated `/platform/post/createAudio` surface.
3
+ *
4
+ * WHY this file exists (2026-11-16, the "shipinhao audio never publishes" failure): the audio
5
+ * operation used to drive the VIDEO create surface (`/platform/post/create`, reached from the
6
+ * dashboard's 发表视频), feeding the .mp3 to the video intake. The platform then transcodes it as a
7
+ * video — the cover sits at 封面预览 生成中 forever — so the post never persisted and the receipt
8
+ * stage could only report `uncertain / effect unknown` (2026-11-15 run:
9
+ * `kk-news-generate-20261115-1794799176832`, receipt status `uncertain`).
10
+ *
11
+ * Live recon 2026-11-16 pinned the real surface: dashboard → `内容管理` → `音频` (`音频管理`,
12
+ * `/platform/post/audioManager`, which also carries the 音频 | 合集 tabs) → `发表音频`
13
+ * (`/platform/post/createAudio`) with, in order: 音频 (上传文件 / 从视频选音频), 文件
14
+ * (drag-drop zone, WAV/MP3, ≥10 s, ≥64 kbps, ≤1 GB), 封面 (1:1, jpg/png, ≤8 MB), 标题 (≤40),
15
+ * 描述 (textarea, ≤3000), 合集 (`选择合集`, per-kind list: 不加合集 / <collections> / 创建新合集),
16
+ * 定时发表, and ONE submit rail — `发表音频`. There is no 保存草稿 on this surface, which is why a
17
+ * `publishStatus: 'draft'` request is refused here instead of being approximated.
18
+ *
19
+ * The receipt is the audio LIST, not a URL shape: the site returns to `/platform/post/audioManager`
20
+ * and the new row (title + 发布时间 + status) is the works record. A submit whose row never appears
21
+ * is `unknown`, never `published`.
22
+ */
23
+
24
+ import { type Result, ResultSchema } from '@gobing-ai/kk-core';
25
+ import type { Page } from 'playwright';
26
+ import { SHP_TARGET, type ShipinhaoOperationName } from './selectors';
27
+
28
+ /** The 音频 manager and create routes (recon-Grounded 2026-11-16). */
29
+ export const SHP_AUDIO_MANAGER_PATH = '/platform/post/audioManager';
30
+ export const SHP_AUDIO_CREATE_PATH = '/platform/post/createAudio';
31
+
32
+ /** 标题 hard cap on the audio form (0/40 counter, live recon 2026-11-16). */
33
+ export const SHP_AUDIO_TITLE_MAX = 40;
34
+ /** 描述 hard cap on the audio form (0/3000 counter, live recon 2026-11-16). */
35
+ export const SHP_AUDIO_DESCRIPTION_MAX = 3000;
36
+ /** Budget for the fresh-row receipt in 音频管理 after 发表音频 (recon: the list re-renders in seconds). */
37
+ export const SHP_AUDIO_RECEIPT_MS = 30_000;
38
+
39
+ /** Test seam for the receipt clock: the 30 s production value made the suite unrunnable. */
40
+ let receiptBudgetMs: number | null = null;
41
+ export function setAudioReceiptBudgetForTests(ms: number | null): void {
42
+ receiptBudgetMs = ms;
43
+ }
44
+
45
+ /** Everything the audio flow needs; the caller owns the pre-browser ladder and the session check. */
46
+ export interface AudioFlowInput {
47
+ page: Page;
48
+ title: string;
49
+ body: string;
50
+ tags: readonly string[];
51
+ /** One local audio file (the episode mp3). */
52
+ media: readonly string[];
53
+ coverPath?: string;
54
+ collection?: string;
55
+ publishPublic: boolean;
56
+ operation: ShipinhaoOperationName;
57
+ profileDir: string;
58
+ stepTimeoutMs: number;
59
+ }
60
+
61
+ /** A typed failure Result, matching the flow's `stageFail` shape without importing the video flow. */
62
+ function stageFail(message: string, stage: string, metadata: Record<string, unknown>, evidence?: string): Result {
63
+ return ResultSchema.parse({
64
+ ok: false,
65
+ target: SHP_TARGET,
66
+ error: message,
67
+ effect: 'unknown',
68
+ metadata: { ...metadata, stage, ...(evidence === undefined ? {} : { evidence }) },
69
+ });
70
+ }
71
+
72
+ /** Poll `probe` until it returns a non-null value, or the budget runs out. */
73
+ export async function expectOutcome<T>(
74
+ probe: () => Promise<T | null>,
75
+ timeoutMs: number,
76
+ label: string,
77
+ ): Promise<{ ok: true; evidence: T } | { ok: false; error: string }> {
78
+ const deadline = Date.now() + timeoutMs;
79
+ let last = `${label} never observed`;
80
+ for (;;) {
81
+ try {
82
+ const value = await probe();
83
+ if (value !== null) return { ok: true, evidence: value };
84
+ } catch (error) {
85
+ last = `${label}: ${error instanceof Error ? error.message : String(error)}`;
86
+ }
87
+ if (Date.now() >= deadline) return { ok: false, error: last };
88
+ await new Promise((resolve) => setTimeout(resolve, 500));
89
+ }
90
+ }
91
+
92
+ /** The 描述 text: the body's trimmed plain text plus the topic tags, clipped to the form's cap. */
93
+ export function buildAudioDescription(body: string, tags: readonly string[]): string {
94
+ const topicLine = tags.map((tag) => `#${tag.replace(/^#/, '')}`).join(' ');
95
+ const combined = topicLine.length > 0 ? `${body.trim()}\n\n${topicLine}` : body.trim();
96
+ return combined.slice(0, SHP_AUDIO_DESCRIPTION_MAX);
97
+ }
98
+
99
+ /** The 标题: clipped to 40 by code point so a long title is a clipped title, never a failed fill. */
100
+ export function clipAudioTitle(title: string): string {
101
+ return Array.from(title.trim()).slice(0, SHP_AUDIO_TITLE_MAX).join('');
102
+ }
103
+
104
+ /**
105
+ * Navigate dashboard → 内容管理 → 音频 → 发表音频 and confirm the create surface, returning a typed
106
+ * failure instead of throwing when any hop is missing (the SPA's submenu only exists while hovered,
107
+ * so the click is dispatched on the anchor once the menu is open).
108
+ */
109
+ async function openAudioCreate(page: Page, stepTimeoutMs: number): Promise<string | null> {
110
+ await page.goto('https://channels.weixin.qq.com/platform', {
111
+ waitUntil: 'domcontentloaded',
112
+ timeout: stepTimeoutMs,
113
+ });
114
+ await page.waitForTimeout(8_000);
115
+ const menu = page.locator('a:has-text("内容管理")').first();
116
+ await menu.hover({ timeout: stepTimeoutMs });
117
+ await page.waitForTimeout(2_000);
118
+ // The submenu exists only while 内容管理 is hovered, and the anchor is an SPA link: click it
119
+ // through the DOM (a Playwright click rejects the item once the hover moves).
120
+ const clicked = await page.evaluate(`(() => {
121
+ const anchor = Array.from(document.querySelectorAll('a')).find((el) => (el.textContent || '').trim() === '音频');
122
+ if (!anchor) return false;
123
+ anchor.click();
124
+ return true;
125
+ })()`);
126
+ if (!clicked) return '音频 submenu entry not found under 内容管理';
127
+ const manager = await expectOutcome(
128
+ async () => (page.url().includes(SHP_AUDIO_MANAGER_PATH) ? page.url() : null),
129
+ stepTimeoutMs,
130
+ '音频管理 page',
131
+ );
132
+ if (!manager.ok) return `音频管理 page never opened: ${manager.error}`;
133
+ const entry = page.locator('button:has-text("发表音频")').first();
134
+ // The URL flips before the manager renders its header button — poll, do not count once.
135
+ const ready = await expectOutcome(
136
+ async () => ((await entry.count()) > 0 ? '发表音频 entry rendered' : null),
137
+ stepTimeoutMs,
138
+ '音频管理 发表音频 entry',
139
+ );
140
+ if (!ready.ok) return `发表音频 entry never rendered on 音频管理: ${ready.error}`;
141
+ await entry.click({ timeout: stepTimeoutMs });
142
+ const create = await expectOutcome(
143
+ async () => (page.url().includes(SHP_AUDIO_CREATE_PATH) ? page.url() : null),
144
+ stepTimeoutMs,
145
+ '发表音频 form',
146
+ );
147
+ if (!create.ok) return `发表音频 form never opened: ${create.error}`;
148
+ return null;
149
+ }
150
+
151
+ /** Upload the mp3 through the drop zone's file chooser and wait for the file chip to render. */
152
+ async function attachAudio(page: Page, file: string, stepTimeoutMs: number): Promise<string | null> {
153
+ const zone = page.locator('text=拖拽到此处上传').first();
154
+ if ((await zone.count()) === 0) return 'audio drop zone (拖拽到此处上传) not found';
155
+ const chooserPromise = page.waitForEvent('filechooser', { timeout: stepTimeoutMs }).catch(() => null);
156
+ await zone.click({ timeout: stepTimeoutMs });
157
+ const chooser = await chooserPromise;
158
+ if (chooser === null) return 'clicking the audio drop zone opened no file chooser';
159
+ await chooser.setFiles(file);
160
+ const name = file.split('/').pop() ?? '';
161
+ const attached = await expectOutcome(
162
+ async () => ((await page.locator(`text=${name.slice(0, 12)}`).count()) > 0 ? 'file chip rendered' : null),
163
+ 60_000,
164
+ 'audio file chip',
165
+ );
166
+ if (!attached.ok) return `the file was handed to the form but no file chip appeared: ${attached.error}`;
167
+ return null;
168
+ }
169
+
170
+ /**
171
+ * Attach the 封面: click the tile above the 封面宽高比 hint, hand the file to the chooser, then
172
+ * confirm the 编辑音频封面 crop dialog (确认). Success = the form's 「请上传封面」 validation text is
173
+ * gone and a preview is rendered — a cover the form rejected must never reach the submit click.
174
+ */
175
+ export async function attachAudioCover(page: Page, coverPath: string, stepTimeoutMs: number): Promise<string | null> {
176
+ const hint = page.locator('text=封面宽高比').first();
177
+ if ((await hint.count()) === 0) return '音频 封面 hint (封面宽高比) not found';
178
+ await hint.scrollIntoViewIfNeeded();
179
+ const box = await hint.boundingBox();
180
+ if (box === null) return '音频 封面 tile has no layout box';
181
+ const chooserPromise = page.waitForEvent('filechooser', { timeout: stepTimeoutMs }).catch(() => null);
182
+ // The tile is the dashed “+” square directly above the hint text.
183
+ await page.mouse.click(box.x + 40, box.y - 70);
184
+ const chooser = await chooserPromise;
185
+ if (chooser === null) return 'clicking the 封面 tile opened no file chooser';
186
+ await chooser.setFiles(coverPath);
187
+ // 2026-11-18 (the "shipinhao audio never publishes" leaf cause): choosing the file was treated as
188
+ // a committed cover. The tile then shows an upload percentage (25% measured) for as long as the
189
+ // file is in flight, and a submit clicked in that window fails client-side with 「请上传封面」
190
+ // while the page stays on the form — so no works row ever appeared and every run ended
191
+ // `uncertain`. The percentage token is the only pre-submit signal that the cover is NOT committed.
192
+ const settled = await expectOutcome(
193
+ async () => ((await coverUploadPending(page)) ? null : 'cover upload settled'),
194
+ stepTimeoutMs,
195
+ '音频 封面 upload',
196
+ );
197
+ if (!settled.ok) return `the 封面 file was chosen but its upload never settled: ${settled.error}`;
198
+ // 2026-11-18 (measured): the crop dialog renders inside the `WUJIE-APP` shadow root, and it mounts
199
+ // BEFORE its cropper initializes — a single 确认 click fired in that window is swallowed, the
200
+ // dialog stays open, and the form then refuses the submit with 「请上传封面」. So the click is
201
+ // retried while the dialog is still there, and success is the dialog CLOSING, not the click call
202
+ // returning. `page.locator` pierces the open shadow root natively; `document.*` text reads do not
203
+ // (that is why the older probe believed an uncommitted cover had been accepted).
204
+ let cropSeen = false;
205
+ // Open, then wait for the cropper IMAGE: clicking 确认 while the cropper is still mounting closes
206
+ // the dialog without committing the cover (measured 2026-11-18 — the form then refuses the
207
+ // submit with 「请上传封面」 and no works row is ever created).
208
+ const cropReady = await expectOutcome(
209
+ async () => {
210
+ const dialog = page.locator(CROP_DIALOG).first();
211
+ const open = (await dialog.count()) > 0 && (await dialog.isVisible().catch(() => false));
212
+ if (!open) return cropSeen ? 'crop dialog closed before it was ready' : null;
213
+ cropSeen = true;
214
+ const cropper = page.locator(CROP_IMAGE).first();
215
+ return (await cropper.count()) > 0 && (await cropper.isVisible().catch(() => false))
216
+ ? 'cropper ready'
217
+ : null;
218
+ },
219
+ stepTimeoutMs,
220
+ '编辑音频封面 crop dialog',
221
+ );
222
+ if (!cropReady.ok) return `the 封面 crop dialog never appeared or its cropper never mounted: ${cropReady.error}`;
223
+ const cropped = await expectOutcome(
224
+ async () => {
225
+ const dialog = page.locator(CROP_DIALOG).first();
226
+ if ((await dialog.count()) === 0 || !(await dialog.isVisible().catch(() => false))) {
227
+ return 'crop dialog closed';
228
+ }
229
+ // The dialog can survive the first click while the cropper settles, so each pass clicks.
230
+ await page
231
+ .locator(`${CROP_DIALOG} button:text-is("确认")`)
232
+ .last()
233
+ .click({ timeout: 4_000 })
234
+ .catch(() => {});
235
+ return null;
236
+ },
237
+ stepTimeoutMs,
238
+ '编辑音频封面 crop confirm',
239
+ );
240
+ if (!cropped.ok) return `the 封面 crop dialog never closed: ${cropped.error}`;
241
+ const cleared = await expectOutcome(
242
+ async () => ((await page.locator('text=请上传封面').count()) === 0 ? 'cover accepted' : null),
243
+ stepTimeoutMs,
244
+ '音频 封面 validation',
245
+ );
246
+ if (!cleared.ok) return `the 封面 was uploaded but the form still reports 「请上传封面」: ${cleared.error}`;
247
+ return null;
248
+ }
249
+
250
+ /**
251
+ * The inline validation lines the 音频 form renders when a submit is refused client-side (measured
252
+ * 2026-11-18). Only these exact lines are read: any other text on the page is content, not a verdict.
253
+ */
254
+ const AUDIO_FORM_REFUSALS = ['请上传封面', '请上传音频', '请填写标题', '请填写描述', '请选择合集'] as const;
255
+
256
+ /** The form's refusal line after a submit, or null when it rendered none. */
257
+ async function readSubmitRefusal(page: Page): Promise<string | null> {
258
+ for (const text of AUDIO_FORM_REFUSALS) {
259
+ try {
260
+ if ((await page.locator(`text=${text}`).count()) > 0) return text;
261
+ } catch {
262
+ // An unreadable probe is not a refusal.
263
+ }
264
+ }
265
+ return null;
266
+ }
267
+
268
+ /**
269
+ * The 编辑音频封面 crop dialog. It lives in the `WUJIE-APP` shadow root (measured 2026-11-18), so it is
270
+ * matched by the cropper it contains or by its own title, never by a light-DOM ancestor.
271
+ */
272
+ const CROP_DIALOG = '.weui-desktop-dialog:has(.cropper-wrap), .weui-desktop-dialog:has-text("编辑音频封面")';
273
+ /** The cropper's own image: present only once the dialog has finished mounting (measured 2026-11-18). */
274
+ const CROP_IMAGE = `${CROP_DIALOG} .cropper-wrap img, ${CROP_DIALOG} .croppie-container img, ${CROP_DIALOG} img`;
275
+
276
+ /**
277
+ * Whether the 封面 tile still shows an upload percentage ("25%"), i.e. the file is in flight and the
278
+ * cover is NOT committed yet (measured 2026-11-18). The form's own 「请上传封面」 line is useless as a
279
+ * pre-submit check: it only renders after a refused submit.
280
+ */
281
+ async function coverUploadPending(page: Page): Promise<boolean> {
282
+ try {
283
+ return (await page.locator('text=/\\d{1,3}%/').count()) > 0;
284
+ } catch {
285
+ // An unreadable probe is not evidence of an upload; the crop/validation checks still run.
286
+ return false;
287
+ }
288
+ }
289
+
290
+ /** Open the 合集 picker, click the exact collection, and verify the row reads it back. */
291
+ export async function selectAudioCollection(
292
+ page: Page,
293
+ collection: string,
294
+ stepTimeoutMs: number,
295
+ ): Promise<string | null> {
296
+ const picker = page.locator('div.display-text:has-text("选择合集")').first();
297
+ if ((await picker.count()) === 0) return '合集 picker (选择合集) not found on the audio form';
298
+ await picker.scrollIntoViewIfNeeded();
299
+ // The same node keeps the selection — only its text changes to the collection name — so hold it;
300
+ // a text re-query for 选择合集 would resolve to nothing after the click.
301
+ const row = await picker.elementHandle();
302
+ await picker.click({ timeout: stepTimeoutMs });
303
+ await page.waitForTimeout(2_000);
304
+ // Exact text only: the 标题 input carries "每日AI乱炖 · 2026-11-15", so a substring match would
305
+ // click our own title instead of the collection option.
306
+ const option = page.getByText(collection, { exact: true });
307
+ if ((await option.count()) === 0) return `合集 '${collection}' is not among this account's 音频 collections`;
308
+ await option.last().click({ timeout: stepTimeoutMs });
309
+ const readback = await expectOutcome(
310
+ async () => {
311
+ const text = ((await row?.textContent()) ?? '').trim();
312
+ return text.includes(collection) ? text : null;
313
+ },
314
+ stepTimeoutMs,
315
+ '合集 readback',
316
+ );
317
+ if (!readback.ok) return `合集 '${collection}' was clicked but the form does not show it: ${readback.error}`;
318
+ return null;
319
+ }
320
+
321
+ /**
322
+ * How many rows in 音频管理 carry `title`. The list is a div grid (no `<tr>`), so this counts the
323
+ * title text nodes; a re-publish of the same title raises the count, which is what the fresh-row
324
+ * contract needs.
325
+ */
326
+ export async function countAudioRows(page: Page, title: string): Promise<number> {
327
+ try {
328
+ return await page.getByText(title, { exact: false }).count();
329
+ } catch {
330
+ return 0;
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Run the audio post. Returns a `Result` — `ok: true` only when the audio list carries the new row.
336
+ */
337
+ export async function runAudioPostFlow(input: AudioFlowInput): Promise<Result> {
338
+ const { collection, publishPublic, operation, profileDir } = input;
339
+ const metadata: Record<string, unknown> = {
340
+ operation,
341
+ driver: 'script',
342
+ publishStatus: publishPublic ? 'public' : 'draft',
343
+ profileDir,
344
+ ...(collection !== undefined ? { collection } : {}),
345
+ };
346
+ // 发表音频 is the only submit rail on this surface: a draft request cannot be honoured.
347
+ if (!publishPublic) {
348
+ return stageFail(
349
+ 'shipinhao 音频 has no draft rail — the 发表音频 form offers only 发表音频 (no 保存草稿); request publishStatus: public or publish nothing',
350
+ 'draft-unsupported',
351
+ metadata,
352
+ );
353
+ }
354
+ // 封面 is MANDATORY on the audio form: submitting without one fails client-side validation with
355
+ // 「请上传封面」 and silently produces no works row (live recon 2026-11-16 — this is what made every
356
+ // audio publish end `uncertain`). The refusal is pre-browser; a supplied cover is attached through
357
+ // the form's own crop dialog inside pendingAudioFlow.
358
+ if (input.coverPath === undefined) {
359
+ return stageFail(
360
+ 'shipinhao 音频 requires a cover (封面) — the form refuses to submit without one (「请上传封面」); pass coverPath',
361
+ 'audio-cover',
362
+ metadata,
363
+ );
364
+ }
365
+ return pendingAudioFlow(input, metadata);
366
+ }
367
+
368
+ /**
369
+ * The recon-grounded steps: open 音频管理 → 发表音频, upload, 标题/描述, 封面 (crop dialog 确认),
370
+ * 合集 by exact text, submit, then the fresh-row receipt. Exported for the stage tests, which drive
371
+ * the steps against a fake page.
372
+ */
373
+ export async function pendingAudioFlow(input: AudioFlowInput, metadata: Record<string, unknown>): Promise<Result> {
374
+ const { page, title, body, tags, media, collection, profileDir, stepTimeoutMs } = input;
375
+ const audio = media[0];
376
+ if (audio === undefined) return stageFail('shipinhao 音频 requires one audio file', 'media', metadata);
377
+
378
+ const opened = await openAudioCreate(page, stepTimeoutMs);
379
+ if (opened !== null) return stageFail(opened, 'audio-open', metadata);
380
+
381
+ const attached = await attachAudio(page, audio, stepTimeoutMs);
382
+ if (attached !== null) return stageFail(attached, 'audio-upload', metadata);
383
+
384
+ const clipped = clipAudioTitle(title);
385
+ const description = buildAudioDescription(body, tags);
386
+ const titleInput = page.locator('input[placeholder="请填写标题"]').first();
387
+ if ((await titleInput.count()) === 0) return stageFail('音频 标题 input not found', 'audio-title', metadata);
388
+ await titleInput.fill(clipped);
389
+ const titleOk = await expectOutcome(
390
+ async () => ((await titleInput.inputValue()) === clipped ? 'title retained' : null),
391
+ stepTimeoutMs,
392
+ '音频 标题 readback',
393
+ );
394
+ if (!titleOk.ok) return stageFail(`音频 标题 readback failed: ${titleOk.error}`, 'audio-title', metadata);
395
+
396
+ const descriptionBox = page.locator('textarea[placeholder="请填写描述"]').first();
397
+ if ((await descriptionBox.count()) === 0)
398
+ return stageFail('音频 描述 textarea not found', 'audio-description', metadata);
399
+ await descriptionBox.fill(description);
400
+ const descriptionOk = await expectOutcome(
401
+ async () => ((await descriptionBox.inputValue()).length > 0 ? 'description retained' : null),
402
+ stepTimeoutMs,
403
+ '音频 描述 readback',
404
+ );
405
+ if (!descriptionOk.ok) {
406
+ return stageFail(`音频 描述 readback failed: ${descriptionOk.error}`, 'audio-description', metadata);
407
+ }
408
+
409
+ const coverPath = input.coverPath;
410
+ if (coverPath !== undefined) {
411
+ const cover = await attachAudioCover(page, coverPath, stepTimeoutMs);
412
+ if (cover !== null) return stageFail(cover, 'audio-cover', metadata);
413
+ }
414
+
415
+ if (collection !== undefined) {
416
+ const selected = await selectAudioCollection(page, collection, stepTimeoutMs);
417
+ if (selected !== null) return stageFail(selected, 'collection-select', metadata);
418
+ } else {
419
+ // Absence is explicit: 不加合集 is the form's default, and a post must never inherit a
420
+ // previously chosen collection silently.
421
+ const readback = await page.locator('div.display-text:has-text("选择合集")').count();
422
+ if (readback === 0) {
423
+ return stageFail('合集 row missing before submit', 'collection-select', metadata);
424
+ }
425
+ }
426
+
427
+ // Fresh-row contract: record how many 音频 rows already carry this title, submit, then require
428
+ // the count to INCREASE. A count that only holds steady means the submit restored an existing
429
+ // row, never that it published ours (the video rail's fresh-receipt rule, restated for a list).
430
+ const baseline = await countAudioRows(page, clipped);
431
+
432
+ const submit = page.locator('button:has-text("发表音频")').first();
433
+ if ((await submit.count()) === 0) return stageFail('发表音频 submit control not found', 'audio-submit', metadata);
434
+ if (await submit.isDisabled()) return stageFail('发表音频 submit control is disabled', 'audio-submit', metadata);
435
+ await submit.click({ timeout: stepTimeoutMs });
436
+
437
+ // Some submissions raise a confirmation; click it once when it appears.
438
+ await page.waitForTimeout(3_000);
439
+ for (const label of ['确认发表', '确定']) {
440
+ const confirm = page.locator(`button:text-is("${label}")`).first();
441
+ if ((await confirm.count()) > 0 && (await confirm.isVisible().catch(() => false))) {
442
+ await confirm.click({ timeout: 5_000 }).catch(() => {});
443
+ break;
444
+ }
445
+ }
446
+
447
+ // A form that stays on the create route after the submit did not submit: the platform renders its
448
+ // client-side validation inline (measured 2026-11-18: 「请上传封面」 under the cover tile while the
449
+ // page never left /platform/post/createAudio). Reading it turns an opaque `unknown` into the one
450
+ // line that names the fix — the 2026-11-15/17/18 runs all died as "no works row ever observed".
451
+ if (page.url().includes(SHP_AUDIO_CREATE_PATH)) {
452
+ const refusal = await readSubmitRefusal(page);
453
+ if (refusal !== null) {
454
+ return stageFail(
455
+ `shipinhao 音频 submit was refused by the form: 「${refusal}」 — nothing was published`,
456
+ 'audio-submit-validation',
457
+ metadata,
458
+ `inline validation: ${refusal}`,
459
+ );
460
+ }
461
+ }
462
+
463
+ // Receipt: the 音频 list row. The site returns to /platform/post/audioManager and renders the
464
+ // new row there; the table is div-based, so the row is found by its title text, never by `tr`.
465
+ const receipt = await expectOutcome(
466
+ async () => {
467
+ if (!page.url().includes(SHP_AUDIO_MANAGER_PATH)) return null;
468
+ const count = await countAudioRows(page, clipped);
469
+ if (count <= baseline) return null;
470
+ return { url: page.url(), rows: count };
471
+ },
472
+ // The site's own list pagination settles in well under a minute; the submit click already
473
+ // proved the form accepted the post, so a longer wait only delays a truthful `unknown`.
474
+ receiptBudgetMs ?? SHP_AUDIO_RECEIPT_MS,
475
+ '音频 list row',
476
+ );
477
+ if (!receipt.ok) {
478
+ return stageFail(
479
+ 'shipinhao 音频 publish-receipt not confirmed — 发表音频 was clicked but no new row carrying the title appeared in 音频管理; a submit without a works row is unknown and is never reported as published',
480
+ 'audio-receipt',
481
+ metadata,
482
+ receipt.error,
483
+ );
484
+ }
485
+ return ResultSchema.parse({
486
+ ok: true,
487
+ target: SHP_TARGET,
488
+ url: receipt.evidence.url,
489
+ message: `shipinhao audio published and confirmed in the 音频 list (${profileDir})`,
490
+ metadata: { ...metadata, confirmedBy: 'audio-list-row', rowsWithTitle: receipt.evidence.rows },
491
+ });
492
+ }