@gobing-ai/knowledge-kit 0.1.15 → 0.1.17

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 (116) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +1765 -40
  3. package/package.json +1 -1
  4. package/plugins/generations/content-gen/dist/index.js +58 -52
  5. package/plugins/generations/content-gen/src/storm.ts +94 -61
  6. package/plugins/generations/core-facts-gen/dist/index.js +1 -1
  7. package/plugins/generations/daily-article-gen/dist/index.js +1 -1
  8. package/plugins/generations/dailynews-gen/dist/index.js +1 -1
  9. package/plugins/generations/episode-plan-gen/dist/index.js +1 -1
  10. package/plugins/generations/gemini-tts/dist/index.js +1 -1
  11. package/plugins/generations/image-gen/README.md +31 -10
  12. package/plugins/generations/image-gen/assets/sample/cover__quasi-news-podcast.jpg +0 -0
  13. package/plugins/generations/image-gen/assets/sample/daily-news-cover__quasi-news-podcast.jpg +0 -0
  14. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__clean-webapp-ui.jpg +0 -0
  15. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__cute.jpg +0 -0
  16. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__daily-news.jpg +0 -0
  17. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__editorial.jpg +0 -0
  18. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__fresh.jpg +0 -0
  19. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__minimalist.jpg +0 -0
  20. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__photorealistic.jpg +0 -0
  21. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__quasi-news-podcast.jpg +0 -0
  22. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__sketch.jpg +0 -0
  23. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__technical-diagram.jpg +0 -0
  24. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__vibrant.jpg +0 -0
  25. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__warm.jpg +0 -0
  26. package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__xhs-knowledge.jpg +0 -0
  27. package/plugins/generations/image-gen/assets/sample/free__quasi-news-podcast.jpg +0 -0
  28. package/plugins/generations/image-gen/assets/sample/illustration__quasi-news-podcast.jpg +0 -0
  29. package/plugins/generations/image-gen/assets/sample/xhs-card__quasi-news-podcast.jpg +0 -0
  30. package/plugins/generations/image-gen/dist/index.js +1 -1
  31. package/plugins/generations/image-gen/presets/formats/daily-news-podcast-cover.yaml +18 -0
  32. package/plugins/generations/image-gen/presets/styles/quasi-news-podcast.yaml +9 -0
  33. package/plugins/generations/news-report-gen/dist/index.js +1 -1
  34. package/plugins/generations/voice-gen/dist/index.js +1 -1
  35. package/plugins/generations/voxcpm-tts/dist/index.js +1 -1
  36. package/plugins/ingestions/aihot-ingest/dist/index.js +1 -1
  37. package/plugins/ingestions/horizon-ingest/dist/index.js +1 -1
  38. package/plugins/ingestions/last30days-ingest/dist/index.js +1 -1
  39. package/plugins/ingestions/web-search/dist/index.js +1 -1
  40. package/plugins/kk/plugin.json +1 -1
  41. package/plugins/kk/publish-presets/daily-ai-voice-migration.json +12 -3
  42. package/plugins/kk/publish-presets/daily-ai-voice.json +17 -9
  43. package/plugins/kk/publish-presets/itc-main.json +42 -0
  44. package/plugins/kk/scripts/cover-compositor.ts +198 -0
  45. package/plugins/kk/scripts/daily-cover-mock.ts +164 -0
  46. package/plugins/kk/scripts/daily-scheduled-run.ts +188 -3
  47. package/plugins/kk/scripts/daily-stages.ts +134 -26
  48. package/plugins/kk/scripts/daily-triage-core.ts +451 -0
  49. package/plugins/kk/scripts/daily-triage.ts +74 -0
  50. package/plugins/kk/scripts/itc-stages.ts +3 -2
  51. package/plugins/kk/scripts/kk-workflow-stages.ts +31 -2
  52. package/plugins/kk/scripts/voice3-publish-window.ts +5 -1
  53. package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +16 -10
  54. package/plugins/kk/skills/news-editorial/SKILL.md +3 -3
  55. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +2 -1
  56. package/plugins/kk/skills/publish/SKILL.md +1 -1
  57. package/plugins/kk/skills/wiki-authoring/SKILL.md +53 -0
  58. package/plugins/kk/skills/wiki-authoring/references/page-shapes.md +44 -0
  59. package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +3 -3
  60. package/plugins/kk/workflows/kk-daily-publish3.yaml +10 -3
  61. package/plugins/kk/workflows/kk-daily-safety.yaml +32 -7
  62. package/plugins/publishings/bilibili-pub/dist/index.js +90 -17
  63. package/plugins/publishings/bilibili-pub/dist/profile-check.js +90 -16
  64. package/plugins/publishings/cnblogs-pub/dist/index.js +90 -17
  65. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +90 -16
  66. package/plugins/publishings/csdn-pub/dist/index.js +90 -17
  67. package/plugins/publishings/csdn-pub/dist/profile-check.js +91 -17
  68. package/plugins/publishings/emdash-pub/dist/index.js +1 -1
  69. package/plugins/publishings/infoq-pub/dist/index.js +120 -19
  70. package/plugins/publishings/infoq-pub/dist/profile-check.js +95 -18
  71. package/plugins/publishings/infoq-pub/src/index.ts +40 -1
  72. package/plugins/publishings/jike-pub/dist/index.js +90 -17
  73. package/plugins/publishings/jike-pub/dist/profile-check.js +91 -17
  74. package/plugins/publishings/juejin-pub/dist/index.js +117 -20
  75. package/plugins/publishings/juejin-pub/dist/profile-check.js +94 -18
  76. package/plugins/publishings/juejin-pub/src/index.ts +41 -2
  77. package/plugins/publishings/linkedin-pub/dist/index.js +90 -17
  78. package/plugins/publishings/linkedin-pub/dist/profile-check.js +91 -17
  79. package/plugins/publishings/medium-pub/dist/index.js +1 -1
  80. package/plugins/publishings/podcast-pub/dist/index.js +1 -1
  81. package/plugins/publishings/qiita-pub/dist/index.js +1 -1
  82. package/plugins/publishings/shipinhao-pub/dist/index.js +311 -66
  83. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +138 -17
  84. package/plugins/publishings/shipinhao-pub/plugin.json +2 -2
  85. package/plugins/publishings/shipinhao-pub/src/flow.ts +335 -79
  86. package/plugins/publishings/shipinhao-pub/src/index.ts +16 -8
  87. package/plugins/publishings/shipinhao-pub/src/profile-check.ts +1 -1
  88. package/plugins/publishings/shipinhao-pub/src/selectors.ts +103 -5
  89. package/plugins/publishings/sspai-pub/dist/index.js +90 -17
  90. package/plugins/publishings/sspai-pub/dist/profile-check.js +90 -16
  91. package/plugins/publishings/substack-pub/dist/index.js +90 -17
  92. package/plugins/publishings/substack-pub/dist/profile-check.js +91 -17
  93. package/plugins/publishings/surfdash-pub/dist/index.js +244 -13
  94. package/plugins/publishings/surfdash-pub/src/index.ts +144 -8
  95. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +189 -0
  96. package/plugins/publishings/threads-pub/dist/index.js +1 -1
  97. package/plugins/publishings/wechatmp-pub/dist/index.js +186 -39
  98. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +96 -19
  99. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +14 -2
  100. package/plugins/publishings/wechatmp-pub/src/enrich.ts +10 -3
  101. package/plugins/publishings/wechatmp-pub/src/flow.ts +158 -25
  102. package/plugins/publishings/wechatmp-pub/src/page.ts +14 -0
  103. package/plugins/publishings/wechatmp-pub/src/profile-check.ts +8 -1
  104. package/plugins/publishings/weibo-pub/dist/index.js +90 -17
  105. package/plugins/publishings/weibo-pub/dist/profile-check.js +91 -17
  106. package/plugins/publishings/x-pub/dist/index.js +90 -17
  107. package/plugins/publishings/x-pub/dist/profile-check.js +91 -17
  108. package/plugins/publishings/xhs-pub/dist/index.js +646 -47
  109. package/plugins/publishings/xhs-pub/dist/profile-check.js +109 -17
  110. package/plugins/publishings/xhs-pub/src/errors.ts +45 -0
  111. package/plugins/publishings/xhs-pub/src/flow.ts +773 -45
  112. package/plugins/publishings/xhs-pub/src/page.ts +33 -0
  113. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +90 -17
  114. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +90 -16
  115. package/plugins/publishings/zenn-pub/dist/index.js +94 -2
  116. package/plugins/publishings/zenn-pub/src/index.ts +134 -1
@@ -19853,8 +19853,11 @@ import {
19853
19853
  mkdirSync as mkdirSync2,
19854
19854
  openSync,
19855
19855
  readdirSync as readdirSync2,
19856
+ readlinkSync,
19856
19857
  realpathSync as realpathSync2,
19857
- rmdirSync
19858
+ renameSync as renameSync2,
19859
+ rmdirSync,
19860
+ unlinkSync
19858
19861
  } from "fs";
19859
19862
  function lstat(path) {
19860
19863
  try {
@@ -19889,6 +19892,33 @@ function rmdir(path) {
19889
19892
  throw error;
19890
19893
  }
19891
19894
  }
19895
+ function readlink(path) {
19896
+ try {
19897
+ return readlinkSync(path);
19898
+ } catch {
19899
+ return null;
19900
+ }
19901
+ }
19902
+ function unlink(path) {
19903
+ try {
19904
+ unlinkSync(path);
19905
+ return true;
19906
+ } catch (error) {
19907
+ if (error.code === "ENOENT")
19908
+ return false;
19909
+ throw error;
19910
+ }
19911
+ }
19912
+ function rename(from, to) {
19913
+ try {
19914
+ renameSync2(from, to);
19915
+ return true;
19916
+ } catch (error) {
19917
+ if (error.code === "ENOENT")
19918
+ return false;
19919
+ throw error;
19920
+ }
19921
+ }
19892
19922
  function chmod(path, mode) {
19893
19923
  chmodSync(path, mode);
19894
19924
  }
@@ -19900,14 +19930,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
19900
19930
 
19901
19931
  // ../../packages/publish-harness/src/profile-lease.ts
19902
19932
  import { createHash, randomBytes } from "crypto";
19903
- import { homedir as homedir2 } from "os";
19933
+ import { homedir as homedir2, hostname } from "os";
19904
19934
  import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
19905
19935
  var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
19906
19936
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
19907
19937
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
19908
19938
  var OWNER_FILE = "owner.json";
19909
19939
  var HOLDER_PREFIX = "holder-";
19910
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
19940
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
19911
19941
  async function acquireProfileLease(profileDir, options = {}) {
19912
19942
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
19913
19943
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20075,6 +20105,8 @@ function isProcessAlive(pid) {
20075
20105
  }
20076
20106
  }
20077
20107
  function refuseNativeLock(profileDir) {
20108
+ if (reclaimStaleNativeLock(profileDir))
20109
+ return;
20078
20110
  for (const name of NATIVE_LOCK_FILES) {
20079
20111
  const path = join2(profileDir, name);
20080
20112
  if (lstat(path) !== null) {
@@ -20082,6 +20114,24 @@ function refuseNativeLock(profileDir) {
20082
20114
  }
20083
20115
  }
20084
20116
  }
20117
+ function reclaimStaleNativeLock(profileDir) {
20118
+ const lockPath = join2(profileDir, "SingletonLock");
20119
+ const target = readlink(lockPath);
20120
+ if (target === null)
20121
+ return false;
20122
+ const match = /^(.*)-(\d+)$/.exec(target);
20123
+ if (match === null)
20124
+ return false;
20125
+ const [, host, pidText] = match;
20126
+ if (host !== hostname())
20127
+ return false;
20128
+ const pid = Number(pidText);
20129
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20130
+ return false;
20131
+ for (const name of NATIVE_LOCK_FILES)
20132
+ unlink(join2(profileDir, name));
20133
+ return true;
20134
+ }
20085
20135
  function sha256Hex(value) {
20086
20136
  return createHash("sha256").update(value).digest("hex");
20087
20137
  }
@@ -20140,6 +20190,27 @@ var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20140
20190
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20141
20191
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20142
20192
  var DEFAULT_POLL_MS = 500;
20193
+ function isInstantBrowserDeath(message) {
20194
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20195
+ }
20196
+ function classifyLaunchError(error, profileDir, channel) {
20197
+ const message = errorMessage2(error);
20198
+ if (/singleton|already in use|in use by another/i.test(message))
20199
+ return new BrowserProfileBusyError(profileDir, error);
20200
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20201
+ return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20202
+ }
20203
+ if (isInstantBrowserDeath(message)) {
20204
+ return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
20205
+ }
20206
+ return error instanceof Error ? error : new Error(message);
20207
+ }
20208
+ function quarantineProfileSyncData(profileDir) {
20209
+ const syncData = join5(profileDir, "Default", "Sync Data");
20210
+ if (lstat(syncData) === null)
20211
+ return false;
20212
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20213
+ }
20143
20214
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20144
20215
  return {
20145
20216
  async launch(request) {
@@ -20168,23 +20239,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20168
20239
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20169
20240
  }
20170
20241
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20242
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20243
+ headless,
20244
+ channel,
20245
+ args: ["--disable-blink-features=AutomationControlled"],
20246
+ ignoreDefaultArgs: ["--enable-automation"]
20247
+ });
20171
20248
  let context;
20172
20249
  try {
20173
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20174
- headless,
20175
- channel,
20176
- args: ["--disable-blink-features=AutomationControlled"],
20177
- ignoreDefaultArgs: ["--enable-automation"]
20178
- });
20250
+ context = await launch();
20179
20251
  } catch (error) {
20180
- const message = errorMessage2(error);
20181
- if (/singleton|already in use|in use by another/i.test(message)) {
20182
- throw new BrowserProfileBusyError(profileDir, error);
20183
- }
20184
- if (/playwright install|executable doesn't exist/i.test(message)) {
20185
- throw new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20252
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20253
+ throw classifyLaunchError(error, profileDir, channel);
20254
+ if (!quarantineProfileSyncData(profileDir))
20255
+ throw classifyLaunchError(error, profileDir, channel);
20256
+ try {
20257
+ context = await launch();
20258
+ } catch (retryError) {
20259
+ throw classifyLaunchError(retryError, profileDir, channel);
20186
20260
  }
20187
- throw error;
20188
20261
  }
20189
20262
  try {
20190
20263
  await context.addInitScript(() => {
@@ -20341,6 +20414,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20341
20414
  if (command === "login") {
20342
20415
  const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
20343
20416
  const launcher = deps.launcher ?? kkBrowserLauncher;
20417
+ stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
20344
20418
  try {
20345
20419
  if (url === undefined) {
20346
20420
  await loginWithProfile({
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
19905
19905
  shortVideo: Object.freeze({
19906
19906
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19907
19907
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19908
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
19908
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
19909
19909
  })
19910
19910
  })
19911
19911
  });
@@ -20467,8 +20467,11 @@ import {
20467
20467
  mkdirSync as mkdirSync2,
20468
20468
  openSync,
20469
20469
  readdirSync as readdirSync2,
20470
+ readlinkSync,
20470
20471
  realpathSync as realpathSync2,
20471
- rmdirSync
20472
+ renameSync as renameSync2,
20473
+ rmdirSync,
20474
+ unlinkSync
20472
20475
  } from "fs";
20473
20476
  function lstat(path) {
20474
20477
  try {
@@ -20503,6 +20506,33 @@ function rmdir(path) {
20503
20506
  throw error;
20504
20507
  }
20505
20508
  }
20509
+ function readlink(path) {
20510
+ try {
20511
+ return readlinkSync(path);
20512
+ } catch {
20513
+ return null;
20514
+ }
20515
+ }
20516
+ function unlink(path) {
20517
+ try {
20518
+ unlinkSync(path);
20519
+ return true;
20520
+ } catch (error) {
20521
+ if (error.code === "ENOENT")
20522
+ return false;
20523
+ throw error;
20524
+ }
20525
+ }
20526
+ function rename(from, to) {
20527
+ try {
20528
+ renameSync2(from, to);
20529
+ return true;
20530
+ } catch (error) {
20531
+ if (error.code === "ENOENT")
20532
+ return false;
20533
+ throw error;
20534
+ }
20535
+ }
20506
20536
  function chmod(path, mode) {
20507
20537
  chmodSync(path, mode);
20508
20538
  }
@@ -20514,14 +20544,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-t
20514
20544
 
20515
20545
  // ../../packages/publish-harness/src/profile-lease.ts
20516
20546
  import { createHash, randomBytes } from "crypto";
20517
- import { homedir as homedir3 } from "os";
20547
+ import { homedir as homedir3, hostname } from "os";
20518
20548
  import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
20519
20549
  var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
20520
20550
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
20521
20551
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
20522
20552
  var OWNER_FILE = "owner.json";
20523
20553
  var HOLDER_PREFIX = "holder-";
20524
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
20554
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
20525
20555
  async function acquireProfileLease(profileDir, options = {}) {
20526
20556
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
20527
20557
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20689,6 +20719,8 @@ function isProcessAlive(pid) {
20689
20719
  }
20690
20720
  }
20691
20721
  function refuseNativeLock(profileDir) {
20722
+ if (reclaimStaleNativeLock(profileDir))
20723
+ return;
20692
20724
  for (const name of NATIVE_LOCK_FILES) {
20693
20725
  const path = join3(profileDir, name);
20694
20726
  if (lstat(path) !== null) {
@@ -20696,6 +20728,24 @@ function refuseNativeLock(profileDir) {
20696
20728
  }
20697
20729
  }
20698
20730
  }
20731
+ function reclaimStaleNativeLock(profileDir) {
20732
+ const lockPath = join3(profileDir, "SingletonLock");
20733
+ const target = readlink(lockPath);
20734
+ if (target === null)
20735
+ return false;
20736
+ const match = /^(.*)-(\d+)$/.exec(target);
20737
+ if (match === null)
20738
+ return false;
20739
+ const [, host, pidText] = match;
20740
+ if (host !== hostname())
20741
+ return false;
20742
+ const pid = Number(pidText);
20743
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20744
+ return false;
20745
+ for (const name of NATIVE_LOCK_FILES)
20746
+ unlink(join3(profileDir, name));
20747
+ return true;
20748
+ }
20699
20749
  function sha256Hex(value) {
20700
20750
  return createHash("sha256").update(value).digest("hex");
20701
20751
  }
@@ -20732,6 +20782,27 @@ var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20732
20782
  var DEFAULT_STEP_TIMEOUT_MS = 30000;
20733
20783
  var DEFAULT_POLL_MS = 500;
20734
20784
  var ATTACH_POLL_MS = 100;
20785
+ function isInstantBrowserDeath(message) {
20786
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20787
+ }
20788
+ function classifyLaunchError(error, profileDir, channel) {
20789
+ const message = errorMessage2(error);
20790
+ if (/singleton|already in use|in use by another/i.test(message))
20791
+ return new BrowserProfileBusyError(profileDir, error);
20792
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20793
+ return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20794
+ }
20795
+ if (isInstantBrowserDeath(message)) {
20796
+ return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
20797
+ }
20798
+ return error instanceof Error ? error : new Error(message);
20799
+ }
20800
+ function quarantineProfileSyncData(profileDir) {
20801
+ const syncData = join5(profileDir, "Default", "Sync Data");
20802
+ if (lstat(syncData) === null)
20803
+ return false;
20804
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20805
+ }
20735
20806
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20736
20807
  return {
20737
20808
  async launch(request) {
@@ -20760,23 +20831,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20760
20831
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20761
20832
  }
20762
20833
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20834
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20835
+ headless,
20836
+ channel,
20837
+ args: ["--disable-blink-features=AutomationControlled"],
20838
+ ignoreDefaultArgs: ["--enable-automation"]
20839
+ });
20763
20840
  let context;
20764
20841
  try {
20765
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20766
- headless,
20767
- channel,
20768
- args: ["--disable-blink-features=AutomationControlled"],
20769
- ignoreDefaultArgs: ["--enable-automation"]
20770
- });
20842
+ context = await launch();
20771
20843
  } catch (error) {
20772
- const message = errorMessage2(error);
20773
- if (/singleton|already in use|in use by another/i.test(message)) {
20774
- throw new BrowserProfileBusyError(profileDir, error);
20775
- }
20776
- if (/playwright install|executable doesn't exist/i.test(message)) {
20777
- throw new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20844
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20845
+ throw classifyLaunchError(error, profileDir, channel);
20846
+ if (!quarantineProfileSyncData(profileDir))
20847
+ throw classifyLaunchError(error, profileDir, channel);
20848
+ try {
20849
+ context = await launch();
20850
+ } catch (retryError) {
20851
+ throw classifyLaunchError(retryError, profileDir, channel);
20778
20852
  }
20779
- throw error;
20780
20853
  }
20781
20854
  try {
20782
20855
  await context.addInitScript(() => {
@@ -19853,8 +19853,11 @@ import {
19853
19853
  mkdirSync as mkdirSync2,
19854
19854
  openSync,
19855
19855
  readdirSync as readdirSync2,
19856
+ readlinkSync,
19856
19857
  realpathSync as realpathSync2,
19857
- rmdirSync
19858
+ renameSync as renameSync2,
19859
+ rmdirSync,
19860
+ unlinkSync
19858
19861
  } from "fs";
19859
19862
  function lstat(path) {
19860
19863
  try {
@@ -19889,6 +19892,33 @@ function rmdir(path) {
19889
19892
  throw error;
19890
19893
  }
19891
19894
  }
19895
+ function readlink(path) {
19896
+ try {
19897
+ return readlinkSync(path);
19898
+ } catch {
19899
+ return null;
19900
+ }
19901
+ }
19902
+ function unlink(path) {
19903
+ try {
19904
+ unlinkSync(path);
19905
+ return true;
19906
+ } catch (error) {
19907
+ if (error.code === "ENOENT")
19908
+ return false;
19909
+ throw error;
19910
+ }
19911
+ }
19912
+ function rename(from, to) {
19913
+ try {
19914
+ renameSync2(from, to);
19915
+ return true;
19916
+ } catch (error) {
19917
+ if (error.code === "ENOENT")
19918
+ return false;
19919
+ throw error;
19920
+ }
19921
+ }
19892
19922
  function chmod(path, mode) {
19893
19923
  chmodSync(path, mode);
19894
19924
  }
@@ -19900,14 +19930,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
19900
19930
 
19901
19931
  // ../../packages/publish-harness/src/profile-lease.ts
19902
19932
  import { createHash, randomBytes } from "crypto";
19903
- import { homedir as homedir2 } from "os";
19933
+ import { homedir as homedir2, hostname } from "os";
19904
19934
  import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
19905
19935
  var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
19906
19936
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
19907
19937
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
19908
19938
  var OWNER_FILE = "owner.json";
19909
19939
  var HOLDER_PREFIX = "holder-";
19910
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
19940
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
19911
19941
  async function acquireProfileLease(profileDir, options = {}) {
19912
19942
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
19913
19943
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20075,6 +20105,8 @@ function isProcessAlive(pid) {
20075
20105
  }
20076
20106
  }
20077
20107
  function refuseNativeLock(profileDir) {
20108
+ if (reclaimStaleNativeLock(profileDir))
20109
+ return;
20078
20110
  for (const name of NATIVE_LOCK_FILES) {
20079
20111
  const path = join2(profileDir, name);
20080
20112
  if (lstat(path) !== null) {
@@ -20082,6 +20114,24 @@ function refuseNativeLock(profileDir) {
20082
20114
  }
20083
20115
  }
20084
20116
  }
20117
+ function reclaimStaleNativeLock(profileDir) {
20118
+ const lockPath = join2(profileDir, "SingletonLock");
20119
+ const target = readlink(lockPath);
20120
+ if (target === null)
20121
+ return false;
20122
+ const match = /^(.*)-(\d+)$/.exec(target);
20123
+ if (match === null)
20124
+ return false;
20125
+ const [, host, pidText] = match;
20126
+ if (host !== hostname())
20127
+ return false;
20128
+ const pid = Number(pidText);
20129
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20130
+ return false;
20131
+ for (const name of NATIVE_LOCK_FILES)
20132
+ unlink(join2(profileDir, name));
20133
+ return true;
20134
+ }
20085
20135
  function sha256Hex(value) {
20086
20136
  return createHash("sha256").update(value).digest("hex");
20087
20137
  }
@@ -20160,6 +20210,27 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20160
20210
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20161
20211
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20162
20212
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20213
+ function isInstantBrowserDeath(message) {
20214
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20215
+ }
20216
+ function classifyLaunchError(error, profileDir, channel) {
20217
+ const message = errorMessage2(error);
20218
+ if (/singleton|already in use|in use by another/i.test(message))
20219
+ return new BrowserProfileBusyError(profileDir, error);
20220
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20221
+ return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20222
+ }
20223
+ if (isInstantBrowserDeath(message)) {
20224
+ return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
20225
+ }
20226
+ return error instanceof Error ? error : new Error(message);
20227
+ }
20228
+ function quarantineProfileSyncData(profileDir) {
20229
+ const syncData = join5(profileDir, "Default", "Sync Data");
20230
+ if (lstat(syncData) === null)
20231
+ return false;
20232
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20233
+ }
20163
20234
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20164
20235
  return {
20165
20236
  async launch(request) {
@@ -20188,23 +20259,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20188
20259
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20189
20260
  }
20190
20261
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20262
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20263
+ headless,
20264
+ channel,
20265
+ args: ["--disable-blink-features=AutomationControlled"],
20266
+ ignoreDefaultArgs: ["--enable-automation"]
20267
+ });
20191
20268
  let context;
20192
20269
  try {
20193
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20194
- headless,
20195
- channel,
20196
- args: ["--disable-blink-features=AutomationControlled"],
20197
- ignoreDefaultArgs: ["--enable-automation"]
20198
- });
20270
+ context = await launch();
20199
20271
  } catch (error) {
20200
- const message = errorMessage2(error);
20201
- if (/singleton|already in use|in use by another/i.test(message)) {
20202
- throw new BrowserProfileBusyError(profileDir, error);
20203
- }
20204
- if (/playwright install|executable doesn't exist/i.test(message)) {
20205
- throw new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20272
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20273
+ throw classifyLaunchError(error, profileDir, channel);
20274
+ if (!quarantineProfileSyncData(profileDir))
20275
+ throw classifyLaunchError(error, profileDir, channel);
20276
+ try {
20277
+ context = await launch();
20278
+ } catch (retryError) {
20279
+ throw classifyLaunchError(retryError, profileDir, channel);
20206
20280
  }
20207
- throw error;
20208
20281
  }
20209
20282
  try {
20210
20283
  await context.addInitScript(() => {
@@ -20361,6 +20434,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20361
20434
  if (command === "login") {
20362
20435
  const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
20363
20436
  const launcher = deps.launcher ?? kkBrowserLauncher;
20437
+ stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
20364
20438
  try {
20365
20439
  if (url === undefined) {
20366
20440
  await loginWithProfile({
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
19905
19905
  shortVideo: Object.freeze({
19906
19906
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19907
19907
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
19908
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
19908
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
19909
19909
  })
19910
19910
  })
19911
19911
  });
@@ -20464,8 +20464,11 @@ import {
20464
20464
  mkdirSync as mkdirSync2,
20465
20465
  openSync,
20466
20466
  readdirSync as readdirSync2,
20467
+ readlinkSync,
20467
20468
  realpathSync as realpathSync2,
20468
- rmdirSync
20469
+ renameSync as renameSync2,
20470
+ rmdirSync,
20471
+ unlinkSync
20469
20472
  } from "fs";
20470
20473
  function lstat(path) {
20471
20474
  try {
@@ -20500,6 +20503,33 @@ function rmdir(path) {
20500
20503
  throw error;
20501
20504
  }
20502
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
+ }
20503
20533
  function chmod(path, mode) {
20504
20534
  chmodSync(path, mode);
20505
20535
  }
@@ -20511,14 +20541,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join2(homedir2(), ".config", "kk", "browser-t
20511
20541
 
20512
20542
  // ../../packages/publish-harness/src/profile-lease.ts
20513
20543
  import { createHash, randomBytes } from "crypto";
20514
- import { homedir as homedir3 } from "os";
20544
+ import { homedir as homedir3, hostname } from "os";
20515
20545
  import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
20516
20546
  var DEFAULT_BOT_LEASE_ROOT = join3(homedir3(), ".config", "kk", "browser-leases");
20517
20547
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
20518
20548
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
20519
20549
  var OWNER_FILE = "owner.json";
20520
20550
  var HOLDER_PREFIX = "holder-";
20521
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
20551
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
20522
20552
  async function acquireProfileLease(profileDir, options = {}) {
20523
20553
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
20524
20554
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20686,6 +20716,8 @@ function isProcessAlive(pid) {
20686
20716
  }
20687
20717
  }
20688
20718
  function refuseNativeLock(profileDir) {
20719
+ if (reclaimStaleNativeLock(profileDir))
20720
+ return;
20689
20721
  for (const name of NATIVE_LOCK_FILES) {
20690
20722
  const path = join3(profileDir, name);
20691
20723
  if (lstat(path) !== null) {
@@ -20693,6 +20725,24 @@ function refuseNativeLock(profileDir) {
20693
20725
  }
20694
20726
  }
20695
20727
  }
20728
+ function reclaimStaleNativeLock(profileDir) {
20729
+ const lockPath = join3(profileDir, "SingletonLock");
20730
+ const target = readlink(lockPath);
20731
+ if (target === null)
20732
+ return false;
20733
+ const match = /^(.*)-(\d+)$/.exec(target);
20734
+ if (match === null)
20735
+ return false;
20736
+ const [, host, pidText] = match;
20737
+ if (host !== hostname())
20738
+ return false;
20739
+ const pid = Number(pidText);
20740
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20741
+ return false;
20742
+ for (const name of NATIVE_LOCK_FILES)
20743
+ unlink(join3(profileDir, name));
20744
+ return true;
20745
+ }
20696
20746
  function sha256Hex(value) {
20697
20747
  return createHash("sha256").update(value).digest("hex");
20698
20748
  }
@@ -20729,6 +20779,27 @@ var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20729
20779
  var DEFAULT_STEP_TIMEOUT_MS = 30000;
20730
20780
  var DEFAULT_POLL_MS = 500;
20731
20781
  var ATTACH_POLL_MS = 100;
20782
+ function isInstantBrowserDeath(message) {
20783
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20784
+ }
20785
+ function classifyLaunchError(error, profileDir, channel) {
20786
+ const message = errorMessage2(error);
20787
+ if (/singleton|already in use|in use by another/i.test(message))
20788
+ return new BrowserProfileBusyError(profileDir, error);
20789
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20790
+ return new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20791
+ }
20792
+ if (isInstantBrowserDeath(message)) {
20793
+ return new PlaywrightUnavailableError(`browser profile ${profileDir} makes Chromium exit during startup (no diagnostic reported). Move it aside (\`mv ${profileDir} ${profileDir}.broken-<date>\`) and log in again; \`storage-state.json\` is the only state worth keeping.`, { cause: error });
20794
+ }
20795
+ return error instanceof Error ? error : new Error(message);
20796
+ }
20797
+ function quarantineProfileSyncData(profileDir) {
20798
+ const syncData = join5(profileDir, "Default", "Sync Data");
20799
+ if (lstat(syncData) === null)
20800
+ return false;
20801
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20802
+ }
20732
20803
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20733
20804
  return {
20734
20805
  async launch(request) {
@@ -20757,23 +20828,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20757
20828
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20758
20829
  }
20759
20830
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20831
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20832
+ headless,
20833
+ channel,
20834
+ args: ["--disable-blink-features=AutomationControlled"],
20835
+ ignoreDefaultArgs: ["--enable-automation"]
20836
+ });
20760
20837
  let context;
20761
20838
  try {
20762
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20763
- headless,
20764
- channel,
20765
- args: ["--disable-blink-features=AutomationControlled"],
20766
- ignoreDefaultArgs: ["--enable-automation"]
20767
- });
20839
+ context = await launch();
20768
20840
  } catch (error) {
20769
- const message = errorMessage2(error);
20770
- if (/singleton|already in use|in use by another/i.test(message)) {
20771
- throw new BrowserProfileBusyError(profileDir, error);
20772
- }
20773
- if (/playwright install|executable doesn't exist/i.test(message)) {
20774
- throw new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error });
20841
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20842
+ throw classifyLaunchError(error, profileDir, channel);
20843
+ if (!quarantineProfileSyncData(profileDir))
20844
+ throw classifyLaunchError(error, profileDir, channel);
20845
+ try {
20846
+ context = await launch();
20847
+ } catch (retryError) {
20848
+ throw classifyLaunchError(retryError, profileDir, channel);
20775
20849
  }
20776
- throw error;
20777
20850
  }
20778
20851
  try {
20779
20852
  await context.addInitScript(() => {