@aigis-ai/cli 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/BENCHMARKS.md +89 -0
  2. package/CHANGELOG.md +49 -0
  3. package/CONTRIBUTING.md +10 -0
  4. package/IMPROVEMENTS.md +41 -0
  5. package/README.md +65 -4
  6. package/SKILL.md +20 -15
  7. package/bin/aigis.js +67 -6
  8. package/content/index/atlas-NOTICE.md +238 -0
  9. package/content/index/atlas-entry-points.json +15 -0
  10. package/content/index/atlas.json +2694 -0
  11. package/content/index/audit-scan.md +6 -0
  12. package/content/index/auto-verify-rules.json +139 -0
  13. package/content/index/taxonomy.md +1 -1
  14. package/content/skills/areas/agent-permissions.md +228 -0
  15. package/content/skills/areas/agent-tool-safety.md +217 -0
  16. package/content/skills/areas/audit-logging.md +1 -0
  17. package/content/skills/areas/bias-monitoring.md +1 -0
  18. package/content/skills/areas/confidence-scoring.md +1 -0
  19. package/content/skills/areas/data-integrity.md +1 -0
  20. package/content/skills/areas/explainability.md +1 -0
  21. package/content/skills/areas/fallback-patterns.md +1 -0
  22. package/content/skills/areas/human-oversight.md +1 -0
  23. package/content/skills/areas/input-validation.md +1 -0
  24. package/content/skills/areas/monitoring.md +1 -0
  25. package/content/skills/areas/output-sanitization.md +1 -0
  26. package/content/skills/areas/pii-handling.md +1 -0
  27. package/content/skills/areas/prompt-security.md +1 -0
  28. package/content/skills/areas/rag-security.md +1 -0
  29. package/content/skills/areas/rate-limiting.md +1 -0
  30. package/content/skills/areas/supply-chain.md +1 -0
  31. package/content/skills/core.md +15 -0
  32. package/content/templates/threat-model.md +80 -0
  33. package/content/verify/checklist-agent-permissions.md +16 -0
  34. package/content/verify/checklist-agent-tool-safety.md +15 -0
  35. package/docs/frontmatter-schema.md +15 -1
  36. package/lib/atlas.js +302 -0
  37. package/lib/auto-verify.js +49 -5
  38. package/lib/build.js +77 -10
  39. package/lib/classify.js +53 -5
  40. package/lib/fetch.js +2 -1
  41. package/lib/report.js +22 -1
  42. package/lib/search.js +6 -2
  43. package/lib/special-recognizers.js +206 -1
  44. package/lib/threats.js +381 -0
  45. package/package.json +4 -1
  46. package/scripts/area-controls-baseline.json +53 -3
  47. package/scripts/area-frontmatter.schema.json +6 -0
  48. package/scripts/build-atlas-index.js +316 -0
  49. package/scripts/test-all.js +61 -0
  50. package/scripts/validate-area-frontmatter.js +58 -2
@@ -9,6 +9,9 @@
9
9
  "iso42001": [
10
10
  "Clause-9.1",
11
11
  "Annex-A.6"
12
+ ],
13
+ "atlas": [
14
+ "AML.M0024"
12
15
  ]
13
16
  },
14
17
  "bias-monitoring": {
@@ -21,7 +24,8 @@
21
24
  "iso42001": [
22
25
  "Clause-6.1",
23
26
  "Annex-C"
24
- ]
27
+ ],
28
+ "atlas": []
25
29
  },
26
30
  "confidence-scoring": {
27
31
  "owasp": [
@@ -34,6 +38,9 @@
34
38
  ],
35
39
  "iso42001": [
36
40
  "Annex-A.8"
41
+ ],
42
+ "atlas": [
43
+ "AML.M0020"
37
44
  ]
38
45
  },
39
46
  "data-integrity": {
@@ -46,6 +53,11 @@
46
53
  ],
47
54
  "iso42001": [
48
55
  "Annex-A.7"
56
+ ],
57
+ "atlas": [
58
+ "AML.M0007",
59
+ "AML.M0014",
60
+ "AML.M0025"
49
61
  ]
50
62
  },
51
63
  "explainability": {
@@ -57,7 +69,8 @@
57
69
  "iso42001": [
58
70
  "Annex-A.8",
59
71
  "Clause-7.4"
60
- ]
72
+ ],
73
+ "atlas": []
61
74
  },
62
75
  "fallback-patterns": {
63
76
  "owasp": [],
@@ -68,7 +81,8 @@
68
81
  ],
69
82
  "iso42001": [
70
83
  "Clause-8.2"
71
- ]
84
+ ],
85
+ "atlas": []
72
86
  },
73
87
  "human-oversight": {
74
88
  "owasp": [
@@ -82,6 +96,11 @@
82
96
  "iso42001": [
83
97
  "Annex-A.9",
84
98
  "Clause-8.4"
99
+ ],
100
+ "atlas": [
101
+ "AML.M0020",
102
+ "AML.M0029",
103
+ "AML.M0036"
85
104
  ]
86
105
  },
87
106
  "input-validation": {
@@ -95,6 +114,10 @@
95
114
  "iso42001": [
96
115
  "Clause-8.2",
97
116
  "Annex-A.6"
117
+ ],
118
+ "atlas": [
119
+ "AML.M0020",
120
+ "AML.M0036"
98
121
  ]
99
122
  },
100
123
  "monitoring": {
@@ -108,6 +131,9 @@
108
131
  "iso42001": [
109
132
  "Clause-9.1",
110
133
  "Clause-10"
134
+ ],
135
+ "atlas": [
136
+ "AML.M0024"
111
137
  ]
112
138
  },
113
139
  "output-sanitization": {
@@ -120,6 +146,10 @@
120
146
  ],
121
147
  "iso42001": [
122
148
  "Clause-8.2"
149
+ ],
150
+ "atlas": [
151
+ "AML.M0020",
152
+ "AML.M0032"
123
153
  ]
124
154
  },
125
155
  "pii-handling": {
@@ -133,6 +163,10 @@
133
163
  "iso42001": [
134
164
  "Annex-A.7",
135
165
  "Annex-A.4"
166
+ ],
167
+ "atlas": [
168
+ "AML.M0020",
169
+ "AML.M0024"
136
170
  ]
137
171
  },
138
172
  "prompt-security": {
@@ -145,6 +179,10 @@
145
179
  ],
146
180
  "iso42001": [
147
181
  "Clause-8.2"
182
+ ],
183
+ "atlas": [
184
+ "AML.M0020",
185
+ "AML.M0021"
148
186
  ]
149
187
  },
150
188
  "rag-security": {
@@ -157,6 +195,11 @@
157
195
  "iso42001": [
158
196
  "Clause-8.2",
159
197
  "Annex-A.7"
198
+ ],
199
+ "atlas": [
200
+ "AML.M0019",
201
+ "AML.M0020",
202
+ "AML.M0024"
160
203
  ]
161
204
  },
162
205
  "rate-limiting": {
@@ -169,6 +212,10 @@
169
212
  ],
170
213
  "iso42001": [
171
214
  "Clause-8.2"
215
+ ],
216
+ "atlas": [
217
+ "AML.M0004",
218
+ "AML.M0036"
172
219
  ]
173
220
  },
174
221
  "supply-chain": {
@@ -183,6 +230,9 @@
183
230
  ],
184
231
  "iso42001": [
185
232
  "Annex-A.10"
233
+ ],
234
+ "atlas": [
235
+ "AML.M0008"
186
236
  ]
187
237
  }
188
238
  }
@@ -39,6 +39,12 @@
39
39
  "pattern": "^(Art-\\d+(\\([0-9a-z]+\\))*|Annex-[IVX]+(\\([0-9a-z]+\\))*)$"
40
40
  },
41
41
  "description": "EU AI Act article references. v2.1 addition. Optional."
42
+ },
43
+ "atlas": {
44
+ "type": "array",
45
+ "uniqueItems": true,
46
+ "items": { "type": "string", "pattern": "^AML\\.M\\d{4}$" },
47
+ "description": "MITRE ATLAS mitigation ids (must exist in content/index/atlas.json, ATLAS 2026.10) that this area helps implement (in part). v3.0 addition. Optional, may be empty. Not allowed on areas that declare jurisdiction."
42
48
  }
43
49
  }
44
50
  },
@@ -0,0 +1,316 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generates content/index/atlas.json, the vendored MITRE ATLAS catalog subset,
4
+ * from the pinned upstream release file. The catalog is never edited by hand.
5
+ *
6
+ * node scripts/build-atlas-index.js --source <path-to-ATLAS-2026.10.yaml> [--check]
7
+ *
8
+ * Without --check: verifies the source sha256 against ATLAS_SHA256, derives the
9
+ * catalog, and writes it to content/index/atlas.json and to the Python mirror
10
+ * cli-python/aigis_cli/content/index/atlas.json (the two trees must stay
11
+ * byte-identical; see scripts/check-content-sync.js).
12
+ * With --check: derives the catalog in memory and compares it byte for byte
13
+ * with both files on disk. Prints OK and exits 0 when equal; exits 1 otherwise.
14
+ *
15
+ * What is kept: ids, names, maturity, tactic links, sub-technique parents,
16
+ * MITRE's direct `mitigates` links, and case-study counts. No descriptions or
17
+ * references. Derivation rules: build/atlas/SPEC.md section S1.1.
18
+ *
19
+ * This script has no network code. To move to a future ATLAS version:
20
+ * 1. Download the release asset by hand from
21
+ * https://github.com/mitre-atlas/atlas-data/releases (tag v<version>,
22
+ * file dist/v6/ATLAS-<version>.yaml) and its LICENSE notice.
23
+ * 2. Change ATLAS_VERSION, ATLAS_SHA256, MODIFIED_DATE and FORMAT_VERSION
24
+ * below (and the shared constants in lib/atlas.js and the tests).
25
+ * 3. Rerun this script with --source pointing at the downloaded file, then
26
+ * update content/index/atlas-NOTICE.md.
27
+ * 4. A version bump needs new gold approval for the Aigis mappings
28
+ * (`controls.atlas` in area frontmatter and atlas-entry-points.json),
29
+ * because MITRE may rename, split or relink techniques and mitigations.
30
+ *
31
+ * YAML is parsed with js-yaml, which is already installed as a dependency of
32
+ * gray-matter. It is not a direct dependency of this package and is only
33
+ * needed when this developer script runs.
34
+ *
35
+ * Exit codes: 0 success (or --check OK), 1 usage error, unreadable source,
36
+ * sha256 mismatch, unexpected source structure, or --check difference.
37
+ */
38
+
39
+ 'use strict';
40
+
41
+ const crypto = require('crypto');
42
+ const fs = require('fs');
43
+ const path = require('path');
44
+
45
+ const ROOT = path.join(__dirname, '..');
46
+
47
+ const ATLAS_VERSION = '2026.10';
48
+ const ATLAS_SHA256 = 'ac41ee9f99a47084ba5fdfc77ae83a28687e12390240fffeb37df7914ffe142d';
49
+ const FORMAT_VERSION = '6.1.0';
50
+ const MODIFIED_DATE = '2026-10-28';
51
+
52
+ const OUTPUT_REL = 'content/index/atlas.json';
53
+ const MIRROR_REL = 'cli-python/aigis_cli/content/index/atlas.json';
54
+ const MAX_BYTES = 64000;
55
+
56
+ const MATURITY_LEVELS = ['Realized', 'Demonstrated', 'Feasible'];
57
+ const MATRIX_ID = 'ATLAS-matrix';
58
+ const CASE_STUDY_PREFIX = 'AML.CS';
59
+
60
+ const USAGE = 'Usage: node scripts/build-atlas-index.js --source <path-to-ATLAS-2026.10.yaml> [--check]';
61
+
62
+ class BuildError extends Error {}
63
+
64
+ function parseArgs(argv) {
65
+ const opts = { source: null, check: false, help: false };
66
+ for (let i = 0; i < argv.length; i++) {
67
+ const arg = argv[i];
68
+ if (arg === '--check') opts.check = true;
69
+ else if (arg === '--help' || arg === '-h') opts.help = true;
70
+ else if (arg === '--source') {
71
+ const value = argv[++i];
72
+ if (value === undefined || value.startsWith('--')) throw new BuildError(`--source needs a path.\n${USAGE}`);
73
+ opts.source = value;
74
+ } else if (arg.startsWith('--source=')) {
75
+ opts.source = arg.slice('--source='.length);
76
+ if (!opts.source) throw new BuildError(`--source needs a path.\n${USAGE}`);
77
+ } else throw new BuildError(`Unknown argument: ${arg}\n${USAGE}`);
78
+ }
79
+ if (!opts.help && !opts.source) throw new BuildError(USAGE);
80
+ return opts;
81
+ }
82
+
83
+ function loadYamlParser() {
84
+ let yaml;
85
+ try {
86
+ yaml = require('js-yaml');
87
+ } catch (_) {
88
+ throw new BuildError('Cannot load js-yaml (normally installed with gray-matter). Run `npm install` in the repo root first.');
89
+ }
90
+ // js-yaml 3.x: safeLoad is the schema without JS types. js-yaml 4.x: load is safe by default.
91
+ return typeof yaml.safeLoad === 'function' ? yaml.safeLoad : yaml.load;
92
+ }
93
+
94
+ function sha256(buf) {
95
+ return crypto.createHash('sha256').update(buf).digest('hex');
96
+ }
97
+
98
+ function byId(a, b) {
99
+ return a < b ? -1 : a > b ? 1 : 0;
100
+ }
101
+
102
+ function expect(condition, message) {
103
+ if (!condition) throw new BuildError(`Unexpected source structure: ${message}`);
104
+ }
105
+
106
+ function relationshipsOf(rels, id, type) {
107
+ const entry = rels[id];
108
+ if (!entry || entry[type] === undefined) return [];
109
+ expect(Array.isArray(entry[type]), `relationships["${id}"].${type} is not a list`);
110
+ for (const r of entry[type]) {
111
+ expect(r && r.source === id && r['relationship-type'] === type && typeof r.target === 'string',
112
+ `malformed ${type} relationship under "${id}"`);
113
+ }
114
+ return entry[type];
115
+ }
116
+
117
+ function sortedUnique(ids) {
118
+ return [...new Set(ids)].sort(byId);
119
+ }
120
+
121
+ function buildCatalog(doc) {
122
+ expect(doc && typeof doc === 'object', 'top level is not a mapping');
123
+ for (const key of ['collection', 'tactics', 'techniques', 'mitigations', 'case-studies', 'relationships']) {
124
+ expect(doc[key] && typeof doc[key] === 'object' && !Array.isArray(doc[key]), `missing mapping "${key}"`);
125
+ }
126
+ expect(String(doc['format-version']) === FORMAT_VERSION, `format-version is ${doc['format-version']}, expected ${FORMAT_VERSION}`);
127
+ expect(String(doc.collection.version) === ATLAS_VERSION, `collection.version is ${doc.collection.version}, expected ${ATLAS_VERSION}`);
128
+ expect(String(doc.collection['modified-date']) === MODIFIED_DATE, `collection.modified-date is ${doc.collection['modified-date']}, expected ${MODIFIED_DATE}`);
129
+
130
+ const rels = doc.relationships;
131
+ const name = (obj, id) => {
132
+ expect(typeof obj.name === 'string' && obj.name.trim() === obj.name && obj.name.length > 0, `"${id}" has no usable name`);
133
+ return obj.name;
134
+ };
135
+
136
+ // Tactics, in matrix order.
137
+ const sequence = relationshipsOf(rels, MATRIX_ID, 'sequences');
138
+ expect(sequence.length > 0, `relationships["${MATRIX_ID}"].sequences is empty`);
139
+ const positions = new Set();
140
+ for (const s of sequence) {
141
+ expect(Number.isInteger(s.position), `sequence entry for ${s.target} has no integer position`);
142
+ expect(!positions.has(s.position), `duplicate matrix position ${s.position}`);
143
+ positions.add(s.position);
144
+ }
145
+ const tactics = [...sequence]
146
+ .sort((a, b) => a.position - b.position)
147
+ .map((s) => {
148
+ expect(doc.tactics[s.target], `matrix lists unknown tactic ${s.target}`);
149
+ return { id: s.target, name: name(doc.tactics[s.target], s.target) };
150
+ });
151
+ expect(tactics.length === Object.keys(doc.tactics).length, 'matrix sequence does not list every tactic exactly once');
152
+ const tacticIds = new Set(tactics.map((t) => t.id));
153
+ expect(tacticIds.size === tactics.length, 'matrix lists a tactic twice');
154
+
155
+ // Case-study counts: distinct AML.CS* sources with an `employs` link to the technique.
156
+ const caseStudiesByTechnique = new Map();
157
+ for (const source of Object.keys(rels).sort(byId)) {
158
+ if (!source.startsWith(CASE_STUDY_PREFIX)) continue;
159
+ for (const r of relationshipsOf(rels, source, 'employs')) {
160
+ if (!caseStudiesByTechnique.has(r.target)) caseStudiesByTechnique.set(r.target, new Set());
161
+ caseStudiesByTechnique.get(r.target).add(source);
162
+ }
163
+ }
164
+
165
+ // Techniques, ascending id.
166
+ const techniqueIds = Object.keys(doc.techniques).sort(byId);
167
+ const techniqueSet = new Set(techniqueIds);
168
+ const techniques = {};
169
+ let subtechniques = 0;
170
+ const maturityCounts = Object.fromEntries(MATURITY_LEVELS.map((m) => [m, 0]));
171
+ for (const id of techniqueIds) {
172
+ const src = doc.techniques[id];
173
+ expect(MATURITY_LEVELS.includes(src.maturity), `technique ${id} has maturity "${src.maturity}"`);
174
+ const tacticLinks = sortedUnique(relationshipsOf(rels, id, 'achieves').map((r) => r.target));
175
+ expect(tacticLinks.length > 0, `technique ${id} achieves no tactic`);
176
+ tacticLinks.forEach((t) => expect(tacticIds.has(t), `technique ${id} achieves unknown tactic ${t}`));
177
+ const parents = sortedUnique(relationshipsOf(rels, id, 'specializes').map((r) => r.target));
178
+ expect(parents.length <= 1, `technique ${id} specializes more than one technique`);
179
+
180
+ const out = { name: name(src, id), maturity: src.maturity, tactics: tacticLinks };
181
+ if (parents.length === 1) {
182
+ expect(techniqueSet.has(parents[0]), `technique ${id} specializes unknown technique ${parents[0]}`);
183
+ out.parent = parents[0];
184
+ subtechniques++;
185
+ }
186
+ out.case_studies = caseStudiesByTechnique.has(id) ? caseStudiesByTechnique.get(id).size : 0;
187
+ techniques[id] = out;
188
+ maturityCounts[src.maturity]++;
189
+ }
190
+ for (const target of caseStudiesByTechnique.keys()) expect(techniqueSet.has(target), `a case study employs unknown technique ${target}`);
191
+
192
+ // Mitigations, ascending id, with MITRE's direct `mitigates` links only.
193
+ const mitigations = {};
194
+ let mitigationLinks = 0;
195
+ for (const id of Object.keys(doc.mitigations).sort(byId)) {
196
+ const links = relationshipsOf(rels, id, 'mitigates').map((r) => r.target);
197
+ const targets = sortedUnique(links);
198
+ expect(targets.length === links.length, `mitigation ${id} lists a technique twice`);
199
+ targets.forEach((t) => expect(techniqueSet.has(t), `mitigation ${id} mitigates unknown technique ${t}`));
200
+ mitigations[id] = { name: name(doc.mitigations[id], id), techniques: targets };
201
+ mitigationLinks += targets.length;
202
+ }
203
+
204
+ return {
205
+ source: {
206
+ name: 'MITRE ATLAS',
207
+ repository: 'https://github.com/mitre-atlas/atlas-data',
208
+ release_tag: `v${ATLAS_VERSION}`,
209
+ file: `dist/v6/ATLAS-${ATLAS_VERSION}.yaml`,
210
+ format_version: FORMAT_VERSION,
211
+ version: ATLAS_VERSION,
212
+ modified_date: MODIFIED_DATE,
213
+ sha256: ATLAS_SHA256,
214
+ license: 'Apache-2.0',
215
+ notice: 'content/index/atlas-NOTICE.md',
216
+ subset: 'ids, names, maturity, tactic links, sub-technique parents, mitigation links, case-study counts; no descriptions',
217
+ },
218
+ counts: {
219
+ tactics: tactics.length,
220
+ techniques: techniqueIds.length,
221
+ subtechniques,
222
+ mitigations: Object.keys(mitigations).length,
223
+ mitigation_links: mitigationLinks,
224
+ case_studies: Object.keys(doc['case-studies']).length,
225
+ maturity: maturityCounts,
226
+ },
227
+ tactics,
228
+ techniques,
229
+ mitigations,
230
+ };
231
+ }
232
+
233
+ function serialize(catalog) {
234
+ const pretty = `${JSON.stringify(catalog, null, 1)}\n`;
235
+ if (Buffer.byteLength(pretty) <= MAX_BYTES) return pretty;
236
+ const minified = `${JSON.stringify(catalog)}\n`;
237
+ if (Buffer.byteLength(minified) > MAX_BYTES) {
238
+ throw new BuildError(`Catalog is ${Buffer.byteLength(minified)} bytes minified, over the ${MAX_BYTES}-byte cap.`);
239
+ }
240
+ return minified;
241
+ }
242
+
243
+ function generate(sourcePath) {
244
+ let raw;
245
+ try {
246
+ raw = fs.readFileSync(sourcePath);
247
+ } catch (_) {
248
+ throw new BuildError(`Cannot read ${sourcePath}`);
249
+ }
250
+ const actual = sha256(raw);
251
+ if (actual !== ATLAS_SHA256) {
252
+ throw new BuildError(`sha256 mismatch: expected ${ATLAS_SHA256}, got ${actual}. Refusing to generate.`);
253
+ }
254
+ const parse = loadYamlParser();
255
+ let doc;
256
+ try {
257
+ doc = parse(raw.toString('utf8'), { filename: sourcePath });
258
+ } catch (error) {
259
+ throw new BuildError(`Cannot parse ${sourcePath}: ${error.message}`);
260
+ }
261
+ return serialize(buildCatalog(doc));
262
+ }
263
+
264
+ function writeAtomic(rel, text) {
265
+ const target = path.join(ROOT, rel);
266
+ const tmp = `${target}.tmp-${process.pid}`;
267
+ fs.writeFileSync(tmp, text);
268
+ fs.renameSync(tmp, target);
269
+ }
270
+
271
+ function readIfExists(rel) {
272
+ const target = path.join(ROOT, rel);
273
+ return fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : null;
274
+ }
275
+
276
+ function main(argv) {
277
+ const opts = parseArgs(argv);
278
+ if (opts.help) {
279
+ process.stdout.write(`${USAGE}\n`);
280
+ return 0;
281
+ }
282
+ const text = generate(opts.source);
283
+
284
+ if (opts.check) {
285
+ const problems = [];
286
+ for (const rel of [OUTPUT_REL, MIRROR_REL]) {
287
+ const onDisk = readIfExists(rel);
288
+ if (onDisk === null) problems.push(`${rel} is missing`);
289
+ else if (onDisk !== text) problems.push(`${rel} differs from the generated catalog`);
290
+ }
291
+ if (problems.length) {
292
+ process.stderr.write(`${problems.join('\n')}\nRegenerate with: node scripts/build-atlas-index.js --source ${opts.source}\n`);
293
+ return 1;
294
+ }
295
+ process.stdout.write(`OK (source sha256 ${ATLAS_SHA256})\n`);
296
+ return 0;
297
+ }
298
+
299
+ writeAtomic(OUTPUT_REL, text);
300
+ writeAtomic(MIRROR_REL, text);
301
+ process.stdout.write(`Wrote ${OUTPUT_REL} (${Buffer.byteLength(text)} bytes, ATLAS ${ATLAS_VERSION})\n`);
302
+ process.stdout.write(`Wrote ${MIRROR_REL} (mirror)\n`);
303
+ return 0;
304
+ }
305
+
306
+ if (require.main === module) {
307
+ try {
308
+ process.exitCode = main(process.argv.slice(2));
309
+ } catch (error) {
310
+ if (!(error instanceof BuildError)) throw error;
311
+ process.stderr.write(`${error.message}\n`);
312
+ process.exitCode = 1;
313
+ }
314
+ }
315
+
316
+ module.exports = { ATLAS_VERSION, ATLAS_SHA256, buildCatalog, serialize };
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fast suite: every validator and test file, in one command (`npm test`).
4
+ *
5
+ * Runs each check as its own process so one crash can't hide another, prints
6
+ * one line per check, and exits non-zero if anything failed. Plain Node, no
7
+ * test framework, matching the rest of the repo.
8
+ */
9
+
10
+ const { spawnSync } = require('child_process');
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const ROOT = path.join(__dirname, '..');
15
+
16
+ function versionAgreement() {
17
+ const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8');
18
+ const found = {
19
+ 'package.json': JSON.parse(read('package.json')).version,
20
+ 'package-lock.json': JSON.parse(read('package-lock.json')).version,
21
+ 'package-lock.json packages[""]': JSON.parse(read('package-lock.json')).packages[''].version,
22
+ 'bin/aigis.js': (read('bin/aigis.js').match(/\.version\('([^']+)'\)/) || [])[1],
23
+ 'cli-python/pyproject.toml': (read('cli-python/pyproject.toml').match(/^version\s*=\s*"([^"]+)"/m) || [])[1],
24
+ };
25
+ const versions = new Set(Object.values(found));
26
+ if (versions.size === 1 && !versions.has(undefined)) return { ok: true, detail: `all at ${[...versions][0]}` };
27
+ return { ok: false, detail: Object.entries(found).map(([k, v]) => `${k}=${v}`).join(', ') };
28
+ }
29
+
30
+ const checks = [
31
+ ['validate-triggers', ['scripts/validate-triggers.js']],
32
+ ['validate-area-frontmatter', ['scripts/validate-area-frontmatter.js']],
33
+ ['check-content-sync', ['scripts/check-content-sync.js']],
34
+ ...fs.readdirSync(path.join(ROOT, 'test'))
35
+ .filter((f) => f.endsWith('.test.js'))
36
+ .sort()
37
+ .map((f) => [f, [path.join('test', f)]]),
38
+ ];
39
+
40
+ let failed = 0;
41
+ const started = Date.now();
42
+
43
+ const v = versionAgreement();
44
+ console.log(`${v.ok ? 'PASS' : 'FAIL'} version-agreement (${v.detail})`);
45
+ if (!v.ok) failed++;
46
+
47
+ for (const [name, args] of checks) {
48
+ const t0 = Date.now();
49
+ const r = spawnSync(process.execPath, args, { cwd: ROOT, encoding: 'utf8' });
50
+ const ok = r.status === 0;
51
+ console.log(`${ok ? 'PASS' : 'FAIL'} ${name} (${Date.now() - t0} ms)`);
52
+ if (!ok) {
53
+ failed++;
54
+ const out = `${r.stdout || ''}${r.stderr || ''}`.trim().split('\n').slice(-15).join('\n');
55
+ console.log(out.replace(/^/gm, ' '));
56
+ }
57
+ }
58
+
59
+ const total = checks.length + 1;
60
+ console.log(`\n${total - failed}/${total} checks passed in ${Date.now() - started} ms`);
61
+ process.exit(failed ? 1 : 0);
@@ -12,6 +12,9 @@
12
12
  * 0 All area files satisfy the schema.
13
13
  * 1 At least one file failed; offending entries printed to stderr.
14
14
  *
15
+ * controls.atlas (optional) is checked against the pinned MITRE ATLAS catalog
16
+ * at content/index/atlas.json via lib/atlas.js; a missing catalog fails.
17
+ *
15
18
  * Used by .github/workflows/area-frontmatter-validation.yml on PRs that touch
16
19
  * content/skills/areas/. Also runs locally:
17
20
  * node scripts/validate-area-frontmatter.js
@@ -26,6 +29,18 @@ const AREAS_DIR = path.join(ROOT, 'content', 'skills', 'areas');
26
29
  const BASELINE_PATH = path.join(__dirname, 'area-controls-baseline.json');
27
30
  const { ALL_TRAITS } = require(path.join(ROOT, 'lib', 'classify.js'));
28
31
  const ALL_TRAITS_SET = new Set(ALL_TRAITS);
32
+ const atlasLib = require(path.join(ROOT, 'lib', 'atlas.js'));
33
+
34
+ // ATLAS mitigation ids (controls.atlas) are checked against the vendored,
35
+ // pinned catalog at content/index/atlas.json. Loaded once; a missing or
36
+ // corrupt catalog is reported as an error rather than silently skipped.
37
+ let _atlasMitigations = null;
38
+ function loadAtlasMitigations() {
39
+ if (_atlasMitigations) return _atlasMitigations;
40
+ const catalog = atlasLib.loadCatalog();
41
+ _atlasMitigations = new Set(Object.keys(catalog.mitigations));
42
+ return _atlasMitigations;
43
+ }
29
44
 
30
45
  // v2.1 no-deletion baseline: existing area files (those listed in
31
46
  // area-controls-baseline.json, captured at v2.0.2) must preserve their
@@ -58,6 +73,8 @@ const RE_OWASP = /^LLM\d{2}$/;
58
73
  const RE_NIST = /^(MAP|MEASURE|MANAGE|GOVERN)-\d+(\.\d+)?$/;
59
74
  const RE_ISO = /^(Clause-\d+(\.\d+)?|Annex-[A-Z](\.\d+)?|Annex-[A-Z])$/;
60
75
  const RE_EU_AI_ACT = /^(Art-\d+(\([0-9a-z]+\))*|Annex-[IVX]+(\([0-9a-z]+\))*)$/;
76
+ const RE_ATLAS = /^AML\.M\d{4}$/;
77
+ const CONTROL_KEYS = ['owasp', 'nist', 'iso42001', 'eu_ai_act', 'atlas'];
61
78
 
62
79
  function listAreaFiles() {
63
80
  return fs.readdirSync(AREAS_DIR)
@@ -136,18 +153,49 @@ function validateOne(filename) {
136
153
  }
137
154
  }
138
155
  }
156
+ // atlas is OPTIONAL: ATLAS mitigation ids this area helps implement (in part).
157
+ if ('atlas' in fm.controls) {
158
+ if (!Array.isArray(fm.controls.atlas)) {
159
+ errors.push('controls.atlas must be an array if present');
160
+ } else {
161
+ let known = null;
162
+ try {
163
+ known = loadAtlasMitigations();
164
+ } catch (e) {
165
+ errors.push(`controls.atlas cannot be checked: ${e.message}`);
166
+ }
167
+ const seen = new Set();
168
+ for (const v of fm.controls.atlas) {
169
+ if (typeof v !== 'string' || !RE_ATLAS.test(v)) {
170
+ errors.push(`controls.atlas value "${v}" does not match AML.M####`);
171
+ } else if (known && !known.has(v)) {
172
+ errors.push(`controls.atlas value "${v}" is not a mitigation in ATLAS ${atlasLib.PINNED.version}`);
173
+ }
174
+ if (seen.has(v)) errors.push(`controls.atlas value "${v}" is a duplicate`);
175
+ seen.add(v);
176
+ }
177
+ }
178
+ // ATLAS is never jurisdiction-gated (docs/frontmatter-schema.md):
179
+ // a jurisdiction-gated area must not declare it.
180
+ if ('jurisdiction' in fm) {
181
+ errors.push('controls.atlas must not be declared on an area with jurisdiction: (ATLAS citations are never jurisdiction-gated)');
182
+ }
183
+ }
139
184
  // No other keys allowed under controls
140
185
  for (const k of Object.keys(fm.controls)) {
141
- if (!['owasp', 'nist', 'iso42001', 'eu_ai_act'].includes(k)) {
186
+ if (!CONTROL_KEYS.includes(k)) {
142
187
  errors.push(`controls.${k} is not a recognized framework key`);
143
188
  }
144
189
  }
145
190
  // ── v2.1 no-deletion check: existing areas must preserve their
146
191
  // owasp/nist/iso42001 arrays from the v2.0.2 baseline. Adding
147
192
  // eu_ai_act is fine; modifying the original three is a regression.
193
+ // v3.0: atlas joins the protected set for baseline areas that record it.
148
194
  const baseline = loadBaseline();
149
195
  if (baseline[expectedId]) {
150
- for (const fw of ['owasp', 'nist', 'iso42001']) {
196
+ const protectedKeys = ['owasp', 'nist', 'iso42001'];
197
+ if ('atlas' in baseline[expectedId]) protectedKeys.push('atlas');
198
+ for (const fw of protectedKeys) {
151
199
  if (!arraysEqualSet(fm.controls[fw], baseline[expectedId][fw])) {
152
200
  const before = JSON.stringify(baseline[expectedId][fw]);
153
201
  const after = JSON.stringify(fm.controls[fw] || []);
@@ -202,6 +250,14 @@ function main() {
202
250
  process.exit(1);
203
251
  }
204
252
 
253
+ try {
254
+ loadAtlasMitigations();
255
+ } catch (e) {
256
+ console.error(`ATLAS catalog unavailable: ${e.message}`);
257
+ console.error('controls.atlas cannot be validated without content/index/atlas.json (see content/index/atlas-NOTICE.md).');
258
+ process.exit(1);
259
+ }
260
+
205
261
  let totalErrors = 0;
206
262
  let firstErrorFile = null;
207
263
  for (const f of files) {