arkaik-mcp 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +411 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15338,6 +15338,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
15338
15338
  medium: external_exports.number().optional(),
15339
15339
  low: external_exports.number().optional(),
15340
15340
  info: external_exports.number().optional()
15341
+ }).catchall(external_exports.unknown()).optional(),
15342
+ // A scoped re-audit (issue #443). Optional and catchall like `counts`:
15343
+ // older readers ignore it, and its `scores` stay the same shape either way.
15344
+ scope: external_exports.object({
15345
+ partial: external_exports.boolean().optional(),
15346
+ cells: external_exports.number().optional(),
15347
+ since: external_exports.string().optional()
15341
15348
  }).catchall(external_exports.unknown()).optional()
15342
15349
  }).catchall(external_exports.unknown());
15343
15350
  var QualityFindingOpenedEventSchema = external_exports.object({
@@ -17791,7 +17798,8 @@ function auditCompletedInput(matrix, meta3) {
17791
17798
  framework_version: meta3.framework_version,
17792
17799
  ...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
17793
17800
  scores,
17794
- counts: matrix.finding_counts
17801
+ counts: matrix.finding_counts,
17802
+ ...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
17795
17803
  }
17796
17804
  };
17797
17805
  }
@@ -18055,6 +18063,164 @@ function trendRows(trend, filter = {}) {
18055
18063
  return { surfaces, rows };
18056
18064
  }
18057
18065
 
18066
+ // ../schema/src/quality-scope.ts
18067
+ var rowsOf2 = (value) => Array.isArray(value) ? value : [];
18068
+ var isString = (value) => typeof value === "string" && value !== "";
18069
+ var stringsOf = (value) => rowsOf2(value).filter(isString);
18070
+ var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
18071
+ function recordedAuditIds(events) {
18072
+ const ids = [];
18073
+ for (const event of orderEvents(rowsOf2(events))) {
18074
+ if (event?.type !== "quality.audit.completed") continue;
18075
+ const id = event.audit_id;
18076
+ if (isString(id) && !ids.includes(id)) ids.push(id);
18077
+ }
18078
+ return ids;
18079
+ }
18080
+ function deriveAuditScope(events, section, library, options = {}) {
18081
+ const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
18082
+ let sinceIndex = -1;
18083
+ for (let i = ordered.length - 1; i >= 0; i--) {
18084
+ const event = ordered[i];
18085
+ if (event.type !== "quality.audit.completed") continue;
18086
+ const id = event.audit_id;
18087
+ if (options.since !== void 0 && id !== options.since) continue;
18088
+ sinceIndex = i;
18089
+ break;
18090
+ }
18091
+ const empty = {
18092
+ since: options.since ?? null,
18093
+ since_ts: null,
18094
+ cells: [],
18095
+ findings: [],
18096
+ resolved_by: {},
18097
+ unknown: [],
18098
+ unscorable: [],
18099
+ widened: 0
18100
+ };
18101
+ if (sinceIndex === -1) return empty;
18102
+ const anchor = ordered[sinceIndex];
18103
+ const anchorId = anchor.audit_id;
18104
+ const since = isString(anchorId) ? anchorId : null;
18105
+ const sinceTs = isString(anchor.ts) ? anchor.ts : null;
18106
+ const resolutions = /* @__PURE__ */ new Map();
18107
+ for (const event of ordered.slice(sinceIndex + 1)) {
18108
+ if (event.type !== "quality.finding.resolved") continue;
18109
+ const findingId = event.finding_id;
18110
+ if (!isString(findingId)) continue;
18111
+ const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
18112
+ const by = event.resolved_by;
18113
+ if (isString(by)) entry.resolved_by = by;
18114
+ for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
18115
+ resolutions.set(findingId, entry);
18116
+ }
18117
+ if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
18118
+ const findings = rowsOf2(section?.findings).filter(
18119
+ (finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
18120
+ );
18121
+ const findingById = /* @__PURE__ */ new Map();
18122
+ for (const finding of findings) findingById.set(finding.id, finding);
18123
+ const criterionById = /* @__PURE__ */ new Map();
18124
+ for (const criterion of rowsOf2(library?.criteria)) {
18125
+ if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
18126
+ }
18127
+ const assessmentByCell = /* @__PURE__ */ new Map();
18128
+ for (const assessment of rowsOf2(section?.assessments)) {
18129
+ if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
18130
+ assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
18131
+ }
18132
+ const declared2 = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
18133
+ const surfaces = declared2.length > 0 ? [...new Set(declared2)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
18134
+ const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
18135
+ const scorable = (criterionId, surface) => {
18136
+ const criterion = criterionById.get(criterionId);
18137
+ if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
18138
+ if (declared2.length > 0 && !surfaces.includes(surface)) return false;
18139
+ return appliesTo(criterion, surface);
18140
+ };
18141
+ const cells = /* @__PURE__ */ new Map();
18142
+ const addDirect = (criterionId, surface, findingId) => {
18143
+ const key = cellKey2(criterionId, surface);
18144
+ const existing = cells.get(key);
18145
+ if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
18146
+ else if (!existing.because.includes(findingId)) existing.because.push(findingId);
18147
+ };
18148
+ const drivers = [];
18149
+ const unknown2 = [];
18150
+ const unscorable = [];
18151
+ const resolvedBy = {};
18152
+ const resolvedNodes = /* @__PURE__ */ new Set();
18153
+ for (const [findingId, resolution] of resolutions) {
18154
+ const finding = findingById.get(findingId);
18155
+ if (finding === void 0) {
18156
+ unknown2.push(findingId);
18157
+ continue;
18158
+ }
18159
+ if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
18160
+ const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
18161
+ (surface) => scorable(finding.criterion_id, surface)
18162
+ );
18163
+ for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
18164
+ for (const node of resolution.node_ids) resolvedNodes.add(node);
18165
+ if (targets.length === 0) {
18166
+ unscorable.push(findingId);
18167
+ continue;
18168
+ }
18169
+ drivers.push(findingId);
18170
+ if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
18171
+ for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
18172
+ }
18173
+ let widened = 0;
18174
+ if (options.widen !== false && resolvedNodes.size > 0) {
18175
+ const nodesByCell = /* @__PURE__ */ new Map();
18176
+ const noteNodes = (criterionId, surface, nodes) => {
18177
+ const key = cellKey2(criterionId, surface);
18178
+ const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
18179
+ for (const node of nodes) bucket.add(node);
18180
+ nodesByCell.set(key, bucket);
18181
+ };
18182
+ for (const finding of findings) {
18183
+ const nodes = stringsOf(finding.node_ids);
18184
+ if (nodes.length === 0) continue;
18185
+ if (finding.surface === CROSS_SURFACE_ID) {
18186
+ for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
18187
+ } else {
18188
+ noteNodes(finding.criterion_id, finding.surface, nodes);
18189
+ }
18190
+ }
18191
+ for (const [key, assessment] of assessmentByCell) {
18192
+ if (cells.has(key)) continue;
18193
+ if (!criterionById.has(assessment.criterion_id)) continue;
18194
+ if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
18195
+ const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
18196
+ if (shared.length === 0) continue;
18197
+ cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
18198
+ widened++;
18199
+ }
18200
+ }
18201
+ for (const [key, cell] of cells) {
18202
+ const assessment = assessmentByCell.get(key);
18203
+ if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
18204
+ cell.current = { level: assessment.level, audit_id: assessment.audit_id };
18205
+ }
18206
+ }
18207
+ const column = (surface) => {
18208
+ const at = surfaces.indexOf(surface);
18209
+ return at === -1 ? surfaces.length : at;
18210
+ };
18211
+ const sorted = [...cells.values()].sort(
18212
+ (a, b) => column(a.surface) - column(b.surface) || (a.surface < b.surface ? -1 : a.surface > b.surface ? 1 : 0) || (a.criterion_id < b.criterion_id ? -1 : a.criterion_id > b.criterion_id ? 1 : 0)
18213
+ );
18214
+ return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
18215
+ }
18216
+ function scopeSummary(scope) {
18217
+ const direct = scope.cells.length - scope.widened;
18218
+ const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
18219
+ const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
18220
+ const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
18221
+ return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
18222
+ }
18223
+
18058
18224
  // ../schema/src/cli/kritik-audit.ts
18059
18225
  import { existsSync as existsSync2, readdirSync, statSync } from "node:fs";
18060
18226
  import { join as join2 } from "node:path";
@@ -18150,6 +18316,100 @@ function loadQualitySection(root, auditId, library, scores = loadScores(root, au
18150
18316
  findings: findings.findings
18151
18317
  };
18152
18318
  }
18319
+ function stripDerived(finding) {
18320
+ const { severity: _severity, priority: _priority, ...rest } = finding;
18321
+ void _severity;
18322
+ void _priority;
18323
+ return rest;
18324
+ }
18325
+ function requireAudit(root, auditId) {
18326
+ if (!listAuditIds(root).includes(auditId)) {
18327
+ throw new Error(`no audit "${auditId}" under ${auditsDir(root)}`);
18328
+ }
18329
+ }
18330
+ function loadCurrentQualitySection(root, library) {
18331
+ const auditIds = listAuditIds(root);
18332
+ if (auditIds.length === 0) return void 0;
18333
+ const profile = loadProfile(root);
18334
+ if (!profile) return void 0;
18335
+ return mergeAudits(root, auditIds, library, profile);
18336
+ }
18337
+ function loadQualitySectionThrough(root, auditId, library) {
18338
+ requireAudit(root, auditId);
18339
+ const auditIds = listAuditIds(root);
18340
+ return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
18341
+ }
18342
+ function mergeAudits(root, auditIds, library, profile) {
18343
+ const cells = /* @__PURE__ */ new Map();
18344
+ const findings = [];
18345
+ let frameworkVersion;
18346
+ for (const id of auditIds) {
18347
+ const scores = loadScoresOrEmpty(root, id);
18348
+ if (typeof scores.framework_version === "string") frameworkVersion = scores.framework_version;
18349
+ for (const assessment of scores.assessments) {
18350
+ cells.set(`${assessment.criterion_id}\0${assessment.surface}`, assessment);
18351
+ }
18352
+ for (const finding of loadFindings(root, id).findings) findings.push(stripDerived(finding));
18353
+ }
18354
+ return {
18355
+ framework_version: frameworkVersion ?? library.version,
18356
+ library,
18357
+ profile,
18358
+ assessments: [...cells.values()],
18359
+ findings
18360
+ };
18361
+ }
18362
+ function scopedAuditTarget(root, since, month, requested, recorded = []) {
18363
+ const existing = listAuditIds(root);
18364
+ const newest = existing[existing.length - 1];
18365
+ if (requested !== void 0) {
18366
+ if (requested === since) {
18367
+ throw new Error(
18368
+ `"${requested}" is the audit this scope is measured from \u2014 its recorded reading is history. Re-score into a new audit (e.g. \`--audit ${month}-scoped\`); every other cell keeps its score through the merge.`
18369
+ );
18370
+ }
18371
+ if (newest !== void 0 && requested < newest) {
18372
+ throw new Error(
18373
+ `"${requested}" sorts before "${newest}", and audits merge latest-wins in lexical order \u2014 its scores would be outvoted by the older ones they replace. Name one that sorts last (e.g. \`${month}-scoped\`).`
18374
+ );
18375
+ }
18376
+ return requested;
18377
+ }
18378
+ if (newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since) {
18379
+ return newest;
18380
+ }
18381
+ for (let n = 1; n < 100; n++) {
18382
+ const candidate = n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
18383
+ if (existing.includes(candidate)) continue;
18384
+ if (newest !== void 0 && candidate < newest) {
18385
+ throw new Error(
18386
+ `"${candidate}" would sort before "${newest}", so its scores would lose the latest-wins merge. Name the scoped audit yourself with --audit, one that sorts after "${newest}".`
18387
+ );
18388
+ }
18389
+ return candidate;
18390
+ }
18391
+ throw new Error(`99 scoped audits in ${month} \u2014 name the next one with --audit.`);
18392
+ }
18393
+ function declaredScopeSince(auditId, recorded) {
18394
+ if (recorded.includes(auditId)) {
18395
+ throw new Error(
18396
+ `"${auditId}" is already recorded, so declaring it scoped would re-record that reading as a partial one. If you re-scored inside the audit a scope was measured from, move those scores into an audit of their own. If "${auditId}" really is a scoped re-audit recorded without its marker, add "scope": { "since": "<the audit it followed>" } to its scores.json and record it again.`
18397
+ );
18398
+ }
18399
+ const before = recorded.filter((id) => id < auditId).sort();
18400
+ const since = before[before.length - 1];
18401
+ if (since === void 0) {
18402
+ throw new Error(
18403
+ `no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
18404
+ );
18405
+ }
18406
+ return since;
18407
+ }
18408
+ function auditOrderNote(root, auditId) {
18409
+ const later = listAuditIds(root).filter((id) => id > auditId);
18410
+ if (later.length === 0) return void 0;
18411
+ return `"${auditId}" sorts before ${later.map((id) => `"${id}"`).join(", ")} \u2014 audits merge latest-wins in id order, so for any cell ${later.length === 1 ? "that audit" : "those audits"} also hold${later.length === 1 ? "s" : ""}, the later score wins. Name a new audit so it sorts last.`;
18412
+ }
18153
18413
  function computeAuditMatrix(root, auditId, library) {
18154
18414
  const scores = loadScores(root, auditId);
18155
18415
  const section = loadQualitySection(root, auditId, library, scores);
@@ -18480,10 +18740,38 @@ function buildKritikCatalog(ctx) {
18480
18740
  throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
18481
18741
  }
18482
18742
  };
18743
+ const scopeOf = (graph, options = {}) => {
18744
+ if (options.since !== void 0) {
18745
+ const recorded = recordedAuditIds(graph.journal);
18746
+ if (!recorded.includes(options.since)) {
18747
+ throw new ToolError(
18748
+ `No recorded audit "${options.since}" in this journal (recorded: ${recorded.join(", ") || "none"}). A scope is measured from a recorded reading \u2014 kritik_matrix with record=true writes one.`
18749
+ );
18750
+ }
18751
+ }
18752
+ let section;
18753
+ let library;
18754
+ if (ctx.qualityRoot === void 0) {
18755
+ const hosted = hostedSection(graph);
18756
+ section = hosted.section;
18757
+ library = hosted.library ?? { criteria: [] };
18758
+ } else {
18759
+ const root = ctx.qualityRoot;
18760
+ const full = libraryOf(root);
18761
+ const profile = profileOf(root);
18762
+ try {
18763
+ section = loadCurrentQualitySection(root, full) ?? { profile, assessments: [], findings: [] };
18764
+ } catch (error51) {
18765
+ throw new ToolError(error51.message);
18766
+ }
18767
+ library = full;
18768
+ }
18769
+ return deriveAuditScope(graph.journal, section, library, options);
18770
+ };
18483
18771
  tool(
18484
18772
  {
18485
18773
  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 (no audit_id/commit \u2014 hosted has no audit file) and record is refused \u2014 recording belongs to the audit run, which reads code.",
18774
+ description: "The comparative quality matrix: a score and grade per (domain x surface), the weighted roll-up per surface, and open findings by priority lane. Anti-averaging caps are applied \u2014 one open Critical caps its cell at D, one open High at B \u2014 so a cell full of 3s cannot absorb a live defect. In repo mode this refreshes the audit's matrix.json, and with record=true appends quality.audit.completed; in hosted mode it is a read of the stored quality section (no audit_id/commit \u2014 hosted has no audit file) and record is refused \u2014 recording belongs to the audit run, which reads code. A scoped re-audit (scored with kritik_score scope=true, or declared with scope=true here) returns `scope` and records the MERGED matrix through it with a scope marker, so the trend never reads its unscored cells as dropped; matrix.json stays this audit alone.",
18487
18775
  inputSchema: {
18488
18776
  type: "object",
18489
18777
  properties: {
@@ -18491,6 +18779,10 @@ function buildKritikCatalog(ctx) {
18491
18779
  record: {
18492
18780
  type: "boolean",
18493
18781
  description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit."
18782
+ },
18783
+ scope: {
18784
+ type: "boolean",
18785
+ description: "Treat the audit as a scoped re-audit even though it was scored without kritik_score scope=true (which marks it). Repo mode only."
18494
18786
  }
18495
18787
  },
18496
18788
  additionalProperties: false
@@ -18500,11 +18792,12 @@ function buildKritikCatalog(ctx) {
18500
18792
  const hosted = ctx.qualityRoot === void 0;
18501
18793
  if (hosted) {
18502
18794
  if (args.record === true) refuseHostedRecord("quality.audit.completed");
18795
+ if (args.scope === true) throw new ToolError("A scoped re-audit is an audit run, which reads code \u2014 the hosted matrix is the current state.");
18503
18796
  if (typeof args.audit_id === "string" && args.audit_id !== "") {
18504
18797
  throw new ToolError("The hosted matrix is the current state, not one audit \u2014 audit_id does not partition it (issue #400 decision 3).");
18505
18798
  }
18506
- const graph = await load2();
18507
- const { section: section2, library: library2 } = hostedSection(graph);
18799
+ const graph2 = await load2();
18800
+ const { section: section2, library: library2 } = hostedSection(graph2);
18508
18801
  const m = deriveQualityMatrix({ quality: section2 }, library2);
18509
18802
  const { open: open2, lanes: lanes2, p0: p02 } = openFindingsSummary(section2.findings, library2);
18510
18803
  return {
@@ -18535,19 +18828,48 @@ function buildKritikCatalog(ctx) {
18535
18828
  }
18536
18829
  const { section, matrix, file: file2 } = computed;
18537
18830
  const { open, lanes, p0 } = openFindingsSummary(section.findings, library);
18831
+ let graph;
18832
+ let since = loadScoresOrEmpty(root, auditId).scope?.since;
18833
+ if (since === void 0 && args.scope === true) {
18834
+ graph = await load2();
18835
+ try {
18836
+ since = declaredScopeSince(auditId, recordedAuditIds(graph.journal));
18837
+ } catch (error51) {
18838
+ throw new ToolError(`scope=true refused \u2014 ${error51.message}`);
18839
+ }
18840
+ }
18841
+ const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
18842
+ let leftUnscored = [];
18843
+ if (scope !== void 0) {
18844
+ graph = graph ?? await load2();
18845
+ const current = scopeOf(graph);
18846
+ if (current.since === scope.since) {
18847
+ const done = new Set(section.assessments.map((a) => `${a.criterion_id}::${a.surface}`));
18848
+ leftUnscored = current.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`)).map((cell) => ({ criterion_id: cell.criterion_id, surface: cell.surface, kind: cell.kind }));
18849
+ }
18850
+ }
18538
18851
  let events = [];
18539
18852
  if (args.record === true) {
18540
- const graph = await load2();
18541
- events = await record2(graph, [
18542
- auditCompletedInput(matrix, {
18853
+ let recorded = matrix;
18854
+ if (scope !== void 0) {
18855
+ try {
18856
+ recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(root, auditId, library) }, library);
18857
+ } catch (error51) {
18858
+ throw new ToolError(error51.message);
18859
+ }
18860
+ }
18861
+ events = await record2(graph ?? await load2(), [
18862
+ auditCompletedInput(recorded, {
18543
18863
  audit_id: auditId,
18544
18864
  framework_version: file2.framework_version,
18545
- ...file2.commit !== void 0 ? { commit: file2.commit } : {}
18865
+ ...file2.commit !== void 0 ? { commit: file2.commit } : {},
18866
+ ...scope !== void 0 ? { scope } : {}
18546
18867
  })
18547
18868
  ]);
18548
18869
  }
18549
18870
  return {
18550
18871
  ...file2,
18872
+ ...scope !== void 0 ? { scope, left_unscored: leftUnscored } : {},
18551
18873
  assessment_count: section.assessments.length,
18552
18874
  open_findings: open.length,
18553
18875
  lanes,
@@ -18641,7 +18963,7 @@ function buildKritikCatalog(ctx) {
18641
18963
  tool(
18642
18964
  {
18643
18965
  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. Cells scored in only one of the two audits 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.",
18966
+ description: "What got worse between two audits: a cell whose maturity level dropped, a cell that gained an open Critical or High finding, and a finding that was resolved and is open again. In repo mode each side is every audit through it, merged latest-wins, so a scoped re-audit's cells are compared with their last reading wherever it was taken; cells with no reading on one side are not compared \u2014 a half-finished audit is not a regression. With record=true, appends one quality.signal.tripped per regression (repo mode only \u2014 hosted comparisons are read-only and cover assessment-level drops, since hosted findings are a living pool rather than per-audit snapshots). A tripped signal is NOT a finding; it is the prompt to go look.",
18645
18967
  inputSchema: {
18646
18968
  type: "object",
18647
18969
  properties: {
@@ -18691,8 +19013,8 @@ function buildKritikCatalog(ctx) {
18691
19013
  let regressions;
18692
19014
  try {
18693
19015
  regressions = detectRegressions(
18694
- loadQualitySection(root, from, library),
18695
- loadQualitySection(root, to, library),
19016
+ loadQualitySectionThrough(root, from, library),
19017
+ loadQualitySectionThrough(root, to, library),
18696
19018
  library
18697
19019
  );
18698
19020
  } catch (error51) {
@@ -18747,6 +19069,33 @@ function buildKritikCatalog(ctx) {
18747
19069
  };
18748
19070
  }
18749
19071
  );
19072
+ tool(
19073
+ {
19074
+ name: "kritik_scope",
19075
+ description: "The cells a batch of fixes made stale \u2014 the work list for a scoped re-audit. A score only moves when its cell is re-scored, so after closing findings this lists exactly which (criterion x surface) cells to re-score instead of running a comprehensive audit: every quality.finding.resolved since the last recorded audit names its cell (`kind: direct`, `because` = finding ids), and one hop over node_ids adds neighbouring assessed cells a shared fix plausibly moved (`kind: widened`, `because` = node ids). Accepted risks are not fixes and never scope anything. `unknown` lists resolved ids that name no finding \u2014 report those, something closed an id that does not exist; `unscorable` lists resolved findings whose cell nothing can re-score (a retired criterion, a surface no longer in the profile). It plans an audit and scores nothing: re-score each cell with kritik_score, evidence and scope=true (which writes into an audit of its own, `<YYYY-MM>-scoped`, never the `since` audit whose recorded reading is history), then kritik_matrix with that audit_id and record=true. Recording closes the window: a cell left unscored drops out of the next scope, so re-score a widened cell that did not move at its current level, saying so in the evidence. Works in both modes \u2014 hosted reads the hosted journal and quality section.",
19076
+ inputSchema: {
19077
+ type: "object",
19078
+ properties: {
19079
+ since: { type: "string", description: "The recorded audit to measure from. Default: the newest quality.audit.completed." },
19080
+ widen: { type: "boolean", description: "Add the one-hop node neighbours. Default: true." }
19081
+ },
19082
+ additionalProperties: false
19083
+ }
19084
+ },
19085
+ async (args) => {
19086
+ const graph = await load2();
19087
+ const since = typeof args.since === "string" && args.since !== "" ? args.since : void 0;
19088
+ const scope = scopeOf(graph, {
19089
+ ...since !== void 0 ? { since } : {},
19090
+ ...args.widen === false ? { widen: false } : {}
19091
+ });
19092
+ return {
19093
+ ...scope,
19094
+ summary: scopeSummary(scope),
19095
+ ...scope.since === null ? { note: "No recorded audit yet \u2014 a scope is measured from one. `kritik_matrix` with record=true writes it." } : {}
19096
+ };
19097
+ }
19098
+ );
18750
19099
  tool(
18751
19100
  {
18752
19101
  name: "kritik_issue",
@@ -18807,7 +19156,7 @@ function buildKritikCatalog(ctx) {
18807
19156
  tool(
18808
19157
  {
18809
19158
  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. Repo sessions only: scoring reads the code, so a hosted session refuses.",
19159
+ description: "Record one (criterion x surface) maturity level with the evidence behind it. A cell holds exactly one level, so re-scoring replaces in place. Evidence is required: a score without a citation is an opinion, not an assessment. Score what the code IS, never what an open PR promises \u2014 that is what makes a trend real. For a scoped re-audit pass scope=true: a cell kritik_scope does not list is refused (so a between-milestone re-audit cannot drift into a comprehensive one), and the score lands in a scoped audit of its own (default <YYYY-MM>-scoped). Repo sessions only: scoring reads the code, so a hosted session refuses.",
18811
19160
  inputSchema: {
18812
19161
  type: "object",
18813
19162
  properties: {
@@ -18819,8 +19168,15 @@ function buildKritikCatalog(ctx) {
18819
19168
  description: "0 Absent \xB7 1 Ad-hoc \xB7 2 Defined \xB7 3 Managed \xB7 4 Verified. N/A is the absence of the row, not a level."
18820
19169
  },
18821
19170
  evidence: { type: "string", description: "file:line / config citations, markdown." },
18822
- audit_id: { type: "string", description: "Default: the newest audit, or the current YYYY-MM." },
18823
- commit: { type: "string" }
19171
+ audit_id: {
19172
+ type: "string",
19173
+ description: "Default: the newest audit, or the current YYYY-MM. With scope=true: the scoped audit in progress, else <YYYY-MM>-scoped."
19174
+ },
19175
+ commit: { type: "string" },
19176
+ scope: {
19177
+ type: "boolean",
19178
+ description: "This is a scoped re-audit: refuse a cell kritik_scope does not list. Leave it off to re-score an out-of-scope cell on purpose."
19179
+ }
18824
19180
  },
18825
19181
  required: ["criterion_id", "surface", "level", "evidence"],
18826
19182
  additionalProperties: false
@@ -18841,7 +19197,42 @@ function buildKritikCatalog(ctx) {
18841
19197
  `${criterionId} does not apply to "${surface}" (applies to: ${appliesTo.join(", ")}). Scoring it there would produce a cell nothing rolls up.`
18842
19198
  );
18843
19199
  }
18844
- const auditId = auditForWrite(root, args.audit_id);
19200
+ let scopedFrom;
19201
+ let auditId;
19202
+ const graph = await load2();
19203
+ if (args.scope === true) {
19204
+ const scope = scopeOf(graph);
19205
+ if (scope.since === null) {
19206
+ throw new ToolError("scope=true needs a recorded audit to measure from \u2014 kritik_matrix with record=true writes one.");
19207
+ }
19208
+ if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
19209
+ throw new ToolError(
19210
+ `${criterionId} x ${surface} is not in the current scope (${scopeSummary(scope)}). kritik_scope lists the cells; leave scope off to re-score this one on purpose.`
19211
+ );
19212
+ }
19213
+ try {
19214
+ auditId = scopedAuditTarget(
19215
+ root,
19216
+ scope.since,
19217
+ currentAuditId(),
19218
+ typeof args.audit_id === "string" && args.audit_id !== "" ? args.audit_id : void 0,
19219
+ recordedAuditIds(graph.journal)
19220
+ );
19221
+ } catch (error51) {
19222
+ throw new ToolError(error51.message);
19223
+ }
19224
+ scopedFrom = scope.since;
19225
+ } else {
19226
+ auditId = auditForWrite(root, args.audit_id);
19227
+ }
19228
+ const notes = [];
19229
+ if (scopedFrom === void 0) {
19230
+ if (recordedAuditIds(graph.journal).includes(auditId)) {
19231
+ notes.push(`${auditId} is already recorded \u2014 a re-score here rewrites that reading. For a re-audit after fixes, pass scope=true.`);
19232
+ }
19233
+ const order = auditOrderNote(root, auditId);
19234
+ if (order !== void 0) notes.push(order);
19235
+ }
18845
19236
  const file2 = loadScoresOrEmpty(root, auditId);
18846
19237
  const assessment = {
18847
19238
  criterion_id: criterionId,
@@ -18858,14 +19249,17 @@ function buildKritikCatalog(ctx) {
18858
19249
  audit_id: auditId,
18859
19250
  framework_version: file2.framework_version ?? library.version,
18860
19251
  ...typeof args.commit === "string" ? { commit: args.commit } : {},
19252
+ ...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
18861
19253
  assessments
18862
19254
  });
18863
19255
  return {
18864
19256
  assessment,
18865
19257
  audit_id: auditId,
19258
+ ...scopedFrom !== void 0 ? { scoped_from: scopedFrom } : {},
18866
19259
  assessment_count: assessments.length,
18867
19260
  ...replaced !== void 0 ? { replaced_level: replaced.level } : {},
18868
- anchor: criterion.level_anchors?.[`l${level}`]
19261
+ anchor: criterion.level_anchors?.[`l${level}`],
19262
+ ...notes.length > 0 ? { notes } : {}
18869
19263
  };
18870
19264
  }
18871
19265
  );
@@ -19861,7 +20255,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
19861
20255
  }
19862
20256
 
19863
20257
  // src/index.ts
19864
- var VERSION = "0.5.0";
20258
+ var VERSION = "0.6.0";
19865
20259
  var argv = process.argv.slice(2);
19866
20260
  if (argv.includes("--help") || argv.includes("-h")) {
19867
20261
  process.stdout.write(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkaik-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Arkaik MCP server — stdio tools over an Arkaik product-graph bundle: read projections plus validator-gated dual-write mutations.",
5
5
  "license": "MIT",
6
6
  "type": "module",