arkaik-mcp 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/assets/kritik/library.json +5854 -0
- package/dist/index.js +1990 -148
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __export = (target, all) => {
|
|
|
5
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { dirname as dirname4, resolve as resolve3, sep } from "node:path";
|
|
10
|
+
|
|
8
11
|
// src/protocol.ts
|
|
9
12
|
import { createInterface } from "node:readline";
|
|
10
13
|
var PROTOCOL_VERSION = "2025-06-18";
|
|
@@ -14632,7 +14635,7 @@ function date4(params) {
|
|
|
14632
14635
|
config(en_default());
|
|
14633
14636
|
|
|
14634
14637
|
// ../schema/src/ids.ts
|
|
14635
|
-
var SPECIES_IDS = ["flow", "view", "data-model", "api-endpoint", "acceptance"];
|
|
14638
|
+
var SPECIES_IDS = ["flow", "view", "data-model", "api-endpoint", "acceptance", "decision"];
|
|
14636
14639
|
var STATUS_IDS = [
|
|
14637
14640
|
"idea",
|
|
14638
14641
|
"discovery",
|
|
@@ -14643,7 +14646,7 @@ var STATUS_IDS = [
|
|
|
14643
14646
|
"archived"
|
|
14644
14647
|
];
|
|
14645
14648
|
var PLATFORM_IDS = ["web", "ios", "android"];
|
|
14646
|
-
var EDGE_TYPE_IDS = ["composes", "calls", "displays", "queries", "covers"];
|
|
14649
|
+
var EDGE_TYPE_IDS = ["composes", "calls", "displays", "queries", "covers", "supersedes", "generates", "impacts"];
|
|
14647
14650
|
var VALID_EDGE_SEMANTICS = {
|
|
14648
14651
|
composes: [
|
|
14649
14652
|
["flow", "view"],
|
|
@@ -14670,6 +14673,18 @@ var VALID_EDGE_SEMANTICS = {
|
|
|
14670
14673
|
covers: [
|
|
14671
14674
|
["acceptance", "view"],
|
|
14672
14675
|
["acceptance", "flow"]
|
|
14676
|
+
],
|
|
14677
|
+
// Decision edges (cycle 2). `generates` and `impacts` are deliberately
|
|
14678
|
+
// disjoint: an acceptance is *generated* by a decision, never merely
|
|
14679
|
+
// impacted, so `impacts` does not admit an acceptance target
|
|
14680
|
+
// (docs/superpowers/specs/2026-08-03-decisions-species-design.md §3).
|
|
14681
|
+
supersedes: [["decision", "decision"]],
|
|
14682
|
+
generates: [["decision", "acceptance"]],
|
|
14683
|
+
impacts: [
|
|
14684
|
+
["decision", "flow"],
|
|
14685
|
+
["decision", "view"],
|
|
14686
|
+
["decision", "data-model"],
|
|
14687
|
+
["decision", "api-endpoint"]
|
|
14673
14688
|
]
|
|
14674
14689
|
};
|
|
14675
14690
|
var VALUE_TIER_IDS = ["functional", "emotional", "life-changing", "social-impact"];
|
|
@@ -14782,6 +14797,34 @@ function migrateStatusVocabulary(bundle) {
|
|
|
14782
14797
|
return { ...bundle, schema_version: STATUS_VOCABULARY_VERSION, nodes };
|
|
14783
14798
|
}
|
|
14784
14799
|
|
|
14800
|
+
// ../schema/src/decision.ts
|
|
14801
|
+
var DECISION_STATUS_IDS = [
|
|
14802
|
+
"proposed",
|
|
14803
|
+
"approved",
|
|
14804
|
+
"enacted",
|
|
14805
|
+
"rejected",
|
|
14806
|
+
"deprecated",
|
|
14807
|
+
"superseded"
|
|
14808
|
+
];
|
|
14809
|
+
function lifecycleStatusForDecision(decisionStatus) {
|
|
14810
|
+
switch (decisionStatus) {
|
|
14811
|
+
case "proposed":
|
|
14812
|
+
return "discovery";
|
|
14813
|
+
case "approved":
|
|
14814
|
+
return "backlog";
|
|
14815
|
+
case "enacted":
|
|
14816
|
+
return "live";
|
|
14817
|
+
case "rejected":
|
|
14818
|
+
case "deprecated":
|
|
14819
|
+
case "superseded":
|
|
14820
|
+
return "archived";
|
|
14821
|
+
}
|
|
14822
|
+
}
|
|
14823
|
+
function decisionStatusOf(node) {
|
|
14824
|
+
const raw = node.metadata?.decision_status;
|
|
14825
|
+
return DECISION_STATUS_IDS.includes(raw) ? raw : "proposed";
|
|
14826
|
+
}
|
|
14827
|
+
|
|
14785
14828
|
// ../schema/src/enums.ts
|
|
14786
14829
|
var SpeciesSchema = external_exports.enum(SPECIES_IDS).meta({
|
|
14787
14830
|
id: "Species",
|
|
@@ -14811,6 +14854,10 @@ var ValueSchema = external_exports.enum(VALUE_IDS).meta({
|
|
|
14811
14854
|
id: "Value",
|
|
14812
14855
|
description: "A Bain B2C Elements-of-Value element served by an acceptance (spec \xA73.2)."
|
|
14813
14856
|
});
|
|
14857
|
+
var DecisionStatusSchema = external_exports.enum(DECISION_STATUS_IDS).meta({
|
|
14858
|
+
id: "DecisionStatus",
|
|
14859
|
+
description: "Decision nodes only: proposed \u2192 approved (agreed, not yet reality) \u2192 enacted (in effect); terminal: rejected, deprecated, superseded. Not a lifecycle status \u2014 the node's status field is kept in sync (proposed\u2192discovery, approved\u2192backlog, enacted\u2192live, terminals\u2192archived)."
|
|
14860
|
+
});
|
|
14814
14861
|
|
|
14815
14862
|
// ../schema/src/id-gen.ts
|
|
14816
14863
|
var SPECIES_PREFIXES = {
|
|
@@ -14818,7 +14865,8 @@ var SPECIES_PREFIXES = {
|
|
|
14818
14865
|
view: "V-",
|
|
14819
14866
|
"data-model": "DM-",
|
|
14820
14867
|
"api-endpoint": "API-",
|
|
14821
|
-
acceptance: "AC-"
|
|
14868
|
+
acceptance: "AC-",
|
|
14869
|
+
decision: "DEC-"
|
|
14822
14870
|
};
|
|
14823
14871
|
function kebabCase(input) {
|
|
14824
14872
|
return input.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -14959,6 +15007,7 @@ function parseJournalLines(text) {
|
|
|
14959
15007
|
var NODE_REF_FIELDS = {
|
|
14960
15008
|
"node.updated": ["node_id"],
|
|
14961
15009
|
"node.status_changed": ["node_id"],
|
|
15010
|
+
"decision.status_changed": ["node_id"],
|
|
14962
15011
|
"node.deleted": ["node_id"],
|
|
14963
15012
|
"edge.added": ["source_id", "target_id"],
|
|
14964
15013
|
"ref.added": ["node_id"],
|
|
@@ -14991,9 +15040,15 @@ function crossCheckJournal(bundle) {
|
|
|
14991
15040
|
const nodesRaw = Array.isArray(bundle.nodes) ? bundle.nodes : [];
|
|
14992
15041
|
const edgesRaw = Array.isArray(bundle.edges) ? bundle.edges : [];
|
|
14993
15042
|
const snapshotNodeStatus = /* @__PURE__ */ new Map();
|
|
15043
|
+
const snapshotDecisionStatus = /* @__PURE__ */ new Map();
|
|
14994
15044
|
for (const n of nodesRaw) {
|
|
14995
15045
|
const id = str(n?.id);
|
|
14996
|
-
if (id !== void 0)
|
|
15046
|
+
if (id !== void 0) {
|
|
15047
|
+
snapshotNodeStatus.set(id, n.status);
|
|
15048
|
+
const metadata = n.metadata;
|
|
15049
|
+
const decisionStatus = metadata && typeof metadata === "object" && !Array.isArray(metadata) ? metadata.decision_status : void 0;
|
|
15050
|
+
snapshotDecisionStatus.set(id, decisionStatus ?? "proposed");
|
|
15051
|
+
}
|
|
14997
15052
|
}
|
|
14998
15053
|
const snapshotEdgeIds = /* @__PURE__ */ new Set();
|
|
14999
15054
|
for (const e of edgesRaw) {
|
|
@@ -15030,6 +15085,7 @@ function crossCheckJournal(bundle) {
|
|
|
15030
15085
|
});
|
|
15031
15086
|
const everNodes = new Set(snapshotNodeStatus.keys());
|
|
15032
15087
|
const everEdges = new Set(snapshotEdgeIds);
|
|
15088
|
+
const baselined = /* @__PURE__ */ new Set();
|
|
15033
15089
|
for (const { ev } of valid) {
|
|
15034
15090
|
if (ev.type === "node.created") {
|
|
15035
15091
|
const nid = str(ev.node_id);
|
|
@@ -15037,11 +15093,20 @@ function crossCheckJournal(bundle) {
|
|
|
15037
15093
|
} else if (ev.type === "edge.added") {
|
|
15038
15094
|
const eid = str(ev.edge_id);
|
|
15039
15095
|
if (eid) everEdges.add(eid);
|
|
15096
|
+
} else if (ev.type === "journal.baseline" && Array.isArray(ev.node_ids)) {
|
|
15097
|
+
for (const raw of ev.node_ids) {
|
|
15098
|
+
const nid = str(raw);
|
|
15099
|
+
if (nid) {
|
|
15100
|
+
baselined.add(nid);
|
|
15101
|
+
everNodes.add(nid);
|
|
15102
|
+
}
|
|
15103
|
+
}
|
|
15040
15104
|
}
|
|
15041
15105
|
}
|
|
15042
15106
|
const ordered = orderEvents(valid.map((v) => v.ev));
|
|
15043
15107
|
const created = /* @__PURE__ */ new Set();
|
|
15044
15108
|
const lastProjectStatus = /* @__PURE__ */ new Map();
|
|
15109
|
+
const lastDecisionStatus = /* @__PURE__ */ new Map();
|
|
15045
15110
|
for (const ev of ordered) {
|
|
15046
15111
|
if (ev.type === "node.created") {
|
|
15047
15112
|
const nid = str(ev.node_id);
|
|
@@ -15052,6 +15117,12 @@ function crossCheckJournal(bundle) {
|
|
|
15052
15117
|
const to = str(ev.to);
|
|
15053
15118
|
if (to !== void 0) lastProjectStatus.set(nid, to);
|
|
15054
15119
|
}
|
|
15120
|
+
} else if (ev.type === "decision.status_changed") {
|
|
15121
|
+
const nid = str(ev.node_id);
|
|
15122
|
+
if (nid) {
|
|
15123
|
+
const to = str(ev.to);
|
|
15124
|
+
if (to !== void 0) lastDecisionStatus.set(nid, to);
|
|
15125
|
+
}
|
|
15055
15126
|
}
|
|
15056
15127
|
}
|
|
15057
15128
|
for (const { ev, index } of valid) {
|
|
@@ -15069,6 +15140,19 @@ function crossCheckJournal(bundle) {
|
|
|
15069
15140
|
}
|
|
15070
15141
|
}
|
|
15071
15142
|
}
|
|
15143
|
+
if (ev.type === "deliverable.shipped" && Array.isArray(ev.node_ids)) {
|
|
15144
|
+
ev.node_ids.forEach((raw, i) => {
|
|
15145
|
+
const ref = str(raw);
|
|
15146
|
+
if (ref !== void 0 && !everNodes.has(ref)) {
|
|
15147
|
+
findings.push({
|
|
15148
|
+
path: `journal[${index}].node_ids[${i}]`,
|
|
15149
|
+
rule: "journal-dangling-node-ref",
|
|
15150
|
+
message: `journal[${index}] (${ev.type}): references node "${ref}" that never existed in the snapshot or journal.`,
|
|
15151
|
+
severity: "error"
|
|
15152
|
+
});
|
|
15153
|
+
}
|
|
15154
|
+
});
|
|
15155
|
+
}
|
|
15072
15156
|
if (ev.type === "edge.removed") {
|
|
15073
15157
|
const ref = str(ev.edge_id);
|
|
15074
15158
|
if (ref !== void 0 && !everEdges.has(ref)) {
|
|
@@ -15082,7 +15166,7 @@ function crossCheckJournal(bundle) {
|
|
|
15082
15166
|
}
|
|
15083
15167
|
}
|
|
15084
15168
|
for (const [nodeId, status] of snapshotNodeStatus) {
|
|
15085
|
-
if (!created.has(nodeId)) {
|
|
15169
|
+
if (!created.has(nodeId) && !baselined.has(nodeId)) {
|
|
15086
15170
|
findings.push({
|
|
15087
15171
|
path: "journal",
|
|
15088
15172
|
rule: "journal-missing-node-created",
|
|
@@ -15100,8 +15184,40 @@ function crossCheckJournal(bundle) {
|
|
|
15100
15184
|
});
|
|
15101
15185
|
}
|
|
15102
15186
|
}
|
|
15187
|
+
for (const [nodeId, last] of lastDecisionStatus) {
|
|
15188
|
+
if (!snapshotDecisionStatus.has(nodeId)) continue;
|
|
15189
|
+
const current = snapshotDecisionStatus.get(nodeId) ?? "proposed";
|
|
15190
|
+
if (last !== current) {
|
|
15191
|
+
findings.push({
|
|
15192
|
+
path: "journal",
|
|
15193
|
+
rule: "journal-decision-status-mismatch",
|
|
15194
|
+
message: `Node "${nodeId}": journal's last decision.status_changed.to "${last}" disagrees with snapshot decision_status "${String(current)}".`,
|
|
15195
|
+
severity: "error"
|
|
15196
|
+
});
|
|
15197
|
+
}
|
|
15198
|
+
}
|
|
15103
15199
|
return findings;
|
|
15104
15200
|
}
|
|
15201
|
+
function missingProvenanceNodeIds(snapshotNodeIds, events) {
|
|
15202
|
+
const covered = /* @__PURE__ */ new Set();
|
|
15203
|
+
for (const ev of events) {
|
|
15204
|
+
if (ev.type === "node.created") {
|
|
15205
|
+
if (typeof ev.node_id === "string") covered.add(ev.node_id);
|
|
15206
|
+
} else if (ev.type === "journal.baseline" && Array.isArray(ev.node_ids)) {
|
|
15207
|
+
for (const id of ev.node_ids) {
|
|
15208
|
+
if (typeof id === "string") covered.add(id);
|
|
15209
|
+
}
|
|
15210
|
+
}
|
|
15211
|
+
}
|
|
15212
|
+
const missing = [];
|
|
15213
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15214
|
+
for (const id of snapshotNodeIds) {
|
|
15215
|
+
if (covered.has(id) || seen.has(id)) continue;
|
|
15216
|
+
seen.add(id);
|
|
15217
|
+
missing.push(id);
|
|
15218
|
+
}
|
|
15219
|
+
return missing;
|
|
15220
|
+
}
|
|
15105
15221
|
|
|
15106
15222
|
// ../schema/src/journal-events.ts
|
|
15107
15223
|
var envelope = {
|
|
@@ -15136,6 +15252,13 @@ var NodeStatusChangedEventSchema = external_exports.object({
|
|
|
15136
15252
|
to: AnyStatusSchema,
|
|
15137
15253
|
platform: PlatformSchema.optional()
|
|
15138
15254
|
}).catchall(external_exports.unknown());
|
|
15255
|
+
var DecisionStatusChangedEventSchema = external_exports.object({
|
|
15256
|
+
...envelope,
|
|
15257
|
+
type: external_exports.literal("decision.status_changed"),
|
|
15258
|
+
node_id: external_exports.string(),
|
|
15259
|
+
from: DecisionStatusSchema,
|
|
15260
|
+
to: DecisionStatusSchema
|
|
15261
|
+
}).catchall(external_exports.unknown());
|
|
15139
15262
|
var NodeDeletedEventSchema = external_exports.object({ ...envelope, type: external_exports.literal("node.deleted"), node_id: external_exports.string() }).catchall(external_exports.unknown());
|
|
15140
15263
|
var EdgeAddedEventSchema = external_exports.object({
|
|
15141
15264
|
...envelope,
|
|
@@ -15153,6 +15276,21 @@ var ReleaseTaggedEventSchema = external_exports.object({
|
|
|
15153
15276
|
notes: external_exports.string().optional(),
|
|
15154
15277
|
platform: PlatformSchema.optional()
|
|
15155
15278
|
}).catchall(external_exports.unknown());
|
|
15279
|
+
var DeliverableShippedEventSchema = external_exports.object({
|
|
15280
|
+
...envelope,
|
|
15281
|
+
type: external_exports.literal("deliverable.shipped"),
|
|
15282
|
+
deliverable_id: external_exports.string(),
|
|
15283
|
+
title: external_exports.string(),
|
|
15284
|
+
summary: external_exports.string().optional(),
|
|
15285
|
+
url: external_exports.string().optional(),
|
|
15286
|
+
node_ids: external_exports.array(external_exports.string()).optional(),
|
|
15287
|
+
platform: PlatformSchema.optional(),
|
|
15288
|
+
lab_note: external_exports.object({
|
|
15289
|
+
en: external_exports.object({ title: external_exports.string(), summary: external_exports.string() }).catchall(external_exports.unknown()),
|
|
15290
|
+
fr: external_exports.object({ title: external_exports.string().optional(), summary: external_exports.string().optional() }).catchall(external_exports.unknown()).optional(),
|
|
15291
|
+
suggested: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
15292
|
+
}).catchall(external_exports.unknown()).optional().meta({ description: "The Lab Note a merged PR carried (slice 3); en.title/en.summary required when present." })
|
|
15293
|
+
}).catchall(external_exports.unknown());
|
|
15156
15294
|
var IdeaProposedEventSchema = external_exports.object({
|
|
15157
15295
|
...envelope,
|
|
15158
15296
|
type: external_exports.literal("idea.proposed"),
|
|
@@ -15186,35 +15324,192 @@ var RefStatusChangedEventSchema = external_exports.object({
|
|
|
15186
15324
|
to: external_exports.string(),
|
|
15187
15325
|
synced_at: external_exports.string()
|
|
15188
15326
|
}).catchall(external_exports.unknown());
|
|
15327
|
+
var JournalBaselineEventSchema = external_exports.object({ ...envelope, type: external_exports.literal("journal.baseline"), node_ids: external_exports.array(external_exports.string()) }).catchall(external_exports.unknown());
|
|
15328
|
+
var QualityAuditCompletedEventSchema = external_exports.object({
|
|
15329
|
+
...envelope,
|
|
15330
|
+
type: external_exports.literal("quality.audit.completed"),
|
|
15331
|
+
audit_id: external_exports.string(),
|
|
15332
|
+
framework_version: external_exports.string(),
|
|
15333
|
+
commit: external_exports.string().optional(),
|
|
15334
|
+
scores: external_exports.record(external_exports.string(), external_exports.record(external_exports.string(), external_exports.number())).optional(),
|
|
15335
|
+
counts: external_exports.object({
|
|
15336
|
+
critical: external_exports.number().optional(),
|
|
15337
|
+
high: external_exports.number().optional(),
|
|
15338
|
+
medium: external_exports.number().optional(),
|
|
15339
|
+
low: external_exports.number().optional(),
|
|
15340
|
+
info: external_exports.number().optional()
|
|
15341
|
+
}).catchall(external_exports.unknown()).optional()
|
|
15342
|
+
}).catchall(external_exports.unknown());
|
|
15343
|
+
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
15344
|
+
...envelope,
|
|
15345
|
+
type: external_exports.literal("quality.finding.opened"),
|
|
15346
|
+
finding_id: external_exports.string(),
|
|
15347
|
+
criterion_id: external_exports.string(),
|
|
15348
|
+
surface: external_exports.string(),
|
|
15349
|
+
severity: external_exports.string(),
|
|
15350
|
+
priority: external_exports.string(),
|
|
15351
|
+
title: external_exports.string(),
|
|
15352
|
+
node_ids: external_exports.array(external_exports.string()).optional(),
|
|
15353
|
+
issue_url: external_exports.string().optional()
|
|
15354
|
+
}).catchall(external_exports.unknown());
|
|
15355
|
+
var QualityFindingResolvedEventSchema = external_exports.object({
|
|
15356
|
+
...envelope,
|
|
15357
|
+
type: external_exports.literal("quality.finding.resolved"),
|
|
15358
|
+
finding_id: external_exports.string(),
|
|
15359
|
+
resolved_by: external_exports.string().optional(),
|
|
15360
|
+
node_ids: external_exports.array(external_exports.string()).optional()
|
|
15361
|
+
}).catchall(external_exports.unknown());
|
|
15362
|
+
var QualitySignalTrippedEventSchema = external_exports.object({
|
|
15363
|
+
...envelope,
|
|
15364
|
+
type: external_exports.literal("quality.signal.tripped"),
|
|
15365
|
+
criterion_id: external_exports.string(),
|
|
15366
|
+
surface: external_exports.string(),
|
|
15367
|
+
signal: external_exports.string(),
|
|
15368
|
+
detail: external_exports.string().optional()
|
|
15369
|
+
}).catchall(external_exports.unknown());
|
|
15189
15370
|
var JOURNAL_EVENT_SCHEMAS = {
|
|
15190
15371
|
"node.created": NodeCreatedEventSchema,
|
|
15191
15372
|
"node.updated": NodeUpdatedEventSchema,
|
|
15192
15373
|
"node.status_changed": NodeStatusChangedEventSchema,
|
|
15374
|
+
"decision.status_changed": DecisionStatusChangedEventSchema,
|
|
15193
15375
|
"node.deleted": NodeDeletedEventSchema,
|
|
15194
15376
|
"edge.added": EdgeAddedEventSchema,
|
|
15195
15377
|
"edge.removed": EdgeRemovedEventSchema,
|
|
15196
15378
|
"release.tagged": ReleaseTaggedEventSchema,
|
|
15379
|
+
"deliverable.shipped": DeliverableShippedEventSchema,
|
|
15197
15380
|
"idea.proposed": IdeaProposedEventSchema,
|
|
15198
15381
|
"request.filed": RequestFiledEventSchema,
|
|
15199
15382
|
"ref.added": RefAddedEventSchema,
|
|
15200
15383
|
"ref.removed": RefRemovedEventSchema,
|
|
15201
|
-
"ref.status_changed": RefStatusChangedEventSchema
|
|
15384
|
+
"ref.status_changed": RefStatusChangedEventSchema,
|
|
15385
|
+
"journal.baseline": JournalBaselineEventSchema,
|
|
15386
|
+
"quality.audit.completed": QualityAuditCompletedEventSchema,
|
|
15387
|
+
"quality.finding.opened": QualityFindingOpenedEventSchema,
|
|
15388
|
+
"quality.finding.resolved": QualityFindingResolvedEventSchema,
|
|
15389
|
+
"quality.signal.tripped": QualitySignalTrippedEventSchema
|
|
15202
15390
|
};
|
|
15203
15391
|
var KnownJournalEventSchema = external_exports.union([
|
|
15204
15392
|
NodeCreatedEventSchema,
|
|
15205
15393
|
NodeUpdatedEventSchema,
|
|
15206
15394
|
NodeStatusChangedEventSchema,
|
|
15395
|
+
DecisionStatusChangedEventSchema,
|
|
15207
15396
|
NodeDeletedEventSchema,
|
|
15208
15397
|
EdgeAddedEventSchema,
|
|
15209
15398
|
EdgeRemovedEventSchema,
|
|
15210
15399
|
ReleaseTaggedEventSchema,
|
|
15400
|
+
DeliverableShippedEventSchema,
|
|
15211
15401
|
IdeaProposedEventSchema,
|
|
15212
15402
|
RequestFiledEventSchema,
|
|
15213
15403
|
RefAddedEventSchema,
|
|
15214
15404
|
RefRemovedEventSchema,
|
|
15215
|
-
RefStatusChangedEventSchema
|
|
15405
|
+
RefStatusChangedEventSchema,
|
|
15406
|
+
JournalBaselineEventSchema,
|
|
15407
|
+
QualityAuditCompletedEventSchema,
|
|
15408
|
+
QualityFindingOpenedEventSchema,
|
|
15409
|
+
QualityFindingResolvedEventSchema,
|
|
15410
|
+
QualitySignalTrippedEventSchema
|
|
15216
15411
|
]);
|
|
15217
15412
|
|
|
15413
|
+
// ../schema/src/quality-schemas.ts
|
|
15414
|
+
var GradeSchema = external_exports.enum(["A", "B", "C", "D", "E"]);
|
|
15415
|
+
var KritikScalesSchema = external_exports.object({
|
|
15416
|
+
grades: external_exports.partialRecord(GradeSchema, external_exports.number()).optional(),
|
|
15417
|
+
severity_buckets: external_exports.partialRecord(external_exports.enum(["critical", "high", "medium", "low", "info"]), external_exports.tuple([external_exports.number(), external_exports.number()])).optional(),
|
|
15418
|
+
caps: external_exports.object({ critical_open: GradeSchema.optional(), high_open: GradeSchema.optional() }).catchall(external_exports.unknown()).optional()
|
|
15419
|
+
}).catchall(external_exports.unknown()).meta({
|
|
15420
|
+
id: "KritikScales",
|
|
15421
|
+
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)."
|
|
15422
|
+
});
|
|
15423
|
+
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)." });
|
|
15424
|
+
var KritikIssueTemplateSchema = external_exports.object({
|
|
15425
|
+
title_template: external_exports.string().optional(),
|
|
15426
|
+
labels: external_exports.array(external_exports.string()).optional(),
|
|
15427
|
+
body_skeleton: external_exports.string().optional()
|
|
15428
|
+
}).catchall(external_exports.unknown()).meta({ id: "KritikIssueTemplate", description: "Per-criterion issue skeleton \u2014 what `arkaik kritik issue` prefills." });
|
|
15429
|
+
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." });
|
|
15430
|
+
var KritikCriterionSchema = external_exports.object({
|
|
15431
|
+
id: external_exports.string().meta({ description: "Stable identifier, `<DOMAIN>-NN`. Never redefined \u2014 retired via superseded_by." }),
|
|
15432
|
+
domain: external_exports.string(),
|
|
15433
|
+
subcategory: external_exports.string().optional(),
|
|
15434
|
+
name: external_exports.string().optional(),
|
|
15435
|
+
question: external_exports.string().optional(),
|
|
15436
|
+
definition: external_exports.string().optional(),
|
|
15437
|
+
rationale: external_exports.string().optional(),
|
|
15438
|
+
applies_to: external_exports.array(external_exports.string()).optional().meta({ description: "Surface ids where the criterion is meaningful; absence means N/A." }),
|
|
15439
|
+
level_anchors: external_exports.record(external_exports.string(), external_exports.string()).optional().meta({ description: "Observable descriptions per maturity level, keyed l0\u2026l4." }),
|
|
15440
|
+
default_impact: external_exports.number().optional(),
|
|
15441
|
+
weight: external_exports.number().optional().meta({ description: "Weight in the domain roll-up (1\u20133; 3 = load-bearing). Absent means 1." }),
|
|
15442
|
+
references: external_exports.array(KritikReferenceSchema).optional(),
|
|
15443
|
+
checklist: external_exports.array(external_exports.string()).optional(),
|
|
15444
|
+
signals: external_exports.array(external_exports.string()).optional().meta({ description: "Mechanically checkable monitoring hooks run between audits." }),
|
|
15445
|
+
remediation: external_exports.string().optional(),
|
|
15446
|
+
issue: KritikIssueTemplateSchema.optional(),
|
|
15447
|
+
superseded_by: external_exports.string().optional()
|
|
15448
|
+
}).catchall(external_exports.unknown()).meta({ id: "KritikCriterion", description: "The atomic auditable unit (packages/kritik-library/SPEC.md \xA7 5)." });
|
|
15449
|
+
var KritikLibrarySchema = external_exports.object({
|
|
15450
|
+
version: external_exports.string().meta({ description: "Semver of the pack; matrices are comparable only within a major." }),
|
|
15451
|
+
domains: external_exports.array(KritikDomainSchema),
|
|
15452
|
+
criteria: external_exports.array(KritikCriterionSchema),
|
|
15453
|
+
scales: KritikScalesSchema.optional()
|
|
15454
|
+
}).catchall(external_exports.unknown()).meta({
|
|
15455
|
+
id: "KritikLibrary",
|
|
15456
|
+
description: "A versioned criteria pack. Embedded on export; repos may instead pin it as a sidecar file."
|
|
15457
|
+
});
|
|
15458
|
+
var SurfaceDefSchema = external_exports.object({
|
|
15459
|
+
id: external_exports.string(),
|
|
15460
|
+
title: external_exports.string(),
|
|
15461
|
+
platform: PlatformSchema.optional().meta({
|
|
15462
|
+
description: "Optional bridge to PLATFORM_IDS where a surface is also a view-shipping platform. Surfaces are not platforms (RFC \xA7 2)."
|
|
15463
|
+
}),
|
|
15464
|
+
path: external_exports.string().optional()
|
|
15465
|
+
}).catchall(external_exports.unknown()).meta({ id: "SurfaceDef", description: "One independently assessable body of code \u2014 an audit target, chosen at install." });
|
|
15466
|
+
var QualityProfileSchema = external_exports.object({
|
|
15467
|
+
surfaces: external_exports.array(SurfaceDefSchema),
|
|
15468
|
+
domain_weights: external_exports.record(external_exports.string(), external_exports.number()).optional().meta({
|
|
15469
|
+
description: "Per-domain weight in the surface roll-up, keyed by domain code. A missing weight is 1."
|
|
15470
|
+
})
|
|
15471
|
+
}).catchall(external_exports.unknown()).meta({ id: "QualityProfile", description: "The project's parameterization of the pack (RFC \xA7 6)." });
|
|
15472
|
+
var QualityAssessmentSchema = external_exports.object({
|
|
15473
|
+
criterion_id: external_exports.string(),
|
|
15474
|
+
surface: external_exports.string(),
|
|
15475
|
+
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({
|
|
15476
|
+
description: "Maturity 0\u20134. N/A is the absence of the row, never a level."
|
|
15477
|
+
}),
|
|
15478
|
+
evidence: external_exports.string().meta({ description: "file:line / config citations. A score without evidence is an opinion, not an assessment." }),
|
|
15479
|
+
audit_id: external_exports.string(),
|
|
15480
|
+
commit: external_exports.string().optional(),
|
|
15481
|
+
ts: external_exports.string()
|
|
15482
|
+
}).catchall(external_exports.unknown()).meta({ id: "QualityAssessment", description: "One (criterion \xD7 surface) score \u2014 latest wins; history lives in the journal." });
|
|
15483
|
+
var QualityFindingSchema = external_exports.object({
|
|
15484
|
+
id: external_exports.string(),
|
|
15485
|
+
criterion_id: external_exports.string(),
|
|
15486
|
+
surface: external_exports.string(),
|
|
15487
|
+
title: external_exports.string(),
|
|
15488
|
+
detail: external_exports.string(),
|
|
15489
|
+
evidence: external_exports.string(),
|
|
15490
|
+
impact: external_exports.number().meta({ description: "Worst plausible consequence, 1\u20135." }),
|
|
15491
|
+
likelihood: external_exports.number().meta({ description: "Probability it materializes, 1\u20135." }),
|
|
15492
|
+
cost: external_exports.enum(["S", "M", "L", "XL"]),
|
|
15493
|
+
status: external_exports.enum(["open", "resolved", "refuted", "accepted-risk"]),
|
|
15494
|
+
remediation: external_exports.string().optional(),
|
|
15495
|
+
node_ids: external_exports.array(external_exports.string()).optional().meta({ description: "Graph nodes this finding is about \u2014 the tie deliverable.shipped already uses." }),
|
|
15496
|
+
issue_url: external_exports.string().optional(),
|
|
15497
|
+
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." })
|
|
15498
|
+
}).catchall(external_exports.unknown()).meta({
|
|
15499
|
+
id: "QualityFinding",
|
|
15500
|
+
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."
|
|
15501
|
+
});
|
|
15502
|
+
var QualitySectionSchema = external_exports.object({
|
|
15503
|
+
framework_version: external_exports.string(),
|
|
15504
|
+
library: KritikLibrarySchema.optional(),
|
|
15505
|
+
profile: QualityProfileSchema,
|
|
15506
|
+
assessments: external_exports.array(QualityAssessmentSchema),
|
|
15507
|
+
findings: external_exports.array(QualityFindingSchema)
|
|
15508
|
+
}).catchall(external_exports.unknown()).meta({
|
|
15509
|
+
id: "QualitySection",
|
|
15510
|
+
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."
|
|
15511
|
+
});
|
|
15512
|
+
|
|
15218
15513
|
// ../schema/src/bundle.ts
|
|
15219
15514
|
var PlatformStatusMapSchema = external_exports.partialRecord(
|
|
15220
15515
|
PlatformSchema,
|
|
@@ -15267,6 +15562,18 @@ var NodeMetadataSchema = external_exports.object({
|
|
|
15267
15562
|
}),
|
|
15268
15563
|
product: external_exports.string().optional().meta({
|
|
15269
15564
|
description: "Product membership (docs/spec/bundle-format.md \xA7 Products); flow, view, and acceptance only."
|
|
15565
|
+
}),
|
|
15566
|
+
decision_status: DecisionStatusSchema.optional().meta({
|
|
15567
|
+
description: "Decision nodes only: proposed | approved | enacted | rejected | deprecated | superseded. The node's lifecycle status is kept in sync (spec \xA72)."
|
|
15568
|
+
}),
|
|
15569
|
+
context: external_exports.string().optional().meta({
|
|
15570
|
+
description: "Decision nodes only: Context \u2014 the Why (markdown)."
|
|
15571
|
+
}),
|
|
15572
|
+
consequences: external_exports.string().optional().meta({
|
|
15573
|
+
description: "Decision nodes only: Consequences \u2014 the How (markdown)."
|
|
15574
|
+
}),
|
|
15575
|
+
decided_at: external_exports.string().optional().meta({
|
|
15576
|
+
description: "Decision nodes only: ISO 8601 date the decision was made."
|
|
15270
15577
|
})
|
|
15271
15578
|
}).catchall(external_exports.unknown()).meta({ id: "NodeMetadata", description: "Optional metadata for a node." });
|
|
15272
15579
|
var NodeSchema = external_exports.object({
|
|
@@ -15344,7 +15651,8 @@ var ProjectMetadataSchema = external_exports.object({
|
|
|
15344
15651
|
}),
|
|
15345
15652
|
products: external_exports.array(ProductDefinitionSchema).optional().meta({
|
|
15346
15653
|
description: "Product definitions (docs/spec/bundle-format.md \xA7 Products) \u2014 additive; unknown fields preserved."
|
|
15347
|
-
})
|
|
15654
|
+
}),
|
|
15655
|
+
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." })
|
|
15348
15656
|
}).catchall(external_exports.unknown()).meta({ id: "ProjectMetadata", description: "Optional project-level UI settings." });
|
|
15349
15657
|
var ProjectSchema = external_exports.object({
|
|
15350
15658
|
id: external_exports.string().meta({ description: "Unique project identifier." }),
|
|
@@ -15372,6 +15680,9 @@ var ProjectBundleSchema = external_exports.object({
|
|
|
15372
15680
|
edges: external_exports.array(EdgeSchema).meta({ description: "All edges (relationships) between nodes." }),
|
|
15373
15681
|
journal: external_exports.array(JournalEventSchema).optional().meta({
|
|
15374
15682
|
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."
|
|
15683
|
+
}),
|
|
15684
|
+
quality: QualitySectionSchema.optional().meta({
|
|
15685
|
+
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."
|
|
15375
15686
|
})
|
|
15376
15687
|
}).catchall(external_exports.unknown()).meta({
|
|
15377
15688
|
id: "ProjectBundle",
|
|
@@ -15379,6 +15690,115 @@ var ProjectBundleSchema = external_exports.object({
|
|
|
15379
15690
|
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)."
|
|
15380
15691
|
});
|
|
15381
15692
|
|
|
15693
|
+
// ../schema/src/products.ts
|
|
15694
|
+
var PRODUCT_MEMBERSHIP_SPECIES = ["flow", "view", "acceptance"];
|
|
15695
|
+
function resolveProducts(project) {
|
|
15696
|
+
const stored = project?.metadata?.products;
|
|
15697
|
+
if (!Array.isArray(stored)) return [];
|
|
15698
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15699
|
+
const products = [];
|
|
15700
|
+
for (const entry of stored) {
|
|
15701
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
15702
|
+
const candidate = entry;
|
|
15703
|
+
if (typeof candidate.id !== "string" || candidate.id.trim() === "" || seen.has(candidate.id)) continue;
|
|
15704
|
+
seen.add(candidate.id);
|
|
15705
|
+
products.push(candidate);
|
|
15706
|
+
}
|
|
15707
|
+
return products;
|
|
15708
|
+
}
|
|
15709
|
+
function productOf(node) {
|
|
15710
|
+
if (!PRODUCT_MEMBERSHIP_SPECIES.includes(node.species)) return null;
|
|
15711
|
+
const product = node.metadata?.product;
|
|
15712
|
+
return typeof product === "string" ? product : null;
|
|
15713
|
+
}
|
|
15714
|
+
var SYSTEM_LAYER_SPECIES = ["api-endpoint", "data-model"];
|
|
15715
|
+
var USAGE_EDGE_TYPES = /* @__PURE__ */ new Set(["calls", "displays", "queries"]);
|
|
15716
|
+
function buildProductUsageIndex(nodes, edges) {
|
|
15717
|
+
const speciesById = /* @__PURE__ */ new Map();
|
|
15718
|
+
for (const node of nodes) speciesById.set(node.id, node.species);
|
|
15719
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
15720
|
+
for (const edge of edges) {
|
|
15721
|
+
if (!USAGE_EDGE_TYPES.has(edge.edge_type)) continue;
|
|
15722
|
+
const targetSpecies = speciesById.get(edge.target_id);
|
|
15723
|
+
if (targetSpecies === void 0 || !SYSTEM_LAYER_SPECIES.includes(targetSpecies)) continue;
|
|
15724
|
+
const list = outgoing.get(edge.source_id) ?? [];
|
|
15725
|
+
list.push(edge.target_id);
|
|
15726
|
+
outgoing.set(edge.source_id, list);
|
|
15727
|
+
}
|
|
15728
|
+
const seedsByProduct = /* @__PURE__ */ new Map();
|
|
15729
|
+
for (const node of nodes) {
|
|
15730
|
+
const product = productOf(node);
|
|
15731
|
+
if (product === null) continue;
|
|
15732
|
+
const seeds = seedsByProduct.get(product) ?? /* @__PURE__ */ new Set();
|
|
15733
|
+
for (const next of outgoing.get(node.id) ?? []) seeds.add(next);
|
|
15734
|
+
seedsByProduct.set(product, seeds);
|
|
15735
|
+
}
|
|
15736
|
+
const byNode = /* @__PURE__ */ new Map();
|
|
15737
|
+
for (const [product, seeds] of seedsByProduct) {
|
|
15738
|
+
const visited = new Set(seeds);
|
|
15739
|
+
let frontier = [...seeds];
|
|
15740
|
+
while (frontier.length > 0) {
|
|
15741
|
+
const next = [];
|
|
15742
|
+
for (const current of frontier) {
|
|
15743
|
+
const products = byNode.get(current) ?? /* @__PURE__ */ new Set();
|
|
15744
|
+
products.add(product);
|
|
15745
|
+
byNode.set(current, products);
|
|
15746
|
+
for (const neighbor of outgoing.get(current) ?? []) {
|
|
15747
|
+
if (visited.has(neighbor)) continue;
|
|
15748
|
+
visited.add(neighbor);
|
|
15749
|
+
next.push(neighbor);
|
|
15750
|
+
}
|
|
15751
|
+
}
|
|
15752
|
+
frontier = next;
|
|
15753
|
+
}
|
|
15754
|
+
}
|
|
15755
|
+
const index = /* @__PURE__ */ new Map();
|
|
15756
|
+
for (const [nodeId, products] of byNode) index.set(nodeId, [...products].sort());
|
|
15757
|
+
return index;
|
|
15758
|
+
}
|
|
15759
|
+
function productsUsingNode(nodeId, index) {
|
|
15760
|
+
return index.get(nodeId) ?? [];
|
|
15761
|
+
}
|
|
15762
|
+
function buildProductGraph(nodes, edges) {
|
|
15763
|
+
return {
|
|
15764
|
+
edges,
|
|
15765
|
+
nodesById: new Map(nodes.map((node) => [node.id, node])),
|
|
15766
|
+
usageIndex: buildProductUsageIndex(nodes, edges)
|
|
15767
|
+
};
|
|
15768
|
+
}
|
|
15769
|
+
function coveredAnchorIds(acceptanceId, edges) {
|
|
15770
|
+
return edges.filter((edge) => edge.edge_type === "covers" && edge.source_id === acceptanceId).map((edge) => edge.target_id);
|
|
15771
|
+
}
|
|
15772
|
+
function productsOfAcceptance(acceptance, edges, nodesById) {
|
|
15773
|
+
const anchors = coveredAnchorIds(acceptance.id, edges).map((anchorId) => nodesById.get(anchorId)).filter((anchor) => anchor !== void 0);
|
|
15774
|
+
if (anchors.length === 0) {
|
|
15775
|
+
const stored = productOf(acceptance);
|
|
15776
|
+
return stored === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([stored]);
|
|
15777
|
+
}
|
|
15778
|
+
const products = /* @__PURE__ */ new Set();
|
|
15779
|
+
for (const anchor of anchors) {
|
|
15780
|
+
const product = productOf(anchor);
|
|
15781
|
+
if (product !== null) products.add(product);
|
|
15782
|
+
}
|
|
15783
|
+
return products;
|
|
15784
|
+
}
|
|
15785
|
+
function productsOfNode(node, graph) {
|
|
15786
|
+
if (node.species === "acceptance") {
|
|
15787
|
+
return productsOfAcceptance(node, graph.edges, graph.nodesById);
|
|
15788
|
+
}
|
|
15789
|
+
if (PRODUCT_MEMBERSHIP_SPECIES.includes(node.species)) {
|
|
15790
|
+
const stored = productOf(node);
|
|
15791
|
+
return stored === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([stored]);
|
|
15792
|
+
}
|
|
15793
|
+
return new Set(productsUsingNode(node.id, graph.usageIndex));
|
|
15794
|
+
}
|
|
15795
|
+
function nodeInProduct(node, productId, graph) {
|
|
15796
|
+
if (productId === null) return true;
|
|
15797
|
+
const products = productsOfNode(node, graph);
|
|
15798
|
+
if (products.size === 0) return !PRODUCT_MEMBERSHIP_SPECIES.includes(node.species);
|
|
15799
|
+
return products.has(productId);
|
|
15800
|
+
}
|
|
15801
|
+
|
|
15382
15802
|
// ../schema/src/maps.ts
|
|
15383
15803
|
var MAP_FLOW_PLATFORMS_MODES = ["rings", "bars"];
|
|
15384
15804
|
var MAP_VIEW_PLATFORMS_MODES = ["chips", "rows"];
|
|
@@ -15414,11 +15834,20 @@ function resolveMapDefaults(definition) {
|
|
|
15414
15834
|
edge_types: definition.edge_types ?? defaults?.edge_types ?? []
|
|
15415
15835
|
};
|
|
15416
15836
|
}
|
|
15417
|
-
function
|
|
15837
|
+
function declared(value) {
|
|
15838
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
15839
|
+
}
|
|
15840
|
+
function mapProductId(definition, defaultProductId = null) {
|
|
15841
|
+
return declared(definition?.product) ?? defaultProductId;
|
|
15842
|
+
}
|
|
15843
|
+
function computeMapSubgraph(definition, nodes, edges, options) {
|
|
15418
15844
|
const resolved = resolveMapDefaults(definition);
|
|
15419
15845
|
const speciesSet = new Set(resolved.species);
|
|
15420
15846
|
const edgeTypeSet = new Set(resolved.edge_types);
|
|
15421
|
-
const
|
|
15847
|
+
const productId = options?.product !== void 0 ? options.product : mapProductId(definition);
|
|
15848
|
+
const productGraph = productId === null ? void 0 : options?.graph ?? buildProductGraph(nodes, edges);
|
|
15849
|
+
const selectable = productGraph === void 0 ? nodes : nodes.filter((node) => nodeInProduct(node, productId, productGraph));
|
|
15850
|
+
const keptNodes = selectable.filter((node) => speciesSet.has(node.species));
|
|
15422
15851
|
const keptNodeIds = new Set(keptNodes.map((node) => node.id));
|
|
15423
15852
|
const keptEdges = edges.filter(
|
|
15424
15853
|
(edge) => edgeTypeSet.has(edge.edge_type) && keptNodeIds.has(edge.source_id) && keptNodeIds.has(edge.target_id)
|
|
@@ -15473,21 +15902,205 @@ function listMaps(project) {
|
|
|
15473
15902
|
return [...BUILT_IN_MAPS, ...custom2];
|
|
15474
15903
|
}
|
|
15475
15904
|
|
|
15476
|
-
// ../schema/src/
|
|
15477
|
-
var
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15905
|
+
// ../schema/src/quality.ts
|
|
15906
|
+
var asArray = (value) => Array.isArray(value) ? value : [];
|
|
15907
|
+
var MATURITY_LEVELS = [0, 1, 2, 3, 4];
|
|
15908
|
+
var FINDING_SEVERITIES = ["critical", "high", "medium", "low", "info"];
|
|
15909
|
+
var REMEDIATION_COSTS = ["S", "M", "L", "XL"];
|
|
15910
|
+
var FINDING_STATUSES = ["open", "resolved", "refuted", "accepted-risk"];
|
|
15911
|
+
var QUALITY_GRADES = ["A", "B", "C", "D", "E"];
|
|
15912
|
+
var DEFAULT_GRADE_BANDS = { A: 85, B: 70, C: 55, D: 40, E: 0 };
|
|
15913
|
+
var DEFAULT_SEVERITY_BUCKETS = {
|
|
15914
|
+
critical: [20, 25],
|
|
15915
|
+
high: [12, 19],
|
|
15916
|
+
medium: [6, 11],
|
|
15917
|
+
low: [2, 5],
|
|
15918
|
+
info: [1, 1]
|
|
15919
|
+
};
|
|
15920
|
+
var DEFAULT_CAPS = {
|
|
15921
|
+
critical_open: "D",
|
|
15922
|
+
high_open: "B"
|
|
15923
|
+
};
|
|
15924
|
+
var CROSS_SURFACE_ID = "cross-surface";
|
|
15925
|
+
function mergeKritikLibrary(pack, overlay) {
|
|
15926
|
+
if (!overlay || typeof overlay !== "object") return pack;
|
|
15927
|
+
const domains = [...asArray(pack.domains)];
|
|
15928
|
+
for (const domain2 of asArray(overlay.domains)) {
|
|
15929
|
+
if (typeof domain2?.code !== "string" || domain2.code === "") continue;
|
|
15930
|
+
const at = domains.findIndex((existing) => existing?.code === domain2.code);
|
|
15931
|
+
if (at >= 0) domains[at] = domain2;
|
|
15932
|
+
else domains.push(domain2);
|
|
15933
|
+
}
|
|
15934
|
+
const criteria = [...asArray(pack.criteria)];
|
|
15935
|
+
for (const criterion of asArray(overlay.criteria)) {
|
|
15936
|
+
if (typeof criterion?.id !== "string" || criterion.id === "") continue;
|
|
15937
|
+
const at = criteria.findIndex((existing) => existing?.id === criterion.id);
|
|
15938
|
+
if (at >= 0) criteria[at] = criterion;
|
|
15939
|
+
else criteria.push(criterion);
|
|
15940
|
+
}
|
|
15941
|
+
const scales = pack.scales || overlay.scales ? { ...pack.scales ?? {}, ...overlay.scales ?? {} } : void 0;
|
|
15942
|
+
return { ...pack, domains, criteria, ...scales ? { scales } : {} };
|
|
15943
|
+
}
|
|
15944
|
+
function bucketsOf(library) {
|
|
15945
|
+
const stored = library?.scales?.severity_buckets;
|
|
15946
|
+
const out = { ...DEFAULT_SEVERITY_BUCKETS };
|
|
15947
|
+
if (!stored || typeof stored !== "object") return out;
|
|
15948
|
+
for (const severity of FINDING_SEVERITIES) {
|
|
15949
|
+
const band = stored[severity];
|
|
15950
|
+
if (Array.isArray(band) && typeof band[0] === "number" && typeof band[1] === "number") {
|
|
15951
|
+
out[severity] = [band[0], band[1]];
|
|
15952
|
+
}
|
|
15489
15953
|
}
|
|
15490
|
-
return
|
|
15954
|
+
return out;
|
|
15955
|
+
}
|
|
15956
|
+
function bandsOf(library) {
|
|
15957
|
+
const stored = library?.scales?.grades;
|
|
15958
|
+
const out = { ...DEFAULT_GRADE_BANDS };
|
|
15959
|
+
if (!stored || typeof stored !== "object") return out;
|
|
15960
|
+
for (const grade of QUALITY_GRADES) {
|
|
15961
|
+
const min = stored[grade];
|
|
15962
|
+
if (typeof min === "number" && Number.isFinite(min)) out[grade] = min;
|
|
15963
|
+
}
|
|
15964
|
+
return out;
|
|
15965
|
+
}
|
|
15966
|
+
function capsOf(library) {
|
|
15967
|
+
const stored = library?.scales?.caps;
|
|
15968
|
+
const pick2 = (value, fallback) => typeof value === "string" && QUALITY_GRADES.includes(value) ? value : fallback;
|
|
15969
|
+
return {
|
|
15970
|
+
critical_open: pick2(stored?.critical_open, DEFAULT_CAPS.critical_open),
|
|
15971
|
+
high_open: pick2(stored?.high_open, DEFAULT_CAPS.high_open)
|
|
15972
|
+
};
|
|
15973
|
+
}
|
|
15974
|
+
function severityOf(finding, library) {
|
|
15975
|
+
const impact = typeof finding.impact === "number" ? finding.impact : 0;
|
|
15976
|
+
const likelihood = typeof finding.likelihood === "number" ? finding.likelihood : 0;
|
|
15977
|
+
const score = impact * likelihood;
|
|
15978
|
+
const buckets = bucketsOf(library);
|
|
15979
|
+
const worstFirst = [...FINDING_SEVERITIES].sort((a, b) => buckets[b][0] - buckets[a][0]);
|
|
15980
|
+
for (const severity of worstFirst) {
|
|
15981
|
+
if (score >= buckets[severity][0]) return severity;
|
|
15982
|
+
}
|
|
15983
|
+
return "info";
|
|
15984
|
+
}
|
|
15985
|
+
function priorityOf(finding, library) {
|
|
15986
|
+
const severity = severityOf(finding, library);
|
|
15987
|
+
const cheap = finding.cost === "S";
|
|
15988
|
+
if (severity === "critical") return "P0";
|
|
15989
|
+
if (severity === "high") return cheap ? "P0" : "P1";
|
|
15990
|
+
if (severity === "medium") return cheap ? "P1" : "P2";
|
|
15991
|
+
if (severity === "low") return cheap ? "P2" : "P3";
|
|
15992
|
+
return "P3";
|
|
15993
|
+
}
|
|
15994
|
+
function gradeOf(score, library) {
|
|
15995
|
+
const bands = bandsOf(library);
|
|
15996
|
+
const bestFirst = [...QUALITY_GRADES].sort((a, b) => bands[b] - bands[a]);
|
|
15997
|
+
for (const grade of bestFirst) {
|
|
15998
|
+
if (score >= bands[grade]) return grade;
|
|
15999
|
+
}
|
|
16000
|
+
return "E";
|
|
16001
|
+
}
|
|
16002
|
+
function capGrade(grade, cap) {
|
|
16003
|
+
return QUALITY_GRADES[Math.max(QUALITY_GRADES.indexOf(grade), QUALITY_GRADES.indexOf(cap))];
|
|
16004
|
+
}
|
|
16005
|
+
function isOpenFinding(finding) {
|
|
16006
|
+
return (finding.status ?? "open") === "open";
|
|
16007
|
+
}
|
|
16008
|
+
function resolveKritikLibrary(section, library) {
|
|
16009
|
+
const explicit = library ?? section?.library;
|
|
16010
|
+
if (explicit && Array.isArray(explicit.criteria) && Array.isArray(explicit.domains)) return explicit;
|
|
16011
|
+
if (!section) return void 0;
|
|
16012
|
+
const ids = /* @__PURE__ */ new Set();
|
|
16013
|
+
for (const row of [...asArray(section.assessments), ...asArray(section.findings)]) {
|
|
16014
|
+
if (typeof row?.criterion_id === "string" && row.criterion_id !== "") ids.add(row.criterion_id);
|
|
16015
|
+
}
|
|
16016
|
+
if (ids.size === 0) return void 0;
|
|
16017
|
+
const domainOf = (id) => id.includes("-") ? id.slice(0, id.lastIndexOf("-")) : id;
|
|
16018
|
+
const criteria = [...ids].sort().map((id) => ({ id, domain: domainOf(id), weight: 1 }));
|
|
16019
|
+
const domains = [...new Set(criteria.map((c) => c.domain))].sort().map((code) => ({ code, name: code }));
|
|
16020
|
+
return { version: explicit?.version ?? "unknown", domains, criteria, scales: explicit?.scales };
|
|
16021
|
+
}
|
|
16022
|
+
function deriveQualityMatrix(bundle, library) {
|
|
16023
|
+
const section = bundle.quality;
|
|
16024
|
+
const pack = resolveKritikLibrary(section, library);
|
|
16025
|
+
const assessments = asArray(section?.assessments);
|
|
16026
|
+
const findings = asArray(section?.findings);
|
|
16027
|
+
const openFindings = findings.filter((finding) => isOpenFinding(finding));
|
|
16028
|
+
const declared2 = asArray(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => typeof id === "string" && id !== "");
|
|
16029
|
+
const surfaces = declared2.length > 0 ? [...new Set(declared2)] : [...new Set(assessments.map((a) => a.surface).filter((id) => typeof id === "string" && id !== ""))].sort();
|
|
16030
|
+
const domains = asArray(pack?.domains).map((domain2) => domain2?.code).filter((code) => typeof code === "string" && code !== "");
|
|
16031
|
+
const domainOfCriterion = /* @__PURE__ */ new Map();
|
|
16032
|
+
const weightOfCriterion = /* @__PURE__ */ new Map();
|
|
16033
|
+
for (const criterion of asArray(pack?.criteria)) {
|
|
16034
|
+
if (typeof criterion?.id !== "string") continue;
|
|
16035
|
+
if (typeof criterion.domain === "string") domainOfCriterion.set(criterion.id, criterion.domain);
|
|
16036
|
+
weightOfCriterion.set(criterion.id, typeof criterion.weight === "number" && criterion.weight > 0 ? criterion.weight : 1);
|
|
16037
|
+
}
|
|
16038
|
+
const caps = capsOf(pack);
|
|
16039
|
+
const weights = section?.profile?.domain_weights;
|
|
16040
|
+
const matrix = {};
|
|
16041
|
+
for (const domain2 of domains) {
|
|
16042
|
+
matrix[domain2] = {};
|
|
16043
|
+
for (const surface of surfaces) {
|
|
16044
|
+
const rows = assessments.filter((a) => a.surface === surface && domainOfCriterion.get(a.criterion_id) === domain2);
|
|
16045
|
+
if (rows.length === 0) {
|
|
16046
|
+
matrix[domain2][surface] = null;
|
|
16047
|
+
continue;
|
|
16048
|
+
}
|
|
16049
|
+
let earned = 0;
|
|
16050
|
+
let available = 0;
|
|
16051
|
+
for (const row of rows) {
|
|
16052
|
+
const weight = weightOfCriterion.get(row.criterion_id) ?? 1;
|
|
16053
|
+
const level = typeof row.level === "number" ? Math.min(Math.max(row.level, 0), 4) : 0;
|
|
16054
|
+
earned += level * weight;
|
|
16055
|
+
available += 4 * weight;
|
|
16056
|
+
}
|
|
16057
|
+
if (available === 0) {
|
|
16058
|
+
matrix[domain2][surface] = null;
|
|
16059
|
+
continue;
|
|
16060
|
+
}
|
|
16061
|
+
const score = Math.round(earned / available * 100);
|
|
16062
|
+
const cellSeverities = openFindings.filter((finding) => finding.surface === surface && domainOfCriterion.get(finding.criterion_id) === domain2).map((finding) => severityOf(finding, pack));
|
|
16063
|
+
const banded = gradeOf(score, pack);
|
|
16064
|
+
let grade = banded;
|
|
16065
|
+
if (cellSeverities.includes("critical")) grade = capGrade(grade, caps.critical_open);
|
|
16066
|
+
else if (cellSeverities.includes("high")) grade = capGrade(grade, caps.high_open);
|
|
16067
|
+
matrix[domain2][surface] = {
|
|
16068
|
+
score,
|
|
16069
|
+
grade,
|
|
16070
|
+
capped: grade !== banded,
|
|
16071
|
+
criteria: rows.length,
|
|
16072
|
+
findings: {
|
|
16073
|
+
critical: cellSeverities.filter((s) => s === "critical").length,
|
|
16074
|
+
high: cellSeverities.filter((s) => s === "high").length,
|
|
16075
|
+
medium: cellSeverities.filter((s) => s === "medium").length,
|
|
16076
|
+
low: cellSeverities.filter((s) => s === "low").length
|
|
16077
|
+
}
|
|
16078
|
+
};
|
|
16079
|
+
}
|
|
16080
|
+
}
|
|
16081
|
+
const overall = {};
|
|
16082
|
+
for (const surface of surfaces) {
|
|
16083
|
+
let weighted = 0;
|
|
16084
|
+
let total = 0;
|
|
16085
|
+
for (const domain2 of domains) {
|
|
16086
|
+
const cell = matrix[domain2]?.[surface];
|
|
16087
|
+
if (!cell) continue;
|
|
16088
|
+
const weight = typeof weights?.[domain2] === "number" ? weights[domain2] : 1;
|
|
16089
|
+
weighted += cell.score * weight;
|
|
16090
|
+
total += weight;
|
|
16091
|
+
}
|
|
16092
|
+
overall[surface] = total > 0 ? Math.round(weighted / total) : null;
|
|
16093
|
+
}
|
|
16094
|
+
const finding_counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
16095
|
+
for (const finding of openFindings) finding_counts[severityOf(finding, pack)]++;
|
|
16096
|
+
return {
|
|
16097
|
+
framework_version: section?.framework_version,
|
|
16098
|
+
surfaces,
|
|
16099
|
+
domains,
|
|
16100
|
+
matrix,
|
|
16101
|
+
overall,
|
|
16102
|
+
finding_counts
|
|
16103
|
+
};
|
|
15491
16104
|
}
|
|
15492
16105
|
|
|
15493
16106
|
// ../schema/src/validate.ts
|
|
@@ -15596,7 +16209,9 @@ function validateBundle(input) {
|
|
|
15596
16209
|
}
|
|
15597
16210
|
const platforms = node.platforms;
|
|
15598
16211
|
if (!platforms || platforms.length === 0) {
|
|
15599
|
-
|
|
16212
|
+
if (species !== "decision") {
|
|
16213
|
+
error51(`${base}.platforms`, "platforms-non-empty", `Node ${nodeId}: platforms array is empty or missing`);
|
|
16214
|
+
}
|
|
15600
16215
|
} else {
|
|
15601
16216
|
for (const p of platforms) {
|
|
15602
16217
|
if (!PLATFORM_IDS.includes(p)) {
|
|
@@ -15718,6 +16333,25 @@ function validateBundle(input) {
|
|
|
15718
16333
|
}
|
|
15719
16334
|
});
|
|
15720
16335
|
}
|
|
16336
|
+
const decisionStatus = md.decision_status;
|
|
16337
|
+
if (decisionStatus !== void 0 && species !== "decision") {
|
|
16338
|
+
warn(
|
|
16339
|
+
`${base}.metadata.decision_status`,
|
|
16340
|
+
"decision-status-wrong-species",
|
|
16341
|
+
`decision_status is meaningful on decision nodes only; "${nodeId}" is a ${species}.`
|
|
16342
|
+
);
|
|
16343
|
+
}
|
|
16344
|
+
if (species === "decision") {
|
|
16345
|
+
const effective = decisionStatusOf({ metadata: node.metadata });
|
|
16346
|
+
const expected = lifecycleStatusForDecision(effective);
|
|
16347
|
+
if (node.status !== expected) {
|
|
16348
|
+
warn(
|
|
16349
|
+
`${base}.status`,
|
|
16350
|
+
"decision-lifecycle-mismatch",
|
|
16351
|
+
`Decision "${nodeId}" is ${effective}, whose lifecycle status should be "${expected}", but status is "${node.status}" (spec \xA72).`
|
|
16352
|
+
);
|
|
16353
|
+
}
|
|
16354
|
+
}
|
|
15721
16355
|
if (species === "flow") {
|
|
15722
16356
|
const playlist = md.playlist;
|
|
15723
16357
|
if (!node.metadata || !playlist || !playlist.entries) {
|
|
@@ -15985,13 +16619,98 @@ function validateBundle(input) {
|
|
|
15985
16619
|
composesSet.add(`${sourceId}->${targetId}`);
|
|
15986
16620
|
}
|
|
15987
16621
|
});
|
|
16622
|
+
const PLAYLIST_ENTRY_TYPES = ["view", "flow", "condition", "junction"];
|
|
16623
|
+
const checkPlaylistShape = (entries, flowId, path, depth = 0) => {
|
|
16624
|
+
if (depth > 50) return;
|
|
16625
|
+
if (!Array.isArray(entries)) {
|
|
16626
|
+
error51(path, "playlist-entry-shape", `Flow ${flowId}: ${path} must be an array of playlist entries`);
|
|
16627
|
+
return;
|
|
16628
|
+
}
|
|
16629
|
+
entries.forEach((raw, i) => {
|
|
16630
|
+
const p = `${path}[${i}]`;
|
|
16631
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
16632
|
+
error51(p, "playlist-entry-shape", `Flow ${flowId}: ${p} must be a playlist entry object`);
|
|
16633
|
+
return;
|
|
16634
|
+
}
|
|
16635
|
+
const entry = raw;
|
|
16636
|
+
const type = entry.type;
|
|
16637
|
+
if (typeof type !== "string" || !PLAYLIST_ENTRY_TYPES.includes(type)) {
|
|
16638
|
+
error51(
|
|
16639
|
+
`${p}.type`,
|
|
16640
|
+
"playlist-entry-shape",
|
|
16641
|
+
`Flow ${flowId}: ${p}.type must be one of ${PLAYLIST_ENTRY_TYPES.join(", ")} (got ${JSON.stringify(type)})`
|
|
16642
|
+
);
|
|
16643
|
+
return;
|
|
16644
|
+
}
|
|
16645
|
+
if (type === "view") {
|
|
16646
|
+
if (typeof entry.view_id !== "string") {
|
|
16647
|
+
error51(`${p}.view_id`, "playlist-entry-shape", `Flow ${flowId}: ${p} is a view entry with no view_id string`);
|
|
16648
|
+
}
|
|
16649
|
+
} else if (type === "flow") {
|
|
16650
|
+
if (typeof entry.flow_id !== "string") {
|
|
16651
|
+
error51(`${p}.flow_id`, "playlist-entry-shape", `Flow ${flowId}: ${p} is a flow entry with no flow_id string`);
|
|
16652
|
+
}
|
|
16653
|
+
} else if (type === "condition") {
|
|
16654
|
+
if (typeof entry.label !== "string") {
|
|
16655
|
+
error51(`${p}.label`, "playlist-entry-shape", `Flow ${flowId}: ${p} is a condition with no label string`);
|
|
16656
|
+
}
|
|
16657
|
+
for (const branch of ["if_true", "if_false"]) {
|
|
16658
|
+
if (!Array.isArray(entry[branch])) {
|
|
16659
|
+
error51(
|
|
16660
|
+
`${p}.${branch}`,
|
|
16661
|
+
"playlist-entry-shape",
|
|
16662
|
+
`Flow ${flowId}: ${p}.${branch} must be an array of playlist entries (both branches are required, use [] for an empty one)`
|
|
16663
|
+
);
|
|
16664
|
+
} else {
|
|
16665
|
+
checkPlaylistShape(entry[branch], flowId, `${p}.${branch}`, depth + 1);
|
|
16666
|
+
}
|
|
16667
|
+
}
|
|
16668
|
+
} else {
|
|
16669
|
+
if (typeof entry.label !== "string") {
|
|
16670
|
+
error51(`${p}.label`, "playlist-entry-shape", `Flow ${flowId}: ${p} is a junction with no label string`);
|
|
16671
|
+
}
|
|
16672
|
+
if (!Array.isArray(entry.cases)) {
|
|
16673
|
+
error51(`${p}.cases`, "playlist-entry-shape", `Flow ${flowId}: ${p}.cases must be an array of junction cases`);
|
|
16674
|
+
return;
|
|
16675
|
+
}
|
|
16676
|
+
entry.cases.forEach((rawCase, j) => {
|
|
16677
|
+
const cp = `${p}.cases[${j}]`;
|
|
16678
|
+
if (typeof rawCase !== "object" || rawCase === null || Array.isArray(rawCase)) {
|
|
16679
|
+
error51(cp, "playlist-entry-shape", `Flow ${flowId}: ${cp} must be a junction case object`);
|
|
16680
|
+
return;
|
|
16681
|
+
}
|
|
16682
|
+
const branch = rawCase;
|
|
16683
|
+
if (typeof branch.label !== "string") {
|
|
16684
|
+
error51(`${cp}.label`, "playlist-entry-shape", `Flow ${flowId}: ${cp} has no label string`);
|
|
16685
|
+
}
|
|
16686
|
+
if (!Array.isArray(branch.entries)) {
|
|
16687
|
+
error51(
|
|
16688
|
+
`${cp}.entries`,
|
|
16689
|
+
"playlist-entry-shape",
|
|
16690
|
+
`Flow ${flowId}: ${cp}.entries must be an array of playlist entries \u2014 a junction case holds its own entries, not a bare view_id/flow_id`
|
|
16691
|
+
);
|
|
16692
|
+
} else {
|
|
16693
|
+
checkPlaylistShape(branch.entries, flowId, `${cp}.entries`, depth + 1);
|
|
16694
|
+
}
|
|
16695
|
+
});
|
|
16696
|
+
}
|
|
16697
|
+
});
|
|
16698
|
+
};
|
|
16699
|
+
nodes.forEach((node, i) => {
|
|
16700
|
+
const md = node.metadata;
|
|
16701
|
+
if (node.species === "flow" && md?.playlist?.entries) {
|
|
16702
|
+
checkPlaylistShape(md.playlist.entries, node.id, `nodes[${i}].metadata.playlist.entries`);
|
|
16703
|
+
}
|
|
16704
|
+
});
|
|
15988
16705
|
const collectPlaylistRefs = (entries, flowId, path, depth = 0) => {
|
|
15989
16706
|
if (depth > 50) {
|
|
15990
16707
|
error51(path, "playlist-depth", `Flow ${flowId}: playlist nesting too deep (possible cycle)`);
|
|
15991
16708
|
return [];
|
|
15992
16709
|
}
|
|
15993
16710
|
const refs = [];
|
|
16711
|
+
if (!Array.isArray(entries)) return refs;
|
|
15994
16712
|
for (const entry of entries) {
|
|
16713
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
15995
16714
|
if (entry.type === "view") {
|
|
15996
16715
|
if (!nodeIds.has(entry.view_id)) {
|
|
15997
16716
|
error51(path, "playlist-ref-exists", `Flow ${flowId}: playlist references non-existent view "${entry.view_id}"`);
|
|
@@ -16043,7 +16762,9 @@ function validateBundle(input) {
|
|
|
16043
16762
|
const nodeId = node.id;
|
|
16044
16763
|
const subFlows = [];
|
|
16045
16764
|
const findSubFlows = (entries) => {
|
|
16765
|
+
if (!Array.isArray(entries)) return;
|
|
16046
16766
|
for (const e of entries) {
|
|
16767
|
+
if (typeof e !== "object" || e === null) continue;
|
|
16047
16768
|
if (e.type === "flow") subFlows.push(e.flow_id);
|
|
16048
16769
|
if (e.type === "condition") {
|
|
16049
16770
|
if (e.if_true) findSubFlows(e.if_true);
|
|
@@ -16078,6 +16799,151 @@ function validateBundle(input) {
|
|
|
16078
16799
|
for (const id of flowGraph.keys()) {
|
|
16079
16800
|
dfs(id);
|
|
16080
16801
|
}
|
|
16802
|
+
const quality = bundle.quality;
|
|
16803
|
+
if (typeof quality === "object" && quality !== null && !Array.isArray(quality)) {
|
|
16804
|
+
const section = quality;
|
|
16805
|
+
const assessments = Array.isArray(section.assessments) ? section.assessments : [];
|
|
16806
|
+
const qualityFindings = Array.isArray(section.findings) ? section.findings : [];
|
|
16807
|
+
const profile = typeof section.profile === "object" && section.profile !== null ? section.profile : void 0;
|
|
16808
|
+
const declaredSurfaces = /* @__PURE__ */ new Set();
|
|
16809
|
+
if (Array.isArray(profile?.surfaces)) {
|
|
16810
|
+
profile.surfaces.forEach((entry, index) => {
|
|
16811
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return;
|
|
16812
|
+
const surface = entry;
|
|
16813
|
+
const surfaceId = typeof surface.id === "string" ? surface.id : void 0;
|
|
16814
|
+
if (surfaceId === void 0 || surfaceId.trim() === "") return;
|
|
16815
|
+
if (declaredSurfaces.has(surfaceId)) {
|
|
16816
|
+
warn(`quality.profile.surfaces[${index}].id`, "quality-duplicate-surface", `Duplicate surface id "${surfaceId}" \u2014 the first wins`);
|
|
16817
|
+
}
|
|
16818
|
+
declaredSurfaces.add(surfaceId);
|
|
16819
|
+
});
|
|
16820
|
+
}
|
|
16821
|
+
if (declaredSurfaces.size === 0 && (assessments.length > 0 || qualityFindings.length > 0)) {
|
|
16822
|
+
warn(
|
|
16823
|
+
"quality.profile.surfaces",
|
|
16824
|
+
"quality-no-surfaces",
|
|
16825
|
+
"Quality data is stored but the profile declares no surfaces \u2014 the matrix falls back to the surfaces the assessments name"
|
|
16826
|
+
);
|
|
16827
|
+
}
|
|
16828
|
+
const library = typeof section.library === "object" && section.library !== null ? section.library : void 0;
|
|
16829
|
+
const knownCriteria = /* @__PURE__ */ new Set();
|
|
16830
|
+
const retiredCriteria = /* @__PURE__ */ new Map();
|
|
16831
|
+
if (Array.isArray(library?.criteria)) {
|
|
16832
|
+
for (const entry of library.criteria) {
|
|
16833
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
16834
|
+
const criterion = entry;
|
|
16835
|
+
if (typeof criterion.id !== "string") continue;
|
|
16836
|
+
knownCriteria.add(criterion.id);
|
|
16837
|
+
if (typeof criterion.superseded_by === "string" && criterion.superseded_by !== "") {
|
|
16838
|
+
retiredCriteria.set(criterion.id, criterion.superseded_by);
|
|
16839
|
+
}
|
|
16840
|
+
}
|
|
16841
|
+
} else if (assessments.length > 0 || qualityFindings.length > 0) {
|
|
16842
|
+
warn(
|
|
16843
|
+
"quality.library",
|
|
16844
|
+
"quality-library-missing",
|
|
16845
|
+
"No criteria pack is embedded \u2014 criterion ids cannot be resolved to domains or weights; the matrix uses a synthesized library"
|
|
16846
|
+
);
|
|
16847
|
+
}
|
|
16848
|
+
if (typeof section.framework_version !== "string" || section.framework_version === "") {
|
|
16849
|
+
warn("quality.framework_version", "quality-framework-version-missing", "Quality section has no framework_version \u2014 scores are not comparable across audits without one");
|
|
16850
|
+
}
|
|
16851
|
+
const checkRowRefs = (row, path, label) => {
|
|
16852
|
+
const criterionId = typeof row.criterion_id === "string" ? row.criterion_id : void 0;
|
|
16853
|
+
if (criterionId !== void 0 && knownCriteria.size > 0 && !knownCriteria.has(criterionId)) {
|
|
16854
|
+
warn(`${path}.criterion_id`, "quality-unknown-criterion", `${label}: criterion "${criterionId}" is not in the pinned library`);
|
|
16855
|
+
}
|
|
16856
|
+
const supersededBy = criterionId !== void 0 ? retiredCriteria.get(criterionId) : void 0;
|
|
16857
|
+
if (supersededBy !== void 0) {
|
|
16858
|
+
warn(`${path}.criterion_id`, "quality-retired-criterion", `${label}: criterion "${criterionId}" is retired \u2014 superseded by "${supersededBy}"`);
|
|
16859
|
+
}
|
|
16860
|
+
const surface = typeof row.surface === "string" ? row.surface : void 0;
|
|
16861
|
+
if (surface !== void 0 && surface !== CROSS_SURFACE_ID && declaredSurfaces.size > 0 && !declaredSurfaces.has(surface)) {
|
|
16862
|
+
warn(`${path}.surface`, "quality-unknown-surface", `${label}: surface "${surface}" is not declared in the profile`);
|
|
16863
|
+
}
|
|
16864
|
+
};
|
|
16865
|
+
const seenCells = /* @__PURE__ */ new Set();
|
|
16866
|
+
assessments.forEach((entry, index) => {
|
|
16867
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return;
|
|
16868
|
+
const assessment = entry;
|
|
16869
|
+
const path = `quality.assessments[${index}]`;
|
|
16870
|
+
const label = `Assessment ${index}`;
|
|
16871
|
+
checkRowRefs(assessment, path, label);
|
|
16872
|
+
const level = assessment.level;
|
|
16873
|
+
if (typeof level !== "number" || !Number.isInteger(level) || level < 0 || level > 4) {
|
|
16874
|
+
warn(`${path}.level`, "quality-level-range", `${label}: level must be an integer 0-4 (N/A is the absence of the row, not a level)`);
|
|
16875
|
+
}
|
|
16876
|
+
if (assessment.surface === CROSS_SURFACE_ID) {
|
|
16877
|
+
warn(`${path}.surface`, "quality-cross-surface-assessment", `${label}: "${CROSS_SURFACE_ID}" is a findings-only lens \u2014 it carries no matrix column, so this score would render nowhere`);
|
|
16878
|
+
}
|
|
16879
|
+
if (typeof assessment.evidence !== "string" || assessment.evidence.trim() === "") {
|
|
16880
|
+
warn(`${path}.evidence`, "quality-assessment-no-evidence", `${label}: scored with no evidence \u2014 a score without a citation is an opinion, not an assessment`);
|
|
16881
|
+
}
|
|
16882
|
+
const criterionId = typeof assessment.criterion_id === "string" ? assessment.criterion_id : void 0;
|
|
16883
|
+
const surface = typeof assessment.surface === "string" ? assessment.surface : void 0;
|
|
16884
|
+
if (criterionId !== void 0 && surface !== void 0) {
|
|
16885
|
+
const cell = `${criterionId}\0${surface}`;
|
|
16886
|
+
if (seenCells.has(cell)) {
|
|
16887
|
+
warn(`${path}`, "quality-duplicate-assessment", `${label}: a second score for (${criterionId} x ${surface}) \u2014 the section stores latest-per-cell, so this cell is ambiguous`);
|
|
16888
|
+
}
|
|
16889
|
+
seenCells.add(cell);
|
|
16890
|
+
}
|
|
16891
|
+
});
|
|
16892
|
+
const seenFindingIds = /* @__PURE__ */ new Set();
|
|
16893
|
+
qualityFindings.forEach((entry, index) => {
|
|
16894
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return;
|
|
16895
|
+
const finding = entry;
|
|
16896
|
+
const path = `quality.findings[${index}]`;
|
|
16897
|
+
const label = `Finding ${index}`;
|
|
16898
|
+
checkRowRefs(finding, path, label);
|
|
16899
|
+
const findingId = typeof finding.id === "string" ? finding.id : void 0;
|
|
16900
|
+
if (findingId !== void 0) {
|
|
16901
|
+
if (seenFindingIds.has(findingId)) {
|
|
16902
|
+
warn(`${path}.id`, "quality-duplicate-finding-id", `Duplicate finding id "${findingId}"`);
|
|
16903
|
+
}
|
|
16904
|
+
seenFindingIds.add(findingId);
|
|
16905
|
+
}
|
|
16906
|
+
for (const field of ["impact", "likelihood"]) {
|
|
16907
|
+
const value = finding[field];
|
|
16908
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 5) {
|
|
16909
|
+
warn(`${path}.${field}`, "quality-risk-range", `${label}: ${field} must be an integer 1-5 \u2014 severity is derived from impact x likelihood`);
|
|
16910
|
+
}
|
|
16911
|
+
}
|
|
16912
|
+
for (const derived of ["severity", "priority"]) {
|
|
16913
|
+
if (derived in finding) {
|
|
16914
|
+
warn(`${path}.${derived}`, "quality-derived-field-stored", `${label}: ${derived} is derived from impact, likelihood and cost \u2014 storing it lets it drift from the numbers behind it`);
|
|
16915
|
+
}
|
|
16916
|
+
}
|
|
16917
|
+
if (finding.status === "accepted-risk" && (typeof finding.detail !== "string" || finding.detail.trim() === "")) {
|
|
16918
|
+
warn(`${path}.detail`, "quality-accepted-risk-no-note", `${label}: accepted-risk with no note \u2014 an accepted risk is a decision and reads like one`);
|
|
16919
|
+
}
|
|
16920
|
+
});
|
|
16921
|
+
const openedInJournal = /* @__PURE__ */ new Set();
|
|
16922
|
+
const journalEvents = Array.isArray(bundle.journal) ? bundle.journal : [];
|
|
16923
|
+
journalEvents.forEach((entry) => {
|
|
16924
|
+
if (typeof entry !== "object" || entry === null) return;
|
|
16925
|
+
const event = entry;
|
|
16926
|
+
if (event.type === "quality.finding.opened" && typeof event.finding_id === "string") openedInJournal.add(event.finding_id);
|
|
16927
|
+
});
|
|
16928
|
+
journalEvents.forEach((entry, index) => {
|
|
16929
|
+
if (typeof entry !== "object" || entry === null) return;
|
|
16930
|
+
const event = entry;
|
|
16931
|
+
const type = typeof event.type === "string" ? event.type : "";
|
|
16932
|
+
if (!type.startsWith("quality.")) return;
|
|
16933
|
+
if (typeof event.actor !== "string" || event.actor.trim() === "") {
|
|
16934
|
+
warn(`journal[${index}].actor`, "quality-event-no-actor", `Journal event ${index}: ${type} has no actor \u2014 human, agent and CI scores become indistinguishable`);
|
|
16935
|
+
}
|
|
16936
|
+
if (type === "quality.finding.resolved" && typeof event.finding_id === "string") {
|
|
16937
|
+
if (!openedInJournal.has(event.finding_id) && !seenFindingIds.has(event.finding_id)) {
|
|
16938
|
+
warn(
|
|
16939
|
+
`journal[${index}].finding_id`,
|
|
16940
|
+
"quality-resolved-never-opened",
|
|
16941
|
+
`Journal event ${index}: resolves finding "${event.finding_id}", which no quality.finding.opened event or stored finding ever declared`
|
|
16942
|
+
);
|
|
16943
|
+
}
|
|
16944
|
+
}
|
|
16945
|
+
});
|
|
16946
|
+
}
|
|
16081
16947
|
for (const finding of crossCheckJournal(bundle)) findings.push(finding);
|
|
16082
16948
|
return result();
|
|
16083
16949
|
}
|
|
@@ -16240,6 +17106,9 @@ function eventAffectsPlatform(ev, platform, nodesById) {
|
|
|
16240
17106
|
const edge = ev;
|
|
16241
17107
|
return onPlatform(edge.source_id) || onPlatform(edge.target_id);
|
|
16242
17108
|
}
|
|
17109
|
+
if (ev.type === "deliverable.shipped" && Array.isArray(ev.node_ids)) {
|
|
17110
|
+
return ev.node_ids.some(onPlatform);
|
|
17111
|
+
}
|
|
16243
17112
|
return false;
|
|
16244
17113
|
}
|
|
16245
17114
|
function computeChangelog(events, toVersion, options = {}) {
|
|
@@ -16253,7 +17122,7 @@ function computeChangelog(events, toVersion, options = {}) {
|
|
|
16253
17122
|
}
|
|
16254
17123
|
}
|
|
16255
17124
|
if (toIndex === -1) {
|
|
16256
|
-
return { fromVersion: null, toVersion, events: [] };
|
|
17125
|
+
return { fromVersion: null, toVersion, events: [], deliverables: [] };
|
|
16257
17126
|
}
|
|
16258
17127
|
const platform = asString(ordered[toIndex].platform);
|
|
16259
17128
|
let fromIndex = -1;
|
|
@@ -16282,7 +17151,8 @@ function computeChangelog(events, toVersion, options = {}) {
|
|
|
16282
17151
|
fromVersion: fromIndex >= 0 ? asString(ordered[fromIndex].version) ?? null : null,
|
|
16283
17152
|
toVersion,
|
|
16284
17153
|
...platform ? { platform } : {},
|
|
16285
|
-
events: slice
|
|
17154
|
+
events: slice,
|
|
17155
|
+
deliverables: computeDeliverables(ordered).filter((d) => d.releaseVersion === toVersion)
|
|
16286
17156
|
};
|
|
16287
17157
|
}
|
|
16288
17158
|
function deriveExistingNodeIds(orderedEvents) {
|
|
@@ -16311,6 +17181,61 @@ function computeBacklog(events, options = {}) {
|
|
|
16311
17181
|
items
|
|
16312
17182
|
};
|
|
16313
17183
|
}
|
|
17184
|
+
function computeDeliverables(events) {
|
|
17185
|
+
const ordered = orderEvents(events);
|
|
17186
|
+
const firstIndex = /* @__PURE__ */ new Map();
|
|
17187
|
+
const latest = /* @__PURE__ */ new Map();
|
|
17188
|
+
ordered.forEach((ev, i) => {
|
|
17189
|
+
if (ev.type !== "deliverable.shipped") return;
|
|
17190
|
+
const id = asString(ev.deliverable_id);
|
|
17191
|
+
if (id === void 0) return;
|
|
17192
|
+
if (!firstIndex.has(id)) firstIndex.set(id, i);
|
|
17193
|
+
latest.set(id, ev);
|
|
17194
|
+
});
|
|
17195
|
+
if (firstIndex.size === 0) return [];
|
|
17196
|
+
const markerLatest = /* @__PURE__ */ new Map();
|
|
17197
|
+
ordered.forEach((ev, i) => {
|
|
17198
|
+
if (ev.type !== "release.tagged") return;
|
|
17199
|
+
const version2 = asString(ev.version);
|
|
17200
|
+
if (version2 !== void 0) markerLatest.set(version2, i);
|
|
17201
|
+
});
|
|
17202
|
+
const windows = [];
|
|
17203
|
+
for (const [version2, toIndex] of markerLatest) {
|
|
17204
|
+
let fromIndex = -1;
|
|
17205
|
+
for (let i = toIndex - 1; i >= 0; i -= 1) {
|
|
17206
|
+
if (ordered[i].type === "release.tagged") {
|
|
17207
|
+
fromIndex = i;
|
|
17208
|
+
break;
|
|
17209
|
+
}
|
|
17210
|
+
}
|
|
17211
|
+
windows.push({ version: version2, from: fromIndex, to: toIndex });
|
|
17212
|
+
}
|
|
17213
|
+
const releaseOf = (index) => {
|
|
17214
|
+
for (const w of windows) {
|
|
17215
|
+
if (index > w.from && index < w.to) return w.version;
|
|
17216
|
+
}
|
|
17217
|
+
return null;
|
|
17218
|
+
};
|
|
17219
|
+
const out = [];
|
|
17220
|
+
for (const [id, anchorIndex] of firstIndex) {
|
|
17221
|
+
const ev = latest.get(id);
|
|
17222
|
+
if (ev === void 0) continue;
|
|
17223
|
+
const summary = asString(ev.summary);
|
|
17224
|
+
const url2 = asString(ev.url);
|
|
17225
|
+
const platform = asString(ev.platform);
|
|
17226
|
+
out.push({
|
|
17227
|
+
deliverable_id: id,
|
|
17228
|
+
title: asString(ev.title) ?? id,
|
|
17229
|
+
...summary !== void 0 ? { summary } : {},
|
|
17230
|
+
...url2 !== void 0 ? { url: url2 } : {},
|
|
17231
|
+
node_ids: Array.isArray(ev.node_ids) ? ev.node_ids.filter((n) => typeof n === "string") : [],
|
|
17232
|
+
...platform !== void 0 ? { platform } : {},
|
|
17233
|
+
ts: asString(ordered[anchorIndex].ts) ?? "",
|
|
17234
|
+
releaseVersion: releaseOf(anchorIndex)
|
|
17235
|
+
});
|
|
17236
|
+
}
|
|
17237
|
+
return out;
|
|
17238
|
+
}
|
|
16314
17239
|
|
|
16315
17240
|
// ../schema/src/emit.ts
|
|
16316
17241
|
var ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -16495,6 +17420,12 @@ function diffNodeUpdate(current, patch) {
|
|
|
16495
17420
|
for (const platform of changedMapKeys(prevMeta[key], nextMeta[key])) {
|
|
16496
17421
|
changedPaths.push(`metadata.${key}.${platform}`);
|
|
16497
17422
|
}
|
|
17423
|
+
} else if (key === "decision_status") {
|
|
17424
|
+
const from = prevMeta[key] ?? "proposed";
|
|
17425
|
+
const to = nextMeta[key] ?? "proposed";
|
|
17426
|
+
if (!valueEqual(from, to)) {
|
|
17427
|
+
events.push({ type: "decision.status_changed", payload: { node_id: nodeId, from, to } });
|
|
17428
|
+
}
|
|
16498
17429
|
} else if (!valueEqual(prevMeta[key], nextMeta[key])) {
|
|
16499
17430
|
changedPaths.push(`metadata.${key}`);
|
|
16500
17431
|
}
|
|
@@ -16683,23 +17614,979 @@ function applyOps(input, ops) {
|
|
|
16683
17614
|
return { nodes, edges, eventInputs, synthesizedEdges, cascadedEdgeIds };
|
|
16684
17615
|
}
|
|
16685
17616
|
|
|
16686
|
-
// src/
|
|
16687
|
-
|
|
16688
|
-
|
|
16689
|
-
|
|
16690
|
-
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
|
|
17617
|
+
// ../schema/src/quality-ops.ts
|
|
17618
|
+
function upsertAssessment(assessments, next) {
|
|
17619
|
+
const index = assessments.findIndex(
|
|
17620
|
+
(candidate) => candidate.criterion_id === next.criterion_id && candidate.surface === next.surface
|
|
17621
|
+
);
|
|
17622
|
+
if (index === -1) return { assessments: [...assessments, next] };
|
|
17623
|
+
const updated = [...assessments];
|
|
17624
|
+
const replaced = updated[index];
|
|
17625
|
+
updated[index] = next;
|
|
17626
|
+
return { assessments: updated, replaced };
|
|
17627
|
+
}
|
|
17628
|
+
function domainCodeOf(criterionId, library) {
|
|
17629
|
+
const criterion = (library?.criteria ?? []).find((candidate) => candidate.id === criterionId);
|
|
17630
|
+
if (typeof criterion?.domain === "string" && criterion.domain !== "") return criterion.domain;
|
|
17631
|
+
const dash = criterionId.indexOf("-");
|
|
17632
|
+
return dash > 0 ? criterionId.slice(0, dash) : criterionId;
|
|
17633
|
+
}
|
|
17634
|
+
function mintFindingId(auditId, criterionId, surface, taken, library) {
|
|
17635
|
+
const prefix = `F-${auditId}-${domainCodeOf(criterionId, library)}-${surface}-`;
|
|
17636
|
+
const used = new Set(taken);
|
|
17637
|
+
for (let n = 1; n < 1e3; n++) {
|
|
17638
|
+
const candidate = `${prefix}${String(n).padStart(2, "0")}`;
|
|
17639
|
+
if (!used.has(candidate)) return candidate;
|
|
17640
|
+
}
|
|
17641
|
+
throw new Error(`Kritik: exhausted finding ids for ${prefix}NN \u2014 999 findings on one cell is a data problem, not a numbering one`);
|
|
17642
|
+
}
|
|
17643
|
+
function upsertFinding(findings, next) {
|
|
17644
|
+
const index = findings.findIndex((candidate) => candidate.id === next.id);
|
|
17645
|
+
if (index === -1) return { findings: [...findings, next] };
|
|
17646
|
+
const updated = [...findings];
|
|
17647
|
+
const replaced = updated[index];
|
|
17648
|
+
updated[index] = next;
|
|
17649
|
+
return { findings: updated, replaced };
|
|
17650
|
+
}
|
|
17651
|
+
function patchFinding(findings, id, patch) {
|
|
17652
|
+
const index = findings.findIndex((candidate) => candidate.id === id);
|
|
17653
|
+
if (index === -1) return { findings: [...findings] };
|
|
17654
|
+
const updated = [...findings];
|
|
17655
|
+
const previous = updated[index];
|
|
17656
|
+
const finding = { ...previous, ...patch };
|
|
17657
|
+
updated[index] = finding;
|
|
17658
|
+
return { findings: updated, finding, previous };
|
|
17659
|
+
}
|
|
17660
|
+
function resolveFinding(findings, id, resolvedBy) {
|
|
17661
|
+
return patchFinding(findings, id, {
|
|
17662
|
+
status: "resolved",
|
|
17663
|
+
...resolvedBy !== void 0 ? { resolved_by: resolvedBy } : {}
|
|
17664
|
+
});
|
|
17665
|
+
}
|
|
17666
|
+
function acceptFinding(findings, id, note) {
|
|
17667
|
+
const existing = findings.find((candidate) => candidate.id === id);
|
|
17668
|
+
const detail = existing === void 0 ? note : `${existing.detail}
|
|
17669
|
+
|
|
17670
|
+
Accepted risk: ${note}`.trim();
|
|
17671
|
+
return patchFinding(findings, id, { status: "accepted-risk", detail });
|
|
17672
|
+
}
|
|
17673
|
+
function fillTemplate(text, values) {
|
|
17674
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => values[key] ?? whole);
|
|
17675
|
+
}
|
|
17676
|
+
function renderIssue(criterion, options) {
|
|
17677
|
+
const { surface, finding, library } = options;
|
|
17678
|
+
const anchors = criterion.level_anchors ?? {};
|
|
17679
|
+
const level = options.level === void 0 || options.level === "" ? "" : String(options.level);
|
|
17680
|
+
const observed = level === "" ? "{observed_level}" : level;
|
|
17681
|
+
const target = options.targetLevel !== void 0 && options.targetLevel !== "" ? String(options.targetLevel) : level === "" ? "{target_level}" : String(Math.min(Number(level) + 1, 4));
|
|
17682
|
+
const values = {
|
|
17683
|
+
surface,
|
|
17684
|
+
observed_level: observed,
|
|
17685
|
+
target_level: target,
|
|
17686
|
+
observed_level_name: anchors[`l${observed}`] ?? "{observed_level_name}",
|
|
17687
|
+
target_level_name: anchors[`l${target}`] ?? "{target_level_name}",
|
|
17688
|
+
target_anchor_text: anchors[`l${target}`] ?? "{target_anchor_text}",
|
|
17689
|
+
impact: String(finding?.impact ?? criterion.default_impact ?? 3)
|
|
17690
|
+
};
|
|
17691
|
+
if (finding !== void 0) {
|
|
17692
|
+
values.likelihood = String(finding.likelihood);
|
|
17693
|
+
values.evidence_bullets_with_file_paths = finding.evidence;
|
|
17694
|
+
values.risk_narrative = finding.detail;
|
|
17695
|
+
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
17696
|
+
values.remediation_step_1 = finding.remediation;
|
|
17697
|
+
}
|
|
17698
|
+
}
|
|
17699
|
+
const issue2 = criterion.issue ?? {};
|
|
17700
|
+
const labels = [.../* @__PURE__ */ new Set([...issue2.labels ?? ["quality"], surface])];
|
|
17701
|
+
const body = fillTemplate(issue2.body_skeleton ?? "", values);
|
|
16694
17702
|
return {
|
|
16695
|
-
|
|
16696
|
-
|
|
16697
|
-
|
|
17703
|
+
title: fillTemplate(issue2.title_template ?? `[Quality] ${criterion.id} on {surface}`, values),
|
|
17704
|
+
labels,
|
|
17705
|
+
body: finding === void 0 ? body : `${body}
|
|
17706
|
+
${findingFooter(finding, library)}`,
|
|
17707
|
+
...typeof criterion.remediation === "string" && criterion.remediation !== "" ? { remediation: criterion.remediation } : {}
|
|
17708
|
+
};
|
|
17709
|
+
}
|
|
17710
|
+
function findingFooter(finding, library) {
|
|
17711
|
+
const lines = [
|
|
17712
|
+
``,
|
|
17713
|
+
`---`,
|
|
17714
|
+
`<sub>Kritik finding \`${finding.id}\` \u2014 **${severityOf(finding, library)} / ${priorityOf(finding, library)}** (impact ${finding.impact} x likelihood ${finding.likelihood}, cost ${finding.cost})</sub>`,
|
|
17715
|
+
``,
|
|
17716
|
+
`**Evidence**`,
|
|
17717
|
+
finding.evidence
|
|
17718
|
+
];
|
|
17719
|
+
if (typeof finding.remediation === "string" && finding.remediation !== "") {
|
|
17720
|
+
lines.push(``, `**Remediation**`, finding.remediation);
|
|
17721
|
+
}
|
|
17722
|
+
return lines.join("\n");
|
|
17723
|
+
}
|
|
17724
|
+
function signalRunSheet(library, surfaces, filter = {}) {
|
|
17725
|
+
const surfaceIds = surfaces.map((surface) => surface.id).filter((id) => id !== CROSS_SURFACE_ID);
|
|
17726
|
+
const rows = [];
|
|
17727
|
+
for (const criterion of library.criteria ?? []) {
|
|
17728
|
+
if (criterion.superseded_by !== void 0) continue;
|
|
17729
|
+
if (filter.criterion !== void 0 && criterion.id !== filter.criterion) continue;
|
|
17730
|
+
if (filter.domain !== void 0 && criterion.domain !== filter.domain) continue;
|
|
17731
|
+
const signals = criterion.signals ?? [];
|
|
17732
|
+
if (signals.length === 0) continue;
|
|
17733
|
+
const appliesTo = criterion.applies_to;
|
|
17734
|
+
for (const surfaceId of surfaceIds) {
|
|
17735
|
+
if (Array.isArray(appliesTo) && !appliesTo.includes(surfaceId)) continue;
|
|
17736
|
+
if (filter.surface !== void 0 && surfaceId !== filter.surface) continue;
|
|
17737
|
+
signals.forEach((signal, index) => {
|
|
17738
|
+
rows.push({ criterion_id: criterion.id, surface: surfaceId, index, signal });
|
|
17739
|
+
});
|
|
17740
|
+
}
|
|
17741
|
+
}
|
|
17742
|
+
return rows;
|
|
17743
|
+
}
|
|
17744
|
+
function auditCompletedInput(matrix, meta3) {
|
|
17745
|
+
const scores = {};
|
|
17746
|
+
for (const surface of matrix.surfaces) {
|
|
17747
|
+
const bySurface = {};
|
|
17748
|
+
for (const domain2 of matrix.domains) {
|
|
17749
|
+
const cell = matrix.matrix[domain2]?.[surface];
|
|
17750
|
+
if (cell) bySurface[domain2] = cell.score;
|
|
17751
|
+
}
|
|
17752
|
+
scores[surface] = bySurface;
|
|
17753
|
+
}
|
|
17754
|
+
return {
|
|
17755
|
+
type: "quality.audit.completed",
|
|
17756
|
+
payload: {
|
|
17757
|
+
audit_id: meta3.audit_id,
|
|
17758
|
+
framework_version: meta3.framework_version,
|
|
17759
|
+
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
17760
|
+
scores,
|
|
17761
|
+
counts: matrix.finding_counts
|
|
17762
|
+
}
|
|
17763
|
+
};
|
|
17764
|
+
}
|
|
17765
|
+
function findingOpenedInput(finding, library) {
|
|
17766
|
+
return {
|
|
17767
|
+
type: "quality.finding.opened",
|
|
17768
|
+
payload: {
|
|
17769
|
+
finding_id: finding.id,
|
|
17770
|
+
criterion_id: finding.criterion_id,
|
|
17771
|
+
surface: finding.surface,
|
|
17772
|
+
severity: severityOf(finding, library),
|
|
17773
|
+
priority: priorityOf(finding, library),
|
|
17774
|
+
title: finding.title,
|
|
17775
|
+
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {},
|
|
17776
|
+
...finding.issue_url !== void 0 ? { issue_url: finding.issue_url } : {}
|
|
17777
|
+
}
|
|
17778
|
+
};
|
|
17779
|
+
}
|
|
17780
|
+
function findingResolvedInput(finding, resolvedBy) {
|
|
17781
|
+
return {
|
|
17782
|
+
type: "quality.finding.resolved",
|
|
17783
|
+
payload: {
|
|
17784
|
+
finding_id: finding.id,
|
|
17785
|
+
...resolvedBy !== void 0 ? { resolved_by: resolvedBy } : {},
|
|
17786
|
+
...finding.node_ids !== void 0 ? { node_ids: finding.node_ids } : {}
|
|
17787
|
+
}
|
|
17788
|
+
};
|
|
17789
|
+
}
|
|
17790
|
+
function signalTrippedInput(trip) {
|
|
17791
|
+
return {
|
|
17792
|
+
type: "quality.signal.tripped",
|
|
17793
|
+
payload: {
|
|
17794
|
+
criterion_id: trip.criterion_id,
|
|
17795
|
+
surface: trip.surface,
|
|
17796
|
+
signal: trip.signal,
|
|
17797
|
+
...trip.detail !== void 0 ? { detail: trip.detail } : {}
|
|
17798
|
+
}
|
|
17799
|
+
};
|
|
17800
|
+
}
|
|
17801
|
+
|
|
17802
|
+
// ../schema/src/cli/kritik-audit.ts
|
|
17803
|
+
import { existsSync as existsSync2, readdirSync, statSync } from "node:fs";
|
|
17804
|
+
import { join as join2 } from "node:path";
|
|
17805
|
+
|
|
17806
|
+
// ../schema/src/cli/kritik-paths.ts
|
|
17807
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17808
|
+
import { dirname, join, resolve } from "node:path";
|
|
17809
|
+
var QUALITY_DIR = "docs/quality";
|
|
17810
|
+
var PROFILE_FILE = "profile.json";
|
|
17811
|
+
var OVERLAY_FILE = "criteria.custom.json";
|
|
17812
|
+
var AUDITS_DIR = "audits";
|
|
17813
|
+
var PACK_FILE = "library.json";
|
|
17814
|
+
function readJson(path) {
|
|
17815
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
17816
|
+
}
|
|
17817
|
+
function writeJson(path, value) {
|
|
17818
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
17819
|
+
writeFileSync(path, JSON.stringify(value, null, 2) + "\n");
|
|
17820
|
+
}
|
|
17821
|
+
var profilePath = (root) => join(root, QUALITY_DIR, PROFILE_FILE);
|
|
17822
|
+
var overlayPath = (root) => join(root, QUALITY_DIR, OVERLAY_FILE);
|
|
17823
|
+
var auditDir = (root, auditId) => join(root, QUALITY_DIR, AUDITS_DIR, auditId);
|
|
17824
|
+
function loadProfile(root) {
|
|
17825
|
+
const path = profilePath(root);
|
|
17826
|
+
return existsSync(path) ? readJson(path) : null;
|
|
17827
|
+
}
|
|
17828
|
+
function loadOverlay(root) {
|
|
17829
|
+
const path = overlayPath(root);
|
|
17830
|
+
return existsSync(path) ? readJson(path) : null;
|
|
17831
|
+
}
|
|
17832
|
+
|
|
17833
|
+
// ../schema/src/cli/kritik-audit.ts
|
|
17834
|
+
var SCORES_FILE = "scores.json";
|
|
17835
|
+
var FINDINGS_FILE = "findings.json";
|
|
17836
|
+
var MATRIX_FILE = "matrix.json";
|
|
17837
|
+
var scoresPath = (root, auditId) => join2(auditDir(root, auditId), SCORES_FILE);
|
|
17838
|
+
var findingsPath = (root, auditId) => join2(auditDir(root, auditId), FINDINGS_FILE);
|
|
17839
|
+
var matrixPath = (root, auditId) => join2(auditDir(root, auditId), MATRIX_FILE);
|
|
17840
|
+
function listAuditIds(root) {
|
|
17841
|
+
const dir = join2(root, QUALITY_DIR, AUDITS_DIR);
|
|
17842
|
+
if (!existsSync2(dir)) return [];
|
|
17843
|
+
return readdirSync(dir).filter((name) => statSync(join2(dir, name)).isDirectory()).sort();
|
|
17844
|
+
}
|
|
17845
|
+
function newestAuditId(root) {
|
|
17846
|
+
const dir = join2(root, QUALITY_DIR, AUDITS_DIR);
|
|
17847
|
+
if (!existsSync2(dir)) throw new Error(`no audits directory at ${dir}`);
|
|
17848
|
+
const ids = listAuditIds(root);
|
|
17849
|
+
if (ids.length === 0) throw new Error(`no audits found under ${dir}`);
|
|
17850
|
+
return ids[ids.length - 1];
|
|
17851
|
+
}
|
|
17852
|
+
function loadScores(root, auditId) {
|
|
17853
|
+
const path = scoresPath(root, auditId);
|
|
17854
|
+
if (!existsSync2(path)) throw new Error(`no ${SCORES_FILE} at ${path}`);
|
|
17855
|
+
const file2 = readJson(path);
|
|
17856
|
+
return { ...file2, assessments: Array.isArray(file2.assessments) ? file2.assessments : [] };
|
|
17857
|
+
}
|
|
17858
|
+
function loadScoresOrEmpty(root, auditId) {
|
|
17859
|
+
return existsSync2(scoresPath(root, auditId)) ? loadScores(root, auditId) : { audit_id: auditId, assessments: [] };
|
|
17860
|
+
}
|
|
17861
|
+
function loadFindings(root, auditId) {
|
|
17862
|
+
const path = findingsPath(root, auditId);
|
|
17863
|
+
if (!existsSync2(path)) return { audit_id: auditId, findings: [] };
|
|
17864
|
+
const file2 = readJson(path);
|
|
17865
|
+
return { ...file2, findings: Array.isArray(file2.findings) ? file2.findings : [] };
|
|
17866
|
+
}
|
|
17867
|
+
function saveScores(root, auditId, file2) {
|
|
17868
|
+
writeJson(scoresPath(root, auditId), file2);
|
|
17869
|
+
}
|
|
17870
|
+
function saveFindings(root, auditId, file2) {
|
|
17871
|
+
writeJson(findingsPath(root, auditId), file2);
|
|
17872
|
+
}
|
|
17873
|
+
function requireProfile(root) {
|
|
17874
|
+
const profile = loadProfile(root);
|
|
17875
|
+
if (!profile) {
|
|
17876
|
+
throw new Error(
|
|
17877
|
+
`no profile at ${join2(root, QUALITY_DIR, "profile.json")} \u2014 pick this project's surfaces first (\`arkaik kritik profile\`, or the plugin's init-profile.js).`
|
|
17878
|
+
);
|
|
17879
|
+
}
|
|
17880
|
+
return profile;
|
|
17881
|
+
}
|
|
17882
|
+
function loadQualitySection(root, auditId, library, scores = loadScores(root, auditId)) {
|
|
17883
|
+
const findings = loadFindings(root, auditId);
|
|
17884
|
+
return {
|
|
17885
|
+
framework_version: scores.framework_version ?? library.version,
|
|
17886
|
+
profile: requireProfile(root),
|
|
17887
|
+
assessments: scores.assessments,
|
|
17888
|
+
findings: findings.findings
|
|
17889
|
+
};
|
|
17890
|
+
}
|
|
17891
|
+
function computeAuditMatrix(root, auditId, library) {
|
|
17892
|
+
const scores = loadScores(root, auditId);
|
|
17893
|
+
const section = loadQualitySection(root, auditId, library, scores);
|
|
17894
|
+
const matrix = deriveQualityMatrix({ quality: section }, library);
|
|
17895
|
+
const file2 = {
|
|
17896
|
+
audit_id: auditId,
|
|
17897
|
+
commit: scores.commit,
|
|
17898
|
+
framework_version: section.framework_version,
|
|
17899
|
+
matrix: matrix.matrix,
|
|
17900
|
+
overall: matrix.overall,
|
|
17901
|
+
finding_counts: matrix.finding_counts
|
|
17902
|
+
};
|
|
17903
|
+
writeJson(matrixPath(root, auditId), file2);
|
|
17904
|
+
return { section, matrix, file: file2 };
|
|
17905
|
+
}
|
|
17906
|
+
function locateFinding(root, id) {
|
|
17907
|
+
for (const auditId of [...listAuditIds(root)].reverse()) {
|
|
17908
|
+
const file2 = loadFindings(root, auditId);
|
|
17909
|
+
const finding = file2.findings.find((candidate) => candidate.id === id);
|
|
17910
|
+
if (finding) return { auditId, file: file2, finding };
|
|
17911
|
+
}
|
|
17912
|
+
return void 0;
|
|
17913
|
+
}
|
|
17914
|
+
|
|
17915
|
+
// ../cli/src/lib/bundle-io.ts
|
|
17916
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
17917
|
+
function readBundle(filePath) {
|
|
17918
|
+
if (!existsSync3(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
17919
|
+
let parsed;
|
|
17920
|
+
try {
|
|
17921
|
+
parsed = JSON.parse(readFileSync2(filePath, "utf8"));
|
|
17922
|
+
} catch (e) {
|
|
17923
|
+
throw new Error(`Cannot parse JSON \u2014 ${e.message}`);
|
|
17924
|
+
}
|
|
17925
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
17926
|
+
throw new Error("Bundle must be a JSON object.");
|
|
17927
|
+
}
|
|
17928
|
+
const record2 = parsed;
|
|
17929
|
+
if (!Array.isArray(record2.nodes)) return record2;
|
|
17930
|
+
return migrateStatusVocabulary(record2);
|
|
17931
|
+
}
|
|
17932
|
+
|
|
17933
|
+
// ../cli/src/lib/journal-io.ts
|
|
17934
|
+
import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
17935
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
17936
|
+
var JOURNAL_SIDECAR = "journal.jsonl";
|
|
17937
|
+
function journalPathFor(bundlePath) {
|
|
17938
|
+
return join3(dirname2(bundlePath), JOURNAL_SIDECAR);
|
|
17939
|
+
}
|
|
17940
|
+
function archivePathsFor(journalPath) {
|
|
17941
|
+
const dir = join3(dirname2(journalPath), "journal");
|
|
17942
|
+
if (!existsSync4(dir)) return [];
|
|
17943
|
+
return readdirSync2(dir).filter((name) => name.startsWith("archive-") && name.endsWith(".jsonl")).sort().map((name) => join3(dir, name));
|
|
17944
|
+
}
|
|
17945
|
+
function readJournalEvents(journalPath) {
|
|
17946
|
+
if (!existsSync4(journalPath)) return [];
|
|
17947
|
+
return parseJournalLines(readFileSync3(journalPath, "utf8")).events;
|
|
17948
|
+
}
|
|
17949
|
+
function readFullJournalEvents(journalPath) {
|
|
17950
|
+
const events = readJournalEvents(journalPath);
|
|
17951
|
+
for (const archivePath of archivePathsFor(journalPath)) {
|
|
17952
|
+
events.push(...readJournalEvents(archivePath));
|
|
17953
|
+
}
|
|
17954
|
+
return events;
|
|
17955
|
+
}
|
|
17956
|
+
function toLine(event) {
|
|
17957
|
+
return JSON.stringify(event) + "\n";
|
|
17958
|
+
}
|
|
17959
|
+
function appendJournalEvent(journalPath, event) {
|
|
17960
|
+
const line = toLine(event);
|
|
17961
|
+
if (!existsSync4(journalPath)) {
|
|
17962
|
+
mkdirSync2(dirname2(journalPath), { recursive: true });
|
|
17963
|
+
writeFileSync2(journalPath, line);
|
|
17964
|
+
return;
|
|
17965
|
+
}
|
|
17966
|
+
const existing = readFileSync3(journalPath, "utf8");
|
|
17967
|
+
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
17968
|
+
appendFileSync(journalPath, prefix + line);
|
|
17969
|
+
}
|
|
17970
|
+
|
|
17971
|
+
// ../cli/src/lib/kritik-io.ts
|
|
17972
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
17973
|
+
import { dirname as dirname3, join as join4 } from "node:path";
|
|
17974
|
+
import { fileURLToPath } from "node:url";
|
|
17975
|
+
var DEFAULT_BUNDLE_PATH = join4("docs", "arkaik", "bundle.json");
|
|
17976
|
+
var VENDORED_PACK = join4(QUALITY_DIR, PACK_FILE);
|
|
17977
|
+
var BUNDLED_PACK = join4(dirname3(fileURLToPath(import.meta.url)), "assets", "kritik", "library.json");
|
|
17978
|
+
function resolvePack(root) {
|
|
17979
|
+
const vendored = join4(root, VENDORED_PACK);
|
|
17980
|
+
if (existsSync5(vendored)) return { library: readJson(vendored), path: vendored, vendored: true };
|
|
17981
|
+
if (!existsSync5(BUNDLED_PACK)) {
|
|
17982
|
+
throw new Error(
|
|
17983
|
+
`no criteria pack found. Looked in:
|
|
17984
|
+
${vendored}
|
|
17985
|
+
${BUNDLED_PACK}
|
|
17986
|
+
The second is shipped with this CLI, so its absence means a broken install \u2014 reinstall \`arkaik\`.`
|
|
17987
|
+
);
|
|
17988
|
+
}
|
|
17989
|
+
return { library: readJson(BUNDLED_PACK), path: BUNDLED_PACK, vendored: false };
|
|
17990
|
+
}
|
|
17991
|
+
function loadKritikLibrary(root) {
|
|
17992
|
+
const pack = resolvePack(root);
|
|
17993
|
+
return { library: mergeKritikLibrary(pack.library, loadOverlay(root)), pack };
|
|
17994
|
+
}
|
|
17995
|
+
function resolveJournal(root, bundlePath) {
|
|
17996
|
+
const resolved = bundlePath ?? join4(root, DEFAULT_BUNDLE_PATH);
|
|
17997
|
+
return { bundlePath: resolved, journalPath: journalPathFor(resolved), present: existsSync5(resolved) };
|
|
17998
|
+
}
|
|
17999
|
+
|
|
18000
|
+
// ../cli/src/lib/bundle-validate.ts
|
|
18001
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4 } from "node:fs";
|
|
18002
|
+
import { basename } from "node:path";
|
|
18003
|
+
function validateBundleAt(filePath) {
|
|
18004
|
+
const bundle = readBundle(filePath);
|
|
18005
|
+
const loose = bundle;
|
|
18006
|
+
if (!loose.project || !loose.nodes || !loose.edges) {
|
|
18007
|
+
throw new Error("Missing top-level keys (project, nodes, edges).");
|
|
18008
|
+
}
|
|
18009
|
+
let sidecarFindings = [];
|
|
18010
|
+
let sidecarLoaded = false;
|
|
18011
|
+
const archiveFindings = [];
|
|
18012
|
+
const archivesLoaded = [];
|
|
18013
|
+
if (loose.journal === void 0) {
|
|
18014
|
+
const sidecarPath = journalPathFor(filePath);
|
|
18015
|
+
const folded = [];
|
|
18016
|
+
if (existsSync6(sidecarPath)) {
|
|
18017
|
+
const { events, findings } = parseJournalLines(readFileSync4(sidecarPath, "utf8"));
|
|
18018
|
+
sidecarFindings = findings;
|
|
18019
|
+
sidecarLoaded = true;
|
|
18020
|
+
folded.push(...events);
|
|
18021
|
+
}
|
|
18022
|
+
for (const archivePath of archivePathsFor(sidecarPath)) {
|
|
18023
|
+
const { events, findings } = parseJournalLines(readFileSync4(archivePath, "utf8"));
|
|
18024
|
+
const file2 = basename(archivePath);
|
|
18025
|
+
for (const finding of findings) archiveFindings.push({ ...finding, file: file2 });
|
|
18026
|
+
archivesLoaded.push(file2);
|
|
18027
|
+
folded.push(...events);
|
|
18028
|
+
}
|
|
18029
|
+
if (sidecarLoaded || archivesLoaded.length > 0) loose.journal = folded;
|
|
18030
|
+
}
|
|
18031
|
+
const nodes = Array.isArray(loose.nodes) ? loose.nodes : [];
|
|
18032
|
+
const edges = Array.isArray(loose.edges) ? loose.edges : [];
|
|
18033
|
+
const journal = Array.isArray(loose.journal) ? loose.journal : [];
|
|
18034
|
+
const result = validateBundle(bundle);
|
|
18035
|
+
const valid = sidecarFindings.length === 0 && archiveFindings.length === 0 && result.errors.length === 0;
|
|
18036
|
+
return {
|
|
18037
|
+
bundle,
|
|
18038
|
+
nodes,
|
|
18039
|
+
edges,
|
|
18040
|
+
journal,
|
|
18041
|
+
sidecarLoaded,
|
|
18042
|
+
sidecarFindings,
|
|
18043
|
+
archivesLoaded,
|
|
18044
|
+
archiveFindings,
|
|
18045
|
+
result,
|
|
18046
|
+
valid
|
|
18047
|
+
};
|
|
18048
|
+
}
|
|
18049
|
+
|
|
18050
|
+
// src/kritik-tools.ts
|
|
18051
|
+
function rootOf(ctx) {
|
|
18052
|
+
if (ctx.qualityRoot === void 0) {
|
|
18053
|
+
throw new ToolError(
|
|
18054
|
+
`Kritik runs against a repository's docs/quality/ files, and this session is connected to a hosted project (${ctx.store.describe()}). Point the server at the checkout instead \u2014 \`arkaik-mcp --bundle <path>\` \u2014 and run the audit where the code is.`
|
|
18055
|
+
);
|
|
18056
|
+
}
|
|
18057
|
+
return ctx.qualityRoot;
|
|
18058
|
+
}
|
|
18059
|
+
function libraryOf(root) {
|
|
18060
|
+
try {
|
|
18061
|
+
return loadKritikLibrary(root).library;
|
|
18062
|
+
} catch (error51) {
|
|
18063
|
+
throw new ToolError(error51.message);
|
|
18064
|
+
}
|
|
18065
|
+
}
|
|
18066
|
+
function profileOf(root) {
|
|
18067
|
+
try {
|
|
18068
|
+
return requireProfile(root);
|
|
18069
|
+
} catch (error51) {
|
|
18070
|
+
throw new ToolError(error51.message);
|
|
18071
|
+
}
|
|
18072
|
+
}
|
|
18073
|
+
function criterionOf(library, criterionId) {
|
|
18074
|
+
const criterion = (library.criteria ?? []).find((candidate) => candidate.id === criterionId);
|
|
18075
|
+
if (!criterion) {
|
|
18076
|
+
const domain2 = criterionId.split("-")[0];
|
|
18077
|
+
const siblings = (library.criteria ?? []).filter((c) => c.domain === domain2).map((c) => c.id);
|
|
18078
|
+
throw new ToolError(
|
|
18079
|
+
`No criterion "${criterionId}" in the pack or this project's overlay.` + (siblings.length > 0 ? ` Criteria in ${domain2}: ${siblings.join(", ")}.` : ` Domains: ${(library.domains ?? []).map((d) => d.code).join(", ")}.`)
|
|
18080
|
+
);
|
|
18081
|
+
}
|
|
18082
|
+
if (typeof criterion.superseded_by === "string") {
|
|
18083
|
+
throw new ToolError(
|
|
18084
|
+
`Criterion "${criterionId}" is retired \u2014 superseded by "${criterion.superseded_by}". Score that one instead; the old id is kept only so past audits still mean what they meant.`
|
|
18085
|
+
);
|
|
18086
|
+
}
|
|
18087
|
+
return criterion;
|
|
18088
|
+
}
|
|
18089
|
+
function surfaceOf(profile, surface, allowCrossSurface = false) {
|
|
18090
|
+
if (surface === CROSS_SURFACE_ID) {
|
|
18091
|
+
if (allowCrossSurface) return surface;
|
|
18092
|
+
throw new ToolError(
|
|
18093
|
+
`"${CROSS_SURFACE_ID}" is a findings-only lens \u2014 it carries no matrix column, so a score there would render nowhere.`
|
|
18094
|
+
);
|
|
18095
|
+
}
|
|
18096
|
+
const declared2 = (profile.surfaces ?? []).map((candidate) => candidate.id);
|
|
18097
|
+
if (!declared2.includes(surface)) {
|
|
18098
|
+
throw new ToolError(`Surface "${surface}" is not declared in this project's profile. Declared: ${declared2.join(", ")}.`);
|
|
18099
|
+
}
|
|
18100
|
+
return surface;
|
|
18101
|
+
}
|
|
18102
|
+
function requireString(args, key) {
|
|
18103
|
+
const value = args[key];
|
|
18104
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
18105
|
+
throw new ToolError(`\`${key}\` is required and must be a non-empty string.`);
|
|
18106
|
+
}
|
|
18107
|
+
return value;
|
|
18108
|
+
}
|
|
18109
|
+
function requireInt(args, key, min, max) {
|
|
18110
|
+
const value = args[key];
|
|
18111
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
18112
|
+
throw new ToolError(`\`${key}\` is required and must be an integer ${min}-${max}.`);
|
|
18113
|
+
}
|
|
18114
|
+
return value;
|
|
18115
|
+
}
|
|
18116
|
+
function currentAuditId() {
|
|
18117
|
+
const now = /* @__PURE__ */ new Date();
|
|
18118
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
|
|
18119
|
+
}
|
|
18120
|
+
function auditForWrite(root, requested) {
|
|
18121
|
+
if (typeof requested === "string" && requested !== "") return requested;
|
|
18122
|
+
const existing = listAuditIds(root);
|
|
18123
|
+
return existing.length > 0 ? existing[existing.length - 1] : currentAuditId();
|
|
18124
|
+
}
|
|
18125
|
+
function buildKritikCatalog(ctx) {
|
|
18126
|
+
const tools2 = [];
|
|
18127
|
+
const handlers2 = {};
|
|
18128
|
+
const tool = (definition, handler) => {
|
|
18129
|
+
tools2.push(definition);
|
|
18130
|
+
handlers2[definition.name] = handler;
|
|
18131
|
+
};
|
|
18132
|
+
const record2 = async (graph, inputs) => {
|
|
18133
|
+
if (inputs.length === 0) return [];
|
|
18134
|
+
const result = await ctx.store.persist(graph, {}, inputs);
|
|
18135
|
+
if (!result.ok) {
|
|
18136
|
+
throw new ToolError("Quality event refused by validateBundle \u2014 nothing was written.", {
|
|
18137
|
+
findings: result.errors,
|
|
18138
|
+
warnings: result.warnings
|
|
18139
|
+
});
|
|
18140
|
+
}
|
|
18141
|
+
return result.events;
|
|
18142
|
+
};
|
|
18143
|
+
const load2 = async () => {
|
|
18144
|
+
try {
|
|
18145
|
+
return await ctx.store.load();
|
|
18146
|
+
} catch (error51) {
|
|
18147
|
+
throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
|
|
18148
|
+
}
|
|
18149
|
+
};
|
|
18150
|
+
tool(
|
|
18151
|
+
{
|
|
18152
|
+
name: "kritik_matrix",
|
|
18153
|
+
description: "The comparative quality matrix for one audit: a score and grade per (domain x surface), the weighted roll-up per surface, and open findings by priority lane. Anti-averaging caps are applied \u2014 one open Critical caps its cell at D, one open High at B \u2014 so a cell full of 3s cannot absorb a live defect. Refreshes the audit's matrix.json, and with record=true appends quality.audit.completed.",
|
|
18154
|
+
inputSchema: {
|
|
18155
|
+
type: "object",
|
|
18156
|
+
properties: {
|
|
18157
|
+
audit_id: { type: "string", description: "Default: the newest audit on disk." },
|
|
18158
|
+
record: {
|
|
18159
|
+
type: "boolean",
|
|
18160
|
+
description: "Append quality.audit.completed carrying these scores and counts. Once per finished audit."
|
|
18161
|
+
}
|
|
18162
|
+
},
|
|
18163
|
+
additionalProperties: false
|
|
18164
|
+
}
|
|
18165
|
+
},
|
|
18166
|
+
async (args) => {
|
|
18167
|
+
const root = rootOf(ctx);
|
|
18168
|
+
const library = libraryOf(root);
|
|
18169
|
+
let auditId;
|
|
18170
|
+
try {
|
|
18171
|
+
auditId = typeof args.audit_id === "string" && args.audit_id !== "" ? args.audit_id : newestAuditId(root);
|
|
18172
|
+
} catch (error51) {
|
|
18173
|
+
throw new ToolError(error51.message);
|
|
18174
|
+
}
|
|
18175
|
+
let computed;
|
|
18176
|
+
try {
|
|
18177
|
+
computed = computeAuditMatrix(root, auditId, library);
|
|
18178
|
+
} catch (error51) {
|
|
18179
|
+
throw new ToolError(error51.message);
|
|
18180
|
+
}
|
|
18181
|
+
const { section, matrix, file: file2 } = computed;
|
|
18182
|
+
const open = section.findings.filter(isOpenFinding);
|
|
18183
|
+
const lanes = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
18184
|
+
for (const finding of open) lanes[priorityOf(finding, library)]++;
|
|
18185
|
+
let events = [];
|
|
18186
|
+
if (args.record === true) {
|
|
18187
|
+
const graph = await load2();
|
|
18188
|
+
events = await record2(graph, [
|
|
18189
|
+
auditCompletedInput(matrix, {
|
|
18190
|
+
audit_id: auditId,
|
|
18191
|
+
framework_version: file2.framework_version,
|
|
18192
|
+
...file2.commit !== void 0 ? { commit: file2.commit } : {}
|
|
18193
|
+
})
|
|
18194
|
+
]);
|
|
18195
|
+
}
|
|
18196
|
+
return {
|
|
18197
|
+
...file2,
|
|
18198
|
+
assessment_count: section.assessments.length,
|
|
18199
|
+
open_findings: open.length,
|
|
18200
|
+
lanes,
|
|
18201
|
+
p0: open.filter((finding) => priorityOf(finding, library) === "P0").map((finding) => ({
|
|
18202
|
+
id: finding.id,
|
|
18203
|
+
surface: finding.surface,
|
|
18204
|
+
criterion_id: finding.criterion_id,
|
|
18205
|
+
title: finding.title,
|
|
18206
|
+
severity: severityOf(finding, library)
|
|
18207
|
+
})),
|
|
18208
|
+
events
|
|
18209
|
+
};
|
|
18210
|
+
}
|
|
18211
|
+
);
|
|
18212
|
+
tool(
|
|
18213
|
+
{
|
|
18214
|
+
name: "kritik_findings",
|
|
18215
|
+
description: "Findings across every audit, with their derived severity and priority. Filter by surface, status, priority, or criterion. Severity and priority are computed from impact x likelihood and cost on every read \u2014 they are never stored, so they cannot drift from the numbers behind them.",
|
|
18216
|
+
inputSchema: {
|
|
18217
|
+
type: "object",
|
|
18218
|
+
properties: {
|
|
18219
|
+
surface: { type: "string" },
|
|
18220
|
+
status: { type: "string", enum: [...FINDING_STATUSES] },
|
|
18221
|
+
priority: { type: "string", enum: ["P0", "P1", "P2", "P3"] },
|
|
18222
|
+
criterion_id: { type: "string" },
|
|
18223
|
+
audit_id: { type: "string", description: "Default: every audit." }
|
|
18224
|
+
},
|
|
18225
|
+
additionalProperties: false
|
|
18226
|
+
}
|
|
18227
|
+
},
|
|
18228
|
+
async (args) => {
|
|
18229
|
+
const root = rootOf(ctx);
|
|
18230
|
+
const library = libraryOf(root);
|
|
18231
|
+
const auditIds = typeof args.audit_id === "string" && args.audit_id !== "" ? [args.audit_id] : listAuditIds(root);
|
|
18232
|
+
const rows = auditIds.flatMap(
|
|
18233
|
+
(auditId) => loadFindings(root, auditId).findings.map((finding) => ({
|
|
18234
|
+
...finding,
|
|
18235
|
+
audit_id: auditId,
|
|
18236
|
+
severity: severityOf(finding, library),
|
|
18237
|
+
priority: priorityOf(finding, library)
|
|
18238
|
+
}))
|
|
18239
|
+
);
|
|
18240
|
+
const matches = rows.filter((row) => {
|
|
18241
|
+
if (typeof args.surface === "string" && row.surface !== args.surface) return false;
|
|
18242
|
+
if (typeof args.status === "string" && (row.status ?? "open") !== args.status) return false;
|
|
18243
|
+
if (typeof args.priority === "string" && row.priority !== args.priority) return false;
|
|
18244
|
+
if (typeof args.criterion_id === "string" && row.criterion_id !== args.criterion_id) return false;
|
|
18245
|
+
return true;
|
|
18246
|
+
});
|
|
18247
|
+
return { total: matches.length, findings: matches };
|
|
18248
|
+
}
|
|
18249
|
+
);
|
|
18250
|
+
tool(
|
|
18251
|
+
{
|
|
18252
|
+
name: "kritik_signals",
|
|
18253
|
+
description: "The signal pack: every applicable criterion's mechanically checkable statements, expanded across the surfaces it applies to, plus anything that has tripped since the last recorded audit. These are statements to CHECK, not commands to run \u2014 a grep that must return nothing, a CI job that must exist \u2014 so run them yourself and report what failed with kritik_trip_signal.",
|
|
18254
|
+
inputSchema: {
|
|
18255
|
+
type: "object",
|
|
18256
|
+
properties: {
|
|
18257
|
+
surface: { type: "string" },
|
|
18258
|
+
criterion_id: { type: "string" },
|
|
18259
|
+
domain: { type: "string", description: "Domain code, e.g. SEC." }
|
|
18260
|
+
},
|
|
18261
|
+
additionalProperties: false
|
|
18262
|
+
}
|
|
18263
|
+
},
|
|
18264
|
+
async (args) => {
|
|
18265
|
+
const root = rootOf(ctx);
|
|
18266
|
+
const library = libraryOf(root);
|
|
18267
|
+
const profile = profileOf(root);
|
|
18268
|
+
const filter = {
|
|
18269
|
+
...typeof args.surface === "string" ? { surface: surfaceOf(profile, args.surface) } : {},
|
|
18270
|
+
...typeof args.criterion_id === "string" ? { criterion: criterionOf(library, args.criterion_id).id } : {},
|
|
18271
|
+
...typeof args.domain === "string" ? { domain: args.domain } : {}
|
|
18272
|
+
};
|
|
18273
|
+
const rows = signalRunSheet(library, profile.surfaces ?? [], filter);
|
|
18274
|
+
const journal = resolveJournal(root);
|
|
18275
|
+
const events = journal.present ? orderEvents(readFullJournalEvents(journal.journalPath)) : [];
|
|
18276
|
+
const lastAudit = events.map((event) => event.type).lastIndexOf("quality.audit.completed");
|
|
18277
|
+
const tripped = events.slice(lastAudit + 1).filter((event) => event.type === "quality.signal.tripped");
|
|
18278
|
+
return { library_version: library.version, total: rows.length, signals: rows, tripped_since_last_audit: tripped };
|
|
18279
|
+
}
|
|
18280
|
+
);
|
|
18281
|
+
tool(
|
|
18282
|
+
{
|
|
18283
|
+
name: "kritik_issue",
|
|
18284
|
+
description: "The criterion's GitHub issue skeleton, filled as far as what is known allows. Placeholders that cannot be filled are left standing \u2014 a skeleton is a form to finish, and an empty '### Risk' reads as 'no risk'. Pass finding_id for the P0/P1 path: the risk numbers, evidence and narrative come from the finding.",
|
|
18285
|
+
inputSchema: {
|
|
18286
|
+
type: "object",
|
|
18287
|
+
properties: {
|
|
18288
|
+
criterion_id: { type: "string" },
|
|
18289
|
+
surface: { type: "string" },
|
|
18290
|
+
level: { type: "integer", minimum: 0, maximum: 4, description: "The observed maturity, so the anchors fill in." },
|
|
18291
|
+
finding_id: { type: "string" }
|
|
18292
|
+
},
|
|
18293
|
+
required: ["criterion_id", "surface"],
|
|
18294
|
+
additionalProperties: false
|
|
18295
|
+
}
|
|
18296
|
+
},
|
|
18297
|
+
async (args) => {
|
|
18298
|
+
const root = rootOf(ctx);
|
|
18299
|
+
const library = libraryOf(root);
|
|
18300
|
+
const criterion = criterionOf(library, requireString(args, "criterion_id"));
|
|
18301
|
+
const surface = requireString(args, "surface");
|
|
18302
|
+
const declared2 = loadProfile(root);
|
|
18303
|
+
if (declared2) surfaceOf(declared2, surface, true);
|
|
18304
|
+
let finding;
|
|
18305
|
+
if (typeof args.finding_id === "string" && args.finding_id !== "") {
|
|
18306
|
+
const located = locateFinding(root, args.finding_id);
|
|
18307
|
+
if (!located) throw new ToolError(`No finding "${args.finding_id}" in any audit.`);
|
|
18308
|
+
finding = located.finding;
|
|
18309
|
+
}
|
|
18310
|
+
return renderIssue(criterion, {
|
|
18311
|
+
surface,
|
|
18312
|
+
...typeof args.level === "number" ? { level: args.level } : {},
|
|
18313
|
+
...finding !== void 0 ? { finding, library } : {}
|
|
18314
|
+
});
|
|
18315
|
+
}
|
|
18316
|
+
);
|
|
18317
|
+
tool(
|
|
18318
|
+
{
|
|
18319
|
+
name: "kritik_score",
|
|
18320
|
+
description: "Record one (criterion x surface) maturity level with the evidence behind it. A cell holds exactly one level, so re-scoring replaces in place. Evidence is required: a score without a citation is an opinion, not an assessment. Score what the code IS, never what an open PR promises \u2014 that is what makes a trend real.",
|
|
18321
|
+
inputSchema: {
|
|
18322
|
+
type: "object",
|
|
18323
|
+
properties: {
|
|
18324
|
+
criterion_id: { type: "string" },
|
|
18325
|
+
surface: { type: "string" },
|
|
18326
|
+
level: {
|
|
18327
|
+
type: "integer",
|
|
18328
|
+
enum: [...MATURITY_LEVELS],
|
|
18329
|
+
description: "0 Absent \xB7 1 Ad-hoc \xB7 2 Defined \xB7 3 Managed \xB7 4 Verified. N/A is the absence of the row, not a level."
|
|
18330
|
+
},
|
|
18331
|
+
evidence: { type: "string", description: "file:line / config citations, markdown." },
|
|
18332
|
+
audit_id: { type: "string", description: "Default: the newest audit, or the current YYYY-MM." },
|
|
18333
|
+
commit: { type: "string" }
|
|
18334
|
+
},
|
|
18335
|
+
required: ["criterion_id", "surface", "level", "evidence"],
|
|
18336
|
+
additionalProperties: false
|
|
18337
|
+
}
|
|
18338
|
+
},
|
|
18339
|
+
async (args) => {
|
|
18340
|
+
const root = rootOf(ctx);
|
|
18341
|
+
const library = libraryOf(root);
|
|
18342
|
+
const profile = profileOf(root);
|
|
18343
|
+
const criterionId = requireString(args, "criterion_id");
|
|
18344
|
+
const criterion = criterionOf(library, criterionId);
|
|
18345
|
+
const surface = surfaceOf(profile, requireString(args, "surface"));
|
|
18346
|
+
const level = requireInt(args, "level", 0, 4);
|
|
18347
|
+
const evidence = requireString(args, "evidence");
|
|
18348
|
+
const appliesTo = criterion.applies_to;
|
|
18349
|
+
if (Array.isArray(appliesTo) && !appliesTo.includes(surface)) {
|
|
18350
|
+
throw new ToolError(
|
|
18351
|
+
`${criterionId} does not apply to "${surface}" (applies to: ${appliesTo.join(", ")}). Scoring it there would produce a cell nothing rolls up.`
|
|
18352
|
+
);
|
|
18353
|
+
}
|
|
18354
|
+
const auditId = auditForWrite(root, args.audit_id);
|
|
18355
|
+
const file2 = loadScoresOrEmpty(root, auditId);
|
|
18356
|
+
const assessment = {
|
|
18357
|
+
criterion_id: criterionId,
|
|
18358
|
+
surface,
|
|
18359
|
+
level,
|
|
18360
|
+
evidence,
|
|
18361
|
+
audit_id: auditId,
|
|
18362
|
+
...typeof args.commit === "string" ? { commit: args.commit } : {},
|
|
18363
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
18364
|
+
};
|
|
18365
|
+
const { assessments, replaced } = upsertAssessment(file2.assessments, assessment);
|
|
18366
|
+
saveScores(root, auditId, {
|
|
18367
|
+
...file2,
|
|
18368
|
+
audit_id: auditId,
|
|
18369
|
+
framework_version: file2.framework_version ?? library.version,
|
|
18370
|
+
...typeof args.commit === "string" ? { commit: args.commit } : {},
|
|
18371
|
+
assessments
|
|
18372
|
+
});
|
|
18373
|
+
return {
|
|
18374
|
+
assessment,
|
|
18375
|
+
audit_id: auditId,
|
|
18376
|
+
assessment_count: assessments.length,
|
|
18377
|
+
...replaced !== void 0 ? { replaced_level: replaced.level } : {},
|
|
18378
|
+
anchor: criterion.level_anchors?.[`l${level}`]
|
|
18379
|
+
};
|
|
18380
|
+
}
|
|
18381
|
+
);
|
|
18382
|
+
tool(
|
|
18383
|
+
{
|
|
18384
|
+
name: "kritik_open_finding",
|
|
18385
|
+
description: "Open a finding on a (criterion x surface) cell and append quality.finding.opened. One finding is one defect \u2014 not one criterion, and not one surface's worth of grumbling. Verify Critical and High adversarially BEFORE opening: try to refute them against the repo, and record the verdict. Severity and priority come back derived; they are never stored.",
|
|
18386
|
+
inputSchema: {
|
|
18387
|
+
type: "object",
|
|
18388
|
+
properties: {
|
|
18389
|
+
criterion_id: { type: "string" },
|
|
18390
|
+
surface: { type: "string", description: `A profile surface, or "${CROSS_SURFACE_ID}" for a defect belonging to the contract between surfaces.` },
|
|
18391
|
+
title: { type: "string", description: "One line naming the actual defect, not the category." },
|
|
18392
|
+
detail: { type: "string", description: "What breaks, for whom, and the path that gets there. Defaults to the title." },
|
|
18393
|
+
evidence: { type: "string", description: "file:line citations someone can check." },
|
|
18394
|
+
impact: { type: "integer", minimum: 1, maximum: 5, description: "Worst plausible consequence." },
|
|
18395
|
+
likelihood: { type: "integer", minimum: 1, maximum: 5, description: "Probability it materializes." },
|
|
18396
|
+
cost: { type: "string", enum: [...REMEDIATION_COSTS], description: "S <= half day \xB7 M <= 2 days \xB7 L <= 1 week \xB7 XL beyond." },
|
|
18397
|
+
remediation: { type: "string" },
|
|
18398
|
+
node_ids: { type: "array", items: { type: "string" }, description: "Product-graph nodes this is about." },
|
|
18399
|
+
issue_url: { type: "string" },
|
|
18400
|
+
verification: {
|
|
18401
|
+
type: "object",
|
|
18402
|
+
properties: {
|
|
18403
|
+
verdict: { type: "string", enum: ["CONFIRMED", "REFUTED", "DOWNGRADED"] },
|
|
18404
|
+
note: { type: "string" }
|
|
18405
|
+
},
|
|
18406
|
+
required: ["verdict"],
|
|
18407
|
+
additionalProperties: false,
|
|
18408
|
+
description: "The adversarial pass. A refuted finding is disclosed, not deleted \u2014 open it with status refuted."
|
|
18409
|
+
},
|
|
18410
|
+
audit_id: { type: "string" },
|
|
18411
|
+
finding_id: { type: "string", description: "Default: minted as F-<audit>-<DOMAIN>-<surface>-NN." }
|
|
18412
|
+
},
|
|
18413
|
+
required: ["criterion_id", "surface", "title", "evidence", "impact", "likelihood", "cost"],
|
|
18414
|
+
additionalProperties: false
|
|
18415
|
+
}
|
|
18416
|
+
},
|
|
18417
|
+
async (args) => {
|
|
18418
|
+
const root = rootOf(ctx);
|
|
18419
|
+
const library = libraryOf(root);
|
|
18420
|
+
const profile = profileOf(root);
|
|
18421
|
+
const criterionId = requireString(args, "criterion_id");
|
|
18422
|
+
criterionOf(library, criterionId);
|
|
18423
|
+
const surface = surfaceOf(profile, requireString(args, "surface"), true);
|
|
18424
|
+
const title = requireString(args, "title");
|
|
18425
|
+
const evidence = requireString(args, "evidence");
|
|
18426
|
+
const impact = requireInt(args, "impact", 1, 5);
|
|
18427
|
+
const likelihood = requireInt(args, "likelihood", 1, 5);
|
|
18428
|
+
const cost = requireString(args, "cost");
|
|
18429
|
+
if (!REMEDIATION_COSTS.includes(cost)) {
|
|
18430
|
+
throw new ToolError(`\`cost\` must be one of ${REMEDIATION_COSTS.join(", ")} \u2014 it decides priority.`);
|
|
18431
|
+
}
|
|
18432
|
+
const auditId = auditForWrite(root, args.audit_id);
|
|
18433
|
+
const file2 = loadFindings(root, auditId);
|
|
18434
|
+
const taken = new Set(file2.findings.map((candidate) => candidate.id));
|
|
18435
|
+
const requestedId = typeof args.finding_id === "string" && args.finding_id !== "" ? args.finding_id : void 0;
|
|
18436
|
+
if (requestedId !== void 0 && taken.has(requestedId)) {
|
|
18437
|
+
throw new ToolError(`Finding "${requestedId}" already exists in ${auditId} \u2014 resolve or accept it rather than reopening the id.`);
|
|
18438
|
+
}
|
|
18439
|
+
const id = requestedId ?? mintFindingId(auditId, criterionId, surface, taken, library);
|
|
18440
|
+
const nodeIds = Array.isArray(args.node_ids) ? args.node_ids.filter((value) => typeof value === "string") : void 0;
|
|
18441
|
+
const verification = args.verification;
|
|
18442
|
+
const finding = {
|
|
18443
|
+
id,
|
|
18444
|
+
criterion_id: criterionId,
|
|
18445
|
+
surface,
|
|
18446
|
+
title,
|
|
18447
|
+
detail: typeof args.detail === "string" && args.detail !== "" ? args.detail : title,
|
|
18448
|
+
evidence,
|
|
18449
|
+
impact,
|
|
18450
|
+
likelihood,
|
|
18451
|
+
cost,
|
|
18452
|
+
status: verification?.verdict === "REFUTED" ? "refuted" : "open",
|
|
18453
|
+
...typeof args.remediation === "string" ? { remediation: args.remediation } : {},
|
|
18454
|
+
...nodeIds !== void 0 && nodeIds.length > 0 ? { node_ids: nodeIds } : {},
|
|
18455
|
+
...typeof args.issue_url === "string" ? { issue_url: args.issue_url } : {},
|
|
18456
|
+
...verification !== void 0 ? { verification } : {}
|
|
18457
|
+
};
|
|
18458
|
+
const graph = await load2();
|
|
18459
|
+
const events = await record2(graph, finding.status === "refuted" ? [] : [findingOpenedInput(finding, library)]);
|
|
18460
|
+
const { findings } = upsertFinding(file2.findings, finding);
|
|
18461
|
+
saveFindings(root, auditId, {
|
|
18462
|
+
...file2,
|
|
18463
|
+
audit_id: auditId,
|
|
18464
|
+
framework_version: file2.framework_version ?? library.version,
|
|
18465
|
+
findings
|
|
18466
|
+
});
|
|
18467
|
+
return {
|
|
18468
|
+
finding,
|
|
18469
|
+
audit_id: auditId,
|
|
18470
|
+
severity: severityOf(finding, library),
|
|
18471
|
+
priority: priorityOf(finding, library),
|
|
18472
|
+
finding_count: findings.length,
|
|
18473
|
+
events
|
|
18474
|
+
};
|
|
18475
|
+
}
|
|
18476
|
+
);
|
|
18477
|
+
tool(
|
|
18478
|
+
{
|
|
18479
|
+
name: "kritik_resolve_finding",
|
|
18480
|
+
description: "Close a finding because the fix merged, and append quality.finding.resolved. `resolved_by` is the PR or commit URL \u2014 the evidence it is actually gone, which is the only thing separating 'resolved' from 'we stopped looking'. Idempotent: resolving an already-resolved finding writes nothing.",
|
|
18481
|
+
inputSchema: {
|
|
18482
|
+
type: "object",
|
|
18483
|
+
properties: {
|
|
18484
|
+
finding_id: { type: "string" },
|
|
18485
|
+
resolved_by: { type: "string", description: "The PR or commit URL that closed it." }
|
|
18486
|
+
},
|
|
18487
|
+
required: ["finding_id"],
|
|
18488
|
+
additionalProperties: false
|
|
18489
|
+
}
|
|
18490
|
+
},
|
|
18491
|
+
async (args) => {
|
|
18492
|
+
const root = rootOf(ctx);
|
|
18493
|
+
const id = requireString(args, "finding_id");
|
|
18494
|
+
const located = locateFinding(root, id);
|
|
18495
|
+
if (!located) throw new ToolError(`No finding "${id}" in any audit under docs/quality/audits/.`);
|
|
18496
|
+
if (located.finding.status === "resolved") {
|
|
18497
|
+
return { finding: located.finding, audit_id: located.auditId, events: [], note: "Already resolved \u2014 nothing written." };
|
|
18498
|
+
}
|
|
18499
|
+
const resolvedBy = typeof args.resolved_by === "string" && args.resolved_by !== "" ? args.resolved_by : void 0;
|
|
18500
|
+
const graph = await load2();
|
|
18501
|
+
const events = await record2(graph, [findingResolvedInput(located.finding, resolvedBy)]);
|
|
18502
|
+
const { findings, finding } = resolveFinding(located.file.findings, id, resolvedBy);
|
|
18503
|
+
saveFindings(root, located.auditId, { ...located.file, findings });
|
|
18504
|
+
return { finding, audit_id: located.auditId, events };
|
|
18505
|
+
}
|
|
18506
|
+
);
|
|
18507
|
+
tool(
|
|
18508
|
+
{
|
|
18509
|
+
name: "kritik_accept_finding",
|
|
18510
|
+
description: "Record a finding as a known, owned risk. The note is required \u2014 an accepted risk is a decision and reads like one, and the findings board renders it as a decision-log entry. No journal event: acceptance is a state of the finding, not something that happened to the product.",
|
|
18511
|
+
inputSchema: {
|
|
18512
|
+
type: "object",
|
|
18513
|
+
properties: {
|
|
18514
|
+
finding_id: { type: "string" },
|
|
18515
|
+
note: { type: "string", description: "Why this risk is accepted, and by what reasoning." }
|
|
18516
|
+
},
|
|
18517
|
+
required: ["finding_id", "note"],
|
|
18518
|
+
additionalProperties: false
|
|
18519
|
+
}
|
|
18520
|
+
},
|
|
18521
|
+
async (args) => {
|
|
18522
|
+
const root = rootOf(ctx);
|
|
18523
|
+
const id = requireString(args, "finding_id");
|
|
18524
|
+
const note = requireString(args, "note");
|
|
18525
|
+
const located = locateFinding(root, id);
|
|
18526
|
+
if (!located) throw new ToolError(`No finding "${id}" in any audit under docs/quality/audits/.`);
|
|
18527
|
+
const { findings, finding } = acceptFinding(located.file.findings, id, note);
|
|
18528
|
+
saveFindings(root, located.auditId, { ...located.file, findings });
|
|
18529
|
+
return { finding, audit_id: located.auditId, events: [] };
|
|
18530
|
+
}
|
|
18531
|
+
);
|
|
18532
|
+
tool(
|
|
18533
|
+
{
|
|
18534
|
+
name: "kritik_trip_signal",
|
|
18535
|
+
description: "Record that a monitoring signal failed between audits: appends quality.signal.tripped. A tripped signal is NOT a finding \u2014 it is the prompt to go look. Cheap, frequent, and allowed to be wrong, where a finding is expensive, rare, and has survived an adversarial pass.",
|
|
18536
|
+
inputSchema: {
|
|
18537
|
+
type: "object",
|
|
18538
|
+
properties: {
|
|
18539
|
+
criterion_id: { type: "string" },
|
|
18540
|
+
surface: { type: "string" },
|
|
18541
|
+
signal: { type: "string", description: "The statement that failed, or its index in the criterion's signals[]." },
|
|
18542
|
+
detail: { type: "string", description: "What you actually observed." }
|
|
18543
|
+
},
|
|
18544
|
+
required: ["criterion_id", "surface", "signal"],
|
|
18545
|
+
additionalProperties: false
|
|
18546
|
+
}
|
|
18547
|
+
},
|
|
18548
|
+
async (args) => {
|
|
18549
|
+
const root = rootOf(ctx);
|
|
18550
|
+
const library = libraryOf(root);
|
|
18551
|
+
const profile = profileOf(root);
|
|
18552
|
+
const criterion = criterionOf(library, requireString(args, "criterion_id"));
|
|
18553
|
+
const surface = surfaceOf(profile, requireString(args, "surface"));
|
|
18554
|
+
const raw = requireString(args, "signal");
|
|
18555
|
+
const signals = criterion.signals ?? [];
|
|
18556
|
+
const index = Number(raw);
|
|
18557
|
+
const signal = Number.isInteger(index) && index >= 0 && index < signals.length ? signals[index] : raw;
|
|
18558
|
+
const graph = await load2();
|
|
18559
|
+
const events = await record2(graph, [
|
|
18560
|
+
signalTrippedInput({
|
|
18561
|
+
criterion_id: criterion.id,
|
|
18562
|
+
surface,
|
|
18563
|
+
signal,
|
|
18564
|
+
...typeof args.detail === "string" ? { detail: args.detail } : {}
|
|
18565
|
+
})
|
|
18566
|
+
]);
|
|
18567
|
+
return { criterion_id: criterion.id, surface, signal, events };
|
|
18568
|
+
}
|
|
18569
|
+
);
|
|
18570
|
+
return { tools: tools2, handlers: handlers2 };
|
|
18571
|
+
}
|
|
18572
|
+
|
|
18573
|
+
// src/tools.ts
|
|
18574
|
+
async function load(ctx) {
|
|
18575
|
+
let graph;
|
|
18576
|
+
try {
|
|
18577
|
+
graph = await ctx.store.load();
|
|
18578
|
+
} catch (error51) {
|
|
18579
|
+
throw new ToolError(`Cannot load ${ctx.store.describe()}: ${error51.message}`);
|
|
18580
|
+
}
|
|
18581
|
+
return {
|
|
18582
|
+
loaded: graph.loaded,
|
|
18583
|
+
nodes: graph.nodes,
|
|
18584
|
+
edges: graph.edges,
|
|
16698
18585
|
project: graph.project,
|
|
16699
18586
|
journal: graph.journal
|
|
16700
18587
|
};
|
|
16701
18588
|
}
|
|
16702
|
-
function
|
|
18589
|
+
function requireString2(args, key) {
|
|
16703
18590
|
const value = args[key];
|
|
16704
18591
|
if (typeof value !== "string" || value.length === 0) {
|
|
16705
18592
|
throw new ToolError(`\`${key}\` is required and must be a non-empty string.`);
|
|
@@ -16831,7 +18718,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
16831
18718
|
}
|
|
16832
18719
|
},
|
|
16833
18720
|
async (args) => {
|
|
16834
|
-
const nodeId =
|
|
18721
|
+
const nodeId = requireString2(args, "node_id");
|
|
16835
18722
|
const { nodes, edges, journal } = await load(ctx);
|
|
16836
18723
|
const node = findNode(nodes, nodeId);
|
|
16837
18724
|
const nodesById = new Map(nodes.map((candidate) => [candidate.id, candidate]));
|
|
@@ -16899,14 +18786,15 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
16899
18786
|
tool(
|
|
16900
18787
|
{
|
|
16901
18788
|
name: "list_maps",
|
|
16902
|
-
description: "Every map the project offers \u2014 built-ins plus stored definitions \u2014 with live subgraph sizes.",
|
|
18789
|
+
description: "Every map the project offers \u2014 built-ins plus stored definitions \u2014 with live subgraph sizes. A definition carrying a `product` is counted through that restriction, as the canvas draws it.",
|
|
16903
18790
|
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
16904
18791
|
},
|
|
16905
18792
|
async () => {
|
|
16906
18793
|
const { nodes, edges, project } = await load(ctx);
|
|
18794
|
+
const graph = buildProductGraph(nodes, edges);
|
|
16907
18795
|
return {
|
|
16908
18796
|
maps: listMaps(project).map((definition) => {
|
|
16909
|
-
const subgraph = computeMapSubgraph(definition, nodes, edges);
|
|
18797
|
+
const subgraph = computeMapSubgraph(definition, nodes, edges, { graph });
|
|
16910
18798
|
return { definition, nodeCount: subgraph.nodes.length, edgeCount: subgraph.edges.length };
|
|
16911
18799
|
})
|
|
16912
18800
|
};
|
|
@@ -16915,7 +18803,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
16915
18803
|
tool(
|
|
16916
18804
|
{
|
|
16917
18805
|
name: "get_map",
|
|
16918
|
-
description: "Resolve a map definition (built-in or stored) and return its computed subgraph.",
|
|
18806
|
+
description: "Resolve a map definition (built-in or stored) and return its computed subgraph. A definition carrying a `product` returns only that product's nodes \u2014 the same subgraph the canvas draws.",
|
|
16919
18807
|
inputSchema: {
|
|
16920
18808
|
type: "object",
|
|
16921
18809
|
properties: { map_id: { type: "string" } },
|
|
@@ -16924,7 +18812,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
16924
18812
|
}
|
|
16925
18813
|
},
|
|
16926
18814
|
async (args) => {
|
|
16927
|
-
const mapId =
|
|
18815
|
+
const mapId = requireString2(args, "map_id");
|
|
16928
18816
|
const { nodes, edges, project } = await load(ctx);
|
|
16929
18817
|
const definition = listMaps(project).find((candidate) => candidate.id === mapId);
|
|
16930
18818
|
if (!definition) throw new ToolError(`No map with id "${mapId}".`);
|
|
@@ -16968,8 +18856,8 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
16968
18856
|
},
|
|
16969
18857
|
async (args) => {
|
|
16970
18858
|
const graph = await load(ctx);
|
|
16971
|
-
const species =
|
|
16972
|
-
const title =
|
|
18859
|
+
const species = requireString2(args, "species");
|
|
18860
|
+
const title = requireString2(args, "title");
|
|
16973
18861
|
const platforms = Array.isArray(args.platforms) ? args.platforms : [];
|
|
16974
18862
|
const node = {
|
|
16975
18863
|
id: deriveNodeId(species, title, graph.nodes.map((candidate) => candidate.id)),
|
|
@@ -17017,7 +18905,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17017
18905
|
}
|
|
17018
18906
|
},
|
|
17019
18907
|
async (args) => {
|
|
17020
|
-
const nodeId =
|
|
18908
|
+
const nodeId = requireString2(args, "node_id");
|
|
17021
18909
|
if (typeof args.patch !== "object" || args.patch === null || Array.isArray(args.patch)) {
|
|
17022
18910
|
throw new ToolError("`patch` is required and must be an object.");
|
|
17023
18911
|
}
|
|
@@ -17057,7 +18945,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17057
18945
|
}
|
|
17058
18946
|
},
|
|
17059
18947
|
async (args) => {
|
|
17060
|
-
const nodeId =
|
|
18948
|
+
const nodeId = requireString2(args, "node_id");
|
|
17061
18949
|
const graph = await load(ctx);
|
|
17062
18950
|
const node = findNode(graph.nodes, nodeId);
|
|
17063
18951
|
const ops = [{ op: "delete_node", node_id: nodeId }];
|
|
@@ -17087,9 +18975,9 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17087
18975
|
}
|
|
17088
18976
|
},
|
|
17089
18977
|
async (args) => {
|
|
17090
|
-
const sourceId =
|
|
17091
|
-
const targetId =
|
|
17092
|
-
const edgeType =
|
|
18978
|
+
const sourceId = requireString2(args, "source_id");
|
|
18979
|
+
const targetId = requireString2(args, "target_id");
|
|
18980
|
+
const edgeType = requireString2(args, "edge_type");
|
|
17093
18981
|
const graph = await load(ctx);
|
|
17094
18982
|
const edge = {
|
|
17095
18983
|
id: edgeId(sourceId, targetId),
|
|
@@ -17124,7 +19012,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17124
19012
|
}
|
|
17125
19013
|
},
|
|
17126
19014
|
async (args) => {
|
|
17127
|
-
const edgeIdArg =
|
|
19015
|
+
const edgeIdArg = requireString2(args, "edge_id");
|
|
17128
19016
|
const graph = await load(ctx);
|
|
17129
19017
|
const edge = graph.edges.find((candidate) => candidate.id === edgeIdArg);
|
|
17130
19018
|
if (!edge) throw new ToolError(`No edge with id "${edgeIdArg}".`);
|
|
@@ -17140,7 +19028,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17140
19028
|
}
|
|
17141
19029
|
);
|
|
17142
19030
|
const journalOnly = (type) => async (args) => {
|
|
17143
|
-
const title =
|
|
19031
|
+
const title = requireString2(args, "title");
|
|
17144
19032
|
const graph = await load(ctx);
|
|
17145
19033
|
const payload = { title };
|
|
17146
19034
|
if (typeof args.description === "string") payload.description = args.description;
|
|
@@ -17186,97 +19074,36 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17186
19074
|
},
|
|
17187
19075
|
journalOnly("request.filed")
|
|
17188
19076
|
);
|
|
19077
|
+
const kritik = buildKritikCatalog(ctx);
|
|
19078
|
+
tools2.push(...kritik.tools);
|
|
19079
|
+
Object.assign(handlers2, kritik.handlers);
|
|
17189
19080
|
return { tools: tools2, handlers: handlers2 };
|
|
17190
19081
|
}
|
|
17191
19082
|
|
|
17192
19083
|
// src/store.ts
|
|
17193
|
-
import { writeFileSync as
|
|
17194
|
-
import { resolve } from "node:path";
|
|
17195
|
-
|
|
17196
|
-
// ../cli/src/lib/bundle-io.ts
|
|
17197
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
17198
|
-
function readBundle(filePath) {
|
|
17199
|
-
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
17200
|
-
let parsed;
|
|
17201
|
-
try {
|
|
17202
|
-
parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
17203
|
-
} catch (e) {
|
|
17204
|
-
throw new Error(`Cannot parse JSON \u2014 ${e.message}`);
|
|
17205
|
-
}
|
|
17206
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
17207
|
-
throw new Error("Bundle must be a JSON object.");
|
|
17208
|
-
}
|
|
17209
|
-
const record2 = parsed;
|
|
17210
|
-
if (!Array.isArray(record2.nodes)) return record2;
|
|
17211
|
-
return migrateStatusVocabulary(record2);
|
|
17212
|
-
}
|
|
17213
|
-
|
|
17214
|
-
// ../cli/src/lib/journal-io.ts
|
|
17215
|
-
import { appendFileSync, existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
17216
|
-
import { dirname, join } from "node:path";
|
|
17217
|
-
var JOURNAL_SIDECAR = "journal.jsonl";
|
|
17218
|
-
function journalPathFor(bundlePath) {
|
|
17219
|
-
return join(dirname(bundlePath), JOURNAL_SIDECAR);
|
|
17220
|
-
}
|
|
17221
|
-
function toLine(event) {
|
|
17222
|
-
return JSON.stringify(event) + "\n";
|
|
17223
|
-
}
|
|
17224
|
-
function appendJournalEvent(journalPath, event) {
|
|
17225
|
-
const line = toLine(event);
|
|
17226
|
-
if (!existsSync2(journalPath)) {
|
|
17227
|
-
mkdirSync(dirname(journalPath), { recursive: true });
|
|
17228
|
-
writeFileSync(journalPath, line);
|
|
17229
|
-
return;
|
|
17230
|
-
}
|
|
17231
|
-
const existing = readFileSync2(journalPath, "utf8");
|
|
17232
|
-
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
17233
|
-
appendFileSync(journalPath, prefix + line);
|
|
17234
|
-
}
|
|
17235
|
-
|
|
17236
|
-
// ../cli/src/lib/bundle-validate.ts
|
|
17237
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
17238
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
17239
|
-
var JOURNAL_SIDECAR2 = "journal.jsonl";
|
|
17240
|
-
function validateBundleAt(filePath) {
|
|
17241
|
-
const bundle = readBundle(filePath);
|
|
17242
|
-
const loose = bundle;
|
|
17243
|
-
if (!loose.project || !loose.nodes || !loose.edges) {
|
|
17244
|
-
throw new Error("Missing top-level keys (project, nodes, edges).");
|
|
17245
|
-
}
|
|
17246
|
-
let sidecarFindings = [];
|
|
17247
|
-
let sidecarLoaded = false;
|
|
17248
|
-
if (loose.journal === void 0) {
|
|
17249
|
-
const sidecarPath = join2(dirname2(filePath), JOURNAL_SIDECAR2);
|
|
17250
|
-
if (existsSync3(sidecarPath)) {
|
|
17251
|
-
const { events, findings } = parseJournalLines(readFileSync3(sidecarPath, "utf8"));
|
|
17252
|
-
sidecarFindings = findings;
|
|
17253
|
-
sidecarLoaded = true;
|
|
17254
|
-
loose.journal = events;
|
|
17255
|
-
}
|
|
17256
|
-
}
|
|
17257
|
-
const nodes = Array.isArray(loose.nodes) ? loose.nodes : [];
|
|
17258
|
-
const edges = Array.isArray(loose.edges) ? loose.edges : [];
|
|
17259
|
-
const journal = Array.isArray(loose.journal) ? loose.journal : [];
|
|
17260
|
-
const result = validateBundle(bundle);
|
|
17261
|
-
const valid = sidecarFindings.length === 0 && result.errors.length === 0;
|
|
17262
|
-
return { bundle, nodes, edges, journal, sidecarLoaded, sidecarFindings, result, valid };
|
|
17263
|
-
}
|
|
17264
|
-
|
|
17265
|
-
// src/store.ts
|
|
19084
|
+
import { writeFileSync as writeFileSync3 } from "node:fs";
|
|
19085
|
+
import { resolve as resolve2 } from "node:path";
|
|
17266
19086
|
var MCP_ACTOR = "arkaik-mcp";
|
|
17267
|
-
var
|
|
19087
|
+
var DEFAULT_BUNDLE_PATH2 = "docs/arkaik/bundle.json";
|
|
17268
19088
|
function resolveBundlePath(argv2, env) {
|
|
17269
19089
|
const flagIndex = argv2.indexOf("--bundle");
|
|
17270
19090
|
const flagValue2 = flagIndex !== -1 ? argv2[flagIndex + 1] : void 0;
|
|
17271
|
-
if (flagValue2) return
|
|
17272
|
-
if (env.ARKAIK_BUNDLE) return
|
|
17273
|
-
return
|
|
19091
|
+
if (flagValue2) return resolve2(flagValue2);
|
|
19092
|
+
if (env.ARKAIK_BUNDLE) return resolve2(env.ARKAIK_BUNDLE);
|
|
19093
|
+
return resolve2(DEFAULT_BUNDLE_PATH2);
|
|
17274
19094
|
}
|
|
17275
19095
|
function loadBundle(bundlePath) {
|
|
17276
19096
|
return validateBundleAt(bundlePath);
|
|
17277
19097
|
}
|
|
19098
|
+
function nodeIdsOf(nodes) {
|
|
19099
|
+
return nodes.map((node) => node?.id).filter((id) => typeof id === "string");
|
|
19100
|
+
}
|
|
17278
19101
|
function persistMutation(bundlePath, loaded, next, inputs) {
|
|
17279
|
-
const
|
|
19102
|
+
const baselineNodeIds = inputs.length === 0 ? [] : missingProvenanceNodeIds(nodeIdsOf(loaded.nodes), loaded.journal);
|
|
19103
|
+
const events = [
|
|
19104
|
+
...baselineNodeIds.length > 0 ? [makeEvent("journal.baseline", { node_ids: baselineNodeIds }, { actor: MCP_ACTOR })] : [],
|
|
19105
|
+
...toJournalEvents(inputs, MCP_ACTOR)
|
|
19106
|
+
];
|
|
17280
19107
|
const nextNodes = next.nodes ?? loaded.nodes;
|
|
17281
19108
|
const nextEdges = next.edges ?? loaded.edges;
|
|
17282
19109
|
const candidate = {
|
|
@@ -17289,9 +19116,10 @@ function persistMutation(bundlePath, loaded, next, inputs) {
|
|
|
17289
19116
|
if (result.errors.length > 0) {
|
|
17290
19117
|
return { ok: false, errors: result.errors, warnings: result.warnings };
|
|
17291
19118
|
}
|
|
17292
|
-
const
|
|
19119
|
+
const journalOnDisk = loaded.sidecarLoaded || loaded.archivesLoaded.length > 0;
|
|
19120
|
+
const embeddedJournal = !journalOnDisk && loaded.bundle.journal !== void 0;
|
|
17293
19121
|
if (embeddedJournal) {
|
|
17294
|
-
|
|
19122
|
+
writeFileSync3(bundlePath, serializeBundle(candidate));
|
|
17295
19123
|
} else {
|
|
17296
19124
|
const journalPath = journalPathFor(bundlePath);
|
|
17297
19125
|
for (const event of events) {
|
|
@@ -17300,7 +19128,7 @@ function persistMutation(bundlePath, loaded, next, inputs) {
|
|
|
17300
19128
|
if (next.nodes !== void 0 || next.edges !== void 0) {
|
|
17301
19129
|
const snapshot = { ...loaded.bundle, nodes: nextNodes, edges: nextEdges };
|
|
17302
19130
|
delete snapshot.journal;
|
|
17303
|
-
|
|
19131
|
+
writeFileSync3(bundlePath, serializeBundle(snapshot));
|
|
17304
19132
|
}
|
|
17305
19133
|
}
|
|
17306
19134
|
return { ok: true, warnings: result.warnings, events };
|
|
@@ -17372,9 +19200,12 @@ function createRemoteStore(options) {
|
|
|
17372
19200
|
edges,
|
|
17373
19201
|
journal,
|
|
17374
19202
|
sidecarLoaded: false,
|
|
17375
|
-
// Nothing was folded in from a JSONL sidecar
|
|
17376
|
-
// findings — hosted journals arrive already
|
|
19203
|
+
// Nothing was folded in from a JSONL sidecar or a compaction archive,
|
|
19204
|
+
// so there are no line findings — hosted journals arrive already
|
|
19205
|
+
// parsed, and compaction is a repo-mode concern.
|
|
17377
19206
|
sidecarFindings: [],
|
|
19207
|
+
archivesLoaded: [],
|
|
19208
|
+
archiveFindings: [],
|
|
17378
19209
|
get result() {
|
|
17379
19210
|
return validate();
|
|
17380
19211
|
},
|
|
@@ -17439,13 +19270,13 @@ function describeFailure(status, body) {
|
|
|
17439
19270
|
}
|
|
17440
19271
|
|
|
17441
19272
|
// src/config.ts
|
|
17442
|
-
import { readFileSync as
|
|
17443
|
-
import { join as
|
|
19273
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
19274
|
+
import { join as join5 } from "node:path";
|
|
17444
19275
|
var LINK_FILE = "docs/arkaik/arkaik.json";
|
|
17445
19276
|
var DEFAULT_BASE_URL = "https://arkaik.app";
|
|
17446
19277
|
function readLinkFile(cwd) {
|
|
17447
19278
|
try {
|
|
17448
|
-
const parsed = JSON.parse(
|
|
19279
|
+
const parsed = JSON.parse(readFileSync5(join5(cwd, LINK_FILE), "utf8"));
|
|
17449
19280
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
17450
19281
|
return parsed;
|
|
17451
19282
|
} catch {
|
|
@@ -17486,7 +19317,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
|
|
|
17486
19317
|
}
|
|
17487
19318
|
|
|
17488
19319
|
// src/index.ts
|
|
17489
|
-
var VERSION = "0.
|
|
19320
|
+
var VERSION = "0.3.0";
|
|
17490
19321
|
var argv = process.argv.slice(2);
|
|
17491
19322
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
17492
19323
|
process.stdout.write(
|
|
@@ -17514,23 +19345,34 @@ if (argv.includes("--help") || argv.includes("-h")) {
|
|
|
17514
19345
|
function resolveStore() {
|
|
17515
19346
|
const remote = resolveRemoteConfig(argv, process.env, process.cwd());
|
|
17516
19347
|
if (remote.mode === "remote") {
|
|
17517
|
-
return
|
|
17518
|
-
|
|
17519
|
-
|
|
17520
|
-
|
|
17521
|
-
|
|
19348
|
+
return {
|
|
19349
|
+
store: createRemoteStore({
|
|
19350
|
+
baseUrl: remote.baseUrl,
|
|
19351
|
+
projectId: remote.projectId,
|
|
19352
|
+
token: remote.token
|
|
19353
|
+
})
|
|
19354
|
+
};
|
|
17522
19355
|
}
|
|
17523
|
-
|
|
19356
|
+
const bundlePath = resolveBundlePath(argv, process.env);
|
|
19357
|
+
return { store: createFileStore(bundlePath), qualityRoot: qualityRootFor(bundlePath) };
|
|
19358
|
+
}
|
|
19359
|
+
function qualityRootFor(bundlePath) {
|
|
19360
|
+
if (process.env.ARKAIK_QUALITY_ROOT) return resolve3(process.env.ARKAIK_QUALITY_ROOT);
|
|
19361
|
+
const dir = dirname4(bundlePath);
|
|
19362
|
+
const parent = dirname4(dir);
|
|
19363
|
+
if (dir.endsWith(`${sep}arkaik`) && parent.endsWith(`${sep}docs`)) return dirname4(parent);
|
|
19364
|
+
return dir;
|
|
17524
19365
|
}
|
|
17525
19366
|
var store;
|
|
19367
|
+
var qualityRoot;
|
|
17526
19368
|
try {
|
|
17527
|
-
store = resolveStore();
|
|
19369
|
+
({ store, qualityRoot } = resolveStore());
|
|
17528
19370
|
} catch (error51) {
|
|
17529
19371
|
process.stderr.write(`arkaik-mcp: ${error51.message}
|
|
17530
19372
|
`);
|
|
17531
19373
|
process.exit(1);
|
|
17532
19374
|
}
|
|
17533
|
-
var { tools, handlers } = buildCatalog({ store });
|
|
19375
|
+
var { tools, handlers } = buildCatalog({ store, qualityRoot });
|
|
17534
19376
|
process.stderr.write(`arkaik-mcp v${VERSION} \u2014 ${store.describe()}
|
|
17535
19377
|
`);
|
|
17536
19378
|
startServer({
|