arkaik 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +507 -16
  2. package/dist/io.js +23 -1
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15195,7 +15195,27 @@ 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()
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()
15205
+ }).catchall(external_exports.unknown()).optional(),
15206
+ // A reading synthesized from a stored audit that arrived without one (issue #472).
15207
+ baseline: external_exports.boolean().optional()
15208
+ }).catchall(external_exports.unknown());
15209
+ var QualityAssessmentScoredEventSchema = external_exports.object({
15210
+ ...envelope,
15211
+ type: external_exports.literal("quality.assessment.scored"),
15212
+ audit_id: external_exports.string(),
15213
+ criterion_id: external_exports.string(),
15214
+ surface: external_exports.string(),
15215
+ level: external_exports.number().int().min(0).max(4),
15216
+ evidence: external_exports.string(),
15217
+ commit: external_exports.string().optional(),
15218
+ scope: external_exports.object({ since: external_exports.string().optional() }).catchall(external_exports.unknown()).optional()
15199
15219
  }).catchall(external_exports.unknown());
15200
15220
  var QualityFindingOpenedEventSchema = external_exports.object({
15201
15221
  ...envelope,
@@ -15249,6 +15269,7 @@ var JOURNAL_EVENT_SCHEMAS = {
15249
15269
  "ref.status_changed": RefStatusChangedEventSchema,
15250
15270
  "journal.baseline": JournalBaselineEventSchema,
15251
15271
  "quality.audit.completed": QualityAuditCompletedEventSchema,
15272
+ "quality.assessment.scored": QualityAssessmentScoredEventSchema,
15252
15273
  "quality.finding.opened": QualityFindingOpenedEventSchema,
15253
15274
  "quality.finding.resolved": QualityFindingResolvedEventSchema,
15254
15275
  "quality.finding.accepted": QualityFindingAcceptedEventSchema,
@@ -15271,6 +15292,7 @@ var KnownJournalEventSchema = external_exports.union([
15271
15292
  RefStatusChangedEventSchema,
15272
15293
  JournalBaselineEventSchema,
15273
15294
  QualityAuditCompletedEventSchema,
15295
+ QualityAssessmentScoredEventSchema,
15274
15296
  QualityFindingOpenedEventSchema,
15275
15297
  QualityFindingResolvedEventSchema,
15276
15298
  QualityFindingAcceptedEventSchema,
@@ -17202,7 +17224,8 @@ function auditCompletedInput(matrix, meta3) {
17202
17224
  framework_version: meta3.framework_version,
17203
17225
  ...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
17204
17226
  scores,
17205
- counts: matrix.finding_counts
17227
+ counts: matrix.finding_counts,
17228
+ ...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
17206
17229
  }
17207
17230
  };
17208
17231
  }
@@ -17334,6 +17357,10 @@ function sameFrameworkMajor(a, b) {
17334
17357
  const right = frameworkMajor(b);
17335
17358
  return left === null || right === null || left === right;
17336
17359
  }
17360
+ function scopeOf(raw) {
17361
+ if (!isRecord(raw) || typeof raw.since !== "string" || raw.since === "") return void 0;
17362
+ return { scope: { since: raw.since, cells: typeof raw.cells === "number" && Number.isFinite(raw.cells) ? raw.cells : null } };
17363
+ }
17337
17364
  function cleanScores(raw) {
17338
17365
  const scores = {};
17339
17366
  if (!isRecord(raw)) return scores;
@@ -17404,7 +17431,9 @@ function deriveQualityTrend(events, profile, live) {
17404
17431
  comparable: true,
17405
17432
  scores,
17406
17433
  overall,
17407
- counts: cleanCounts(event.counts)
17434
+ counts: cleanCounts(event.counts),
17435
+ ...event.baseline === true ? { baseline: true } : {},
17436
+ ...scopeOf(event.scope) ?? {}
17408
17437
  };
17409
17438
  byAudit.delete(auditId);
17410
17439
  byAudit.set(auditId, snapshot);
@@ -17460,7 +17489,9 @@ function trendRows(trend, filter = {}) {
17460
17489
  ...snapshot.commit !== void 0 ? { commit: snapshot.commit } : {},
17461
17490
  ...snapshot.framework_version !== void 0 ? { framework_version: snapshot.framework_version } : {},
17462
17491
  comparable: snapshot.comparable,
17463
- cells
17492
+ cells,
17493
+ ...snapshot.baseline ? { baseline: true } : {},
17494
+ ...snapshot.scope !== void 0 ? { scope: snapshot.scope } : {}
17464
17495
  });
17465
17496
  });
17466
17497
  return { surfaces, rows };
@@ -17472,6 +17503,207 @@ function formatDelta(delta) {
17472
17503
  return "=";
17473
17504
  }
17474
17505
 
17506
+ // ../schema/src/quality-scope.ts
17507
+ var rowsOf2 = (value) => Array.isArray(value) ? value : [];
17508
+ var isString = (value) => typeof value === "string" && value !== "";
17509
+ var stringsOf = (value) => rowsOf2(value).filter(isString);
17510
+ var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
17511
+ function recordedAuditIds(events) {
17512
+ const ids = [];
17513
+ for (const event of orderEvents(rowsOf2(events))) {
17514
+ if (event?.type !== "quality.audit.completed") continue;
17515
+ const id = event.audit_id;
17516
+ if (isString(id) && !ids.includes(id)) ids.push(id);
17517
+ }
17518
+ return ids;
17519
+ }
17520
+ function deriveAuditScope(events, section, library, options = {}) {
17521
+ const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
17522
+ let sinceIndex = -1;
17523
+ for (let i = ordered.length - 1; i >= 0; i--) {
17524
+ const event = ordered[i];
17525
+ if (event.type !== "quality.audit.completed") continue;
17526
+ const id = event.audit_id;
17527
+ if (options.since !== void 0 && id !== options.since) continue;
17528
+ sinceIndex = i;
17529
+ break;
17530
+ }
17531
+ const empty = {
17532
+ since: options.since ?? null,
17533
+ since_ts: null,
17534
+ cells: [],
17535
+ findings: [],
17536
+ resolved_by: {},
17537
+ unknown: [],
17538
+ unscorable: [],
17539
+ widened: 0
17540
+ };
17541
+ if (sinceIndex === -1) return empty;
17542
+ const anchor = ordered[sinceIndex];
17543
+ const anchorId = anchor.audit_id;
17544
+ const since = isString(anchorId) ? anchorId : null;
17545
+ const sinceTs = isString(anchor.ts) ? anchor.ts : null;
17546
+ const resolutions = /* @__PURE__ */ new Map();
17547
+ for (const event of ordered.slice(sinceIndex + 1)) {
17548
+ if (event.type !== "quality.finding.resolved") continue;
17549
+ const findingId = event.finding_id;
17550
+ if (!isString(findingId)) continue;
17551
+ const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
17552
+ const by = event.resolved_by;
17553
+ if (isString(by)) entry.resolved_by = by;
17554
+ for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
17555
+ resolutions.set(findingId, entry);
17556
+ }
17557
+ if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
17558
+ const findings = rowsOf2(section?.findings).filter(
17559
+ (finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
17560
+ );
17561
+ const findingById = /* @__PURE__ */ new Map();
17562
+ for (const finding of findings) findingById.set(finding.id, finding);
17563
+ const criterionById = /* @__PURE__ */ new Map();
17564
+ for (const criterion of rowsOf2(library?.criteria)) {
17565
+ if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
17566
+ }
17567
+ const assessmentByCell = /* @__PURE__ */ new Map();
17568
+ for (const assessment of rowsOf2(section?.assessments)) {
17569
+ if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
17570
+ assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
17571
+ }
17572
+ const declared = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
17573
+ const surfaces = declared.length > 0 ? [...new Set(declared)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
17574
+ const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
17575
+ const scorable = (criterionId, surface) => {
17576
+ const criterion = criterionById.get(criterionId);
17577
+ if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
17578
+ if (declared.length > 0 && !surfaces.includes(surface)) return false;
17579
+ return appliesTo(criterion, surface);
17580
+ };
17581
+ const cells = /* @__PURE__ */ new Map();
17582
+ const addDirect = (criterionId, surface, findingId) => {
17583
+ const key = cellKey2(criterionId, surface);
17584
+ const existing = cells.get(key);
17585
+ if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
17586
+ else if (!existing.because.includes(findingId)) existing.because.push(findingId);
17587
+ };
17588
+ const drivers = [];
17589
+ const unknown2 = [];
17590
+ const unscorable = [];
17591
+ const resolvedBy = {};
17592
+ const resolvedNodes = /* @__PURE__ */ new Set();
17593
+ for (const [findingId, resolution] of resolutions) {
17594
+ const finding = findingById.get(findingId);
17595
+ if (finding === void 0) {
17596
+ unknown2.push(findingId);
17597
+ continue;
17598
+ }
17599
+ if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
17600
+ const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
17601
+ (surface) => scorable(finding.criterion_id, surface)
17602
+ );
17603
+ for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
17604
+ for (const node of resolution.node_ids) resolvedNodes.add(node);
17605
+ if (targets.length === 0) {
17606
+ unscorable.push(findingId);
17607
+ continue;
17608
+ }
17609
+ drivers.push(findingId);
17610
+ if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
17611
+ for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
17612
+ }
17613
+ let widened = 0;
17614
+ if (options.widen !== false && resolvedNodes.size > 0) {
17615
+ const nodesByCell = /* @__PURE__ */ new Map();
17616
+ const noteNodes = (criterionId, surface, nodes) => {
17617
+ const key = cellKey2(criterionId, surface);
17618
+ const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
17619
+ for (const node of nodes) bucket.add(node);
17620
+ nodesByCell.set(key, bucket);
17621
+ };
17622
+ for (const finding of findings) {
17623
+ const nodes = stringsOf(finding.node_ids);
17624
+ if (nodes.length === 0) continue;
17625
+ if (finding.surface === CROSS_SURFACE_ID) {
17626
+ for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
17627
+ } else {
17628
+ noteNodes(finding.criterion_id, finding.surface, nodes);
17629
+ }
17630
+ }
17631
+ for (const [key, assessment] of assessmentByCell) {
17632
+ if (cells.has(key)) continue;
17633
+ if (!criterionById.has(assessment.criterion_id)) continue;
17634
+ if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
17635
+ const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
17636
+ if (shared.length === 0) continue;
17637
+ cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
17638
+ widened++;
17639
+ }
17640
+ }
17641
+ for (const [key, cell] of cells) {
17642
+ const assessment = assessmentByCell.get(key);
17643
+ if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
17644
+ cell.current = { level: assessment.level, audit_id: assessment.audit_id };
17645
+ }
17646
+ }
17647
+ const column = (surface) => {
17648
+ const at2 = surfaces.indexOf(surface);
17649
+ return at2 === -1 ? surfaces.length : at2;
17650
+ };
17651
+ const sorted = [...cells.values()].sort(
17652
+ (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)
17653
+ );
17654
+ return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
17655
+ }
17656
+ function scopedAuditId(input) {
17657
+ const { since, month, requested, known, recorded, open } = input;
17658
+ const newest = [...known].sort().at(-1);
17659
+ if (requested !== void 0) {
17660
+ if (requested === since) {
17661
+ throw new Error(
17662
+ `"${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.`
17663
+ );
17664
+ }
17665
+ if (recorded.includes(requested)) {
17666
+ throw new Error(`"${requested}" is already recorded \u2014 its reading is history. Name a new audit.`);
17667
+ }
17668
+ if (newest !== void 0 && requested < newest) {
17669
+ throw new Error(
17670
+ `"${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)}\`).`
17671
+ );
17672
+ }
17673
+ return requested;
17674
+ }
17675
+ if (open !== void 0 && (newest === void 0 || open >= newest)) return open;
17676
+ for (const candidate of scopedCandidates(month)) {
17677
+ if (known.includes(candidate)) continue;
17678
+ if (newest !== void 0 && candidate < newest) {
17679
+ throw new Error(
17680
+ `"${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)}\`).`
17681
+ );
17682
+ }
17683
+ return candidate;
17684
+ }
17685
+ throw new Error(`99 scoped audits in ${month} \u2014 name the next one yourself.`);
17686
+ }
17687
+ function* scopedCandidates(month) {
17688
+ for (let n = 1; n < 100; n++) yield n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
17689
+ }
17690
+ function suggestedAuditId({ since, month, requested, known, recorded }) {
17691
+ const taken = /* @__PURE__ */ new Set([...known, ...recorded, since, ...requested !== void 0 ? [requested] : []]);
17692
+ const floor = [...taken].sort().at(-1);
17693
+ for (const candidate of scopedCandidates(month)) {
17694
+ if (taken.has(candidate)) continue;
17695
+ if (floor === void 0 || candidate > floor) return candidate;
17696
+ }
17697
+ return `${floor}-scoped`;
17698
+ }
17699
+ function scopeSummary(scope) {
17700
+ const direct = scope.cells.length - scope.widened;
17701
+ const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
17702
+ const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
17703
+ const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
17704
+ return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
17705
+ }
17706
+
17475
17707
  // src/commands/init.ts
17476
17708
  var DEFAULT_BUNDLE_PATH = "docs/arkaik/bundle.json";
17477
17709
  var DEFAULT_JOURNAL_PATH = "docs/arkaik/journal.jsonl";
@@ -18957,6 +19189,14 @@ function loadCurrentQualitySection(root, library) {
18957
19189
  if (auditIds.length === 0) return void 0;
18958
19190
  const profile = loadProfile(root);
18959
19191
  if (!profile) return void 0;
19192
+ return mergeAudits(root, auditIds, library, profile);
19193
+ }
19194
+ function loadQualitySectionThrough(root, auditId, library) {
19195
+ requireAudit(root, auditId);
19196
+ const auditIds = listAuditIds(root);
19197
+ return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
19198
+ }
19199
+ function mergeAudits(root, auditIds, library, profile) {
18960
19200
  const cells = /* @__PURE__ */ new Map();
18961
19201
  const findings = [];
18962
19202
  let frameworkVersion;
@@ -18976,6 +19216,32 @@ function loadCurrentQualitySection(root, library) {
18976
19216
  findings
18977
19217
  };
18978
19218
  }
19219
+ function scopedAuditTarget(root, since, month, requested, recorded = []) {
19220
+ const known = listAuditIds(root);
19221
+ const newest = known[known.length - 1];
19222
+ const open = newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since ? newest : void 0;
19223
+ return scopedAuditId({ since, month, requested, known, recorded, open });
19224
+ }
19225
+ function declaredScopeSince(auditId, recorded) {
19226
+ if (recorded.includes(auditId)) {
19227
+ throw new Error(
19228
+ `"${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.`
19229
+ );
19230
+ }
19231
+ const before = recorded.filter((id) => id < auditId).sort();
19232
+ const since = before[before.length - 1];
19233
+ if (since === void 0) {
19234
+ throw new Error(
19235
+ `no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
19236
+ );
19237
+ }
19238
+ return since;
19239
+ }
19240
+ function auditOrderNote(root, auditId) {
19241
+ const later = listAuditIds(root).filter((id) => id > auditId);
19242
+ if (later.length === 0) return void 0;
19243
+ 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.`;
19244
+ }
18979
19245
  function loadAuditQualitySection(root, auditId, library) {
18980
19246
  requireAudit(root, auditId);
18981
19247
  const section = loadQualitySection(root, auditId, library, loadScoresOrEmpty(root, auditId));
@@ -21867,6 +22133,7 @@ Subcommands:
21867
22133
  signals The signal pack, and what has tripped since the last audit.
21868
22134
  regressions What got worse between two audits.
21869
22135
  trend Every recorded audit's scores, and which way each moved.
22136
+ scope The cells your resolved findings made stale since the last audit.
21870
22137
  issue <criterion> Print the prefilled GitHub issue skeleton.
21871
22138
  criterion add ... Add a project-specific criterion to the overlay.
21872
22139
 
@@ -21894,6 +22161,10 @@ Options:
21894
22161
  Required: a score without a citation is an opinion.
21895
22162
  --audit <id> The audit run (default: the newest, or the current YYYY-MM).
21896
22163
  --commit <sha> The commit the evidence is pinned to.
22164
+ --scope This is a scoped re-audit: refuse a cell \`arkaik kritik scope\`
22165
+ does not list, and write into a scoped audit of its own
22166
+ (default <YYYY-MM>-scoped, never the audit it was scoped
22167
+ from). Leave it off to re-score an out-of-scope cell on purpose.
21897
22168
 
21898
22169
  Writes docs/quality/audits/<id>/scores.json`;
21899
22170
  var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
@@ -21917,7 +22188,7 @@ var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
21917
22188
  Records it as a known, owned risk. The note is required \u2014 an accepted risk is a
21918
22189
  decision and reads like one. No journal event: acceptance is a state of the
21919
22190
  finding, not something that happened to the product.`;
21920
- var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record]
22191
+ var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record] [--scope]
21921
22192
 
21922
22193
  Roll one audit up into its comparative matrix and write matrix.json \u2014 the only
21923
22194
  thing that may write that file.
@@ -21925,7 +22196,14 @@ thing that may write that file.
21925
22196
  audit-id The audit under docs/quality/audits/ (default: the newest).
21926
22197
  --json Print matrix.json instead of the markdown table.
21927
22198
  --record Also append quality.audit.completed, carrying these scores
21928
- and counts. Do this once per finished audit.`;
22199
+ and counts. Do this once per finished audit.
22200
+ --scope Treat the audit as a scoped re-audit even though it was
22201
+ scored without \`score --scope\` (which marks it for you).
22202
+
22203
+ A scoped re-audit holds only the cells it re-scored, so matrix.json shows just
22204
+ those ("how did this audit go"), while --record carries the merged matrix
22205
+ through this audit ("where does the product stand") \u2014 the reading the trend
22206
+ replays. Everything else keeps its last score.`;
21929
22207
  var SIGNALS_USAGE = `arkaik kritik signals [--surface <s>] [--criterion <c>] [--domain <CODE>] [--json]
21930
22208
  arkaik kritik signals --trip <criterion> --surface <s> --signal <index|text> [--detail <d>]
21931
22209
 
@@ -21944,8 +22222,10 @@ var REGRESSIONS_USAGE = `arkaik kritik regressions [--from <audit>] [--to <audit
21944
22222
 
21945
22223
  What got worse between two audits: a cell whose maturity dropped, a cell that
21946
22224
  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.
22225
+ again. Each side is every audit through it, merged latest-wins \u2014 so a scoped
22226
+ re-audit's cells are compared with their last reading, wherever it was taken.
22227
+ Cells with no reading on one side are not compared \u2014 a half-finished audit is
22228
+ not a regression.
21949
22229
 
21950
22230
  Exits 1 when anything regressed, which is what makes it usable as a CI step or a
21951
22231
  scheduled routine.
@@ -21969,6 +22249,27 @@ Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.js
21969
22249
  and audits recorded with \`arkaik kritik matrix --record\`. A framework major
21970
22250
  bump between two audits breaks the comparison there (SPEC \xA7 8): the row still
21971
22251
  prints, without an arrow.`;
22252
+ var SCOPE_USAGE = `arkaik kritik scope [--since <audit>] [--no-widen] [--json]
22253
+
22254
+ The cells a batch of fixes made stale. A score is an assessment, so closing
22255
+ findings moves nothing until the cells they lived on are re-scored \u2014 and a
22256
+ comprehensive audit is a lot of audit for twenty fixes. Every finding resolved
22257
+ since the last recorded audit names its (criterion x surface) cell; one hop
22258
+ over node_ids adds the neighbours a fix in a shared view plausibly moved.
22259
+
22260
+ This is a work list, not a score: re-score each cell with evidence
22261
+ (\`arkaik kritik score \u2026 --scope\`, which writes into an audit of its own,
22262
+ <YYYY-MM>-scoped, and refuses a cell this list does not hold), then
22263
+ \`arkaik kritik matrix --record\`. Every other cell keeps its last score.
22264
+ Recording closes the window: a cell left unscored drops out of the next scope.
22265
+
22266
+ --since <audit> Measure from this recorded audit (default: the newest
22267
+ quality.audit.completed in the journal).
22268
+ --no-widen Only the resolved findings' own cells, no neighbours.
22269
+ --json The scope as JSON (what an agent should read).
22270
+
22271
+ Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.json)
22272
+ and an audit recorded with \`arkaik kritik matrix --record\` to measure from.`;
21972
22273
  var ISSUE_USAGE = `arkaik kritik issue <criterion> --surface <s> [--level <n>] [--finding <id>]
21973
22274
 
21974
22275
  Print the criterion's GitHub issue skeleton, filled as far as what we know
@@ -22191,7 +22492,7 @@ Pass --force if that is genuinely what you want.`
22191
22492
  process.exit(0);
22192
22493
  }
22193
22494
  function runScore(args, common) {
22194
- const { single, flags, positionals } = collect(args);
22495
+ const { single, flags, positionals } = collect(args, [], ["scope"]);
22195
22496
  if (flags.has("help")) {
22196
22497
  console.log(SCORE_USAGE);
22197
22498
  process.exit(0);
@@ -22220,7 +22521,39 @@ Scoring it there would produce a cell nothing rolls up.`
22220
22521
  ${SCORE_USAGE}`);
22221
22522
  }
22222
22523
  const evidence = textOrFile(single.evidence);
22223
- const auditId = auditForWrite(common.root, single.audit);
22524
+ let scopedFrom;
22525
+ let auditId;
22526
+ if (flags.has("scope")) {
22527
+ const { scope, recorded } = currentScope(common, library, profile);
22528
+ if (scope.since === null) {
22529
+ fail12(`kritik: --scope needs a recorded audit to measure from \u2014 \`arkaik kritik matrix --record\` writes one.`);
22530
+ }
22531
+ if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
22532
+ fail12(
22533
+ `kritik: ${criterionId} x ${surface} is not in the current scope (${scopeSummary(scope)}).
22534
+ \`arkaik kritik scope\` lists the cells; drop --scope to re-score this one on purpose.`
22535
+ );
22536
+ }
22537
+ try {
22538
+ auditId = scopedAuditTarget(common.root, scope.since, currentAuditId(), single.audit, recorded);
22539
+ } catch (error51) {
22540
+ return fail12(`kritik: ${error51.message} Pass it with --audit <id>.`);
22541
+ }
22542
+ scopedFrom = scope.since;
22543
+ } else {
22544
+ auditId = auditForWrite(common.root, single.audit);
22545
+ }
22546
+ const notes = [];
22547
+ if (scopedFrom === void 0) {
22548
+ const journal = resolveJournal(common.root, common.bundlePath);
22549
+ if (journal.present && recordedAuditIds(readFullJournalEvents(journal.journalPath)).includes(auditId)) {
22550
+ notes.push(
22551
+ `${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.`
22552
+ );
22553
+ }
22554
+ const order = auditOrderNote(common.root, auditId);
22555
+ if (order !== void 0) notes.push(order);
22556
+ }
22224
22557
  const file2 = loadScoresOrEmpty(common.root, auditId);
22225
22558
  const assessment = {
22226
22559
  criterion_id: criterionId,
@@ -22237,14 +22570,17 @@ ${SCORE_USAGE}`);
22237
22570
  audit_id: auditId,
22238
22571
  framework_version: file2.framework_version ?? library.version,
22239
22572
  ...single.commit !== void 0 ? { commit: single.commit } : {},
22573
+ ...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
22240
22574
  assessments
22241
22575
  });
22242
22576
  const anchor = criterion.level_anchors?.[`l${level}`];
22243
22577
  console.log(
22244
22578
  `
22245
22579
  ${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)}`
22580
+ ${assessments.length} assessment${assessments.length === 1 ? "" : "s"} in ${auditId} -> ${scoresPath(common.root, auditId)}` + (scopedFrom !== void 0 ? `
22581
+ scoped re-audit since ${scopedFrom} \u2014 every cell it does not re-score keeps its last score` : "")
22247
22582
  );
22583
+ for (const note of notes) console.log(` note: ${note}`);
22248
22584
  if (level < DEFAULT_TARGET_LEVEL) {
22249
22585
  console.log(
22250
22586
  ` 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 +22737,31 @@ ${FINDING_USAGE}`);
22401
22737
  );
22402
22738
  process.exit(0);
22403
22739
  }
22740
+ function scopedSince(common, auditId, stamped, declared) {
22741
+ if (stamped !== void 0) return stamped;
22742
+ if (!declared) return void 0;
22743
+ const journal = resolveJournal(common.root, common.bundlePath);
22744
+ if (!journal.present) {
22745
+ fail12(`kritik: --scope needs the audit this one was scoped from, and there is no journal at ${journal.bundlePath}.`);
22746
+ }
22747
+ try {
22748
+ return declaredScopeSince(auditId, recordedAuditIds(readFullJournalEvents(journal.journalPath)));
22749
+ } catch (error51) {
22750
+ return fail12(`kritik: --scope refused \u2014 ${error51.message}`);
22751
+ }
22752
+ }
22753
+ function unscoredScopeCells(common, library, since, assessed) {
22754
+ const journal = resolveJournal(common.root, common.bundlePath);
22755
+ const profile = loadProfile(common.root);
22756
+ if (!journal.present || !profile) return [];
22757
+ const section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
22758
+ const scope = deriveAuditScope(readFullJournalEvents(journal.journalPath), section, library);
22759
+ if (scope.since !== since) return [];
22760
+ const done = new Set(assessed.map((a) => `${a.criterion_id}::${a.surface}`));
22761
+ return scope.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`));
22762
+ }
22404
22763
  function runMatrix(args, common) {
22405
- const { flags, positionals } = collect(args, [], ["json", "record"]);
22764
+ const { flags, positionals } = collect(args, [], ["json", "record", "scope"]);
22406
22765
  if (flags.has("help")) {
22407
22766
  console.log(MATRIX_USAGE);
22408
22767
  process.exit(0);
@@ -22421,8 +22780,21 @@ function runMatrix(args, common) {
22421
22780
  return fail12(`kritik: ${error51.message}`);
22422
22781
  }
22423
22782
  const { section, matrix, file: file2 } = computed;
22783
+ const since = scopedSince(common, auditId, loadScoresOrEmpty(common.root, auditId).scope?.since, flags.has("scope"));
22784
+ const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
22785
+ const unscored = scope !== void 0 ? unscoredScopeCells(common, library, scope.since, section.assessments) : [];
22786
+ const reportUnscored = (log) => {
22787
+ if (unscored.length === 0) return;
22788
+ log(
22789
+ flags.has("record") ? `
22790
+ ! ${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\`:` : `
22791
+ ${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):`
22792
+ );
22793
+ for (const cell of unscored) log(` ${cell.surface} \xB7 ${cell.criterion_id} (${cell.kind})`);
22794
+ };
22424
22795
  if (flags.has("json")) {
22425
22796
  console.log(JSON.stringify(file2, null, 2));
22797
+ reportUnscored((line2) => console.error(line2));
22426
22798
  } else {
22427
22799
  const domainNames = new Map((library.domains ?? []).map((d) => [d.code, d.name]));
22428
22800
  console.log(`
@@ -22446,11 +22818,33 @@ P0 \u2014 fix first:`);
22446
22818
  }
22447
22819
  console.log(`
22448
22820
  wrote ${matrixPath(common.root, auditId)}`);
22821
+ if (scope !== void 0) {
22822
+ reportUnscored((line2) => console.log(line2));
22823
+ console.log(
22824
+ `
22825
+ 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.`
22826
+ );
22827
+ }
22449
22828
  }
22450
22829
  if (flags.has("record")) {
22830
+ let recorded = matrix;
22831
+ if (scope !== void 0) {
22832
+ try {
22833
+ recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(common.root, auditId, library) }, library);
22834
+ } catch (error51) {
22835
+ return fail12(`kritik: ${error51.message}`);
22836
+ }
22837
+ }
22451
22838
  reportJournal(
22452
22839
  common.root,
22453
- [auditCompletedInput(matrix, { audit_id: auditId, framework_version: file2.framework_version, ...file2.commit !== void 0 ? { commit: file2.commit } : {} })],
22840
+ [
22841
+ auditCompletedInput(recorded, {
22842
+ audit_id: auditId,
22843
+ framework_version: file2.framework_version,
22844
+ ...file2.commit !== void 0 ? { commit: file2.commit } : {},
22845
+ ...scope !== void 0 ? { scope } : {}
22846
+ })
22847
+ ],
22454
22848
  common
22455
22849
  );
22456
22850
  }
@@ -22576,8 +22970,8 @@ function runRegressions(args, common) {
22576
22970
  let regressions;
22577
22971
  try {
22578
22972
  regressions = detectRegressions(
22579
- loadQualitySection(common.root, from, library),
22580
- loadQualitySection(common.root, to, library),
22973
+ loadQualitySectionThrough(common.root, from, library),
22974
+ loadQualitySectionThrough(common.root, to, library),
22581
22975
  library
22582
22976
  );
22583
22977
  } catch (error51) {
@@ -22672,6 +23066,12 @@ function runTrend(args, common) {
22672
23066
  if (!row.comparable) {
22673
23067
  console.log(` ${"".padEnd(widths[0])} framework ${row.framework_version ?? "?"} \u2014 not comparable to the audit above`);
22674
23068
  }
23069
+ if (row.baseline) {
23070
+ console.log(` ${"".padEnd(widths[0])} baseline \u2014 rebuilt from a restored audit's stored scores`);
23071
+ }
23072
+ if (row.scope) {
23073
+ console.log(` ${"".padEnd(widths[0])} scoped re-audit of ${row.scope.cells ?? "?"} cell(s) since ${row.scope.since}`);
23074
+ }
22675
23075
  }
22676
23076
  console.log(
22677
23077
  `
@@ -22680,6 +23080,95 @@ function runTrend(args, common) {
22680
23080
  );
22681
23081
  process.exit(0);
22682
23082
  }
23083
+ function scopeReason(cell, resolvedBy) {
23084
+ if (cell.kind === "widened") return `widened via ${cell.because.join(", ")}`;
23085
+ const findings = cell.because.map((id) => resolvedBy[id] !== void 0 ? `${id} (resolved by ${resolvedBy[id]})` : id);
23086
+ return `because ${findings.join(", ")}`;
23087
+ }
23088
+ function currentScope(common, library, profile, options = {}) {
23089
+ const journal = resolveJournal(common.root, common.bundlePath);
23090
+ if (!journal.present) {
23091
+ fail12(
23092
+ `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.`
23093
+ );
23094
+ }
23095
+ const events = readFullJournalEvents(journal.journalPath);
23096
+ const recorded = recordedAuditIds(events);
23097
+ if (options.since !== void 0) {
23098
+ if (!recorded.includes(options.since)) {
23099
+ fail12(
23100
+ `kritik: no recorded audit "${options.since}" in ${journal.journalPath} (recorded: ${recorded.join(", ") || "none \u2014 `arkaik kritik matrix --record` writes one"}).
23101
+ A scope is measured from a recorded reading; an audit directory that was never recorded is not one.`
23102
+ );
23103
+ }
23104
+ }
23105
+ let section;
23106
+ try {
23107
+ section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
23108
+ } catch (error51) {
23109
+ return fail12(`kritik: ${error51.message}`);
23110
+ }
23111
+ return { scope: deriveAuditScope(events, section, library, options), journalPath: journal.journalPath, recorded };
23112
+ }
23113
+ function runScope(args, common) {
23114
+ const { single, flags } = collect(args, [], ["json", "no-widen"]);
23115
+ if (flags.has("help")) {
23116
+ console.log(SCOPE_USAGE);
23117
+ process.exit(0);
23118
+ }
23119
+ const library = loadLibraryOrFail(common.root);
23120
+ const profile = profileOrFail(common.root);
23121
+ const { scope } = currentScope(common, library, profile, {
23122
+ ...single.since !== void 0 ? { since: single.since } : {},
23123
+ widen: !flags.has("no-widen")
23124
+ });
23125
+ if (flags.has("json")) {
23126
+ console.log(JSON.stringify({ ...scope, summary: scopeSummary(scope) }, null, 2));
23127
+ process.exit(0);
23128
+ }
23129
+ if (scope.since === null) {
23130
+ console.log(
23131
+ `
23132
+ no recorded audit yet \u2014 a scope is measured from one. \`arkaik kritik matrix --record\` writes it.
23133
+ `
23134
+ );
23135
+ process.exit(0);
23136
+ }
23137
+ console.log("");
23138
+ let surface = "";
23139
+ for (const cell of scope.cells) {
23140
+ if (cell.surface !== surface) {
23141
+ if (surface !== "") console.log("");
23142
+ surface = cell.surface;
23143
+ }
23144
+ const current = cell.current !== void 0 ? `at ${cell.current.level} (${cell.current.audit_id})` : "unscored";
23145
+ console.log(` ${cell.surface} \xB7 ${cell.criterion_id} \xB7 ${current} \xB7 ${scopeReason(cell, scope.resolved_by)}`);
23146
+ }
23147
+ if (scope.cells.length > 0) console.log("");
23148
+ console.log(` ${scopeSummary(scope)}`);
23149
+ if (scope.unknown.length > 0) {
23150
+ console.log(
23151
+ `
23152
+ ! ${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:`
23153
+ );
23154
+ for (const id of scope.unknown) console.log(` ${id}`);
23155
+ }
23156
+ if (scope.unscorable.length > 0) {
23157
+ console.log(
23158
+ `
23159
+ ! ${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:`
23160
+ );
23161
+ for (const id of scope.unscorable) console.log(` ${id}`);
23162
+ }
23163
+ if (scope.cells.length > 0) {
23164
+ console.log(
23165
+ `
23166
+ 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.`
23167
+ );
23168
+ }
23169
+ console.log("");
23170
+ process.exit(0);
23171
+ }
22683
23172
  function runIssue(args, common) {
22684
23173
  const { single, flags, positionals } = collect(args);
22685
23174
  if (flags.has("help")) {
@@ -22823,6 +23312,8 @@ function runKritik(args) {
22823
23312
  return runRegressions(subArgs, common);
22824
23313
  case "trend":
22825
23314
  return runTrend(subArgs, common);
23315
+ case "scope":
23316
+ return runScope(subArgs, common);
22826
23317
  case "issue":
22827
23318
  return runIssue(subArgs, common);
22828
23319
  case "criterion":
@@ -22862,7 +23353,7 @@ Options:
22862
23353
  -v, --version Print the version.
22863
23354
 
22864
23355
  Run "arkaik <command> --help" for command-specific help.`;
22865
- var VERSION = "0.5.0";
23356
+ var VERSION = "0.7.0";
22866
23357
  function main(argv) {
22867
23358
  const [command, ...rest] = argv;
22868
23359
  if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
package/dist/io.js CHANGED
@@ -15182,7 +15182,27 @@ 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()
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()
15192
+ }).catchall(external_exports.unknown()).optional(),
15193
+ // A reading synthesized from a stored audit that arrived without one (issue #472).
15194
+ baseline: external_exports.boolean().optional()
15195
+ }).catchall(external_exports.unknown());
15196
+ var QualityAssessmentScoredEventSchema = external_exports.object({
15197
+ ...envelope,
15198
+ type: external_exports.literal("quality.assessment.scored"),
15199
+ audit_id: external_exports.string(),
15200
+ criterion_id: external_exports.string(),
15201
+ surface: external_exports.string(),
15202
+ level: external_exports.number().int().min(0).max(4),
15203
+ evidence: external_exports.string(),
15204
+ commit: external_exports.string().optional(),
15205
+ scope: external_exports.object({ since: external_exports.string().optional() }).catchall(external_exports.unknown()).optional()
15186
15206
  }).catchall(external_exports.unknown());
15187
15207
  var QualityFindingOpenedEventSchema = external_exports.object({
15188
15208
  ...envelope,
@@ -15236,6 +15256,7 @@ var JOURNAL_EVENT_SCHEMAS = {
15236
15256
  "ref.status_changed": RefStatusChangedEventSchema,
15237
15257
  "journal.baseline": JournalBaselineEventSchema,
15238
15258
  "quality.audit.completed": QualityAuditCompletedEventSchema,
15259
+ "quality.assessment.scored": QualityAssessmentScoredEventSchema,
15239
15260
  "quality.finding.opened": QualityFindingOpenedEventSchema,
15240
15261
  "quality.finding.resolved": QualityFindingResolvedEventSchema,
15241
15262
  "quality.finding.accepted": QualityFindingAcceptedEventSchema,
@@ -15258,6 +15279,7 @@ var KnownJournalEventSchema = external_exports.union([
15258
15279
  RefStatusChangedEventSchema,
15259
15280
  JournalBaselineEventSchema,
15260
15281
  QualityAuditCompletedEventSchema,
15282
+ QualityAssessmentScoredEventSchema,
15261
15283
  QualityFindingOpenedEventSchema,
15262
15284
  QualityFindingResolvedEventSchema,
15263
15285
  QualityFindingAcceptedEventSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkaik",
3
- "version": "0.5.0",
3
+ "version": "0.7.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",