aigis-cli 2.0.2__tar.gz → 2.1.0__tar.gz
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.
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/PKG-INFO +1 -1
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/__init__.py +1 -1
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/auto_verify.py +61 -1
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/build.py +73 -12
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/classify.py +8 -2
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/cli.py +120 -10
- aigis_cli-2.1.0/aigis_cli/content/resolvers/triggers.json +551 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/audit-logging.md +33 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/bias-monitoring.md +34 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/confidence-scoring.md +23 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/data-integrity.md +25 -0
- aigis_cli-2.1.0/aigis_cli/content/skills/areas/eu-ai-act-art-13-deployer-transparency.md +133 -0
- aigis_cli-2.1.0/aigis_cli/content/skills/areas/eu-ai-act-art-50-transparency-disclosure.md +134 -0
- aigis_cli-2.1.0/aigis_cli/content/skills/areas/eu-ai-act-art-73-incident-reporting.md +149 -0
- aigis_cli-2.1.0/aigis_cli/content/skills/areas/eu-ai-act-art-9-risk-management.md +141 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/fallback-patterns.md +28 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/human-oversight.md +38 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/input-validation.md +27 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/monitoring.md +29 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/prompt-security.md +29 -0
- aigis_cli-2.1.0/aigis_cli/content/templates/eu-ai-act-annex-iv.md +193 -0
- aigis_cli-2.1.0/aigis_cli/init_ide.py +390 -0
- aigis_cli-2.1.0/aigis_cli/jurisdiction.py +115 -0
- aigis_cli-2.1.0/aigis_cli/report.py +297 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/PKG-INFO +1 -1
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/SOURCES.txt +7 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/pyproject.toml +1 -1
- aigis_cli-2.0.2/aigis_cli/content/resolvers/triggers.json +0 -229
- aigis_cli-2.0.2/aigis_cli/init_ide.py +0 -159
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/LICENSE +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/README.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/SKILL.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/annotate.py +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/checksum.py +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/audit-scan.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/auto-verify-rules.json +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/context-rules.json +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/frameworks.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/guardrails.json +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/index/taxonomy.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/explainability.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/output-sanitization.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/pii-handling.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/rag-security.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/rate-limiting.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/areas/supply-chain.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/core.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/infrastructure/logging.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/infrastructure/rate-limiting.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/infrastructure/secrets.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/skills/workflows/fastapi-llm.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/templates/ai-impact-assessment.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/templates/intended-purpose-doc.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/templates/risk-characterization.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/templates/third-party-assessment.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-audit-logging.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-bias-monitoring.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-confidence-scoring.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-data-integrity.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-explainability.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-fallback-patterns.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-human-oversight.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-input-validation.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-monitoring.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-output-sanitization.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-pii-handling.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-prompt-security.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-rag-security.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-rate-limiting.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/content/verify/checklist-supply-chain.md +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/fetch.py +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/keywords.py +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli/search.py +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/dependency_links.txt +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/entry_points.txt +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/requires.txt +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/aigis_cli.egg-info/top_level.txt +0 -0
- {aigis_cli-2.0.2 → aigis_cli-2.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aigis-cli
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: AI governance guardrails for coding agents. Framework-aligned security and compliance patterns from NIST AI RMF, OWASP Top 10 for LLMs, and ISO/IEC 42001.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/NayanKanaparthi/aigis
|
|
@@ -406,7 +406,13 @@ _SPECIAL_REGISTRY = {
|
|
|
406
406
|
|
|
407
407
|
# ── Public API ─────────────────────────────────────────────────────────
|
|
408
408
|
|
|
409
|
-
def auto_verify_area(area_id: str, project_dir: str) -> dict[str, Any]:
|
|
409
|
+
def auto_verify_area(area_id: str, project_dir: str, jurisdictions: list[str] | None = None) -> dict[str, Any]:
|
|
410
|
+
"""v2.1: jurisdictions list (e.g. ['eu']) gates EU AI Act control citations
|
|
411
|
+
in the report. Default empty — verify is conservative; eu_ai_act citations
|
|
412
|
+
only appear when the user explicitly opts in via --jurisdiction eu.
|
|
413
|
+
"""
|
|
414
|
+
user_jurisdictions = set(jurisdictions or [])
|
|
415
|
+
|
|
410
416
|
rules = load_rules()
|
|
411
417
|
area = rules.get(area_id)
|
|
412
418
|
if not area:
|
|
@@ -414,6 +420,10 @@ def auto_verify_area(area_id: str, project_dir: str) -> dict[str, Any]:
|
|
|
414
420
|
f"No auto-verify rules for pattern area '{area_id}'. "
|
|
415
421
|
f"Known: {', '.join(rules.keys())}"
|
|
416
422
|
)
|
|
423
|
+
|
|
424
|
+
# v2.1: read area frontmatter controls for citation in the report.
|
|
425
|
+
all_controls = _read_area_controls(area_id)
|
|
426
|
+
|
|
417
427
|
root = Path(project_dir).resolve()
|
|
418
428
|
files = _load_files(root)
|
|
419
429
|
|
|
@@ -455,6 +465,17 @@ def auto_verify_area(area_id: str, project_dir: str) -> dict[str, Any]:
|
|
|
455
465
|
auto_fail = sum(1 for r in auto_results.values() if r["status"] == "FAIL")
|
|
456
466
|
overclaims_raised = sum(1 for r in overclaim_results.values() if r["raised"])
|
|
457
467
|
|
|
468
|
+
# v2.1: assemble cited controls. EU AI Act gated on jurisdiction.
|
|
469
|
+
show_eu = "eu" in user_jurisdictions
|
|
470
|
+
cited = None
|
|
471
|
+
if all_controls:
|
|
472
|
+
cited = {
|
|
473
|
+
"owasp": all_controls["owasp"],
|
|
474
|
+
"nist": all_controls["nist"],
|
|
475
|
+
"iso42001": all_controls["iso42001"],
|
|
476
|
+
"eu_ai_act": all_controls["eu_ai_act"] if show_eu else [],
|
|
477
|
+
}
|
|
478
|
+
|
|
458
479
|
return {
|
|
459
480
|
"area": area_id,
|
|
460
481
|
"project_dir": str(root),
|
|
@@ -469,9 +490,34 @@ def auto_verify_area(area_id: str, project_dir: str) -> dict[str, Any]:
|
|
|
469
490
|
"auto_checks": auto_results,
|
|
470
491
|
"overclaim_checks": overclaim_results,
|
|
471
492
|
"judgment_checks": judgment_results,
|
|
493
|
+
"cited_controls": cited,
|
|
494
|
+
"user_jurisdictions": sorted(user_jurisdictions),
|
|
472
495
|
}
|
|
473
496
|
|
|
474
497
|
|
|
498
|
+
def _read_area_controls(area_id: str) -> dict[str, list[str]] | None:
|
|
499
|
+
"""Read an area's frontmatter `controls` block (all four frameworks).
|
|
500
|
+
Returns None on missing file or parse failure.
|
|
501
|
+
"""
|
|
502
|
+
try:
|
|
503
|
+
import frontmatter # local import to keep top-of-file imports lean
|
|
504
|
+
from pathlib import Path
|
|
505
|
+
areas_dir = Path(__file__).resolve().parent / "content" / "skills" / "areas"
|
|
506
|
+
filepath = areas_dir / f"{area_id}.md"
|
|
507
|
+
if not filepath.exists():
|
|
508
|
+
return None
|
|
509
|
+
fm = frontmatter.loads(filepath.read_text(encoding="utf-8")).metadata
|
|
510
|
+
c = fm.get("controls", {}) or {}
|
|
511
|
+
return {
|
|
512
|
+
"owasp": c.get("owasp", []) or [],
|
|
513
|
+
"nist": c.get("nist", []) or [],
|
|
514
|
+
"iso42001": c.get("iso42001", []) or [],
|
|
515
|
+
"eu_ai_act": c.get("eu_ai_act", []) or [],
|
|
516
|
+
}
|
|
517
|
+
except Exception:
|
|
518
|
+
return None
|
|
519
|
+
|
|
520
|
+
|
|
475
521
|
def format_text_report(result: dict[str, Any]) -> str:
|
|
476
522
|
lines: list[str] = []
|
|
477
523
|
lines.append(f"═══ AUTO-VERIFY: {result['area']} ═══\n")
|
|
@@ -482,6 +528,20 @@ def format_text_report(result: dict[str, Any]) -> str:
|
|
|
482
528
|
lines.append(f"Overclaim recognizers raised: {s['overclaims_raised']}")
|
|
483
529
|
lines.append(f"Judgment required: {s['judgment_required']} check(s)\n")
|
|
484
530
|
|
|
531
|
+
# v2.1: cite framework controls. Mirror of lib/auto-verify.js.
|
|
532
|
+
cited = result.get("cited_controls")
|
|
533
|
+
if cited:
|
|
534
|
+
total_cited = len(cited["owasp"]) + len(cited["nist"]) + len(cited["iso42001"]) + len(cited["eu_ai_act"])
|
|
535
|
+
if total_cited > 0:
|
|
536
|
+
all_pass = s["auto_pass"] == s["auto_total"] and s["auto_fail"] == 0
|
|
537
|
+
header = "Controls satisfied (all auto checks PASS):" if all_pass else "Controls in scope (partial — fix FAIL/OVERCLAIM to fully satisfy):"
|
|
538
|
+
lines.append(f"── {header} ──")
|
|
539
|
+
if cited["owasp"]: lines.append(f" OWASP LLM Top 10: {', '.join(cited['owasp'])}")
|
|
540
|
+
if cited["nist"]: lines.append(f" NIST AI RMF: {', '.join(cited['nist'])}")
|
|
541
|
+
if cited["iso42001"]: lines.append(f" ISO/IEC 42001: {', '.join(cited['iso42001'])}")
|
|
542
|
+
if cited["eu_ai_act"]:lines.append(f" EU AI Act: {', '.join(cited['eu_ai_act'])}")
|
|
543
|
+
lines.append("")
|
|
544
|
+
|
|
485
545
|
if result["auto_checks"]:
|
|
486
546
|
lines.append("── AUTO CHECKS ──")
|
|
487
547
|
for cid, r in result["auto_checks"].items():
|
|
@@ -23,6 +23,11 @@ import frontmatter
|
|
|
23
23
|
from .classify import classify
|
|
24
24
|
from .keywords import detect_traits_from_text
|
|
25
25
|
from .fetch import get_infra
|
|
26
|
+
from .jurisdiction import (
|
|
27
|
+
get_user_jurisdictions,
|
|
28
|
+
filter_areas_by_jurisdiction,
|
|
29
|
+
strip_jurisdiction_gated_sections,
|
|
30
|
+
)
|
|
26
31
|
|
|
27
32
|
CONTENT_DIR = Path(__file__).resolve().parent / "content"
|
|
28
33
|
|
|
@@ -169,7 +174,21 @@ def _read_version() -> str:
|
|
|
169
174
|
return "unknown"
|
|
170
175
|
|
|
171
176
|
|
|
172
|
-
def
|
|
177
|
+
def _read_area_system_traits(area_id: str) -> list[str] | None:
|
|
178
|
+
"""v2.1: read an area's `system_traits` frontmatter for --tight matching."""
|
|
179
|
+
try:
|
|
180
|
+
filepath = CONTENT_DIR / "skills" / "areas" / f"{area_id}.md"
|
|
181
|
+
if not filepath.exists():
|
|
182
|
+
return None
|
|
183
|
+
fm = frontmatter.loads(filepath.read_text(encoding="utf-8")).metadata
|
|
184
|
+
st = fm.get("system_traits")
|
|
185
|
+
return list(st) if isinstance(st, list) else None
|
|
186
|
+
except Exception:
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _prepare(description: str, decisions: dict, extra_jurisdictions: list[str] | None = None, tight: bool = False) -> dict:
|
|
191
|
+
extra_jurisdictions = extra_jurisdictions or []
|
|
173
192
|
normalized = normalize_description(description)
|
|
174
193
|
if not normalized:
|
|
175
194
|
raise ValueError('Provide a description in quotes. Example: aigis build "customer chatbot with RAG"')
|
|
@@ -185,13 +204,39 @@ def _prepare(description: str, decisions: dict) -> dict:
|
|
|
185
204
|
numeric_decisions[m["id"]] = decisions[m["id"]]
|
|
186
205
|
|
|
187
206
|
resolved = resolve_traits(detection_with_slugs, numeric_decisions, uncertain_as_included=True)
|
|
188
|
-
|
|
207
|
+
|
|
208
|
+
# v2.1: --jurisdiction flag adds jurisdiction-* traits before classify.
|
|
209
|
+
extra_jurisdiction_traits = [f"jurisdiction-{c}" for c in (extra_jurisdictions or []) if c]
|
|
210
|
+
all_traits_with_jurisdiction = sorted(set(resolved["all_traits"]) | set(extra_jurisdiction_traits))
|
|
211
|
+
|
|
212
|
+
if not all_traits_with_jurisdiction:
|
|
189
213
|
raise ValueError(
|
|
190
214
|
"No traits resolved from description. Try a more specific description, "
|
|
191
215
|
'or use `aigis classify --traits ...` directly.'
|
|
192
216
|
)
|
|
193
|
-
cls = classify(
|
|
194
|
-
|
|
217
|
+
cls = classify(all_traits_with_jurisdiction)
|
|
218
|
+
|
|
219
|
+
# v2.1: jurisdiction filter on the area list.
|
|
220
|
+
user_jurisdictions = get_user_jurisdictions(all_traits_with_jurisdiction)
|
|
221
|
+
areas_before_filter = cls["implement_files"]
|
|
222
|
+
areas = filter_areas_by_jurisdiction(areas_before_filter, user_jurisdictions)
|
|
223
|
+
|
|
224
|
+
# v2.1 --tight mode: require ≥2 of the user's traits to match an area's system_traits.
|
|
225
|
+
areas_before_tight: list[str] | None = None
|
|
226
|
+
tight_dropped: list[dict] = []
|
|
227
|
+
if tight:
|
|
228
|
+
areas_before_tight = list(areas)
|
|
229
|
+
user_trait_set = set(all_traits_with_jurisdiction)
|
|
230
|
+
kept: list[str] = []
|
|
231
|
+
for area in areas:
|
|
232
|
+
sys_traits = _read_area_system_traits(area) or []
|
|
233
|
+
match_count = sum(1 for t in sys_traits if t in user_trait_set)
|
|
234
|
+
if match_count >= 2:
|
|
235
|
+
kept.append(area)
|
|
236
|
+
else:
|
|
237
|
+
tight_dropped.append({"area": area, "match_count": match_count})
|
|
238
|
+
areas = kept
|
|
239
|
+
|
|
195
240
|
infra_ids = collect_infra_references(areas)
|
|
196
241
|
|
|
197
242
|
return {
|
|
@@ -202,6 +247,11 @@ def _prepare(description: str, decisions: dict) -> dict:
|
|
|
202
247
|
"resolved": resolved,
|
|
203
248
|
"cls": cls,
|
|
204
249
|
"areas": areas,
|
|
250
|
+
"areas_before_jurisdiction_filter": areas_before_filter,
|
|
251
|
+
"areas_before_tight_filter": areas_before_tight,
|
|
252
|
+
"tight_dropped": tight_dropped,
|
|
253
|
+
"tight_mode": bool(tight),
|
|
254
|
+
"user_jurisdictions": sorted(user_jurisdictions),
|
|
205
255
|
"infra_ids": infra_ids,
|
|
206
256
|
}
|
|
207
257
|
|
|
@@ -303,11 +353,13 @@ def _render_verification(*, areas, resolved, cls):
|
|
|
303
353
|
|
|
304
354
|
|
|
305
355
|
def build_compact(description: str, decisions: dict | None = None, *,
|
|
356
|
+
extra_jurisdictions: list[str] | None = None,
|
|
357
|
+
tight: bool = False,
|
|
306
358
|
timestamp: datetime | None = None,
|
|
307
359
|
version_string: str | None = None,
|
|
308
360
|
fell_back_from_full: bool = False) -> dict:
|
|
309
361
|
decisions = decisions or {}
|
|
310
|
-
prep = _prepare(description, decisions)
|
|
362
|
+
prep = _prepare(description, decisions, extra_jurisdictions, tight=tight)
|
|
311
363
|
ts = _iso_ms(timestamp)
|
|
312
364
|
version = version_string or _read_version()
|
|
313
365
|
|
|
@@ -352,11 +404,13 @@ def build_compact(description: str, decisions: dict | None = None, *,
|
|
|
352
404
|
|
|
353
405
|
|
|
354
406
|
def build_full(description: str, decisions: dict | None = None, *,
|
|
407
|
+
extra_jurisdictions: list[str] | None = None,
|
|
408
|
+
tight: bool = False,
|
|
355
409
|
char_cap: int = FULL_HARD_CAP,
|
|
356
410
|
timestamp: datetime | None = None,
|
|
357
411
|
version_string: str | None = None) -> dict:
|
|
358
412
|
decisions = decisions or {}
|
|
359
|
-
prep = _prepare(description, decisions)
|
|
413
|
+
prep = _prepare(description, decisions, extra_jurisdictions, tight=tight)
|
|
360
414
|
ts = _iso_ms(timestamp)
|
|
361
415
|
version = version_string or _read_version()
|
|
362
416
|
|
|
@@ -365,6 +419,10 @@ def build_full(description: str, decisions: dict | None = None, *,
|
|
|
365
419
|
cls=prep["cls"], resolved=prep["resolved"], areas=prep["areas"], infra_ids=prep["infra_ids"],
|
|
366
420
|
)
|
|
367
421
|
|
|
422
|
+
# v2.1: for non-EU users, strip `## EU AI Act extensions` sections from
|
|
423
|
+
# universal-area content before inlining (parity with lib/build.js).
|
|
424
|
+
user_j = set(prep["user_jurisdictions"])
|
|
425
|
+
|
|
368
426
|
s.append("## Areas")
|
|
369
427
|
s.append("")
|
|
370
428
|
for i, area in enumerate(prep["areas"], 1):
|
|
@@ -373,6 +431,7 @@ def build_full(description: str, decisions: dict | None = None, *,
|
|
|
373
431
|
except FileNotFoundError:
|
|
374
432
|
continue
|
|
375
433
|
stripped = strip_frontmatter_raw(raw)
|
|
434
|
+
stripped = strip_jurisdiction_gated_sections(stripped, user_j)
|
|
376
435
|
s.append(f"### {i}. {area}")
|
|
377
436
|
s.append("")
|
|
378
437
|
s.append(stripped)
|
|
@@ -406,23 +465,25 @@ def build_full(description: str, decisions: dict | None = None, *,
|
|
|
406
465
|
|
|
407
466
|
|
|
408
467
|
def build_brief(description: str, decisions: dict | None = None, *,
|
|
468
|
+
extra_jurisdictions: list[str] | None = None,
|
|
469
|
+
tight: bool = False,
|
|
409
470
|
mode: str = "auto",
|
|
410
471
|
timestamp: datetime | None = None,
|
|
411
472
|
version_string: str | None = None) -> dict:
|
|
412
473
|
"""Dispatcher. mode ∈ {'auto', 'full', 'compact'}."""
|
|
413
474
|
decisions = decisions or {}
|
|
414
475
|
if mode == "compact":
|
|
415
|
-
r = build_compact(description, decisions, timestamp=timestamp, version_string=version_string)
|
|
476
|
+
r = build_compact(description, decisions, extra_jurisdictions=extra_jurisdictions, tight=tight, timestamp=timestamp, version_string=version_string)
|
|
416
477
|
return {**r, "mode": "compact", "auto_fallback": False}
|
|
417
478
|
if mode == "full":
|
|
418
|
-
r = build_full(description, decisions, char_cap=FULL_HARD_CAP, timestamp=timestamp, version_string=version_string)
|
|
479
|
+
r = build_full(description, decisions, extra_jurisdictions=extra_jurisdictions, tight=tight, char_cap=FULL_HARD_CAP, timestamp=timestamp, version_string=version_string)
|
|
419
480
|
return {**r, "mode": "full", "auto_fallback": False}
|
|
420
481
|
# auto
|
|
421
482
|
try:
|
|
422
|
-
r = build_full(description, decisions, char_cap=AUTO_FULL_CAP, timestamp=timestamp, version_string=version_string)
|
|
483
|
+
r = build_full(description, decisions, extra_jurisdictions=extra_jurisdictions, tight=tight, char_cap=AUTO_FULL_CAP, timestamp=timestamp, version_string=version_string)
|
|
423
484
|
return {**r, "mode": "full", "auto_fallback": False}
|
|
424
485
|
except BriefTooLargeError as e:
|
|
425
|
-
compact = build_compact(description, decisions, timestamp=timestamp, version_string=version_string, fell_back_from_full=True)
|
|
486
|
+
compact = build_compact(description, decisions, extra_jurisdictions=extra_jurisdictions, tight=tight, timestamp=timestamp, version_string=version_string, fell_back_from_full=True)
|
|
426
487
|
return {
|
|
427
488
|
**compact,
|
|
428
489
|
"mode": "compact",
|
|
@@ -432,9 +493,9 @@ def build_brief(description: str, decisions: dict | None = None, *,
|
|
|
432
493
|
}
|
|
433
494
|
|
|
434
495
|
|
|
435
|
-
def build_list(description: str) -> str:
|
|
496
|
+
def build_list(description: str, extra_jurisdictions: list[str] | None = None, tight: bool = False) -> str:
|
|
436
497
|
"""Shape A — text output for `aigis build --list`."""
|
|
437
|
-
prep = _prepare(description, {})
|
|
498
|
+
prep = _prepare(description, {}, extra_jurisdictions, tight=tight)
|
|
438
499
|
lines: list[str] = []
|
|
439
500
|
lines.append(f"Description: {prep['normalized']}")
|
|
440
501
|
lines.append(f"Risk tier: {prep['cls']['risk_tier']}")
|
|
@@ -6,10 +6,11 @@ ALL_TRAITS = [
|
|
|
6
6
|
"influences-decisions", "accepts-user-input", "is-external", "is-internal", "is-high-volume",
|
|
7
7
|
"generates-code", "generates-content", "multi-model-pipeline",
|
|
8
8
|
"jurisdiction-eu", "jurisdiction-us-regulated", "jurisdiction-global",
|
|
9
|
+
"is-eu-high-risk", # v2.1: EU AI Act Annex III gating trait
|
|
9
10
|
]
|
|
10
11
|
|
|
11
12
|
TRAIT_FILES: dict[str, list[str]] = {
|
|
12
|
-
"uses-llm": ["input-validation", "output-sanitization", "prompt-security", "audit-logging", "monitoring"],
|
|
13
|
+
"uses-llm": ["input-validation", "output-sanitization", "prompt-security", "audit-logging", "monitoring", "eu-ai-act-art-50-transparency-disclosure"],
|
|
13
14
|
"uses-rag": ["rag-security", "data-integrity"],
|
|
14
15
|
"uses-finetuned": ["data-integrity", "supply-chain"],
|
|
15
16
|
"uses-thirdparty-api": ["supply-chain"],
|
|
@@ -21,7 +22,7 @@ TRAIT_FILES: dict[str, list[str]] = {
|
|
|
21
22
|
"handles-proprietary": ["pii-handling", "prompt-security"],
|
|
22
23
|
"handles-minors": ["pii-handling", "bias-monitoring", "human-oversight"],
|
|
23
24
|
"influences-decisions": ["bias-monitoring", "confidence-scoring", "human-oversight", "explainability"],
|
|
24
|
-
"accepts-user-input": ["input-validation", "output-sanitization"],
|
|
25
|
+
"accepts-user-input": ["input-validation", "output-sanitization", "eu-ai-act-art-50-transparency-disclosure"],
|
|
25
26
|
"is-external": ["rate-limiting", "confidence-scoring"],
|
|
26
27
|
"is-internal": [],
|
|
27
28
|
"is-high-volume": ["rate-limiting", "monitoring", "fallback-patterns"],
|
|
@@ -31,6 +32,11 @@ TRAIT_FILES: dict[str, list[str]] = {
|
|
|
31
32
|
"jurisdiction-eu": [],
|
|
32
33
|
"jurisdiction-us-regulated": [],
|
|
33
34
|
"jurisdiction-global": [],
|
|
35
|
+
"is-eu-high-risk": [
|
|
36
|
+
"eu-ai-act-art-9-risk-management",
|
|
37
|
+
"eu-ai-act-art-13-deployer-transparency",
|
|
38
|
+
"eu-ai-act-art-73-incident-reporting",
|
|
39
|
+
], # v2.1: pulls EU AI Act high-risk areas; brief assembly filters by jurisdiction-eu
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
FILE_CONTROLS: dict[str, dict[str, list[str]]] = {
|
|
@@ -10,6 +10,7 @@ from . import __version__
|
|
|
10
10
|
from .classify import classify as run_classify
|
|
11
11
|
from .fetch import get as fetch_get, get_audit_scan, get_infra, get_template, get_workflow, list_infras, list_workflows, verify as fetch_verify
|
|
12
12
|
from .build import build_brief, build_list, BriefTooLargeError, normalize_description, assign_unique_slugs
|
|
13
|
+
from .report import build_report, format_report_markdown, format_report_json
|
|
13
14
|
from .keywords import detect_traits_from_text
|
|
14
15
|
from .search import list_all, search as run_search
|
|
15
16
|
from .annotate import annotate as add_annotation, clear_annotation, list_annotations
|
|
@@ -59,8 +60,10 @@ def cli() -> None:
|
|
|
59
60
|
@click.option("--json", "as_json", is_flag=True, help="Output as JSON (also enabled automatically when stdout is not a TTY)")
|
|
60
61
|
@click.option("--confirm", "confirm_str", default=None, help="Comma-separated low-confidence suggestion IDs to confirm")
|
|
61
62
|
@click.option("--reject", "reject_str", default=None, help="Comma-separated low-confidence suggestion IDs to reject")
|
|
63
|
+
@click.option("--jurisdiction", "jurisdiction_str", default=None, help="Comma-separated jurisdiction codes (eu, us-regulated, global). Adds the matching jurisdiction-* traits.")
|
|
62
64
|
def classify(description: str | None, traits_str: str | None, as_json: bool,
|
|
63
|
-
confirm_str: str | None, reject_str: str | None
|
|
65
|
+
confirm_str: str | None, reject_str: str | None,
|
|
66
|
+
jurisdiction_str: str | None) -> None:
|
|
64
67
|
"""Classify an AI system and get recommended governance files."""
|
|
65
68
|
from .keywords import apply_confirmations
|
|
66
69
|
if not traits_str and not description:
|
|
@@ -98,7 +101,12 @@ def classify(description: str | None, traits_str: str | None, as_json: bool,
|
|
|
98
101
|
decisions = _prompt_low_confidence(detection)
|
|
99
102
|
|
|
100
103
|
resolved = apply_confirmations(detection, decisions)
|
|
101
|
-
|
|
104
|
+
# v2.1: --jurisdiction flag adds jurisdiction-* traits.
|
|
105
|
+
jurisdiction_traits = (
|
|
106
|
+
[f"jurisdiction-{c}" for c in (s.strip() for s in jurisdiction_str.split(",")) if c]
|
|
107
|
+
if jurisdiction_str else []
|
|
108
|
+
)
|
|
109
|
+
final_traits = sorted(set(resolved["final_traits"]) | set(traits_from_flag) | set(jurisdiction_traits))
|
|
102
110
|
|
|
103
111
|
resolver_report = None
|
|
104
112
|
if description:
|
|
@@ -125,6 +133,16 @@ def classify(description: str | None, traits_str: str | None, as_json: bool,
|
|
|
125
133
|
except ValueError as exc:
|
|
126
134
|
console.print(f"[red]{exc}[/red]")
|
|
127
135
|
sys.exit(1)
|
|
136
|
+
|
|
137
|
+
# v2.1: jurisdiction filter on the area list (parity with bin/aigis.js).
|
|
138
|
+
from .jurisdiction import get_user_jurisdictions, filter_areas_by_jurisdiction
|
|
139
|
+
user_jurisdictions = get_user_jurisdictions(final_traits)
|
|
140
|
+
before_filter = len(result["implement_files"])
|
|
141
|
+
result["implement_files"] = filter_areas_by_jurisdiction(result["implement_files"], user_jurisdictions)
|
|
142
|
+
result["filtered_by_jurisdiction"] = {
|
|
143
|
+
"user_jurisdictions": sorted(user_jurisdictions),
|
|
144
|
+
"dropped_count": before_filter - len(result["implement_files"]),
|
|
145
|
+
}
|
|
128
146
|
if resolver_report:
|
|
129
147
|
result["resolver"] = resolver_report
|
|
130
148
|
|
|
@@ -205,7 +223,8 @@ def get_cmd(files: tuple[str, ...], all_files: bool, lang: str | None,
|
|
|
205
223
|
@click.argument("files", nargs=-1, required=True)
|
|
206
224
|
@click.option("--auto", "auto_path", default=None, help="Run deterministic scanner against the project at this path instead of returning the blank checklist")
|
|
207
225
|
@click.option("--json", "as_json", is_flag=True, help="Output auto-verify results as JSON (only with --auto)")
|
|
208
|
-
|
|
226
|
+
@click.option("--jurisdiction", "jurisdiction_str", default=None, help="Comma-separated jurisdiction codes (eu, us-regulated). Surfaces jurisdiction-specific control citations (e.g. EU AI Act articles) in the report.")
|
|
227
|
+
def verify(files: tuple[str, ...], auto_path: str | None, as_json: bool, jurisdiction_str: str | None) -> None:
|
|
209
228
|
"""Fetch verification checklists, or run deterministic auto-verify with --auto."""
|
|
210
229
|
if not auto_path:
|
|
211
230
|
click.echo(fetch_verify(list(files)))
|
|
@@ -219,10 +238,13 @@ def verify(files: tuple[str, ...], auto_path: str | None, as_json: bool) -> None
|
|
|
219
238
|
console.print(f"[red]Project path does not exist: {proj}[/red]")
|
|
220
239
|
sys.exit(1)
|
|
221
240
|
|
|
241
|
+
# v2.1: parse --jurisdiction once, applied to every area.
|
|
242
|
+
jurisdictions = [s.strip() for s in jurisdiction_str.split(",") if s.strip()] if jurisdiction_str else []
|
|
243
|
+
|
|
222
244
|
results = []
|
|
223
245
|
for area in files:
|
|
224
246
|
try:
|
|
225
|
-
results.append(auto_verify_area(area, str(proj)))
|
|
247
|
+
results.append(auto_verify_area(area, str(proj), jurisdictions=jurisdictions))
|
|
226
248
|
except Exception as e:
|
|
227
249
|
console.print(f"[red]Error verifying '{area}': {e}[/red]")
|
|
228
250
|
sys.exit(1)
|
|
@@ -308,9 +330,12 @@ def _prompt_build_low_confidence(low_conf: list[dict]) -> dict[str, str]:
|
|
|
308
330
|
@click.option("--list", "list_only", is_flag=True, help="Shape A: print area names + traits + pre-built flags only")
|
|
309
331
|
@click.option("--confirm", "confirm_str", default=None, help="Comma-separated low-confidence trigger ids/slugs to confirm")
|
|
310
332
|
@click.option("--reject", "reject_str", default=None, help="Comma-separated low-confidence trigger ids/slugs to reject")
|
|
333
|
+
@click.option("--jurisdiction", "jurisdiction_str", default=None, help="Comma-separated jurisdiction codes (eu, us-regulated). Adds jurisdiction-* traits and gates EU AI Act / regional content accordingly.")
|
|
334
|
+
@click.option("--tight", "tight_flag", is_flag=True, help="Experimental: require ≥2 trait matches for area inclusion (vs default ≥1). Smaller briefs; recall trade-off.")
|
|
311
335
|
@click.option("--json", "as_json", is_flag=True, help="Output JSON (brief + meta) instead of plain markdown")
|
|
312
336
|
def build(description: str, force_full: bool, force_compact: bool, list_only: bool,
|
|
313
|
-
confirm_str: str | None, reject_str: str | None,
|
|
337
|
+
confirm_str: str | None, reject_str: str | None,
|
|
338
|
+
jurisdiction_str: str | None, tight_flag: bool, as_json: bool) -> None:
|
|
314
339
|
"""Compose a consolidated governance brief for a feature description."""
|
|
315
340
|
if force_full and force_compact:
|
|
316
341
|
console.print("[red]Pass --full or --compact, not both.[/red]")
|
|
@@ -319,9 +344,15 @@ def build(description: str, force_full: bool, force_compact: bool, list_only: bo
|
|
|
319
344
|
console.print("[red]--list is independent of --full/--compact; pass only one.[/red]")
|
|
320
345
|
sys.exit(1)
|
|
321
346
|
|
|
347
|
+
# v2.1: parse --jurisdiction once, used by all paths.
|
|
348
|
+
extra_jurisdictions = (
|
|
349
|
+
[s.strip() for s in jurisdiction_str.split(",") if s.strip()]
|
|
350
|
+
if jurisdiction_str else []
|
|
351
|
+
)
|
|
352
|
+
|
|
322
353
|
if list_only:
|
|
323
354
|
try:
|
|
324
|
-
click.echo(build_list(description), nl=False)
|
|
355
|
+
click.echo(build_list(description, extra_jurisdictions=extra_jurisdictions, tight=tight_flag), nl=False)
|
|
325
356
|
except ValueError as e:
|
|
326
357
|
console.print(f"[red]{e}[/red]")
|
|
327
358
|
sys.exit(1)
|
|
@@ -370,7 +401,7 @@ def build(description: str, force_full: bool, force_compact: bool, list_only: bo
|
|
|
370
401
|
mode = "compact"
|
|
371
402
|
|
|
372
403
|
try:
|
|
373
|
-
result = build_brief(description, decisions, mode=mode)
|
|
404
|
+
result = build_brief(description, decisions, extra_jurisdictions=extra_jurisdictions, tight=tight_flag, mode=mode)
|
|
374
405
|
except BriefTooLargeError as e:
|
|
375
406
|
console.print(f"[red]{e}[/red]")
|
|
376
407
|
sys.exit(2)
|
|
@@ -402,6 +433,83 @@ def build(description: str, force_full: bool, force_compact: bool, list_only: bo
|
|
|
402
433
|
click.echo(result["brief"], nl=False)
|
|
403
434
|
|
|
404
435
|
|
|
436
|
+
# ── report (v2.1) ───────────────────────────────────────────────────
|
|
437
|
+
@cli.command()
|
|
438
|
+
@click.option("--areas", "areas_str", default=None, help="Comma-separated area ids to evaluate")
|
|
439
|
+
@click.option("--from-classify", "from_classify", default=None, help="Auto-detect areas: run classify on this description first")
|
|
440
|
+
@click.option("--all", "all_areas", is_flag=True, help="Evaluate every area in content/skills/areas/ (warning: large output)")
|
|
441
|
+
@click.option("--project", "project_dir", default=".", help="Path to project to scan (default: current directory)")
|
|
442
|
+
@click.option("--jurisdiction", "jurisdiction_str", default=None, help="Comma-separated jurisdiction codes (eu, us-regulated)")
|
|
443
|
+
@click.option("--format", "fmt", default="markdown", help="Output format: markdown | json")
|
|
444
|
+
@click.option("--output", "output_path", default=None, help="Write report to file instead of stdout")
|
|
445
|
+
def report(areas_str: str | None, from_classify: str | None, all_areas: bool,
|
|
446
|
+
project_dir: str, jurisdiction_str: str | None, fmt: str,
|
|
447
|
+
output_path: str | None) -> None:
|
|
448
|
+
"""Compile an audit-ready compliance report (verify across multiple areas + cross-framework citations + evidence)."""
|
|
449
|
+
from pathlib import Path
|
|
450
|
+
proj = Path(project_dir).resolve()
|
|
451
|
+
if not proj.exists():
|
|
452
|
+
console.print(f"[red]Project path does not exist: {proj}[/red]")
|
|
453
|
+
sys.exit(1)
|
|
454
|
+
|
|
455
|
+
sources = sum(1 for x in [areas_str, from_classify, all_areas] if x)
|
|
456
|
+
if sources == 0:
|
|
457
|
+
console.print('[red]Provide one of --areas <ids>, --from-classify "<description>", or --all.[/red]')
|
|
458
|
+
sys.exit(1)
|
|
459
|
+
if sources > 1:
|
|
460
|
+
console.print("[red]Pass exactly one of --areas, --from-classify, --all.[/red]")
|
|
461
|
+
sys.exit(1)
|
|
462
|
+
|
|
463
|
+
jurisdictions = [s.strip() for s in jurisdiction_str.split(",") if s.strip()] if jurisdiction_str else []
|
|
464
|
+
from .jurisdiction import filter_areas_by_jurisdiction, get_user_jurisdictions
|
|
465
|
+
|
|
466
|
+
if areas_str:
|
|
467
|
+
areas = [s.strip() for s in areas_str.split(",") if s.strip()]
|
|
468
|
+
elif from_classify:
|
|
469
|
+
from .keywords import detect_traits_from_text, apply_confirmations
|
|
470
|
+
det = detect_traits_from_text(from_classify)
|
|
471
|
+
decisions = {sug["id"]: "no" for sug in det["low_confidence_matches"]}
|
|
472
|
+
resolved = apply_confirmations(det, decisions)
|
|
473
|
+
jurisdiction_traits = [f"jurisdiction-{c}" for c in jurisdictions]
|
|
474
|
+
final_traits = sorted(set(resolved["final_traits"]) | set(jurisdiction_traits))
|
|
475
|
+
if not final_traits:
|
|
476
|
+
console.print("[red]No traits resolved from --from-classify description. Try --areas <list> instead.[/red]")
|
|
477
|
+
sys.exit(1)
|
|
478
|
+
cls = run_classify(final_traits)
|
|
479
|
+
areas = filter_areas_by_jurisdiction(cls["implement_files"], get_user_jurisdictions(final_traits))
|
|
480
|
+
else:
|
|
481
|
+
from pathlib import Path as _Path
|
|
482
|
+
areas_dir = _Path(__file__).resolve().parent / "content" / "skills" / "areas"
|
|
483
|
+
areas = sorted(p.stem for p in areas_dir.iterdir() if p.suffix == ".md")
|
|
484
|
+
areas = filter_areas_by_jurisdiction(areas, get_user_jurisdictions([f"jurisdiction-{c}" for c in jurisdictions]))
|
|
485
|
+
|
|
486
|
+
if not areas:
|
|
487
|
+
console.print("[red]No areas to evaluate after jurisdiction filtering.[/red]")
|
|
488
|
+
sys.exit(1)
|
|
489
|
+
|
|
490
|
+
try:
|
|
491
|
+
rep = build_report(project_dir=str(proj), areas=areas, jurisdictions=jurisdictions)
|
|
492
|
+
except Exception as e:
|
|
493
|
+
console.print(f"[red]{e}[/red]")
|
|
494
|
+
sys.exit(1)
|
|
495
|
+
|
|
496
|
+
fmt_lower = (fmt or "markdown").lower()
|
|
497
|
+
if fmt_lower == "json":
|
|
498
|
+
output = format_report_json(rep)
|
|
499
|
+
elif fmt_lower in ("markdown", "md"):
|
|
500
|
+
output = format_report_markdown(rep)
|
|
501
|
+
else:
|
|
502
|
+
console.print(f"[red]Unknown --format '{fmt}'. Use markdown or json.[/red]")
|
|
503
|
+
sys.exit(1)
|
|
504
|
+
|
|
505
|
+
if output_path:
|
|
506
|
+
from pathlib import Path as _Path
|
|
507
|
+
_Path(output_path).write_text(output + ("" if output.endswith("\n") else "\n"))
|
|
508
|
+
console.print(f"[green]Report written to {output_path} ({len(output)} chars, {len(areas)} area{'' if len(areas)==1 else 's'} evaluated)[/green]")
|
|
509
|
+
else:
|
|
510
|
+
click.echo(output, nl=not output.endswith("\n"))
|
|
511
|
+
|
|
512
|
+
|
|
405
513
|
# ── infra ───────────────────────────────────────────────────────────
|
|
406
514
|
@cli.command()
|
|
407
515
|
@click.argument("area", required=False, default=None)
|
|
@@ -595,9 +703,11 @@ def annotate(file_id: str | None, note: str | None,
|
|
|
595
703
|
@cli.command("init")
|
|
596
704
|
@click.argument("ide")
|
|
597
705
|
@click.option("--refresh", is_flag=True, help="Overwrite existing aigis content (destructive — use after Aigis updates or to fix a stale resolver block checksum)")
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
706
|
+
@click.option("--ci", default=None, help="Install CI workflow file. Currently supports: github (drops .github/workflows/aigis.yml).")
|
|
707
|
+
@click.option("--hook", is_flag=True, help="Install .git/hooks/pre-commit that runs aigis verify on areas declared in .aigisrc.json.")
|
|
708
|
+
def init_cmd(ide: str, refresh: bool, ci: str | None, hook: bool) -> None:
|
|
709
|
+
"""Set up aigis for your IDE (writes core skill + resolver block). Optional --ci and --hook activation surfaces."""
|
|
710
|
+
run_init(ide, refresh=refresh, ci=ci, hook=hook)
|
|
601
711
|
|
|
602
712
|
|
|
603
713
|
# ── traits ──────────────────────────────────────────────────────────
|