arkaik 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/skill/references/schema.md +60 -53
- package/dist/assets/skill/scripts/validate-bundle.js +4 -4
- package/dist/assets/skill/skill.md +3 -0
- package/dist/index.js +2924 -849
- package/dist/io.js +219 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14796,11 +14796,102 @@ var PlaylistEntrySchema = external_exports.lazy(
|
|
|
14796
14796
|
id: "PlaylistEntry",
|
|
14797
14797
|
description: "An entry in a flow's playlist. Discriminated union on 'type'."
|
|
14798
14798
|
});
|
|
14799
|
+
function collectPlaylistNodeRefs(entries) {
|
|
14800
|
+
const refs = [];
|
|
14801
|
+
for (const entry of entries) {
|
|
14802
|
+
if (!entry) continue;
|
|
14803
|
+
if (entry.type === "view") {
|
|
14804
|
+
refs.push(entry.view_id);
|
|
14805
|
+
} else if (entry.type === "flow") {
|
|
14806
|
+
refs.push(entry.flow_id);
|
|
14807
|
+
} else if (entry.type === "condition") {
|
|
14808
|
+
refs.push(...collectPlaylistNodeRefs(entry.if_true ?? []));
|
|
14809
|
+
refs.push(...collectPlaylistNodeRefs(entry.if_false ?? []));
|
|
14810
|
+
} else if (entry.type === "junction") {
|
|
14811
|
+
for (const branch of entry.cases ?? []) {
|
|
14812
|
+
refs.push(...collectPlaylistNodeRefs(branch.entries ?? []));
|
|
14813
|
+
}
|
|
14814
|
+
}
|
|
14815
|
+
}
|
|
14816
|
+
return refs;
|
|
14817
|
+
}
|
|
14799
14818
|
var FlowPlaylistSchema = external_exports.object({
|
|
14800
14819
|
entries: external_exports.array(PlaylistEntrySchema)
|
|
14801
14820
|
}).meta({ id: "FlowPlaylist" });
|
|
14802
14821
|
|
|
14822
|
+
// ../schema/src/screenshots.ts
|
|
14823
|
+
var SHOT_BEARING_SPECIES = ["view", "acceptance"];
|
|
14824
|
+
var HTTPS = /^https:\/\/\S+$/;
|
|
14825
|
+
var HAS_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
14826
|
+
var IMAGE_DATA_URI = /^data:image\/[a-z0-9.+-]+[;,]/i;
|
|
14827
|
+
function isValidScreenshotValue(form, value) {
|
|
14828
|
+
if (value === "" || /[\u0000-\u001f\u007f]/.test(value)) return false;
|
|
14829
|
+
switch (form) {
|
|
14830
|
+
case "url":
|
|
14831
|
+
return HTTPS.test(value);
|
|
14832
|
+
case "path":
|
|
14833
|
+
return !value.startsWith("/") && !HAS_SCHEME.test(value) && !/(^|\/)\.\.(\/|$)/.test(value);
|
|
14834
|
+
case "data":
|
|
14835
|
+
return IMAGE_DATA_URI.test(value);
|
|
14836
|
+
}
|
|
14837
|
+
}
|
|
14838
|
+
function isRecord(value) {
|
|
14839
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14840
|
+
}
|
|
14841
|
+
function readSlot(node, platform) {
|
|
14842
|
+
const md = isRecord(node.metadata) ? node.metadata : {};
|
|
14843
|
+
const shots = isRecord(md.platformScreenshots) ? md.platformScreenshots : {};
|
|
14844
|
+
const metas = isRecord(md.platformScreenshotMeta) ? md.platformScreenshotMeta : {};
|
|
14845
|
+
const meta3 = isRecord(metas[platform]) ? metas[platform] : {};
|
|
14846
|
+
const rawValue = shots[platform];
|
|
14847
|
+
const value = typeof rawValue === "string" ? rawValue : void 0;
|
|
14848
|
+
const rawOrder = meta3.ci_order;
|
|
14849
|
+
const ciOrder = typeof rawOrder === "number" ? rawOrder : void 0;
|
|
14850
|
+
return { value, ciOrder };
|
|
14851
|
+
}
|
|
14852
|
+
function decideScreenshot(node, input) {
|
|
14853
|
+
if (!node) return { kind: "refuse", code: "node_not_found", message: `Node ${input.node_id} not found` };
|
|
14854
|
+
if (!SHOT_BEARING_SPECIES.includes(node.species)) {
|
|
14855
|
+
return { kind: "refuse", code: "not_shot_bearing", message: `${node.id} is a ${node.species}; only views and acceptances carry screenshots` };
|
|
14856
|
+
}
|
|
14857
|
+
if (!node.platforms.includes(input.platform)) {
|
|
14858
|
+
return {
|
|
14859
|
+
kind: "refuse",
|
|
14860
|
+
code: "platform_not_applicable",
|
|
14861
|
+
message: `${input.platform} is not a platform of ${node.id} (${node.platforms.length > 0 ? `lists: ${node.platforms.join(", ")}` : "lists none"})`
|
|
14862
|
+
};
|
|
14863
|
+
}
|
|
14864
|
+
if (!isValidScreenshotValue(input.form, input.value)) {
|
|
14865
|
+
return { kind: "refuse", code: "invalid_screenshot", message: `value is not a well-formed ${input.form} screenshot` };
|
|
14866
|
+
}
|
|
14867
|
+
if (input.source === "ci" && (typeof input.order !== "number" || !Number.isInteger(input.order) || input.order < 0)) {
|
|
14868
|
+
return { kind: "refuse", code: "invalid_screenshot", message: "a ci screenshot needs a non-negative integer order" };
|
|
14869
|
+
}
|
|
14870
|
+
const slot = readSlot(node, input.platform);
|
|
14871
|
+
if (input.source === "ci" && slot.ciOrder !== void 0 && typeof input.order === "number" && input.order < slot.ciOrder) {
|
|
14872
|
+
return { kind: "skip", reason: "stale_order" };
|
|
14873
|
+
}
|
|
14874
|
+
if (slot.value === input.value) return { kind: "skip", reason: "unchanged" };
|
|
14875
|
+
return { kind: "apply" };
|
|
14876
|
+
}
|
|
14877
|
+
function reduceScreenshotSlots(ordered) {
|
|
14878
|
+
const slots = /* @__PURE__ */ new Map();
|
|
14879
|
+
for (const ev of ordered) {
|
|
14880
|
+
if (ev.type !== "screenshot.recorded" && ev.type !== "screenshot.removed") continue;
|
|
14881
|
+
if (typeof ev.node_id !== "string" || typeof ev.platform !== "string") continue;
|
|
14882
|
+
let byPlatform = slots.get(ev.node_id);
|
|
14883
|
+
if (!byPlatform) {
|
|
14884
|
+
byPlatform = /* @__PURE__ */ new Map();
|
|
14885
|
+
slots.set(ev.node_id, byPlatform);
|
|
14886
|
+
}
|
|
14887
|
+
byPlatform.set(ev.platform, ev.type === "screenshot.removed" ? null : ev);
|
|
14888
|
+
}
|
|
14889
|
+
return slots;
|
|
14890
|
+
}
|
|
14891
|
+
|
|
14803
14892
|
// ../schema/src/journal.ts
|
|
14893
|
+
var SCREENSHOT_SOURCES = ["ci", "manual"];
|
|
14894
|
+
var SCREENSHOT_FORMS = ["url", "path", "data"];
|
|
14804
14895
|
function orderEvents(events) {
|
|
14805
14896
|
const key = (v) => typeof v === "string" ? v : "";
|
|
14806
14897
|
return [...events].sort((a, b) => {
|
|
@@ -14870,9 +14961,14 @@ var NODE_REF_FIELDS = {
|
|
|
14870
14961
|
"ref.added": ["node_id"],
|
|
14871
14962
|
"ref.removed": ["node_id"],
|
|
14872
14963
|
"ref.status_changed": ["node_id"],
|
|
14964
|
+
"screenshot.recorded": ["node_id"],
|
|
14965
|
+
"screenshot.removed": ["node_id"],
|
|
14873
14966
|
"idea.proposed": ["node_id"],
|
|
14874
14967
|
"request.filed": ["node_id"]
|
|
14875
14968
|
};
|
|
14969
|
+
function isRecord2(value) {
|
|
14970
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14971
|
+
}
|
|
14876
14972
|
function statusesAgree(last, snapshot) {
|
|
14877
14973
|
if (last === snapshot) return true;
|
|
14878
14974
|
if (typeof snapshot !== "string") return false;
|
|
@@ -15053,6 +15149,41 @@ function crossCheckJournal(bundle) {
|
|
|
15053
15149
|
});
|
|
15054
15150
|
}
|
|
15055
15151
|
}
|
|
15152
|
+
const slots = reduceScreenshotSlots(ordered);
|
|
15153
|
+
nodesRaw.forEach((n, index) => {
|
|
15154
|
+
const nodeId = str2(n?.id);
|
|
15155
|
+
if (nodeId === void 0) return;
|
|
15156
|
+
const metadata = isRecord2(n.metadata) ? n.metadata : {};
|
|
15157
|
+
const shots = isRecord2(metadata.platformScreenshots) ? metadata.platformScreenshots : {};
|
|
15158
|
+
const eventSlots = slots.get(nodeId);
|
|
15159
|
+
const platforms = /* @__PURE__ */ new Set([...Object.keys(shots), ...eventSlots ? eventSlots.keys() : []]);
|
|
15160
|
+
for (const platform of platforms) {
|
|
15161
|
+
const last = eventSlots?.get(platform);
|
|
15162
|
+
if (last === void 0) continue;
|
|
15163
|
+
const slot = typeof shots[platform] === "string" ? shots[platform] : void 0;
|
|
15164
|
+
let says;
|
|
15165
|
+
let agrees;
|
|
15166
|
+
if (last === null) {
|
|
15167
|
+
agrees = slot === void 0;
|
|
15168
|
+
says = "it was removed";
|
|
15169
|
+
} else if (last.form === "data") {
|
|
15170
|
+
agrees = slot !== void 0;
|
|
15171
|
+
says = "a data URI was recorded";
|
|
15172
|
+
} else {
|
|
15173
|
+
const url2 = str2(last.url);
|
|
15174
|
+
agrees = slot === url2;
|
|
15175
|
+
says = url2 === void 0 ? "an unknown value was recorded" : `"${url2}" was recorded`;
|
|
15176
|
+
}
|
|
15177
|
+
if (!agrees) {
|
|
15178
|
+
findings.push({
|
|
15179
|
+
path: `nodes[${index}].metadata.platformScreenshots.${platform}`,
|
|
15180
|
+
rule: "screenshot-untracked",
|
|
15181
|
+
message: `Node "${nodeId}": platformScreenshots.${platform} is ${slot === void 0 ? "empty" : `"${slot}"`} but the journal's last screenshot event says ${says} \u2014 write screenshots through record_screenshot, not update_node.`,
|
|
15182
|
+
severity: "warning"
|
|
15183
|
+
});
|
|
15184
|
+
}
|
|
15185
|
+
}
|
|
15186
|
+
});
|
|
15056
15187
|
return findings;
|
|
15057
15188
|
}
|
|
15058
15189
|
function missingProvenanceNodeIds(snapshotNodeIds, events) {
|
|
@@ -15182,6 +15313,19 @@ var RefStatusChangedEventSchema = external_exports.object({
|
|
|
15182
15313
|
to: external_exports.string(),
|
|
15183
15314
|
synced_at: external_exports.string()
|
|
15184
15315
|
}).catchall(external_exports.unknown());
|
|
15316
|
+
var ScreenshotRecordedEventSchema = external_exports.object({
|
|
15317
|
+
...envelope,
|
|
15318
|
+
type: external_exports.literal("screenshot.recorded"),
|
|
15319
|
+
node_id: external_exports.string(),
|
|
15320
|
+
platform: PlatformSchema,
|
|
15321
|
+
source: external_exports.enum(SCREENSHOT_SOURCES),
|
|
15322
|
+
form: external_exports.enum(SCREENSHOT_FORMS),
|
|
15323
|
+
url: external_exports.string().optional(),
|
|
15324
|
+
commit: external_exports.string().optional(),
|
|
15325
|
+
order: external_exports.number().int().nonnegative().optional(),
|
|
15326
|
+
detail: external_exports.string().optional()
|
|
15327
|
+
}).catchall(external_exports.unknown());
|
|
15328
|
+
var ScreenshotRemovedEventSchema = external_exports.object({ ...envelope, type: external_exports.literal("screenshot.removed"), node_id: external_exports.string(), platform: PlatformSchema }).catchall(external_exports.unknown());
|
|
15185
15329
|
var JournalBaselineEventSchema = external_exports.object({ ...envelope, type: external_exports.literal("journal.baseline"), node_ids: external_exports.array(external_exports.string()) }).catchall(external_exports.unknown());
|
|
15186
15330
|
var QualityAuditCompletedEventSchema = external_exports.object({
|
|
15187
15331
|
...envelope,
|
|
@@ -15268,6 +15412,8 @@ var JOURNAL_EVENT_SCHEMAS = {
|
|
|
15268
15412
|
"ref.added": RefAddedEventSchema,
|
|
15269
15413
|
"ref.removed": RefRemovedEventSchema,
|
|
15270
15414
|
"ref.status_changed": RefStatusChangedEventSchema,
|
|
15415
|
+
"screenshot.recorded": ScreenshotRecordedEventSchema,
|
|
15416
|
+
"screenshot.removed": ScreenshotRemovedEventSchema,
|
|
15271
15417
|
"journal.baseline": JournalBaselineEventSchema,
|
|
15272
15418
|
"quality.audit.completed": QualityAuditCompletedEventSchema,
|
|
15273
15419
|
"quality.assessment.scored": QualityAssessmentScoredEventSchema,
|
|
@@ -15291,6 +15437,8 @@ var KnownJournalEventSchema = external_exports.union([
|
|
|
15291
15437
|
RefAddedEventSchema,
|
|
15292
15438
|
RefRemovedEventSchema,
|
|
15293
15439
|
RefStatusChangedEventSchema,
|
|
15440
|
+
ScreenshotRecordedEventSchema,
|
|
15441
|
+
ScreenshotRemovedEventSchema,
|
|
15294
15442
|
JournalBaselineEventSchema,
|
|
15295
15443
|
QualityAuditCompletedEventSchema,
|
|
15296
15444
|
QualityAssessmentScoredEventSchema,
|
|
@@ -15300,315 +15448,6 @@ var KnownJournalEventSchema = external_exports.union([
|
|
|
15300
15448
|
QualitySignalTrippedEventSchema
|
|
15301
15449
|
]);
|
|
15302
15450
|
|
|
15303
|
-
// ../schema/src/quality-schemas.ts
|
|
15304
|
-
var GradeSchema = external_exports.enum(["A", "B", "C", "D", "E"]);
|
|
15305
|
-
var KritikScalesSchema = external_exports.object({
|
|
15306
|
-
grades: external_exports.partialRecord(GradeSchema, external_exports.number()).optional(),
|
|
15307
|
-
severity_buckets: external_exports.partialRecord(external_exports.enum(["critical", "high", "medium", "low", "info"]), external_exports.tuple([external_exports.number(), external_exports.number()])).optional(),
|
|
15308
|
-
caps: external_exports.object({ critical_open: GradeSchema.optional(), high_open: GradeSchema.optional() }).catchall(external_exports.unknown()).optional()
|
|
15309
|
-
}).catchall(external_exports.unknown()).meta({
|
|
15310
|
-
id: "KritikScales",
|
|
15311
|
-
description: "Overridable maturity/severity/grade scales carried by a criteria pack. Absent entries fall back to the framework defaults (packages/kritik-library/SPEC.md \xA7 4)."
|
|
15312
|
-
});
|
|
15313
|
-
var KritikReferenceSchema = external_exports.object({ title: external_exports.string(), anchor: external_exports.string().optional(), url: external_exports.string().optional() }).catchall(external_exports.unknown()).meta({ id: "KritikReference", description: "A stable external anchor behind a criterion (OWASP control, GDPR article, WCAG SC\u2026)." });
|
|
15314
|
-
var KritikIssueTemplateSchema = external_exports.object({
|
|
15315
|
-
title_template: external_exports.string().optional(),
|
|
15316
|
-
labels: external_exports.array(external_exports.string()).optional(),
|
|
15317
|
-
body_skeleton: external_exports.string().optional()
|
|
15318
|
-
}).catchall(external_exports.unknown()).meta({ id: "KritikIssueTemplate", description: "Per-criterion issue skeleton \u2014 what `arkaik kritik issue` prefills." });
|
|
15319
|
-
var KritikDomainSchema = external_exports.object({ code: external_exports.string(), name: external_exports.string(), description: external_exports.string().optional() }).catchall(external_exports.unknown()).meta({ id: "KritikDomain", description: "A top-level criteria category owning a roll-up row in the matrix." });
|
|
15320
|
-
var KritikCriterionSchema = external_exports.object({
|
|
15321
|
-
id: external_exports.string().meta({ description: "Stable identifier, `<DOMAIN>-NN`. Never redefined \u2014 retired via superseded_by." }),
|
|
15322
|
-
domain: external_exports.string(),
|
|
15323
|
-
subcategory: external_exports.string().optional(),
|
|
15324
|
-
name: external_exports.string().optional(),
|
|
15325
|
-
question: external_exports.string().optional(),
|
|
15326
|
-
definition: external_exports.string().optional(),
|
|
15327
|
-
rationale: external_exports.string().optional(),
|
|
15328
|
-
applies_to: external_exports.array(external_exports.string()).optional().meta({ description: "Surface ids where the criterion is meaningful; absence means N/A." }),
|
|
15329
|
-
level_anchors: external_exports.record(external_exports.string(), external_exports.string()).optional().meta({ description: "Observable descriptions per maturity level, keyed l0\u2026l4." }),
|
|
15330
|
-
default_impact: external_exports.number().optional(),
|
|
15331
|
-
weight: external_exports.number().optional().meta({ description: "Weight in the domain roll-up (1\u20133; 3 = load-bearing). Absent means 1." }),
|
|
15332
|
-
references: external_exports.array(KritikReferenceSchema).optional(),
|
|
15333
|
-
checklist: external_exports.array(external_exports.string()).optional(),
|
|
15334
|
-
signals: external_exports.array(external_exports.string()).optional().meta({ description: "Mechanically checkable monitoring hooks run between audits." }),
|
|
15335
|
-
remediation: external_exports.string().optional(),
|
|
15336
|
-
issue: KritikIssueTemplateSchema.optional(),
|
|
15337
|
-
superseded_by: external_exports.string().optional()
|
|
15338
|
-
}).catchall(external_exports.unknown()).meta({ id: "KritikCriterion", description: "The atomic auditable unit (packages/kritik-library/SPEC.md \xA7 5)." });
|
|
15339
|
-
var KritikLibrarySchema = external_exports.object({
|
|
15340
|
-
version: external_exports.string().meta({ description: "Semver of the pack; matrices are comparable only within a major." }),
|
|
15341
|
-
domains: external_exports.array(KritikDomainSchema),
|
|
15342
|
-
criteria: external_exports.array(KritikCriterionSchema),
|
|
15343
|
-
scales: KritikScalesSchema.optional()
|
|
15344
|
-
}).catchall(external_exports.unknown()).meta({
|
|
15345
|
-
id: "KritikLibrary",
|
|
15346
|
-
description: "A versioned criteria pack. Embedded on export; repos may instead pin it as a sidecar file."
|
|
15347
|
-
});
|
|
15348
|
-
var SurfaceDefSchema = external_exports.object({
|
|
15349
|
-
id: external_exports.string(),
|
|
15350
|
-
title: external_exports.string(),
|
|
15351
|
-
platform: PlatformSchema.optional().meta({
|
|
15352
|
-
description: "Optional bridge to PLATFORM_IDS where a surface is also a view-shipping platform. Surfaces are not platforms (RFC \xA7 2)."
|
|
15353
|
-
}),
|
|
15354
|
-
path: external_exports.string().optional()
|
|
15355
|
-
}).catchall(external_exports.unknown()).meta({ id: "SurfaceDef", description: "One independently assessable body of code \u2014 an audit target, chosen at install." });
|
|
15356
|
-
var QualityProfileSchema = external_exports.object({
|
|
15357
|
-
surfaces: external_exports.array(SurfaceDefSchema),
|
|
15358
|
-
domain_weights: external_exports.record(external_exports.string(), external_exports.number()).optional().meta({
|
|
15359
|
-
description: "Per-domain weight in the surface roll-up, keyed by domain code. A missing weight is 1."
|
|
15360
|
-
})
|
|
15361
|
-
}).catchall(external_exports.unknown()).meta({ id: "QualityProfile", description: "The project's parameterization of the pack (RFC \xA7 6)." });
|
|
15362
|
-
var QualityAssessmentSchema = external_exports.object({
|
|
15363
|
-
criterion_id: external_exports.string(),
|
|
15364
|
-
surface: external_exports.string(),
|
|
15365
|
-
level: external_exports.union([external_exports.literal(0), external_exports.literal(1), external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).meta({
|
|
15366
|
-
description: "Maturity 0\u20134. N/A is the absence of the row, never a level."
|
|
15367
|
-
}),
|
|
15368
|
-
evidence: external_exports.string().meta({ description: "file:line / config citations. A score without evidence is an opinion, not an assessment." }),
|
|
15369
|
-
audit_id: external_exports.string(),
|
|
15370
|
-
commit: external_exports.string().optional(),
|
|
15371
|
-
ts: external_exports.string()
|
|
15372
|
-
}).catchall(external_exports.unknown()).meta({ id: "QualityAssessment", description: "One (criterion \xD7 surface) score \u2014 latest wins; history lives in the journal." });
|
|
15373
|
-
var QualityFindingSchema = external_exports.object({
|
|
15374
|
-
id: external_exports.string(),
|
|
15375
|
-
criterion_id: external_exports.string(),
|
|
15376
|
-
surface: external_exports.string(),
|
|
15377
|
-
title: external_exports.string(),
|
|
15378
|
-
detail: external_exports.string(),
|
|
15379
|
-
evidence: external_exports.string(),
|
|
15380
|
-
impact: external_exports.number().meta({ description: "Worst plausible consequence, 1\u20135." }),
|
|
15381
|
-
likelihood: external_exports.number().meta({ description: "Probability it materializes, 1\u20135." }),
|
|
15382
|
-
cost: external_exports.enum(["S", "M", "L", "XL"]),
|
|
15383
|
-
status: external_exports.enum(["open", "resolved", "refuted", "accepted-risk"]),
|
|
15384
|
-
remediation: external_exports.string().optional(),
|
|
15385
|
-
node_ids: external_exports.array(external_exports.string()).optional().meta({ description: "Graph nodes this finding is about \u2014 the tie deliverable.shipped already uses." }),
|
|
15386
|
-
issue_url: external_exports.string().optional(),
|
|
15387
|
-
commit: external_exports.string().optional().meta({
|
|
15388
|
-
description: "Commit SHA anchoring the file:line evidence. Required by policy on any finding written away from a checkout (issue #400 decision 4) \u2014 without it a stale citation is indistinguishable from a wrong one."
|
|
15389
|
-
}),
|
|
15390
|
-
verification: external_exports.object({ verdict: external_exports.enum(["CONFIRMED", "REFUTED", "DOWNGRADED"]), note: external_exports.string().optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Result of the adversarial refutation pass. Refuted findings are disclosed, not deleted." })
|
|
15391
|
-
}).catchall(external_exports.unknown()).meta({
|
|
15392
|
-
id: "QualityFinding",
|
|
15393
|
-
description: "One concrete defect. Severity and priority are deliberately absent \u2014 they are derived from impact \xD7 likelihood and cost (deriveQualityMatrix), so a finding can never carry a severity its own numbers disagree with."
|
|
15394
|
-
});
|
|
15395
|
-
var QualitySectionSchema = external_exports.object({
|
|
15396
|
-
framework_version: external_exports.string(),
|
|
15397
|
-
library: KritikLibrarySchema.optional(),
|
|
15398
|
-
profile: QualityProfileSchema,
|
|
15399
|
-
assessments: external_exports.array(QualityAssessmentSchema),
|
|
15400
|
-
findings: external_exports.array(QualityFindingSchema)
|
|
15401
|
-
}).catchall(external_exports.unknown()).meta({
|
|
15402
|
-
id: "QualitySection",
|
|
15403
|
-
description: "The project's Kritik state (docs/rfcs/kritik.md \xA7 4.1) \u2014 profile, assessments, findings. Criteria are library content, not graph nodes; the matrix is a projection, never stored."
|
|
15404
|
-
});
|
|
15405
|
-
|
|
15406
|
-
// ../schema/src/bundle.ts
|
|
15407
|
-
var PlatformStatusMapSchema = external_exports.partialRecord(
|
|
15408
|
-
PlatformSchema,
|
|
15409
|
-
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
15410
|
-
AnyStatusSchema
|
|
15411
|
-
).meta({ id: "PlatformStatusMap", description: "Per-platform status overrides for view nodes." });
|
|
15412
|
-
var PlatformNotesMapSchema = external_exports.partialRecord(
|
|
15413
|
-
PlatformSchema,
|
|
15414
|
-
external_exports.string()
|
|
15415
|
-
).meta({ id: "PlatformNotesMap", description: "Freeform per-platform notes." });
|
|
15416
|
-
var PlatformScreenshotsMapSchema = external_exports.partialRecord(
|
|
15417
|
-
PlatformSchema,
|
|
15418
|
-
external_exports.string()
|
|
15419
|
-
).meta({
|
|
15420
|
-
id: "PlatformScreenshotsMap",
|
|
15421
|
-
description: "Per-platform screenshot: a relative path, an absolute URL, or a data URI (see docs/spec/bundle-format.md \xA7 Asset Values)."
|
|
15422
|
-
});
|
|
15423
|
-
var RefSchema = external_exports.object({
|
|
15424
|
-
id: external_exports.string().meta({ description: 'Unique within the node, kebab-case (e.g. "gh-142").' }),
|
|
15425
|
-
type: external_exports.string().meta({
|
|
15426
|
-
description: "Ref type: figma | github-issue | gitlab-issue | linear-issue | github-pr | gitlab-mr | url. Unrecognized values are preserved and render as generic links."
|
|
15427
|
-
}),
|
|
15428
|
-
url: external_exports.string().meta({ description: "Canonical external URL." }),
|
|
15429
|
-
title: external_exports.string().optional().meta({ description: "Display label." }),
|
|
15430
|
-
external_status: external_exports.string().optional().meta({
|
|
15431
|
-
description: 'Mirrored external state, verbatim (e.g. "open", "merged", "In Progress").'
|
|
15432
|
-
}),
|
|
15433
|
-
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
15434
|
-
status_mapped: AnyStatusSchema.optional().meta({
|
|
15435
|
-
description: "Optional mapping of external_status into the arkaik lifecycle. Advisory display data \u2014 never mutates node.status."
|
|
15436
|
-
}),
|
|
15437
|
-
platform: PlatformSchema.optional().meta({ description: "Optional scoping to one platform variant." }),
|
|
15438
|
-
synced_at: external_exports.string().optional().meta({ description: "ISO 8601 \u2014 when external_status was last mirrored." })
|
|
15439
|
-
}).meta({ id: "Ref", description: "A typed external reference on a node (docs/spec/bundle-format.md \xA7 References)." });
|
|
15440
|
-
var NodeMetadataSchema = external_exports.object({
|
|
15441
|
-
stage: external_exports.string().optional(),
|
|
15442
|
-
blocked_by: external_exports.string().optional().meta({
|
|
15443
|
-
description: "Non-empty = blocked at the current status. A node id (rendered as a link) or free text naming the dependency."
|
|
15444
|
-
}),
|
|
15445
|
-
playlist: FlowPlaylistSchema.optional(),
|
|
15446
|
-
platformNotes: PlatformNotesMapSchema.optional(),
|
|
15447
|
-
platformStatuses: PlatformStatusMapSchema.optional(),
|
|
15448
|
-
platformScreenshots: PlatformScreenshotsMapSchema.optional(),
|
|
15449
|
-
refs: external_exports.array(RefSchema).optional().meta({ description: "Typed external references on the node." }),
|
|
15450
|
-
gherkin: external_exports.string().optional().meta({
|
|
15451
|
-
description: "Acceptance nodes only: exactly one Given/When/Then scenario (the How). A second scenario is a second acceptance node."
|
|
15452
|
-
}),
|
|
15453
|
-
values: external_exports.array(ValueSchema).optional().meta({
|
|
15454
|
-
description: "Acceptance nodes only: 1..n Bain value elements served (the Why)."
|
|
15455
|
-
}),
|
|
15456
|
-
product: external_exports.string().optional().meta({
|
|
15457
|
-
description: "Product membership (docs/spec/bundle-format.md \xA7 Products); flow, view, and acceptance only."
|
|
15458
|
-
}),
|
|
15459
|
-
decision_status: DecisionStatusSchema.optional().meta({
|
|
15460
|
-
description: "Decision nodes only: proposed | approved | enacted | rejected | deprecated | superseded. The node's lifecycle status is kept in sync (spec \xA72)."
|
|
15461
|
-
}),
|
|
15462
|
-
context: external_exports.string().optional().meta({
|
|
15463
|
-
description: "Decision nodes only: Context \u2014 the Why (markdown)."
|
|
15464
|
-
}),
|
|
15465
|
-
consequences: external_exports.string().optional().meta({
|
|
15466
|
-
description: "Decision nodes only: Consequences \u2014 the How (markdown)."
|
|
15467
|
-
}),
|
|
15468
|
-
decided_at: external_exports.string().optional().meta({
|
|
15469
|
-
description: "Decision nodes only: ISO 8601 date the decision was made."
|
|
15470
|
-
})
|
|
15471
|
-
}).catchall(external_exports.unknown()).meta({ id: "NodeMetadata", description: "Optional metadata for a node." });
|
|
15472
|
-
var NodeSchema = external_exports.object({
|
|
15473
|
-
id: external_exports.string().meta({ description: "Unique node ID. Convention: prefix with species \u2014 F- (flow), V- (view), DM- (data-model), API- (api-endpoint)." }),
|
|
15474
|
-
project_id: external_exports.string().meta({ description: "Must match project.id." }),
|
|
15475
|
-
species: SpeciesSchema,
|
|
15476
|
-
title: external_exports.string().meta({ description: "Human-readable node title." }),
|
|
15477
|
-
description: external_exports.string().optional().meta({ description: "Optional description of the node's purpose." }),
|
|
15478
|
-
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
15479
|
-
status: AnyStatusSchema,
|
|
15480
|
-
platforms: external_exports.array(PlatformSchema).meta({ description: "One or more target platforms." }),
|
|
15481
|
-
metadata: NodeMetadataSchema.optional()
|
|
15482
|
-
}).meta({ id: "Node" });
|
|
15483
|
-
var EdgeSchema = external_exports.object({
|
|
15484
|
-
id: external_exports.string().meta({ description: "Unique edge ID. Convention: e-{source_id}-{target_id}." }),
|
|
15485
|
-
project_id: external_exports.string().meta({ description: "Must match project.id." }),
|
|
15486
|
-
source_id: external_exports.string().meta({ description: "ID of the source node." }),
|
|
15487
|
-
target_id: external_exports.string().meta({ description: "ID of the target node." }),
|
|
15488
|
-
edge_type: EdgeTypeSchema,
|
|
15489
|
-
metadata: external_exports.record(external_exports.string(), external_exports.unknown()).optional().meta({ description: "Optional edge metadata." })
|
|
15490
|
-
}).meta({ id: "Edge" });
|
|
15491
|
-
var MapDisplayOptionsSchema = external_exports.object({
|
|
15492
|
-
images: external_exports.boolean().optional().meta({ description: "Screenshot (or cover) art on view cards." }),
|
|
15493
|
-
flow_platforms: external_exports.string().optional().meta({
|
|
15494
|
-
description: "A flow card's platform delivery: rings (default) | bars."
|
|
15495
|
-
}),
|
|
15496
|
-
view_platforms: external_exports.string().optional().meta({
|
|
15497
|
-
description: "A view card's platform availability: chips (default) | rows."
|
|
15498
|
-
}),
|
|
15499
|
-
minimap_color: external_exports.string().optional().meta({
|
|
15500
|
-
description: "What a minimap node's fill encodes: status (default) | species."
|
|
15501
|
-
})
|
|
15502
|
-
}).catchall(external_exports.unknown()).meta({ id: "MapDisplayOptions", description: "How a map draws its cards (docs/spec/maps.md \xA7 Display Options)." });
|
|
15503
|
-
var MapDefinitionSchema = external_exports.object({
|
|
15504
|
-
id: external_exports.string().meta({
|
|
15505
|
-
description: "Kebab-case, unique within the project; built-in ids (journey, system) are reserved."
|
|
15506
|
-
}),
|
|
15507
|
-
title: external_exports.string().meta({ description: "Display title." }),
|
|
15508
|
-
description: external_exports.string().optional().meta({ description: "What this map is for." }),
|
|
15509
|
-
kind: external_exports.string().meta({
|
|
15510
|
-
description: "Map kind: journey | system. Selects the renderer and selection defaults; unrecognized kinds are preserved and listed as unrenderable."
|
|
15511
|
-
}),
|
|
15512
|
-
species: external_exports.array(external_exports.string()).optional().meta({
|
|
15513
|
-
description: "Node filter; defaults by kind (journey: flow+view; system: view+api-endpoint+data-model)."
|
|
15514
|
-
}),
|
|
15515
|
-
edge_types: external_exports.array(external_exports.string()).optional().meta({
|
|
15516
|
-
description: "Edge filter; defaults by kind (journey: composes; system: calls+displays+queries)."
|
|
15517
|
-
}),
|
|
15518
|
-
root_node_id: external_exports.string().optional().meta({
|
|
15519
|
-
description: "Scope anchor: the subgraph is the undirected neighborhood reachable from this node."
|
|
15520
|
-
}),
|
|
15521
|
-
product: external_exports.string().optional().meta({ description: "Product scope; absent = every product." }),
|
|
15522
|
-
depth: external_exports.number().optional().meta({ description: "Traversal bound from the root; absent = unbounded." }),
|
|
15523
|
-
layout: external_exports.object({ direction: external_exports.string().optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Renderer layout hints (e.g. direction: DOWN | RIGHT)." }),
|
|
15524
|
-
display: MapDisplayOptionsSchema.optional().meta({
|
|
15525
|
-
description: "Card rendering; the human twin is project.metadata.map_display[id]."
|
|
15526
|
-
})
|
|
15527
|
-
}).catchall(external_exports.unknown()).meta({ id: "MapDefinition", description: "A stored map definition (docs/spec/maps.md \xA7 MapDefinition)." });
|
|
15528
|
-
var ProductDefinitionSchema = external_exports.object({
|
|
15529
|
-
id: external_exports.string().meta({ description: "Kebab-case, unique within the project." }),
|
|
15530
|
-
title: external_exports.string().meta({ description: "Display title." }),
|
|
15531
|
-
description: external_exports.string().optional().meta({ description: "What this product is." }),
|
|
15532
|
-
platforms: external_exports.array(PlatformSchema).meta({
|
|
15533
|
-
description: "The platforms this product can ship on; empty means availability is not tracked."
|
|
15534
|
-
}),
|
|
15535
|
-
root_node_id: external_exports.string().optional().meta({ description: "This product's journey anchor." })
|
|
15536
|
-
}).catchall(external_exports.unknown()).meta({ id: "ProductDefinition", description: "A product definition (docs/spec/bundle-format.md \xA7 Products)." });
|
|
15537
|
-
var ProjectMetadataSchema = external_exports.object({
|
|
15538
|
-
view_card_variant: external_exports.enum(["compact", "large"]).optional(),
|
|
15539
|
-
maps: external_exports.array(MapDefinitionSchema).optional().meta({
|
|
15540
|
-
description: "Stored map definitions (docs/spec/maps.md \xA7 Storage) \u2014 additive; unknown fields preserved."
|
|
15541
|
-
}),
|
|
15542
|
-
map_display: external_exports.record(external_exports.string(), MapDisplayOptionsSchema).optional().meta({
|
|
15543
|
-
description: "Per-map display overrides keyed by map id (docs/spec/maps.md \xA7 Display Options) \u2014 the only path open to the built-in maps."
|
|
15544
|
-
}),
|
|
15545
|
-
products: external_exports.array(ProductDefinitionSchema).optional().meta({
|
|
15546
|
-
description: "Product definitions (docs/spec/bundle-format.md \xA7 Products) \u2014 additive; unknown fields preserved."
|
|
15547
|
-
}),
|
|
15548
|
-
pollen: external_exports.object({ plant: external_exports.string().regex(/^[a-z0-9][a-z0-9-]*$/).optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Federation settings \u2014 docs/spec/services.md \xA7 Pollen feed. `plant` enables the feed." })
|
|
15549
|
-
}).catchall(external_exports.unknown()).meta({ id: "ProjectMetadata", description: "Optional project-level UI settings." });
|
|
15550
|
-
var ProjectSchema = external_exports.object({
|
|
15551
|
-
id: external_exports.string().meta({ description: "Unique project identifier." }),
|
|
15552
|
-
title: external_exports.string().meta({ description: "Project title." }),
|
|
15553
|
-
description: external_exports.string().optional().meta({ description: "Optional project description." }),
|
|
15554
|
-
version: external_exports.string().optional().meta({
|
|
15555
|
-
description: "Current version label of the mapped product (free-form; semver recommended, not required). Version history lives in the journal as release.tagged events."
|
|
15556
|
-
}),
|
|
15557
|
-
root_node_id: external_exports.string().optional().meta({
|
|
15558
|
-
description: "ID of the root node used as the canvas entry point. Should reference an existing node."
|
|
15559
|
-
}),
|
|
15560
|
-
metadata: ProjectMetadataSchema.optional(),
|
|
15561
|
-
created_at: external_exports.string().meta({ description: "ISO 8601 creation timestamp." }),
|
|
15562
|
-
updated_at: external_exports.string().meta({ description: "ISO 8601 last-update timestamp." }),
|
|
15563
|
-
archived_at: external_exports.string().nullable().optional().meta({
|
|
15564
|
-
description: "ISO 8601 archive timestamp, or null if active."
|
|
15565
|
-
})
|
|
15566
|
-
}).catchall(external_exports.unknown()).meta({ id: "Project" });
|
|
15567
|
-
var ProjectBundleSchema = external_exports.object({
|
|
15568
|
-
schema_version: external_exports.number().int().optional().meta({
|
|
15569
|
-
description: "Bundle Format contract version. Absent means 1 (docs/spec/bundle-format.md \xA7 Schema Versioning). Older versions migrate through an explicit chain; unknown fields from newer versions are preserved on re-export."
|
|
15570
|
-
}),
|
|
15571
|
-
project: ProjectSchema,
|
|
15572
|
-
nodes: external_exports.array(NodeSchema).meta({ description: "All nodes in the project graph." }),
|
|
15573
|
-
edges: external_exports.array(EdgeSchema).meta({ description: "All edges (relationships) between nodes." }),
|
|
15574
|
-
journal: external_exports.array(JournalEventSchema).optional().meta({
|
|
15575
|
-
description: "Optional embedded journal events \u2014 the Level 2 interchange projection (docs/spec/journal.md). Canonical storage in repos is the JSONL sidecar; a bundle without a journal is Level 0/1, not an error."
|
|
15576
|
-
}),
|
|
15577
|
-
quality: QualitySectionSchema.optional().meta({
|
|
15578
|
-
description: "Optional Kritik quality state (docs/rfcs/kritik.md \xA7 4.1) \u2014 the pinned pack version, the project's surface profile, its assessments and findings. Additive: a bundle without it is not an error, and the comparative matrix is derived from it (deriveQualityMatrix), never stored."
|
|
15579
|
-
})
|
|
15580
|
-
}).catchall(external_exports.unknown()).meta({
|
|
15581
|
-
id: "ProjectBundle",
|
|
15582
|
-
title: "Arkaik ProjectBundle",
|
|
15583
|
-
description: "The import/export format for an Arkaik product graph. Contains a project, its nodes (flows, views, data models, API endpoints), and edges (relationships between nodes)."
|
|
15584
|
-
});
|
|
15585
|
-
|
|
15586
|
-
// ../schema/src/products.ts
|
|
15587
|
-
var PRODUCT_MEMBERSHIP_SPECIES = ["flow", "view", "acceptance"];
|
|
15588
|
-
function resolveProducts(project) {
|
|
15589
|
-
const stored = project?.metadata?.products;
|
|
15590
|
-
if (!Array.isArray(stored)) return [];
|
|
15591
|
-
const seen = /* @__PURE__ */ new Set();
|
|
15592
|
-
const products = [];
|
|
15593
|
-
for (const entry of stored) {
|
|
15594
|
-
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
15595
|
-
const candidate = entry;
|
|
15596
|
-
if (typeof candidate.id !== "string" || candidate.id.trim() === "" || seen.has(candidate.id)) continue;
|
|
15597
|
-
seen.add(candidate.id);
|
|
15598
|
-
products.push(candidate);
|
|
15599
|
-
}
|
|
15600
|
-
return products;
|
|
15601
|
-
}
|
|
15602
|
-
|
|
15603
|
-
// ../schema/src/maps.ts
|
|
15604
|
-
var MAP_FLOW_PLATFORMS_MODES = ["rings", "bars"];
|
|
15605
|
-
var MAP_VIEW_PLATFORMS_MODES = ["chips", "rows"];
|
|
15606
|
-
var MAP_MINIMAP_COLOR_MODES = ["status", "species"];
|
|
15607
|
-
var BUILT_IN_MAP_IDS = ["journey", "system"];
|
|
15608
|
-
function isBuiltInMapId(id) {
|
|
15609
|
-
return BUILT_IN_MAP_IDS.includes(id);
|
|
15610
|
-
}
|
|
15611
|
-
|
|
15612
15451
|
// ../schema/src/quality.ts
|
|
15613
15452
|
var asArray = (value) => Array.isArray(value) ? value : [];
|
|
15614
15453
|
var FINDING_SEVERITIES = ["critical", "high", "medium", "low", "info"];
|
|
@@ -15646,6 +15485,18 @@ function mergeKritikLibrary(pack, overlay) {
|
|
|
15646
15485
|
const scales = pack.scales || overlay.scales ? { ...pack.scales ?? {}, ...overlay.scales ?? {} } : void 0;
|
|
15647
15486
|
return { ...pack, domains, criteria, ...scales ? { scales } : {} };
|
|
15648
15487
|
}
|
|
15488
|
+
function applicableCells(library, surfaces) {
|
|
15489
|
+
const selected = surfaces.filter((id) => id !== CROSS_SURFACE_ID);
|
|
15490
|
+
const cells = [];
|
|
15491
|
+
for (const criterion of asArray(library.criteria)) {
|
|
15492
|
+
if (typeof criterion?.id !== "string" || criterion.id === "") continue;
|
|
15493
|
+
if (typeof criterion.superseded_by === "string" && criterion.superseded_by !== "") continue;
|
|
15494
|
+
const appliesTo = Array.isArray(criterion.applies_to) ? criterion.applies_to : void 0;
|
|
15495
|
+
const matched = appliesTo === void 0 ? [...selected] : selected.filter((id) => appliesTo.includes(id));
|
|
15496
|
+
if (matched.length > 0) cells.push({ criterion_id: criterion.id, surfaces: matched });
|
|
15497
|
+
}
|
|
15498
|
+
return cells;
|
|
15499
|
+
}
|
|
15649
15500
|
function bucketsOf(library) {
|
|
15650
15501
|
const stored = library?.scales?.severity_buckets;
|
|
15651
15502
|
const out = { ...DEFAULT_SEVERITY_BUCKETS };
|
|
@@ -15816,79 +15667,1114 @@ function deriveQualityMatrix(bundle, library) {
|
|
|
15816
15667
|
};
|
|
15817
15668
|
}
|
|
15818
15669
|
|
|
15819
|
-
// ../schema/src/
|
|
15820
|
-
var
|
|
15821
|
-
|
|
15822
|
-
|
|
15823
|
-
|
|
15824
|
-
|
|
15825
|
-
if (
|
|
15826
|
-
const
|
|
15827
|
-
const
|
|
15828
|
-
|
|
15829
|
-
}
|
|
15830
|
-
function isIsoDate(value) {
|
|
15831
|
-
return typeof value === "string" && !Number.isNaN(Date.parse(value));
|
|
15670
|
+
// ../schema/src/quality-ops.ts
|
|
15671
|
+
var DEFAULT_TARGET_LEVEL = 3;
|
|
15672
|
+
function upsertAssessment(assessments, next) {
|
|
15673
|
+
const index = assessments.findIndex(
|
|
15674
|
+
(candidate) => candidate.criterion_id === next.criterion_id && candidate.surface === next.surface
|
|
15675
|
+
);
|
|
15676
|
+
if (index === -1) return { assessments: [...assessments, next] };
|
|
15677
|
+
const updated = [...assessments];
|
|
15678
|
+
const replaced = updated[index];
|
|
15679
|
+
updated[index] = next;
|
|
15680
|
+
return { assessments: updated, replaced };
|
|
15832
15681
|
}
|
|
15833
|
-
function
|
|
15834
|
-
const
|
|
15835
|
-
const
|
|
15836
|
-
|
|
15837
|
-
|
|
15838
|
-
|
|
15839
|
-
|
|
15840
|
-
|
|
15841
|
-
};
|
|
15842
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
15843
|
-
error51("", "bundle-shape", "Bundle must be an object with project, nodes, and edges.");
|
|
15844
|
-
return result();
|
|
15845
|
-
}
|
|
15846
|
-
const bundle = input;
|
|
15847
|
-
const project = bundle.project;
|
|
15848
|
-
const nodesRaw = bundle.nodes;
|
|
15849
|
-
const edgesRaw = bundle.edges;
|
|
15850
|
-
if (!project || !nodesRaw || !edgesRaw) {
|
|
15851
|
-
error51("", "bundle-shape", "Missing top-level keys (project, nodes, edges).");
|
|
15852
|
-
return result();
|
|
15853
|
-
}
|
|
15854
|
-
if (!Array.isArray(nodesRaw)) {
|
|
15855
|
-
error51("nodes", "bundle-shape", "nodes must be an array.");
|
|
15856
|
-
return result();
|
|
15857
|
-
}
|
|
15858
|
-
if (!Array.isArray(edgesRaw)) {
|
|
15859
|
-
error51("edges", "bundle-shape", "edges must be an array.");
|
|
15860
|
-
return result();
|
|
15861
|
-
}
|
|
15862
|
-
const nodes = nodesRaw;
|
|
15863
|
-
const edges = edgesRaw;
|
|
15864
|
-
const nodeMap = /* @__PURE__ */ new Map();
|
|
15865
|
-
const nodeIds = /* @__PURE__ */ new Set();
|
|
15866
|
-
if (!project.id) error51("project.id", "project-id-required", "project.id is missing");
|
|
15867
|
-
if (typeof project.title !== "string" || !project.title.trim()) {
|
|
15868
|
-
error51("project.title", "title-non-empty", "project.title is missing or empty");
|
|
15869
|
-
}
|
|
15870
|
-
if (!project.created_at) {
|
|
15871
|
-
error51("project.created_at", "timestamp-required", "project.created_at is missing");
|
|
15682
|
+
function parseSurfaceSpec(spec) {
|
|
15683
|
+
const parts = spec.split(":");
|
|
15684
|
+
const id = (parts[0] ?? "").trim();
|
|
15685
|
+
if (id === "") throw new Error(`--surface needs an id (got "${spec}")`);
|
|
15686
|
+
if (id === CROSS_SURFACE_ID) {
|
|
15687
|
+
throw new Error(
|
|
15688
|
+
`"${CROSS_SURFACE_ID}" is reserved \u2014 it is the contract lens between surfaces. Findings may carry it; it holds no assessments and never becomes a matrix column, so it is not declared here.`
|
|
15689
|
+
);
|
|
15872
15690
|
}
|
|
15873
|
-
if (
|
|
15874
|
-
|
|
15691
|
+
if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(id)) {
|
|
15692
|
+
throw new Error(
|
|
15693
|
+
`surface id "${id}" is not kebab-case \u2014 assessments reference it, so it has to be stable and typo-proof`
|
|
15694
|
+
);
|
|
15875
15695
|
}
|
|
15876
|
-
|
|
15877
|
-
|
|
15696
|
+
const title2 = (parts[1] ?? "").trim() || id;
|
|
15697
|
+
const platform = (parts[2] ?? "").trim();
|
|
15698
|
+
if (platform !== "" && !PLATFORM_IDS.includes(platform)) {
|
|
15699
|
+
throw new Error(
|
|
15700
|
+
`"${platform}" is not an Arkaik platform (${PLATFORM_IDS.join(", ")}). A surface that ships no views simply has none \u2014 leave it off rather than inventing one.`
|
|
15701
|
+
);
|
|
15878
15702
|
}
|
|
15879
|
-
|
|
15880
|
-
|
|
15703
|
+
return platform === "" ? { id, title: title2 } : { id, title: title2, platform };
|
|
15704
|
+
}
|
|
15705
|
+
function domainCodeOf(criterionId, library) {
|
|
15706
|
+
const criterion = (library?.criteria ?? []).find((candidate) => candidate.id === criterionId);
|
|
15707
|
+
if (typeof criterion?.domain === "string" && criterion.domain !== "") return criterion.domain;
|
|
15708
|
+
const dash = criterionId.indexOf("-");
|
|
15709
|
+
return dash > 0 ? criterionId.slice(0, dash) : criterionId;
|
|
15710
|
+
}
|
|
15711
|
+
function mintFindingId(auditId, criterionId, surface, taken, library) {
|
|
15712
|
+
const prefix = `F-${auditId}-${domainCodeOf(criterionId, library)}-${surface}-`;
|
|
15713
|
+
const used = new Set(taken);
|
|
15714
|
+
for (let n = 1; n < 1e3; n++) {
|
|
15715
|
+
const candidate = `${prefix}${String(n).padStart(2, "0")}`;
|
|
15716
|
+
if (!used.has(candidate)) return candidate;
|
|
15881
15717
|
}
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
15885
|
-
|
|
15886
|
-
|
|
15887
|
-
|
|
15888
|
-
|
|
15718
|
+
throw new Error(`Kritik: exhausted finding ids for ${prefix}NN \u2014 999 findings on one cell is a data problem, not a numbering one`);
|
|
15719
|
+
}
|
|
15720
|
+
function upsertFinding(findings, next) {
|
|
15721
|
+
const index = findings.findIndex((candidate) => candidate.id === next.id);
|
|
15722
|
+
if (index === -1) return { findings: [...findings, next] };
|
|
15723
|
+
const updated = [...findings];
|
|
15724
|
+
const replaced = updated[index];
|
|
15725
|
+
updated[index] = next;
|
|
15726
|
+
return { findings: updated, replaced };
|
|
15727
|
+
}
|
|
15728
|
+
function patchFinding(findings, id, patch) {
|
|
15729
|
+
const index = findings.findIndex((candidate) => candidate.id === id);
|
|
15730
|
+
if (index === -1) return { findings: [...findings] };
|
|
15731
|
+
const updated = [...findings];
|
|
15732
|
+
const previous = updated[index];
|
|
15733
|
+
const finding = { ...previous, ...patch };
|
|
15734
|
+
updated[index] = finding;
|
|
15735
|
+
return { findings: updated, finding, previous };
|
|
15736
|
+
}
|
|
15737
|
+
function resolveFinding(findings, id, resolvedBy) {
|
|
15738
|
+
return patchFinding(findings, id, {
|
|
15739
|
+
status: "resolved",
|
|
15740
|
+
...resolvedBy !== void 0 ? { resolved_by: resolvedBy } : {}
|
|
15741
|
+
});
|
|
15742
|
+
}
|
|
15743
|
+
function acceptedDetail(detail, note) {
|
|
15744
|
+
return `${detail}
|
|
15745
|
+
|
|
15746
|
+
Accepted risk: ${note}`.trim();
|
|
15747
|
+
}
|
|
15748
|
+
function acceptFinding(findings, id, note) {
|
|
15749
|
+
const existing = findings.find((candidate) => candidate.id === id);
|
|
15750
|
+
const detail = existing === void 0 ? note : acceptedDetail(existing.detail, note);
|
|
15751
|
+
return patchFinding(findings, id, { status: "accepted-risk", detail });
|
|
15752
|
+
}
|
|
15753
|
+
function fillTemplate(text, values) {
|
|
15754
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => values[key] ?? whole);
|
|
15755
|
+
}
|
|
15756
|
+
function renderIssue(criterion, options) {
|
|
15757
|
+
const { surface, finding, library } = options;
|
|
15758
|
+
const anchors = criterion.level_anchors ?? {};
|
|
15759
|
+
const level = options.level === void 0 || options.level === "" ? "" : String(options.level);
|
|
15760
|
+
const observed = level === "" ? "{observed_level}" : level;
|
|
15761
|
+
const target = options.targetLevel !== void 0 && options.targetLevel !== "" ? String(options.targetLevel) : level === "" ? "{target_level}" : String(Math.min(Number(level) + 1, 4));
|
|
15762
|
+
const values = {
|
|
15763
|
+
surface,
|
|
15764
|
+
observed_level: observed,
|
|
15765
|
+
target_level: target,
|
|
15766
|
+
observed_level_name: anchors[`l${observed}`] ?? "{observed_level_name}",
|
|
15767
|
+
target_level_name: anchors[`l${target}`] ?? "{target_level_name}",
|
|
15768
|
+
target_anchor_text: anchors[`l${target}`] ?? "{target_anchor_text}",
|
|
15769
|
+
impact: String(finding?.impact ?? criterion.default_impact ?? 3)
|
|
15770
|
+
};
|
|
15771
|
+
if (finding !== void 0) {
|
|
15772
|
+
values.likelihood = String(finding.likelihood);
|
|
15773
|
+
values.evidence_bullets_with_file_paths = finding.evidence;
|
|
15774
|
+
values.risk_narrative = finding.detail;
|
|
15775
|
+
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
15776
|
+
values.remediation_step_1 = finding.remediation;
|
|
15777
|
+
}
|
|
15889
15778
|
}
|
|
15890
|
-
|
|
15891
|
-
|
|
15779
|
+
const issue2 = criterion.issue ?? {};
|
|
15780
|
+
const labels = [.../* @__PURE__ */ new Set([...issue2.labels ?? ["quality"], surface])];
|
|
15781
|
+
const body = fillTemplate(issue2.body_skeleton ?? "", values);
|
|
15782
|
+
return {
|
|
15783
|
+
title: fillTemplate(issue2.title_template ?? `[Quality] ${criterion.id} on {surface}`, values),
|
|
15784
|
+
labels,
|
|
15785
|
+
body: finding === void 0 ? body : `${body}
|
|
15786
|
+
${findingFooter(finding, library)}`,
|
|
15787
|
+
...typeof criterion.remediation === "string" && criterion.remediation !== "" ? { remediation: criterion.remediation } : {}
|
|
15788
|
+
};
|
|
15789
|
+
}
|
|
15790
|
+
function findingFooter(finding, library) {
|
|
15791
|
+
const lines = [
|
|
15792
|
+
``,
|
|
15793
|
+
`---`,
|
|
15794
|
+
`<sub>Kritik finding \`${finding.id}\` \u2014 **${severityOf(finding, library)} / ${priorityOf(finding, library)}** (impact ${finding.impact} x likelihood ${finding.likelihood}, cost ${finding.cost})</sub>`,
|
|
15795
|
+
``,
|
|
15796
|
+
`**Evidence**`,
|
|
15797
|
+
finding.evidence
|
|
15798
|
+
];
|
|
15799
|
+
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
15800
|
+
lines.push(``, `**Remediation**`, finding.remediation);
|
|
15801
|
+
}
|
|
15802
|
+
return lines.join("\n");
|
|
15803
|
+
}
|
|
15804
|
+
function signalRunSheet(library, surfaces, filter = {}) {
|
|
15805
|
+
const surfaceIds = surfaces.map((surface) => surface.id).filter((id) => id !== CROSS_SURFACE_ID);
|
|
15806
|
+
const rows = [];
|
|
15807
|
+
for (const criterion of library.criteria ?? []) {
|
|
15808
|
+
if (criterion.superseded_by !== void 0) continue;
|
|
15809
|
+
if (filter.criterion !== void 0 && criterion.id !== filter.criterion) continue;
|
|
15810
|
+
if (filter.domain !== void 0 && criterion.domain !== filter.domain) continue;
|
|
15811
|
+
const signals = criterion.signals ?? [];
|
|
15812
|
+
if (signals.length === 0) continue;
|
|
15813
|
+
const appliesTo = criterion.applies_to;
|
|
15814
|
+
for (const surfaceId of surfaceIds) {
|
|
15815
|
+
if (Array.isArray(appliesTo) && !appliesTo.includes(surfaceId)) continue;
|
|
15816
|
+
if (filter.surface !== void 0 && surfaceId !== filter.surface) continue;
|
|
15817
|
+
signals.forEach((signal, index) => {
|
|
15818
|
+
rows.push({ criterion_id: criterion.id, surface: surfaceId, index, signal });
|
|
15819
|
+
});
|
|
15820
|
+
}
|
|
15821
|
+
}
|
|
15822
|
+
return rows;
|
|
15823
|
+
}
|
|
15824
|
+
function auditCompletedInput(matrix, meta3) {
|
|
15825
|
+
const scores = {};
|
|
15826
|
+
for (const surface of matrix.surfaces) {
|
|
15827
|
+
const bySurface = {};
|
|
15828
|
+
for (const domain2 of matrix.domains) {
|
|
15829
|
+
const cell = matrix.matrix[domain2]?.[surface];
|
|
15830
|
+
if (cell) bySurface[domain2] = cell.score;
|
|
15831
|
+
}
|
|
15832
|
+
scores[surface] = bySurface;
|
|
15833
|
+
}
|
|
15834
|
+
return {
|
|
15835
|
+
type: "quality.audit.completed",
|
|
15836
|
+
payload: {
|
|
15837
|
+
audit_id: meta3.audit_id,
|
|
15838
|
+
framework_version: meta3.framework_version,
|
|
15839
|
+
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
15840
|
+
scores,
|
|
15841
|
+
counts: matrix.finding_counts,
|
|
15842
|
+
...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
|
|
15843
|
+
}
|
|
15844
|
+
};
|
|
15845
|
+
}
|
|
15846
|
+
function findingOpenedInput(finding, library) {
|
|
15847
|
+
return {
|
|
15848
|
+
type: "quality.finding.opened",
|
|
15849
|
+
payload: {
|
|
15850
|
+
finding_id: finding.id,
|
|
15851
|
+
criterion_id: finding.criterion_id,
|
|
15852
|
+
surface: finding.surface,
|
|
15853
|
+
severity: severityOf(finding, library),
|
|
15854
|
+
priority: priorityOf(finding, library),
|
|
15855
|
+
title: finding.title,
|
|
15856
|
+
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {},
|
|
15857
|
+
...finding.issue_url !== void 0 ? { issue_url: finding.issue_url } : {}
|
|
15858
|
+
}
|
|
15859
|
+
};
|
|
15860
|
+
}
|
|
15861
|
+
function findingResolvedInput(finding, resolvedBy) {
|
|
15862
|
+
return {
|
|
15863
|
+
type: "quality.finding.resolved",
|
|
15864
|
+
payload: {
|
|
15865
|
+
finding_id: finding.id,
|
|
15866
|
+
...resolvedBy !== void 0 ? { resolved_by: resolvedBy } : {},
|
|
15867
|
+
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {}
|
|
15868
|
+
}
|
|
15869
|
+
};
|
|
15870
|
+
}
|
|
15871
|
+
function signalTrippedInput(trip) {
|
|
15872
|
+
return {
|
|
15873
|
+
type: "quality.signal.tripped",
|
|
15874
|
+
payload: {
|
|
15875
|
+
criterion_id: trip.criterion_id,
|
|
15876
|
+
surface: trip.surface,
|
|
15877
|
+
signal: trip.signal,
|
|
15878
|
+
...trip.commit !== void 0 ? { commit: trip.commit } : {},
|
|
15879
|
+
...trip.detail !== void 0 ? { detail: trip.detail } : {}
|
|
15880
|
+
}
|
|
15881
|
+
};
|
|
15882
|
+
}
|
|
15883
|
+
|
|
15884
|
+
// ../schema/src/kritik-plan-prompt.ts
|
|
15885
|
+
var THOUSANDS = /\B(?=(\d{3})+(?!\d))/g;
|
|
15886
|
+
var SKILL_STEP = 'Follow the Kritik skill (SKILL.md), section "A planned partial audit". Run it in the repository checkout: a hosted session cannot score a plan part.';
|
|
15887
|
+
var USAGE_READOUT = "this session's usage readout: model, tokens in and out, duration, number of agents.";
|
|
15888
|
+
var SIGNALS_EXIT = "It exits 1 when a signal has tripped since the last recorded audit: that is information for this audit, not an error.";
|
|
15889
|
+
var FINDING_FLAGS = '--title "<one line>" --impact <1-5> --likelihood <1-5> --cost <S|M|L|XL> --evidence "<file:line \u2026>"';
|
|
15890
|
+
function planRecordCommand(planId2) {
|
|
15891
|
+
return `arkaik kritik matrix ${planId2} --record --plan`;
|
|
15892
|
+
}
|
|
15893
|
+
function plural(count, noun) {
|
|
15894
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
15895
|
+
}
|
|
15896
|
+
function tokenCount(value) {
|
|
15897
|
+
return String(Math.round(value)).replace(THOUSANDS, ",");
|
|
15898
|
+
}
|
|
15899
|
+
function dollars(value) {
|
|
15900
|
+
return `$${value.toFixed(2)}`;
|
|
15901
|
+
}
|
|
15902
|
+
function where(commit) {
|
|
15903
|
+
return commit === null ? "not a git checkout" : `commit ${commit}`;
|
|
15904
|
+
}
|
|
15905
|
+
function estimateSentence(tokens, usd, calibrated) {
|
|
15906
|
+
if (tokens === null) return "";
|
|
15907
|
+
const cost = usd === null ? "" : ` (${dollars(usd.low)}\u2013${dollars(usd.high)})`;
|
|
15908
|
+
return ` Estimate: ${tokenCount(tokens.low)}\u2013${tokenCount(tokens.high)} tokens${cost}${calibrated ? "" : ", uncalibrated"}.`;
|
|
15909
|
+
}
|
|
15910
|
+
function scopeSentence(cells, steps) {
|
|
15911
|
+
return `${plural(cells, "cell")}, ${plural(steps, "checklist step")}`;
|
|
15912
|
+
}
|
|
15913
|
+
function partSteps(part, first) {
|
|
15914
|
+
const audit = `--audit ${part.auditId}`;
|
|
15915
|
+
return [
|
|
15916
|
+
`${first}. Get the run sheet: \`arkaik kritik signals --domain ${part.domain} --surface ${part.surface}\`. ${SIGNALS_EXIT}`,
|
|
15917
|
+
`${first + 1}. Score exactly these cells and no others:`,
|
|
15918
|
+
...part.cells.map(
|
|
15919
|
+
(cell) => ` - ${cell.criterion_id} on ${cell.surface}: \`arkaik kritik score ${cell.criterion_id} ${cell.surface} <level> --evidence "<file:line \u2026>" ${audit}\``
|
|
15920
|
+
),
|
|
15921
|
+
`${first + 2}. Open every finding on this part's audit: \`arkaik kritik finding open <criterion> ${part.surface} ${FINDING_FLAGS} ${audit}\`. Give file-and-line evidence, and verify every Critical and High finding adversarially before you open it.`
|
|
15922
|
+
];
|
|
15923
|
+
}
|
|
15924
|
+
function renderPartPrompt(plan, part) {
|
|
15925
|
+
const estimate = part.estimate === null ? "" : estimateSentence(part.estimate.tokens, part.estimate.usd, part.estimate.calibrated);
|
|
15926
|
+
return [
|
|
15927
|
+
`Run part ${part.domain}:${part.surface} of Kritik plan ${plan.planId} in this repo (${where(plan.commit)}).`,
|
|
15928
|
+
`Scope: ${scopeSentence(part.cells.length, part.steps)}.${estimate}`,
|
|
15929
|
+
`Audit id for this part: ${part.auditId}`,
|
|
15930
|
+
"",
|
|
15931
|
+
`1. ${SKILL_STEP}`,
|
|
15932
|
+
...partSteps(part, 2),
|
|
15933
|
+
"5. Do not record this part. The plan is recorded once, after every part is scored, with the plan's own command.",
|
|
15934
|
+
`6. Finish by printing ${USAGE_READOUT}`
|
|
15935
|
+
].join("\n");
|
|
15936
|
+
}
|
|
15937
|
+
function renderPlanPrompt(plan) {
|
|
15938
|
+
const included = plan.parts.filter((part) => part.status === "included");
|
|
15939
|
+
const deferred = plan.parts.filter((part) => part.status === "deferred");
|
|
15940
|
+
const calibrated = included.every((part) => part.estimate?.calibrated === true);
|
|
15941
|
+
const lines = [
|
|
15942
|
+
`Run Kritik plan ${plan.planId} in this repo (${where(plan.commit)}): ${plural(included.length, "part")}, one after the other, in this session.`,
|
|
15943
|
+
`Scope: ${scopeSentence(plan.totals.cells, plan.totals.steps)}, of ${plan.totals.applicableCells} applicable cells.` + estimateSentence(plan.totals.tokens, plan.totals.usd, calibrated),
|
|
15944
|
+
"",
|
|
15945
|
+
`1. ${SKILL_STEP} Do not record a part on its own.`
|
|
15946
|
+
];
|
|
15947
|
+
let step = 2;
|
|
15948
|
+
for (const part of included) {
|
|
15949
|
+
lines.push(
|
|
15950
|
+
"",
|
|
15951
|
+
`Part ${part.domain}:${part.surface}, audit id ${part.auditId} (${scopeSentence(part.cells.length, part.steps)}):`,
|
|
15952
|
+
...partSteps(part, step)
|
|
15953
|
+
);
|
|
15954
|
+
step += 3;
|
|
15955
|
+
}
|
|
15956
|
+
lines.push(
|
|
15957
|
+
"",
|
|
15958
|
+
`${step}. Check that every part is scored: \`arkaik kritik plan --status ${plan.planId}\``,
|
|
15959
|
+
`${step + 1}. Print ${USAGE_READOUT}`,
|
|
15960
|
+
`${step + 2}. When every part is scored, run \`${plan.recordCommand}\``
|
|
15961
|
+
);
|
|
15962
|
+
if (deferred.length > 0) {
|
|
15963
|
+
lines.push(
|
|
15964
|
+
"",
|
|
15965
|
+
"Not in this run (over budget):",
|
|
15966
|
+
...deferred.map((part) => ` - ${part.domain}:${part.surface} (${part.auditId}). Do not score it.`)
|
|
15967
|
+
);
|
|
15968
|
+
}
|
|
15969
|
+
return lines.join("\n");
|
|
15970
|
+
}
|
|
15971
|
+
|
|
15972
|
+
// ../schema/src/quality-plan.ts
|
|
15973
|
+
var KRITIK_PLAN_SCHEMA = "arkaik.kritik.plan/1";
|
|
15974
|
+
var PLAN_PLANS_DIR = "plans";
|
|
15975
|
+
var SCOPED_AUDIT_ID = /-scoped(-\d+)?$/;
|
|
15976
|
+
var PLAN_ID = /^\d{4}-\d{2}-zplan-\d{4}$/;
|
|
15977
|
+
var PLAN_PART_ID = /^\d{4}-\d{2}-zplan-\d{4}-[a-z0-9]{2,5}-.+$/;
|
|
15978
|
+
var PLAN_ID_LENGTH = 18;
|
|
15979
|
+
function planCellKey(criterionId, surface) {
|
|
15980
|
+
return `${criterionId}::${surface}`;
|
|
15981
|
+
}
|
|
15982
|
+
function isScopedAuditId(id) {
|
|
15983
|
+
return typeof id === "string" && SCOPED_AUDIT_ID.test(id);
|
|
15984
|
+
}
|
|
15985
|
+
function isPlanId(id) {
|
|
15986
|
+
return typeof id === "string" && PLAN_ID.test(id);
|
|
15987
|
+
}
|
|
15988
|
+
function isPlanPartId(id) {
|
|
15989
|
+
return typeof id === "string" && PLAN_PART_ID.test(id) && !isScopedAuditId(id);
|
|
15990
|
+
}
|
|
15991
|
+
function planIdOfPartId(id) {
|
|
15992
|
+
return isPlanPartId(id) ? id.slice(0, PLAN_ID_LENGTH) : null;
|
|
15993
|
+
}
|
|
15994
|
+
var RUN_TOKEN = /^([A-Za-z0-9]{2,5}):([A-Za-z0-9_-]+)$/;
|
|
15995
|
+
var PLANNABLE_DOMAIN = /^[A-Z0-9]{2,5}$/;
|
|
15996
|
+
function parseRun(tokens, vocabulary) {
|
|
15997
|
+
if (tokens.length === 0) throw new Error("at least one --run DOMAIN:SURFACE is required");
|
|
15998
|
+
const surfaces = vocabulary.surfaces.filter((id) => id !== CROSS_SURFACE_ID);
|
|
15999
|
+
const plannable = vocabulary.domains.filter((code) => PLANNABLE_DOMAIN.test(code));
|
|
16000
|
+
const unplannable = vocabulary.domains.filter((code) => !PLANNABLE_DOMAIN.test(code));
|
|
16001
|
+
const runs = [];
|
|
16002
|
+
const warnings = [];
|
|
16003
|
+
const tokenBySuffix = /* @__PURE__ */ new Map();
|
|
16004
|
+
for (const token of tokens) {
|
|
16005
|
+
const match = RUN_TOKEN.exec(token);
|
|
16006
|
+
if (match === null) {
|
|
16007
|
+
throw new Error(
|
|
16008
|
+
`--run "${token}" is not DOMAIN:SURFACE \u2014 a domain code of 2 to 5 letters or digits, a colon, then a surface id of letters, digits, "-" or "_" (for example SEC:web).`
|
|
16009
|
+
);
|
|
16010
|
+
}
|
|
16011
|
+
const domain2 = match[1].toUpperCase();
|
|
16012
|
+
const surface = match[2];
|
|
16013
|
+
if (!plannable.includes(domain2)) {
|
|
16014
|
+
throw new Error(
|
|
16015
|
+
`--run "${token}": ${domain2} is not a domain of this library. Domain codes: ${plannable.length > 0 ? plannable.join(", ") : "none that can be planned"}.` + (unplannable.length > 0 ? ` ${unplannable.join(", ")} cannot be planned: a domain code must be 2 to 5 upper-case letters or digits.` : "")
|
|
16016
|
+
);
|
|
16017
|
+
}
|
|
16018
|
+
if (surface === CROSS_SURFACE_ID) {
|
|
16019
|
+
throw new Error(
|
|
16020
|
+
`--run "${token}": ${CROSS_SURFACE_ID} is a lens for findings, not a surface anything is scored on. Plan the surfaces it connects instead.`
|
|
16021
|
+
);
|
|
16022
|
+
}
|
|
16023
|
+
if (!surfaces.includes(surface)) {
|
|
16024
|
+
throw new Error(
|
|
16025
|
+
`--run "${token}": "${surface}" is not a surface of this project's profile. Surfaces: ${surfaces.length > 0 ? surfaces.join(", ") : "none declared"}. A surface must match its id exactly, case included.`
|
|
16026
|
+
);
|
|
16027
|
+
}
|
|
16028
|
+
if (runs.some((run) => run.domain === domain2 && run.surface === surface)) {
|
|
16029
|
+
warnings.push(`--run ${token} repeats ${domain2}:${surface}; the two are one part.`);
|
|
16030
|
+
continue;
|
|
16031
|
+
}
|
|
16032
|
+
const suffix = `${domain2.toLowerCase()}-${surface.toLowerCase()}`;
|
|
16033
|
+
const other = tokenBySuffix.get(suffix);
|
|
16034
|
+
if (other !== void 0) {
|
|
16035
|
+
throw new Error(
|
|
16036
|
+
`--run "${other}" and --run "${token}" name surfaces that differ only by case, so both would score into the one part id "<planId>-${suffix}". Plan one of them, or give the profile's surfaces ids that differ by more than case.`
|
|
16037
|
+
);
|
|
16038
|
+
}
|
|
16039
|
+
tokenBySuffix.set(suffix, token);
|
|
16040
|
+
runs.push({ domain: domain2, surface });
|
|
16041
|
+
}
|
|
16042
|
+
return { runs, warnings };
|
|
16043
|
+
}
|
|
16044
|
+
function planCells(library, surfaces, run) {
|
|
16045
|
+
const byId = /* @__PURE__ */ new Map();
|
|
16046
|
+
for (const criterion of Array.isArray(library.criteria) ? library.criteria : []) {
|
|
16047
|
+
if (typeof criterion?.id === "string" && !byId.has(criterion.id)) byId.set(criterion.id, criterion);
|
|
16048
|
+
}
|
|
16049
|
+
const cells = [];
|
|
16050
|
+
let steps = 0;
|
|
16051
|
+
for (const entry of applicableCells(library, surfaces)) {
|
|
16052
|
+
if (!entry.surfaces.includes(run.surface)) continue;
|
|
16053
|
+
if (domainCodeOf(entry.criterion_id, library) !== run.domain) continue;
|
|
16054
|
+
cells.push({ criterion_id: entry.criterion_id, surface: run.surface });
|
|
16055
|
+
const checklist = byId.get(entry.criterion_id)?.checklist;
|
|
16056
|
+
steps += Array.isArray(checklist) ? checklist.length : 0;
|
|
16057
|
+
}
|
|
16058
|
+
return { cells, steps };
|
|
16059
|
+
}
|
|
16060
|
+
function applicableCellCount(library, surfaces) {
|
|
16061
|
+
let count = 0;
|
|
16062
|
+
for (const entry of applicableCells(library, surfaces)) count += entry.surfaces.length;
|
|
16063
|
+
return count;
|
|
16064
|
+
}
|
|
16065
|
+
function planPartId(planId2, domain2, surface) {
|
|
16066
|
+
const id = `${planId2}-${domain2.toLowerCase()}-${surface.toLowerCase()}`;
|
|
16067
|
+
if (isScopedAuditId(id)) {
|
|
16068
|
+
throw new Error(
|
|
16069
|
+
`the part ${domain2}:${surface} would be named "${id}", which reads as a scoped re-audit. A surface named "scoped", or ending in "-scoped" or "-scoped-NN", cannot be planned.`
|
|
16070
|
+
);
|
|
16071
|
+
}
|
|
16072
|
+
return id;
|
|
16073
|
+
}
|
|
16074
|
+
function planId(input) {
|
|
16075
|
+
const { now, known, runs } = input;
|
|
16076
|
+
if (runs.length === 0) throw new Error("a plan id needs at least one run: with none, no part is checked to sort last");
|
|
16077
|
+
const ids = known.filter((id) => typeof id === "string" && id !== "");
|
|
16078
|
+
const greatest = [...ids].sort().at(-1);
|
|
16079
|
+
const year = String(now.getFullYear()).padStart(4, "0");
|
|
16080
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
16081
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
16082
|
+
for (let n = 0; n < 100; n++) {
|
|
16083
|
+
const candidate = `${year}-${month}-zplan-${day}${String(n).padStart(2, "0")}`;
|
|
16084
|
+
if (ids.some((id) => id === candidate || id.startsWith(`${candidate}-`))) continue;
|
|
16085
|
+
if (greatest !== void 0 && !runs.every((run) => planPartId(candidate, run.domain, run.surface) > greatest)) continue;
|
|
16086
|
+
return candidate;
|
|
16087
|
+
}
|
|
16088
|
+
throw new Error(`no plan id on ${year}-${month}-${day} sorts after "${greatest}"`);
|
|
16089
|
+
}
|
|
16090
|
+
function outsortedBy(partId, known) {
|
|
16091
|
+
const plan = planIdOfPartId(partId);
|
|
16092
|
+
if (plan === null) return [];
|
|
16093
|
+
const after = /* @__PURE__ */ new Set();
|
|
16094
|
+
for (const id of known) {
|
|
16095
|
+
if (typeof id !== "string" || !(id > partId)) continue;
|
|
16096
|
+
if (planIdOfPartId(id) === plan) continue;
|
|
16097
|
+
after.add(id);
|
|
16098
|
+
}
|
|
16099
|
+
return [...after].sort();
|
|
16100
|
+
}
|
|
16101
|
+
var isCount = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
16102
|
+
var nonEmptyStrings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
16103
|
+
function readCoverage(value) {
|
|
16104
|
+
if (typeof value !== "object" || value === null) return null;
|
|
16105
|
+
const row = value;
|
|
16106
|
+
if (!isCount(row.scored) || !isCount(row.assessed) || !isCount(row.applicable)) return null;
|
|
16107
|
+
const surfaces = {};
|
|
16108
|
+
if (typeof row.surfaces === "object" && row.surfaces !== null && !Array.isArray(row.surfaces)) {
|
|
16109
|
+
for (const [surface, entry] of Object.entries(row.surfaces)) {
|
|
16110
|
+
if (surface === "__proto__") continue;
|
|
16111
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
16112
|
+
const { assessed, applicable } = entry;
|
|
16113
|
+
if (isCount(assessed) && isCount(applicable)) surfaces[surface] = { assessed, applicable };
|
|
16114
|
+
}
|
|
16115
|
+
}
|
|
16116
|
+
return { scored: row.scored, assessed: row.assessed, applicable: row.applicable, surfaces };
|
|
16117
|
+
}
|
|
16118
|
+
function readPlanScope(scope) {
|
|
16119
|
+
if (typeof scope !== "object" || scope === null) return null;
|
|
16120
|
+
const row = scope;
|
|
16121
|
+
if (typeof row.plan !== "string" || row.plan === "") return null;
|
|
16122
|
+
return {
|
|
16123
|
+
plan: row.plan,
|
|
16124
|
+
parts: nonEmptyStrings(row.parts),
|
|
16125
|
+
scored: nonEmptyStrings(row.scored),
|
|
16126
|
+
cells: isCount(row.cells) ? row.cells : null,
|
|
16127
|
+
since: typeof row.since === "string" && row.since !== "" ? row.since : null,
|
|
16128
|
+
coverage: readCoverage(row.coverage)
|
|
16129
|
+
};
|
|
16130
|
+
}
|
|
16131
|
+
function buildKritikPlan(input) {
|
|
16132
|
+
const { library, surfaces, runs, known, now, commit } = input;
|
|
16133
|
+
const counted = runs.map((run) => {
|
|
16134
|
+
const { cells, steps } = planCells(library, surfaces, run);
|
|
16135
|
+
if (cells.length === 0) {
|
|
16136
|
+
throw new Error(
|
|
16137
|
+
`no ${run.domain} criterion applies to "${run.surface}" \u2014 every ${run.domain} criterion's applies_to leaves it out, so this part would score nothing.`
|
|
16138
|
+
);
|
|
16139
|
+
}
|
|
16140
|
+
return { run, cells, steps };
|
|
16141
|
+
});
|
|
16142
|
+
const id = planId({ now, known, runs });
|
|
16143
|
+
const parts = counted.map(({ run, cells, steps }) => ({
|
|
16144
|
+
domain: run.domain,
|
|
16145
|
+
surface: run.surface,
|
|
16146
|
+
auditId: planPartId(id, run.domain, run.surface),
|
|
16147
|
+
cells,
|
|
16148
|
+
steps,
|
|
16149
|
+
estimate: null,
|
|
16150
|
+
status: "included"
|
|
16151
|
+
}));
|
|
16152
|
+
const included = parts.filter((part) => part.status === "included");
|
|
16153
|
+
const head = {
|
|
16154
|
+
schema: KRITIK_PLAN_SCHEMA,
|
|
16155
|
+
planId: id,
|
|
16156
|
+
createdAt: now.toISOString(),
|
|
16157
|
+
commit,
|
|
16158
|
+
frameworkVersion: library.version,
|
|
16159
|
+
tier: null,
|
|
16160
|
+
budgetTokens: null,
|
|
16161
|
+
budgetUsd: null,
|
|
16162
|
+
pricePerMTok: null,
|
|
16163
|
+
totals: {
|
|
16164
|
+
cells: included.reduce((sum, part) => sum + part.cells.length, 0),
|
|
16165
|
+
steps: included.reduce((sum, part) => sum + part.steps, 0),
|
|
16166
|
+
applicableCells: applicableCellCount(library, surfaces),
|
|
16167
|
+
tokens: null,
|
|
16168
|
+
usd: null
|
|
16169
|
+
},
|
|
16170
|
+
recordCommand: planRecordCommand(id)
|
|
16171
|
+
};
|
|
16172
|
+
return {
|
|
16173
|
+
schema: head.schema,
|
|
16174
|
+
planId: head.planId,
|
|
16175
|
+
createdAt: head.createdAt,
|
|
16176
|
+
commit: head.commit,
|
|
16177
|
+
frameworkVersion: head.frameworkVersion,
|
|
16178
|
+
tier: head.tier,
|
|
16179
|
+
budgetTokens: head.budgetTokens,
|
|
16180
|
+
budgetUsd: head.budgetUsd,
|
|
16181
|
+
pricePerMTok: head.pricePerMTok,
|
|
16182
|
+
parts: parts.map((part) => ({ ...part, prompt: renderPartPrompt({ planId: id, commit }, part) })),
|
|
16183
|
+
totals: head.totals,
|
|
16184
|
+
prompt: renderPlanPrompt({ ...head, parts }),
|
|
16185
|
+
recordCommand: head.recordCommand
|
|
16186
|
+
};
|
|
16187
|
+
}
|
|
16188
|
+
function planPartStatuses(plan, scoresByPart) {
|
|
16189
|
+
return plan.parts.map((part) => {
|
|
16190
|
+
const planned = new Set(part.cells.map((cell) => planCellKey(cell.criterion_id, cell.surface)));
|
|
16191
|
+
const scoredKeys = /* @__PURE__ */ new Set();
|
|
16192
|
+
const strayKeys = /* @__PURE__ */ new Set();
|
|
16193
|
+
const stray = [];
|
|
16194
|
+
const scores = Object.prototype.hasOwnProperty.call(scoresByPart, part.auditId) ? scoresByPart[part.auditId] : [];
|
|
16195
|
+
for (const score of scores) {
|
|
16196
|
+
const key = planCellKey(score.criterion_id, score.surface);
|
|
16197
|
+
if (planned.has(key)) scoredKeys.add(key);
|
|
16198
|
+
else if (!strayKeys.has(key)) {
|
|
16199
|
+
strayKeys.add(key);
|
|
16200
|
+
stray.push({ criterion_id: score.criterion_id, surface: score.surface });
|
|
16201
|
+
}
|
|
16202
|
+
}
|
|
16203
|
+
const missing = part.cells.filter((cell) => !scoredKeys.has(planCellKey(cell.criterion_id, cell.surface)));
|
|
16204
|
+
const scored = part.cells.length - missing.length;
|
|
16205
|
+
const progress = part.status === "deferred" ? "deferred" : scored === 0 && stray.length === 0 ? "not started" : missing.length === 0 ? "scored" : "in progress";
|
|
16206
|
+
return {
|
|
16207
|
+
auditId: part.auditId,
|
|
16208
|
+
domain: part.domain,
|
|
16209
|
+
surface: part.surface,
|
|
16210
|
+
progress,
|
|
16211
|
+
scored,
|
|
16212
|
+
cells: part.cells.length,
|
|
16213
|
+
missing,
|
|
16214
|
+
stray
|
|
16215
|
+
};
|
|
16216
|
+
});
|
|
16217
|
+
}
|
|
16218
|
+
function coverageOf(section, library, scored = 0) {
|
|
16219
|
+
const assessments = Array.isArray(section.assessments) ? section.assessments : [];
|
|
16220
|
+
const listed = section.profile?.surfaces;
|
|
16221
|
+
const surfaces = [];
|
|
16222
|
+
for (const surface of Array.isArray(listed) ? listed : []) {
|
|
16223
|
+
const id = surface?.id;
|
|
16224
|
+
if (typeof id === "string" && id !== "" && id !== CROSS_SURFACE_ID && !surfaces.includes(id)) surfaces.push(id);
|
|
16225
|
+
}
|
|
16226
|
+
if (surfaces.length === 0) {
|
|
16227
|
+
for (const assessment of assessments) {
|
|
16228
|
+
const id = assessment?.surface;
|
|
16229
|
+
if (typeof id === "string" && id !== "" && id !== CROSS_SURFACE_ID && !surfaces.includes(id)) surfaces.push(id);
|
|
16230
|
+
}
|
|
16231
|
+
}
|
|
16232
|
+
const perSurface = /* @__PURE__ */ new Map();
|
|
16233
|
+
for (const surface of surfaces) perSurface.set(surface, { assessed: 0, applicable: 0 });
|
|
16234
|
+
const applicable = /* @__PURE__ */ new Set();
|
|
16235
|
+
for (const entry of applicableCells(library, surfaces)) {
|
|
16236
|
+
for (const surface of entry.surfaces) {
|
|
16237
|
+
const counts = perSurface.get(surface);
|
|
16238
|
+
if (counts === void 0) continue;
|
|
16239
|
+
applicable.add(planCellKey(entry.criterion_id, surface));
|
|
16240
|
+
counts.applicable++;
|
|
16241
|
+
}
|
|
16242
|
+
}
|
|
16243
|
+
const assessed = /* @__PURE__ */ new Set();
|
|
16244
|
+
for (const assessment of assessments) {
|
|
16245
|
+
if (typeof assessment?.criterion_id !== "string" || typeof assessment?.surface !== "string") continue;
|
|
16246
|
+
const key = planCellKey(assessment.criterion_id, assessment.surface);
|
|
16247
|
+
if (!applicable.has(key) || assessed.has(key)) continue;
|
|
16248
|
+
assessed.add(key);
|
|
16249
|
+
const counts = perSurface.get(assessment.surface);
|
|
16250
|
+
if (counts !== void 0) counts.assessed++;
|
|
16251
|
+
}
|
|
16252
|
+
const bySurface = {};
|
|
16253
|
+
for (const [surface, counts] of perSurface) {
|
|
16254
|
+
if (surface === "__proto__") continue;
|
|
16255
|
+
bySurface[surface] = counts;
|
|
16256
|
+
}
|
|
16257
|
+
return { scored, assessed: assessed.size, applicable: applicable.size, surfaces: bySurface };
|
|
16258
|
+
}
|
|
16259
|
+
function coverageNotes(coverage, overall) {
|
|
16260
|
+
const notes = [];
|
|
16261
|
+
const surfaces = coverage.surfaces ?? {};
|
|
16262
|
+
for (const surface of Object.keys(surfaces)) {
|
|
16263
|
+
const { assessed, applicable } = surfaces[surface];
|
|
16264
|
+
if (!(assessed < applicable)) continue;
|
|
16265
|
+
const score = Object.prototype.hasOwnProperty.call(overall, surface) ? overall[surface] : void 0;
|
|
16266
|
+
notes.push(`${surface} ${typeof score === "number" ? score : "\u2014"}, from ${assessed} of ${applicable} cells`);
|
|
16267
|
+
}
|
|
16268
|
+
return notes;
|
|
16269
|
+
}
|
|
16270
|
+
function auditReadings(auditIds) {
|
|
16271
|
+
const readings = [];
|
|
16272
|
+
const byId = /* @__PURE__ */ new Map();
|
|
16273
|
+
const lastAt = /* @__PURE__ */ new Map();
|
|
16274
|
+
auditIds.forEach((auditId, index) => {
|
|
16275
|
+
const id = planIdOfPartId(auditId) ?? auditId;
|
|
16276
|
+
const existing = byId.get(id);
|
|
16277
|
+
if (existing !== void 0) {
|
|
16278
|
+
existing.auditIds.push(auditId);
|
|
16279
|
+
lastAt.set(existing, index);
|
|
16280
|
+
return;
|
|
16281
|
+
}
|
|
16282
|
+
const reading = { id, auditIds: [auditId] };
|
|
16283
|
+
byId.set(id, reading);
|
|
16284
|
+
lastAt.set(reading, index);
|
|
16285
|
+
readings.push(reading);
|
|
16286
|
+
});
|
|
16287
|
+
return readings.sort((a, b) => (lastAt.get(a) ?? 0) - (lastAt.get(b) ?? 0));
|
|
16288
|
+
}
|
|
16289
|
+
function readingOf(readings, id) {
|
|
16290
|
+
return readings.find((reading) => reading.id === id) ?? readings.find((reading) => reading.auditIds.includes(id));
|
|
16291
|
+
}
|
|
16292
|
+
|
|
16293
|
+
// ../schema/src/quality-schemas.ts
|
|
16294
|
+
var GradeSchema = external_exports.enum(["A", "B", "C", "D", "E"]);
|
|
16295
|
+
var KritikScalesSchema = external_exports.object({
|
|
16296
|
+
grades: external_exports.partialRecord(GradeSchema, external_exports.number()).optional(),
|
|
16297
|
+
severity_buckets: external_exports.partialRecord(external_exports.enum(["critical", "high", "medium", "low", "info"]), external_exports.tuple([external_exports.number(), external_exports.number()])).optional(),
|
|
16298
|
+
caps: external_exports.object({ critical_open: GradeSchema.optional(), high_open: GradeSchema.optional() }).catchall(external_exports.unknown()).optional()
|
|
16299
|
+
}).catchall(external_exports.unknown()).meta({
|
|
16300
|
+
id: "KritikScales",
|
|
16301
|
+
description: "Overridable maturity/severity/grade scales carried by a criteria pack. Absent entries fall back to the framework defaults (packages/kritik-library/SPEC.md \xA7 4)."
|
|
16302
|
+
});
|
|
16303
|
+
var KritikReferenceSchema = external_exports.object({ title: external_exports.string(), anchor: external_exports.string().optional(), url: external_exports.string().optional() }).catchall(external_exports.unknown()).meta({ id: "KritikReference", description: "A stable external anchor behind a criterion (OWASP control, GDPR article, WCAG SC\u2026)." });
|
|
16304
|
+
var KritikIssueTemplateSchema = external_exports.object({
|
|
16305
|
+
title_template: external_exports.string().optional(),
|
|
16306
|
+
labels: external_exports.array(external_exports.string()).optional(),
|
|
16307
|
+
body_skeleton: external_exports.string().optional()
|
|
16308
|
+
}).catchall(external_exports.unknown()).meta({ id: "KritikIssueTemplate", description: "Per-criterion issue skeleton \u2014 what `arkaik kritik issue` prefills." });
|
|
16309
|
+
var KritikDomainSchema = external_exports.object({ code: external_exports.string(), name: external_exports.string(), description: external_exports.string().optional() }).catchall(external_exports.unknown()).meta({ id: "KritikDomain", description: "A top-level criteria category owning a roll-up row in the matrix." });
|
|
16310
|
+
var KritikCriterionSchema = external_exports.object({
|
|
16311
|
+
id: external_exports.string().meta({ description: "Stable identifier, `<DOMAIN>-NN`. Never redefined \u2014 retired via superseded_by." }),
|
|
16312
|
+
domain: external_exports.string(),
|
|
16313
|
+
subcategory: external_exports.string().optional(),
|
|
16314
|
+
name: external_exports.string().optional(),
|
|
16315
|
+
question: external_exports.string().optional(),
|
|
16316
|
+
definition: external_exports.string().optional(),
|
|
16317
|
+
rationale: external_exports.string().optional(),
|
|
16318
|
+
applies_to: external_exports.array(external_exports.string()).optional().meta({ description: "Surface ids where the criterion is meaningful; absence means N/A." }),
|
|
16319
|
+
level_anchors: external_exports.record(external_exports.string(), external_exports.string()).optional().meta({ description: "Observable descriptions per maturity level, keyed l0\u2026l4." }),
|
|
16320
|
+
default_impact: external_exports.number().optional(),
|
|
16321
|
+
weight: external_exports.number().optional().meta({ description: "Weight in the domain roll-up (1\u20133; 3 = load-bearing). Absent means 1." }),
|
|
16322
|
+
references: external_exports.array(KritikReferenceSchema).optional(),
|
|
16323
|
+
checklist: external_exports.array(external_exports.string()).optional(),
|
|
16324
|
+
signals: external_exports.array(external_exports.string()).optional().meta({ description: "Mechanically checkable monitoring hooks run between audits." }),
|
|
16325
|
+
remediation: external_exports.string().optional(),
|
|
16326
|
+
issue: KritikIssueTemplateSchema.optional(),
|
|
16327
|
+
superseded_by: external_exports.string().optional()
|
|
16328
|
+
}).catchall(external_exports.unknown()).meta({ id: "KritikCriterion", description: "The atomic auditable unit (packages/kritik-library/SPEC.md \xA7 5)." });
|
|
16329
|
+
var KritikLibrarySchema = external_exports.object({
|
|
16330
|
+
version: external_exports.string().meta({ description: "Semver of the pack; matrices are comparable only within a major." }),
|
|
16331
|
+
domains: external_exports.array(KritikDomainSchema),
|
|
16332
|
+
criteria: external_exports.array(KritikCriterionSchema),
|
|
16333
|
+
scales: KritikScalesSchema.optional()
|
|
16334
|
+
}).catchall(external_exports.unknown()).meta({
|
|
16335
|
+
id: "KritikLibrary",
|
|
16336
|
+
description: "A versioned criteria pack. Embedded on export; repos may instead pin it as a sidecar file."
|
|
16337
|
+
});
|
|
16338
|
+
var SurfaceDefSchema = external_exports.object({
|
|
16339
|
+
id: external_exports.string(),
|
|
16340
|
+
title: external_exports.string(),
|
|
16341
|
+
platform: PlatformSchema.optional().meta({
|
|
16342
|
+
description: "Optional bridge to PLATFORM_IDS where a surface is also a view-shipping platform. Surfaces are not platforms (RFC \xA7 2)."
|
|
16343
|
+
}),
|
|
16344
|
+
path: external_exports.string().optional()
|
|
16345
|
+
}).catchall(external_exports.unknown()).meta({ id: "SurfaceDef", description: "One independently assessable body of code \u2014 an audit target, chosen at install." });
|
|
16346
|
+
var QualityProfileSchema = external_exports.object({
|
|
16347
|
+
surfaces: external_exports.array(SurfaceDefSchema),
|
|
16348
|
+
domain_weights: external_exports.record(external_exports.string(), external_exports.number()).optional().meta({
|
|
16349
|
+
description: "Per-domain weight in the surface roll-up, keyed by domain code. A missing weight is 1."
|
|
16350
|
+
})
|
|
16351
|
+
}).catchall(external_exports.unknown()).meta({ id: "QualityProfile", description: "The project's parameterization of the pack (RFC \xA7 6)." });
|
|
16352
|
+
var QualityAssessmentSchema = external_exports.object({
|
|
16353
|
+
criterion_id: external_exports.string(),
|
|
16354
|
+
surface: external_exports.string(),
|
|
16355
|
+
level: external_exports.union([external_exports.literal(0), external_exports.literal(1), external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).meta({
|
|
16356
|
+
description: "Maturity 0\u20134. N/A is the absence of the row, never a level."
|
|
16357
|
+
}),
|
|
16358
|
+
evidence: external_exports.string().meta({ description: "file:line / config citations. A score without evidence is an opinion, not an assessment." }),
|
|
16359
|
+
audit_id: external_exports.string(),
|
|
16360
|
+
commit: external_exports.string().optional(),
|
|
16361
|
+
ts: external_exports.string()
|
|
16362
|
+
}).catchall(external_exports.unknown()).meta({ id: "QualityAssessment", description: "One (criterion \xD7 surface) score \u2014 latest wins; history lives in the journal." });
|
|
16363
|
+
var QualityFindingSchema = external_exports.object({
|
|
16364
|
+
id: external_exports.string(),
|
|
16365
|
+
criterion_id: external_exports.string(),
|
|
16366
|
+
surface: external_exports.string(),
|
|
16367
|
+
title: external_exports.string(),
|
|
16368
|
+
detail: external_exports.string(),
|
|
16369
|
+
evidence: external_exports.string(),
|
|
16370
|
+
impact: external_exports.number().meta({ description: "Worst plausible consequence, 1\u20135." }),
|
|
16371
|
+
likelihood: external_exports.number().meta({ description: "Probability it materializes, 1\u20135." }),
|
|
16372
|
+
cost: external_exports.enum(["S", "M", "L", "XL"]),
|
|
16373
|
+
status: external_exports.enum(["open", "resolved", "refuted", "accepted-risk"]),
|
|
16374
|
+
remediation: external_exports.string().optional(),
|
|
16375
|
+
node_ids: external_exports.array(external_exports.string()).optional().meta({ description: "Graph nodes this finding is about \u2014 the tie deliverable.shipped already uses." }),
|
|
16376
|
+
issue_url: external_exports.string().optional(),
|
|
16377
|
+
commit: external_exports.string().optional().meta({
|
|
16378
|
+
description: "Commit SHA anchoring the file:line evidence. Required by policy on any finding written away from a checkout (issue #400 decision 4) \u2014 without it a stale citation is indistinguishable from a wrong one."
|
|
16379
|
+
}),
|
|
16380
|
+
verification: external_exports.object({ verdict: external_exports.enum(["CONFIRMED", "REFUTED", "DOWNGRADED"]), note: external_exports.string().optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Result of the adversarial refutation pass. Refuted findings are disclosed, not deleted." })
|
|
16381
|
+
}).catchall(external_exports.unknown()).meta({
|
|
16382
|
+
id: "QualityFinding",
|
|
16383
|
+
description: "One concrete defect. Severity and priority are deliberately absent \u2014 they are derived from impact \xD7 likelihood and cost (deriveQualityMatrix), so a finding can never carry a severity its own numbers disagree with."
|
|
16384
|
+
});
|
|
16385
|
+
var QualitySectionSchema = external_exports.object({
|
|
16386
|
+
framework_version: external_exports.string(),
|
|
16387
|
+
library: KritikLibrarySchema.optional(),
|
|
16388
|
+
profile: QualityProfileSchema,
|
|
16389
|
+
assessments: external_exports.array(QualityAssessmentSchema),
|
|
16390
|
+
findings: external_exports.array(QualityFindingSchema)
|
|
16391
|
+
}).catchall(external_exports.unknown()).meta({
|
|
16392
|
+
id: "QualitySection",
|
|
16393
|
+
description: "The project's Kritik state (docs/rfcs/kritik.md \xA7 4.1) \u2014 profile, assessments, findings. Criteria are library content, not graph nodes; the matrix is a projection, never stored."
|
|
16394
|
+
});
|
|
16395
|
+
var KritikPlanBandSchema = external_exports.object({
|
|
16396
|
+
low: external_exports.number().nonnegative(),
|
|
16397
|
+
mid: external_exports.number().nonnegative(),
|
|
16398
|
+
high: external_exports.number().nonnegative()
|
|
16399
|
+
});
|
|
16400
|
+
var KritikPlanCellSchema = external_exports.object({ criterion_id: external_exports.string(), surface: external_exports.string() });
|
|
16401
|
+
var KritikPlanPartSchema = external_exports.object({
|
|
16402
|
+
domain: external_exports.string().regex(/^[A-Z0-9]{2,5}$/),
|
|
16403
|
+
surface: external_exports.string().min(1),
|
|
16404
|
+
auditId: external_exports.string(),
|
|
16405
|
+
cells: external_exports.array(KritikPlanCellSchema).min(1),
|
|
16406
|
+
steps: external_exports.number().int().nonnegative(),
|
|
16407
|
+
estimate: external_exports.object({
|
|
16408
|
+
tokens: KritikPlanBandSchema,
|
|
16409
|
+
usd: KritikPlanBandSchema.nullable(),
|
|
16410
|
+
inputs: external_exports.object({
|
|
16411
|
+
P: external_exports.number(),
|
|
16412
|
+
B: external_exports.number(),
|
|
16413
|
+
c: KritikPlanBandSchema,
|
|
16414
|
+
q: KritikPlanBandSchema,
|
|
16415
|
+
h: KritikPlanBandSchema,
|
|
16416
|
+
V: KritikPlanBandSchema
|
|
16417
|
+
}),
|
|
16418
|
+
calibrated: external_exports.boolean()
|
|
16419
|
+
}).nullable(),
|
|
16420
|
+
status: external_exports.enum(["included", "deferred"]),
|
|
16421
|
+
prompt: external_exports.string()
|
|
16422
|
+
});
|
|
16423
|
+
var KritikPlanSchema = external_exports.object({
|
|
16424
|
+
schema: external_exports.literal(KRITIK_PLAN_SCHEMA),
|
|
16425
|
+
planId: external_exports.string(),
|
|
16426
|
+
createdAt: external_exports.iso.datetime(),
|
|
16427
|
+
commit: external_exports.string().nullable(),
|
|
16428
|
+
frameworkVersion: external_exports.string(),
|
|
16429
|
+
tier: external_exports.string().nullable(),
|
|
16430
|
+
budgetTokens: external_exports.number().int().positive().nullable(),
|
|
16431
|
+
budgetUsd: external_exports.number().positive().nullable(),
|
|
16432
|
+
pricePerMTok: external_exports.number().positive().nullable(),
|
|
16433
|
+
parts: external_exports.array(KritikPlanPartSchema).min(1),
|
|
16434
|
+
totals: external_exports.object({
|
|
16435
|
+
cells: external_exports.number().int(),
|
|
16436
|
+
steps: external_exports.number().int(),
|
|
16437
|
+
applicableCells: external_exports.number().int(),
|
|
16438
|
+
tokens: KritikPlanBandSchema.nullable(),
|
|
16439
|
+
usd: KritikPlanBandSchema.nullable()
|
|
16440
|
+
}),
|
|
16441
|
+
prompt: external_exports.string(),
|
|
16442
|
+
recordCommand: external_exports.string()
|
|
16443
|
+
}).superRefine((plan, ctx) => {
|
|
16444
|
+
if (plan.budgetUsd !== null && plan.pricePerMTok === null) {
|
|
16445
|
+
ctx.addIssue({ code: "custom", path: ["pricePerMTok"], message: "required when budgetUsd is set" });
|
|
16446
|
+
}
|
|
16447
|
+
if (!isPlanId(plan.planId)) {
|
|
16448
|
+
ctx.addIssue({ code: "custom", path: ["planId"], message: "not a plan id (YYYY-MM-zplan-DDNN)" });
|
|
16449
|
+
return;
|
|
16450
|
+
}
|
|
16451
|
+
const seen = /* @__PURE__ */ new Map();
|
|
16452
|
+
plan.parts.forEach((part, index) => {
|
|
16453
|
+
let expected;
|
|
16454
|
+
try {
|
|
16455
|
+
expected = planPartId(plan.planId, part.domain, part.surface);
|
|
16456
|
+
} catch {
|
|
16457
|
+
expected = null;
|
|
16458
|
+
}
|
|
16459
|
+
if (part.auditId !== expected) {
|
|
16460
|
+
ctx.addIssue({
|
|
16461
|
+
code: "custom",
|
|
16462
|
+
path: ["parts", index, "auditId"],
|
|
16463
|
+
message: expected === null ? `the surface "${part.surface}" cannot be planned, so no audit id fits this part` : `not this part's audit id: expected "${expected}"`
|
|
16464
|
+
});
|
|
16465
|
+
} else if (seen.has(part.auditId)) {
|
|
16466
|
+
ctx.addIssue({ code: "custom", path: ["parts", index, "auditId"], message: `repeats the audit id of part ${seen.get(part.auditId)}` });
|
|
16467
|
+
} else {
|
|
16468
|
+
seen.set(part.auditId, index);
|
|
16469
|
+
}
|
|
16470
|
+
part.cells.forEach((cell, cellIndex) => {
|
|
16471
|
+
if (cell.surface !== part.surface) {
|
|
16472
|
+
ctx.addIssue({
|
|
16473
|
+
code: "custom",
|
|
16474
|
+
path: ["parts", index, "cells", cellIndex, "surface"],
|
|
16475
|
+
message: `not the part's surface "${part.surface}"`
|
|
16476
|
+
});
|
|
16477
|
+
}
|
|
16478
|
+
});
|
|
16479
|
+
});
|
|
16480
|
+
});
|
|
16481
|
+
function parseKritikPlan(value) {
|
|
16482
|
+
const result = KritikPlanSchema.safeParse(value);
|
|
16483
|
+
if (result.success) return { ok: true, plan: result.data };
|
|
16484
|
+
const first = result.error.issues[0];
|
|
16485
|
+
const path6 = first === void 0 ? "" : first.path.map(String).join(".");
|
|
16486
|
+
return { ok: false, issue: `${path6 === "" ? "(root)" : path6}: ${first?.message ?? "not a plan"}` };
|
|
16487
|
+
}
|
|
16488
|
+
|
|
16489
|
+
// ../schema/src/bundle.ts
|
|
16490
|
+
var PlatformStatusMapSchema = external_exports.partialRecord(
|
|
16491
|
+
PlatformSchema,
|
|
16492
|
+
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
16493
|
+
AnyStatusSchema
|
|
16494
|
+
).meta({ id: "PlatformStatusMap", description: "Per-platform status overrides for view nodes." });
|
|
16495
|
+
var PlatformNotesMapSchema = external_exports.partialRecord(
|
|
16496
|
+
PlatformSchema,
|
|
16497
|
+
external_exports.string()
|
|
16498
|
+
).meta({ id: "PlatformNotesMap", description: "Freeform per-platform notes." });
|
|
16499
|
+
var PlatformScreenshotsMapSchema = external_exports.partialRecord(
|
|
16500
|
+
PlatformSchema,
|
|
16501
|
+
external_exports.string()
|
|
16502
|
+
).meta({
|
|
16503
|
+
id: "PlatformScreenshotsMap",
|
|
16504
|
+
description: "Per-platform screenshot: a relative path, an absolute URL, or a data URI (see docs/spec/bundle-format.md \xA7 Asset Values)."
|
|
16505
|
+
});
|
|
16506
|
+
var PlatformScreenshotMetaSchema = external_exports.object({
|
|
16507
|
+
ts: external_exports.string().optional().meta({ description: "ISO 8601 timestamp of when the current shot was recorded." }),
|
|
16508
|
+
source: external_exports.enum(SCREENSHOT_SOURCES).optional().meta({ description: "Who recorded the current shot: ci or manual." }),
|
|
16509
|
+
form: external_exports.enum(SCREENSHOT_FORMS).optional().meta({ description: "Asset form of the slot value: url, path or data (see Asset Values)." }),
|
|
16510
|
+
commit: external_exports.string().optional().meta({ description: "The sha a CI shot was rendered from." }),
|
|
16511
|
+
order: external_exports.number().int().nonnegative().optional().meta({ description: "That commit's height on the default branch." }),
|
|
16512
|
+
ci_order: external_exports.number().int().nonnegative().optional().meta({ description: "The highest CI order ever accepted for this slot, kept across a manual shot and a removal so a late CI re-run cannot overwrite a newer shot." })
|
|
16513
|
+
}).meta({ id: "PlatformScreenshotMeta", description: "Provenance of the current per-platform screenshot and the CI order watermark." });
|
|
16514
|
+
var PlatformScreenshotMetaMapSchema = external_exports.partialRecord(PlatformSchema, PlatformScreenshotMetaSchema).meta({ id: "PlatformScreenshotMetaMap", description: "Per-platform screenshot provenance (see PlatformScreenshotMeta)." });
|
|
16515
|
+
var RefSchema = external_exports.object({
|
|
16516
|
+
id: external_exports.string().meta({ description: 'Unique within the node, kebab-case (e.g. "gh-142").' }),
|
|
16517
|
+
type: external_exports.string().meta({
|
|
16518
|
+
description: "Ref type: figma | github-issue | gitlab-issue | linear-issue | github-pr | gitlab-mr | url. Unrecognized values are preserved and render as generic links."
|
|
16519
|
+
}),
|
|
16520
|
+
url: external_exports.string().meta({ description: "Canonical external URL." }),
|
|
16521
|
+
title: external_exports.string().optional().meta({ description: "Display label." }),
|
|
16522
|
+
external_status: external_exports.string().optional().meta({
|
|
16523
|
+
description: 'Mirrored external state, verbatim (e.g. "open", "merged", "In Progress").'
|
|
16524
|
+
}),
|
|
16525
|
+
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
16526
|
+
status_mapped: AnyStatusSchema.optional().meta({
|
|
16527
|
+
description: "Optional mapping of external_status into the arkaik lifecycle. Advisory display data \u2014 never mutates node.status."
|
|
16528
|
+
}),
|
|
16529
|
+
platform: PlatformSchema.optional().meta({ description: "Optional scoping to one platform variant." }),
|
|
16530
|
+
synced_at: external_exports.string().optional().meta({ description: "ISO 8601 \u2014 when external_status was last mirrored." })
|
|
16531
|
+
}).meta({ id: "Ref", description: "A typed external reference on a node (docs/spec/bundle-format.md \xA7 References)." });
|
|
16532
|
+
var NodeMetadataSchema = external_exports.object({
|
|
16533
|
+
stage: external_exports.string().optional(),
|
|
16534
|
+
blocked_by: external_exports.string().optional().meta({
|
|
16535
|
+
description: "Non-empty = blocked at the current status. A node id (rendered as a link) or free text naming the dependency."
|
|
16536
|
+
}),
|
|
16537
|
+
playlist: FlowPlaylistSchema.optional(),
|
|
16538
|
+
platformNotes: PlatformNotesMapSchema.optional(),
|
|
16539
|
+
platformStatuses: PlatformStatusMapSchema.optional(),
|
|
16540
|
+
platformScreenshots: PlatformScreenshotsMapSchema.optional(),
|
|
16541
|
+
platformScreenshotMeta: PlatformScreenshotMetaMapSchema.optional(),
|
|
16542
|
+
refs: external_exports.array(RefSchema).optional().meta({ description: "Typed external references on the node." }),
|
|
16543
|
+
gherkin: external_exports.string().optional().meta({
|
|
16544
|
+
description: "Acceptance nodes only: exactly one Given/When/Then scenario (the How). A second scenario is a second acceptance node."
|
|
16545
|
+
}),
|
|
16546
|
+
values: external_exports.array(ValueSchema).optional().meta({
|
|
16547
|
+
description: "Acceptance nodes only: 1..n Bain value elements served (the Why)."
|
|
16548
|
+
}),
|
|
16549
|
+
product: external_exports.string().optional().meta({
|
|
16550
|
+
description: "Product membership (docs/spec/bundle-format.md \xA7 Products); flow, view, and acceptance only."
|
|
16551
|
+
}),
|
|
16552
|
+
decision_status: DecisionStatusSchema.optional().meta({
|
|
16553
|
+
description: "Decision nodes only: proposed | approved | enacted | rejected | deprecated | superseded. The node's lifecycle status is kept in sync (spec \xA72)."
|
|
16554
|
+
}),
|
|
16555
|
+
context: external_exports.string().optional().meta({
|
|
16556
|
+
description: "Decision nodes only: Context \u2014 the Why (markdown)."
|
|
16557
|
+
}),
|
|
16558
|
+
consequences: external_exports.string().optional().meta({
|
|
16559
|
+
description: "Decision nodes only: Consequences \u2014 the How (markdown)."
|
|
16560
|
+
}),
|
|
16561
|
+
decided_at: external_exports.string().optional().meta({
|
|
16562
|
+
description: "Decision nodes only: ISO 8601 date the decision was made."
|
|
16563
|
+
})
|
|
16564
|
+
}).catchall(external_exports.unknown()).meta({ id: "NodeMetadata", description: "Optional metadata for a node." });
|
|
16565
|
+
var NodeSchema = external_exports.object({
|
|
16566
|
+
id: external_exports.string().meta({ description: "Unique node ID. Convention: prefix with species \u2014 F- (flow), V- (view), DM- (data-model), API- (api-endpoint)." }),
|
|
16567
|
+
project_id: external_exports.string().meta({ description: "Must match project.id." }),
|
|
16568
|
+
species: SpeciesSchema,
|
|
16569
|
+
title: external_exports.string().meta({ description: "Human-readable node title." }),
|
|
16570
|
+
description: external_exports.string().optional().meta({ description: "Optional description of the node's purpose." }),
|
|
16571
|
+
// legacy-tolerant: migrateStatusVocabulary normalizes on load
|
|
16572
|
+
status: AnyStatusSchema,
|
|
16573
|
+
platforms: external_exports.array(PlatformSchema).meta({ description: "One or more target platforms." }),
|
|
16574
|
+
metadata: NodeMetadataSchema.optional()
|
|
16575
|
+
}).meta({ id: "Node" });
|
|
16576
|
+
var EdgeSchema = external_exports.object({
|
|
16577
|
+
id: external_exports.string().meta({ description: "Unique edge ID. Convention: e-{source_id}-{target_id}." }),
|
|
16578
|
+
project_id: external_exports.string().meta({ description: "Must match project.id." }),
|
|
16579
|
+
source_id: external_exports.string().meta({ description: "ID of the source node." }),
|
|
16580
|
+
target_id: external_exports.string().meta({ description: "ID of the target node." }),
|
|
16581
|
+
edge_type: EdgeTypeSchema,
|
|
16582
|
+
metadata: external_exports.record(external_exports.string(), external_exports.unknown()).optional().meta({ description: "Optional edge metadata." })
|
|
16583
|
+
}).meta({ id: "Edge" });
|
|
16584
|
+
var MapDisplayOptionsSchema = external_exports.object({
|
|
16585
|
+
images: external_exports.boolean().optional().meta({ description: "Screenshot (or cover) art on view cards." }),
|
|
16586
|
+
flow_platforms: external_exports.string().optional().meta({
|
|
16587
|
+
description: "A flow card's platform delivery: rings (default) | bars."
|
|
16588
|
+
}),
|
|
16589
|
+
view_platforms: external_exports.string().optional().meta({
|
|
16590
|
+
description: "A view card's platform availability: chips (default) | rows."
|
|
16591
|
+
}),
|
|
16592
|
+
minimap_color: external_exports.string().optional().meta({
|
|
16593
|
+
description: "What a minimap node's fill encodes: status (default) | species."
|
|
16594
|
+
})
|
|
16595
|
+
}).catchall(external_exports.unknown()).meta({ id: "MapDisplayOptions", description: "How a map draws its cards (docs/spec/maps.md \xA7 Display Options)." });
|
|
16596
|
+
var MapDefinitionSchema = external_exports.object({
|
|
16597
|
+
id: external_exports.string().meta({
|
|
16598
|
+
description: "Kebab-case, unique within the project; built-in ids (journey, system, screens) are reserved."
|
|
16599
|
+
}),
|
|
16600
|
+
title: external_exports.string().meta({ description: "Display title." }),
|
|
16601
|
+
description: external_exports.string().optional().meta({ description: "What this map is for." }),
|
|
16602
|
+
kind: external_exports.string().meta({
|
|
16603
|
+
description: "Map kind: journey | system | screens. Selects the renderer and selection defaults; unrecognized kinds are preserved and listed as unrenderable."
|
|
16604
|
+
}),
|
|
16605
|
+
species: external_exports.array(external_exports.string()).optional().meta({
|
|
16606
|
+
description: "Node filter; defaults by kind (journey: flow+view; system: view+api-endpoint+data-model; screens: flow+view)."
|
|
16607
|
+
}),
|
|
16608
|
+
edge_types: external_exports.array(external_exports.string()).optional().meta({
|
|
16609
|
+
description: "Edge filter; defaults by kind (journey: composes; system: calls+displays+queries; screens: none)."
|
|
16610
|
+
}),
|
|
16611
|
+
root_node_id: external_exports.string().optional().meta({
|
|
16612
|
+
description: "Scope anchor: the subgraph is the undirected neighborhood reachable from this node."
|
|
16613
|
+
}),
|
|
16614
|
+
product: external_exports.string().optional().meta({ description: "Product scope; absent = every product." }),
|
|
16615
|
+
depth: external_exports.number().optional().meta({ description: "Traversal bound from the root; absent = unbounded." }),
|
|
16616
|
+
layout: external_exports.object({ direction: external_exports.string().optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Renderer layout hints (e.g. direction: DOWN | RIGHT)." }),
|
|
16617
|
+
display: MapDisplayOptionsSchema.optional().meta({
|
|
16618
|
+
description: "Card rendering; the human twin is project.metadata.map_display[id]."
|
|
16619
|
+
})
|
|
16620
|
+
}).catchall(external_exports.unknown()).meta({ id: "MapDefinition", description: "A stored map definition (docs/spec/maps.md \xA7 MapDefinition)." });
|
|
16621
|
+
var ProductDefinitionSchema = external_exports.object({
|
|
16622
|
+
id: external_exports.string().meta({ description: "Kebab-case, unique within the project." }),
|
|
16623
|
+
title: external_exports.string().meta({ description: "Display title." }),
|
|
16624
|
+
description: external_exports.string().optional().meta({ description: "What this product is." }),
|
|
16625
|
+
platforms: external_exports.array(PlatformSchema).meta({
|
|
16626
|
+
description: "The platforms this product can ship on; empty means availability is not tracked."
|
|
16627
|
+
}),
|
|
16628
|
+
root_node_id: external_exports.string().optional().meta({ description: "This product's journey anchor." })
|
|
16629
|
+
}).catchall(external_exports.unknown()).meta({ id: "ProductDefinition", description: "A product definition (docs/spec/bundle-format.md \xA7 Products)." });
|
|
16630
|
+
var ProjectMetadataSchema = external_exports.object({
|
|
16631
|
+
view_card_variant: external_exports.enum(["compact", "large"]).optional(),
|
|
16632
|
+
maps: external_exports.array(MapDefinitionSchema).optional().meta({
|
|
16633
|
+
description: "Stored map definitions (docs/spec/maps.md \xA7 Storage) \u2014 additive; unknown fields preserved."
|
|
16634
|
+
}),
|
|
16635
|
+
map_display: external_exports.record(external_exports.string(), MapDisplayOptionsSchema).optional().meta({
|
|
16636
|
+
description: "Per-map display overrides keyed by map id (docs/spec/maps.md \xA7 Display Options) \u2014 the only path open to the built-in maps."
|
|
16637
|
+
}),
|
|
16638
|
+
products: external_exports.array(ProductDefinitionSchema).optional().meta({
|
|
16639
|
+
description: "Product definitions (docs/spec/bundle-format.md \xA7 Products) \u2014 additive; unknown fields preserved."
|
|
16640
|
+
}),
|
|
16641
|
+
pollen: external_exports.object({ plant: external_exports.string().regex(/^[a-z0-9][a-z0-9-]*$/).optional() }).catchall(external_exports.unknown()).optional().meta({ description: "Federation settings \u2014 docs/spec/services.md \xA7 Pollen feed. `plant` enables the feed." })
|
|
16642
|
+
}).catchall(external_exports.unknown()).meta({ id: "ProjectMetadata", description: "Optional project-level UI settings." });
|
|
16643
|
+
var ProjectSchema = external_exports.object({
|
|
16644
|
+
id: external_exports.string().meta({ description: "Unique project identifier." }),
|
|
16645
|
+
title: external_exports.string().meta({ description: "Project title." }),
|
|
16646
|
+
description: external_exports.string().optional().meta({ description: "Optional project description." }),
|
|
16647
|
+
version: external_exports.string().optional().meta({
|
|
16648
|
+
description: "Current version label of the mapped product (free-form; semver recommended, not required). Version history lives in the journal as release.tagged events."
|
|
16649
|
+
}),
|
|
16650
|
+
root_node_id: external_exports.string().optional().meta({
|
|
16651
|
+
description: "ID of the root node used as the canvas entry point. Should reference an existing node."
|
|
16652
|
+
}),
|
|
16653
|
+
metadata: ProjectMetadataSchema.optional(),
|
|
16654
|
+
created_at: external_exports.string().meta({ description: "ISO 8601 creation timestamp." }),
|
|
16655
|
+
updated_at: external_exports.string().meta({ description: "ISO 8601 last-update timestamp." }),
|
|
16656
|
+
archived_at: external_exports.string().nullable().optional().meta({
|
|
16657
|
+
description: "ISO 8601 archive timestamp, or null if active."
|
|
16658
|
+
})
|
|
16659
|
+
}).catchall(external_exports.unknown()).meta({ id: "Project" });
|
|
16660
|
+
var ProjectBundleSchema = external_exports.object({
|
|
16661
|
+
schema_version: external_exports.number().int().optional().meta({
|
|
16662
|
+
description: "Bundle Format contract version. Absent means 1 (docs/spec/bundle-format.md \xA7 Schema Versioning). Older versions migrate through an explicit chain; unknown fields from newer versions are preserved on re-export."
|
|
16663
|
+
}),
|
|
16664
|
+
project: ProjectSchema,
|
|
16665
|
+
nodes: external_exports.array(NodeSchema).meta({ description: "All nodes in the project graph." }),
|
|
16666
|
+
edges: external_exports.array(EdgeSchema).meta({ description: "All edges (relationships) between nodes." }),
|
|
16667
|
+
journal: external_exports.array(JournalEventSchema).optional().meta({
|
|
16668
|
+
description: "Optional embedded journal events \u2014 the Level 2 interchange projection (docs/spec/journal.md). Canonical storage in repos is the JSONL sidecar; a bundle without a journal is Level 0/1, not an error."
|
|
16669
|
+
}),
|
|
16670
|
+
quality: QualitySectionSchema.optional().meta({
|
|
16671
|
+
description: "Optional Kritik quality state (docs/rfcs/kritik.md \xA7 4.1) \u2014 the pinned pack version, the project's surface profile, its assessments and findings. Additive: a bundle without it is not an error, and the comparative matrix is derived from it (deriveQualityMatrix), never stored."
|
|
16672
|
+
})
|
|
16673
|
+
}).catchall(external_exports.unknown()).meta({
|
|
16674
|
+
id: "ProjectBundle",
|
|
16675
|
+
title: "Arkaik ProjectBundle",
|
|
16676
|
+
description: "The import/export format for an Arkaik product graph. Contains a project, its nodes (flows, views, data models, API endpoints), and edges (relationships between nodes)."
|
|
16677
|
+
});
|
|
16678
|
+
|
|
16679
|
+
// ../schema/src/products.ts
|
|
16680
|
+
var PRODUCT_MEMBERSHIP_SPECIES = ["flow", "view", "acceptance"];
|
|
16681
|
+
function resolveProducts(project) {
|
|
16682
|
+
const stored = project?.metadata?.products;
|
|
16683
|
+
if (!Array.isArray(stored)) return [];
|
|
16684
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16685
|
+
const products = [];
|
|
16686
|
+
for (const entry of stored) {
|
|
16687
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
16688
|
+
const candidate = entry;
|
|
16689
|
+
if (typeof candidate.id !== "string" || candidate.id.trim() === "" || seen.has(candidate.id)) continue;
|
|
16690
|
+
seen.add(candidate.id);
|
|
16691
|
+
products.push(candidate);
|
|
16692
|
+
}
|
|
16693
|
+
return products;
|
|
16694
|
+
}
|
|
16695
|
+
|
|
16696
|
+
// ../schema/src/maps.ts
|
|
16697
|
+
var MAP_FLOW_PLATFORMS_MODES = ["rings", "bars"];
|
|
16698
|
+
var MAP_VIEW_PLATFORMS_MODES = ["chips", "rows"];
|
|
16699
|
+
var MAP_MINIMAP_COLOR_MODES = ["status", "species"];
|
|
16700
|
+
var BUILT_IN_MAP_IDS = ["journey", "system", "screens"];
|
|
16701
|
+
function isBuiltInMapId(id) {
|
|
16702
|
+
return BUILT_IN_MAP_IDS.includes(id);
|
|
16703
|
+
}
|
|
16704
|
+
|
|
16705
|
+
// ../schema/src/validate.ts
|
|
16706
|
+
var VALID_STAGES = ["beta", "monitoring", "deprecated"];
|
|
16707
|
+
var VALID_VIEW_CARD_VARIANTS = ["compact", "large"];
|
|
16708
|
+
var MAX_SCREENSHOT_DATA_URI_BYTES = 2 * 1024 * 1024;
|
|
16709
|
+
function estimateDataUriBytes(dataUri) {
|
|
16710
|
+
const comma = dataUri.indexOf(",");
|
|
16711
|
+
if (comma === -1) return 0;
|
|
16712
|
+
const payload = dataUri.slice(comma + 1);
|
|
16713
|
+
const padding = payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0;
|
|
16714
|
+
return Math.floor(payload.length * 3 / 4) - padding;
|
|
16715
|
+
}
|
|
16716
|
+
function isIsoDate(value) {
|
|
16717
|
+
return typeof value === "string" && !Number.isNaN(Date.parse(value));
|
|
16718
|
+
}
|
|
16719
|
+
function validateBundle(input) {
|
|
16720
|
+
const findings = [];
|
|
16721
|
+
const error51 = (path6, rule, message) => findings.push({ path: path6, rule, message, severity: "error" });
|
|
16722
|
+
const warn = (path6, rule, message) => findings.push({ path: path6, rule, message, severity: "warning" });
|
|
16723
|
+
const result = () => {
|
|
16724
|
+
const errors = findings.filter((f) => f.severity === "error");
|
|
16725
|
+
const warnings = findings.filter((f) => f.severity === "warning");
|
|
16726
|
+
return { valid: errors.length === 0, findings, errors, warnings };
|
|
16727
|
+
};
|
|
16728
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
16729
|
+
error51("", "bundle-shape", "Bundle must be an object with project, nodes, and edges.");
|
|
16730
|
+
return result();
|
|
16731
|
+
}
|
|
16732
|
+
const bundle = input;
|
|
16733
|
+
const project = bundle.project;
|
|
16734
|
+
const nodesRaw = bundle.nodes;
|
|
16735
|
+
const edgesRaw = bundle.edges;
|
|
16736
|
+
if (!project || !nodesRaw || !edgesRaw) {
|
|
16737
|
+
error51("", "bundle-shape", "Missing top-level keys (project, nodes, edges).");
|
|
16738
|
+
return result();
|
|
16739
|
+
}
|
|
16740
|
+
if (!Array.isArray(nodesRaw)) {
|
|
16741
|
+
error51("nodes", "bundle-shape", "nodes must be an array.");
|
|
16742
|
+
return result();
|
|
16743
|
+
}
|
|
16744
|
+
if (!Array.isArray(edgesRaw)) {
|
|
16745
|
+
error51("edges", "bundle-shape", "edges must be an array.");
|
|
16746
|
+
return result();
|
|
16747
|
+
}
|
|
16748
|
+
const nodes = nodesRaw;
|
|
16749
|
+
const edges = edgesRaw;
|
|
16750
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
16751
|
+
const nodeIds = /* @__PURE__ */ new Set();
|
|
16752
|
+
if (!project.id) error51("project.id", "project-id-required", "project.id is missing");
|
|
16753
|
+
if (typeof project.title !== "string" || !project.title.trim()) {
|
|
16754
|
+
error51("project.title", "title-non-empty", "project.title is missing or empty");
|
|
16755
|
+
}
|
|
16756
|
+
if (!project.created_at) {
|
|
16757
|
+
error51("project.created_at", "timestamp-required", "project.created_at is missing");
|
|
16758
|
+
}
|
|
16759
|
+
if (!project.updated_at) {
|
|
16760
|
+
error51("project.updated_at", "timestamp-required", "project.updated_at is missing");
|
|
16761
|
+
}
|
|
16762
|
+
if (project.created_at && !isIsoDate(project.created_at)) {
|
|
16763
|
+
warn("project.created_at", "iso-timestamp", "project.created_at is not a valid ISO 8601 timestamp");
|
|
16764
|
+
}
|
|
16765
|
+
if (project.updated_at && !isIsoDate(project.updated_at)) {
|
|
16766
|
+
warn("project.updated_at", "iso-timestamp", "project.updated_at is not a valid ISO 8601 timestamp");
|
|
16767
|
+
}
|
|
16768
|
+
const projectMetadata = project.metadata;
|
|
16769
|
+
if (projectMetadata && projectMetadata.view_card_variant !== void 0 && !VALID_VIEW_CARD_VARIANTS.includes(projectMetadata.view_card_variant)) {
|
|
16770
|
+
error51(
|
|
16771
|
+
"project.metadata.view_card_variant",
|
|
16772
|
+
"view-card-variant",
|
|
16773
|
+
`project.metadata.view_card_variant must be one of ${VALID_VIEW_CARD_VARIANTS.join(", ")} (import rejects other values)`
|
|
16774
|
+
);
|
|
16775
|
+
}
|
|
16776
|
+
nodes.forEach((node, i) => {
|
|
16777
|
+
const base = `nodes[${i}]`;
|
|
15892
16778
|
const nodeId = node.id;
|
|
15893
16779
|
if (nodeIds.has(nodeId)) {
|
|
15894
16780
|
error51(`${base}.id`, "duplicate-node-id", `Duplicate node ID: ${nodeId}`);
|
|
@@ -16894,7 +17780,7 @@ function computeDeliverables(events) {
|
|
|
16894
17780
|
return null;
|
|
16895
17781
|
};
|
|
16896
17782
|
const out = [];
|
|
16897
|
-
for (const [id,
|
|
17783
|
+
for (const [id, anchorIndex2] of firstIndex) {
|
|
16898
17784
|
const ev = latest.get(id);
|
|
16899
17785
|
if (ev === void 0) continue;
|
|
16900
17786
|
const summary = asString(ev.summary);
|
|
@@ -16907,8 +17793,8 @@ function computeDeliverables(events) {
|
|
|
16907
17793
|
...url2 !== void 0 ? { url: url2 } : {},
|
|
16908
17794
|
node_ids: Array.isArray(ev.node_ids) ? ev.node_ids.filter((n) => typeof n === "string") : [],
|
|
16909
17795
|
...platform !== void 0 ? { platform } : {},
|
|
16910
|
-
ts: asString(ordered[
|
|
16911
|
-
releaseVersion: releaseOf(
|
|
17796
|
+
ts: asString(ordered[anchorIndex2].ts) ?? "",
|
|
17797
|
+
releaseVersion: releaseOf(anchorIndex2)
|
|
16912
17798
|
});
|
|
16913
17799
|
}
|
|
16914
17800
|
return out;
|
|
@@ -16941,33 +17827,426 @@ function incrementSymbols(symbols) {
|
|
|
16941
17827
|
out[i] += 1;
|
|
16942
17828
|
return out;
|
|
16943
17829
|
}
|
|
16944
|
-
out[i] = 0;
|
|
16945
|
-
}
|
|
16946
|
-
return randomSymbols(RANDOM_LEN);
|
|
16947
|
-
}
|
|
16948
|
-
var lastTime = -1;
|
|
16949
|
-
var lastRandom = [];
|
|
16950
|
-
function ulid3(seedTime = Date.now()) {
|
|
16951
|
-
if (seedTime > lastTime) {
|
|
16952
|
-
lastTime = seedTime;
|
|
16953
|
-
lastRandom = randomSymbols(RANDOM_LEN);
|
|
16954
|
-
} else {
|
|
16955
|
-
lastRandom = incrementSymbols(lastRandom);
|
|
17830
|
+
out[i] = 0;
|
|
17831
|
+
}
|
|
17832
|
+
return randomSymbols(RANDOM_LEN);
|
|
17833
|
+
}
|
|
17834
|
+
var lastTime = -1;
|
|
17835
|
+
var lastRandom = [];
|
|
17836
|
+
function ulid3(seedTime = Date.now()) {
|
|
17837
|
+
if (seedTime > lastTime) {
|
|
17838
|
+
lastTime = seedTime;
|
|
17839
|
+
lastRandom = randomSymbols(RANDOM_LEN);
|
|
17840
|
+
} else {
|
|
17841
|
+
lastRandom = incrementSymbols(lastRandom);
|
|
17842
|
+
}
|
|
17843
|
+
return encodeTime(lastTime, TIME_LEN) + lastRandom.map((s) => ENCODING[s]).join("");
|
|
17844
|
+
}
|
|
17845
|
+
function makeEvent(type, payload = {}, options = {}) {
|
|
17846
|
+
const ts = options.ts instanceof Date ? options.ts.toISOString() : options.ts ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
17847
|
+
const id = options.id ?? ulid3();
|
|
17848
|
+
const event = {
|
|
17849
|
+
id,
|
|
17850
|
+
ts,
|
|
17851
|
+
...options.actor !== void 0 ? { actor: options.actor } : {},
|
|
17852
|
+
type,
|
|
17853
|
+
...payload
|
|
17854
|
+
};
|
|
17855
|
+
const schema = JOURNAL_EVENT_SCHEMAS[type] ?? JournalEventSchema;
|
|
17856
|
+
return schema.parse(event);
|
|
17857
|
+
}
|
|
17858
|
+
|
|
17859
|
+
// ../schema/src/derive.ts
|
|
17860
|
+
function toJournalEvents(inputs, actor) {
|
|
17861
|
+
return inputs.map((input) => makeEvent(input.type, input.payload, { actor }));
|
|
17862
|
+
}
|
|
17863
|
+
function nodeCreatedInput(node) {
|
|
17864
|
+
return {
|
|
17865
|
+
type: "node.created",
|
|
17866
|
+
payload: { node_id: node.id, species: node.species, title: node.title }
|
|
17867
|
+
};
|
|
17868
|
+
}
|
|
17869
|
+
function nodeDeletedInput(nodeId) {
|
|
17870
|
+
return { type: "node.deleted", payload: { node_id: nodeId } };
|
|
17871
|
+
}
|
|
17872
|
+
function edgeAddedInput(edge) {
|
|
17873
|
+
return {
|
|
17874
|
+
type: "edge.added",
|
|
17875
|
+
payload: {
|
|
17876
|
+
edge_id: edge.id,
|
|
17877
|
+
source_id: edge.source_id,
|
|
17878
|
+
target_id: edge.target_id,
|
|
17879
|
+
edge_type: edge.edge_type
|
|
17880
|
+
}
|
|
17881
|
+
};
|
|
17882
|
+
}
|
|
17883
|
+
function edgeRemovedInput(edgeId2) {
|
|
17884
|
+
return { type: "edge.removed", payload: { edge_id: edgeId2 } };
|
|
17885
|
+
}
|
|
17886
|
+
var TOP_LEVEL_FIELDS = ["species", "title", "description", "status", "platforms"];
|
|
17887
|
+
var MAX_SCALAR_LEN = 512;
|
|
17888
|
+
function isRecord3(value) {
|
|
17889
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17890
|
+
}
|
|
17891
|
+
function isShortScalar(value) {
|
|
17892
|
+
if (typeof value === "number" || typeof value === "boolean") return true;
|
|
17893
|
+
return typeof value === "string" && value.length <= MAX_SCALAR_LEN;
|
|
17894
|
+
}
|
|
17895
|
+
function valueEqual(a, b) {
|
|
17896
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
17897
|
+
}
|
|
17898
|
+
function changedMapKeys(prev, next) {
|
|
17899
|
+
const p = isRecord3(prev) ? prev : {};
|
|
17900
|
+
const n = isRecord3(next) ? next : {};
|
|
17901
|
+
const changed = [];
|
|
17902
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(p), ...Object.keys(n)])) {
|
|
17903
|
+
if (!valueEqual(p[key], n[key])) changed.push(key);
|
|
17904
|
+
}
|
|
17905
|
+
return changed.sort();
|
|
17906
|
+
}
|
|
17907
|
+
function diffPlatformStatuses(nodeId, currentBase, nextBase, prev, next) {
|
|
17908
|
+
const p = isRecord3(prev) ? prev : {};
|
|
17909
|
+
const n = isRecord3(next) ? next : {};
|
|
17910
|
+
const events = [];
|
|
17911
|
+
for (const platform of [.../* @__PURE__ */ new Set([...Object.keys(p), ...Object.keys(n)])].sort()) {
|
|
17912
|
+
const from = p[platform];
|
|
17913
|
+
const to = n[platform];
|
|
17914
|
+
if (valueEqual(from, to)) continue;
|
|
17915
|
+
events.push({
|
|
17916
|
+
type: "node.status_changed",
|
|
17917
|
+
payload: {
|
|
17918
|
+
node_id: nodeId,
|
|
17919
|
+
from: from ?? currentBase,
|
|
17920
|
+
to: to ?? nextBase,
|
|
17921
|
+
platform
|
|
17922
|
+
}
|
|
17923
|
+
});
|
|
17924
|
+
}
|
|
17925
|
+
return events;
|
|
17926
|
+
}
|
|
17927
|
+
function diffRefs(nodeId, prev, next) {
|
|
17928
|
+
const prevArr = Array.isArray(prev) ? prev : [];
|
|
17929
|
+
const nextArr = Array.isArray(next) ? next : [];
|
|
17930
|
+
const byId = (arr) => {
|
|
17931
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
17932
|
+
for (const item of arr) {
|
|
17933
|
+
if (isRecord3(item) && typeof item.id === "string") map2.set(item.id, item);
|
|
17934
|
+
}
|
|
17935
|
+
return map2;
|
|
17936
|
+
};
|
|
17937
|
+
const prevById = byId(prevArr);
|
|
17938
|
+
const nextById = byId(nextArr);
|
|
17939
|
+
const events = [];
|
|
17940
|
+
for (const [id, ref] of nextById) {
|
|
17941
|
+
if (!prevById.has(id)) {
|
|
17942
|
+
events.push({
|
|
17943
|
+
type: "ref.added",
|
|
17944
|
+
payload: { node_id: nodeId, ref_id: id, ref_type: ref.type, url: ref.url }
|
|
17945
|
+
});
|
|
17946
|
+
}
|
|
17947
|
+
}
|
|
17948
|
+
for (const id of prevById.keys()) {
|
|
17949
|
+
if (!nextById.has(id)) {
|
|
17950
|
+
events.push({ type: "ref.removed", payload: { node_id: nodeId, ref_id: id } });
|
|
17951
|
+
}
|
|
17952
|
+
}
|
|
17953
|
+
return events;
|
|
17954
|
+
}
|
|
17955
|
+
function diffNodeUpdate(current, patch) {
|
|
17956
|
+
const events = [];
|
|
17957
|
+
const nodeId = current.id;
|
|
17958
|
+
const changedPaths = [];
|
|
17959
|
+
const cur = current;
|
|
17960
|
+
const pat = patch;
|
|
17961
|
+
for (const field of TOP_LEVEL_FIELDS) {
|
|
17962
|
+
if (!(field in pat)) continue;
|
|
17963
|
+
const prev = cur[field];
|
|
17964
|
+
const nextVal = pat[field];
|
|
17965
|
+
if (valueEqual(prev, nextVal)) continue;
|
|
17966
|
+
if (field === "status") {
|
|
17967
|
+
events.push({ type: "node.status_changed", payload: { node_id: nodeId, from: prev, to: nextVal } });
|
|
17968
|
+
} else {
|
|
17969
|
+
changedPaths.push(field);
|
|
17970
|
+
}
|
|
17971
|
+
}
|
|
17972
|
+
if ("metadata" in pat) {
|
|
17973
|
+
const prevMeta = isRecord3(current.metadata) ? current.metadata : {};
|
|
17974
|
+
const nextMeta = isRecord3(patch.metadata) ? patch.metadata : {};
|
|
17975
|
+
const currentBase = current.status;
|
|
17976
|
+
const nextBase = "status" in pat && pat.status !== void 0 ? pat.status : current.status;
|
|
17977
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(prevMeta), ...Object.keys(nextMeta)])) {
|
|
17978
|
+
if (key === "platformStatuses") {
|
|
17979
|
+
events.push(...diffPlatformStatuses(nodeId, currentBase, nextBase, prevMeta[key], nextMeta[key]));
|
|
17980
|
+
} else if (key === "refs") {
|
|
17981
|
+
events.push(...diffRefs(nodeId, prevMeta[key], nextMeta[key]));
|
|
17982
|
+
} else if (key === "platformScreenshots" || key === "platformNotes") {
|
|
17983
|
+
for (const platform of changedMapKeys(prevMeta[key], nextMeta[key])) {
|
|
17984
|
+
changedPaths.push(`metadata.${key}.${platform}`);
|
|
17985
|
+
}
|
|
17986
|
+
} else if (key === "decision_status") {
|
|
17987
|
+
const from = prevMeta[key] ?? "proposed";
|
|
17988
|
+
const to = nextMeta[key] ?? "proposed";
|
|
17989
|
+
if (!valueEqual(from, to)) {
|
|
17990
|
+
events.push({ type: "decision.status_changed", payload: { node_id: nodeId, from, to } });
|
|
17991
|
+
}
|
|
17992
|
+
} else if (!valueEqual(prevMeta[key], nextMeta[key])) {
|
|
17993
|
+
changedPaths.push(`metadata.${key}`);
|
|
17994
|
+
}
|
|
17995
|
+
}
|
|
17996
|
+
}
|
|
17997
|
+
if (changedPaths.length > 0) {
|
|
17998
|
+
changedPaths.sort();
|
|
17999
|
+
const payload = { node_id: nodeId, fields: changedPaths };
|
|
18000
|
+
const only = changedPaths.length === 1 ? changedPaths[0] : void 0;
|
|
18001
|
+
if (only !== void 0 && !only.includes(".") && isShortScalar(cur[only]) && isShortScalar(pat[only])) {
|
|
18002
|
+
payload.from = cur[only];
|
|
18003
|
+
payload.to = pat[only];
|
|
18004
|
+
}
|
|
18005
|
+
events.push({ type: "node.updated", payload });
|
|
18006
|
+
}
|
|
18007
|
+
return events;
|
|
18008
|
+
}
|
|
18009
|
+
|
|
18010
|
+
// ../schema/src/mutate.ts
|
|
18011
|
+
var MutationError = class extends Error {
|
|
18012
|
+
constructor(code, message, subjectId) {
|
|
18013
|
+
super(message);
|
|
18014
|
+
this.name = "MutationError";
|
|
18015
|
+
this.code = code;
|
|
18016
|
+
this.subjectId = subjectId;
|
|
18017
|
+
}
|
|
18018
|
+
};
|
|
18019
|
+
function wouldCreateCycle(flowId, candidateId, allNodes) {
|
|
18020
|
+
if (candidateId === flowId) return true;
|
|
18021
|
+
const nodesById = new Map(allNodes.map((node) => [node.id, node]));
|
|
18022
|
+
const candidate = nodesById.get(candidateId);
|
|
18023
|
+
if (!candidate || candidate.species !== "flow") return false;
|
|
18024
|
+
const visited = /* @__PURE__ */ new Set();
|
|
18025
|
+
const stack = [candidateId];
|
|
18026
|
+
while (stack.length > 0) {
|
|
18027
|
+
const currentFlowId = stack.pop();
|
|
18028
|
+
if (!currentFlowId || visited.has(currentFlowId)) continue;
|
|
18029
|
+
visited.add(currentFlowId);
|
|
18030
|
+
const currentFlow = nodesById.get(currentFlowId);
|
|
18031
|
+
if (!currentFlow || currentFlow.species !== "flow") continue;
|
|
18032
|
+
const entries = currentFlow.metadata?.playlist?.entries;
|
|
18033
|
+
if (!Array.isArray(entries)) continue;
|
|
18034
|
+
const referenced = collectPlaylistNodeRefs(entries);
|
|
18035
|
+
if (referenced.includes(flowId)) return true;
|
|
18036
|
+
for (const refId of referenced) {
|
|
18037
|
+
if (!visited.has(refId)) stack.push(refId);
|
|
18038
|
+
}
|
|
18039
|
+
}
|
|
18040
|
+
return false;
|
|
18041
|
+
}
|
|
18042
|
+
function synthesizeComposesEdges(flow, existingEdges, projectId) {
|
|
18043
|
+
if (flow.species !== "flow") return [];
|
|
18044
|
+
const entries = flow.metadata?.playlist?.entries;
|
|
18045
|
+
if (!Array.isArray(entries) || entries.length === 0) return [];
|
|
18046
|
+
const existingIds = new Set(existingEdges.map((edge) => edge.id));
|
|
18047
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18048
|
+
const synthesized = [];
|
|
18049
|
+
for (const refId of collectPlaylistNodeRefs(entries)) {
|
|
18050
|
+
const id = edgeId(flow.id, refId);
|
|
18051
|
+
if (existingIds.has(id) || seen.has(id)) continue;
|
|
18052
|
+
seen.add(id);
|
|
18053
|
+
synthesized.push({
|
|
18054
|
+
id,
|
|
18055
|
+
project_id: projectId,
|
|
18056
|
+
source_id: flow.id,
|
|
18057
|
+
target_id: refId,
|
|
18058
|
+
edge_type: "composes"
|
|
18059
|
+
});
|
|
18060
|
+
}
|
|
18061
|
+
return synthesized;
|
|
18062
|
+
}
|
|
18063
|
+
function assertNoPlaylistCycle(flow, nextNodes) {
|
|
18064
|
+
const entries = flow.metadata?.playlist?.entries;
|
|
18065
|
+
if (!Array.isArray(entries)) return;
|
|
18066
|
+
for (const candidateId of collectPlaylistNodeRefs(entries)) {
|
|
18067
|
+
if (wouldCreateCycle(flow.id, candidateId, nextNodes)) {
|
|
18068
|
+
throw new MutationError(
|
|
18069
|
+
"playlist_cycle",
|
|
18070
|
+
`Cannot add Flow ${candidateId}: it would create a circular reference.`,
|
|
18071
|
+
candidateId
|
|
18072
|
+
);
|
|
18073
|
+
}
|
|
18074
|
+
}
|
|
18075
|
+
}
|
|
18076
|
+
function applyOps(input, ops) {
|
|
18077
|
+
let nodes = [...input.nodes];
|
|
18078
|
+
let edges = [...input.edges];
|
|
18079
|
+
const eventInputs = [];
|
|
18080
|
+
const synthesizedEdges = [];
|
|
18081
|
+
const cascadedEdgeIds = [];
|
|
18082
|
+
const foldSynthesized = (flow) => {
|
|
18083
|
+
const created = synthesizeComposesEdges(flow, edges, input.projectId);
|
|
18084
|
+
if (created.length === 0) return;
|
|
18085
|
+
edges = [...edges, ...created];
|
|
18086
|
+
synthesizedEdges.push(...created);
|
|
18087
|
+
eventInputs.push(...created.map(edgeAddedInput));
|
|
18088
|
+
};
|
|
18089
|
+
for (const op of ops) {
|
|
18090
|
+
switch (op.op) {
|
|
18091
|
+
case "create_node": {
|
|
18092
|
+
if (nodes.some((candidate) => candidate.id === op.node.id)) {
|
|
18093
|
+
throw new MutationError("duplicate_node", `Node "${op.node.id}" already exists.`, op.node.id);
|
|
18094
|
+
}
|
|
18095
|
+
nodes = [...nodes, op.node];
|
|
18096
|
+
assertNoPlaylistCycle(op.node, nodes);
|
|
18097
|
+
eventInputs.push(nodeCreatedInput(op.node));
|
|
18098
|
+
foldSynthesized(op.node);
|
|
18099
|
+
break;
|
|
18100
|
+
}
|
|
18101
|
+
case "update_node": {
|
|
18102
|
+
const index = nodes.findIndex((candidate) => candidate.id === op.node_id);
|
|
18103
|
+
if (index === -1) {
|
|
18104
|
+
throw new MutationError("node_not_found", `Node ${op.node_id} not found`, op.node_id);
|
|
18105
|
+
}
|
|
18106
|
+
const current = nodes[index];
|
|
18107
|
+
const updated = { ...current, ...op.patch };
|
|
18108
|
+
const nextNodes = [...nodes];
|
|
18109
|
+
nextNodes[index] = updated;
|
|
18110
|
+
if (updated.species === "flow") assertNoPlaylistCycle(updated, nextNodes);
|
|
18111
|
+
const inputs = diffNodeUpdate(current, op.patch);
|
|
18112
|
+
nodes = nextNodes;
|
|
18113
|
+
eventInputs.push(...inputs);
|
|
18114
|
+
if (inputs.length > 0) foldSynthesized(updated);
|
|
18115
|
+
break;
|
|
18116
|
+
}
|
|
18117
|
+
case "delete_node": {
|
|
18118
|
+
if (!nodes.some((candidate) => candidate.id === op.node_id)) {
|
|
18119
|
+
throw new MutationError("node_not_found", `Node ${op.node_id} not found`, op.node_id);
|
|
18120
|
+
}
|
|
18121
|
+
nodes = nodes.filter((candidate) => candidate.id !== op.node_id);
|
|
18122
|
+
for (const edge of edges) {
|
|
18123
|
+
if (edge.source_id === op.node_id || edge.target_id === op.node_id) {
|
|
18124
|
+
cascadedEdgeIds.push(edge.id);
|
|
18125
|
+
}
|
|
18126
|
+
}
|
|
18127
|
+
edges = edges.filter(
|
|
18128
|
+
(edge) => edge.source_id !== op.node_id && edge.target_id !== op.node_id
|
|
18129
|
+
);
|
|
18130
|
+
eventInputs.push(nodeDeletedInput(op.node_id));
|
|
18131
|
+
break;
|
|
18132
|
+
}
|
|
18133
|
+
case "delete_nodes": {
|
|
18134
|
+
const present = new Set(
|
|
18135
|
+
nodes.filter((candidate) => op.node_ids.includes(candidate.id)).map((n) => n.id)
|
|
18136
|
+
);
|
|
18137
|
+
if (present.size === 0) break;
|
|
18138
|
+
nodes = nodes.filter((candidate) => !present.has(candidate.id));
|
|
18139
|
+
for (const edge of edges) {
|
|
18140
|
+
if (present.has(edge.source_id) || present.has(edge.target_id)) {
|
|
18141
|
+
cascadedEdgeIds.push(edge.id);
|
|
18142
|
+
}
|
|
18143
|
+
}
|
|
18144
|
+
edges = edges.filter(
|
|
18145
|
+
(edge) => !present.has(edge.source_id) && !present.has(edge.target_id)
|
|
18146
|
+
);
|
|
18147
|
+
for (const id of present) eventInputs.push(nodeDeletedInput(id));
|
|
18148
|
+
break;
|
|
18149
|
+
}
|
|
18150
|
+
case "create_edge": {
|
|
18151
|
+
const edge = { ...op.edge, id: edgeId(op.edge.source_id, op.edge.target_id) };
|
|
18152
|
+
const existing = edges.find((candidate) => candidate.id === edge.id);
|
|
18153
|
+
if (existing) {
|
|
18154
|
+
if (existing.edge_type !== edge.edge_type) {
|
|
18155
|
+
throw new MutationError(
|
|
18156
|
+
"edge_type_conflict",
|
|
18157
|
+
`Edge "${edge.id}" already exists as "${existing.edge_type}", cannot re-add as "${edge.edge_type}".`,
|
|
18158
|
+
edge.id
|
|
18159
|
+
);
|
|
18160
|
+
}
|
|
18161
|
+
break;
|
|
18162
|
+
}
|
|
18163
|
+
edges = [...edges, edge];
|
|
18164
|
+
eventInputs.push(edgeAddedInput(edge));
|
|
18165
|
+
break;
|
|
18166
|
+
}
|
|
18167
|
+
case "delete_edge": {
|
|
18168
|
+
if (!edges.some((candidate) => candidate.id === op.edge_id)) {
|
|
18169
|
+
throw new MutationError("edge_not_found", `Edge ${op.edge_id} not found`, op.edge_id);
|
|
18170
|
+
}
|
|
18171
|
+
edges = edges.filter((candidate) => candidate.id !== op.edge_id);
|
|
18172
|
+
eventInputs.push(edgeRemovedInput(op.edge_id));
|
|
18173
|
+
break;
|
|
18174
|
+
}
|
|
18175
|
+
case "record_screenshot": {
|
|
18176
|
+
const index = nodes.findIndex((candidate) => candidate.id === op.node_id);
|
|
18177
|
+
if (index === -1) {
|
|
18178
|
+
throw new MutationError("node_not_found", `Node ${op.node_id} not found`, op.node_id);
|
|
18179
|
+
}
|
|
18180
|
+
const node = nodes[index];
|
|
18181
|
+
const decision = decideScreenshot(node, op);
|
|
18182
|
+
if (decision.kind === "refuse") throw new MutationError(decision.code, decision.message, op.node_id);
|
|
18183
|
+
if (decision.kind === "skip") break;
|
|
18184
|
+
const ciOrder = op.source === "ci" && typeof op.order === "number" ? op.order : void 0;
|
|
18185
|
+
const commit = op.source === "ci" ? op.commit : void 0;
|
|
18186
|
+
const prevWatermark = readSlot(node, op.platform).ciOrder;
|
|
18187
|
+
const watermark = ciOrder === void 0 ? prevWatermark : prevWatermark === void 0 ? ciOrder : Math.max(prevWatermark, ciOrder);
|
|
18188
|
+
const meta3 = {
|
|
18189
|
+
ts: op.ts ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
18190
|
+
source: op.source,
|
|
18191
|
+
form: op.form,
|
|
18192
|
+
...commit !== void 0 ? { commit } : {},
|
|
18193
|
+
...ciOrder !== void 0 ? { order: ciOrder } : {},
|
|
18194
|
+
...watermark !== void 0 ? { ci_order: watermark } : {}
|
|
18195
|
+
};
|
|
18196
|
+
const updated = {
|
|
18197
|
+
...node,
|
|
18198
|
+
metadata: {
|
|
18199
|
+
...node.metadata,
|
|
18200
|
+
platformScreenshots: { ...node.metadata?.platformScreenshots, [op.platform]: op.value },
|
|
18201
|
+
platformScreenshotMeta: { ...node.metadata?.platformScreenshotMeta, [op.platform]: meta3 }
|
|
18202
|
+
}
|
|
18203
|
+
};
|
|
18204
|
+
const nextNodes = [...nodes];
|
|
18205
|
+
nextNodes[index] = updated;
|
|
18206
|
+
nodes = nextNodes;
|
|
18207
|
+
eventInputs.push({
|
|
18208
|
+
type: "screenshot.recorded",
|
|
18209
|
+
payload: {
|
|
18210
|
+
node_id: op.node_id,
|
|
18211
|
+
platform: op.platform,
|
|
18212
|
+
source: op.source,
|
|
18213
|
+
form: op.form,
|
|
18214
|
+
// Events never embed asset payloads: a data URI stays in the
|
|
18215
|
+
// snapshot. A `path` form travels under `url` too, on purpose.
|
|
18216
|
+
...op.form !== "data" ? { url: op.value } : {},
|
|
18217
|
+
...commit !== void 0 ? { commit } : {},
|
|
18218
|
+
...ciOrder !== void 0 ? { order: ciOrder } : {},
|
|
18219
|
+
...op.detail !== void 0 ? { detail: op.detail } : {}
|
|
18220
|
+
}
|
|
18221
|
+
});
|
|
18222
|
+
break;
|
|
18223
|
+
}
|
|
18224
|
+
case "remove_screenshot": {
|
|
18225
|
+
const index = nodes.findIndex((candidate) => candidate.id === op.node_id);
|
|
18226
|
+
if (index === -1) {
|
|
18227
|
+
throw new MutationError("node_not_found", `Node ${op.node_id} not found`, op.node_id);
|
|
18228
|
+
}
|
|
18229
|
+
const node = nodes[index];
|
|
18230
|
+
const shots = { ...node.metadata?.platformScreenshots };
|
|
18231
|
+
if (!(op.platform in shots)) break;
|
|
18232
|
+
delete shots[op.platform];
|
|
18233
|
+
const metas = { ...node.metadata?.platformScreenshotMeta };
|
|
18234
|
+
const watermark = readSlot(node, op.platform).ciOrder;
|
|
18235
|
+
if (watermark !== void 0) metas[op.platform] = { ci_order: watermark };
|
|
18236
|
+
else delete metas[op.platform];
|
|
18237
|
+
const updated = {
|
|
18238
|
+
...node,
|
|
18239
|
+
metadata: { ...node.metadata, platformScreenshots: shots, platformScreenshotMeta: metas }
|
|
18240
|
+
};
|
|
18241
|
+
const nextNodes = [...nodes];
|
|
18242
|
+
nextNodes[index] = updated;
|
|
18243
|
+
nodes = nextNodes;
|
|
18244
|
+
eventInputs.push({ type: "screenshot.removed", payload: { node_id: op.node_id, platform: op.platform } });
|
|
18245
|
+
break;
|
|
18246
|
+
}
|
|
18247
|
+
}
|
|
16956
18248
|
}
|
|
16957
|
-
return
|
|
16958
|
-
}
|
|
16959
|
-
function makeEvent(type, payload = {}, options = {}) {
|
|
16960
|
-
const ts = options.ts instanceof Date ? options.ts.toISOString() : options.ts ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
16961
|
-
const id = options.id ?? ulid3();
|
|
16962
|
-
const event = {
|
|
16963
|
-
id,
|
|
16964
|
-
ts,
|
|
16965
|
-
...options.actor !== void 0 ? { actor: options.actor } : {},
|
|
16966
|
-
type,
|
|
16967
|
-
...payload
|
|
16968
|
-
};
|
|
16969
|
-
const schema = JOURNAL_EVENT_SCHEMAS[type] ?? JournalEventSchema;
|
|
16970
|
-
return schema.parse(event);
|
|
18249
|
+
return { nodes, edges, eventInputs, synthesizedEdges, cascadedEdgeIds };
|
|
16971
18250
|
}
|
|
16972
18251
|
|
|
16973
18252
|
// ../schema/src/promote.ts
|
|
@@ -17032,279 +18311,65 @@ function computeRefPromotions(bundle) {
|
|
|
17032
18311
|
skipped.push({ node_id: node.id, ref_id: ref.id, reason: "already-there", detail: to });
|
|
17033
18312
|
continue;
|
|
17034
18313
|
}
|
|
17035
|
-
if (from === "live") {
|
|
17036
|
-
skipped.push({ node_id: node.id, ref_id: ref.id, reason: "live", detail: to });
|
|
17037
|
-
continue;
|
|
17038
|
-
}
|
|
17039
|
-
promotions.push({
|
|
17040
|
-
node_id: node.id,
|
|
17041
|
-
ref_id: ref.id,
|
|
17042
|
-
...ref.platform ? { platform: ref.platform } : {},
|
|
17043
|
-
from,
|
|
17044
|
-
to,
|
|
17045
|
-
external_status: ref.external_status
|
|
17046
|
-
});
|
|
17047
|
-
}
|
|
17048
|
-
}
|
|
17049
|
-
return { promotions, skipped };
|
|
17050
|
-
}
|
|
17051
|
-
function promotionPatch(node, promotion) {
|
|
17052
|
-
if (!promotion.platform) return { status: promotion.to };
|
|
17053
|
-
return {
|
|
17054
|
-
metadata: {
|
|
17055
|
-
...node.metadata,
|
|
17056
|
-
platformStatuses: { ...node.metadata?.platformStatuses, [promotion.platform]: promotion.to }
|
|
17057
|
-
}
|
|
17058
|
-
};
|
|
17059
|
-
}
|
|
17060
|
-
|
|
17061
|
-
// ../schema/src/mentions.ts
|
|
17062
|
-
function isPlatformId(value) {
|
|
17063
|
-
return PLATFORM_IDS.includes(value);
|
|
17064
|
-
}
|
|
17065
|
-
var ACCEPTANCE_MENTION = /\b(AC-[a-z0-9][a-z0-9-]*)(?:\\?@((?:(?!\bAC-[a-z0-9])\S)+))?/gi;
|
|
17066
|
-
var TRAILING_PROSE = /* @__PURE__ */ new Set([".", ",", ";", ":", "!", "?", ")", "]", "}", ">", "'", '"', "`", "*", "_", "~"]);
|
|
17067
|
-
function trimTrailingProse(token) {
|
|
17068
|
-
let end = token.length;
|
|
17069
|
-
while (end > 0 && TRAILING_PROSE.has(token[end - 1])) end -= 1;
|
|
17070
|
-
return token.slice(0, end);
|
|
17071
|
-
}
|
|
17072
|
-
function mentionedAcceptances(event) {
|
|
17073
|
-
const mentions = /* @__PURE__ */ new Map();
|
|
17074
|
-
const unknown2 = /* @__PURE__ */ new Map();
|
|
17075
|
-
for (const text of [event.title, event.body]) {
|
|
17076
|
-
if (!text) continue;
|
|
17077
|
-
for (const match of text.matchAll(ACCEPTANCE_MENTION)) {
|
|
17078
|
-
const id = `AC-${match[1].slice(3)}`;
|
|
17079
|
-
const written = match[2];
|
|
17080
|
-
if (written === void 0) {
|
|
17081
|
-
mentions.set(`${id}@`, { id, platform: null });
|
|
17082
|
-
continue;
|
|
17083
|
-
}
|
|
17084
|
-
const token = trimTrailingProse(written);
|
|
17085
|
-
const suffix = token.toLowerCase();
|
|
17086
|
-
if (!isPlatformId(suffix)) {
|
|
17087
|
-
unknown2.set(`${id}@${suffix}`, { id, platform: token || written });
|
|
17088
|
-
continue;
|
|
17089
|
-
}
|
|
17090
|
-
mentions.set(`${id}@${suffix}`, { id, platform: suffix });
|
|
17091
|
-
}
|
|
17092
|
-
}
|
|
17093
|
-
return { mentions: [...mentions.values()], unknown: [...unknown2.values()] };
|
|
17094
|
-
}
|
|
17095
|
-
|
|
17096
|
-
// ../schema/src/quality-ops.ts
|
|
17097
|
-
var DEFAULT_TARGET_LEVEL = 3;
|
|
17098
|
-
function upsertAssessment(assessments, next) {
|
|
17099
|
-
const index = assessments.findIndex(
|
|
17100
|
-
(candidate) => candidate.criterion_id === next.criterion_id && candidate.surface === next.surface
|
|
17101
|
-
);
|
|
17102
|
-
if (index === -1) return { assessments: [...assessments, next] };
|
|
17103
|
-
const updated = [...assessments];
|
|
17104
|
-
const replaced = updated[index];
|
|
17105
|
-
updated[index] = next;
|
|
17106
|
-
return { assessments: updated, replaced };
|
|
17107
|
-
}
|
|
17108
|
-
function parseSurfaceSpec(spec) {
|
|
17109
|
-
const parts = spec.split(":");
|
|
17110
|
-
const id = (parts[0] ?? "").trim();
|
|
17111
|
-
if (id === "") throw new Error(`--surface needs an id (got "${spec}")`);
|
|
17112
|
-
if (id === CROSS_SURFACE_ID) {
|
|
17113
|
-
throw new Error(
|
|
17114
|
-
`"${CROSS_SURFACE_ID}" is reserved \u2014 it is the contract lens between surfaces. Findings may carry it; it holds no assessments and never becomes a matrix column, so it is not declared here.`
|
|
17115
|
-
);
|
|
17116
|
-
}
|
|
17117
|
-
if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(id)) {
|
|
17118
|
-
throw new Error(
|
|
17119
|
-
`surface id "${id}" is not kebab-case \u2014 assessments reference it, so it has to be stable and typo-proof`
|
|
17120
|
-
);
|
|
17121
|
-
}
|
|
17122
|
-
const title2 = (parts[1] ?? "").trim() || id;
|
|
17123
|
-
const platform = (parts[2] ?? "").trim();
|
|
17124
|
-
if (platform !== "" && !PLATFORM_IDS.includes(platform)) {
|
|
17125
|
-
throw new Error(
|
|
17126
|
-
`"${platform}" is not an Arkaik platform (${PLATFORM_IDS.join(", ")}). A surface that ships no views simply has none \u2014 leave it off rather than inventing one.`
|
|
17127
|
-
);
|
|
17128
|
-
}
|
|
17129
|
-
return platform === "" ? { id, title: title2 } : { id, title: title2, platform };
|
|
17130
|
-
}
|
|
17131
|
-
function domainCodeOf(criterionId, library) {
|
|
17132
|
-
const criterion = (library?.criteria ?? []).find((candidate) => candidate.id === criterionId);
|
|
17133
|
-
if (typeof criterion?.domain === "string" && criterion.domain !== "") return criterion.domain;
|
|
17134
|
-
const dash = criterionId.indexOf("-");
|
|
17135
|
-
return dash > 0 ? criterionId.slice(0, dash) : criterionId;
|
|
17136
|
-
}
|
|
17137
|
-
function mintFindingId(auditId, criterionId, surface, taken, library) {
|
|
17138
|
-
const prefix = `F-${auditId}-${domainCodeOf(criterionId, library)}-${surface}-`;
|
|
17139
|
-
const used = new Set(taken);
|
|
17140
|
-
for (let n = 1; n < 1e3; n++) {
|
|
17141
|
-
const candidate = `${prefix}${String(n).padStart(2, "0")}`;
|
|
17142
|
-
if (!used.has(candidate)) return candidate;
|
|
17143
|
-
}
|
|
17144
|
-
throw new Error(`Kritik: exhausted finding ids for ${prefix}NN \u2014 999 findings on one cell is a data problem, not a numbering one`);
|
|
17145
|
-
}
|
|
17146
|
-
function upsertFinding(findings, next) {
|
|
17147
|
-
const index = findings.findIndex((candidate) => candidate.id === next.id);
|
|
17148
|
-
if (index === -1) return { findings: [...findings, next] };
|
|
17149
|
-
const updated = [...findings];
|
|
17150
|
-
const replaced = updated[index];
|
|
17151
|
-
updated[index] = next;
|
|
17152
|
-
return { findings: updated, replaced };
|
|
17153
|
-
}
|
|
17154
|
-
function patchFinding(findings, id, patch) {
|
|
17155
|
-
const index = findings.findIndex((candidate) => candidate.id === id);
|
|
17156
|
-
if (index === -1) return { findings: [...findings] };
|
|
17157
|
-
const updated = [...findings];
|
|
17158
|
-
const previous = updated[index];
|
|
17159
|
-
const finding = { ...previous, ...patch };
|
|
17160
|
-
updated[index] = finding;
|
|
17161
|
-
return { findings: updated, finding, previous };
|
|
17162
|
-
}
|
|
17163
|
-
function resolveFinding(findings, id, resolvedBy) {
|
|
17164
|
-
return patchFinding(findings, id, {
|
|
17165
|
-
status: "resolved",
|
|
17166
|
-
...resolvedBy !== void 0 ? { resolved_by: resolvedBy } : {}
|
|
17167
|
-
});
|
|
17168
|
-
}
|
|
17169
|
-
function acceptedDetail(detail, note) {
|
|
17170
|
-
return `${detail}
|
|
17171
|
-
|
|
17172
|
-
Accepted risk: ${note}`.trim();
|
|
17173
|
-
}
|
|
17174
|
-
function acceptFinding(findings, id, note) {
|
|
17175
|
-
const existing = findings.find((candidate) => candidate.id === id);
|
|
17176
|
-
const detail = existing === void 0 ? note : acceptedDetail(existing.detail, note);
|
|
17177
|
-
return patchFinding(findings, id, { status: "accepted-risk", detail });
|
|
17178
|
-
}
|
|
17179
|
-
function fillTemplate(text, values) {
|
|
17180
|
-
return text.replace(/\{(\w+)\}/g, (whole, key) => values[key] ?? whole);
|
|
17181
|
-
}
|
|
17182
|
-
function renderIssue(criterion, options) {
|
|
17183
|
-
const { surface, finding, library } = options;
|
|
17184
|
-
const anchors = criterion.level_anchors ?? {};
|
|
17185
|
-
const level = options.level === void 0 || options.level === "" ? "" : String(options.level);
|
|
17186
|
-
const observed = level === "" ? "{observed_level}" : level;
|
|
17187
|
-
const target = options.targetLevel !== void 0 && options.targetLevel !== "" ? String(options.targetLevel) : level === "" ? "{target_level}" : String(Math.min(Number(level) + 1, 4));
|
|
17188
|
-
const values = {
|
|
17189
|
-
surface,
|
|
17190
|
-
observed_level: observed,
|
|
17191
|
-
target_level: target,
|
|
17192
|
-
observed_level_name: anchors[`l${observed}`] ?? "{observed_level_name}",
|
|
17193
|
-
target_level_name: anchors[`l${target}`] ?? "{target_level_name}",
|
|
17194
|
-
target_anchor_text: anchors[`l${target}`] ?? "{target_anchor_text}",
|
|
17195
|
-
impact: String(finding?.impact ?? criterion.default_impact ?? 3)
|
|
17196
|
-
};
|
|
17197
|
-
if (finding !== void 0) {
|
|
17198
|
-
values.likelihood = String(finding.likelihood);
|
|
17199
|
-
values.evidence_bullets_with_file_paths = finding.evidence;
|
|
17200
|
-
values.risk_narrative = finding.detail;
|
|
17201
|
-
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
17202
|
-
values.remediation_step_1 = finding.remediation;
|
|
17203
|
-
}
|
|
17204
|
-
}
|
|
17205
|
-
const issue2 = criterion.issue ?? {};
|
|
17206
|
-
const labels = [.../* @__PURE__ */ new Set([...issue2.labels ?? ["quality"], surface])];
|
|
17207
|
-
const body = fillTemplate(issue2.body_skeleton ?? "", values);
|
|
17208
|
-
return {
|
|
17209
|
-
title: fillTemplate(issue2.title_template ?? `[Quality] ${criterion.id} on {surface}`, values),
|
|
17210
|
-
labels,
|
|
17211
|
-
body: finding === void 0 ? body : `${body}
|
|
17212
|
-
${findingFooter(finding, library)}`,
|
|
17213
|
-
...typeof criterion.remediation === "string" && criterion.remediation !== "" ? { remediation: criterion.remediation } : {}
|
|
17214
|
-
};
|
|
17215
|
-
}
|
|
17216
|
-
function findingFooter(finding, library) {
|
|
17217
|
-
const lines = [
|
|
17218
|
-
``,
|
|
17219
|
-
`---`,
|
|
17220
|
-
`<sub>Kritik finding \`${finding.id}\` \u2014 **${severityOf(finding, library)} / ${priorityOf(finding, library)}** (impact ${finding.impact} x likelihood ${finding.likelihood}, cost ${finding.cost})</sub>`,
|
|
17221
|
-
``,
|
|
17222
|
-
`**Evidence**`,
|
|
17223
|
-
finding.evidence
|
|
17224
|
-
];
|
|
17225
|
-
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
17226
|
-
lines.push(``, `**Remediation**`, finding.remediation);
|
|
17227
|
-
}
|
|
17228
|
-
return lines.join("\n");
|
|
17229
|
-
}
|
|
17230
|
-
function signalRunSheet(library, surfaces, filter = {}) {
|
|
17231
|
-
const surfaceIds = surfaces.map((surface) => surface.id).filter((id) => id !== CROSS_SURFACE_ID);
|
|
17232
|
-
const rows = [];
|
|
17233
|
-
for (const criterion of library.criteria ?? []) {
|
|
17234
|
-
if (criterion.superseded_by !== void 0) continue;
|
|
17235
|
-
if (filter.criterion !== void 0 && criterion.id !== filter.criterion) continue;
|
|
17236
|
-
if (filter.domain !== void 0 && criterion.domain !== filter.domain) continue;
|
|
17237
|
-
const signals = criterion.signals ?? [];
|
|
17238
|
-
if (signals.length === 0) continue;
|
|
17239
|
-
const appliesTo = criterion.applies_to;
|
|
17240
|
-
for (const surfaceId of surfaceIds) {
|
|
17241
|
-
if (Array.isArray(appliesTo) && !appliesTo.includes(surfaceId)) continue;
|
|
17242
|
-
if (filter.surface !== void 0 && surfaceId !== filter.surface) continue;
|
|
17243
|
-
signals.forEach((signal, index) => {
|
|
17244
|
-
rows.push({ criterion_id: criterion.id, surface: surfaceId, index, signal });
|
|
18314
|
+
if (from === "live") {
|
|
18315
|
+
skipped.push({ node_id: node.id, ref_id: ref.id, reason: "live", detail: to });
|
|
18316
|
+
continue;
|
|
18317
|
+
}
|
|
18318
|
+
promotions.push({
|
|
18319
|
+
node_id: node.id,
|
|
18320
|
+
ref_id: ref.id,
|
|
18321
|
+
...ref.platform ? { platform: ref.platform } : {},
|
|
18322
|
+
from,
|
|
18323
|
+
to,
|
|
18324
|
+
external_status: ref.external_status
|
|
17245
18325
|
});
|
|
17246
18326
|
}
|
|
17247
18327
|
}
|
|
17248
|
-
return
|
|
18328
|
+
return { promotions, skipped };
|
|
17249
18329
|
}
|
|
17250
|
-
function
|
|
17251
|
-
|
|
17252
|
-
for (const surface of matrix.surfaces) {
|
|
17253
|
-
const bySurface = {};
|
|
17254
|
-
for (const domain2 of matrix.domains) {
|
|
17255
|
-
const cell = matrix.matrix[domain2]?.[surface];
|
|
17256
|
-
if (cell) bySurface[domain2] = cell.score;
|
|
17257
|
-
}
|
|
17258
|
-
scores[surface] = bySurface;
|
|
17259
|
-
}
|
|
18330
|
+
function promotionPatch(node, promotion) {
|
|
18331
|
+
if (!promotion.platform) return { status: promotion.to };
|
|
17260
18332
|
return {
|
|
17261
|
-
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
framework_version: meta3.framework_version,
|
|
17265
|
-
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
17266
|
-
scores,
|
|
17267
|
-
counts: matrix.finding_counts,
|
|
17268
|
-
...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
|
|
18333
|
+
metadata: {
|
|
18334
|
+
...node.metadata,
|
|
18335
|
+
platformStatuses: { ...node.metadata?.platformStatuses, [promotion.platform]: promotion.to }
|
|
17269
18336
|
}
|
|
17270
18337
|
};
|
|
17271
18338
|
}
|
|
17272
|
-
|
|
17273
|
-
|
|
17274
|
-
|
|
17275
|
-
|
|
17276
|
-
finding_id: finding.id,
|
|
17277
|
-
criterion_id: finding.criterion_id,
|
|
17278
|
-
surface: finding.surface,
|
|
17279
|
-
severity: severityOf(finding, library),
|
|
17280
|
-
priority: priorityOf(finding, library),
|
|
17281
|
-
title: finding.title,
|
|
17282
|
-
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {},
|
|
17283
|
-
...finding.issue_url !== void 0 ? { issue_url: finding.issue_url } : {}
|
|
17284
|
-
}
|
|
17285
|
-
};
|
|
18339
|
+
|
|
18340
|
+
// ../schema/src/mentions.ts
|
|
18341
|
+
function isPlatformId(value) {
|
|
18342
|
+
return PLATFORM_IDS.includes(value);
|
|
17286
18343
|
}
|
|
17287
|
-
|
|
17288
|
-
|
|
17289
|
-
|
|
17290
|
-
|
|
17291
|
-
|
|
17292
|
-
|
|
17293
|
-
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {}
|
|
17294
|
-
}
|
|
17295
|
-
};
|
|
18344
|
+
var ACCEPTANCE_MENTION = /\b(AC-[a-z0-9][a-z0-9-]*)(?:\\?@((?:(?!\bAC-[a-z0-9])\S)+))?/gi;
|
|
18345
|
+
var TRAILING_PROSE = /* @__PURE__ */ new Set([".", ",", ";", ":", "!", "?", ")", "]", "}", ">", "'", '"', "`", "*", "_", "~"]);
|
|
18346
|
+
function trimTrailingProse(token) {
|
|
18347
|
+
let end = token.length;
|
|
18348
|
+
while (end > 0 && TRAILING_PROSE.has(token[end - 1])) end -= 1;
|
|
18349
|
+
return token.slice(0, end);
|
|
17296
18350
|
}
|
|
17297
|
-
function
|
|
17298
|
-
|
|
17299
|
-
|
|
17300
|
-
|
|
17301
|
-
|
|
17302
|
-
|
|
17303
|
-
|
|
17304
|
-
|
|
17305
|
-
|
|
18351
|
+
function mentionedAcceptances(event) {
|
|
18352
|
+
const mentions = /* @__PURE__ */ new Map();
|
|
18353
|
+
const unknown2 = /* @__PURE__ */ new Map();
|
|
18354
|
+
for (const text of [event.title, event.body]) {
|
|
18355
|
+
if (!text) continue;
|
|
18356
|
+
for (const match of text.matchAll(ACCEPTANCE_MENTION)) {
|
|
18357
|
+
const id = `AC-${match[1].slice(3)}`;
|
|
18358
|
+
const written = match[2];
|
|
18359
|
+
if (written === void 0) {
|
|
18360
|
+
mentions.set(`${id}@`, { id, platform: null });
|
|
18361
|
+
continue;
|
|
18362
|
+
}
|
|
18363
|
+
const token = trimTrailingProse(written);
|
|
18364
|
+
const suffix = token.toLowerCase();
|
|
18365
|
+
if (!isPlatformId(suffix)) {
|
|
18366
|
+
unknown2.set(`${id}@${suffix}`, { id, platform: token || written });
|
|
18367
|
+
continue;
|
|
18368
|
+
}
|
|
18369
|
+
mentions.set(`${id}@${suffix}`, { id, platform: suffix });
|
|
17306
18370
|
}
|
|
17307
|
-
}
|
|
18371
|
+
}
|
|
18372
|
+
return { mentions: [...mentions.values()], unknown: [...unknown2.values()] };
|
|
17308
18373
|
}
|
|
17309
18374
|
|
|
17310
18375
|
// ../schema/src/quality-regressions.ts
|
|
@@ -17386,7 +18451,7 @@ function detectRegressions(previous, next, library) {
|
|
|
17386
18451
|
|
|
17387
18452
|
// ../schema/src/quality-trend.ts
|
|
17388
18453
|
var NO_DELTA = { previous: null, delta: null };
|
|
17389
|
-
var
|
|
18454
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17390
18455
|
function frameworkMajor(version2) {
|
|
17391
18456
|
if (typeof version2 !== "string") return null;
|
|
17392
18457
|
const match = /^\s*v?(\d+)/.exec(version2);
|
|
@@ -17398,15 +18463,16 @@ function sameFrameworkMajor(a, b) {
|
|
|
17398
18463
|
return left === null || right === null || left === right;
|
|
17399
18464
|
}
|
|
17400
18465
|
function scopeOf(raw) {
|
|
17401
|
-
if (
|
|
18466
|
+
if (readPlanScope(raw) !== null) return void 0;
|
|
18467
|
+
if (!isRecord4(raw) || typeof raw.since !== "string" || raw.since === "") return void 0;
|
|
17402
18468
|
return { scope: { since: raw.since, cells: typeof raw.cells === "number" && Number.isFinite(raw.cells) ? raw.cells : null } };
|
|
17403
18469
|
}
|
|
17404
18470
|
function cleanScores(raw) {
|
|
17405
18471
|
const scores = {};
|
|
17406
|
-
if (!
|
|
18472
|
+
if (!isRecord4(raw)) return scores;
|
|
17407
18473
|
for (const surface of Object.keys(raw)) {
|
|
17408
18474
|
const bySurface = raw[surface];
|
|
17409
|
-
if (!
|
|
18475
|
+
if (!isRecord4(bySurface)) continue;
|
|
17410
18476
|
const cleaned = {};
|
|
17411
18477
|
for (const domain2 of Object.keys(bySurface)) {
|
|
17412
18478
|
const score = bySurface[domain2];
|
|
@@ -17418,7 +18484,7 @@ function cleanScores(raw) {
|
|
|
17418
18484
|
}
|
|
17419
18485
|
function cleanCounts(raw) {
|
|
17420
18486
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
17421
|
-
if (!
|
|
18487
|
+
if (!isRecord4(raw)) return counts;
|
|
17422
18488
|
for (const severity of Object.keys(counts)) {
|
|
17423
18489
|
const value = raw[severity];
|
|
17424
18490
|
if (typeof value === "number" && Number.isFinite(value)) counts[severity] = value;
|
|
@@ -17436,7 +18502,7 @@ function liveScores(live) {
|
|
|
17436
18502
|
const scores = {};
|
|
17437
18503
|
for (const domain2 of Object.keys(live.matrix ?? {})) {
|
|
17438
18504
|
const row = live.matrix[domain2];
|
|
17439
|
-
if (!
|
|
18505
|
+
if (!isRecord4(row)) continue;
|
|
17440
18506
|
for (const surface of Object.keys(row)) {
|
|
17441
18507
|
const cell = row[surface];
|
|
17442
18508
|
if (!cell || typeof cell.score !== "number") continue;
|
|
@@ -17456,13 +18522,14 @@ function deriveQualityTrend(events, profile, live) {
|
|
|
17456
18522
|
const weights = profile?.domain_weights;
|
|
17457
18523
|
const byAudit = /* @__PURE__ */ new Map();
|
|
17458
18524
|
const audits = (Array.isArray(events) ? events : []).filter(
|
|
17459
|
-
(event) =>
|
|
18525
|
+
(event) => isRecord4(event) && event.type === "quality.audit.completed"
|
|
17460
18526
|
);
|
|
17461
18527
|
for (const event of orderEvents(audits)) {
|
|
17462
18528
|
const auditId = typeof event.audit_id === "string" ? event.audit_id : typeof event.id === "string" ? event.id : "";
|
|
17463
18529
|
const scores = cleanScores(event.scores);
|
|
17464
18530
|
const overall = {};
|
|
17465
18531
|
for (const surface of Object.keys(scores)) overall[surface] = rollUpSurface(scores[surface], weights);
|
|
18532
|
+
const plan = readPlanScope(event.scope);
|
|
17466
18533
|
const snapshot = {
|
|
17467
18534
|
audit_id: auditId,
|
|
17468
18535
|
ts: typeof event.ts === "string" ? event.ts : "",
|
|
@@ -17473,7 +18540,8 @@ function deriveQualityTrend(events, profile, live) {
|
|
|
17473
18540
|
overall,
|
|
17474
18541
|
counts: cleanCounts(event.counts),
|
|
17475
18542
|
...event.baseline === true ? { baseline: true } : {},
|
|
17476
|
-
...scopeOf(event.scope) ?? {}
|
|
18543
|
+
...scopeOf(event.scope) ?? {},
|
|
18544
|
+
...plan !== null ? { plan } : {}
|
|
17477
18545
|
};
|
|
17478
18546
|
byAudit.delete(auditId);
|
|
17479
18547
|
byAudit.set(auditId, snapshot);
|
|
@@ -17501,6 +18569,18 @@ function deriveQualityTrend(events, profile, live) {
|
|
|
17501
18569
|
deltaOverall: (surface) => against(previous?.overall[surface], live?.overall?.[surface])
|
|
17502
18570
|
};
|
|
17503
18571
|
}
|
|
18572
|
+
function planScored(plan, surface, domain2) {
|
|
18573
|
+
return plan.scored.some((key) => {
|
|
18574
|
+
const at2 = key.lastIndexOf("::");
|
|
18575
|
+
if (at2 <= 0 || key.slice(at2 + 2) !== surface) return false;
|
|
18576
|
+
return domain2 === void 0 || domainCodeOf(key.slice(0, at2)) === domain2;
|
|
18577
|
+
});
|
|
18578
|
+
}
|
|
18579
|
+
function sameDomains(a, b, surface) {
|
|
18580
|
+
const left = Object.keys(a.scores[surface] ?? {});
|
|
18581
|
+
const right = new Set(Object.keys(b.scores[surface] ?? {}));
|
|
18582
|
+
return left.length === right.size && left.every((domain2) => right.has(domain2));
|
|
18583
|
+
}
|
|
17504
18584
|
function trendRows(trend, filter = {}) {
|
|
17505
18585
|
const surfaces = [];
|
|
17506
18586
|
for (const snapshot of trend.snapshots) {
|
|
@@ -17520,7 +18600,8 @@ function trendRows(trend, filter = {}) {
|
|
|
17520
18600
|
for (const surface of surfaces) {
|
|
17521
18601
|
const score = valueOf(snapshot, surface);
|
|
17522
18602
|
const before = above === null ? null : valueOf(above, surface);
|
|
17523
|
-
const
|
|
18603
|
+
const looked = snapshot.plan === void 0 || planScored(snapshot.plan, surface, filter.domain) && (filter.domain !== void 0 || above === null || sameDomains(snapshot, above, surface));
|
|
18604
|
+
const delta = looked && snapshot.comparable && score !== null && before !== null ? score - before : null;
|
|
17524
18605
|
cells[surface] = { score, delta };
|
|
17525
18606
|
}
|
|
17526
18607
|
rows.push({
|
|
@@ -17531,7 +18612,8 @@ function trendRows(trend, filter = {}) {
|
|
|
17531
18612
|
comparable: snapshot.comparable,
|
|
17532
18613
|
cells,
|
|
17533
18614
|
...snapshot.baseline ? { baseline: true } : {},
|
|
17534
|
-
...snapshot.scope !== void 0 ? { scope: snapshot.scope } : {}
|
|
18615
|
+
...snapshot.scope !== void 0 ? { scope: snapshot.scope } : {},
|
|
18616
|
+
...snapshot.plan !== void 0 ? { plan: snapshot.plan } : {}
|
|
17535
18617
|
});
|
|
17536
18618
|
});
|
|
17537
18619
|
return { surfaces, rows };
|
|
@@ -17548,28 +18630,72 @@ var rowsOf2 = (value) => Array.isArray(value) ? value : [];
|
|
|
17548
18630
|
var isString = (value) => typeof value === "string" && value !== "";
|
|
17549
18631
|
var stringsOf = (value) => rowsOf2(value).filter(isString);
|
|
17550
18632
|
var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
|
|
18633
|
+
var orderedRows = (events) => orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
|
|
18634
|
+
function isPlanRecord(event) {
|
|
18635
|
+
if (typeof event !== "object" || event === null) return false;
|
|
18636
|
+
const { type, scope, audit_id: auditId } = event;
|
|
18637
|
+
return type === "quality.audit.completed" && (readPlanScope(scope) !== null || isPlanId(auditId));
|
|
18638
|
+
}
|
|
18639
|
+
function recordedPlans(events) {
|
|
18640
|
+
const plans = [];
|
|
18641
|
+
for (const event of orderedRows(events)) {
|
|
18642
|
+
if (!isPlanRecord(event)) continue;
|
|
18643
|
+
const reading = readPlanScope(event.scope);
|
|
18644
|
+
const ts = isString(event.ts) ? event.ts : null;
|
|
18645
|
+
if (reading === null) plans.push({ plan: event.audit_id, parts: [], scored: [], ts });
|
|
18646
|
+
else plans.push({ plan: reading.plan, parts: stringsOf(reading.parts), scored: stringsOf(reading.scored), ts });
|
|
18647
|
+
}
|
|
18648
|
+
return plans;
|
|
18649
|
+
}
|
|
17551
18650
|
function recordedAuditIds(events) {
|
|
17552
18651
|
const ids = [];
|
|
17553
|
-
|
|
17554
|
-
if (event?.type !== "quality.audit.completed") continue;
|
|
17555
|
-
const id = event.audit_id;
|
|
18652
|
+
const note = (id) => {
|
|
17556
18653
|
if (isString(id) && !ids.includes(id)) ids.push(id);
|
|
18654
|
+
};
|
|
18655
|
+
for (const event of orderedRows(events)) {
|
|
18656
|
+
if (event.type !== "quality.audit.completed") continue;
|
|
18657
|
+
note(event.audit_id);
|
|
18658
|
+
for (const part of readPlanScope(event.scope)?.parts ?? []) note(part);
|
|
17557
18659
|
}
|
|
17558
18660
|
return ids;
|
|
17559
18661
|
}
|
|
17560
|
-
function
|
|
17561
|
-
|
|
17562
|
-
|
|
18662
|
+
function neverAnAnchor(event) {
|
|
18663
|
+
return isPlanRecord(event) || isPlanPartId(event?.audit_id);
|
|
18664
|
+
}
|
|
18665
|
+
function recordedSinceIds(events) {
|
|
18666
|
+
return recordedAuditIds(rowsOf2(events).filter((event) => !neverAnAnchor(event)));
|
|
18667
|
+
}
|
|
18668
|
+
function anchorIndex(ordered, since) {
|
|
17563
18669
|
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
17564
18670
|
const event = ordered[i];
|
|
17565
|
-
if (event.type !== "quality.audit.completed") continue;
|
|
17566
|
-
|
|
17567
|
-
|
|
17568
|
-
|
|
17569
|
-
|
|
17570
|
-
|
|
18671
|
+
if (event.type !== "quality.audit.completed" || neverAnAnchor(event)) continue;
|
|
18672
|
+
if (since !== void 0 && event.audit_id !== since) continue;
|
|
18673
|
+
return i;
|
|
18674
|
+
}
|
|
18675
|
+
return -1;
|
|
18676
|
+
}
|
|
18677
|
+
function namesPlan(ordered, id) {
|
|
18678
|
+
if (isPlanId(id) || isPlanPartId(id)) return true;
|
|
18679
|
+
return ordered.some((event) => {
|
|
18680
|
+
if (!isPlanRecord(event)) return false;
|
|
18681
|
+
if (event.audit_id === id) return true;
|
|
18682
|
+
const reading = readPlanScope(event.scope);
|
|
18683
|
+
return reading !== null && (reading.plan === id || reading.parts.includes(id));
|
|
18684
|
+
});
|
|
18685
|
+
}
|
|
18686
|
+
function scopeAnchorId(events) {
|
|
18687
|
+
const ordered = orderedRows(events);
|
|
18688
|
+
const at2 = anchorIndex(ordered, void 0);
|
|
18689
|
+
if (at2 === -1) return null;
|
|
18690
|
+
const id = ordered[at2].audit_id;
|
|
18691
|
+
return isString(id) ? id : null;
|
|
18692
|
+
}
|
|
18693
|
+
function deriveAuditScope(events, section, library, options = {}) {
|
|
18694
|
+
const ordered = orderedRows(events);
|
|
18695
|
+
const sinceIndex = anchorIndex(ordered, options.since);
|
|
18696
|
+
const asked = options.since;
|
|
17571
18697
|
const empty = {
|
|
17572
|
-
since:
|
|
18698
|
+
since: asked === void 0 || namesPlan(ordered, asked) ? null : asked,
|
|
17573
18699
|
since_ts: null,
|
|
17574
18700
|
cells: [],
|
|
17575
18701
|
findings: [],
|
|
@@ -17583,15 +18709,51 @@ function deriveAuditScope(events, section, library, options = {}) {
|
|
|
17583
18709
|
const anchorId = anchor.audit_id;
|
|
17584
18710
|
const since = isString(anchorId) ? anchorId : null;
|
|
17585
18711
|
const sinceTs = isString(anchor.ts) ? anchor.ts : null;
|
|
18712
|
+
const scoredAt = /* @__PURE__ */ new Map();
|
|
18713
|
+
for (const assessment of rowsOf2(section?.assessments)) {
|
|
18714
|
+
if (!isString(assessment?.criterion_id) || !isString(assessment?.surface) || !isString(assessment?.audit_id)) continue;
|
|
18715
|
+
if (!isString(assessment.ts)) continue;
|
|
18716
|
+
const key = cellKey2(assessment.criterion_id, assessment.surface);
|
|
18717
|
+
const byAudit = scoredAt.get(key) ?? /* @__PURE__ */ new Map();
|
|
18718
|
+
const seen = byAudit.get(assessment.audit_id);
|
|
18719
|
+
if (seen === void 0 || seen < assessment.ts) byAudit.set(assessment.audit_id, assessment.ts);
|
|
18720
|
+
scoredAt.set(key, byAudit);
|
|
18721
|
+
}
|
|
18722
|
+
const planFloor = /* @__PURE__ */ new Map();
|
|
18723
|
+
for (let i = sinceIndex + 1; i < ordered.length; i++) {
|
|
18724
|
+
const event = ordered[i];
|
|
18725
|
+
if (event.type !== "quality.audit.completed") continue;
|
|
18726
|
+
const reading = readPlanScope(event.scope);
|
|
18727
|
+
if (reading === null) continue;
|
|
18728
|
+
for (const key of reading.scored) {
|
|
18729
|
+
let ts = null;
|
|
18730
|
+
for (const part of reading.parts) {
|
|
18731
|
+
const at2 = scoredAt.get(key)?.get(part);
|
|
18732
|
+
if (at2 !== void 0 && (ts === null || ts < at2)) ts = at2;
|
|
18733
|
+
}
|
|
18734
|
+
planFloor.set(key, { index: i, ts });
|
|
18735
|
+
}
|
|
18736
|
+
}
|
|
18737
|
+
const sortKeyAt = (index) => {
|
|
18738
|
+
const ts = ordered[index]?.ts;
|
|
18739
|
+
return typeof ts === "string" ? ts : "";
|
|
18740
|
+
};
|
|
18741
|
+
const countsFor = (key, index) => {
|
|
18742
|
+
const floor = planFloor.get(key);
|
|
18743
|
+
if (floor === void 0) return index > sinceIndex;
|
|
18744
|
+
return floor.ts !== null ? sortKeyAt(index) > floor.ts : index > floor.index;
|
|
18745
|
+
};
|
|
17586
18746
|
const resolutions = /* @__PURE__ */ new Map();
|
|
17587
|
-
for (
|
|
18747
|
+
for (let i = sinceIndex + 1; i < ordered.length; i++) {
|
|
18748
|
+
const event = ordered[i];
|
|
17588
18749
|
if (event.type !== "quality.finding.resolved") continue;
|
|
17589
18750
|
const findingId = event.finding_id;
|
|
17590
18751
|
if (!isString(findingId)) continue;
|
|
17591
|
-
const entry = resolutions.get(findingId) ?? {
|
|
18752
|
+
const entry = resolutions.get(findingId) ?? { last: i, nodes: /* @__PURE__ */ new Map() };
|
|
18753
|
+
entry.last = i;
|
|
17592
18754
|
const by = event.resolved_by;
|
|
17593
18755
|
if (isString(by)) entry.resolved_by = by;
|
|
17594
|
-
for (const node of stringsOf(event.node_ids)) entry.
|
|
18756
|
+
for (const node of stringsOf(event.node_ids)) entry.nodes.set(node, i);
|
|
17595
18757
|
resolutions.set(findingId, entry);
|
|
17596
18758
|
}
|
|
17597
18759
|
if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
|
|
@@ -17629,7 +18791,10 @@ function deriveAuditScope(events, section, library, options = {}) {
|
|
|
17629
18791
|
const unknown2 = [];
|
|
17630
18792
|
const unscorable = [];
|
|
17631
18793
|
const resolvedBy = {};
|
|
17632
|
-
const resolvedNodes = /* @__PURE__ */ new
|
|
18794
|
+
const resolvedNodes = /* @__PURE__ */ new Map();
|
|
18795
|
+
const touch = (node, index) => {
|
|
18796
|
+
if ((resolvedNodes.get(node) ?? -1) < index) resolvedNodes.set(node, index);
|
|
18797
|
+
};
|
|
17633
18798
|
for (const [findingId, resolution] of resolutions) {
|
|
17634
18799
|
const finding = findingById.get(findingId);
|
|
17635
18800
|
if (finding === void 0) {
|
|
@@ -17640,15 +18805,17 @@ function deriveAuditScope(events, section, library, options = {}) {
|
|
|
17640
18805
|
const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
|
|
17641
18806
|
(surface) => scorable(finding.criterion_id, surface)
|
|
17642
18807
|
);
|
|
17643
|
-
for (const node of stringsOf(finding.node_ids))
|
|
17644
|
-
for (const node of resolution.
|
|
18808
|
+
for (const node of stringsOf(finding.node_ids)) touch(node, resolution.last);
|
|
18809
|
+
for (const [node, index] of resolution.nodes) touch(node, index);
|
|
17645
18810
|
if (targets.length === 0) {
|
|
17646
18811
|
unscorable.push(findingId);
|
|
17647
18812
|
continue;
|
|
17648
18813
|
}
|
|
18814
|
+
const live = targets.filter((surface) => countsFor(cellKey2(finding.criterion_id, surface), resolution.last));
|
|
18815
|
+
if (live.length === 0) continue;
|
|
17649
18816
|
drivers.push(findingId);
|
|
17650
18817
|
if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
|
|
17651
|
-
for (const surface of
|
|
18818
|
+
for (const surface of live) addDirect(finding.criterion_id, surface, findingId);
|
|
17652
18819
|
}
|
|
17653
18820
|
let widened = 0;
|
|
17654
18821
|
if (options.widen !== false && resolvedNodes.size > 0) {
|
|
@@ -17672,7 +18839,10 @@ function deriveAuditScope(events, section, library, options = {}) {
|
|
|
17672
18839
|
if (cells.has(key)) continue;
|
|
17673
18840
|
if (!criterionById.has(assessment.criterion_id)) continue;
|
|
17674
18841
|
if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
|
|
17675
|
-
const shared = [...nodesByCell.get(key) ?? []].filter((node) =>
|
|
18842
|
+
const shared = [...nodesByCell.get(key) ?? []].filter((node) => {
|
|
18843
|
+
const at2 = resolvedNodes.get(node);
|
|
18844
|
+
return at2 !== void 0 && countsFor(key, at2);
|
|
18845
|
+
}).sort();
|
|
17676
18846
|
if (shared.length === 0) continue;
|
|
17677
18847
|
cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
|
|
17678
18848
|
widened++;
|
|
@@ -17705,6 +18875,11 @@ function scopedAuditId(input) {
|
|
|
17705
18875
|
if (recorded.includes(requested)) {
|
|
17706
18876
|
throw new Error(`"${requested}" is already recorded \u2014 its reading is history. Name a new audit.`);
|
|
17707
18877
|
}
|
|
18878
|
+
if (isPlanId(requested) || isPlanPartId(requested)) {
|
|
18879
|
+
throw new Error(
|
|
18880
|
+
`"${requested}" is reserved for plans and their parts \u2014 a plan id (YYYY-MM-zplan-DDNN) names a plan, and <planId>-<domain>-<surface> one of its parts, so an audit under that id could never be recorded or read as one. Name a scoped re-audit (e.g. \`${suggestedAuditId({ ...input, requested: void 0 })}\`).`
|
|
18881
|
+
);
|
|
18882
|
+
}
|
|
17708
18883
|
if (newest !== void 0 && requested < newest) {
|
|
17709
18884
|
throw new Error(
|
|
17710
18885
|
`"${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)}\`).`
|
|
@@ -17713,7 +18888,7 @@ function scopedAuditId(input) {
|
|
|
17713
18888
|
return requested;
|
|
17714
18889
|
}
|
|
17715
18890
|
if (open !== void 0 && (newest === void 0 || open >= newest)) return open;
|
|
17716
|
-
for (const candidate of scopedCandidates(month)) {
|
|
18891
|
+
for (const candidate of scopedCandidates(month, known)) {
|
|
17717
18892
|
if (known.includes(candidate)) continue;
|
|
17718
18893
|
if (newest !== void 0 && candidate < newest) {
|
|
17719
18894
|
throw new Error(
|
|
@@ -17724,13 +18899,16 @@ function scopedAuditId(input) {
|
|
|
17724
18899
|
}
|
|
17725
18900
|
throw new Error(`99 scoped audits in ${month} \u2014 name the next one yourself.`);
|
|
17726
18901
|
}
|
|
17727
|
-
function* scopedCandidates(month) {
|
|
17728
|
-
|
|
18902
|
+
function* scopedCandidates(month, known) {
|
|
18903
|
+
const newest = [...known].sort().at(-1) ?? "";
|
|
18904
|
+
const stem = newest.replace(/-scoped(-\d+)?$/, "");
|
|
18905
|
+
const base = `${month}-scoped` < newest && isPlanPartId(stem) ? stem : month;
|
|
18906
|
+
for (let n = 1; n < 100; n++) yield n === 1 ? `${base}-scoped` : `${base}-scoped-${String(n).padStart(2, "0")}`;
|
|
17729
18907
|
}
|
|
17730
18908
|
function suggestedAuditId({ since, month, requested, known, recorded }) {
|
|
17731
18909
|
const taken = /* @__PURE__ */ new Set([...known, ...recorded, since, ...requested !== void 0 ? [requested] : []]);
|
|
17732
18910
|
const floor = [...taken].sort().at(-1);
|
|
17733
|
-
for (const candidate of scopedCandidates(month)) {
|
|
18911
|
+
for (const candidate of scopedCandidates(month, known)) {
|
|
17734
18912
|
if (taken.has(candidate)) continue;
|
|
17735
18913
|
if (floor === void 0 || candidate > floor) return candidate;
|
|
17736
18914
|
}
|
|
@@ -17740,8 +18918,9 @@ function scopeSummary(scope) {
|
|
|
17740
18918
|
const direct = scope.cells.length - scope.widened;
|
|
17741
18919
|
const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
|
|
17742
18920
|
const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
|
|
17743
|
-
const
|
|
17744
|
-
|
|
18921
|
+
const count = scope.findings.length;
|
|
18922
|
+
const from = count > 0 ? ` from ${count} resolved finding${count === 1 ? "" : "s"}` : "";
|
|
18923
|
+
return `${cells}${split}${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
|
|
17745
18924
|
}
|
|
17746
18925
|
|
|
17747
18926
|
// ../schema/src/quality-burndown.ts
|
|
@@ -17751,13 +18930,13 @@ var EVENT_CAUSE = {
|
|
|
17751
18930
|
"quality.finding.accepted": "accepted",
|
|
17752
18931
|
"quality.audit.completed": "audit"
|
|
17753
18932
|
};
|
|
17754
|
-
var
|
|
18933
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17755
18934
|
var isString2 = (value) => typeof value === "string" && value !== "";
|
|
17756
18935
|
var emptyCounts = () => ({ critical: 0, high: 0, medium: 0, low: 0, info: 0 });
|
|
17757
18936
|
var asSeverity = (value) => typeof value === "string" && FINDING_SEVERITIES.includes(value) ? value : null;
|
|
17758
18937
|
function cleanCounts2(raw) {
|
|
17759
18938
|
const counts = emptyCounts();
|
|
17760
|
-
if (!
|
|
18939
|
+
if (!isRecord5(raw)) return counts;
|
|
17761
18940
|
for (const severity of FINDING_SEVERITIES) {
|
|
17762
18941
|
const value = raw[severity];
|
|
17763
18942
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) counts[severity] = value;
|
|
@@ -17772,19 +18951,19 @@ function deriveFindingsBurndown(events, options = {}) {
|
|
|
17772
18951
|
const filtered = surface !== void 0 || domain2 !== void 0;
|
|
17773
18952
|
const sectionById = /* @__PURE__ */ new Map();
|
|
17774
18953
|
for (const finding of Array.isArray(options.findings) ? options.findings : []) {
|
|
17775
|
-
if (
|
|
18954
|
+
if (isRecord5(finding) && isString2(finding.id)) sectionById.set(finding.id, finding);
|
|
17776
18955
|
}
|
|
17777
|
-
const inView = (
|
|
18956
|
+
const inView = (where2) => {
|
|
17778
18957
|
if (!filtered) return true;
|
|
17779
|
-
if (
|
|
17780
|
-
if (surface !== void 0 &&
|
|
17781
|
-
if (domain2 !== void 0 && (!isString2(
|
|
18958
|
+
if (where2 === void 0) return false;
|
|
18959
|
+
if (surface !== void 0 && where2.surface !== surface) return false;
|
|
18960
|
+
if (domain2 !== void 0 && (!isString2(where2.criterion_id) || domainCodeOf(where2.criterion_id, library) !== domain2)) {
|
|
17782
18961
|
return false;
|
|
17783
18962
|
}
|
|
17784
18963
|
return true;
|
|
17785
18964
|
};
|
|
17786
18965
|
const relevant = (Array.isArray(events) ? events : []).filter(
|
|
17787
|
-
(event) =>
|
|
18966
|
+
(event) => isRecord5(event) && typeof event.type === "string" && event.type in EVENT_CAUSE
|
|
17788
18967
|
);
|
|
17789
18968
|
const openedIds = /* @__PURE__ */ new Set();
|
|
17790
18969
|
const decidedIds = /* @__PURE__ */ new Set();
|
|
@@ -17900,9 +19079,9 @@ function burndownSummary(burndown, openNow) {
|
|
|
17900
19079
|
if (burndown.points.length === 0) return null;
|
|
17901
19080
|
const tally = burndown.since ?? burndown;
|
|
17902
19081
|
const closed = tally.resolved + tally.accepted;
|
|
17903
|
-
const
|
|
19082
|
+
const where2 = burndown.since ? ` since the ${burndown.since.audit_id} audit` : "";
|
|
17904
19083
|
const open = openNow ?? openTotal(burndown.points[burndown.points.length - 1].open);
|
|
17905
|
-
return `${closed} closed${
|
|
19084
|
+
return `${closed} closed${where2} (${tally.resolved} resolved, ${tally.accepted} accepted) \xB7 ${tally.opened} opened \xB7 ${open} open`;
|
|
17906
19085
|
}
|
|
17907
19086
|
|
|
17908
19087
|
// src/commands/init.ts
|
|
@@ -18380,8 +19559,8 @@ function countBySpecies(nodes, species) {
|
|
|
18380
19559
|
return nodes.filter((n) => n?.species === species).length;
|
|
18381
19560
|
}
|
|
18382
19561
|
function formatFinding(f) {
|
|
18383
|
-
const
|
|
18384
|
-
return `${f.severity.toUpperCase()} [${f.rule}]${
|
|
19562
|
+
const where2 = f.path ? ` ${f.path}` : "";
|
|
19563
|
+
return `${f.severity.toUpperCase()} [${f.rule}]${where2}: ${f.message}`;
|
|
18385
19564
|
}
|
|
18386
19565
|
function fixFormat(filePath) {
|
|
18387
19566
|
let bundle;
|
|
@@ -18534,6 +19713,14 @@ function renderEventLine(event, nodesById) {
|
|
|
18534
19713
|
const to = str(event.to) ?? "?";
|
|
18535
19714
|
return `${title(event.node_id, nodesById)}: reference ${from ? `${from} -> ${to}` : to}`;
|
|
18536
19715
|
}
|
|
19716
|
+
case "screenshot.recorded": {
|
|
19717
|
+
const platform = str(event.platform);
|
|
19718
|
+
return `${title(event.node_id, nodesById)}: screenshot recorded${platform ? ` [${platform}]` : ""}`;
|
|
19719
|
+
}
|
|
19720
|
+
case "screenshot.removed": {
|
|
19721
|
+
const platform = str(event.platform);
|
|
19722
|
+
return `${title(event.node_id, nodesById)}: screenshot removed${platform ? ` [${platform}]` : ""}`;
|
|
19723
|
+
}
|
|
18537
19724
|
case "journal.baseline": {
|
|
18538
19725
|
const count = Array.isArray(event.node_ids) ? event.node_ids.length : 0;
|
|
18539
19726
|
return `Journal baseline: ${count} pre-existing node(s) recorded`;
|
|
@@ -19440,7 +20627,8 @@ function declaredScopeSince(auditId, recorded) {
|
|
|
19440
20627
|
return since;
|
|
19441
20628
|
}
|
|
19442
20629
|
function auditOrderNote(root, auditId) {
|
|
19443
|
-
const
|
|
20630
|
+
const plan = planIdOfPartId(auditId);
|
|
20631
|
+
const later = listAuditIds(root).filter((id) => id > auditId && (plan === null || planIdOfPartId(id) !== plan));
|
|
19444
20632
|
if (later.length === 0) return void 0;
|
|
19445
20633
|
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.`;
|
|
19446
20634
|
}
|
|
@@ -20593,21 +21781,302 @@ async function runLive(argv, options = {}) {
|
|
|
20593
21781
|
break;
|
|
20594
21782
|
}
|
|
20595
21783
|
}
|
|
20596
|
-
return { ok: true, ids };
|
|
21784
|
+
return { ok: true, ids };
|
|
21785
|
+
}
|
|
21786
|
+
function runLiveCli(argv) {
|
|
21787
|
+
void runLive(argv).then((result) => {
|
|
21788
|
+
if (!result.ok) process.exit(1);
|
|
21789
|
+
});
|
|
21790
|
+
}
|
|
21791
|
+
|
|
21792
|
+
// src/commands/shot.ts
|
|
21793
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
21794
|
+
import { join as join9, resolve as resolve10 } from "node:path";
|
|
21795
|
+
var LINK_FILE3 = "docs/arkaik/arkaik.json";
|
|
21796
|
+
var DEFAULT_BUNDLE_PATH9 = "docs/arkaik/bundle.json";
|
|
21797
|
+
var DEFAULT_BASE_URL3 = "https://arkaik.app";
|
|
21798
|
+
var ACTOR4 = "arkaik-cli";
|
|
21799
|
+
var MAX_ENTRIES_PER_REQUEST2 = 100;
|
|
21800
|
+
var KNOWN_FLAGS2 = /* @__PURE__ */ new Set(["--manifest", "--commit", "--order", "--remote", "--bundle", "--dry-run", "--help"]);
|
|
21801
|
+
var VALUED_FLAGS2 = /* @__PURE__ */ new Set(["--manifest", "--commit", "--order", "--remote", "--bundle"]);
|
|
21802
|
+
var USAGE12 = `arkaik shot \u2014 record screenshots for views and acceptances
|
|
21803
|
+
|
|
21804
|
+
Usage:
|
|
21805
|
+
arkaik shot --manifest <file> --commit <sha> --order <n> [options]
|
|
21806
|
+
arkaik shot <node_id> <platform> <value> [--commit <sha> --order <n>]
|
|
21807
|
+
|
|
21808
|
+
Options:
|
|
21809
|
+
--manifest <file> JSON array of { node_id, platform, url, detail? }.
|
|
21810
|
+
--commit <sha> The commit the shots were rendered from. Required when hosted.
|
|
21811
|
+
--order <n> The commit's height on the default branch (git rev-list --count). Required with --commit.
|
|
21812
|
+
--remote <url> Hosted only: the instance origin. Default: $ARKAIK_URL, else the link file's remote, else ${DEFAULT_BASE_URL3}
|
|
21813
|
+
--bundle <path> Kommit only: the bundle to write (default: ${DEFAULT_BUNDLE_PATH9}).
|
|
21814
|
+
--dry-run Show what would be recorded and exit 0.
|
|
21815
|
+
-h, --help Show this help.
|
|
21816
|
+
|
|
21817
|
+
Environment:
|
|
21818
|
+
ARKAIK_TOKEN Required when hosted. A screenshot:append token from <origin>/settings/tokens.
|
|
21819
|
+
|
|
21820
|
+
Reads ${LINK_FILE3} for the project id; without it the repo bundle is written instead.
|
|
21821
|
+
Exit 0 when every entry is recorded or skipped; exit 1 on a refusal or any failed request.`;
|
|
21822
|
+
function schemeOf(value) {
|
|
21823
|
+
const match = /^([a-z][a-z0-9+.-]*:)/i.exec(value);
|
|
21824
|
+
return match === null ? void 0 : match[1].toLowerCase();
|
|
21825
|
+
}
|
|
21826
|
+
function flagValue3(argv, flag) {
|
|
21827
|
+
const at2 = argv.indexOf(flag);
|
|
21828
|
+
return at2 === -1 ? void 0 : argv[at2 + 1];
|
|
21829
|
+
}
|
|
21830
|
+
function readManifest(file2) {
|
|
21831
|
+
let parsed;
|
|
21832
|
+
try {
|
|
21833
|
+
parsed = JSON.parse(readFileSync10(file2, "utf8"));
|
|
21834
|
+
} catch (e) {
|
|
21835
|
+
return { error: `Could not read ${file2}: ${e.message}` };
|
|
21836
|
+
}
|
|
21837
|
+
if (!Array.isArray(parsed)) return { error: `${file2} must be a JSON array of { node_id, platform, url, detail? }` };
|
|
21838
|
+
const entries = [];
|
|
21839
|
+
for (const [i, raw] of parsed.entries()) {
|
|
21840
|
+
if (typeof raw !== "object" || raw === null) return { error: `${file2}[${i}] must be an object` };
|
|
21841
|
+
const r = raw;
|
|
21842
|
+
if (typeof r.node_id !== "string" || r.node_id === "") return { error: `${file2}[${i}].node_id must be a non-empty string` };
|
|
21843
|
+
if (typeof r.platform !== "string" || !isPlatformId(r.platform)) return { error: `${file2}[${i}].platform must be one of: ${PLATFORM_IDS.join(", ")}` };
|
|
21844
|
+
if (typeof r.url !== "string" || r.url === "") return { error: `${file2}[${i}].url must be a non-empty string` };
|
|
21845
|
+
if (r.detail !== void 0 && typeof r.detail !== "string") return { error: `${file2}[${i}].detail must be a string` };
|
|
21846
|
+
entries.push({ node_id: r.node_id, platform: r.platform, url: r.url, ...typeof r.detail === "string" && r.detail !== "" ? { detail: r.detail } : {} });
|
|
21847
|
+
}
|
|
21848
|
+
return entries;
|
|
21849
|
+
}
|
|
21850
|
+
function describeFailure3(status, baseUrl, body) {
|
|
21851
|
+
if (status === 401) return `Unauthorized \u2014 check ARKAIK_TOKEN (create one at ${baseUrl}/settings/tokens).`;
|
|
21852
|
+
if (status === 403) return "Forbidden \u2014 this token lacks the screenshot:append scope (or graph:write).";
|
|
21853
|
+
if (status === 404) return `No linked project in this account \u2014 check ${LINK_FILE3}.`;
|
|
21854
|
+
if (status === 409) return "The project changed under every retry \u2014 run again.";
|
|
21855
|
+
return `Request failed (${status})${body.message ? ` \u2014 ${body.message}` : body.error ? ` \u2014 ${body.error}` : ""}.`;
|
|
21856
|
+
}
|
|
21857
|
+
async function runShot(argv, options = {}) {
|
|
21858
|
+
const log = options.log ?? ((m) => console.log(m));
|
|
21859
|
+
const errorLog = options.errorLog ?? ((m) => console.error(m));
|
|
21860
|
+
const env = options.env ?? process.env;
|
|
21861
|
+
const cwd = options.cwd ?? process.cwd();
|
|
21862
|
+
const doFetch = options.httpClient ?? ((...args) => fetch(...args));
|
|
21863
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
21864
|
+
log(USAGE12);
|
|
21865
|
+
return { ok: true };
|
|
21866
|
+
}
|
|
21867
|
+
const positional = [];
|
|
21868
|
+
for (let i = 0; i < argv.length; i++) {
|
|
21869
|
+
const arg = argv[i];
|
|
21870
|
+
if (VALUED_FLAGS2.has(arg)) {
|
|
21871
|
+
i++;
|
|
21872
|
+
continue;
|
|
21873
|
+
}
|
|
21874
|
+
if (arg.startsWith("--")) {
|
|
21875
|
+
if (KNOWN_FLAGS2.has(arg)) continue;
|
|
21876
|
+
errorLog(`Unknown flag ${arg}. Flags take a separate value (--manifest shots.json), see arkaik shot --help.`);
|
|
21877
|
+
return { ok: false };
|
|
21878
|
+
}
|
|
21879
|
+
positional.push(arg);
|
|
21880
|
+
}
|
|
21881
|
+
if (positional.length !== 0 && positional.length !== 3) {
|
|
21882
|
+
errorLog("A positional shot is exactly <node_id> <platform> <value>; see arkaik shot --help.");
|
|
21883
|
+
return { ok: false };
|
|
21884
|
+
}
|
|
21885
|
+
const manifestFile = flagValue3(argv, "--manifest");
|
|
21886
|
+
const commit = flagValue3(argv, "--commit");
|
|
21887
|
+
const orderArg = flagValue3(argv, "--order");
|
|
21888
|
+
const dryRun = argv.includes("--dry-run");
|
|
21889
|
+
let order;
|
|
21890
|
+
if (orderArg !== void 0) {
|
|
21891
|
+
order = Number(orderArg);
|
|
21892
|
+
if (!Number.isInteger(order) || order < 0) {
|
|
21893
|
+
errorLog(`--order must be a non-negative integer, got "${orderArg}".`);
|
|
21894
|
+
return { ok: false };
|
|
21895
|
+
}
|
|
21896
|
+
}
|
|
21897
|
+
if (commit !== void 0 && order === void 0) {
|
|
21898
|
+
errorLog("--order is required with --commit: the commit's height on the default branch (git rev-list --count <sha>).");
|
|
21899
|
+
return { ok: false };
|
|
21900
|
+
}
|
|
21901
|
+
const entries = [];
|
|
21902
|
+
if (manifestFile !== void 0) {
|
|
21903
|
+
const read = readManifest(resolve10(cwd, manifestFile));
|
|
21904
|
+
if (!Array.isArray(read)) {
|
|
21905
|
+
errorLog(read.error);
|
|
21906
|
+
return { ok: false };
|
|
21907
|
+
}
|
|
21908
|
+
entries.push(...read);
|
|
21909
|
+
}
|
|
21910
|
+
if (positional.length === 3) {
|
|
21911
|
+
const [node_id, platform, url2] = positional;
|
|
21912
|
+
if (!isPlatformId(platform)) {
|
|
21913
|
+
errorLog(`"${platform}" is not a platform. Expected one of: ${PLATFORM_IDS.join(", ")}.`);
|
|
21914
|
+
return { ok: false };
|
|
21915
|
+
}
|
|
21916
|
+
entries.push({ node_id, platform, url: url2 });
|
|
21917
|
+
}
|
|
21918
|
+
if (entries.length === 0) {
|
|
21919
|
+
errorLog("Nothing to record: pass --manifest <file> or <node_id> <platform> <value>.");
|
|
21920
|
+
return { ok: false };
|
|
21921
|
+
}
|
|
21922
|
+
for (const e of entries) {
|
|
21923
|
+
const scheme = schemeOf(e.url);
|
|
21924
|
+
if (scheme !== void 0 && scheme !== "https:" && scheme !== "data:") {
|
|
21925
|
+
errorLog(`"${e.url}": screenshot values must be https:// URLs, image data URIs, or paths relative to the bundle (got ${scheme})`);
|
|
21926
|
+
return { ok: false };
|
|
21927
|
+
}
|
|
21928
|
+
}
|
|
21929
|
+
const linkPath = join9(cwd, LINK_FILE3);
|
|
21930
|
+
if (existsSync9(linkPath)) {
|
|
21931
|
+
return runHosted({ entries, commit, order, dryRun, linkPath, argv, env, doFetch, log, errorLog });
|
|
21932
|
+
}
|
|
21933
|
+
return runKommit({ entries, commit, order, dryRun, cwd, argv, log, errorLog });
|
|
21934
|
+
}
|
|
21935
|
+
async function runHosted(input) {
|
|
21936
|
+
const { entries, commit, order, dryRun, linkPath, argv, env, doFetch, log, errorLog } = input;
|
|
21937
|
+
if (commit === void 0 || order === void 0) {
|
|
21938
|
+
errorLog("--commit and --order are required against a hosted project: the door records CI shots, and a CI shot without provenance is worthless.");
|
|
21939
|
+
return { ok: false };
|
|
21940
|
+
}
|
|
21941
|
+
let link;
|
|
21942
|
+
try {
|
|
21943
|
+
link = JSON.parse(readFileSync10(linkPath, "utf8"));
|
|
21944
|
+
} catch {
|
|
21945
|
+
errorLog(`Could not read ${LINK_FILE3}.`);
|
|
21946
|
+
return { ok: false };
|
|
21947
|
+
}
|
|
21948
|
+
const projectId = link.project_id;
|
|
21949
|
+
if (!projectId) {
|
|
21950
|
+
errorLog(`${LINK_FILE3} has no project_id. Run \`arkaik link --project <id>\`.`);
|
|
21951
|
+
return { ok: false };
|
|
21952
|
+
}
|
|
21953
|
+
const baseUrl = (flagValue3(argv, "--remote") ?? env.ARKAIK_URL ?? link.remote ?? DEFAULT_BASE_URL3).replace(/\/+$/, "");
|
|
21954
|
+
const doorEntries = entries.map((e) => ({ node_id: e.node_id, platform: e.platform, url: e.url, commit, order, ...e.detail !== void 0 ? { detail: e.detail } : {} }));
|
|
21955
|
+
if (dryRun) {
|
|
21956
|
+
log(`Would record ${doorEntries.length} screenshot(s) on ${projectId} (${baseUrl}) from ${commit} (order ${order}):`);
|
|
21957
|
+
for (const e of doorEntries) log(` ${e.node_id}@${e.platform} \u2190 ${e.url}`);
|
|
21958
|
+
return { ok: true };
|
|
21959
|
+
}
|
|
21960
|
+
const token = env.ARKAIK_TOKEN;
|
|
21961
|
+
if (!token) {
|
|
21962
|
+
errorLog(`ARKAIK_TOKEN is not set. Create a screenshot:append token at ${baseUrl}/settings/tokens and export it.`);
|
|
21963
|
+
return { ok: false };
|
|
21964
|
+
}
|
|
21965
|
+
for (let start = 0; start < doorEntries.length; start += MAX_ENTRIES_PER_REQUEST2) {
|
|
21966
|
+
const chunk = doorEntries.slice(start, start + MAX_ENTRIES_PER_REQUEST2);
|
|
21967
|
+
let res;
|
|
21968
|
+
try {
|
|
21969
|
+
res = await doFetch(`${baseUrl}/api/graph/projects/${encodeURIComponent(projectId)}/screenshots`, {
|
|
21970
|
+
method: "POST",
|
|
21971
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
21972
|
+
body: JSON.stringify({ entries: chunk })
|
|
21973
|
+
});
|
|
21974
|
+
} catch (e) {
|
|
21975
|
+
errorLog(`Could not reach ${baseUrl}: ${e.message}`);
|
|
21976
|
+
return { ok: false };
|
|
21977
|
+
}
|
|
21978
|
+
let body = {};
|
|
21979
|
+
try {
|
|
21980
|
+
body = await res.json();
|
|
21981
|
+
} catch {
|
|
21982
|
+
}
|
|
21983
|
+
if (res.status === 422 && Array.isArray(body.refusals)) {
|
|
21984
|
+
for (const r of body.refusals) {
|
|
21985
|
+
const e = chunk[r.index];
|
|
21986
|
+
errorLog(`refused: ${e?.node_id ?? r.node_id}@${e?.platform ?? r.platform} \u2014 ${r.reason}${r.detail ? ` (${r.detail})` : ""}`);
|
|
21987
|
+
}
|
|
21988
|
+
errorLog(start > 0 ? `Nothing from entries ${start}\u2013${start + chunk.length - 1} was recorded: a refused entry refuses its whole batch (the ${start} before them were applied above).` : "Nothing was recorded: a refused entry refuses the whole batch.");
|
|
21989
|
+
return { ok: false };
|
|
21990
|
+
}
|
|
21991
|
+
if (!res.ok) {
|
|
21992
|
+
errorLog(describeFailure3(res.status, baseUrl, body));
|
|
21993
|
+
return { ok: false };
|
|
21994
|
+
}
|
|
21995
|
+
for (const a of body.applied ?? []) log(`recorded: ${a.node_id}@${a.platform} \u2190 ${a.url}`);
|
|
21996
|
+
for (const s of body.skipped ?? []) log(`skipped: ${s.node_id}@${s.platform} \u2014 ${s.reason}`);
|
|
21997
|
+
}
|
|
21998
|
+
return { ok: true };
|
|
21999
|
+
}
|
|
22000
|
+
function formOf(value) {
|
|
22001
|
+
if (/^https:\/\//i.test(value)) return "url";
|
|
22002
|
+
if (/^data:/i.test(value)) return "data";
|
|
22003
|
+
return "path";
|
|
22004
|
+
}
|
|
22005
|
+
function runKommit(input) {
|
|
22006
|
+
const { entries, commit, order, dryRun, cwd, argv, log, errorLog } = input;
|
|
22007
|
+
const bundlePath = resolve10(cwd, flagValue3(argv, "--bundle") ?? DEFAULT_BUNDLE_PATH9);
|
|
22008
|
+
let bundle;
|
|
22009
|
+
try {
|
|
22010
|
+
bundle = readBundle(bundlePath);
|
|
22011
|
+
} catch (e) {
|
|
22012
|
+
errorLog(`FATAL: ${e.message}`);
|
|
22013
|
+
return { ok: false };
|
|
22014
|
+
}
|
|
22015
|
+
const source = commit !== void 0 ? "ci" : "manual";
|
|
22016
|
+
const ops = entries.map((e) => ({
|
|
22017
|
+
op: "record_screenshot",
|
|
22018
|
+
node_id: e.node_id,
|
|
22019
|
+
platform: e.platform,
|
|
22020
|
+
source,
|
|
22021
|
+
form: formOf(e.url),
|
|
22022
|
+
value: e.url,
|
|
22023
|
+
...commit !== void 0 ? { commit, order } : {},
|
|
22024
|
+
...e.detail !== void 0 ? { detail: e.detail } : {}
|
|
22025
|
+
}));
|
|
22026
|
+
if (dryRun) {
|
|
22027
|
+
log(`Would record ${ops.length} ${source} screenshot(s) into ${bundlePath}:`);
|
|
22028
|
+
for (const e of entries) log(` ${e.node_id}@${e.platform} \u2190 ${e.url}`);
|
|
22029
|
+
return { ok: true };
|
|
22030
|
+
}
|
|
22031
|
+
const project = bundle.project;
|
|
22032
|
+
if (typeof project !== "object" || project === null || !("id" in project) || typeof project.id !== "string") {
|
|
22033
|
+
errorLog(`FATAL: ${bundlePath} has no project.id.`);
|
|
22034
|
+
return { ok: false };
|
|
22035
|
+
}
|
|
22036
|
+
const nodes = Array.isArray(bundle.nodes) ? bundle.nodes : [];
|
|
22037
|
+
const edges = Array.isArray(bundle.edges) ? bundle.edges : [];
|
|
22038
|
+
let outcome;
|
|
22039
|
+
try {
|
|
22040
|
+
outcome = applyOps({ projectId: project.id, nodes, edges }, ops);
|
|
22041
|
+
} catch (e) {
|
|
22042
|
+
errorLog(`FATAL: ${e.message}`);
|
|
22043
|
+
return { ok: false };
|
|
22044
|
+
}
|
|
22045
|
+
if (outcome.eventInputs.length === 0) {
|
|
22046
|
+
log("Nothing to record: every slot already holds this value, or a newer CI shot outranks it.");
|
|
22047
|
+
return { ok: true };
|
|
22048
|
+
}
|
|
22049
|
+
let events;
|
|
22050
|
+
try {
|
|
22051
|
+
events = toJournalEvents(outcome.eventInputs, ACTOR4);
|
|
22052
|
+
} catch (e) {
|
|
22053
|
+
errorLog(`FATAL: could not build screenshot event \u2014 ${e.message}`);
|
|
22054
|
+
return { ok: false };
|
|
22055
|
+
}
|
|
22056
|
+
const next = { ...bundle, nodes: outcome.nodes, edges: outcome.edges, project: { ...project, updated_at: (/* @__PURE__ */ new Date()).toISOString() } };
|
|
22057
|
+
const journalPath = journalPathFor(bundlePath);
|
|
22058
|
+
const baseline = ensureJournalBaseline(journalPath, bundle, ACTOR4);
|
|
22059
|
+
writeFileSync9(bundlePath, serializeBundle(next));
|
|
22060
|
+
if (baseline !== void 0) log(` ${renderEventLine(baseline)} -> ${journalPath}`);
|
|
22061
|
+
for (const event of events) {
|
|
22062
|
+
appendJournalEvent(journalPath, event);
|
|
22063
|
+
log(` ${renderEventLine(event)} -> ${journalPath}`);
|
|
22064
|
+
}
|
|
22065
|
+
return { ok: true };
|
|
20597
22066
|
}
|
|
20598
|
-
function
|
|
20599
|
-
void
|
|
22067
|
+
function runShotCli(argv) {
|
|
22068
|
+
void runShot(argv).then((result) => {
|
|
20600
22069
|
if (!result.ok) process.exit(1);
|
|
20601
22070
|
});
|
|
20602
22071
|
}
|
|
20603
22072
|
|
|
20604
22073
|
// src/commands/restore.ts
|
|
20605
|
-
import { existsSync as
|
|
20606
|
-
import { join as
|
|
20607
|
-
var
|
|
20608
|
-
var
|
|
22074
|
+
import { existsSync as existsSync10, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync11, unlinkSync, writeFileSync as writeFileSync10 } from "node:fs";
|
|
22075
|
+
import { join as join10, resolve as resolve11 } from "node:path";
|
|
22076
|
+
var LINK_FILE4 = "docs/arkaik/arkaik.json";
|
|
22077
|
+
var DEFAULT_BUNDLE_PATH10 = "docs/arkaik/bundle.json";
|
|
20609
22078
|
var DEFAULT_API_BASE2 = "https://arkaik.app";
|
|
20610
|
-
var
|
|
22079
|
+
var USAGE13 = `arkaik restore [options] [path]
|
|
20611
22080
|
|
|
20612
22081
|
Replace the linked hosted project's bundle, journal AND quality section with
|
|
20613
22082
|
a local bundle \u2014
|
|
@@ -20620,7 +22089,7 @@ only way back if the restore turns out to be wrong.
|
|
|
20620
22089
|
|
|
20621
22090
|
Arguments:
|
|
20622
22091
|
path Path to the local bundle JSON file
|
|
20623
|
-
(default: ${
|
|
22092
|
+
(default: ${DEFAULT_BUNDLE_PATH10}). Its journal.jsonl
|
|
20624
22093
|
sidecar (or an embedded journal, which wins) is folded
|
|
20625
22094
|
in automatically, as is the docs/quality/ tree of the
|
|
20626
22095
|
repo that bundle belongs to.
|
|
@@ -20654,6 +22123,12 @@ Options:
|
|
|
20654
22123
|
flag, that refuses outright \u2014 it usually means
|
|
20655
22124
|
docs/quality/ was looked for in the wrong place, which
|
|
20656
22125
|
--root fixes, rather than an intended wipe.
|
|
22126
|
+
--allow-metadata-loss Proceed even though the local bundle's project.metadata
|
|
22127
|
+
lacks settings the hosted project has (products, maps,
|
|
22128
|
+
ref_policy, pollen, ...). Without this flag, that
|
|
22129
|
+
refuses outright and names the keys \u2014 those settings
|
|
22130
|
+
are usually edited in the app and never reach the
|
|
22131
|
+
repo bundle, so a restore would silently delete them.
|
|
20657
22132
|
--audit <id> Fold ONE audit's snapshot rather than merging every
|
|
20658
22133
|
audit into current state. An id that is not on disk is
|
|
20659
22134
|
an error, not an empty section.
|
|
@@ -20767,7 +22242,7 @@ async function interpretPutResponse(res, ctx) {
|
|
|
20767
22242
|
}
|
|
20768
22243
|
function writeBackupFile(filePath, content) {
|
|
20769
22244
|
const tmpPath = `${filePath}.tmp-${process.pid}`;
|
|
20770
|
-
|
|
22245
|
+
writeFileSync10(tmpPath, content);
|
|
20771
22246
|
try {
|
|
20772
22247
|
linkSync(tmpPath, filePath);
|
|
20773
22248
|
} finally {
|
|
@@ -20827,7 +22302,7 @@ function describeQualityLoss(hostedQuality, qualityRoot, noQuality, foldNotice)
|
|
|
20827
22302
|
lines.push("The outbound bundle has no section because the fold found nothing to build one from:");
|
|
20828
22303
|
lines.push(` ${foldNotice}`);
|
|
20829
22304
|
}
|
|
20830
|
-
if (!
|
|
22305
|
+
if (!existsSync10(join10(qualityRoot, QUALITY_DIR))) {
|
|
20831
22306
|
lines.push(
|
|
20832
22307
|
`There is no ${QUALITY_DIR}/ under ${qualityRoot} at all. If this project's sidecars live somewhere else, point --root at that repo and the section is rebuilt rather than removed.`
|
|
20833
22308
|
);
|
|
@@ -20836,6 +22311,21 @@ function describeQualityLoss(hostedQuality, qualityRoot, noQuality, foldNotice)
|
|
|
20836
22311
|
}
|
|
20837
22312
|
return lines.join("\n");
|
|
20838
22313
|
}
|
|
22314
|
+
function droppedMetadataKeys(hostedProject, outboundProject) {
|
|
22315
|
+
const metadataOf = (project) => {
|
|
22316
|
+
if (typeof project !== "object" || project === null || Array.isArray(project)) return {};
|
|
22317
|
+
const metadata = project.metadata;
|
|
22318
|
+
return typeof metadata === "object" && metadata !== null && !Array.isArray(metadata) ? metadata : {};
|
|
22319
|
+
};
|
|
22320
|
+
const outbound = metadataOf(outboundProject);
|
|
22321
|
+
return Object.keys(metadataOf(hostedProject)).filter((key) => !(key in outbound)).sort();
|
|
22322
|
+
}
|
|
22323
|
+
function describeMetadataLoss(dropped, bundlePath) {
|
|
22324
|
+
return [
|
|
22325
|
+
`This restore would DELETE ${dropped.length} hosted project setting${dropped.length === 1 ? "" : "s"} (project.metadata: ${dropped.join(", ")}) that ${bundlePath} does not carry. Nothing was sent.`,
|
|
22326
|
+
`Those settings are usually edited in the app and never reach the repo bundle. Copy them into the local bundle's project.metadata (GET .../export has them) so the restore keeps them, or re-run with --allow-metadata-loss if they really are meant to go.`
|
|
22327
|
+
].join("\n");
|
|
22328
|
+
}
|
|
20839
22329
|
async function runRestore(options = {}) {
|
|
20840
22330
|
const cwd = options.cwd ?? process.cwd();
|
|
20841
22331
|
const env = options.env ?? process.env;
|
|
@@ -20844,28 +22334,29 @@ async function runRestore(options = {}) {
|
|
|
20844
22334
|
const allowDeletions = options.allowDeletions ?? false;
|
|
20845
22335
|
const noQuality = options.noQuality ?? false;
|
|
20846
22336
|
const allowQualityLoss = options.allowQualityLoss ?? false;
|
|
22337
|
+
const allowMetadataLoss = options.allowMetadataLoss ?? false;
|
|
20847
22338
|
const httpClient = options.httpClient ?? DEFAULT_HTTP_CLIENT;
|
|
20848
|
-
const linkPath =
|
|
20849
|
-
if (!
|
|
20850
|
-
return fatalResult5(dryRun, `No ${
|
|
22339
|
+
const linkPath = join10(cwd, LINK_FILE4);
|
|
22340
|
+
if (!existsSync10(linkPath)) {
|
|
22341
|
+
return fatalResult5(dryRun, `No ${LINK_FILE4}. Run \`arkaik link\` first \u2014 restore only targets hosted projects.`);
|
|
20851
22342
|
}
|
|
20852
22343
|
let link;
|
|
20853
22344
|
try {
|
|
20854
|
-
link = JSON.parse(
|
|
22345
|
+
link = JSON.parse(readFileSync11(linkPath, "utf8"));
|
|
20855
22346
|
} catch (e) {
|
|
20856
|
-
return fatalResult5(dryRun, `Could not parse ${
|
|
22347
|
+
return fatalResult5(dryRun, `Could not parse ${LINK_FILE4}: ${e.message}`);
|
|
20857
22348
|
}
|
|
20858
22349
|
const projectId = link.project_id;
|
|
20859
|
-
if (!projectId) return fatalResult5(dryRun, `${
|
|
22350
|
+
if (!projectId) return fatalResult5(dryRun, `${LINK_FILE4} has no project_id. Run \`arkaik link --project <id>\`.`);
|
|
20860
22351
|
const baseUrl = (options.apiBase ?? env.ARKAIK_URL ?? link.remote ?? DEFAULT_API_BASE2).replace(/\/+$/, "");
|
|
20861
22352
|
const encodedProjectId = encodeURIComponent(projectId);
|
|
20862
22353
|
const token = env.ARKAIK_TOKEN;
|
|
20863
22354
|
if (!token) return fatalResult5(dryRun, `ARKAIK_TOKEN is not set. Create a token at ${baseUrl}/settings/tokens and export it.`);
|
|
20864
|
-
const bundlePath =
|
|
20865
|
-
if (!
|
|
22355
|
+
const bundlePath = resolve11(cwd, options.path ?? DEFAULT_BUNDLE_PATH10);
|
|
22356
|
+
if (!existsSync10(bundlePath)) return fatalResult5(dryRun, `No bundle at ${bundlePath}. Run \`arkaik merge\` (or \`arkaik pack\`) first.`);
|
|
20866
22357
|
let localRaw;
|
|
20867
22358
|
try {
|
|
20868
|
-
localRaw = JSON.parse(
|
|
22359
|
+
localRaw = JSON.parse(readFileSync11(bundlePath, "utf8"));
|
|
20869
22360
|
} catch (e) {
|
|
20870
22361
|
return fatalResult5(dryRun, `Could not parse ${bundlePath}: ${e.message}`);
|
|
20871
22362
|
}
|
|
@@ -20954,20 +22445,24 @@ async function runRestore(options = {}) {
|
|
|
20954
22445
|
if (isQualitySection(hostedQuality) && !isQualitySection(outboundBundle.quality) && !allowQualityLoss) {
|
|
20955
22446
|
return fatalResult5(dryRun, describeQualityLoss(hostedQuality, qualityRoot, noQuality, qualityNotice), qualityFields);
|
|
20956
22447
|
}
|
|
22448
|
+
const droppedKeys = droppedMetadataKeys(exportedBundle.project, outboundBundle.project);
|
|
22449
|
+
if (droppedKeys.length > 0 && !allowMetadataLoss) {
|
|
22450
|
+
return fatalResult5(dryRun, describeMetadataLoss(droppedKeys, bundlePath), qualityFields);
|
|
22451
|
+
}
|
|
20957
22452
|
const removedNodes = removedIds(exportedBundle.nodes, Array.isArray(local.nodes) ? local.nodes : []);
|
|
20958
22453
|
const removedEdges = removedIds(exportedBundle.edges, Array.isArray(local.edges) ? local.edges : []);
|
|
20959
22454
|
if ((removedNodes.length > 0 || removedEdges.length > 0) && !allowDeletions) {
|
|
20960
22455
|
return fatalResult5(dryRun, describeDeletions(removedNodes, removedEdges, bundlePath), qualityFields);
|
|
20961
22456
|
}
|
|
20962
|
-
const backupDir =
|
|
22457
|
+
const backupDir = join10(cwd, "docs", "arkaik", ".backups");
|
|
20963
22458
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
20964
|
-
const backupPath =
|
|
22459
|
+
const backupPath = join10(backupDir, `${stamp}-bundle.json`);
|
|
20965
22460
|
const backupContent = `${JSON.stringify(exported, null, 2)}
|
|
20966
22461
|
`;
|
|
20967
22462
|
try {
|
|
20968
22463
|
mkdirSync6(backupDir, { recursive: true });
|
|
20969
22464
|
writeBackupFile(backupPath, backupContent);
|
|
20970
|
-
JSON.parse(
|
|
22465
|
+
JSON.parse(readFileSync11(backupPath, "utf8"));
|
|
20971
22466
|
} catch (e) {
|
|
20972
22467
|
return fatalResult5(
|
|
20973
22468
|
dryRun,
|
|
@@ -21036,7 +22531,7 @@ function reportRestore(result) {
|
|
|
21036
22531
|
console.log("[dry-run] server preview \u2014 nothing was written:");
|
|
21037
22532
|
printDelta(result.delta);
|
|
21038
22533
|
console.log(
|
|
21039
|
-
"Re-run without --dry-run to apply \u2014 that run takes the backup, and only that run checks the history, deletion and
|
|
22534
|
+
"Re-run without --dry-run to apply \u2014 that run takes the backup, and only that run checks the history, deletion, quality-loss and metadata-loss guards (all four read the export, which a dry run never fetches)."
|
|
21040
22535
|
);
|
|
21041
22536
|
} else {
|
|
21042
22537
|
console.log(`Restored. New version ${result.version}.`);
|
|
@@ -21060,6 +22555,7 @@ function runRestoreCli(argv) {
|
|
|
21060
22555
|
let allowDeletions = false;
|
|
21061
22556
|
let noQuality = false;
|
|
21062
22557
|
let allowQualityLoss = false;
|
|
22558
|
+
let allowMetadataLoss = false;
|
|
21063
22559
|
let audit;
|
|
21064
22560
|
let root;
|
|
21065
22561
|
let apiBase;
|
|
@@ -21067,7 +22563,7 @@ function runRestoreCli(argv) {
|
|
|
21067
22563
|
for (let i = 0; i < argv.length; i++) {
|
|
21068
22564
|
const arg = argv[i];
|
|
21069
22565
|
if (arg === "-h" || arg === "--help") {
|
|
21070
|
-
console.log(
|
|
22566
|
+
console.log(USAGE13);
|
|
21071
22567
|
process.exitCode = 0;
|
|
21072
22568
|
return;
|
|
21073
22569
|
} else if (arg === "--dry-run") {
|
|
@@ -21080,55 +22576,68 @@ function runRestoreCli(argv) {
|
|
|
21080
22576
|
noQuality = true;
|
|
21081
22577
|
} else if (arg === "--allow-quality-loss") {
|
|
21082
22578
|
allowQualityLoss = true;
|
|
22579
|
+
} else if (arg === "--allow-metadata-loss") {
|
|
22580
|
+
allowMetadataLoss = true;
|
|
21083
22581
|
} else if (arg === "--audit") {
|
|
21084
22582
|
const value = argv[++i];
|
|
21085
22583
|
if (value === void 0) fail10(`Missing value for --audit
|
|
21086
22584
|
|
|
21087
|
-
${
|
|
22585
|
+
${USAGE13}`);
|
|
21088
22586
|
audit = value;
|
|
21089
22587
|
} else if (arg === "--root") {
|
|
21090
22588
|
const value = argv[++i];
|
|
21091
22589
|
if (value === void 0) fail10(`Missing value for --root
|
|
21092
22590
|
|
|
21093
|
-
${
|
|
22591
|
+
${USAGE13}`);
|
|
21094
22592
|
root = value;
|
|
21095
22593
|
} else if (arg === "--api") {
|
|
21096
22594
|
const value = argv[++i];
|
|
21097
22595
|
if (value === void 0) fail10(`Missing value for --api
|
|
21098
22596
|
|
|
21099
|
-
${
|
|
22597
|
+
${USAGE13}`);
|
|
21100
22598
|
apiBase = value;
|
|
21101
22599
|
} else if (arg.startsWith("-")) {
|
|
21102
22600
|
fail10(`Unknown option: ${arg}
|
|
21103
22601
|
|
|
21104
|
-
${
|
|
22602
|
+
${USAGE13}`);
|
|
21105
22603
|
} else {
|
|
21106
22604
|
positionals.push(arg);
|
|
21107
22605
|
}
|
|
21108
22606
|
}
|
|
21109
22607
|
if (positionals.length > 1) fail10(`Unexpected argument(s): ${positionals.slice(1).join(" ")}
|
|
21110
22608
|
|
|
21111
|
-
${
|
|
22609
|
+
${USAGE13}`);
|
|
21112
22610
|
if (noQuality && audit !== void 0) {
|
|
21113
22611
|
fail10(`--audit and --no-quality contradict each other: one names an audit to fold, the other removes the section
|
|
21114
22612
|
|
|
21115
|
-
${
|
|
22613
|
+
${USAGE13}`);
|
|
21116
22614
|
}
|
|
21117
|
-
runRestore({
|
|
22615
|
+
runRestore({
|
|
22616
|
+
path: positionals[0],
|
|
22617
|
+
dryRun,
|
|
22618
|
+
allowHistoryLoss,
|
|
22619
|
+
allowDeletions,
|
|
22620
|
+
noQuality,
|
|
22621
|
+
allowQualityLoss,
|
|
22622
|
+
allowMetadataLoss,
|
|
22623
|
+
audit,
|
|
22624
|
+
root,
|
|
22625
|
+
apiBase
|
|
22626
|
+
}).then((result) => reportRestore(result)).catch((e) => fail10(`FATAL: ${e.message}`));
|
|
21118
22627
|
}
|
|
21119
22628
|
|
|
21120
22629
|
// src/commands/bootstrap.ts
|
|
21121
22630
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
21122
|
-
import { existsSync as
|
|
22631
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync8, renameSync, writeFileSync as writeFileSync14 } from "node:fs";
|
|
21123
22632
|
import path5 from "node:path";
|
|
21124
22633
|
|
|
21125
22634
|
// src/lib/bootstrap/corpus.ts
|
|
21126
22635
|
import { spawnSync } from "node:child_process";
|
|
21127
|
-
import { existsSync as
|
|
22636
|
+
import { existsSync as existsSync12, readdirSync as readdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync12 } from "node:fs";
|
|
21128
22637
|
import path2 from "node:path";
|
|
21129
22638
|
|
|
21130
22639
|
// src/lib/bootstrap/paths.ts
|
|
21131
|
-
import { existsSync as
|
|
22640
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync7, readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "node:fs";
|
|
21132
22641
|
import path from "node:path";
|
|
21133
22642
|
var BOOTSTRAP_ROOT = ".arkaik";
|
|
21134
22643
|
var CORPUS_DIR = ".arkaik/corpus";
|
|
@@ -21148,11 +22657,11 @@ function ensureDir(dirPath) {
|
|
|
21148
22657
|
function ensureGitignored(cwd) {
|
|
21149
22658
|
const file2 = path.join(cwd, ".gitignore");
|
|
21150
22659
|
const line2 = `${BOOTSTRAP_ROOT}/`;
|
|
21151
|
-
const current =
|
|
22660
|
+
const current = existsSync11(file2) ? readFileSync12(file2, "utf8") : "";
|
|
21152
22661
|
const ignored = current.split("\n").map((l) => l.trim()).some((l) => l === line2 || l === BOOTSTRAP_ROOT);
|
|
21153
22662
|
if (ignored) return false;
|
|
21154
22663
|
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
21155
|
-
|
|
22664
|
+
writeFileSync11(file2, `${current}${prefix}${line2}
|
|
21156
22665
|
`);
|
|
21157
22666
|
return true;
|
|
21158
22667
|
}
|
|
@@ -21267,7 +22776,7 @@ function listFiles(cwd) {
|
|
|
21267
22776
|
}
|
|
21268
22777
|
function buildDocsManifest(cwd, files) {
|
|
21269
22778
|
return files.filter((f) => f.startsWith("docs/") && f.endsWith(".md")).map((f) => {
|
|
21270
|
-
const text =
|
|
22779
|
+
const text = readFileSync13(path2.join(cwd, f), "utf8");
|
|
21271
22780
|
const heading = /^#\s+(.+)$/m.exec(text);
|
|
21272
22781
|
return { path: f, title: heading ? heading[1].trim() : path2.basename(f, ".md") };
|
|
21273
22782
|
});
|
|
@@ -21282,7 +22791,7 @@ function buildSurfaceInventory(files) {
|
|
|
21282
22791
|
}
|
|
21283
22792
|
function buildCorpus(options) {
|
|
21284
22793
|
const { cwd } = options;
|
|
21285
|
-
const raw = options.fromJson ? JSON.parse(
|
|
22794
|
+
const raw = options.fromJson ? JSON.parse(readFileSync13(path2.resolve(cwd, options.fromJson), "utf8")) : options.fromGit ? fetchPrsViaGit(cwd) : fetchPrsViaGh(cwd, options.limit);
|
|
21286
22795
|
let prs = normalizePrs(raw);
|
|
21287
22796
|
let sinceDroppedUndated = 0;
|
|
21288
22797
|
if (options.since) {
|
|
@@ -21303,21 +22812,21 @@ function buildCorpus(options) {
|
|
|
21303
22812
|
const docs = buildDocsManifest(cwd, files);
|
|
21304
22813
|
const surfaces = buildSurfaceInventory(files);
|
|
21305
22814
|
ensureDir(at(cwd, CORPUS_DIR));
|
|
21306
|
-
|
|
21307
|
-
|
|
22815
|
+
writeFileSync12(at(cwd, PRS_FILE), prs.map((pr) => JSON.stringify(pr)).join("\n") + (prs.length ? "\n" : ""));
|
|
22816
|
+
writeFileSync12(at(cwd, DOCS_FILE), `${JSON.stringify(docs, null, 2)}
|
|
21308
22817
|
`);
|
|
21309
|
-
|
|
22818
|
+
writeFileSync12(at(cwd, SURFACES_FILE), `${JSON.stringify(surfaces, null, 2)}
|
|
21310
22819
|
`);
|
|
21311
22820
|
return { prs: prs.length, docs: docs.length, surfaces: surfaces.length, sinceDroppedUndated };
|
|
21312
22821
|
}
|
|
21313
22822
|
function readCorpusPrs(cwd) {
|
|
21314
22823
|
const file2 = at(cwd, PRS_FILE);
|
|
21315
|
-
if (!
|
|
21316
|
-
return
|
|
22824
|
+
if (!existsSync12(file2)) return [];
|
|
22825
|
+
return readFileSync13(file2, "utf8").split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
21317
22826
|
}
|
|
21318
22827
|
|
|
21319
22828
|
// src/lib/bootstrap/fragments.ts
|
|
21320
|
-
import { existsSync as
|
|
22829
|
+
import { existsSync as existsSync13, readFileSync as readFileSync14 } from "node:fs";
|
|
21321
22830
|
import path3 from "node:path";
|
|
21322
22831
|
function isArrayOfObjects(value) {
|
|
21323
22832
|
return value === void 0 || Array.isArray(value) && value.every((v) => typeof v === "object" && v !== null && !Array.isArray(v));
|
|
@@ -21343,13 +22852,13 @@ function loadFragments(cwd, manifest) {
|
|
|
21343
22852
|
problems.push({ unit: String(unit2.id), message: err instanceof Error ? err.message : String(err) });
|
|
21344
22853
|
continue;
|
|
21345
22854
|
}
|
|
21346
|
-
if (!
|
|
22855
|
+
if (!existsSync13(file2)) {
|
|
21347
22856
|
missing.push(unit2.id);
|
|
21348
22857
|
continue;
|
|
21349
22858
|
}
|
|
21350
22859
|
let parsed;
|
|
21351
22860
|
try {
|
|
21352
|
-
parsed = JSON.parse(
|
|
22861
|
+
parsed = JSON.parse(readFileSync14(file2, "utf8"));
|
|
21353
22862
|
} catch (err) {
|
|
21354
22863
|
problems.push({ unit: unit2.id, message: `not valid JSON: ${err instanceof Error ? err.message : "parse error"}` });
|
|
21355
22864
|
continue;
|
|
@@ -21386,7 +22895,7 @@ function renderIndex(bundle) {
|
|
|
21386
22895
|
}
|
|
21387
22896
|
|
|
21388
22897
|
// src/lib/bootstrap/manifest.ts
|
|
21389
|
-
import { existsSync as
|
|
22898
|
+
import { existsSync as existsSync14, readFileSync as readFileSync15, writeFileSync as writeFileSync13 } from "node:fs";
|
|
21390
22899
|
import path4 from "node:path";
|
|
21391
22900
|
|
|
21392
22901
|
// src/lib/bootstrap/era-window.ts
|
|
@@ -21495,18 +23004,18 @@ function assertValidProfile(profile) {
|
|
|
21495
23004
|
// src/lib/bootstrap/manifest.ts
|
|
21496
23005
|
function readProfile(cwd) {
|
|
21497
23006
|
const file2 = at(cwd, PROFILE_FILE2);
|
|
21498
|
-
if (!
|
|
23007
|
+
if (!existsSync14(file2)) return null;
|
|
21499
23008
|
try {
|
|
21500
|
-
return JSON.parse(
|
|
23009
|
+
return JSON.parse(readFileSync15(file2, "utf8"));
|
|
21501
23010
|
} catch (err) {
|
|
21502
23011
|
throw new Error(`cannot read ${PROFILE_FILE2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21503
23012
|
}
|
|
21504
23013
|
}
|
|
21505
|
-
function
|
|
23014
|
+
function readManifest2(cwd) {
|
|
21506
23015
|
const file2 = at(cwd, MANIFEST_FILE);
|
|
21507
|
-
if (!
|
|
23016
|
+
if (!existsSync14(file2)) return null;
|
|
21508
23017
|
try {
|
|
21509
|
-
return JSON.parse(
|
|
23018
|
+
return JSON.parse(readFileSync15(file2, "utf8"));
|
|
21510
23019
|
} catch (err) {
|
|
21511
23020
|
throw new Error(`cannot read ${MANIFEST_FILE}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21512
23021
|
}
|
|
@@ -21514,15 +23023,15 @@ function readManifest(cwd) {
|
|
|
21514
23023
|
function writeManifest(cwd, manifest) {
|
|
21515
23024
|
ensureDir(at(cwd, PLAN_DIR));
|
|
21516
23025
|
ensureDir(at(cwd, FRAGMENTS_DIR));
|
|
21517
|
-
|
|
23026
|
+
writeFileSync13(at(cwd, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
|
|
21518
23027
|
`);
|
|
21519
23028
|
}
|
|
21520
23029
|
function detectMode(cwd, bundlePath) {
|
|
21521
23030
|
const file2 = path4.resolve(cwd, bundlePath);
|
|
21522
|
-
if (!
|
|
23031
|
+
if (!existsSync14(file2)) return "greenfield";
|
|
21523
23032
|
let parsed;
|
|
21524
23033
|
try {
|
|
21525
|
-
parsed = JSON.parse(
|
|
23034
|
+
parsed = JSON.parse(readFileSync15(file2, "utf8"));
|
|
21526
23035
|
} catch (err) {
|
|
21527
23036
|
throw new Error(`cannot read bundle at ${bundlePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21528
23037
|
}
|
|
@@ -21975,7 +23484,7 @@ function mergeFragments(input) {
|
|
|
21975
23484
|
}
|
|
21976
23485
|
|
|
21977
23486
|
// src/lib/bootstrap/slice.ts
|
|
21978
|
-
import { existsSync as
|
|
23487
|
+
import { existsSync as existsSync15, readFileSync as readFileSync16 } from "node:fs";
|
|
21979
23488
|
|
|
21980
23489
|
// src/lib/bootstrap/body-budget.ts
|
|
21981
23490
|
var LAB_NOTE_HEADING_RE = /^##\s+Lab Note.*$/m;
|
|
@@ -22017,8 +23526,8 @@ function boundBody(body) {
|
|
|
22017
23526
|
|
|
22018
23527
|
// src/lib/bootstrap/slice.ts
|
|
22019
23528
|
function readJsonArray(file2) {
|
|
22020
|
-
if (!
|
|
22021
|
-
const parsed = JSON.parse(
|
|
23529
|
+
if (!existsSync15(file2)) return [];
|
|
23530
|
+
const parsed = JSON.parse(readFileSync16(file2, "utf8"));
|
|
22022
23531
|
return Array.isArray(parsed) ? parsed : [];
|
|
22023
23532
|
}
|
|
22024
23533
|
function toPosix(value) {
|
|
@@ -22092,7 +23601,7 @@ function resolveSlice(cwd, unit2) {
|
|
|
22092
23601
|
}
|
|
22093
23602
|
|
|
22094
23603
|
// src/commands/bootstrap.ts
|
|
22095
|
-
var
|
|
23604
|
+
var USAGE14 = `arkaik bootstrap <subcommand> [options]
|
|
22096
23605
|
|
|
22097
23606
|
Subcommands:
|
|
22098
23607
|
corpus [options] Mine merged PRs, docs and surfaces into .arkaik/corpus/.
|
|
@@ -22128,7 +23637,7 @@ ${usage}`);
|
|
|
22128
23637
|
}
|
|
22129
23638
|
function writeFileAtomic(filePath, content) {
|
|
22130
23639
|
const tmpPath = `${filePath}.tmp-${process.pid}`;
|
|
22131
|
-
|
|
23640
|
+
writeFileSync14(tmpPath, content);
|
|
22132
23641
|
renameSync(tmpPath, filePath);
|
|
22133
23642
|
}
|
|
22134
23643
|
function runCorpus(argv) {
|
|
@@ -22163,7 +23672,7 @@ ${CORPUS_USAGE}`);
|
|
|
22163
23672
|
${CORPUS_USAGE}`);
|
|
22164
23673
|
}
|
|
22165
23674
|
}
|
|
22166
|
-
if (!
|
|
23675
|
+
if (!existsSync16(path5.join(cwd, ".git"))) {
|
|
22167
23676
|
fail11("`arkaik bootstrap corpus` must run from the repository root (no .git here).");
|
|
22168
23677
|
}
|
|
22169
23678
|
try {
|
|
@@ -22225,12 +23734,12 @@ ${PLAN_USAGE}`);
|
|
|
22225
23734
|
|
|
22226
23735
|
${PLAN_USAGE}`);
|
|
22227
23736
|
}
|
|
22228
|
-
if (!
|
|
23737
|
+
if (!existsSync16(path5.join(cwd, ".git"))) {
|
|
22229
23738
|
fail11("`arkaik bootstrap plan` must run from the repository root (no .git here).");
|
|
22230
23739
|
}
|
|
22231
23740
|
try {
|
|
22232
23741
|
const mode = detectMode(cwd, bundle);
|
|
22233
|
-
const manifest = planUnits({ mode, bundle, profile: readProfile(cwd), previous:
|
|
23742
|
+
const manifest = planUnits({ mode, bundle, profile: readProfile(cwd), previous: readManifest2(cwd) });
|
|
22234
23743
|
writeManifest(cwd, manifest);
|
|
22235
23744
|
const ignored = ensureGitignored(cwd);
|
|
22236
23745
|
if (ignored) console.log(` added ${BOOTSTRAP_ROOT}/ to .gitignore`);
|
|
@@ -22297,7 +23806,7 @@ function runSlice(argv) {
|
|
|
22297
23806
|
if (unitId === void 0) fail11(`Missing required argument: <unit>
|
|
22298
23807
|
|
|
22299
23808
|
${SLICE_USAGE}`);
|
|
22300
|
-
const manifest =
|
|
23809
|
+
const manifest = readManifest2(cwd);
|
|
22301
23810
|
if (!manifest) fail11("No manifest. Run `arkaik bootstrap plan` first.");
|
|
22302
23811
|
const unit2 = manifest.units.find((u) => u.id === unitId);
|
|
22303
23812
|
if (!unit2) fail11(`Unknown unit: ${unitId}
|
|
@@ -22358,13 +23867,13 @@ function runMerge(argv) {
|
|
|
22358
23867
|
${MERGE_USAGE}`);
|
|
22359
23868
|
}
|
|
22360
23869
|
}
|
|
22361
|
-
const manifest =
|
|
23870
|
+
const manifest = readManifest2(cwd);
|
|
22362
23871
|
if (!manifest) {
|
|
22363
23872
|
fail11("No manifest. Run `arkaik bootstrap plan` first.");
|
|
22364
23873
|
}
|
|
22365
23874
|
try {
|
|
22366
23875
|
const bundlePath = path5.resolve(cwd, manifest.bundle);
|
|
22367
|
-
const base =
|
|
23876
|
+
const base = existsSync16(bundlePath) ? readBundle(bundlePath) : {
|
|
22368
23877
|
schema_version: 3,
|
|
22369
23878
|
project: {
|
|
22370
23879
|
id: path5.basename(cwd),
|
|
@@ -22422,7 +23931,7 @@ ${MERGE_USAGE}`);
|
|
|
22422
23931
|
function runBootstrap(argv) {
|
|
22423
23932
|
const [sub, ...rest] = argv;
|
|
22424
23933
|
if (sub === void 0 || sub === "-h" || sub === "--help" || sub === "help") {
|
|
22425
|
-
console.log(
|
|
23934
|
+
console.log(USAGE14);
|
|
22426
23935
|
process.exit(0);
|
|
22427
23936
|
}
|
|
22428
23937
|
switch (sub) {
|
|
@@ -22444,7 +23953,7 @@ function runBootstrap(argv) {
|
|
|
22444
23953
|
default:
|
|
22445
23954
|
console.error(`Unknown bootstrap subcommand: ${sub}
|
|
22446
23955
|
|
|
22447
|
-
${
|
|
23956
|
+
${USAGE14}`);
|
|
22448
23957
|
process.exit(1);
|
|
22449
23958
|
}
|
|
22450
23959
|
}
|
|
@@ -22577,9 +24086,187 @@ Pass --domain-name "<display name>" to define it, or use an existing domain code
|
|
|
22577
24086
|
return { path: path6, overlay, replaced: at2 >= 0, ...addedDomain !== void 0 ? { addedDomain } : {} };
|
|
22578
24087
|
}
|
|
22579
24088
|
|
|
24089
|
+
// ../schema/src/cli/kritik-plan.ts
|
|
24090
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
24091
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4, statSync as statSync2 } from "node:fs";
|
|
24092
|
+
import { join as join11 } from "node:path";
|
|
24093
|
+
var plansDir = (root) => join11(root, QUALITY_DIR, PLAN_PLANS_DIR);
|
|
24094
|
+
var planPath = (root, planId2) => join11(plansDir(root), `${planId2}.json`);
|
|
24095
|
+
function listPlanIds(root) {
|
|
24096
|
+
const dir = plansDir(root);
|
|
24097
|
+
if (!existsSync17(dir)) return [];
|
|
24098
|
+
return readdirSync4(dir).filter((name) => name.endsWith(".json") && statSync2(join11(dir, name)).isFile()).map((name) => name.slice(0, -".json".length)).filter((id) => isPlanId(id)).sort();
|
|
24099
|
+
}
|
|
24100
|
+
function readPlanFile(path6) {
|
|
24101
|
+
if (!existsSync17(path6)) throw new Error(`no plan at ${path6}`);
|
|
24102
|
+
const parsed = parseKritikPlan(readJson(path6));
|
|
24103
|
+
if (!parsed.ok) throw new Error(`${path6}: ${parsed.issue}`);
|
|
24104
|
+
return parsed.plan;
|
|
24105
|
+
}
|
|
24106
|
+
function loadPlan(root, planId2) {
|
|
24107
|
+
if (!isPlanId(planId2)) {
|
|
24108
|
+
throw new Error(`"${planId2}" is not a plan id \u2014 a plan id reads YYYY-MM-zplan-DDNN, as \`arkaik kritik plan\` prints it.`);
|
|
24109
|
+
}
|
|
24110
|
+
const path6 = planPath(root, planId2);
|
|
24111
|
+
const plan = readPlanFile(path6);
|
|
24112
|
+
if (plan.planId !== planId2) {
|
|
24113
|
+
throw new Error(`${path6} holds the plan "${plan.planId}", not "${planId2}" \u2014 a plan file is named for its plan id.`);
|
|
24114
|
+
}
|
|
24115
|
+
return plan;
|
|
24116
|
+
}
|
|
24117
|
+
function savePlan(path6, plan) {
|
|
24118
|
+
writeJson(path6, plan);
|
|
24119
|
+
}
|
|
24120
|
+
function gitHead(root) {
|
|
24121
|
+
try {
|
|
24122
|
+
const result = spawnSync3("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" });
|
|
24123
|
+
if (result.error !== void 0 || result.status !== 0) return null;
|
|
24124
|
+
const sha = result.stdout.trim();
|
|
24125
|
+
return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
|
|
24126
|
+
} catch {
|
|
24127
|
+
return null;
|
|
24128
|
+
}
|
|
24129
|
+
}
|
|
24130
|
+
function createPlan(root, library, runTokens, options = {}) {
|
|
24131
|
+
const profile = requireProfile(root);
|
|
24132
|
+
const surfaces = (profile.surfaces ?? []).map((surface) => surface.id);
|
|
24133
|
+
const { runs, warnings } = parseRun(runTokens, {
|
|
24134
|
+
domains: (library.domains ?? []).map((domain2) => domain2.code),
|
|
24135
|
+
surfaces
|
|
24136
|
+
});
|
|
24137
|
+
const known = [.../* @__PURE__ */ new Set([...listAuditIds(root), ...listPlanIds(root), ...options.recorded ?? []])];
|
|
24138
|
+
const plan = buildKritikPlan({
|
|
24139
|
+
library,
|
|
24140
|
+
surfaces,
|
|
24141
|
+
runs,
|
|
24142
|
+
known,
|
|
24143
|
+
now: options.now ?? /* @__PURE__ */ new Date(),
|
|
24144
|
+
commit: gitHead(root)
|
|
24145
|
+
});
|
|
24146
|
+
return { plan, warnings };
|
|
24147
|
+
}
|
|
24148
|
+
function planStatus(root, plan) {
|
|
24149
|
+
const scoresByPart = Object.fromEntries(
|
|
24150
|
+
plan.parts.map((part) => [part.auditId, loadScoresOrEmpty(root, part.auditId).assessments])
|
|
24151
|
+
);
|
|
24152
|
+
return planPartStatuses(plan, scoresByPart);
|
|
24153
|
+
}
|
|
24154
|
+
var cellLabel = (cell) => `${cell.criterion_id} on ${cell.surface}`;
|
|
24155
|
+
var runFlags = (parts) => parts.map((part) => `--run ${part.domain}:${part.surface}`).join(" ");
|
|
24156
|
+
function preparePlanRecord(root, planId2, library, events) {
|
|
24157
|
+
const plan = loadPlan(root, planId2);
|
|
24158
|
+
if (recordedPlans(events).some((recorded) => recorded.plan === planId2) || recordedAuditIds(events).includes(planId2)) {
|
|
24159
|
+
throw new Error(
|
|
24160
|
+
`plan "${planId2}" is already recorded \u2014 its reading is history, and the journal is append-only. To correct it, make a new plan for the same parts (\`arkaik kritik plan ${runFlags(plan.parts)}\`) and record that one.`
|
|
24161
|
+
);
|
|
24162
|
+
}
|
|
24163
|
+
const included = plan.parts.filter((part) => part.status === "included");
|
|
24164
|
+
if (included.length === 0) {
|
|
24165
|
+
throw new Error(`plan "${planId2}" includes no part \u2014 every part was deferred, so there is nothing to record.`);
|
|
24166
|
+
}
|
|
24167
|
+
const recordedAlone = included.filter(
|
|
24168
|
+
(part) => events.some((event) => event?.type === "quality.audit.completed" && event.audit_id === part.auditId)
|
|
24169
|
+
);
|
|
24170
|
+
if (recordedAlone.length > 0) {
|
|
24171
|
+
const [first] = recordedAlone;
|
|
24172
|
+
throw new Error(
|
|
24173
|
+
`plan "${planId2}" cannot be recorded \u2014 its part "${first.auditId}" was already recorded on its own` + (recordedAlone.length > 1 ? ` (and ${recordedAlone.slice(1).map((part) => `"${part.auditId}"`).join(", ")})` : "") + `, and a part recorded on its own cannot be folded into a plan record: its reading is history, and the journal is append-only. To record these cells as a plan, make a new plan: \`arkaik kritik plan ${runFlags(plan.parts)}\`.`
|
|
24174
|
+
);
|
|
24175
|
+
}
|
|
24176
|
+
const surfaces = (requireProfile(root).surfaces ?? []).map((surface) => surface.id);
|
|
24177
|
+
const moved = [];
|
|
24178
|
+
if (plan.frameworkVersion !== library.version) {
|
|
24179
|
+
moved.push(`the framework is ${library.version} now, and the plan was made against ${plan.frameworkVersion}`);
|
|
24180
|
+
}
|
|
24181
|
+
for (const part of included) {
|
|
24182
|
+
const current = planCells(library, surfaces, { domain: part.domain, surface: part.surface }).cells;
|
|
24183
|
+
const was = new Set(part.cells.map((cell) => planCellKey(cell.criterion_id, cell.surface)));
|
|
24184
|
+
const is = new Set(current.map((cell) => planCellKey(cell.criterion_id, cell.surface)));
|
|
24185
|
+
const added = current.filter((cell) => !was.has(planCellKey(cell.criterion_id, cell.surface)));
|
|
24186
|
+
const removed = part.cells.filter((cell) => !is.has(planCellKey(cell.criterion_id, cell.surface)));
|
|
24187
|
+
const changes = [];
|
|
24188
|
+
if (added.length > 0) changes.push(`gained ${added.map((cell) => cell.criterion_id).join(", ")}`);
|
|
24189
|
+
if (removed.length > 0) changes.push(`lost ${removed.map((cell) => cell.criterion_id).join(", ")}`);
|
|
24190
|
+
if (changes.length > 0) moved.push(`${part.domain}:${part.surface} ${changes.join(" and ")}`);
|
|
24191
|
+
}
|
|
24192
|
+
if (moved.length > 0) {
|
|
24193
|
+
throw new Error(
|
|
24194
|
+
`the cells have moved since plan "${planId2}" was made \u2014 ${moved.join("; ")}. Make a new plan: \`arkaik kritik plan ${runFlags(included)}\`.`
|
|
24195
|
+
);
|
|
24196
|
+
}
|
|
24197
|
+
const onDiskIds = listAuditIds(root);
|
|
24198
|
+
const outsorted = included.map((part) => ({ part, later: outsortedBy(part.auditId, onDiskIds) })).filter((entry) => entry.later.length > 0);
|
|
24199
|
+
if (outsorted.length > 0) {
|
|
24200
|
+
throw new Error(
|
|
24201
|
+
`plan "${planId2}" cannot be recorded \u2014 audits merge latest-wins in id order, and on any cell an audit sorting after a part also holds, that part's scores would lose the merge:
|
|
24202
|
+
` + outsorted.map(({ part, later }) => ` ${part.auditId}: ${later.map((id) => `"${id}"`).join(", ")} now sort${later.length === 1 ? "s" : ""} after it`).join("\n") + `
|
|
24203
|
+
Make a new plan for the affected parts and score them again: \`arkaik kritik plan ${runFlags(outsorted.map(({ part }) => part))}\` names parts that sort last again.`
|
|
24204
|
+
);
|
|
24205
|
+
}
|
|
24206
|
+
const last = included.map((part) => part.auditId).sort()[included.length - 1];
|
|
24207
|
+
const ownParts = new Set(included.map((part) => part.auditId));
|
|
24208
|
+
const recordedIds = new Set(recordedAuditIds(events));
|
|
24209
|
+
const unannounced = onDiskIds.filter((id) => id < last && !ownParts.has(id) && !recordedIds.has(id)).map((id) => ({ id, scores: loadScoresOrEmpty(root, id).assessments.length })).filter((entry) => entry.scores > 0);
|
|
24210
|
+
if (unannounced.length > 0) {
|
|
24211
|
+
throw new Error(
|
|
24212
|
+
`plan "${planId2}" cannot be recorded \u2014 ${unannounced.length === 1 ? "an audit directory sorts" : "audit directories sort"} before its last part, ${unannounced.length === 1 ? "holds scores and was" : "hold scores and were"} never recorded. The record merges every audit through the plan's last part but names only the plan's own cells as re-scored, so ${unannounced.length === 1 ? "its scores" : "their scores"} would enter this plan's record unannounced:
|
|
24213
|
+
` + unannounced.map(({ id, scores }) => {
|
|
24214
|
+
const owner = planIdOfPartId(id);
|
|
24215
|
+
return ` ${id}: ${scores} score${scores === 1 ? "" : "s"}, never recorded` + (owner !== null ? ` (a part of plan "${owner}")` : "");
|
|
24216
|
+
}).join("\n") + `
|
|
24217
|
+
Record each first, or remove its scores (docs/quality/audits/<id>/scores.json), then record this plan.`
|
|
24218
|
+
);
|
|
24219
|
+
}
|
|
24220
|
+
const onDisk = new Set(onDiskIds);
|
|
24221
|
+
const scoresByPart = {};
|
|
24222
|
+
for (const part of included) scoresByPart[part.auditId] = loadScoresOrEmpty(root, part.auditId).assessments;
|
|
24223
|
+
const statuses = planPartStatuses({ parts: included }, scoresByPart);
|
|
24224
|
+
const strays = statuses.filter((status) => status.stray.length > 0);
|
|
24225
|
+
if (strays.length > 0) {
|
|
24226
|
+
const count = strays.reduce((sum, status) => sum + status.stray.length, 0);
|
|
24227
|
+
throw new Error(
|
|
24228
|
+
`${count} score${count === 1 ? "" : "s"} outside plan "${planId2}" \u2014 the merge reads every audit directory, so ${count === 1 ? "it" : "they"} would enter the recorded matrix anyway. Remove ${count === 1 ? "it" : "them"} before recording, or make a plan that includes ${count === 1 ? "it" : "them"}:
|
|
24229
|
+
` + strays.map(
|
|
24230
|
+
(status) => ` ${status.auditId}: ${status.stray.map(cellLabel).join(", ")} \u2014 for each, delete its row from docs/quality/audits/${status.auditId}/scores.json`
|
|
24231
|
+
).join("\n")
|
|
24232
|
+
);
|
|
24233
|
+
}
|
|
24234
|
+
const unscored = statuses.filter((status) => status.missing.length > 0);
|
|
24235
|
+
if (unscored.length > 0) {
|
|
24236
|
+
const count = unscored.reduce((sum, status) => sum + status.missing.length, 0);
|
|
24237
|
+
throw new Error(
|
|
24238
|
+
`${count} plan cell${count === 1 ? " has" : "s have"} no score yet \u2014 a plan records once, after every part is scored (\`arkaik kritik plan --status ${planId2}\`):
|
|
24239
|
+
` + unscored.map(
|
|
24240
|
+
(status) => onDisk.has(status.auditId) ? ` ${status.auditId}: ${status.missing.map(cellLabel).join(", ")}` : ` ${status.auditId}: no audit directory in this checkout \u2014 if this part ran in another worktree, copy or merge its docs/quality/audits/${status.auditId}/ here first`
|
|
24241
|
+
).join("\n")
|
|
24242
|
+
);
|
|
24243
|
+
}
|
|
24244
|
+
const section = loadQualitySectionThrough(root, last, library);
|
|
24245
|
+
const matrix = deriveQualityMatrix({ quality: section }, library);
|
|
24246
|
+
const scored = included.flatMap((part) => part.cells.map((cell) => planCellKey(cell.criterion_id, cell.surface)));
|
|
24247
|
+
const since = scopeAnchorId(events);
|
|
24248
|
+
const scope = {
|
|
24249
|
+
partial: true,
|
|
24250
|
+
cells: scored.length,
|
|
24251
|
+
...since !== null ? { since } : {},
|
|
24252
|
+
plan: plan.planId,
|
|
24253
|
+
parts: included.map((part) => part.auditId),
|
|
24254
|
+
scored,
|
|
24255
|
+
coverage: coverageOf(section, library, scored.length)
|
|
24256
|
+
};
|
|
24257
|
+
const input = auditCompletedInput(matrix, {
|
|
24258
|
+
audit_id: plan.planId,
|
|
24259
|
+
framework_version: plan.frameworkVersion,
|
|
24260
|
+
...plan.commit !== null ? { commit: plan.commit } : {},
|
|
24261
|
+
scope
|
|
24262
|
+
});
|
|
24263
|
+
return { plan, section, matrix, scope, input };
|
|
24264
|
+
}
|
|
24265
|
+
|
|
22580
24266
|
// src/commands/kritik.ts
|
|
22581
|
-
import { existsSync as
|
|
22582
|
-
|
|
24267
|
+
import { existsSync as existsSync18, readFileSync as readFileSync17 } from "node:fs";
|
|
24268
|
+
import { resolve as resolve12 } from "node:path";
|
|
24269
|
+
var USAGE15 = `arkaik kritik <subcommand> [options]
|
|
22583
24270
|
|
|
22584
24271
|
Audit this product's quality with the Kritik framework: a maturity level per
|
|
22585
24272
|
criterion per surface backed by evidence, findings carrying risk and cost, and
|
|
@@ -22597,6 +24284,7 @@ Subcommands:
|
|
|
22597
24284
|
trend Every recorded audit's scores, and which way each moved.
|
|
22598
24285
|
burndown Open findings over time, and what closed since the last audit.
|
|
22599
24286
|
scope The cells your resolved findings made stale since the last audit.
|
|
24287
|
+
plan --run <D:S> Plan a partial audit: its parts, their cells, audit ids and prompts.
|
|
22600
24288
|
issue <criterion> Print the prefilled GitHub issue skeleton.
|
|
22601
24289
|
criterion add ... Add a project-specific criterion to the overlay.
|
|
22602
24290
|
|
|
@@ -22652,6 +24340,7 @@ var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
|
|
|
22652
24340
|
decision and reads like one. No journal event: acceptance is a state of the
|
|
22653
24341
|
finding, not something that happened to the product.`;
|
|
22654
24342
|
var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record] [--scope]
|
|
24343
|
+
arkaik kritik matrix <plan-id> --plan [--record] [--json]
|
|
22655
24344
|
|
|
22656
24345
|
Roll one audit up into its comparative matrix and write matrix.json \u2014 the only
|
|
22657
24346
|
thing that may write that file.
|
|
@@ -22662,11 +24351,20 @@ thing that may write that file.
|
|
|
22662
24351
|
and counts. Do this once per finished audit.
|
|
22663
24352
|
--scope Treat the audit as a scoped re-audit even though it was
|
|
22664
24353
|
scored without \`score --scope\` (which marks it for you).
|
|
24354
|
+
--plan The id is a plan from \`arkaik kritik plan\`: read the merged
|
|
24355
|
+
matrix through its last part, writing nothing; with --record,
|
|
24356
|
+
append it as one quality.audit.completed under the plan id.
|
|
24357
|
+
Refused unless every part scored exactly its cells, and
|
|
24358
|
+
never with --scope.
|
|
22665
24359
|
|
|
22666
24360
|
A scoped re-audit holds only the cells it re-scored, so matrix.json shows just
|
|
22667
24361
|
those ("how did this audit go"), while --record carries the merged matrix
|
|
22668
24362
|
through this audit ("where does the product stand") \u2014 the reading the trend
|
|
22669
|
-
replays. Everything else keeps its last score
|
|
24363
|
+
replays. Everything else keeps its last score.
|
|
24364
|
+
|
|
24365
|
+
A plan records once, as a whole: a part's own id is refused with --record or
|
|
24366
|
+
--scope. Under every table, a coverage line names each surface whose roll-up
|
|
24367
|
+
rests on fewer cells than apply to it: "web 62, from 6 of 73 cells".`;
|
|
22670
24368
|
var SIGNALS_USAGE = `arkaik kritik signals [--surface <s>] [--criterion <c>] [--domain <CODE>] [--json]
|
|
22671
24369
|
arkaik kritik signals --trip <criterion> --surface <s> --signal <index|text> [--detail <d>]
|
|
22672
24370
|
|
|
@@ -22693,8 +24391,10 @@ not a regression.
|
|
|
22693
24391
|
Exits 1 when anything regressed, which is what makes it usable as a CI step or a
|
|
22694
24392
|
scheduled routine.
|
|
22695
24393
|
|
|
22696
|
-
--from <audit> The older reading (default: the
|
|
24394
|
+
--from <audit> The older reading (default: the reading before --to).
|
|
22697
24395
|
--to <audit> The newer reading (default: the newest on disk).
|
|
24396
|
+
A plan's parts are one reading: a plan id, or any of its
|
|
24397
|
+
part ids, names the state through the plan's last part.
|
|
22698
24398
|
--record Append one quality.signal.tripped per regression.
|
|
22699
24399
|
--json The full list as JSON.`;
|
|
22700
24400
|
var TREND_USAGE = `arkaik kritik trend [--surface <s>] [--domain <CODE>] [--json]
|
|
@@ -22711,7 +24411,12 @@ findings: "from where we started to where we are now".
|
|
|
22711
24411
|
Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.json)
|
|
22712
24412
|
and audits recorded with \`arkaik kritik matrix --record\`. A framework major
|
|
22713
24413
|
bump between two audits breaks the comparison there (SPEC \xA7 8): the row still
|
|
22714
|
-
prints, without an arrow
|
|
24414
|
+
prints, without an arrow.
|
|
24415
|
+
|
|
24416
|
+
A planned partial audit's row says so \u2014 "planned partial audit: 6 cells
|
|
24417
|
+
re-scored in 1 part since 2026-08" \u2014 moves its arrows only where the plan
|
|
24418
|
+
re-scored, and lists each surface it did not fully cover: "web 62, from 6 of
|
|
24419
|
+
73 cells".`;
|
|
22715
24420
|
var BURNDOWN_USAGE = `arkaik kritik burndown [--surface <s>] [--domain <CODE>] [--json]
|
|
22716
24421
|
|
|
22717
24422
|
How many findings closed since the last recorded audit, and how many are open
|
|
@@ -22742,7 +24447,8 @@ This is a work list, not a score: re-score each cell with evidence
|
|
|
22742
24447
|
Recording closes the window: a cell left unscored drops out of the next scope.
|
|
22743
24448
|
|
|
22744
24449
|
--since <audit> Measure from this recorded audit (default: the newest
|
|
22745
|
-
quality.audit.completed
|
|
24450
|
+
quality.audit.completed that is not a plan's). A plan
|
|
24451
|
+
record is never what a scope is measured from.
|
|
22746
24452
|
--no-widen Only the resolved findings' own cells, no neighbours.
|
|
22747
24453
|
--json The scope as JSON (what an agent should read).
|
|
22748
24454
|
|
|
@@ -22820,8 +24526,8 @@ function collect(args, repeatable = [], boolean4 = []) {
|
|
|
22820
24526
|
function textOrFile(value) {
|
|
22821
24527
|
if (!value.startsWith("@")) return value;
|
|
22822
24528
|
const path6 = value.slice(1);
|
|
22823
|
-
if (!
|
|
22824
|
-
return
|
|
24529
|
+
if (!existsSync18(path6)) fail12(`kritik: no file at ${path6}`);
|
|
24530
|
+
return readFileSync17(path6, "utf8").trim();
|
|
22825
24531
|
}
|
|
22826
24532
|
function currentAuditId() {
|
|
22827
24533
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -22832,6 +24538,14 @@ function auditForWrite(root, requested) {
|
|
|
22832
24538
|
const existing = listAuditIds(root);
|
|
22833
24539
|
return existing.length > 0 ? existing[existing.length - 1] : currentAuditId();
|
|
22834
24540
|
}
|
|
24541
|
+
function refuseOutsortedPart(root, auditId) {
|
|
24542
|
+
const later = outsortedBy(auditId, listAuditIds(root));
|
|
24543
|
+
if (later.length === 0) return;
|
|
24544
|
+
fail12(
|
|
24545
|
+
`kritik: "${auditId}" is a part of plan ${planIdOfPartId(auditId)}, and ${later.map((id) => `"${id}"`).join(", ")} now sort${later.length === 1 ? "s" : ""} after it \u2014 audits merge latest-wins in id order, so on any cell ${later.length === 1 ? "both hold" : "they share with it"}, this part's scores would lose the merge. Nothing written.
|
|
24546
|
+
Make a new plan for the parts not yet scored: \`arkaik kritik plan --run <DOMAIN:SURFACE> \u2026\` names parts that sort last again.`
|
|
24547
|
+
);
|
|
24548
|
+
}
|
|
22835
24549
|
function loadLibraryOrFail(root) {
|
|
22836
24550
|
try {
|
|
22837
24551
|
return loadKritikLibrary(root).library;
|
|
@@ -22951,7 +24665,7 @@ ${PROFILE_USAGE}`);
|
|
|
22951
24665
|
weights[code] = value;
|
|
22952
24666
|
}
|
|
22953
24667
|
const path6 = profilePath(common.root);
|
|
22954
|
-
if (
|
|
24668
|
+
if (existsSync18(path6) && !flags.has("force")) {
|
|
22955
24669
|
fail12(
|
|
22956
24670
|
`kritik: ${path6} already exists.
|
|
22957
24671
|
Changing the surface list invalidates every score recorded against the old one, so this refuses by default.
|
|
@@ -23002,9 +24716,11 @@ ${SCORE_USAGE}`);
|
|
|
23002
24716
|
let scopedFrom;
|
|
23003
24717
|
let auditId;
|
|
23004
24718
|
if (flags.has("scope")) {
|
|
23005
|
-
const { scope, recorded } = currentScope(common, library, profile);
|
|
24719
|
+
const { scope, recorded, plans } = currentScope(common, library, profile);
|
|
23006
24720
|
if (scope.since === null) {
|
|
23007
|
-
fail12(
|
|
24721
|
+
fail12(
|
|
24722
|
+
plans.length > 0 ? `kritik: --scope needs a full or scoped audit to measure from, and ${planOnlyScopeNote(plans)}` : `kritik: --scope needs a recorded audit to measure from \u2014 \`arkaik kritik matrix --record\` writes one.`
|
|
24723
|
+
);
|
|
23008
24724
|
}
|
|
23009
24725
|
if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
|
|
23010
24726
|
fail12(
|
|
@@ -23021,6 +24737,7 @@ ${SCORE_USAGE}`);
|
|
|
23021
24737
|
} else {
|
|
23022
24738
|
auditId = auditForWrite(common.root, single.audit);
|
|
23023
24739
|
}
|
|
24740
|
+
refuseOutsortedPart(common.root, auditId);
|
|
23024
24741
|
const notes = [];
|
|
23025
24742
|
if (scopedFrom === void 0) {
|
|
23026
24743
|
const journal = resolveJournal(common.root, common.bundlePath);
|
|
@@ -23029,7 +24746,7 @@ ${SCORE_USAGE}`);
|
|
|
23029
24746
|
`${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.`
|
|
23030
24747
|
);
|
|
23031
24748
|
}
|
|
23032
|
-
const order = auditOrderNote(common.root, auditId);
|
|
24749
|
+
const order = isPlanPartId(auditId) ? void 0 : auditOrderNote(common.root, auditId);
|
|
23033
24750
|
if (order !== void 0) notes.push(order);
|
|
23034
24751
|
}
|
|
23035
24752
|
const file2 = loadScoresOrEmpty(common.root, auditId);
|
|
@@ -23115,6 +24832,7 @@ ${FINDING_USAGE}`);
|
|
|
23115
24832
|
);
|
|
23116
24833
|
}
|
|
23117
24834
|
const auditId = auditForWrite(common.root, single.audit);
|
|
24835
|
+
refuseOutsortedPart(common.root, auditId);
|
|
23118
24836
|
const file2 = loadFindings(common.root, auditId);
|
|
23119
24837
|
const taken = new Set(file2.findings.map((f) => f.id));
|
|
23120
24838
|
const id = single.id ?? mintFindingId(auditId, criterionId, surface, taken, library);
|
|
@@ -23216,14 +24934,21 @@ ${FINDING_USAGE}`);
|
|
|
23216
24934
|
process.exit(0);
|
|
23217
24935
|
}
|
|
23218
24936
|
function scopedSince(common, auditId, stamped, declared) {
|
|
23219
|
-
if (stamped !== void 0)
|
|
24937
|
+
if (stamped !== void 0) {
|
|
24938
|
+
if (isPlanId(stamped) || isPlanPartId(stamped)) {
|
|
24939
|
+
return fail12(
|
|
24940
|
+
`kritik: ${scoresPath(common.root, auditId)} stamps "scope": { "since": "${stamped}" }, a plan or one of its parts \u2014 a scope is measured from a full or scoped audit, never from a plan. Stamp the full or scoped audit this one followed.`
|
|
24941
|
+
);
|
|
24942
|
+
}
|
|
24943
|
+
return stamped;
|
|
24944
|
+
}
|
|
23220
24945
|
if (!declared) return void 0;
|
|
23221
24946
|
const journal = resolveJournal(common.root, common.bundlePath);
|
|
23222
24947
|
if (!journal.present) {
|
|
23223
24948
|
fail12(`kritik: --scope needs the audit this one was scoped from, and there is no journal at ${journal.bundlePath}.`);
|
|
23224
24949
|
}
|
|
23225
24950
|
try {
|
|
23226
|
-
return declaredScopeSince(auditId,
|
|
24951
|
+
return declaredScopeSince(auditId, recordedSinceIds(readFullJournalEvents(journal.journalPath)));
|
|
23227
24952
|
} catch (error51) {
|
|
23228
24953
|
return fail12(`kritik: --scope refused \u2014 ${error51.message}`);
|
|
23229
24954
|
}
|
|
@@ -23238,19 +24963,126 @@ function unscoredScopeCells(common, library, since, assessed) {
|
|
|
23238
24963
|
const done = new Set(assessed.map((a) => `${a.criterion_id}::${a.surface}`));
|
|
23239
24964
|
return scope.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`));
|
|
23240
24965
|
}
|
|
24966
|
+
function printMatrixReport(section, matrix, library) {
|
|
24967
|
+
const domainNames = new Map((library.domains ?? []).map((d) => [d.code, d.name]));
|
|
24968
|
+
console.log(`
|
|
24969
|
+
${renderMatrixMarkdown(matrix, domainNames)}
|
|
24970
|
+
`);
|
|
24971
|
+
const notes = coverageNotes(coverageOf(section, library), matrix.overall);
|
|
24972
|
+
if (notes.length > 0) {
|
|
24973
|
+
console.log(`coverage \u2014 a roll-up reads only the cells that hold a score:`);
|
|
24974
|
+
for (const note of notes) console.log(` ${note}`);
|
|
24975
|
+
console.log("");
|
|
24976
|
+
}
|
|
24977
|
+
const open = section.findings.filter(isOpenFinding);
|
|
24978
|
+
const lanes = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
24979
|
+
for (const finding of open) lanes[priorityOf(finding, library)]++;
|
|
24980
|
+
const counts = matrix.finding_counts;
|
|
24981
|
+
console.log(
|
|
24982
|
+
`${section.assessments.length} assessments \xB7 ${open.length} open findings (${counts.critical} critical, ${counts.high} high, ${counts.medium} medium, ${counts.low} low)
|
|
24983
|
+
lanes: P0 ${lanes.P0} \xB7 P1 ${lanes.P1} \xB7 P2 ${lanes.P2} \xB7 P3 ${lanes.P3}`
|
|
24984
|
+
);
|
|
24985
|
+
const p0 = open.filter((finding) => priorityOf(finding, library) === "P0");
|
|
24986
|
+
if (p0.length > 0) {
|
|
24987
|
+
console.log(`
|
|
24988
|
+
P0 \u2014 fix first:`);
|
|
24989
|
+
for (const finding of p0) {
|
|
24990
|
+
console.log(` [${severityOf(finding, library)}] ${finding.surface} \xB7 ${finding.id} \u2014 ${finding.title}`);
|
|
24991
|
+
}
|
|
24992
|
+
}
|
|
24993
|
+
}
|
|
24994
|
+
function runPlanMatrix(planId2, flags, common, library) {
|
|
24995
|
+
const record2 = flags.has("record");
|
|
24996
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
24997
|
+
const events = journal.present ? readFullJournalEvents(journal.journalPath) : [];
|
|
24998
|
+
let prepared;
|
|
24999
|
+
try {
|
|
25000
|
+
prepared = preparePlanRecord(common.root, planId2, library, events);
|
|
25001
|
+
} catch (error51) {
|
|
25002
|
+
return fail12(`kritik: ${error51.message}`);
|
|
25003
|
+
}
|
|
25004
|
+
const { plan, section, matrix, scope } = prepared;
|
|
25005
|
+
const parts = scope.parts.length;
|
|
25006
|
+
if (flags.has("json")) {
|
|
25007
|
+
console.log(
|
|
25008
|
+
JSON.stringify(
|
|
25009
|
+
{
|
|
25010
|
+
audit_id: plan.planId,
|
|
25011
|
+
...plan.commit !== null ? { commit: plan.commit } : {},
|
|
25012
|
+
framework_version: plan.frameworkVersion,
|
|
25013
|
+
matrix: matrix.matrix,
|
|
25014
|
+
overall: matrix.overall,
|
|
25015
|
+
finding_counts: matrix.finding_counts,
|
|
25016
|
+
scope
|
|
25017
|
+
},
|
|
25018
|
+
null,
|
|
25019
|
+
2
|
|
25020
|
+
)
|
|
25021
|
+
);
|
|
25022
|
+
} else {
|
|
25023
|
+
printMatrixReport(section, matrix, library);
|
|
25024
|
+
console.log(
|
|
25025
|
+
`
|
|
25026
|
+
planned partial audit ${plan.planId}: ${scope.cells} cell${scope.cells === 1 ? "" : "s"} re-scored in ${parts} part${parts === 1 ? "" : "s"}` + (scope.since !== void 0 ? ` since ${scope.since}` : ", with no full audit before it") + `. The table is the merged reading through the plan's last part \u2014 every other cell at its last score.` + (record2 ? "" : `
|
|
25027
|
+
Nothing written. Record it: \`${planRecordCommand(plan.planId)}\``)
|
|
25028
|
+
);
|
|
25029
|
+
}
|
|
25030
|
+
if (record2) reportJournal(common.root, [prepared.input], common);
|
|
25031
|
+
console.log("");
|
|
25032
|
+
process.exit(0);
|
|
25033
|
+
}
|
|
23241
25034
|
function runMatrix(args, common) {
|
|
23242
|
-
const { flags, positionals } = collect(args, [], ["json", "record", "scope"]);
|
|
25035
|
+
const { flags, positionals } = collect(args, [], ["json", "record", "scope", "plan"]);
|
|
23243
25036
|
if (flags.has("help")) {
|
|
23244
25037
|
console.log(MATRIX_USAGE);
|
|
23245
25038
|
process.exit(0);
|
|
23246
25039
|
}
|
|
23247
25040
|
const library = loadLibraryOrFail(common.root);
|
|
25041
|
+
if (flags.has("plan")) {
|
|
25042
|
+
const planId2 = positionals[0];
|
|
25043
|
+
if (flags.has("scope")) {
|
|
25044
|
+
return fail12(`kritik: --plan and --scope cannot be combined \u2014 a plan records its own scope marker, measured from the newest full or scoped audit.`);
|
|
25045
|
+
}
|
|
25046
|
+
if (planId2 === void 0) {
|
|
25047
|
+
const plans = listPlanIds(common.root);
|
|
25048
|
+
return fail12(
|
|
25049
|
+
`kritik: --plan needs the plan id \u2014 \`arkaik kritik matrix <planId> --record --plan\` (plans: ${plans.join(", ") || "none \u2014 `arkaik kritik plan` makes one"}).`
|
|
25050
|
+
);
|
|
25051
|
+
}
|
|
25052
|
+
if (isPlanPartId(planId2)) {
|
|
25053
|
+
const owner = planIdOfPartId(planId2) ?? planId2;
|
|
25054
|
+
return fail12(`kritik: "${planId2}" is one part of plan "${owner}" \u2014 pass the plan id: \`arkaik kritik matrix ${owner} --record --plan\`.`);
|
|
25055
|
+
}
|
|
25056
|
+
if (flags.has("record")) {
|
|
25057
|
+
if (!common.journal) {
|
|
25058
|
+
return fail12(`kritik: --record --plan appends the plan's reading to the journal, and --no-journal says not to \u2014 drop one of them.`);
|
|
25059
|
+
}
|
|
25060
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
25061
|
+
if (!journal.present) {
|
|
25062
|
+
return fail12(
|
|
25063
|
+
`kritik: --record --plan needs a journal, and there is no bundle at ${journal.bundlePath} \u2014 a plan's reading exists only as its quality.audit.completed.`
|
|
25064
|
+
);
|
|
25065
|
+
}
|
|
25066
|
+
}
|
|
25067
|
+
return runPlanMatrix(planId2, flags, common, library);
|
|
25068
|
+
}
|
|
23248
25069
|
let auditId;
|
|
23249
25070
|
try {
|
|
23250
25071
|
auditId = positionals[0] ?? newestAuditId(common.root);
|
|
23251
25072
|
} catch (error51) {
|
|
23252
25073
|
return fail12(`kritik: ${error51.message}`);
|
|
23253
25074
|
}
|
|
25075
|
+
if (isPlanId(auditId)) {
|
|
25076
|
+
return fail12(
|
|
25077
|
+
`kritik: "${auditId}" is a plan, not an audit \u2014 pass --plan: \`arkaik kritik matrix ${auditId} --plan\` previews its merged reading, \`arkaik kritik matrix ${auditId} --record --plan\` records it.`
|
|
25078
|
+
);
|
|
25079
|
+
}
|
|
25080
|
+
if (isPlanPartId(auditId) && (flags.has("record") || flags.has("scope"))) {
|
|
25081
|
+
const owner = planIdOfPartId(auditId) ?? auditId;
|
|
25082
|
+
return fail12(
|
|
25083
|
+
`kritik: "${auditId}" is one part of plan "${owner}" \u2014 a plan records once, as a whole, and carries its own scope marker: \`arkaik kritik matrix ${owner} --record --plan\`.`
|
|
25084
|
+
);
|
|
25085
|
+
}
|
|
23254
25086
|
let computed;
|
|
23255
25087
|
try {
|
|
23256
25088
|
computed = computeAuditMatrix(common.root, auditId, library);
|
|
@@ -23274,26 +25106,7 @@ ${unscored.length} cell${unscored.length === 1 ? "" : "s"} in the scope not re-s
|
|
|
23274
25106
|
console.log(JSON.stringify(file2, null, 2));
|
|
23275
25107
|
reportUnscored((line2) => console.error(line2));
|
|
23276
25108
|
} else {
|
|
23277
|
-
|
|
23278
|
-
console.log(`
|
|
23279
|
-
${renderMatrixMarkdown(matrix, domainNames)}
|
|
23280
|
-
`);
|
|
23281
|
-
const open = section.findings.filter(isOpenFinding);
|
|
23282
|
-
const lanes = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
23283
|
-
for (const finding of open) lanes[priorityOf(finding, library)]++;
|
|
23284
|
-
const counts = matrix.finding_counts;
|
|
23285
|
-
console.log(
|
|
23286
|
-
`${section.assessments.length} assessments \xB7 ${open.length} open findings (${counts.critical} critical, ${counts.high} high, ${counts.medium} medium, ${counts.low} low)
|
|
23287
|
-
lanes: P0 ${lanes.P0} \xB7 P1 ${lanes.P1} \xB7 P2 ${lanes.P2} \xB7 P3 ${lanes.P3}`
|
|
23288
|
-
);
|
|
23289
|
-
const p0 = open.filter((finding) => priorityOf(finding, library) === "P0");
|
|
23290
|
-
if (p0.length > 0) {
|
|
23291
|
-
console.log(`
|
|
23292
|
-
P0 \u2014 fix first:`);
|
|
23293
|
-
for (const finding of p0) {
|
|
23294
|
-
console.log(` [${severityOf(finding, library)}] ${finding.surface} \xB7 ${finding.id} \u2014 ${finding.title}`);
|
|
23295
|
-
}
|
|
23296
|
-
}
|
|
25109
|
+
printMatrixReport(section, matrix, library);
|
|
23297
25110
|
console.log(`
|
|
23298
25111
|
wrote ${matrixPath(common.root, auditId)}`);
|
|
23299
25112
|
if (scope !== void 0) {
|
|
@@ -23411,28 +25224,32 @@ function runSignals(args, common) {
|
|
|
23411
25224
|
console.log("");
|
|
23412
25225
|
process.exit(0);
|
|
23413
25226
|
}
|
|
25227
|
+
var lastAuditOf = (reading) => reading.auditIds[reading.auditIds.length - 1];
|
|
23414
25228
|
function auditPair(root, from, to) {
|
|
23415
|
-
const
|
|
23416
|
-
if (
|
|
25229
|
+
const readings = auditReadings(listAuditIds(root));
|
|
25230
|
+
if (readings.length < 2) {
|
|
23417
25231
|
fail12(
|
|
23418
|
-
`kritik: regressions needs two audits to compare \u2014 ${
|
|
25232
|
+
`kritik: regressions needs two audits to compare \u2014 ${readings.length === 0 ? "docs/quality/audits/ holds none" : `only "${readings[0].id}" exists`}.
|
|
23419
25233
|
A regression is the difference between two readings; one reading is a baseline.`
|
|
23420
25234
|
);
|
|
23421
25235
|
}
|
|
23422
25236
|
const known = (id) => {
|
|
23423
|
-
|
|
23424
|
-
|
|
25237
|
+
const reading = readingOf(readings, id);
|
|
25238
|
+
if (reading === void 0) {
|
|
25239
|
+
return fail12(`kritik: no audit "${id}" under docs/quality/audits/ (have: ${readings.map((r) => r.id).join(", ")})`);
|
|
25240
|
+
}
|
|
25241
|
+
return reading;
|
|
23425
25242
|
};
|
|
23426
|
-
const newer = to === void 0 ?
|
|
23427
|
-
const older = from === void 0 ?
|
|
25243
|
+
const newer = to === void 0 ? readings[readings.length - 1] : known(to);
|
|
25244
|
+
const older = from === void 0 ? readings[readings.indexOf(newer) - 1] : known(from);
|
|
23428
25245
|
if (older === void 0) {
|
|
23429
|
-
fail12(`kritik: "${newer}" is the oldest audit \u2014 there is nothing before it to compare against.`);
|
|
25246
|
+
fail12(`kritik: "${newer.id}" is the oldest audit \u2014 there is nothing before it to compare against.`);
|
|
23430
25247
|
}
|
|
23431
25248
|
if (older === newer) {
|
|
23432
|
-
fail12(`kritik: --from and --to name the same audit ("${newer}") \u2014 a regression needs two readings.`);
|
|
25249
|
+
fail12(`kritik: --from and --to name the same audit ("${newer.id}") \u2014 a regression needs two readings.`);
|
|
23433
25250
|
}
|
|
23434
|
-
if (
|
|
23435
|
-
fail12(`kritik: --from "${older}" is newer than --to "${newer}" \u2014 swap them, or the comparison inverts.`);
|
|
25251
|
+
if (readings.indexOf(older) > readings.indexOf(newer)) {
|
|
25252
|
+
fail12(`kritik: --from "${older.id}" is newer than --to "${newer.id}" \u2014 swap them, or the comparison inverts.`);
|
|
23436
25253
|
}
|
|
23437
25254
|
return { from: older, to: newer };
|
|
23438
25255
|
}
|
|
@@ -23444,12 +25261,14 @@ function runRegressions(args, common) {
|
|
|
23444
25261
|
}
|
|
23445
25262
|
const library = loadLibraryOrFail(common.root);
|
|
23446
25263
|
profileOrFail(common.root);
|
|
23447
|
-
const
|
|
25264
|
+
const pair = auditPair(common.root, single.from, single.to);
|
|
25265
|
+
const from = pair.from.id;
|
|
25266
|
+
const to = pair.to.id;
|
|
23448
25267
|
let regressions;
|
|
23449
25268
|
try {
|
|
23450
25269
|
regressions = detectRegressions(
|
|
23451
|
-
loadQualitySectionThrough(common.root, from, library),
|
|
23452
|
-
loadQualitySectionThrough(common.root, to, library),
|
|
25270
|
+
loadQualitySectionThrough(common.root, lastAuditOf(pair.from), library),
|
|
25271
|
+
loadQualitySectionThrough(common.root, lastAuditOf(pair.to), library),
|
|
23453
25272
|
library
|
|
23454
25273
|
);
|
|
23455
25274
|
} catch (error51) {
|
|
@@ -23550,6 +25369,21 @@ function runTrend(args, common) {
|
|
|
23550
25369
|
if (row.scope) {
|
|
23551
25370
|
console.log(` ${"".padEnd(widths[0])} scoped re-audit of ${row.scope.cells ?? "?"} cell(s) since ${row.scope.since}`);
|
|
23552
25371
|
}
|
|
25372
|
+
if (row.plan) {
|
|
25373
|
+
const parts = row.plan.parts.length;
|
|
25374
|
+
console.log(
|
|
25375
|
+
` ${"".padEnd(widths[0])} planned partial audit: ${row.plan.cells ?? "?"} cell${row.plan.cells === 1 ? "" : "s"} re-scored in ${parts} part${parts === 1 ? "" : "s"}` + (row.plan.since !== null ? ` since ${row.plan.since}` : " \u2014 no full audit before it")
|
|
25376
|
+
);
|
|
25377
|
+
if (row.plan.coverage !== null && single.domain === void 0) {
|
|
25378
|
+
const shown = {
|
|
25379
|
+
...row.plan.coverage,
|
|
25380
|
+
surfaces: Object.fromEntries(Object.entries(row.plan.coverage.surfaces).filter(([surface]) => surfaces.includes(surface)))
|
|
25381
|
+
};
|
|
25382
|
+
for (const note of coverageNotes(shown, trend.snapshots[index].overall)) {
|
|
25383
|
+
console.log(` ${"".padEnd(widths[0])} ${note}`);
|
|
25384
|
+
}
|
|
25385
|
+
}
|
|
25386
|
+
}
|
|
23553
25387
|
}
|
|
23554
25388
|
console.log(
|
|
23555
25389
|
`
|
|
@@ -23643,6 +25477,9 @@ function scopeReason(cell, resolvedBy) {
|
|
|
23643
25477
|
const findings = cell.because.map((id) => resolvedBy[id] !== void 0 ? `${id} (resolved by ${resolvedBy[id]})` : id);
|
|
23644
25478
|
return `because ${findings.join(", ")}`;
|
|
23645
25479
|
}
|
|
25480
|
+
function planOnlyScopeNote(plans) {
|
|
25481
|
+
return `only plan records are in this journal (${plans.join(", ")}) \u2014 a plan record is never what a scope is measured from. Until a full audit is recorded, re-check a fix by running its plan part again: \`arkaik kritik plan --run <DOMAIN:SURFACE>\`, then record that plan.`;
|
|
25482
|
+
}
|
|
23646
25483
|
function currentScope(common, library, profile, options = {}) {
|
|
23647
25484
|
const journal = resolveJournal(common.root, common.bundlePath);
|
|
23648
25485
|
if (!journal.present) {
|
|
@@ -23652,10 +25489,18 @@ function currentScope(common, library, profile, options = {}) {
|
|
|
23652
25489
|
}
|
|
23653
25490
|
const events = readFullJournalEvents(journal.journalPath);
|
|
23654
25491
|
const recorded = recordedAuditIds(events);
|
|
25492
|
+
const sinceIds = recordedSinceIds(events);
|
|
25493
|
+
const plans = recordedPlans(events).map((plan) => plan.plan);
|
|
23655
25494
|
if (options.since !== void 0) {
|
|
23656
|
-
|
|
25495
|
+
const since = options.since;
|
|
25496
|
+
if (isPlanId(since) || isPlanPartId(since) || recorded.includes(since) && !sinceIds.includes(since)) {
|
|
25497
|
+
fail12(
|
|
25498
|
+
`kritik: "${since}" is a plan record, never a scope's anchor \u2014 a scope is measured from a full or scoped audit (recorded: ${sinceIds.join(", ") || "none yet \u2014 `arkaik kritik matrix --record` writes one"}).`
|
|
25499
|
+
);
|
|
25500
|
+
}
|
|
25501
|
+
if (!sinceIds.includes(since)) {
|
|
23657
25502
|
fail12(
|
|
23658
|
-
`kritik: no recorded audit "${
|
|
25503
|
+
`kritik: no recorded audit "${since}" in ${journal.journalPath} (recorded: ${sinceIds.join(", ") || "none \u2014 `arkaik kritik matrix --record` writes one"}).
|
|
23659
25504
|
A scope is measured from a recorded reading; an audit directory that was never recorded is not one.`
|
|
23660
25505
|
);
|
|
23661
25506
|
}
|
|
@@ -23666,7 +25511,7 @@ A scope is measured from a recorded reading; an audit directory that was never r
|
|
|
23666
25511
|
} catch (error51) {
|
|
23667
25512
|
return fail12(`kritik: ${error51.message}`);
|
|
23668
25513
|
}
|
|
23669
|
-
return { scope: deriveAuditScope(events, section, library, options), journalPath: journal.journalPath, recorded };
|
|
25514
|
+
return { scope: deriveAuditScope(events, section, library, options), journalPath: journal.journalPath, recorded, plans };
|
|
23670
25515
|
}
|
|
23671
25516
|
function runScope(args, common) {
|
|
23672
25517
|
const { single, flags } = collect(args, [], ["json", "no-widen"]);
|
|
@@ -23676,17 +25521,29 @@ function runScope(args, common) {
|
|
|
23676
25521
|
}
|
|
23677
25522
|
const library = loadLibraryOrFail(common.root);
|
|
23678
25523
|
const profile = profileOrFail(common.root);
|
|
23679
|
-
const { scope } = currentScope(common, library, profile, {
|
|
25524
|
+
const { scope, plans } = currentScope(common, library, profile, {
|
|
23680
25525
|
...single.since !== void 0 ? { since: single.since } : {},
|
|
23681
25526
|
widen: !flags.has("no-widen")
|
|
23682
25527
|
});
|
|
23683
25528
|
if (flags.has("json")) {
|
|
23684
|
-
console.log(
|
|
25529
|
+
console.log(
|
|
25530
|
+
JSON.stringify(
|
|
25531
|
+
{
|
|
25532
|
+
...scope,
|
|
25533
|
+
summary: scopeSummary(scope),
|
|
25534
|
+
...scope.since === null && plans.length > 0 ? { note: `No full audit recorded yet: ${planOnlyScopeNote(plans)}` } : {}
|
|
25535
|
+
},
|
|
25536
|
+
null,
|
|
25537
|
+
2
|
|
25538
|
+
)
|
|
25539
|
+
);
|
|
23685
25540
|
process.exit(0);
|
|
23686
25541
|
}
|
|
23687
25542
|
if (scope.since === null) {
|
|
23688
25543
|
console.log(
|
|
23689
|
-
`
|
|
25544
|
+
plans.length > 0 ? `
|
|
25545
|
+
no full audit recorded yet: ${planOnlyScopeNote(plans)}
|
|
25546
|
+
` : `
|
|
23690
25547
|
no recorded audit yet \u2014 a scope is measured from one. \`arkaik kritik matrix --record\` writes it.
|
|
23691
25548
|
`
|
|
23692
25549
|
);
|
|
@@ -23727,6 +25584,218 @@ function runScope(args, common) {
|
|
|
23727
25584
|
console.log("");
|
|
23728
25585
|
process.exit(0);
|
|
23729
25586
|
}
|
|
25587
|
+
var PLAN_USAGE2 = `arkaik kritik plan --run <DOMAIN:SURFACE> [--run \u2026] [--out <path>] [--json] [--dry-run]
|
|
25588
|
+
arkaik kritik plan --status <planId> [--json]
|
|
25589
|
+
|
|
25590
|
+
Plan a partial audit before you run it. Each --run is one part: a domain on one
|
|
25591
|
+
surface, with an audit id of its own that sorts after every audit already on
|
|
25592
|
+
disk, the exact cells it scores, and a prompt to paste into an agent session.
|
|
25593
|
+
Run the parts in parallel sessions or one after the other, then record the plan
|
|
25594
|
+
once, after every part is scored: \`arkaik kritik matrix <planId> --record --plan\`.
|
|
25595
|
+
|
|
25596
|
+
--run D:S One part: a domain code and a profile surface, e.g. SEC:web.
|
|
25597
|
+
Repeatable; the order given is kept. The surface must match
|
|
25598
|
+
a profile id exactly (web, never Web).
|
|
25599
|
+
--out <path> Write the plan file here instead. --status and the record
|
|
25600
|
+
step read only docs/quality/plans/<planId>.json, so move it
|
|
25601
|
+
there before recording.
|
|
25602
|
+
--json Print the plan file instead of the summary.
|
|
25603
|
+
--dry-run Print the plan, write nothing.
|
|
25604
|
+
--counts-only Accepted. Every plan counts cells and checklist steps only.
|
|
25605
|
+
--status <id> Read-only: each part's progress (not started, in progress,
|
|
25606
|
+
scored) from its audit directory, and any score outside the plan.
|
|
25607
|
+
|
|
25608
|
+
--budget, --budget-tokens, --price and --tier arrive with the estimator. Until
|
|
25609
|
+
then they are refused.
|
|
25610
|
+
|
|
25611
|
+
Writes docs/quality/plans/<planId>.json`;
|
|
25612
|
+
var ESTIMATOR_FLAGS = ["budget", "budget-tokens", "price", "tier"];
|
|
25613
|
+
function recordedIdsOf(common) {
|
|
25614
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
25615
|
+
return journal.present ? recordedAuditIds(readFullJournalEvents(journal.journalPath)) : [];
|
|
25616
|
+
}
|
|
25617
|
+
function alignedTable(rows, numeric = []) {
|
|
25618
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
25619
|
+
return rows.map(
|
|
25620
|
+
(row) => ` ${row.map((cell, column) => numeric.includes(column) ? cell.padStart(widths[column]) : cell.padEnd(widths[column])).join(" ")}`.trimEnd()
|
|
25621
|
+
);
|
|
25622
|
+
}
|
|
25623
|
+
function partSummary(status) {
|
|
25624
|
+
return status.stray.length === 0 ? status.progress : `${status.progress}, ${status.stray.length} outside the plan`;
|
|
25625
|
+
}
|
|
25626
|
+
function readyToRecord(statuses, recorded) {
|
|
25627
|
+
return !recorded && statuses.every((status) => status.progress === "deferred" || status.progress === "scored" && status.stray.length === 0);
|
|
25628
|
+
}
|
|
25629
|
+
function printPlanStatus(plan, statuses, recorded) {
|
|
25630
|
+
console.log(`
|
|
25631
|
+
Plan ${plan.planId} \u2014 ${recorded ? "recorded" : "not recorded"}
|
|
25632
|
+
`);
|
|
25633
|
+
const rows = [
|
|
25634
|
+
["part", "audit id", "progress", "scored"],
|
|
25635
|
+
...statuses.map((status) => [
|
|
25636
|
+
`${status.domain}:${status.surface}`,
|
|
25637
|
+
status.auditId,
|
|
25638
|
+
partSummary(status),
|
|
25639
|
+
`${status.scored} of ${status.cells}`
|
|
25640
|
+
])
|
|
25641
|
+
];
|
|
25642
|
+
for (const line2 of alignedTable(rows)) console.log(line2);
|
|
25643
|
+
const cellList = (cells) => cells.map((cell) => `${cell.criterion_id} on ${cell.surface}`).join(", ");
|
|
25644
|
+
const notes = [];
|
|
25645
|
+
for (const status of statuses) {
|
|
25646
|
+
if (status.progress === "in progress" && status.missing.length > 0) {
|
|
25647
|
+
notes.push(`${status.domain}:${status.surface} still to score: ${cellList(status.missing)}`);
|
|
25648
|
+
}
|
|
25649
|
+
if (status.stray.length > 0) {
|
|
25650
|
+
notes.push(
|
|
25651
|
+
`${status.domain}:${status.surface} outside the plan, remove before recording: ${cellList(status.stray)} \u2014 for each, delete its row from docs/quality/audits/${status.auditId}/scores.json`
|
|
25652
|
+
);
|
|
25653
|
+
}
|
|
25654
|
+
}
|
|
25655
|
+
if (notes.length > 0) console.log("");
|
|
25656
|
+
for (const note of notes) console.log(` ${note}`);
|
|
25657
|
+
const included = statuses.filter((status) => status.progress !== "deferred");
|
|
25658
|
+
const done = included.filter((status) => status.progress === "scored").length;
|
|
25659
|
+
const strays = included.reduce((sum, status) => sum + status.stray.length, 0);
|
|
25660
|
+
if (recorded) {
|
|
25661
|
+
console.log(`
|
|
25662
|
+
recorded \u2014 to correct it, make a new plan for the same parts.
|
|
25663
|
+
`);
|
|
25664
|
+
} else if (done === included.length && strays === 0) {
|
|
25665
|
+
console.log(`
|
|
25666
|
+
every part is scored \u2014 record it once: ${plan.recordCommand}
|
|
25667
|
+
`);
|
|
25668
|
+
} else if (done === included.length) {
|
|
25669
|
+
console.log(
|
|
25670
|
+
`
|
|
25671
|
+
every plan cell is scored, but ${strays} score${strays === 1 ? "" : "s"} outside the plan must go first (above) \u2014 then record it once: ${plan.recordCommand}
|
|
25672
|
+
`
|
|
25673
|
+
);
|
|
25674
|
+
} else {
|
|
25675
|
+
console.log(`
|
|
25676
|
+
${done} of ${included.length} part${included.length === 1 ? "" : "s"} scored \u2014 record once every part is scored: ${plan.recordCommand}
|
|
25677
|
+
`);
|
|
25678
|
+
}
|
|
25679
|
+
}
|
|
25680
|
+
function printPlanSummary(plan, warnings, written, home) {
|
|
25681
|
+
const commit = plan.commit === null ? "not a git checkout" : `@ ${plan.commit.slice(0, 7)}`;
|
|
25682
|
+
console.log(`
|
|
25683
|
+
Plan ${plan.planId} ${commit} framework ${plan.frameworkVersion}
|
|
25684
|
+
`);
|
|
25685
|
+
const rows = [
|
|
25686
|
+
["part", "audit id", "cells", "steps", "status"],
|
|
25687
|
+
...plan.parts.map((part) => [`${part.domain}:${part.surface}`, part.auditId, String(part.cells.length), String(part.steps), part.status]),
|
|
25688
|
+
["total", "", String(plan.totals.cells), String(plan.totals.steps), `of ${plan.totals.applicableCells} applicable cells`]
|
|
25689
|
+
];
|
|
25690
|
+
for (const line2 of alignedTable(rows, [2, 3])) console.log(line2);
|
|
25691
|
+
console.log(`
|
|
25692
|
+
counts only: cells and checklist steps. The token estimate ships with the estimator.`);
|
|
25693
|
+
for (const warning of warnings) console.log(` note: ${warning}`);
|
|
25694
|
+
if (written === null) {
|
|
25695
|
+
console.log(` dry run \u2014 nothing written`);
|
|
25696
|
+
} else {
|
|
25697
|
+
console.log(` wrote ${written}`);
|
|
25698
|
+
if (resolve12(written) !== resolve12(home)) {
|
|
25699
|
+
console.log(` --status and the record step read only ${home} \u2014 move the file there before recording.`);
|
|
25700
|
+
console.log(` ${plan.planId} is reserved only once the file is under docs/quality/plans/ \u2014 until then, another plan can take the same id.`);
|
|
25701
|
+
}
|
|
25702
|
+
}
|
|
25703
|
+
console.log(`
|
|
25704
|
+
Paste into one agent session. For one session per part, each part's own prompt is parts[].prompt in the plan file (--json prints it).
|
|
25705
|
+
`);
|
|
25706
|
+
console.log(plan.prompt);
|
|
25707
|
+
console.log(`
|
|
25708
|
+
After every part is scored: ${plan.recordCommand}
|
|
25709
|
+
`);
|
|
25710
|
+
}
|
|
25711
|
+
function runPlan2(args, common) {
|
|
25712
|
+
const estimatorRefusal = (flag) => `kritik: --${flag} is not available yet \u2014 the estimator ships later, and every plan is counts-only for now.`;
|
|
25713
|
+
const last = args[args.length - 1];
|
|
25714
|
+
const bare = ESTIMATOR_FLAGS.find((flag) => last === `--${flag}`);
|
|
25715
|
+
if (bare !== void 0) fail12(estimatorRefusal(bare));
|
|
25716
|
+
const { single, many, flags } = collect(args, ["run"], ["json", "dry-run", "counts-only"]);
|
|
25717
|
+
if (flags.has("help")) {
|
|
25718
|
+
console.log(PLAN_USAGE2);
|
|
25719
|
+
process.exit(0);
|
|
25720
|
+
}
|
|
25721
|
+
for (const flag of ESTIMATOR_FLAGS) {
|
|
25722
|
+
if (single[flag] !== void 0) fail12(estimatorRefusal(flag));
|
|
25723
|
+
}
|
|
25724
|
+
if (single.status !== void 0) {
|
|
25725
|
+
if (many.run.length > 0 || single.out !== void 0 || flags.has("dry-run")) {
|
|
25726
|
+
fail12(`kritik: --status reads a plan that exists \u2014 it takes no --run, --out or --dry-run.
|
|
25727
|
+
|
|
25728
|
+
${PLAN_USAGE2}`);
|
|
25729
|
+
}
|
|
25730
|
+
let plan2;
|
|
25731
|
+
let statuses;
|
|
25732
|
+
try {
|
|
25733
|
+
plan2 = loadPlan(common.root, single.status);
|
|
25734
|
+
statuses = planStatus(common.root, plan2);
|
|
25735
|
+
} catch (error51) {
|
|
25736
|
+
return fail12(`kritik: ${error51.message}`);
|
|
25737
|
+
}
|
|
25738
|
+
const recorded = recordedIdsOf(common).includes(plan2.planId);
|
|
25739
|
+
if (flags.has("json")) {
|
|
25740
|
+
console.log(
|
|
25741
|
+
JSON.stringify(
|
|
25742
|
+
{
|
|
25743
|
+
plan_id: plan2.planId,
|
|
25744
|
+
recorded,
|
|
25745
|
+
parts: statuses.map((status) => ({ ...status, summary: partSummary(status) })),
|
|
25746
|
+
ready_to_record: readyToRecord(statuses, recorded)
|
|
25747
|
+
},
|
|
25748
|
+
null,
|
|
25749
|
+
2
|
|
25750
|
+
)
|
|
25751
|
+
);
|
|
25752
|
+
} else {
|
|
25753
|
+
printPlanStatus(plan2, statuses, recorded);
|
|
25754
|
+
}
|
|
25755
|
+
process.exit(0);
|
|
25756
|
+
}
|
|
25757
|
+
if (many.run.length === 0) fail12(`kritik: at least one --run DOMAIN:SURFACE is required
|
|
25758
|
+
|
|
25759
|
+
${PLAN_USAGE2}`);
|
|
25760
|
+
if (flags.has("dry-run") && single.out !== void 0) {
|
|
25761
|
+
fail12(`kritik: --dry-run writes nothing, so it takes no --out \u2014 drop one of the two.`);
|
|
25762
|
+
}
|
|
25763
|
+
const library = loadLibraryOrFail(common.root);
|
|
25764
|
+
let created;
|
|
25765
|
+
try {
|
|
25766
|
+
created = createPlan(common.root, library, many.run, { recorded: recordedIdsOf(common) });
|
|
25767
|
+
} catch (error51) {
|
|
25768
|
+
return fail12(`kritik: ${error51.message}`);
|
|
25769
|
+
}
|
|
25770
|
+
const { plan, warnings } = created;
|
|
25771
|
+
const home = planPath(common.root, plan.planId);
|
|
25772
|
+
const target = single.out ?? home;
|
|
25773
|
+
let written = null;
|
|
25774
|
+
if (!flags.has("dry-run")) {
|
|
25775
|
+
if (single.out !== void 0 && existsSync18(target)) {
|
|
25776
|
+
fail12(`kritik: ${target} already exists \u2014 a plan file is written once. Pick another --out.`);
|
|
25777
|
+
}
|
|
25778
|
+
if (existsSync18(target)) {
|
|
25779
|
+
fail12(`kritik: ${target} already exists \u2014 a plan file is written once, and another plan took ${plan.planId} meanwhile. Run the command again for the next id.`);
|
|
25780
|
+
}
|
|
25781
|
+
savePlan(target, plan);
|
|
25782
|
+
written = target;
|
|
25783
|
+
}
|
|
25784
|
+
if (flags.has("json")) {
|
|
25785
|
+
console.log(JSON.stringify(plan, null, 2));
|
|
25786
|
+
for (const warning of warnings) console.error(`note: ${warning}`);
|
|
25787
|
+
if (written !== null) {
|
|
25788
|
+
console.error(`wrote ${written}`);
|
|
25789
|
+
if (resolve12(written) !== resolve12(home)) {
|
|
25790
|
+
console.error(`--status and the record step read only ${home} \u2014 move the file there before recording.`);
|
|
25791
|
+
console.error(`${plan.planId} is reserved only once the file is under docs/quality/plans/ \u2014 until then, another plan can take the same id.`);
|
|
25792
|
+
}
|
|
25793
|
+
}
|
|
25794
|
+
} else {
|
|
25795
|
+
printPlanSummary(plan, warnings, written, home);
|
|
25796
|
+
}
|
|
25797
|
+
process.exit(0);
|
|
25798
|
+
}
|
|
23730
25799
|
function runIssue(args, common) {
|
|
23731
25800
|
const { single, flags, positionals } = collect(args);
|
|
23732
25801
|
if (flags.has("help")) {
|
|
@@ -23796,8 +25865,8 @@ ${CRITERION_USAGE}`);
|
|
|
23796
25865
|
let criterion;
|
|
23797
25866
|
try {
|
|
23798
25867
|
if (single.from !== void 0) {
|
|
23799
|
-
if (!
|
|
23800
|
-
criterion = JSON.parse(
|
|
25868
|
+
if (!existsSync18(single.from)) fail12(`kritik: no file at ${single.from}`);
|
|
25869
|
+
criterion = JSON.parse(readFileSync17(single.from, "utf8"));
|
|
23801
25870
|
} else {
|
|
23802
25871
|
const anchors = {};
|
|
23803
25872
|
for (const spec of many.anchor) {
|
|
@@ -23852,7 +25921,7 @@ function runKritik(args) {
|
|
|
23852
25921
|
const { rest, common } = takeCommon(args);
|
|
23853
25922
|
const [sub, ...subArgs] = rest;
|
|
23854
25923
|
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
23855
|
-
console.log(
|
|
25924
|
+
console.log(USAGE15);
|
|
23856
25925
|
process.exit(sub === void 0 ? 1 : 0);
|
|
23857
25926
|
}
|
|
23858
25927
|
switch (sub) {
|
|
@@ -23874,6 +25943,8 @@ function runKritik(args) {
|
|
|
23874
25943
|
return runBurndown(subArgs, common);
|
|
23875
25944
|
case "scope":
|
|
23876
25945
|
return runScope(subArgs, common);
|
|
25946
|
+
case "plan":
|
|
25947
|
+
return runPlan2(subArgs, common);
|
|
23877
25948
|
case "issue":
|
|
23878
25949
|
return runIssue(subArgs, common);
|
|
23879
25950
|
case "criterion":
|
|
@@ -23881,12 +25952,12 @@ function runKritik(args) {
|
|
|
23881
25952
|
default:
|
|
23882
25953
|
fail12(`kritik: unknown subcommand "${sub}"
|
|
23883
25954
|
|
|
23884
|
-
${
|
|
25955
|
+
${USAGE15}`);
|
|
23885
25956
|
}
|
|
23886
25957
|
}
|
|
23887
25958
|
|
|
23888
25959
|
// src/index.ts
|
|
23889
|
-
var
|
|
25960
|
+
var USAGE16 = `arkaik \u2014 CLI for Arkaik project bundles
|
|
23890
25961
|
|
|
23891
25962
|
Usage:
|
|
23892
25963
|
arkaik <command> [options]
|
|
@@ -23906,6 +25977,7 @@ Commands:
|
|
|
23906
25977
|
--list shows the projects your token can reach.
|
|
23907
25978
|
live --platform <p> [ids] Mark acceptances live on one platform from a deploy (release:append token).
|
|
23908
25979
|
--mentions <file> derives them from merged pull requests.
|
|
25980
|
+
shot [options] [id p value] Record screenshots: --manifest <file> to the hosted door (screenshot:append token), or into the repo bundle.
|
|
23909
25981
|
restore [options] [path] Replace the linked project's bundle, journal + quality (backs up first).
|
|
23910
25982
|
bootstrap <sub> [options] One-time onboarding: mine, plan, slice, merge a map from a repo.
|
|
23911
25983
|
kritik <sub> [options] Quality audits: score criteria, open findings, roll up the matrix.
|
|
@@ -23915,11 +25987,11 @@ Options:
|
|
|
23915
25987
|
-v, --version Print the version.
|
|
23916
25988
|
|
|
23917
25989
|
Run "arkaik <command> --help" for command-specific help.`;
|
|
23918
|
-
var VERSION = "0.
|
|
25990
|
+
var VERSION = "0.11.1";
|
|
23919
25991
|
function main(argv) {
|
|
23920
25992
|
const [command, ...rest] = argv;
|
|
23921
25993
|
if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
|
|
23922
|
-
console.log(
|
|
25994
|
+
console.log(USAGE16);
|
|
23923
25995
|
process.exit(0);
|
|
23924
25996
|
}
|
|
23925
25997
|
if (command === "--version" || command === "-v" || command === "version") {
|
|
@@ -23960,6 +26032,9 @@ function main(argv) {
|
|
|
23960
26032
|
case "live":
|
|
23961
26033
|
runLiveCli(rest);
|
|
23962
26034
|
return;
|
|
26035
|
+
case "shot":
|
|
26036
|
+
runShotCli(rest);
|
|
26037
|
+
return;
|
|
23963
26038
|
case "restore":
|
|
23964
26039
|
runRestoreCli(rest);
|
|
23965
26040
|
return;
|
|
@@ -23972,7 +26047,7 @@ function main(argv) {
|
|
|
23972
26047
|
default:
|
|
23973
26048
|
console.error(`Unknown command: ${command}
|
|
23974
26049
|
`);
|
|
23975
|
-
console.error(
|
|
26050
|
+
console.error(USAGE16);
|
|
23976
26051
|
process.exit(1);
|
|
23977
26052
|
}
|
|
23978
26053
|
}
|