@gobing-ai/knowledge-kit 0.1.17 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/daily-voice/index.js +40 -7
  3. package/dist/index.js +8428 -4448
  4. package/package.json +1 -1
  5. package/plugins/generations/image-gen/README.md +31 -31
  6. package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
  7. package/plugins/generations/image-gen/config.example.yaml +3 -0
  8. package/plugins/generations/image-gen/dist/index.js +154 -14
  9. package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
  10. package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
  11. package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
  12. package/plugins/generations/image-gen/src/presets.ts +6 -5
  13. package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
  14. package/plugins/generations/image-gen/src/providers/types.ts +11 -1
  15. package/plugins/kk/config.example.yaml +7 -2
  16. package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
  17. package/plugins/kk/plugin.json +1 -1
  18. package/plugins/kk/publish-presets/chinese-article.json +8 -2
  19. package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
  20. package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
  21. package/plugins/kk/publish-presets/itc-main.json +36 -9
  22. package/plugins/kk/publish-presets/technical-article.json +8 -2
  23. package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
  24. package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
  25. package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
  26. package/plugins/kk/scripts/daily-stages.ts +238 -14
  27. package/plugins/kk/scripts/daily-triage-core.ts +43 -25
  28. package/plugins/kk/scripts/daily-triage.ts +1 -1
  29. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  30. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  31. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  32. package/plugins/kk/skills/publish/SKILL.md +15 -2
  33. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  34. package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
  35. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  36. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
  37. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
  38. package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
  39. package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
  40. package/plugins/kk/workflows/kk-publish.yaml +236 -0
  41. package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
  42. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
  43. package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
  44. package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
  45. package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
  46. package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
  47. package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
  48. package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
  49. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  50. package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
  51. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
  52. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  53. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
  54. package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
  55. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  56. package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
  57. package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
  58. package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
  59. package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
  60. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
  61. package/plugins/publishings/threads-pub/dist/index.js +9196 -296
  62. package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
  63. package/plugins/publishings/threads-pub/package.json +3 -1
  64. package/plugins/publishings/threads-pub/plugin.json +6 -1
  65. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  66. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  67. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  68. package/plugins/publishings/wechatmp-pub/dist/index.js +454 -81
  69. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
  70. package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
  71. package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
  72. package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
  73. package/plugins/publishings/weibo-pub/dist/index.js +136 -22
  74. package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
  75. package/plugins/publishings/weibo-pub/src/index.ts +208 -22
  76. package/plugins/publishings/x-pub/dist/index.js +263 -43
  77. package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
  78. package/plugins/publishings/x-pub/src/index.ts +15 -1
  79. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
  80. package/plugins/publishings/xhs-pub/dist/index.js +193 -201
  81. package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
  82. package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
  83. package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
  84. package/plugins/publishings/xhs-pub/src/index.ts +65 -59
  85. package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
  86. package/plugins/publishings/xhs-pub/src/page.ts +2 -2
  87. package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
  88. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
  89. package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
  90. package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
  91. package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
  92. package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
  93. package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
  94. package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
  95. package/plugins/kk/workflows/kk-itc.yaml +0 -291
@@ -248,119 +248,84 @@ async function invokeHostSave(page: XhsPage): Promise<string | null> {
248
248
  }
249
249
  }
250
250
 
251
- /**
252
- * Layered server-response capture (task 0350 R1, vendor-proven from
253
- * `vendors/xiaohongshu-skills/scripts/xhs/publish.py`): the save/publish response is the only
254
- * truth about whether a note persisted — the console toast has lied while the API returned
255
- * `HTTPBizError` (2026-11-09/10 runs). Four layers race for the first matching payload — XHR
256
- * `loadend`, wrapped `fetch`, console output, and a DOM toast observer — and the first capture
257
- * wins. Signatures are content-based, not URL-based: `HTTPBizError`, a −913x code, `note_id`,
258
- * or a short toast naming 禁止发笔记 / 违反 / 违规 / 审核未通过 / 账号异常 / 无法发布.
259
- * Arming is idempotent; a page that refused injection degrades to the legacy UI signals. The
260
- * sentinel markers keep a mocked evaluate from ever reading as a real capture.
261
- */
262
- export const CAPTURE_INJECT_EXPR = `/* kk-capture-inject */ (() => {
263
- const w = window;
264
- if (w.__kkXhsArmed) return 'kk-capture-armed';
265
- w.__kkXhsArmed = true;
266
- w.__kkXhsOutcome = null;
267
- const signatures = [
268
- /HTTPBizError/,
269
- /"code"\\s*:\\s*-913\\d/,
270
- /禁止发笔记/,
271
- /note_id/,
272
- /违反|违规|审核未通过|账号异常|无法发布/,
273
- ];
274
- const matches = (text) => signatures.some((re) => re.test(text));
275
- const record = (source, text) => {
276
- if (w.__kkXhsOutcome) return;
277
- const asString = String(text || '');
278
- if (!asString || !matches(asString)) return;
279
- w.__kkXhsOutcome = { source: source, text: asString.slice(0, 800) };
280
- };
281
- const proto = XMLHttpRequest.prototype;
282
- if (!proto.__kkPatched) {
283
- proto.__kkPatched = true;
284
- const open = proto.open;
285
- const send = proto.send;
286
- proto.open = function (method, url) { this.__kkUrl = url; return open.apply(this, arguments); };
287
- proto.send = function () {
288
- this.addEventListener('loadend', () => {
289
- try { record('xhr', (this.__kkUrl || '') + ' ' + this.responseText); } catch (e) {}
290
- });
291
- return send.apply(this, arguments);
292
- };
293
- }
294
- if (typeof w.fetch === 'function' && !w.fetch.__kkPatched) {
295
- const original = w.fetch;
296
- w.fetch = function () {
297
- return original.apply(this, arguments).then((response) => {
298
- try {
299
- response.clone().text().then((text) => record('fetch', (response.url || '') + ' ' + text)).catch(() => {});
300
- } catch (e) {}
301
- return response;
302
- });
303
- };
304
- w.fetch.__kkPatched = true;
305
- }
306
- if (!console.__kkPatched) {
307
- console.__kkPatched = true;
308
- for (const key of ['error', 'warn', 'log']) {
309
- const original = console[key].bind(console);
310
- console[key] = function () {
311
- try { record('console', Array.prototype.map.call(arguments, String).join(' ')); } catch (e) {}
312
- original.apply(console, arguments);
313
- };
314
- }
315
- }
316
- if (typeof MutationObserver === 'function' && document.body && !w.__kkXhsToastObs) {
317
- const toastRisk = /违反|违规|禁止发笔记|审核未通过|账号异常|无法发布/;
318
- const obs = new MutationObserver((muts) => {
319
- if (w.__kkXhsOutcome) return;
320
- for (const m of muts) {
321
- for (const n of m.addedNodes || []) {
322
- if (!n || n.nodeType !== 1) continue;
323
- const txt = String(n.textContent || '').trim();
324
- if (txt.length === 0 || txt.length > 300) continue;
325
- if (!toastRisk.test(txt)) continue;
326
- record('toast', txt);
327
- }
328
- }
329
- });
330
- obs.observe(document.body, { childList: true, subtree: true });
331
- w.__kkXhsToastObs = true;
332
- }
333
- return 'kk-capture-armed';
334
- })()`;
335
- const CAPTURE_READ_EXPR = `/* kk-capture-read */ (() => {
336
- const captured = window.__kkXhsOutcome;
337
- return captured ? JSON.stringify(captured) : 'kk-capture-none';
338
- })()`;
251
+ /** Read short risk-text leaves without changing the console or mistaking an existing body for a toast. */
252
+ export const RISK_LEAVES_EXPR = `/* kk-risk-leaves */ (() => JSON.stringify(
253
+ Array.from(document.querySelectorAll('body *')).filter((el) => el.children.length === 0)
254
+ .map((el) => String(el.textContent || '').trim())
255
+ .filter((text) => text.length > 0 && text.length <= 300 && /禁止发笔记|违反|违规|审核未通过|账号异常|无法发布/.test(text))
256
+ ))()`;
339
257
 
340
258
  interface OutcomeCapture {
341
259
  source: string;
342
260
  text: string;
343
261
  }
344
262
 
345
- async function armOutcomeCapture(page: XhsPage): Promise<void> {
346
- try {
347
- await page.evaluate(CAPTURE_INJECT_EXPR);
348
- } catch {
349
- // No injection, no capture: the legacy UI signals remain the only outcome evidence.
350
- }
351
- }
352
-
353
- async function readOutcomeCapture(page: XhsPage): Promise<OutcomeCapture | null> {
354
- try {
355
- const read = await page.evaluate(CAPTURE_READ_EXPR);
356
- if (typeof read !== 'string' || !read.startsWith('{')) return null;
357
- const parsed = JSON.parse(read) as Partial<OutcomeCapture>;
358
- return typeof parsed.source === 'string' && typeof parsed.text === 'string'
359
- ? { source: parsed.source, text: parsed.text }
360
- : null;
361
- } catch {
362
- return null;
363
- }
263
+ async function armOutcomeCapture(
264
+ page: XhsPage,
265
+ timeoutMs: number,
266
+ ): Promise<{ read(): Promise<OutcomeCapture | null>; dispose(): void }> {
267
+ const riskLeaves = async (): Promise<string[]> => {
268
+ try {
269
+ const value: unknown = JSON.parse(String(await page.evaluate(RISK_LEAVES_EXPR)));
270
+ return Array.isArray(value) ? value.filter((text): text is string => typeof text === 'string') : [];
271
+ } catch {
272
+ return [];
273
+ }
274
+ };
275
+ const baseline = new Set(await riskLeaves());
276
+ let capture: OutcomeCapture | null = null;
277
+ const pending = new Set<Promise<void>>();
278
+ const record = (source: string, text: string): void => {
279
+ if (
280
+ capture === null &&
281
+ /HTTPBizError|"code"\s*:\s*-913\d|note_id|禁止发笔记|违反|违规|审核未通过|账号异常|无法发布/.test(text)
282
+ ) {
283
+ capture = { source, text: text.slice(0, 800) };
284
+ }
285
+ };
286
+ const responseHandler = (payload: unknown): void => {
287
+ const read = (async () => {
288
+ let timer: ReturnType<typeof setTimeout> | undefined;
289
+ try {
290
+ const response = payload as { request?(): { resourceType(): string }; text(): Promise<string> };
291
+ const source = response.request?.().resourceType();
292
+ if (source !== 'xhr' && source !== 'fetch') return;
293
+ const text = await Promise.race([
294
+ response.text(),
295
+ new Promise<string>((resolve) => {
296
+ timer = setTimeout(() => resolve(''), timeoutMs);
297
+ }),
298
+ ]);
299
+ record(source, text);
300
+ } catch {
301
+ // A response without a readable body leaves the existing UI evidence authoritative.
302
+ } finally {
303
+ clearTimeout(timer);
304
+ }
305
+ })();
306
+ pending.add(read);
307
+ void read.finally(() => pending.delete(read));
308
+ };
309
+ const consoleHandler = (payload: unknown): void => {
310
+ try {
311
+ record('console', (payload as { text(): string }).text());
312
+ } catch {
313
+ /* A detached message has no evidence. */
314
+ }
315
+ };
316
+ page.onContextResponse?.(responseHandler);
317
+ page.on?.('console', consoleHandler);
318
+ return {
319
+ read: async () => {
320
+ await Promise.all(pending);
321
+ for (const text of await riskLeaves()) if (!baseline.has(text)) record('toast', text);
322
+ return capture;
323
+ },
324
+ dispose: () => {
325
+ page.offContextResponse?.(responseHandler);
326
+ page.off?.('console', consoleHandler);
327
+ },
328
+ };
364
329
  }
365
330
 
366
331
  const RISK_SIGNATURE = /禁止发笔记|违反|违规|审核未通过|账号异常|无法发布/;
@@ -735,9 +700,10 @@ async function enterImageMode(deps: ModeRunDeps, label: string): Promise<void> {
735
700
  */
736
701
  async function settleConsole(deps: ModeRunDeps): Promise<void> {
737
702
  let lastResponseAt = Date.now();
738
- deps.page.onContextResponse?.(() => {
703
+ const handler = (): void => {
739
704
  lastResponseAt = Date.now();
740
- });
705
+ };
706
+ deps.page.onContextResponse?.(handler);
741
707
  try {
742
708
  const start = Date.now();
743
709
  while (Date.now() - start < CONSOLE_SETTLE_MS) {
@@ -745,9 +711,7 @@ async function settleConsole(deps: ModeRunDeps): Promise<void> {
745
711
  await new Promise((resolve) => setTimeout(resolve, POLL_MS));
746
712
  }
747
713
  } finally {
748
- deps.page.offContextResponse?.(() => {
749
- lastResponseAt = Date.now();
750
- });
714
+ deps.page.offContextResponse?.(handler);
751
715
  }
752
716
  }
753
717
 
@@ -1156,64 +1120,68 @@ async function saveDraft(input: ModeInput, deps: ModeRunDeps): Promise<Result> {
1156
1120
  let signal: string | null = null;
1157
1121
  let attempts = 0;
1158
1122
  let capture: OutcomeCapture | null = null;
1159
- await armOutcomeCapture(deps.page);
1160
- while (signal === null && attempts < deps.submitAttempts) {
1161
- attempts += 1;
1162
- await sleep(deps.submitSettleMs);
1163
- // Host-method save first: the closed-shadow bar swallows synthetic coordinate clicks.
1164
- const method = await invokeHostSave(deps.page);
1165
- const control: Awaited<ReturnType<typeof clickActionControl>> =
1166
- method !== null
1167
- ? { ok: true, path: 'shadow', label: `_onSave:${method}`, click: 'shadow-host-method' }
1168
- : await clickActionControl(input.operation, deps, DRAFT_LABELS, 'draft control');
1169
- if (!control.ok) return fail(control.error);
1170
- clicked = control;
1171
- // The capture is refreshed inside the probe (expectOutcome swallows probe throws by
1172
- // design — the refusal is classified OUTSIDE, so it propagates as a typed error).
1173
- const outcome = await expectOutcome(
1174
- async () => {
1175
- if (capture === null) capture = await readOutcomeCapture(deps.page);
1176
- return draftSignalEvidence(deps.page, deps.draftBaseline);
1177
- },
1178
- {
1179
- timeoutMs: deps.submitSettleMs,
1180
- label: `draft confirmation '${control.label}'`,
1181
- pollMs: POLL_MS,
1182
- },
1183
- );
1184
- if (outcome.ok) signal = outcome.evidence;
1185
- else {
1186
- // A captured refusal must not be retried: refresh and re-check before another click.
1187
- capture = capture ?? (await readOutcomeCapture(deps.page));
1188
- assertCapturedOutcome(capture);
1123
+ const outcomeCapture = await armOutcomeCapture(deps.page, deps.stepTimeoutMs);
1124
+ try {
1125
+ while (signal === null && attempts < deps.submitAttempts) {
1126
+ attempts += 1;
1127
+ await sleep(deps.submitSettleMs);
1128
+ // Host-method save first: the closed-shadow bar swallows synthetic coordinate clicks.
1129
+ const method = await invokeHostSave(deps.page);
1130
+ const control: Awaited<ReturnType<typeof clickActionControl>> =
1131
+ method !== null
1132
+ ? { ok: true, path: 'shadow', label: `_onSave:${method}`, click: 'shadow-host-method' }
1133
+ : await clickActionControl(input.operation, deps, DRAFT_LABELS, 'draft control');
1134
+ if (!control.ok) return fail(control.error);
1135
+ clicked = control;
1136
+ // The capture is refreshed inside the probe (expectOutcome swallows probe throws by
1137
+ // design — the refusal is classified OUTSIDE, so it propagates as a typed error).
1138
+ const outcome = await expectOutcome(
1139
+ async () => {
1140
+ if (capture === null) capture = await outcomeCapture.read();
1141
+ return draftSignalEvidence(deps.page, deps.draftBaseline);
1142
+ },
1143
+ {
1144
+ timeoutMs: deps.submitSettleMs,
1145
+ label: `draft confirmation '${control.label}'`,
1146
+ pollMs: POLL_MS,
1147
+ },
1148
+ );
1149
+ if (outcome.ok) signal = outcome.evidence;
1150
+ else {
1151
+ // A captured refusal must not be retried: refresh and re-check before another click.
1152
+ capture = capture ?? (await outcomeCapture.read());
1153
+ assertCapturedOutcome(capture);
1154
+ }
1189
1155
  }
1156
+ if (capture === null) capture = await outcomeCapture.read();
1157
+ // The captured server response outranks every UI signal — a toast can lie while the API
1158
+ // refused (2026-11-09/10 runs) — so it is classified before any success is reported.
1159
+ assertCapturedOutcome(capture);
1160
+ const draftCountAfter = await readDraftCount(deps.page);
1161
+ if (signal === null || clicked === null) {
1162
+ return fail(
1163
+ `draft confirmation: '${clicked?.label ?? DRAFT_LABELS[0]}' was clicked ${attempts}× but neither a fresh ${TARGET} save timestamp, a moved draft counter, nor a scoped '${DRAFT_TOASTS[0]}' toast was observed within ${deps.submitSettleMs}ms (before=${String(deps.draftBaseline.count)}, after=${String(draftCountAfter)})`,
1164
+ );
1165
+ }
1166
+ return ResultSchema.parse({
1167
+ ok: true,
1168
+ target: TARGET,
1169
+ message: `${TARGET} draft saved (unpublished) in profile ${deps.profileDir} via '${clicked.label}' (${input.operation})`,
1170
+ metadata: {
1171
+ ...baseMetadata(input, deps),
1172
+ draftControl: clicked.label,
1173
+ draftClick: clicked.click,
1174
+ draftPath: clicked.path,
1175
+ draftAttempts: attempts,
1176
+ draftSignal: signal,
1177
+ draftCountBefore: deps.draftBaseline.count,
1178
+ draftCountAfter,
1179
+ ...captureMetadata(capture),
1180
+ },
1181
+ });
1182
+ } finally {
1183
+ outcomeCapture.dispose();
1190
1184
  }
1191
- if (capture === null) capture = await readOutcomeCapture(deps.page);
1192
- // The captured server response outranks every UI signal — a toast can lie while the API
1193
- // refused (2026-11-09/10 runs) — so it is classified before any success is reported.
1194
- assertCapturedOutcome(capture);
1195
- const draftCountAfter = await readDraftCount(deps.page);
1196
- if (signal === null || clicked === null) {
1197
- return fail(
1198
- `draft confirmation: '${clicked?.label ?? DRAFT_LABELS[0]}' was clicked ${attempts}× but neither a fresh ${TARGET} save timestamp, a moved draft counter, nor a scoped '${DRAFT_TOASTS[0]}' toast was observed within ${deps.submitSettleMs}ms (before=${String(deps.draftBaseline.count)}, after=${String(draftCountAfter)})`,
1199
- );
1200
- }
1201
- return ResultSchema.parse({
1202
- ok: true,
1203
- target: TARGET,
1204
- message: `${TARGET} draft saved (unpublished) in profile ${deps.profileDir} via '${clicked.label}' (${input.operation})`,
1205
- metadata: {
1206
- ...baseMetadata(input, deps),
1207
- draftControl: clicked.label,
1208
- draftClick: clicked.click,
1209
- draftPath: clicked.path,
1210
- draftAttempts: attempts,
1211
- draftSignal: signal,
1212
- draftCountBefore: deps.draftBaseline.count,
1213
- draftCountAfter,
1214
- ...captureMetadata(capture),
1215
- },
1216
- });
1217
1185
  }
1218
1186
 
1219
1187
  /**
@@ -1225,44 +1193,48 @@ async function saveDraft(input: ModeInput, deps: ModeRunDeps): Promise<Result> {
1225
1193
  async function publishNote(input: ModeInput, deps: ModeRunDeps): Promise<Result> {
1226
1194
  await sleep(deps.submitSettleMs);
1227
1195
  let capture: OutcomeCapture | null = null;
1228
- await armOutcomeCapture(deps.page);
1229
- const submitted = await clickActionControl(input.operation, deps, PUBLISH_LABELS, 'publish control');
1230
- if (!submitted.ok) return fail(submitted.error);
1231
-
1232
- const urlBeforeSubmit = deps.page.url();
1233
- const confirmed = await waitUntil(async () => {
1234
- // The captured refusal aborts immediately — waitUntil propagates the typed throw, and a
1235
- // publish click is never retried (unlike the draft loop there is no next attempt).
1236
- if (capture === null) capture = await readOutcomeCapture(deps.page);
1237
- assertCapturedOutcome(capture);
1238
- // The console rewrites its URL to `…published=true` once the post is accepted; the toast is
1239
- // the fallback, read scoped (never from the document at large).
1240
- if (deps.page.url().includes(PUBLISHED_MARKER)) return true;
1241
- return (await readScopedSignal(asPlaywrightPage(deps.page), PUBLISH_CONFIRM)) !== null;
1242
- }, deps.stepTimeoutMs);
1243
- if (!confirmed) {
1244
- // A refusal that lands late still outranks the "state unknown" timeout message.
1245
- capture = capture ?? (await readOutcomeCapture(deps.page));
1246
- assertCapturedOutcome(capture);
1247
- return fail(
1248
- `publish submission: state unknown — the '${submitted.label}' click (${submitted.click}) was sent from ${urlBeforeSubmit} but no success state was observed (now ${deps.page.url()}). Check the ${TARGET} creator note manager before retrying: a retry could duplicate the post.`,
1249
- );
1196
+ const outcomeCapture = await armOutcomeCapture(deps.page, deps.stepTimeoutMs);
1197
+ try {
1198
+ const submitted = await clickActionControl(input.operation, deps, PUBLISH_LABELS, 'publish control');
1199
+ if (!submitted.ok) return fail(submitted.error);
1200
+
1201
+ const urlBeforeSubmit = deps.page.url();
1202
+ const confirmed = await waitUntil(async () => {
1203
+ // The captured refusal aborts immediately — waitUntil propagates the typed throw, and a
1204
+ // publish click is never retried (unlike the draft loop there is no next attempt).
1205
+ if (capture === null) capture = await outcomeCapture.read();
1206
+ assertCapturedOutcome(capture);
1207
+ // The console rewrites its URL to `…published=true` once the post is accepted; the toast is
1208
+ // the fallback, read scoped (never from the document at large).
1209
+ if (deps.page.url().includes(PUBLISHED_MARKER)) return true;
1210
+ return (await readScopedSignal(asPlaywrightPage(deps.page), PUBLISH_CONFIRM)) !== null;
1211
+ }, deps.stepTimeoutMs);
1212
+ if (!confirmed) {
1213
+ // A refusal that lands late still outranks the "state unknown" timeout message.
1214
+ capture = capture ?? (await outcomeCapture.read());
1215
+ assertCapturedOutcome(capture);
1216
+ return fail(
1217
+ `publish submission: state unknown — the '${submitted.label}' click (${submitted.click}) was sent from ${urlBeforeSubmit} but no success state was observed (now ${deps.page.url()}). Check the ${TARGET} creator note manager before retrying: a retry could duplicate the post.`,
1218
+ );
1219
+ }
1220
+ const url = deps.page.url();
1221
+ return ResultSchema.parse({
1222
+ ok: true,
1223
+ target: TARGET,
1224
+ ...(url !== PUBLISH_URL ? { url } : {}),
1225
+ message: `${TARGET} ${input.operation} post published`,
1226
+ metadata: {
1227
+ ...baseMetadata(input, deps),
1228
+ publishControl: submitted.label,
1229
+ publishPath: submitted.path,
1230
+ publishClick: submitted.click,
1231
+ publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : 'toast',
1232
+ ...captureMetadata(capture),
1233
+ },
1234
+ });
1235
+ } finally {
1236
+ outcomeCapture.dispose();
1250
1237
  }
1251
- const url = deps.page.url();
1252
- return ResultSchema.parse({
1253
- ok: true,
1254
- target: TARGET,
1255
- ...(url !== PUBLISH_URL ? { url } : {}),
1256
- message: `${TARGET} ${input.operation} post published`,
1257
- metadata: {
1258
- ...baseMetadata(input, deps),
1259
- publishControl: submitted.label,
1260
- publishPath: submitted.path,
1261
- publishClick: submitted.click,
1262
- publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : 'toast',
1263
- ...captureMetadata(capture),
1264
- },
1265
- });
1266
1238
  }
1267
1239
 
1268
1240
  /** What the reopened draft must show for the save to count as server-side complete (R3). */