@aigis-ai/cli 2.0.2 → 2.1.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 +94 -45
- package/bin/aigis.js +139 -8
- package/content/resolvers/triggers.json +363 -41
- package/content/skills/areas/audit-logging.md +33 -0
- package/content/skills/areas/bias-monitoring.md +34 -0
- package/content/skills/areas/confidence-scoring.md +23 -0
- package/content/skills/areas/data-integrity.md +25 -0
- package/content/skills/areas/eu-ai-act-art-13-deployer-transparency.md +133 -0
- package/content/skills/areas/eu-ai-act-art-50-transparency-disclosure.md +134 -0
- package/content/skills/areas/eu-ai-act-art-73-incident-reporting.md +149 -0
- package/content/skills/areas/eu-ai-act-art-9-risk-management.md +141 -0
- package/content/skills/areas/fallback-patterns.md +28 -0
- package/content/skills/areas/human-oversight.md +38 -0
- package/content/skills/areas/input-validation.md +27 -0
- package/content/skills/areas/monitoring.md +29 -0
- package/content/skills/areas/prompt-security.md +29 -0
- package/content/templates/eu-ai-act-annex-iv.md +193 -0
- package/docs/frontmatter-schema.md +75 -0
- package/docs/screenshots/README.md +17 -0
- package/docs/screenshots/agent-flow.png +0 -0
- package/docs/screenshots/setup.png +0 -0
- package/docs/screenshots/verify.png +0 -0
- package/lib/auto-verify.js +70 -1
- package/lib/build.js +101 -12
- package/lib/classify.js +8 -2
- package/lib/init.js +269 -5
- package/lib/jurisdiction.js +137 -0
- package/lib/report.js +331 -0
- package/package.json +1 -1
- package/scripts/area-controls-baseline.json +188 -0
- package/scripts/area-frontmatter.schema.json +61 -0
- package/scripts/validate-area-frontmatter.js +228 -0
- package/aigis-ai-cli-2.0.1.tgz +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/auto-verify.js
CHANGED
|
@@ -17,9 +17,34 @@
|
|
|
17
17
|
|
|
18
18
|
const fs = require('fs');
|
|
19
19
|
const path = require('path');
|
|
20
|
+
const matter = require('gray-matter');
|
|
20
21
|
const { REGISTRY: SPECIAL } = require('./special-recognizers');
|
|
22
|
+
const { getUserJurisdictions } = require('./jurisdiction');
|
|
21
23
|
|
|
22
24
|
const RULES_PATH = path.join(__dirname, '..', 'content', 'index', 'auto-verify-rules.json');
|
|
25
|
+
const AREAS_DIR = path.join(__dirname, '..', 'content', 'skills', 'areas');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* v2.1: Read an area's frontmatter `controls` block (all four frameworks).
|
|
29
|
+
* Returns { owasp, nist, iso42001, eu_ai_act } with arrays (empty if absent).
|
|
30
|
+
* Returns null on missing file or parse failure.
|
|
31
|
+
*/
|
|
32
|
+
function readAreaControls(areaId) {
|
|
33
|
+
try {
|
|
34
|
+
const filepath = path.join(AREAS_DIR, `${areaId}.md`);
|
|
35
|
+
if (!fs.existsSync(filepath)) return null;
|
|
36
|
+
const fm = matter(fs.readFileSync(filepath, 'utf8')).data;
|
|
37
|
+
const c = fm.controls || {};
|
|
38
|
+
return {
|
|
39
|
+
owasp: c.owasp || [],
|
|
40
|
+
nist: c.nist || [],
|
|
41
|
+
iso42001: c.iso42001 || [],
|
|
42
|
+
eu_ai_act: c.eu_ai_act || [],
|
|
43
|
+
};
|
|
44
|
+
} catch (_) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
23
48
|
|
|
24
49
|
// Default glob: scan typical source files, skip noise.
|
|
25
50
|
const DEFAULT_INCLUDE_EXTS = new Set([
|
|
@@ -205,13 +230,25 @@ function runSpecialRecognizer(name, files, ctx) {
|
|
|
205
230
|
* directory, run all AUTO and OVERCLAIM rules and return a structured
|
|
206
231
|
* result the CLI can format.
|
|
207
232
|
*/
|
|
208
|
-
function autoVerifyArea(areaId, projectDir) {
|
|
233
|
+
function autoVerifyArea(areaId, projectDir, opts = {}) {
|
|
234
|
+
// v2.1: opts.jurisdictions = array of jurisdiction codes (e.g. ['eu']).
|
|
235
|
+
// Used to gate EU AI Act control citations in the output. Defaults to none
|
|
236
|
+
// — verify is conservative; eu_ai_act citations only appear when the user
|
|
237
|
+
// explicitly opts in via --jurisdiction eu.
|
|
238
|
+
const userJurisdictions = new Set(opts.jurisdictions || []);
|
|
239
|
+
|
|
209
240
|
const rules = loadRules();
|
|
210
241
|
const area = rules[areaId];
|
|
211
242
|
if (!area) {
|
|
212
243
|
throw new Error(`No auto-verify rules for pattern area "${areaId}". Known areas: ${Object.keys(rules).join(', ')}`);
|
|
213
244
|
}
|
|
214
245
|
|
|
246
|
+
// v2.1: read area frontmatter controls for citation in the report.
|
|
247
|
+
// If the area's frontmatter has `jurisdiction: [eu]` and the user is not
|
|
248
|
+
// in EU jurisdiction, skip the entire area citation block (the area
|
|
249
|
+
// shouldn't have been verified at all in that case).
|
|
250
|
+
const allControls = readAreaControls(areaId);
|
|
251
|
+
|
|
215
252
|
const files = loadFiles(projectDir);
|
|
216
253
|
|
|
217
254
|
const autoResults = {};
|
|
@@ -261,6 +298,17 @@ function autoVerifyArea(areaId, projectDir) {
|
|
|
261
298
|
const overclaimsRaised = Object.values(overclaimResults).filter((r) => r.raised).length;
|
|
262
299
|
const judgmentCount = Object.keys(judgmentResults).length;
|
|
263
300
|
|
|
301
|
+
// v2.1: assemble the controls citation. EU AI Act controls are gated on
|
|
302
|
+
// the user passing --jurisdiction eu (or equivalent). NIST/OWASP/ISO are
|
|
303
|
+
// always cited if the area declares them.
|
|
304
|
+
const showEu = userJurisdictions.has('eu');
|
|
305
|
+
const cited = allControls ? {
|
|
306
|
+
owasp: allControls.owasp,
|
|
307
|
+
nist: allControls.nist,
|
|
308
|
+
iso42001: allControls.iso42001,
|
|
309
|
+
eu_ai_act: showEu ? allControls.eu_ai_act : [],
|
|
310
|
+
} : null;
|
|
311
|
+
|
|
264
312
|
return {
|
|
265
313
|
area: areaId,
|
|
266
314
|
project_dir: projectDir,
|
|
@@ -275,6 +323,8 @@ function autoVerifyArea(areaId, projectDir) {
|
|
|
275
323
|
auto_checks: autoResults,
|
|
276
324
|
overclaim_checks: overclaimResults,
|
|
277
325
|
judgment_checks: judgmentResults,
|
|
326
|
+
cited_controls: cited,
|
|
327
|
+
user_jurisdictions: [...userJurisdictions],
|
|
278
328
|
};
|
|
279
329
|
}
|
|
280
330
|
|
|
@@ -309,6 +359,25 @@ function formatTextReport(result) {
|
|
|
309
359
|
lines.push(`Overclaim recognizers raised: ${s.overclaims_raised}`);
|
|
310
360
|
lines.push(`Judgment required: ${s.judgment_required} check(s)\n`);
|
|
311
361
|
|
|
362
|
+
// v2.1: cite framework controls satisfied when ALL auto checks PASS.
|
|
363
|
+
// Citation is gated on user jurisdiction for EU AI Act references.
|
|
364
|
+
if (result.cited_controls) {
|
|
365
|
+
const c = result.cited_controls;
|
|
366
|
+
const totalCited = c.owasp.length + c.nist.length + c.iso42001.length + c.eu_ai_act.length;
|
|
367
|
+
if (totalCited > 0) {
|
|
368
|
+
const allPass = s.auto_pass === s.auto_total && s.auto_fail === 0;
|
|
369
|
+
const header = allPass
|
|
370
|
+
? 'Controls satisfied (all auto checks PASS):'
|
|
371
|
+
: 'Controls in scope (partial — fix FAIL/OVERCLAIM to fully satisfy):';
|
|
372
|
+
lines.push(`── ${header} ──`);
|
|
373
|
+
if (c.owasp.length > 0) lines.push(` OWASP LLM Top 10: ${c.owasp.join(', ')}`);
|
|
374
|
+
if (c.nist.length > 0) lines.push(` NIST AI RMF: ${c.nist.join(', ')}`);
|
|
375
|
+
if (c.iso42001.length > 0) lines.push(` ISO/IEC 42001: ${c.iso42001.join(', ')}`);
|
|
376
|
+
if (c.eu_ai_act.length > 0) lines.push(` EU AI Act: ${c.eu_ai_act.join(', ')}`);
|
|
377
|
+
lines.push('');
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
312
381
|
// AUTO section
|
|
313
382
|
if (Object.keys(result.auto_checks).length > 0) {
|
|
314
383
|
lines.push('── AUTO CHECKS ──');
|
package/lib/build.js
CHANGED
|
@@ -32,6 +32,7 @@ const matter = require('gray-matter');
|
|
|
32
32
|
const { classify, ALL_TRAITS } = require('./classify');
|
|
33
33
|
const { detectTraitsFromText, applyConfirmations } = require('./keywords');
|
|
34
34
|
const { get: fetchAreas, getInfra } = require('./fetch');
|
|
35
|
+
const { getUserJurisdictions, filterAreasByJurisdiction, stripJurisdictionGatedSections } = require('./jurisdiction');
|
|
35
36
|
|
|
36
37
|
const CONTENT_DIR = path.join(__dirname, '..', 'content');
|
|
37
38
|
|
|
@@ -207,7 +208,7 @@ function resolveTraits(detection, decisionMap, opts = {}) {
|
|
|
207
208
|
* Shape A — `aigis build --list` output (text). Includes trigger IDs so
|
|
208
209
|
* users can pre-build --confirm/--reject flags without an interactive run.
|
|
209
210
|
*/
|
|
210
|
-
function buildList({ description } = {}) {
|
|
211
|
+
function buildList({ description, extraJurisdictions = [], tight = false } = {}) {
|
|
211
212
|
const normalized = normalizeDescription(description);
|
|
212
213
|
if (!normalized) {
|
|
213
214
|
throw new Error('Provide a description in quotes. Example: aigis build "customer chatbot with RAG"');
|
|
@@ -216,11 +217,23 @@ function buildList({ description } = {}) {
|
|
|
216
217
|
const lowConfWithSlugs = assignUniqueSlugs(detection.low_confidence_matches);
|
|
217
218
|
const detectionWithSlugs = { ...detection, low_confidence_matches: lowConfWithSlugs };
|
|
218
219
|
const resolved = resolveTraits(detectionWithSlugs, {}, { uncertainAsIncluded: true });
|
|
219
|
-
|
|
220
|
+
// v2.1: --jurisdiction-derived traits added before classify; jurisdiction filter applied to areas after.
|
|
221
|
+
const extraJurisdictionTraits = (extraJurisdictions || []).filter(Boolean).map((c) => `jurisdiction-${c}`);
|
|
222
|
+
const allTraitsWithJurisdiction = [...new Set([...resolved.all_traits, ...extraJurisdictionTraits])].sort();
|
|
223
|
+
if (allTraitsWithJurisdiction.length === 0) {
|
|
220
224
|
throw new Error('No traits resolved from description. Try a more specific description, or use `aigis classify --traits ...` directly.');
|
|
221
225
|
}
|
|
222
|
-
const cls = classify(
|
|
223
|
-
const
|
|
226
|
+
const cls = classify(allTraitsWithJurisdiction);
|
|
227
|
+
const userJurisdictions = getUserJurisdictions(allTraitsWithJurisdiction);
|
|
228
|
+
let areas = filterAreasByJurisdiction(cls.implement_files, userJurisdictions);
|
|
229
|
+
// v2.1 --tight mode for buildList — same logic as prepareBriefInputs.
|
|
230
|
+
if (tight) {
|
|
231
|
+
const userTraitSet = new Set(allTraitsWithJurisdiction);
|
|
232
|
+
areas = areas.filter((area) => {
|
|
233
|
+
const sysTraits = readAreaSystemTraits(area) || [];
|
|
234
|
+
return sysTraits.filter((t) => userTraitSet.has(t)).length >= 2;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
224
237
|
|
|
225
238
|
// Collect referenced infra (best-effort; missing files are skipped quietly).
|
|
226
239
|
const infraIds = collectInfraReferences(areas);
|
|
@@ -377,11 +390,13 @@ function renderVerificationSection({ areas, resolved, cls }) {
|
|
|
377
390
|
function buildCompact({
|
|
378
391
|
description,
|
|
379
392
|
decisions = {},
|
|
393
|
+
extraJurisdictions = [],
|
|
394
|
+
tight = false,
|
|
380
395
|
timestamp = null,
|
|
381
396
|
versionString = null,
|
|
382
397
|
fellBackFromFull = false, // if true, header notes the auto-fallback
|
|
383
398
|
} = {}) {
|
|
384
|
-
const prep = prepareBriefInputs({ description, decisions });
|
|
399
|
+
const prep = prepareBriefInputs({ description, decisions, extraJurisdictions, tight });
|
|
385
400
|
const { normalized, resolved, cls, areas, infraIds, lowConfWithSlugs } = prep;
|
|
386
401
|
const ts = (timestamp || new Date()).toISOString();
|
|
387
402
|
const version = versionString || readPackageVersion();
|
|
@@ -435,11 +450,13 @@ function buildCompact({
|
|
|
435
450
|
function buildFull({
|
|
436
451
|
description,
|
|
437
452
|
decisions = {},
|
|
453
|
+
extraJurisdictions = [],
|
|
454
|
+
tight = false,
|
|
438
455
|
charCap = FULL_HARD_CAP, // dispatcher overrides this to AUTO_FULL_CAP for auto mode
|
|
439
456
|
timestamp = null,
|
|
440
457
|
versionString = null,
|
|
441
458
|
} = {}) {
|
|
442
|
-
const prep = prepareBriefInputs({ description, decisions });
|
|
459
|
+
const prep = prepareBriefInputs({ description, decisions, extraJurisdictions, tight });
|
|
443
460
|
const { normalized, resolved, cls, areas, infraIds, lowConfWithSlugs } = prep;
|
|
444
461
|
const ts = (timestamp || new Date()).toISOString();
|
|
445
462
|
const version = versionString || readPackageVersion();
|
|
@@ -447,6 +464,9 @@ function buildFull({
|
|
|
447
464
|
const sections = renderCommonSections({ normalized, version, ts, modeNote: null, cls, resolved, areas, infraIds });
|
|
448
465
|
|
|
449
466
|
// ─── Areas (inlined) ───────────────────────────────────────────────────
|
|
467
|
+
// v2.1: for non-EU users, strip `## EU AI Act extensions` sections from
|
|
468
|
+
// each universal area's content before inlining. EU users see the section.
|
|
469
|
+
const userJ = new Set(prep.user_jurisdictions);
|
|
450
470
|
sections.push(`## Areas`);
|
|
451
471
|
sections.push('');
|
|
452
472
|
let i = 1;
|
|
@@ -457,7 +477,8 @@ function buildFull({
|
|
|
457
477
|
} catch (_) {
|
|
458
478
|
continue;
|
|
459
479
|
}
|
|
460
|
-
|
|
480
|
+
let stripped = stripFrontmatterRaw(raw);
|
|
481
|
+
stripped = stripJurisdictionGatedSections(stripped, userJ);
|
|
461
482
|
sections.push(`### ${i}. ${area}`);
|
|
462
483
|
sections.push('');
|
|
463
484
|
sections.push(stripped);
|
|
@@ -513,6 +534,7 @@ function buildFull({
|
|
|
513
534
|
* compact: buildCompact (no cap concern).
|
|
514
535
|
*/
|
|
515
536
|
function buildBrief(opts = {}) {
|
|
537
|
+
// opts may include: description, decisions, extraJurisdictions, mode, timestamp, versionString
|
|
516
538
|
const mode = opts.mode || 'auto';
|
|
517
539
|
if (mode === 'compact') {
|
|
518
540
|
return { ...buildCompact(opts), mode: 'compact', auto_fallback: false };
|
|
@@ -541,8 +563,13 @@ function buildBrief(opts = {}) {
|
|
|
541
563
|
* Shared input prep used by buildFull, buildCompact, and buildList. Centralizes
|
|
542
564
|
* the normalize → detect → slug → resolve → classify pipeline so all three modes
|
|
543
565
|
* see the same trait/area/infra outputs given the same input.
|
|
566
|
+
*
|
|
567
|
+
* v2.1: applies jurisdiction filter to the area list before infra collection.
|
|
568
|
+
* Universal areas pass through; areas declaring `jurisdiction: [eu]` (etc.) are
|
|
569
|
+
* dropped if the user is not in that jurisdiction. extraJurisdictions augments
|
|
570
|
+
* the resolver-derived jurisdiction set (powers `--jurisdiction <code>` flag).
|
|
544
571
|
*/
|
|
545
|
-
function prepareBriefInputs({ description, decisions = {} }) {
|
|
572
|
+
function prepareBriefInputs({ description, decisions = {}, extraJurisdictions = [], tight = false }) {
|
|
546
573
|
const normalized = normalizeDescription(description);
|
|
547
574
|
if (!normalized) {
|
|
548
575
|
throw new Error('Provide a description in quotes. Example: aigis build "customer chatbot with RAG"');
|
|
@@ -559,15 +586,77 @@ function prepareBriefInputs({ description, decisions = {} }) {
|
|
|
559
586
|
}
|
|
560
587
|
|
|
561
588
|
const resolved = resolveTraits(detectionWithSlugs, numericDecisions, { uncertainAsIncluded: true });
|
|
562
|
-
|
|
589
|
+
|
|
590
|
+
// v2.1: --jurisdiction flag adds jurisdiction-* traits to the set so that
|
|
591
|
+
// resolver-blind users can declare jurisdiction explicitly.
|
|
592
|
+
const extraJurisdictionTraits = (extraJurisdictions || [])
|
|
593
|
+
.filter(Boolean)
|
|
594
|
+
.map((c) => `jurisdiction-${c}`);
|
|
595
|
+
const allTraitsWithJurisdiction = [...new Set([...resolved.all_traits, ...extraJurisdictionTraits])].sort();
|
|
596
|
+
|
|
597
|
+
if (allTraitsWithJurisdiction.length === 0) {
|
|
563
598
|
throw new Error('No traits resolved from description. Try a more specific description, or use `aigis classify --traits ...` directly.');
|
|
564
599
|
}
|
|
565
600
|
|
|
566
|
-
const cls = classify(
|
|
567
|
-
|
|
601
|
+
const cls = classify(allTraitsWithJurisdiction);
|
|
602
|
+
|
|
603
|
+
// v2.1 jurisdiction filter: drop EU-tagged areas if user not in EU, etc.
|
|
604
|
+
const userJurisdictions = getUserJurisdictions(allTraitsWithJurisdiction);
|
|
605
|
+
const areasBeforeFilter = cls.implement_files;
|
|
606
|
+
let areas = filterAreasByJurisdiction(areasBeforeFilter, userJurisdictions);
|
|
607
|
+
|
|
608
|
+
// v2.1 --tight mode: require ≥2 of the user's traits to match an area's
|
|
609
|
+
// system_traits before including it. Default mode (≥1) unchanged. Tight
|
|
610
|
+
// mode is opt-in: meant for users who want minimal briefs and accept the
|
|
611
|
+
// recall trade. Benchmarked against default in v2.1-tight harness.
|
|
612
|
+
let areas_before_tight_filter = null;
|
|
613
|
+
let tight_dropped = [];
|
|
614
|
+
if (tight) {
|
|
615
|
+
areas_before_tight_filter = areas.slice();
|
|
616
|
+
const userTraitSet = new Set(allTraitsWithJurisdiction);
|
|
617
|
+
const kept = [];
|
|
618
|
+
for (const area of areas) {
|
|
619
|
+
const sysTraits = readAreaSystemTraits(area) || [];
|
|
620
|
+
const matchCount = sysTraits.filter((t) => userTraitSet.has(t)).length;
|
|
621
|
+
if (matchCount >= 2) kept.push(area);
|
|
622
|
+
else tight_dropped.push({ area, match_count: matchCount });
|
|
623
|
+
}
|
|
624
|
+
areas = kept;
|
|
625
|
+
}
|
|
626
|
+
|
|
568
627
|
const infraIds = collectInfraReferences(areas);
|
|
569
628
|
|
|
570
|
-
return {
|
|
629
|
+
return {
|
|
630
|
+
normalized,
|
|
631
|
+
raw_input: description,
|
|
632
|
+
detection,
|
|
633
|
+
lowConfWithSlugs,
|
|
634
|
+
resolved,
|
|
635
|
+
cls,
|
|
636
|
+
areas,
|
|
637
|
+
areas_before_jurisdiction_filter: areasBeforeFilter,
|
|
638
|
+
areas_before_tight_filter, // null if tight mode was off
|
|
639
|
+
tight_dropped, // [] if tight mode was off
|
|
640
|
+
tight_mode: !!tight,
|
|
641
|
+
user_jurisdictions: [...userJurisdictions],
|
|
642
|
+
infraIds,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* v2.1 helper: read an area's `system_traits` frontmatter. Used by tight
|
|
648
|
+
* mode to count user-trait matches per area. Returns null on missing file
|
|
649
|
+
* or parse failure (caller treats as 0 matches → area dropped under tight).
|
|
650
|
+
*/
|
|
651
|
+
function readAreaSystemTraits(areaId) {
|
|
652
|
+
try {
|
|
653
|
+
const filepath = path.join(CONTENT_DIR, 'skills', 'areas', `${areaId}.md`);
|
|
654
|
+
if (!fs.existsSync(filepath)) return null;
|
|
655
|
+
const fm = matter(fs.readFileSync(filepath, 'utf8')).data;
|
|
656
|
+
return Array.isArray(fm.system_traits) ? fm.system_traits : null;
|
|
657
|
+
} catch (_) {
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
571
660
|
}
|
|
572
661
|
|
|
573
662
|
function makeMeta({ prep, brief, mode, cap, ts, version, fellBackFromFull }) {
|
package/lib/classify.js
CHANGED
|
@@ -7,10 +7,11 @@ const ALL_TRAITS = [
|
|
|
7
7
|
'influences-decisions', 'accepts-user-input', 'is-external', 'is-internal', 'is-high-volume',
|
|
8
8
|
'generates-code', 'generates-content', 'multi-model-pipeline',
|
|
9
9
|
'jurisdiction-eu', 'jurisdiction-us-regulated', 'jurisdiction-global',
|
|
10
|
+
'is-eu-high-risk', // v2.1: EU AI Act Annex III gating trait — pulls EU AI Act high-risk articles in brief assembly
|
|
10
11
|
];
|
|
11
12
|
|
|
12
13
|
const TRAIT_FILES = {
|
|
13
|
-
'uses-llm': ['input-validation', 'output-sanitization', 'prompt-security', 'audit-logging', 'monitoring'],
|
|
14
|
+
'uses-llm': ['input-validation', 'output-sanitization', 'prompt-security', 'audit-logging', 'monitoring', 'eu-ai-act-art-50-transparency-disclosure'],
|
|
14
15
|
'uses-rag': ['rag-security', 'data-integrity'],
|
|
15
16
|
'uses-finetuned': ['data-integrity', 'supply-chain'],
|
|
16
17
|
'uses-thirdparty-api': ['supply-chain'],
|
|
@@ -22,7 +23,7 @@ const TRAIT_FILES = {
|
|
|
22
23
|
'handles-proprietary': ['pii-handling', 'prompt-security'],
|
|
23
24
|
'handles-minors': ['pii-handling', 'bias-monitoring', 'human-oversight'],
|
|
24
25
|
'influences-decisions': ['bias-monitoring', 'confidence-scoring', 'human-oversight', 'explainability'],
|
|
25
|
-
'accepts-user-input': ['input-validation', 'output-sanitization'],
|
|
26
|
+
'accepts-user-input': ['input-validation', 'output-sanitization', 'eu-ai-act-art-50-transparency-disclosure'],
|
|
26
27
|
'is-external': ['rate-limiting', 'confidence-scoring'],
|
|
27
28
|
'is-internal': [],
|
|
28
29
|
'is-high-volume': ['rate-limiting', 'monitoring', 'fallback-patterns'],
|
|
@@ -32,6 +33,11 @@ const TRAIT_FILES = {
|
|
|
32
33
|
'jurisdiction-eu': [],
|
|
33
34
|
'jurisdiction-us-regulated': [],
|
|
34
35
|
'jurisdiction-global': [],
|
|
36
|
+
'is-eu-high-risk': [
|
|
37
|
+
'eu-ai-act-art-9-risk-management',
|
|
38
|
+
'eu-ai-act-art-13-deployer-transparency',
|
|
39
|
+
'eu-ai-act-art-73-incident-reporting',
|
|
40
|
+
], // v2.1: pulls EU AI Act high-risk areas. Brief assembly (Step 4) filters by jurisdiction-eu before rendering.
|
|
35
41
|
};
|
|
36
42
|
|
|
37
43
|
const FILE_CONTROLS = {
|
package/lib/init.js
CHANGED
|
@@ -106,14 +106,270 @@ function init(ide, opts = {}) {
|
|
|
106
106
|
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
107
107
|
if (!fs.existsSync(skillDir)) fs.mkdirSync(skillDir, { recursive: true });
|
|
108
108
|
writeOrRefresh(skillFile, content, checksum, opts.refresh, dest.instruction, ideLower);
|
|
109
|
+
} else {
|
|
110
|
+
// Other IDEs
|
|
111
|
+
const targetFile = path.resolve(dest.file);
|
|
112
|
+
const targetDir = path.dirname(targetFile);
|
|
113
|
+
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
|
|
114
|
+
writeOrRefresh(targetFile, content, checksum, opts.refresh, dest.instruction, ideLower, dest.file);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// v2.1: optional activation surfaces — additive, opt-in via flags.
|
|
118
|
+
if (opts.ci === 'github' || opts.ci === true) {
|
|
119
|
+
installGithubAction({ refresh: !!opts.refresh });
|
|
120
|
+
}
|
|
121
|
+
if (opts.hook) {
|
|
122
|
+
installPreCommitHook({ refresh: !!opts.refresh });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* v2.1 — GitHub Action template installer.
|
|
128
|
+
*
|
|
129
|
+
* Drops `.github/workflows/aigis.yml` into the repo. The workflow runs
|
|
130
|
+
* `aigis report --areas <list> --project .` on every pull_request, where
|
|
131
|
+
* the area list comes from an opt-in `.aigisrc.json` file the user maintains.
|
|
132
|
+
* No `.aigisrc.json` → workflow no-ops with a helpful message.
|
|
133
|
+
*
|
|
134
|
+
* Refresh model identical to the IDE rules block: checksum-guarded; existing
|
|
135
|
+
* file with matching checksum is left alone; mismatch errors with --refresh hint.
|
|
136
|
+
*/
|
|
137
|
+
function installGithubAction({ refresh = false } = {}) {
|
|
138
|
+
const targetDir = path.resolve('.github', 'workflows');
|
|
139
|
+
const targetFile = path.join(targetDir, 'aigis.yml');
|
|
140
|
+
const display = '.github/workflows/aigis.yml';
|
|
141
|
+
const content = renderGithubActionWorkflow();
|
|
142
|
+
// Checksum is over the BODY only (not the comment header that contains the
|
|
143
|
+
// checksum itself — would be self-referential). Must match what
|
|
144
|
+
// renderGithubActionWorkflow embeds in the header tag.
|
|
145
|
+
const checksum = sha256(GITHUB_ACTION_BODY).slice(0, 12);
|
|
146
|
+
|
|
147
|
+
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
|
|
148
|
+
|
|
149
|
+
if (!fs.existsSync(targetFile)) {
|
|
150
|
+
fs.writeFileSync(targetFile, content);
|
|
151
|
+
console.log(chalk.green(`✓ Installed CI workflow: ${display}`));
|
|
152
|
+
console.log(chalk.dim(' Add a .aigisrc.json to your repo root to declare which areas to verify on PRs.'));
|
|
153
|
+
console.log(chalk.dim(' Example: { "areas": ["pii-handling", "audit-logging"], "jurisdiction": "eu" }\n'));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Existing file — check checksum
|
|
158
|
+
const existing = fs.readFileSync(targetFile, 'utf8');
|
|
159
|
+
const existingChecksum = (existing.match(/# aigis-action-checksum: ([a-f0-9]+)/) || [])[1];
|
|
160
|
+
if (existingChecksum === checksum) {
|
|
161
|
+
console.log(chalk.dim(`${display} is up to date.`));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (refresh) {
|
|
165
|
+
fs.writeFileSync(targetFile, content);
|
|
166
|
+
console.log(chalk.green(`✓ Refreshed ${display} (checksum: ${checksum})`));
|
|
109
167
|
return;
|
|
110
168
|
}
|
|
169
|
+
console.log(chalk.yellow(`⚠ ${display} exists with a different checksum.`));
|
|
170
|
+
console.log(chalk.dim(` Existing: ${existingChecksum || '(no checksum tag)'}`));
|
|
171
|
+
console.log(chalk.dim(` Current: ${checksum}`));
|
|
172
|
+
console.log(` Re-run with ${chalk.green('--refresh')} to overwrite, or remove the file manually.`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderGithubActionWorkflow() {
|
|
176
|
+
// Single, opinionated workflow. Reads .aigisrc.json from the repo root for
|
|
177
|
+
// configuration. No magic — the user opts in by creating that file.
|
|
178
|
+
const checksum = sha256(GITHUB_ACTION_BODY).slice(0, 12);
|
|
179
|
+
return `# aigis-action-checksum: ${checksum}
|
|
180
|
+
# Installed by \`aigis init <ide> --ci github\`. Re-run with --refresh to update.
|
|
181
|
+
# Configure areas to verify by creating a .aigisrc.json in your repo root:
|
|
182
|
+
# { "areas": ["pii-handling", "audit-logging"], "jurisdiction": "eu" }
|
|
183
|
+
${GITHUB_ACTION_BODY}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const GITHUB_ACTION_BODY = `name: aigis governance
|
|
187
|
+
|
|
188
|
+
on:
|
|
189
|
+
pull_request:
|
|
190
|
+
branches: ['**']
|
|
191
|
+
workflow_dispatch:
|
|
192
|
+
|
|
193
|
+
jobs:
|
|
194
|
+
verify:
|
|
195
|
+
name: aigis verify (declared areas)
|
|
196
|
+
runs-on: ubuntu-latest
|
|
197
|
+
steps:
|
|
198
|
+
- name: Checkout
|
|
199
|
+
uses: actions/checkout@v4
|
|
200
|
+
|
|
201
|
+
- name: Setup Node
|
|
202
|
+
uses: actions/setup-node@v4
|
|
203
|
+
with:
|
|
204
|
+
node-version: '20'
|
|
205
|
+
|
|
206
|
+
- name: Install aigis
|
|
207
|
+
run: npm install -g @aigis-ai/cli
|
|
208
|
+
|
|
209
|
+
- name: Read .aigisrc.json
|
|
210
|
+
id: config
|
|
211
|
+
run: |
|
|
212
|
+
if [ -f .aigisrc.json ]; then
|
|
213
|
+
AREAS=$(node -e "console.log((JSON.parse(require('fs').readFileSync('.aigisrc.json'))['areas']||[]).join(','))")
|
|
214
|
+
JUR=$(node -e "console.log(JSON.parse(require('fs').readFileSync('.aigisrc.json'))['jurisdiction']||'')")
|
|
215
|
+
echo "areas=$AREAS" >> "$GITHUB_OUTPUT"
|
|
216
|
+
echo "jurisdiction=$JUR" >> "$GITHUB_OUTPUT"
|
|
217
|
+
else
|
|
218
|
+
echo "::notice::No .aigisrc.json found. Aigis is installed but no areas declared. See https://github.com/NayanKanaparthi/aigis"
|
|
219
|
+
echo "areas=" >> "$GITHUB_OUTPUT"
|
|
220
|
+
echo "jurisdiction=" >> "$GITHUB_OUTPUT"
|
|
221
|
+
fi
|
|
222
|
+
|
|
223
|
+
- name: Generate compliance report
|
|
224
|
+
if: steps.config.outputs.areas != ''
|
|
225
|
+
run: |
|
|
226
|
+
ARGS="--areas \${{ steps.config.outputs.areas }} --project ."
|
|
227
|
+
if [ -n "\${{ steps.config.outputs.jurisdiction }}" ]; then
|
|
228
|
+
ARGS="$ARGS --jurisdiction \${{ steps.config.outputs.jurisdiction }}"
|
|
229
|
+
fi
|
|
230
|
+
aigis report $ARGS --output aigis-report.md
|
|
231
|
+
cat aigis-report.md
|
|
232
|
+
|
|
233
|
+
- name: Upload report artifact
|
|
234
|
+
if: steps.config.outputs.areas != ''
|
|
235
|
+
uses: actions/upload-artifact@v4
|
|
236
|
+
with:
|
|
237
|
+
name: aigis-compliance-report
|
|
238
|
+
path: aigis-report.md
|
|
239
|
+
retention-days: 30
|
|
240
|
+
|
|
241
|
+
- name: Run verify (per area, exit on FAIL)
|
|
242
|
+
if: steps.config.outputs.areas != ''
|
|
243
|
+
run: |
|
|
244
|
+
IFS=',' read -ra AREA_LIST <<< "\${{ steps.config.outputs.areas }}"
|
|
245
|
+
FAILED=0
|
|
246
|
+
for AREA in "\${AREA_LIST[@]}"; do
|
|
247
|
+
AREA=$(echo "$AREA" | xargs)
|
|
248
|
+
JUR_FLAG=""
|
|
249
|
+
if [ -n "\${{ steps.config.outputs.jurisdiction }}" ]; then
|
|
250
|
+
JUR_FLAG="--jurisdiction \${{ steps.config.outputs.jurisdiction }}"
|
|
251
|
+
fi
|
|
252
|
+
if ! aigis verify "$AREA" --auto . $JUR_FLAG > /tmp/aigis-$AREA.txt; then
|
|
253
|
+
echo "::error title=aigis verify $AREA::FAIL or OVERCLAIM detected"
|
|
254
|
+
cat /tmp/aigis-$AREA.txt
|
|
255
|
+
FAILED=1
|
|
256
|
+
else
|
|
257
|
+
echo "::group::aigis verify $AREA"
|
|
258
|
+
cat /tmp/aigis-$AREA.txt
|
|
259
|
+
echo "::endgroup::"
|
|
260
|
+
fi
|
|
261
|
+
done
|
|
262
|
+
if [ "$FAILED" -ne 0 ]; then exit 1; fi
|
|
263
|
+
`;
|
|
111
264
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
265
|
+
/**
|
|
266
|
+
* v2.1 — Pre-commit hook installer.
|
|
267
|
+
*
|
|
268
|
+
* Drops `.git/hooks/pre-commit` shell script. Runs `aigis verify` on
|
|
269
|
+
* areas declared in `.aigisrc.json`. Blocks commit on FAIL/OVERCLAIM.
|
|
270
|
+
* No `.aigisrc.json` → no-op (lets commit through with a notice).
|
|
271
|
+
*
|
|
272
|
+
* Refresh-guarded with checksum tag in the script header.
|
|
273
|
+
*/
|
|
274
|
+
function installPreCommitHook({ refresh = false } = {}) {
|
|
275
|
+
const targetDir = path.resolve('.git', 'hooks');
|
|
276
|
+
const targetFile = path.join(targetDir, 'pre-commit');
|
|
277
|
+
const display = '.git/hooks/pre-commit';
|
|
278
|
+
if (!fs.existsSync(path.resolve('.git'))) {
|
|
279
|
+
console.log(chalk.yellow(`⚠ Not a git repository (.git/ not found). Skipping pre-commit hook installation.`));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
115
282
|
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
|
|
116
|
-
|
|
283
|
+
|
|
284
|
+
const content = renderPreCommitHook();
|
|
285
|
+
// Checksum is over the BODY only (matches what renderPreCommitHook embeds
|
|
286
|
+
// in the header tag); avoids self-reference.
|
|
287
|
+
const checksum = sha256(PRE_COMMIT_BODY).slice(0, 12);
|
|
288
|
+
|
|
289
|
+
if (!fs.existsSync(targetFile)) {
|
|
290
|
+
fs.writeFileSync(targetFile, content);
|
|
291
|
+
fs.chmodSync(targetFile, 0o755);
|
|
292
|
+
console.log(chalk.green(`✓ Installed pre-commit hook: ${display}`));
|
|
293
|
+
console.log(chalk.dim(' Add a .aigisrc.json to your repo root to declare which areas to verify on commit.'));
|
|
294
|
+
console.log(chalk.dim(' Example: { "areas": ["pii-handling", "audit-logging"], "jurisdiction": "eu" }\n'));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const existing = fs.readFileSync(targetFile, 'utf8');
|
|
299
|
+
const existingChecksum = (existing.match(/# aigis-hook-checksum: ([a-f0-9]+)/) || [])[1];
|
|
300
|
+
if (existingChecksum === checksum) {
|
|
301
|
+
console.log(chalk.dim(`${display} is up to date.`));
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (refresh) {
|
|
305
|
+
fs.writeFileSync(targetFile, content);
|
|
306
|
+
fs.chmodSync(targetFile, 0o755);
|
|
307
|
+
console.log(chalk.green(`✓ Refreshed ${display} (checksum: ${checksum})`));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
console.log(chalk.yellow(`⚠ ${display} exists with a different checksum.`));
|
|
311
|
+
console.log(chalk.dim(` Existing: ${existingChecksum || '(no checksum tag — likely not from aigis)'}`));
|
|
312
|
+
console.log(chalk.dim(` Current: ${checksum}`));
|
|
313
|
+
console.log(` Re-run with ${chalk.green('--refresh')} to overwrite (will replace your existing pre-commit hook).`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function renderPreCommitHook() {
|
|
317
|
+
const checksum = sha256(PRE_COMMIT_BODY).slice(0, 12);
|
|
318
|
+
return `#!/usr/bin/env bash
|
|
319
|
+
# aigis-hook-checksum: ${checksum}
|
|
320
|
+
# Installed by \`aigis init <ide> --hook\`. Re-run with --refresh to update.
|
|
321
|
+
# Configure areas to verify by creating a .aigisrc.json in your repo root:
|
|
322
|
+
# { "areas": ["pii-handling", "audit-logging"], "jurisdiction": "eu" }
|
|
323
|
+
${PRE_COMMIT_BODY}`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const PRE_COMMIT_BODY = `set -e
|
|
327
|
+
|
|
328
|
+
if [ ! -f .aigisrc.json ]; then
|
|
329
|
+
echo "[aigis] No .aigisrc.json found. Skipping verify (configure to enable)."
|
|
330
|
+
exit 0
|
|
331
|
+
fi
|
|
332
|
+
|
|
333
|
+
if ! command -v aigis > /dev/null 2>&1; then
|
|
334
|
+
echo "[aigis] aigis CLI not on PATH. Skipping verify (install via 'npm i -g @aigis-ai/cli' or 'pip install aigis-cli')."
|
|
335
|
+
exit 0
|
|
336
|
+
fi
|
|
337
|
+
|
|
338
|
+
AREAS=$(node -e "console.log((JSON.parse(require('fs').readFileSync('.aigisrc.json'))['areas']||[]).join(' '))" 2>/dev/null || echo "")
|
|
339
|
+
JUR=$(node -e "console.log(JSON.parse(require('fs').readFileSync('.aigisrc.json'))['jurisdiction']||'')" 2>/dev/null || echo "")
|
|
340
|
+
|
|
341
|
+
if [ -z "$AREAS" ]; then
|
|
342
|
+
echo "[aigis] .aigisrc.json found but no 'areas' declared. Skipping."
|
|
343
|
+
exit 0
|
|
344
|
+
fi
|
|
345
|
+
|
|
346
|
+
JUR_FLAG=""
|
|
347
|
+
if [ -n "$JUR" ]; then
|
|
348
|
+
JUR_FLAG="--jurisdiction $JUR"
|
|
349
|
+
fi
|
|
350
|
+
|
|
351
|
+
FAILED=0
|
|
352
|
+
for AREA in $AREAS; do
|
|
353
|
+
if ! aigis verify "$AREA" --auto . $JUR_FLAG > /tmp/aigis-precommit-$AREA.txt 2>&1; then
|
|
354
|
+
echo "[aigis] FAIL or OVERCLAIM in $AREA — blocking commit."
|
|
355
|
+
echo
|
|
356
|
+
tail -40 /tmp/aigis-precommit-$AREA.txt
|
|
357
|
+
echo
|
|
358
|
+
FAILED=1
|
|
359
|
+
fi
|
|
360
|
+
done
|
|
361
|
+
|
|
362
|
+
if [ "$FAILED" -ne 0 ]; then
|
|
363
|
+
echo
|
|
364
|
+
echo "[aigis] Commit blocked. Fix the above OR commit with --no-verify to bypass."
|
|
365
|
+
exit 1
|
|
366
|
+
fi
|
|
367
|
+
|
|
368
|
+
echo "[aigis] All declared areas pass. Commit proceeding."
|
|
369
|
+
`;
|
|
370
|
+
|
|
371
|
+
function sha256(s) {
|
|
372
|
+
return require('crypto').createHash('sha256').update(s).digest('hex');
|
|
117
373
|
}
|
|
118
374
|
|
|
119
375
|
function writeOrRefresh(targetFile, content, expectedChecksum, refresh, instruction, ideName, displayName) {
|
|
@@ -170,4 +426,12 @@ function writeOrRefresh(targetFile, content, expectedChecksum, refresh, instruct
|
|
|
170
426
|
process.exit(1);
|
|
171
427
|
}
|
|
172
428
|
|
|
173
|
-
module.exports = {
|
|
429
|
+
module.exports = {
|
|
430
|
+
init,
|
|
431
|
+
buildFullContent,
|
|
432
|
+
renderResolverBlock,
|
|
433
|
+
installGithubAction,
|
|
434
|
+
installPreCommitHook,
|
|
435
|
+
renderGithubActionWorkflow,
|
|
436
|
+
renderPreCommitHook,
|
|
437
|
+
};
|