@gobing-ai/knowledge-kit 0.1.25 → 0.1.27

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 (50) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +115 -21
  3. package/package.json +1 -1
  4. package/plugins/kk/plugin.json +1 -1
  5. package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
  6. package/plugins/kk/scripts/daily-stages.ts +416 -134
  7. package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
  8. package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
  9. package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
  10. package/plugins/publishings/bilibili-pub/dist/index.js +33 -2
  11. package/plugins/publishings/bilibili-pub/dist/profile-check.js +33 -2
  12. package/plugins/publishings/cnblogs-pub/dist/index.js +33 -2
  13. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +33 -2
  14. package/plugins/publishings/csdn-pub/dist/index.js +33 -2
  15. package/plugins/publishings/csdn-pub/dist/profile-check.js +33 -2
  16. package/plugins/publishings/infoq-pub/dist/index.js +33 -2
  17. package/plugins/publishings/infoq-pub/dist/profile-check.js +33 -2
  18. package/plugins/publishings/jike-pub/dist/index.js +33 -2
  19. package/plugins/publishings/jike-pub/dist/profile-check.js +33 -2
  20. package/plugins/publishings/juejin-pub/dist/index.js +33 -2
  21. package/plugins/publishings/juejin-pub/dist/profile-check.js +33 -2
  22. package/plugins/publishings/linkedin-pub/dist/index.js +84 -13
  23. package/plugins/publishings/linkedin-pub/dist/profile-check.js +50 -5
  24. package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
  25. package/plugins/publishings/medium-pub/dist/index.js +33 -2
  26. package/plugins/publishings/medium-pub/dist/profile-check.js +33 -2
  27. package/plugins/publishings/shipinhao-pub/dist/index.js +33 -2
  28. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +33 -2
  29. package/plugins/publishings/sspai-pub/dist/index.js +33 -2
  30. package/plugins/publishings/sspai-pub/dist/profile-check.js +33 -2
  31. package/plugins/publishings/substack-pub/dist/index.js +33 -2
  32. package/plugins/publishings/substack-pub/dist/profile-check.js +33 -2
  33. package/plugins/publishings/surfdash-pub/dist/index.js +53 -15
  34. package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
  35. package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
  36. package/plugins/publishings/threads-pub/dist/index.js +33 -2
  37. package/plugins/publishings/threads-pub/dist/profile-check.js +33 -2
  38. package/plugins/publishings/wechatmp-pub/dist/index.js +65 -3
  39. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +67 -3
  40. package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
  41. package/plugins/publishings/weibo-pub/dist/index.js +56 -8
  42. package/plugins/publishings/weibo-pub/dist/profile-check.js +55 -8
  43. package/plugins/publishings/weibo-pub/plugin.json +1 -1
  44. package/plugins/publishings/weibo-pub/src/index.ts +76 -8
  45. package/plugins/publishings/x-pub/dist/index.js +33 -2
  46. package/plugins/publishings/x-pub/dist/profile-check.js +33 -2
  47. package/plugins/publishings/xhs-pub/dist/index.js +33 -2
  48. package/plugins/publishings/xhs-pub/dist/profile-check.js +33 -2
  49. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +33 -2
  50. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +33 -2
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "plugins": [
8
8
  {
9
- "version": "0.1.25",
9
+ "version": "0.1.27",
10
10
  "name": "kk",
11
11
  "source": "./plugins/kk",
12
12
  "description": "knowledge-kit — a set of toolkit for knowledge management"
package/dist/index.js CHANGED
@@ -38202,7 +38202,12 @@ async function acquireProfileLease(profileDir, options = {}) {
38202
38202
  const leaseDir = join15(leaseRoot, id);
38203
38203
  await fileSystem.ensureDir(leaseRoot);
38204
38204
  if (!mkdirExclusive(leaseDir, 448)) {
38205
- throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
38205
+ if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
38206
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
38207
+ }
38208
+ if (!mkdirExclusive(leaseDir, 448)) {
38209
+ throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
38210
+ }
38206
38211
  }
38207
38212
  const token = randomBytes(16).toString("hex");
38208
38213
  const owner = {
@@ -38318,9 +38323,35 @@ async function busyGuidance(fileSystem, leaseDir) {
38318
38323
  }
38319
38324
  return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
38320
38325
  }
38321
- const suffix = isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
38326
+ const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
38327
+ const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
38322
38328
  return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
38323
38329
  }
38330
+ async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
38331
+ const owner = await readOwner(fileSystem, leaseDir);
38332
+ if (owner === null || isProcessAlive(owner.pid))
38333
+ return false;
38334
+ if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
38335
+ return false;
38336
+ const target = staleLeaseDir(leaseDir);
38337
+ try {
38338
+ rename(leaseDir, target);
38339
+ } catch {
38340
+ return false;
38341
+ }
38342
+ const moved = await readOwner(fileSystem, target);
38343
+ if (moved !== null && moved.token !== owner.token) {
38344
+ try {
38345
+ rename(target, leaseDir);
38346
+ } catch {}
38347
+ return false;
38348
+ }
38349
+ return true;
38350
+ }
38351
+ function staleLeaseDir(leaseDir) {
38352
+ const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
38353
+ return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
38354
+ }
38324
38355
  async function holderResidue(fileSystem, leaseDir) {
38325
38356
  try {
38326
38357
  const entries = await fileSystem.readDir(leaseDir);
@@ -50307,8 +50338,25 @@ async function runPublishMatrixValidate(args, deps = {}) {
50307
50338
  }
50308
50339
  var LINK_SOURCES = [
50309
50340
  { placeholder: "{{article_url}}", plugin: "surfdash-pub", receipt: "article" },
50310
- { placeholder: "{{podcast_url}}", plugin: "podcast-pub", receipt: "podcast" }
50341
+ { placeholder: "{{podcast_url}}", plugin: "podcast-pub", receipt: "podcast", fallback: "article" }
50311
50342
  ];
50343
+ function substituteLinkPlaceholders(payloadText, links) {
50344
+ let text = payloadText;
50345
+ const fallbacks = [];
50346
+ for (const source of LINK_SOURCES) {
50347
+ if (!text.includes(source.placeholder))
50348
+ continue;
50349
+ const own = links[source.receipt];
50350
+ const url = own ?? (source.fallback === undefined ? undefined : links[source.fallback]);
50351
+ if (url === undefined)
50352
+ continue;
50353
+ if (own === undefined && source.fallback !== undefined) {
50354
+ fallbacks.push({ placeholder: source.placeholder, source: source.fallback, url });
50355
+ }
50356
+ text = text.split(source.placeholder).join(JSON.stringify(url).slice(1, -1));
50357
+ }
50358
+ return { text, fallbacks };
50359
+ }
50312
50360
  async function readPlan(fs, workDir, window) {
50313
50361
  const planPath = join10(workDir, "4-publish", `plan.${window}.json`);
50314
50362
  if (!await fs.exists(planPath)) {
@@ -50857,13 +50905,15 @@ async function runPublishMatrixSettle(args, deps = {}) {
50857
50905
  unresolved.push({ id: row.id, reason: `prepared as ${receipt.mode ?? "unknown"}, not published live` });
50858
50906
  }
50859
50907
  }
50908
+ const coverPatch = await readCoverPatchDiagnostic(fs, publishDir);
50860
50909
  const settlement = {
50861
50910
  schemaVersion: 1,
50862
50911
  window: parsedWindow.data,
50863
50912
  runDate: plan.runDate ?? "",
50864
50913
  parentRunId,
50865
50914
  marked: unresolved.length === 0,
50866
- unresolved
50915
+ unresolved,
50916
+ ...coverPatch !== undefined ? { coverPatch } : {}
50867
50917
  };
50868
50918
  await fs.ensureDir(publishDir);
50869
50919
  const settlementPath = join10(publishDir, `settlement.${parsedWindow.data}.json`);
@@ -51064,6 +51114,27 @@ async function readOfficialAccountArticleIds(fs, publishDir, plan) {
51064
51114
  }
51065
51115
  return ids;
51066
51116
  }
51117
+ async function readCoverPatchDiagnostic(fs, publishDir) {
51118
+ const path = join10(publishDir, "patch-surfdash.result.json");
51119
+ if (!await fs.exists(path))
51120
+ return;
51121
+ try {
51122
+ const result = JSON.parse(await fs.readFile(path));
51123
+ const coverPatch = result.metadata?.coverPatch;
51124
+ if (coverPatch === null || typeof coverPatch !== "object" || Array.isArray(coverPatch))
51125
+ return;
51126
+ const entry = coverPatch;
51127
+ if (entry.status !== "applied" && entry.status !== "skipped")
51128
+ return;
51129
+ return {
51130
+ status: entry.status,
51131
+ reason: typeof entry.reason === "string" ? entry.reason : "",
51132
+ pageUrl: typeof entry.pageUrl === "string" ? entry.pageUrl : ""
51133
+ };
51134
+ } catch {
51135
+ return;
51136
+ }
51137
+ }
51067
51138
  var DISPATCH_MODE_RANK = { off: 0, dummy: 1, draft: 2, live: 3 };
51068
51139
  function ledgerSuppresses(row, entry, hasReceipt) {
51069
51140
  if (entry === undefined || entry.state !== "dispatched")
@@ -51274,28 +51345,38 @@ async function sendPublishMatrix(args, deps = {}) {
51274
51345
  });
51275
51346
  }
51276
51347
  }
51277
- let resolved = raw;
51278
- for (const source of LINK_SOURCES) {
51279
- const url = links[source.receipt];
51280
- if (url === undefined)
51281
- continue;
51282
- resolved = resolved.split(source.placeholder).join(JSON.stringify(url).slice(1, -1));
51348
+ const substitution = substituteLinkPlaceholders(raw, links);
51349
+ let resolved = substitution.text;
51350
+ for (const fallback of substitution.fallbacks) {
51351
+ await appendEvent(fs, publishDir, {
51352
+ event: "link-fallback",
51353
+ window: plan.window,
51354
+ id: row.key,
51355
+ placeholder: fallback.placeholder,
51356
+ source: fallback.source,
51357
+ url: fallback.url,
51358
+ mode: row.mode
51359
+ });
51360
+ echo(`publish-matrix-send: ${row.key} carries the ${fallback.source} link in place of ${fallback.placeholder} (no succeeded receipt for it)`);
51283
51361
  }
51284
51362
  if (cardLink !== undefined) {
51285
51363
  const carried = carryOfficialAccountLink(resolved, cardLink);
51286
51364
  resolved = carried.text;
51287
51365
  echo(`publish-matrix-send: ${row.key} carries the confirmed Official Account link (${carried.placement})`);
51288
51366
  }
51289
- if (LINK_SOURCES.some((source) => resolved.includes(source.placeholder))) {
51290
- const unresolved = LINK_SOURCES.filter((source) => resolved.includes(source.placeholder)).map((source) => source.placeholder);
51291
- const draftMayDropLink = row.mode === "draft" && unresolved.every((placeholder) => placeholder === "{{article_url}}");
51292
- if (draftMayDropLink) {
51293
- resolved = resolved.replace(/"originalUrl"\s*:\s*"\{\{article_url\}\}"/, '"originalUrl": ""');
51367
+ let stillUnresolved = LINK_SOURCES.filter((source) => resolved.includes(source.placeholder));
51368
+ if (stillUnresolved.length > 0 && row.mode === "draft") {
51369
+ const draftMayDropLink = stillUnresolved.every((source) => source.placeholder === "{{article_url}}");
51370
+ const dropped = draftMayDropLink ? resolved.replace(/"originalUrl"\s*:\s*"\{\{article_url\}\}"/, '"originalUrl": ""') : resolved;
51371
+ if (dropped !== resolved) {
51372
+ resolved = dropped;
51373
+ stillUnresolved = LINK_SOURCES.filter((source) => resolved.includes(source.placeholder));
51294
51374
  echo(`publish-matrix-send: ${row.key} is a draft \u2014 dropped the unresolved {{article_url}} cross-link`);
51295
51375
  }
51296
51376
  }
51297
- if (LINK_SOURCES.some((source) => resolved.includes(source.placeholder))) {
51298
- return { error: "unresolved-link" };
51377
+ if (stillUnresolved.length > 0) {
51378
+ const namable = stillUnresolved.find((source) => source.fallback !== undefined);
51379
+ return { error: namable === undefined ? "unresolved-link" : `${namable.receipt}-link-missing` };
51299
51380
  }
51300
51381
  const resolvedPath = join10(workDir, "4-publish", "payloads", `content.${row.key}.resolved.json`);
51301
51382
  await fs.writeFile(resolvedPath, resolved);
@@ -53523,7 +53604,10 @@ function appendLadderReport(body, workDir) {
53523
53604
  const section = [
53524
53605
  "## Pool ladder",
53525
53606
  "",
53526
- `- Driving measure: ${String(ladder.ratioUsed ?? "unknown")} spoken/raw ratio (${String(ladder.ratioSource ?? "unknown source")})`,
53607
+ `- Driving measure: ${String(ladder.spokenPerPoolChar ?? "unknown")} spoken chars per pool char (keep rate ${String(ladder.keepRate ?? "unknown")} \xD7 kept ratio ${String(ladder.keptRatio ?? "unknown")})`,
53608
+ `- Keep rate: ${String(ladder.keepRate ?? "unknown")} (${String(ladder.keepRateSource ?? "unknown source")})`,
53609
+ `- Kept ratio: ${String(ladder.keptRatio ?? "unknown")} (${String(ladder.keptRatioSource ?? "unknown source")})`,
53610
+ `- Recorded pool ratio: ${String(ladder.ratioUsed ?? "unknown")} (${String(ladder.ratioSource ?? "unknown source")})`,
53527
53611
  `- Chosen window: ${String(ladder.chosen ?? "unknown")}`,
53528
53612
  "",
53529
53613
  "| Window | Items | Characters | Estimated minutes | Clears floor |",
@@ -59288,6 +59372,13 @@ async function readJson6(fs, path) {
59288
59372
  return null;
59289
59373
  }
59290
59374
  }
59375
+ function variantCount(variants) {
59376
+ if (Array.isArray(variants))
59377
+ return variants.length;
59378
+ if (isObject7(variants))
59379
+ return Object.keys(variants).length;
59380
+ return null;
59381
+ }
59291
59382
  async function statusPayload(fs, workDir, type, selectedWindow) {
59292
59383
  const receipt = await readJson6(fs, join33(workDir, "schedule-receipt.json"));
59293
59384
  const generate = receipt === null ? null : {
@@ -59296,11 +59387,14 @@ async function statusPayload(fs, workDir, type, selectedWindow) {
59296
59387
  executor: optionalString3(receipt.executor),
59297
59388
  checkoutCommit: optionalString3(receipt.checkoutCommit)
59298
59389
  };
59299
- const bundle = await readJson6(fs, join33(workDir, "4-publish", "bundle.json"));
59390
+ const bundlePath = await resolveBundlePath(fs, workDir);
59391
+ const bundle = await readJson6(fs, bundlePath);
59392
+ const atRunRoot = bundlePath === join33(workDir, "bundle.json");
59300
59393
  const bundleSummary = bundle === null ? null : {
59301
- frozen: typeof bundle.frozen === "boolean" ? bundle.frozen : null,
59394
+ frozen: typeof bundle.frozen === "boolean" ? bundle.frozen : atRunRoot ? true : null,
59302
59395
  runId: optionalString3(bundle.runId),
59303
- variants: bundle.variants ?? null
59396
+ variants: bundle.variants ?? null,
59397
+ ...atRunRoot ? { variantCount: variantCount(bundle.variants) } : {}
59304
59398
  };
59305
59399
  const windows = {};
59306
59400
  const publishDir = join33(workDir, "4-publish");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/knowledge-kit",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "An ingest → create → publish content pipeline CLI (Bun).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "kk",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "knowledge-kit Claude Code plugin: skills, commands, subagents, hooks, and rules"
5
5
  }