@aigis-ai/cli 1.0.3 → 2.0.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/CONTRIBUTING.md +53 -0
- package/SKILL.md +20 -55
- package/bin/aigis.js +446 -59
- package/cli-python/LICENSE +21 -0
- package/cli-python/README.md +32 -0
- package/cli-python/aigis_cli/SKILL.md +70 -0
- package/cli-python/aigis_cli/__init__.py +3 -0
- package/cli-python/aigis_cli/__pycache__/__init__.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/annotate.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/build.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/checksum.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/classify.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/cli.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/fetch.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/init_ide.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/keywords.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/search.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/annotate.py +45 -0
- package/cli-python/aigis_cli/auto_verify.py +518 -0
- package/cli-python/aigis_cli/build.py +470 -0
- package/cli-python/aigis_cli/checksum.py +22 -0
- package/cli-python/aigis_cli/classify.py +192 -0
- package/cli-python/aigis_cli/cli.py +618 -0
- package/cli-python/aigis_cli/content/index/audit-scan.md +217 -0
- package/cli-python/aigis_cli/content/index/auto-verify-rules.json +439 -0
- package/cli-python/aigis_cli/content/index/context-rules.json +90 -0
- package/cli-python/aigis_cli/content/index/frameworks.md +82 -0
- package/cli-python/aigis_cli/content/index/guardrails.json +23 -0
- package/cli-python/aigis_cli/content/index/taxonomy.md +81 -0
- package/cli-python/aigis_cli/content/resolvers/triggers.json +229 -0
- package/{content/implement → cli-python/aigis_cli/content/skills/areas}/audit-logging.md +5 -0
- package/cli-python/aigis_cli/content/skills/areas/fallback-patterns.md +200 -0
- package/cli-python/aigis_cli/content/skills/areas/input-validation.md +380 -0
- package/cli-python/aigis_cli/content/skills/areas/pii-handling.md +189 -0
- package/cli-python/aigis_cli/content/skills/areas/rate-limiting.md +246 -0
- package/cli-python/aigis_cli/content/skills/core.md +62 -0
- package/cli-python/aigis_cli/content/skills/infrastructure/logging.md +202 -0
- package/cli-python/aigis_cli/content/skills/infrastructure/rate-limiting.md +169 -0
- package/cli-python/aigis_cli/content/skills/infrastructure/secrets.md +167 -0
- package/cli-python/aigis_cli/content/skills/workflows/fastapi-llm.md +86 -0
- package/cli-python/aigis_cli/content/templates/ai-impact-assessment.md +54 -0
- package/cli-python/aigis_cli/content/templates/intended-purpose-doc.md +39 -0
- package/cli-python/aigis_cli/content/templates/risk-characterization.md +34 -0
- package/cli-python/aigis_cli/content/templates/third-party-assessment.md +41 -0
- package/cli-python/aigis_cli/content/verify/checklist-audit-logging.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-bias-monitoring.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-confidence-scoring.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-data-integrity.md +12 -0
- package/cli-python/aigis_cli/content/verify/checklist-explainability.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-fallback-patterns.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-human-oversight.md +14 -0
- package/cli-python/aigis_cli/content/verify/checklist-input-validation.md +16 -0
- package/cli-python/aigis_cli/content/verify/checklist-monitoring.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-output-sanitization.md +14 -0
- package/cli-python/aigis_cli/content/verify/checklist-pii-handling.md +14 -0
- package/cli-python/aigis_cli/content/verify/checklist-prompt-security.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-rag-security.md +12 -0
- package/cli-python/aigis_cli/content/verify/checklist-rate-limiting.md +13 -0
- package/cli-python/aigis_cli/content/verify/checklist-supply-chain.md +13 -0
- package/cli-python/aigis_cli/fetch.py +232 -0
- package/cli-python/aigis_cli/init_ide.py +159 -0
- package/cli-python/aigis_cli/keywords.py +73 -0
- package/cli-python/aigis_cli/search.py +69 -0
- package/cli-python/aigis_cli.egg-info/PKG-INFO +59 -0
- package/cli-python/aigis_cli.egg-info/SOURCES.txt +56 -0
- package/cli-python/aigis_cli.egg-info/dependency_links.txt +1 -0
- package/cli-python/aigis_cli.egg-info/entry_points.txt +2 -0
- package/cli-python/aigis_cli.egg-info/requires.txt +6 -0
- package/cli-python/aigis_cli.egg-info/top_level.txt +1 -0
- package/cli-python/dist/aigis_cli-1.0.3-py3-none-any.whl +0 -0
- package/cli-python/dist/aigis_cli-1.0.3.tar.gz +0 -0
- package/cli-python/pyproject.toml +49 -0
- package/content/index/audit-scan.md +21 -207
- package/content/index/auto-verify-rules.json +439 -0
- package/content/index/context-rules.json +90 -0
- package/content/resolvers/triggers.json +229 -0
- package/content/skills/areas/audit-logging.md +176 -0
- package/content/skills/areas/bias-monitoring.md +172 -0
- package/content/skills/areas/confidence-scoring.md +180 -0
- package/content/skills/areas/data-integrity.md +257 -0
- package/content/skills/areas/explainability.md +174 -0
- package/content/skills/areas/fallback-patterns.md +200 -0
- package/content/skills/areas/human-oversight.md +220 -0
- package/content/skills/areas/input-validation.md +380 -0
- package/content/skills/areas/monitoring.md +207 -0
- package/content/skills/areas/output-sanitization.md +183 -0
- package/content/skills/areas/pii-handling.md +189 -0
- package/content/skills/areas/prompt-security.md +153 -0
- package/content/skills/areas/rag-security.md +230 -0
- package/content/skills/areas/rate-limiting.md +246 -0
- package/content/skills/areas/supply-chain.md +193 -0
- package/content/skills/core.md +62 -0
- package/content/skills/infrastructure/logging.md +202 -0
- package/content/skills/infrastructure/rate-limiting.md +169 -0
- package/content/skills/infrastructure/secrets.md +167 -0
- package/content/skills/workflows/fastapi-llm.md +86 -0
- package/docs/resolvers.md +114 -0
- package/lib/auto-verify.js +378 -0
- package/lib/build.js +629 -0
- package/lib/checksum.js +39 -0
- package/lib/fetch.js +164 -9
- package/lib/init.js +141 -93
- package/lib/keywords.js +92 -130
- package/lib/special-recognizers.js +370 -0
- package/package.json +1 -1
- package/scripts/baseline-cursorrules.snapshot.txt +30 -0
- package/scripts/bootstrap-step-6-bench.js +85 -0
- package/scripts/check-content-sync.js +91 -0
- package/scripts/triggers.schema.json +50 -0
- package/scripts/validate-triggers.js +176 -0
- package/content/implement/fallback-patterns.md +0 -190
- package/content/implement/input-validation.md +0 -212
- package/content/implement/pii-handling.md +0 -207
- package/content/implement/rate-limiting.md +0 -217
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/bias-monitoring.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/confidence-scoring.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/data-integrity.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/explainability.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/human-oversight.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/monitoring.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/output-sanitization.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/prompt-security.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/rag-security.md +0 -0
- /package/{content/implement → cli-python/aigis_cli/content/skills/areas}/supply-chain.md +0 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .classify import classify as run_classify
|
|
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
|
+
from .build import build_brief, build_list, BriefTooLargeError, normalize_description, assign_unique_slugs
|
|
13
|
+
from .keywords import detect_traits_from_text
|
|
14
|
+
from .search import list_all, search as run_search
|
|
15
|
+
from .annotate import annotate as add_annotation, clear_annotation, list_annotations
|
|
16
|
+
from .init_ide import init as run_init
|
|
17
|
+
|
|
18
|
+
console = Console(highlight=False)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _prompt_low_confidence(detection: dict) -> dict[str, str]:
|
|
22
|
+
"""Interactive prompt for low-confidence resolver suggestions."""
|
|
23
|
+
decisions: dict[str, str] = {}
|
|
24
|
+
console.print("\n[bold]═══ AIGIS RESOLVER ═══[/bold]")
|
|
25
|
+
if detection["high_confidence_matches"]:
|
|
26
|
+
console.print("\n[bold]High-confidence triggers (auto-applied):[/bold]")
|
|
27
|
+
for m in detection["high_confidence_matches"]:
|
|
28
|
+
console.print(f" [green]✓[/green] \"{m['phrase']}\" → {', '.join(m['traits'])}")
|
|
29
|
+
console.print(f"\n[bold]Low-confidence triggers (need your input — {len(detection['low_confidence_matches'])}):[/bold]")
|
|
30
|
+
for sug in detection["low_confidence_matches"]:
|
|
31
|
+
console.print(f"\n [bold][{sug['id']}] \"{sug['phrase']}\"[/bold]")
|
|
32
|
+
console.print(f" [dim]Suggested traits: {', '.join(sug['traits'])}[/dim]")
|
|
33
|
+
console.print(f" {sug['confirmation_prompt']}")
|
|
34
|
+
ans = input(" (y)es / (n)o / (u)nsure [n]: ").strip().lower()
|
|
35
|
+
if ans in ("", "n", "no"):
|
|
36
|
+
decision = "no"
|
|
37
|
+
elif ans in ("y", "yes"):
|
|
38
|
+
decision = "yes"
|
|
39
|
+
elif ans in ("u", "unsure"):
|
|
40
|
+
decision = "unsure"
|
|
41
|
+
else:
|
|
42
|
+
console.print(f" [dim](unrecognized — defaulting to 'no')[/dim]")
|
|
43
|
+
decision = "no"
|
|
44
|
+
decisions[sug["id"]] = decision
|
|
45
|
+
console.print("")
|
|
46
|
+
return decisions
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@click.group()
|
|
50
|
+
@click.version_option(__version__, prog_name="aigis")
|
|
51
|
+
def cli() -> None:
|
|
52
|
+
"""AI governance guardrails for coding agents."""
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ── classify ────────────────────────────────────────────────────────
|
|
56
|
+
@cli.command()
|
|
57
|
+
@click.argument("description", required=False, default=None)
|
|
58
|
+
@click.option("--traits", "traits_str", default=None, help="Comma-separated trait IDs (additive: combines with --description triggers if both passed)")
|
|
59
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON (also enabled automatically when stdout is not a TTY)")
|
|
60
|
+
@click.option("--confirm", "confirm_str", default=None, help="Comma-separated low-confidence suggestion IDs to confirm")
|
|
61
|
+
@click.option("--reject", "reject_str", default=None, help="Comma-separated low-confidence suggestion IDs to reject")
|
|
62
|
+
def classify(description: str | None, traits_str: str | None, as_json: bool,
|
|
63
|
+
confirm_str: str | None, reject_str: str | None) -> None:
|
|
64
|
+
"""Classify an AI system and get recommended governance files."""
|
|
65
|
+
from .keywords import apply_confirmations
|
|
66
|
+
if not traits_str and not description:
|
|
67
|
+
console.print("[red]Provide --traits, a quoted description, or both.[/red]")
|
|
68
|
+
console.print("[dim]Example: aigis classify --traits uses-llm,processes-pii[/dim]")
|
|
69
|
+
console.print('[dim]Example: aigis classify "customer chatbot with RAG"[/dim]')
|
|
70
|
+
console.print('[dim]Example: aigis classify "chatbot" --traits handles-financial (additive)\n[/dim]')
|
|
71
|
+
sys.exit(1)
|
|
72
|
+
|
|
73
|
+
json_mode = bool(as_json) or not sys.stdout.isatty()
|
|
74
|
+
traits_from_flag = [t.strip() for t in traits_str.split(",") if t.strip()] if traits_str else []
|
|
75
|
+
confirm_ids = set(s.strip() for s in confirm_str.split(",") if s.strip()) if confirm_str else None
|
|
76
|
+
reject_ids = set(s.strip() for s in reject_str.split(",") if s.strip()) if reject_str else None
|
|
77
|
+
|
|
78
|
+
detection = {"high_confidence_matches": [], "low_confidence_matches": [], "traits_auto_applied": []}
|
|
79
|
+
if description:
|
|
80
|
+
detection = detect_traits_from_text(description)
|
|
81
|
+
|
|
82
|
+
decisions: dict[str, str] = {}
|
|
83
|
+
used_flags = bool(confirm_ids or reject_ids)
|
|
84
|
+
|
|
85
|
+
if description and detection["low_confidence_matches"]:
|
|
86
|
+
if used_flags:
|
|
87
|
+
for sug in detection["low_confidence_matches"]:
|
|
88
|
+
if confirm_ids and sug["id"] in confirm_ids:
|
|
89
|
+
decisions[sug["id"]] = "yes"
|
|
90
|
+
elif reject_ids and sug["id"] in reject_ids:
|
|
91
|
+
decisions[sug["id"]] = "no"
|
|
92
|
+
else:
|
|
93
|
+
decisions[sug["id"]] = "no"
|
|
94
|
+
elif json_mode:
|
|
95
|
+
for sug in detection["low_confidence_matches"]:
|
|
96
|
+
decisions[sug["id"]] = "no"
|
|
97
|
+
else:
|
|
98
|
+
decisions = _prompt_low_confidence(detection)
|
|
99
|
+
|
|
100
|
+
resolved = apply_confirmations(detection, decisions)
|
|
101
|
+
final_traits = sorted(set(resolved["final_traits"]) | set(traits_from_flag))
|
|
102
|
+
|
|
103
|
+
resolver_report = None
|
|
104
|
+
if description:
|
|
105
|
+
resolver_report = {
|
|
106
|
+
"input": description,
|
|
107
|
+
"high_confidence_matches": detection["high_confidence_matches"],
|
|
108
|
+
"low_confidence_suggestions": resolved["low_confidence_decisions"],
|
|
109
|
+
"traits_from_description": resolved["final_traits"],
|
|
110
|
+
"traits_from_flag": traits_from_flag,
|
|
111
|
+
"final_traits": final_traits,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if not final_traits:
|
|
115
|
+
msg = "No traits resolved from description or --traits flag."
|
|
116
|
+
if json_mode:
|
|
117
|
+
click.echo(json.dumps({"error": msg, "resolver": resolver_report}, indent=2))
|
|
118
|
+
else:
|
|
119
|
+
console.print(f"[red]{msg}[/red]")
|
|
120
|
+
console.print('[dim]Run "aigis traits" to see available traits.\n[/dim]')
|
|
121
|
+
sys.exit(1)
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
result = run_classify(final_traits)
|
|
125
|
+
except ValueError as exc:
|
|
126
|
+
console.print(f"[red]{exc}[/red]")
|
|
127
|
+
sys.exit(1)
|
|
128
|
+
if resolver_report:
|
|
129
|
+
result["resolver"] = resolver_report
|
|
130
|
+
|
|
131
|
+
if json_mode:
|
|
132
|
+
click.echo(json.dumps(result, indent=2))
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
if resolver_report:
|
|
136
|
+
console.print("[bold]═══ AIGIS RESOLVER ═══[/bold]")
|
|
137
|
+
if detection["high_confidence_matches"]:
|
|
138
|
+
console.print("\n[bold]High-confidence triggers (auto-applied):[/bold]")
|
|
139
|
+
for m in detection["high_confidence_matches"]:
|
|
140
|
+
console.print(f" [green]✓[/green] \"{m['phrase']}\" → {', '.join(m['traits'])}")
|
|
141
|
+
if resolved["low_confidence_decisions"]:
|
|
142
|
+
console.print("\n[bold]Low-confidence decisions:[/bold]")
|
|
143
|
+
for d in resolved["low_confidence_decisions"]:
|
|
144
|
+
icon = "[green]✓[/green]" if d["user_decision"] == "yes" else ("[yellow]?[/yellow]" if d["user_decision"] == "unsure" else "[dim]✗[/dim]")
|
|
145
|
+
console.print(f" {icon} [{d['id']}] \"{d['phrase']}\" → {', '.join(d['traits'])} (decision: {d['user_decision']})")
|
|
146
|
+
if traits_from_flag:
|
|
147
|
+
console.print(f"\n[bold]Added via --traits flag:[/bold] {', '.join(traits_from_flag)}")
|
|
148
|
+
console.print(f"\n[bold]Final trait set ({len(final_traits)}):[/bold] {', '.join(final_traits)}\n")
|
|
149
|
+
console.print("[dim]═══════════════════════[/dim]\n")
|
|
150
|
+
|
|
151
|
+
tier = result["risk_tier"]
|
|
152
|
+
tier_color = "red" if tier == "HIGH" else "yellow" if tier == "MEDIUM" else "green"
|
|
153
|
+
console.print(f"[bold]Risk tier:[/bold] [bold {tier_color}]{tier}[/bold {tier_color}]")
|
|
154
|
+
console.print(f"[bold]Reason:[/bold] {result['reason']}\n")
|
|
155
|
+
|
|
156
|
+
for w in result["warnings"]:
|
|
157
|
+
console.print(f"[yellow]⚠ {w}[/yellow]")
|
|
158
|
+
if result["warnings"]:
|
|
159
|
+
console.print()
|
|
160
|
+
|
|
161
|
+
console.print(f"[bold]Implement files ({len(result['implement_files'])}):[/bold]")
|
|
162
|
+
for f in result["implement_files"]:
|
|
163
|
+
console.print(f"[green] aigis get {f}[/green]")
|
|
164
|
+
|
|
165
|
+
if result["templates"]:
|
|
166
|
+
console.print(f"\n[bold]Templates ({len(result['templates'])}):[/bold]")
|
|
167
|
+
for t in result["templates"]:
|
|
168
|
+
console.print(f"[yellow] aigis template {t}[/yellow]")
|
|
169
|
+
|
|
170
|
+
if result["guardrails_fired"]:
|
|
171
|
+
console.print("\n[bold]Guardrails fired:[/bold]")
|
|
172
|
+
for g in result["guardrails_fired"]:
|
|
173
|
+
console.print(f"[yellow] {g['id']}: {g['action']} — {g['rationale']}[/yellow]")
|
|
174
|
+
|
|
175
|
+
console.print("\n[bold]Verify after implementation:[/bold]")
|
|
176
|
+
for f in result["implement_files"]:
|
|
177
|
+
console.print(f"[green] aigis verify {f}[/green]")
|
|
178
|
+
|
|
179
|
+
c = result["controls"]
|
|
180
|
+
console.print(f"\n[dim]Controls: {len(c['owasp'])} OWASP, {len(c['nist'])} NIST, {len(c['iso'])} ISO[/dim]")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
# ── get ─────────────────────────────────────────────────────────────
|
|
184
|
+
@cli.command("get")
|
|
185
|
+
@click.argument("files", nargs=-1)
|
|
186
|
+
@click.option("--all", "all_files", is_flag=True, help="Fetch all implement files")
|
|
187
|
+
@click.option("--lang", default=None, help="Filter code blocks to one language. Accepts py, python, js, javascript, ts, typescript, go, rust.")
|
|
188
|
+
@click.option("--context", default=None, help="Filter patterns by system context. Accepts web, agentic, rag, batch.")
|
|
189
|
+
@click.option("--no-frontmatter", "no_frontmatter", is_flag=True, help="Strip YAML frontmatter")
|
|
190
|
+
def get_cmd(files: tuple[str, ...], all_files: bool, lang: str | None,
|
|
191
|
+
context: str | None, no_frontmatter: bool) -> None:
|
|
192
|
+
"""Fetch implementation pattern files."""
|
|
193
|
+
try:
|
|
194
|
+
content = fetch_get(list(files) or None, all_files=all_files,
|
|
195
|
+
strip_fm=not no_frontmatter, lang=lang,
|
|
196
|
+
context=context)
|
|
197
|
+
click.echo(content)
|
|
198
|
+
except ValueError as e:
|
|
199
|
+
console.print(f"[red]{e}[/red]")
|
|
200
|
+
sys.exit(1)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# ── verify ──────────────────────────────────────────────────────────
|
|
204
|
+
@cli.command()
|
|
205
|
+
@click.argument("files", nargs=-1, required=True)
|
|
206
|
+
@click.option("--auto", "auto_path", default=None, help="Run deterministic scanner against the project at this path instead of returning the blank checklist")
|
|
207
|
+
@click.option("--json", "as_json", is_flag=True, help="Output auto-verify results as JSON (only with --auto)")
|
|
208
|
+
def verify(files: tuple[str, ...], auto_path: str | None, as_json: bool) -> None:
|
|
209
|
+
"""Fetch verification checklists, or run deterministic auto-verify with --auto."""
|
|
210
|
+
if not auto_path:
|
|
211
|
+
click.echo(fetch_verify(list(files)))
|
|
212
|
+
return
|
|
213
|
+
|
|
214
|
+
from pathlib import Path
|
|
215
|
+
from .auto_verify import auto_verify_area, format_text_report
|
|
216
|
+
|
|
217
|
+
proj = Path(auto_path).resolve()
|
|
218
|
+
if not proj.exists():
|
|
219
|
+
console.print(f"[red]Project path does not exist: {proj}[/red]")
|
|
220
|
+
sys.exit(1)
|
|
221
|
+
|
|
222
|
+
results = []
|
|
223
|
+
for area in files:
|
|
224
|
+
try:
|
|
225
|
+
results.append(auto_verify_area(area, str(proj)))
|
|
226
|
+
except Exception as e:
|
|
227
|
+
console.print(f"[red]Error verifying '{area}': {e}[/red]")
|
|
228
|
+
sys.exit(1)
|
|
229
|
+
|
|
230
|
+
if as_json:
|
|
231
|
+
click.echo(json.dumps(results[0] if len(results) == 1 else results, indent=2))
|
|
232
|
+
return
|
|
233
|
+
|
|
234
|
+
for i, r in enumerate(results):
|
|
235
|
+
click.echo(format_text_report(r))
|
|
236
|
+
if len(results) > 1 and i < len(results) - 1:
|
|
237
|
+
click.echo("\n" + "─" * 60 + "\n")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# ── template ────────────────────────────────────────────────────────
|
|
241
|
+
@cli.command()
|
|
242
|
+
@click.argument("templates", nargs=-1, required=True)
|
|
243
|
+
def template(templates: tuple[str, ...]) -> None:
|
|
244
|
+
"""Fetch compliance documentation templates."""
|
|
245
|
+
click.echo(get_template(list(templates)))
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# ── workflow ────────────────────────────────────────────────────────
|
|
249
|
+
@cli.command()
|
|
250
|
+
@click.argument("type_", metavar="TYPE", required=False, default=None)
|
|
251
|
+
@click.option("--list", "list_workflows_flag", is_flag=True, help="List available workflows")
|
|
252
|
+
def workflow(type_: str | None, list_workflows_flag: bool) -> None:
|
|
253
|
+
"""Fetch the canonical file layout + wiring contracts for a project type."""
|
|
254
|
+
if list_workflows_flag:
|
|
255
|
+
items = list_workflows()
|
|
256
|
+
if not items:
|
|
257
|
+
console.print("[dim]No workflow skills found.[/dim]")
|
|
258
|
+
return
|
|
259
|
+
console.print("[bold]Available workflows:[/bold]\n")
|
|
260
|
+
for w in items:
|
|
261
|
+
console.print(f" {w}")
|
|
262
|
+
console.print("[dim]\nFetch one with: aigis workflow <type>[/dim]")
|
|
263
|
+
return
|
|
264
|
+
if not type_:
|
|
265
|
+
console.print("[red]Provide a workflow type or pass --list.[/red]")
|
|
266
|
+
console.print("[dim] aigis workflow fastapi-llm[/dim]")
|
|
267
|
+
console.print("[dim] aigis workflow --list\n[/dim]")
|
|
268
|
+
sys.exit(1)
|
|
269
|
+
try:
|
|
270
|
+
click.echo(get_workflow(type_))
|
|
271
|
+
except Exception as exc:
|
|
272
|
+
console.print(f"[red]{exc}[/red]")
|
|
273
|
+
items = list_workflows()
|
|
274
|
+
if items:
|
|
275
|
+
console.print(f"[dim]\nAvailable workflows: {', '.join(items)}[/dim]")
|
|
276
|
+
sys.exit(1)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
# ── build ───────────────────────────────────────────────────────────
|
|
280
|
+
def _prompt_build_low_confidence(low_conf: list[dict]) -> dict[str, str]:
|
|
281
|
+
"""Interactive prompt for low-conf triggers in `aigis build`. Default = unsure."""
|
|
282
|
+
decisions: dict[str, str] = {}
|
|
283
|
+
console.print("\n[bold]═══ AIGIS BUILD — low-confidence triggers ═══[/bold]")
|
|
284
|
+
console.print('[dim]Default for each is "unsure" → trait is included in the brief with a ⚠ flag for the agent to surface to you.\n[/dim]')
|
|
285
|
+
for m in low_conf:
|
|
286
|
+
console.print(f" [bold][{m['slug']}] \"{m['phrase']}\"[/bold]")
|
|
287
|
+
console.print(f" [dim]Suggested traits: {', '.join(m['traits'])}[/dim]")
|
|
288
|
+
console.print(f" {m['confirmation_prompt']}")
|
|
289
|
+
ans = input(" (y)es / (n)o / (u)nsure [u]: ").strip().lower()
|
|
290
|
+
if ans in ("", "u", "unsure"):
|
|
291
|
+
decision = "unsure"
|
|
292
|
+
elif ans in ("y", "yes"):
|
|
293
|
+
decision = "yes"
|
|
294
|
+
elif ans in ("n", "no"):
|
|
295
|
+
decision = "no"
|
|
296
|
+
else:
|
|
297
|
+
console.print(" [dim](unrecognized — defaulting to 'unsure')[/dim]")
|
|
298
|
+
decision = "unsure"
|
|
299
|
+
decisions[m["slug"]] = decision
|
|
300
|
+
console.print("")
|
|
301
|
+
return decisions
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
@cli.command()
|
|
305
|
+
@click.argument("description", required=True)
|
|
306
|
+
@click.option("--full", "force_full", is_flag=True, help="Force full inlined brief (hard cap at 200k chars)")
|
|
307
|
+
@click.option("--compact", "force_compact", is_flag=True, help="Force compact pointer-only brief (no auto-fallback)")
|
|
308
|
+
@click.option("--list", "list_only", is_flag=True, help="Shape A: print area names + traits + pre-built flags only")
|
|
309
|
+
@click.option("--confirm", "confirm_str", default=None, help="Comma-separated low-confidence trigger ids/slugs to confirm")
|
|
310
|
+
@click.option("--reject", "reject_str", default=None, help="Comma-separated low-confidence trigger ids/slugs to reject")
|
|
311
|
+
@click.option("--json", "as_json", is_flag=True, help="Output JSON (brief + meta) instead of plain markdown")
|
|
312
|
+
def build(description: str, force_full: bool, force_compact: bool, list_only: bool,
|
|
313
|
+
confirm_str: str | None, reject_str: str | None, as_json: bool) -> None:
|
|
314
|
+
"""Compose a consolidated governance brief for a feature description."""
|
|
315
|
+
if force_full and force_compact:
|
|
316
|
+
console.print("[red]Pass --full or --compact, not both.[/red]")
|
|
317
|
+
sys.exit(1)
|
|
318
|
+
if list_only and (force_full or force_compact):
|
|
319
|
+
console.print("[red]--list is independent of --full/--compact; pass only one.[/red]")
|
|
320
|
+
sys.exit(1)
|
|
321
|
+
|
|
322
|
+
if list_only:
|
|
323
|
+
try:
|
|
324
|
+
click.echo(build_list(description), nl=False)
|
|
325
|
+
except ValueError as e:
|
|
326
|
+
console.print(f"[red]{e}[/red]")
|
|
327
|
+
sys.exit(1)
|
|
328
|
+
return
|
|
329
|
+
|
|
330
|
+
confirm_ids = set(s.strip() for s in confirm_str.split(",") if s.strip()) if confirm_str else None
|
|
331
|
+
reject_ids = set(s.strip() for s in reject_str.split(",") if s.strip()) if reject_str else None
|
|
332
|
+
if confirm_ids and reject_ids:
|
|
333
|
+
overlap = confirm_ids & reject_ids
|
|
334
|
+
if overlap:
|
|
335
|
+
console.print(f"[red]Trigger {', '.join(overlap)} appears in both --confirm and --reject. Pick one.[/red]")
|
|
336
|
+
sys.exit(1)
|
|
337
|
+
|
|
338
|
+
# Need slugs to know what to prompt for / what flags refer to.
|
|
339
|
+
from .keywords import detect_traits_from_text
|
|
340
|
+
normalized = normalize_description(description)
|
|
341
|
+
if not normalized:
|
|
342
|
+
console.print('[red]Provide a description in quotes. Example: aigis build "customer chatbot with RAG"[/red]')
|
|
343
|
+
sys.exit(1)
|
|
344
|
+
det = detect_traits_from_text(normalized)
|
|
345
|
+
low_conf = assign_unique_slugs(det["low_confidence_matches"])
|
|
346
|
+
|
|
347
|
+
decisions: dict[str, str] = {}
|
|
348
|
+
is_tty = sys.stdout.isatty() and sys.stdin.isatty()
|
|
349
|
+
used_flags = bool(confirm_ids or reject_ids)
|
|
350
|
+
|
|
351
|
+
if low_conf:
|
|
352
|
+
if used_flags:
|
|
353
|
+
for m in low_conf:
|
|
354
|
+
if confirm_ids and (m["slug"] in confirm_ids or m["id"] in confirm_ids):
|
|
355
|
+
decisions[m["slug"]] = "yes"
|
|
356
|
+
elif reject_ids and (m["slug"] in reject_ids or m["id"] in reject_ids):
|
|
357
|
+
decisions[m["slug"]] = "no"
|
|
358
|
+
else:
|
|
359
|
+
decisions[m["slug"]] = "unsure"
|
|
360
|
+
elif is_tty:
|
|
361
|
+
decisions = _prompt_build_low_confidence(low_conf)
|
|
362
|
+
else:
|
|
363
|
+
for m in low_conf:
|
|
364
|
+
decisions[m["slug"]] = "unsure"
|
|
365
|
+
|
|
366
|
+
mode = "auto"
|
|
367
|
+
if force_full:
|
|
368
|
+
mode = "full"
|
|
369
|
+
elif force_compact:
|
|
370
|
+
mode = "compact"
|
|
371
|
+
|
|
372
|
+
try:
|
|
373
|
+
result = build_brief(description, decisions, mode=mode)
|
|
374
|
+
except BriefTooLargeError as e:
|
|
375
|
+
console.print(f"[red]{e}[/red]")
|
|
376
|
+
sys.exit(2)
|
|
377
|
+
except ValueError as e:
|
|
378
|
+
console.print(f"[red]{e}[/red]")
|
|
379
|
+
sys.exit(1)
|
|
380
|
+
|
|
381
|
+
if result.get("auto_fallback"):
|
|
382
|
+
full_cap = result["auto_fallback_full_cap"]
|
|
383
|
+
full_chars = result["auto_fallback_full_chars"]
|
|
384
|
+
normalized = result["meta"]["normalized_description"]
|
|
385
|
+
console.print(
|
|
386
|
+
f"[yellow]Brief exceeded {full_cap:,} chars with full content inlined "
|
|
387
|
+
f"({full_chars:,} chars). Falling back to compact mode (pointers only). "
|
|
388
|
+
f'Run `aigis build "{normalized}" --full` to force full content — '
|
|
389
|
+
f"you may need to split the build into per-domain runs if the brief is still too large.[/yellow]",
|
|
390
|
+
highlight=False,
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
if as_json:
|
|
394
|
+
click.echo(json.dumps({
|
|
395
|
+
"brief": result["brief"],
|
|
396
|
+
"meta": result["meta"],
|
|
397
|
+
"mode": result["mode"],
|
|
398
|
+
"auto_fallback": result.get("auto_fallback", False),
|
|
399
|
+
}, indent=2))
|
|
400
|
+
return
|
|
401
|
+
|
|
402
|
+
click.echo(result["brief"], nl=False)
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
# ── infra ───────────────────────────────────────────────────────────
|
|
406
|
+
@cli.command()
|
|
407
|
+
@click.argument("area", required=False, default=None)
|
|
408
|
+
@click.option("--list", "list_infras_flag", is_flag=True, help="List available infrastructure areas")
|
|
409
|
+
def infra(area: str | None, list_infras_flag: bool) -> None:
|
|
410
|
+
"""Fetch infrastructure setup content (rate-limiting, secrets, logging)."""
|
|
411
|
+
if list_infras_flag:
|
|
412
|
+
items = list_infras()
|
|
413
|
+
if not items:
|
|
414
|
+
console.print("[dim]No infrastructure areas found.[/dim]")
|
|
415
|
+
return
|
|
416
|
+
console.print("[bold]Available infrastructure areas:[/bold]\n")
|
|
417
|
+
for i in items:
|
|
418
|
+
console.print(f" {i}")
|
|
419
|
+
console.print("[dim]\nFetch one with: aigis infra <area>[/dim]")
|
|
420
|
+
return
|
|
421
|
+
if not area:
|
|
422
|
+
console.print("[red]Provide an infrastructure area or pass --list.[/red]")
|
|
423
|
+
console.print("[dim] aigis infra rate-limiting[/dim]")
|
|
424
|
+
console.print("[dim] aigis infra --list\n[/dim]")
|
|
425
|
+
sys.exit(1)
|
|
426
|
+
try:
|
|
427
|
+
click.echo(get_infra(area))
|
|
428
|
+
except (ValueError, FileNotFoundError) as exc:
|
|
429
|
+
console.print(f"[red]{exc}[/red]")
|
|
430
|
+
items = list_infras()
|
|
431
|
+
if items:
|
|
432
|
+
console.print(f"[dim]\nAvailable areas: {', '.join(items)}[/dim]")
|
|
433
|
+
sys.exit(1)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
# ── audit ───────────────────────────────────────────────────────────
|
|
437
|
+
@cli.command()
|
|
438
|
+
@click.option("--scan", is_flag=True, help="Get structured discovery prompt (Phases 1-3: inventory, trait detection, classify handoff)")
|
|
439
|
+
@click.option("--traits", "traits_str", default=None, help="Run scoped audit: classify + checklists only for recommended areas. Prints deterministic denominator.")
|
|
440
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON")
|
|
441
|
+
def audit(scan: bool, traits_str: str | None, as_json: bool) -> None:
|
|
442
|
+
"""Audit an existing codebase for governance gaps."""
|
|
443
|
+
if scan:
|
|
444
|
+
click.echo(get_audit_scan())
|
|
445
|
+
return
|
|
446
|
+
|
|
447
|
+
if traits_str:
|
|
448
|
+
import re
|
|
449
|
+
traits = [t.strip() for t in traits_str.split(",")]
|
|
450
|
+
classification = run_classify(traits)
|
|
451
|
+
|
|
452
|
+
# Count checks per scoped area by parsing checklist rows (format: "| V<n> | ...").
|
|
453
|
+
# Deterministic denominator the agent must score against.
|
|
454
|
+
checklists_by_area: dict[str, str] = {}
|
|
455
|
+
per_area_counts: dict[str, int] = {}
|
|
456
|
+
total_checks = 0
|
|
457
|
+
for f in classification["implement_files"]:
|
|
458
|
+
checklist = fetch_verify([f])
|
|
459
|
+
checklists_by_area[f] = checklist
|
|
460
|
+
row_matches = re.findall(r"^\| V\d+\b", checklist, flags=re.MULTILINE)
|
|
461
|
+
per_area_counts[f] = len(row_matches)
|
|
462
|
+
total_checks += len(row_matches)
|
|
463
|
+
areas_csv = ", ".join(classification["implement_files"])
|
|
464
|
+
score_line_template = (
|
|
465
|
+
f"Score: <P> / {total_checks} total checks across "
|
|
466
|
+
f"{len(classification['implement_files'])} recommended areas (areas: {areas_csv})"
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
if as_json:
|
|
470
|
+
click.echo(json.dumps({
|
|
471
|
+
"classification": classification,
|
|
472
|
+
"checklists": checklists_by_area,
|
|
473
|
+
"score_template": {
|
|
474
|
+
"total_checks": total_checks,
|
|
475
|
+
"recommended_areas_count": len(classification["implement_files"]),
|
|
476
|
+
"recommended_areas": classification["implement_files"],
|
|
477
|
+
"per_area_check_count": per_area_counts,
|
|
478
|
+
"score_line_template": score_line_template,
|
|
479
|
+
},
|
|
480
|
+
}, indent=2))
|
|
481
|
+
return
|
|
482
|
+
|
|
483
|
+
tier = classification["risk_tier"]
|
|
484
|
+
tier_color = "red" if tier == "HIGH" else "yellow" if tier == "MEDIUM" else "green"
|
|
485
|
+
console.print("[bold]═══ AIGIS GOVERNANCE AUDIT (SCOPED) ═══[/bold]\n")
|
|
486
|
+
console.print(f"[bold]Risk tier:[/bold] [bold {tier_color}]{tier}[/bold {tier_color}]")
|
|
487
|
+
console.print(f"[bold]Recommended areas:[/bold] {len(classification['implement_files'])}")
|
|
488
|
+
console.print(f"[bold]Areas:[/bold] {areas_csv}")
|
|
489
|
+
console.print(f"[bold]Total checks (deterministic denominator):[/bold] {total_checks}\n")
|
|
490
|
+
|
|
491
|
+
console.print("[bold]Instructions for agent:[/bold]")
|
|
492
|
+
console.print("[dim]Evaluate the existing codebase against each check below.[/dim]")
|
|
493
|
+
console.print('[dim]Mark PASS / FAIL / PARTIAL with evidence (file:line or "not found").[/dim]')
|
|
494
|
+
console.print("[dim]At the end of your report, emit this exact line (replace <P> with the PASS count):[/dim]")
|
|
495
|
+
console.print(f"[dim] {score_line_template}[/dim]\n")
|
|
496
|
+
|
|
497
|
+
for f in classification["implement_files"]:
|
|
498
|
+
click.echo(checklists_by_area[f])
|
|
499
|
+
click.echo()
|
|
500
|
+
|
|
501
|
+
console.print("[bold]═══ SCORING ═══[/bold]")
|
|
502
|
+
console.print(
|
|
503
|
+
f"Denominator: {total_checks} total checks across "
|
|
504
|
+
f"{len(classification['implement_files'])} recommended areas."
|
|
505
|
+
)
|
|
506
|
+
console.print(f"Areas: {areas_csv}")
|
|
507
|
+
console.print(f"Emit at end of report: [bold]{score_line_template}[/bold]")
|
|
508
|
+
|
|
509
|
+
if classification["templates"]:
|
|
510
|
+
console.print("\n[bold]Required documentation:[/bold]")
|
|
511
|
+
for t in classification["templates"]:
|
|
512
|
+
console.print(f"[yellow] aigis template {t}[/yellow]")
|
|
513
|
+
return
|
|
514
|
+
|
|
515
|
+
console.print("[red]Provide --scan or --traits.[/red]")
|
|
516
|
+
console.print("[dim] aigis audit --scan # get scan prompt[/dim]")
|
|
517
|
+
console.print("[dim] aigis audit --traits uses-llm,... # run audit\n[/dim]")
|
|
518
|
+
sys.exit(1)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
# ── search ──────────────────────────────────────────────────────────
|
|
522
|
+
@cli.command()
|
|
523
|
+
@click.argument("query", required=False, default=None)
|
|
524
|
+
@click.option("--list", "list_files", is_flag=True, help="List all available files")
|
|
525
|
+
def search(query: str | None, list_files: bool) -> None:
|
|
526
|
+
"""Search across all content."""
|
|
527
|
+
if list_files:
|
|
528
|
+
results = list_all()
|
|
529
|
+
console.print("[bold]Available content:\n[/bold]")
|
|
530
|
+
console.print("[bold]Implement files (governance patterns):[/bold]")
|
|
531
|
+
for r in results["implement"]:
|
|
532
|
+
console.print(f" [cyan]{r['id']:<25}[/cyan] {r['title']}")
|
|
533
|
+
console.print("\n[bold]Templates (compliance documentation):[/bold]")
|
|
534
|
+
for r in results["templates"]:
|
|
535
|
+
console.print(f" [yellow]{r['id']:<25}[/yellow] {r['title']}")
|
|
536
|
+
console.print("\n[bold]Verify checklists:[/bold]")
|
|
537
|
+
console.print("[dim] (one per implement file, auto-fetched via aigis verify <id>)[/dim]")
|
|
538
|
+
return
|
|
539
|
+
|
|
540
|
+
if not query:
|
|
541
|
+
console.print("[red]Provide a search query or use --list.[/red]")
|
|
542
|
+
sys.exit(1)
|
|
543
|
+
|
|
544
|
+
results = run_search(query)
|
|
545
|
+
if not results:
|
|
546
|
+
console.print(f'[dim]No results found for "{query}"[/dim]')
|
|
547
|
+
return
|
|
548
|
+
console.print(f'[bold]Results for "{query}":\n[/bold]')
|
|
549
|
+
for r in results:
|
|
550
|
+
console.print(f" [cyan]{r['id']:<25}[/cyan] {r['title']}")
|
|
551
|
+
if r["matched_controls"]:
|
|
552
|
+
console.print(f" [dim]{'':<25} controls: {', '.join(r['matched_controls'])}[/dim]")
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
# ── annotate ────────────────────────────────────────────────────────
|
|
556
|
+
@cli.command()
|
|
557
|
+
@click.argument("file_id", required=False, default=None)
|
|
558
|
+
@click.argument("note", required=False, default=None)
|
|
559
|
+
@click.option("--list", "list_all_annotations", is_flag=True, help="List all annotations")
|
|
560
|
+
@click.option("--clear", is_flag=True, help="Clear annotations for a file")
|
|
561
|
+
def annotate(file_id: str | None, note: str | None,
|
|
562
|
+
list_all_annotations: bool, clear: bool) -> None:
|
|
563
|
+
"""Attach or manage local notes on content files."""
|
|
564
|
+
if list_all_annotations:
|
|
565
|
+
all_notes = list_annotations()
|
|
566
|
+
if not all_notes:
|
|
567
|
+
console.print("[dim]No annotations yet.[/dim]")
|
|
568
|
+
return
|
|
569
|
+
console.print("[bold]Annotations:\n[/bold]")
|
|
570
|
+
for fid, notes in all_notes.items():
|
|
571
|
+
console.print(f" [cyan]{fid}:[/cyan]")
|
|
572
|
+
for n in notes:
|
|
573
|
+
console.print(f' [dim] "{n["note"]}" ({n["date"]})[/dim]')
|
|
574
|
+
return
|
|
575
|
+
|
|
576
|
+
if not file_id:
|
|
577
|
+
console.print("[red]Provide a file ID. Use --list to see annotations.[/red]")
|
|
578
|
+
sys.exit(1)
|
|
579
|
+
|
|
580
|
+
if clear:
|
|
581
|
+
clear_annotation(file_id)
|
|
582
|
+
console.print(f"[green]Cleared annotations for {file_id}[/green]")
|
|
583
|
+
return
|
|
584
|
+
|
|
585
|
+
if not note:
|
|
586
|
+
console.print("[red]Provide a note in quotes.[/red]")
|
|
587
|
+
console.print('[dim]Example: aigis annotate input-validation "Needs raw body for webhooks"[/dim]')
|
|
588
|
+
sys.exit(1)
|
|
589
|
+
|
|
590
|
+
add_annotation(file_id, note)
|
|
591
|
+
console.print(f"[green]Annotation added to {file_id}[/green]")
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
# ── init ────────────────────────────────────────────────────────────
|
|
595
|
+
@cli.command("init")
|
|
596
|
+
@click.argument("ide")
|
|
597
|
+
@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
|
+
def init_cmd(ide: str, refresh: bool) -> None:
|
|
599
|
+
"""Set up aigis for your IDE (writes core skill + resolver block)."""
|
|
600
|
+
run_init(ide, refresh=refresh)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
# ── traits ──────────────────────────────────────────────────────────
|
|
604
|
+
@cli.command()
|
|
605
|
+
def traits() -> None:
|
|
606
|
+
"""List all available classification traits."""
|
|
607
|
+
console.print("[bold]Available traits (22):\n[/bold]")
|
|
608
|
+
groups = {
|
|
609
|
+
"AI architecture": ["uses-llm", "uses-rag", "uses-finetuned", "uses-thirdparty-api", "is-agentic", "is-multimodal"],
|
|
610
|
+
"Data sensitivity": ["processes-pii", "handles-financial", "handles-health", "handles-proprietary", "handles-minors"],
|
|
611
|
+
"Impact scope": ["influences-decisions", "accepts-user-input", "is-external", "is-internal", "is-high-volume"],
|
|
612
|
+
"Output type": ["generates-code", "generates-content", "multi-model-pipeline"],
|
|
613
|
+
"Jurisdiction": ["jurisdiction-eu", "jurisdiction-us-regulated", "jurisdiction-global"],
|
|
614
|
+
}
|
|
615
|
+
for group, trait_list in groups.items():
|
|
616
|
+
console.print(f" [dim]{group}:[/dim]")
|
|
617
|
+
formatted = ", ".join(f"[cyan]{t}[/cyan]" for t in trait_list)
|
|
618
|
+
console.print(f" {formatted}\n")
|