@kaddo/cli 3.129.0 → 3.129.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.
Files changed (3) hide show
  1. package/dist/core.js +133 -133
  2. package/dist/index.js +133 -133
  3. package/package.json +1 -1
package/dist/core.js CHANGED
@@ -10454,101 +10454,83 @@ function relFromDir(dir, filePath) {
10454
10454
  function sha256(content) {
10455
10455
  return createHash2("sha256").update(content, "utf-8").digest("hex");
10456
10456
  }
10457
- var GENERIC_HEADINGS = /* @__PURE__ */ new Set([
10458
- "purpose",
10459
- "proposito",
10460
- "prop\xF3sito",
10461
- "intent",
10462
- "goal",
10463
- "objetivo",
10464
- "summary",
10465
- "resumen",
10466
- "overview",
10467
- "context",
10468
- "contexto",
10469
- "scope",
10470
- "alcance",
10471
- "out of scope",
10472
- "fuera de alcance",
10473
- "acceptance criteria",
10474
- "criterios de aceptacion",
10475
- "criterios de aceptaci\xF3n",
10476
- "validation",
10477
- "validation scenarios",
10478
- "validacion",
10479
- "validaci\xF3n",
10480
- "escenarios de validacion",
10481
- "escenarios de validaci\xF3n",
10482
- "notes",
10483
- "notas",
10484
- "references",
10485
- "referencias",
10486
- "examples",
10487
- "ejemplos",
10488
- "learning",
10489
- "learnings",
10490
- "aprendizaje",
10491
- "aprendizajes",
10492
- // Work Item template sections
10493
- "problem",
10494
- "problema",
10495
- "expected result",
10496
- "resultado esperado",
10497
- "refinement",
10498
- "refinamiento",
10499
- "implementation guidance",
10500
- "guia de implementacion",
10501
- "gu\xEDa de implementaci\xF3n",
10502
- "definition of done",
10503
- "definicion de hecho",
10504
- "definici\xF3n de hecho",
10505
- "commit gate",
10506
- "future evolution",
10507
- "evolucion futura",
10508
- "evoluci\xF3n futura",
10509
- "guiding principle",
10510
- "principio rector",
10511
- "open questions",
10512
- "preguntas abiertas",
10513
- "dependencies",
10514
- "dependencias",
10515
- "conceptual model",
10516
- "goal"
10517
- ]);
10518
- var RULE_KEYWORDS = [
10519
- "siempre",
10520
- "nunca",
10521
- "debe",
10522
- "deben",
10523
- "requiere",
10524
- "requieren",
10525
- "invariante",
10526
- "restriccion",
10527
- "restricci\xF3n",
10528
- "regla",
10529
- "obligatorio",
10530
- "must",
10531
- "always",
10532
- "never",
10533
- "require",
10534
- "requires",
10535
- "constraint",
10536
- "invariant",
10537
- "rule"
10538
- ];
10539
- function normalizeHeading(h) {
10540
- return h.trim().toLowerCase().replace(/\s+/g, " ");
10541
- }
10542
- function distinctiveHeadings(body) {
10543
- const out = [];
10544
- for (const line of body.split(/\r?\n/)) {
10545
- const m = line.match(/^#{2,3}\s+(.+?)\s*$/);
10546
- if (!m) continue;
10547
- const norm = normalizeHeading(m[1]);
10548
- if (!norm || GENERIC_HEADINGS.has(norm)) continue;
10549
- out.push(norm);
10457
+ var SHINGLE_SIZE = 6;
10458
+ var MIN_SHARED_RUN = 6;
10459
+ function contentWords(body) {
10460
+ const words = [];
10461
+ let inFence = false;
10462
+ for (const raw of body.split(/\r?\n/)) {
10463
+ const t = raw.trim();
10464
+ if (/^```/.test(t)) {
10465
+ inFence = !inFence;
10466
+ continue;
10467
+ }
10468
+ if (inFence) continue;
10469
+ if (/^#{1,6}\s/.test(t)) continue;
10470
+ if (/^>/.test(t)) continue;
10471
+ const text2 = t.replace(/^([-*+]\s+|\d+\.\s+)/, "");
10472
+ const matched = text2.toLowerCase().match(/[a-záéíóúñü0-9]+/gi);
10473
+ if (matched) words.push(...matched);
10474
+ }
10475
+ return words;
10476
+ }
10477
+ function buildShingles(body) {
10478
+ const words = contentWords(body);
10479
+ const keys = [];
10480
+ const set = /* @__PURE__ */ new Set();
10481
+ for (let i = 0; i + SHINGLE_SIZE <= words.length; i++) {
10482
+ const key = words.slice(i, i + SHINGLE_SIZE).join(" ");
10483
+ keys.push(key);
10484
+ set.add(key);
10485
+ }
10486
+ return { words, keys, set };
10487
+ }
10488
+ function longestSharedRun(a, b) {
10489
+ let best = 0;
10490
+ let bestStart = -1;
10491
+ let run = 0;
10492
+ let runStart = 0;
10493
+ for (let i = 0; i < a.keys.length; i++) {
10494
+ if (b.set.has(a.keys[i])) {
10495
+ if (run === 0) runStart = i;
10496
+ run += 1;
10497
+ if (run > best) {
10498
+ best = run;
10499
+ bestStart = runStart;
10500
+ }
10501
+ } else {
10502
+ run = 0;
10503
+ }
10504
+ }
10505
+ if (best === 0) return { length: 0, snippet: "" };
10506
+ const snippet = a.words.slice(bestStart, bestStart + SHINGLE_SIZE + best - 1).join(" ");
10507
+ return { length: best, snippet };
10508
+ }
10509
+ var NORMATIVE_RE = /(^|[^a-záéíóúñü])(must|should|shall|debe[ns]?|deber[ií]a[ns]?|se\s+debe|hay\s+que|requiere[ns]?|require[sd]?|no\s+debe|invariant[e]?|invariants|restricci[oó]n|constraint|regla|obligatori[oa])([^a-záéíóúñü]|$)/i;
10510
+ var PAST_RESULT_RE = /(compil[aoeéó]\w*|compiled|benchmark\w*|passed|succeed\w*|succeeded|ran\s+successfully|ejecut\w*|resultad\w*|crates?\b|ns\/op|µs\b|throughput|latenc\w*|baseline|measured|medid\w*|\d+\s*%|\bx\d|faster|slower)/i;
10511
+ var TEST_RE = /(\btest\w*|\bpruebas?\b|coverage|cobertura|verde[s]?|green\b|assert\w*)/i;
10512
+ var BENCH_RE = /(benchmark\w*|ns\/op|µs\b|throughput|latenc\w*|ops\/s|\d+\s*%|faster|slower|baseline)/i;
10513
+ var EXPERIMENT_RE = /(experiment\w*|experiment[oa]\w*|prototyp\w*|prototip\w*|spike\b|probamos|probé|intentamos)/i;
10514
+ function splitSentences(text2) {
10515
+ return text2.replace(/\s+/g, " ").split(/(?<=[.!?;])\s+/).map((s) => s.trim()).filter(Boolean);
10516
+ }
10517
+ function classifyLearningSentence(sentence) {
10518
+ const s = sentence.trim();
10519
+ if (!s) return "none";
10520
+ const normative = NORMATIVE_RE.test(s);
10521
+ const pastResult = PAST_RESULT_RE.test(s);
10522
+ if (normative && !pastResult) return "durable-rule";
10523
+ if (BENCH_RE.test(s)) return "benchmark-evidence";
10524
+ if (pastResult) return "historical-result";
10525
+ if (TEST_RE.test(s)) return "test-observation";
10526
+ if (EXPERIMENT_RE.test(s)) return "experimental-result";
10527
+ return "none";
10528
+ }
10529
+ function firstRuleFragment(learning) {
10530
+ for (const sentence of splitSentences(learning)) {
10531
+ if (classifyLearningSentence(sentence) === "durable-rule") return sentence;
10550
10532
  }
10551
- return [...new Set(out)];
10533
+ return null;
10552
10534
  }
10553
10535
  function sectionBody(body, titles) {
10554
10536
  const lines = body.split(/\r?\n/);
@@ -10632,32 +10614,33 @@ function buildConsolidationPlan(dir, opts = {}) {
10632
10614
  requires_semantic_review: false
10633
10615
  });
10634
10616
  }
10635
- const canonical = scoped.filter(
10636
- (la) => la.layer !== null && !isWorkItem(la) && la.artifact.type !== "roadmap"
10637
- );
10638
- const byHeading = /* @__PURE__ */ new Map();
10639
- for (const la of canonical) {
10640
- for (const h of distinctiveHeadings(la.body)) {
10641
- const arr = byHeading.get(h) ?? [];
10617
+ const comparable = scoped.filter(isComparableKnowledge);
10618
+ const shingleIndex = /* @__PURE__ */ new Map();
10619
+ const shinglesByRel = /* @__PURE__ */ new Map();
10620
+ for (const la of comparable) {
10621
+ const shingles = buildShingles(la.body);
10622
+ shinglesByRel.set(la.rel, shingles);
10623
+ for (const key of shingles.set) {
10624
+ const arr = shingleIndex.get(key) ?? [];
10642
10625
  arr.push(la);
10643
- byHeading.set(h, arr);
10626
+ shingleIndex.set(key, arr);
10644
10627
  }
10645
10628
  }
10646
- const pairHeadings = /* @__PURE__ */ new Map();
10647
- for (const [heading, arts] of byHeading) {
10629
+ const candidatePairs = /* @__PURE__ */ new Map();
10630
+ for (const arts of shingleIndex.values()) {
10648
10631
  if (arts.length < 2) continue;
10649
10632
  for (let i = 0; i < arts.length; i++) {
10650
10633
  for (let j = i + 1; j < arts.length; j++) {
10651
10634
  if (arts[i].rel === arts[j].rel) continue;
10652
10635
  const key = [arts[i].rel, arts[j].rel].sort().join("||");
10653
- const entry = pairHeadings.get(key) ?? { a: arts[i], b: arts[j], shared: /* @__PURE__ */ new Set() };
10654
- entry.shared.add(heading);
10655
- pairHeadings.set(key, entry);
10636
+ if (!candidatePairs.has(key)) candidatePairs.set(key, { a: arts[i], b: arts[j] });
10656
10637
  }
10657
10638
  }
10658
10639
  }
10659
- for (const { a, b, shared } of pairHeadings.values()) {
10660
- if (shared.size < 2) continue;
10640
+ for (const { a, b } of candidatePairs.values()) {
10641
+ const run = longestSharedRun(shinglesByRel.get(a.rel), shinglesByRel.get(b.rel));
10642
+ if (run.length < MIN_SHARED_RUN) continue;
10643
+ const passageWords = SHINGLE_SIZE + run.length - 1;
10661
10644
  opportunities.push({
10662
10645
  id: stableOpportunityId("knowledge_redundancy", [label(a), label(b)]),
10663
10646
  category: "knowledge_redundancy",
@@ -10666,10 +10649,12 @@ function buildConsolidationPlan(dir, opts = {}) {
10666
10649
  title: `Possible overlapping content between ${label(a)} and ${label(b)}`,
10667
10650
  source_artifacts: [label(a), label(b)],
10668
10651
  target_artifacts: [label(a), label(b)],
10669
- evidence: [`Both artifacts declare the sections: ${[...shared].sort().join(", ")}.`],
10670
- rationale: "Shared section titles are a hint of potential overlap, NOT proof of duplication. Two documents can legitimately address the same topic from different layers/responsibilities.",
10652
+ evidence: [
10653
+ `A ${passageWords}-word passage appears verbatim in both artifacts: "${redactSecrets2(run.snippet)}".`
10654
+ ],
10655
+ rationale: "A verbatim shared passage is a hint of potential duplication, NOT proof. Two documents can legitimately restate context from different layers/responsibilities; shared template structure alone was NOT used.",
10671
10656
  possible_impact: "If genuinely duplicated, the same fact can drift out of sync across files.",
10672
- suggested_action: "Semantic review: compare the sections; if one restates the other, keep a single reference location and link the rest. Preserve layer separation.",
10657
+ suggested_action: "Semantic review: compare the overlapping passage; if one restates the other, keep a single reference location and link the rest. Preserve layer separation.",
10673
10658
  requires_semantic_review: true
10674
10659
  });
10675
10660
  }
@@ -10677,7 +10662,8 @@ function buildConsolidationPlan(dir, opts = {}) {
10677
10662
  if (!isCompletedWorkItem(la)) continue;
10678
10663
  const learning = sectionBody(la.body, ["Learning", "Aprendizaje", "Aprendizajes", "Learnings"]);
10679
10664
  if (!learning) continue;
10680
- if (!looksLikeDurableRule(learning)) continue;
10665
+ const ruleFragment = firstRuleFragment(learning);
10666
+ if (!ruleFragment) continue;
10681
10667
  opportunities.push({
10682
10668
  id: stableOpportunityId("unincorporated_learning", [label(la)]),
10683
10669
  category: "unincorporated_learning",
@@ -10685,16 +10671,18 @@ function buildConsolidationPlan(dir, opts = {}) {
10685
10671
  confidence: "requires-review",
10686
10672
  title: `${label(la)} captured a learning that may belong in current knowledge`,
10687
10673
  source_artifacts: [label(la)],
10688
- target_artifacts: ["knowledge/tech/codebase.md"],
10689
- evidence: [`Completed Work Item records a rule-like learning: "${firstSentence(learning)}"`],
10690
- rationale: "A learning phrased as a durable rule MAY represent live technical knowledge not yet reflected in Tech Knowledge. This is a candidate, not a confirmed gap.",
10674
+ target_artifacts: [],
10675
+ // unresolved — determined in semantic review (never invent a destination)
10676
+ evidence: [`Completed Work Item records a rule-like learning (heuristic classification): "${redactSecrets2(ruleFragment)}"`],
10677
+ rationale: "A sentence phrased as a durable rule MAY represent live technical knowledge not yet reflected in current knowledge. The rule/result distinction is a heuristic, not a verified conclusion \u2014 this is a candidate, not a confirmed gap.",
10691
10678
  possible_impact: "A relevant constraint stays buried in delivery history instead of informing current work.",
10692
- suggested_action: "Semantic review: decide whether this learning is a live rule; if so, incorporate it into the right Tech artifact WITH a reference back to the Work Item. Do not delete or summarize the Work Item.",
10679
+ suggested_action: "Semantic review: confirm whether this is a live rule and determine the right destination artifact; if so, incorporate it WITH a reference back to the Work Item. Do not delete or summarize the Work Item.",
10693
10680
  requires_semantic_review: true
10694
10681
  });
10695
10682
  }
10696
10683
  const weakByFolder = /* @__PURE__ */ new Map();
10697
10684
  for (const la of scoped) {
10685
+ if (!isConsolidatableKnowledge(la)) continue;
10698
10686
  const quality = safeQuality(dir, la.rel);
10699
10687
  if (quality === "placeholder" || quality === "weak") {
10700
10688
  opportunities.push({
@@ -10705,11 +10693,11 @@ function buildConsolidationPlan(dir, opts = {}) {
10705
10693
  title: `${label(la)} is ${quality} and may need consolidation or expansion`,
10706
10694
  source_artifacts: [label(la)],
10707
10695
  target_artifacts: [label(la)],
10708
- evidence: [`Artifact quality analysis classifies this artifact as "${quality}".`],
10709
- rationale: "Low-signal artifacts reduce retrieval quality. This is an observed quality signal, not a judgement that the content is wrong.",
10696
+ evidence: [`Artifact quality analysis classifies this canonical knowledge artifact as "${quality}".`],
10697
+ rationale: "Observed: the quality heuristic rates this artifact low-signal. Whether it should be expanded, merged or cross-referenced is a judgement that needs semantic review \u2014 the quality signal alone does not decide it.",
10710
10698
  possible_impact: "Readers must open more files to assemble a complete picture.",
10711
- suggested_action: "Review whether to expand, merge into a stronger artifact, or cross-reference it.",
10712
- requires_semantic_review: false
10699
+ suggested_action: "Semantic review: decide whether to expand, merge into a stronger artifact, or cross-reference it.",
10700
+ requires_semantic_review: true
10713
10701
  });
10714
10702
  const folder = la.rel.split("/").slice(0, -1).join("/");
10715
10703
  const arr = weakByFolder.get(folder) ?? [];
@@ -10724,11 +10712,11 @@ function buildConsolidationPlan(dir, opts = {}) {
10724
10712
  category: "knowledge_fragmentation",
10725
10713
  classification: "suggested",
10726
10714
  confidence: "requires-review",
10727
- title: `${folder}/ holds ${arts.length} low-signal artifacts \u2014 possible fragmentation`,
10715
+ title: `${folder}/ holds ${arts.length} low-signal canonical artifacts \u2014 possible fragmentation`,
10728
10716
  source_artifacts: arts.map((a) => label(a)),
10729
10717
  target_artifacts: [folder],
10730
- evidence: [`${arts.length} placeholder/weak artifacts in the same folder: ${arts.map((a) => a.rel.split("/").pop()).join(", ")}.`],
10731
- rationale: "Several thin artifacts in one folder MAY be easier to consume if consolidated or cross-linked. Consolidation must preserve each distinct responsibility.",
10718
+ evidence: [`${arts.length} placeholder/weak canonical knowledge artifacts in the same folder: ${arts.map((a) => a.rel.split("/").pop()).join(", ")}.`],
10719
+ rationale: "Several thin canonical artifacts in one folder MAY be easier to consume if consolidated or cross-linked. Consolidation must preserve each distinct responsibility; Work Items and generated/lifecycle artifacts are not considered here.",
10732
10720
  possible_impact: "Related knowledge is spread across too many files to follow.",
10733
10721
  suggested_action: "Semantic review: evaluate whether cross-references or a consolidation would add clarity. Do not merge by file count alone.",
10734
10722
  requires_semantic_review: true
@@ -10833,7 +10821,9 @@ function renderConsolidationMarkdown(plan) {
10833
10821
  lines.push(`- Classification: **${o.classification}**${o.requires_semantic_review ? " (requires semantic review)" : ""}`);
10834
10822
  lines.push(`- Confidence: ${o.confidence}`);
10835
10823
  lines.push(`- Source: ${o.source_artifacts.join(", ") || "\u2014"}`);
10836
- lines.push(`- Suggested target: ${o.target_artifacts.join(", ") || "\u2014"}`);
10824
+ lines.push(
10825
+ `- Suggested target: ${o.target_artifacts.length > 0 ? o.target_artifacts.join(", ") : "(unresolved \u2014 to be determined in semantic review)"}`
10826
+ );
10837
10827
  lines.push(`- Evidence:`);
10838
10828
  for (const e of o.evidence) lines.push(` - ${e}`);
10839
10829
  lines.push(`- Rationale: ${o.rationale}`);
@@ -10858,15 +10848,25 @@ function isCompletedWorkItem(la) {
10858
10848
  const p = toPosix6(la.artifact.filePath);
10859
10849
  return p.includes("/delivery/work-items/completed/") || isWorkItem(la) && la.artifact.status === "completed";
10860
10850
  }
10861
- function looksLikeDurableRule(text2) {
10862
- const lower = text2.toLowerCase();
10863
- return RULE_KEYWORDS.some((k) => new RegExp(`(^|[^a-z\xE1\xE9\xED\xF3\xFA\xF1])${k}([^a-z\xE1\xE9\xED\xF3\xFA\xF1]|$)`, "i").test(lower));
10851
+ function isScaffolding(la) {
10852
+ const p = toPosix6(la.artifact.filePath);
10853
+ return p.includes(`/${KNOWLEDGE5}/agents/`) || p.includes(`/${KNOWLEDGE5}/skills/`) || p.includes(`/${KNOWLEDGE5}/external/`) || la.artifact.type === "knowledge-capsule";
10854
+ }
10855
+ var NON_KNOWLEDGE_DOC_TYPES = /* @__PURE__ */ new Set([
10856
+ "roadmap",
10857
+ "initiative",
10858
+ "deprecation",
10859
+ "knowledge-capsule",
10860
+ "inventory",
10861
+ "project-resource"
10862
+ ]);
10863
+ function isComparableKnowledge(la) {
10864
+ return !isWorkItem(la) && la.artifact.type !== "roadmap" && !isScaffolding(la);
10864
10865
  }
10865
- function firstSentence(text2) {
10866
- const flat = text2.replace(/\s+/g, " ").trim();
10867
- const m = flat.match(/^(.{0,200}?[.!?])(\s|$)/);
10868
- const s = (m ? m[1] : flat).slice(0, 200);
10869
- return redactSecrets2(s.trim());
10866
+ function isConsolidatableKnowledge(la) {
10867
+ if (isWorkItem(la) || isScaffolding(la)) return false;
10868
+ if (NON_KNOWLEDGE_DOC_TYPES.has(la.artifact.type)) return false;
10869
+ return la.layer === "Business" || la.layer === "Product" || la.layer === "Tech";
10870
10870
  }
10871
10871
  var SECRET_TOKEN_PATTERNS = [
10872
10872
  /\bgh[pours]_[A-Za-z0-9]{16,}\b/g,
package/dist/index.js CHANGED
@@ -25961,101 +25961,83 @@ function relFromDir(dir, filePath) {
25961
25961
  function sha256(content) {
25962
25962
  return createHash2("sha256").update(content, "utf-8").digest("hex");
25963
25963
  }
25964
- var GENERIC_HEADINGS = /* @__PURE__ */ new Set([
25965
- "purpose",
25966
- "proposito",
25967
- "prop\xF3sito",
25968
- "intent",
25969
- "goal",
25970
- "objetivo",
25971
- "summary",
25972
- "resumen",
25973
- "overview",
25974
- "context",
25975
- "contexto",
25976
- "scope",
25977
- "alcance",
25978
- "out of scope",
25979
- "fuera de alcance",
25980
- "acceptance criteria",
25981
- "criterios de aceptacion",
25982
- "criterios de aceptaci\xF3n",
25983
- "validation",
25984
- "validation scenarios",
25985
- "validacion",
25986
- "validaci\xF3n",
25987
- "escenarios de validacion",
25988
- "escenarios de validaci\xF3n",
25989
- "notes",
25990
- "notas",
25991
- "references",
25992
- "referencias",
25993
- "examples",
25994
- "ejemplos",
25995
- "learning",
25996
- "learnings",
25997
- "aprendizaje",
25998
- "aprendizajes",
25999
- // Work Item template sections
26000
- "problem",
26001
- "problema",
26002
- "expected result",
26003
- "resultado esperado",
26004
- "refinement",
26005
- "refinamiento",
26006
- "implementation guidance",
26007
- "guia de implementacion",
26008
- "gu\xEDa de implementaci\xF3n",
26009
- "definition of done",
26010
- "definicion de hecho",
26011
- "definici\xF3n de hecho",
26012
- "commit gate",
26013
- "future evolution",
26014
- "evolucion futura",
26015
- "evoluci\xF3n futura",
26016
- "guiding principle",
26017
- "principio rector",
26018
- "open questions",
26019
- "preguntas abiertas",
26020
- "dependencies",
26021
- "dependencias",
26022
- "conceptual model",
26023
- "goal"
26024
- ]);
26025
- var RULE_KEYWORDS = [
26026
- "siempre",
26027
- "nunca",
26028
- "debe",
26029
- "deben",
26030
- "requiere",
26031
- "requieren",
26032
- "invariante",
26033
- "restriccion",
26034
- "restricci\xF3n",
26035
- "regla",
26036
- "obligatorio",
26037
- "must",
26038
- "always",
26039
- "never",
26040
- "require",
26041
- "requires",
26042
- "constraint",
26043
- "invariant",
26044
- "rule"
26045
- ];
26046
- function normalizeHeading(h) {
26047
- return h.trim().toLowerCase().replace(/\s+/g, " ");
26048
- }
26049
- function distinctiveHeadings(body) {
26050
- const out = [];
26051
- for (const line of body.split(/\r?\n/)) {
26052
- const m = line.match(/^#{2,3}\s+(.+?)\s*$/);
26053
- if (!m) continue;
26054
- const norm = normalizeHeading(m[1]);
26055
- if (!norm || GENERIC_HEADINGS.has(norm)) continue;
26056
- out.push(norm);
25964
+ var SHINGLE_SIZE = 6;
25965
+ var MIN_SHARED_RUN = 6;
25966
+ function contentWords(body) {
25967
+ const words = [];
25968
+ let inFence = false;
25969
+ for (const raw of body.split(/\r?\n/)) {
25970
+ const t = raw.trim();
25971
+ if (/^```/.test(t)) {
25972
+ inFence = !inFence;
25973
+ continue;
25974
+ }
25975
+ if (inFence) continue;
25976
+ if (/^#{1,6}\s/.test(t)) continue;
25977
+ if (/^>/.test(t)) continue;
25978
+ const text2 = t.replace(/^([-*+]\s+|\d+\.\s+)/, "");
25979
+ const matched = text2.toLowerCase().match(/[a-záéíóúñü0-9]+/gi);
25980
+ if (matched) words.push(...matched);
25981
+ }
25982
+ return words;
25983
+ }
25984
+ function buildShingles(body) {
25985
+ const words = contentWords(body);
25986
+ const keys = [];
25987
+ const set = /* @__PURE__ */ new Set();
25988
+ for (let i = 0; i + SHINGLE_SIZE <= words.length; i++) {
25989
+ const key = words.slice(i, i + SHINGLE_SIZE).join(" ");
25990
+ keys.push(key);
25991
+ set.add(key);
25992
+ }
25993
+ return { words, keys, set };
25994
+ }
25995
+ function longestSharedRun(a, b) {
25996
+ let best = 0;
25997
+ let bestStart = -1;
25998
+ let run = 0;
25999
+ let runStart = 0;
26000
+ for (let i = 0; i < a.keys.length; i++) {
26001
+ if (b.set.has(a.keys[i])) {
26002
+ if (run === 0) runStart = i;
26003
+ run += 1;
26004
+ if (run > best) {
26005
+ best = run;
26006
+ bestStart = runStart;
26007
+ }
26008
+ } else {
26009
+ run = 0;
26010
+ }
26011
+ }
26012
+ if (best === 0) return { length: 0, snippet: "" };
26013
+ const snippet = a.words.slice(bestStart, bestStart + SHINGLE_SIZE + best - 1).join(" ");
26014
+ return { length: best, snippet };
26015
+ }
26016
+ var NORMATIVE_RE = /(^|[^a-záéíóúñü])(must|should|shall|debe[ns]?|deber[ií]a[ns]?|se\s+debe|hay\s+que|requiere[ns]?|require[sd]?|no\s+debe|invariant[e]?|invariants|restricci[oó]n|constraint|regla|obligatori[oa])([^a-záéíóúñü]|$)/i;
26017
+ var PAST_RESULT_RE = /(compil[aoeéó]\w*|compiled|benchmark\w*|passed|succeed\w*|succeeded|ran\s+successfully|ejecut\w*|resultad\w*|crates?\b|ns\/op|µs\b|throughput|latenc\w*|baseline|measured|medid\w*|\d+\s*%|\bx\d|faster|slower)/i;
26018
+ var TEST_RE = /(\btest\w*|\bpruebas?\b|coverage|cobertura|verde[s]?|green\b|assert\w*)/i;
26019
+ var BENCH_RE = /(benchmark\w*|ns\/op|µs\b|throughput|latenc\w*|ops\/s|\d+\s*%|faster|slower|baseline)/i;
26020
+ var EXPERIMENT_RE = /(experiment\w*|experiment[oa]\w*|prototyp\w*|prototip\w*|spike\b|probamos|probé|intentamos)/i;
26021
+ function splitSentences(text2) {
26022
+ return text2.replace(/\s+/g, " ").split(/(?<=[.!?;])\s+/).map((s) => s.trim()).filter(Boolean);
26023
+ }
26024
+ function classifyLearningSentence(sentence) {
26025
+ const s = sentence.trim();
26026
+ if (!s) return "none";
26027
+ const normative = NORMATIVE_RE.test(s);
26028
+ const pastResult = PAST_RESULT_RE.test(s);
26029
+ if (normative && !pastResult) return "durable-rule";
26030
+ if (BENCH_RE.test(s)) return "benchmark-evidence";
26031
+ if (pastResult) return "historical-result";
26032
+ if (TEST_RE.test(s)) return "test-observation";
26033
+ if (EXPERIMENT_RE.test(s)) return "experimental-result";
26034
+ return "none";
26035
+ }
26036
+ function firstRuleFragment(learning) {
26037
+ for (const sentence of splitSentences(learning)) {
26038
+ if (classifyLearningSentence(sentence) === "durable-rule") return sentence;
26057
26039
  }
26058
- return [...new Set(out)];
26040
+ return null;
26059
26041
  }
26060
26042
  function sectionBody(body, titles) {
26061
26043
  const lines = body.split(/\r?\n/);
@@ -26139,32 +26121,33 @@ function buildConsolidationPlan(dir, opts = {}) {
26139
26121
  requires_semantic_review: false
26140
26122
  });
26141
26123
  }
26142
- const canonical = scoped.filter(
26143
- (la) => la.layer !== null && !isWorkItem(la) && la.artifact.type !== "roadmap"
26144
- );
26145
- const byHeading = /* @__PURE__ */ new Map();
26146
- for (const la of canonical) {
26147
- for (const h of distinctiveHeadings(la.body)) {
26148
- const arr = byHeading.get(h) ?? [];
26124
+ const comparable = scoped.filter(isComparableKnowledge);
26125
+ const shingleIndex = /* @__PURE__ */ new Map();
26126
+ const shinglesByRel = /* @__PURE__ */ new Map();
26127
+ for (const la of comparable) {
26128
+ const shingles = buildShingles(la.body);
26129
+ shinglesByRel.set(la.rel, shingles);
26130
+ for (const key of shingles.set) {
26131
+ const arr = shingleIndex.get(key) ?? [];
26149
26132
  arr.push(la);
26150
- byHeading.set(h, arr);
26133
+ shingleIndex.set(key, arr);
26151
26134
  }
26152
26135
  }
26153
- const pairHeadings = /* @__PURE__ */ new Map();
26154
- for (const [heading, arts] of byHeading) {
26136
+ const candidatePairs = /* @__PURE__ */ new Map();
26137
+ for (const arts of shingleIndex.values()) {
26155
26138
  if (arts.length < 2) continue;
26156
26139
  for (let i = 0; i < arts.length; i++) {
26157
26140
  for (let j = i + 1; j < arts.length; j++) {
26158
26141
  if (arts[i].rel === arts[j].rel) continue;
26159
26142
  const key = [arts[i].rel, arts[j].rel].sort().join("||");
26160
- const entry = pairHeadings.get(key) ?? { a: arts[i], b: arts[j], shared: /* @__PURE__ */ new Set() };
26161
- entry.shared.add(heading);
26162
- pairHeadings.set(key, entry);
26143
+ if (!candidatePairs.has(key)) candidatePairs.set(key, { a: arts[i], b: arts[j] });
26163
26144
  }
26164
26145
  }
26165
26146
  }
26166
- for (const { a, b, shared } of pairHeadings.values()) {
26167
- if (shared.size < 2) continue;
26147
+ for (const { a, b } of candidatePairs.values()) {
26148
+ const run = longestSharedRun(shinglesByRel.get(a.rel), shinglesByRel.get(b.rel));
26149
+ if (run.length < MIN_SHARED_RUN) continue;
26150
+ const passageWords = SHINGLE_SIZE + run.length - 1;
26168
26151
  opportunities.push({
26169
26152
  id: stableOpportunityId("knowledge_redundancy", [label(a), label(b)]),
26170
26153
  category: "knowledge_redundancy",
@@ -26173,10 +26156,12 @@ function buildConsolidationPlan(dir, opts = {}) {
26173
26156
  title: `Possible overlapping content between ${label(a)} and ${label(b)}`,
26174
26157
  source_artifacts: [label(a), label(b)],
26175
26158
  target_artifacts: [label(a), label(b)],
26176
- evidence: [`Both artifacts declare the sections: ${[...shared].sort().join(", ")}.`],
26177
- rationale: "Shared section titles are a hint of potential overlap, NOT proof of duplication. Two documents can legitimately address the same topic from different layers/responsibilities.",
26159
+ evidence: [
26160
+ `A ${passageWords}-word passage appears verbatim in both artifacts: "${redactSecrets2(run.snippet)}".`
26161
+ ],
26162
+ rationale: "A verbatim shared passage is a hint of potential duplication, NOT proof. Two documents can legitimately restate context from different layers/responsibilities; shared template structure alone was NOT used.",
26178
26163
  possible_impact: "If genuinely duplicated, the same fact can drift out of sync across files.",
26179
- suggested_action: "Semantic review: compare the sections; if one restates the other, keep a single reference location and link the rest. Preserve layer separation.",
26164
+ suggested_action: "Semantic review: compare the overlapping passage; if one restates the other, keep a single reference location and link the rest. Preserve layer separation.",
26180
26165
  requires_semantic_review: true
26181
26166
  });
26182
26167
  }
@@ -26184,7 +26169,8 @@ function buildConsolidationPlan(dir, opts = {}) {
26184
26169
  if (!isCompletedWorkItem(la)) continue;
26185
26170
  const learning = sectionBody(la.body, ["Learning", "Aprendizaje", "Aprendizajes", "Learnings"]);
26186
26171
  if (!learning) continue;
26187
- if (!looksLikeDurableRule(learning)) continue;
26172
+ const ruleFragment = firstRuleFragment(learning);
26173
+ if (!ruleFragment) continue;
26188
26174
  opportunities.push({
26189
26175
  id: stableOpportunityId("unincorporated_learning", [label(la)]),
26190
26176
  category: "unincorporated_learning",
@@ -26192,16 +26178,18 @@ function buildConsolidationPlan(dir, opts = {}) {
26192
26178
  confidence: "requires-review",
26193
26179
  title: `${label(la)} captured a learning that may belong in current knowledge`,
26194
26180
  source_artifacts: [label(la)],
26195
- target_artifacts: ["knowledge/tech/codebase.md"],
26196
- evidence: [`Completed Work Item records a rule-like learning: "${firstSentence(learning)}"`],
26197
- rationale: "A learning phrased as a durable rule MAY represent live technical knowledge not yet reflected in Tech Knowledge. This is a candidate, not a confirmed gap.",
26181
+ target_artifacts: [],
26182
+ // unresolved — determined in semantic review (never invent a destination)
26183
+ evidence: [`Completed Work Item records a rule-like learning (heuristic classification): "${redactSecrets2(ruleFragment)}"`],
26184
+ rationale: "A sentence phrased as a durable rule MAY represent live technical knowledge not yet reflected in current knowledge. The rule/result distinction is a heuristic, not a verified conclusion \u2014 this is a candidate, not a confirmed gap.",
26198
26185
  possible_impact: "A relevant constraint stays buried in delivery history instead of informing current work.",
26199
- suggested_action: "Semantic review: decide whether this learning is a live rule; if so, incorporate it into the right Tech artifact WITH a reference back to the Work Item. Do not delete or summarize the Work Item.",
26186
+ suggested_action: "Semantic review: confirm whether this is a live rule and determine the right destination artifact; if so, incorporate it WITH a reference back to the Work Item. Do not delete or summarize the Work Item.",
26200
26187
  requires_semantic_review: true
26201
26188
  });
26202
26189
  }
26203
26190
  const weakByFolder = /* @__PURE__ */ new Map();
26204
26191
  for (const la of scoped) {
26192
+ if (!isConsolidatableKnowledge(la)) continue;
26205
26193
  const quality = safeQuality(dir, la.rel);
26206
26194
  if (quality === "placeholder" || quality === "weak") {
26207
26195
  opportunities.push({
@@ -26212,11 +26200,11 @@ function buildConsolidationPlan(dir, opts = {}) {
26212
26200
  title: `${label(la)} is ${quality} and may need consolidation or expansion`,
26213
26201
  source_artifacts: [label(la)],
26214
26202
  target_artifacts: [label(la)],
26215
- evidence: [`Artifact quality analysis classifies this artifact as "${quality}".`],
26216
- rationale: "Low-signal artifacts reduce retrieval quality. This is an observed quality signal, not a judgement that the content is wrong.",
26203
+ evidence: [`Artifact quality analysis classifies this canonical knowledge artifact as "${quality}".`],
26204
+ rationale: "Observed: the quality heuristic rates this artifact low-signal. Whether it should be expanded, merged or cross-referenced is a judgement that needs semantic review \u2014 the quality signal alone does not decide it.",
26217
26205
  possible_impact: "Readers must open more files to assemble a complete picture.",
26218
- suggested_action: "Review whether to expand, merge into a stronger artifact, or cross-reference it.",
26219
- requires_semantic_review: false
26206
+ suggested_action: "Semantic review: decide whether to expand, merge into a stronger artifact, or cross-reference it.",
26207
+ requires_semantic_review: true
26220
26208
  });
26221
26209
  const folder = la.rel.split("/").slice(0, -1).join("/");
26222
26210
  const arr = weakByFolder.get(folder) ?? [];
@@ -26231,11 +26219,11 @@ function buildConsolidationPlan(dir, opts = {}) {
26231
26219
  category: "knowledge_fragmentation",
26232
26220
  classification: "suggested",
26233
26221
  confidence: "requires-review",
26234
- title: `${folder}/ holds ${arts.length} low-signal artifacts \u2014 possible fragmentation`,
26222
+ title: `${folder}/ holds ${arts.length} low-signal canonical artifacts \u2014 possible fragmentation`,
26235
26223
  source_artifacts: arts.map((a) => label(a)),
26236
26224
  target_artifacts: [folder],
26237
- evidence: [`${arts.length} placeholder/weak artifacts in the same folder: ${arts.map((a) => a.rel.split("/").pop()).join(", ")}.`],
26238
- rationale: "Several thin artifacts in one folder MAY be easier to consume if consolidated or cross-linked. Consolidation must preserve each distinct responsibility.",
26225
+ evidence: [`${arts.length} placeholder/weak canonical knowledge artifacts in the same folder: ${arts.map((a) => a.rel.split("/").pop()).join(", ")}.`],
26226
+ rationale: "Several thin canonical artifacts in one folder MAY be easier to consume if consolidated or cross-linked. Consolidation must preserve each distinct responsibility; Work Items and generated/lifecycle artifacts are not considered here.",
26239
26227
  possible_impact: "Related knowledge is spread across too many files to follow.",
26240
26228
  suggested_action: "Semantic review: evaluate whether cross-references or a consolidation would add clarity. Do not merge by file count alone.",
26241
26229
  requires_semantic_review: true
@@ -26327,7 +26315,9 @@ function renderConsolidationMarkdown(plan) {
26327
26315
  lines.push(`- Classification: **${o.classification}**${o.requires_semantic_review ? " (requires semantic review)" : ""}`);
26328
26316
  lines.push(`- Confidence: ${o.confidence}`);
26329
26317
  lines.push(`- Source: ${o.source_artifacts.join(", ") || "\u2014"}`);
26330
- lines.push(`- Suggested target: ${o.target_artifacts.join(", ") || "\u2014"}`);
26318
+ lines.push(
26319
+ `- Suggested target: ${o.target_artifacts.length > 0 ? o.target_artifacts.join(", ") : "(unresolved \u2014 to be determined in semantic review)"}`
26320
+ );
26331
26321
  lines.push(`- Evidence:`);
26332
26322
  for (const e of o.evidence) lines.push(` - ${e}`);
26333
26323
  lines.push(`- Rationale: ${o.rationale}`);
@@ -26352,15 +26342,25 @@ function isCompletedWorkItem(la) {
26352
26342
  const p = toPosix7(la.artifact.filePath);
26353
26343
  return p.includes("/delivery/work-items/completed/") || isWorkItem(la) && la.artifact.status === "completed";
26354
26344
  }
26355
- function looksLikeDurableRule(text2) {
26356
- const lower = text2.toLowerCase();
26357
- return RULE_KEYWORDS.some((k) => new RegExp(`(^|[^a-z\xE1\xE9\xED\xF3\xFA\xF1])${k}([^a-z\xE1\xE9\xED\xF3\xFA\xF1]|$)`, "i").test(lower));
26345
+ function isScaffolding(la) {
26346
+ const p = toPosix7(la.artifact.filePath);
26347
+ return p.includes(`/${KNOWLEDGE6}/agents/`) || p.includes(`/${KNOWLEDGE6}/skills/`) || p.includes(`/${KNOWLEDGE6}/external/`) || la.artifact.type === "knowledge-capsule";
26348
+ }
26349
+ var NON_KNOWLEDGE_DOC_TYPES = /* @__PURE__ */ new Set([
26350
+ "roadmap",
26351
+ "initiative",
26352
+ "deprecation",
26353
+ "knowledge-capsule",
26354
+ "inventory",
26355
+ "project-resource"
26356
+ ]);
26357
+ function isComparableKnowledge(la) {
26358
+ return !isWorkItem(la) && la.artifact.type !== "roadmap" && !isScaffolding(la);
26358
26359
  }
26359
- function firstSentence(text2) {
26360
- const flat = text2.replace(/\s+/g, " ").trim();
26361
- const m = flat.match(/^(.{0,200}?[.!?])(\s|$)/);
26362
- const s = (m ? m[1] : flat).slice(0, 200);
26363
- return redactSecrets2(s.trim());
26360
+ function isConsolidatableKnowledge(la) {
26361
+ if (isWorkItem(la) || isScaffolding(la)) return false;
26362
+ if (NON_KNOWLEDGE_DOC_TYPES.has(la.artifact.type)) return false;
26363
+ return la.layer === "Business" || la.layer === "Product" || la.layer === "Tech";
26364
26364
  }
26365
26365
  var SECRET_TOKEN_PATTERNS = [
26366
26366
  /\bgh[pours]_[A-Za-z0-9]{16,}\b/g,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaddo/cli",
3
- "version": "3.129.0",
3
+ "version": "3.129.1",
4
4
  "description": "Knowledge Driven Development toolkit",
5
5
  "license": "MIT",
6
6
  "repository": {