arkaik-mcp 0.5.0 → 0.7.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 +739 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15338,7 +15338,27 @@ 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()
|
|
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()
|
|
15348
|
+
}).catchall(external_exports.unknown()).optional(),
|
|
15349
|
+
// A reading synthesized from a stored audit that arrived without one (issue #472).
|
|
15350
|
+
baseline: external_exports.boolean().optional()
|
|
15351
|
+
}).catchall(external_exports.unknown());
|
|
15352
|
+
var QualityAssessmentScoredEventSchema = external_exports.object({
|
|
15353
|
+
...envelope,
|
|
15354
|
+
type: external_exports.literal("quality.assessment.scored"),
|
|
15355
|
+
audit_id: external_exports.string(),
|
|
15356
|
+
criterion_id: external_exports.string(),
|
|
15357
|
+
surface: external_exports.string(),
|
|
15358
|
+
level: external_exports.number().int().min(0).max(4),
|
|
15359
|
+
evidence: external_exports.string(),
|
|
15360
|
+
commit: external_exports.string().optional(),
|
|
15361
|
+
scope: external_exports.object({ since: external_exports.string().optional() }).catchall(external_exports.unknown()).optional()
|
|
15342
15362
|
}).catchall(external_exports.unknown());
|
|
15343
15363
|
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
15344
15364
|
...envelope,
|
|
@@ -15392,6 +15412,7 @@ var JOURNAL_EVENT_SCHEMAS = {
|
|
|
15392
15412
|
"ref.status_changed": RefStatusChangedEventSchema,
|
|
15393
15413
|
"journal.baseline": JournalBaselineEventSchema,
|
|
15394
15414
|
"quality.audit.completed": QualityAuditCompletedEventSchema,
|
|
15415
|
+
"quality.assessment.scored": QualityAssessmentScoredEventSchema,
|
|
15395
15416
|
"quality.finding.opened": QualityFindingOpenedEventSchema,
|
|
15396
15417
|
"quality.finding.resolved": QualityFindingResolvedEventSchema,
|
|
15397
15418
|
"quality.finding.accepted": QualityFindingAcceptedEventSchema,
|
|
@@ -15414,6 +15435,7 @@ var KnownJournalEventSchema = external_exports.union([
|
|
|
15414
15435
|
RefStatusChangedEventSchema,
|
|
15415
15436
|
JournalBaselineEventSchema,
|
|
15416
15437
|
QualityAuditCompletedEventSchema,
|
|
15438
|
+
QualityAssessmentScoredEventSchema,
|
|
15417
15439
|
QualityFindingOpenedEventSchema,
|
|
15418
15440
|
QualityFindingResolvedEventSchema,
|
|
15419
15441
|
QualityFindingAcceptedEventSchema,
|
|
@@ -17791,7 +17813,8 @@ function auditCompletedInput(matrix, meta3) {
|
|
|
17791
17813
|
framework_version: meta3.framework_version,
|
|
17792
17814
|
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
17793
17815
|
scores,
|
|
17794
|
-
counts: matrix.finding_counts
|
|
17816
|
+
counts: matrix.finding_counts,
|
|
17817
|
+
...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
|
|
17795
17818
|
}
|
|
17796
17819
|
};
|
|
17797
17820
|
}
|
|
@@ -17923,6 +17946,10 @@ function sameFrameworkMajor(a, b) {
|
|
|
17923
17946
|
const right = frameworkMajor(b);
|
|
17924
17947
|
return left === null || right === null || left === right;
|
|
17925
17948
|
}
|
|
17949
|
+
function scopeOf(raw) {
|
|
17950
|
+
if (!isRecord2(raw) || typeof raw.since !== "string" || raw.since === "") return void 0;
|
|
17951
|
+
return { scope: { since: raw.since, cells: typeof raw.cells === "number" && Number.isFinite(raw.cells) ? raw.cells : null } };
|
|
17952
|
+
}
|
|
17926
17953
|
function cleanScores(raw) {
|
|
17927
17954
|
const scores = {};
|
|
17928
17955
|
if (!isRecord2(raw)) return scores;
|
|
@@ -17993,7 +18020,9 @@ function deriveQualityTrend(events, profile, live) {
|
|
|
17993
18020
|
comparable: true,
|
|
17994
18021
|
scores,
|
|
17995
18022
|
overall,
|
|
17996
|
-
counts: cleanCounts(event.counts)
|
|
18023
|
+
counts: cleanCounts(event.counts),
|
|
18024
|
+
...event.baseline === true ? { baseline: true } : {},
|
|
18025
|
+
...scopeOf(event.scope) ?? {}
|
|
17997
18026
|
};
|
|
17998
18027
|
byAudit.delete(auditId);
|
|
17999
18028
|
byAudit.set(auditId, snapshot);
|
|
@@ -18049,12 +18078,287 @@ function trendRows(trend, filter = {}) {
|
|
|
18049
18078
|
...snapshot.commit !== void 0 ? { commit: snapshot.commit } : {},
|
|
18050
18079
|
...snapshot.framework_version !== void 0 ? { framework_version: snapshot.framework_version } : {},
|
|
18051
18080
|
comparable: snapshot.comparable,
|
|
18052
|
-
cells
|
|
18081
|
+
cells,
|
|
18082
|
+
...snapshot.baseline ? { baseline: true } : {},
|
|
18083
|
+
...snapshot.scope !== void 0 ? { scope: snapshot.scope } : {}
|
|
18053
18084
|
});
|
|
18054
18085
|
});
|
|
18055
18086
|
return { surfaces, rows };
|
|
18056
18087
|
}
|
|
18057
18088
|
|
|
18089
|
+
// ../schema/src/quality-scope.ts
|
|
18090
|
+
var rowsOf2 = (value) => Array.isArray(value) ? value : [];
|
|
18091
|
+
var isString = (value) => typeof value === "string" && value !== "";
|
|
18092
|
+
var stringsOf = (value) => rowsOf2(value).filter(isString);
|
|
18093
|
+
var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
|
|
18094
|
+
function recordedAuditIds(events) {
|
|
18095
|
+
const ids = [];
|
|
18096
|
+
for (const event of orderEvents(rowsOf2(events))) {
|
|
18097
|
+
if (event?.type !== "quality.audit.completed") continue;
|
|
18098
|
+
const id = event.audit_id;
|
|
18099
|
+
if (isString(id) && !ids.includes(id)) ids.push(id);
|
|
18100
|
+
}
|
|
18101
|
+
return ids;
|
|
18102
|
+
}
|
|
18103
|
+
function deriveAuditScope(events, section, library, options = {}) {
|
|
18104
|
+
const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
|
|
18105
|
+
let sinceIndex = -1;
|
|
18106
|
+
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
18107
|
+
const event = ordered[i];
|
|
18108
|
+
if (event.type !== "quality.audit.completed") continue;
|
|
18109
|
+
const id = event.audit_id;
|
|
18110
|
+
if (options.since !== void 0 && id !== options.since) continue;
|
|
18111
|
+
sinceIndex = i;
|
|
18112
|
+
break;
|
|
18113
|
+
}
|
|
18114
|
+
const empty = {
|
|
18115
|
+
since: options.since ?? null,
|
|
18116
|
+
since_ts: null,
|
|
18117
|
+
cells: [],
|
|
18118
|
+
findings: [],
|
|
18119
|
+
resolved_by: {},
|
|
18120
|
+
unknown: [],
|
|
18121
|
+
unscorable: [],
|
|
18122
|
+
widened: 0
|
|
18123
|
+
};
|
|
18124
|
+
if (sinceIndex === -1) return empty;
|
|
18125
|
+
const anchor = ordered[sinceIndex];
|
|
18126
|
+
const anchorId = anchor.audit_id;
|
|
18127
|
+
const since = isString(anchorId) ? anchorId : null;
|
|
18128
|
+
const sinceTs = isString(anchor.ts) ? anchor.ts : null;
|
|
18129
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
18130
|
+
for (const event of ordered.slice(sinceIndex + 1)) {
|
|
18131
|
+
if (event.type !== "quality.finding.resolved") continue;
|
|
18132
|
+
const findingId = event.finding_id;
|
|
18133
|
+
if (!isString(findingId)) continue;
|
|
18134
|
+
const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
|
|
18135
|
+
const by = event.resolved_by;
|
|
18136
|
+
if (isString(by)) entry.resolved_by = by;
|
|
18137
|
+
for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
|
|
18138
|
+
resolutions.set(findingId, entry);
|
|
18139
|
+
}
|
|
18140
|
+
if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
|
|
18141
|
+
const findings = rowsOf2(section?.findings).filter(
|
|
18142
|
+
(finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
|
|
18143
|
+
);
|
|
18144
|
+
const findingById = /* @__PURE__ */ new Map();
|
|
18145
|
+
for (const finding of findings) findingById.set(finding.id, finding);
|
|
18146
|
+
const criterionById = /* @__PURE__ */ new Map();
|
|
18147
|
+
for (const criterion of rowsOf2(library?.criteria)) {
|
|
18148
|
+
if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
|
|
18149
|
+
}
|
|
18150
|
+
const assessmentByCell = /* @__PURE__ */ new Map();
|
|
18151
|
+
for (const assessment of rowsOf2(section?.assessments)) {
|
|
18152
|
+
if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
|
|
18153
|
+
assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
|
|
18154
|
+
}
|
|
18155
|
+
const declared2 = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
|
|
18156
|
+
const surfaces = declared2.length > 0 ? [...new Set(declared2)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
|
|
18157
|
+
const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
|
|
18158
|
+
const scorable = (criterionId, surface) => {
|
|
18159
|
+
const criterion = criterionById.get(criterionId);
|
|
18160
|
+
if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
|
|
18161
|
+
if (declared2.length > 0 && !surfaces.includes(surface)) return false;
|
|
18162
|
+
return appliesTo(criterion, surface);
|
|
18163
|
+
};
|
|
18164
|
+
const cells = /* @__PURE__ */ new Map();
|
|
18165
|
+
const addDirect = (criterionId, surface, findingId) => {
|
|
18166
|
+
const key = cellKey2(criterionId, surface);
|
|
18167
|
+
const existing = cells.get(key);
|
|
18168
|
+
if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
|
|
18169
|
+
else if (!existing.because.includes(findingId)) existing.because.push(findingId);
|
|
18170
|
+
};
|
|
18171
|
+
const drivers = [];
|
|
18172
|
+
const unknown2 = [];
|
|
18173
|
+
const unscorable = [];
|
|
18174
|
+
const resolvedBy = {};
|
|
18175
|
+
const resolvedNodes = /* @__PURE__ */ new Set();
|
|
18176
|
+
for (const [findingId, resolution] of resolutions) {
|
|
18177
|
+
const finding = findingById.get(findingId);
|
|
18178
|
+
if (finding === void 0) {
|
|
18179
|
+
unknown2.push(findingId);
|
|
18180
|
+
continue;
|
|
18181
|
+
}
|
|
18182
|
+
if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
|
|
18183
|
+
const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
|
|
18184
|
+
(surface) => scorable(finding.criterion_id, surface)
|
|
18185
|
+
);
|
|
18186
|
+
for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
|
|
18187
|
+
for (const node of resolution.node_ids) resolvedNodes.add(node);
|
|
18188
|
+
if (targets.length === 0) {
|
|
18189
|
+
unscorable.push(findingId);
|
|
18190
|
+
continue;
|
|
18191
|
+
}
|
|
18192
|
+
drivers.push(findingId);
|
|
18193
|
+
if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
|
|
18194
|
+
for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
|
|
18195
|
+
}
|
|
18196
|
+
let widened = 0;
|
|
18197
|
+
if (options.widen !== false && resolvedNodes.size > 0) {
|
|
18198
|
+
const nodesByCell = /* @__PURE__ */ new Map();
|
|
18199
|
+
const noteNodes = (criterionId, surface, nodes) => {
|
|
18200
|
+
const key = cellKey2(criterionId, surface);
|
|
18201
|
+
const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
|
|
18202
|
+
for (const node of nodes) bucket.add(node);
|
|
18203
|
+
nodesByCell.set(key, bucket);
|
|
18204
|
+
};
|
|
18205
|
+
for (const finding of findings) {
|
|
18206
|
+
const nodes = stringsOf(finding.node_ids);
|
|
18207
|
+
if (nodes.length === 0) continue;
|
|
18208
|
+
if (finding.surface === CROSS_SURFACE_ID) {
|
|
18209
|
+
for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
|
|
18210
|
+
} else {
|
|
18211
|
+
noteNodes(finding.criterion_id, finding.surface, nodes);
|
|
18212
|
+
}
|
|
18213
|
+
}
|
|
18214
|
+
for (const [key, assessment] of assessmentByCell) {
|
|
18215
|
+
if (cells.has(key)) continue;
|
|
18216
|
+
if (!criterionById.has(assessment.criterion_id)) continue;
|
|
18217
|
+
if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
|
|
18218
|
+
const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
|
|
18219
|
+
if (shared.length === 0) continue;
|
|
18220
|
+
cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
|
|
18221
|
+
widened++;
|
|
18222
|
+
}
|
|
18223
|
+
}
|
|
18224
|
+
for (const [key, cell] of cells) {
|
|
18225
|
+
const assessment = assessmentByCell.get(key);
|
|
18226
|
+
if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
|
|
18227
|
+
cell.current = { level: assessment.level, audit_id: assessment.audit_id };
|
|
18228
|
+
}
|
|
18229
|
+
}
|
|
18230
|
+
const column = (surface) => {
|
|
18231
|
+
const at = surfaces.indexOf(surface);
|
|
18232
|
+
return at === -1 ? surfaces.length : at;
|
|
18233
|
+
};
|
|
18234
|
+
const sorted = [...cells.values()].sort(
|
|
18235
|
+
(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)
|
|
18236
|
+
);
|
|
18237
|
+
return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
|
|
18238
|
+
}
|
|
18239
|
+
function scopedAuditId(input) {
|
|
18240
|
+
const { since, month, requested, known, recorded, open } = input;
|
|
18241
|
+
const newest = [...known].sort().at(-1);
|
|
18242
|
+
if (requested !== void 0) {
|
|
18243
|
+
if (requested === since) {
|
|
18244
|
+
throw new Error(
|
|
18245
|
+
`"${requested}" is the audit this scope is measured from \u2014 its recorded reading is history. Name a new audit (e.g. \`${suggestedAuditId(input)}\`); every other cell keeps its score through the merge.`
|
|
18246
|
+
);
|
|
18247
|
+
}
|
|
18248
|
+
if (recorded.includes(requested)) {
|
|
18249
|
+
throw new Error(`"${requested}" is already recorded \u2014 its reading is history. Name a new audit.`);
|
|
18250
|
+
}
|
|
18251
|
+
if (newest !== void 0 && requested < newest) {
|
|
18252
|
+
throw new Error(
|
|
18253
|
+
`"${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. \`${suggestedAuditId(input)}\`).`
|
|
18254
|
+
);
|
|
18255
|
+
}
|
|
18256
|
+
return requested;
|
|
18257
|
+
}
|
|
18258
|
+
if (open !== void 0 && (newest === void 0 || open >= newest)) return open;
|
|
18259
|
+
for (const candidate of scopedCandidates(month)) {
|
|
18260
|
+
if (known.includes(candidate)) continue;
|
|
18261
|
+
if (newest !== void 0 && candidate < newest) {
|
|
18262
|
+
throw new Error(
|
|
18263
|
+
`"${candidate}" would sort before "${newest}", so its scores would lose the latest-wins merge. Name the scoped audit yourself, one that sorts after "${newest}" (e.g. \`${suggestedAuditId(input)}\`).`
|
|
18264
|
+
);
|
|
18265
|
+
}
|
|
18266
|
+
return candidate;
|
|
18267
|
+
}
|
|
18268
|
+
throw new Error(`99 scoped audits in ${month} \u2014 name the next one yourself.`);
|
|
18269
|
+
}
|
|
18270
|
+
function* scopedCandidates(month) {
|
|
18271
|
+
for (let n = 1; n < 100; n++) yield n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
|
|
18272
|
+
}
|
|
18273
|
+
function suggestedAuditId({ since, month, requested, known, recorded }) {
|
|
18274
|
+
const taken = /* @__PURE__ */ new Set([...known, ...recorded, since, ...requested !== void 0 ? [requested] : []]);
|
|
18275
|
+
const floor = [...taken].sort().at(-1);
|
|
18276
|
+
for (const candidate of scopedCandidates(month)) {
|
|
18277
|
+
if (taken.has(candidate)) continue;
|
|
18278
|
+
if (floor === void 0 || candidate > floor) return candidate;
|
|
18279
|
+
}
|
|
18280
|
+
return `${floor}-scoped`;
|
|
18281
|
+
}
|
|
18282
|
+
function scopeSummary(scope) {
|
|
18283
|
+
const direct = scope.cells.length - scope.widened;
|
|
18284
|
+
const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
|
|
18285
|
+
const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
|
|
18286
|
+
const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
|
|
18287
|
+
return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
|
|
18288
|
+
}
|
|
18289
|
+
|
|
18290
|
+
// ../schema/src/quality-baseline.ts
|
|
18291
|
+
var EPOCH = "1970-01-01T00:00:00.000Z";
|
|
18292
|
+
var DECISIONS = /* @__PURE__ */ new Set(["quality.finding.resolved", "quality.finding.accepted"]);
|
|
18293
|
+
var REVERTIBLE = /* @__PURE__ */ new Set(["resolved", "accepted-risk"]);
|
|
18294
|
+
var SCOPED_AUDIT_ID = /-scoped(-\d+)?$/;
|
|
18295
|
+
var rowsOf3 = (value) => Array.isArray(value) ? value : [];
|
|
18296
|
+
var isString2 = (value) => typeof value === "string" && value !== "";
|
|
18297
|
+
var isScopedAuditId = (value) => isString2(value) && SCOPED_AUDIT_ID.test(value);
|
|
18298
|
+
var isRow = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18299
|
+
var objectRowsOf = (value) => rowsOf3(value).filter(isRow);
|
|
18300
|
+
function omit2(obj, keys) {
|
|
18301
|
+
const out = { ...obj };
|
|
18302
|
+
for (const key of keys) delete out[key];
|
|
18303
|
+
return out;
|
|
18304
|
+
}
|
|
18305
|
+
function isoOf(value) {
|
|
18306
|
+
if (!isString2(value)) return void 0;
|
|
18307
|
+
const at = Date.parse(value);
|
|
18308
|
+
return Number.isFinite(at) ? new Date(at).toISOString() : void 0;
|
|
18309
|
+
}
|
|
18310
|
+
function oneMsBefore(iso) {
|
|
18311
|
+
const before = new Date(Date.parse(iso) - 1);
|
|
18312
|
+
return Number.isNaN(before.getTime()) ? EPOCH : before.toISOString();
|
|
18313
|
+
}
|
|
18314
|
+
function implicitAuditBaseline(events, section, library) {
|
|
18315
|
+
const rows = objectRowsOf(events);
|
|
18316
|
+
if (rows.some((event) => event.type === "quality.audit.completed")) return null;
|
|
18317
|
+
const assessmentRows = objectRowsOf(section?.assessments).filter((row) => !isScopedAuditId(row.audit_id));
|
|
18318
|
+
const taggedAssessments = assessmentRows.filter((row) => isString2(row.audit_id));
|
|
18319
|
+
if (taggedAssessments.length === 0) return null;
|
|
18320
|
+
const auditId = taggedAssessments.map((row) => row.audit_id).sort().at(-1);
|
|
18321
|
+
const assessedAts = taggedAssessments.filter((row) => row.audit_id === auditId).map((row) => isoOf(row.ts)).filter((at) => at !== void 0).sort();
|
|
18322
|
+
const auditStart = assessedAts[0];
|
|
18323
|
+
const assessedAt = assessedAts.at(-1);
|
|
18324
|
+
const ordered = orderEvents(rows);
|
|
18325
|
+
const sortKeyOf = (event) => typeof event.ts === "string" ? event.ts : "";
|
|
18326
|
+
const decisions = ordered.filter(
|
|
18327
|
+
(event) => DECISIONS.has(event.type) && (auditStart === void 0 || sortKeyOf(event) >= auditStart)
|
|
18328
|
+
);
|
|
18329
|
+
const firstDecision = decisions[0];
|
|
18330
|
+
let ts;
|
|
18331
|
+
if (firstDecision === void 0) {
|
|
18332
|
+
ts = assessedAt ?? EPOCH;
|
|
18333
|
+
} else {
|
|
18334
|
+
const decidedAt = isoOf(firstDecision.ts);
|
|
18335
|
+
if (decidedAt === void 0) {
|
|
18336
|
+
ts = EPOCH;
|
|
18337
|
+
} else {
|
|
18338
|
+
const justBefore = oneMsBefore(decidedAt);
|
|
18339
|
+
ts = assessedAt !== void 0 && assessedAt < justBefore ? assessedAt : justBefore;
|
|
18340
|
+
}
|
|
18341
|
+
if (!(ts < sortKeyOf(firstDecision))) ts = EPOCH;
|
|
18342
|
+
}
|
|
18343
|
+
const decided = /* @__PURE__ */ new Set();
|
|
18344
|
+
for (const event of decisions) {
|
|
18345
|
+
const id = event.finding_id;
|
|
18346
|
+
if (isString2(id)) decided.add(id);
|
|
18347
|
+
}
|
|
18348
|
+
const findings = objectRowsOf(section?.findings).map((finding) => {
|
|
18349
|
+
if (!isString2(finding.id) || !decided.has(finding.id) || !REVERTIBLE.has(finding.status)) return finding;
|
|
18350
|
+
return { ...omit2(finding, ["resolved_by"]), status: "open" };
|
|
18351
|
+
});
|
|
18352
|
+
const matrix = deriveQualityMatrix({ quality: { ...section, assessments: assessmentRows, findings } }, library);
|
|
18353
|
+
const frameworkVersion = matrix.framework_version ?? library?.version ?? "unknown";
|
|
18354
|
+
const input = auditCompletedInput(matrix, { audit_id: auditId, framework_version: frameworkVersion });
|
|
18355
|
+
return { id: `implicit-baseline:${auditId}`, ts, type: input.type, ...input.payload, baseline: true };
|
|
18356
|
+
}
|
|
18357
|
+
function withImplicitBaseline(events, section, library) {
|
|
18358
|
+
const baseline = implicitAuditBaseline(events, section, library);
|
|
18359
|
+
return baseline === null ? events : [baseline, ...events];
|
|
18360
|
+
}
|
|
18361
|
+
|
|
18058
18362
|
// ../schema/src/cli/kritik-audit.ts
|
|
18059
18363
|
import { existsSync as existsSync2, readdirSync, statSync } from "node:fs";
|
|
18060
18364
|
import { join as join2 } from "node:path";
|
|
@@ -18150,6 +18454,75 @@ function loadQualitySection(root, auditId, library, scores = loadScores(root, au
|
|
|
18150
18454
|
findings: findings.findings
|
|
18151
18455
|
};
|
|
18152
18456
|
}
|
|
18457
|
+
function stripDerived(finding) {
|
|
18458
|
+
const { severity: _severity, priority: _priority, ...rest } = finding;
|
|
18459
|
+
void _severity;
|
|
18460
|
+
void _priority;
|
|
18461
|
+
return rest;
|
|
18462
|
+
}
|
|
18463
|
+
function requireAudit(root, auditId) {
|
|
18464
|
+
if (!listAuditIds(root).includes(auditId)) {
|
|
18465
|
+
throw new Error(`no audit "${auditId}" under ${auditsDir(root)}`);
|
|
18466
|
+
}
|
|
18467
|
+
}
|
|
18468
|
+
function loadCurrentQualitySection(root, library) {
|
|
18469
|
+
const auditIds = listAuditIds(root);
|
|
18470
|
+
if (auditIds.length === 0) return void 0;
|
|
18471
|
+
const profile = loadProfile(root);
|
|
18472
|
+
if (!profile) return void 0;
|
|
18473
|
+
return mergeAudits(root, auditIds, library, profile);
|
|
18474
|
+
}
|
|
18475
|
+
function loadQualitySectionThrough(root, auditId, library) {
|
|
18476
|
+
requireAudit(root, auditId);
|
|
18477
|
+
const auditIds = listAuditIds(root);
|
|
18478
|
+
return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
|
|
18479
|
+
}
|
|
18480
|
+
function mergeAudits(root, auditIds, library, profile) {
|
|
18481
|
+
const cells = /* @__PURE__ */ new Map();
|
|
18482
|
+
const findings = [];
|
|
18483
|
+
let frameworkVersion;
|
|
18484
|
+
for (const id of auditIds) {
|
|
18485
|
+
const scores = loadScoresOrEmpty(root, id);
|
|
18486
|
+
if (typeof scores.framework_version === "string") frameworkVersion = scores.framework_version;
|
|
18487
|
+
for (const assessment of scores.assessments) {
|
|
18488
|
+
cells.set(`${assessment.criterion_id}\0${assessment.surface}`, assessment);
|
|
18489
|
+
}
|
|
18490
|
+
for (const finding of loadFindings(root, id).findings) findings.push(stripDerived(finding));
|
|
18491
|
+
}
|
|
18492
|
+
return {
|
|
18493
|
+
framework_version: frameworkVersion ?? library.version,
|
|
18494
|
+
library,
|
|
18495
|
+
profile,
|
|
18496
|
+
assessments: [...cells.values()],
|
|
18497
|
+
findings
|
|
18498
|
+
};
|
|
18499
|
+
}
|
|
18500
|
+
function scopedAuditTarget(root, since, month, requested, recorded = []) {
|
|
18501
|
+
const known = listAuditIds(root);
|
|
18502
|
+
const newest = known[known.length - 1];
|
|
18503
|
+
const open = newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since ? newest : void 0;
|
|
18504
|
+
return scopedAuditId({ since, month, requested, known, recorded, open });
|
|
18505
|
+
}
|
|
18506
|
+
function declaredScopeSince(auditId, recorded) {
|
|
18507
|
+
if (recorded.includes(auditId)) {
|
|
18508
|
+
throw new Error(
|
|
18509
|
+
`"${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.`
|
|
18510
|
+
);
|
|
18511
|
+
}
|
|
18512
|
+
const before = recorded.filter((id) => id < auditId).sort();
|
|
18513
|
+
const since = before[before.length - 1];
|
|
18514
|
+
if (since === void 0) {
|
|
18515
|
+
throw new Error(
|
|
18516
|
+
`no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
|
|
18517
|
+
);
|
|
18518
|
+
}
|
|
18519
|
+
return since;
|
|
18520
|
+
}
|
|
18521
|
+
function auditOrderNote(root, auditId) {
|
|
18522
|
+
const later = listAuditIds(root).filter((id) => id > auditId);
|
|
18523
|
+
if (later.length === 0) return void 0;
|
|
18524
|
+
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.`;
|
|
18525
|
+
}
|
|
18153
18526
|
function computeAuditMatrix(root, auditId, library) {
|
|
18154
18527
|
const scores = loadScores(root, auditId);
|
|
18155
18528
|
const section = loadQualitySection(root, auditId, library, scores);
|
|
@@ -18337,6 +18710,7 @@ async function appendHosted(store2, inputs) {
|
|
|
18337
18710
|
throw new ToolError(error51.message);
|
|
18338
18711
|
}
|
|
18339
18712
|
}
|
|
18713
|
+
var NO_HOSTED_AUDIT = "This hosted project has no audit to measure from. One must be run in the repository and restored (`arkaik restore`) first \u2014 a hosted session cannot write one.";
|
|
18340
18714
|
function hostedSection(graph) {
|
|
18341
18715
|
const section = graph.loaded.bundle.quality;
|
|
18342
18716
|
if (section === void 0 || !Array.isArray(section.findings) || !Array.isArray(section.assessments)) {
|
|
@@ -18349,6 +18723,21 @@ function hostedSection(graph) {
|
|
|
18349
18723
|
function refuseHostedRecord(eventType) {
|
|
18350
18724
|
throw new ToolError(`Recording ${eventType} belongs to the audit run, which reads code. Run the audit where the checkout is.`);
|
|
18351
18725
|
}
|
|
18726
|
+
function hostedMatrixRead(graph) {
|
|
18727
|
+
const { section, library } = hostedSection(graph);
|
|
18728
|
+
const m = deriveQualityMatrix({ quality: section }, library);
|
|
18729
|
+
const { open, lanes, p0 } = openFindingsSummary(section.findings, library);
|
|
18730
|
+
return {
|
|
18731
|
+
...m.framework_version !== void 0 ? { framework_version: m.framework_version } : {},
|
|
18732
|
+
matrix: m.matrix,
|
|
18733
|
+
overall: m.overall,
|
|
18734
|
+
finding_counts: m.finding_counts,
|
|
18735
|
+
assessment_count: section.assessments.length,
|
|
18736
|
+
open_findings: open.length,
|
|
18737
|
+
lanes,
|
|
18738
|
+
p0
|
|
18739
|
+
};
|
|
18740
|
+
}
|
|
18352
18741
|
function openFindingsSummary(findings, library) {
|
|
18353
18742
|
const open = findings.filter(isOpenFinding);
|
|
18354
18743
|
const lanes = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
@@ -18480,17 +18869,58 @@ function buildKritikCatalog(ctx) {
|
|
|
18480
18869
|
throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
|
|
18481
18870
|
}
|
|
18482
18871
|
};
|
|
18872
|
+
const scopeOf2 = (graph, options = {}) => {
|
|
18873
|
+
let section;
|
|
18874
|
+
let library;
|
|
18875
|
+
let events;
|
|
18876
|
+
if (ctx.qualityRoot === void 0) {
|
|
18877
|
+
const hosted = hostedSection(graph);
|
|
18878
|
+
section = hosted.section;
|
|
18879
|
+
library = hosted.library ?? { criteria: [] };
|
|
18880
|
+
events = withImplicitBaseline(graph.journal, hosted.section, hosted.library);
|
|
18881
|
+
} else {
|
|
18882
|
+
const root = ctx.qualityRoot;
|
|
18883
|
+
const full = libraryOf(root);
|
|
18884
|
+
const profile = profileOf(root);
|
|
18885
|
+
try {
|
|
18886
|
+
section = loadCurrentQualitySection(root, full) ?? { profile, assessments: [], findings: [] };
|
|
18887
|
+
} catch (error51) {
|
|
18888
|
+
throw new ToolError(error51.message);
|
|
18889
|
+
}
|
|
18890
|
+
library = full;
|
|
18891
|
+
events = graph.journal;
|
|
18892
|
+
}
|
|
18893
|
+
if (options.since !== void 0) {
|
|
18894
|
+
const recorded = recordedAuditIds(events);
|
|
18895
|
+
if (!recorded.includes(options.since)) {
|
|
18896
|
+
const hint = ctx.qualityRoot !== void 0 ? "A scope is measured from a recorded reading \u2014 kritik_matrix with record=true writes one." : recorded.length > 0 ? "Pass one of the recorded audits, or leave since off to measure from the newest." : NO_HOSTED_AUDIT;
|
|
18897
|
+
throw new ToolError(`No recorded audit "${options.since}" in this journal (recorded: ${recorded.join(", ") || "none"}). ${hint}`);
|
|
18898
|
+
}
|
|
18899
|
+
}
|
|
18900
|
+
return deriveAuditScope(events, section, library, options);
|
|
18901
|
+
};
|
|
18483
18902
|
tool(
|
|
18484
18903
|
{
|
|
18485
18904
|
name: "kritik_matrix",
|
|
18486
|
-
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 (
|
|
18905
|
+
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, and record=true (with the audit_id kritik_score returned) records that scoped re-audit \u2014 the server computes the reading from the scores it holds, rather than accepting one on the wire. A scoped re-audit (scored with kritik_score scope=true, or, in repo mode, 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.",
|
|
18487
18906
|
inputSchema: {
|
|
18488
18907
|
type: "object",
|
|
18489
18908
|
properties: {
|
|
18490
|
-
audit_id: {
|
|
18909
|
+
audit_id: {
|
|
18910
|
+
type: "string",
|
|
18911
|
+
description: "Default: the newest audit on disk. Hosted: required with record=true, refused otherwise."
|
|
18912
|
+
},
|
|
18491
18913
|
record: {
|
|
18492
18914
|
type: "boolean",
|
|
18493
|
-
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit."
|
|
18915
|
+
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit. Hosted: the server computes the scores and counts."
|
|
18916
|
+
},
|
|
18917
|
+
scope: {
|
|
18918
|
+
type: "boolean",
|
|
18919
|
+
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."
|
|
18920
|
+
},
|
|
18921
|
+
commit: {
|
|
18922
|
+
type: "string",
|
|
18923
|
+
description: "Hosted record only: the commit the scoped re-audit read. Repo mode reads it from the audit's scores.json."
|
|
18494
18924
|
}
|
|
18495
18925
|
},
|
|
18496
18926
|
additionalProperties: false
|
|
@@ -18499,25 +18929,79 @@ function buildKritikCatalog(ctx) {
|
|
|
18499
18929
|
async (args) => {
|
|
18500
18930
|
const hosted = ctx.qualityRoot === void 0;
|
|
18501
18931
|
if (hosted) {
|
|
18502
|
-
if (args.record === true)
|
|
18932
|
+
if (args.record === true) {
|
|
18933
|
+
if (typeof args.audit_id !== "string" || args.audit_id === "") {
|
|
18934
|
+
throw new ToolError(
|
|
18935
|
+
"record=true in a hosted session records a scoped re-audit: pass the audit_id kritik_score returned (e.g. 2026-09-scoped)."
|
|
18936
|
+
);
|
|
18937
|
+
}
|
|
18938
|
+
const auditId2 = args.audit_id;
|
|
18939
|
+
const commit = typeof args.commit === "string" && args.commit !== "" ? args.commit : void 0;
|
|
18940
|
+
const graph3 = await load2();
|
|
18941
|
+
const scope2 = scopeOf2(graph3);
|
|
18942
|
+
const scoredForAudit = graph3.journal.filter(
|
|
18943
|
+
(event) => event.type === "quality.assessment.scored" && event.audit_id === auditId2
|
|
18944
|
+
);
|
|
18945
|
+
const scoredSince = scoredForAudit.map((event) => event.scope?.since).find((since2) => typeof since2 === "string");
|
|
18946
|
+
let leftUnscored2 = [];
|
|
18947
|
+
if (scope2.since !== null && scoredSince === scope2.since) {
|
|
18948
|
+
const done = new Set(
|
|
18949
|
+
scoredForAudit.map(
|
|
18950
|
+
(event) => `${String(event.criterion_id)}::${String(event.surface)}`
|
|
18951
|
+
)
|
|
18952
|
+
);
|
|
18953
|
+
leftUnscored2 = scope2.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`)).map((cell) => ({ criterion_id: cell.criterion_id, surface: cell.surface, kind: cell.kind }));
|
|
18954
|
+
}
|
|
18955
|
+
if (ctx.store.appendQualityEvents === void 0) {
|
|
18956
|
+
throw new ToolError(`${ctx.store.describe()} cannot append quality events.`);
|
|
18957
|
+
}
|
|
18958
|
+
let events2;
|
|
18959
|
+
try {
|
|
18960
|
+
events2 = await ctx.store.appendQualityEvents([
|
|
18961
|
+
{ type: "quality.audit.completed", scope: true, audit_id: auditId2, ...commit !== void 0 ? { commit } : {} }
|
|
18962
|
+
]);
|
|
18963
|
+
} catch (error51) {
|
|
18964
|
+
const refusals = error51.refusals;
|
|
18965
|
+
if (Array.isArray(refusals) && refusals.length > 0 && refusals.every((r) => r.reason === "already_recorded") && scoredForAudit.length > 0) {
|
|
18966
|
+
const reloaded2 = await load2();
|
|
18967
|
+
const landed = reloaded2.journal.find(
|
|
18968
|
+
(event) => event.type === "quality.audit.completed" && event.audit_id === auditId2 && event.baseline !== true && event.scope?.partial === true
|
|
18969
|
+
);
|
|
18970
|
+
if (landed !== void 0) {
|
|
18971
|
+
return {
|
|
18972
|
+
...hostedMatrixRead(reloaded2),
|
|
18973
|
+
audit_id: auditId2,
|
|
18974
|
+
scope: landed.scope,
|
|
18975
|
+
// Not reconstructable: recording re-anchors the scope on
|
|
18976
|
+
// the landed reading itself, so "what's left" no longer
|
|
18977
|
+
// means what it meant before the write landed.
|
|
18978
|
+
events: [landed],
|
|
18979
|
+
note: "Already recorded \u2014 returning the reading that landed. left_unscored can't be reconstructed after recording."
|
|
18980
|
+
};
|
|
18981
|
+
}
|
|
18982
|
+
}
|
|
18983
|
+
throw new ToolError(error51.message);
|
|
18984
|
+
}
|
|
18985
|
+
const reloaded = await load2();
|
|
18986
|
+
const recorded = events2.find((event) => event.type === "quality.audit.completed");
|
|
18987
|
+
return {
|
|
18988
|
+
...hostedMatrixRead(reloaded),
|
|
18989
|
+
audit_id: auditId2,
|
|
18990
|
+
scope: recorded?.scope,
|
|
18991
|
+
left_unscored: leftUnscored2,
|
|
18992
|
+
events: events2
|
|
18993
|
+
};
|
|
18994
|
+
}
|
|
18995
|
+
if (args.scope === true) {
|
|
18996
|
+
throw new ToolError(
|
|
18997
|
+
"In a hosted session a scoped re-audit is recorded with record=true and its audit_id; the read is always the current state."
|
|
18998
|
+
);
|
|
18999
|
+
}
|
|
18503
19000
|
if (typeof args.audit_id === "string" && args.audit_id !== "") {
|
|
18504
19001
|
throw new ToolError("The hosted matrix is the current state, not one audit \u2014 audit_id does not partition it (issue #400 decision 3).");
|
|
18505
19002
|
}
|
|
18506
|
-
const
|
|
18507
|
-
|
|
18508
|
-
const m = deriveQualityMatrix({ quality: section2 }, library2);
|
|
18509
|
-
const { open: open2, lanes: lanes2, p0: p02 } = openFindingsSummary(section2.findings, library2);
|
|
18510
|
-
return {
|
|
18511
|
-
...m.framework_version !== void 0 ? { framework_version: m.framework_version } : {},
|
|
18512
|
-
matrix: m.matrix,
|
|
18513
|
-
overall: m.overall,
|
|
18514
|
-
finding_counts: m.finding_counts,
|
|
18515
|
-
assessment_count: section2.assessments.length,
|
|
18516
|
-
open_findings: open2.length,
|
|
18517
|
-
lanes: lanes2,
|
|
18518
|
-
p0: p02,
|
|
18519
|
-
events: []
|
|
18520
|
-
};
|
|
19003
|
+
const graph2 = await load2();
|
|
19004
|
+
return { ...hostedMatrixRead(graph2), events: [] };
|
|
18521
19005
|
}
|
|
18522
19006
|
const root = repoRootOf(ctx, REPO_MODE_ONLY);
|
|
18523
19007
|
const library = libraryOf(root);
|
|
@@ -18535,24 +19019,55 @@ function buildKritikCatalog(ctx) {
|
|
|
18535
19019
|
}
|
|
18536
19020
|
const { section, matrix, file: file2 } = computed;
|
|
18537
19021
|
const { open, lanes, p0 } = openFindingsSummary(section.findings, library);
|
|
19022
|
+
let graph;
|
|
19023
|
+
let since = loadScoresOrEmpty(root, auditId).scope?.since;
|
|
19024
|
+
if (since === void 0 && args.scope === true) {
|
|
19025
|
+
graph = await load2();
|
|
19026
|
+
try {
|
|
19027
|
+
since = declaredScopeSince(auditId, recordedAuditIds(graph.journal));
|
|
19028
|
+
} catch (error51) {
|
|
19029
|
+
throw new ToolError(`scope=true refused \u2014 ${error51.message}`);
|
|
19030
|
+
}
|
|
19031
|
+
}
|
|
19032
|
+
const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
|
|
19033
|
+
let leftUnscored = [];
|
|
19034
|
+
if (scope !== void 0) {
|
|
19035
|
+
graph = graph ?? await load2();
|
|
19036
|
+
const current = scopeOf2(graph);
|
|
19037
|
+
if (current.since === scope.since) {
|
|
19038
|
+
const done = new Set(section.assessments.map((a) => `${a.criterion_id}::${a.surface}`));
|
|
19039
|
+
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 }));
|
|
19040
|
+
}
|
|
19041
|
+
}
|
|
18538
19042
|
let events = [];
|
|
18539
19043
|
if (args.record === true) {
|
|
18540
|
-
|
|
18541
|
-
|
|
18542
|
-
|
|
19044
|
+
let recorded = matrix;
|
|
19045
|
+
if (scope !== void 0) {
|
|
19046
|
+
try {
|
|
19047
|
+
recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(root, auditId, library) }, library);
|
|
19048
|
+
} catch (error51) {
|
|
19049
|
+
throw new ToolError(error51.message);
|
|
19050
|
+
}
|
|
19051
|
+
}
|
|
19052
|
+
events = await record2(graph ?? await load2(), [
|
|
19053
|
+
auditCompletedInput(recorded, {
|
|
18543
19054
|
audit_id: auditId,
|
|
18544
19055
|
framework_version: file2.framework_version,
|
|
18545
|
-
...file2.commit !== void 0 ? { commit: file2.commit } : {}
|
|
19056
|
+
...file2.commit !== void 0 ? { commit: file2.commit } : {},
|
|
19057
|
+
...scope !== void 0 ? { scope } : {}
|
|
18546
19058
|
})
|
|
18547
19059
|
]);
|
|
18548
19060
|
}
|
|
19061
|
+
const notes = typeof args.commit === "string" && args.commit !== "" ? ["commit is only used when recording in a hosted session \u2014 repo mode reads it from the audit's scores.json"] : void 0;
|
|
18549
19062
|
return {
|
|
18550
19063
|
...file2,
|
|
19064
|
+
...scope !== void 0 ? { scope, left_unscored: leftUnscored } : {},
|
|
18551
19065
|
assessment_count: section.assessments.length,
|
|
18552
19066
|
open_findings: open.length,
|
|
18553
19067
|
lanes,
|
|
18554
19068
|
p0,
|
|
18555
|
-
events
|
|
19069
|
+
events,
|
|
19070
|
+
...notes !== void 0 ? { notes } : {}
|
|
18556
19071
|
};
|
|
18557
19072
|
}
|
|
18558
19073
|
);
|
|
@@ -18641,7 +19156,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18641
19156
|
tool(
|
|
18642
19157
|
{
|
|
18643
19158
|
name: "kritik_regressions",
|
|
18644
|
-
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.
|
|
19159
|
+
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.",
|
|
18645
19160
|
inputSchema: {
|
|
18646
19161
|
type: "object",
|
|
18647
19162
|
properties: {
|
|
@@ -18691,8 +19206,8 @@ function buildKritikCatalog(ctx) {
|
|
|
18691
19206
|
let regressions;
|
|
18692
19207
|
try {
|
|
18693
19208
|
regressions = detectRegressions(
|
|
18694
|
-
|
|
18695
|
-
|
|
19209
|
+
loadQualitySectionThrough(root, from, library),
|
|
19210
|
+
loadQualitySectionThrough(root, to, library),
|
|
18696
19211
|
library
|
|
18697
19212
|
);
|
|
18698
19213
|
} catch (error51) {
|
|
@@ -18719,7 +19234,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18719
19234
|
tool(
|
|
18720
19235
|
{
|
|
18721
19236
|
name: "kritik_trend",
|
|
18722
|
-
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.",
|
|
19237
|
+
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 \u2014 and there a restored audit with no recorded reading appears as a baseline first row.",
|
|
18723
19238
|
inputSchema: {
|
|
18724
19239
|
type: "object",
|
|
18725
19240
|
properties: {
|
|
@@ -18731,8 +19246,10 @@ function buildKritikCatalog(ctx) {
|
|
|
18731
19246
|
},
|
|
18732
19247
|
async (args) => {
|
|
18733
19248
|
const graph = await load2();
|
|
18734
|
-
const
|
|
18735
|
-
const
|
|
19249
|
+
const quality = ctx.qualityRoot === void 0 ? graph.loaded.bundle.quality : void 0;
|
|
19250
|
+
const profile = ctx.qualityRoot === void 0 ? quality?.profile : loadProfile(ctx.qualityRoot) ?? void 0;
|
|
19251
|
+
const events = quality !== void 0 && Array.isArray(quality.assessments) && Array.isArray(quality.findings) ? withImplicitBaseline(graph.journal, quality, resolveKritikLibrary(quality)) : graph.journal;
|
|
19252
|
+
const trend = deriveQualityTrend(events, profile);
|
|
18736
19253
|
const filter = {
|
|
18737
19254
|
...typeof args.surface === "string" && args.surface !== "" ? { surface: args.surface } : {},
|
|
18738
19255
|
...typeof args.domain === "string" && args.domain !== "" ? { domain: args.domain } : {}
|
|
@@ -18743,7 +19260,79 @@ function buildKritikCatalog(ctx) {
|
|
|
18743
19260
|
surfaces,
|
|
18744
19261
|
rows,
|
|
18745
19262
|
snapshots: trend.snapshots,
|
|
18746
|
-
...trend.snapshots.length === 0 ? { note: "No recorded audits yet \u2014 `kritik_matrix` with record=true writes one." } : {
|
|
19263
|
+
...trend.snapshots.length === 0 ? { note: ctx.qualityRoot === void 0 ? NO_HOSTED_AUDIT : "No recorded audits yet \u2014 `kritik_matrix` with record=true writes one." } : rows[0]?.baseline === true ? {
|
|
19264
|
+
// Synthesized only until the first hosted score writes the
|
|
19265
|
+
// baseline for real (flagged `baseline: true`); after that the
|
|
19266
|
+
// row IS a recorded reading, and saying otherwise is false.
|
|
19267
|
+
note: graph.journal.some(
|
|
19268
|
+
(event) => event.type === "quality.audit.completed" && event.baseline === true
|
|
19269
|
+
) ? "The first row is the restored audit's reading, recorded when the first hosted score landed." : "The first row is the restored audit's reading, rebuilt from its stored scores \u2014 no reading was recorded for it."
|
|
19270
|
+
} : {}
|
|
19271
|
+
};
|
|
19272
|
+
}
|
|
19273
|
+
);
|
|
19274
|
+
tool(
|
|
19275
|
+
{
|
|
19276
|
+
name: "kritik_scope",
|
|
19277
|
+
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. In a hosted project whose audit arrived by restore with no recorded reading, the scope measures from that audit, dated where it was taken. In a hosted session, open_audit and rescored show what the scoped re-audit in progress has already covered \u2014 record only when every cell is rescored. In a hosted session the server checks each kritik_score against the default scope (measured from the newest recorded audit, widened), so since and widen=false only change what this read shows, not which cells kritik_score accepts.",
|
|
19278
|
+
inputSchema: {
|
|
19279
|
+
type: "object",
|
|
19280
|
+
properties: {
|
|
19281
|
+
since: { type: "string", description: "The recorded audit to measure from. Default: the newest quality.audit.completed." },
|
|
19282
|
+
widen: { type: "boolean", description: "Add the one-hop node neighbours. Default: true." }
|
|
19283
|
+
},
|
|
19284
|
+
additionalProperties: false
|
|
19285
|
+
}
|
|
19286
|
+
},
|
|
19287
|
+
async (args) => {
|
|
19288
|
+
const graph = await load2();
|
|
19289
|
+
const since = typeof args.since === "string" && args.since !== "" ? args.since : void 0;
|
|
19290
|
+
const scope = scopeOf2(graph, {
|
|
19291
|
+
...since !== void 0 ? { since } : {},
|
|
19292
|
+
...args.widen === false ? { widen: false } : {}
|
|
19293
|
+
});
|
|
19294
|
+
let openAudit = null;
|
|
19295
|
+
let cells = scope.cells;
|
|
19296
|
+
if (ctx.qualityRoot === void 0 && scope.since !== null) {
|
|
19297
|
+
const { section, library } = hostedSection(graph);
|
|
19298
|
+
const recorded = new Set(recordedAuditIds(withImplicitBaseline(graph.journal, section, library)));
|
|
19299
|
+
const scoredEvents = graph.journal.filter((event) => event.type === "quality.assessment.scored");
|
|
19300
|
+
const auditIdOf = (event) => {
|
|
19301
|
+
const id = event.audit_id;
|
|
19302
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
19303
|
+
};
|
|
19304
|
+
const sinceOf = (event) => {
|
|
19305
|
+
const since2 = event.scope?.since;
|
|
19306
|
+
return typeof since2 === "string" && since2 !== "" ? since2 : void 0;
|
|
19307
|
+
};
|
|
19308
|
+
let open;
|
|
19309
|
+
for (const event of scoredEvents) {
|
|
19310
|
+
const id = auditIdOf(event);
|
|
19311
|
+
if (id !== void 0 && sinceOf(event) === scope.since && !recorded.has(id)) open = id;
|
|
19312
|
+
}
|
|
19313
|
+
if (open !== void 0) {
|
|
19314
|
+
const scored = [];
|
|
19315
|
+
for (const event of scoredEvents) {
|
|
19316
|
+
if (auditIdOf(event) !== open || sinceOf(event) !== scope.since) continue;
|
|
19317
|
+
const criterionId = event.criterion_id;
|
|
19318
|
+
const surface = event.surface;
|
|
19319
|
+
if (typeof criterionId === "string" && typeof surface === "string") scored.push({ criterion_id: criterionId, surface });
|
|
19320
|
+
}
|
|
19321
|
+
openAudit = { audit_id: open, scored };
|
|
19322
|
+
const done = new Set(scored.map((cell) => `${cell.criterion_id}::${cell.surface}`));
|
|
19323
|
+
cells = scope.cells.map(
|
|
19324
|
+
(cell) => done.has(`${cell.criterion_id}::${cell.surface}`) ? { ...cell, rescored: true } : cell
|
|
19325
|
+
);
|
|
19326
|
+
}
|
|
19327
|
+
}
|
|
19328
|
+
return {
|
|
19329
|
+
...scope,
|
|
19330
|
+
cells,
|
|
19331
|
+
summary: scopeSummary(scope),
|
|
19332
|
+
...ctx.qualityRoot === void 0 ? { open_audit: openAudit } : {},
|
|
19333
|
+
...scope.since === null ? {
|
|
19334
|
+
note: ctx.qualityRoot === void 0 ? NO_HOSTED_AUDIT : "No recorded audit yet \u2014 a scope is measured from one. `kritik_matrix` with record=true writes it."
|
|
19335
|
+
} : {}
|
|
18747
19336
|
};
|
|
18748
19337
|
}
|
|
18749
19338
|
);
|
|
@@ -18807,7 +19396,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18807
19396
|
tool(
|
|
18808
19397
|
{
|
|
18809
19398
|
name: "kritik_score",
|
|
18810
|
-
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.
|
|
19399
|
+
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). In a hosted session scoring is scoped-only (scope=true is required) and nothing is written to disk. The server checks the cell against the scope, names the audit (default <YYYY-MM>-scoped), and, for a restored audit with no recorded reading, records that baseline first. You are still reading code: have the product's code at hand to read \u2014 the session can stay hosted \u2014 and pass commit so the evidence can be checked against it.",
|
|
18811
19400
|
inputSchema: {
|
|
18812
19401
|
type: "object",
|
|
18813
19402
|
properties: {
|
|
@@ -18819,14 +19408,75 @@ function buildKritikCatalog(ctx) {
|
|
|
18819
19408
|
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."
|
|
18820
19409
|
},
|
|
18821
19410
|
evidence: { type: "string", description: "file:line / config citations, markdown." },
|
|
18822
|
-
audit_id: {
|
|
18823
|
-
|
|
19411
|
+
audit_id: {
|
|
19412
|
+
type: "string",
|
|
19413
|
+
description: "Default: the newest audit, or the current YYYY-MM. With scope=true: the scoped audit in progress, else <YYYY-MM>-scoped."
|
|
19414
|
+
},
|
|
19415
|
+
commit: { type: "string" },
|
|
19416
|
+
scope: {
|
|
19417
|
+
type: "boolean",
|
|
19418
|
+
description: "This is a scoped re-audit: refuse a cell kritik_scope does not list. In repo mode, leave it off to re-score an out-of-scope cell on purpose; a hosted session must pass it."
|
|
19419
|
+
}
|
|
18824
19420
|
},
|
|
18825
19421
|
required: ["criterion_id", "surface", "level", "evidence"],
|
|
18826
19422
|
additionalProperties: false
|
|
18827
19423
|
}
|
|
18828
19424
|
},
|
|
18829
19425
|
async (args) => {
|
|
19426
|
+
if (ctx.qualityRoot === void 0) {
|
|
19427
|
+
if (args.scope !== true) {
|
|
19428
|
+
throw new ToolError(
|
|
19429
|
+
"A hosted session scores only a scoped re-audit: pass scope=true and score the cells kritik_scope lists. A comprehensive audit is a different, repo-mode operation \u2014 it runs in a session pointed at a checkout, not this one."
|
|
19430
|
+
);
|
|
19431
|
+
}
|
|
19432
|
+
const graph2 = await load2();
|
|
19433
|
+
const { library: library2 } = hostedSection(graph2);
|
|
19434
|
+
const criterionId2 = requireString(args, "criterion_id");
|
|
19435
|
+
const surface2 = requireString(args, "surface");
|
|
19436
|
+
const level2 = requireInt(args, "level", 0, 4);
|
|
19437
|
+
const evidence2 = requireString(args, "evidence");
|
|
19438
|
+
const commit = typeof args.commit === "string" && args.commit !== "" ? args.commit : void 0;
|
|
19439
|
+
const events = await appendHosted(ctx.store, [
|
|
19440
|
+
{
|
|
19441
|
+
type: "quality.assessment.scored",
|
|
19442
|
+
criterion_id: criterionId2,
|
|
19443
|
+
surface: surface2,
|
|
19444
|
+
level: level2,
|
|
19445
|
+
evidence: evidence2,
|
|
19446
|
+
...typeof args.audit_id === "string" && args.audit_id !== "" ? { audit_id: args.audit_id } : {},
|
|
19447
|
+
...commit !== void 0 ? { commit } : {}
|
|
19448
|
+
}
|
|
19449
|
+
]);
|
|
19450
|
+
const scored = events.find((e) => e.type === "quality.assessment.scored");
|
|
19451
|
+
const baseline = events.find(
|
|
19452
|
+
(e) => e.type === "quality.audit.completed" && e.baseline === true
|
|
19453
|
+
);
|
|
19454
|
+
const notes2 = [];
|
|
19455
|
+
if (baseline !== void 0) {
|
|
19456
|
+
notes2.push(
|
|
19457
|
+
`Recorded the baseline reading of ${baseline.audit_id} first, dated where that audit was taken \u2014 the scope and the trend now measure from a real event.`
|
|
19458
|
+
);
|
|
19459
|
+
}
|
|
19460
|
+
if (commit === void 0) {
|
|
19461
|
+
notes2.push("No commit given \u2014 it is the only thing that lets a hosted reader check this evidence against the tree it cites.");
|
|
19462
|
+
}
|
|
19463
|
+
return {
|
|
19464
|
+
assessment: {
|
|
19465
|
+
criterion_id: criterionId2,
|
|
19466
|
+
surface: surface2,
|
|
19467
|
+
level: level2,
|
|
19468
|
+
evidence: evidence2,
|
|
19469
|
+
audit_id: scored?.audit_id,
|
|
19470
|
+
...commit !== void 0 ? { commit } : {},
|
|
19471
|
+
ts: scored?.ts
|
|
19472
|
+
},
|
|
19473
|
+
audit_id: scored?.audit_id,
|
|
19474
|
+
...scored?.scope?.since !== void 0 ? { scoped_from: scored.scope.since } : {},
|
|
19475
|
+
anchor: library2?.criteria?.find((c) => c.id === criterionId2)?.level_anchors?.[`l${level2}`],
|
|
19476
|
+
events,
|
|
19477
|
+
...notes2.length > 0 ? { notes: notes2 } : {}
|
|
19478
|
+
};
|
|
19479
|
+
}
|
|
18830
19480
|
const root = repoRootOf(ctx, "Scoring reads the code \u2014 evidence is file:line against a working tree.");
|
|
18831
19481
|
const library = libraryOf(root);
|
|
18832
19482
|
const profile = profileOf(root);
|
|
@@ -18841,7 +19491,42 @@ function buildKritikCatalog(ctx) {
|
|
|
18841
19491
|
`${criterionId} does not apply to "${surface}" (applies to: ${appliesTo.join(", ")}). Scoring it there would produce a cell nothing rolls up.`
|
|
18842
19492
|
);
|
|
18843
19493
|
}
|
|
18844
|
-
|
|
19494
|
+
let scopedFrom;
|
|
19495
|
+
let auditId;
|
|
19496
|
+
const graph = await load2();
|
|
19497
|
+
if (args.scope === true) {
|
|
19498
|
+
const scope = scopeOf2(graph);
|
|
19499
|
+
if (scope.since === null) {
|
|
19500
|
+
throw new ToolError("scope=true needs a recorded audit to measure from \u2014 kritik_matrix with record=true writes one.");
|
|
19501
|
+
}
|
|
19502
|
+
if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
|
|
19503
|
+
throw new ToolError(
|
|
19504
|
+
`${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.`
|
|
19505
|
+
);
|
|
19506
|
+
}
|
|
19507
|
+
try {
|
|
19508
|
+
auditId = scopedAuditTarget(
|
|
19509
|
+
root,
|
|
19510
|
+
scope.since,
|
|
19511
|
+
currentAuditId(),
|
|
19512
|
+
typeof args.audit_id === "string" && args.audit_id !== "" ? args.audit_id : void 0,
|
|
19513
|
+
recordedAuditIds(graph.journal)
|
|
19514
|
+
);
|
|
19515
|
+
} catch (error51) {
|
|
19516
|
+
throw new ToolError(error51.message);
|
|
19517
|
+
}
|
|
19518
|
+
scopedFrom = scope.since;
|
|
19519
|
+
} else {
|
|
19520
|
+
auditId = auditForWrite(root, args.audit_id);
|
|
19521
|
+
}
|
|
19522
|
+
const notes = [];
|
|
19523
|
+
if (scopedFrom === void 0) {
|
|
19524
|
+
if (recordedAuditIds(graph.journal).includes(auditId)) {
|
|
19525
|
+
notes.push(`${auditId} is already recorded \u2014 a re-score here rewrites that reading. For a re-audit after fixes, pass scope=true.`);
|
|
19526
|
+
}
|
|
19527
|
+
const order = auditOrderNote(root, auditId);
|
|
19528
|
+
if (order !== void 0) notes.push(order);
|
|
19529
|
+
}
|
|
18845
19530
|
const file2 = loadScoresOrEmpty(root, auditId);
|
|
18846
19531
|
const assessment = {
|
|
18847
19532
|
criterion_id: criterionId,
|
|
@@ -18858,14 +19543,17 @@ function buildKritikCatalog(ctx) {
|
|
|
18858
19543
|
audit_id: auditId,
|
|
18859
19544
|
framework_version: file2.framework_version ?? library.version,
|
|
18860
19545
|
...typeof args.commit === "string" ? { commit: args.commit } : {},
|
|
19546
|
+
...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
|
|
18861
19547
|
assessments
|
|
18862
19548
|
});
|
|
18863
19549
|
return {
|
|
18864
19550
|
assessment,
|
|
18865
19551
|
audit_id: auditId,
|
|
19552
|
+
...scopedFrom !== void 0 ? { scoped_from: scopedFrom } : {},
|
|
18866
19553
|
assessment_count: assessments.length,
|
|
18867
19554
|
...replaced !== void 0 ? { replaced_level: replaced.level } : {},
|
|
18868
|
-
anchor: criterion.level_anchors?.[`l${level}`]
|
|
19555
|
+
anchor: criterion.level_anchors?.[`l${level}`],
|
|
19556
|
+
...notes.length > 0 ? { notes } : {}
|
|
18869
19557
|
};
|
|
18870
19558
|
}
|
|
18871
19559
|
);
|
|
@@ -19786,7 +20474,11 @@ function createRemoteStore(options) {
|
|
|
19786
20474
|
// the server holds that journal. Sending an "open" guess from here could
|
|
19787
20475
|
// only be stale the moment two sessions race, so this method does no
|
|
19788
20476
|
// checking of its own — it forwards the inputs and lets the server's
|
|
19789
|
-
//
|
|
20477
|
+
// post-fold verdict be the only one that counts. This route is
|
|
20478
|
+
// deliberately UNLOCKED, unlike `/mutations` — no row lock serializes two
|
|
20479
|
+
// posts — which is exactly why a dropped response is ambiguous and a
|
|
20480
|
+
// caller (`kritik_matrix record=true`) needs a retry path rather than a
|
|
20481
|
+
// guarantee that a refusal here means nothing was written.
|
|
19790
20482
|
async appendQualityEvents(inputs) {
|
|
19791
20483
|
try {
|
|
19792
20484
|
const result = await request("/quality/events", {
|
|
@@ -19797,8 +20489,11 @@ function createRemoteStore(options) {
|
|
|
19797
20489
|
} catch (err) {
|
|
19798
20490
|
const e = err;
|
|
19799
20491
|
if (e.status === 422 && e.body?.error === "refused") {
|
|
19800
|
-
const
|
|
19801
|
-
|
|
20492
|
+
const refusals = e.body.refusals;
|
|
20493
|
+
const detail = refusals ? refusals.map((r) => `${r.finding_id ?? `entry ${r.index}`}: ${r.reason}${r.detail ? ` \u2014 ${r.detail}` : ""}`).join("; ") : e.body.reason ?? "refused";
|
|
20494
|
+
const rejection = new Error(`Quality events refused \u2014 ${detail}`);
|
|
20495
|
+
if (refusals) rejection.refusals = refusals;
|
|
20496
|
+
throw rejection;
|
|
19802
20497
|
}
|
|
19803
20498
|
throw err;
|
|
19804
20499
|
}
|
|
@@ -19861,7 +20556,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
|
|
|
19861
20556
|
}
|
|
19862
20557
|
|
|
19863
20558
|
// src/index.ts
|
|
19864
|
-
var VERSION = "0.
|
|
20559
|
+
var VERSION = "0.7.0";
|
|
19865
20560
|
var argv = process.argv.slice(2);
|
|
19866
20561
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
19867
20562
|
process.stdout.write(
|
package/package.json
CHANGED