@kaddo/mcp 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/dist/index.js +327 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2086,6 +2086,129 @@ function renderExplanationAgent(exp) {
|
|
|
2086
2086
|
return JSON.stringify({ ...rest, mapped_modules: mappedModules }, null, 2) + "\n";
|
|
2087
2087
|
}
|
|
2088
2088
|
|
|
2089
|
+
// ../cli/src/core/guard-history.ts
|
|
2090
|
+
var HISTORY_DIR = ".kaddo/history";
|
|
2091
|
+
var RUNS_PATH = `${HISTORY_DIR}/guard-runs.jsonl`;
|
|
2092
|
+
var SUMMARY_PATH = `${HISTORY_DIR}/guard-summary.json`;
|
|
2093
|
+
function toPosix5(p) {
|
|
2094
|
+
return p.replace(/\\/g, "/");
|
|
2095
|
+
}
|
|
2096
|
+
function loadGuardRuns(dir) {
|
|
2097
|
+
const p = join(dir, RUNS_PATH);
|
|
2098
|
+
if (!exists(p)) return [];
|
|
2099
|
+
const out = [];
|
|
2100
|
+
for (const line of readFile(p).split(/\r?\n/)) {
|
|
2101
|
+
const t = line.trim();
|
|
2102
|
+
if (!t) continue;
|
|
2103
|
+
try {
|
|
2104
|
+
out.push(JSON.parse(t));
|
|
2105
|
+
} catch {
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
return out;
|
|
2109
|
+
}
|
|
2110
|
+
function resolveDriftThreads(runs) {
|
|
2111
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
2112
|
+
const paths = /* @__PURE__ */ new Set();
|
|
2113
|
+
for (const r of sorted) for (const w of r.warnings) paths.add(w.code_path);
|
|
2114
|
+
const threads = [];
|
|
2115
|
+
for (const codePath of paths) {
|
|
2116
|
+
const related = /* @__PURE__ */ new Set();
|
|
2117
|
+
let firstDetected = "";
|
|
2118
|
+
let lastWarn = "";
|
|
2119
|
+
for (const r of sorted) {
|
|
2120
|
+
const w = r.warnings.find((x) => x.code_path === codePath);
|
|
2121
|
+
if (w) {
|
|
2122
|
+
if (!firstDetected) firstDetected = r.generated_at;
|
|
2123
|
+
lastWarn = r.generated_at;
|
|
2124
|
+
for (const a of w.related_artifacts) related.add(a);
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
let resolvedAt;
|
|
2128
|
+
for (const r of sorted) {
|
|
2129
|
+
if (r.generated_at <= lastWarn) continue;
|
|
2130
|
+
const touched = r.touched_files.some((f) => toPosix5(f) === codePath);
|
|
2131
|
+
const warnedHere = r.warnings.some((x) => x.code_path === codePath);
|
|
2132
|
+
const updatedRelated = r.updated_artifacts.some((a) => related.has(a));
|
|
2133
|
+
if (touched && updatedRelated && !warnedHere) {
|
|
2134
|
+
resolvedAt = r.generated_at;
|
|
2135
|
+
break;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
threads.push({
|
|
2139
|
+
code_path: codePath,
|
|
2140
|
+
related_artifacts: [...related],
|
|
2141
|
+
first_detected: firstDetected,
|
|
2142
|
+
last_seen: lastWarn,
|
|
2143
|
+
status: resolvedAt ? "resolved" : "open",
|
|
2144
|
+
...resolvedAt ? { resolved_at: resolvedAt } : {}
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
return threads;
|
|
2148
|
+
}
|
|
2149
|
+
function hotspotDir(codePath) {
|
|
2150
|
+
const i = codePath.lastIndexOf("/");
|
|
2151
|
+
return i >= 0 ? codePath.slice(0, i + 1) : codePath;
|
|
2152
|
+
}
|
|
2153
|
+
function computeTrend(runs) {
|
|
2154
|
+
if (runs.length < 2) return { direction: "unknown", reason: "Not enough recorded runs to detect a trend." };
|
|
2155
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
2156
|
+
const mid = Math.floor(sorted.length / 2);
|
|
2157
|
+
const avg = (arr) => arr.length ? arr.reduce((s, r) => s + r.warnings.length, 0) / arr.length : 0;
|
|
2158
|
+
const earlier = avg(sorted.slice(0, mid));
|
|
2159
|
+
const recent = avg(sorted.slice(mid));
|
|
2160
|
+
if (recent < earlier) return { direction: "improving", reason: "Fewer warnings in the last recorded runs." };
|
|
2161
|
+
if (recent > earlier) return { direction: "worsening", reason: "More warnings in the last recorded runs." };
|
|
2162
|
+
return { direction: "stable", reason: "Warning volume is roughly stable across recorded runs." };
|
|
2163
|
+
}
|
|
2164
|
+
function buildGuardHistory(dir) {
|
|
2165
|
+
const runs = loadGuardRuns(dir);
|
|
2166
|
+
if (runs.length === 0) {
|
|
2167
|
+
return {
|
|
2168
|
+
available: false,
|
|
2169
|
+
total_runs: 0,
|
|
2170
|
+
first_run: null,
|
|
2171
|
+
last_run: null,
|
|
2172
|
+
runs_with_warnings: 0,
|
|
2173
|
+
runs_clean: 0,
|
|
2174
|
+
detected: 0,
|
|
2175
|
+
open: 0,
|
|
2176
|
+
resolved: 0,
|
|
2177
|
+
resolution_rate: 0,
|
|
2178
|
+
threads: [],
|
|
2179
|
+
hotspots: [],
|
|
2180
|
+
trend: { direction: "unknown", reason: "No guard history recorded yet." }
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
const sorted = [...runs].sort((a, b) => a.generated_at.localeCompare(b.generated_at));
|
|
2184
|
+
const threads = resolveDriftThreads(sorted);
|
|
2185
|
+
const open = threads.filter((t) => t.status === "open").length;
|
|
2186
|
+
const resolved = threads.filter((t) => t.status === "resolved").length;
|
|
2187
|
+
const detected = threads.length;
|
|
2188
|
+
const runsWithWarnings = sorted.filter((r) => r.warnings.length > 0).length;
|
|
2189
|
+
const hotspotMap = /* @__PURE__ */ new Map();
|
|
2190
|
+
for (const t of threads) {
|
|
2191
|
+
const d = hotspotDir(t.code_path);
|
|
2192
|
+
hotspotMap.set(d, (hotspotMap.get(d) ?? 0) + 1);
|
|
2193
|
+
}
|
|
2194
|
+
const hotspots = [...hotspotMap.entries()].map(([path3, warnings]) => ({ path: path3, warnings })).sort((a, b) => b.warnings - a.warnings);
|
|
2195
|
+
return {
|
|
2196
|
+
available: true,
|
|
2197
|
+
total_runs: sorted.length,
|
|
2198
|
+
first_run: sorted[0].generated_at,
|
|
2199
|
+
last_run: sorted[sorted.length - 1].generated_at,
|
|
2200
|
+
runs_with_warnings: runsWithWarnings,
|
|
2201
|
+
runs_clean: sorted.length - runsWithWarnings,
|
|
2202
|
+
detected,
|
|
2203
|
+
open,
|
|
2204
|
+
resolved,
|
|
2205
|
+
resolution_rate: detected > 0 ? Math.round(resolved / detected * 1e3) / 10 : 0,
|
|
2206
|
+
threads,
|
|
2207
|
+
hotspots,
|
|
2208
|
+
trend: computeTrend(sorted)
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2089
2212
|
// ../cli/src/core/impact-report.ts
|
|
2090
2213
|
function isBroadGlob(glob) {
|
|
2091
2214
|
if (!glob.endsWith("/**")) return false;
|
|
@@ -2337,10 +2460,10 @@ function buildImpactReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
2337
2460
|
ready_quality: byState.ready > 0 ? `${byState.ready} ready` : "not applicable"
|
|
2338
2461
|
},
|
|
2339
2462
|
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`." },
|
|
2340
|
-
guard_activity: {
|
|
2341
|
-
|
|
2342
|
-
note: "Guard history is not persisted. Run `kaddo guard` to
|
|
2343
|
-
},
|
|
2463
|
+
guard_activity: (() => {
|
|
2464
|
+
const gh = buildGuardHistory(dir);
|
|
2465
|
+
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." };
|
|
2466
|
+
})(),
|
|
2344
2467
|
impact_signals,
|
|
2345
2468
|
actionable_gaps: gaps,
|
|
2346
2469
|
score,
|
|
@@ -2429,8 +2552,18 @@ function renderImpactMarkdown(r) {
|
|
|
2429
2552
|
}
|
|
2430
2553
|
L.push("");
|
|
2431
2554
|
L.push("## Guard Activity", "");
|
|
2432
|
-
|
|
2433
|
-
|
|
2555
|
+
if (r.guard_activity.available) {
|
|
2556
|
+
const ga = r.guard_activity;
|
|
2557
|
+
L.push("- Guard history: available");
|
|
2558
|
+
L.push(`- Guard runs recorded: ${ga.runs_recorded}`);
|
|
2559
|
+
L.push(`- Drift warnings detected: ${ga.detected}`);
|
|
2560
|
+
L.push(`- Open warnings: ${ga.open}`);
|
|
2561
|
+
L.push(`- Resolved warnings: ${ga.resolved}`);
|
|
2562
|
+
L.push(`- Resolution rate: ${ga.resolution_rate}%`);
|
|
2563
|
+
} else {
|
|
2564
|
+
L.push("- Guard history: not available");
|
|
2565
|
+
L.push(`- Note: ${r.guard_activity.note}`);
|
|
2566
|
+
}
|
|
2434
2567
|
L.push("");
|
|
2435
2568
|
L.push("## Impact Signals", "");
|
|
2436
2569
|
const s = r.impact_signals;
|
|
@@ -2568,18 +2701,28 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
2568
2701
|
const onboardH = round2(a.expected_new_contributors_per_month * a.onboarding_hours_saved_per_new_contributor * readinessMult);
|
|
2569
2702
|
const graphMult = GRAPH_MULT[graphQuality] ?? 0;
|
|
2570
2703
|
const archH = round2(a.architecture_discovery_hours_saved_when_graph_good * graphMult);
|
|
2571
|
-
const
|
|
2704
|
+
const guard = buildGuardHistory(dir);
|
|
2705
|
+
const driftSavings = guard.available && guard.resolved > 0 ? {
|
|
2706
|
+
available: true,
|
|
2707
|
+
hours: round2(guard.resolved * a.rework_hours_avoided_per_resolved_drift),
|
|
2708
|
+
formula: `${guard.resolved} resolved drift warnings \xD7 ${a.rework_hours_avoided_per_resolved_drift} h`
|
|
2709
|
+
} : { available: false, hours: 0, reason: "Guard history is not persisted yet." };
|
|
2710
|
+
const totalHours = round2(ctxPrepH + reviewH + clarH + onboardH + archH + driftSavings.hours);
|
|
2572
2711
|
const totalValue = Math.round(totalHours * a.hourly_cost);
|
|
2573
2712
|
const reasons = [];
|
|
2574
2713
|
let level;
|
|
2575
2714
|
if (impact.score === null || impact.score < 60 || graphQuality === "empty") {
|
|
2576
2715
|
level = "Low";
|
|
2577
2716
|
reasons.push("Impact score is low or the knowledge graph is empty.");
|
|
2717
|
+
} else if (impact.score >= 85 && graphQuality === "good" && source === "file" && guard.available && guard.resolved > 0) {
|
|
2718
|
+
level = "High";
|
|
2719
|
+
reasons.push("Strong evidence, custom assumptions and recorded drift resolution.");
|
|
2578
2720
|
} else {
|
|
2579
2721
|
level = "Medium";
|
|
2580
2722
|
reasons.push("Strong knowledge and graph evidence.");
|
|
2581
2723
|
}
|
|
2582
|
-
reasons.push("Guard history is not persisted yet \u2014 avoided rework is not estimated.");
|
|
2724
|
+
if (!guard.available) reasons.push("Guard history is not persisted yet \u2014 avoided rework is not estimated.");
|
|
2725
|
+
else reasons.push(`Guard history available (${guard.resolved} resolved drift warning(s)).`);
|
|
2583
2726
|
reasons.push(source === "file" ? "Assumptions come from `.kaddo/savings.yml`." : "Savings assumptions are defaults and should be calibrated.");
|
|
2584
2727
|
const actions = [];
|
|
2585
2728
|
if (source === "default") actions.push("Run `kaddo savings init` to customize assumptions.");
|
|
@@ -2612,7 +2755,7 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
2612
2755
|
graph_nodes: impact.graph_quality.available ? impact.graph_quality.nodes : null,
|
|
2613
2756
|
graph_edges: impact.graph_quality.available ? impact.graph_quality.edges : null,
|
|
2614
2757
|
context_readiness: readiness,
|
|
2615
|
-
guard_history_available:
|
|
2758
|
+
guard_history_available: guard.available
|
|
2616
2759
|
},
|
|
2617
2760
|
estimated_savings: {
|
|
2618
2761
|
context_preparation: { hours: ctxPrepH, formula: `${completed} Work Items \xD7 ${a.context_preparation_minutes_saved_per_work_item} min` },
|
|
@@ -2620,7 +2763,7 @@ function buildSavingsReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
2620
2763
|
clarification_reduction: { hours: clarH, formula: `${wiWithAcceptance} Work Items with Acceptance Criteria \xD7 ${a.clarification_minutes_saved_per_ready_work_item} min` },
|
|
2621
2764
|
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` },
|
|
2622
2765
|
architecture_discovery: { hours: archH, formula: `${a.architecture_discovery_hours_saved_when_graph_good} h \xD7 ${graphMult.toFixed(2)} graph multiplier` },
|
|
2623
|
-
drift_prevention:
|
|
2766
|
+
drift_prevention: driftSavings
|
|
2624
2767
|
},
|
|
2625
2768
|
total: { estimated_hours_saved: totalHours, estimated_value: totalValue, currency: a.currency },
|
|
2626
2769
|
confidence: { level, reasons },
|
|
@@ -2677,8 +2820,13 @@ function renderSavingsMarkdown(r) {
|
|
|
2677
2820
|
line("Onboarding", s.onboarding);
|
|
2678
2821
|
line("Architecture Discovery", s.architecture_discovery);
|
|
2679
2822
|
L.push("### Drift Prevention", "");
|
|
2680
|
-
|
|
2681
|
-
|
|
2823
|
+
if (s.drift_prevention.available) {
|
|
2824
|
+
L.push(`- Formula: ${s.drift_prevention.formula}`);
|
|
2825
|
+
L.push(`- Estimated: ${s.drift_prevention.hours} h`, "");
|
|
2826
|
+
} else {
|
|
2827
|
+
L.push("- Not available yet.");
|
|
2828
|
+
L.push(`- Reason: ${s.drift_prevention.reason}`, "");
|
|
2829
|
+
}
|
|
2682
2830
|
L.push("## Total", "");
|
|
2683
2831
|
L.push(`- Estimated time saved: ${r.total.estimated_hours_saved} h`);
|
|
2684
2832
|
L.push(`- Estimated value: ${r.total.estimated_value} ${r.currency}`);
|
|
@@ -2696,6 +2844,118 @@ function serializeSavingsJson(r) {
|
|
|
2696
2844
|
return JSON.stringify(r, null, 2) + "\n";
|
|
2697
2845
|
}
|
|
2698
2846
|
|
|
2847
|
+
// ../cli/src/core/drift-report.ts
|
|
2848
|
+
function buildDriftReport(dir, now = /* @__PURE__ */ new Date()) {
|
|
2849
|
+
const h = buildGuardHistory(dir);
|
|
2850
|
+
const project = loadConfig(dir)?.project.name ?? "unknown";
|
|
2851
|
+
const actions = [];
|
|
2852
|
+
if (!h.available) {
|
|
2853
|
+
actions.push("Run `kaddo guard --record` to start recording guard history.");
|
|
2854
|
+
} else {
|
|
2855
|
+
if (h.open > 0) actions.push("Review open drift warnings and update related Work Items or ownership.");
|
|
2856
|
+
actions.push("Run `kaddo guard --record` before important commits.");
|
|
2857
|
+
actions.push("Use this report to calibrate estimated drift-prevention savings.");
|
|
2858
|
+
}
|
|
2859
|
+
return {
|
|
2860
|
+
generated_at: now.toISOString(),
|
|
2861
|
+
project,
|
|
2862
|
+
guard_history: {
|
|
2863
|
+
available: h.available,
|
|
2864
|
+
total_runs: h.total_runs,
|
|
2865
|
+
first_run: h.first_run,
|
|
2866
|
+
last_run: h.last_run,
|
|
2867
|
+
runs_with_warnings: h.runs_with_warnings,
|
|
2868
|
+
runs_clean: h.runs_clean
|
|
2869
|
+
},
|
|
2870
|
+
drift_warnings: { detected: h.detected, open: h.open, resolved: h.resolved, resolution_rate: h.resolution_rate },
|
|
2871
|
+
hotspots: h.hotspots,
|
|
2872
|
+
trend: h.trend,
|
|
2873
|
+
threads: h.threads,
|
|
2874
|
+
suggested_actions: actions
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
function renderDriftMarkdown(r) {
|
|
2878
|
+
const L = [];
|
|
2879
|
+
L.push("# Kaddo Drift Trend Report", "");
|
|
2880
|
+
L.push(`Generated at: ${r.generated_at}`);
|
|
2881
|
+
L.push(`Project: ${r.project}`);
|
|
2882
|
+
L.push("");
|
|
2883
|
+
if (!r.guard_history.available) {
|
|
2884
|
+
L.push("## Guard History", "");
|
|
2885
|
+
L.push("No guard history recorded yet.");
|
|
2886
|
+
L.push("");
|
|
2887
|
+
L.push("Run `kaddo guard --record` to start recording drift evidence.");
|
|
2888
|
+
L.push("");
|
|
2889
|
+
L.push("## Suggested Actions", "");
|
|
2890
|
+
r.suggested_actions.forEach((a, i) => L.push(`${i + 1}. ${a}`));
|
|
2891
|
+
L.push("");
|
|
2892
|
+
return L.join("\n");
|
|
2893
|
+
}
|
|
2894
|
+
const w = r.drift_warnings;
|
|
2895
|
+
L.push("## Executive Summary", "");
|
|
2896
|
+
L.push(`- Guard runs recorded: ${r.guard_history.total_runs}`);
|
|
2897
|
+
L.push(`- Drift warnings detected: ${w.detected}`);
|
|
2898
|
+
L.push(`- Open warnings: ${w.open}`);
|
|
2899
|
+
L.push(`- Resolved warnings: ${w.resolved}`);
|
|
2900
|
+
L.push(`- Resolution rate: ${w.resolution_rate}%`);
|
|
2901
|
+
if (r.hotspots.length > 0) L.push(`- Most affected area: ${r.hotspots[0].path}`);
|
|
2902
|
+
L.push("");
|
|
2903
|
+
L.push("## Guard History", "");
|
|
2904
|
+
L.push(`- First run: ${r.guard_history.first_run}`);
|
|
2905
|
+
L.push(`- Last run: ${r.guard_history.last_run}`);
|
|
2906
|
+
L.push(`- Runs with warnings: ${r.guard_history.runs_with_warnings}/${r.guard_history.total_runs}`);
|
|
2907
|
+
L.push(`- Runs clean: ${r.guard_history.runs_clean}/${r.guard_history.total_runs}`);
|
|
2908
|
+
L.push("");
|
|
2909
|
+
L.push("## Drift Warnings", "");
|
|
2910
|
+
const open = r.threads.filter((t) => t.status === "open");
|
|
2911
|
+
const resolved = r.threads.filter((t) => t.status === "resolved");
|
|
2912
|
+
L.push("### Open", "");
|
|
2913
|
+
if (open.length === 0) L.push("_None._", "");
|
|
2914
|
+
for (const t of open) {
|
|
2915
|
+
L.push(`- ${t.code_path}`);
|
|
2916
|
+
L.push(` - Related artifacts: ${t.related_artifacts.join(", ") || "\u2014"}`);
|
|
2917
|
+
L.push(` - First detected: ${t.first_detected}`);
|
|
2918
|
+
L.push(` - Last seen: ${t.last_seen}`);
|
|
2919
|
+
L.push(" - Status: open");
|
|
2920
|
+
}
|
|
2921
|
+
L.push("");
|
|
2922
|
+
L.push("### Resolved", "");
|
|
2923
|
+
if (resolved.length === 0) L.push("_None._", "");
|
|
2924
|
+
for (const t of resolved) {
|
|
2925
|
+
L.push(`- ${t.code_path}`);
|
|
2926
|
+
L.push(` - Related artifacts: ${t.related_artifacts.join(", ") || "\u2014"}`);
|
|
2927
|
+
L.push(` - First detected: ${t.first_detected}`);
|
|
2928
|
+
L.push(` - Resolved at: ${t.resolved_at}`);
|
|
2929
|
+
L.push(" - Status: resolved");
|
|
2930
|
+
}
|
|
2931
|
+
L.push("");
|
|
2932
|
+
L.push("## Hotspots", "");
|
|
2933
|
+
if (r.hotspots.length === 0) L.push("_None._");
|
|
2934
|
+
for (const h of r.hotspots) L.push(`- ${h.path}: ${h.warnings} warning(s)`);
|
|
2935
|
+
L.push("");
|
|
2936
|
+
L.push("## Trend", "");
|
|
2937
|
+
L.push(`- Recent direction: ${r.trend.direction}`);
|
|
2938
|
+
L.push(`- Reason: ${r.trend.reason}`);
|
|
2939
|
+
L.push("");
|
|
2940
|
+
L.push("## Suggested Actions", "");
|
|
2941
|
+
r.suggested_actions.forEach((a, i) => L.push(`${i + 1}. ${a}`));
|
|
2942
|
+
L.push("");
|
|
2943
|
+
return L.join("\n");
|
|
2944
|
+
}
|
|
2945
|
+
function serializeDriftJson(r) {
|
|
2946
|
+
const out = {
|
|
2947
|
+
generated_at: r.generated_at,
|
|
2948
|
+
project: r.project,
|
|
2949
|
+
guard_history: r.guard_history,
|
|
2950
|
+
drift_warnings: r.drift_warnings,
|
|
2951
|
+
hotspots: r.hotspots,
|
|
2952
|
+
trend: r.trend,
|
|
2953
|
+
threads: r.threads,
|
|
2954
|
+
suggested_actions: r.suggested_actions
|
|
2955
|
+
};
|
|
2956
|
+
return JSON.stringify(out, null, 2) + "\n";
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2699
2959
|
// src/workitems.ts
|
|
2700
2960
|
import matter7 from "gray-matter";
|
|
2701
2961
|
var ACTIVE_STATES2 = /* @__PURE__ */ new Set(["draft", "ready", "in-progress", "blocked"]);
|
|
@@ -2922,6 +3182,30 @@ var RESOURCES = [
|
|
|
2922
3182
|
}
|
|
2923
3183
|
return [{ uri: "kaddo://savings-report", text: renderSavingsMarkdown(buildSavingsReport(root, { scope: "all", scopeSource: "default" })), mimeType: "text/markdown" }];
|
|
2924
3184
|
}
|
|
3185
|
+
},
|
|
3186
|
+
{
|
|
3187
|
+
uri: "kaddo://drift-report",
|
|
3188
|
+
name: "Kaddo drift report",
|
|
3189
|
+
description: "Drift Trend Report \u2014 the last written report, or generated in memory (read-only).",
|
|
3190
|
+
mimeType: "text/markdown",
|
|
3191
|
+
read: (root) => {
|
|
3192
|
+
const saved = readText(root, ".kaddo/reports/drift-report.md");
|
|
3193
|
+
if (saved) return [{ uri: "kaddo://drift-report", text: saved, mimeType: "text/markdown" }];
|
|
3194
|
+
return [{ uri: "kaddo://drift-report", text: renderDriftMarkdown(buildDriftReport(root)), mimeType: "text/markdown" }];
|
|
3195
|
+
}
|
|
3196
|
+
},
|
|
3197
|
+
{
|
|
3198
|
+
uri: "kaddo://guard-history",
|
|
3199
|
+
name: "Kaddo guard history",
|
|
3200
|
+
description: "Recorded guard runs (.kaddo/history/guard-runs.jsonl) \u2014 read-only.",
|
|
3201
|
+
mimeType: "application/jsonl",
|
|
3202
|
+
read: (root) => {
|
|
3203
|
+
const runs = readText(root, ".kaddo/history/guard-runs.jsonl");
|
|
3204
|
+
if (runs === null) {
|
|
3205
|
+
return text("kaddo://guard-history", "No guard history recorded yet. Run `kaddo guard --record`.", "text/plain");
|
|
3206
|
+
}
|
|
3207
|
+
return [{ uri: "kaddo://guard-history", text: runs, mimeType: "application/jsonl" }];
|
|
3208
|
+
}
|
|
2925
3209
|
}
|
|
2926
3210
|
];
|
|
2927
3211
|
|
|
@@ -3716,6 +4000,21 @@ function generateSavingsReport(root, opts = {}) {
|
|
|
3716
4000
|
next_suggested_resources: ["kaddo://savings-report"]
|
|
3717
4001
|
};
|
|
3718
4002
|
}
|
|
4003
|
+
function generateDriftReport(root, opts = {}) {
|
|
4004
|
+
requireConfig(root);
|
|
4005
|
+
const format = opts.format ?? "markdown";
|
|
4006
|
+
const report = buildDriftReport(root);
|
|
4007
|
+
const content = format === "json" ? serializeDriftJson(report) : renderDriftMarkdown(report);
|
|
4008
|
+
const out = opts.output ?? `.kaddo/reports/drift-report.${format === "json" ? "json" : "md"}`;
|
|
4009
|
+
writeDerived(root, out, content);
|
|
4010
|
+
return {
|
|
4011
|
+
status: "ok",
|
|
4012
|
+
files_written: [out.replace(/\\/g, "/")],
|
|
4013
|
+
summary: report.guard_history.available ? `Drift report generated (${report.drift_warnings.open} open, ${report.drift_warnings.resolved} resolved).` : "Drift report generated (no guard history yet \u2014 run `kaddo guard --record`).",
|
|
4014
|
+
warnings: report.guard_history.available ? [] : ["No guard history recorded yet."],
|
|
4015
|
+
next_suggested_resources: ["kaddo://drift-report"]
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
3719
4018
|
function generateCapsuleDraft(root) {
|
|
3720
4019
|
const config = requireConfig(root);
|
|
3721
4020
|
requireKnowledge(root);
|
|
@@ -3933,6 +4232,22 @@ function createServer(root) {
|
|
|
3933
4232
|
() => generateSavingsReport(root, { format: args.format, scope: args.scope, output: args.output })
|
|
3934
4233
|
)
|
|
3935
4234
|
);
|
|
4235
|
+
server.registerTool(
|
|
4236
|
+
"kaddo_generate_drift_report",
|
|
4237
|
+
{
|
|
4238
|
+
title: "Generate drift report",
|
|
4239
|
+
description: `Write the Drift Trend Report under .kaddo/reports/ from recorded guard history. format: markdown (default) or json. Does NOT record guard runs. ${DERIVED_NOTE}`,
|
|
4240
|
+
inputSchema: {
|
|
4241
|
+
format: z2.enum(["markdown", "json"]).optional(),
|
|
4242
|
+
output: z2.string().optional()
|
|
4243
|
+
}
|
|
4244
|
+
},
|
|
4245
|
+
async (args) => generated(
|
|
4246
|
+
root,
|
|
4247
|
+
"generate drift report",
|
|
4248
|
+
() => generateDriftReport(root, { format: args.format, output: args.output })
|
|
4249
|
+
)
|
|
4250
|
+
);
|
|
3936
4251
|
server.registerTool(
|
|
3937
4252
|
"kaddo_generate_capsule_draft",
|
|
3938
4253
|
{ title: "Generate capsule draft", description: `Write a capsule DRAFT under .kaddo/exports/ (never registers it). ${DERIVED_NOTE}`, inputSchema: {} },
|
package/package.json
CHANGED