@c4a/context-cli 0.5.38-beta.2 → 0.5.38-beta.3

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 (2) hide show
  1. package/cli.js +66 -16
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -51664,12 +51664,34 @@ function isMeaningfulTerm(term) {
51664
51664
  return compacted.length >= 4;
51665
51665
  }
51666
51666
  function uniqueTerms(node3) {
51667
- return [...new Set([node3.slug, node3.title, ...node3.aliases ?? []].filter((term) => typeof term === "string").map((term) => term.trim()).filter(isMeaningfulTerm))];
51667
+ const out2 = [];
51668
+ const seen = new Set;
51669
+ const push2 = (kind, term) => {
51670
+ if (typeof term !== "string")
51671
+ return;
51672
+ const value = term.trim();
51673
+ if (!isMeaningfulTerm(value))
51674
+ return;
51675
+ const key = `${kind}:${value}`;
51676
+ if (seen.has(key))
51677
+ return;
51678
+ seen.add(key);
51679
+ out2.push({ value, kind });
51680
+ };
51681
+ push2("slug", node3.slug);
51682
+ push2("title", node3.title);
51683
+ for (const alias of node3.aliases ?? [])
51684
+ push2("alias", alias);
51685
+ return out2;
51668
51686
  }
51669
51687
  function containsAsciiLikeTerm(text5, term) {
51670
51688
  const pattern = new RegExp(`(^|${ASCII_BOUNDARY})${escapeRegExp(term.toLowerCase())}($|${ASCII_BOUNDARY})`, "iu");
51671
51689
  return pattern.test(text5);
51672
51690
  }
51691
+ function containsAsciiLikeNameTerm(text5, term) {
51692
+ const pattern = new RegExp(`(^|${ASCII_NAME_BOUNDARY})${escapeRegExp(term.toLowerCase())}($|${ASCII_NAME_BOUNDARY})`, "iu");
51693
+ return pattern.test(text5);
51694
+ }
51673
51695
  function containsCjkTerm(text5, term) {
51674
51696
  const normalized = term.toLowerCase();
51675
51697
  let index2 = text5.indexOf(normalized);
@@ -51692,16 +51714,35 @@ function containsStrongTerm(text5, compactText, term) {
51692
51714
  const compacted = compact(normalized);
51693
51715
  return compacted.length >= 6 && compactText.includes(compacted);
51694
51716
  }
51717
+ function containsTerm(text5, compactText, term) {
51718
+ if (term.kind === "slug")
51719
+ return containsStrongTerm(text5, compactText, term.value);
51720
+ const normalized = term.value.normalize("NFKC").toLowerCase();
51721
+ if (CJK_RE2.test(normalized))
51722
+ return containsCjkTerm(text5, normalized);
51723
+ return containsAsciiLikeNameTerm(text5, normalized);
51724
+ }
51725
+ function currentCodePackage(input) {
51726
+ return input.currentCodePackage ?? input.knownNodes.find((node3) => node3.slug === input.currentNodeSlug)?.codePackage;
51727
+ }
51728
+ function canInferFromTerm(input) {
51729
+ if (input.term.kind === "slug")
51730
+ return true;
51731
+ if (input.currentCodePackage === undefined || input.targetCodePackage === undefined)
51732
+ return true;
51733
+ return input.currentCodePackage === input.targetCodePackage;
51734
+ }
51695
51735
  function inferRefersToNodes(input) {
51696
51736
  const existing = input.existing ?? [];
51697
51737
  const output = [...existing];
51698
51738
  const seen = new Set(output);
51699
51739
  const text5 = input.text.normalize("NFKC").toLowerCase();
51700
51740
  const compactText = compact(input.text);
51741
+ const currentPackage = currentCodePackage(input);
51701
51742
  for (const node3 of input.knownNodes) {
51702
51743
  if (node3.slug === input.currentNodeSlug || seen.has(node3.slug))
51703
51744
  continue;
51704
- if (uniqueTerms(node3).some((term) => containsStrongTerm(text5, compactText, term))) {
51745
+ if (uniqueTerms(node3).some((term) => canInferFromTerm({ term, currentCodePackage: currentPackage, targetCodePackage: node3.codePackage }) && containsTerm(text5, compactText, term))) {
51705
51746
  output.push(node3.slug);
51706
51747
  seen.add(node3.slug);
51707
51748
  }
@@ -51719,7 +51760,8 @@ async function collectKnownRefersToNodes(ctxDir) {
51719
51760
  bySlug.set(node3.parsed.node.id, {
51720
51761
  slug: node3.parsed.node.id,
51721
51762
  title: node3.parsed.node.title,
51722
- aliases: node3.parsed.node.aliases ?? []
51763
+ aliases: node3.parsed.node.aliases ?? [],
51764
+ ...node3.parsed.node.code_package !== undefined ? { codePackage: node3.parsed.node.code_package } : {}
51723
51765
  });
51724
51766
  }
51725
51767
  let activeSources = new Set;
@@ -51738,7 +51780,7 @@ async function collectKnownRefersToNodes(ctxDir) {
51738
51780
  }
51739
51781
  return [...bySlug.values()];
51740
51782
  }
51741
- var ASCII_BOUNDARY = "[^\\p{Letter}\\p{Number}_]", CJK_RE2;
51783
+ var ASCII_BOUNDARY = "[^\\p{Letter}\\p{Number}_]", ASCII_NAME_BOUNDARY = "[^\\p{Letter}\\p{Number}_/-]", CJK_RE2;
51742
51784
  var init_refersToInference = __esm(() => {
51743
51785
  init_alignPlan();
51744
51786
  init_sources();
@@ -58412,11 +58454,12 @@ function sectionText(section) {
58412
58454
  return [section.summary, section.content, section.detail].filter((value) => typeof value === "string").join(`
58413
58455
  `);
58414
58456
  }
58415
- async function withInferredRefersToNodes(ctxDir, nodeSlug, input) {
58457
+ async function withInferredRefersToNodes(ctxDir, nodeSlug, currentCodePackage2, input) {
58416
58458
  const inferred = inferRefersToNodes({
58417
58459
  text: [input.summary, input.content, input.detail].filter((value) => typeof value === "string").join(`
58418
58460
  `),
58419
58461
  currentNodeSlug: nodeSlug,
58462
+ currentCodePackage: currentCodePackage2,
58420
58463
  knownNodes: await collectKnownRefersToNodes(ctxDir),
58421
58464
  existing: input.refers_to_nodes
58422
58465
  });
@@ -58424,7 +58467,7 @@ async function withInferredRefersToNodes(ctxDir, nodeSlug, input) {
58424
58467
  }
58425
58468
  async function mdriveSectionAdd(input) {
58426
58469
  const located = await locateNode(input.ctxDir, input.nodeSlug);
58427
- const sectionInput = await withInferredRefersToNodes(input.ctxDir, input.nodeSlug, input.input);
58470
+ const sectionInput = await withInferredRefersToNodes(input.ctxDir, input.nodeSlug, located.parsed.node.code_package, input.input);
58428
58471
  const section = createSection(input.nodeSlug, sectionInput, nextSectionId(located.parsed.sections), located.parsed.node.type);
58429
58472
  reassignSections(located.parsed, [...located.parsed.sections, section]);
58430
58473
  await atomicRewriteRootFile(located.filePath, located.root);
@@ -58515,6 +58558,7 @@ async function mdriveSectionUpdate(input) {
58515
58558
  const inferred = inferRefersToNodes({
58516
58559
  text: sectionText(section),
58517
58560
  currentNodeSlug: input.nodeSlug,
58561
+ currentCodePackage: located.parsed.node.code_package,
58518
58562
  knownNodes: await collectKnownRefersToNodes(input.ctxDir),
58519
58563
  existing: section.refers_to_nodes
58520
58564
  });
@@ -58550,7 +58594,7 @@ async function mdriveSectionSupersede(input) {
58550
58594
  const oldSection = findSection(input.nodeSlug, located.parsed, input.oldSectionId);
58551
58595
  oldSection.status = SectionStatus.deprecated;
58552
58596
  const nextId = nextSectionId(located.parsed.sections);
58553
- const sectionInput = await withInferredRefersToNodes(input.ctxDir, input.nodeSlug, input.input);
58597
+ const sectionInput = await withInferredRefersToNodes(input.ctxDir, input.nodeSlug, located.parsed.node.code_package, input.input);
58554
58598
  const added = createSection(input.nodeSlug, sectionInput, nextId, located.parsed.node.type);
58555
58599
  added.relations = [
58556
58600
  ...added.relations ?? [],
@@ -98529,6 +98573,7 @@ function inferredRefersToNodes(input) {
98529
98573
  const inferred = inferRefersToNodes({
98530
98574
  text: input.text,
98531
98575
  currentNodeSlug: input.nodeSlug,
98576
+ currentCodePackage: input.currentCodePackage,
98532
98577
  knownNodes: input.knownNodes,
98533
98578
  existing: input.existing
98534
98579
  });
@@ -98549,6 +98594,7 @@ function createProjectionSection(input) {
98549
98594
  const inferred = inferredRefersToNodes({
98550
98595
  knownNodes: input.knownNodes,
98551
98596
  nodeSlug: input.row.node_slug,
98597
+ currentCodePackage: input.node.parsed.node.code_package,
98552
98598
  text: sectionText2(section)
98553
98599
  });
98554
98600
  if (inferred !== undefined)
@@ -98582,15 +98628,19 @@ function updateProjectionSection(input) {
98582
98628
  input.section.status = SectionStatus.active;
98583
98629
  changed = true;
98584
98630
  }
98585
- if (contentChanged) {
98586
- const inferred = inferredRefersToNodes({
98587
- knownNodes: input.knownNodes,
98588
- nodeSlug: input.row.node_slug,
98589
- text: sectionText2(input.section),
98590
- existing: input.section.refers_to_nodes
98591
- });
98592
- if (inferred !== undefined)
98631
+ const inferred = inferredRefersToNodes({
98632
+ knownNodes: input.knownNodes,
98633
+ nodeSlug: input.row.node_slug,
98634
+ currentCodePackage: input.node.parsed.node.code_package,
98635
+ text: sectionText2(input.section)
98636
+ });
98637
+ if (JSON.stringify(input.section.refers_to_nodes ?? undefined) !== JSON.stringify(inferred)) {
98638
+ if (inferred === undefined) {
98639
+ delete input.section.refers_to_nodes;
98640
+ } else {
98593
98641
  input.section.refers_to_nodes = inferred;
98642
+ }
98643
+ changed = true;
98594
98644
  }
98595
98645
  const issues = validateSection(input.section);
98596
98646
  if (issues.length > 0) {
@@ -98833,7 +98883,7 @@ function applyProjectableRows(input) {
98833
98883
  input.touchedNodes.add(node3);
98834
98884
  input.touchedFiles.add(node3.filePath);
98835
98885
  added += 1;
98836
- } else if (updateProjectionSection({ section: current.section, row, sourceRef, knownNodes: input.knownNodes })) {
98886
+ } else if (updateProjectionSection({ section: current.section, node: node3, row, sourceRef, knownNodes: input.knownNodes })) {
98837
98887
  input.touchedNodes.add(node3);
98838
98888
  input.touchedFiles.add(node3.filePath);
98839
98889
  updated += 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4a/context-cli",
3
- "version": "0.5.38-beta.2",
3
+ "version": "0.5.38-beta.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "context": "./cli.js"