arkaik-mcp 0.6.0 → 0.8.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 +593 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15345,7 +15345,20 @@ var QualityAuditCompletedEventSchema = external_exports.object({
|
|
|
15345
15345
|
partial: external_exports.boolean().optional(),
|
|
15346
15346
|
cells: external_exports.number().optional(),
|
|
15347
15347
|
since: external_exports.string().optional()
|
|
15348
|
-
}).catchall(external_exports.unknown()).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()
|
|
15349
15362
|
}).catchall(external_exports.unknown());
|
|
15350
15363
|
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
15351
15364
|
...envelope,
|
|
@@ -15399,6 +15412,7 @@ var JOURNAL_EVENT_SCHEMAS = {
|
|
|
15399
15412
|
"ref.status_changed": RefStatusChangedEventSchema,
|
|
15400
15413
|
"journal.baseline": JournalBaselineEventSchema,
|
|
15401
15414
|
"quality.audit.completed": QualityAuditCompletedEventSchema,
|
|
15415
|
+
"quality.assessment.scored": QualityAssessmentScoredEventSchema,
|
|
15402
15416
|
"quality.finding.opened": QualityFindingOpenedEventSchema,
|
|
15403
15417
|
"quality.finding.resolved": QualityFindingResolvedEventSchema,
|
|
15404
15418
|
"quality.finding.accepted": QualityFindingAcceptedEventSchema,
|
|
@@ -15421,6 +15435,7 @@ var KnownJournalEventSchema = external_exports.union([
|
|
|
15421
15435
|
RefStatusChangedEventSchema,
|
|
15422
15436
|
JournalBaselineEventSchema,
|
|
15423
15437
|
QualityAuditCompletedEventSchema,
|
|
15438
|
+
QualityAssessmentScoredEventSchema,
|
|
15424
15439
|
QualityFindingOpenedEventSchema,
|
|
15425
15440
|
QualityFindingResolvedEventSchema,
|
|
15426
15441
|
QualityFindingAcceptedEventSchema,
|
|
@@ -17931,6 +17946,10 @@ function sameFrameworkMajor(a, b) {
|
|
|
17931
17946
|
const right = frameworkMajor(b);
|
|
17932
17947
|
return left === null || right === null || left === right;
|
|
17933
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
|
+
}
|
|
17934
17953
|
function cleanScores(raw) {
|
|
17935
17954
|
const scores = {};
|
|
17936
17955
|
if (!isRecord2(raw)) return scores;
|
|
@@ -18001,7 +18020,9 @@ function deriveQualityTrend(events, profile, live) {
|
|
|
18001
18020
|
comparable: true,
|
|
18002
18021
|
scores,
|
|
18003
18022
|
overall,
|
|
18004
|
-
counts: cleanCounts(event.counts)
|
|
18023
|
+
counts: cleanCounts(event.counts),
|
|
18024
|
+
...event.baseline === true ? { baseline: true } : {},
|
|
18025
|
+
...scopeOf(event.scope) ?? {}
|
|
18005
18026
|
};
|
|
18006
18027
|
byAudit.delete(auditId);
|
|
18007
18028
|
byAudit.set(auditId, snapshot);
|
|
@@ -18057,7 +18078,9 @@ function trendRows(trend, filter = {}) {
|
|
|
18057
18078
|
...snapshot.commit !== void 0 ? { commit: snapshot.commit } : {},
|
|
18058
18079
|
...snapshot.framework_version !== void 0 ? { framework_version: snapshot.framework_version } : {},
|
|
18059
18080
|
comparable: snapshot.comparable,
|
|
18060
|
-
cells
|
|
18081
|
+
cells,
|
|
18082
|
+
...snapshot.baseline ? { baseline: true } : {},
|
|
18083
|
+
...snapshot.scope !== void 0 ? { scope: snapshot.scope } : {}
|
|
18061
18084
|
});
|
|
18062
18085
|
});
|
|
18063
18086
|
return { surfaces, rows };
|
|
@@ -18213,6 +18236,49 @@ function deriveAuditScope(events, section, library, options = {}) {
|
|
|
18213
18236
|
);
|
|
18214
18237
|
return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
|
|
18215
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
|
+
}
|
|
18216
18282
|
function scopeSummary(scope) {
|
|
18217
18283
|
const direct = scope.cells.length - scope.widened;
|
|
18218
18284
|
const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
|
|
@@ -18221,6 +18287,239 @@ function scopeSummary(scope) {
|
|
|
18221
18287
|
return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
|
|
18222
18288
|
}
|
|
18223
18289
|
|
|
18290
|
+
// ../schema/src/quality-burndown.ts
|
|
18291
|
+
var EVENT_CAUSE = {
|
|
18292
|
+
"quality.finding.opened": "opened",
|
|
18293
|
+
"quality.finding.resolved": "resolved",
|
|
18294
|
+
"quality.finding.accepted": "accepted",
|
|
18295
|
+
"quality.audit.completed": "audit"
|
|
18296
|
+
};
|
|
18297
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18298
|
+
var isString2 = (value) => typeof value === "string" && value !== "";
|
|
18299
|
+
var emptyCounts = () => ({ critical: 0, high: 0, medium: 0, low: 0, info: 0 });
|
|
18300
|
+
var asSeverity = (value) => typeof value === "string" && FINDING_SEVERITIES.includes(value) ? value : null;
|
|
18301
|
+
function cleanCounts2(raw) {
|
|
18302
|
+
const counts = emptyCounts();
|
|
18303
|
+
if (!isRecord3(raw)) return counts;
|
|
18304
|
+
for (const severity of FINDING_SEVERITIES) {
|
|
18305
|
+
const value = raw[severity];
|
|
18306
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) counts[severity] = value;
|
|
18307
|
+
}
|
|
18308
|
+
return counts;
|
|
18309
|
+
}
|
|
18310
|
+
function openTotal(open) {
|
|
18311
|
+
return FINDING_SEVERITIES.reduce((sum, severity) => sum + (open[severity] ?? 0), 0);
|
|
18312
|
+
}
|
|
18313
|
+
function deriveFindingsBurndown(events, options = {}) {
|
|
18314
|
+
const { surface, domain: domain2, library } = options;
|
|
18315
|
+
const filtered = surface !== void 0 || domain2 !== void 0;
|
|
18316
|
+
const sectionById = /* @__PURE__ */ new Map();
|
|
18317
|
+
for (const finding of Array.isArray(options.findings) ? options.findings : []) {
|
|
18318
|
+
if (isRecord3(finding) && isString2(finding.id)) sectionById.set(finding.id, finding);
|
|
18319
|
+
}
|
|
18320
|
+
const inView = (where) => {
|
|
18321
|
+
if (!filtered) return true;
|
|
18322
|
+
if (where === void 0) return false;
|
|
18323
|
+
if (surface !== void 0 && where.surface !== surface) return false;
|
|
18324
|
+
if (domain2 !== void 0 && (!isString2(where.criterion_id) || domainCodeOf(where.criterion_id, library) !== domain2)) {
|
|
18325
|
+
return false;
|
|
18326
|
+
}
|
|
18327
|
+
return true;
|
|
18328
|
+
};
|
|
18329
|
+
const relevant = (Array.isArray(events) ? events : []).filter(
|
|
18330
|
+
(event) => isRecord3(event) && typeof event.type === "string" && event.type in EVENT_CAUSE
|
|
18331
|
+
);
|
|
18332
|
+
const openedIds = /* @__PURE__ */ new Set();
|
|
18333
|
+
const decidedIds = /* @__PURE__ */ new Set();
|
|
18334
|
+
for (const event of relevant) {
|
|
18335
|
+
if (!isString2(event.finding_id)) continue;
|
|
18336
|
+
if (event.type === "quality.finding.opened") openedIds.add(event.finding_id);
|
|
18337
|
+
else if (event.type !== "quality.audit.completed") decidedIds.add(event.finding_id);
|
|
18338
|
+
}
|
|
18339
|
+
const seedable = (id, finding) => {
|
|
18340
|
+
if (openedIds.has(id) || !inView(finding)) return false;
|
|
18341
|
+
if (finding.status === "open") return true;
|
|
18342
|
+
return (finding.status === "resolved" || finding.status === "accepted-risk") && decidedIds.has(id);
|
|
18343
|
+
};
|
|
18344
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
18345
|
+
const open = emptyCounts();
|
|
18346
|
+
const points = [];
|
|
18347
|
+
const totals = { opened: 0, resolved: 0, accepted: 0 };
|
|
18348
|
+
let since = null;
|
|
18349
|
+
let seeded = false;
|
|
18350
|
+
const bump = (severity, by) => {
|
|
18351
|
+
if (severity !== null) open[severity] = Math.max(0, open[severity] + by);
|
|
18352
|
+
};
|
|
18353
|
+
const mark = (event, type, id) => {
|
|
18354
|
+
points.push({ ts: typeof event.ts === "string" ? event.ts : "", open: { ...open }, cause: { type, id } });
|
|
18355
|
+
};
|
|
18356
|
+
const count = (type) => {
|
|
18357
|
+
totals[type]++;
|
|
18358
|
+
if (since !== null) since[type]++;
|
|
18359
|
+
};
|
|
18360
|
+
for (const event of orderEvents(relevant)) {
|
|
18361
|
+
const type = EVENT_CAUSE[event.type];
|
|
18362
|
+
if (type === "audit") {
|
|
18363
|
+
if (!seeded) {
|
|
18364
|
+
seeded = true;
|
|
18365
|
+
for (const [id2, finding] of sectionById) {
|
|
18366
|
+
if (tracked.has(id2) || !seedable(id2, finding)) continue;
|
|
18367
|
+
const severity = severityOf(finding, library);
|
|
18368
|
+
tracked.set(id2, { severity, open: true, surface: finding.surface, criterion_id: finding.criterion_id });
|
|
18369
|
+
bump(severity, 1);
|
|
18370
|
+
}
|
|
18371
|
+
}
|
|
18372
|
+
if (!filtered) Object.assign(open, cleanCounts2(event.counts));
|
|
18373
|
+
const auditId = isString2(event.audit_id) ? event.audit_id : isString2(event.id) ? event.id : "";
|
|
18374
|
+
since = { audit_id: auditId, ts: typeof event.ts === "string" ? event.ts : "", opened: 0, resolved: 0, accepted: 0 };
|
|
18375
|
+
mark(event, "audit", auditId);
|
|
18376
|
+
continue;
|
|
18377
|
+
}
|
|
18378
|
+
const id = event.finding_id;
|
|
18379
|
+
if (!isString2(id)) continue;
|
|
18380
|
+
const known = tracked.get(id);
|
|
18381
|
+
if (type === "opened") {
|
|
18382
|
+
if (known?.open) continue;
|
|
18383
|
+
if (!inView(event)) continue;
|
|
18384
|
+
const severity = asSeverity(event.severity);
|
|
18385
|
+
tracked.set(id, {
|
|
18386
|
+
severity,
|
|
18387
|
+
open: true,
|
|
18388
|
+
...typeof event.surface === "string" ? { surface: event.surface } : {},
|
|
18389
|
+
...typeof event.criterion_id === "string" ? { criterion_id: event.criterion_id } : {}
|
|
18390
|
+
});
|
|
18391
|
+
bump(severity, 1);
|
|
18392
|
+
count("opened");
|
|
18393
|
+
mark(event, "opened", id);
|
|
18394
|
+
continue;
|
|
18395
|
+
}
|
|
18396
|
+
if (known !== void 0) {
|
|
18397
|
+
if (!known.open) continue;
|
|
18398
|
+
known.open = false;
|
|
18399
|
+
bump(known.severity, -1);
|
|
18400
|
+
} else {
|
|
18401
|
+
const fromSection = sectionById.get(id);
|
|
18402
|
+
if (!inView(fromSection)) continue;
|
|
18403
|
+
tracked.set(id, {
|
|
18404
|
+
severity: null,
|
|
18405
|
+
open: false,
|
|
18406
|
+
...fromSection ? { surface: fromSection.surface, criterion_id: fromSection.criterion_id } : {}
|
|
18407
|
+
});
|
|
18408
|
+
}
|
|
18409
|
+
count(type);
|
|
18410
|
+
mark(event, type, id);
|
|
18411
|
+
}
|
|
18412
|
+
return { points, ...totals, since };
|
|
18413
|
+
}
|
|
18414
|
+
function burndownRows(burndown) {
|
|
18415
|
+
const { points, since } = burndown;
|
|
18416
|
+
if (points.length === 0) return { reference: null, rows: [] };
|
|
18417
|
+
let referenceIndex = 0;
|
|
18418
|
+
if (since !== null) {
|
|
18419
|
+
for (let index = points.length - 1; index >= 0; index--) {
|
|
18420
|
+
if (points[index].cause.type === "audit") {
|
|
18421
|
+
referenceIndex = index;
|
|
18422
|
+
break;
|
|
18423
|
+
}
|
|
18424
|
+
}
|
|
18425
|
+
}
|
|
18426
|
+
const reference = points[referenceIndex];
|
|
18427
|
+
const last = points[points.length - 1];
|
|
18428
|
+
return {
|
|
18429
|
+
reference: {
|
|
18430
|
+
kind: since !== null ? "audit" : "start",
|
|
18431
|
+
id: reference.cause.id,
|
|
18432
|
+
ts: reference.ts
|
|
18433
|
+
},
|
|
18434
|
+
rows: FINDING_SEVERITIES.map((severity) => ({
|
|
18435
|
+
severity,
|
|
18436
|
+
at_reference: reference.open[severity],
|
|
18437
|
+
now: last.open[severity],
|
|
18438
|
+
change: last.open[severity] - reference.open[severity]
|
|
18439
|
+
}))
|
|
18440
|
+
};
|
|
18441
|
+
}
|
|
18442
|
+
function burndownSummary(burndown, openNow) {
|
|
18443
|
+
if (burndown.points.length === 0) return null;
|
|
18444
|
+
const tally = burndown.since ?? burndown;
|
|
18445
|
+
const closed = tally.resolved + tally.accepted;
|
|
18446
|
+
const where = burndown.since ? ` since the ${burndown.since.audit_id} audit` : "";
|
|
18447
|
+
const open = openNow ?? openTotal(burndown.points[burndown.points.length - 1].open);
|
|
18448
|
+
return `${closed} closed${where} (${tally.resolved} resolved, ${tally.accepted} accepted) \xB7 ${tally.opened} opened \xB7 ${open} open`;
|
|
18449
|
+
}
|
|
18450
|
+
|
|
18451
|
+
// ../schema/src/quality-baseline.ts
|
|
18452
|
+
var EPOCH = "1970-01-01T00:00:00.000Z";
|
|
18453
|
+
var DECISIONS = /* @__PURE__ */ new Set(["quality.finding.resolved", "quality.finding.accepted"]);
|
|
18454
|
+
var REVERTIBLE = /* @__PURE__ */ new Set(["resolved", "accepted-risk"]);
|
|
18455
|
+
var SCOPED_AUDIT_ID = /-scoped(-\d+)?$/;
|
|
18456
|
+
var rowsOf3 = (value) => Array.isArray(value) ? value : [];
|
|
18457
|
+
var isString3 = (value) => typeof value === "string" && value !== "";
|
|
18458
|
+
var isScopedAuditId = (value) => isString3(value) && SCOPED_AUDIT_ID.test(value);
|
|
18459
|
+
var isRow = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18460
|
+
var objectRowsOf = (value) => rowsOf3(value).filter(isRow);
|
|
18461
|
+
function omit2(obj, keys) {
|
|
18462
|
+
const out = { ...obj };
|
|
18463
|
+
for (const key of keys) delete out[key];
|
|
18464
|
+
return out;
|
|
18465
|
+
}
|
|
18466
|
+
function isoOf(value) {
|
|
18467
|
+
if (!isString3(value)) return void 0;
|
|
18468
|
+
const at = Date.parse(value);
|
|
18469
|
+
return Number.isFinite(at) ? new Date(at).toISOString() : void 0;
|
|
18470
|
+
}
|
|
18471
|
+
function oneMsBefore(iso) {
|
|
18472
|
+
const before = new Date(Date.parse(iso) - 1);
|
|
18473
|
+
return Number.isNaN(before.getTime()) ? EPOCH : before.toISOString();
|
|
18474
|
+
}
|
|
18475
|
+
function implicitAuditBaseline(events, section, library) {
|
|
18476
|
+
const rows = objectRowsOf(events);
|
|
18477
|
+
if (rows.some((event) => event.type === "quality.audit.completed")) return null;
|
|
18478
|
+
const assessmentRows = objectRowsOf(section?.assessments).filter((row) => !isScopedAuditId(row.audit_id));
|
|
18479
|
+
const taggedAssessments = assessmentRows.filter((row) => isString3(row.audit_id));
|
|
18480
|
+
if (taggedAssessments.length === 0) return null;
|
|
18481
|
+
const auditId = taggedAssessments.map((row) => row.audit_id).sort().at(-1);
|
|
18482
|
+
const assessedAts = taggedAssessments.filter((row) => row.audit_id === auditId).map((row) => isoOf(row.ts)).filter((at) => at !== void 0).sort();
|
|
18483
|
+
const auditStart = assessedAts[0];
|
|
18484
|
+
const assessedAt = assessedAts.at(-1);
|
|
18485
|
+
const ordered = orderEvents(rows);
|
|
18486
|
+
const sortKeyOf = (event) => typeof event.ts === "string" ? event.ts : "";
|
|
18487
|
+
const decisions = ordered.filter(
|
|
18488
|
+
(event) => DECISIONS.has(event.type) && (auditStart === void 0 || sortKeyOf(event) >= auditStart)
|
|
18489
|
+
);
|
|
18490
|
+
const firstDecision = decisions[0];
|
|
18491
|
+
let ts;
|
|
18492
|
+
if (firstDecision === void 0) {
|
|
18493
|
+
ts = assessedAt ?? EPOCH;
|
|
18494
|
+
} else {
|
|
18495
|
+
const decidedAt = isoOf(firstDecision.ts);
|
|
18496
|
+
if (decidedAt === void 0) {
|
|
18497
|
+
ts = EPOCH;
|
|
18498
|
+
} else {
|
|
18499
|
+
const justBefore = oneMsBefore(decidedAt);
|
|
18500
|
+
ts = assessedAt !== void 0 && assessedAt < justBefore ? assessedAt : justBefore;
|
|
18501
|
+
}
|
|
18502
|
+
if (!(ts < sortKeyOf(firstDecision))) ts = EPOCH;
|
|
18503
|
+
}
|
|
18504
|
+
const decided = /* @__PURE__ */ new Set();
|
|
18505
|
+
for (const event of decisions) {
|
|
18506
|
+
const id = event.finding_id;
|
|
18507
|
+
if (isString3(id)) decided.add(id);
|
|
18508
|
+
}
|
|
18509
|
+
const findings = objectRowsOf(section?.findings).map((finding) => {
|
|
18510
|
+
if (!isString3(finding.id) || !decided.has(finding.id) || !REVERTIBLE.has(finding.status)) return finding;
|
|
18511
|
+
return { ...omit2(finding, ["resolved_by"]), status: "open" };
|
|
18512
|
+
});
|
|
18513
|
+
const matrix = deriveQualityMatrix({ quality: { ...section, assessments: assessmentRows, findings } }, library);
|
|
18514
|
+
const frameworkVersion = matrix.framework_version ?? library?.version ?? "unknown";
|
|
18515
|
+
const input = auditCompletedInput(matrix, { audit_id: auditId, framework_version: frameworkVersion });
|
|
18516
|
+
return { id: `implicit-baseline:${auditId}`, ts, type: input.type, ...input.payload, baseline: true };
|
|
18517
|
+
}
|
|
18518
|
+
function withImplicitBaseline(events, section, library) {
|
|
18519
|
+
const baseline = implicitAuditBaseline(events, section, library);
|
|
18520
|
+
return baseline === null ? events : [baseline, ...events];
|
|
18521
|
+
}
|
|
18522
|
+
|
|
18224
18523
|
// ../schema/src/cli/kritik-audit.ts
|
|
18225
18524
|
import { existsSync as existsSync2, readdirSync, statSync } from "node:fs";
|
|
18226
18525
|
import { join as join2 } from "node:path";
|
|
@@ -18360,35 +18659,10 @@ function mergeAudits(root, auditIds, library, profile) {
|
|
|
18360
18659
|
};
|
|
18361
18660
|
}
|
|
18362
18661
|
function scopedAuditTarget(root, since, month, requested, recorded = []) {
|
|
18363
|
-
const
|
|
18364
|
-
const newest =
|
|
18365
|
-
|
|
18366
|
-
|
|
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.`);
|
|
18662
|
+
const known = listAuditIds(root);
|
|
18663
|
+
const newest = known[known.length - 1];
|
|
18664
|
+
const open = newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since ? newest : void 0;
|
|
18665
|
+
return scopedAuditId({ since, month, requested, known, recorded, open });
|
|
18392
18666
|
}
|
|
18393
18667
|
function declaredScopeSince(auditId, recorded) {
|
|
18394
18668
|
if (recorded.includes(auditId)) {
|
|
@@ -18597,6 +18871,7 @@ async function appendHosted(store2, inputs) {
|
|
|
18597
18871
|
throw new ToolError(error51.message);
|
|
18598
18872
|
}
|
|
18599
18873
|
}
|
|
18874
|
+
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.";
|
|
18600
18875
|
function hostedSection(graph) {
|
|
18601
18876
|
const section = graph.loaded.bundle.quality;
|
|
18602
18877
|
if (section === void 0 || !Array.isArray(section.findings) || !Array.isArray(section.assessments)) {
|
|
@@ -18609,6 +18884,21 @@ function hostedSection(graph) {
|
|
|
18609
18884
|
function refuseHostedRecord(eventType) {
|
|
18610
18885
|
throw new ToolError(`Recording ${eventType} belongs to the audit run, which reads code. Run the audit where the checkout is.`);
|
|
18611
18886
|
}
|
|
18887
|
+
function hostedMatrixRead(graph) {
|
|
18888
|
+
const { section, library } = hostedSection(graph);
|
|
18889
|
+
const m = deriveQualityMatrix({ quality: section }, library);
|
|
18890
|
+
const { open, lanes, p0 } = openFindingsSummary(section.findings, library);
|
|
18891
|
+
return {
|
|
18892
|
+
...m.framework_version !== void 0 ? { framework_version: m.framework_version } : {},
|
|
18893
|
+
matrix: m.matrix,
|
|
18894
|
+
overall: m.overall,
|
|
18895
|
+
finding_counts: m.finding_counts,
|
|
18896
|
+
assessment_count: section.assessments.length,
|
|
18897
|
+
open_findings: open.length,
|
|
18898
|
+
lanes,
|
|
18899
|
+
p0
|
|
18900
|
+
};
|
|
18901
|
+
}
|
|
18612
18902
|
function openFindingsSummary(findings, library) {
|
|
18613
18903
|
const open = findings.filter(isOpenFinding);
|
|
18614
18904
|
const lanes = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
@@ -18740,21 +19030,15 @@ function buildKritikCatalog(ctx) {
|
|
|
18740
19030
|
throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
|
|
18741
19031
|
}
|
|
18742
19032
|
};
|
|
18743
|
-
const
|
|
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
|
-
}
|
|
19033
|
+
const scopeOf2 = (graph, options = {}) => {
|
|
18752
19034
|
let section;
|
|
18753
19035
|
let library;
|
|
19036
|
+
let events;
|
|
18754
19037
|
if (ctx.qualityRoot === void 0) {
|
|
18755
19038
|
const hosted = hostedSection(graph);
|
|
18756
19039
|
section = hosted.section;
|
|
18757
19040
|
library = hosted.library ?? { criteria: [] };
|
|
19041
|
+
events = withImplicitBaseline(graph.journal, hosted.section, hosted.library);
|
|
18758
19042
|
} else {
|
|
18759
19043
|
const root = ctx.qualityRoot;
|
|
18760
19044
|
const full = libraryOf(root);
|
|
@@ -18765,24 +19049,39 @@ function buildKritikCatalog(ctx) {
|
|
|
18765
19049
|
throw new ToolError(error51.message);
|
|
18766
19050
|
}
|
|
18767
19051
|
library = full;
|
|
19052
|
+
events = graph.journal;
|
|
18768
19053
|
}
|
|
18769
|
-
|
|
19054
|
+
if (options.since !== void 0) {
|
|
19055
|
+
const recorded = recordedAuditIds(events);
|
|
19056
|
+
if (!recorded.includes(options.since)) {
|
|
19057
|
+
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;
|
|
19058
|
+
throw new ToolError(`No recorded audit "${options.since}" in this journal (recorded: ${recorded.join(", ") || "none"}). ${hint}`);
|
|
19059
|
+
}
|
|
19060
|
+
}
|
|
19061
|
+
return deriveAuditScope(events, section, library, options);
|
|
18770
19062
|
};
|
|
18771
19063
|
tool(
|
|
18772
19064
|
{
|
|
18773
19065
|
name: "kritik_matrix",
|
|
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
|
|
19066
|
+
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.",
|
|
18775
19067
|
inputSchema: {
|
|
18776
19068
|
type: "object",
|
|
18777
19069
|
properties: {
|
|
18778
|
-
audit_id: {
|
|
19070
|
+
audit_id: {
|
|
19071
|
+
type: "string",
|
|
19072
|
+
description: "Default: the newest audit on disk. Hosted: required with record=true, refused otherwise."
|
|
19073
|
+
},
|
|
18779
19074
|
record: {
|
|
18780
19075
|
type: "boolean",
|
|
18781
|
-
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit."
|
|
19076
|
+
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit. Hosted: the server computes the scores and counts."
|
|
18782
19077
|
},
|
|
18783
19078
|
scope: {
|
|
18784
19079
|
type: "boolean",
|
|
18785
19080
|
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."
|
|
19081
|
+
},
|
|
19082
|
+
commit: {
|
|
19083
|
+
type: "string",
|
|
19084
|
+
description: "Hosted record only: the commit the scoped re-audit read. Repo mode reads it from the audit's scores.json."
|
|
18786
19085
|
}
|
|
18787
19086
|
},
|
|
18788
19087
|
additionalProperties: false
|
|
@@ -18791,26 +19090,79 @@ function buildKritikCatalog(ctx) {
|
|
|
18791
19090
|
async (args) => {
|
|
18792
19091
|
const hosted = ctx.qualityRoot === void 0;
|
|
18793
19092
|
if (hosted) {
|
|
18794
|
-
if (args.record === true)
|
|
18795
|
-
|
|
19093
|
+
if (args.record === true) {
|
|
19094
|
+
if (typeof args.audit_id !== "string" || args.audit_id === "") {
|
|
19095
|
+
throw new ToolError(
|
|
19096
|
+
"record=true in a hosted session records a scoped re-audit: pass the audit_id kritik_score returned (e.g. 2026-09-scoped)."
|
|
19097
|
+
);
|
|
19098
|
+
}
|
|
19099
|
+
const auditId2 = args.audit_id;
|
|
19100
|
+
const commit = typeof args.commit === "string" && args.commit !== "" ? args.commit : void 0;
|
|
19101
|
+
const graph3 = await load2();
|
|
19102
|
+
const scope2 = scopeOf2(graph3);
|
|
19103
|
+
const scoredForAudit = graph3.journal.filter(
|
|
19104
|
+
(event) => event.type === "quality.assessment.scored" && event.audit_id === auditId2
|
|
19105
|
+
);
|
|
19106
|
+
const scoredSince = scoredForAudit.map((event) => event.scope?.since).find((since2) => typeof since2 === "string");
|
|
19107
|
+
let leftUnscored2 = [];
|
|
19108
|
+
if (scope2.since !== null && scoredSince === scope2.since) {
|
|
19109
|
+
const done = new Set(
|
|
19110
|
+
scoredForAudit.map(
|
|
19111
|
+
(event) => `${String(event.criterion_id)}::${String(event.surface)}`
|
|
19112
|
+
)
|
|
19113
|
+
);
|
|
19114
|
+
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 }));
|
|
19115
|
+
}
|
|
19116
|
+
if (ctx.store.appendQualityEvents === void 0) {
|
|
19117
|
+
throw new ToolError(`${ctx.store.describe()} cannot append quality events.`);
|
|
19118
|
+
}
|
|
19119
|
+
let events2;
|
|
19120
|
+
try {
|
|
19121
|
+
events2 = await ctx.store.appendQualityEvents([
|
|
19122
|
+
{ type: "quality.audit.completed", scope: true, audit_id: auditId2, ...commit !== void 0 ? { commit } : {} }
|
|
19123
|
+
]);
|
|
19124
|
+
} catch (error51) {
|
|
19125
|
+
const refusals = error51.refusals;
|
|
19126
|
+
if (Array.isArray(refusals) && refusals.length > 0 && refusals.every((r) => r.reason === "already_recorded") && scoredForAudit.length > 0) {
|
|
19127
|
+
const reloaded2 = await load2();
|
|
19128
|
+
const landed = reloaded2.journal.find(
|
|
19129
|
+
(event) => event.type === "quality.audit.completed" && event.audit_id === auditId2 && event.baseline !== true && event.scope?.partial === true
|
|
19130
|
+
);
|
|
19131
|
+
if (landed !== void 0) {
|
|
19132
|
+
return {
|
|
19133
|
+
...hostedMatrixRead(reloaded2),
|
|
19134
|
+
audit_id: auditId2,
|
|
19135
|
+
scope: landed.scope,
|
|
19136
|
+
// Not reconstructable: recording re-anchors the scope on
|
|
19137
|
+
// the landed reading itself, so "what's left" no longer
|
|
19138
|
+
// means what it meant before the write landed.
|
|
19139
|
+
events: [landed],
|
|
19140
|
+
note: "Already recorded \u2014 returning the reading that landed. left_unscored can't be reconstructed after recording."
|
|
19141
|
+
};
|
|
19142
|
+
}
|
|
19143
|
+
}
|
|
19144
|
+
throw new ToolError(error51.message);
|
|
19145
|
+
}
|
|
19146
|
+
const reloaded = await load2();
|
|
19147
|
+
const recorded = events2.find((event) => event.type === "quality.audit.completed");
|
|
19148
|
+
return {
|
|
19149
|
+
...hostedMatrixRead(reloaded),
|
|
19150
|
+
audit_id: auditId2,
|
|
19151
|
+
scope: recorded?.scope,
|
|
19152
|
+
left_unscored: leftUnscored2,
|
|
19153
|
+
events: events2
|
|
19154
|
+
};
|
|
19155
|
+
}
|
|
19156
|
+
if (args.scope === true) {
|
|
19157
|
+
throw new ToolError(
|
|
19158
|
+
"In a hosted session a scoped re-audit is recorded with record=true and its audit_id; the read is always the current state."
|
|
19159
|
+
);
|
|
19160
|
+
}
|
|
18796
19161
|
if (typeof args.audit_id === "string" && args.audit_id !== "") {
|
|
18797
19162
|
throw new ToolError("The hosted matrix is the current state, not one audit \u2014 audit_id does not partition it (issue #400 decision 3).");
|
|
18798
19163
|
}
|
|
18799
19164
|
const graph2 = await load2();
|
|
18800
|
-
|
|
18801
|
-
const m = deriveQualityMatrix({ quality: section2 }, library2);
|
|
18802
|
-
const { open: open2, lanes: lanes2, p0: p02 } = openFindingsSummary(section2.findings, library2);
|
|
18803
|
-
return {
|
|
18804
|
-
...m.framework_version !== void 0 ? { framework_version: m.framework_version } : {},
|
|
18805
|
-
matrix: m.matrix,
|
|
18806
|
-
overall: m.overall,
|
|
18807
|
-
finding_counts: m.finding_counts,
|
|
18808
|
-
assessment_count: section2.assessments.length,
|
|
18809
|
-
open_findings: open2.length,
|
|
18810
|
-
lanes: lanes2,
|
|
18811
|
-
p0: p02,
|
|
18812
|
-
events: []
|
|
18813
|
-
};
|
|
19165
|
+
return { ...hostedMatrixRead(graph2), events: [] };
|
|
18814
19166
|
}
|
|
18815
19167
|
const root = repoRootOf(ctx, REPO_MODE_ONLY);
|
|
18816
19168
|
const library = libraryOf(root);
|
|
@@ -18842,7 +19194,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18842
19194
|
let leftUnscored = [];
|
|
18843
19195
|
if (scope !== void 0) {
|
|
18844
19196
|
graph = graph ?? await load2();
|
|
18845
|
-
const current =
|
|
19197
|
+
const current = scopeOf2(graph);
|
|
18846
19198
|
if (current.since === scope.since) {
|
|
18847
19199
|
const done = new Set(section.assessments.map((a) => `${a.criterion_id}::${a.surface}`));
|
|
18848
19200
|
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 }));
|
|
@@ -18867,6 +19219,7 @@ function buildKritikCatalog(ctx) {
|
|
|
18867
19219
|
})
|
|
18868
19220
|
]);
|
|
18869
19221
|
}
|
|
19222
|
+
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;
|
|
18870
19223
|
return {
|
|
18871
19224
|
...file2,
|
|
18872
19225
|
...scope !== void 0 ? { scope, left_unscored: leftUnscored } : {},
|
|
@@ -18874,7 +19227,8 @@ function buildKritikCatalog(ctx) {
|
|
|
18874
19227
|
open_findings: open.length,
|
|
18875
19228
|
lanes,
|
|
18876
19229
|
p0,
|
|
18877
|
-
events
|
|
19230
|
+
events,
|
|
19231
|
+
...notes !== void 0 ? { notes } : {}
|
|
18878
19232
|
};
|
|
18879
19233
|
}
|
|
18880
19234
|
);
|
|
@@ -19041,7 +19395,7 @@ function buildKritikCatalog(ctx) {
|
|
|
19041
19395
|
tool(
|
|
19042
19396
|
{
|
|
19043
19397
|
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.",
|
|
19398
|
+
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.",
|
|
19045
19399
|
inputSchema: {
|
|
19046
19400
|
type: "object",
|
|
19047
19401
|
properties: {
|
|
@@ -19053,8 +19407,10 @@ function buildKritikCatalog(ctx) {
|
|
|
19053
19407
|
},
|
|
19054
19408
|
async (args) => {
|
|
19055
19409
|
const graph = await load2();
|
|
19056
|
-
const
|
|
19057
|
-
const
|
|
19410
|
+
const quality = ctx.qualityRoot === void 0 ? graph.loaded.bundle.quality : void 0;
|
|
19411
|
+
const profile = ctx.qualityRoot === void 0 ? quality?.profile : loadProfile(ctx.qualityRoot) ?? void 0;
|
|
19412
|
+
const events = quality !== void 0 && Array.isArray(quality.assessments) && Array.isArray(quality.findings) ? withImplicitBaseline(graph.journal, quality, resolveKritikLibrary(quality)) : graph.journal;
|
|
19413
|
+
const trend = deriveQualityTrend(events, profile);
|
|
19058
19414
|
const filter = {
|
|
19059
19415
|
...typeof args.surface === "string" && args.surface !== "" ? { surface: args.surface } : {},
|
|
19060
19416
|
...typeof args.domain === "string" && args.domain !== "" ? { domain: args.domain } : {}
|
|
@@ -19065,14 +19421,75 @@ function buildKritikCatalog(ctx) {
|
|
|
19065
19421
|
surfaces,
|
|
19066
19422
|
rows,
|
|
19067
19423
|
snapshots: trend.snapshots,
|
|
19068
|
-
...trend.snapshots.length === 0 ? { note: "No recorded audits yet \u2014 `kritik_matrix` with record=true writes one." } : {
|
|
19424
|
+
...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 ? {
|
|
19425
|
+
// Synthesized only until the first hosted score writes the
|
|
19426
|
+
// baseline for real (flagged `baseline: true`); after that the
|
|
19427
|
+
// row IS a recorded reading, and saying otherwise is false.
|
|
19428
|
+
note: graph.journal.some(
|
|
19429
|
+
(event) => event.type === "quality.audit.completed" && event.baseline === true
|
|
19430
|
+
) ? "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."
|
|
19431
|
+
} : {}
|
|
19432
|
+
};
|
|
19433
|
+
}
|
|
19434
|
+
);
|
|
19435
|
+
tool(
|
|
19436
|
+
{
|
|
19437
|
+
name: "kritik_burndown",
|
|
19438
|
+
description: "What was done since the last audit, not what the code is: how many findings closed (resolved or accepted) since the newest recorded audit, how many opened, and the open count by severity then and now \u2014 plus every point of the burndown. A score only moves when its cell is re-scored; this moves the day a finding closes. Replays quality.finding.opened / resolved / accepted in journal order; each quality.audit.completed re-baselines the open counts to what that audit counted, so a finding closed by hand is corrected at the next audit. An opened finding counts at the severity stored on its event; a close of a finding no event opened still counts as closed. surface and domain narrow the replay (never re-baselined, since an audit's counts are project-wide). Works in both modes: repo reads the journal sidecar, hosted reads the hosted journal \u2014 and there a restored audit with no recorded reading is the first point.",
|
|
19439
|
+
inputSchema: {
|
|
19440
|
+
type: "object",
|
|
19441
|
+
properties: {
|
|
19442
|
+
surface: { type: "string", description: "Only findings on this surface." },
|
|
19443
|
+
domain: { type: "string", description: "Domain code, e.g. SEC \u2014 only findings in this domain." }
|
|
19444
|
+
},
|
|
19445
|
+
additionalProperties: false
|
|
19446
|
+
}
|
|
19447
|
+
},
|
|
19448
|
+
async (args) => {
|
|
19449
|
+
const graph = await load2();
|
|
19450
|
+
let section;
|
|
19451
|
+
let library;
|
|
19452
|
+
if (ctx.qualityRoot === void 0) {
|
|
19453
|
+
const hosted = graph.loaded.bundle.quality;
|
|
19454
|
+
if (hosted !== void 0 && Array.isArray(hosted.findings) && Array.isArray(hosted.assessments)) {
|
|
19455
|
+
section = hosted;
|
|
19456
|
+
library = resolveKritikLibrary(hosted);
|
|
19457
|
+
}
|
|
19458
|
+
} else {
|
|
19459
|
+
try {
|
|
19460
|
+
library = libraryOf(ctx.qualityRoot);
|
|
19461
|
+
section = loadCurrentQualitySection(ctx.qualityRoot, library);
|
|
19462
|
+
} catch {
|
|
19463
|
+
}
|
|
19464
|
+
}
|
|
19465
|
+
const events = ctx.qualityRoot === void 0 && section !== void 0 ? withImplicitBaseline(graph.journal, section, library) : graph.journal;
|
|
19466
|
+
const filter = {
|
|
19467
|
+
...typeof args.surface === "string" && args.surface !== "" ? { surface: args.surface } : {},
|
|
19468
|
+
...typeof args.domain === "string" && args.domain !== "" ? { domain: args.domain } : {}
|
|
19469
|
+
};
|
|
19470
|
+
const burndown = deriveFindingsBurndown(events, { ...filter, library, findings: section?.findings });
|
|
19471
|
+
const open = section ? section.findings.filter(
|
|
19472
|
+
(finding) => isOpenFinding(finding) && (filter.surface === void 0 || finding.surface === filter.surface) && (filter.domain === void 0 || domainCodeOf(finding.criterion_id, library) === filter.domain)
|
|
19473
|
+
).length : void 0;
|
|
19474
|
+
const { reference, rows } = burndownRows(burndown);
|
|
19475
|
+
return {
|
|
19476
|
+
summary: burndownSummary(burndown, open),
|
|
19477
|
+
opened: burndown.opened,
|
|
19478
|
+
resolved: burndown.resolved,
|
|
19479
|
+
accepted: burndown.accepted,
|
|
19480
|
+
since: burndown.since,
|
|
19481
|
+
...open !== void 0 ? { open } : {},
|
|
19482
|
+
reference,
|
|
19483
|
+
rows,
|
|
19484
|
+
points: burndown.points,
|
|
19485
|
+
...burndown.points.length === 0 ? { note: "No finding history yet \u2014 kritik_open_finding and kritik_resolve_finding write it, and kritik_matrix with record=true records an audit to measure from." } : {}
|
|
19069
19486
|
};
|
|
19070
19487
|
}
|
|
19071
19488
|
);
|
|
19072
19489
|
tool(
|
|
19073
19490
|
{
|
|
19074
19491
|
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.",
|
|
19492
|
+
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.",
|
|
19076
19493
|
inputSchema: {
|
|
19077
19494
|
type: "object",
|
|
19078
19495
|
properties: {
|
|
@@ -19085,14 +19502,52 @@ function buildKritikCatalog(ctx) {
|
|
|
19085
19502
|
async (args) => {
|
|
19086
19503
|
const graph = await load2();
|
|
19087
19504
|
const since = typeof args.since === "string" && args.since !== "" ? args.since : void 0;
|
|
19088
|
-
const scope =
|
|
19505
|
+
const scope = scopeOf2(graph, {
|
|
19089
19506
|
...since !== void 0 ? { since } : {},
|
|
19090
19507
|
...args.widen === false ? { widen: false } : {}
|
|
19091
19508
|
});
|
|
19509
|
+
let openAudit = null;
|
|
19510
|
+
let cells = scope.cells;
|
|
19511
|
+
if (ctx.qualityRoot === void 0 && scope.since !== null) {
|
|
19512
|
+
const { section, library } = hostedSection(graph);
|
|
19513
|
+
const recorded = new Set(recordedAuditIds(withImplicitBaseline(graph.journal, section, library)));
|
|
19514
|
+
const scoredEvents = graph.journal.filter((event) => event.type === "quality.assessment.scored");
|
|
19515
|
+
const auditIdOf = (event) => {
|
|
19516
|
+
const id = event.audit_id;
|
|
19517
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
19518
|
+
};
|
|
19519
|
+
const sinceOf = (event) => {
|
|
19520
|
+
const since2 = event.scope?.since;
|
|
19521
|
+
return typeof since2 === "string" && since2 !== "" ? since2 : void 0;
|
|
19522
|
+
};
|
|
19523
|
+
let open;
|
|
19524
|
+
for (const event of scoredEvents) {
|
|
19525
|
+
const id = auditIdOf(event);
|
|
19526
|
+
if (id !== void 0 && sinceOf(event) === scope.since && !recorded.has(id)) open = id;
|
|
19527
|
+
}
|
|
19528
|
+
if (open !== void 0) {
|
|
19529
|
+
const scored = [];
|
|
19530
|
+
for (const event of scoredEvents) {
|
|
19531
|
+
if (auditIdOf(event) !== open || sinceOf(event) !== scope.since) continue;
|
|
19532
|
+
const criterionId = event.criterion_id;
|
|
19533
|
+
const surface = event.surface;
|
|
19534
|
+
if (typeof criterionId === "string" && typeof surface === "string") scored.push({ criterion_id: criterionId, surface });
|
|
19535
|
+
}
|
|
19536
|
+
openAudit = { audit_id: open, scored };
|
|
19537
|
+
const done = new Set(scored.map((cell) => `${cell.criterion_id}::${cell.surface}`));
|
|
19538
|
+
cells = scope.cells.map(
|
|
19539
|
+
(cell) => done.has(`${cell.criterion_id}::${cell.surface}`) ? { ...cell, rescored: true } : cell
|
|
19540
|
+
);
|
|
19541
|
+
}
|
|
19542
|
+
}
|
|
19092
19543
|
return {
|
|
19093
19544
|
...scope,
|
|
19545
|
+
cells,
|
|
19094
19546
|
summary: scopeSummary(scope),
|
|
19095
|
-
...
|
|
19547
|
+
...ctx.qualityRoot === void 0 ? { open_audit: openAudit } : {},
|
|
19548
|
+
...scope.since === null ? {
|
|
19549
|
+
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."
|
|
19550
|
+
} : {}
|
|
19096
19551
|
};
|
|
19097
19552
|
}
|
|
19098
19553
|
);
|
|
@@ -19156,7 +19611,7 @@ function buildKritikCatalog(ctx) {
|
|
|
19156
19611
|
tool(
|
|
19157
19612
|
{
|
|
19158
19613
|
name: "kritik_score",
|
|
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).
|
|
19614
|
+
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.",
|
|
19160
19615
|
inputSchema: {
|
|
19161
19616
|
type: "object",
|
|
19162
19617
|
properties: {
|
|
@@ -19175,7 +19630,7 @@ function buildKritikCatalog(ctx) {
|
|
|
19175
19630
|
commit: { type: "string" },
|
|
19176
19631
|
scope: {
|
|
19177
19632
|
type: "boolean",
|
|
19178
|
-
description: "This is a scoped re-audit: refuse a cell kritik_scope does not list.
|
|
19633
|
+
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."
|
|
19179
19634
|
}
|
|
19180
19635
|
},
|
|
19181
19636
|
required: ["criterion_id", "surface", "level", "evidence"],
|
|
@@ -19183,6 +19638,60 @@ function buildKritikCatalog(ctx) {
|
|
|
19183
19638
|
}
|
|
19184
19639
|
},
|
|
19185
19640
|
async (args) => {
|
|
19641
|
+
if (ctx.qualityRoot === void 0) {
|
|
19642
|
+
if (args.scope !== true) {
|
|
19643
|
+
throw new ToolError(
|
|
19644
|
+
"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."
|
|
19645
|
+
);
|
|
19646
|
+
}
|
|
19647
|
+
const graph2 = await load2();
|
|
19648
|
+
const { library: library2 } = hostedSection(graph2);
|
|
19649
|
+
const criterionId2 = requireString(args, "criterion_id");
|
|
19650
|
+
const surface2 = requireString(args, "surface");
|
|
19651
|
+
const level2 = requireInt(args, "level", 0, 4);
|
|
19652
|
+
const evidence2 = requireString(args, "evidence");
|
|
19653
|
+
const commit = typeof args.commit === "string" && args.commit !== "" ? args.commit : void 0;
|
|
19654
|
+
const events = await appendHosted(ctx.store, [
|
|
19655
|
+
{
|
|
19656
|
+
type: "quality.assessment.scored",
|
|
19657
|
+
criterion_id: criterionId2,
|
|
19658
|
+
surface: surface2,
|
|
19659
|
+
level: level2,
|
|
19660
|
+
evidence: evidence2,
|
|
19661
|
+
...typeof args.audit_id === "string" && args.audit_id !== "" ? { audit_id: args.audit_id } : {},
|
|
19662
|
+
...commit !== void 0 ? { commit } : {}
|
|
19663
|
+
}
|
|
19664
|
+
]);
|
|
19665
|
+
const scored = events.find((e) => e.type === "quality.assessment.scored");
|
|
19666
|
+
const baseline = events.find(
|
|
19667
|
+
(e) => e.type === "quality.audit.completed" && e.baseline === true
|
|
19668
|
+
);
|
|
19669
|
+
const notes2 = [];
|
|
19670
|
+
if (baseline !== void 0) {
|
|
19671
|
+
notes2.push(
|
|
19672
|
+
`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.`
|
|
19673
|
+
);
|
|
19674
|
+
}
|
|
19675
|
+
if (commit === void 0) {
|
|
19676
|
+
notes2.push("No commit given \u2014 it is the only thing that lets a hosted reader check this evidence against the tree it cites.");
|
|
19677
|
+
}
|
|
19678
|
+
return {
|
|
19679
|
+
assessment: {
|
|
19680
|
+
criterion_id: criterionId2,
|
|
19681
|
+
surface: surface2,
|
|
19682
|
+
level: level2,
|
|
19683
|
+
evidence: evidence2,
|
|
19684
|
+
audit_id: scored?.audit_id,
|
|
19685
|
+
...commit !== void 0 ? { commit } : {},
|
|
19686
|
+
ts: scored?.ts
|
|
19687
|
+
},
|
|
19688
|
+
audit_id: scored?.audit_id,
|
|
19689
|
+
...scored?.scope?.since !== void 0 ? { scoped_from: scored.scope.since } : {},
|
|
19690
|
+
anchor: library2?.criteria?.find((c) => c.id === criterionId2)?.level_anchors?.[`l${level2}`],
|
|
19691
|
+
events,
|
|
19692
|
+
...notes2.length > 0 ? { notes: notes2 } : {}
|
|
19693
|
+
};
|
|
19694
|
+
}
|
|
19186
19695
|
const root = repoRootOf(ctx, "Scoring reads the code \u2014 evidence is file:line against a working tree.");
|
|
19187
19696
|
const library = libraryOf(root);
|
|
19188
19697
|
const profile = profileOf(root);
|
|
@@ -19201,7 +19710,7 @@ function buildKritikCatalog(ctx) {
|
|
|
19201
19710
|
let auditId;
|
|
19202
19711
|
const graph = await load2();
|
|
19203
19712
|
if (args.scope === true) {
|
|
19204
|
-
const scope =
|
|
19713
|
+
const scope = scopeOf2(graph);
|
|
19205
19714
|
if (scope.since === null) {
|
|
19206
19715
|
throw new ToolError("scope=true needs a recorded audit to measure from \u2014 kritik_matrix with record=true writes one.");
|
|
19207
19716
|
}
|
|
@@ -20180,7 +20689,11 @@ function createRemoteStore(options) {
|
|
|
20180
20689
|
// the server holds that journal. Sending an "open" guess from here could
|
|
20181
20690
|
// only be stale the moment two sessions race, so this method does no
|
|
20182
20691
|
// checking of its own — it forwards the inputs and lets the server's
|
|
20183
|
-
//
|
|
20692
|
+
// post-fold verdict be the only one that counts. This route is
|
|
20693
|
+
// deliberately UNLOCKED, unlike `/mutations` — no row lock serializes two
|
|
20694
|
+
// posts — which is exactly why a dropped response is ambiguous and a
|
|
20695
|
+
// caller (`kritik_matrix record=true`) needs a retry path rather than a
|
|
20696
|
+
// guarantee that a refusal here means nothing was written.
|
|
20184
20697
|
async appendQualityEvents(inputs) {
|
|
20185
20698
|
try {
|
|
20186
20699
|
const result = await request("/quality/events", {
|
|
@@ -20191,8 +20704,11 @@ function createRemoteStore(options) {
|
|
|
20191
20704
|
} catch (err) {
|
|
20192
20705
|
const e = err;
|
|
20193
20706
|
if (e.status === 422 && e.body?.error === "refused") {
|
|
20194
|
-
const
|
|
20195
|
-
|
|
20707
|
+
const refusals = e.body.refusals;
|
|
20708
|
+
const detail = refusals ? refusals.map((r) => `${r.finding_id ?? `entry ${r.index}`}: ${r.reason}${r.detail ? ` \u2014 ${r.detail}` : ""}`).join("; ") : e.body.reason ?? "refused";
|
|
20709
|
+
const rejection = new Error(`Quality events refused \u2014 ${detail}`);
|
|
20710
|
+
if (refusals) rejection.refusals = refusals;
|
|
20711
|
+
throw rejection;
|
|
20196
20712
|
}
|
|
20197
20713
|
throw err;
|
|
20198
20714
|
}
|
|
@@ -20255,7 +20771,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
|
|
|
20255
20771
|
}
|
|
20256
20772
|
|
|
20257
20773
|
// src/index.ts
|
|
20258
|
-
var VERSION = "0.
|
|
20774
|
+
var VERSION = "0.8.0";
|
|
20259
20775
|
var argv = process.argv.slice(2);
|
|
20260
20776
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
20261
20777
|
process.stdout.write(
|
package/package.json
CHANGED