@jupiterone/jupiterone-mcp 2.4.3 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/client/graphql/mutations.d.ts +3 -0
- package/dist/client/graphql/mutations.d.ts.map +1 -1
- package/dist/client/graphql/mutations.js +20 -1
- package/dist/client/graphql/mutations.js.map +1 -1
- package/dist/client/graphql/queries.d.ts +27 -0
- package/dist/client/graphql/queries.d.ts.map +1 -1
- package/dist/client/graphql/queries.js +186 -1
- package/dist/client/graphql/queries.js.map +1 -1
- package/dist/client/jupiterone-client.d.ts +26 -1
- package/dist/client/jupiterone-client.d.ts.map +1 -1
- package/dist/client/jupiterone-client.js +44 -3
- package/dist/client/jupiterone-client.js.map +1 -1
- package/dist/client/sanitize-error.d.ts +2 -0
- package/dist/client/sanitize-error.d.ts.map +1 -1
- package/dist/client/sanitize-error.js +9 -1
- package/dist/client/sanitize-error.js.map +1 -1
- package/dist/client/services/compliance-service.d.ts +61 -0
- package/dist/client/services/compliance-service.d.ts.map +1 -0
- package/dist/client/services/compliance-service.js +246 -0
- package/dist/client/services/compliance-service.js.map +1 -0
- package/dist/client/services/rule-service.d.ts +4 -6
- package/dist/client/services/rule-service.d.ts.map +1 -1
- package/dist/client/services/rule-service.js +6 -21
- package/dist/client/services/rule-service.js.map +1 -1
- package/dist/generated/description-map.d.ts.map +1 -1
- package/dist/generated/description-map.js +736 -4
- package/dist/generated/description-map.js.map +1 -1
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +1 -0
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/tools/account.d.ts.map +1 -1
- package/dist/server/tools/account.js +4 -4
- package/dist/server/tools/account.js.map +1 -1
- package/dist/server/tools/compliance/attestations.d.ts +3 -0
- package/dist/server/tools/compliance/attestations.d.ts.map +1 -0
- package/dist/server/tools/compliance/attestations.js +560 -0
- package/dist/server/tools/compliance/attestations.js.map +1 -0
- package/dist/server/tools/compliance/controls.d.ts +40 -0
- package/dist/server/tools/compliance/controls.d.ts.map +1 -0
- package/dist/server/tools/compliance/controls.js +865 -0
- package/dist/server/tools/compliance/controls.js.map +1 -0
- package/dist/server/tools/compliance/index.d.ts +21 -0
- package/dist/server/tools/compliance/index.d.ts.map +1 -0
- package/dist/server/tools/compliance/index.js +45 -0
- package/dist/server/tools/compliance/index.js.map +1 -0
- package/dist/server/tools/compliance/schemas.d.ts +365 -0
- package/dist/server/tools/compliance/schemas.d.ts.map +1 -0
- package/dist/server/tools/compliance/schemas.js +292 -0
- package/dist/server/tools/compliance/schemas.js.map +1 -0
- package/dist/server/tools/compliance/shared.d.ts +141 -0
- package/dist/server/tools/compliance/shared.d.ts.map +1 -0
- package/dist/server/tools/compliance/shared.js +231 -0
- package/dist/server/tools/compliance/shared.js.map +1 -0
- package/dist/server/tools/compliance/summary.d.ts +11 -0
- package/dist/server/tools/compliance/summary.d.ts.map +1 -0
- package/dist/server/tools/compliance/summary.js +897 -0
- package/dist/server/tools/compliance/summary.js.map +1 -0
- package/dist/server/tools/errors.d.ts +17 -1
- package/dist/server/tools/errors.d.ts.map +1 -1
- package/dist/server/tools/errors.js +59 -4
- package/dist/server/tools/errors.js.map +1 -1
- package/dist/server/tools/index.d.ts.map +1 -1
- package/dist/server/tools/index.js +2 -0
- package/dist/server/tools/index.js.map +1 -1
- package/dist/server/tools/rules.d.ts +35 -1
- package/dist/server/tools/rules.d.ts.map +1 -1
- package/dist/server/tools/rules.js +252 -9
- package/dist/server/tools/rules.js.map +1 -1
- package/dist/server/tools/threat.js +1 -1
- package/dist/server/tools/threat.js.map +1 -1
- package/dist/server/tools/usage.d.ts +6 -0
- package/dist/server/tools/usage.d.ts.map +1 -1
- package/dist/server/tools/usage.js +257 -6
- package/dist/server/tools/usage.js.map +1 -1
- package/dist/types/jupiterone.d.ts +247 -0
- package/dist/types/jupiterone.d.ts.map +1 -1
- package/dist/utils/expires-on.d.ts +24 -0
- package/dist/utils/expires-on.d.ts.map +1 -0
- package/dist/utils/expires-on.js +79 -0
- package/dist/utils/expires-on.js.map +1 -0
- package/node_modules/dtrace-provider/build/Makefile +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.summaryTools = exports.GRAPH_MAX_PAGES = exports.GRAPH_PAGE_SIZE = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const j1ql_service_js_1 = require("../../../client/services/j1ql-service.js");
|
|
6
|
+
const expires_on_js_1 = require("../../../utils/expires-on.js");
|
|
7
|
+
const load_description_js_1 = require("../../../utils/load-description.js");
|
|
8
|
+
const result_js_1 = require("../result.js");
|
|
9
|
+
const types_js_1 = require("../types.js");
|
|
10
|
+
const schemas_js_1 = require("./schemas.js");
|
|
11
|
+
const shared_js_1 = require("./shared.js");
|
|
12
|
+
/** get-compliance-summary: the frameworks scorecard and the one-framework drill. */
|
|
13
|
+
/** Passing share of the requirements that have a verdict; null when none has one. */
|
|
14
|
+
function healthPct(stats) {
|
|
15
|
+
const passing = stats?.numberOfPassingRequirements ?? 0;
|
|
16
|
+
const failing = stats?.numberOfFailingRequirements ?? 0;
|
|
17
|
+
const assessed = passing + failing;
|
|
18
|
+
return assessed > 0 ? Math.round((100 * passing) / assessed) : null;
|
|
19
|
+
}
|
|
20
|
+
function frameworkScore(framework, stats, subdomain) {
|
|
21
|
+
return {
|
|
22
|
+
id: framework.id,
|
|
23
|
+
name: framework.name,
|
|
24
|
+
url: (0, shared_js_1.frameworkUrl)(framework.id, subdomain),
|
|
25
|
+
source: framework.source ?? null,
|
|
26
|
+
sourceId: framework.sourceId ?? null,
|
|
27
|
+
owner: framework.owner ?? null,
|
|
28
|
+
importStatus: framework.status?.status ?? null,
|
|
29
|
+
controls: stats
|
|
30
|
+
? {
|
|
31
|
+
total: stats.numberOfControls,
|
|
32
|
+
passing: stats.numberOfPassingControls,
|
|
33
|
+
failing: stats.numberOfFailingControls,
|
|
34
|
+
attested: stats.numberOfAttestedControls,
|
|
35
|
+
withTests: stats.numberOfControlsWithTests,
|
|
36
|
+
}
|
|
37
|
+
: null,
|
|
38
|
+
requirements: stats
|
|
39
|
+
? {
|
|
40
|
+
total: stats.numberOfRequirements,
|
|
41
|
+
passing: stats.numberOfPassingRequirements,
|
|
42
|
+
failing: stats.numberOfFailingRequirements,
|
|
43
|
+
failingCritical: stats.numberOfFailingCriticalRequirements,
|
|
44
|
+
}
|
|
45
|
+
: null,
|
|
46
|
+
healthPct: healthPct(stats),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The scorecard counts, STATS_CHUNK_SIZE frameworks per read, every read issued at once and raced
|
|
51
|
+
* against `deadlineAt`. The backend computes requirement stats per framework, and one read for all
|
|
52
|
+
* of j1dev's 62 frameworks took 37.9 s on the only one of five bare summaries that did not hit the
|
|
53
|
+
* remote's 55 s abort (2026-10-14). A chunk that times out or fails leaves its frameworks in
|
|
54
|
+
* `incomplete`. Only when every chunk failed outright does the call fail, so an access refusal
|
|
55
|
+
* still surfaces.
|
|
56
|
+
*/
|
|
57
|
+
async function readStats(client, ids, deadlineAt, options) {
|
|
58
|
+
if (Date.now() >= deadlineAt)
|
|
59
|
+
return { stats: [], incomplete: ids, chunkMaxMs: null };
|
|
60
|
+
const chunks = [];
|
|
61
|
+
for (let start = 0; start < ids.length; start += shared_js_1.STATS_CHUNK_SIZE) {
|
|
62
|
+
chunks.push(ids.slice(start, start + shared_js_1.STATS_CHUNK_SIZE));
|
|
63
|
+
}
|
|
64
|
+
const settled = await Promise.allSettled(chunks.map(async (chunk) => {
|
|
65
|
+
const chunkStartedAt = Date.now();
|
|
66
|
+
const read = await (0, shared_js_1.withDeadline)(client.getControlFrameworkStats(chunk, options), deadlineAt);
|
|
67
|
+
return read === shared_js_1.DEADLINE_PASSED ? read : { stats: read, ms: Date.now() - chunkStartedAt };
|
|
68
|
+
}));
|
|
69
|
+
const stats = [];
|
|
70
|
+
const incomplete = [];
|
|
71
|
+
const failures = [];
|
|
72
|
+
let chunkMaxMs = null;
|
|
73
|
+
settled.forEach((result, index) => {
|
|
74
|
+
if (result.status === 'fulfilled' && result.value !== shared_js_1.DEADLINE_PASSED) {
|
|
75
|
+
stats.push(...result.value.stats);
|
|
76
|
+
chunkMaxMs = Math.max(chunkMaxMs ?? 0, result.value.ms);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
incomplete.push(...chunks[index]);
|
|
80
|
+
if (result.status === 'rejected')
|
|
81
|
+
failures.push(result.reason);
|
|
82
|
+
});
|
|
83
|
+
if (failures.length > 0 && failures.length === chunks.length)
|
|
84
|
+
throw failures[0];
|
|
85
|
+
for (const failure of failures)
|
|
86
|
+
console.error('Error reading framework stats:', failure);
|
|
87
|
+
return { stats, incomplete, chunkMaxMs };
|
|
88
|
+
}
|
|
89
|
+
function compareRequirements(a, b) {
|
|
90
|
+
const critical = Number(b.priority === 'CRITICAL') - Number(a.priority === 'CRITICAL');
|
|
91
|
+
return (critical ||
|
|
92
|
+
(a.section ?? '').localeCompare(b.section ?? '') ||
|
|
93
|
+
(a.identifier ?? '').localeCompare(b.identifier ?? ''));
|
|
94
|
+
}
|
|
95
|
+
const DRILL_PAGES = { limit: shared_js_1.FAILING_CONTROLS_PAGE_LIMIT, maxPages: shared_js_1.MAX_FAILING_CONTROL_PAGES };
|
|
96
|
+
/**
|
|
97
|
+
* The framework's failing controls as CCM counts them: LIVE and FAIL, asked of the API directly. A
|
|
98
|
+
* DRAFT, REVIEW or RETIRED control keeps the status of its last evaluation, so on j1dev's SOC 2 the
|
|
99
|
+
* stale FAILs of draft controls made 36 requirements look failing where CCM's own count said 5
|
|
100
|
+
* (2026-10-14). Failing controls are few; past MAX_FAILING_CONTROL_PAGES pages the rest are cut.
|
|
101
|
+
*/
|
|
102
|
+
async function failingLiveControls(client, frameworkId) {
|
|
103
|
+
const { items, complete } = await (0, shared_js_1.walkControls)(client, { frameworkId: [frameworkId], status: ['FAIL'], states: ['LIVE'] }, DRILL_PAGES);
|
|
104
|
+
return { controls: items, truncated: !complete };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* How many of the framework's LIVE controls pass on tests that saw no data. CCM counts them as
|
|
108
|
+
* passing, so the scorecard cannot tell a pass backed by evidence from one on no data: the AI-ASM
|
|
109
|
+
* session on j1dev needed list-controls and per-control reads to find 7 such passes behind 73%
|
|
110
|
+
* (2026-10-14). A count is decoration on the scorecard, so a failed or late read gives no count
|
|
111
|
+
* and says which: it came back null on most of the tester's drills with no reason given.
|
|
112
|
+
*/
|
|
113
|
+
async function passingWithoutDataCount(client, frameworkId, deadlineAt) {
|
|
114
|
+
if (Date.now() >= deadlineAt)
|
|
115
|
+
return { skipped: 'time_budget' };
|
|
116
|
+
try {
|
|
117
|
+
const read = await (0, shared_js_1.withDeadline)((0, shared_js_1.walkControls)(client, {
|
|
118
|
+
frameworkId: [frameworkId],
|
|
119
|
+
status: ['PASS'],
|
|
120
|
+
states: ['LIVE'],
|
|
121
|
+
effectiveness: 'NO_DATAPOINTS',
|
|
122
|
+
}, DRILL_PAGES), deadlineAt);
|
|
123
|
+
if (read === shared_js_1.DEADLINE_PASSED)
|
|
124
|
+
return { skipped: 'time_budget' };
|
|
125
|
+
return { count: read.items.length, truncated: !read.complete };
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Error counting controls that pass without data:', error);
|
|
129
|
+
return { skipped: 'read_failed' };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The requirements of up to MAX_REQUIREMENT_LOOKUPS failing controls, read concurrently and raced
|
|
134
|
+
* against `deadlineAt`. A lookup that fails is logged and counted as skipped rather than failing
|
|
135
|
+
* the summary, unless every lookup failed: then there is nothing to report and it throws.
|
|
136
|
+
*/
|
|
137
|
+
async function lookupRequirements(client, controls, deadlineAt) {
|
|
138
|
+
const admitted = controls.slice(0, shared_js_1.MAX_REQUIREMENT_LOOKUPS);
|
|
139
|
+
const settled = await Promise.allSettled(admitted.map(async (control) => {
|
|
140
|
+
if (Date.now() >= deadlineAt)
|
|
141
|
+
return shared_js_1.DEADLINE_PASSED;
|
|
142
|
+
const walk = await (0, shared_js_1.withDeadline)(client.listControlRequirements(control.id), deadlineAt);
|
|
143
|
+
return walk === shared_js_1.DEADLINE_PASSED
|
|
144
|
+
? walk
|
|
145
|
+
: { control, requirements: walk.requirements, complete: walk.complete };
|
|
146
|
+
}));
|
|
147
|
+
const failed = settled.filter((result) => result.status === 'rejected');
|
|
148
|
+
if (failed.length > 0 && failed.length === admitted.length)
|
|
149
|
+
throw failed[0].reason;
|
|
150
|
+
for (const failure of failed) {
|
|
151
|
+
console.error("Error reading a failing control's requirements:", failure.reason);
|
|
152
|
+
}
|
|
153
|
+
const answered = settled.flatMap((result) => result.status === 'fulfilled' && result.value !== shared_js_1.DEADLINE_PASSED ? [result.value] : []);
|
|
154
|
+
// A control whose requirement pages ran past that read's own cap keeps the rows it has, but its
|
|
155
|
+
// requirements were not all read; it counts under `cap` with the controls past the lookup cap
|
|
156
|
+
// (PR #55 review).
|
|
157
|
+
const cut = answered.filter((lookup) => !lookup.complete).length;
|
|
158
|
+
const skippedBy = {
|
|
159
|
+
timeBudget: settled.length - answered.length - failed.length,
|
|
160
|
+
cap: controls.length - admitted.length + cut,
|
|
161
|
+
readFailed: failed.length,
|
|
162
|
+
};
|
|
163
|
+
const read = answered.map(({ control, requirements }) => ({ control, requirements }));
|
|
164
|
+
return { read, skipped: controls.length - answered.length + cut, skippedBy };
|
|
165
|
+
}
|
|
166
|
+
/** Requirements of this framework with the failing controls that make them fail. */
|
|
167
|
+
function groupByRequirement(lookups, frameworkId) {
|
|
168
|
+
const byRequirement = new Map();
|
|
169
|
+
for (const { control, requirements } of lookups) {
|
|
170
|
+
for (const requirement of requirements) {
|
|
171
|
+
if (!(requirement.frameworkIds ?? []).includes(frameworkId))
|
|
172
|
+
continue;
|
|
173
|
+
const entry = byRequirement.get(requirement.id) ?? { requirement, controls: [] };
|
|
174
|
+
entry.controls.push(control);
|
|
175
|
+
byRequirement.set(requirement.id, entry);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return [...byRequirement.values()]
|
|
179
|
+
.sort((a, b) => compareRequirements(a.requirement, b.requirement))
|
|
180
|
+
.map(({ requirement, controls }) => ({
|
|
181
|
+
id: requirement.id,
|
|
182
|
+
identifier: requirement.identifier,
|
|
183
|
+
title: requirement.title,
|
|
184
|
+
section: requirement.section,
|
|
185
|
+
priority: requirement.priority,
|
|
186
|
+
failingControls: controls.map((control) => ({
|
|
187
|
+
id: control.id,
|
|
188
|
+
identifier: control.identifier,
|
|
189
|
+
name: control.name,
|
|
190
|
+
})),
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* One framework's sections and failing requirements. The requirements come from the failing LIVE
|
|
195
|
+
* controls, not from the framework's requirement tree: that tree, with a page of controls under
|
|
196
|
+
* every requirement, timed out past the remote's 55 s on j1dev's DORA framework (122 requirements,
|
|
197
|
+
* 104 controls) while SOC 2 (61 requirements) returned in seconds, and the same shape measured 8 MB
|
|
198
|
+
* in the terraform provider's notes.
|
|
199
|
+
*/
|
|
200
|
+
async function apiDrill(client, frameworkId, deadlineAt, timings) {
|
|
201
|
+
const failing = await (0, shared_js_1.timed)(timings, 'failingControls', () => failingLiveControls(client, frameworkId));
|
|
202
|
+
const lookups = failing.controls.length > 0
|
|
203
|
+
? (0, shared_js_1.timed)(timings, 'requirements', () => lookupRequirements(client, failing.controls, deadlineAt))
|
|
204
|
+
: Promise.resolve({
|
|
205
|
+
read: [],
|
|
206
|
+
skipped: 0,
|
|
207
|
+
skippedBy: { timeBudget: 0, cap: 0, readFailed: 0 },
|
|
208
|
+
});
|
|
209
|
+
// Not concurrent with the failing-controls read: when it ran beside that read, the read took
|
|
210
|
+
// 10.6–19.3 s on j1dev against 7.2–7.7 s without it (2026-10-14).
|
|
211
|
+
const noData = (0, shared_js_1.timed)(timings, 'passingWithoutData', () => passingWithoutDataCount(client, frameworkId, deadlineAt));
|
|
212
|
+
const [{ read, skipped, skippedBy }, passingWithoutData] = await Promise.all([lookups, noData]);
|
|
213
|
+
return {
|
|
214
|
+
passingWithoutData,
|
|
215
|
+
failingRequirements: groupByRequirement(read, frameworkId),
|
|
216
|
+
// Kept whatever the lookups managed: on j1dev a slow drill skipped all 11 requirement lookups
|
|
217
|
+
// and returned nothing an agent could act on, and recovering took 11 get-control calls
|
|
218
|
+
// (2026-10-14).
|
|
219
|
+
failingControls: failing.controls.map((control) => ({
|
|
220
|
+
id: control.id,
|
|
221
|
+
identifier: control.identifier,
|
|
222
|
+
name: control.name,
|
|
223
|
+
})),
|
|
224
|
+
failingControlsTruncated: failing.truncated,
|
|
225
|
+
requirementLookupsSkipped: skipped,
|
|
226
|
+
...(skipped > 0 ? { requirementLookupsSkippedBy: skippedBy } : {}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** A framework id the graph queries may interpolate: a UUID, or `ccm_f_` and a slug. */
|
|
230
|
+
const GRAPH_FRAMEWORK_ID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|ccm_f_[A-Za-z0-9_-]+)$/i;
|
|
231
|
+
/**
|
|
232
|
+
* Rows per page of a graph query. The query service refuses a larger LIMIT: on ECS 186 both drill
|
|
233
|
+
* queries at LIMIT 1000 failed with `"limit" must be a value between 1 and 250`, and every drill
|
|
234
|
+
* fell back to the API (2026-10-15).
|
|
235
|
+
*/
|
|
236
|
+
exports.GRAPH_PAGE_SIZE = 250;
|
|
237
|
+
/** Pages a drill query follows its cursor through: up to 1,000 rows. Past it, it is cut short. */
|
|
238
|
+
exports.GRAPH_MAX_PAGES = 4;
|
|
239
|
+
/**
|
|
240
|
+
* Each failing LIVE control of the framework with each requirement of it the control serves, as
|
|
241
|
+
* one row per pair: 103 ms for SOC 2 on j1dev, matching the five requirements and three controls
|
|
242
|
+
* the apps-api drill took 28 s to assemble (2026-10-15).
|
|
243
|
+
*/
|
|
244
|
+
function failingPairsQuery(frameworkId) {
|
|
245
|
+
return (`FIND ccm_framework WITH id = '${frameworkId}' THAT HAS ccm_requirement AS r ` +
|
|
246
|
+
"THAT HAS ccm_control WITH state = 'LIVE' AND status = 'FAIL' AS c " +
|
|
247
|
+
'RETURN r.id AS requirementId, r.identifier AS requirementIdentifier, ' +
|
|
248
|
+
'r.title AS requirementTitle, r.section AS requirementSection, ' +
|
|
249
|
+
'r.priority AS requirementPriority, c.id AS controlId, c.identifier AS controlIdentifier, ' +
|
|
250
|
+
`c.name AS controlName LIMIT ${exports.GRAPH_PAGE_SIZE}`);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The framework's passing LIVE controls, one row per test with whether it saw data, and one row
|
|
254
|
+
* with a null `testId` for a control with no tests. `effectiveStatus` is not in the graph, so the
|
|
255
|
+
* tests decide (`passesWithoutData`). Counting effective tests per control instead gave a control
|
|
256
|
+
* with no tests at all, one passing by attestation, a count of 0 and called it a no-data pass,
|
|
257
|
+
* which the API's NO_DATAPOINTS filter never does (PR #55 review). This shape took 283 ms for 12
|
|
258
|
+
* rows on j1dev's SOC 2 (2026-10-15).
|
|
259
|
+
*/
|
|
260
|
+
function noDataQuery(frameworkId) {
|
|
261
|
+
return (`FIND ccm_control WITH frameworkId = '${frameworkId}' AND state = 'LIVE' ` +
|
|
262
|
+
"AND status = 'PASS' AS c (THAT DEFINES ccm_control_test AS t)? " +
|
|
263
|
+
`RETURN c.id AS controlId, t.id AS testId, t.effective AS effective LIMIT ${exports.GRAPH_PAGE_SIZE}`);
|
|
264
|
+
}
|
|
265
|
+
/** Passing controls with at least one test, none of which saw data: the no-data passes. */
|
|
266
|
+
function passesWithoutData(rows) {
|
|
267
|
+
const controls = new Map();
|
|
268
|
+
for (const row of rows) {
|
|
269
|
+
const controlId = textOf(row.controlId);
|
|
270
|
+
if (!controlId)
|
|
271
|
+
continue;
|
|
272
|
+
const control = controls.get(controlId) ?? { tested: false, sawData: false };
|
|
273
|
+
if (textOf(row.testId)) {
|
|
274
|
+
control.tested = true;
|
|
275
|
+
if (row.effective === true)
|
|
276
|
+
control.sawData = true;
|
|
277
|
+
}
|
|
278
|
+
controls.set(controlId, control);
|
|
279
|
+
}
|
|
280
|
+
return [...controls.values()].filter((control) => control.tested && !control.sawData).length;
|
|
281
|
+
}
|
|
282
|
+
function textOf(value) {
|
|
283
|
+
return typeof value === 'string' ? value : null;
|
|
284
|
+
}
|
|
285
|
+
/** Requirement–control pairs as failing requirements, critical first, and the distinct controls. */
|
|
286
|
+
function groupPairs(rows) {
|
|
287
|
+
const byRequirement = new Map();
|
|
288
|
+
const controls = new Map();
|
|
289
|
+
for (const row of rows) {
|
|
290
|
+
const requirementId = textOf(row.requirementId);
|
|
291
|
+
const controlId = textOf(row.controlId);
|
|
292
|
+
if (!requirementId || !controlId)
|
|
293
|
+
continue;
|
|
294
|
+
const control = {
|
|
295
|
+
id: controlId,
|
|
296
|
+
identifier: textOf(row.controlIdentifier),
|
|
297
|
+
name: textOf(row.controlName),
|
|
298
|
+
};
|
|
299
|
+
if (!controls.has(controlId))
|
|
300
|
+
controls.set(controlId, control);
|
|
301
|
+
const entry = byRequirement.get(requirementId) ?? {
|
|
302
|
+
requirement: {
|
|
303
|
+
id: requirementId,
|
|
304
|
+
identifier: textOf(row.requirementIdentifier),
|
|
305
|
+
title: textOf(row.requirementTitle),
|
|
306
|
+
section: textOf(row.requirementSection),
|
|
307
|
+
priority: textOf(row.requirementPriority),
|
|
308
|
+
},
|
|
309
|
+
controls: new Map(),
|
|
310
|
+
};
|
|
311
|
+
entry.controls.set(controlId, control);
|
|
312
|
+
byRequirement.set(requirementId, entry);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
failingRequirements: [...byRequirement.values()]
|
|
316
|
+
.sort((a, b) => compareRequirements(a.requirement, b.requirement))
|
|
317
|
+
.map(({ requirement, controls: failing }) => ({
|
|
318
|
+
...requirement,
|
|
319
|
+
failingControls: [...failing.values()],
|
|
320
|
+
})),
|
|
321
|
+
failingControls: [...controls.values()],
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The drill from two graph queries, run at once. On j1dev that morning the apps-api drill skipped
|
|
326
|
+
* every requirement lookup on time in every drill of a framework with failures, while J1QL over
|
|
327
|
+
* `ccm_*` answered in about 100 ms (2026-10-15). Null, for the apps-api path, when the id cannot
|
|
328
|
+
* be interpolated or either query failed; a query that ran out of time is a skip, since no time is
|
|
329
|
+
* left for another path either.
|
|
330
|
+
*/
|
|
331
|
+
async function graphDrill(client, frameworkId, deadlineAt, timings) {
|
|
332
|
+
if (!GRAPH_FRAMEWORK_ID.test(frameworkId))
|
|
333
|
+
return null;
|
|
334
|
+
const [failing, noData] = await (0, shared_js_1.timed)(timings, 'drillGraph', () => Promise.all([
|
|
335
|
+
runGraphQuery(client, failingPairsQuery(frameworkId), deadlineAt, exports.GRAPH_MAX_PAGES),
|
|
336
|
+
runGraphQuery(client, noDataQuery(frameworkId), deadlineAt, exports.GRAPH_MAX_PAGES),
|
|
337
|
+
]));
|
|
338
|
+
const failed = [failing, noData].find((read) => read.kind === 'failed');
|
|
339
|
+
if (failed) {
|
|
340
|
+
console.error('Error reading the drill from the graph; reading it from the API:', failed);
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
const grouped = failing.kind === 'rows'
|
|
344
|
+
? groupPairs(failing.rows)
|
|
345
|
+
: { failingRequirements: [], failingControls: [] };
|
|
346
|
+
return {
|
|
347
|
+
passingWithoutData: noData.kind === 'rows'
|
|
348
|
+
? {
|
|
349
|
+
count: passesWithoutData(noData.rows),
|
|
350
|
+
truncated: noData.more,
|
|
351
|
+
}
|
|
352
|
+
: { skipped: 'time_budget' },
|
|
353
|
+
...grouped,
|
|
354
|
+
failingControlsTruncated: failing.kind !== 'rows' || failing.more,
|
|
355
|
+
requirementLookupsSkipped: 0,
|
|
356
|
+
/** The scorecard then says how many failing controls went unread. */
|
|
357
|
+
failingTimedOut: failing.kind === 'timeout',
|
|
358
|
+
drillSource: 'graph',
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/** The drill: from the graph, or from the API when the graph cannot answer. */
|
|
362
|
+
async function drillFramework(client, frameworkId, startedAt, timings) {
|
|
363
|
+
const deadlineAt = startedAt + shared_js_1.SUMMARY_READ_DEADLINE_MS;
|
|
364
|
+
const graph = await graphDrill(client, frameworkId, deadlineAt, timings);
|
|
365
|
+
if (graph)
|
|
366
|
+
return graph;
|
|
367
|
+
const api = await apiDrill(client, frameworkId, deadlineAt, timings);
|
|
368
|
+
return { ...api, failingTimedOut: false, drillSource: 'api' };
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* How many failing controls a timed-out graph read left unread: the scorecard's count, which is
|
|
372
|
+
* CCM's own, else none known. A completed read reports its own skips.
|
|
373
|
+
*/
|
|
374
|
+
function lookupSkips(drill, stats) {
|
|
375
|
+
if (!drill.failingTimedOut) {
|
|
376
|
+
return {
|
|
377
|
+
requirementLookupsSkipped: drill.requirementLookupsSkipped,
|
|
378
|
+
...('requirementLookupsSkippedBy' in drill
|
|
379
|
+
? { requirementLookupsSkippedBy: drill.requirementLookupsSkippedBy }
|
|
380
|
+
: {}),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
const unread = stats?.numberOfFailingControls ?? 0;
|
|
384
|
+
return {
|
|
385
|
+
requirementLookupsSkipped: unread,
|
|
386
|
+
...(unread > 0
|
|
387
|
+
? { requirementLookupsSkippedBy: { timeBudget: unread, cap: 0, readFailed: 0 } }
|
|
388
|
+
: {}),
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A warning when the graph's failing controls and the scorecard's count disagree. The scorecard is
|
|
393
|
+
* CCM's own count; the graph is refreshed after each evaluation, so the two can differ until then.
|
|
394
|
+
*/
|
|
395
|
+
function drillWarning(drill, stats) {
|
|
396
|
+
const counted = stats?.numberOfFailingControls;
|
|
397
|
+
if (drill.drillSource !== 'graph' || drill.failingControlsTruncated)
|
|
398
|
+
return null;
|
|
399
|
+
if (typeof counted !== 'number' || counted === drill.failingControls.length)
|
|
400
|
+
return null;
|
|
401
|
+
return (`The drill lists ${drill.failingControls.length} failing controls from the graph, and the ` +
|
|
402
|
+
`scorecard counts ${counted}. CCM refreshes the graph after each evaluation, so the two can ` +
|
|
403
|
+
'differ until then.');
|
|
404
|
+
}
|
|
405
|
+
/** The drilled framework's scorecard, sections from its stats, and its failing requirements. */
|
|
406
|
+
function frameworkDrill(frameworkId, meta, stats, drill, subdomain) {
|
|
407
|
+
const { passingWithoutData } = drill;
|
|
408
|
+
const score = frameworkScore(meta ?? { id: frameworkId, name: null }, stats, subdomain);
|
|
409
|
+
return {
|
|
410
|
+
...score,
|
|
411
|
+
controls: score.controls && {
|
|
412
|
+
...score.controls,
|
|
413
|
+
passingWithoutData: 'count' in passingWithoutData ? passingWithoutData.count : null,
|
|
414
|
+
},
|
|
415
|
+
...('skipped' in passingWithoutData
|
|
416
|
+
? { passingWithoutDataSkipped: passingWithoutData.skipped }
|
|
417
|
+
: {}),
|
|
418
|
+
...('truncated' in passingWithoutData && passingWithoutData.truncated
|
|
419
|
+
? { passingWithoutDataTruncated: true }
|
|
420
|
+
: {}),
|
|
421
|
+
// Null, not empty, when the stats were not read: an empty list beside unread stats read as
|
|
422
|
+
// "this framework has no sections" on j1dev (2026-10-15).
|
|
423
|
+
sections: stats
|
|
424
|
+
? (stats.sectionStats ?? []).map((section) => ({
|
|
425
|
+
section: section.sectionName,
|
|
426
|
+
requirements: section.numberOfRequirements,
|
|
427
|
+
passing: section.numberOfPassingRequirements,
|
|
428
|
+
failing: section.numberOfFailingRequirements,
|
|
429
|
+
}))
|
|
430
|
+
: null,
|
|
431
|
+
failingRequirements: drill.failingRequirements.map((requirement) => ({
|
|
432
|
+
...requirement,
|
|
433
|
+
failingControls: requirement.failingControls.map((control) => ({
|
|
434
|
+
...control,
|
|
435
|
+
url: (0, shared_js_1.controlUrl)(control.id, subdomain),
|
|
436
|
+
})),
|
|
437
|
+
})),
|
|
438
|
+
failingControls: drill.failingControls.map((control) => ({
|
|
439
|
+
...control,
|
|
440
|
+
url: (0, shared_js_1.controlUrl)(control.id, subdomain),
|
|
441
|
+
})),
|
|
442
|
+
failingControlsTruncated: drill.failingControlsTruncated,
|
|
443
|
+
drillSource: drill.drillSource,
|
|
444
|
+
...lookupSkips(drill, stats),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/** `frameworkId` is an array on the graph entity; a lone string is read as a list of one. */
|
|
448
|
+
function idList(value) {
|
|
449
|
+
if (Array.isArray(value)) {
|
|
450
|
+
return value.filter((entry) => typeof entry === 'string');
|
|
451
|
+
}
|
|
452
|
+
return typeof value === 'string' ? [value] : [];
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The J1QL that names controls, in the form apps' own control reads use. Every id has passed the
|
|
456
|
+
* CONTROL_ID_FORBIDDEN check, so none can close its quoted literal.
|
|
457
|
+
*/
|
|
458
|
+
function controlNameQuery(controlIds) {
|
|
459
|
+
const literals = controlIds.map((id) => `'${id}'`);
|
|
460
|
+
const condition = literals.length === 1 ? literals[0] : `(${literals.join(' OR ')})`;
|
|
461
|
+
return (`FIND ccm_control WITH id = ${condition} AS c ` +
|
|
462
|
+
'RETURN c.id AS controlId, c.name AS controlName, c.frameworkId AS frameworkIds LIMIT 250');
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Names and framework membership for the listed attestations' controls, from one graph query.
|
|
466
|
+
* The control pages this replaces took 19–30 s on every real framework on j1dev and 13–19 s on a
|
|
467
|
+
* six-control fixture, so every real drill fell back to account scope with every name null; the
|
|
468
|
+
* tester's own J1QL over ccm_control answered in 2.4 s (2026-10-14). Null when the query fails or
|
|
469
|
+
* outlives the deadline.
|
|
470
|
+
*/
|
|
471
|
+
async function readGraphControls(client, controlIds, deadlineAt) {
|
|
472
|
+
if (controlIds.length === 0)
|
|
473
|
+
return new Map();
|
|
474
|
+
const read = await runGraphQuery(client, controlNameQuery(controlIds), deadlineAt);
|
|
475
|
+
if (read.kind === 'failed') {
|
|
476
|
+
console.error('Error naming the controls of listed attestations:', read.error);
|
|
477
|
+
}
|
|
478
|
+
if (read.kind !== 'rows')
|
|
479
|
+
return null;
|
|
480
|
+
const controls = new Map();
|
|
481
|
+
for (const row of read.rows) {
|
|
482
|
+
if (typeof row.controlId !== 'string')
|
|
483
|
+
continue;
|
|
484
|
+
controls.set(row.controlId, {
|
|
485
|
+
name: typeof row.controlName === 'string' ? row.controlName : null,
|
|
486
|
+
frameworkIds: idList(row.frameworkIds),
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
return controls;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* One page, raced against `deadlineAt` and polling no longer than the time left. A poll budget
|
|
493
|
+
* that runs out is a timeout, like the race; anything else, a malformed answer included, is a
|
|
494
|
+
* failure.
|
|
495
|
+
*/
|
|
496
|
+
async function readGraphPage(client, query, cursor, deadlineAt) {
|
|
497
|
+
if (Date.now() >= deadlineAt)
|
|
498
|
+
return { kind: 'timeout' };
|
|
499
|
+
try {
|
|
500
|
+
const result = await (0, shared_js_1.withDeadline)(client.executeJ1qlQuery({
|
|
501
|
+
query,
|
|
502
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
503
|
+
maxPollAttempts: Math.max(1, Math.ceil((deadlineAt - Date.now()) / 1000)),
|
|
504
|
+
}), deadlineAt);
|
|
505
|
+
if (result === shared_js_1.DEADLINE_PASSED)
|
|
506
|
+
return { kind: 'timeout' };
|
|
507
|
+
const { data, cursor: next } = (result ?? {});
|
|
508
|
+
if (!Array.isArray(data)) {
|
|
509
|
+
throw new Error('Invalid response structure from JupiterOne API: a graph query returned no data');
|
|
510
|
+
}
|
|
511
|
+
const rows = data.filter((row) => typeof row === 'object' && row !== null);
|
|
512
|
+
return {
|
|
513
|
+
kind: 'page',
|
|
514
|
+
rows,
|
|
515
|
+
cursor: typeof next === 'string' && next.length > 0 ? next : null,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
return error instanceof j1ql_service_js_1.J1qlQueryTimeoutError ? { kind: 'timeout' } : { kind: 'failed', error };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* A graph query's rows over up to `maxPages` pages of its cursor, every page inside `deadlineAt`.
|
|
524
|
+
* `more` says the rows may be cut short: a cursor left after the last page, or a later page that
|
|
525
|
+
* ran out of time. The cursor is the only "more" signal: a live probe showed a full 250-row page
|
|
526
|
+
* under `LIMIT 250` carries a cursor when more remain, and a page can come back short while more
|
|
527
|
+
* do. A first page that runs out of time is a timeout, and a failed page fails the read.
|
|
528
|
+
*/
|
|
529
|
+
async function runGraphQuery(client, query, deadlineAt, maxPages = 1) {
|
|
530
|
+
const rows = [];
|
|
531
|
+
let cursor;
|
|
532
|
+
for (let page = 0; page < maxPages; page++) {
|
|
533
|
+
const read = await readGraphPage(client, query, cursor, deadlineAt);
|
|
534
|
+
if (read.kind === 'failed')
|
|
535
|
+
return read;
|
|
536
|
+
if (read.kind === 'timeout')
|
|
537
|
+
return page === 0 ? read : { kind: 'rows', rows, more: true };
|
|
538
|
+
rows.push(...read.rows);
|
|
539
|
+
if (read.cursor === null)
|
|
540
|
+
return { kind: 'rows', rows, more: false };
|
|
541
|
+
cursor = read.cursor;
|
|
542
|
+
}
|
|
543
|
+
return { kind: 'rows', rows, more: true };
|
|
544
|
+
}
|
|
545
|
+
/** An unknown expiry sorts as the oldest, so it never pushes a dated lapse off the list. */
|
|
546
|
+
function expiryMs(attestation) {
|
|
547
|
+
return Number.isFinite(attestation.expiresOn) ? attestation.expiresOn : 0;
|
|
548
|
+
}
|
|
549
|
+
function wholeDays(ms) {
|
|
550
|
+
return Number.isFinite(ms) ? Math.max(0, Math.floor(ms / expires_on_js_1.DAY_MS)) : null;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The control ids to name, in the order they matter: the expired attestations' controls first,
|
|
554
|
+
* most recently expired first, since they fail controls now; then the expiring ones, soonest
|
|
555
|
+
* first. An id the API would reject is never interpolated into the query.
|
|
556
|
+
*/
|
|
557
|
+
function idsToName(lapsed, expiring) {
|
|
558
|
+
const soonest = expiring === 'unavailable' ? [] : [...expiring].sort((a, b) => expiryMs(a) - expiryMs(b));
|
|
559
|
+
const ordered = [...(lapsed === 'unavailable' ? [] : lapsed), ...soonest];
|
|
560
|
+
return [...new Set(ordered.map((attestation) => attestation.controlId))]
|
|
561
|
+
.filter(isString)
|
|
562
|
+
.filter((id) => !shared_js_1.CONTROL_ID_FORBIDDEN.test(id));
|
|
563
|
+
}
|
|
564
|
+
function controlNameOf(attestation, lookup) {
|
|
565
|
+
return attestation.controlId ? (lookup.controls?.get(attestation.controlId)?.name ?? null) : null;
|
|
566
|
+
}
|
|
567
|
+
/** Asked about, and the read has no row for it. */
|
|
568
|
+
function unresolved(attestation, lookup) {
|
|
569
|
+
const id = attestation.controlId;
|
|
570
|
+
return lookup.controls !== null && !(id && (lookup.controls.has(id) || lookup.beyondCap.has(id)));
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* The ACTIVE attestations expiring within the window and the EXPIRED ones nobody revoked, then
|
|
574
|
+
* one graph read naming their controls. Started with the request and depending on nothing else:
|
|
575
|
+
* on j1dev the lists waited 4–21 s for the framework list and then took 24–27 s themselves, so the
|
|
576
|
+
* names query, 1.9–3.3 s whenever it ran, never ran on a slow drill (2026-10-15).
|
|
577
|
+
*/
|
|
578
|
+
async function readAttestations(client, expiringWithinDays, timings, deadlineAt, abandoned) {
|
|
579
|
+
const [expiring, expired] = await (0, shared_js_1.timed)(timings, 'attestations', () => Promise.all([
|
|
580
|
+
client.listAttestations({ expiringWithinDays, state: 'ACTIVE' }).catch(shared_js_1.degradeOnAccessDenied),
|
|
581
|
+
// EXPIRED is `revoked != true AND expiresOn <= now` on the API, so a revoked one is not here.
|
|
582
|
+
client.listAttestations({ state: 'EXPIRED' }).catch(shared_js_1.degradeOnAccessDenied),
|
|
583
|
+
]));
|
|
584
|
+
const lapsed = expired === 'unavailable' ? expired : [...expired].sort((a, b) => expiryMs(b) - expiryMs(a));
|
|
585
|
+
const listedAny = [expiring, lapsed].some((list) => list !== 'unavailable' && list.length > 0);
|
|
586
|
+
const ids = idsToName(lapsed, expiring);
|
|
587
|
+
const named = listedAny && !abandoned.value;
|
|
588
|
+
return {
|
|
589
|
+
expiring,
|
|
590
|
+
lapsed,
|
|
591
|
+
lookup: {
|
|
592
|
+
controls: named
|
|
593
|
+
? await (0, shared_js_1.timed)(timings, 'controlNames', () => readGraphControls(client, ids.slice(0, shared_js_1.MAX_NAMED_CONTROLS), deadlineAt))
|
|
594
|
+
: new Map(),
|
|
595
|
+
beyondCap: new Set(ids.slice(shared_js_1.MAX_NAMED_CONTROLS)),
|
|
596
|
+
},
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Both attestation lists, on a drill kept to the framework's controls: listing them account-wide
|
|
601
|
+
* on a drill put another framework's attestation in the AI-ASM report on j1dev (2026-10-14). An
|
|
602
|
+
* attestation whose control the read has no row for stays listed with a null name: the graph can
|
|
603
|
+
* lag a control created moments ago, and dropping a real framework attestation is the worse
|
|
604
|
+
* error. When the read failed, nothing can be scoped, so both lists stay account-wide and `scope`
|
|
605
|
+
* says so. Past the naming cap, controls were never read, so their attestations could be in any
|
|
606
|
+
* framework: then the lists stay account-wide too, rather than claim a scope for attestations no
|
|
607
|
+
* read checked (PR #55 review). The expired list stops at MAX_EXPIRED_ATTESTATIONS after scoping.
|
|
608
|
+
*/
|
|
609
|
+
function scopeAttestations(named, frameworkId) {
|
|
610
|
+
const { lookup, lapsed } = named;
|
|
611
|
+
const scoped = frameworkId !== undefined && lookup.controls !== null && lookup.beyondCap.size === 0;
|
|
612
|
+
const inScope = (attestation) => {
|
|
613
|
+
const control = attestation.controlId ? lookup.controls?.get(attestation.controlId) : undefined;
|
|
614
|
+
return !scoped || !control || control.frameworkIds.includes(frameworkId ?? '');
|
|
615
|
+
};
|
|
616
|
+
const now = Date.now();
|
|
617
|
+
const expiring = named.expiring === 'unavailable' ? [] : named.expiring.filter(inScope);
|
|
618
|
+
const expired = lapsed === 'unavailable' ? [] : lapsed.filter(inScope);
|
|
619
|
+
const shownExpired = expired.slice(0, shared_js_1.MAX_EXPIRED_ATTESTATIONS);
|
|
620
|
+
const row = (attestation) => ({
|
|
621
|
+
...(0, shared_js_1.projectAttestation)(attestation),
|
|
622
|
+
controlName: controlNameOf(attestation, lookup),
|
|
623
|
+
});
|
|
624
|
+
return {
|
|
625
|
+
expiring: named.expiring === 'unavailable'
|
|
626
|
+
? named.expiring
|
|
627
|
+
: expiring.map((attestation) => ({
|
|
628
|
+
...row(attestation),
|
|
629
|
+
daysUntilExpiry: wholeDays(attestation.expiresOn - now),
|
|
630
|
+
})),
|
|
631
|
+
expired: lapsed === 'unavailable'
|
|
632
|
+
? lapsed
|
|
633
|
+
: shownExpired.map((attestation) => ({
|
|
634
|
+
...row(attestation),
|
|
635
|
+
daysSinceExpiry: wholeDays(now - attestation.expiresOn),
|
|
636
|
+
})),
|
|
637
|
+
expiredTruncated: expired.length > shared_js_1.MAX_EXPIRED_ATTESTATIONS,
|
|
638
|
+
namesUnavailable: lookup.controls === null || lookup.beyondCap.size > 0,
|
|
639
|
+
unresolved: [...expiring, ...shownExpired].filter((attestation) => unresolved(attestation, lookup)).length,
|
|
640
|
+
scope: scoped ? 'framework' : 'account',
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* The attestation fields of the summary. The scope and the names flags describe whichever lists
|
|
645
|
+
* were read; `controlNamesUnavailable`, `controlNamesUnresolved` and
|
|
646
|
+
* `expiredAttestationsTruncated` appear only when set.
|
|
647
|
+
*/
|
|
648
|
+
function attestationFields(read, subdomain) {
|
|
649
|
+
const linked = (rows) => rows === 'unavailable'
|
|
650
|
+
? rows
|
|
651
|
+
: rows.map((row) => ({ ...row, url: (0, shared_js_1.controlUrl)(row.controlId, subdomain) }));
|
|
652
|
+
const anyRead = read.expiring !== 'unavailable' || read.expired !== 'unavailable';
|
|
653
|
+
return {
|
|
654
|
+
expiringAttestations: linked(read.expiring),
|
|
655
|
+
expiredAttestations: linked(read.expired),
|
|
656
|
+
...(read.expiredTruncated ? { expiredAttestationsTruncated: true } : {}),
|
|
657
|
+
...(anyRead ? { expiringAttestationsScope: read.scope } : {}),
|
|
658
|
+
...(read.namesUnavailable ? { controlNamesUnavailable: true } : {}),
|
|
659
|
+
...(read.unresolved > 0 ? { controlNamesUnresolved: read.unresolved } : {}),
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function isString(value) {
|
|
663
|
+
return typeof value === 'string' && value.length > 0;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* A framework name against the list the summary already reads: an exact id, then an exact name
|
|
667
|
+
* ignoring case, then a single partial match. Names repeat (j1dev holds "SOC 2 Trust Services
|
|
668
|
+
* Criteria" twice and "CIS GitHub Benchmark v1.1.0" five times, 2026-10-14), so several exact
|
|
669
|
+
* matches are `ambiguous` rather than a guess.
|
|
670
|
+
*/
|
|
671
|
+
function pickByName(frameworks, name) {
|
|
672
|
+
const byId = frameworks.find((framework) => framework.id === name);
|
|
673
|
+
if (byId)
|
|
674
|
+
return { kind: 'drill', id: byId.id, meta: byId, resolution: 'id' };
|
|
675
|
+
const folded = name.toLowerCase();
|
|
676
|
+
const named = (framework) => (framework.name ?? '').trim().toLowerCase();
|
|
677
|
+
const exact = frameworks.filter((framework) => named(framework) === folded);
|
|
678
|
+
if (exact.length === 1)
|
|
679
|
+
return { kind: 'drill', id: exact[0].id, meta: exact[0], resolution: 'name' };
|
|
680
|
+
if (exact.length > 1)
|
|
681
|
+
return { kind: 'ambiguous', matches: exact };
|
|
682
|
+
const partial = frameworks.filter((framework) => named(framework).includes(folded));
|
|
683
|
+
if (partial.length === 1) {
|
|
684
|
+
return { kind: 'drill', id: partial[0].id, meta: partial[0], resolution: 'partial' };
|
|
685
|
+
}
|
|
686
|
+
return partial.length > 1 ? { kind: 'ambiguous', matches: partial } : { kind: 'not_found' };
|
|
687
|
+
}
|
|
688
|
+
function pickFramework(frameworks, complete, request) {
|
|
689
|
+
if (request.frameworkName !== undefined)
|
|
690
|
+
return pickByName(frameworks, request.frameworkName);
|
|
691
|
+
const { frameworkId } = request;
|
|
692
|
+
if (frameworkId === undefined)
|
|
693
|
+
return { kind: 'all' };
|
|
694
|
+
const meta = frameworks.find((framework) => framework.id === frameworkId);
|
|
695
|
+
// Only a complete walk proves absence; past the page cap the framework may still exist, so the
|
|
696
|
+
// drill goes ahead and `frameworksComplete: false` says the list is partial.
|
|
697
|
+
if (!meta && complete)
|
|
698
|
+
return { kind: 'not_found' };
|
|
699
|
+
return { kind: 'drill', id: frameworkId, meta, resolution: 'id' };
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* A framework to choose from: who it is, where it came from and whether it imported, with no
|
|
703
|
+
* counts. Two j1dev frameworks named "SOC 2 Trust Services Criteria" differed only by id until
|
|
704
|
+
* source, sourceId and owner were shown (2026-10-15).
|
|
705
|
+
*/
|
|
706
|
+
function frameworkListing(framework, subdomain) {
|
|
707
|
+
return {
|
|
708
|
+
id: framework.id,
|
|
709
|
+
name: framework.name,
|
|
710
|
+
source: framework.source ?? null,
|
|
711
|
+
sourceId: framework.sourceId ?? null,
|
|
712
|
+
owner: framework.owner ?? null,
|
|
713
|
+
importStatus: framework.status?.status ?? null,
|
|
714
|
+
url: (0, shared_js_1.frameworkUrl)(framework.id, subdomain),
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* The `ambiguous` or `framework_not_found` answer: what was asked, and what to choose from. Both
|
|
719
|
+
* list every framework in `frameworks`: a host that cached the schema from before `ambiguous`
|
|
720
|
+
* existed requires the key, and rejected the by-name call that left it out (ECS 184, 2026-10-15).
|
|
721
|
+
*/
|
|
722
|
+
function unresolvedFramework(pick, request, frameworks, subdomain) {
|
|
723
|
+
const asked = request.frameworkName !== undefined
|
|
724
|
+
? { frameworkName: request.frameworkName }
|
|
725
|
+
: { frameworkId: request.frameworkId };
|
|
726
|
+
const listing = {
|
|
727
|
+
frameworksComplete: frameworks.complete,
|
|
728
|
+
frameworks: frameworks.frameworks.map((framework) => frameworkListing(framework, subdomain)),
|
|
729
|
+
};
|
|
730
|
+
if (pick.kind === 'not_found') {
|
|
731
|
+
return {
|
|
732
|
+
outcome: 'framework_not_found',
|
|
733
|
+
...asked,
|
|
734
|
+
frameworkResolution: 'not_found',
|
|
735
|
+
...listing,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
return {
|
|
739
|
+
outcome: 'ambiguous',
|
|
740
|
+
...asked,
|
|
741
|
+
frameworkResolution: 'ambiguous',
|
|
742
|
+
...listing,
|
|
743
|
+
candidates: pick.matches
|
|
744
|
+
.slice(0, shared_js_1.MAX_CANDIDATES)
|
|
745
|
+
.map((framework) => frameworkListing(framework, subdomain)),
|
|
746
|
+
candidateCount: pick.matches.length,
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
async function complianceSummary(client, request, expiringWithinDays) {
|
|
750
|
+
const startedAt = Date.now();
|
|
751
|
+
const timings = {};
|
|
752
|
+
const abandoned = { value: false };
|
|
753
|
+
try {
|
|
754
|
+
return await summarize(client, request, expiringWithinDays, {
|
|
755
|
+
startedAt,
|
|
756
|
+
timings,
|
|
757
|
+
abandoned,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
finally {
|
|
761
|
+
abandoned.value = true;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
async function summarize(client, request, expiringWithinDays, run) {
|
|
765
|
+
const { startedAt, timings } = run;
|
|
766
|
+
const subdomainRead = (0, shared_js_1.readSubdomain)(client, timings);
|
|
767
|
+
const attestationsRead = readAttestations(client, expiringWithinDays, timings, startedAt + shared_js_1.SUMMARY_READ_DEADLINE_MS, run.abandoned);
|
|
768
|
+
// Awaited below on every path that uses it; this keeps an early answer, or a failed framework
|
|
769
|
+
// read, from leaving its rejection unhandled.
|
|
770
|
+
attestationsRead.catch(() => undefined);
|
|
771
|
+
const early = request.frameworkId !== undefined ? startDrill(client, request.frameworkId, run) : undefined;
|
|
772
|
+
const listed = await (0, shared_js_1.timed)(timings, 'frameworks', () => client.listAllControlFrameworks());
|
|
773
|
+
const { frameworks, complete } = listed;
|
|
774
|
+
const pick = pickFramework(frameworks, complete, request);
|
|
775
|
+
if (pick.kind === 'ambiguous' || pick.kind === 'not_found') {
|
|
776
|
+
const subdomain = await subdomainRead;
|
|
777
|
+
// A copy: the attestation reads still in flight would otherwise write into this answer.
|
|
778
|
+
return { ...unresolvedFramework(pick, request, listed, subdomain), timingsMs: { ...timings } };
|
|
779
|
+
}
|
|
780
|
+
const frameworkId = pick.kind === 'drill' ? pick.id : undefined;
|
|
781
|
+
const meta = pick.kind === 'drill' ? pick.meta : undefined;
|
|
782
|
+
// A drill reads and scores one framework: a caller who names one is asking about that one.
|
|
783
|
+
const scored = frameworkId ? [meta ?? { id: frameworkId, name: null }] : frameworks;
|
|
784
|
+
const drillReads = frameworkId === undefined ? undefined : (early ?? startDrill(client, frameworkId, run));
|
|
785
|
+
const [statsRead, named, drill] = await Promise.all([
|
|
786
|
+
drillReads?.stats ?? scorecardStats(client, frameworks, run),
|
|
787
|
+
attestationsRead,
|
|
788
|
+
drillReads?.drill ?? Promise.resolve(null),
|
|
789
|
+
]);
|
|
790
|
+
const attestations = scopeAttestations(named, frameworkId);
|
|
791
|
+
const statsById = new Map(statsRead.stats.map((entry) => [entry.id, entry]));
|
|
792
|
+
const drillWarned = drill && frameworkId ? drillWarning(drill, statsById.get(frameworkId)) : null;
|
|
793
|
+
const warnings = [
|
|
794
|
+
...(drillWarned ? [drillWarned] : []),
|
|
795
|
+
...summaryWarnings(frameworkId, attestations),
|
|
796
|
+
];
|
|
797
|
+
// Absent rather than null when no chunk finished: `timingsMs` is declared as numbers only, and
|
|
798
|
+
// hosts validate against the schema they cached.
|
|
799
|
+
if (statsRead.chunkMaxMs !== null)
|
|
800
|
+
timings.statsChunkMaxMs = statsRead.chunkMaxMs;
|
|
801
|
+
const subdomain = await subdomainRead;
|
|
802
|
+
return {
|
|
803
|
+
outcome: 'ok',
|
|
804
|
+
...(pick.kind === 'drill' ? { frameworkResolution: pick.resolution } : {}),
|
|
805
|
+
frameworksComplete: complete,
|
|
806
|
+
frameworks: scored.map((framework) => frameworkScore(framework, statsById.get(framework.id), subdomain)),
|
|
807
|
+
...(statsRead.incomplete.length > 0 ? { statsIncomplete: statsRead.incomplete } : {}),
|
|
808
|
+
...(frameworkId && drill
|
|
809
|
+
? {
|
|
810
|
+
framework: frameworkDrill(frameworkId, meta, statsById.get(frameworkId), drill, subdomain),
|
|
811
|
+
}
|
|
812
|
+
: {}),
|
|
813
|
+
...attestationFields(attestations, subdomain),
|
|
814
|
+
attestationsExpiringWithinDays: expiringWithinDays,
|
|
815
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
816
|
+
timingsMs: timings,
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Starts a drill's reads. An id needs no framework list, so a `frameworkId` call starts them with
|
|
821
|
+
* the request: the list took 4–21 s on j1dev before any drill read began (2026-10-15). A name
|
|
822
|
+
* starts them once the list has resolved it.
|
|
823
|
+
*/
|
|
824
|
+
function startDrill(client, frameworkId, run) {
|
|
825
|
+
const stats = (0, shared_js_1.timed)(run.timings, 'stats', () => readStats(client, [frameworkId], run.startedAt + shared_js_1.SUMMARY_READ_DEADLINE_MS, {
|
|
826
|
+
withSections: true,
|
|
827
|
+
}));
|
|
828
|
+
const drill = drillFramework(client, frameworkId, run.startedAt, run.timings);
|
|
829
|
+
// Awaited once the framework resolves; an early answer leaves them behind.
|
|
830
|
+
stats.catch(() => undefined);
|
|
831
|
+
drill.catch(() => undefined);
|
|
832
|
+
return { stats, drill };
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Every framework's counts for the scorecard, without sections: a drill alone shows them. The
|
|
836
|
+
* backend computes requirement stats per framework, so this read grows with every framework (the
|
|
837
|
+
* bare summary took 39 s on j1dev's 60 frameworks, 2026-10-14).
|
|
838
|
+
*/
|
|
839
|
+
function scorecardStats(client, frameworks, run) {
|
|
840
|
+
if (frameworks.length === 0)
|
|
841
|
+
return Promise.resolve({ stats: [], incomplete: [], chunkMaxMs: null });
|
|
842
|
+
return (0, shared_js_1.timed)(run.timings, 'stats', () => readStats(client, frameworks.map((framework) => framework.id), run.startedAt + shared_js_1.SUMMARY_READ_DEADLINE_MS, { withSections: false }));
|
|
843
|
+
}
|
|
844
|
+
const WARNING_ACCOUNT_WIDE_ATTESTATIONS = "The attestation lists are account-wide: the framework's controls could not be confirmed.";
|
|
845
|
+
/**
|
|
846
|
+
* Sentences an assistant should pass on with the answer. A drill whose attestation lists stayed
|
|
847
|
+
* account-wide is the one the tester would have misreported: "what lapsed in SOC 2?" answered with
|
|
848
|
+
* 15 attestations, none of them SOC 2's (j1dev, 2026-10-15).
|
|
849
|
+
*/
|
|
850
|
+
function summaryWarnings(frameworkId, attestations) {
|
|
851
|
+
return frameworkId !== undefined && attestations.scope === 'account'
|
|
852
|
+
? [WARNING_ACCOUNT_WIDE_ATTESTATIONS]
|
|
853
|
+
: [];
|
|
854
|
+
}
|
|
855
|
+
exports.summaryTools = [
|
|
856
|
+
(0, types_js_1.defineTool)({
|
|
857
|
+
name: 'get-compliance-summary',
|
|
858
|
+
title: 'Compliance Summary',
|
|
859
|
+
description: (0, load_description_js_1.loadDescription)('get-compliance-summary.md'),
|
|
860
|
+
inputSchema: {
|
|
861
|
+
frameworkId: zod_1.z
|
|
862
|
+
.string()
|
|
863
|
+
.min(1)
|
|
864
|
+
.optional()
|
|
865
|
+
.describe("A framework `id` from this tool's `frameworks` list. When set, the response adds that " +
|
|
866
|
+
"framework's section scores and its failing requirements with the controls failing " +
|
|
867
|
+
'them.'),
|
|
868
|
+
frameworkName: zod_1.z
|
|
869
|
+
.string()
|
|
870
|
+
.trim()
|
|
871
|
+
.min(1)
|
|
872
|
+
.optional()
|
|
873
|
+
.describe('A framework name, instead of `frameworkId`: matched exactly ignoring case, else as ' +
|
|
874
|
+
'the single framework whose name contains it. Several matches return ' +
|
|
875
|
+
'`outcome: "ambiguous"` with candidates.'),
|
|
876
|
+
attestationsExpiringWithinDays: zod_1.z
|
|
877
|
+
.number()
|
|
878
|
+
.int()
|
|
879
|
+
.min(1)
|
|
880
|
+
.max(365)
|
|
881
|
+
.optional()
|
|
882
|
+
.describe('How far ahead to look for active attestations about to expire, in days (1–365, ' +
|
|
883
|
+
`default ${shared_js_1.DEFAULT_EXPIRING_WITHIN_DAYS}).`),
|
|
884
|
+
},
|
|
885
|
+
outputSchema: schemas_js_1.complianceSummaryOutput,
|
|
886
|
+
annotations: types_js_1.READ_ONLY,
|
|
887
|
+
accessDeniedHint: shared_js_1.ACCESS_DENIED_HINT,
|
|
888
|
+
errorContext: 'Error fetching the compliance summary',
|
|
889
|
+
handler: async ({ frameworkId, frameworkName, attestationsExpiringWithinDays }, client) => {
|
|
890
|
+
if (frameworkId !== undefined && frameworkName !== undefined) {
|
|
891
|
+
return (0, shared_js_1.validationError)('Pass at most one of `frameworkId` or `frameworkName`.');
|
|
892
|
+
}
|
|
893
|
+
return (0, result_js_1.structuredResult)(await complianceSummary(client, { frameworkId, frameworkName }, attestationsExpiringWithinDays ?? shared_js_1.DEFAULT_EXPIRING_WITHIN_DAYS));
|
|
894
|
+
},
|
|
895
|
+
}),
|
|
896
|
+
];
|
|
897
|
+
//# sourceMappingURL=summary.js.map
|