arkaik-mcp 0.2.3 → 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/dist/assets/kritik/library.json +5854 -0
- package/dist/index.js +1514 -133
- package/package.json +1 -1
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";
|
|
@@ -15281,7 +15284,12 @@ var DeliverableShippedEventSchema = external_exports.object({
|
|
|
15281
15284
|
summary: external_exports.string().optional(),
|
|
15282
15285
|
url: external_exports.string().optional(),
|
|
15283
15286
|
node_ids: external_exports.array(external_exports.string()).optional(),
|
|
15284
|
-
platform: PlatformSchema.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." })
|
|
15285
15293
|
}).catchall(external_exports.unknown());
|
|
15286
15294
|
var IdeaProposedEventSchema = external_exports.object({
|
|
15287
15295
|
...envelope,
|
|
@@ -15317,6 +15325,48 @@ var RefStatusChangedEventSchema = external_exports.object({
|
|
|
15317
15325
|
synced_at: external_exports.string()
|
|
15318
15326
|
}).catchall(external_exports.unknown());
|
|
15319
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());
|
|
15320
15370
|
var JOURNAL_EVENT_SCHEMAS = {
|
|
15321
15371
|
"node.created": NodeCreatedEventSchema,
|
|
15322
15372
|
"node.updated": NodeUpdatedEventSchema,
|
|
@@ -15332,7 +15382,11 @@ var JOURNAL_EVENT_SCHEMAS = {
|
|
|
15332
15382
|
"ref.added": RefAddedEventSchema,
|
|
15333
15383
|
"ref.removed": RefRemovedEventSchema,
|
|
15334
15384
|
"ref.status_changed": RefStatusChangedEventSchema,
|
|
15335
|
-
"journal.baseline": JournalBaselineEventSchema
|
|
15385
|
+
"journal.baseline": JournalBaselineEventSchema,
|
|
15386
|
+
"quality.audit.completed": QualityAuditCompletedEventSchema,
|
|
15387
|
+
"quality.finding.opened": QualityFindingOpenedEventSchema,
|
|
15388
|
+
"quality.finding.resolved": QualityFindingResolvedEventSchema,
|
|
15389
|
+
"quality.signal.tripped": QualitySignalTrippedEventSchema
|
|
15336
15390
|
};
|
|
15337
15391
|
var KnownJournalEventSchema = external_exports.union([
|
|
15338
15392
|
NodeCreatedEventSchema,
|
|
@@ -15349,9 +15403,113 @@ var KnownJournalEventSchema = external_exports.union([
|
|
|
15349
15403
|
RefAddedEventSchema,
|
|
15350
15404
|
RefRemovedEventSchema,
|
|
15351
15405
|
RefStatusChangedEventSchema,
|
|
15352
|
-
JournalBaselineEventSchema
|
|
15406
|
+
JournalBaselineEventSchema,
|
|
15407
|
+
QualityAuditCompletedEventSchema,
|
|
15408
|
+
QualityFindingOpenedEventSchema,
|
|
15409
|
+
QualityFindingResolvedEventSchema,
|
|
15410
|
+
QualitySignalTrippedEventSchema
|
|
15353
15411
|
]);
|
|
15354
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
|
+
|
|
15355
15513
|
// ../schema/src/bundle.ts
|
|
15356
15514
|
var PlatformStatusMapSchema = external_exports.partialRecord(
|
|
15357
15515
|
PlatformSchema,
|
|
@@ -15493,7 +15651,8 @@ var ProjectMetadataSchema = external_exports.object({
|
|
|
15493
15651
|
}),
|
|
15494
15652
|
products: external_exports.array(ProductDefinitionSchema).optional().meta({
|
|
15495
15653
|
description: "Product definitions (docs/spec/bundle-format.md \xA7 Products) \u2014 additive; unknown fields preserved."
|
|
15496
|
-
})
|
|
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." })
|
|
15497
15656
|
}).catchall(external_exports.unknown()).meta({ id: "ProjectMetadata", description: "Optional project-level UI settings." });
|
|
15498
15657
|
var ProjectSchema = external_exports.object({
|
|
15499
15658
|
id: external_exports.string().meta({ description: "Unique project identifier." }),
|
|
@@ -15521,6 +15680,9 @@ var ProjectBundleSchema = external_exports.object({
|
|
|
15521
15680
|
edges: external_exports.array(EdgeSchema).meta({ description: "All edges (relationships) between nodes." }),
|
|
15522
15681
|
journal: external_exports.array(JournalEventSchema).optional().meta({
|
|
15523
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."
|
|
15524
15686
|
})
|
|
15525
15687
|
}).catchall(external_exports.unknown()).meta({
|
|
15526
15688
|
id: "ProjectBundle",
|
|
@@ -15740,6 +15902,207 @@ function listMaps(project) {
|
|
|
15740
15902
|
return [...BUILT_IN_MAPS, ...custom2];
|
|
15741
15903
|
}
|
|
15742
15904
|
|
|
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
|
+
}
|
|
15953
|
+
}
|
|
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
|
+
};
|
|
16104
|
+
}
|
|
16105
|
+
|
|
15743
16106
|
// ../schema/src/validate.ts
|
|
15744
16107
|
var VALID_STAGES = ["beta", "monitoring", "deprecated"];
|
|
15745
16108
|
var VALID_VIEW_CARD_VARIANTS = ["compact", "large"];
|
|
@@ -16436,6 +16799,151 @@ function validateBundle(input) {
|
|
|
16436
16799
|
for (const id of flowGraph.keys()) {
|
|
16437
16800
|
dfs(id);
|
|
16438
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
|
+
}
|
|
16439
16947
|
for (const finding of crossCheckJournal(bundle)) findings.push(finding);
|
|
16440
16948
|
return result();
|
|
16441
16949
|
}
|
|
@@ -17106,6 +17614,962 @@ function applyOps(input, ops) {
|
|
|
17106
17614
|
return { nodes, edges, eventInputs, synthesizedEdges, cascadedEdgeIds };
|
|
17107
17615
|
}
|
|
17108
17616
|
|
|
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);
|
|
17702
|
+
return {
|
|
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
|
+
|
|
17109
18573
|
// src/tools.ts
|
|
17110
18574
|
async function load(ctx) {
|
|
17111
18575
|
let graph;
|
|
@@ -17122,7 +18586,7 @@ async function load(ctx) {
|
|
|
17122
18586
|
journal: graph.journal
|
|
17123
18587
|
};
|
|
17124
18588
|
}
|
|
17125
|
-
function
|
|
18589
|
+
function requireString2(args, key) {
|
|
17126
18590
|
const value = args[key];
|
|
17127
18591
|
if (typeof value !== "string" || value.length === 0) {
|
|
17128
18592
|
throw new ToolError(`\`${key}\` is required and must be a non-empty string.`);
|
|
@@ -17254,7 +18718,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17254
18718
|
}
|
|
17255
18719
|
},
|
|
17256
18720
|
async (args) => {
|
|
17257
|
-
const nodeId =
|
|
18721
|
+
const nodeId = requireString2(args, "node_id");
|
|
17258
18722
|
const { nodes, edges, journal } = await load(ctx);
|
|
17259
18723
|
const node = findNode(nodes, nodeId);
|
|
17260
18724
|
const nodesById = new Map(nodes.map((candidate) => [candidate.id, candidate]));
|
|
@@ -17348,7 +18812,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17348
18812
|
}
|
|
17349
18813
|
},
|
|
17350
18814
|
async (args) => {
|
|
17351
|
-
const mapId =
|
|
18815
|
+
const mapId = requireString2(args, "map_id");
|
|
17352
18816
|
const { nodes, edges, project } = await load(ctx);
|
|
17353
18817
|
const definition = listMaps(project).find((candidate) => candidate.id === mapId);
|
|
17354
18818
|
if (!definition) throw new ToolError(`No map with id "${mapId}".`);
|
|
@@ -17392,8 +18856,8 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17392
18856
|
},
|
|
17393
18857
|
async (args) => {
|
|
17394
18858
|
const graph = await load(ctx);
|
|
17395
|
-
const species =
|
|
17396
|
-
const title =
|
|
18859
|
+
const species = requireString2(args, "species");
|
|
18860
|
+
const title = requireString2(args, "title");
|
|
17397
18861
|
const platforms = Array.isArray(args.platforms) ? args.platforms : [];
|
|
17398
18862
|
const node = {
|
|
17399
18863
|
id: deriveNodeId(species, title, graph.nodes.map((candidate) => candidate.id)),
|
|
@@ -17441,7 +18905,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17441
18905
|
}
|
|
17442
18906
|
},
|
|
17443
18907
|
async (args) => {
|
|
17444
|
-
const nodeId =
|
|
18908
|
+
const nodeId = requireString2(args, "node_id");
|
|
17445
18909
|
if (typeof args.patch !== "object" || args.patch === null || Array.isArray(args.patch)) {
|
|
17446
18910
|
throw new ToolError("`patch` is required and must be an object.");
|
|
17447
18911
|
}
|
|
@@ -17481,7 +18945,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17481
18945
|
}
|
|
17482
18946
|
},
|
|
17483
18947
|
async (args) => {
|
|
17484
|
-
const nodeId =
|
|
18948
|
+
const nodeId = requireString2(args, "node_id");
|
|
17485
18949
|
const graph = await load(ctx);
|
|
17486
18950
|
const node = findNode(graph.nodes, nodeId);
|
|
17487
18951
|
const ops = [{ op: "delete_node", node_id: nodeId }];
|
|
@@ -17511,9 +18975,9 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17511
18975
|
}
|
|
17512
18976
|
},
|
|
17513
18977
|
async (args) => {
|
|
17514
|
-
const sourceId =
|
|
17515
|
-
const targetId =
|
|
17516
|
-
const edgeType =
|
|
18978
|
+
const sourceId = requireString2(args, "source_id");
|
|
18979
|
+
const targetId = requireString2(args, "target_id");
|
|
18980
|
+
const edgeType = requireString2(args, "edge_type");
|
|
17517
18981
|
const graph = await load(ctx);
|
|
17518
18982
|
const edge = {
|
|
17519
18983
|
id: edgeId(sourceId, targetId),
|
|
@@ -17548,7 +19012,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17548
19012
|
}
|
|
17549
19013
|
},
|
|
17550
19014
|
async (args) => {
|
|
17551
|
-
const edgeIdArg =
|
|
19015
|
+
const edgeIdArg = requireString2(args, "edge_id");
|
|
17552
19016
|
const graph = await load(ctx);
|
|
17553
19017
|
const edge = graph.edges.find((candidate) => candidate.id === edgeIdArg);
|
|
17554
19018
|
if (!edge) throw new ToolError(`No edge with id "${edgeIdArg}".`);
|
|
@@ -17564,7 +19028,7 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17564
19028
|
}
|
|
17565
19029
|
);
|
|
17566
19030
|
const journalOnly = (type) => async (args) => {
|
|
17567
|
-
const title =
|
|
19031
|
+
const title = requireString2(args, "title");
|
|
17568
19032
|
const graph = await load(ctx);
|
|
17569
19033
|
const payload = { title };
|
|
17570
19034
|
if (typeof args.description === "string") payload.description = args.description;
|
|
@@ -17610,117 +19074,23 @@ ${node.description ?? ""}`.toLowerCase();
|
|
|
17610
19074
|
},
|
|
17611
19075
|
journalOnly("request.filed")
|
|
17612
19076
|
);
|
|
19077
|
+
const kritik = buildKritikCatalog(ctx);
|
|
19078
|
+
tools2.push(...kritik.tools);
|
|
19079
|
+
Object.assign(handlers2, kritik.handlers);
|
|
17613
19080
|
return { tools: tools2, handlers: handlers2 };
|
|
17614
19081
|
}
|
|
17615
19082
|
|
|
17616
19083
|
// src/store.ts
|
|
17617
|
-
import { writeFileSync as
|
|
17618
|
-
import { resolve } from "node:path";
|
|
17619
|
-
|
|
17620
|
-
// ../cli/src/lib/bundle-io.ts
|
|
17621
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
17622
|
-
function readBundle(filePath) {
|
|
17623
|
-
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
17624
|
-
let parsed;
|
|
17625
|
-
try {
|
|
17626
|
-
parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
17627
|
-
} catch (e) {
|
|
17628
|
-
throw new Error(`Cannot parse JSON \u2014 ${e.message}`);
|
|
17629
|
-
}
|
|
17630
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
17631
|
-
throw new Error("Bundle must be a JSON object.");
|
|
17632
|
-
}
|
|
17633
|
-
const record2 = parsed;
|
|
17634
|
-
if (!Array.isArray(record2.nodes)) return record2;
|
|
17635
|
-
return migrateStatusVocabulary(record2);
|
|
17636
|
-
}
|
|
17637
|
-
|
|
17638
|
-
// ../cli/src/lib/journal-io.ts
|
|
17639
|
-
import { appendFileSync, existsSync as existsSync2, mkdirSync, readdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
17640
|
-
import { dirname, join } from "node:path";
|
|
17641
|
-
var JOURNAL_SIDECAR = "journal.jsonl";
|
|
17642
|
-
function journalPathFor(bundlePath) {
|
|
17643
|
-
return join(dirname(bundlePath), JOURNAL_SIDECAR);
|
|
17644
|
-
}
|
|
17645
|
-
function archivePathsFor(journalPath) {
|
|
17646
|
-
const dir = join(dirname(journalPath), "journal");
|
|
17647
|
-
if (!existsSync2(dir)) return [];
|
|
17648
|
-
return readdirSync(dir).filter((name) => name.startsWith("archive-") && name.endsWith(".jsonl")).sort().map((name) => join(dir, name));
|
|
17649
|
-
}
|
|
17650
|
-
function toLine(event) {
|
|
17651
|
-
return JSON.stringify(event) + "\n";
|
|
17652
|
-
}
|
|
17653
|
-
function appendJournalEvent(journalPath, event) {
|
|
17654
|
-
const line = toLine(event);
|
|
17655
|
-
if (!existsSync2(journalPath)) {
|
|
17656
|
-
mkdirSync(dirname(journalPath), { recursive: true });
|
|
17657
|
-
writeFileSync(journalPath, line);
|
|
17658
|
-
return;
|
|
17659
|
-
}
|
|
17660
|
-
const existing = readFileSync2(journalPath, "utf8");
|
|
17661
|
-
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
17662
|
-
appendFileSync(journalPath, prefix + line);
|
|
17663
|
-
}
|
|
17664
|
-
|
|
17665
|
-
// ../cli/src/lib/bundle-validate.ts
|
|
17666
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
17667
|
-
import { basename } from "node:path";
|
|
17668
|
-
function validateBundleAt(filePath) {
|
|
17669
|
-
const bundle = readBundle(filePath);
|
|
17670
|
-
const loose = bundle;
|
|
17671
|
-
if (!loose.project || !loose.nodes || !loose.edges) {
|
|
17672
|
-
throw new Error("Missing top-level keys (project, nodes, edges).");
|
|
17673
|
-
}
|
|
17674
|
-
let sidecarFindings = [];
|
|
17675
|
-
let sidecarLoaded = false;
|
|
17676
|
-
const archiveFindings = [];
|
|
17677
|
-
const archivesLoaded = [];
|
|
17678
|
-
if (loose.journal === void 0) {
|
|
17679
|
-
const sidecarPath = journalPathFor(filePath);
|
|
17680
|
-
const folded = [];
|
|
17681
|
-
if (existsSync3(sidecarPath)) {
|
|
17682
|
-
const { events, findings } = parseJournalLines(readFileSync3(sidecarPath, "utf8"));
|
|
17683
|
-
sidecarFindings = findings;
|
|
17684
|
-
sidecarLoaded = true;
|
|
17685
|
-
folded.push(...events);
|
|
17686
|
-
}
|
|
17687
|
-
for (const archivePath of archivePathsFor(sidecarPath)) {
|
|
17688
|
-
const { events, findings } = parseJournalLines(readFileSync3(archivePath, "utf8"));
|
|
17689
|
-
const file2 = basename(archivePath);
|
|
17690
|
-
for (const finding of findings) archiveFindings.push({ ...finding, file: file2 });
|
|
17691
|
-
archivesLoaded.push(file2);
|
|
17692
|
-
folded.push(...events);
|
|
17693
|
-
}
|
|
17694
|
-
if (sidecarLoaded || archivesLoaded.length > 0) loose.journal = folded;
|
|
17695
|
-
}
|
|
17696
|
-
const nodes = Array.isArray(loose.nodes) ? loose.nodes : [];
|
|
17697
|
-
const edges = Array.isArray(loose.edges) ? loose.edges : [];
|
|
17698
|
-
const journal = Array.isArray(loose.journal) ? loose.journal : [];
|
|
17699
|
-
const result = validateBundle(bundle);
|
|
17700
|
-
const valid = sidecarFindings.length === 0 && archiveFindings.length === 0 && result.errors.length === 0;
|
|
17701
|
-
return {
|
|
17702
|
-
bundle,
|
|
17703
|
-
nodes,
|
|
17704
|
-
edges,
|
|
17705
|
-
journal,
|
|
17706
|
-
sidecarLoaded,
|
|
17707
|
-
sidecarFindings,
|
|
17708
|
-
archivesLoaded,
|
|
17709
|
-
archiveFindings,
|
|
17710
|
-
result,
|
|
17711
|
-
valid
|
|
17712
|
-
};
|
|
17713
|
-
}
|
|
17714
|
-
|
|
17715
|
-
// src/store.ts
|
|
19084
|
+
import { writeFileSync as writeFileSync3 } from "node:fs";
|
|
19085
|
+
import { resolve as resolve2 } from "node:path";
|
|
17716
19086
|
var MCP_ACTOR = "arkaik-mcp";
|
|
17717
|
-
var
|
|
19087
|
+
var DEFAULT_BUNDLE_PATH2 = "docs/arkaik/bundle.json";
|
|
17718
19088
|
function resolveBundlePath(argv2, env) {
|
|
17719
19089
|
const flagIndex = argv2.indexOf("--bundle");
|
|
17720
19090
|
const flagValue2 = flagIndex !== -1 ? argv2[flagIndex + 1] : void 0;
|
|
17721
|
-
if (flagValue2) return
|
|
17722
|
-
if (env.ARKAIK_BUNDLE) return
|
|
17723
|
-
return
|
|
19091
|
+
if (flagValue2) return resolve2(flagValue2);
|
|
19092
|
+
if (env.ARKAIK_BUNDLE) return resolve2(env.ARKAIK_BUNDLE);
|
|
19093
|
+
return resolve2(DEFAULT_BUNDLE_PATH2);
|
|
17724
19094
|
}
|
|
17725
19095
|
function loadBundle(bundlePath) {
|
|
17726
19096
|
return validateBundleAt(bundlePath);
|
|
@@ -17749,7 +19119,7 @@ function persistMutation(bundlePath, loaded, next, inputs) {
|
|
|
17749
19119
|
const journalOnDisk = loaded.sidecarLoaded || loaded.archivesLoaded.length > 0;
|
|
17750
19120
|
const embeddedJournal = !journalOnDisk && loaded.bundle.journal !== void 0;
|
|
17751
19121
|
if (embeddedJournal) {
|
|
17752
|
-
|
|
19122
|
+
writeFileSync3(bundlePath, serializeBundle(candidate));
|
|
17753
19123
|
} else {
|
|
17754
19124
|
const journalPath = journalPathFor(bundlePath);
|
|
17755
19125
|
for (const event of events) {
|
|
@@ -17758,7 +19128,7 @@ function persistMutation(bundlePath, loaded, next, inputs) {
|
|
|
17758
19128
|
if (next.nodes !== void 0 || next.edges !== void 0) {
|
|
17759
19129
|
const snapshot = { ...loaded.bundle, nodes: nextNodes, edges: nextEdges };
|
|
17760
19130
|
delete snapshot.journal;
|
|
17761
|
-
|
|
19131
|
+
writeFileSync3(bundlePath, serializeBundle(snapshot));
|
|
17762
19132
|
}
|
|
17763
19133
|
}
|
|
17764
19134
|
return { ok: true, warnings: result.warnings, events };
|
|
@@ -17900,13 +19270,13 @@ function describeFailure(status, body) {
|
|
|
17900
19270
|
}
|
|
17901
19271
|
|
|
17902
19272
|
// src/config.ts
|
|
17903
|
-
import { readFileSync as
|
|
17904
|
-
import { join as
|
|
19273
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
19274
|
+
import { join as join5 } from "node:path";
|
|
17905
19275
|
var LINK_FILE = "docs/arkaik/arkaik.json";
|
|
17906
19276
|
var DEFAULT_BASE_URL = "https://arkaik.app";
|
|
17907
19277
|
function readLinkFile(cwd) {
|
|
17908
19278
|
try {
|
|
17909
|
-
const parsed = JSON.parse(
|
|
19279
|
+
const parsed = JSON.parse(readFileSync5(join5(cwd, LINK_FILE), "utf8"));
|
|
17910
19280
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
17911
19281
|
return parsed;
|
|
17912
19282
|
} catch {
|
|
@@ -17947,7 +19317,7 @@ function resolveRemoteConfig(argv2, env, cwd) {
|
|
|
17947
19317
|
}
|
|
17948
19318
|
|
|
17949
19319
|
// src/index.ts
|
|
17950
|
-
var VERSION = "0.
|
|
19320
|
+
var VERSION = "0.3.0";
|
|
17951
19321
|
var argv = process.argv.slice(2);
|
|
17952
19322
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
17953
19323
|
process.stdout.write(
|
|
@@ -17975,23 +19345,34 @@ if (argv.includes("--help") || argv.includes("-h")) {
|
|
|
17975
19345
|
function resolveStore() {
|
|
17976
19346
|
const remote = resolveRemoteConfig(argv, process.env, process.cwd());
|
|
17977
19347
|
if (remote.mode === "remote") {
|
|
17978
|
-
return
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
19348
|
+
return {
|
|
19349
|
+
store: createRemoteStore({
|
|
19350
|
+
baseUrl: remote.baseUrl,
|
|
19351
|
+
projectId: remote.projectId,
|
|
19352
|
+
token: remote.token
|
|
19353
|
+
})
|
|
19354
|
+
};
|
|
17983
19355
|
}
|
|
17984
|
-
|
|
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;
|
|
17985
19365
|
}
|
|
17986
19366
|
var store;
|
|
19367
|
+
var qualityRoot;
|
|
17987
19368
|
try {
|
|
17988
|
-
store = resolveStore();
|
|
19369
|
+
({ store, qualityRoot } = resolveStore());
|
|
17989
19370
|
} catch (error51) {
|
|
17990
19371
|
process.stderr.write(`arkaik-mcp: ${error51.message}
|
|
17991
19372
|
`);
|
|
17992
19373
|
process.exit(1);
|
|
17993
19374
|
}
|
|
17994
|
-
var { tools, handlers } = buildCatalog({ store });
|
|
19375
|
+
var { tools, handlers } = buildCatalog({ store, qualityRoot });
|
|
17995
19376
|
process.stderr.write(`arkaik-mcp v${VERSION} \u2014 ${store.describe()}
|
|
17996
19377
|
`);
|
|
17997
19378
|
startServer({
|