zam-core 0.14.0 → 0.15.1

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.
package/dist/cli/app.js CHANGED
@@ -2140,6 +2140,15 @@ async function listTokens(db, options) {
2140
2140
  )`);
2141
2141
  params.push(options.knowledgeContext);
2142
2142
  }
2143
+ if (options?.sourceLinkBases) {
2144
+ const clauses = options.sourceLinkBases.map(
2145
+ () => `(source_link = ? OR source_link LIKE ? || '#%' ESCAPE '\\')`
2146
+ );
2147
+ whereClauses.push(clauses.length ? `(${clauses.join(" OR ")})` : "0 = 1");
2148
+ for (const base of options.sourceLinkBases) {
2149
+ params.push(base, escapeLike(base));
2150
+ }
2151
+ }
2143
2152
  const orderBy = options?.domain || options?.domainPrefix ? "ORDER BY bloom_level, slug" : "ORDER BY bloom_level, domain, slug";
2144
2153
  const sql = `SELECT * FROM tokens WHERE ${whereClauses.join(" AND ")} ${orderBy}`;
2145
2154
  const tokens = await db.prepare(sql).all(...params);
@@ -7349,7 +7358,7 @@ function unquote(raw) {
7349
7358
  return v;
7350
7359
  }
7351
7360
  function parseFrontmatter(markdown) {
7352
- const lines = markdown.split("\n");
7361
+ const lines = markdown.replace(/^/, "").split(/\r\n|\n/);
7353
7362
  if (lines[0]?.trim() !== "---") {
7354
7363
  throw new Error("frontmatter: file must start with a --- fence");
7355
7364
  }
@@ -7466,7 +7475,7 @@ ${rows}`;
7466
7475
  function appendLog(existing, date, line) {
7467
7476
  const header = `## ${date}`;
7468
7477
  const entry = `- ${line}`;
7469
- const trimmed = existing.trim();
7478
+ const trimmed = existing.replace(/^/, "").replace(/\r\n/g, "\n").trim();
7470
7479
  if (trimmed === "") {
7471
7480
  return `# Log
7472
7481
 
@@ -7501,6 +7510,7 @@ var init_bundle = __esm({
7501
7510
  var io_exports = {};
7502
7511
  __export(io_exports, {
7503
7512
  DEFAULT_BUNDLE_DIR: () => DEFAULT_BUNDLE_DIR,
7513
+ collectSourceLinkBases: () => collectSourceLinkBases,
7504
7514
  findRepoRoot: () => findRepoRoot,
7505
7515
  loadBundle: () => loadBundle,
7506
7516
  resolveArticlePath: () => resolveArticlePath,
@@ -7529,6 +7539,12 @@ function resolveBundleDirFromRoots(rootUris, fallback) {
7529
7539
  }
7530
7540
  return dirs.find((dir) => existsSync18(dir)) ?? dirs[0] ?? fallback;
7531
7541
  }
7542
+ function collectSourceLinkBases(dir) {
7543
+ const bundle = loadBundle(dir);
7544
+ return bundle.catalog.map(
7545
+ (entry) => entry.resource ?? resolveArticlePath(dir, entry.file)
7546
+ );
7547
+ }
7532
7548
  function resolveArticlePath(dir, file) {
7533
7549
  if (file.includes("/") || file.includes("\\") || file.includes("..")) {
7534
7550
  throw new Error(`invalid article file name: ${file}`);
@@ -10725,7 +10741,7 @@ async function readWebLink(url) {
10725
10741
  redirect: "manual",
10726
10742
  signal: controller.signal,
10727
10743
  headers: {
10728
- "User-Agent": "ZAM-Content-Studio/0.14.0"
10744
+ "User-Agent": "ZAM-Content-Studio/0.15.1"
10729
10745
  }
10730
10746
  });
10731
10747
  if (res.status >= 300 && res.status < 400) {
@@ -32381,7 +32397,12 @@ bridgeCommand.command("list-tokens").description(
32381
32397
  ).option("--domain <domain>", "Filter by exact domain").option(
32382
32398
  "--domain-prefix <prefix>",
32383
32399
  "Filter by domain prefix (e.g. company-team) \u2014 uses / separator for hierarchy"
32384
- ).option("--knowledge-context <context>", "Filter by knowledge context").action(async (opts) => {
32400
+ ).option("--knowledge-context <context>", "Filter by knowledge context").option(
32401
+ "--source-link-base <base>",
32402
+ "Filter by source-link base (exact or '<base>#<anchor>', as written by OKF imports); repeatable",
32403
+ (value, previous) => [...previous, value],
32404
+ []
32405
+ ).action(async (opts) => {
32385
32406
  await withDb2(async (db) => {
32386
32407
  const userId = opts.user ? await resolveUser(opts, db, { json: true }) : void 0;
32387
32408
  const listOpts = {};
@@ -32389,6 +32410,8 @@ bridgeCommand.command("list-tokens").description(
32389
32410
  if (opts.domainPrefix) listOpts.domainPrefix = opts.domainPrefix;
32390
32411
  if (opts.knowledgeContext)
32391
32412
  listOpts.knowledgeContext = opts.knowledgeContext;
32413
+ if (opts.sourceLinkBase.length)
32414
+ listOpts.sourceLinkBases = opts.sourceLinkBase;
32392
32415
  const tokens = await listTokens(
32393
32416
  db,
32394
32417
  Object.keys(listOpts).length ? listOpts : void 0