arkaik-mcp 0.4.0 → 0.6.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 +604 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15338,6 +15338,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
|
|
|
15338
15338
|
medium: external_exports.number().optional(),
|
|
15339
15339
|
low: external_exports.number().optional(),
|
|
15340
15340
|
info: external_exports.number().optional()
|
|
15341
|
+
}).catchall(external_exports.unknown()).optional(),
|
|
15342
|
+
// A scoped re-audit (issue #443). Optional and catchall like `counts`:
|
|
15343
|
+
// older readers ignore it, and its `scores` stay the same shape either way.
|
|
15344
|
+
scope: external_exports.object({
|
|
15345
|
+
partial: external_exports.boolean().optional(),
|
|
15346
|
+
cells: external_exports.number().optional(),
|
|
15347
|
+
since: external_exports.string().optional()
|
|
15341
15348
|
}).catchall(external_exports.unknown()).optional()
|
|
15342
15349
|
}).catchall(external_exports.unknown());
|
|
15343
15350
|
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
@@ -15372,6 +15379,7 @@ var QualitySignalTrippedEventSchema = external_exports.object({
|
|
|
15372
15379
|
criterion_id: external_exports.string(),
|
|
15373
15380
|
surface: external_exports.string(),
|
|
15374
15381
|
signal: external_exports.string(),
|
|
15382
|
+
commit: external_exports.string().optional(),
|
|
15375
15383
|
detail: external_exports.string().optional()
|
|
15376
15384
|
}).catchall(external_exports.unknown());
|
|
15377
15385
|
var JOURNAL_EVENT_SCHEMAS = {
|
|
@@ -16017,6 +16025,18 @@ function capGrade(grade, cap) {
|
|
|
16017
16025
|
function isOpenFinding(finding) {
|
|
16018
16026
|
return (finding.status ?? "open") === "open";
|
|
16019
16027
|
}
|
|
16028
|
+
function rollUpSurface(scores, weights) {
|
|
16029
|
+
let weighted = 0;
|
|
16030
|
+
let total = 0;
|
|
16031
|
+
for (const domain2 of Object.keys(scores)) {
|
|
16032
|
+
const score = scores[domain2];
|
|
16033
|
+
if (typeof score !== "number" || !Number.isFinite(score)) continue;
|
|
16034
|
+
const weight = typeof weights?.[domain2] === "number" ? weights[domain2] : 1;
|
|
16035
|
+
weighted += score * weight;
|
|
16036
|
+
total += weight;
|
|
16037
|
+
}
|
|
16038
|
+
return total > 0 ? Math.round(weighted / total) : null;
|
|
16039
|
+
}
|
|
16020
16040
|
function resolveKritikLibrary(section, library) {
|
|
16021
16041
|
const explicit = library ?? section?.library;
|
|
16022
16042
|
if (explicit && Array.isArray(explicit.criteria) && Array.isArray(explicit.domains)) return explicit;
|
|
@@ -16092,16 +16112,12 @@ function deriveQualityMatrix(bundle, library) {
|
|
|
16092
16112
|
}
|
|
16093
16113
|
const overall = {};
|
|
16094
16114
|
for (const surface of surfaces) {
|
|
16095
|
-
|
|
16096
|
-
let total = 0;
|
|
16115
|
+
const bySurface = {};
|
|
16097
16116
|
for (const domain2 of domains) {
|
|
16098
16117
|
const cell = matrix[domain2]?.[surface];
|
|
16099
|
-
if (
|
|
16100
|
-
const weight = typeof weights?.[domain2] === "number" ? weights[domain2] : 1;
|
|
16101
|
-
weighted += cell.score * weight;
|
|
16102
|
-
total += weight;
|
|
16118
|
+
if (cell) bySurface[domain2] = cell.score;
|
|
16103
16119
|
}
|
|
16104
|
-
overall[surface] =
|
|
16120
|
+
overall[surface] = rollUpSurface(bySurface, weights);
|
|
16105
16121
|
}
|
|
16106
16122
|
const finding_counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
16107
16123
|
for (const finding of openFindings) finding_counts[severityOf(finding, pack)]++;
|
|
@@ -17782,7 +17798,8 @@ function auditCompletedInput(matrix, meta3) {
|
|
|
17782
17798
|
framework_version: meta3.framework_version,
|
|
17783
17799
|
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
17784
17800
|
scores,
|
|
17785
|
-
counts: matrix.finding_counts
|
|
17801
|
+
counts: matrix.finding_counts,
|
|
17802
|
+
...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
|
|
17786
17803
|
}
|
|
17787
17804
|
};
|
|
17788
17805
|
}
|
|
@@ -17818,6 +17835,7 @@ function signalTrippedInput(trip) {
|
|
|
17818
17835
|
criterion_id: trip.criterion_id,
|
|
17819
17836
|
surface: trip.surface,
|
|
17820
17837
|
signal: trip.signal,
|
|
17838
|
+
...trip.commit !== void 0 ? { commit: trip.commit } : {},
|
|
17821
17839
|
...trip.detail !== void 0 ? { detail: trip.detail } : {}
|
|
17822
17840
|
}
|
|
17823
17841
|
};
|
|
@@ -17900,6 +17918,309 @@ function detectRegressions(previous, next, library) {
|
|
|
17900
17918
|
return regressions;
|
|
17901
17919
|
}
|
|
17902
17920
|
|
|
17921
|
+
// ../schema/src/quality-trend.ts
|
|
17922
|
+
var NO_DELTA = { previous: null, delta: null };
|
|
17923
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17924
|
+
function frameworkMajor(version2) {
|
|
17925
|
+
if (typeof version2 !== "string") return null;
|
|
17926
|
+
const match = /^\s*v?(\d+)/.exec(version2);
|
|
17927
|
+
return match ? Number(match[1]) : null;
|
|
17928
|
+
}
|
|
17929
|
+
function sameFrameworkMajor(a, b) {
|
|
17930
|
+
const left = frameworkMajor(a);
|
|
17931
|
+
const right = frameworkMajor(b);
|
|
17932
|
+
return left === null || right === null || left === right;
|
|
17933
|
+
}
|
|
17934
|
+
function cleanScores(raw) {
|
|
17935
|
+
const scores = {};
|
|
17936
|
+
if (!isRecord2(raw)) return scores;
|
|
17937
|
+
for (const surface of Object.keys(raw)) {
|
|
17938
|
+
const bySurface = raw[surface];
|
|
17939
|
+
if (!isRecord2(bySurface)) continue;
|
|
17940
|
+
const cleaned = {};
|
|
17941
|
+
for (const domain2 of Object.keys(bySurface)) {
|
|
17942
|
+
const score = bySurface[domain2];
|
|
17943
|
+
if (typeof score === "number" && Number.isFinite(score)) cleaned[domain2] = score;
|
|
17944
|
+
}
|
|
17945
|
+
scores[surface] = cleaned;
|
|
17946
|
+
}
|
|
17947
|
+
return scores;
|
|
17948
|
+
}
|
|
17949
|
+
function cleanCounts(raw) {
|
|
17950
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
17951
|
+
if (!isRecord2(raw)) return counts;
|
|
17952
|
+
for (const severity of Object.keys(counts)) {
|
|
17953
|
+
const value = raw[severity];
|
|
17954
|
+
if (typeof value === "number" && Number.isFinite(value)) counts[severity] = value;
|
|
17955
|
+
}
|
|
17956
|
+
return counts;
|
|
17957
|
+
}
|
|
17958
|
+
function cellSet(scores) {
|
|
17959
|
+
const cells = /* @__PURE__ */ new Map();
|
|
17960
|
+
for (const surface of Object.keys(scores)) {
|
|
17961
|
+
for (const domain2 of Object.keys(scores[surface])) cells.set(`${surface}::${domain2}`, scores[surface][domain2]);
|
|
17962
|
+
}
|
|
17963
|
+
return cells;
|
|
17964
|
+
}
|
|
17965
|
+
function liveScores(live) {
|
|
17966
|
+
const scores = {};
|
|
17967
|
+
for (const domain2 of Object.keys(live.matrix ?? {})) {
|
|
17968
|
+
const row = live.matrix[domain2];
|
|
17969
|
+
if (!isRecord2(row)) continue;
|
|
17970
|
+
for (const surface of Object.keys(row)) {
|
|
17971
|
+
const cell = row[surface];
|
|
17972
|
+
if (!cell || typeof cell.score !== "number") continue;
|
|
17973
|
+
(scores[surface] ??= {})[domain2] = cell.score;
|
|
17974
|
+
}
|
|
17975
|
+
}
|
|
17976
|
+
return scores;
|
|
17977
|
+
}
|
|
17978
|
+
function sameCells(a, b) {
|
|
17979
|
+
if (a.size !== b.size) return false;
|
|
17980
|
+
for (const [key, value] of a) {
|
|
17981
|
+
if (b.get(key) !== value) return false;
|
|
17982
|
+
}
|
|
17983
|
+
return true;
|
|
17984
|
+
}
|
|
17985
|
+
function deriveQualityTrend(events, profile, live) {
|
|
17986
|
+
const weights = profile?.domain_weights;
|
|
17987
|
+
const byAudit = /* @__PURE__ */ new Map();
|
|
17988
|
+
const audits = (Array.isArray(events) ? events : []).filter(
|
|
17989
|
+
(event) => isRecord2(event) && event.type === "quality.audit.completed"
|
|
17990
|
+
);
|
|
17991
|
+
for (const event of orderEvents(audits)) {
|
|
17992
|
+
const auditId = typeof event.audit_id === "string" ? event.audit_id : typeof event.id === "string" ? event.id : "";
|
|
17993
|
+
const scores = cleanScores(event.scores);
|
|
17994
|
+
const overall = {};
|
|
17995
|
+
for (const surface of Object.keys(scores)) overall[surface] = rollUpSurface(scores[surface], weights);
|
|
17996
|
+
const snapshot = {
|
|
17997
|
+
audit_id: auditId,
|
|
17998
|
+
ts: typeof event.ts === "string" ? event.ts : "",
|
|
17999
|
+
...typeof event.commit === "string" && event.commit !== "" ? { commit: event.commit } : {},
|
|
18000
|
+
...typeof event.framework_version === "string" ? { framework_version: event.framework_version } : {},
|
|
18001
|
+
comparable: true,
|
|
18002
|
+
scores,
|
|
18003
|
+
overall,
|
|
18004
|
+
counts: cleanCounts(event.counts)
|
|
18005
|
+
};
|
|
18006
|
+
byAudit.delete(auditId);
|
|
18007
|
+
byAudit.set(auditId, snapshot);
|
|
18008
|
+
}
|
|
18009
|
+
const snapshots = [...byAudit.values()];
|
|
18010
|
+
for (let i = 1; i < snapshots.length; i++) {
|
|
18011
|
+
snapshots[i].comparable = sameFrameworkMajor(snapshots[i - 1].framework_version, snapshots[i].framework_version);
|
|
18012
|
+
}
|
|
18013
|
+
const latest = snapshots.length > 0 ? snapshots[snapshots.length - 1] : null;
|
|
18014
|
+
let previous = latest;
|
|
18015
|
+
if (live && latest !== null && sameCells(cellSet(latest.scores), cellSet(liveScores(live)))) {
|
|
18016
|
+
previous = snapshots.length > 1 ? snapshots[snapshots.length - 2] : null;
|
|
18017
|
+
}
|
|
18018
|
+
const comparable = previous !== null && live ? sameFrameworkMajor(previous.framework_version, live.framework_version) : false;
|
|
18019
|
+
const against = (prev, current) => {
|
|
18020
|
+
if (previous === null || typeof prev !== "number") return NO_DELTA;
|
|
18021
|
+
const delta = comparable && typeof current === "number" ? current - prev : null;
|
|
18022
|
+
return { previous: prev, delta, audit_id: previous.audit_id };
|
|
18023
|
+
};
|
|
18024
|
+
return {
|
|
18025
|
+
snapshots,
|
|
18026
|
+
latest,
|
|
18027
|
+
previous,
|
|
18028
|
+
deltaCell: (domain2, surface) => against(previous?.scores[surface]?.[domain2], live?.matrix?.[domain2]?.[surface]?.score),
|
|
18029
|
+
deltaOverall: (surface) => against(previous?.overall[surface], live?.overall?.[surface])
|
|
18030
|
+
};
|
|
18031
|
+
}
|
|
18032
|
+
function trendRows(trend, filter = {}) {
|
|
18033
|
+
const surfaces = [];
|
|
18034
|
+
for (const snapshot of trend.snapshots) {
|
|
18035
|
+
for (const surface of Object.keys(snapshot.scores)) {
|
|
18036
|
+
if (filter.surface !== void 0 && surface !== filter.surface) continue;
|
|
18037
|
+
if (!surfaces.includes(surface)) surfaces.push(surface);
|
|
18038
|
+
}
|
|
18039
|
+
}
|
|
18040
|
+
const valueOf = (snapshot, surface) => {
|
|
18041
|
+
if (filter.domain !== void 0) return snapshot.scores[surface]?.[filter.domain] ?? null;
|
|
18042
|
+
return snapshot.overall[surface] ?? null;
|
|
18043
|
+
};
|
|
18044
|
+
const rows = [];
|
|
18045
|
+
trend.snapshots.forEach((snapshot, index) => {
|
|
18046
|
+
const above = index > 0 ? trend.snapshots[index - 1] : null;
|
|
18047
|
+
const cells = {};
|
|
18048
|
+
for (const surface of surfaces) {
|
|
18049
|
+
const score = valueOf(snapshot, surface);
|
|
18050
|
+
const before = above === null ? null : valueOf(above, surface);
|
|
18051
|
+
const delta = snapshot.comparable && score !== null && before !== null ? score - before : null;
|
|
18052
|
+
cells[surface] = { score, delta };
|
|
18053
|
+
}
|
|
18054
|
+
rows.push({
|
|
18055
|
+
audit_id: snapshot.audit_id,
|
|
18056
|
+
ts: snapshot.ts,
|
|
18057
|
+
...snapshot.commit !== void 0 ? { commit: snapshot.commit } : {},
|
|
18058
|
+
...snapshot.framework_version !== void 0 ? { framework_version: snapshot.framework_version } : {},
|
|
18059
|
+
comparable: snapshot.comparable,
|
|
18060
|
+
cells
|
|
18061
|
+
});
|
|
18062
|
+
});
|
|
18063
|
+
return { surfaces, rows };
|
|
18064
|
+
}
|
|
18065
|
+
|
|
18066
|
+
// ../schema/src/quality-scope.ts
|
|
18067
|
+
var rowsOf2 = (value) => Array.isArray(value) ? value : [];
|
|
18068
|
+
var isString = (value) => typeof value === "string" && value !== "";
|
|
18069
|
+
var stringsOf = (value) => rowsOf2(value).filter(isString);
|
|
18070
|
+
var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
|
|
18071
|
+
function recordedAuditIds(events) {
|
|
18072
|
+
const ids = [];
|
|
18073
|
+
for (const event of orderEvents(rowsOf2(events))) {
|
|
18074
|
+
if (event?.type !== "quality.audit.completed") continue;
|
|
18075
|
+
const id = event.audit_id;
|
|
18076
|
+
if (isString(id) && !ids.includes(id)) ids.push(id);
|
|
18077
|
+
}
|
|
18078
|
+
return ids;
|
|
18079
|
+
}
|
|
18080
|
+
function deriveAuditScope(events, section, library, options = {}) {
|
|
18081
|
+
const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
|
|
18082
|
+
let sinceIndex = -1;
|
|
18083
|
+
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
18084
|
+
const event = ordered[i];
|
|
18085
|
+
if (event.type !== "quality.audit.completed") continue;
|
|
18086
|
+
const id = event.audit_id;
|
|
18087
|
+
if (options.since !== void 0 && id !== options.since) continue;
|
|
18088
|
+
sinceIndex = i;
|
|
18089
|
+
break;
|
|
18090
|
+
}
|
|
18091
|
+
const empty = {
|
|
18092
|
+
since: options.since ?? null,
|
|
18093
|
+
since_ts: null,
|
|
18094
|
+
cells: [],
|
|
18095
|
+
findings: [],
|
|
18096
|
+
resolved_by: {},
|
|
18097
|
+
unknown: [],
|
|
18098
|
+
unscorable: [],
|
|
18099
|
+
widened: 0
|
|
18100
|
+
};
|
|
18101
|
+
if (sinceIndex === -1) return empty;
|
|
18102
|
+
const anchor = ordered[sinceIndex];
|
|
18103
|
+
const anchorId = anchor.audit_id;
|
|
18104
|
+
const since = isString(anchorId) ? anchorId : null;
|
|
18105
|
+
const sinceTs = isString(anchor.ts) ? anchor.ts : null;
|
|
18106
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
18107
|
+
for (const event of ordered.slice(sinceIndex + 1)) {
|
|
18108
|
+
if (event.type !== "quality.finding.resolved") continue;
|
|
18109
|
+
const findingId = event.finding_id;
|
|
18110
|
+
if (!isString(findingId)) continue;
|
|
18111
|
+
const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
|
|
18112
|
+
const by = event.resolved_by;
|
|
18113
|
+
if (isString(by)) entry.resolved_by = by;
|
|
18114
|
+
for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
|
|
18115
|
+
resolutions.set(findingId, entry);
|
|
18116
|
+
}
|
|
18117
|
+
if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
|
|
18118
|
+
const findings = rowsOf2(section?.findings).filter(
|
|
18119
|
+
(finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
|
|
18120
|
+
);
|
|
18121
|
+
const findingById = /* @__PURE__ */ new Map();
|
|
18122
|
+
for (const finding of findings) findingById.set(finding.id, finding);
|
|
18123
|
+
const criterionById = /* @__PURE__ */ new Map();
|
|
18124
|
+
for (const criterion of rowsOf2(library?.criteria)) {
|
|
18125
|
+
if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
|
|
18126
|
+
}
|
|
18127
|
+
const assessmentByCell = /* @__PURE__ */ new Map();
|
|
18128
|
+
for (const assessment of rowsOf2(section?.assessments)) {
|
|
18129
|
+
if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
|
|
18130
|
+
assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
|
|
18131
|
+
}
|
|
18132
|
+
const declared2 = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
|
|
18133
|
+
const surfaces = declared2.length > 0 ? [...new Set(declared2)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
|
|
18134
|
+
const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
|
|
18135
|
+
const scorable = (criterionId, surface) => {
|
|
18136
|
+
const criterion = criterionById.get(criterionId);
|
|
18137
|
+
if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
|
|
18138
|
+
if (declared2.length > 0 && !surfaces.includes(surface)) return false;
|
|
18139
|
+
return appliesTo(criterion, surface);
|
|
18140
|
+
};
|
|
18141
|
+
const cells = /* @__PURE__ */ new Map();
|
|
18142
|
+
const addDirect = (criterionId, surface, findingId) => {
|
|
18143
|
+
const key = cellKey2(criterionId, surface);
|
|
18144
|
+
const existing = cells.get(key);
|
|
18145
|
+
if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
|
|
18146
|
+
else if (!existing.because.includes(findingId)) existing.because.push(findingId);
|
|
18147
|
+
};
|
|
18148
|
+
const drivers = [];
|
|
18149
|
+
const unknown2 = [];
|
|
18150
|
+
const unscorable = [];
|
|
18151
|
+
const resolvedBy = {};
|
|
18152
|
+
const resolvedNodes = /* @__PURE__ */ new Set();
|
|
18153
|
+
for (const [findingId, resolution] of resolutions) {
|
|
18154
|
+
const finding = findingById.get(findingId);
|
|
18155
|
+
if (finding === void 0) {
|
|
18156
|
+
unknown2.push(findingId);
|
|
18157
|
+
continue;
|
|
18158
|
+
}
|
|
18159
|
+
if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
|
|
18160
|
+
const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
|
|
18161
|
+
(surface) => scorable(finding.criterion_id, surface)
|
|
18162
|
+
);
|
|
18163
|
+
for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
|
|
18164
|
+
for (const node of resolution.node_ids) resolvedNodes.add(node);
|
|
18165
|
+
if (targets.length === 0) {
|
|
18166
|
+
unscorable.push(findingId);
|
|
18167
|
+
continue;
|
|
18168
|
+
}
|
|
18169
|
+
drivers.push(findingId);
|
|
18170
|
+
if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
|
|
18171
|
+
for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
|
|
18172
|
+
}
|
|
18173
|
+
let widened = 0;
|
|
18174
|
+
if (options.widen !== false && resolvedNodes.size > 0) {
|
|
18175
|
+
const nodesByCell = /* @__PURE__ */ new Map();
|
|
18176
|
+
const noteNodes = (criterionId, surface, nodes) => {
|
|
18177
|
+
const key = cellKey2(criterionId, surface);
|
|
18178
|
+
const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
|
|
18179
|
+
for (const node of nodes) bucket.add(node);
|
|
18180
|
+
nodesByCell.set(key, bucket);
|
|
18181
|
+
};
|
|
18182
|
+
for (const finding of findings) {
|
|
18183
|
+
const nodes = stringsOf(finding.node_ids);
|
|
18184
|
+
if (nodes.length === 0) continue;
|
|
18185
|
+
if (finding.surface === CROSS_SURFACE_ID) {
|
|
18186
|
+
for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
|
|
18187
|
+
} else {
|
|
18188
|
+
noteNodes(finding.criterion_id, finding.surface, nodes);
|
|
18189
|
+
}
|
|
18190
|
+
}
|
|
18191
|
+
for (const [key, assessment] of assessmentByCell) {
|
|
18192
|
+
if (cells.has(key)) continue;
|
|
18193
|
+
if (!criterionById.has(assessment.criterion_id)) continue;
|
|
18194
|
+
if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
|
|
18195
|
+
const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
|
|
18196
|
+
if (shared.length === 0) continue;
|
|
18197
|
+
cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
|
|
18198
|
+
widened++;
|
|
18199
|
+
}
|
|
18200
|
+
}
|
|
18201
|
+
for (const [key, cell] of cells) {
|
|
18202
|
+
const assessment = assessmentByCell.get(key);
|
|
18203
|
+
if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
|
|
18204
|
+
cell.current = { level: assessment.level, audit_id: assessment.audit_id };
|
|
18205
|
+
}
|
|
18206
|
+
}
|
|
18207
|
+
const column = (surface) => {
|
|
18208
|
+
const at = surfaces.indexOf(surface);
|
|
18209
|
+
return at === -1 ? surfaces.length : at;
|
|
18210
|
+
};
|
|
18211
|
+
const sorted = [...cells.values()].sort(
|
|
18212
|
+
(a, b) => column(a.surface) - column(b.surface) || (a.surface < b.surface ? -1 : a.surface > b.surface ? 1 : 0) || (a.criterion_id < b.criterion_id ? -1 : a.criterion_id > b.criterion_id ? 1 : 0)
|
|
18213
|
+
);
|
|
18214
|
+
return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
|
|
18215
|
+
}
|
|
18216
|
+
function scopeSummary(scope) {
|
|
18217
|
+
const direct = scope.cells.length - scope.widened;
|
|
18218
|
+
const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
|
|
18219
|
+
const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
|
|
18220
|
+
const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
|
|
18221
|
+
return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
|
|
18222
|
+
}
|
|
18223
|
+
|
|
17903
18224
|
// ../schema/src/cli/kritik-audit.ts
|
|
17904
18225
|
import { existsSync as existsSync2, readdirSync, statSync } from "node:fs";
|
|
17905
18226
|
import { join as join2 } from "node:path";
|
|
@@ -17995,6 +18316,100 @@ function loadQualitySection(root, auditId, library, scores = loadScores(root, au
|
|
|
17995
18316
|
findings: findings.findings
|
|
17996
18317
|
};
|
|
17997
18318
|
}
|
|
18319
|
+
function stripDerived(finding) {
|
|
18320
|
+
const { severity: _severity, priority: _priority, ...rest } = finding;
|
|
18321
|
+
void _severity;
|
|
18322
|
+
void _priority;
|
|
18323
|
+
return rest;
|
|
18324
|
+
}
|
|
18325
|
+
function requireAudit(root, auditId) {
|
|
18326
|
+
if (!listAuditIds(root).includes(auditId)) {
|
|
18327
|
+
throw new Error(`no audit "${auditId}" under ${auditsDir(root)}`);
|
|
18328
|
+
}
|
|
18329
|
+
}
|
|
18330
|
+
function loadCurrentQualitySection(root, library) {
|
|
18331
|
+
const auditIds = listAuditIds(root);
|
|
18332
|
+
if (auditIds.length === 0) return void 0;
|
|
18333
|
+
const profile = loadProfile(root);
|
|
18334
|
+
if (!profile) return void 0;
|
|
18335
|
+
return mergeAudits(root, auditIds, library, profile);
|
|
18336
|
+
}
|
|
18337
|
+
function loadQualitySectionThrough(root, auditId, library) {
|
|
18338
|
+
requireAudit(root, auditId);
|
|
18339
|
+
const auditIds = listAuditIds(root);
|
|
18340
|
+
return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
|
|
18341
|
+
}
|
|
18342
|
+
function mergeAudits(root, auditIds, library, profile) {
|
|
18343
|
+
const cells = /* @__PURE__ */ new Map();
|
|
18344
|
+
const findings = [];
|
|
18345
|
+
let frameworkVersion;
|
|
18346
|
+
for (const id of auditIds) {
|
|
18347
|
+
const scores = loadScoresOrEmpty(root, id);
|
|
18348
|
+
if (typeof scores.framework_version === "string") frameworkVersion = scores.framework_version;
|
|
18349
|
+
for (const assessment of scores.assessments) {
|
|
18350
|
+
cells.set(`${assessment.criterion_id}\0${assessment.surface}`, assessment);
|
|
18351
|
+
}
|
|
18352
|
+
for (const finding of loadFindings(root, id).findings) findings.push(stripDerived(finding));
|
|
18353
|
+
}
|
|
18354
|
+
return {
|
|
18355
|
+
framework_version: frameworkVersion ?? library.version,
|
|
18356
|
+
library,
|
|
18357
|
+
profile,
|
|
18358
|
+
assessments: [...cells.values()],
|
|
18359
|
+
findings
|
|
18360
|
+
};
|
|
18361
|
+
}
|
|
18362
|
+
function scopedAuditTarget(root, since, month, requested, recorded = []) {
|
|
18363
|
+
const existing = listAuditIds(root);
|
|
18364
|
+
const newest = existing[existing.length - 1];
|
|
18365
|
+
if (requested !== void 0) {
|
|
18366
|
+
if (requested === since) {
|
|
18367
|
+
throw new Error(
|
|
18368
|
+
`"${requested}" is the audit this scope is measured from \u2014 its recorded reading is history. Re-score into a new audit (e.g. \`--audit ${month}-scoped\`); every other cell keeps its score through the merge.`
|
|
18369
|
+
);
|
|
18370
|
+
}
|
|
18371
|
+
if (newest !== void 0 && requested < newest) {
|
|
18372
|
+
throw new Error(
|
|
18373
|
+
`"${requested}" sorts before "${newest}", and audits merge latest-wins in lexical order \u2014 its scores would be outvoted by the older ones they replace. Name one that sorts last (e.g. \`${month}-scoped\`).`
|
|
18374
|
+
);
|
|
18375
|
+
}
|
|
18376
|
+
return requested;
|
|
18377
|
+
}
|
|
18378
|
+
if (newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since) {
|
|
18379
|
+
return newest;
|
|
18380
|
+
}
|
|
18381
|
+
for (let n = 1; n < 100; n++) {
|
|
18382
|
+
const candidate = n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
|
|
18383
|
+
if (existing.includes(candidate)) continue;
|
|
18384
|
+
if (newest !== void 0 && candidate < newest) {
|
|
18385
|
+
throw new Error(
|
|
18386
|
+
`"${candidate}" would sort before "${newest}", so its scores would lose the latest-wins merge. Name the scoped audit yourself with --audit, one that sorts after "${newest}".`
|
|
18387
|
+
);
|
|
18388
|
+
}
|
|
18389
|
+
return candidate;
|
|
18390
|
+
}
|
|
18391
|
+
throw new Error(`99 scoped audits in ${month} \u2014 name the next one with --audit.`);
|
|
18392
|
+
}
|
|
18393
|
+
function declaredScopeSince(auditId, recorded) {
|
|
18394
|
+
if (recorded.includes(auditId)) {
|
|
18395
|
+
throw new Error(
|
|
18396
|
+
`"${auditId}" is already recorded, so declaring it scoped would re-record that reading as a partial one. If you re-scored inside the audit a scope was measured from, move those scores into an audit of their own. If "${auditId}" really is a scoped re-audit recorded without its marker, add "scope": { "since": "<the audit it followed>" } to its scores.json and record it again.`
|
|
18397
|
+
);
|
|
18398
|
+
}
|
|
18399
|
+
const before = recorded.filter((id) => id < auditId).sort();
|
|
18400
|
+
const since = before[before.length - 1];
|
|
18401
|
+
if (since === void 0) {
|
|
18402
|
+
throw new Error(
|
|
18403
|
+
`no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
|
|
18404
|
+
);
|
|
18405
|
+
}
|
|
18406
|
+
return since;
|
|
18407
|
+
}
|
|
18408
|
+
function auditOrderNote(root, auditId) {
|
|
18409
|
+
const later = listAuditIds(root).filter((id) => id > auditId);
|
|
18410
|
+
if (later.length === 0) return void 0;
|
|
18411
|
+
return `"${auditId}" sorts before ${later.map((id) => `"${id}"`).join(", ")} \u2014 audits merge latest-wins in id order, so for any cell ${later.length === 1 ? "that audit" : "those audits"} also hold${later.length === 1 ? "s" : ""}, the later score wins. Name a new audit so it sorts last.`;
|
|
18412
|
+
}
|
|
17998
18413
|
function computeAuditMatrix(root, auditId, library) {
|
|
17999
18414
|
const scores = loadScores(root, auditId);
|
|
18000
18415
|
const section = loadQualitySection(root, auditId, library, scores);
|
|
@@ -18325,10 +18740,38 @@ function buildKritikCatalog(ctx) {
|
|
|
18325
18740
|
throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
|
|
18326
18741
|
}
|
|
18327
18742
|
};
|
|
18743
|
+
const scopeOf = (graph, options = {}) => {
|
|
18744
|
+
if (options.since !== void 0) {
|
|
18745
|
+
const recorded = recordedAuditIds(graph.journal);
|
|
18746
|
+
if (!recorded.includes(options.since)) {
|
|
18747
|
+
throw new ToolError(
|
|
18748
|
+
`No recorded audit "${options.since}" in this journal (recorded: ${recorded.join(", ") || "none"}). A scope is measured from a recorded reading \u2014 kritik_matrix with record=true writes one.`
|
|
18749
|
+
);
|
|
18750
|
+
}
|
|
18751
|
+
}
|
|
18752
|
+
let section;
|
|
18753
|
+
let library;
|
|
18754
|
+
if (ctx.qualityRoot === void 0) {
|
|
18755
|
+
const hosted = hostedSection(graph);
|
|
18756
|
+
section = hosted.section;
|
|
18757
|
+
library = hosted.library ?? { criteria: [] };
|
|
18758
|
+
} else {
|
|
18759
|
+
const root = ctx.qualityRoot;
|
|
18760
|
+
const full = libraryOf(root);
|
|
18761
|
+
const profile = profileOf(root);
|
|
18762
|
+
try {
|
|
18763
|
+
section = loadCurrentQualitySection(root, full) ?? { profile, assessments: [], findings: [] };
|
|
18764
|
+
} catch (error51) {
|
|
18765
|
+
throw new ToolError(error51.message);
|
|
18766
|
+
}
|
|
18767
|
+
library = full;
|
|
18768
|
+
}
|
|
18769
|
+
return deriveAuditScope(graph.journal, section, library, options);
|
|
18770
|
+
};
|
|
18328
18771
|
tool(
|
|
18329
18772
|
{
|
|
18330
18773
|
name: "kritik_matrix",
|
|
18331
|
-
description: "The comparative quality matrix: a score and grade per (domain x surface), the weighted roll-up per surface, and open findings by priority lane. Anti-averaging caps are applied \u2014 one open Critical caps its cell at D, one open High at B \u2014 so a cell full of 3s cannot absorb a live defect. In repo mode this refreshes the audit's matrix.json, and with record=true appends quality.audit.completed; in hosted mode it is a read of the stored quality section (no audit_id/commit \u2014 hosted has no audit file) and record is refused \u2014 recording belongs to the audit run, which reads code.",
|
|
18774
|
+
description: "The comparative quality matrix: a score and grade per (domain x surface), the weighted roll-up per surface, and open findings by priority lane. Anti-averaging caps are applied \u2014 one open Critical caps its cell at D, one open High at B \u2014 so a cell full of 3s cannot absorb a live defect. In repo mode this refreshes the audit's matrix.json, and with record=true appends quality.audit.completed; in hosted mode it is a read of the stored quality section (no audit_id/commit \u2014 hosted has no audit file) and record is refused \u2014 recording belongs to the audit run, which reads code. A scoped re-audit (scored with kritik_score scope=true, or declared with scope=true here) returns `scope` and records the MERGED matrix through it with a scope marker, so the trend never reads its unscored cells as dropped; matrix.json stays this audit alone.",
|
|
18332
18775
|
inputSchema: {
|
|
18333
18776
|
type: "object",
|
|
18334
18777
|
properties: {
|
|
@@ -18336,6 +18779,10 @@ function buildKritikCatalog(ctx) {
|
|
|
18336
18779
|
record: {
|
|
18337
18780
|
type: "boolean",
|
|
18338
18781
|
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit."
|
|
18782
|
+
},
|
|
18783
|
+
scope: {
|
|
18784
|
+
type: "boolean",
|
|
18785
|
+
description: "Treat the audit as a scoped re-audit even though it was scored without kritik_score scope=true (which marks it). Repo mode only."
|
|
18339
18786
|
}
|
|
18340
18787
|
},
|
|
18341
18788
|
additionalProperties: false
|
|
@@ -18345,11 +18792,12 @@ function buildKritikCatalog(ctx) {
|
|
|
18345
18792
|
const hosted = ctx.qualityRoot === void 0;
|
|
18346
18793
|
if (hosted) {
|
|
18347
18794
|
if (args.record === true) refuseHostedRecord("quality.audit.completed");
|
|
18795
|
+
if (args.scope === true) throw new ToolError("A scoped re-audit is an audit run, which reads code \u2014 the hosted matrix is the current state.");
|
|
18348
18796
|
if (typeof args.audit_id === "string" && args.audit_id !== "") {
|
|
18349
18797
|
throw new ToolError("The hosted matrix is the current state, not one audit \u2014 audit_id does not partition it (issue #400 decision 3).");
|
|
18350
18798
|
}
|
|
18351
|
-
const
|
|
18352
|
-
const { section: section2, library: library2 } = hostedSection(
|
|
18799
|
+
const graph2 = await load2();
|
|
18800
|
+
const { section: section2, library: library2 } = hostedSection(graph2);
|
|
18353
18801
|
const m = deriveQualityMatrix({ quality: section2 }, library2);
|
|
18354
18802
|
const { open: open2, lanes: lanes2, p0: p02 } = openFindingsSummary(section2.findings, library2);
|
|
18355
18803
|
return {
|
|
@@ -18380,19 +18828,48 @@ function buildKritikCatalog(ctx) {
|
|
|
18380
18828
|
}
|
|
18381
18829
|
const { section, matrix, file: file2 } = computed;
|
|
18382
18830
|
const { open, lanes, p0 } = openFindingsSummary(section.findings, library);
|
|
18831
|
+
let graph;
|
|
18832
|
+
let since = loadScoresOrEmpty(root, auditId).scope?.since;
|
|
18833
|
+
if (since === void 0 && args.scope === true) {
|
|
18834
|
+
graph = await load2();
|
|
18835
|
+
try {
|
|
18836
|
+
since = declaredScopeSince(auditId, recordedAuditIds(graph.journal));
|
|
18837
|
+
} catch (error51) {
|
|
18838
|
+
throw new ToolError(`scope=true refused \u2014 ${error51.message}`);
|
|
18839
|
+
}
|
|
18840
|
+
}
|
|
18841
|
+
const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
|
|
18842
|
+
let leftUnscored = [];
|
|
18843
|
+
if (scope !== void 0) {
|
|
18844
|
+
graph = graph ?? await load2();
|
|
18845
|
+
const current = scopeOf(graph);
|
|
18846
|
+
if (current.since === scope.since) {
|
|
18847
|
+
const done = new Set(section.assessments.map((a) => `${a.criterion_id}::${a.surface}`));
|
|
18848
|
+
leftUnscored = current.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`)).map((cell) => ({ criterion_id: cell.criterion_id, surface: cell.surface, kind: cell.kind }));
|
|
18849
|
+
}
|
|
18850
|
+
}
|
|
18383
18851
|
let events = [];
|
|
18384
18852
|
if (args.record === true) {
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18853
|
+
let recorded = matrix;
|
|
18854
|
+
if (scope !== void 0) {
|
|
18855
|
+
try {
|
|
18856
|
+
recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(root, auditId, library) }, library);
|
|
18857
|
+
} catch (error51) {
|
|
18858
|
+
throw new ToolError(error51.message);
|
|
18859
|
+
}
|
|
18860
|
+
}
|
|
18861
|
+
events = await record2(graph ?? await load2(), [
|
|
18862
|
+
auditCompletedInput(recorded, {
|
|
18388
18863
|
audit_id: auditId,
|
|
18389
18864
|
framework_version: file2.framework_version,
|
|
18390
|
-
...file2.commit !== void 0 ? { commit: file2.commit } : {}
|
|
18865
|
+
...file2.commit !== void 0 ? { commit: file2.commit } : {},
|
|
18866
|
+
...scope !== void 0 ? { scope } : {}
|
|
18391
18867
|
})
|
|
18392
18868
|
]);
|
|
18393
18869
|
}
|
|
18394
18870
|
return {
|
|
18395
18871
|
...file2,
|
|
18872
|
+
...scope !== void 0 ? { scope, left_unscored: leftUnscored } : {},
|
|
18396
18873
|
assessment_count: section.assessments.length,
|
|
18397
18874
|
open_findings: open.length,
|
|
18398
18875
|
lanes,
|
|
@@ -18486,7 +18963,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18486
18963
|
tool(
|
|
18487
18964
|
{
|
|
18488
18965
|
name: "kritik_regressions",
|
|
18489
|
-
description: "What got worse between two audits: a cell whose maturity level dropped, a cell that gained an open Critical or High finding, and a finding that was resolved and is open again.
|
|
18966
|
+
description: "What got worse between two audits: a cell whose maturity level dropped, a cell that gained an open Critical or High finding, and a finding that was resolved and is open again. In repo mode each side is every audit through it, merged latest-wins, so a scoped re-audit's cells are compared with their last reading wherever it was taken; cells with no reading on one side are not compared \u2014 a half-finished audit is not a regression. With record=true, appends one quality.signal.tripped per regression (repo mode only \u2014 hosted comparisons are read-only and cover assessment-level drops, since hosted findings are a living pool rather than per-audit snapshots). A tripped signal is NOT a finding; it is the prompt to go look.",
|
|
18490
18967
|
inputSchema: {
|
|
18491
18968
|
type: "object",
|
|
18492
18969
|
properties: {
|
|
@@ -18536,8 +19013,8 @@ function buildKritikCatalog(ctx) {
|
|
|
18536
19013
|
let regressions;
|
|
18537
19014
|
try {
|
|
18538
19015
|
regressions = detectRegressions(
|
|
18539
|
-
|
|
18540
|
-
|
|
19016
|
+
loadQualitySectionThrough(root, from, library),
|
|
19017
|
+
loadQualitySectionThrough(root, to, library),
|
|
18541
19018
|
library
|
|
18542
19019
|
);
|
|
18543
19020
|
} catch (error51) {
|
|
@@ -18561,6 +19038,64 @@ function buildKritikCatalog(ctx) {
|
|
|
18561
19038
|
return { from, to, total: regressions.length, regressions, events };
|
|
18562
19039
|
}
|
|
18563
19040
|
);
|
|
19041
|
+
tool(
|
|
19042
|
+
{
|
|
19043
|
+
name: "kritik_trend",
|
|
19044
|
+
description: "Where the product stood at each recorded audit, oldest first: one row per quality.audit.completed in the journal, the overall score per surface (or one domain's score with domain), and how each moved against the row above. The score, not the findings \u2014 'from where we started to where we are now'. Rows are ordered by when they were recorded, a re-recorded audit id keeps only its latest reading, and a framework major bump between two audits marks the later row comparable=false with no delta across it. Works in both modes: repo reads the journal sidecar, hosted reads the hosted journal.",
|
|
19045
|
+
inputSchema: {
|
|
19046
|
+
type: "object",
|
|
19047
|
+
properties: {
|
|
19048
|
+
surface: { type: "string", description: "One column only." },
|
|
19049
|
+
domain: { type: "string", description: "Domain code, e.g. SEC \u2014 that domain's score per surface instead of the roll-up." }
|
|
19050
|
+
},
|
|
19051
|
+
additionalProperties: false
|
|
19052
|
+
}
|
|
19053
|
+
},
|
|
19054
|
+
async (args) => {
|
|
19055
|
+
const graph = await load2();
|
|
19056
|
+
const profile = ctx.qualityRoot === void 0 ? graph.loaded.bundle.quality?.profile : loadProfile(ctx.qualityRoot) ?? void 0;
|
|
19057
|
+
const trend = deriveQualityTrend(graph.journal, profile);
|
|
19058
|
+
const filter = {
|
|
19059
|
+
...typeof args.surface === "string" && args.surface !== "" ? { surface: args.surface } : {},
|
|
19060
|
+
...typeof args.domain === "string" && args.domain !== "" ? { domain: args.domain } : {}
|
|
19061
|
+
};
|
|
19062
|
+
const { surfaces, rows } = trendRows(trend, filter);
|
|
19063
|
+
return {
|
|
19064
|
+
total: trend.snapshots.length,
|
|
19065
|
+
surfaces,
|
|
19066
|
+
rows,
|
|
19067
|
+
snapshots: trend.snapshots,
|
|
19068
|
+
...trend.snapshots.length === 0 ? { note: "No recorded audits yet \u2014 `kritik_matrix` with record=true writes one." } : {}
|
|
19069
|
+
};
|
|
19070
|
+
}
|
|
19071
|
+
);
|
|
19072
|
+
tool(
|
|
19073
|
+
{
|
|
19074
|
+
name: "kritik_scope",
|
|
19075
|
+
description: "The cells a batch of fixes made stale \u2014 the work list for a scoped re-audit. A score only moves when its cell is re-scored, so after closing findings this lists exactly which (criterion x surface) cells to re-score instead of running a comprehensive audit: every quality.finding.resolved since the last recorded audit names its cell (`kind: direct`, `because` = finding ids), and one hop over node_ids adds neighbouring assessed cells a shared fix plausibly moved (`kind: widened`, `because` = node ids). Accepted risks are not fixes and never scope anything. `unknown` lists resolved ids that name no finding \u2014 report those, something closed an id that does not exist; `unscorable` lists resolved findings whose cell nothing can re-score (a retired criterion, a surface no longer in the profile). It plans an audit and scores nothing: re-score each cell with kritik_score, evidence and scope=true (which writes into an audit of its own, `<YYYY-MM>-scoped`, never the `since` audit whose recorded reading is history), then kritik_matrix with that audit_id and record=true. Recording closes the window: a cell left unscored drops out of the next scope, so re-score a widened cell that did not move at its current level, saying so in the evidence. Works in both modes \u2014 hosted reads the hosted journal and quality section.",
|
|
19076
|
+
inputSchema: {
|
|
19077
|
+
type: "object",
|
|
19078
|
+
properties: {
|
|
19079
|
+
since: { type: "string", description: "The recorded audit to measure from. Default: the newest quality.audit.completed." },
|
|
19080
|
+
widen: { type: "boolean", description: "Add the one-hop node neighbours. Default: true." }
|
|
19081
|
+
},
|
|
19082
|
+
additionalProperties: false
|
|
19083
|
+
}
|
|
19084
|
+
},
|
|
19085
|
+
async (args) => {
|
|
19086
|
+
const graph = await load2();
|
|
19087
|
+
const since = typeof args.since === "string" && args.since !== "" ? args.since : void 0;
|
|
19088
|
+
const scope = scopeOf(graph, {
|
|
19089
|
+
...since !== void 0 ? { since } : {},
|
|
19090
|
+
...args.widen === false ? { widen: false } : {}
|
|
19091
|
+
});
|
|
19092
|
+
return {
|
|
19093
|
+
...scope,
|
|
19094
|
+
summary: scopeSummary(scope),
|
|
19095
|
+
...scope.since === null ? { note: "No recorded audit yet \u2014 a scope is measured from one. `kritik_matrix` with record=true writes it." } : {}
|
|
19096
|
+
};
|
|
19097
|
+
}
|
|
19098
|
+
);
|
|
18564
19099
|
tool(
|
|
18565
19100
|
{
|
|
18566
19101
|
name: "kritik_issue",
|
|
@@ -18621,7 +19156,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18621
19156
|
tool(
|
|
18622
19157
|
{
|
|
18623
19158
|
name: "kritik_score",
|
|
18624
|
-
description: "Record one (criterion x surface) maturity level with the evidence behind it. A cell holds exactly one level, so re-scoring replaces in place. Evidence is required: a score without a citation is an opinion, not an assessment. Score what the code IS, never what an open PR promises \u2014 that is what makes a trend real. Repo sessions only: scoring reads the code, so a hosted session refuses.",
|
|
19159
|
+
description: "Record one (criterion x surface) maturity level with the evidence behind it. A cell holds exactly one level, so re-scoring replaces in place. Evidence is required: a score without a citation is an opinion, not an assessment. Score what the code IS, never what an open PR promises \u2014 that is what makes a trend real. For a scoped re-audit pass scope=true: a cell kritik_scope does not list is refused (so a between-milestone re-audit cannot drift into a comprehensive one), and the score lands in a scoped audit of its own (default <YYYY-MM>-scoped). Repo sessions only: scoring reads the code, so a hosted session refuses.",
|
|
18625
19160
|
inputSchema: {
|
|
18626
19161
|
type: "object",
|
|
18627
19162
|
properties: {
|
|
@@ -18633,8 +19168,15 @@ function buildKritikCatalog(ctx) {
|
|
|
18633
19168
|
description: "0 Absent \xB7 1 Ad-hoc \xB7 2 Defined \xB7 3 Managed \xB7 4 Verified. N/A is the absence of the row, not a level."
|
|
18634
19169
|
},
|
|
18635
19170
|
evidence: { type: "string", description: "file:line / config citations, markdown." },
|
|
18636
|
-
audit_id: {
|
|
18637
|
-
|
|
19171
|
+
audit_id: {
|
|
19172
|
+
type: "string",
|
|
19173
|
+
description: "Default: the newest audit, or the current YYYY-MM. With scope=true: the scoped audit in progress, else <YYYY-MM>-scoped."
|
|
19174
|
+
},
|
|
19175
|
+
commit: { type: "string" },
|
|
19176
|
+
scope: {
|
|
19177
|
+
type: "boolean",
|
|
19178
|
+
description: "This is a scoped re-audit: refuse a cell kritik_scope does not list. Leave it off to re-score an out-of-scope cell on purpose."
|
|
19179
|
+
}
|
|
18638
19180
|
},
|
|
18639
19181
|
required: ["criterion_id", "surface", "level", "evidence"],
|
|
18640
19182
|
additionalProperties: false
|
|
@@ -18655,7 +19197,42 @@ function buildKritikCatalog(ctx) {
|
|
|
18655
19197
|
`${criterionId} does not apply to "${surface}" (applies to: ${appliesTo.join(", ")}). Scoring it there would produce a cell nothing rolls up.`
|
|
18656
19198
|
);
|
|
18657
19199
|
}
|
|
18658
|
-
|
|
19200
|
+
let scopedFrom;
|
|
19201
|
+
let auditId;
|
|
19202
|
+
const graph = await load2();
|
|
19203
|
+
if (args.scope === true) {
|
|
19204
|
+
const scope = scopeOf(graph);
|
|
19205
|
+
if (scope.since === null) {
|
|
19206
|
+
throw new ToolError("scope=true needs a recorded audit to measure from \u2014 kritik_matrix with record=true writes one.");
|
|
19207
|
+
}
|
|
19208
|
+
if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
|
|
19209
|
+
throw new ToolError(
|
|
19210
|
+
`${criterionId} x ${surface} is not in the current scope (${scopeSummary(scope)}). kritik_scope lists the cells; leave scope off to re-score this one on purpose.`
|
|
19211
|
+
);
|
|
19212
|
+
}
|
|
19213
|
+
try {
|
|
19214
|
+
auditId = scopedAuditTarget(
|
|
19215
|
+
root,
|
|
19216
|
+
scope.since,
|
|
19217
|
+
currentAuditId(),
|
|
19218
|
+
typeof args.audit_id === "string" && args.audit_id !== "" ? args.audit_id : void 0,
|
|
19219
|
+
recordedAuditIds(graph.journal)
|
|
19220
|
+
);
|
|
19221
|
+
} catch (error51) {
|
|
19222
|
+
throw new ToolError(error51.message);
|
|
19223
|
+
}
|
|
19224
|
+
scopedFrom = scope.since;
|
|
19225
|
+
} else {
|
|
19226
|
+
auditId = auditForWrite(root, args.audit_id);
|
|
19227
|
+
}
|
|
19228
|
+
const notes = [];
|
|
19229
|
+
if (scopedFrom === void 0) {
|
|
19230
|
+
if (recordedAuditIds(graph.journal).includes(auditId)) {
|
|
19231
|
+
notes.push(`${auditId} is already recorded \u2014 a re-score here rewrites that reading. For a re-audit after fixes, pass scope=true.`);
|
|
19232
|
+
}
|
|
19233
|
+
const order = auditOrderNote(root, auditId);
|
|
19234
|
+
if (order !== void 0) notes.push(order);
|
|
19235
|
+
}
|
|
18659
19236
|
const file2 = loadScoresOrEmpty(root, auditId);
|
|
18660
19237
|
const assessment = {
|
|
18661
19238
|
criterion_id: criterionId,
|
|
@@ -18672,14 +19249,17 @@ function buildKritikCatalog(ctx) {
|
|
|
18672
19249
|
audit_id: auditId,
|
|
18673
19250
|
framework_version: file2.framework_version ?? library.version,
|
|
18674
19251
|
...typeof args.commit === "string" ? { commit: args.commit } : {},
|
|
19252
|
+
...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
|
|
18675
19253
|
assessments
|
|
18676
19254
|
});
|
|
18677
19255
|
return {
|
|
18678
19256
|
assessment,
|
|
18679
19257
|
audit_id: auditId,
|
|
19258
|
+
...scopedFrom !== void 0 ? { scoped_from: scopedFrom } : {},
|
|
18680
19259
|
assessment_count: assessments.length,
|
|
18681
19260
|
...replaced !== void 0 ? { replaced_level: replaced.level } : {},
|
|
18682
|
-
anchor: criterion.level_anchors?.[`l${level}`]
|
|
19261
|
+
anchor: criterion.level_anchors?.[`l${level}`],
|
|
19262
|
+
...notes.length > 0 ? { notes } : {}
|
|
18683
19263
|
};
|
|
18684
19264
|
}
|
|
18685
19265
|
);
|
|
@@ -19675,7 +20255,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
|
|
|
19675
20255
|
}
|
|
19676
20256
|
|
|
19677
20257
|
// src/index.ts
|
|
19678
|
-
var VERSION = "0.
|
|
20258
|
+
var VERSION = "0.6.0";
|
|
19679
20259
|
var argv = process.argv.slice(2);
|
|
19680
20260
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
19681
20261
|
process.stdout.write(
|
package/package.json
CHANGED