arkaik 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 (3) hide show
  1. package/dist/index.js +457 -13
  2. package/dist/io.js +7 -0
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15195,6 +15195,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
15195
15195
  medium: external_exports.number().optional(),
15196
15196
  low: external_exports.number().optional(),
15197
15197
  info: external_exports.number().optional()
15198
+ }).catchall(external_exports.unknown()).optional(),
15199
+ // A scoped re-audit (issue #443). Optional and catchall like `counts`:
15200
+ // older readers ignore it, and its `scores` stay the same shape either way.
15201
+ scope: external_exports.object({
15202
+ partial: external_exports.boolean().optional(),
15203
+ cells: external_exports.number().optional(),
15204
+ since: external_exports.string().optional()
15198
15205
  }).catchall(external_exports.unknown()).optional()
15199
15206
  }).catchall(external_exports.unknown());
15200
15207
  var QualityFindingOpenedEventSchema = external_exports.object({
@@ -17202,7 +17209,8 @@ function auditCompletedInput(matrix, meta3) {
17202
17209
  framework_version: meta3.framework_version,
17203
17210
  ...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
17204
17211
  scores,
17205
- counts: matrix.finding_counts
17212
+ counts: matrix.finding_counts,
17213
+ ...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
17206
17214
  }
17207
17215
  };
17208
17216
  }
@@ -17472,6 +17480,164 @@ function formatDelta(delta) {
17472
17480
  return "=";
17473
17481
  }
17474
17482
 
17483
+ // ../schema/src/quality-scope.ts
17484
+ var rowsOf2 = (value) => Array.isArray(value) ? value : [];
17485
+ var isString = (value) => typeof value === "string" && value !== "";
17486
+ var stringsOf = (value) => rowsOf2(value).filter(isString);
17487
+ var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
17488
+ function recordedAuditIds(events) {
17489
+ const ids = [];
17490
+ for (const event of orderEvents(rowsOf2(events))) {
17491
+ if (event?.type !== "quality.audit.completed") continue;
17492
+ const id = event.audit_id;
17493
+ if (isString(id) && !ids.includes(id)) ids.push(id);
17494
+ }
17495
+ return ids;
17496
+ }
17497
+ function deriveAuditScope(events, section, library, options = {}) {
17498
+ const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
17499
+ let sinceIndex = -1;
17500
+ for (let i = ordered.length - 1; i >= 0; i--) {
17501
+ const event = ordered[i];
17502
+ if (event.type !== "quality.audit.completed") continue;
17503
+ const id = event.audit_id;
17504
+ if (options.since !== void 0 && id !== options.since) continue;
17505
+ sinceIndex = i;
17506
+ break;
17507
+ }
17508
+ const empty = {
17509
+ since: options.since ?? null,
17510
+ since_ts: null,
17511
+ cells: [],
17512
+ findings: [],
17513
+ resolved_by: {},
17514
+ unknown: [],
17515
+ unscorable: [],
17516
+ widened: 0
17517
+ };
17518
+ if (sinceIndex === -1) return empty;
17519
+ const anchor = ordered[sinceIndex];
17520
+ const anchorId = anchor.audit_id;
17521
+ const since = isString(anchorId) ? anchorId : null;
17522
+ const sinceTs = isString(anchor.ts) ? anchor.ts : null;
17523
+ const resolutions = /* @__PURE__ */ new Map();
17524
+ for (const event of ordered.slice(sinceIndex + 1)) {
17525
+ if (event.type !== "quality.finding.resolved") continue;
17526
+ const findingId = event.finding_id;
17527
+ if (!isString(findingId)) continue;
17528
+ const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
17529
+ const by = event.resolved_by;
17530
+ if (isString(by)) entry.resolved_by = by;
17531
+ for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
17532
+ resolutions.set(findingId, entry);
17533
+ }
17534
+ if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
17535
+ const findings = rowsOf2(section?.findings).filter(
17536
+ (finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
17537
+ );
17538
+ const findingById = /* @__PURE__ */ new Map();
17539
+ for (const finding of findings) findingById.set(finding.id, finding);
17540
+ const criterionById = /* @__PURE__ */ new Map();
17541
+ for (const criterion of rowsOf2(library?.criteria)) {
17542
+ if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
17543
+ }
17544
+ const assessmentByCell = /* @__PURE__ */ new Map();
17545
+ for (const assessment of rowsOf2(section?.assessments)) {
17546
+ if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
17547
+ assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
17548
+ }
17549
+ const declared = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
17550
+ const surfaces = declared.length > 0 ? [...new Set(declared)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
17551
+ const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
17552
+ const scorable = (criterionId, surface) => {
17553
+ const criterion = criterionById.get(criterionId);
17554
+ if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
17555
+ if (declared.length > 0 && !surfaces.includes(surface)) return false;
17556
+ return appliesTo(criterion, surface);
17557
+ };
17558
+ const cells = /* @__PURE__ */ new Map();
17559
+ const addDirect = (criterionId, surface, findingId) => {
17560
+ const key = cellKey2(criterionId, surface);
17561
+ const existing = cells.get(key);
17562
+ if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
17563
+ else if (!existing.because.includes(findingId)) existing.because.push(findingId);
17564
+ };
17565
+ const drivers = [];
17566
+ const unknown2 = [];
17567
+ const unscorable = [];
17568
+ const resolvedBy = {};
17569
+ const resolvedNodes = /* @__PURE__ */ new Set();
17570
+ for (const [findingId, resolution] of resolutions) {
17571
+ const finding = findingById.get(findingId);
17572
+ if (finding === void 0) {
17573
+ unknown2.push(findingId);
17574
+ continue;
17575
+ }
17576
+ if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
17577
+ const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
17578
+ (surface) => scorable(finding.criterion_id, surface)
17579
+ );
17580
+ for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
17581
+ for (const node of resolution.node_ids) resolvedNodes.add(node);
17582
+ if (targets.length === 0) {
17583
+ unscorable.push(findingId);
17584
+ continue;
17585
+ }
17586
+ drivers.push(findingId);
17587
+ if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
17588
+ for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
17589
+ }
17590
+ let widened = 0;
17591
+ if (options.widen !== false && resolvedNodes.size > 0) {
17592
+ const nodesByCell = /* @__PURE__ */ new Map();
17593
+ const noteNodes = (criterionId, surface, nodes) => {
17594
+ const key = cellKey2(criterionId, surface);
17595
+ const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
17596
+ for (const node of nodes) bucket.add(node);
17597
+ nodesByCell.set(key, bucket);
17598
+ };
17599
+ for (const finding of findings) {
17600
+ const nodes = stringsOf(finding.node_ids);
17601
+ if (nodes.length === 0) continue;
17602
+ if (finding.surface === CROSS_SURFACE_ID) {
17603
+ for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
17604
+ } else {
17605
+ noteNodes(finding.criterion_id, finding.surface, nodes);
17606
+ }
17607
+ }
17608
+ for (const [key, assessment] of assessmentByCell) {
17609
+ if (cells.has(key)) continue;
17610
+ if (!criterionById.has(assessment.criterion_id)) continue;
17611
+ if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
17612
+ const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
17613
+ if (shared.length === 0) continue;
17614
+ cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
17615
+ widened++;
17616
+ }
17617
+ }
17618
+ for (const [key, cell] of cells) {
17619
+ const assessment = assessmentByCell.get(key);
17620
+ if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
17621
+ cell.current = { level: assessment.level, audit_id: assessment.audit_id };
17622
+ }
17623
+ }
17624
+ const column = (surface) => {
17625
+ const at2 = surfaces.indexOf(surface);
17626
+ return at2 === -1 ? surfaces.length : at2;
17627
+ };
17628
+ const sorted = [...cells.values()].sort(
17629
+ (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)
17630
+ );
17631
+ return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
17632
+ }
17633
+ function scopeSummary(scope) {
17634
+ const direct = scope.cells.length - scope.widened;
17635
+ const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
17636
+ const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
17637
+ const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
17638
+ return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
17639
+ }
17640
+
17475
17641
  // src/commands/init.ts
17476
17642
  var DEFAULT_BUNDLE_PATH = "docs/arkaik/bundle.json";
17477
17643
  var DEFAULT_JOURNAL_PATH = "docs/arkaik/journal.jsonl";
@@ -18957,6 +19123,14 @@ function loadCurrentQualitySection(root, library) {
18957
19123
  if (auditIds.length === 0) return void 0;
18958
19124
  const profile = loadProfile(root);
18959
19125
  if (!profile) return void 0;
19126
+ return mergeAudits(root, auditIds, library, profile);
19127
+ }
19128
+ function loadQualitySectionThrough(root, auditId, library) {
19129
+ requireAudit(root, auditId);
19130
+ const auditIds = listAuditIds(root);
19131
+ return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
19132
+ }
19133
+ function mergeAudits(root, auditIds, library, profile) {
18960
19134
  const cells = /* @__PURE__ */ new Map();
18961
19135
  const findings = [];
18962
19136
  let frameworkVersion;
@@ -18976,6 +19150,57 @@ function loadCurrentQualitySection(root, library) {
18976
19150
  findings
18977
19151
  };
18978
19152
  }
19153
+ function scopedAuditTarget(root, since, month, requested, recorded = []) {
19154
+ const existing = listAuditIds(root);
19155
+ const newest = existing[existing.length - 1];
19156
+ if (requested !== void 0) {
19157
+ if (requested === since) {
19158
+ throw new Error(
19159
+ `"${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.`
19160
+ );
19161
+ }
19162
+ if (newest !== void 0 && requested < newest) {
19163
+ throw new Error(
19164
+ `"${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\`).`
19165
+ );
19166
+ }
19167
+ return requested;
19168
+ }
19169
+ if (newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since) {
19170
+ return newest;
19171
+ }
19172
+ for (let n = 1; n < 100; n++) {
19173
+ const candidate = n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
19174
+ if (existing.includes(candidate)) continue;
19175
+ if (newest !== void 0 && candidate < newest) {
19176
+ throw new Error(
19177
+ `"${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}".`
19178
+ );
19179
+ }
19180
+ return candidate;
19181
+ }
19182
+ throw new Error(`99 scoped audits in ${month} \u2014 name the next one with --audit.`);
19183
+ }
19184
+ function declaredScopeSince(auditId, recorded) {
19185
+ if (recorded.includes(auditId)) {
19186
+ throw new Error(
19187
+ `"${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.`
19188
+ );
19189
+ }
19190
+ const before = recorded.filter((id) => id < auditId).sort();
19191
+ const since = before[before.length - 1];
19192
+ if (since === void 0) {
19193
+ throw new Error(
19194
+ `no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
19195
+ );
19196
+ }
19197
+ return since;
19198
+ }
19199
+ function auditOrderNote(root, auditId) {
19200
+ const later = listAuditIds(root).filter((id) => id > auditId);
19201
+ if (later.length === 0) return void 0;
19202
+ 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.`;
19203
+ }
18979
19204
  function loadAuditQualitySection(root, auditId, library) {
18980
19205
  requireAudit(root, auditId);
18981
19206
  const section = loadQualitySection(root, auditId, library, loadScoresOrEmpty(root, auditId));
@@ -21867,6 +22092,7 @@ Subcommands:
21867
22092
  signals The signal pack, and what has tripped since the last audit.
21868
22093
  regressions What got worse between two audits.
21869
22094
  trend Every recorded audit's scores, and which way each moved.
22095
+ scope The cells your resolved findings made stale since the last audit.
21870
22096
  issue <criterion> Print the prefilled GitHub issue skeleton.
21871
22097
  criterion add ... Add a project-specific criterion to the overlay.
21872
22098
 
@@ -21894,6 +22120,10 @@ Options:
21894
22120
  Required: a score without a citation is an opinion.
21895
22121
  --audit <id> The audit run (default: the newest, or the current YYYY-MM).
21896
22122
  --commit <sha> The commit the evidence is pinned to.
22123
+ --scope This is a scoped re-audit: refuse a cell \`arkaik kritik scope\`
22124
+ does not list, and write into a scoped audit of its own
22125
+ (default <YYYY-MM>-scoped, never the audit it was scoped
22126
+ from). Leave it off to re-score an out-of-scope cell on purpose.
21897
22127
 
21898
22128
  Writes docs/quality/audits/<id>/scores.json`;
21899
22129
  var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
@@ -21917,7 +22147,7 @@ var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
21917
22147
  Records it as a known, owned risk. The note is required \u2014 an accepted risk is a
21918
22148
  decision and reads like one. No journal event: acceptance is a state of the
21919
22149
  finding, not something that happened to the product.`;
21920
- var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record]
22150
+ var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record] [--scope]
21921
22151
 
21922
22152
  Roll one audit up into its comparative matrix and write matrix.json \u2014 the only
21923
22153
  thing that may write that file.
@@ -21925,7 +22155,14 @@ thing that may write that file.
21925
22155
  audit-id The audit under docs/quality/audits/ (default: the newest).
21926
22156
  --json Print matrix.json instead of the markdown table.
21927
22157
  --record Also append quality.audit.completed, carrying these scores
21928
- and counts. Do this once per finished audit.`;
22158
+ and counts. Do this once per finished audit.
22159
+ --scope Treat the audit as a scoped re-audit even though it was
22160
+ scored without \`score --scope\` (which marks it for you).
22161
+
22162
+ A scoped re-audit holds only the cells it re-scored, so matrix.json shows just
22163
+ those ("how did this audit go"), while --record carries the merged matrix
22164
+ through this audit ("where does the product stand") \u2014 the reading the trend
22165
+ replays. Everything else keeps its last score.`;
21929
22166
  var SIGNALS_USAGE = `arkaik kritik signals [--surface <s>] [--criterion <c>] [--domain <CODE>] [--json]
21930
22167
  arkaik kritik signals --trip <criterion> --surface <s> --signal <index|text> [--detail <d>]
21931
22168
 
@@ -21944,8 +22181,10 @@ var REGRESSIONS_USAGE = `arkaik kritik regressions [--from <audit>] [--to <audit
21944
22181
 
21945
22182
  What got worse between two audits: a cell whose maturity dropped, a cell that
21946
22183
  gained an open Critical or High finding, a finding that was resolved and is open
21947
- again. Cells scored in only one of the two audits are not compared \u2014 a
21948
- half-finished audit is not a regression.
22184
+ again. Each side is every audit through it, merged latest-wins \u2014 so a scoped
22185
+ re-audit's cells are compared with their last reading, wherever it was taken.
22186
+ Cells with no reading on one side are not compared \u2014 a half-finished audit is
22187
+ not a regression.
21949
22188
 
21950
22189
  Exits 1 when anything regressed, which is what makes it usable as a CI step or a
21951
22190
  scheduled routine.
@@ -21969,6 +22208,27 @@ Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.js
21969
22208
  and audits recorded with \`arkaik kritik matrix --record\`. A framework major
21970
22209
  bump between two audits breaks the comparison there (SPEC \xA7 8): the row still
21971
22210
  prints, without an arrow.`;
22211
+ var SCOPE_USAGE = `arkaik kritik scope [--since <audit>] [--no-widen] [--json]
22212
+
22213
+ The cells a batch of fixes made stale. A score is an assessment, so closing
22214
+ findings moves nothing until the cells they lived on are re-scored \u2014 and a
22215
+ comprehensive audit is a lot of audit for twenty fixes. Every finding resolved
22216
+ since the last recorded audit names its (criterion x surface) cell; one hop
22217
+ over node_ids adds the neighbours a fix in a shared view plausibly moved.
22218
+
22219
+ This is a work list, not a score: re-score each cell with evidence
22220
+ (\`arkaik kritik score \u2026 --scope\`, which writes into an audit of its own,
22221
+ <YYYY-MM>-scoped, and refuses a cell this list does not hold), then
22222
+ \`arkaik kritik matrix --record\`. Every other cell keeps its last score.
22223
+ Recording closes the window: a cell left unscored drops out of the next scope.
22224
+
22225
+ --since <audit> Measure from this recorded audit (default: the newest
22226
+ quality.audit.completed in the journal).
22227
+ --no-widen Only the resolved findings' own cells, no neighbours.
22228
+ --json The scope as JSON (what an agent should read).
22229
+
22230
+ Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.json)
22231
+ and an audit recorded with \`arkaik kritik matrix --record\` to measure from.`;
21972
22232
  var ISSUE_USAGE = `arkaik kritik issue <criterion> --surface <s> [--level <n>] [--finding <id>]
21973
22233
 
21974
22234
  Print the criterion's GitHub issue skeleton, filled as far as what we know
@@ -22191,7 +22451,7 @@ Pass --force if that is genuinely what you want.`
22191
22451
  process.exit(0);
22192
22452
  }
22193
22453
  function runScore(args, common) {
22194
- const { single, flags, positionals } = collect(args);
22454
+ const { single, flags, positionals } = collect(args, [], ["scope"]);
22195
22455
  if (flags.has("help")) {
22196
22456
  console.log(SCORE_USAGE);
22197
22457
  process.exit(0);
@@ -22220,7 +22480,39 @@ Scoring it there would produce a cell nothing rolls up.`
22220
22480
  ${SCORE_USAGE}`);
22221
22481
  }
22222
22482
  const evidence = textOrFile(single.evidence);
22223
- const auditId = auditForWrite(common.root, single.audit);
22483
+ let scopedFrom;
22484
+ let auditId;
22485
+ if (flags.has("scope")) {
22486
+ const { scope, recorded } = currentScope(common, library, profile);
22487
+ if (scope.since === null) {
22488
+ fail12(`kritik: --scope needs a recorded audit to measure from \u2014 \`arkaik kritik matrix --record\` writes one.`);
22489
+ }
22490
+ if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
22491
+ fail12(
22492
+ `kritik: ${criterionId} x ${surface} is not in the current scope (${scopeSummary(scope)}).
22493
+ \`arkaik kritik scope\` lists the cells; drop --scope to re-score this one on purpose.`
22494
+ );
22495
+ }
22496
+ try {
22497
+ auditId = scopedAuditTarget(common.root, scope.since, currentAuditId(), single.audit, recorded);
22498
+ } catch (error51) {
22499
+ return fail12(`kritik: ${error51.message}`);
22500
+ }
22501
+ scopedFrom = scope.since;
22502
+ } else {
22503
+ auditId = auditForWrite(common.root, single.audit);
22504
+ }
22505
+ const notes = [];
22506
+ if (scopedFrom === void 0) {
22507
+ const journal = resolveJournal(common.root, common.bundlePath);
22508
+ if (journal.present && recordedAuditIds(readFullJournalEvents(journal.journalPath)).includes(auditId)) {
22509
+ notes.push(
22510
+ `${auditId} is already recorded \u2014 a re-score here rewrites that reading. For a re-audit after fixes, \`arkaik kritik score \u2026 --scope\` writes into an audit of its own.`
22511
+ );
22512
+ }
22513
+ const order = auditOrderNote(common.root, auditId);
22514
+ if (order !== void 0) notes.push(order);
22515
+ }
22224
22516
  const file2 = loadScoresOrEmpty(common.root, auditId);
22225
22517
  const assessment = {
22226
22518
  criterion_id: criterionId,
@@ -22237,14 +22529,17 @@ ${SCORE_USAGE}`);
22237
22529
  audit_id: auditId,
22238
22530
  framework_version: file2.framework_version ?? library.version,
22239
22531
  ...single.commit !== void 0 ? { commit: single.commit } : {},
22532
+ ...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
22240
22533
  assessments
22241
22534
  });
22242
22535
  const anchor = criterion.level_anchors?.[`l${level}`];
22243
22536
  console.log(
22244
22537
  `
22245
22538
  ${replaced ? `re-scored ${criterionId} x ${surface}: ${replaced.level} -> ${level}` : `scored ${criterionId} x ${surface} at ${level}`}${anchor ? ` \u2014 ${anchor}` : ""}
22246
- ${assessments.length} assessment${assessments.length === 1 ? "" : "s"} in ${auditId} -> ${scoresPath(common.root, auditId)}`
22539
+ ${assessments.length} assessment${assessments.length === 1 ? "" : "s"} in ${auditId} -> ${scoresPath(common.root, auditId)}` + (scopedFrom !== void 0 ? `
22540
+ scoped re-audit since ${scopedFrom} \u2014 every cell it does not re-score keeps its last score` : "")
22247
22541
  );
22542
+ for (const note of notes) console.log(` note: ${note}`);
22248
22543
  if (level < DEFAULT_TARGET_LEVEL) {
22249
22544
  console.log(
22250
22545
  ` below the level-${DEFAULT_TARGET_LEVEL} target \u2014 open a finding, or say in the evidence why this surface should not reach it.`
@@ -22401,8 +22696,31 @@ ${FINDING_USAGE}`);
22401
22696
  );
22402
22697
  process.exit(0);
22403
22698
  }
22699
+ function scopedSince(common, auditId, stamped, declared) {
22700
+ if (stamped !== void 0) return stamped;
22701
+ if (!declared) return void 0;
22702
+ const journal = resolveJournal(common.root, common.bundlePath);
22703
+ if (!journal.present) {
22704
+ fail12(`kritik: --scope needs the audit this one was scoped from, and there is no journal at ${journal.bundlePath}.`);
22705
+ }
22706
+ try {
22707
+ return declaredScopeSince(auditId, recordedAuditIds(readFullJournalEvents(journal.journalPath)));
22708
+ } catch (error51) {
22709
+ return fail12(`kritik: --scope refused \u2014 ${error51.message}`);
22710
+ }
22711
+ }
22712
+ function unscoredScopeCells(common, library, since, assessed) {
22713
+ const journal = resolveJournal(common.root, common.bundlePath);
22714
+ const profile = loadProfile(common.root);
22715
+ if (!journal.present || !profile) return [];
22716
+ const section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
22717
+ const scope = deriveAuditScope(readFullJournalEvents(journal.journalPath), section, library);
22718
+ if (scope.since !== since) return [];
22719
+ const done = new Set(assessed.map((a) => `${a.criterion_id}::${a.surface}`));
22720
+ return scope.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`));
22721
+ }
22404
22722
  function runMatrix(args, common) {
22405
- const { flags, positionals } = collect(args, [], ["json", "record"]);
22723
+ const { flags, positionals } = collect(args, [], ["json", "record", "scope"]);
22406
22724
  if (flags.has("help")) {
22407
22725
  console.log(MATRIX_USAGE);
22408
22726
  process.exit(0);
@@ -22421,8 +22739,21 @@ function runMatrix(args, common) {
22421
22739
  return fail12(`kritik: ${error51.message}`);
22422
22740
  }
22423
22741
  const { section, matrix, file: file2 } = computed;
22742
+ const since = scopedSince(common, auditId, loadScoresOrEmpty(common.root, auditId).scope?.since, flags.has("scope"));
22743
+ const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
22744
+ const unscored = scope !== void 0 ? unscoredScopeCells(common, library, scope.since, section.assessments) : [];
22745
+ const reportUnscored = (log) => {
22746
+ if (unscored.length === 0) return;
22747
+ log(
22748
+ flags.has("record") ? `
22749
+ ! ${unscored.length} cell${unscored.length === 1 ? "" : "s"} in the scope ${unscored.length === 1 ? "was" : "were"} left unscored \u2014 recording closes the window, so ${unscored.length === 1 ? "it drops" : "they drop"} out of the next \`scope\`:` : `
22750
+ ${unscored.length} cell${unscored.length === 1 ? "" : "s"} in the scope not re-scored yet (a widened cell that did not move is re-scored at its current level, saying so):`
22751
+ );
22752
+ for (const cell of unscored) log(` ${cell.surface} \xB7 ${cell.criterion_id} (${cell.kind})`);
22753
+ };
22424
22754
  if (flags.has("json")) {
22425
22755
  console.log(JSON.stringify(file2, null, 2));
22756
+ reportUnscored((line2) => console.error(line2));
22426
22757
  } else {
22427
22758
  const domainNames = new Map((library.domains ?? []).map((d) => [d.code, d.name]));
22428
22759
  console.log(`
@@ -22446,11 +22777,33 @@ P0 \u2014 fix first:`);
22446
22777
  }
22447
22778
  console.log(`
22448
22779
  wrote ${matrixPath(common.root, auditId)}`);
22780
+ if (scope !== void 0) {
22781
+ reportUnscored((line2) => console.log(line2));
22782
+ console.log(
22783
+ `
22784
+ scoped re-audit: ${scope.cells} cell${scope.cells === 1 ? "" : "s"} re-scored since ${scope.since}. The table is this audit alone; ${flags.has("record") ? "the recorded event carries" : "--record records"} the merged matrix through it \u2014 every other cell at its last score.`
22785
+ );
22786
+ }
22449
22787
  }
22450
22788
  if (flags.has("record")) {
22789
+ let recorded = matrix;
22790
+ if (scope !== void 0) {
22791
+ try {
22792
+ recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(common.root, auditId, library) }, library);
22793
+ } catch (error51) {
22794
+ return fail12(`kritik: ${error51.message}`);
22795
+ }
22796
+ }
22451
22797
  reportJournal(
22452
22798
  common.root,
22453
- [auditCompletedInput(matrix, { audit_id: auditId, framework_version: file2.framework_version, ...file2.commit !== void 0 ? { commit: file2.commit } : {} })],
22799
+ [
22800
+ auditCompletedInput(recorded, {
22801
+ audit_id: auditId,
22802
+ framework_version: file2.framework_version,
22803
+ ...file2.commit !== void 0 ? { commit: file2.commit } : {},
22804
+ ...scope !== void 0 ? { scope } : {}
22805
+ })
22806
+ ],
22454
22807
  common
22455
22808
  );
22456
22809
  }
@@ -22576,8 +22929,8 @@ function runRegressions(args, common) {
22576
22929
  let regressions;
22577
22930
  try {
22578
22931
  regressions = detectRegressions(
22579
- loadQualitySection(common.root, from, library),
22580
- loadQualitySection(common.root, to, library),
22932
+ loadQualitySectionThrough(common.root, from, library),
22933
+ loadQualitySectionThrough(common.root, to, library),
22581
22934
  library
22582
22935
  );
22583
22936
  } catch (error51) {
@@ -22680,6 +23033,95 @@ function runTrend(args, common) {
22680
23033
  );
22681
23034
  process.exit(0);
22682
23035
  }
23036
+ function scopeReason(cell, resolvedBy) {
23037
+ if (cell.kind === "widened") return `widened via ${cell.because.join(", ")}`;
23038
+ const findings = cell.because.map((id) => resolvedBy[id] !== void 0 ? `${id} (resolved by ${resolvedBy[id]})` : id);
23039
+ return `because ${findings.join(", ")}`;
23040
+ }
23041
+ function currentScope(common, library, profile, options = {}) {
23042
+ const journal = resolveJournal(common.root, common.bundlePath);
23043
+ if (!journal.present) {
23044
+ fail12(
23045
+ `kritik: no bundle at ${journal.bundlePath} \u2014 the scope is measured from the journal's quality.audit.completed and quality.finding.resolved events, and there is no journal without a bundle.`
23046
+ );
23047
+ }
23048
+ const events = readFullJournalEvents(journal.journalPath);
23049
+ const recorded = recordedAuditIds(events);
23050
+ if (options.since !== void 0) {
23051
+ if (!recorded.includes(options.since)) {
23052
+ fail12(
23053
+ `kritik: no recorded audit "${options.since}" in ${journal.journalPath} (recorded: ${recorded.join(", ") || "none \u2014 `arkaik kritik matrix --record` writes one"}).
23054
+ A scope is measured from a recorded reading; an audit directory that was never recorded is not one.`
23055
+ );
23056
+ }
23057
+ }
23058
+ let section;
23059
+ try {
23060
+ section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
23061
+ } catch (error51) {
23062
+ return fail12(`kritik: ${error51.message}`);
23063
+ }
23064
+ return { scope: deriveAuditScope(events, section, library, options), journalPath: journal.journalPath, recorded };
23065
+ }
23066
+ function runScope(args, common) {
23067
+ const { single, flags } = collect(args, [], ["json", "no-widen"]);
23068
+ if (flags.has("help")) {
23069
+ console.log(SCOPE_USAGE);
23070
+ process.exit(0);
23071
+ }
23072
+ const library = loadLibraryOrFail(common.root);
23073
+ const profile = profileOrFail(common.root);
23074
+ const { scope } = currentScope(common, library, profile, {
23075
+ ...single.since !== void 0 ? { since: single.since } : {},
23076
+ widen: !flags.has("no-widen")
23077
+ });
23078
+ if (flags.has("json")) {
23079
+ console.log(JSON.stringify({ ...scope, summary: scopeSummary(scope) }, null, 2));
23080
+ process.exit(0);
23081
+ }
23082
+ if (scope.since === null) {
23083
+ console.log(
23084
+ `
23085
+ no recorded audit yet \u2014 a scope is measured from one. \`arkaik kritik matrix --record\` writes it.
23086
+ `
23087
+ );
23088
+ process.exit(0);
23089
+ }
23090
+ console.log("");
23091
+ let surface = "";
23092
+ for (const cell of scope.cells) {
23093
+ if (cell.surface !== surface) {
23094
+ if (surface !== "") console.log("");
23095
+ surface = cell.surface;
23096
+ }
23097
+ const current = cell.current !== void 0 ? `at ${cell.current.level} (${cell.current.audit_id})` : "unscored";
23098
+ console.log(` ${cell.surface} \xB7 ${cell.criterion_id} \xB7 ${current} \xB7 ${scopeReason(cell, scope.resolved_by)}`);
23099
+ }
23100
+ if (scope.cells.length > 0) console.log("");
23101
+ console.log(` ${scopeSummary(scope)}`);
23102
+ if (scope.unknown.length > 0) {
23103
+ console.log(
23104
+ `
23105
+ ! ${scope.unknown.length} resolved id${scope.unknown.length === 1 ? " names" : "s name"} no finding in any audit \u2014 something closed an id that does not exist:`
23106
+ );
23107
+ for (const id of scope.unknown) console.log(` ${id}`);
23108
+ }
23109
+ if (scope.unscorable.length > 0) {
23110
+ console.log(
23111
+ `
23112
+ ! ${scope.unscorable.length} resolved finding${scope.unscorable.length === 1 ? " sits" : "s sit"} on a cell nothing can re-score (a retired criterion, or a surface no longer in the profile) \u2014 the fix still counts, but there is no score to move:`
23113
+ );
23114
+ for (const id of scope.unscorable) console.log(` ${id}`);
23115
+ }
23116
+ if (scope.cells.length > 0) {
23117
+ console.log(
23118
+ `
23119
+ re-score each with evidence \u2014 \`arkaik kritik score <criterion> <surface> <level> --evidence \u2026 --scope\` \u2014 then \`arkaik kritik matrix --record\`. --scope writes into an audit of its own, never ${scope.since}, whose recorded reading is history. Every other cell keeps its last score.`
23120
+ );
23121
+ }
23122
+ console.log("");
23123
+ process.exit(0);
23124
+ }
22683
23125
  function runIssue(args, common) {
22684
23126
  const { single, flags, positionals } = collect(args);
22685
23127
  if (flags.has("help")) {
@@ -22823,6 +23265,8 @@ function runKritik(args) {
22823
23265
  return runRegressions(subArgs, common);
22824
23266
  case "trend":
22825
23267
  return runTrend(subArgs, common);
23268
+ case "scope":
23269
+ return runScope(subArgs, common);
22826
23270
  case "issue":
22827
23271
  return runIssue(subArgs, common);
22828
23272
  case "criterion":
@@ -22862,7 +23306,7 @@ Options:
22862
23306
  -v, --version Print the version.
22863
23307
 
22864
23308
  Run "arkaik <command> --help" for command-specific help.`;
22865
- var VERSION = "0.5.0";
23309
+ var VERSION = "0.6.0";
22866
23310
  function main(argv) {
22867
23311
  const [command, ...rest] = argv;
22868
23312
  if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
package/dist/io.js CHANGED
@@ -15182,6 +15182,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
15182
15182
  medium: external_exports.number().optional(),
15183
15183
  low: external_exports.number().optional(),
15184
15184
  info: external_exports.number().optional()
15185
+ }).catchall(external_exports.unknown()).optional(),
15186
+ // A scoped re-audit (issue #443). Optional and catchall like `counts`:
15187
+ // older readers ignore it, and its `scores` stay the same shape either way.
15188
+ scope: external_exports.object({
15189
+ partial: external_exports.boolean().optional(),
15190
+ cells: external_exports.number().optional(),
15191
+ since: external_exports.string().optional()
15185
15192
  }).catchall(external_exports.unknown()).optional()
15186
15193
  }).catchall(external_exports.unknown());
15187
15194
  var QualityFindingOpenedEventSchema = external_exports.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkaik",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Arkaik CLI — link a repository to a hosted product graph, validate and pack bundles, mirror external ref status.",
5
5
  "license": "MIT",
6
6
  "type": "module",