@gobing-ai/knowledge-kit 0.1.25 → 0.1.28

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 (62) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/collect/index.js +10 -0
  3. package/dist/board/daily-voice/index.js +1327 -2168
  4. package/dist/board/itc/index.js +10 -0
  5. package/dist/index.js +6043 -4620
  6. package/package.json +1 -1
  7. package/plugins/ingestions/aihot-ingest/dist/index.js +4 -1
  8. package/plugins/ingestions/aihot-ingest/src/rss.ts +22 -11
  9. package/plugins/kk/plugin.json +1 -1
  10. package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
  11. package/plugins/kk/scripts/daily-stages.ts +423 -141
  12. package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
  13. package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
  14. package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
  15. package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
  16. package/plugins/publishings/bilibili-pub/dist/index.js +114 -82
  17. package/plugins/publishings/bilibili-pub/dist/profile-check.js +34 -3
  18. package/plugins/publishings/cnblogs-pub/dist/index.js +114 -82
  19. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +34 -3
  20. package/plugins/publishings/csdn-pub/dist/index.js +114 -82
  21. package/plugins/publishings/csdn-pub/dist/profile-check.js +34 -3
  22. package/plugins/publishings/infoq-pub/dist/index.js +114 -82
  23. package/plugins/publishings/infoq-pub/dist/profile-check.js +34 -3
  24. package/plugins/publishings/jike-pub/dist/index.js +114 -82
  25. package/plugins/publishings/jike-pub/dist/profile-check.js +34 -3
  26. package/plugins/publishings/juejin-pub/dist/index.js +114 -82
  27. package/plugins/publishings/juejin-pub/dist/profile-check.js +34 -3
  28. package/plugins/publishings/linkedin-pub/dist/index.js +165 -93
  29. package/plugins/publishings/linkedin-pub/dist/profile-check.js +51 -6
  30. package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
  31. package/plugins/publishings/medium-pub/dist/index.js +114 -82
  32. package/plugins/publishings/medium-pub/dist/profile-check.js +34 -3
  33. package/plugins/publishings/shipinhao-pub/dist/index.js +305 -87
  34. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +145 -5
  35. package/plugins/publishings/shipinhao-pub/src/cover-crop.ts +60 -0
  36. package/plugins/publishings/shipinhao-pub/src/flow.ts +15 -2
  37. package/plugins/publishings/shipinhao-pub/src/profile-check.ts +15 -12
  38. package/plugins/publishings/shipinhao-pub/src/selectors.ts +22 -1
  39. package/plugins/publishings/sspai-pub/dist/index.js +114 -82
  40. package/plugins/publishings/sspai-pub/dist/profile-check.js +34 -3
  41. package/plugins/publishings/substack-pub/dist/index.js +114 -82
  42. package/plugins/publishings/substack-pub/dist/profile-check.js +34 -3
  43. package/plugins/publishings/surfdash-pub/dist/index.js +96 -20
  44. package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
  45. package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
  46. package/plugins/publishings/threads-pub/dist/index.js +119 -83
  47. package/plugins/publishings/threads-pub/dist/profile-check.js +34 -3
  48. package/plugins/publishings/threads-pub/src/index.ts +10 -0
  49. package/plugins/publishings/wechatmp-pub/dist/index.js +149 -86
  50. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +68 -4
  51. package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
  52. package/plugins/publishings/weibo-pub/dist/index.js +273 -91
  53. package/plugins/publishings/weibo-pub/dist/profile-check.js +178 -11
  54. package/plugins/publishings/weibo-pub/plugin.json +1 -1
  55. package/plugins/publishings/weibo-pub/src/index.ts +136 -10
  56. package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
  57. package/plugins/publishings/x-pub/dist/index.js +114 -82
  58. package/plugins/publishings/x-pub/dist/profile-check.js +34 -3
  59. package/plugins/publishings/xhs-pub/dist/index.js +114 -82
  60. package/plugins/publishings/xhs-pub/dist/profile-check.js +34 -3
  61. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +114 -82
  62. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +34 -3
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20219
20219
  const leaseDir = join2(leaseRoot, id);
20220
20220
  await fileSystem.ensureDir(leaseRoot);
20221
20221
  if (!mkdirExclusive(leaseDir, 448)) {
20222
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20222
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20223
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20224
+ }
20225
+ if (!mkdirExclusive(leaseDir, 448)) {
20226
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20227
+ }
20223
20228
  }
20224
20229
  const token = randomBytes(16).toString("hex");
20225
20230
  const owner = {
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20335
20340
  }
20336
20341
  return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
20337
20342
  }
20338
- const suffix = isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20343
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20344
+ const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20339
20345
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20340
20346
  }
20347
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20348
+ const owner = await readOwner(fileSystem, leaseDir);
20349
+ if (owner === null || isProcessAlive(owner.pid))
20350
+ return false;
20351
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20352
+ return false;
20353
+ const target = staleLeaseDir(leaseDir);
20354
+ try {
20355
+ rename(leaseDir, target);
20356
+ } catch {
20357
+ return false;
20358
+ }
20359
+ const moved = await readOwner(fileSystem, target);
20360
+ if (moved !== null && moved.token !== owner.token) {
20361
+ try {
20362
+ rename(target, leaseDir);
20363
+ } catch {}
20364
+ return false;
20365
+ }
20366
+ return true;
20367
+ }
20368
+ function staleLeaseDir(leaseDir) {
20369
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20370
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20371
+ }
20341
20372
  async function holderResidue(fileSystem, leaseDir) {
20342
20373
  try {
20343
20374
  const entries = await fileSystem.readDir(leaseDir);
@@ -20506,7 +20537,7 @@ function quarantineProfileSyncData(profileDir) {
20506
20537
  const syncData = join5(profileDir, "Default", "Sync Data");
20507
20538
  if (lstat(syncData) === null)
20508
20539
  return false;
20509
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20540
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20510
20541
  }
20511
20542
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20512
20543
  return {
@@ -21118,6 +21149,7 @@ var LINKEDIN_LOGIN_URL_RE = /(\/authwall|\/login|\/checkpoint)/;
21118
21149
  var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
21119
21150
  var LINKEDIN_POST_SELECTORS = {
21120
21151
  shareTrigger: [
21152
+ 'div[role="button"][aria-label="Start a post"]',
21121
21153
  'button:has-text("Start a post")',
21122
21154
  'div[role="button"]:has-text("Start a post")',
21123
21155
  'text="Start a post"',
@@ -21131,8 +21163,7 @@ var LINKEDIN_POST_SELECTORS = {
21131
21163
  'div[role="textbox"].tiptap',
21132
21164
  ".tiptap.ProseMirror",
21133
21165
  '[role="dialog"] div[role="textbox"]',
21134
- 'div.editor-content[contenteditable="true"]',
21135
- 'div[role="textbox"][contenteditable="true"]'
21166
+ 'div.editor-content[contenteditable="true"]'
21136
21167
  ],
21137
21168
  mediaButton: [
21138
21169
  'button[aria-label="Media"]',
@@ -21148,6 +21179,7 @@ var LINKEDIN_POST_SELECTORS = {
21148
21179
  ]
21149
21180
  };
21150
21181
  var LOGIN_TIMEOUT_MS = 180000;
21182
+ var LINKEDIN_LOGIN_INSTRUCTION = "bun plugins/publishings/linkedin-pub/src/profile-check.ts login";
21151
21183
  var isLinkedinAuthenticated = async (page) => {
21152
21184
  if (LINKEDIN_LOGIN_URL_RE.test(page.url()))
21153
21185
  return false;
@@ -21160,11 +21192,24 @@ var isLinkedinAuthenticated = async (page) => {
21160
21192
  return false;
21161
21193
  }
21162
21194
  };
21195
+ var LINKEDIN_AUTH_COOKIE = "li_at";
21196
+ function hasLinkedinAuthCookie(cookies, nowMs = Date.now()) {
21197
+ return cookies.some((cookie) => cookie.name === LINKEDIN_AUTH_COOKIE && (cookie.value ?? "") !== "" && (cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs));
21198
+ }
21163
21199
  var LINKEDIN_CONFIG = {
21164
21200
  channel: TARGET,
21165
21201
  homeUrl: LINKEDIN_HOME_URL,
21166
21202
  isAuthenticated: isLinkedinAuthenticated,
21167
- loginTimeoutMs: LOGIN_TIMEOUT_MS
21203
+ loginTimeoutMs: LOGIN_TIMEOUT_MS,
21204
+ checkHeadedOnly: true,
21205
+ sessionState: {
21206
+ onAuthenticated: async ({ context }) => {
21207
+ const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => []);
21208
+ if (hasLinkedinAuthCookie(cookies))
21209
+ return;
21210
+ throw new Error(`the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` + `saved \u2014 confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`);
21211
+ }
21212
+ }
21168
21213
  };
21169
21214
  if (false) {}
21170
21215
 
@@ -85,6 +85,10 @@ export const LINKEDIN_POST_SELECTORS = {
85
85
  // clicking THAT does not open the composer (the run then timed out in the composer stage and
86
86
  // reported "composer did not open … selector drift"). The has-text forms hit the clickable
87
87
  // ancestor; the text form stays last for the previous UI.
88
+ // Measured 2026-11-25 (0437 recon, `.spur/run/dogfood/2026-11-25-linkedin/`): no `<button>` carries
89
+ // the text any more — the one visible trigger is `div[role=button][aria-label="Start a post"]`
90
+ // with obfuscated classes. The exact aria form leads so no descendant-text match can win.
91
+ 'div[role="button"][aria-label="Start a post"]',
88
92
  'button:has-text("Start a post")',
89
93
  'div[role="button"]:has-text("Start a post")',
90
94
  'text="Start a post"',
@@ -101,7 +105,6 @@ export const LINKEDIN_POST_SELECTORS = {
101
105
  '.tiptap.ProseMirror',
102
106
  '[role="dialog"] div[role="textbox"]',
103
107
  'div.editor-content[contenteditable="true"]',
104
- 'div[role="textbox"][contenteditable="true"]',
105
108
  ],
106
109
  mediaButton: [
107
110
  'button[aria-label="Media"]',
@@ -134,6 +137,15 @@ const PREVIEW_POLL_MS = 250;
134
137
  const LINK_PREVIEW_TIMEOUT_MS = 10_000;
135
138
 
136
139
  const STEP_TIMEOUT_MS = 30_000;
140
+ /**
141
+ * Default budget for the read-only session preflight. The harness subtracts a print margin and a
142
+ * launch reserve from whatever it is given, so the 30 s STEP_TIMEOUT_MS became an ~18 s pass — and on
143
+ * 2026-11-24 that was short enough that a freshly signed-in profile reported "not confirmed", after
144
+ * which LinkedIn cleared `li_at` and the sign-in was lost. 90 s covers a cold headed feed load.
145
+ * An explicit `stepTimeoutMs` dep overrides it, so tests and callers that tune the step budget also
146
+ * tune the preflight.
147
+ */
148
+ const PREFLIGHT_TIMEOUT_MS = 90_000;
137
149
  const LOGIN_TIMEOUT_MS = 180_000;
138
150
  /** Operator recovery command every session failure names — never a cookie, DOM dump or stack. */
139
151
  export const LINKEDIN_LOGIN_INSTRUCTION = 'bun plugins/publishings/linkedin-pub/src/profile-check.ts login';
@@ -154,6 +166,45 @@ function stageFail(error: string, stage: string, metadata: Record<string, unknow
154
166
  });
155
167
  }
156
168
 
169
+ /**
170
+ * A stage failure raised before the Post click: nothing reached LinkedIn, so the receipt is
171
+ * `failed/none` and `--retry` resends without `--confirm-none` (0437 R4; same marker as
172
+ * `weibo-pub`'s `refuse`). Never used at or after the Post click — those stay `effect: unknown`.
173
+ */
174
+ function preSubmitFail(error: string, stage: string, metadata: Record<string, unknown>): Result {
175
+ return stageFail(error, stage, { ...metadata, itcDelivery: { schemaVersion: 1, effect: 'none' } });
176
+ }
177
+
178
+ /**
179
+ * What the page held when the composer never opened (0437 R2): match counts of the trigger that was
180
+ * clicked, every composer candidate's count, the url and the frame count — so the next drift is
181
+ * diagnosable from the receipt alone. Counts only: no DOM text ever leaves the page.
182
+ */
183
+ async function probeComposer(
184
+ page: Page,
185
+ trigger: string,
186
+ ): Promise<{
187
+ trigger: string;
188
+ triggerMatches: number;
189
+ triggerVisible: number;
190
+ candidates: Record<string, number>;
191
+ url: string;
192
+ frames: number;
193
+ }> {
194
+ const count = (locator: { count(): Promise<number> }) => locator.count().catch(() => -1);
195
+ const triggerLocator = page.locator(trigger);
196
+ const candidates: Record<string, number> = {};
197
+ for (const selector of LINKEDIN_POST_SELECTORS.composer) candidates[selector] = await count(page.locator(selector));
198
+ return {
199
+ trigger,
200
+ triggerMatches: await count(triggerLocator),
201
+ triggerVisible: await count(triggerLocator.filter({ visible: true })),
202
+ candidates,
203
+ url: page.url(),
204
+ frames: typeof page.frames === 'function' ? page.frames().length : 0,
205
+ };
206
+ }
207
+
157
208
  /** One short line, bounded: no DOM dump, cookie, token or stack ever reaches the Result. */
158
209
  function boundedDetail(detail: string): string {
159
210
  return detail.replace(/\s+/g, ' ').trim().slice(0, 300);
@@ -229,6 +280,36 @@ export const isLinkedinAuthenticated: IsAuthenticatedPredicate = async (page) =>
229
280
  }
230
281
  };
231
282
 
283
+ /**
284
+ * LinkedIn's session ticket. The readiness predicate only sees the rendered page, so a profile can
285
+ * pass it and still carry no session at all — the measured 2026-11-24 shape was `li_at` at 0 rows
286
+ * (`select count(*) from cookies where name='li_at'`) after two separate operator sign-ins. Name
287
+ * only: this module never reads, logs or returns the value.
288
+ */
289
+ export const LINKEDIN_AUTH_COOKIE = 'li_at';
290
+
291
+ /** The cookie facts this assertion reads — everything but the value. */
292
+ export interface StoredCookie {
293
+ name: string;
294
+ value?: string;
295
+ /** Seconds since the epoch; Playwright reports a session cookie as `-1`. */
296
+ expires?: number;
297
+ }
298
+
299
+ /**
300
+ * `true` when the jar holds a usable {@link LINKEDIN_AUTH_COOKIE} (0436 R4). A non-empty value that
301
+ * has not expired is the whole test: an expired or empty ticket cannot authenticate anything, so
302
+ * reporting a login from it would leave exactly the profile every later check calls "expired".
303
+ */
304
+ export function hasLinkedinAuthCookie(cookies: readonly StoredCookie[], nowMs: number = Date.now()): boolean {
305
+ return cookies.some(
306
+ (cookie) =>
307
+ cookie.name === LINKEDIN_AUTH_COOKIE &&
308
+ (cookie.value ?? '') !== '' &&
309
+ (cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs),
310
+ );
311
+ }
312
+
232
313
  /**
233
314
  * Site-owned config for the shared session check and operator CLI (ADR-032). The publish preflight
234
315
  * never forwards a headed fallback: it is the operator CLI's setting, and a refusal must never
@@ -239,6 +320,28 @@ export const LINKEDIN_CONFIG: ChannelBrowserConfig = {
239
320
  homeUrl: LINKEDIN_HOME_URL,
240
321
  isAuthenticated: isLinkedinAuthenticated,
241
322
  loginTimeoutMs: LOGIN_TIMEOUT_MS,
323
+ // Headless with a SIGNED-IN profile lands on the login wall (measured 2026-11-24: `check`
324
+ // refused in 68 s while `check --headed` verified on the same profile, and the same pair of
325
+ // launches repeated after two operator sign-ins). A headless preflight pass is therefore a
326
+ // guaranteed burn, and the post flow is headed anyway — so the preflight probes headed, the
327
+ // same shape medium-pub carries for its Cloudflare interstitial.
328
+ checkHeadedOnly: true,
329
+ // This channel has no `storageState` artifact — the profile's own cookie store is the session —
330
+ // so the hook is used as the post-login ASSERTION instead of a capture: a sign-in the page
331
+ // predicate accepted but that stored no auth ticket fails here, at the login that produced it,
332
+ // rather than silently leaving a profile every later `check` refuses (0436 R4). A hook throw
333
+ // already fails the verb and suppresses the `verified` verdict, so the bot parent promotes
334
+ // nothing. No cookie name/value pair is ever logged: the message names the cookie only.
335
+ sessionState: {
336
+ onAuthenticated: async ({ context }) => {
337
+ const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => [] as StoredCookie[]);
338
+ if (hasLinkedinAuthCookie(cookies)) return;
339
+ throw new Error(
340
+ `the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` +
341
+ `saved — confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`,
342
+ );
343
+ },
344
+ },
242
345
  };
243
346
 
244
347
  /**
@@ -294,6 +397,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
294
397
  private readonly operation: LinkedinOperation;
295
398
  private readonly launcher: BrowserLauncher;
296
399
  private readonly stepTimeoutMs: number;
400
+ private readonly preflightTimeoutMs: number;
297
401
  constructor(
298
402
  operation: LinkedinOperation = 'post',
299
403
  driver: BrowserDriver = 'script',
@@ -303,6 +407,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
303
407
  this.driver = driver;
304
408
  this.launcher = deps.launcher ?? kkBrowserLauncher;
305
409
  this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
410
+ this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
306
411
  }
307
412
 
308
413
  /**
@@ -347,8 +452,9 @@ export class LinkedinBrowserTransport implements PublishTransport {
347
452
  const session = await checkChannelSession(LINKEDIN_CONFIG, {
348
453
  profileDir,
349
454
  launcher: this.launcher,
350
- headedFallback: false,
351
- timeoutMs: this.stepTimeoutMs,
455
+ // Headed, not headless: see LINKEDIN_CONFIG.checkHeadedOnly (measured 2026-11-24).
456
+ headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
457
+ timeoutMs: this.preflightTimeoutMs,
352
458
  });
353
459
  if (session.status !== 'verified') {
354
460
  // The recovery command leads the message: `fail()` bounds the line, and the operator's
@@ -409,13 +515,15 @@ export class LinkedinBrowserTransport implements PublishTransport {
409
515
  label: 'linkedin share box',
410
516
  });
411
517
  } catch {
412
- return stageFail(
518
+ return preSubmitFail(
413
519
  `linkedin share box not found on ${LINKEDIN_HOME_URL} (session may be logged out, or the selector drifted) — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
414
520
  'share-trigger',
415
521
  metadata,
416
522
  );
417
523
  }
418
- await page.locator(triggerSelector).first().click();
524
+ // Visible match only (0437 R1): `resolveSelector` resolves attached nodes, so a hidden duplicate
525
+ // can resolve first and swallow the click while the composer never opens.
526
+ await page.locator(triggerSelector).filter({ visible: true }).first().click();
419
527
 
420
528
  // Modal editor. A missing editor after the click is the same loud typed refusal family.
421
529
  // The share box is a React target that can be clicked before the feed finishes hydrating
@@ -435,6 +543,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
435
543
  if (retryTrigger !== null)
436
544
  await page
437
545
  .locator(retryTrigger)
546
+ .filter({ visible: true })
438
547
  .first()
439
548
  .click()
440
549
  .catch(() => {});
@@ -444,10 +553,18 @@ export class LinkedinBrowserTransport implements PublishTransport {
444
553
  }).catch(() => '');
445
554
  }
446
555
  if (composerSelector === '') {
556
+ const probe = await probeComposer(page, triggerSelector);
557
+ const counts = Object.values(probe.candidates);
558
+ const found = counts.every((n) => n === 0) ? 'all 0' : counts.map((n, i) => `#${i}=${n}`).join(',');
559
+ // Counts lead and the login hint trails inside the 300-char bound; the full selector→count
560
+ // map rides in `metadata.composerProbe`. The screenshot is the visual twin of the send stage's.
561
+ await Promise.resolve()
562
+ .then(() => page.screenshot({ path: '/tmp/kk-linkedin-composer-latest.png' }))
563
+ .catch(() => null);
447
564
  return stageFail(
448
- `linkedin composer did not open after the share box, twice (selector drift) — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
565
+ `linkedin composer did not open after the share box, twice — trigger ${probe.trigger} (matches ${probe.triggerMatches}, visible ${probe.triggerVisible}); composer candidates ${found}; url ${probe.url}; frames ${probe.frames} — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
449
566
  'composer',
450
- metadata,
567
+ { ...metadata, composerProbe: probe, itcDelivery: { schemaVersion: 1, effect: 'none' } },
451
568
  );
452
569
  }
453
570
  const composer = page.locator(composerSelector).first();
@@ -463,7 +580,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
463
580
 
464
581
  // Readback before anything else: a field the editor dropped must never be submitted.
465
582
  const readback = await this.requireReadback(page, composerSelector, text);
466
- if (!readback.ok) return stageFail(readback.error, 'text-readback', metadata);
583
+ if (!readback.ok) return preSubmitFail(readback.error, 'text-readback', metadata);
467
584
 
468
585
  // Image upload: confirmed landed; an unconfirmed upload refuses before submit — never a
469
586
  // silent text-only post while an image was requested. When posting a URL with no image,
@@ -471,7 +588,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
471
588
  const [image] = images;
472
589
  if (image !== undefined) {
473
590
  const uploaded = await this.uploadImage(page, image);
474
- if (!uploaded.ok) return stageFail(uploaded.error, 'image-upload', metadata);
591
+ if (!uploaded.ok) return preSubmitFail(uploaded.error, 'image-upload', metadata);
475
592
  } else {
476
593
  await this.waitForLinkPreview(page, composerSelector, text);
477
594
  }
@@ -20171,6 +20171,86 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
20171
20171
  import { homedir } from "os";
20172
20172
  import { join, resolve } from "path";
20173
20173
 
20174
+ // ../../packages/publish-harness/src/bot-fs.ts
20175
+ import {
20176
+ chmodSync,
20177
+ closeSync,
20178
+ copyFileSync,
20179
+ lstatSync,
20180
+ mkdirSync as mkdirSync2,
20181
+ openSync,
20182
+ readdirSync as readdirSync2,
20183
+ readlinkSync,
20184
+ realpathSync as realpathSync2,
20185
+ renameSync as renameSync2,
20186
+ rmdirSync,
20187
+ unlinkSync
20188
+ } from "fs";
20189
+ function lstat(path) {
20190
+ try {
20191
+ return lstatSync(path);
20192
+ } catch (error) {
20193
+ if (error.code === "ENOENT")
20194
+ return null;
20195
+ throw error;
20196
+ }
20197
+ }
20198
+ function realpath(path) {
20199
+ return realpathSync2(path);
20200
+ }
20201
+ function mkdirExclusive(path, mode = 448) {
20202
+ try {
20203
+ mkdirSync2(path, { mode });
20204
+ return true;
20205
+ } catch (error) {
20206
+ if (error.code === "EEXIST")
20207
+ return false;
20208
+ throw error;
20209
+ }
20210
+ }
20211
+ function rmdir(path) {
20212
+ try {
20213
+ rmdirSync(path);
20214
+ return true;
20215
+ } catch (error) {
20216
+ const code = error.code;
20217
+ if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
20218
+ return false;
20219
+ throw error;
20220
+ }
20221
+ }
20222
+ function readlink(path) {
20223
+ try {
20224
+ return readlinkSync(path);
20225
+ } catch {
20226
+ return null;
20227
+ }
20228
+ }
20229
+ function unlink(path) {
20230
+ try {
20231
+ unlinkSync(path);
20232
+ return true;
20233
+ } catch (error) {
20234
+ if (error.code === "ENOENT")
20235
+ return false;
20236
+ throw error;
20237
+ }
20238
+ }
20239
+ function rename(from, to) {
20240
+ try {
20241
+ renameSync2(from, to);
20242
+ return true;
20243
+ } catch (error) {
20244
+ if (error.code === "ENOENT")
20245
+ return false;
20246
+ throw error;
20247
+ }
20248
+ }
20249
+ function chmod(path, mode) {
20250
+ chmodSync(path, mode);
20251
+ }
20252
+
20253
+ // ../../packages/publish-harness/src/index.ts
20174
20254
  class FakeTransportCore {
20175
20255
  callLogs = [];
20176
20256
  nextResult;
@@ -20454,85 +20534,6 @@ init_dist();
20454
20534
  import { homedir as homedir4 } from "os";
20455
20535
  import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
20456
20536
 
20457
- // ../../packages/publish-harness/src/bot-fs.ts
20458
- import {
20459
- chmodSync,
20460
- closeSync,
20461
- copyFileSync,
20462
- lstatSync,
20463
- mkdirSync as mkdirSync2,
20464
- openSync,
20465
- readdirSync as readdirSync2,
20466
- readlinkSync,
20467
- realpathSync as realpathSync2,
20468
- renameSync as renameSync2,
20469
- rmdirSync,
20470
- unlinkSync
20471
- } from "fs";
20472
- function lstat(path) {
20473
- try {
20474
- return lstatSync(path);
20475
- } catch (error) {
20476
- if (error.code === "ENOENT")
20477
- return null;
20478
- throw error;
20479
- }
20480
- }
20481
- function realpath(path) {
20482
- return realpathSync2(path);
20483
- }
20484
- function mkdirExclusive(path, mode = 448) {
20485
- try {
20486
- mkdirSync2(path, { mode });
20487
- return true;
20488
- } catch (error) {
20489
- if (error.code === "EEXIST")
20490
- return false;
20491
- throw error;
20492
- }
20493
- }
20494
- function rmdir(path) {
20495
- try {
20496
- rmdirSync(path);
20497
- return true;
20498
- } catch (error) {
20499
- const code = error.code;
20500
- if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
20501
- return false;
20502
- throw error;
20503
- }
20504
- }
20505
- function readlink(path) {
20506
- try {
20507
- return readlinkSync(path);
20508
- } catch {
20509
- return null;
20510
- }
20511
- }
20512
- function unlink(path) {
20513
- try {
20514
- unlinkSync(path);
20515
- return true;
20516
- } catch (error) {
20517
- if (error.code === "ENOENT")
20518
- return false;
20519
- throw error;
20520
- }
20521
- }
20522
- function rename(from, to) {
20523
- try {
20524
- renameSync2(from, to);
20525
- return true;
20526
- } catch (error) {
20527
- if (error.code === "ENOENT")
20528
- return false;
20529
- throw error;
20530
- }
20531
- }
20532
- function chmod(path, mode) {
20533
- chmodSync(path, mode);
20534
- }
20535
-
20536
20537
  // ../../packages/publish-harness/src/bot-transaction.ts
20537
20538
  import { homedir as homedir2 } from "os";
20538
20539
  import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
@@ -20557,7 +20558,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20557
20558
  const leaseDir = join3(leaseRoot, id);
20558
20559
  await fileSystem.ensureDir(leaseRoot);
20559
20560
  if (!mkdirExclusive(leaseDir, 448)) {
20560
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20561
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20562
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20563
+ }
20564
+ if (!mkdirExclusive(leaseDir, 448)) {
20565
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20566
+ }
20561
20567
  }
20562
20568
  const token = randomBytes(16).toString("hex");
20563
20569
  const owner = {
@@ -20673,9 +20679,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20673
20679
  }
20674
20680
  return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
20675
20681
  }
20676
- const suffix = isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20682
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20683
+ const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20677
20684
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20678
20685
  }
20686
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20687
+ const owner = await readOwner(fileSystem, leaseDir);
20688
+ if (owner === null || isProcessAlive(owner.pid))
20689
+ return false;
20690
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20691
+ return false;
20692
+ const target = staleLeaseDir(leaseDir);
20693
+ try {
20694
+ rename(leaseDir, target);
20695
+ } catch {
20696
+ return false;
20697
+ }
20698
+ const moved = await readOwner(fileSystem, target);
20699
+ if (moved !== null && moved.token !== owner.token) {
20700
+ try {
20701
+ rename(target, leaseDir);
20702
+ } catch {}
20703
+ return false;
20704
+ }
20705
+ return true;
20706
+ }
20707
+ function staleLeaseDir(leaseDir) {
20708
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20709
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20710
+ }
20679
20711
  async function holderResidue(fileSystem, leaseDir) {
20680
20712
  try {
20681
20713
  const entries = await fileSystem.readDir(leaseDir);
@@ -20801,7 +20833,7 @@ function quarantineProfileSyncData(profileDir) {
20801
20833
  const syncData = join5(profileDir, "Default", "Sync Data");
20802
20834
  if (lstat(syncData) === null)
20803
20835
  return false;
20804
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20836
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20805
20837
  }
20806
20838
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20807
20839
  return {
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20219
20219
  const leaseDir = join2(leaseRoot, id);
20220
20220
  await fileSystem.ensureDir(leaseRoot);
20221
20221
  if (!mkdirExclusive(leaseDir, 448)) {
20222
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20222
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20223
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20224
+ }
20225
+ if (!mkdirExclusive(leaseDir, 448)) {
20226
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20227
+ }
20223
20228
  }
20224
20229
  const token = randomBytes(16).toString("hex");
20225
20230
  const owner = {
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20335
20340
  }
20336
20341
  return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
20337
20342
  }
20338
- const suffix = isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20343
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20344
+ const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
20339
20345
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20340
20346
  }
20347
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20348
+ const owner = await readOwner(fileSystem, leaseDir);
20349
+ if (owner === null || isProcessAlive(owner.pid))
20350
+ return false;
20351
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20352
+ return false;
20353
+ const target = staleLeaseDir(leaseDir);
20354
+ try {
20355
+ rename(leaseDir, target);
20356
+ } catch {
20357
+ return false;
20358
+ }
20359
+ const moved = await readOwner(fileSystem, target);
20360
+ if (moved !== null && moved.token !== owner.token) {
20361
+ try {
20362
+ rename(target, leaseDir);
20363
+ } catch {}
20364
+ return false;
20365
+ }
20366
+ return true;
20367
+ }
20368
+ function staleLeaseDir(leaseDir) {
20369
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20370
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20371
+ }
20341
20372
  async function holderResidue(fileSystem, leaseDir) {
20342
20373
  try {
20343
20374
  const entries = await fileSystem.readDir(leaseDir);
@@ -20506,7 +20537,7 @@ function quarantineProfileSyncData(profileDir) {
20506
20537
  const syncData = join5(profileDir, "Default", "Sync Data");
20507
20538
  if (lstat(syncData) === null)
20508
20539
  return false;
20509
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20540
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20510
20541
  }
20511
20542
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20512
20543
  return {