arkaik 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +260 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -17704,6 +17704,167 @@ function scopeSummary(scope) {
17704
17704
  return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
17705
17705
  }
17706
17706
 
17707
+ // ../schema/src/quality-burndown.ts
17708
+ var EVENT_CAUSE = {
17709
+ "quality.finding.opened": "opened",
17710
+ "quality.finding.resolved": "resolved",
17711
+ "quality.finding.accepted": "accepted",
17712
+ "quality.audit.completed": "audit"
17713
+ };
17714
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17715
+ var isString2 = (value) => typeof value === "string" && value !== "";
17716
+ var emptyCounts = () => ({ critical: 0, high: 0, medium: 0, low: 0, info: 0 });
17717
+ var asSeverity = (value) => typeof value === "string" && FINDING_SEVERITIES.includes(value) ? value : null;
17718
+ function cleanCounts2(raw) {
17719
+ const counts = emptyCounts();
17720
+ if (!isRecord2(raw)) return counts;
17721
+ for (const severity of FINDING_SEVERITIES) {
17722
+ const value = raw[severity];
17723
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) counts[severity] = value;
17724
+ }
17725
+ return counts;
17726
+ }
17727
+ function openTotal(open) {
17728
+ return FINDING_SEVERITIES.reduce((sum, severity) => sum + (open[severity] ?? 0), 0);
17729
+ }
17730
+ function deriveFindingsBurndown(events, options = {}) {
17731
+ const { surface, domain: domain2, library } = options;
17732
+ const filtered = surface !== void 0 || domain2 !== void 0;
17733
+ const sectionById = /* @__PURE__ */ new Map();
17734
+ for (const finding of Array.isArray(options.findings) ? options.findings : []) {
17735
+ if (isRecord2(finding) && isString2(finding.id)) sectionById.set(finding.id, finding);
17736
+ }
17737
+ const inView = (where) => {
17738
+ if (!filtered) return true;
17739
+ if (where === void 0) return false;
17740
+ if (surface !== void 0 && where.surface !== surface) return false;
17741
+ if (domain2 !== void 0 && (!isString2(where.criterion_id) || domainCodeOf(where.criterion_id, library) !== domain2)) {
17742
+ return false;
17743
+ }
17744
+ return true;
17745
+ };
17746
+ const relevant = (Array.isArray(events) ? events : []).filter(
17747
+ (event) => isRecord2(event) && typeof event.type === "string" && event.type in EVENT_CAUSE
17748
+ );
17749
+ const openedIds = /* @__PURE__ */ new Set();
17750
+ const decidedIds = /* @__PURE__ */ new Set();
17751
+ for (const event of relevant) {
17752
+ if (!isString2(event.finding_id)) continue;
17753
+ if (event.type === "quality.finding.opened") openedIds.add(event.finding_id);
17754
+ else if (event.type !== "quality.audit.completed") decidedIds.add(event.finding_id);
17755
+ }
17756
+ const seedable = (id, finding) => {
17757
+ if (openedIds.has(id) || !inView(finding)) return false;
17758
+ if (finding.status === "open") return true;
17759
+ return (finding.status === "resolved" || finding.status === "accepted-risk") && decidedIds.has(id);
17760
+ };
17761
+ const tracked = /* @__PURE__ */ new Map();
17762
+ const open = emptyCounts();
17763
+ const points = [];
17764
+ const totals = { opened: 0, resolved: 0, accepted: 0 };
17765
+ let since = null;
17766
+ let seeded = false;
17767
+ const bump = (severity, by) => {
17768
+ if (severity !== null) open[severity] = Math.max(0, open[severity] + by);
17769
+ };
17770
+ const mark = (event, type, id) => {
17771
+ points.push({ ts: typeof event.ts === "string" ? event.ts : "", open: { ...open }, cause: { type, id } });
17772
+ };
17773
+ const count = (type) => {
17774
+ totals[type]++;
17775
+ if (since !== null) since[type]++;
17776
+ };
17777
+ for (const event of orderEvents(relevant)) {
17778
+ const type = EVENT_CAUSE[event.type];
17779
+ if (type === "audit") {
17780
+ if (!seeded) {
17781
+ seeded = true;
17782
+ for (const [id2, finding] of sectionById) {
17783
+ if (tracked.has(id2) || !seedable(id2, finding)) continue;
17784
+ const severity = severityOf(finding, library);
17785
+ tracked.set(id2, { severity, open: true, surface: finding.surface, criterion_id: finding.criterion_id });
17786
+ bump(severity, 1);
17787
+ }
17788
+ }
17789
+ if (!filtered) Object.assign(open, cleanCounts2(event.counts));
17790
+ const auditId = isString2(event.audit_id) ? event.audit_id : isString2(event.id) ? event.id : "";
17791
+ since = { audit_id: auditId, ts: typeof event.ts === "string" ? event.ts : "", opened: 0, resolved: 0, accepted: 0 };
17792
+ mark(event, "audit", auditId);
17793
+ continue;
17794
+ }
17795
+ const id = event.finding_id;
17796
+ if (!isString2(id)) continue;
17797
+ const known = tracked.get(id);
17798
+ if (type === "opened") {
17799
+ if (known?.open) continue;
17800
+ if (!inView(event)) continue;
17801
+ const severity = asSeverity(event.severity);
17802
+ tracked.set(id, {
17803
+ severity,
17804
+ open: true,
17805
+ ...typeof event.surface === "string" ? { surface: event.surface } : {},
17806
+ ...typeof event.criterion_id === "string" ? { criterion_id: event.criterion_id } : {}
17807
+ });
17808
+ bump(severity, 1);
17809
+ count("opened");
17810
+ mark(event, "opened", id);
17811
+ continue;
17812
+ }
17813
+ if (known !== void 0) {
17814
+ if (!known.open) continue;
17815
+ known.open = false;
17816
+ bump(known.severity, -1);
17817
+ } else {
17818
+ const fromSection = sectionById.get(id);
17819
+ if (!inView(fromSection)) continue;
17820
+ tracked.set(id, {
17821
+ severity: null,
17822
+ open: false,
17823
+ ...fromSection ? { surface: fromSection.surface, criterion_id: fromSection.criterion_id } : {}
17824
+ });
17825
+ }
17826
+ count(type);
17827
+ mark(event, type, id);
17828
+ }
17829
+ return { points, ...totals, since };
17830
+ }
17831
+ function burndownRows(burndown) {
17832
+ const { points, since } = burndown;
17833
+ if (points.length === 0) return { reference: null, rows: [] };
17834
+ let referenceIndex = 0;
17835
+ if (since !== null) {
17836
+ for (let index = points.length - 1; index >= 0; index--) {
17837
+ if (points[index].cause.type === "audit") {
17838
+ referenceIndex = index;
17839
+ break;
17840
+ }
17841
+ }
17842
+ }
17843
+ const reference = points[referenceIndex];
17844
+ const last = points[points.length - 1];
17845
+ return {
17846
+ reference: {
17847
+ kind: since !== null ? "audit" : "start",
17848
+ id: reference.cause.id,
17849
+ ts: reference.ts
17850
+ },
17851
+ rows: FINDING_SEVERITIES.map((severity) => ({
17852
+ severity,
17853
+ at_reference: reference.open[severity],
17854
+ now: last.open[severity],
17855
+ change: last.open[severity] - reference.open[severity]
17856
+ }))
17857
+ };
17858
+ }
17859
+ function burndownSummary(burndown, openNow) {
17860
+ if (burndown.points.length === 0) return null;
17861
+ const tally = burndown.since ?? burndown;
17862
+ const closed = tally.resolved + tally.accepted;
17863
+ const where = burndown.since ? ` since the ${burndown.since.audit_id} audit` : "";
17864
+ const open = openNow ?? openTotal(burndown.points[burndown.points.length - 1].open);
17865
+ return `${closed} closed${where} (${tally.resolved} resolved, ${tally.accepted} accepted) \xB7 ${tally.opened} opened \xB7 ${open} open`;
17866
+ }
17867
+
17707
17868
  // src/commands/init.ts
17708
17869
  var DEFAULT_BUNDLE_PATH = "docs/arkaik/bundle.json";
17709
17870
  var DEFAULT_JOURNAL_PATH = "docs/arkaik/journal.jsonl";
@@ -22133,6 +22294,7 @@ Subcommands:
22133
22294
  signals The signal pack, and what has tripped since the last audit.
22134
22295
  regressions What got worse between two audits.
22135
22296
  trend Every recorded audit's scores, and which way each moved.
22297
+ burndown Open findings over time, and what closed since the last audit.
22136
22298
  scope The cells your resolved findings made stale since the last audit.
22137
22299
  issue <criterion> Print the prefilled GitHub issue skeleton.
22138
22300
  criterion add ... Add a project-specific criterion to the overlay.
@@ -22249,6 +22411,21 @@ Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.js
22249
22411
  and audits recorded with \`arkaik kritik matrix --record\`. A framework major
22250
22412
  bump between two audits breaks the comparison there (SPEC \xA7 8): the row still
22251
22413
  prints, without an arrow.`;
22414
+ var BURNDOWN_USAGE = `arkaik kritik burndown [--surface <s>] [--domain <CODE>] [--json]
22415
+
22416
+ How many findings closed since the last recorded audit, and how many are open
22417
+ by severity then and now. The findings, not the score: a score only moves when
22418
+ its cell is re-scored, and this moves the day a finding closes.
22419
+
22420
+ --surface <s> Only findings on that surface.
22421
+ --domain <CODE> Only findings in that domain (SEC, PRF, \u2026).
22422
+ --json Print the totals, the table and every point as JSON.
22423
+
22424
+ Replays quality.finding.opened / resolved / accepted from the journal, so it
22425
+ needs a bundle (--bundle, default docs/arkaik/bundle.json). Each recorded audit
22426
+ (\`arkaik kritik matrix --record\`) re-baselines the counts to what it counted,
22427
+ which corrects a finding closed by hand. A narrowed view is never re-baselined:
22428
+ an audit's counts are project-wide.`;
22252
22429
  var SCOPE_USAGE = `arkaik kritik scope [--since <audit>] [--no-widen] [--json]
22253
22430
 
22254
22431
  The cells a batch of fixes made stale. A score is an assessment, so closing
@@ -23080,6 +23257,86 @@ function runTrend(args, common) {
23080
23257
  );
23081
23258
  process.exit(0);
23082
23259
  }
23260
+ function runBurndown(args, common) {
23261
+ const { single, flags } = collect(args, [], ["json"]);
23262
+ if (flags.has("help")) {
23263
+ console.log(BURNDOWN_USAGE);
23264
+ process.exit(0);
23265
+ }
23266
+ const journal = resolveJournal(common.root, common.bundlePath);
23267
+ if (!journal.present) {
23268
+ fail12(
23269
+ `kritik: no bundle at ${journal.bundlePath} \u2014 the burndown is read from the journal's quality.finding.* events, and there is no journal without a bundle.`
23270
+ );
23271
+ }
23272
+ const events = readFullJournalEvents(journal.journalPath);
23273
+ let library;
23274
+ let section;
23275
+ try {
23276
+ library = loadKritikLibrary(common.root).library;
23277
+ section = loadCurrentQualitySection(common.root, library);
23278
+ } catch {
23279
+ }
23280
+ const filter = {
23281
+ ...single.surface !== void 0 ? { surface: single.surface } : {},
23282
+ ...single.domain !== void 0 ? { domain: single.domain } : {}
23283
+ };
23284
+ const burndown = deriveFindingsBurndown(events, { ...filter, library, findings: section?.findings });
23285
+ const openNow = section ? section.findings.filter(
23286
+ (finding) => isOpenFinding(finding) && (filter.surface === void 0 || finding.surface === filter.surface) && (filter.domain === void 0 || domainCodeOf(finding.criterion_id, library) === filter.domain)
23287
+ ).length : void 0;
23288
+ const { reference, rows } = burndownRows(burndown);
23289
+ const summary = burndownSummary(burndown, openNow);
23290
+ if (flags.has("json")) {
23291
+ console.log(
23292
+ JSON.stringify(
23293
+ {
23294
+ summary,
23295
+ opened: burndown.opened,
23296
+ resolved: burndown.resolved,
23297
+ accepted: burndown.accepted,
23298
+ since: burndown.since,
23299
+ ...openNow !== void 0 ? { open: openNow } : {},
23300
+ reference,
23301
+ rows,
23302
+ points: burndown.points
23303
+ },
23304
+ null,
23305
+ 2
23306
+ )
23307
+ );
23308
+ process.exit(0);
23309
+ }
23310
+ if (summary === null || reference === null) {
23311
+ console.log(
23312
+ `
23313
+ no finding history yet \u2014 \`arkaik kritik finding open\` and \`finding resolve\` write it, and \`arkaik kritik matrix --record\` records an audit to measure from.
23314
+ `
23315
+ );
23316
+ process.exit(0);
23317
+ }
23318
+ const referenceTitle = reference.kind === "audit" ? `at ${reference.id}` : "at start";
23319
+ const header = ["severity", referenceTitle, "now", "change"];
23320
+ const table = rows.map((row) => [
23321
+ row.severity,
23322
+ String(row.at_reference),
23323
+ String(row.now),
23324
+ row.change === 0 ? "=" : row.change > 0 ? `+${row.change}` : `\u2212${Math.abs(row.change)}`
23325
+ ]);
23326
+ const widths = header.map((title2, column) => Math.max(title2.length, ...table.map((line3) => line3[column].length)));
23327
+ const line2 = (cells) => ` ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" ")}`.trimEnd();
23328
+ console.log(`
23329
+ ${summary}
23330
+ `);
23331
+ console.log(line2(header));
23332
+ for (const cells of table) console.log(line2(cells));
23333
+ if (reference.kind === "start") {
23334
+ console.log(`
23335
+ no recorded audit \u2014 read from the first event (${reference.ts.slice(0, 10)}).`);
23336
+ }
23337
+ console.log("");
23338
+ process.exit(0);
23339
+ }
23083
23340
  function scopeReason(cell, resolvedBy) {
23084
23341
  if (cell.kind === "widened") return `widened via ${cell.because.join(", ")}`;
23085
23342
  const findings = cell.because.map((id) => resolvedBy[id] !== void 0 ? `${id} (resolved by ${resolvedBy[id]})` : id);
@@ -23312,6 +23569,8 @@ function runKritik(args) {
23312
23569
  return runRegressions(subArgs, common);
23313
23570
  case "trend":
23314
23571
  return runTrend(subArgs, common);
23572
+ case "burndown":
23573
+ return runBurndown(subArgs, common);
23315
23574
  case "scope":
23316
23575
  return runScope(subArgs, common);
23317
23576
  case "issue":
@@ -23353,7 +23612,7 @@ Options:
23353
23612
  -v, --version Print the version.
23354
23613
 
23355
23614
  Run "arkaik <command> --help" for command-specific help.`;
23356
- var VERSION = "0.7.0";
23615
+ var VERSION = "0.8.0";
23357
23616
  function main(argv) {
23358
23617
  const [command, ...rest] = argv;
23359
23618
  if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkaik",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",