@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
@@ -20125,8 +20125,11 @@ import {
20125
20125
  mkdirSync as mkdirSync2,
20126
20126
  openSync,
20127
20127
  readdirSync as readdirSync2,
20128
+ readlinkSync,
20128
20129
  realpathSync as realpathSync2,
20129
- rmdirSync
20130
+ renameSync as renameSync2,
20131
+ rmdirSync,
20132
+ unlinkSync
20130
20133
  } from "fs";
20131
20134
  function lstat(path) {
20132
20135
  try {
@@ -20161,6 +20164,33 @@ function rmdir(path) {
20161
20164
  throw error;
20162
20165
  }
20163
20166
  }
20167
+ function readlink(path) {
20168
+ try {
20169
+ return readlinkSync(path);
20170
+ } catch {
20171
+ return null;
20172
+ }
20173
+ }
20174
+ function unlink(path) {
20175
+ try {
20176
+ unlinkSync(path);
20177
+ return true;
20178
+ } catch (error) {
20179
+ if (error.code === "ENOENT")
20180
+ return false;
20181
+ throw error;
20182
+ }
20183
+ }
20184
+ function rename(from, to) {
20185
+ try {
20186
+ renameSync2(from, to);
20187
+ return true;
20188
+ } catch (error) {
20189
+ if (error.code === "ENOENT")
20190
+ return false;
20191
+ throw error;
20192
+ }
20193
+ }
20164
20194
  function chmod(path, mode) {
20165
20195
  chmodSync(path, mode);
20166
20196
  }
@@ -20172,14 +20202,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
20172
20202
 
20173
20203
  // ../../packages/publish-harness/src/profile-lease.ts
20174
20204
  import { createHash, randomBytes } from "crypto";
20175
- import { homedir as homedir2 } from "os";
20205
+ import { homedir as homedir2, hostname } from "os";
20176
20206
  import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
20177
20207
  var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
20178
20208
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
20179
20209
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
20180
20210
  var OWNER_FILE = "owner.json";
20181
20211
  var HOLDER_PREFIX = "holder-";
20182
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
20212
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
20183
20213
  async function acquireProfileLease(profileDir, options = {}) {
20184
20214
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
20185
20215
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20347,6 +20377,8 @@ function isProcessAlive(pid) {
20347
20377
  }
20348
20378
  }
20349
20379
  function refuseNativeLock(profileDir) {
20380
+ if (reclaimStaleNativeLock(profileDir))
20381
+ return;
20350
20382
  for (const name of NATIVE_LOCK_FILES) {
20351
20383
  const path = join2(profileDir, name);
20352
20384
  if (lstat(path) !== null) {
@@ -20354,6 +20386,24 @@ function refuseNativeLock(profileDir) {
20354
20386
  }
20355
20387
  }
20356
20388
  }
20389
+ function reclaimStaleNativeLock(profileDir) {
20390
+ const lockPath = join2(profileDir, "SingletonLock");
20391
+ const target = readlink(lockPath);
20392
+ if (target === null)
20393
+ return false;
20394
+ const match = /^(.*)-(\d+)$/.exec(target);
20395
+ if (match === null)
20396
+ return false;
20397
+ const [, host, pidText] = match;
20398
+ if (host !== hostname())
20399
+ return false;
20400
+ const pid = Number(pidText);
20401
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20402
+ return false;
20403
+ for (const name of NATIVE_LOCK_FILES)
20404
+ unlink(join2(profileDir, name));
20405
+ return true;
20406
+ }
20357
20407
  function sha256Hex(value) {
20358
20408
  return createHash("sha256").update(value).digest("hex");
20359
20409
  }
@@ -20432,6 +20482,27 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20432
20482
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20433
20483
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20434
20484
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20485
+ function isInstantBrowserDeath(message) {
20486
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20487
+ }
20488
+ function classifyLaunchError(error, profileDir, channel) {
20489
+ const message = errorMessage2(error);
20490
+ if (/singleton|already in use|in use by another/i.test(message))
20491
+ return new BrowserProfileBusyError(profileDir, error);
20492
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20493
+ 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 });
20494
+ }
20495
+ if (isInstantBrowserDeath(message)) {
20496
+ 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 });
20497
+ }
20498
+ return error instanceof Error ? error : new Error(message);
20499
+ }
20500
+ function quarantineProfileSyncData(profileDir) {
20501
+ const syncData = join5(profileDir, "Default", "Sync Data");
20502
+ if (lstat(syncData) === null)
20503
+ return false;
20504
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20505
+ }
20435
20506
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20436
20507
  return {
20437
20508
  async launch(request) {
@@ -20460,23 +20531,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20460
20531
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20461
20532
  }
20462
20533
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20534
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20535
+ headless,
20536
+ channel,
20537
+ args: ["--disable-blink-features=AutomationControlled"],
20538
+ ignoreDefaultArgs: ["--enable-automation"]
20539
+ });
20463
20540
  let context;
20464
20541
  try {
20465
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20466
- headless,
20467
- channel,
20468
- args: ["--disable-blink-features=AutomationControlled"],
20469
- ignoreDefaultArgs: ["--enable-automation"]
20470
- });
20542
+ context = await launch();
20471
20543
  } catch (error) {
20472
- const message = errorMessage2(error);
20473
- if (/singleton|already in use|in use by another/i.test(message)) {
20474
- throw new BrowserProfileBusyError(profileDir, error);
20475
- }
20476
- if (/playwright install|executable doesn't exist/i.test(message)) {
20477
- 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 });
20544
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20545
+ throw classifyLaunchError(error, profileDir, channel);
20546
+ if (!quarantineProfileSyncData(profileDir))
20547
+ throw classifyLaunchError(error, profileDir, channel);
20548
+ try {
20549
+ context = await launch();
20550
+ } catch (retryError) {
20551
+ throw classifyLaunchError(retryError, profileDir, channel);
20478
20552
  }
20479
- throw error;
20480
20553
  }
20481
20554
  try {
20482
20555
  await context.addInitScript(() => {
@@ -20633,6 +20706,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20633
20706
  if (command === "login") {
20634
20707
  const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
20635
20708
  const launcher = deps.launcher ?? kkBrowserLauncher;
20709
+ 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`);
20636
20710
  try {
20637
20711
  if (url === undefined) {
20638
20712
  await loginWithProfile({
@@ -20779,7 +20853,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
20779
20853
  shortVideo: Object.freeze({
20780
20854
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
20781
20855
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
20782
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
20856
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
20783
20857
  })
20784
20858
  })
20785
20859
  });
@@ -12057,7 +12057,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
12057
12057
  shortVideo: Object.freeze({
12058
12058
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
12059
12059
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
12060
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
12060
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
12061
12061
  })
12062
12062
  })
12063
12063
  });
@@ -19829,7 +19829,7 @@ var init_runtime_node_bun = __esm(() => {
19829
19829
  });
19830
19830
 
19831
19831
  // ../../plugins/publishings/infoq-pub/src/index.ts
19832
- import { dirname as dirname4 } from "path";
19832
+ import { dirname as dirname4, isAbsolute as isAbsolute2 } from "path";
19833
19833
  import { parseArgs } from "util";
19834
19834
 
19835
19835
  // ../../packages/kk-core/src/content-limits.ts
@@ -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(() => {
@@ -20970,7 +21043,10 @@ var SELECTORS = {
20970
21043
  noticeDismiss: ["text=\u77E5\u9053\u4E86"],
20971
21044
  title: ['input[placeholder="\u8BF7\u8F93\u5165\u6807\u9898"]', 'input[placeholder*="\u6807\u9898"]'],
20972
21045
  body: ['.ProseMirror[contenteditable="true"]', '[contenteditable="true"]'],
20973
- live: ["div.submit-btn"]
21046
+ live: ["div.submit-btn"],
21047
+ coverUpload: [".upload-action", "text=\u4E0A\u4F20\u5C01\u9762"],
21048
+ coverFile: ['input[type="file"][accept="image/*"]', "input.Upload_file_EkxQo"],
21049
+ coverPreview: [".upload-action img", '[class*="cover" i] img', '[class*="Cover" i] img']
20974
21050
  };
20975
21051
  var STEP_TIMEOUT_MS = 30000;
20976
21052
  var CHECK_TIMEOUT_MS = 60000;
@@ -21033,6 +21109,28 @@ function resolveOperation(options, content) {
21033
21109
  }
21034
21110
  return { operation: raw };
21035
21111
  }
21112
+ async function attachCover(page, content, timeoutMs) {
21113
+ const coverPath = content.metadata?.coverImage;
21114
+ if (coverPath === undefined)
21115
+ return null;
21116
+ if (typeof coverPath !== "string" || coverPath.trim() === "") {
21117
+ return `cover: metadata.coverImage must be a non-empty local path, got '${String(coverPath)}'`;
21118
+ }
21119
+ if (!isAbsolute2(coverPath) || !await createNodeFileSystem().exists(coverPath)) {
21120
+ return `cover: metadata.coverImage is not a readable absolute path: ${coverPath}`;
21121
+ }
21122
+ const input = await trySelectors(page, SELECTORS.coverFile, { visible: false });
21123
+ if (!input.found || input.selector === null) {
21124
+ const opener = await trySelectors(page, SELECTORS.coverUpload, { visible: true });
21125
+ if (!opener.found || opener.selector === null) {
21126
+ return "cover: the editor exposed no \u4E0A\u4F20\u5C01\u9762 control \u2014 cover not attached";
21127
+ }
21128
+ }
21129
+ const fileSelector = input.selector ?? SELECTORS.coverFile[0];
21130
+ await page.locator(fileSelector).first().setInputFiles(coverPath);
21131
+ const shown = await waitUntil(async () => await page.locator(SELECTORS.coverPreview[0]).count() > 0, Math.min(timeoutMs, 20000));
21132
+ return shown ? null : "cover: the upload landed but the editor shows no cover preview";
21133
+ }
21036
21134
 
21037
21135
  class InfoqBrowserTransport {
21038
21136
  kind = "browser";
@@ -21098,6 +21196,9 @@ class InfoqBrowserTransport {
21098
21196
  const bodySelector = await findSelector(page, SELECTORS.body, "body editor", this.stepTimeoutMs);
21099
21197
  await pasteHtml(page, bodySelector, markdownToHtml(content.body), { timeoutMs: this.stepTimeoutMs });
21100
21198
  await page.evaluate('(selector) => { const editor = document.querySelector(selector); editor && editor.dispatchEvent(new InputEvent("input", { bubbles: true })); }', bodySelector).catch(() => {});
21199
+ const coverWarning = await attachCover(page, content, this.stepTimeoutMs);
21200
+ if (coverWarning !== null)
21201
+ Object.assign(metadata, { warnings: [coverWarning] });
21101
21202
  const draft = await expectOutcome(() => readToast(page, DRAFT_SAVED_TEXTS), {
21102
21203
  timeoutMs: this.stepTimeoutMs,
21103
21204
  label: "infoq draft autosave"
@@ -20125,8 +20125,11 @@ import {
20125
20125
  mkdirSync as mkdirSync2,
20126
20126
  openSync,
20127
20127
  readdirSync as readdirSync2,
20128
+ readlinkSync,
20128
20129
  realpathSync as realpathSync2,
20129
- rmdirSync
20130
+ renameSync as renameSync2,
20131
+ rmdirSync,
20132
+ unlinkSync
20130
20133
  } from "fs";
20131
20134
  function lstat(path) {
20132
20135
  try {
@@ -20161,6 +20164,33 @@ function rmdir(path) {
20161
20164
  throw error;
20162
20165
  }
20163
20166
  }
20167
+ function readlink(path) {
20168
+ try {
20169
+ return readlinkSync(path);
20170
+ } catch {
20171
+ return null;
20172
+ }
20173
+ }
20174
+ function unlink(path) {
20175
+ try {
20176
+ unlinkSync(path);
20177
+ return true;
20178
+ } catch (error) {
20179
+ if (error.code === "ENOENT")
20180
+ return false;
20181
+ throw error;
20182
+ }
20183
+ }
20184
+ function rename(from, to) {
20185
+ try {
20186
+ renameSync2(from, to);
20187
+ return true;
20188
+ } catch (error) {
20189
+ if (error.code === "ENOENT")
20190
+ return false;
20191
+ throw error;
20192
+ }
20193
+ }
20164
20194
  function chmod(path, mode) {
20165
20195
  chmodSync(path, mode);
20166
20196
  }
@@ -20172,14 +20202,14 @@ var DEFAULT_BOT_TRANSACTION_ROOT = join(homedir(), ".config", "kk", "browser-tra
20172
20202
 
20173
20203
  // ../../packages/publish-harness/src/profile-lease.ts
20174
20204
  import { createHash, randomBytes } from "crypto";
20175
- import { homedir as homedir2 } from "os";
20205
+ import { homedir as homedir2, hostname } from "os";
20176
20206
  import { basename, dirname as dirname3, join as join2, resolve as resolve2 } from "path";
20177
20207
  var DEFAULT_BOT_LEASE_ROOT = join2(homedir2(), ".config", "kk", "browser-leases");
20178
20208
  var KK_BOT_LEASE_PATH = "KK_BOT_LEASE_PATH";
20179
20209
  var KK_BOT_LEASE_TOKEN = "KK_BOT_LEASE_TOKEN";
20180
20210
  var OWNER_FILE = "owner.json";
20181
20211
  var HOLDER_PREFIX = "holder-";
20182
- var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket"];
20212
+ var NATIVE_LOCK_FILES = ["SingletonLock", "SingletonSocket", "SingletonCookie"];
20183
20213
  async function acquireProfileLease(profileDir, options = {}) {
20184
20214
  const fileSystem = options.fileSystem ?? createNodeFileSystem();
20185
20215
  const leaseRoot = options.leaseRoot ?? DEFAULT_BOT_LEASE_ROOT;
@@ -20347,6 +20377,8 @@ function isProcessAlive(pid) {
20347
20377
  }
20348
20378
  }
20349
20379
  function refuseNativeLock(profileDir) {
20380
+ if (reclaimStaleNativeLock(profileDir))
20381
+ return;
20350
20382
  for (const name of NATIVE_LOCK_FILES) {
20351
20383
  const path = join2(profileDir, name);
20352
20384
  if (lstat(path) !== null) {
@@ -20354,6 +20386,24 @@ function refuseNativeLock(profileDir) {
20354
20386
  }
20355
20387
  }
20356
20388
  }
20389
+ function reclaimStaleNativeLock(profileDir) {
20390
+ const lockPath = join2(profileDir, "SingletonLock");
20391
+ const target = readlink(lockPath);
20392
+ if (target === null)
20393
+ return false;
20394
+ const match = /^(.*)-(\d+)$/.exec(target);
20395
+ if (match === null)
20396
+ return false;
20397
+ const [, host, pidText] = match;
20398
+ if (host !== hostname())
20399
+ return false;
20400
+ const pid = Number(pidText);
20401
+ if (!Number.isInteger(pid) || pid <= 0 || isProcessAlive(pid))
20402
+ return false;
20403
+ for (const name of NATIVE_LOCK_FILES)
20404
+ unlink(join2(profileDir, name));
20405
+ return true;
20406
+ }
20357
20407
  function sha256Hex(value) {
20358
20408
  return createHash("sha256").update(value).digest("hex");
20359
20409
  }
@@ -20432,6 +20482,27 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20432
20482
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20433
20483
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20434
20484
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20485
+ function isInstantBrowserDeath(message) {
20486
+ return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
20487
+ }
20488
+ function classifyLaunchError(error, profileDir, channel) {
20489
+ const message = errorMessage2(error);
20490
+ if (/singleton|already in use|in use by another/i.test(message))
20491
+ return new BrowserProfileBusyError(profileDir, error);
20492
+ if (/playwright install|executable doesn't exist/i.test(message)) {
20493
+ 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 });
20494
+ }
20495
+ if (isInstantBrowserDeath(message)) {
20496
+ 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 });
20497
+ }
20498
+ return error instanceof Error ? error : new Error(message);
20499
+ }
20500
+ function quarantineProfileSyncData(profileDir) {
20501
+ const syncData = join5(profileDir, "Default", "Sync Data");
20502
+ if (lstat(syncData) === null)
20503
+ return false;
20504
+ return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 15)}`);
20505
+ }
20435
20506
  function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
20436
20507
  return {
20437
20508
  async launch(request) {
@@ -20460,23 +20531,25 @@ async function launchKkContext(loadPlaywright, profileDir, headless) {
20460
20531
  throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error });
20461
20532
  }
20462
20533
  const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
20534
+ const launch = () => playwright.chromium.launchPersistentContext(profileDir, {
20535
+ headless,
20536
+ channel,
20537
+ args: ["--disable-blink-features=AutomationControlled"],
20538
+ ignoreDefaultArgs: ["--enable-automation"]
20539
+ });
20463
20540
  let context;
20464
20541
  try {
20465
- context = await playwright.chromium.launchPersistentContext(profileDir, {
20466
- headless,
20467
- channel,
20468
- args: ["--disable-blink-features=AutomationControlled"],
20469
- ignoreDefaultArgs: ["--enable-automation"]
20470
- });
20542
+ context = await launch();
20471
20543
  } catch (error) {
20472
- const message = errorMessage2(error);
20473
- if (/singleton|already in use|in use by another/i.test(message)) {
20474
- throw new BrowserProfileBusyError(profileDir, error);
20475
- }
20476
- if (/playwright install|executable doesn't exist/i.test(message)) {
20477
- 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 });
20544
+ if (!isInstantBrowserDeath(errorMessage2(error)))
20545
+ throw classifyLaunchError(error, profileDir, channel);
20546
+ if (!quarantineProfileSyncData(profileDir))
20547
+ throw classifyLaunchError(error, profileDir, channel);
20548
+ try {
20549
+ context = await launch();
20550
+ } catch (retryError) {
20551
+ throw classifyLaunchError(retryError, profileDir, channel);
20478
20552
  }
20479
- throw error;
20480
20553
  }
20481
20554
  try {
20482
20555
  await context.addInitScript(() => {
@@ -20633,6 +20706,7 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
20633
20706
  if (command === "login") {
20634
20707
  const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
20635
20708
  const launcher = deps.launcher ?? kkBrowserLauncher;
20709
+ 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`);
20636
20710
  try {
20637
20711
  if (url === undefined) {
20638
20712
  await loginWithProfile({
@@ -20785,7 +20859,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
20785
20859
  shortVideo: Object.freeze({
20786
20860
  douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
20787
20861
  kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
20788
- shipinhao: Object.freeze({ max: 1000, unit: "unicode_code_points" })
20862
+ shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
20789
20863
  })
20790
20864
  })
20791
20865
  });
@@ -20991,7 +21065,10 @@ var SELECTORS = {
20991
21065
  noticeDismiss: ["text=\u77E5\u9053\u4E86"],
20992
21066
  title: ['input[placeholder="\u8BF7\u8F93\u5165\u6807\u9898"]', 'input[placeholder*="\u6807\u9898"]'],
20993
21067
  body: ['.ProseMirror[contenteditable="true"]', '[contenteditable="true"]'],
20994
- live: ["div.submit-btn"]
21068
+ live: ["div.submit-btn"],
21069
+ coverUpload: [".upload-action", "text=\u4E0A\u4F20\u5C01\u9762"],
21070
+ coverFile: ['input[type="file"][accept="image/*"]', "input.Upload_file_EkxQo"],
21071
+ coverPreview: [".upload-action img", '[class*="cover" i] img', '[class*="Cover" i] img']
20995
21072
  };
20996
21073
  var LOGIN_TIMEOUT_MS = 180000;
20997
21074
  var SIGNAL_CONTAINERS = [...DEFAULT_SIGNAL_CONTAINERS, '[class*="save-status" i]'];
@@ -1,4 +1,4 @@
1
- import { dirname } from 'node:path';
1
+ import { dirname, isAbsolute } from 'node:path';
2
2
  import { parseArgs } from 'node:util';
3
3
  import { type Content, ContentSchema, type Result, ResultSchema } from '@gobing-ai/kk-core';
4
4
  import {
@@ -65,6 +65,11 @@ export const SELECTORS = {
65
65
  title: ['input[placeholder="请输入标题"]', 'input[placeholder*="标题"]'],
66
66
  body: ['.ProseMirror[contenteditable="true"]', '[contenteditable="true"]'],
67
67
  live: ['div.submit-btn'],
68
+ /** 封面 is the draft's own upload control (measured 2026-11-12: `.upload-action` 上传封面 + a
69
+ * visible `input[type=file][accept="image/*"]`), so an article can carry a cover here. */
70
+ coverUpload: ['.upload-action', 'text=上传封面'],
71
+ coverFile: ['input[type="file"][accept="image/*"]', 'input.Upload_file_EkxQo'],
72
+ coverPreview: ['.upload-action img', '[class*="cover" i] img', '[class*="Cover" i] img'],
68
73
  } as const;
69
74
 
70
75
  /**
@@ -208,6 +213,36 @@ export function resolveOperation(
208
213
  return { operation: raw as InfoqOperation };
209
214
  }
210
215
 
216
+ /**
217
+ * Attach the draft's 封面; a warning string instead of a throw, because a cover improves the post
218
+ * rather than gating it. Returns `null` when nothing was requested and when the upload visibly
219
+ * landed (a cover image appears in the upload block).
220
+ */
221
+ async function attachCover(page: Page, content: Content, timeoutMs: number): Promise<string | null> {
222
+ const coverPath = content.metadata?.coverImage;
223
+ if (coverPath === undefined) return null;
224
+ if (typeof coverPath !== 'string' || coverPath.trim() === '') {
225
+ return `cover: metadata.coverImage must be a non-empty local path, got '${String(coverPath)}'`;
226
+ }
227
+ if (!isAbsolute(coverPath) || !(await createNodeFileSystem().exists(coverPath))) {
228
+ return `cover: metadata.coverImage is not a readable absolute path: ${coverPath}`;
229
+ }
230
+ const input = await trySelectors(page, SELECTORS.coverFile, { visible: false });
231
+ if (!input.found || input.selector === null) {
232
+ const opener = await trySelectors(page, SELECTORS.coverUpload, { visible: true });
233
+ if (!opener.found || opener.selector === null) {
234
+ return 'cover: the editor exposed no 上传封面 control — cover not attached';
235
+ }
236
+ }
237
+ const fileSelector = input.selector ?? SELECTORS.coverFile[0];
238
+ await page.locator(fileSelector).first().setInputFiles(coverPath);
239
+ const shown = await waitUntil(
240
+ async () => (await page.locator(SELECTORS.coverPreview[0]).count()) > 0,
241
+ Math.min(timeoutMs, 20_000),
242
+ );
243
+ return shown ? null : 'cover: the upload landed but the editor shows no cover preview';
244
+ }
245
+
211
246
  export class InfoqBrowserTransport implements PublishTransport {
212
247
  public readonly kind = 'browser';
213
248
  public readonly driver: BrowserDriver;
@@ -327,6 +362,10 @@ export class InfoqBrowserTransport implements PublishTransport {
327
362
  )
328
363
  .catch(() => {});
329
364
 
365
+ // 封面 rides the same draft: set it before the save signal so one save covers both.
366
+ const coverWarning = await attachCover(page, content, this.stepTimeoutMs);
367
+ if (coverWarning !== null) Object.assign(metadata, { warnings: [coverWarning] });
368
+
330
369
  // Signal = the autosave 已保存 indicator, measured within ~6 s of paste (0201 walk);
331
370
  // the 30 s default window is the 5× margin (see STEP_TIMEOUT_MS).
332
371
  const draft = await expectOutcome(() => readToast(page, DRAFT_SAVED_TEXTS), {