@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
@@ -20172,6 +20172,86 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
20172
20172
  import { homedir } from "os";
20173
20173
  import { join, resolve } from "path";
20174
20174
 
20175
+ // ../../packages/publish-harness/src/bot-fs.ts
20176
+ import {
20177
+ chmodSync,
20178
+ closeSync,
20179
+ copyFileSync,
20180
+ lstatSync,
20181
+ mkdirSync as mkdirSync2,
20182
+ openSync,
20183
+ readdirSync as readdirSync2,
20184
+ readlinkSync,
20185
+ realpathSync as realpathSync2,
20186
+ renameSync as renameSync2,
20187
+ rmdirSync,
20188
+ unlinkSync
20189
+ } from "fs";
20190
+ function lstat(path) {
20191
+ try {
20192
+ return lstatSync(path);
20193
+ } catch (error) {
20194
+ if (error.code === "ENOENT")
20195
+ return null;
20196
+ throw error;
20197
+ }
20198
+ }
20199
+ function realpath(path) {
20200
+ return realpathSync2(path);
20201
+ }
20202
+ function mkdirExclusive(path, mode = 448) {
20203
+ try {
20204
+ mkdirSync2(path, { mode });
20205
+ return true;
20206
+ } catch (error) {
20207
+ if (error.code === "EEXIST")
20208
+ return false;
20209
+ throw error;
20210
+ }
20211
+ }
20212
+ function rmdir(path) {
20213
+ try {
20214
+ rmdirSync(path);
20215
+ return true;
20216
+ } catch (error) {
20217
+ const code = error.code;
20218
+ if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
20219
+ return false;
20220
+ throw error;
20221
+ }
20222
+ }
20223
+ function readlink(path) {
20224
+ try {
20225
+ return readlinkSync(path);
20226
+ } catch {
20227
+ return null;
20228
+ }
20229
+ }
20230
+ function unlink(path) {
20231
+ try {
20232
+ unlinkSync(path);
20233
+ return true;
20234
+ } catch (error) {
20235
+ if (error.code === "ENOENT")
20236
+ return false;
20237
+ throw error;
20238
+ }
20239
+ }
20240
+ function rename(from, to) {
20241
+ try {
20242
+ renameSync2(from, to);
20243
+ return true;
20244
+ } catch (error) {
20245
+ if (error.code === "ENOENT")
20246
+ return false;
20247
+ throw error;
20248
+ }
20249
+ }
20250
+ function chmod(path, mode) {
20251
+ chmodSync(path, mode);
20252
+ }
20253
+
20254
+ // ../../packages/publish-harness/src/index.ts
20175
20255
  class FakeTransportCore {
20176
20256
  callLogs = [];
20177
20257
  nextResult;
@@ -20480,85 +20560,6 @@ init_dist();
20480
20560
  import { homedir as homedir4 } from "os";
20481
20561
  import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
20482
20562
 
20483
- // ../../packages/publish-harness/src/bot-fs.ts
20484
- import {
20485
- chmodSync,
20486
- closeSync,
20487
- copyFileSync,
20488
- lstatSync,
20489
- mkdirSync as mkdirSync2,
20490
- openSync,
20491
- readdirSync as readdirSync2,
20492
- readlinkSync,
20493
- realpathSync as realpathSync2,
20494
- renameSync as renameSync2,
20495
- rmdirSync,
20496
- unlinkSync
20497
- } from "fs";
20498
- function lstat(path) {
20499
- try {
20500
- return lstatSync(path);
20501
- } catch (error) {
20502
- if (error.code === "ENOENT")
20503
- return null;
20504
- throw error;
20505
- }
20506
- }
20507
- function realpath(path) {
20508
- return realpathSync2(path);
20509
- }
20510
- function mkdirExclusive(path, mode = 448) {
20511
- try {
20512
- mkdirSync2(path, { mode });
20513
- return true;
20514
- } catch (error) {
20515
- if (error.code === "EEXIST")
20516
- return false;
20517
- throw error;
20518
- }
20519
- }
20520
- function rmdir(path) {
20521
- try {
20522
- rmdirSync(path);
20523
- return true;
20524
- } catch (error) {
20525
- const code = error.code;
20526
- if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
20527
- return false;
20528
- throw error;
20529
- }
20530
- }
20531
- function readlink(path) {
20532
- try {
20533
- return readlinkSync(path);
20534
- } catch {
20535
- return null;
20536
- }
20537
- }
20538
- function unlink(path) {
20539
- try {
20540
- unlinkSync(path);
20541
- return true;
20542
- } catch (error) {
20543
- if (error.code === "ENOENT")
20544
- return false;
20545
- throw error;
20546
- }
20547
- }
20548
- function rename(from, to) {
20549
- try {
20550
- renameSync2(from, to);
20551
- return true;
20552
- } catch (error) {
20553
- if (error.code === "ENOENT")
20554
- return false;
20555
- throw error;
20556
- }
20557
- }
20558
- function chmod(path, mode) {
20559
- chmodSync(path, mode);
20560
- }
20561
-
20562
20563
  // ../../packages/publish-harness/src/bot-transaction.ts
20563
20564
  import { homedir as homedir2 } from "os";
20564
20565
  import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
@@ -20583,7 +20584,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20583
20584
  const leaseDir = join3(leaseRoot, id);
20584
20585
  await fileSystem.ensureDir(leaseRoot);
20585
20586
  if (!mkdirExclusive(leaseDir, 448)) {
20586
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20587
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20588
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20589
+ }
20590
+ if (!mkdirExclusive(leaseDir, 448)) {
20591
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20592
+ }
20587
20593
  }
20588
20594
  const token = randomBytes(16).toString("hex");
20589
20595
  const owner = {
@@ -20699,9 +20705,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20699
20705
  }
20700
20706
  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`;
20701
20707
  }
20702
- 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}`;
20708
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20709
+ 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}`;
20703
20710
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20704
20711
  }
20712
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20713
+ const owner = await readOwner(fileSystem, leaseDir);
20714
+ if (owner === null || isProcessAlive(owner.pid))
20715
+ return false;
20716
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20717
+ return false;
20718
+ const target = staleLeaseDir(leaseDir);
20719
+ try {
20720
+ rename(leaseDir, target);
20721
+ } catch {
20722
+ return false;
20723
+ }
20724
+ const moved = await readOwner(fileSystem, target);
20725
+ if (moved !== null && moved.token !== owner.token) {
20726
+ try {
20727
+ rename(target, leaseDir);
20728
+ } catch {}
20729
+ return false;
20730
+ }
20731
+ return true;
20732
+ }
20733
+ function staleLeaseDir(leaseDir) {
20734
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20735
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20736
+ }
20705
20737
  async function holderResidue(fileSystem, leaseDir) {
20706
20738
  try {
20707
20739
  const entries = await fileSystem.readDir(leaseDir);
@@ -20827,7 +20859,7 @@ function quarantineProfileSyncData(profileDir) {
20827
20859
  const syncData = join5(profileDir, "Default", "Sync Data");
20828
20860
  if (lstat(syncData) === null)
20829
20861
  return false;
20830
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20862
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20831
20863
  }
20832
20864
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20833
20865
  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 {
@@ -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;
@@ -20455,85 +20535,6 @@ init_dist();
20455
20535
  import { homedir as homedir4 } from "os";
20456
20536
  import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
20457
20537
 
20458
- // ../../packages/publish-harness/src/bot-fs.ts
20459
- import {
20460
- chmodSync,
20461
- closeSync,
20462
- copyFileSync,
20463
- lstatSync,
20464
- mkdirSync as mkdirSync2,
20465
- openSync,
20466
- readdirSync as readdirSync2,
20467
- readlinkSync,
20468
- realpathSync as realpathSync2,
20469
- renameSync as renameSync2,
20470
- rmdirSync,
20471
- unlinkSync
20472
- } from "fs";
20473
- function lstat(path) {
20474
- try {
20475
- return lstatSync(path);
20476
- } catch (error) {
20477
- if (error.code === "ENOENT")
20478
- return null;
20479
- throw error;
20480
- }
20481
- }
20482
- function realpath(path) {
20483
- return realpathSync2(path);
20484
- }
20485
- function mkdirExclusive(path, mode = 448) {
20486
- try {
20487
- mkdirSync2(path, { mode });
20488
- return true;
20489
- } catch (error) {
20490
- if (error.code === "EEXIST")
20491
- return false;
20492
- throw error;
20493
- }
20494
- }
20495
- function rmdir(path) {
20496
- try {
20497
- rmdirSync(path);
20498
- return true;
20499
- } catch (error) {
20500
- const code = error.code;
20501
- if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
20502
- return false;
20503
- throw error;
20504
- }
20505
- }
20506
- function readlink(path) {
20507
- try {
20508
- return readlinkSync(path);
20509
- } catch {
20510
- return null;
20511
- }
20512
- }
20513
- function unlink(path) {
20514
- try {
20515
- unlinkSync(path);
20516
- return true;
20517
- } catch (error) {
20518
- if (error.code === "ENOENT")
20519
- return false;
20520
- throw error;
20521
- }
20522
- }
20523
- function rename(from, to) {
20524
- try {
20525
- renameSync2(from, to);
20526
- return true;
20527
- } catch (error) {
20528
- if (error.code === "ENOENT")
20529
- return false;
20530
- throw error;
20531
- }
20532
- }
20533
- function chmod(path, mode) {
20534
- chmodSync(path, mode);
20535
- }
20536
-
20537
20538
  // ../../packages/publish-harness/src/bot-transaction.ts
20538
20539
  import { homedir as homedir2 } from "os";
20539
20540
  import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
@@ -20558,7 +20559,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20558
20559
  const leaseDir = join3(leaseRoot, id);
20559
20560
  await fileSystem.ensureDir(leaseRoot);
20560
20561
  if (!mkdirExclusive(leaseDir, 448)) {
20561
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20562
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20563
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20564
+ }
20565
+ if (!mkdirExclusive(leaseDir, 448)) {
20566
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20567
+ }
20562
20568
  }
20563
20569
  const token = randomBytes(16).toString("hex");
20564
20570
  const owner = {
@@ -20674,9 +20680,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20674
20680
  }
20675
20681
  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`;
20676
20682
  }
20677
- 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}`;
20683
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20684
+ 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}`;
20678
20685
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20679
20686
  }
20687
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20688
+ const owner = await readOwner(fileSystem, leaseDir);
20689
+ if (owner === null || isProcessAlive(owner.pid))
20690
+ return false;
20691
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20692
+ return false;
20693
+ const target = staleLeaseDir(leaseDir);
20694
+ try {
20695
+ rename(leaseDir, target);
20696
+ } catch {
20697
+ return false;
20698
+ }
20699
+ const moved = await readOwner(fileSystem, target);
20700
+ if (moved !== null && moved.token !== owner.token) {
20701
+ try {
20702
+ rename(target, leaseDir);
20703
+ } catch {}
20704
+ return false;
20705
+ }
20706
+ return true;
20707
+ }
20708
+ function staleLeaseDir(leaseDir) {
20709
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20710
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20711
+ }
20680
20712
  async function holderResidue(fileSystem, leaseDir) {
20681
20713
  try {
20682
20714
  const entries = await fileSystem.readDir(leaseDir);
@@ -20802,7 +20834,7 @@ function quarantineProfileSyncData(profileDir) {
20802
20834
  const syncData = join5(profileDir, "Default", "Sync Data");
20803
20835
  if (lstat(syncData) === null)
20804
20836
  return false;
20805
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20837
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20806
20838
  }
20807
20839
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20808
20840
  return {
@@ -20223,7 +20223,12 @@ async function acquireProfileLease(profileDir, options = {}) {
20223
20223
  const leaseDir = join2(leaseRoot, id);
20224
20224
  await fileSystem.ensureDir(leaseRoot);
20225
20225
  if (!mkdirExclusive(leaseDir, 448)) {
20226
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20226
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
20227
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20228
+ }
20229
+ if (!mkdirExclusive(leaseDir, 448)) {
20230
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
20231
+ }
20227
20232
  }
20228
20233
  const token = randomBytes(16).toString("hex");
20229
20234
  const owner = {
@@ -20339,9 +20344,35 @@ async function busyGuidance(fileSystem, leaseDir) {
20339
20344
  }
20340
20345
  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`;
20341
20346
  }
20342
- 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}`;
20347
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
20348
+ 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}`;
20343
20349
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
20344
20350
  }
20351
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
20352
+ const owner = await readOwner(fileSystem, leaseDir);
20353
+ if (owner === null || isProcessAlive(owner.pid))
20354
+ return false;
20355
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
20356
+ return false;
20357
+ const target = staleLeaseDir(leaseDir);
20358
+ try {
20359
+ rename(leaseDir, target);
20360
+ } catch {
20361
+ return false;
20362
+ }
20363
+ const moved = await readOwner(fileSystem, target);
20364
+ if (moved !== null && moved.token !== owner.token) {
20365
+ try {
20366
+ rename(target, leaseDir);
20367
+ } catch {}
20368
+ return false;
20369
+ }
20370
+ return true;
20371
+ }
20372
+ function staleLeaseDir(leaseDir) {
20373
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
20374
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
20375
+ }
20345
20376
  async function holderResidue(fileSystem, leaseDir) {
20346
20377
  try {
20347
20378
  const entries = await fileSystem.readDir(leaseDir);
@@ -20607,7 +20638,7 @@ function quarantineProfileSyncData(profileDir) {
20607
20638
  const syncData = join5(profileDir, "Default", "Sync Data");
20608
20639
  if (lstat(syncData) === null)
20609
20640
  return false;
20610
- return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20641
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
20611
20642
  }
20612
20643
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20613
20644
  return {