@gobing-ai/knowledge-kit 0.0.32 → 0.0.33

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 (65) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +32320 -15021
  3. package/package.json +4 -4
  4. package/plugins/generations/content-gen/dist/index.js +10 -9
  5. package/plugins/generations/core-facts-gen/dist/index.js +13 -12
  6. package/plugins/generations/daily-article-gen/dist/index.js +14 -13
  7. package/plugins/generations/daily-article-gen/src/index.ts +1 -1
  8. package/plugins/generations/dailynews-gen/dist/index.js +10 -9
  9. package/plugins/generations/episode-plan-gen/dist/index.js +58 -15
  10. package/plugins/generations/episode-plan-gen/src/index.ts +76 -6
  11. package/plugins/generations/gemini-tts/README.md +11 -0
  12. package/plugins/generations/gemini-tts/dist/index.js +10 -9
  13. package/plugins/generations/image-gen/dist/index.js +154 -151
  14. package/plugins/generations/image-gen/src/compose/chromium.ts +60 -42
  15. package/plugins/generations/news-report-gen/dist/index.js +13 -12
  16. package/plugins/generations/voice-gen/dist/index.js +10 -9
  17. package/plugins/ingestions/aihot-ingest/dist/index.js +13 -12
  18. package/plugins/ingestions/horizon-ingest/dist/index.js +13 -12
  19. package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
  20. package/plugins/ingestions/last30days-ingest/dist/index.js +13 -12
  21. package/plugins/ingestions/web-search/dist/index.js +11 -10
  22. package/plugins/kk/README.md +38 -0
  23. package/plugins/kk/decisions/extract/ai-news.yaml +21 -0
  24. package/plugins/kk/decisions/kk-items.yaml +113 -0
  25. package/plugins/kk/plugin.json +1 -1
  26. package/plugins/kk/schedules/cron.tmpl +15 -0
  27. package/plugins/kk/schedules/launchd.plist.tmpl +77 -0
  28. package/plugins/kk/scripts/daily-stages.ts +1533 -0
  29. package/plugins/kk/scripts/kk-workflow-stages.ts +247 -1365
  30. package/plugins/kk/skills/content-safety/SKILL.md +38 -7
  31. package/plugins/kk/skills/web-automation/SKILL.md +100 -0
  32. package/plugins/kk/skills/web-automation/references/browser-launch.md +86 -0
  33. package/plugins/kk/workflows/kk-collect.yaml +258 -0
  34. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +9 -3
  35. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +655 -0
  36. package/plugins/kk/workflows/kk-daily-safety.yaml +170 -0
  37. package/plugins/publishings/emdash-pub/dist/index.js +10 -9
  38. package/plugins/publishings/infoq-pub/dist/index.js +152 -59
  39. package/plugins/publishings/infoq-pub/plugin.json +1 -0
  40. package/plugins/publishings/infoq-pub/src/index.ts +167 -55
  41. package/plugins/publishings/infoq-pub/src/profile-check.ts +4 -2
  42. package/plugins/publishings/juejin-pub/dist/index.js +111 -30
  43. package/plugins/publishings/juejin-pub/plugin.json +1 -0
  44. package/plugins/publishings/juejin-pub/src/index.ts +49 -9
  45. package/plugins/publishings/medium-pub/dist/index.js +10 -9
  46. package/plugins/publishings/podcast-pub/dist/index.js +10 -9
  47. package/plugins/publishings/qiita-pub/dist/index.js +10 -9
  48. package/plugins/publishings/substack-pub/dist/index.js +105 -28
  49. package/plugins/publishings/substack-pub/plugin.json +1 -0
  50. package/plugins/publishings/substack-pub/src/index.ts +39 -8
  51. package/plugins/publishings/substack-pub/src/profile-check.ts +2 -0
  52. package/plugins/publishings/surfdash-pub/dist/index.js +10 -9
  53. package/plugins/publishings/wechatmp-pub/dist/index.js +115 -31
  54. package/plugins/publishings/wechatmp-pub/plugin.json +1 -0
  55. package/plugins/publishings/wechatmp-pub/src/index.ts +42 -9
  56. package/plugins/publishings/wechatmp-pub/src/profile-check.ts +84 -40
  57. package/plugins/publishings/x-pub/dist/index.js +114 -35
  58. package/plugins/publishings/x-pub/plugin.json +1 -0
  59. package/plugins/publishings/x-pub/src/index.ts +68 -14
  60. package/plugins/publishings/xhs-pub/dist/index.js +100 -54
  61. package/plugins/publishings/xhs-pub/plugin.json +1 -0
  62. package/plugins/publishings/xhs-pub/src/index.ts +8 -4
  63. package/plugins/publishings/xhs-pub/src/page.ts +4 -17
  64. package/plugins/publishings/xhs-pub/src/profile-check.ts +28 -15
  65. package/plugins/publishings/zenn-pub/dist/index.js +10 -9
@@ -14671,7 +14671,7 @@ var init_zod = __esm(() => {
14671
14671
  init_external();
14672
14672
  });
14673
14673
 
14674
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/errors.js
14674
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/errors.js
14675
14675
  var ErrorCode;
14676
14676
  var init_errors3 = __esm(() => {
14677
14677
  ErrorCode = {
@@ -14682,7 +14682,7 @@ var init_errors3 = __esm(() => {
14682
14682
  };
14683
14683
  });
14684
14684
 
14685
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/api-response.js
14685
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/api-response.js
14686
14686
  var API_ERROR_CODES, ERROR_CODE_TO_HTTP, CLIENT_SAFE_CODES;
14687
14687
  var init_api_response = __esm(() => {
14688
14688
  init_errors3();
@@ -14705,10 +14705,10 @@ var init_api_response = __esm(() => {
14705
14705
  CLIENT_SAFE_CODES = new Set([ErrorCode.NotFound, ErrorCode.Validation, ErrorCode.Conflict]);
14706
14706
  });
14707
14707
 
14708
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/cursor.js
14708
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/cursor.js
14709
14709
  var init_cursor = () => {};
14710
14710
 
14711
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/env.js
14711
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/env.js
14712
14712
  function getEnvVar(name, fallback) {
14713
14713
  const raw = process.env[name];
14714
14714
  return raw === undefined ? fallback : raw;
@@ -14717,10 +14717,10 @@ function getEnvVars() {
14717
14717
  return process.env;
14718
14718
  }
14719
14719
 
14720
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
14720
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
14721
14721
  var init_event_severity = () => {};
14722
14722
 
14723
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/object.js
14723
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/object.js
14724
14724
  function isPlainObject2(value) {
14725
14725
  return typeof value === "object" && value !== null && !Array.isArray(value);
14726
14726
  }
@@ -14738,7 +14738,7 @@ function deepMerge(target, source) {
14738
14738
  return result;
14739
14739
  }
14740
14740
 
14741
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/output.js
14741
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/output.js
14742
14742
  function processStream(name) {
14743
14743
  const proc = globalThis.process;
14744
14744
  const stream = proc?.[name];
@@ -14756,7 +14756,7 @@ function echoError(message, target = defaultStderrTarget ?? processStream("stder
14756
14756
  }
14757
14757
  var defaultStderrTarget;
14758
14758
 
14759
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.15/node_modules/@gobing-ai/ts-utils/dist/index.js
14759
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.18/node_modules/@gobing-ai/ts-utils/dist/index.js
14760
14760
  var init_dist = __esm(() => {
14761
14761
  init_api_response();
14762
14762
  init_cursor();
@@ -21754,7 +21754,7 @@ var init_dist2 = __esm(() => {
21754
21754
  $visitAsync = visit.visitAsync;
21755
21755
  });
21756
21756
 
21757
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/config.js
21757
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/config.js
21758
21758
  function getProcessEnv() {
21759
21759
  return getEnvVars();
21760
21760
  }
@@ -21832,7 +21832,7 @@ var init_config = __esm(() => {
21832
21832
  };
21833
21833
  });
21834
21834
 
21835
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
21835
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
21836
21836
  import { appendFileSync, cpSync, createReadStream, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
21837
21837
  import { dirname, resolve as resolvePath } from "path";
21838
21838
  function createNodeFileSystem(root, paths) {
@@ -21919,7 +21919,7 @@ function findProjectRoot(startDir) {
21919
21919
  }
21920
21920
  var init_file_system_node = () => {};
21921
21921
 
21922
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/db-errors.js
21922
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/db-errors.js
21923
21923
  var DbModuleNotInstalledError;
21924
21924
  var init_db_errors = __esm(() => {
21925
21925
  DbModuleNotInstalledError = class DbModuleNotInstalledError extends Error {
@@ -29130,7 +29130,7 @@ var init_execa = __esm(() => {
29130
29130
  } = getIpcExport());
29131
29131
  });
29132
29132
 
29133
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/process-group.js
29133
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/process-group.js
29134
29134
  function resolveDeadline(optionTimeout, defaultTimeout) {
29135
29135
  if (optionTimeout === null)
29136
29136
  return null;
@@ -29222,7 +29222,7 @@ function ownProcessGroupLifecycle(ownership) {
29222
29222
  }
29223
29223
  var MAX_TIMEOUT_MS = 2147483647, DEFAULT_KILL_GRACE_MS = 5000, GROUP_POLL_INTERVAL_MS = 25, GROUP_KILL_PATIENCE_MS = 2000;
29224
29224
 
29225
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/process-executor.js
29225
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/process-executor.js
29226
29226
  import { isatty } from "tty";
29227
29227
  function processEventSeverity(reason, exitCode) {
29228
29228
  if (reason === "error")
@@ -29594,7 +29594,7 @@ var init_process_executor = __esm(() => {
29594
29594
  init_config();
29595
29595
  });
29596
29596
 
29597
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/runtime-node-bun.js
29597
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/runtime-node-bun.js
29598
29598
  function getNodeFileSystem() {
29599
29599
  if (!_nodeFileSystem)
29600
29600
  _nodeFileSystem = createNodeFileSystem();
@@ -29741,15 +29741,16 @@ var PluginManifestSchema = exports_external.looseObject({
29741
29741
  name: exports_external.string().min(1),
29742
29742
  kind: PluginKindSchema,
29743
29743
  entry: exports_external.string().min(1),
29744
+ check: exports_external.string().min(1).optional(),
29744
29745
  version: exports_external.string().optional(),
29745
29746
  description: exports_external.string().optional(),
29746
29747
  operations: exports_external.record(exports_external.string(), PluginOperationSchema).optional()
29747
29748
  });
29748
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/index.js
29749
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/index.js
29749
29750
  init_file_system_node();
29750
29751
  init_config();
29751
29752
 
29752
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/path.js
29753
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/path.js
29753
29754
  function normalizeSeparators(path6) {
29754
29755
  return path6.replaceAll("\\", "/");
29755
29756
  }
@@ -29807,7 +29808,7 @@ function getProcessCwd() {
29807
29808
  return globalThis.process?.cwd?.() ?? "/";
29808
29809
  }
29809
29810
 
29810
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.15/node_modules/@gobing-ai/ts-runtime/dist/index.js
29811
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.18+ea28d47622d670ff/node_modules/@gobing-ai/ts-runtime/dist/index.js
29811
29812
  init_runtime_node_bun();
29812
29813
 
29813
29814
  // ../../packages/kk-core/src/render-md.ts
@@ -29920,7 +29921,10 @@ async function trySelectors(page, selectors, options = {}) {
29920
29921
  return { found: false, selector: null };
29921
29922
  }
29922
29923
 
29923
- // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.15+e28deaf1f2c5a2b1/node_modules/@gobing-ai/ts-browser-automation/dist/errors.js
29924
+ // ../../packages/publish-harness/src/browser.ts
29925
+ import { resolve as resolve2 } from "path";
29926
+
29927
+ // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.18+1f5782d4d327a230/node_modules/@gobing-ai/ts-browser-automation/dist/errors.js
29924
29928
  class BrowserAutomationError extends Error {
29925
29929
  constructor(message, options) {
29926
29930
  super(message, options);
@@ -29969,10 +29973,10 @@ class OperationAbortedError extends BrowserAutomationError {
29969
29973
  this.name = "OperationAbortedError";
29970
29974
  }
29971
29975
  }
29972
- // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.15+e28deaf1f2c5a2b1/node_modules/@gobing-ai/ts-browser-automation/dist/launcher.js
29976
+ // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.18+1f5782d4d327a230/node_modules/@gobing-ai/ts-browser-automation/dist/launcher.js
29973
29977
  import { mkdir } from "fs/promises";
29974
29978
 
29975
- // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.15+e28deaf1f2c5a2b1/node_modules/@gobing-ai/ts-browser-automation/dist/profile-dir.js
29979
+ // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.18+1f5782d4d327a230/node_modules/@gobing-ai/ts-browser-automation/dist/profile-dir.js
29976
29980
  function resolveProfileDir(profileDir) {
29977
29981
  if (profileDir.trim() === "") {
29978
29982
  throw new InvalidProfileDirError;
@@ -29984,7 +29988,7 @@ function resolveProfileDir(profileDir) {
29984
29988
  return resolved;
29985
29989
  }
29986
29990
 
29987
- // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.15+e28deaf1f2c5a2b1/node_modules/@gobing-ai/ts-browser-automation/dist/launcher.js
29991
+ // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.18+1f5782d4d327a230/node_modules/@gobing-ai/ts-browser-automation/dist/launcher.js
29988
29992
  var PROFILE_DIR_MODE = 448;
29989
29993
  var BUSY_PROFILE_PATTERN = /singleton|already in use|in use by another/i;
29990
29994
  var CHROMIUM_MISSING_PATTERN = /playwright install|executable doesn't exist/i;
@@ -30035,7 +30039,7 @@ function createPersistentLauncher(options = {}) {
30035
30039
  };
30036
30040
  }
30037
30041
 
30038
- // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.15+e28deaf1f2c5a2b1/node_modules/@gobing-ai/ts-browser-automation/dist/operations.js
30042
+ // ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.18+1f5782d4d327a230/node_modules/@gobing-ai/ts-browser-automation/dist/operations.js
30039
30043
  var DEFAULT_TIMEOUT_MS = 30000;
30040
30044
  var POLL_INTERVAL_MS = 250;
30041
30045
  var defaultLauncher;
@@ -30114,11 +30118,67 @@ async function pollPredicate(page, predicate, timeoutMs, signal) {
30114
30118
  function sleep(ms) {
30115
30119
  return new Promise((resolve2) => setTimeout(resolve2, ms));
30116
30120
  }
30121
+ // ../../packages/publish-harness/src/profile-dir.ts
30122
+ import { mkdir as mkdir2, stat } from "fs/promises";
30123
+ async function ensureProfileDir2(profileDir, headless) {
30124
+ const existing = await stat(profileDir).catch(() => null);
30125
+ if (existing) {
30126
+ if (!existing.isDirectory())
30127
+ throw new InvalidProfileDirError(`profileDir is not a directory: "${profileDir}".`);
30128
+ return;
30129
+ }
30130
+ if (headless)
30131
+ throw new BrowserProfileMissingError(profileDir);
30132
+ await mkdir2(profileDir, { recursive: true, mode: 448 });
30133
+ }
30134
+
30117
30135
  // ../../packages/publish-harness/src/browser.ts
30118
30136
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
30119
30137
  var DEFAULT_STEP_TIMEOUT_MS = 30000;
30120
30138
  var DEFAULT_POLL_MS = 500;
30121
30139
  var ATTACH_POLL_MS = 100;
30140
+ function createKkBrowserLauncher(loadPlaywright = () => import("playwright")) {
30141
+ return {
30142
+ async launch(request) {
30143
+ if (request.profileDir.trim() === "")
30144
+ throw new InvalidProfileDirError;
30145
+ const profileDir = resolve2(request.profileDir);
30146
+ await ensureProfileDir2(profileDir, request.headless);
30147
+ let playwright;
30148
+ try {
30149
+ playwright = await loadPlaywright();
30150
+ } catch (error51) {
30151
+ throw new PlaywrightUnavailableError('The "playwright" dependency is not installed. Run `bunx playwright install chromium`.', { cause: error51 });
30152
+ }
30153
+ const channel = process.env.KK_BROWSER_CHANNEL?.trim() || "chromium";
30154
+ let context2;
30155
+ try {
30156
+ context2 = await playwright.chromium.launchPersistentContext(profileDir, {
30157
+ headless: request.headless,
30158
+ channel,
30159
+ args: ["--disable-blink-features=AutomationControlled"],
30160
+ ignoreDefaultArgs: ["--enable-automation"]
30161
+ });
30162
+ } catch (error51) {
30163
+ const message = errorMessage2(error51);
30164
+ if (/singleton|already in use|in use by another/i.test(message)) {
30165
+ throw new BrowserProfileBusyError(profileDir, error51);
30166
+ }
30167
+ if (/playwright install|executable doesn't exist/i.test(message)) {
30168
+ throw new PlaywrightUnavailableError(`Browser channel '${channel}' is not installed. Run \`bunx playwright install chromium\` (or install Google Chrome for KK_BROWSER_CHANNEL=chrome).`, { cause: error51 });
30169
+ }
30170
+ throw error51;
30171
+ }
30172
+ await context2.addInitScript(() => {
30173
+ Object.defineProperty(navigator, "webdriver", { get: () => {
30174
+ return;
30175
+ } });
30176
+ });
30177
+ return context2;
30178
+ }
30179
+ };
30180
+ }
30181
+ var kkBrowserLauncher = createKkBrowserLauncher();
30122
30182
  function resolveChannelProfileDir(channel, override) {
30123
30183
  const tiers = [override, process.env[`${channel.toUpperCase()}_PROFILE_DIR`], process.env.KK_BROWSER_PROFILE_DIR];
30124
30184
  const chosen = tiers.find((tier) => tier !== undefined && tier.trim().length > 0);
@@ -30126,7 +30186,7 @@ function resolveChannelProfileDir(channel, override) {
30126
30186
  }
30127
30187
  async function checkChannelSession(config3, opts) {
30128
30188
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
30129
- const passes = opts.headedFallback === false ? [true] : [true, false];
30189
+ const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
30130
30190
  let lastDetail = `${config3.channel} readiness was never probed`;
30131
30191
  for (const headless of passes) {
30132
30192
  try {
@@ -30136,12 +30196,12 @@ async function checkChannelSession(config3, opts) {
30136
30196
  url: config3.homeUrl,
30137
30197
  isAuthenticated: config3.isAuthenticated,
30138
30198
  timeoutMs,
30139
- launcher: opts.launcher
30199
+ launcher: opts.launcher ?? kkBrowserLauncher
30140
30200
  }, async () => true);
30141
30201
  return {
30142
30202
  status: "verified",
30143
30203
  profileDir: opts.profileDir,
30144
- detail: `authenticated ${config3.channel} session observed ${headless ? "headlessly" : "via headed fallback"} via profile ${opts.profileDir} (read-only)`
30204
+ detail: `authenticated ${config3.channel} session observed ${headless ? "headlessly" : "via a headed pass"} via profile ${opts.profileDir} (read-only)`
30145
30205
  };
30146
30206
  } catch (error51) {
30147
30207
  if (error51 instanceof BrowserProfileMissingError) {
@@ -30162,7 +30222,7 @@ async function waitUntil(predicate, timeoutMs, pollMs = DEFAULT_POLL_MS) {
30162
30222
  if (await predicate()) {
30163
30223
  return true;
30164
30224
  }
30165
- await new Promise((resolve2) => setTimeout(resolve2, pollMs));
30225
+ await new Promise((resolve3) => setTimeout(resolve3, pollMs));
30166
30226
  }
30167
30227
  return predicate();
30168
30228
  }
@@ -30263,27 +30323,39 @@ function editorTextScript(selector) {
30263
30323
  init_dist();
30264
30324
  var CHANNEL = "infoq";
30265
30325
  var TARGET = "infoq";
30266
- var EDITOR_URL = "https://xie.infoq.cn/write";
30267
- var LOGIN_URL_RE = /(account\.infoq\.cn|\/login)/;
30326
+ var HOME_URL = "https://xie.infoq.cn/";
30327
+ var DRAFT_URL_RE = /\/draft\/(\d+)/;
30328
+ var LOGIN_URL_RE = /(account\.infoq\.cn|account\.geekbang\.org|\/login)/;
30268
30329
  var SELECTORS = {
30269
- title: ['input[placeholder*="\u6807\u9898"]', 'textarea[placeholder*="\u6807\u9898"]'],
30270
- summary: ['input[placeholder*="\u6458\u8981"]', 'textarea[placeholder*="\u6458\u8981"]', 'input[name="summary"]'],
30330
+ writeEntry: ["div.write-btn"],
30331
+ noticeDismiss: ["text=\u77E5\u9053\u4E86"],
30332
+ title: ['input[placeholder="\u8BF7\u8F93\u5165\u6807\u9898"]', 'input[placeholder*="\u6807\u9898"]'],
30271
30333
  body: ['.ProseMirror[contenteditable="true"]', '[contenteditable="true"]'],
30272
- draft: ['button:has-text("\u4FDD\u5B58\u8349\u7A3F")'],
30273
- live: ['button:has-text("\u63D0\u4EA4")']
30334
+ live: ["div.submit-btn"]
30274
30335
  };
30275
30336
  var STEP_TIMEOUT_MS = 30000;
30337
+ var CHECK_TIMEOUT_MS = 60000;
30276
30338
  var LOGIN_TIMEOUT_MS = 180000;
30277
30339
  var LOGIN_INSTRUCTION = "bun plugins/publishings/infoq-pub/src/profile-check.ts login";
30278
- var DRAFT_URL_ID_RE = /\/(\d{4,}|[0-9a-f]{16,})(?:\/|$|\?)/;
30279
- var DRAFT_TOASTS = ["\u4FDD\u5B58\u6210\u529F", "\u5DF2\u4FDD\u5B58"];
30340
+ var DRAFT_SAVED_TEXTS = ["\u5DF2\u4FDD\u5B58"];
30341
+ var SIGNAL_CONTAINERS = [...DEFAULT_SIGNAL_CONTAINERS, '[class*="save-status" i]'];
30280
30342
  var LIVE_TOASTS = ["\u63D0\u4EA4\u6210\u529F", "\u5BA1\u6838"];
30281
- var isAuthenticated = async (page) => !LOGIN_URL_RE.test(page.url()) && (await trySelectors(page, SELECTORS.title, { visible: false })).found;
30343
+ var LOGGED_OUT_MARKER_SCRIPT = `(() => {
30344
+ for (const node of document.querySelectorAll('body *')) {
30345
+ if (node.children.length > 0) continue;
30346
+ if ((node.textContent ?? '').trim() !== '\u767B\u5F55') continue;
30347
+ if (typeof node.checkVisibility === 'function' ? !node.checkVisibility() : node.getClientRects().length === 0) continue;
30348
+ return true;
30349
+ }
30350
+ return false;
30351
+ })()`;
30352
+ var isAuthenticated = async (page) => !LOGIN_URL_RE.test(page.url()) && (await trySelectors(page, SELECTORS.writeEntry, { visible: false })).found && !await page.evaluate(LOGGED_OUT_MARKER_SCRIPT);
30282
30353
  var CONFIG = {
30283
30354
  channel: CHANNEL,
30284
- homeUrl: EDITOR_URL,
30355
+ homeUrl: HOME_URL,
30285
30356
  isAuthenticated,
30286
- loginTimeoutMs: LOGIN_TIMEOUT_MS
30357
+ loginTimeoutMs: LOGIN_TIMEOUT_MS,
30358
+ checkHeadedOnly: true
30287
30359
  };
30288
30360
  function fail(error51) {
30289
30361
  return ResultSchema.parse({ ok: false, target: TARGET, error: error51 });
@@ -30308,7 +30380,19 @@ async function findSelector(page, selectors, what, timeoutMs) {
30308
30380
  return selector;
30309
30381
  }
30310
30382
  async function readToast(page, texts) {
30311
- return readScopedSignal(page, texts);
30383
+ return readScopedSignal(page, texts, SIGNAL_CONTAINERS);
30384
+ }
30385
+ var INFOQ_OPERATIONS = ["draft"];
30386
+ function resolveOperation(options, content) {
30387
+ const raw = options?.operation ?? content?.metadata?.operation;
30388
+ if (raw === undefined)
30389
+ return { operation: "draft" };
30390
+ if (typeof raw !== "string" || !INFOQ_OPERATIONS.includes(raw)) {
30391
+ return {
30392
+ error: `unsupported operation '${String(raw)}' for infoq: expected one of ${INFOQ_OPERATIONS.join(", ")}`
30393
+ };
30394
+ }
30395
+ return { operation: raw };
30312
30396
  }
30313
30397
 
30314
30398
  class InfoqBrowserTransport {
@@ -30316,15 +30400,20 @@ class InfoqBrowserTransport {
30316
30400
  driver;
30317
30401
  launcher;
30318
30402
  stepTimeoutMs;
30403
+ checkTimeoutMs;
30319
30404
  constructor(driver = "script", deps = {}) {
30320
30405
  this.driver = driver;
30321
- this.launcher = deps.launcher;
30406
+ this.launcher = deps.launcher ?? kkBrowserLauncher;
30322
30407
  this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
30408
+ this.checkTimeoutMs = deps.checkTimeoutMs ?? CHECK_TIMEOUT_MS;
30323
30409
  }
30324
30410
  async publish(payload) {
30325
30411
  if (this.driver !== "script") {
30326
30412
  return fail(`unsupported driver '${this.driver}' for ${TARGET}`);
30327
30413
  }
30414
+ const mode = resolveOperation(payload.options, payload.content);
30415
+ if (mode.error !== undefined)
30416
+ return fail(mode.error);
30328
30417
  const requested = payload.content.metadata?.publishStatus;
30329
30418
  if (requested !== undefined && requested !== "draft" && requested !== "public") {
30330
30419
  return fail(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
@@ -30335,8 +30424,8 @@ class InfoqBrowserTransport {
30335
30424
  const session = await checkChannelSession(CONFIG, {
30336
30425
  profileDir,
30337
30426
  launcher: this.launcher,
30338
- headedFallback: false,
30339
- timeoutMs: this.stepTimeoutMs
30427
+ headedOnly: true,
30428
+ timeoutMs: this.checkTimeoutMs
30340
30429
  });
30341
30430
  if (session.status !== "verified") {
30342
30431
  return fail(`${CHANNEL} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
@@ -30344,7 +30433,7 @@ class InfoqBrowserTransport {
30344
30433
  try {
30345
30434
  return await withProfilePage({
30346
30435
  profileDir,
30347
- url: EDITOR_URL,
30436
+ url: HOME_URL,
30348
30437
  isAuthenticated,
30349
30438
  headless: payload.options?.headless === true,
30350
30439
  launcher: this.launcher,
@@ -30357,25 +30446,25 @@ class InfoqBrowserTransport {
30357
30446
  }
30358
30447
  async runEditorFlow(page, content, publishStatus, profileDir) {
30359
30448
  const metadata = { driver: this.driver, publishStatus, profileDir };
30449
+ const entrySelector = await findSelector(page, SELECTORS.writeEntry, "write entry", this.stepTimeoutMs);
30450
+ await page.locator(entrySelector).first().click();
30451
+ const entered = await waitUntil(() => Promise.resolve(DRAFT_URL_RE.test(page.url())), this.stepTimeoutMs);
30452
+ if (!entered) {
30453
+ throw new Error(`infoq editor entry: still on '${page.url()}' \u2014 no /draft/<id> within ${this.stepTimeoutMs}ms`);
30454
+ }
30455
+ const id = DRAFT_URL_RE.exec(page.url())?.[1];
30456
+ await dismissNoticeModal(page, this.stepTimeoutMs);
30360
30457
  const titleSelector = await findSelector(page, SELECTORS.title, "title input", this.stepTimeoutMs);
30361
30458
  await page.locator(titleSelector).first().fill(content.title ?? "");
30362
- const summary = content.metadata?.summary;
30363
- if (typeof summary === "string" && summary.length > 0) {
30364
- const summarySelector = await findSelector(page, SELECTORS.summary, "summary input", this.stepTimeoutMs);
30365
- await page.locator(summarySelector).first().fill(summary);
30366
- }
30367
30459
  const bodySelector = await findSelector(page, SELECTORS.body, "body editor", this.stepTimeoutMs);
30368
30460
  await pasteHtml(page, bodySelector, markdownToHtml(content.body), { timeoutMs: this.stepTimeoutMs });
30369
- const urlBeforeSave = page.url();
30370
- const draftSelector = await findSelector(page, SELECTORS.draft, "draft control", this.stepTimeoutMs);
30371
- await page.locator(draftSelector).first().click();
30372
- const draft = await expectOutcome(() => probeDraft(page, urlBeforeSave), {
30461
+ await page.evaluate('(selector) => { const editor = document.querySelector(selector); editor && editor.dispatchEvent(new InputEvent("input", { bubbles: true })); }', bodySelector).catch(() => {});
30462
+ const draft = await expectOutcome(() => readToast(page, DRAFT_SAVED_TEXTS), {
30373
30463
  timeoutMs: this.stepTimeoutMs,
30374
- label: `infoq draft save '${draftSelector}'`
30464
+ label: "infoq draft autosave"
30375
30465
  });
30376
30466
  if (!draft.ok)
30377
30467
  return fail(draft.error);
30378
- const id = DRAFT_URL_ID_RE.exec(draft.evidence)?.[1];
30379
30468
  if (publishStatus === "draft") {
30380
30469
  return ResultSchema.parse({
30381
30470
  ok: true,
@@ -30405,11 +30494,12 @@ class InfoqBrowserTransport {
30405
30494
  });
30406
30495
  }
30407
30496
  }
30408
- async function probeDraft(page, urlBeforeSave) {
30409
- const url2 = page.url();
30410
- if (url2 !== urlBeforeSave && DRAFT_URL_ID_RE.test(url2))
30411
- return url2;
30412
- return readToast(page, DRAFT_TOASTS);
30497
+ async function dismissNoticeModal(page, timeoutMs) {
30498
+ const modal = page.locator(SELECTORS.noticeDismiss[0]).first();
30499
+ try {
30500
+ if (await modal.count() > 0)
30501
+ await modal.click({ timeout: Math.min(timeoutMs, 5000) });
30502
+ } catch {}
30413
30503
  }
30414
30504
  async function probeLive(page, urlBeforeSave) {
30415
30505
  const toast = await readToast(page, LIVE_TOASTS);
@@ -30474,6 +30564,7 @@ if (import.meta.main) {
30474
30564
  process.exit(await main2());
30475
30565
  }
30476
30566
  export {
30567
+ resolveOperation,
30477
30568
  processPublishIO,
30478
30569
  main2 as main,
30479
30570
  isAuthenticated,
@@ -30481,7 +30572,9 @@ export {
30481
30572
  SELECTORS,
30482
30573
  LOGIN_URL_RE,
30483
30574
  InfoqBrowserTransport,
30484
- EDITOR_URL,
30575
+ INFOQ_OPERATIONS,
30576
+ HOME_URL,
30577
+ DRAFT_URL_RE,
30485
30578
  CONFIG,
30486
30579
  CHANNEL
30487
30580
  };
@@ -2,6 +2,7 @@
2
2
  "name": "infoq-pub",
3
3
  "kind": "publish",
4
4
  "entry": "./dist/index.js",
5
+ "check": "./src/profile-check.ts",
5
6
  "version": "1.0.0",
6
7
  "description": "Publish plugin for InfoQ CN (xie.infoq.cn): article drafts through the InfoQ editor via script browser transport (ts-browser-automation)"
7
8
  }