@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.
Files changed (83) hide show
  1. package/README.md +22 -0
  2. package/dist/client/graphql/mutations.d.ts +3 -0
  3. package/dist/client/graphql/mutations.d.ts.map +1 -1
  4. package/dist/client/graphql/mutations.js +20 -1
  5. package/dist/client/graphql/mutations.js.map +1 -1
  6. package/dist/client/graphql/queries.d.ts +27 -0
  7. package/dist/client/graphql/queries.d.ts.map +1 -1
  8. package/dist/client/graphql/queries.js +186 -1
  9. package/dist/client/graphql/queries.js.map +1 -1
  10. package/dist/client/jupiterone-client.d.ts +26 -1
  11. package/dist/client/jupiterone-client.d.ts.map +1 -1
  12. package/dist/client/jupiterone-client.js +44 -3
  13. package/dist/client/jupiterone-client.js.map +1 -1
  14. package/dist/client/sanitize-error.d.ts +2 -0
  15. package/dist/client/sanitize-error.d.ts.map +1 -1
  16. package/dist/client/sanitize-error.js +9 -1
  17. package/dist/client/sanitize-error.js.map +1 -1
  18. package/dist/client/services/compliance-service.d.ts +61 -0
  19. package/dist/client/services/compliance-service.d.ts.map +1 -0
  20. package/dist/client/services/compliance-service.js +246 -0
  21. package/dist/client/services/compliance-service.js.map +1 -0
  22. package/dist/client/services/rule-service.d.ts +4 -6
  23. package/dist/client/services/rule-service.d.ts.map +1 -1
  24. package/dist/client/services/rule-service.js +6 -21
  25. package/dist/client/services/rule-service.js.map +1 -1
  26. package/dist/generated/description-map.d.ts.map +1 -1
  27. package/dist/generated/description-map.js +736 -4
  28. package/dist/generated/description-map.js.map +1 -1
  29. package/dist/server/mcp-server.d.ts.map +1 -1
  30. package/dist/server/mcp-server.js +1 -0
  31. package/dist/server/mcp-server.js.map +1 -1
  32. package/dist/server/tools/account.d.ts.map +1 -1
  33. package/dist/server/tools/account.js +4 -4
  34. package/dist/server/tools/account.js.map +1 -1
  35. package/dist/server/tools/compliance/attestations.d.ts +3 -0
  36. package/dist/server/tools/compliance/attestations.d.ts.map +1 -0
  37. package/dist/server/tools/compliance/attestations.js +560 -0
  38. package/dist/server/tools/compliance/attestations.js.map +1 -0
  39. package/dist/server/tools/compliance/controls.d.ts +40 -0
  40. package/dist/server/tools/compliance/controls.d.ts.map +1 -0
  41. package/dist/server/tools/compliance/controls.js +865 -0
  42. package/dist/server/tools/compliance/controls.js.map +1 -0
  43. package/dist/server/tools/compliance/index.d.ts +21 -0
  44. package/dist/server/tools/compliance/index.d.ts.map +1 -0
  45. package/dist/server/tools/compliance/index.js +45 -0
  46. package/dist/server/tools/compliance/index.js.map +1 -0
  47. package/dist/server/tools/compliance/schemas.d.ts +365 -0
  48. package/dist/server/tools/compliance/schemas.d.ts.map +1 -0
  49. package/dist/server/tools/compliance/schemas.js +292 -0
  50. package/dist/server/tools/compliance/schemas.js.map +1 -0
  51. package/dist/server/tools/compliance/shared.d.ts +141 -0
  52. package/dist/server/tools/compliance/shared.d.ts.map +1 -0
  53. package/dist/server/tools/compliance/shared.js +231 -0
  54. package/dist/server/tools/compliance/shared.js.map +1 -0
  55. package/dist/server/tools/compliance/summary.d.ts +11 -0
  56. package/dist/server/tools/compliance/summary.d.ts.map +1 -0
  57. package/dist/server/tools/compliance/summary.js +897 -0
  58. package/dist/server/tools/compliance/summary.js.map +1 -0
  59. package/dist/server/tools/errors.d.ts +17 -1
  60. package/dist/server/tools/errors.d.ts.map +1 -1
  61. package/dist/server/tools/errors.js +59 -4
  62. package/dist/server/tools/errors.js.map +1 -1
  63. package/dist/server/tools/index.d.ts.map +1 -1
  64. package/dist/server/tools/index.js +2 -0
  65. package/dist/server/tools/index.js.map +1 -1
  66. package/dist/server/tools/rules.d.ts +35 -1
  67. package/dist/server/tools/rules.d.ts.map +1 -1
  68. package/dist/server/tools/rules.js +252 -9
  69. package/dist/server/tools/rules.js.map +1 -1
  70. package/dist/server/tools/threat.js +1 -1
  71. package/dist/server/tools/threat.js.map +1 -1
  72. package/dist/server/tools/usage.d.ts +6 -0
  73. package/dist/server/tools/usage.d.ts.map +1 -1
  74. package/dist/server/tools/usage.js +257 -6
  75. package/dist/server/tools/usage.js.map +1 -1
  76. package/dist/types/jupiterone.d.ts +247 -0
  77. package/dist/types/jupiterone.d.ts.map +1 -1
  78. package/dist/utils/expires-on.d.ts +24 -0
  79. package/dist/utils/expires-on.d.ts.map +1 -0
  80. package/dist/utils/expires-on.js +79 -0
  81. package/dist/utils/expires-on.js.map +1 -0
  82. package/node_modules/dtrace-provider/build/Makefile +1 -1
  83. package/package.json +1 -1
@@ -0,0 +1,865 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.controlTools = exports.STATUS_EXPLANATIONS = exports.ORG_UNIT_SUGGESTIONS = void 0;
4
+ exports.explainControlStatus = explainControlStatus;
5
+ exports.failureCauses = failureCauses;
6
+ const zod_1 = require("zod");
7
+ const load_description_js_1 = require("../../../utils/load-description.js");
8
+ const errors_js_1 = require("../errors.js");
9
+ const result_js_1 = require("../result.js");
10
+ const types_js_1 = require("../types.js");
11
+ const schemas_js_1 = require("./schemas.js");
12
+ const shared_js_1 = require("./shared.js");
13
+ /**
14
+ * list-controls and get-control, with the status explanation and the evaluation lookups behind
15
+ * get-control.
16
+ */
17
+ // A not_found is a result, not an error, so its recovery travels in a note, the way
18
+ // framework_not_found lists the ids to choose from. None echoes the id or name that was asked for.
19
+ const NOTE_CONTROL_NOT_FOUND = 'No control matched. Search with `list-controls` (`search`, plus `frameworkId` to narrow) and ' +
20
+ 'call again with the `id` it returns; a deleted control is not found either.';
21
+ const NOTE_SEARCH_INCOMPLETE = `The search stopped after ${shared_js_1.CONTROL_SEARCH_PAGE_LIMIT * shared_js_1.MAX_CONTROL_SEARCH_PAGES} controls, so ` +
22
+ 'this is not proof the control does not exist.';
23
+ /** The single hit an OU reference names, or every hit it could mean. */
24
+ function matchOrgUnits(hits, wanted) {
25
+ const byId = hits.filter((hit) => hit.ou._id === wanted);
26
+ if (byId.length > 0)
27
+ return byId.slice(0, 1);
28
+ const folded = wanted.toLowerCase();
29
+ const byName = hits.filter((hit) => hit.ou.displayName?.trim().toLowerCase() === folded);
30
+ return byName.length > 0 ? byName : hits;
31
+ }
32
+ function orgUnitCandidate(hit) {
33
+ return {
34
+ id: hit.ou._id,
35
+ displayName: hit.ou.displayName,
36
+ namespace: hit.namespace.slug,
37
+ active: hit.ou.active,
38
+ assetCount: hit.ou.assetCount,
39
+ };
40
+ }
41
+ /**
42
+ * An OU reference as the API's `ou` filter takes it. A reference containing a colon is taken as an
43
+ * `_id` and used as given, since entity OU tokens read `<namespace-slug>:<value>`. Anything else
44
+ * is searched for in every enabled namespace (up to MAX_OU_NAMESPACES): an exact id, then an exact
45
+ * display name, then a lone search hit. A namespace whose search fails is dropped and counted; if
46
+ * every one fails there is nothing to report, so it throws.
47
+ */
48
+ async function resolveOrgUnit(client, orgUnit) {
49
+ const startedAt = Date.now();
50
+ const wanted = orgUnit.trim();
51
+ if (wanted.includes(':')) {
52
+ return {
53
+ kind: 'resolved',
54
+ orgUnit: { id: wanted, displayName: null, namespace: null, resolvedBy: 'id_unverified' },
55
+ };
56
+ }
57
+ const namespaces = await client.listOuNamespaces();
58
+ const searched = namespaces.filter((ns) => ns.enabled !== false).slice(0, shared_js_1.MAX_OU_NAMESPACES);
59
+ const settled = await Promise.allSettled(searched.map((ns) => client.listOusByNamespace(ns.slug, wanted)));
60
+ const failed = settled.filter((result) => result.status === 'rejected');
61
+ if (failed.length > 0 && failed.length === searched.length)
62
+ throw failed[0].reason;
63
+ const hits = settled.flatMap((result, index) => result.status === 'fulfilled'
64
+ ? result.value.map((ou) => ({ ou, namespace: searched[index] }))
65
+ : []);
66
+ const matches = matchOrgUnits(hits, wanted);
67
+ if (matches.length === 1) {
68
+ const [{ ou, namespace }] = matches;
69
+ return {
70
+ kind: 'resolved',
71
+ orgUnit: {
72
+ id: ou._id,
73
+ displayName: ou.displayName,
74
+ namespace: namespace.slug,
75
+ resolvedBy: ou._id === wanted ? 'id' : 'name',
76
+ },
77
+ };
78
+ }
79
+ if (matches.length > 1) {
80
+ return {
81
+ kind: 'outcome',
82
+ payload: {
83
+ outcome: 'ambiguous',
84
+ ouResolution: 'ambiguous',
85
+ candidates: matches.slice(0, shared_js_1.MAX_CANDIDATES).map(orgUnitCandidate),
86
+ candidateCount: matches.length,
87
+ namespacesFailed: failed.length,
88
+ },
89
+ };
90
+ }
91
+ return {
92
+ kind: 'outcome',
93
+ payload: {
94
+ outcome: 'org_unit_not_found',
95
+ ouResolution: 'not_found',
96
+ namespaces: searched.map((ns, index) => ({
97
+ slug: ns.slug,
98
+ name: ns.name,
99
+ failed: settled[index].status === 'rejected',
100
+ })),
101
+ namespacesNotSearched: namespaces.length - searched.length,
102
+ units: await suggestOrgUnits(client, searched, startedAt + ORG_UNIT_SUGGESTION_DEADLINE_MS),
103
+ },
104
+ };
105
+ }
106
+ /** Units an `org_unit_not_found` lists per searched namespace, to offer by name. */
107
+ exports.ORG_UNIT_SUGGESTIONS = 10;
108
+ /** From the start of the OU resolution; suggestions not back by then are left out. */
109
+ const ORG_UNIT_SUGGESTION_DEADLINE_MS = 20_000;
110
+ /**
111
+ * Up to ORG_UNIT_SUGGESTIONS units of each searched namespace, unfiltered, so the assistant can
112
+ * offer real names: on j1dev "AWS Production" matched nothing, and the tester found "Gaston AWS"
113
+ * only from a unit token on a failing user (2026-10-15). A namespace whose read fails or is late
114
+ * offers none; the answer does not depend on them.
115
+ */
116
+ async function suggestOrgUnits(client, namespaces, deadlineAt) {
117
+ const reads = await Promise.all(namespaces.map(async (ns) => {
118
+ if (Date.now() >= deadlineAt)
119
+ return [];
120
+ try {
121
+ const units = await (0, shared_js_1.withDeadline)(client.listOusByNamespace(ns.slug, undefined, exports.ORG_UNIT_SUGGESTIONS), deadlineAt);
122
+ return units === shared_js_1.DEADLINE_PASSED ? [] : units.slice(0, exports.ORG_UNIT_SUGGESTIONS);
123
+ }
124
+ catch (error) {
125
+ console.error('Error listing organizational units to suggest:', error);
126
+ return [];
127
+ }
128
+ }));
129
+ return reads.flatMap((units, index) => units.map((ou) => ({
130
+ id: ou._id,
131
+ displayName: ou.displayName ?? null,
132
+ namespace: namespaces[index].slug,
133
+ })));
134
+ }
135
+ /** `ControlFilterInput` from the keys the caller set. An empty list filters nothing: dropped. */
136
+ function controlFilter(params, ouId) {
137
+ const filter = {
138
+ searchText: params.search,
139
+ status: params.status,
140
+ states: params.states,
141
+ effectiveness: params.effectiveness,
142
+ hasValidAttestation: params.hasValidAttestation,
143
+ owner: params.owner,
144
+ catalogs: params.catalogs,
145
+ mitreTechniques: params.mitreTechniques,
146
+ frameworkId: params.frameworkId ? [params.frameworkId] : undefined,
147
+ source: params.source,
148
+ ou: ouId ? [ouId] : undefined,
149
+ };
150
+ const set = Object.entries(filter).filter(([, value]) => value !== undefined && !(Array.isArray(value) && value.length === 0));
151
+ return set.length > 0 ? Object.fromEntries(set) : undefined;
152
+ }
153
+ function failingTestCount(tests) {
154
+ return tests ? tests.filter((test) => !test.deleted && test.status === 'FAIL').length : null;
155
+ }
156
+ function controlRow(control, names, subdomain) {
157
+ return {
158
+ id: control.id,
159
+ name: control.name,
160
+ url: (0, shared_js_1.controlUrl)(control.id, subdomain),
161
+ identifier: control.identifier,
162
+ catalog: control.catalog,
163
+ source: control.source,
164
+ sourceId: control.sourceId,
165
+ state: control.state,
166
+ status: control.status,
167
+ effectiveStatus: control.effectiveStatus,
168
+ hasValidAttestation: control.hasValidAttestation,
169
+ owner: control.owner,
170
+ lastEvaluatedOn: control.lastEvaluatedOn,
171
+ lastEvaluatedOnIso: (0, shared_js_1.toIso)(control.lastEvaluatedOn),
172
+ numberOfTests: control.numberOfTests,
173
+ failingTests: failingTestCount(control.controlTests),
174
+ frameworkIds: control.frameworkIds ?? [],
175
+ frameworkNames: (0, shared_js_1.namesFor)(control.frameworkIds, names),
176
+ mitreTechnique: control.mitreTechnique,
177
+ deleted: control.deleted,
178
+ };
179
+ }
180
+ /**
181
+ * A page read that failed on a caller's cursor. The cursor encodes the query of the call that
182
+ * returned it, so one reused with other filters, edited or made up fails upstream: on j1dev, all
183
+ * three came back as a bare "Internal server error" (2026-10-14). Nothing is retried, since the
184
+ * same cursor with the same filters would fail the same way.
185
+ */
186
+ function cursorRejected(error) {
187
+ const reason = error instanceof Error ? error.message : 'Unknown error';
188
+ return (0, shared_js_1.refusal)('cursor_rejected', `Error listing controls with this cursor: ${reason}. A cursor works only with the exact ` +
189
+ 'filters of the call that returned it. Call again with those filters and that cursor, or ' +
190
+ 'without `cursor` for the first page.');
191
+ }
192
+ /**
193
+ * The controls page and the framework list that names its frameworks, read together. A page read
194
+ * that fails on a cursor is answered as `cursor_rejected`; without a cursor, or when access was
195
+ * refused, the failure is not the cursor's and keeps its own frame.
196
+ */
197
+ async function readControlsPage(client, input, timings) {
198
+ const [pageRead, frameworksRead] = await Promise.allSettled([
199
+ (0, shared_js_1.timed)(timings, 'controls', () => client.listControls(input)),
200
+ (0, shared_js_1.timed)(timings, 'frameworks', () => client.listAllControlFrameworks()),
201
+ ]);
202
+ if (pageRead.status === 'rejected') {
203
+ if (input.cursor === undefined || (0, errors_js_1.accessDeniedStatus)(pageRead.reason) !== null) {
204
+ throw pageRead.reason;
205
+ }
206
+ return { kind: 'cursor_rejected', result: cursorRejected(pageRead.reason) };
207
+ }
208
+ if (frameworksRead.status === 'rejected')
209
+ throw frameworksRead.reason;
210
+ return { kind: 'read', page: pageRead.value, frameworks: frameworksRead.value.frameworks };
211
+ }
212
+ exports.STATUS_EXPLANATIONS = [
213
+ 'not_live',
214
+ 'failing_test',
215
+ 'failing_expired_attestation',
216
+ 'undetermined',
217
+ 'passing_by_tests',
218
+ 'passing_by_attestation',
219
+ 'no_tests',
220
+ 'no_datapoints',
221
+ ];
222
+ function passesByTests({ liveTests }) {
223
+ return liveTests.some((test) => test.status === 'PASS');
224
+ }
225
+ function passesByAttestation({ facts, attestations }) {
226
+ return (facts.hasValidAttestation === true ||
227
+ attestations.some((attestation) => attestation.state === 'ACTIVE'));
228
+ }
229
+ /**
230
+ * Why CCM stored the status it did, first match wins. The order is CCM's own recomputation
231
+ * (apps, `controlTest/controlTestRuleEvaluationCompleted/updateControlStatus.ts`,
232
+ * `recomputeControlStatus`): any failing test or any expired, unrevoked attestation fails the
233
+ * control; otherwise any test with status PASS passes it; otherwise a valid attestation passes it;
234
+ * otherwise it has no status. Only LIVE controls are evaluated. CCM never consults effectiveness,
235
+ * so a test whose query saw no data (a GOOD test with zero rows) passes and counts;
236
+ * `passingWithoutData` flags that case rather than this explanation hiding it. A stored FAIL these
237
+ * facts cannot account for is `undetermined` rather than a guess: when the attestations could not
238
+ * be read, or when nothing read passes the control either. When the facts do pass it, they are
239
+ * explained, and the caller reports the stored FAIL as stale.
240
+ */
241
+ const STATUS_RULES = [
242
+ ['not_live', ({ facts }) => facts.state !== 'LIVE'],
243
+ ['failing_test', ({ liveTests }) => liveTests.some((test) => test.status === 'FAIL')],
244
+ [
245
+ 'failing_expired_attestation',
246
+ ({ attestations }) => attestations.some((attestation) => attestation.state === 'EXPIRED'),
247
+ ],
248
+ [
249
+ 'undetermined',
250
+ (evidence) => evidence.facts.status === 'FAIL' &&
251
+ (evidence.facts.attestations === 'unavailable' ||
252
+ !(passesByTests(evidence) || passesByAttestation(evidence))),
253
+ ],
254
+ ['passing_by_tests', passesByTests],
255
+ ['passing_by_attestation', passesByAttestation],
256
+ [
257
+ 'no_tests',
258
+ ({ facts, liveTests }) => liveTests.length === 0 || facts.effectiveStatus === 'NO_TESTS',
259
+ ],
260
+ [
261
+ 'no_datapoints',
262
+ ({ facts, liveTests }) => facts.effectiveStatus === 'NO_DATAPOINTS' || liveTests.every((test) => !test.status),
263
+ ],
264
+ ];
265
+ /** The status an explanation stands for, where it stands for one. */
266
+ const EXPECTED_STATUS = {
267
+ failing_test: 'FAIL',
268
+ failing_expired_attestation: 'FAIL',
269
+ passing_by_tests: 'PASS',
270
+ passing_by_attestation: 'PASS',
271
+ };
272
+ /**
273
+ * The status the facts call for, when CCM's stored status disagrees with them. CCM re-scores an
274
+ * attested control within a day of an expiry and on its next test run, so the stored status can
275
+ * trail the facts: on j1dev a control whose last attestation had lapsed 20 s before still read
276
+ * PASS beside a `failing_expired_attestation` explanation (2026-10-14).
277
+ */
278
+ function staleStatus(explanation, stored) {
279
+ const expected = EXPECTED_STATUS[explanation];
280
+ if (expected === 'FAIL')
281
+ return stored === 'FAIL' ? null : expected;
282
+ if (expected === 'PASS')
283
+ return stored === 'FAIL' ? expected : null;
284
+ return null;
285
+ }
286
+ /** Why a control has the status it has, as one of STATUS_EXPLANATIONS. */
287
+ function explainControlStatus(facts) {
288
+ const evidence = {
289
+ facts,
290
+ liveTests: facts.tests.filter((test) => !test.deleted),
291
+ // Unreadable attestations prove nothing either way, so they can neither fail nor pass it.
292
+ attestations: facts.attestations === 'unavailable' ? [] : facts.attestations,
293
+ };
294
+ const rule = STATUS_RULES.find(([, applies]) => applies(evidence));
295
+ return rule ? rule[0] : 'undetermined';
296
+ }
297
+ const SKIPPED = { latestEvaluationStatus: 'skipped', latestEvaluation: null };
298
+ const NO_EVALUATIONS = { latestEvaluationStatus: 'none', latestEvaluation: null };
299
+ /** A live test backed by a rule — the only kind with evaluations to look up. */
300
+ function hasEvaluations(test) {
301
+ return !test.deleted && typeof test.referencedRuleId === 'string' && test.referencedRuleId !== '';
302
+ }
303
+ /** The descriptor for the test's own query (a test persists only `queries[0]`), else the first. */
304
+ function pickDescriptor(descriptors, queryName) {
305
+ const list = descriptors ?? [];
306
+ return list.find((descriptor) => descriptor.name === queryName) ?? list[0];
307
+ }
308
+ function latestFromPage(test, results, moreInWindow) {
309
+ const window = { evaluationsInWindow: results.length, moreInWindow };
310
+ if (results.length === 0) {
311
+ return { latestEvaluationStatus: 'none', latestEvaluation: null, ...window };
312
+ }
313
+ // The page's sort order is unverified, so the newest is picked here rather than assumed first.
314
+ const latest = results.reduce((newest, entry) => entry.timestamp > newest.timestamp ? entry : newest);
315
+ // A failed run is still the latest evaluation, but it stored no results to read.
316
+ const descriptor = latest.tag === shared_js_1.EVALUATION_FAILURE_TAG
317
+ ? undefined
318
+ : pickDescriptor(latest.rawDataDescriptors, test.queries?.[0]?.name);
319
+ return {
320
+ latestEvaluationStatus: 'found',
321
+ latestEvaluation: {
322
+ rawDataKey: descriptor?.rawDataKey ?? null,
323
+ resultCount: descriptor?.recordCount ?? null,
324
+ evaluatedOn: (0, shared_js_1.toIso)(latest.timestamp),
325
+ timestamp: latest.timestamp,
326
+ tag: latest.tag ?? null,
327
+ },
328
+ ...window,
329
+ };
330
+ }
331
+ /**
332
+ * The latest evaluation of the rule behind a control test: the `rawDataKey` that
333
+ * `get-rule-evaluation-query-results` turns into the assets the test scored.
334
+ *
335
+ * One page of the rule's evaluations from 30 days before the test's `lastEvaluatedOn` to now,
336
+ * raced against `deadlineAt` (see `evaluationDeadline`). `none` without a
337
+ * call for a deleted test or one with no rule; `skipped` past the deadline; `error` on a failed
338
+ * read, which never fails the control read around it.
339
+ */
340
+ async function lookupLatestEvaluation(client, test, deadlineAt) {
341
+ if (!hasEvaluations(test))
342
+ return NO_EVALUATIONS;
343
+ const now = Date.now();
344
+ if (now >= deadlineAt)
345
+ return SKIPPED;
346
+ try {
347
+ const page = await (0, shared_js_1.withDeadline)(client.listRuleEvaluations({
348
+ collectionType: 'RULE_EVALUATION',
349
+ collectionOwnerId: test.referencedRuleId,
350
+ beginTimestamp: (test.lastEvaluatedOn ?? now) - shared_js_1.EVALUATION_WINDOW_MS,
351
+ endTimestamp: now,
352
+ limit: shared_js_1.EVALUATION_PAGE_LIMIT,
353
+ }), deadlineAt);
354
+ if (page === shared_js_1.DEADLINE_PASSED)
355
+ return SKIPPED;
356
+ if (!Array.isArray(page?.results)) {
357
+ throw new Error('Invalid response structure from JupiterOne API: ' +
358
+ 'listCollectionResults.results is not an array');
359
+ }
360
+ return latestFromPage(test, page.results, page.pageInfo?.hasNextPage === true);
361
+ }
362
+ catch (error) {
363
+ console.error('Error looking up the latest control-test evaluation:', error);
364
+ return { latestEvaluationStatus: 'error', latestEvaluation: null };
365
+ }
366
+ }
367
+ /**
368
+ * Every test's lookup, timed together, for MAX_EVALUATION_LOOKUPS rule-backed tests: the failing
369
+ * ones first, awaited, then the rest in list order with whatever budget remains. A failing test's
370
+ * evidence is what explains the control. In list order alone, a 50-test SOC 2 control on j1dev
371
+ * with 19 failing tests got lookups for 4 of them (2026-10-14); admitted first but run alongside
372
+ * the rest, both failing tests of a control on a slow j1dev backend were the lookups the deadline
373
+ * cut, while both passing ones came back (2026-10-15).
374
+ */
375
+ async function lookupLatestEvaluations(client, tests, deadlineAt) {
376
+ const startedAt = Date.now();
377
+ const backed = tests.filter(hasEvaluations);
378
+ const failing = backed.filter((test) => test.status === 'FAIL').slice(0, shared_js_1.MAX_EVALUATION_LOOKUPS);
379
+ const rest = backed
380
+ .filter((test) => test.status !== 'FAIL')
381
+ .slice(0, shared_js_1.MAX_EVALUATION_LOOKUPS - failing.length);
382
+ const found = new Map();
383
+ const lookUp = async (batch) => {
384
+ const results = await Promise.all(batch.map((test) => lookupLatestEvaluation(client, test, deadlineAt)));
385
+ batch.forEach((test, index) => found.set(test, results[index]));
386
+ };
387
+ await lookUp(failing);
388
+ await lookUp(rest);
389
+ const lookups = tests.map((test) => found.get(test) ?? (hasEvaluations(test) ? SKIPPED : NO_EVALUATIONS));
390
+ return { lookups, ms: Date.now() - startedAt };
391
+ }
392
+ const LOOKUP_KEYS = ['controlId', 'identifier', 'controlName'];
393
+ /**
394
+ * `includeDeletedTests` reaches only the control's test list: `control(id)` never returns a
395
+ * deleted control, whatever the flag says.
396
+ */
397
+ async function fetchControl(client, id, lookupBy, includeDeletedTests) {
398
+ try {
399
+ const control = await client.getControl(id, includeDeletedTests);
400
+ return { kind: 'control', control, lookupBy };
401
+ }
402
+ catch (error) {
403
+ if ((0, shared_js_1.isNotFound)(error)) {
404
+ return {
405
+ kind: 'outcome',
406
+ payload: { outcome: 'not_found', lookupBy, note: NOTE_CONTROL_NOT_FOUND },
407
+ };
408
+ }
409
+ throw error;
410
+ }
411
+ }
412
+ /**
413
+ * Up to MAX_CONTROL_SEARCH_PAGES pages of a control search. `searchText` is a substring match
414
+ * over name, description, identifier and id, so a short identifier ("1.1") can bury its exact
415
+ * match under dozens of partial ones; one page would report it missing.
416
+ *
417
+ * Non-deleted controls only, in any state: `control(id)` cannot read a deleted one, so a deleted
418
+ * match could only turn a `found` into `ambiguous`, or end as a `not_found` after the read.
419
+ */
420
+ function searchControls(client, filter) {
421
+ return (0, shared_js_1.walkControls)(client, filter, {
422
+ limit: shared_js_1.CONTROL_SEARCH_PAGE_LIMIT,
423
+ maxPages: shared_js_1.MAX_CONTROL_SEARCH_PAGES,
424
+ });
425
+ }
426
+ /** Exact identifier only; for a name, the exact matches when there are any, else every hit. */
427
+ function matchControls(items, lookupBy, wanted) {
428
+ const folded = wanted.toLowerCase();
429
+ if (lookupBy === 'identifier') {
430
+ return items.filter((control) => control.identifier?.trim().toLowerCase() === folded);
431
+ }
432
+ const exact = items.filter((control) => control.name?.trim().toLowerCase() === folded);
433
+ return exact.length > 0 ? exact : items;
434
+ }
435
+ /**
436
+ * One ambiguous match. Identifiers repeat across frameworks with the same name and often a null
437
+ * catalog (three LIVE `ACCT.02` controls on j1dev, 2026-10-14), so the frameworks are what tells
438
+ * them apart.
439
+ */
440
+ function controlCandidate(control, names, subdomain) {
441
+ return {
442
+ id: control.id,
443
+ name: control.name,
444
+ url: (0, shared_js_1.controlUrl)(control.id, subdomain),
445
+ identifier: control.identifier,
446
+ catalog: control.catalog,
447
+ state: control.state,
448
+ status: control.status,
449
+ frameworkIds: control.frameworkIds ?? [],
450
+ frameworkNames: (0, shared_js_1.namesFor)(control.frameworkIds, names),
451
+ };
452
+ }
453
+ async function resolveControl(client, lookupBy, value, includeDeletedTests, context) {
454
+ if (lookupBy === 'controlId') {
455
+ return fetchControl(client, value, lookupBy, includeDeletedTests);
456
+ }
457
+ const filter = lookupBy === 'identifier' ? { searchText: value } : { nameContains: value };
458
+ const search = await searchControls(client, filter);
459
+ const matches = matchControls(search.items, lookupBy, value);
460
+ // Only a complete search proves the match is the only one: past the search's cap a second match
461
+ // can sit on a page it never read, so a lone match from a cut-short search is `ambiguous`
462
+ // (PR #55 review).
463
+ if (matches.length === 1 && search.complete) {
464
+ return fetchControl(client, matches[0].id, lookupBy, includeDeletedTests);
465
+ }
466
+ // CCM evaluates only LIVE controls, so the one LIVE match is almost always the one meant:
467
+ // `BEDROCK-009` matched a LIVE and a DRAFT control on j1dev and cost a second call (2026-10-14).
468
+ // Only a complete search shows that no other LIVE match exists.
469
+ const live = matches.filter((match) => match.state === 'LIVE');
470
+ if (live.length === 1 && search.complete) {
471
+ const resolved = await fetchControl(client, live[0].id, lookupBy, includeDeletedTests);
472
+ if (resolved.kind === 'outcome')
473
+ return resolved;
474
+ return { ...resolved, otherCandidates: matches.filter((match) => match !== live[0]) };
475
+ }
476
+ if (matches.length === 0) {
477
+ const note = search.complete
478
+ ? NOTE_CONTROL_NOT_FOUND
479
+ : `${NOTE_CONTROL_NOT_FOUND} ${NOTE_SEARCH_INCOMPLETE}`;
480
+ return {
481
+ kind: 'outcome',
482
+ payload: { outcome: 'not_found', lookupBy, searchComplete: search.complete, note },
483
+ };
484
+ }
485
+ const [subdomain, { frameworks }] = await Promise.all([
486
+ context.subdomainRead,
487
+ (0, shared_js_1.timed)(context.timings, 'frameworks', () => client.listAllControlFrameworks()),
488
+ ]);
489
+ const names = (0, shared_js_1.frameworkNameMap)(frameworks);
490
+ return {
491
+ kind: 'outcome',
492
+ payload: {
493
+ outcome: 'ambiguous',
494
+ lookupBy,
495
+ candidates: matches
496
+ .slice(0, shared_js_1.MAX_CANDIDATES)
497
+ .map((match) => controlCandidate(match, names, subdomain)),
498
+ candidateCount: matches.length,
499
+ searchComplete: search.complete,
500
+ },
501
+ };
502
+ }
503
+ function projectControl(control) {
504
+ return {
505
+ id: control.id,
506
+ name: control.name,
507
+ identifier: control.identifier,
508
+ catalog: control.catalog,
509
+ source: control.source,
510
+ sourceId: control.sourceId,
511
+ state: control.state,
512
+ status: control.status,
513
+ effectiveStatus: control.effectiveStatus,
514
+ hasValidAttestation: control.hasValidAttestation,
515
+ owner: control.owner,
516
+ description: control.description,
517
+ remediation: control.remediation,
518
+ exceptionProcess: control.exceptionProcess,
519
+ mitreTechnique: control.mitreTechnique,
520
+ resourceGroupId: control.resourceGroupId,
521
+ frameworkIds: control.frameworkIds ?? [],
522
+ numberOfTests: control.numberOfTests,
523
+ configured: control.configured,
524
+ lastEvaluatedOn: control.lastEvaluatedOn,
525
+ lastEvaluatedOnIso: (0, shared_js_1.toIso)(control.lastEvaluatedOn),
526
+ createdOn: control.createdOn,
527
+ deleted: control.deleted,
528
+ };
529
+ }
530
+ function projectRequirement(requirement, names) {
531
+ return {
532
+ id: requirement.id,
533
+ identifier: requirement.identifier,
534
+ title: requirement.title,
535
+ section: requirement.section,
536
+ priority: requirement.priority,
537
+ frameworkIds: requirement.frameworkIds ?? [],
538
+ frameworkNames: (0, shared_js_1.namesFor)(requirement.frameworkIds, names),
539
+ };
540
+ }
541
+ /** A test persists only its first query (multi-query tests do not exist), so it is flattened. */
542
+ function projectTest(test, lookup) {
543
+ const query = test.queries?.[0];
544
+ return {
545
+ id: test.id,
546
+ name: test.name,
547
+ description: test.description,
548
+ status: test.status,
549
+ deleted: test.deleted,
550
+ query: query?.query ?? null,
551
+ resultsAre: query?.resultsAre ?? null,
552
+ recordCount: query?.recordCount ?? null,
553
+ effective: query?.effective ?? null,
554
+ referencedRuleId: test.referencedRuleId,
555
+ lastEvaluatedOn: test.lastEvaluatedOn,
556
+ lastEvaluatedOnIso: (0, shared_js_1.toIso)(test.lastEvaluatedOn),
557
+ ...lookup,
558
+ };
559
+ }
560
+ /**
561
+ * A PASS that rests only on tests whose queries saw no data. CCM counts such a test as passing, so
562
+ * the status is real, but nothing was checked: on j1dev, BEDROCK-001 stored PASS with both tests
563
+ * `effective: false` (2026-10-14). An unknown `effective` counts as data.
564
+ */
565
+ function passingWithoutData(control, tests) {
566
+ const passing = tests.filter((test) => !test.deleted && test.status === 'PASS');
567
+ return (control.status === 'PASS' &&
568
+ passing.length > 0 &&
569
+ passing.every((test) => test.queries?.[0]?.effective === false));
570
+ }
571
+ /**
572
+ * When get-control's evaluation lookups must stop: READ_FANOUT_DEADLINE_MS after the control read
573
+ * returned, and never past GET_CONTROL_DEADLINE_MS from request start.
574
+ */
575
+ function evaluationDeadline(startedAt) {
576
+ return Math.min(startedAt + shared_js_1.GET_CONTROL_DEADLINE_MS, Date.now() + shared_js_1.READ_FANOUT_DEADLINE_MS);
577
+ }
578
+ /**
579
+ * A read get-control can answer without: raced against the budget, and skipped with its reason
580
+ * rather than failing the call when it runs out of time or fails.
581
+ */
582
+ async function budgeted(work, deadlineAt, what) {
583
+ if (Date.now() >= deadlineAt)
584
+ return { kind: 'skipped', reason: 'time_budget' };
585
+ try {
586
+ const value = await (0, shared_js_1.withDeadline)(work(), deadlineAt);
587
+ return value === shared_js_1.DEADLINE_PASSED
588
+ ? { kind: 'skipped', reason: 'time_budget' }
589
+ : { kind: 'read', value };
590
+ }
591
+ catch (error) {
592
+ console.error(`Error reading ${what} for get-control:`, error);
593
+ return { kind: 'skipped', reason: 'read_failed' };
594
+ }
595
+ }
596
+ /** A control's attestations, `'unavailable'` when refused or not back by the deadline. */
597
+ async function attestationsBy(read, deadlineAt) {
598
+ const settled = await (0, shared_js_1.withDeadline)(read, deadlineAt);
599
+ return settled === shared_js_1.DEADLINE_PASSED ? 'unavailable' : settled;
600
+ }
601
+ function readControlAttestations(client, controlId, timings) {
602
+ return (0, shared_js_1.timed)(timings, 'attestations', () => client.listAttestations({ controlId }).catch(shared_js_1.degradeOnAccessDenied));
603
+ }
604
+ /**
605
+ * Everything behind a found control, inside GET_CONTROL_DEADLINE_MS from the call's start. On
606
+ * j1dev 20 of 27 get-control calls hit the remote's 55 s abort with single reads at 18–30 s
607
+ * (2026-10-15). The control and its tests always come back; attestations that are not back in
608
+ * time read as `'unavailable'`; requirements and frameworks are skipped with their reason.
609
+ */
610
+ async function describeControl(client, resolution, startedAt, context) {
611
+ const { control, lookupBy } = resolution;
612
+ const { timings } = context;
613
+ const budgetAt = startedAt + shared_js_1.GET_CONTROL_DEADLINE_MS;
614
+ const tests = control.controlTests ?? [];
615
+ const evaluations = lookupLatestEvaluations(client, tests, evaluationDeadline(startedAt));
616
+ const [requirementRead, attestations, frameworkRead, { lookups, ms }] = await Promise.all([
617
+ (0, shared_js_1.timed)(timings, 'requirements', () => budgeted(() => client.listControlRequirements(control.id), budgetAt, 'requirements')),
618
+ attestationsBy(context.attestationsRead ?? readControlAttestations(client, control.id, timings), budgetAt),
619
+ (0, shared_js_1.timed)(timings, 'frameworks', () => budgeted(() => client.listAllControlFrameworks(), budgetAt, 'frameworks')),
620
+ evaluations,
621
+ ]);
622
+ timings.evaluations = ms;
623
+ const names = (0, shared_js_1.frameworkNameMap)(frameworkRead.kind === 'read' ? frameworkRead.value.frameworks : []);
624
+ const subdomain = await (0, shared_js_1.subdomainBy)(context.subdomainRead, budgetAt);
625
+ const skippedTests = lookups.filter((lookup) => lookup.latestEvaluationStatus === 'skipped').length;
626
+ const statusExplanation = explainControlStatus({
627
+ state: control.state,
628
+ status: control.status,
629
+ effectiveStatus: control.effectiveStatus,
630
+ hasValidAttestation: control.hasValidAttestation,
631
+ tests,
632
+ attestations,
633
+ });
634
+ const expectedStatus = staleStatus(statusExplanation, control.status);
635
+ return {
636
+ outcome: 'found',
637
+ lookupBy,
638
+ ...(resolution.otherCandidates
639
+ ? {
640
+ otherCandidates: resolution.otherCandidates
641
+ .slice(0, shared_js_1.MAX_CANDIDATES)
642
+ .map((candidate) => controlCandidate(candidate, names, subdomain)),
643
+ }
644
+ : {}),
645
+ control: { ...projectControl(control), url: (0, shared_js_1.controlUrl)(control.id, subdomain) },
646
+ statusExplanation,
647
+ ...(expectedStatus ? { storedStatusStale: true, expectedStatus } : {}),
648
+ passingWithoutData: passingWithoutData(control, tests),
649
+ // statusExplanation names the first cause; a control can fail for several, and fixing one
650
+ // leaves it failing on the next (6.1 on j1dev: a failing test and an expired attestation).
651
+ blockers: failureCauses(tests, attestations === 'unavailable' ? [] : attestations),
652
+ ...(frameworkRead.kind === 'read'
653
+ ? {
654
+ // With its link: the instructions tell the assistant to give a framework's url whenever
655
+ // it names one (PR #55 review).
656
+ frameworks: (control.frameworkIds ?? []).map((id) => ({
657
+ id,
658
+ name: names.get(id) ?? null,
659
+ url: (0, shared_js_1.frameworkUrl)(id, subdomain),
660
+ })),
661
+ }
662
+ : { frameworks: [], frameworksSkipped: frameworkRead.reason }),
663
+ ...(requirementRead.kind === 'read'
664
+ ? {
665
+ requirements: requirementRead.value.requirements.map((entry) => projectRequirement(entry, names)),
666
+ requirementsComplete: requirementRead.value.complete,
667
+ }
668
+ : {
669
+ requirements: [],
670
+ requirementsComplete: false,
671
+ requirementsSkipped: requirementRead.reason,
672
+ }),
673
+ attestations: attestations === 'unavailable' ? attestations : attestations.map(shared_js_1.projectAttestation),
674
+ tests: tests.map((test, index) => projectTest(test, lookups[index])),
675
+ ...(skippedTests > 0 ? { skippedTests } : {}),
676
+ evaluationLookupMs: ms,
677
+ timingsMs: timings,
678
+ };
679
+ }
680
+ /**
681
+ * Everything that fails a control by CCM's rules: each test that fails and is not deleted, and each
682
+ * expired attestation (the API's EXPIRED state is `revoked != true AND expiresOn <= now`).
683
+ */
684
+ function failureCauses(tests, attestations) {
685
+ return [
686
+ ...tests
687
+ .filter((test) => !test.deleted && test.status === 'FAIL')
688
+ .map((test) => ({ type: 'failing_test', id: test.id, name: test.name })),
689
+ ...attestations
690
+ .filter((attestation) => attestation.state === 'EXPIRED')
691
+ .map((attestation) => ({
692
+ type: 'expired_attestation',
693
+ id: attestation.id,
694
+ subject: attestation.subject,
695
+ expiresOnIso: (0, shared_js_1.toIso)(attestation.expiresOn),
696
+ })),
697
+ ];
698
+ }
699
+ exports.controlTools = [
700
+ (0, types_js_1.defineTool)({
701
+ name: 'list-controls',
702
+ title: 'List Controls',
703
+ description: (0, load_description_js_1.loadDescription)('list-controls.md'),
704
+ inputSchema: {
705
+ search: zod_1.z
706
+ .string()
707
+ .min(1)
708
+ .optional()
709
+ .describe('Case-insensitive text matched against control name, description, identifier and id.'),
710
+ status: zod_1.z
711
+ .array(zod_1.z.enum(['PASS', 'FAIL']))
712
+ .optional()
713
+ .describe('Only controls whose evaluated status is one of these.'),
714
+ states: zod_1.z
715
+ .array(zod_1.z.enum(['DRAFT', 'REVIEW', 'LIVE', 'RETIRED']))
716
+ .optional()
717
+ .describe('Only controls in one of these lifecycle states. Only LIVE controls are evaluated.'),
718
+ effectiveness: zod_1.z
719
+ .enum(['NO_TESTS', 'NO_DATAPOINTS'])
720
+ .optional()
721
+ .describe('NO_TESTS: controls with no tests. NO_DATAPOINTS: controls whose tests have produced ' +
722
+ 'no results.'),
723
+ hasValidAttestation: zod_1.z
724
+ .boolean()
725
+ .optional()
726
+ .describe('true: controls covered by at least one valid attestation; false: those with none.'),
727
+ owner: (0, shared_js_1.ownerEmail)().optional().describe("The control owner's email address (exact match)."),
728
+ catalogs: zod_1.z
729
+ .array(zod_1.z.string().min(1))
730
+ .optional()
731
+ .describe('Only controls from these catalogs.'),
732
+ mitreTechniques: zod_1.z
733
+ .array(zod_1.z.string().regex(/^T\d{4}(\.\d{3})?$/))
734
+ .optional()
735
+ .describe('MITRE ATT&CK technique ids, e.g. "T1078" or "T1078.004".'),
736
+ frameworkId: zod_1.z
737
+ .string()
738
+ .min(1)
739
+ .optional()
740
+ .describe('Only controls mapped to this framework (an `id` from `get-compliance-summary`).'),
741
+ source: zod_1.z
742
+ .enum(['J1', 'UCF', 'UPLOAD', 'JSON'])
743
+ .optional()
744
+ .describe('Only controls from this source.'),
745
+ orgUnit: zod_1.z
746
+ .string()
747
+ .trim()
748
+ .min(1)
749
+ .optional()
750
+ .describe('An organizational unit, by its id (contains a ":"; used unchecked, reported as ' +
751
+ '`ouResolution: "id_unverified"`) or its display name. A name that matches several ' +
752
+ 'units returns `outcome: "ambiguous"` with the candidates and their ids.'),
753
+ sort: zod_1.z
754
+ .object({
755
+ field: zod_1.z.enum(['NAME', 'SOURCE', 'STATUS', 'LAST_EVALUATED_ON', 'OWNER']),
756
+ order: zod_1.z.enum(['ASC', 'DESC']),
757
+ })
758
+ .optional()
759
+ .describe('Sort field and direction.'),
760
+ limit: zod_1.z
761
+ .number()
762
+ .int()
763
+ .min(1)
764
+ .max(250)
765
+ .optional()
766
+ .describe(`Rows per page, 1–250 (default ${shared_js_1.DEFAULT_CONTROL_PAGE_LIMIT}).`),
767
+ cursor: zod_1.z.string().optional().describe('`pageInfo.endCursor` from the previous page.'),
768
+ includeDeleted: zod_1.z.boolean().optional().describe('Include deleted controls.'),
769
+ },
770
+ outputSchema: schemas_js_1.listControlsOutput,
771
+ annotations: types_js_1.READ_ONLY,
772
+ accessDeniedHint: shared_js_1.ACCESS_DENIED_HINT,
773
+ errorContext: 'Error listing controls',
774
+ handler: async (params, client) => {
775
+ const timings = {};
776
+ let orgUnit;
777
+ if (params.orgUnit !== undefined) {
778
+ const wanted = params.orgUnit;
779
+ const resolution = await (0, shared_js_1.timed)(timings, 'orgUnit', () => resolveOrgUnit(client, wanted));
780
+ if (resolution.kind === 'outcome') {
781
+ return (0, result_js_1.structuredResult)({ ...resolution.payload, timingsMs: timings });
782
+ }
783
+ orgUnit = resolution.orgUnit;
784
+ }
785
+ const subdomainRead = (0, shared_js_1.readSubdomain)(client, timings);
786
+ const read = await readControlsPage(client, {
787
+ cursor: params.cursor,
788
+ limit: params.limit ?? shared_js_1.DEFAULT_CONTROL_PAGE_LIMIT,
789
+ sort: params.sort,
790
+ includeDeleted: params.includeDeleted,
791
+ filter: controlFilter(params, orgUnit?.id),
792
+ }, timings);
793
+ if (read.kind === 'cursor_rejected')
794
+ return read.result;
795
+ const { page, frameworks } = read;
796
+ const names = (0, shared_js_1.frameworkNameMap)(frameworks);
797
+ const subdomain = await subdomainRead;
798
+ const controls = page.items.map((control) => controlRow(control, names, subdomain));
799
+ return (0, result_js_1.structuredResult)({
800
+ outcome: 'ok',
801
+ returned: controls.length,
802
+ controls,
803
+ pageInfo: page.pageInfo,
804
+ ...(orgUnit ? { orgUnit, ouResolution: orgUnit.resolvedBy } : {}),
805
+ timingsMs: timings,
806
+ });
807
+ },
808
+ }),
809
+ (0, types_js_1.defineTool)({
810
+ name: 'get-control',
811
+ title: 'Control Details',
812
+ description: (0, load_description_js_1.loadDescription)('get-control.md'),
813
+ inputSchema: {
814
+ controlId: zod_1.z
815
+ .string()
816
+ .trim()
817
+ .min(1)
818
+ .optional()
819
+ .describe('The exact control id (`ccm_c_<SOURCE>_<sourceId>`), e.g. from `list-controls`.'),
820
+ identifier: zod_1.z
821
+ .string()
822
+ .trim()
823
+ .min(1)
824
+ .optional()
825
+ .describe('The control identifier the framework shows, e.g. "AC-2" or "CC6.1". Matched exactly, ' +
826
+ 'ignoring case.'),
827
+ controlName: zod_1.z
828
+ .string()
829
+ .trim()
830
+ .min(1)
831
+ .optional()
832
+ .describe('The control name. An exact match (ignoring case) wins; otherwise a single partial ' +
833
+ 'match is used, and several return `outcome: "ambiguous"` with candidates.'),
834
+ includeDeleted: zod_1.z.boolean().optional().describe("Also return the control's deleted tests."),
835
+ },
836
+ outputSchema: schemas_js_1.getControlOutput,
837
+ annotations: types_js_1.READ_ONLY,
838
+ accessDeniedHint: shared_js_1.ACCESS_DENIED_HINT,
839
+ errorContext: 'Error fetching control',
840
+ handler: async (params, client) => {
841
+ const startedAt = Date.now();
842
+ const given = LOOKUP_KEYS.filter((key) => params[key] !== undefined);
843
+ if (given.length !== 1) {
844
+ return (0, shared_js_1.validationError)('Pass exactly one of `controlId`, `identifier` or `controlName` to look up a control.');
845
+ }
846
+ const [lookupBy] = given;
847
+ const timings = {};
848
+ const subdomainRead = (0, shared_js_1.readSubdomain)(client, timings);
849
+ // An id is all the attestation read needs, so it runs beside the control read.
850
+ const attestationsRead = lookupBy === 'controlId'
851
+ ? readControlAttestations(client, params.controlId, timings)
852
+ : undefined;
853
+ // Awaited once the control is found; a not_found or a failed read leaves it behind.
854
+ attestationsRead?.catch(() => undefined);
855
+ const context = { subdomainRead, timings, attestationsRead };
856
+ const resolution = await (0, shared_js_1.timed)(timings, 'control', () => resolveControl(client, lookupBy, params[lookupBy], params.includeDeleted ?? false, context));
857
+ if (resolution.kind === 'outcome') {
858
+ await subdomainRead;
859
+ return (0, result_js_1.structuredResult)({ ...resolution.payload, timingsMs: { ...timings } });
860
+ }
861
+ return (0, result_js_1.structuredResult)(await describeControl(client, resolution, startedAt, context));
862
+ },
863
+ }),
864
+ ];
865
+ //# sourceMappingURL=controls.js.map