@kaddo/cli 3.128.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.
- package/dist/core.js +736 -52
- package/dist/index.js +777 -68
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -166,6 +166,21 @@ function setProjectMode(dir, mode) {
|
|
|
166
166
|
if (!updated) throw new ConfigError("Could not reload .kaddo/config.yml after updating project.mode.");
|
|
167
167
|
return updated;
|
|
168
168
|
}
|
|
169
|
+
function requireConfig(dir) {
|
|
170
|
+
let config;
|
|
171
|
+
try {
|
|
172
|
+
config = loadConfig(dir);
|
|
173
|
+
} catch (err) {
|
|
174
|
+
const message = err instanceof ConfigError ? err.message : String(err);
|
|
175
|
+
console.error(message);
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
if (!config) {
|
|
179
|
+
console.error("No .kaddo/config.yml found. Run `kaddo init` first.");
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
return config;
|
|
183
|
+
}
|
|
169
184
|
function projectRole(config) {
|
|
170
185
|
return config.project.role ?? config.multirepo?.role;
|
|
171
186
|
}
|
|
@@ -3681,7 +3696,8 @@ var AGENT_GROUPS = {
|
|
|
3681
3696
|
"work-item-agent.md",
|
|
3682
3697
|
"implementation-agent.md",
|
|
3683
3698
|
"ownership-agent.md",
|
|
3684
|
-
"git-strategy-agent.md"
|
|
3699
|
+
"git-strategy-agent.md",
|
|
3700
|
+
"knowledge-consolidation-agent.md"
|
|
3685
3701
|
],
|
|
3686
3702
|
utilities: ["legacy-agent.md"]
|
|
3687
3703
|
};
|
|
@@ -4388,7 +4404,7 @@ var KNOWLEDGE_FILES = [
|
|
|
4388
4404
|
function buildReadinessReport(dir, now = /* @__PURE__ */ new Date()) {
|
|
4389
4405
|
const config = loadConfig(dir);
|
|
4390
4406
|
const rec = resolveNextStep(dir, now);
|
|
4391
|
-
const stub = (overall2,
|
|
4407
|
+
const stub = (overall2, label2, command) => ({
|
|
4392
4408
|
project_name: config?.project.name ?? "unknown",
|
|
4393
4409
|
project_type: config?.project.state ?? "unknown",
|
|
4394
4410
|
overall: overall2,
|
|
@@ -4411,7 +4427,7 @@ function buildReadinessReport(dir, now = /* @__PURE__ */ new Date()) {
|
|
|
4411
4427
|
resolved_questions: 0,
|
|
4412
4428
|
deferred_questions: 0
|
|
4413
4429
|
},
|
|
4414
|
-
recommended_next_step: { label, ...command ? { command } : {} },
|
|
4430
|
+
recommended_next_step: { label: label2, ...command ? { command } : {} },
|
|
4415
4431
|
nextStepRecommendation: rec
|
|
4416
4432
|
});
|
|
4417
4433
|
if (!config) return stub("not-initialized", rec.label, rec.command);
|
|
@@ -5286,6 +5302,69 @@ After a POC has a canonical conclusion and Core has prepared its deterministic r
|
|
|
5286
5302
|
15. Traceability and Sources
|
|
5287
5303
|
`
|
|
5288
5304
|
);
|
|
5305
|
+
var KNOWLEDGE_CONSOLIDATION = skill(
|
|
5306
|
+
"knowledge-consolidation",
|
|
5307
|
+
"Knowledge Consolidation Skill",
|
|
5308
|
+
"delivery",
|
|
5309
|
+
["knowledge-consolidation-agent", "work-item-agent", "architecture-agent"],
|
|
5310
|
+
`
|
|
5311
|
+
# Knowledge Consolidation Skill
|
|
5312
|
+
|
|
5313
|
+
## Purpose
|
|
5314
|
+
|
|
5315
|
+
Standardize the SEMANTIC review of a deterministic Consolidation Plan so canonical knowledge becomes
|
|
5316
|
+
more precise, connected, consistent and retrievable \u2014 without losing history, decisions or evidence.
|
|
5317
|
+
|
|
5318
|
+
## When to use
|
|
5319
|
+
|
|
5320
|
+
After \`kaddo knowledge consolidate\` (or the \`kaddo_generate_consolidation_plan\` tool) has produced
|
|
5321
|
+
\`.kaddo/consolidation-plan.{md,json}\`, and a human or agent wants to review the opportunities and
|
|
5322
|
+
prepare refinements. Never as an autonomous rewrite of \`knowledge/\`.
|
|
5323
|
+
|
|
5324
|
+
## Inputs
|
|
5325
|
+
|
|
5326
|
+
The Consolidation Plan (\`.kaddo/consolidation-plan.json\`), the referenced source artifacts, and the
|
|
5327
|
+
context pack. Each opportunity carries: category, classification, confidence, source/target, evidence,
|
|
5328
|
+
rationale, suggested action, and \`requires_semantic_review\`.
|
|
5329
|
+
|
|
5330
|
+
## Output
|
|
5331
|
+
|
|
5332
|
+
For each opportunity the agent chooses to act on: a reviewable proposal that states what would change,
|
|
5333
|
+
what content is added/moved/summarized, what must be preserved, and which claims still need
|
|
5334
|
+
confirmation \u2014 with a diff or equivalent. No canonical file is edited by this skill; application goes
|
|
5335
|
+
through the existing controlled-edit flows after human approval.
|
|
5336
|
+
|
|
5337
|
+
## Rules
|
|
5338
|
+
|
|
5339
|
+
- Distinguish \`observed\` (verifiable fact) from \`suggested\` (a candidate needing judgement). Never
|
|
5340
|
+
present a \`suggested\` candidate as a verified conclusion.
|
|
5341
|
+
- Classify every claim as Observed / Derived / Suggested / Unknown.
|
|
5342
|
+
- Do not merge Business/Product/Tech just because they share a topic \u2014 preserve layer responsibilities.
|
|
5343
|
+
- Do not move every historical learning into current knowledge; incorporate only live rules, WITH a
|
|
5344
|
+
reference back to the originating Work Item. Never summarize or delete the Work Item.
|
|
5345
|
+
- Do not invent relationships, decisions or business rules; a missing optional relationship is an
|
|
5346
|
+
opportunity, not an error.
|
|
5347
|
+
- For a potential inconsistency, present BOTH sources and say whether the conflict is verified or
|
|
5348
|
+
potential. Never pick a winner arbitrarily.
|
|
5349
|
+
- Preserve critical constraints, decisions and reasons, exceptions, known risks, technical contracts,
|
|
5350
|
+
implementation evidence, provenance and necessary history.
|
|
5351
|
+
- Never reveal secret values or resolve secret references; never connect to a Project Resource.
|
|
5352
|
+
- Do not commit, push or release automatically.
|
|
5353
|
+
|
|
5354
|
+
## Quality checklist
|
|
5355
|
+
|
|
5356
|
+
- Every proposal cites its source artifact(s) and evidence.
|
|
5357
|
+
- Facts are separated from interpretations.
|
|
5358
|
+
- Preserved information is named explicitly.
|
|
5359
|
+
- Claims needing confirmation are flagged.
|
|
5360
|
+
- No canonical artifact was modified by the analysis or the review.
|
|
5361
|
+
|
|
5362
|
+
## Example output
|
|
5363
|
+
|
|
5364
|
+
A short set of proposals, each with evidence, a before/after (or diff) and an explicit list of what
|
|
5365
|
+
must be preserved, ready for human approval.
|
|
5366
|
+
`
|
|
5367
|
+
);
|
|
5289
5368
|
var SKILLS = [
|
|
5290
5369
|
ADR_WRITING,
|
|
5291
5370
|
WORK_ITEM_REFINEMENT,
|
|
@@ -5297,10 +5376,11 @@ var SKILLS = [
|
|
|
5297
5376
|
MODULE_CONTEXT_REFINEMENT,
|
|
5298
5377
|
EVIDENCE_VERIFICATION,
|
|
5299
5378
|
LEGACY_RISK_ASSESSMENT,
|
|
5300
|
-
POC_REPORT_WRITING
|
|
5379
|
+
POC_REPORT_WRITING,
|
|
5380
|
+
KNOWLEDGE_CONSOLIDATION
|
|
5301
5381
|
];
|
|
5302
5382
|
var SKILL_GROUPS = {
|
|
5303
|
-
delivery: ["work-item-refinement", "implementation-planning", "learning-capture", "evidence-verification", "legacy-risk-assessment", "poc-report-writing"],
|
|
5383
|
+
delivery: ["work-item-refinement", "implementation-planning", "learning-capture", "evidence-verification", "legacy-risk-assessment", "poc-report-writing", "knowledge-consolidation"],
|
|
5304
5384
|
tech: ["adr-writing", "ownership-suggestion", "graph-metadata-review", "module-context-refinement"],
|
|
5305
5385
|
integration: ["capsule-writing"]
|
|
5306
5386
|
};
|
|
@@ -5496,6 +5576,24 @@ var RESPONSIBILITY_MATRIX = {
|
|
|
5496
5576
|
],
|
|
5497
5577
|
next: ["kaddo graph export"]
|
|
5498
5578
|
},
|
|
5579
|
+
"knowledge-consolidation-agent": {
|
|
5580
|
+
agent: "knowledge-consolidation-agent",
|
|
5581
|
+
responsibleFor: [
|
|
5582
|
+
"Semantic review of the deterministic Consolidation Plan",
|
|
5583
|
+
"Preparing reviewable knowledge refinements"
|
|
5584
|
+
],
|
|
5585
|
+
produces: ["proposed refinements (before/after) for human approval"],
|
|
5586
|
+
canSuggest: ["kaddo knowledge consolidate"],
|
|
5587
|
+
cannotSuggest: [
|
|
5588
|
+
"code",
|
|
5589
|
+
"git",
|
|
5590
|
+
"commits",
|
|
5591
|
+
"modifying canonical knowledge without confirmation",
|
|
5592
|
+
"inventing facts or relationships",
|
|
5593
|
+
"deleting history"
|
|
5594
|
+
],
|
|
5595
|
+
next: ["kaddo knowledge consolidate"]
|
|
5596
|
+
},
|
|
5499
5597
|
"ownership-agent": {
|
|
5500
5598
|
agent: "ownership-agent",
|
|
5501
5599
|
responsibleFor: ["Precise code: ownership for Work Items and artifacts"],
|
|
@@ -7656,6 +7754,78 @@ ADRs) and re-runs \`kaddo graph export\`.
|
|
|
7656
7754
|
- No files were modified; no Git was run.
|
|
7657
7755
|
- The human is asked to confirm and re-export the graph.
|
|
7658
7756
|
`;
|
|
7757
|
+
var KNOWLEDGE_CONSOLIDATION_AGENT = `# Knowledge Consolidation Agent
|
|
7758
|
+
|
|
7759
|
+
## Role
|
|
7760
|
+
|
|
7761
|
+
You are the Kaddo Knowledge Consolidation Agent. Your job is to perform the **semantic review** of
|
|
7762
|
+
the deterministic **Consolidation Plan** produced by \`kaddo knowledge consolidate\`, and to prepare
|
|
7763
|
+
**reviewable refinements** that make canonical knowledge more precise, connected, consistent and
|
|
7764
|
+
retrievable \u2014 without losing history, decisions or evidence.
|
|
7765
|
+
|
|
7766
|
+
You do not write code, you do not modify canonical files, and you never run Git. You propose; a human
|
|
7767
|
+
confirms, and application goes through Kaddo's existing controlled-edit flows.
|
|
7768
|
+
|
|
7769
|
+
## When to Use
|
|
7770
|
+
|
|
7771
|
+
Use this agent after \`kaddo knowledge consolidate\` (or the \`kaddo_generate_consolidation_plan\`
|
|
7772
|
+
tool) has produced \`.kaddo/consolidation-plan.md\` and \`.kaddo/consolidation-plan.json\`, and the
|
|
7773
|
+
plan contains opportunities flagged \`requires_semantic_review\`.
|
|
7774
|
+
|
|
7775
|
+
## Input Required
|
|
7776
|
+
|
|
7777
|
+
Provide \`.kaddo/context-pack.md\` and \`.kaddo/consolidation-plan.json\` as the primary inputs, plus
|
|
7778
|
+
the source artifacts each opportunity references under \`knowledge/\` (and completed Work Items under
|
|
7779
|
+
\`knowledge/delivery/work-items/completed/\` for learning opportunities).
|
|
7780
|
+
|
|
7781
|
+
## Expected Output
|
|
7782
|
+
|
|
7783
|
+
For each opportunity you choose to act on, a proposal that states what would change, what content is
|
|
7784
|
+
added / moved / summarized, what must be preserved, and which claims still need confirmation \u2014 with a
|
|
7785
|
+
diff or equivalent before/after.
|
|
7786
|
+
|
|
7787
|
+
## Instructions
|
|
7788
|
+
|
|
7789
|
+
1. Read the plan and work one opportunity at a time, highest-signal first.
|
|
7790
|
+
2. Separate what you **observe** in the files from what you **suggest** \u2014 never present a suggested
|
|
7791
|
+
candidate as a verified conclusion.
|
|
7792
|
+
3. For possible redundancy, compare the actual sections; propose a single reference location only if
|
|
7793
|
+
one genuinely restates the other. Preserve layer separation (Business / Product / Tech / Delivery).
|
|
7794
|
+
4. For an unincorporated learning, decide whether it is a live rule; if so, propose incorporating it
|
|
7795
|
+
into the right Tech artifact **with a reference back to the originating Work Item**. Never summarize
|
|
7796
|
+
or delete the Work Item.
|
|
7797
|
+
5. For a relationship opportunity, propose the relationship only when existing knowledge justifies it;
|
|
7798
|
+
a missing optional relationship is an opportunity, not an error.
|
|
7799
|
+
6. For a potential inconsistency, present **both** sources and say whether the conflict is verified or
|
|
7800
|
+
potential. Do not pick a winner arbitrarily.
|
|
7801
|
+
7. Classify every claim as Observed / Derived / Suggested / Unknown, and mark what needs confirmation.
|
|
7802
|
+
|
|
7803
|
+
## Constraints
|
|
7804
|
+
|
|
7805
|
+
- Do **not** modify canonical files \u2014 propose changes for a human to apply.
|
|
7806
|
+
- Do **not** invent facts, relationships, decisions or business rules.
|
|
7807
|
+
- Do **not** delete historical information, change Work Item states, or alter verification results.
|
|
7808
|
+
- Do **not** reveal secret values or resolve secret references; do **not** connect to a Project Resource.
|
|
7809
|
+
- Do **not** run Git, commit, push or release.
|
|
7810
|
+
|
|
7811
|
+
## Output Format
|
|
7812
|
+
|
|
7813
|
+
Per opportunity: the opportunity id, classification and confidence, the proposed before/after (or
|
|
7814
|
+
diff), the explicit list of what must be preserved, and the open questions that need confirmation.
|
|
7815
|
+
|
|
7816
|
+
## Where to Save the Result
|
|
7817
|
+
|
|
7818
|
+
Nothing is saved automatically. The human reviews the proposals and applies the approved ones through
|
|
7819
|
+
Kaddo's existing controlled-edit flows. Re-run \`kaddo knowledge consolidate\` afterwards to confirm.
|
|
7820
|
+
|
|
7821
|
+
## Quality Checklist
|
|
7822
|
+
|
|
7823
|
+
- Every proposal cites its source artifact(s) and evidence from the plan.
|
|
7824
|
+
- Facts are separated from interpretations; suggested candidates are never asserted as fact.
|
|
7825
|
+
- Preserved information (constraints, decisions, exceptions, risks, contracts, provenance) is named.
|
|
7826
|
+
- No canonical artifact was modified; no Git was run.
|
|
7827
|
+
- The human is asked to confirm before anything is applied.
|
|
7828
|
+
`;
|
|
7659
7829
|
var AGENT_PROMPTS = [
|
|
7660
7830
|
{ fileName: "capability-agent.md", content: CAPABILITY_AGENT },
|
|
7661
7831
|
{ fileName: "architecture-agent.md", content: ARCHITECTURE_AGENT },
|
|
@@ -7682,7 +7852,9 @@ var AGENT_PROMPTS = [
|
|
|
7682
7852
|
// Knowledge Capsule refinement (external context — VS-054)
|
|
7683
7853
|
{ fileName: "capsule-agent.md", content: CAPSULE_AGENT },
|
|
7684
7854
|
// Graph relationship quality (metadata hints → precise front matter — VS-056)
|
|
7685
|
-
{ fileName: "graph-agent.md", content: GRAPH_AGENT }
|
|
7855
|
+
{ fileName: "graph-agent.md", content: GRAPH_AGENT },
|
|
7856
|
+
// Knowledge Consolidation semantic review (deterministic plan → reviewable refinements — WI-070)
|
|
7857
|
+
{ fileName: "knowledge-consolidation-agent.md", content: KNOWLEDGE_CONSOLIDATION_AGENT }
|
|
7686
7858
|
// Every official prompt ends with its responsibility boundaries + Agent Trace footer.
|
|
7687
7859
|
].map((p) => ({ fileName: p.fileName, content: withResponsibilityTrace(p.fileName, p.content) }));
|
|
7688
7860
|
|
|
@@ -7889,9 +8061,9 @@ function installedAssetsSummary(dir) {
|
|
|
7889
8061
|
// src/core/roadmap-quality.ts
|
|
7890
8062
|
var ROADMAP_PATH = "knowledge/delivery/roadmap.md";
|
|
7891
8063
|
var INITIATIVE_RE2 = /^#{2,4}\s+(RM-[\w.-]+)\s*[:\-–]?\s*(.*)$/;
|
|
7892
|
-
function fieldPresent(lines,
|
|
8064
|
+
function fieldPresent(lines, label2) {
|
|
7893
8065
|
for (let i = 0; i < lines.length; i++) {
|
|
7894
|
-
const m = lines[i].match(new RegExp(`^\\s*[-*]?\\s*(?:\\*\\*)?\\s*(${
|
|
8066
|
+
const m = lines[i].match(new RegExp(`^\\s*[-*]?\\s*(?:\\*\\*)?\\s*(${label2.source})\\s*(?:\\*\\*)?\\s*:\\s*(.*)$`, "i"));
|
|
7895
8067
|
if (!m) continue;
|
|
7896
8068
|
const inline = m[2].trim();
|
|
7897
8069
|
if (inline) return true;
|
|
@@ -9717,9 +9889,9 @@ function renderImpactMarkdown(r, opts = {}) {
|
|
|
9717
9889
|
["validation section", gp.missing_validation]
|
|
9718
9890
|
];
|
|
9719
9891
|
L.push("## Historical Documentation Completeness", "");
|
|
9720
|
-
for (const [
|
|
9892
|
+
for (const [label2, items] of historical) {
|
|
9721
9893
|
const completed = items.filter((item) => item.status === "completed");
|
|
9722
|
-
if (completed.length > 0) L.push(`- Completed Work Items without detected ${
|
|
9894
|
+
if (completed.length > 0) L.push(`- Completed Work Items without detected ${label2}: ${completed.length}`);
|
|
9723
9895
|
}
|
|
9724
9896
|
if (!historical.some(([, items]) => items.some((item) => item.status === "completed"))) {
|
|
9725
9897
|
L.push("No historical documentation completeness gaps were detected.");
|
|
@@ -10259,10 +10431,517 @@ function serializeSavingsJson(r) {
|
|
|
10259
10431
|
return JSON.stringify(r, null, 2) + "\n";
|
|
10260
10432
|
}
|
|
10261
10433
|
|
|
10434
|
+
// src/core/knowledge-consolidation.ts
|
|
10435
|
+
import { createHash as createHash2 } from "crypto";
|
|
10436
|
+
import matter11 from "gray-matter";
|
|
10437
|
+
var KNOWLEDGE5 = "knowledge";
|
|
10438
|
+
var CONSOLIDATION_CATEGORIES = [
|
|
10439
|
+
"knowledge_redundancy",
|
|
10440
|
+
"unincorporated_learning",
|
|
10441
|
+
"knowledge_fragmentation",
|
|
10442
|
+
"relationship_opportunity",
|
|
10443
|
+
"potentially_outdated",
|
|
10444
|
+
"knowledge_organization"
|
|
10445
|
+
];
|
|
10446
|
+
function toPosix6(p) {
|
|
10447
|
+
return p.replace(/\\/g, "/");
|
|
10448
|
+
}
|
|
10449
|
+
function relFromDir(dir, filePath) {
|
|
10450
|
+
const d = toPosix6(dir).replace(/\/+$/, "");
|
|
10451
|
+
const f = toPosix6(filePath);
|
|
10452
|
+
return f.startsWith(d + "/") ? f.slice(d.length + 1) : f;
|
|
10453
|
+
}
|
|
10454
|
+
function sha256(content) {
|
|
10455
|
+
return createHash2("sha256").update(content, "utf-8").digest("hex");
|
|
10456
|
+
}
|
|
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;
|
|
10532
|
+
}
|
|
10533
|
+
return null;
|
|
10534
|
+
}
|
|
10535
|
+
function sectionBody(body, titles) {
|
|
10536
|
+
const lines = body.split(/\r?\n/);
|
|
10537
|
+
const re = new RegExp(`^#{1,3}\\s+(${titles.join("|")})\\s*$`, "i");
|
|
10538
|
+
const start = lines.findIndex((l) => re.test(l));
|
|
10539
|
+
if (start < 0) return null;
|
|
10540
|
+
const collected = [];
|
|
10541
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
10542
|
+
if (/^#{1,3}\s+/.test(lines[i])) break;
|
|
10543
|
+
collected.push(lines[i]);
|
|
10544
|
+
}
|
|
10545
|
+
const text2 = collected.join("\n").trim();
|
|
10546
|
+
return text2.length > 0 ? text2 : null;
|
|
10547
|
+
}
|
|
10548
|
+
function stableOpportunityId(category, sources) {
|
|
10549
|
+
const key = [category, ...[...sources].sort()].join("|");
|
|
10550
|
+
return `${category}:${sha256(key).slice(0, 12)}`;
|
|
10551
|
+
}
|
|
10552
|
+
function layerOf(a) {
|
|
10553
|
+
const byType = layerForType(a.type);
|
|
10554
|
+
if (byType) return byType;
|
|
10555
|
+
const p = toPosix6(a.filePath);
|
|
10556
|
+
if (p.includes(`/${KNOWLEDGE5}/business/`)) return "Business";
|
|
10557
|
+
if (p.includes(`/${KNOWLEDGE5}/product/`)) return "Product";
|
|
10558
|
+
if (p.includes(`/${KNOWLEDGE5}/tech/`)) return "Tech";
|
|
10559
|
+
if (p.includes(`/${KNOWLEDGE5}/delivery/`)) return "Delivery";
|
|
10560
|
+
return null;
|
|
10561
|
+
}
|
|
10562
|
+
function inScope(la, scope) {
|
|
10563
|
+
if (scope.kind === "all") return true;
|
|
10564
|
+
if (scope.kind === "layer") return la.layer === scope.layer;
|
|
10565
|
+
return la.artifact.affectedModules.includes(scope.module);
|
|
10566
|
+
}
|
|
10567
|
+
function label(la) {
|
|
10568
|
+
return la.artifact.id || la.rel;
|
|
10569
|
+
}
|
|
10570
|
+
function buildConsolidationPlan(dir, opts = {}) {
|
|
10571
|
+
requireConfig(dir);
|
|
10572
|
+
const scope = opts.scope ?? { kind: "all" };
|
|
10573
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
10574
|
+
const archDir = join(dir, KNOWLEDGE5);
|
|
10575
|
+
const rawArtifacts = exists(archDir) ? readArtifacts(archDir) : [];
|
|
10576
|
+
const loaded = rawArtifacts.map((a) => {
|
|
10577
|
+
let body = "";
|
|
10578
|
+
try {
|
|
10579
|
+
body = matter11(readFile(a.filePath)).content;
|
|
10580
|
+
} catch {
|
|
10581
|
+
body = "";
|
|
10582
|
+
}
|
|
10583
|
+
return { artifact: a, rel: relFromDir(dir, a.filePath), body, layer: layerOf(a) };
|
|
10584
|
+
});
|
|
10585
|
+
const scoped = loaded.filter((la) => inScope(la, scope));
|
|
10586
|
+
const scopedRels = new Set(scoped.map((la) => la.rel));
|
|
10587
|
+
const knownIds = new Set(loaded.map((la) => la.artifact.id).filter(Boolean));
|
|
10588
|
+
const opportunities = [];
|
|
10589
|
+
try {
|
|
10590
|
+
const config = requireConfig(dir);
|
|
10591
|
+
const graph = buildGraph(dir, config, { scope: "all" }, now);
|
|
10592
|
+
const hints = buildGraphHints(dir, graph, now);
|
|
10593
|
+
for (const hint of hints.hints) {
|
|
10594
|
+
if (!hintInScope(hint, scoped)) continue;
|
|
10595
|
+
opportunities.push(relationshipOpportunityFromHint(hint));
|
|
10596
|
+
}
|
|
10597
|
+
} catch {
|
|
10598
|
+
}
|
|
10599
|
+
for (const la of scoped) {
|
|
10600
|
+
const dangling = la.artifact.decisions.filter((d) => d && !knownIds.has(d) && !decisionFileExists(dir, d));
|
|
10601
|
+
if (dangling.length === 0) continue;
|
|
10602
|
+
opportunities.push({
|
|
10603
|
+
id: stableOpportunityId("potentially_outdated", [label(la), ...dangling]),
|
|
10604
|
+
category: "potentially_outdated",
|
|
10605
|
+
classification: "observed",
|
|
10606
|
+
confidence: "requires-review",
|
|
10607
|
+
title: `${label(la)} references decision(s) that no longer exist`,
|
|
10608
|
+
source_artifacts: [label(la)],
|
|
10609
|
+
target_artifacts: [label(la)],
|
|
10610
|
+
evidence: dangling.map((d) => `Declared decision \`${d}\` has no matching artifact in the project.`),
|
|
10611
|
+
rationale: "A reference to a missing decision is a verifiable inconsistency: either the decision artifact was removed/renamed or the reference is stale.",
|
|
10612
|
+
possible_impact: "Broken traceability between a Work Item/artifact and its decisions.",
|
|
10613
|
+
suggested_action: "Review and update or remove the dangling decision reference.",
|
|
10614
|
+
requires_semantic_review: false
|
|
10615
|
+
});
|
|
10616
|
+
}
|
|
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) ?? [];
|
|
10625
|
+
arr.push(la);
|
|
10626
|
+
shingleIndex.set(key, arr);
|
|
10627
|
+
}
|
|
10628
|
+
}
|
|
10629
|
+
const candidatePairs = /* @__PURE__ */ new Map();
|
|
10630
|
+
for (const arts of shingleIndex.values()) {
|
|
10631
|
+
if (arts.length < 2) continue;
|
|
10632
|
+
for (let i = 0; i < arts.length; i++) {
|
|
10633
|
+
for (let j = i + 1; j < arts.length; j++) {
|
|
10634
|
+
if (arts[i].rel === arts[j].rel) continue;
|
|
10635
|
+
const key = [arts[i].rel, arts[j].rel].sort().join("||");
|
|
10636
|
+
if (!candidatePairs.has(key)) candidatePairs.set(key, { a: arts[i], b: arts[j] });
|
|
10637
|
+
}
|
|
10638
|
+
}
|
|
10639
|
+
}
|
|
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;
|
|
10644
|
+
opportunities.push({
|
|
10645
|
+
id: stableOpportunityId("knowledge_redundancy", [label(a), label(b)]),
|
|
10646
|
+
category: "knowledge_redundancy",
|
|
10647
|
+
classification: "suggested",
|
|
10648
|
+
confidence: "requires-review",
|
|
10649
|
+
title: `Possible overlapping content between ${label(a)} and ${label(b)}`,
|
|
10650
|
+
source_artifacts: [label(a), label(b)],
|
|
10651
|
+
target_artifacts: [label(a), label(b)],
|
|
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.",
|
|
10656
|
+
possible_impact: "If genuinely duplicated, the same fact can drift out of sync across files.",
|
|
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.",
|
|
10658
|
+
requires_semantic_review: true
|
|
10659
|
+
});
|
|
10660
|
+
}
|
|
10661
|
+
for (const la of scoped) {
|
|
10662
|
+
if (!isCompletedWorkItem(la)) continue;
|
|
10663
|
+
const learning = sectionBody(la.body, ["Learning", "Aprendizaje", "Aprendizajes", "Learnings"]);
|
|
10664
|
+
if (!learning) continue;
|
|
10665
|
+
const ruleFragment = firstRuleFragment(learning);
|
|
10666
|
+
if (!ruleFragment) continue;
|
|
10667
|
+
opportunities.push({
|
|
10668
|
+
id: stableOpportunityId("unincorporated_learning", [label(la)]),
|
|
10669
|
+
category: "unincorporated_learning",
|
|
10670
|
+
classification: "suggested",
|
|
10671
|
+
confidence: "requires-review",
|
|
10672
|
+
title: `${label(la)} captured a learning that may belong in current knowledge`,
|
|
10673
|
+
source_artifacts: [label(la)],
|
|
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.",
|
|
10678
|
+
possible_impact: "A relevant constraint stays buried in delivery history instead of informing current work.",
|
|
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.",
|
|
10680
|
+
requires_semantic_review: true
|
|
10681
|
+
});
|
|
10682
|
+
}
|
|
10683
|
+
const weakByFolder = /* @__PURE__ */ new Map();
|
|
10684
|
+
for (const la of scoped) {
|
|
10685
|
+
if (!isConsolidatableKnowledge(la)) continue;
|
|
10686
|
+
const quality = safeQuality(dir, la.rel);
|
|
10687
|
+
if (quality === "placeholder" || quality === "weak") {
|
|
10688
|
+
opportunities.push({
|
|
10689
|
+
id: stableOpportunityId("knowledge_organization", [la.rel]),
|
|
10690
|
+
category: "knowledge_organization",
|
|
10691
|
+
classification: "observed",
|
|
10692
|
+
confidence: "requires-review",
|
|
10693
|
+
title: `${label(la)} is ${quality} and may need consolidation or expansion`,
|
|
10694
|
+
source_artifacts: [label(la)],
|
|
10695
|
+
target_artifacts: [label(la)],
|
|
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.",
|
|
10698
|
+
possible_impact: "Readers must open more files to assemble a complete picture.",
|
|
10699
|
+
suggested_action: "Semantic review: decide whether to expand, merge into a stronger artifact, or cross-reference it.",
|
|
10700
|
+
requires_semantic_review: true
|
|
10701
|
+
});
|
|
10702
|
+
const folder = la.rel.split("/").slice(0, -1).join("/");
|
|
10703
|
+
const arr = weakByFolder.get(folder) ?? [];
|
|
10704
|
+
arr.push(la);
|
|
10705
|
+
weakByFolder.set(folder, arr);
|
|
10706
|
+
}
|
|
10707
|
+
}
|
|
10708
|
+
for (const [folder, arts] of weakByFolder) {
|
|
10709
|
+
if (arts.length < 3) continue;
|
|
10710
|
+
opportunities.push({
|
|
10711
|
+
id: stableOpportunityId("knowledge_fragmentation", arts.map((a) => a.rel)),
|
|
10712
|
+
category: "knowledge_fragmentation",
|
|
10713
|
+
classification: "suggested",
|
|
10714
|
+
confidence: "requires-review",
|
|
10715
|
+
title: `${folder}/ holds ${arts.length} low-signal canonical artifacts \u2014 possible fragmentation`,
|
|
10716
|
+
source_artifacts: arts.map((a) => label(a)),
|
|
10717
|
+
target_artifacts: [folder],
|
|
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.",
|
|
10720
|
+
possible_impact: "Related knowledge is spread across too many files to follow.",
|
|
10721
|
+
suggested_action: "Semantic review: evaluate whether cross-references or a consolidation would add clarity. Do not merge by file count alone.",
|
|
10722
|
+
requires_semantic_review: true
|
|
10723
|
+
});
|
|
10724
|
+
}
|
|
10725
|
+
opportunities.sort((x, y) => {
|
|
10726
|
+
const ci = CONSOLIDATION_CATEGORIES.indexOf(x.category) - CONSOLIDATION_CATEGORIES.indexOf(y.category);
|
|
10727
|
+
return ci !== 0 ? ci : x.id.localeCompare(y.id);
|
|
10728
|
+
});
|
|
10729
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10730
|
+
const deduped = opportunities.filter((o) => seen.has(o.id) ? false : (seen.add(o.id), true));
|
|
10731
|
+
const layers = discoverLayers(dir);
|
|
10732
|
+
const layersEvaluated = scope.kind === "layer" ? [scope.layer] : layers.map((l) => l.layer);
|
|
10733
|
+
const workItemsEvaluated = scoped.filter(isWorkItem).length;
|
|
10734
|
+
const sourceFiles = [...scopedRels].sort().map((rel) => ({ path: rel, hash: sha256(readFileSafe(join(dir, rel))) }));
|
|
10735
|
+
const byCategory = Object.fromEntries(
|
|
10736
|
+
CONSOLIDATION_CATEGORIES.map((c) => [c, deduped.filter((o) => o.category === c).length])
|
|
10737
|
+
);
|
|
10738
|
+
return {
|
|
10739
|
+
generated_at: now.toISOString(),
|
|
10740
|
+
scope: describeScope(scope),
|
|
10741
|
+
project_context: reportingProjectContext(dir),
|
|
10742
|
+
coverage: {
|
|
10743
|
+
scope: describeScope(scope),
|
|
10744
|
+
layers_evaluated: layersEvaluated,
|
|
10745
|
+
artifacts_evaluated: scoped.length,
|
|
10746
|
+
work_items_evaluated: workItemsEvaluated,
|
|
10747
|
+
excluded_sources: scope.kind === "all" ? [] : [...loaded.map((l) => l.rel)].filter((r) => !scopedRels.has(r)).sort()
|
|
10748
|
+
},
|
|
10749
|
+
source_files: sourceFiles,
|
|
10750
|
+
opportunities: deduped,
|
|
10751
|
+
summary: {
|
|
10752
|
+
total: deduped.length,
|
|
10753
|
+
by_category: byCategory,
|
|
10754
|
+
requires_semantic_review: deduped.filter((o) => o.requires_semantic_review).length
|
|
10755
|
+
}
|
|
10756
|
+
};
|
|
10757
|
+
}
|
|
10758
|
+
function consolidationPlanStaleness(dir, plan) {
|
|
10759
|
+
const changed = [];
|
|
10760
|
+
const removed = [];
|
|
10761
|
+
for (const sf of plan.source_files) {
|
|
10762
|
+
const abs = join(dir, sf.path);
|
|
10763
|
+
if (!exists(abs)) {
|
|
10764
|
+
removed.push(sf.path);
|
|
10765
|
+
continue;
|
|
10766
|
+
}
|
|
10767
|
+
if (sha256(readFileSafe(abs)) !== sf.hash) changed.push(sf.path);
|
|
10768
|
+
}
|
|
10769
|
+
return { stale: changed.length > 0 || removed.length > 0, changed, removed };
|
|
10770
|
+
}
|
|
10771
|
+
var CATEGORY_LABELS = {
|
|
10772
|
+
knowledge_redundancy: "Possible redundancy",
|
|
10773
|
+
unincorporated_learning: "Learning integration opportunity",
|
|
10774
|
+
knowledge_fragmentation: "Possible fragmentation",
|
|
10775
|
+
relationship_opportunity: "Relationship review hint",
|
|
10776
|
+
potentially_outdated: "Potential inconsistency",
|
|
10777
|
+
knowledge_organization: "Organization opportunity"
|
|
10778
|
+
};
|
|
10779
|
+
function renderConsolidationMarkdown(plan) {
|
|
10780
|
+
const lines = [];
|
|
10781
|
+
lines.push("# Knowledge Consolidation Plan");
|
|
10782
|
+
lines.push("");
|
|
10783
|
+
lines.push("> Derived, review-only projection. No canonical knowledge was modified by this analysis.");
|
|
10784
|
+
lines.push("");
|
|
10785
|
+
lines.push(`- Generated at: ${plan.generated_at}`);
|
|
10786
|
+
lines.push(`- Scope: ${plan.scope}`);
|
|
10787
|
+
lines.push(`- Project: state=${plan.project_context.state}, mode=${plan.project_context.mode}, structure=${plan.project_context.repository_structure}`);
|
|
10788
|
+
lines.push("");
|
|
10789
|
+
lines.push("## Coverage");
|
|
10790
|
+
lines.push("");
|
|
10791
|
+
lines.push(`- Layers evaluated: ${plan.coverage.layers_evaluated.join(", ") || "\u2014"}`);
|
|
10792
|
+
lines.push(`- Artifacts evaluated: ${plan.coverage.artifacts_evaluated}`);
|
|
10793
|
+
lines.push(`- Work Items evaluated: ${plan.coverage.work_items_evaluated}`);
|
|
10794
|
+
if (plan.coverage.excluded_sources.length > 0) {
|
|
10795
|
+
lines.push(`- Excluded from this scope: ${plan.coverage.excluded_sources.length} artifact(s)`);
|
|
10796
|
+
}
|
|
10797
|
+
lines.push("");
|
|
10798
|
+
lines.push("## Findings");
|
|
10799
|
+
lines.push("");
|
|
10800
|
+
if (plan.summary.total === 0) {
|
|
10801
|
+
lines.push("No consolidation opportunities were detected by the available deterministic analyses within this scope.");
|
|
10802
|
+
lines.push("");
|
|
10803
|
+
lines.push("This is not a claim that the knowledge is perfect \u2014 only that no opportunity was found with the current signals.");
|
|
10804
|
+
lines.push("");
|
|
10805
|
+
return lines.join("\n") + "\n";
|
|
10806
|
+
}
|
|
10807
|
+
for (const cat of CONSOLIDATION_CATEGORIES) {
|
|
10808
|
+
const n = plan.summary.by_category[cat];
|
|
10809
|
+
if (n > 0) lines.push(`- ${n} \xD7 ${CATEGORY_LABELS[cat]}`);
|
|
10810
|
+
}
|
|
10811
|
+
lines.push("");
|
|
10812
|
+
lines.push(`${plan.summary.requires_semantic_review} finding(s) require semantic (agent/human) review before acting.`);
|
|
10813
|
+
lines.push("");
|
|
10814
|
+
lines.push("## Opportunities");
|
|
10815
|
+
lines.push("");
|
|
10816
|
+
for (const o of plan.opportunities) {
|
|
10817
|
+
lines.push(`### ${o.title}`);
|
|
10818
|
+
lines.push("");
|
|
10819
|
+
lines.push(`- Id: \`${o.id}\``);
|
|
10820
|
+
lines.push(`- Category: ${o.category}`);
|
|
10821
|
+
lines.push(`- Classification: **${o.classification}**${o.requires_semantic_review ? " (requires semantic review)" : ""}`);
|
|
10822
|
+
lines.push(`- Confidence: ${o.confidence}`);
|
|
10823
|
+
lines.push(`- Source: ${o.source_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
|
+
);
|
|
10827
|
+
lines.push(`- Evidence:`);
|
|
10828
|
+
for (const e of o.evidence) lines.push(` - ${e}`);
|
|
10829
|
+
lines.push(`- Rationale: ${o.rationale}`);
|
|
10830
|
+
lines.push(`- Possible impact: ${o.possible_impact}`);
|
|
10831
|
+
lines.push(`- Suggested action: ${o.suggested_action}`);
|
|
10832
|
+
lines.push("");
|
|
10833
|
+
}
|
|
10834
|
+
return lines.join("\n") + "\n";
|
|
10835
|
+
}
|
|
10836
|
+
function serializeConsolidationJson(plan) {
|
|
10837
|
+
return JSON.stringify(plan, null, 2) + "\n";
|
|
10838
|
+
}
|
|
10839
|
+
function describeScope(scope) {
|
|
10840
|
+
if (scope.kind === "all") return "all";
|
|
10841
|
+
if (scope.kind === "layer") return `layer:${scope.layer}`;
|
|
10842
|
+
return `module:${scope.module}`;
|
|
10843
|
+
}
|
|
10844
|
+
function isWorkItem(la) {
|
|
10845
|
+
return toPosix6(la.artifact.filePath).includes("/delivery/work-items/");
|
|
10846
|
+
}
|
|
10847
|
+
function isCompletedWorkItem(la) {
|
|
10848
|
+
const p = toPosix6(la.artifact.filePath);
|
|
10849
|
+
return p.includes("/delivery/work-items/completed/") || isWorkItem(la) && la.artifact.status === "completed";
|
|
10850
|
+
}
|
|
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);
|
|
10865
|
+
}
|
|
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
|
+
}
|
|
10871
|
+
var SECRET_TOKEN_PATTERNS = [
|
|
10872
|
+
/\bgh[pours]_[A-Za-z0-9]{16,}\b/g,
|
|
10873
|
+
// GitHub tokens
|
|
10874
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
10875
|
+
// AWS access key ids
|
|
10876
|
+
/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
10877
|
+
// Slack tokens
|
|
10878
|
+
/\bsk-[A-Za-z0-9]{16,}\b/g,
|
|
10879
|
+
// OpenAI-style keys
|
|
10880
|
+
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,
|
|
10881
|
+
// JWTs
|
|
10882
|
+
/\b[A-Za-z0-9+/]{40,}={0,2}\b/g
|
|
10883
|
+
// long base64 / opaque blobs
|
|
10884
|
+
];
|
|
10885
|
+
function redactSecrets2(text2) {
|
|
10886
|
+
let out = text2;
|
|
10887
|
+
for (const re of SECRET_TOKEN_PATTERNS) out = out.replace(re, "[redacted]");
|
|
10888
|
+
return out;
|
|
10889
|
+
}
|
|
10890
|
+
function safeQuality(dir, rel) {
|
|
10891
|
+
try {
|
|
10892
|
+
return analyzeKnowledgeArtifact(dir, rel);
|
|
10893
|
+
} catch {
|
|
10894
|
+
return "useful";
|
|
10895
|
+
}
|
|
10896
|
+
}
|
|
10897
|
+
function readFileSafe(abs) {
|
|
10898
|
+
try {
|
|
10899
|
+
return readFile(abs);
|
|
10900
|
+
} catch {
|
|
10901
|
+
return "";
|
|
10902
|
+
}
|
|
10903
|
+
}
|
|
10904
|
+
function decisionFileExists(dir, decisionId) {
|
|
10905
|
+
const decisionsDir = join(dir, KNOWLEDGE5, "tech", "decisions");
|
|
10906
|
+
if (!exists(decisionsDir)) return false;
|
|
10907
|
+
try {
|
|
10908
|
+
return readDir(decisionsDir).some((e) => {
|
|
10909
|
+
const full = join(decisionsDir, e);
|
|
10910
|
+
if (!isFile(full) || !e.endsWith(".md")) return false;
|
|
10911
|
+
return e.toLowerCase().includes(decisionId.toLowerCase());
|
|
10912
|
+
});
|
|
10913
|
+
} catch {
|
|
10914
|
+
return false;
|
|
10915
|
+
}
|
|
10916
|
+
}
|
|
10917
|
+
function hintInScope(hint, scoped) {
|
|
10918
|
+
if (scoped.length === 0) return false;
|
|
10919
|
+
return scoped.some(
|
|
10920
|
+
(la) => la.artifact.id === hint.artifact_id || hint.path && toPosix6(la.artifact.filePath).endsWith(toPosix6(hint.path))
|
|
10921
|
+
);
|
|
10922
|
+
}
|
|
10923
|
+
function relationshipOpportunityFromHint(hint) {
|
|
10924
|
+
const finding = graphHintFinding(hint);
|
|
10925
|
+
return {
|
|
10926
|
+
id: stableOpportunityId("relationship_opportunity", [hint.artifact_id, ...hint.missing]),
|
|
10927
|
+
category: "relationship_opportunity",
|
|
10928
|
+
classification: "observed",
|
|
10929
|
+
confidence: "requires-review",
|
|
10930
|
+
title: hint.message,
|
|
10931
|
+
source_artifacts: [hint.artifact_id],
|
|
10932
|
+
target_artifacts: [hint.artifact_id],
|
|
10933
|
+
evidence: [finding.evidence],
|
|
10934
|
+
rationale: "A missing OPTIONAL relationship is an opportunity to review, not an error or a verified inconsistency. Kaddo never invents the relationship.",
|
|
10935
|
+
possible_impact: "Weaker traceability in the knowledge graph.",
|
|
10936
|
+
suggested_action: finding.suggested_action,
|
|
10937
|
+
requires_semantic_review: false
|
|
10938
|
+
};
|
|
10939
|
+
}
|
|
10940
|
+
|
|
10262
10941
|
// src/core/resource-write.ts
|
|
10263
10942
|
import fs2 from "fs";
|
|
10264
10943
|
import path2 from "path";
|
|
10265
|
-
import
|
|
10944
|
+
import matter12 from "gray-matter";
|
|
10266
10945
|
var RESOURCES_DIR = "knowledge/tech/resources";
|
|
10267
10946
|
var ResourceWriteError = class extends Error {
|
|
10268
10947
|
constructor(code, message) {
|
|
@@ -10372,7 +11051,7 @@ function buildFrontmatter(id, input, base = {}) {
|
|
|
10372
11051
|
return data;
|
|
10373
11052
|
}
|
|
10374
11053
|
function serialize(data, body) {
|
|
10375
|
-
return
|
|
11054
|
+
return matter12.stringify(`
|
|
10376
11055
|
${body.trim()}
|
|
10377
11056
|
`, data);
|
|
10378
11057
|
}
|
|
@@ -10412,7 +11091,7 @@ function updateResource(dir, id, input) {
|
|
|
10412
11091
|
throw new ResourceWriteError("VALIDATION_FAILED", findings.filter((f) => f.level === "error").map((f) => f.message).join("; "));
|
|
10413
11092
|
}
|
|
10414
11093
|
const raw = readFile(match.filePath);
|
|
10415
|
-
const parsed =
|
|
11094
|
+
const parsed = matter12(raw);
|
|
10416
11095
|
const base = parsed.data ?? {};
|
|
10417
11096
|
const data = buildFrontmatter(match.id || id, input, base);
|
|
10418
11097
|
let body = parsed.content.trim();
|
|
@@ -10683,7 +11362,7 @@ function analyzeCrossRepoEvidence(input) {
|
|
|
10683
11362
|
}
|
|
10684
11363
|
|
|
10685
11364
|
// src/core/work-items.ts
|
|
10686
|
-
import
|
|
11365
|
+
import matter13 from "gray-matter";
|
|
10687
11366
|
|
|
10688
11367
|
// src/core/system-topology.ts
|
|
10689
11368
|
import { parse as parseYaml9, stringify as stringifyYaml5 } from "yaml";
|
|
@@ -11121,7 +11800,7 @@ function parseOriginalSnapshot(fm) {
|
|
|
11121
11800
|
function readBody(filePath) {
|
|
11122
11801
|
try {
|
|
11123
11802
|
const raw = readFile(filePath);
|
|
11124
|
-
return
|
|
11803
|
+
return matter13(raw).content;
|
|
11125
11804
|
} catch {
|
|
11126
11805
|
return "";
|
|
11127
11806
|
}
|
|
@@ -11288,7 +11967,7 @@ function parseRelatedKnowledge(fm, knowledgeById) {
|
|
|
11288
11967
|
import fs4 from "fs";
|
|
11289
11968
|
import path4 from "path";
|
|
11290
11969
|
import crypto2 from "crypto";
|
|
11291
|
-
import
|
|
11970
|
+
import matter14 from "gray-matter";
|
|
11292
11971
|
|
|
11293
11972
|
// src/core/knowledge-levels.ts
|
|
11294
11973
|
var WORK_ITEM_TYPES2 = ["feature", "bugfix", "hotfix", "spike", "chore"];
|
|
@@ -11695,7 +12374,7 @@ function applyFrontmatter(data, input) {
|
|
|
11695
12374
|
return next;
|
|
11696
12375
|
}
|
|
11697
12376
|
function serialize2(data, body) {
|
|
11698
|
-
return
|
|
12377
|
+
return matter14.stringify(`
|
|
11699
12378
|
${body.trim()}
|
|
11700
12379
|
`, data);
|
|
11701
12380
|
}
|
|
@@ -11754,7 +12433,7 @@ function toInput(data, content) {
|
|
|
11754
12433
|
function getWorkItemForEdit(dir, id) {
|
|
11755
12434
|
const { filePath, relPath } = findArtifact(dir, id);
|
|
11756
12435
|
const raw = readFile(filePath);
|
|
11757
|
-
const { data, content } =
|
|
12436
|
+
const { data, content } = matter14(raw);
|
|
11758
12437
|
const status = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
11759
12438
|
const input = toInput(data, content);
|
|
11760
12439
|
const editable = EDITABLE_STATES.includes(status);
|
|
@@ -11847,7 +12526,7 @@ function updateWorkItem(dir, id, input, expectedRevision) {
|
|
|
11847
12526
|
if (revisionOf(raw) !== expectedRevision) {
|
|
11848
12527
|
throw new WorkItemWriteError("WORK_ITEM_CONFLICT", "This Work Item changed outside Kaddo Admin. Reload the latest version before saving.");
|
|
11849
12528
|
}
|
|
11850
|
-
const { data, content } =
|
|
12529
|
+
const { data, content } = matter14(raw);
|
|
11851
12530
|
const status = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
11852
12531
|
if (!EDITABLE_STATES.includes(status)) {
|
|
11853
12532
|
throw new WorkItemWriteError("WORK_ITEM_NOT_EDITABLE", `A ${status} Work Item cannot be edited. Reopen it as Draft first.`);
|
|
@@ -11861,7 +12540,7 @@ function updateWorkItem(dir, id, input, expectedRevision) {
|
|
|
11861
12540
|
function validateWorkItem(dir, id) {
|
|
11862
12541
|
const { filePath } = findArtifact(dir, id);
|
|
11863
12542
|
const raw = readFile(filePath);
|
|
11864
|
-
const { data, content } =
|
|
12543
|
+
const { data, content } = matter14(raw);
|
|
11865
12544
|
const input = toInput(data, content);
|
|
11866
12545
|
const findings = [];
|
|
11867
12546
|
const modules = validModuleIds(dir);
|
|
@@ -11914,7 +12593,7 @@ function transitionWorkItem(dir, id, to, expectedRevision) {
|
|
|
11914
12593
|
if (revisionOf(raw) !== expectedRevision) {
|
|
11915
12594
|
throw new WorkItemWriteError("WORK_ITEM_CONFLICT", "This Work Item changed outside Kaddo Admin. Reload the latest version before continuing.");
|
|
11916
12595
|
}
|
|
11917
|
-
const { data, content } =
|
|
12596
|
+
const { data, content } = matter14(raw);
|
|
11918
12597
|
const from = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
11919
12598
|
if (!(ALLOWED[from] ?? []).includes(to)) {
|
|
11920
12599
|
throw new WorkItemWriteError("INVALID_TRANSITION", `Cannot transition a ${from} Work Item to ${to}.`);
|
|
@@ -13090,7 +13769,7 @@ function deriveImplementationStatus(repos) {
|
|
|
13090
13769
|
// src/core/work-item-import.ts
|
|
13091
13770
|
import crypto3 from "crypto";
|
|
13092
13771
|
import fs5 from "fs";
|
|
13093
|
-
import
|
|
13772
|
+
import matter15 from "gray-matter";
|
|
13094
13773
|
var MAX_INPUT_BYTES = 102400;
|
|
13095
13774
|
var LIFECYCLE_FIELDS = /* @__PURE__ */ new Set([
|
|
13096
13775
|
"id",
|
|
@@ -13112,7 +13791,7 @@ function detectFormat(raw) {
|
|
|
13112
13791
|
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
13113
13792
|
if (trimmed.startsWith("---")) {
|
|
13114
13793
|
try {
|
|
13115
|
-
const { data } =
|
|
13794
|
+
const { data } = matter15(trimmed);
|
|
13116
13795
|
if (data && typeof data === "object" && Object.keys(data).length > 0) {
|
|
13117
13796
|
const d = data;
|
|
13118
13797
|
if (d.type === "work-item" || d.id && typeof d.id === "string" && /^WI-\d+/.test(d.id)) {
|
|
@@ -13134,7 +13813,7 @@ function parseContent(raw) {
|
|
|
13134
13813
|
let bodyText = trimmed;
|
|
13135
13814
|
if (format === "kaddo-frontmatter" || format === "markdown-frontmatter") {
|
|
13136
13815
|
try {
|
|
13137
|
-
const parsed =
|
|
13816
|
+
const parsed = matter15(trimmed);
|
|
13138
13817
|
frontmatterFields = parsed.data ?? {};
|
|
13139
13818
|
bodyText = parsed.content.trim();
|
|
13140
13819
|
} catch {
|
|
@@ -13231,7 +13910,7 @@ function findDuplicateByHash(dir, hash) {
|
|
|
13231
13910
|
const raw = readFile(item.filePath);
|
|
13232
13911
|
if (!raw) continue;
|
|
13233
13912
|
try {
|
|
13234
|
-
const { data } =
|
|
13913
|
+
const { data } = matter15(raw);
|
|
13235
13914
|
const source2 = data?.source;
|
|
13236
13915
|
if (source2 && typeof source2 === "object" && !Array.isArray(source2)) {
|
|
13237
13916
|
const s = source2;
|
|
@@ -13340,7 +14019,7 @@ var ImportError = class extends Error {
|
|
|
13340
14019
|
};
|
|
13341
14020
|
|
|
13342
14021
|
// src/services/integrations.ts
|
|
13343
|
-
import
|
|
14022
|
+
import matter16 from "gray-matter";
|
|
13344
14023
|
import { parse as parseYaml10, stringify as stringifyYaml6 } from "yaml";
|
|
13345
14024
|
|
|
13346
14025
|
// ../integrations/src/errors.ts
|
|
@@ -14682,7 +15361,7 @@ function findLinkedWorkItem(dir, integrationId, externalId) {
|
|
|
14682
15361
|
for (const art of discoverWorkItems(dir)) {
|
|
14683
15362
|
let data;
|
|
14684
15363
|
try {
|
|
14685
|
-
data =
|
|
15364
|
+
data = matter16(readFile(art.filePath)).data;
|
|
14686
15365
|
} catch {
|
|
14687
15366
|
continue;
|
|
14688
15367
|
}
|
|
@@ -14698,7 +15377,7 @@ function buildImportIndex(dir) {
|
|
|
14698
15377
|
for (const art of discoverWorkItems(dir)) {
|
|
14699
15378
|
let data;
|
|
14700
15379
|
try {
|
|
14701
|
-
data =
|
|
15380
|
+
data = matter16(readFile(art.filePath)).data;
|
|
14702
15381
|
} catch {
|
|
14703
15382
|
continue;
|
|
14704
15383
|
}
|
|
@@ -14874,7 +15553,7 @@ function getStatus(dir) {
|
|
|
14874
15553
|
}
|
|
14875
15554
|
|
|
14876
15555
|
// src/core/initiative-write.ts
|
|
14877
|
-
import
|
|
15556
|
+
import matter17 from "gray-matter";
|
|
14878
15557
|
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
14879
15558
|
var DRAFT_DIR = `${WORK_ITEMS_DIR2}/draft`;
|
|
14880
15559
|
var ROADMAP_PATH2 = "knowledge/delivery/roadmap.md";
|
|
@@ -14987,7 +15666,7 @@ function buildInitiativeContent(id, input) {
|
|
|
14987
15666
|
if (input.priority) data.priority = input.priority;
|
|
14988
15667
|
if (input.source) data.source = input.source;
|
|
14989
15668
|
if (input.sourceId) data.source_id = input.sourceId;
|
|
14990
|
-
return
|
|
15669
|
+
return matter17.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
14991
15670
|
}
|
|
14992
15671
|
function createInitiative(dir, input) {
|
|
14993
15672
|
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
@@ -15011,10 +15690,10 @@ function transitionInitiative(dir, id, to) {
|
|
|
15011
15690
|
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
15012
15691
|
}
|
|
15013
15692
|
const raw = readFile(ini.filePath);
|
|
15014
|
-
const { data, content } =
|
|
15693
|
+
const { data, content } = matter17(raw, {});
|
|
15015
15694
|
data.status = to;
|
|
15016
15695
|
if (to === "completed") data.completed_at = today();
|
|
15017
|
-
const newContent =
|
|
15696
|
+
const newContent = matter17.stringify(content, data);
|
|
15018
15697
|
writeFile(ini.filePath, newContent);
|
|
15019
15698
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
15020
15699
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
@@ -15024,7 +15703,7 @@ function addCandidate(dir, id, candidate) {
|
|
|
15024
15703
|
const ini = getInitiative(dir, id);
|
|
15025
15704
|
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
15026
15705
|
const raw = readFile(ini.filePath);
|
|
15027
|
-
const { data, content } =
|
|
15706
|
+
const { data, content } = matter17(raw, {});
|
|
15028
15707
|
const existing = Array.isArray(data.candidates) ? data.candidates : [];
|
|
15029
15708
|
const fallbackId = `WI-CANDIDATE-${String(existing.length + 1).padStart(3, "0")}`;
|
|
15030
15709
|
const normalized = normalizeCandidate(candidate, fallbackId);
|
|
@@ -15032,7 +15711,7 @@ function addCandidate(dir, id, candidate) {
|
|
|
15032
15711
|
throw new InitiativeWriteError(`Candidate ${normalized.id} already exists in ${id}.`);
|
|
15033
15712
|
}
|
|
15034
15713
|
data.candidates = [...existing, candidateToData(normalized)];
|
|
15035
|
-
const newContent =
|
|
15714
|
+
const newContent = matter17.stringify(content, data);
|
|
15036
15715
|
writeFile(ini.filePath, newContent);
|
|
15037
15716
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
15038
15717
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding a candidate.");
|
|
@@ -15042,7 +15721,7 @@ function updateInitiative(dir, id, patch) {
|
|
|
15042
15721
|
const ini = getInitiative(dir, id);
|
|
15043
15722
|
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
15044
15723
|
const raw = readFile(ini.filePath);
|
|
15045
|
-
const { data, content } =
|
|
15724
|
+
const { data, content } = matter17(raw, {});
|
|
15046
15725
|
if (patch.title !== void 0) {
|
|
15047
15726
|
if (!patch.title.trim()) throw new InitiativeWriteError("Initiative title cannot be empty.");
|
|
15048
15727
|
data.title = patch.title.trim();
|
|
@@ -15052,7 +15731,7 @@ function updateInitiative(dir, id, patch) {
|
|
|
15052
15731
|
if (patch.knowledgeLevel !== void 0) data.knowledge_level = patch.knowledgeLevel;
|
|
15053
15732
|
if (patch.domains !== void 0) data.domains = patch.domains;
|
|
15054
15733
|
if (patch.relatedCapabilities !== void 0) data.related_capabilities = patch.relatedCapabilities;
|
|
15055
|
-
const newContent =
|
|
15734
|
+
const newContent = matter17.stringify(content, data);
|
|
15056
15735
|
writeFile(ini.filePath, newContent);
|
|
15057
15736
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
15058
15737
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after update.");
|
|
@@ -15070,10 +15749,10 @@ function addExternalLink(dir, id, link) {
|
|
|
15070
15749
|
throw new InitiativeWriteError(`External link ${link.integration}:${link.externalId} already exists on ${id}.`);
|
|
15071
15750
|
}
|
|
15072
15751
|
const raw = readFile(ini.filePath);
|
|
15073
|
-
const { data, content } =
|
|
15752
|
+
const { data, content } = matter17(raw, {});
|
|
15074
15753
|
const existing = Array.isArray(data.external_links) ? data.external_links : [];
|
|
15075
15754
|
data.external_links = [...existing, externalLinkToData(link)];
|
|
15076
|
-
const newContent =
|
|
15755
|
+
const newContent = matter17.stringify(content, data);
|
|
15077
15756
|
writeFile(ini.filePath, newContent);
|
|
15078
15757
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
15079
15758
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding an external link.");
|
|
@@ -15142,7 +15821,7 @@ function buildWorkItemContent(wiId, iniId, candidate) {
|
|
|
15142
15821
|
"_What did we learn? Update after completion._",
|
|
15143
15822
|
""
|
|
15144
15823
|
].join("\n");
|
|
15145
|
-
return
|
|
15824
|
+
return matter17.stringify("\n" + body, data);
|
|
15146
15825
|
}
|
|
15147
15826
|
function materializeCandidate(dir, id, candidateId) {
|
|
15148
15827
|
const ini = getInitiative(dir, id);
|
|
@@ -15159,13 +15838,13 @@ function materializeCandidate(dir, id, candidateId) {
|
|
|
15159
15838
|
ensureDir(join(dir, DRAFT_DIR));
|
|
15160
15839
|
writeFile(join(dir, DRAFT_DIR, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
15161
15840
|
const raw = readFile(ini.filePath);
|
|
15162
|
-
const { data, content } =
|
|
15841
|
+
const { data, content } = matter17(raw, {});
|
|
15163
15842
|
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
15164
15843
|
for (const c of cands) {
|
|
15165
15844
|
if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
15166
15845
|
}
|
|
15167
15846
|
data.candidates = cands;
|
|
15168
|
-
const newContent =
|
|
15847
|
+
const newContent = matter17.stringify(content, data);
|
|
15169
15848
|
writeFile(ini.filePath, newContent);
|
|
15170
15849
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
15171
15850
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
@@ -15316,7 +15995,7 @@ function evaluateInitiativeCompletion(dir, ini) {
|
|
|
15316
15995
|
// src/core/deprecation-write.ts
|
|
15317
15996
|
import fs6 from "fs";
|
|
15318
15997
|
import path5 from "path";
|
|
15319
|
-
import
|
|
15998
|
+
import matter18 from "gray-matter";
|
|
15320
15999
|
var DeprecationWriteError = class extends Error {
|
|
15321
16000
|
constructor(code, message) {
|
|
15322
16001
|
super(message);
|
|
@@ -15334,7 +16013,7 @@ function atomicWrite4(filePath, content) {
|
|
|
15334
16013
|
fs6.renameSync(tmp, filePath);
|
|
15335
16014
|
}
|
|
15336
16015
|
function serialize3(data, body) {
|
|
15337
|
-
return
|
|
16016
|
+
return matter18.stringify(`
|
|
15338
16017
|
${body.trim()}
|
|
15339
16018
|
`, data);
|
|
15340
16019
|
}
|
|
@@ -15400,7 +16079,7 @@ function validateTargetInput(dir, raw) {
|
|
|
15400
16079
|
function loadPlanRaw(dir, planId) {
|
|
15401
16080
|
const match = allPlanArtifacts(dir).find((a) => a.id === planId || a.title === planId);
|
|
15402
16081
|
if (!match) throw new DeprecationWriteError("NOT_FOUND", `Deprecation Plan "${planId}" not found.`);
|
|
15403
|
-
const parsed =
|
|
16082
|
+
const parsed = matter18(readFile(match.filePath));
|
|
15404
16083
|
const data = { ...parsed.data ?? {} };
|
|
15405
16084
|
return { filePath: match.filePath, data, body: parsed.content.trim() };
|
|
15406
16085
|
}
|
|
@@ -15483,7 +16162,7 @@ function removeTarget(dir, planId, targetId, opts = {}) {
|
|
|
15483
16162
|
}
|
|
15484
16163
|
|
|
15485
16164
|
// src/core/deprecation-runbook.ts
|
|
15486
|
-
import
|
|
16165
|
+
import matter19 from "gray-matter";
|
|
15487
16166
|
var PRODUCTION_RUNBOOK_ARTIFACT_TYPE = "production-runbook";
|
|
15488
16167
|
var PRODUCTION_RUNBOOKS_DIR = "knowledge/delivery/runbooks";
|
|
15489
16168
|
var RUNBOOK_SECTIONS = [
|
|
@@ -15665,7 +16344,7 @@ function createProductionRunbook(dir, planId, targetId) {
|
|
|
15665
16344
|
if (!context.eligible) throw new ProductionRunbookError(context.blockers.join(" "));
|
|
15666
16345
|
const path8 = context.nextPath;
|
|
15667
16346
|
const id = path8.split("/").pop()?.match(/^(RB-\d+)-/)?.[1] ?? "";
|
|
15668
|
-
const content =
|
|
16347
|
+
const content = matter19.stringify(renderRunbook(context), {
|
|
15669
16348
|
id,
|
|
15670
16349
|
type: PRODUCTION_RUNBOOK_ARTIFACT_TYPE,
|
|
15671
16350
|
title: `Production runbook \u2014 ${context.target.title ?? context.target.id}`,
|
|
@@ -15692,7 +16371,7 @@ function getProductionRunbook(dir, id) {
|
|
|
15692
16371
|
for (const name of readDir(root)) {
|
|
15693
16372
|
if (!name.toLowerCase().startsWith(`${id.toLowerCase()}-`) || !name.endsWith(".md")) continue;
|
|
15694
16373
|
const path8 = `${PRODUCTION_RUNBOOKS_DIR}/${name}`;
|
|
15695
|
-
const parsed =
|
|
16374
|
+
const parsed = matter19(readFile(join(dir, path8)));
|
|
15696
16375
|
const data = parsed.data;
|
|
15697
16376
|
if (data.type !== PRODUCTION_RUNBOOK_ARTIFACT_TYPE) continue;
|
|
15698
16377
|
return {
|
|
@@ -15726,7 +16405,7 @@ import fs7 from "fs";
|
|
|
15726
16405
|
import path6 from "path";
|
|
15727
16406
|
|
|
15728
16407
|
// src/core/okf/mapping.ts
|
|
15729
|
-
import
|
|
16408
|
+
import matter20 from "gray-matter";
|
|
15730
16409
|
var OKF_TYPE_TABLE = {
|
|
15731
16410
|
"business-knowledge": "Business Knowledge",
|
|
15732
16411
|
"product-knowledge": "Product Knowledge",
|
|
@@ -15827,7 +16506,7 @@ function conceptId(a) {
|
|
|
15827
16506
|
}
|
|
15828
16507
|
function readBody2(a) {
|
|
15829
16508
|
try {
|
|
15830
|
-
const body =
|
|
16509
|
+
const body = matter20(readFile(a.filePath)).content.trim();
|
|
15831
16510
|
return body || null;
|
|
15832
16511
|
} catch {
|
|
15833
16512
|
return null;
|
|
@@ -16205,7 +16884,7 @@ ${c.body ?? ""}`;
|
|
|
16205
16884
|
// src/core/okf/validate.ts
|
|
16206
16885
|
import fs8 from "fs";
|
|
16207
16886
|
import path7 from "path";
|
|
16208
|
-
import
|
|
16887
|
+
import matter21 from "gray-matter";
|
|
16209
16888
|
function walk(root) {
|
|
16210
16889
|
const out = [];
|
|
16211
16890
|
const rec = (d) => {
|
|
@@ -16252,7 +16931,7 @@ function validateOkf(dir, opts = {}) {
|
|
|
16252
16931
|
const isIndex = path7.basename(file) === "index.md";
|
|
16253
16932
|
let data = {};
|
|
16254
16933
|
try {
|
|
16255
|
-
data =
|
|
16934
|
+
data = matter21(fs8.readFileSync(file, "utf-8")).data ?? {};
|
|
16256
16935
|
} catch {
|
|
16257
16936
|
findings.push({ level: "conformance", file: r, message: "Invalid YAML frontmatter." });
|
|
16258
16937
|
continue;
|
|
@@ -16274,7 +16953,7 @@ function validateOkf(dir, opts = {}) {
|
|
|
16274
16953
|
}
|
|
16275
16954
|
const body = (() => {
|
|
16276
16955
|
try {
|
|
16277
|
-
return
|
|
16956
|
+
return matter21(fs8.readFileSync(file, "utf-8")).content;
|
|
16278
16957
|
} catch {
|
|
16279
16958
|
return "";
|
|
16280
16959
|
}
|
|
@@ -16293,6 +16972,7 @@ function validateOkf(dir, opts = {}) {
|
|
|
16293
16972
|
}
|
|
16294
16973
|
export {
|
|
16295
16974
|
CANDIDATE_DISCOVERY_GUIDANCE,
|
|
16975
|
+
CONSOLIDATION_CATEGORIES,
|
|
16296
16976
|
CURRENT_CONSENT_VERSION,
|
|
16297
16977
|
DEPRECATION_ARTIFACT_TYPE,
|
|
16298
16978
|
DEPRECATION_PLANS_DIR,
|
|
@@ -16347,6 +17027,7 @@ export {
|
|
|
16347
17027
|
applyTopologyProposal,
|
|
16348
17028
|
associatedWorkItems,
|
|
16349
17029
|
buildConcept,
|
|
17030
|
+
buildConsolidationPlan,
|
|
16350
17031
|
buildDriftReport,
|
|
16351
17032
|
buildImpactReport,
|
|
16352
17033
|
buildImplementationHandoff,
|
|
@@ -16365,6 +17046,7 @@ export {
|
|
|
16365
17046
|
computeRefinementStatus,
|
|
16366
17047
|
conceptBundlePath,
|
|
16367
17048
|
consentNotice,
|
|
17049
|
+
consolidationPlanStaleness,
|
|
16368
17050
|
createInitiative,
|
|
16369
17051
|
createIntegration,
|
|
16370
17052
|
createPlan,
|
|
@@ -16473,10 +17155,12 @@ export {
|
|
|
16473
17155
|
redactSecrets,
|
|
16474
17156
|
removeIntegrationSecret,
|
|
16475
17157
|
removeTarget,
|
|
17158
|
+
renderConsolidationMarkdown,
|
|
16476
17159
|
renderDriftMarkdown,
|
|
16477
17160
|
renderImpactMarkdown,
|
|
16478
17161
|
renderSavingsMarkdown,
|
|
16479
17162
|
searchSystemNodes,
|
|
17163
|
+
serializeConsolidationJson,
|
|
16480
17164
|
serializeDriftJson,
|
|
16481
17165
|
serializeImpactJson,
|
|
16482
17166
|
serializeSavingsJson,
|