@kaddo/cli 3.24.0 → 3.25.0
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/README.md +1 -0
- package/dist/index.js +378 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -514,6 +514,7 @@ create --from roadmap → owners → guard → explain`.
|
|
|
514
514
|
| v3.23.1 | Impact report Actionable Gaps: per-Work-Item missing source/initiative/ownership/level/acceptance/DoD/validation, broad globs, overlaps; Work-Item-specific Suggested Actions + Score Breakdown |
|
|
515
515
|
| v3.23.2 | Impact report defaults to `all` scope (accumulated impact), graph built in memory; `--scope active`; `scope_source`/`default_scope` in JSON |
|
|
516
516
|
| v3.24 | Estimated Savings Model: `kaddo savings` (+ `savings init`, `.kaddo/savings.yml`); evidence-based time/value estimates, confidence; MCP resource + tool |
|
|
517
|
+
| v3.25 | Guard history & drift trend: `kaddo guard --record`, `kaddo drift`; feeds impact Guard Activity + savings Drift Prevention; MCP drift/guard-history resources + tool |
|
|
517
518
|
|
|
518
519
|
**Optional modules (installed with `kaddo add`):**
|
|
519
520
|
|
package/dist/index.js
CHANGED
|
@@ -692,6 +692,10 @@ var COMMAND_HELP = {
|
|
|
692
692
|
savings: {
|
|
693
693
|
question: "How much time/value might Kaddo be saving (estimate)?",
|
|
694
694
|
next: "Run `kaddo savings init` to calibrate assumptions"
|
|
695
|
+
},
|
|
696
|
+
drift: {
|
|
697
|
+
question: "Are code and knowledge drifting apart over time?",
|
|
698
|
+
next: "Review open warnings; `kaddo guard --record` before commits"
|
|
695
699
|
}
|
|
696
700
|
};
|
|
697
701
|
function commandFooterLines(name) {
|
|
@@ -5467,6 +5471,162 @@ function collectMatchedDomains(matchedArtifactDomains) {
|
|
|
5467
5471
|
return [...seen];
|
|
5468
5472
|
}
|
|
5469
5473
|
|
|
5474
|
+
// src/core/guard-history.ts
|
|
5475
|
+
import fs2 from "fs";
|
|
5476
|
+
var HISTORY_DIR = ".kaddo/history";
|
|
5477
|
+
var RUNS_PATH = `${HISTORY_DIR}/guard-runs.jsonl`;
|
|
5478
|
+
var SUMMARY_PATH = `${HISTORY_DIR}/guard-summary.json`;
|
|
5479
|
+
function toPosix3(p2) {
|
|
5480
|
+
return p2.replace(/\\/g, "/");
|
|
5481
|
+
}
|
|
5482
|
+
function loadGuardRuns(dir) {
|
|
5483
|
+
const p2 = join(dir, RUNS_PATH);
|
|
5484
|
+
if (!exists(p2)) return [];
|
|
5485
|
+
const out = [];
|
|
5486
|
+
for (const line of readFile(p2).split(/\r?\n/)) {
|
|
5487
|
+
const t = line.trim();
|
|
5488
|
+
if (!t) continue;
|
|
5489
|
+
try {
|
|
5490
|
+
out.push(JSON.parse(t));
|
|
5491
|
+
} catch {
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
return out;
|
|
5495
|
+
}
|
|
5496
|
+
function resolveDriftThreads(runs) {
|
|
5497
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
5498
|
+
const paths = /* @__PURE__ */ new Set();
|
|
5499
|
+
for (const r of sorted) for (const w of r.warnings) paths.add(w.code_path);
|
|
5500
|
+
const threads = [];
|
|
5501
|
+
for (const codePath of paths) {
|
|
5502
|
+
const related = /* @__PURE__ */ new Set();
|
|
5503
|
+
let firstDetected = "";
|
|
5504
|
+
let lastWarn = "";
|
|
5505
|
+
for (const r of sorted) {
|
|
5506
|
+
const w = r.warnings.find((x) => x.code_path === codePath);
|
|
5507
|
+
if (w) {
|
|
5508
|
+
if (!firstDetected) firstDetected = r.generated_at;
|
|
5509
|
+
lastWarn = r.generated_at;
|
|
5510
|
+
for (const a of w.related_artifacts) related.add(a);
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
let resolvedAt;
|
|
5514
|
+
for (const r of sorted) {
|
|
5515
|
+
if (r.generated_at <= lastWarn) continue;
|
|
5516
|
+
const touched = r.touched_files.some((f) => toPosix3(f) === codePath);
|
|
5517
|
+
const warnedHere = r.warnings.some((x) => x.code_path === codePath);
|
|
5518
|
+
const updatedRelated = r.updated_artifacts.some((a) => related.has(a));
|
|
5519
|
+
if (touched && updatedRelated && !warnedHere) {
|
|
5520
|
+
resolvedAt = r.generated_at;
|
|
5521
|
+
break;
|
|
5522
|
+
}
|
|
5523
|
+
}
|
|
5524
|
+
threads.push({
|
|
5525
|
+
code_path: codePath,
|
|
5526
|
+
related_artifacts: [...related],
|
|
5527
|
+
first_detected: firstDetected,
|
|
5528
|
+
last_seen: lastWarn,
|
|
5529
|
+
status: resolvedAt ? "resolved" : "open",
|
|
5530
|
+
...resolvedAt ? { resolved_at: resolvedAt } : {}
|
|
5531
|
+
});
|
|
5532
|
+
}
|
|
5533
|
+
return threads;
|
|
5534
|
+
}
|
|
5535
|
+
function hotspotDir(codePath) {
|
|
5536
|
+
const i = codePath.lastIndexOf("/");
|
|
5537
|
+
return i >= 0 ? codePath.slice(0, i + 1) : codePath;
|
|
5538
|
+
}
|
|
5539
|
+
function computeTrend(runs) {
|
|
5540
|
+
if (runs.length < 2) return { direction: "unknown", reason: "Not enough recorded runs to detect a trend." };
|
|
5541
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
5542
|
+
const mid = Math.floor(sorted.length / 2);
|
|
5543
|
+
const avg = (arr) => arr.length ? arr.reduce((s, r) => s + r.warnings.length, 0) / arr.length : 0;
|
|
5544
|
+
const earlier = avg(sorted.slice(0, mid));
|
|
5545
|
+
const recent = avg(sorted.slice(mid));
|
|
5546
|
+
if (recent < earlier) return { direction: "improving", reason: "Fewer warnings in the last recorded runs." };
|
|
5547
|
+
if (recent > earlier) return { direction: "worsening", reason: "More warnings in the last recorded runs." };
|
|
5548
|
+
return { direction: "stable", reason: "Warning volume is roughly stable across recorded runs." };
|
|
5549
|
+
}
|
|
5550
|
+
function buildGuardHistory(dir) {
|
|
5551
|
+
const runs = loadGuardRuns(dir);
|
|
5552
|
+
if (runs.length === 0) {
|
|
5553
|
+
return {
|
|
5554
|
+
available: false,
|
|
5555
|
+
total_runs: 0,
|
|
5556
|
+
first_run: null,
|
|
5557
|
+
last_run: null,
|
|
5558
|
+
runs_with_warnings: 0,
|
|
5559
|
+
runs_clean: 0,
|
|
5560
|
+
detected: 0,
|
|
5561
|
+
open: 0,
|
|
5562
|
+
resolved: 0,
|
|
5563
|
+
resolution_rate: 0,
|
|
5564
|
+
threads: [],
|
|
5565
|
+
hotspots: [],
|
|
5566
|
+
trend: { direction: "unknown", reason: "No guard history recorded yet." }
|
|
5567
|
+
};
|
|
5568
|
+
}
|
|
5569
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
5570
|
+
const threads = resolveDriftThreads(sorted);
|
|
5571
|
+
const open = threads.filter((t) => t.status === "open").length;
|
|
5572
|
+
const resolved = threads.filter((t) => t.status === "resolved").length;
|
|
5573
|
+
const detected = threads.length;
|
|
5574
|
+
const runsWithWarnings = sorted.filter((r) => r.warnings.length > 0).length;
|
|
5575
|
+
const hotspotMap = /* @__PURE__ */ new Map();
|
|
5576
|
+
for (const t of threads) {
|
|
5577
|
+
const d = hotspotDir(t.code_path);
|
|
5578
|
+
hotspotMap.set(d, (hotspotMap.get(d) ?? 0) + 1);
|
|
5579
|
+
}
|
|
5580
|
+
const hotspots = [...hotspotMap.entries()].map(([path6, warnings]) => ({ path: path6, warnings })).sort((a, b) => b.warnings - a.warnings);
|
|
5581
|
+
return {
|
|
5582
|
+
available: true,
|
|
5583
|
+
total_runs: sorted.length,
|
|
5584
|
+
first_run: sorted[0].generated_at,
|
|
5585
|
+
last_run: sorted[sorted.length - 1].generated_at,
|
|
5586
|
+
runs_with_warnings: runsWithWarnings,
|
|
5587
|
+
runs_clean: sorted.length - runsWithWarnings,
|
|
5588
|
+
detected,
|
|
5589
|
+
open,
|
|
5590
|
+
resolved,
|
|
5591
|
+
resolution_rate: detected > 0 ? Math.round(resolved / detected * 1e3) / 10 : 0,
|
|
5592
|
+
threads,
|
|
5593
|
+
hotspots,
|
|
5594
|
+
trend: computeTrend(sorted)
|
|
5595
|
+
};
|
|
5596
|
+
}
|
|
5597
|
+
function recordGuardRun(dir, input, now = /* @__PURE__ */ new Date()) {
|
|
5598
|
+
const iso = now.toISOString();
|
|
5599
|
+
const run = {
|
|
5600
|
+
run_id: `guard-${iso.replace(/[:.]/g, "-")}`,
|
|
5601
|
+
generated_at: iso,
|
|
5602
|
+
project: input.project,
|
|
5603
|
+
scope: input.scope,
|
|
5604
|
+
touched_files: input.touched_files,
|
|
5605
|
+
matched_artifacts: input.matched_artifacts,
|
|
5606
|
+
updated_artifacts: input.updated_artifacts,
|
|
5607
|
+
warnings: input.warnings,
|
|
5608
|
+
summary: {
|
|
5609
|
+
touched_files: input.touched_files.length,
|
|
5610
|
+
matched_artifacts: input.matched_artifacts.length,
|
|
5611
|
+
warnings: input.warnings.length
|
|
5612
|
+
}
|
|
5613
|
+
};
|
|
5614
|
+
const runsAbs = join(dir, RUNS_PATH);
|
|
5615
|
+
fs2.mkdirSync(join(dir, HISTORY_DIR), { recursive: true });
|
|
5616
|
+
fs2.appendFileSync(runsAbs, JSON.stringify(run) + "\n", "utf-8");
|
|
5617
|
+
const history = buildGuardHistory(dir);
|
|
5618
|
+
const summary = {
|
|
5619
|
+
generated_at: iso,
|
|
5620
|
+
total_runs: history.total_runs,
|
|
5621
|
+
total_warnings: history.detected,
|
|
5622
|
+
open_warnings: history.open,
|
|
5623
|
+
resolved_warnings: history.resolved,
|
|
5624
|
+
last_run_id: run.run_id
|
|
5625
|
+
};
|
|
5626
|
+
writeFile(join(dir, SUMMARY_PATH), JSON.stringify(summary, null, 2) + "\n");
|
|
5627
|
+
return { run, runsPath: RUNS_PATH, summaryPath: SUMMARY_PATH };
|
|
5628
|
+
}
|
|
5629
|
+
|
|
5470
5630
|
// src/commands/guard.ts
|
|
5471
5631
|
var ARCH_DIR3 = "knowledge";
|
|
5472
5632
|
var CONFIG_PATH2 = ".kaddo/config.yml";
|
|
@@ -5669,6 +5829,47 @@ async function runGuard(opts = {}) {
|
|
|
5669
5829
|
const activeMatches = fyiMatches.filter(
|
|
5670
5830
|
(m) => !isIgnored(ignores, m.artifact.id || m.artifact.title)
|
|
5671
5831
|
);
|
|
5832
|
+
if (opts.record) {
|
|
5833
|
+
const idOf = (m) => m.artifact.id || m.artifact.title;
|
|
5834
|
+
const matchedArtifacts = [...new Set(result.matches.map(idOf))];
|
|
5835
|
+
const updatedArtifacts = [...new Set(result.matches.filter((m) => m.artifactWasModified).map(idOf))];
|
|
5836
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
5837
|
+
for (const m of result.matches) {
|
|
5838
|
+
for (const f of m.matchedFiles) {
|
|
5839
|
+
const e = byPath.get(f) ?? { related: /* @__PURE__ */ new Set(), updated: /* @__PURE__ */ new Set() };
|
|
5840
|
+
e.related.add(idOf(m));
|
|
5841
|
+
if (m.artifactWasModified) e.updated.add(idOf(m));
|
|
5842
|
+
byPath.set(f, e);
|
|
5843
|
+
}
|
|
5844
|
+
}
|
|
5845
|
+
const warnings = [];
|
|
5846
|
+
for (const [code_path, e] of byPath) {
|
|
5847
|
+
if ([...e.related].some((a) => !e.updated.has(a))) {
|
|
5848
|
+
warnings.push({
|
|
5849
|
+
type: "possible-knowledge-drift",
|
|
5850
|
+
code_path,
|
|
5851
|
+
related_artifacts: [...e.related],
|
|
5852
|
+
updated_artifacts: [...e.updated],
|
|
5853
|
+
status: "open"
|
|
5854
|
+
});
|
|
5855
|
+
}
|
|
5856
|
+
}
|
|
5857
|
+
const project = loadConfig(dir)?.project.name ?? "unknown";
|
|
5858
|
+
const rec = recordGuardRun(dir, {
|
|
5859
|
+
project,
|
|
5860
|
+
scope: includeArchived ? "active-completed-archived" : "active-and-completed",
|
|
5861
|
+
touched_files: touchedFiles,
|
|
5862
|
+
matched_artifacts: matchedArtifacts,
|
|
5863
|
+
updated_artifacts: updatedArtifacts,
|
|
5864
|
+
warnings
|
|
5865
|
+
});
|
|
5866
|
+
if (!jsonMode) {
|
|
5867
|
+
console.log("");
|
|
5868
|
+
console.log("Guard run recorded:");
|
|
5869
|
+
console.log(`- ${rec.runsPath}`);
|
|
5870
|
+
console.log(`- ${rec.summaryPath}`);
|
|
5871
|
+
}
|
|
5872
|
+
}
|
|
5672
5873
|
if (jsonMode) {
|
|
5673
5874
|
const ownerMapCI = loadOwners(dir);
|
|
5674
5875
|
const matchedDomainsCI = collectMatchedDomains(activeMatches.map((m) => m.artifact.domains));
|
|
@@ -6106,14 +6307,14 @@ var ALL_STATUSES = ["draft", "ready", "in-progress", "blocked", "completed"];
|
|
|
6106
6307
|
function scopeStatuses(scope) {
|
|
6107
6308
|
return scope === "all" ? { included: ALL_STATUSES, excluded: ["archived"] } : { included: ACTIVE_STATUSES, excluded: ["completed", "archived"] };
|
|
6108
6309
|
}
|
|
6109
|
-
function
|
|
6310
|
+
function toPosix4(p2) {
|
|
6110
6311
|
return p2.replace(/\\/g, "/");
|
|
6111
6312
|
}
|
|
6112
6313
|
function slug(s) {
|
|
6113
6314
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6114
6315
|
}
|
|
6115
6316
|
function isAdr(a) {
|
|
6116
|
-
return
|
|
6317
|
+
return toPosix4(a.filePath).includes("/tech/decisions/") && Boolean(a.type);
|
|
6117
6318
|
}
|
|
6118
6319
|
function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
6119
6320
|
const scope = opts.scope ?? "active";
|
|
@@ -6298,14 +6499,14 @@ function loadGraphSummary(dir) {
|
|
|
6298
6499
|
|
|
6299
6500
|
// src/core/graph-hints.ts
|
|
6300
6501
|
var KNOWLEDGE3 = "knowledge";
|
|
6301
|
-
function
|
|
6502
|
+
function toPosix5(p2) {
|
|
6302
6503
|
return p2.replace(/\\/g, "/");
|
|
6303
6504
|
}
|
|
6304
6505
|
function slug2(s) {
|
|
6305
6506
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6306
6507
|
}
|
|
6307
6508
|
function isAdr2(a) {
|
|
6308
|
-
return
|
|
6509
|
+
return toPosix5(a.filePath).includes("/tech/decisions/") && Boolean(a.type);
|
|
6309
6510
|
}
|
|
6310
6511
|
function capabilityHeadings(dir) {
|
|
6311
6512
|
const p2 = join(dir, KNOWLEDGE3, "product", "capabilities.md");
|
|
@@ -11172,10 +11373,10 @@ function buildImpactReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11172
11373
|
ready_quality: byState.ready > 0 ? `${byState.ready} ready` : "not applicable"
|
|
11173
11374
|
},
|
|
11174
11375
|
graph_quality: g.available ? { available: true, scope: g.scope, quality: g.quality, nodes: g.nodes, edges: g.edges, hints: g.hints, reason: g.scopeReason, last_exported: g.generatedAt } : { available: false, suggestion: "Run `kaddo graph export --scope all`." },
|
|
11175
|
-
guard_activity: {
|
|
11176
|
-
|
|
11177
|
-
note: "Guard history is not persisted. Run `kaddo guard` to
|
|
11178
|
-
},
|
|
11376
|
+
guard_activity: (() => {
|
|
11377
|
+
const gh = buildGuardHistory(dir);
|
|
11378
|
+
return gh.available ? { available: true, runs_recorded: gh.total_runs, detected: gh.detected, open: gh.open, resolved: gh.resolved, resolution_rate: gh.resolution_rate } : { available: false, note: "Guard history is not persisted. Run `kaddo guard --record` to record runs for trend analysis." };
|
|
11379
|
+
})(),
|
|
11179
11380
|
impact_signals,
|
|
11180
11381
|
actionable_gaps: gaps,
|
|
11181
11382
|
score,
|
|
@@ -11264,8 +11465,18 @@ function renderImpactMarkdown(r) {
|
|
|
11264
11465
|
}
|
|
11265
11466
|
L.push("");
|
|
11266
11467
|
L.push("## Guard Activity", "");
|
|
11267
|
-
|
|
11268
|
-
|
|
11468
|
+
if (r.guard_activity.available) {
|
|
11469
|
+
const ga = r.guard_activity;
|
|
11470
|
+
L.push("- Guard history: available");
|
|
11471
|
+
L.push(`- Guard runs recorded: ${ga.runs_recorded}`);
|
|
11472
|
+
L.push(`- Drift warnings detected: ${ga.detected}`);
|
|
11473
|
+
L.push(`- Open warnings: ${ga.open}`);
|
|
11474
|
+
L.push(`- Resolved warnings: ${ga.resolved}`);
|
|
11475
|
+
L.push(`- Resolution rate: ${ga.resolution_rate}%`);
|
|
11476
|
+
} else {
|
|
11477
|
+
L.push("- Guard history: not available");
|
|
11478
|
+
L.push(`- Note: ${r.guard_activity.note}`);
|
|
11479
|
+
}
|
|
11269
11480
|
L.push("");
|
|
11270
11481
|
L.push("## Impact Signals", "");
|
|
11271
11482
|
const s = r.impact_signals;
|
|
@@ -11444,18 +11655,28 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11444
11655
|
const onboardH = round2(a.expected_new_contributors_per_month * a.onboarding_hours_saved_per_new_contributor * readinessMult);
|
|
11445
11656
|
const graphMult = GRAPH_MULT[graphQuality] ?? 0;
|
|
11446
11657
|
const archH = round2(a.architecture_discovery_hours_saved_when_graph_good * graphMult);
|
|
11447
|
-
const
|
|
11658
|
+
const guard = buildGuardHistory(dir);
|
|
11659
|
+
const driftSavings = guard.available && guard.resolved > 0 ? {
|
|
11660
|
+
available: true,
|
|
11661
|
+
hours: round2(guard.resolved * a.rework_hours_avoided_per_resolved_drift),
|
|
11662
|
+
formula: `${guard.resolved} resolved drift warnings \xD7 ${a.rework_hours_avoided_per_resolved_drift} h`
|
|
11663
|
+
} : { available: false, hours: 0, reason: "Guard history is not persisted yet." };
|
|
11664
|
+
const totalHours = round2(ctxPrepH + reviewH + clarH + onboardH + archH + driftSavings.hours);
|
|
11448
11665
|
const totalValue = Math.round(totalHours * a.hourly_cost);
|
|
11449
11666
|
const reasons = [];
|
|
11450
11667
|
let level;
|
|
11451
11668
|
if (impact.score === null || impact.score < 60 || graphQuality === "empty") {
|
|
11452
11669
|
level = "Low";
|
|
11453
11670
|
reasons.push("Impact score is low or the knowledge graph is empty.");
|
|
11671
|
+
} else if (impact.score >= 85 && graphQuality === "good" && source === "file" && guard.available && guard.resolved > 0) {
|
|
11672
|
+
level = "High";
|
|
11673
|
+
reasons.push("Strong evidence, custom assumptions and recorded drift resolution.");
|
|
11454
11674
|
} else {
|
|
11455
11675
|
level = "Medium";
|
|
11456
11676
|
reasons.push("Strong knowledge and graph evidence.");
|
|
11457
11677
|
}
|
|
11458
|
-
reasons.push("Guard history is not persisted yet \u2014 avoided rework is not estimated.");
|
|
11678
|
+
if (!guard.available) reasons.push("Guard history is not persisted yet \u2014 avoided rework is not estimated.");
|
|
11679
|
+
else reasons.push(`Guard history available (${guard.resolved} resolved drift warning(s)).`);
|
|
11459
11680
|
reasons.push(source === "file" ? "Assumptions come from `.kaddo/savings.yml`." : "Savings assumptions are defaults and should be calibrated.");
|
|
11460
11681
|
const actions = [];
|
|
11461
11682
|
if (source === "default") actions.push("Run `kaddo savings init` to customize assumptions.");
|
|
@@ -11488,7 +11709,7 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11488
11709
|
graph_nodes: impact.graph_quality.available ? impact.graph_quality.nodes : null,
|
|
11489
11710
|
graph_edges: impact.graph_quality.available ? impact.graph_quality.edges : null,
|
|
11490
11711
|
context_readiness: readiness,
|
|
11491
|
-
guard_history_available:
|
|
11712
|
+
guard_history_available: guard.available
|
|
11492
11713
|
},
|
|
11493
11714
|
estimated_savings: {
|
|
11494
11715
|
context_preparation: { hours: ctxPrepH, formula: `${completed} Work Items \xD7 ${a.context_preparation_minutes_saved_per_work_item} min` },
|
|
@@ -11496,7 +11717,7 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11496
11717
|
clarification_reduction: { hours: clarH, formula: `${wiWithAcceptance} Work Items with Acceptance Criteria \xD7 ${a.clarification_minutes_saved_per_ready_work_item} min` },
|
|
11497
11718
|
onboarding: { hours: onboardH, formula: `${a.expected_new_contributors_per_month} contributor \xD7 ${a.onboarding_hours_saved_per_new_contributor} h \xD7 ${readinessMult.toFixed(2)} readiness multiplier` },
|
|
11498
11719
|
architecture_discovery: { hours: archH, formula: `${a.architecture_discovery_hours_saved_when_graph_good} h \xD7 ${graphMult.toFixed(2)} graph multiplier` },
|
|
11499
|
-
drift_prevention:
|
|
11720
|
+
drift_prevention: driftSavings
|
|
11500
11721
|
},
|
|
11501
11722
|
total: { estimated_hours_saved: totalHours, estimated_value: totalValue, currency: a.currency },
|
|
11502
11723
|
confidence: { level, reasons },
|
|
@@ -11553,8 +11774,13 @@ function renderSavingsMarkdown(r) {
|
|
|
11553
11774
|
line("Onboarding", s.onboarding);
|
|
11554
11775
|
line("Architecture Discovery", s.architecture_discovery);
|
|
11555
11776
|
L.push("### Drift Prevention", "");
|
|
11556
|
-
|
|
11557
|
-
|
|
11777
|
+
if (s.drift_prevention.available) {
|
|
11778
|
+
L.push(`- Formula: ${s.drift_prevention.formula}`);
|
|
11779
|
+
L.push(`- Estimated: ${s.drift_prevention.hours} h`, "");
|
|
11780
|
+
} else {
|
|
11781
|
+
L.push("- Not available yet.");
|
|
11782
|
+
L.push(`- Reason: ${s.drift_prevention.reason}`, "");
|
|
11783
|
+
}
|
|
11558
11784
|
L.push("## Total", "");
|
|
11559
11785
|
L.push(`- Estimated time saved: ${r.total.estimated_hours_saved} h`);
|
|
11560
11786
|
L.push(`- Estimated value: ${r.total.estimated_value} ${r.currency}`);
|
|
@@ -11606,6 +11832,135 @@ function runSavingsInit(opts = {}) {
|
|
|
11606
11832
|
outro2("Savings assumptions ready.");
|
|
11607
11833
|
}
|
|
11608
11834
|
|
|
11835
|
+
// src/core/drift-report.ts
|
|
11836
|
+
function buildDriftReport(dir, now = /* @__PURE__ */ new Date()) {
|
|
11837
|
+
const h = buildGuardHistory(dir);
|
|
11838
|
+
const project = loadConfig(dir)?.project.name ?? "unknown";
|
|
11839
|
+
const actions = [];
|
|
11840
|
+
if (!h.available) {
|
|
11841
|
+
actions.push("Run `kaddo guard --record` to start recording guard history.");
|
|
11842
|
+
} else {
|
|
11843
|
+
if (h.open > 0) actions.push("Review open drift warnings and update related Work Items or ownership.");
|
|
11844
|
+
actions.push("Run `kaddo guard --record` before important commits.");
|
|
11845
|
+
actions.push("Use this report to calibrate estimated drift-prevention savings.");
|
|
11846
|
+
}
|
|
11847
|
+
return {
|
|
11848
|
+
generated_at: now.toISOString(),
|
|
11849
|
+
project,
|
|
11850
|
+
guard_history: {
|
|
11851
|
+
available: h.available,
|
|
11852
|
+
total_runs: h.total_runs,
|
|
11853
|
+
first_run: h.first_run,
|
|
11854
|
+
last_run: h.last_run,
|
|
11855
|
+
runs_with_warnings: h.runs_with_warnings,
|
|
11856
|
+
runs_clean: h.runs_clean
|
|
11857
|
+
},
|
|
11858
|
+
drift_warnings: { detected: h.detected, open: h.open, resolved: h.resolved, resolution_rate: h.resolution_rate },
|
|
11859
|
+
hotspots: h.hotspots,
|
|
11860
|
+
trend: h.trend,
|
|
11861
|
+
threads: h.threads,
|
|
11862
|
+
suggested_actions: actions
|
|
11863
|
+
};
|
|
11864
|
+
}
|
|
11865
|
+
function renderDriftMarkdown(r) {
|
|
11866
|
+
const L = [];
|
|
11867
|
+
L.push("# Kaddo Drift Trend Report", "");
|
|
11868
|
+
L.push(`Generated at: ${r.generated_at}`);
|
|
11869
|
+
L.push(`Project: ${r.project}`);
|
|
11870
|
+
L.push("");
|
|
11871
|
+
if (!r.guard_history.available) {
|
|
11872
|
+
L.push("## Guard History", "");
|
|
11873
|
+
L.push("No guard history recorded yet.");
|
|
11874
|
+
L.push("");
|
|
11875
|
+
L.push("Run `kaddo guard --record` to start recording drift evidence.");
|
|
11876
|
+
L.push("");
|
|
11877
|
+
L.push("## Suggested Actions", "");
|
|
11878
|
+
r.suggested_actions.forEach((a, i) => L.push(`${i + 1}. ${a}`));
|
|
11879
|
+
L.push("");
|
|
11880
|
+
return L.join("\n");
|
|
11881
|
+
}
|
|
11882
|
+
const w = r.drift_warnings;
|
|
11883
|
+
L.push("## Executive Summary", "");
|
|
11884
|
+
L.push(`- Guard runs recorded: ${r.guard_history.total_runs}`);
|
|
11885
|
+
L.push(`- Drift warnings detected: ${w.detected}`);
|
|
11886
|
+
L.push(`- Open warnings: ${w.open}`);
|
|
11887
|
+
L.push(`- Resolved warnings: ${w.resolved}`);
|
|
11888
|
+
L.push(`- Resolution rate: ${w.resolution_rate}%`);
|
|
11889
|
+
if (r.hotspots.length > 0) L.push(`- Most affected area: ${r.hotspots[0].path}`);
|
|
11890
|
+
L.push("");
|
|
11891
|
+
L.push("## Guard History", "");
|
|
11892
|
+
L.push(`- First run: ${r.guard_history.first_run}`);
|
|
11893
|
+
L.push(`- Last run: ${r.guard_history.last_run}`);
|
|
11894
|
+
L.push(`- Runs with warnings: ${r.guard_history.runs_with_warnings}/${r.guard_history.total_runs}`);
|
|
11895
|
+
L.push(`- Runs clean: ${r.guard_history.runs_clean}/${r.guard_history.total_runs}`);
|
|
11896
|
+
L.push("");
|
|
11897
|
+
L.push("## Drift Warnings", "");
|
|
11898
|
+
const open = r.threads.filter((t) => t.status === "open");
|
|
11899
|
+
const resolved = r.threads.filter((t) => t.status === "resolved");
|
|
11900
|
+
L.push("### Open", "");
|
|
11901
|
+
if (open.length === 0) L.push("_None._", "");
|
|
11902
|
+
for (const t of open) {
|
|
11903
|
+
L.push(`- ${t.code_path}`);
|
|
11904
|
+
L.push(` - Related artifacts: ${t.related_artifacts.join(", ") || "\u2014"}`);
|
|
11905
|
+
L.push(` - First detected: ${t.first_detected}`);
|
|
11906
|
+
L.push(` - Last seen: ${t.last_seen}`);
|
|
11907
|
+
L.push(" - Status: open");
|
|
11908
|
+
}
|
|
11909
|
+
L.push("");
|
|
11910
|
+
L.push("### Resolved", "");
|
|
11911
|
+
if (resolved.length === 0) L.push("_None._", "");
|
|
11912
|
+
for (const t of resolved) {
|
|
11913
|
+
L.push(`- ${t.code_path}`);
|
|
11914
|
+
L.push(` - Related artifacts: ${t.related_artifacts.join(", ") || "\u2014"}`);
|
|
11915
|
+
L.push(` - First detected: ${t.first_detected}`);
|
|
11916
|
+
L.push(` - Resolved at: ${t.resolved_at}`);
|
|
11917
|
+
L.push(" - Status: resolved");
|
|
11918
|
+
}
|
|
11919
|
+
L.push("");
|
|
11920
|
+
L.push("## Hotspots", "");
|
|
11921
|
+
if (r.hotspots.length === 0) L.push("_None._");
|
|
11922
|
+
for (const h of r.hotspots) L.push(`- ${h.path}: ${h.warnings} warning(s)`);
|
|
11923
|
+
L.push("");
|
|
11924
|
+
L.push("## Trend", "");
|
|
11925
|
+
L.push(`- Recent direction: ${r.trend.direction}`);
|
|
11926
|
+
L.push(`- Reason: ${r.trend.reason}`);
|
|
11927
|
+
L.push("");
|
|
11928
|
+
L.push("## Suggested Actions", "");
|
|
11929
|
+
r.suggested_actions.forEach((a, i) => L.push(`${i + 1}. ${a}`));
|
|
11930
|
+
L.push("");
|
|
11931
|
+
return L.join("\n");
|
|
11932
|
+
}
|
|
11933
|
+
function serializeDriftJson(r) {
|
|
11934
|
+
const out = {
|
|
11935
|
+
generated_at: r.generated_at,
|
|
11936
|
+
project: r.project,
|
|
11937
|
+
guard_history: r.guard_history,
|
|
11938
|
+
drift_warnings: r.drift_warnings,
|
|
11939
|
+
hotspots: r.hotspots,
|
|
11940
|
+
trend: r.trend,
|
|
11941
|
+
threads: r.threads,
|
|
11942
|
+
suggested_actions: r.suggested_actions
|
|
11943
|
+
};
|
|
11944
|
+
return JSON.stringify(out, null, 2) + "\n";
|
|
11945
|
+
}
|
|
11946
|
+
|
|
11947
|
+
// src/commands/drift.ts
|
|
11948
|
+
function runDrift(opts = {}) {
|
|
11949
|
+
const dir = cwd();
|
|
11950
|
+
requireConfig(dir);
|
|
11951
|
+
const report = buildDriftReport(dir);
|
|
11952
|
+
const content = opts.json ? serializeDriftJson(report) : renderDriftMarkdown(report);
|
|
11953
|
+
if (opts.output) {
|
|
11954
|
+
intro2("kaddo drift");
|
|
11955
|
+
writeFile(join(dir, opts.output), content);
|
|
11956
|
+
log2.success(`Wrote ${opts.output.replace(/\\/g, "/")}`);
|
|
11957
|
+
printCommandFooter("drift");
|
|
11958
|
+
outro2("Drift report written.");
|
|
11959
|
+
return;
|
|
11960
|
+
}
|
|
11961
|
+
console.log(content);
|
|
11962
|
+
}
|
|
11963
|
+
|
|
11609
11964
|
// src/index.ts
|
|
11610
11965
|
var require2 = createRequire(import.meta.url);
|
|
11611
11966
|
var { version } = require2("../package.json");
|
|
@@ -11650,7 +12005,13 @@ var savingsCmd = program.command("savings").description("Estimated Savings Repor
|
|
|
11650
12005
|
savingsCmd.command("init").description("Create an editable `.kaddo/savings.yml` with savings assumptions").option("--force", "Overwrite an existing .kaddo/savings.yml").action((opts) => {
|
|
11651
12006
|
runSavingsInit(opts);
|
|
11652
12007
|
});
|
|
11653
|
-
|
|
12008
|
+
reportCmd.command("drift").description("Drift Trend Report from recorded guard history (deterministic, no LLM)").option("--json", "Output JSON instead of Markdown").option("--output <path>", "Write the report to a file (e.g. .kaddo/reports/drift-report.md)").action((opts) => {
|
|
12009
|
+
runDrift(opts);
|
|
12010
|
+
});
|
|
12011
|
+
program.command("drift").description("Drift Trend Report from recorded `kaddo guard --record` history").option("--json", "Output JSON instead of Markdown").option("--output <path>", "Write the report to a file").action((opts) => {
|
|
12012
|
+
runDrift(opts);
|
|
12013
|
+
});
|
|
12014
|
+
program.command("guard").description("Check if modified code has related artifacts that were not updated").option("--staged", "Check only staged files").option("--no-interactive", "Disable interactive ignore prompts").option("--ci", "CI mode: output JSON, no prompts, non-blocking").option("--json", "Output JSON (alias for --ci)").option("--workspace", "Also check local mapped module repos from .kaddo/modules.yml (opt-in)").option("--include-archived", "Include archived Work Items in ownership matching (excluded by default)").option("--record", "Record this run to .kaddo/history/ for drift trend reporting").action(async (opts) => {
|
|
11654
12015
|
await runGuard(opts);
|
|
11655
12016
|
});
|
|
11656
12017
|
var ignoreCmd = program.command("ignore").description("Manage guard ignore list");
|