@aigis-ai/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -0
  3. package/SKILL.md +74 -0
  4. package/bin/aigis.js +337 -0
  5. package/content/implement/audit-logging.md +171 -0
  6. package/content/implement/bias-monitoring.md +172 -0
  7. package/content/implement/confidence-scoring.md +180 -0
  8. package/content/implement/data-integrity.md +257 -0
  9. package/content/implement/explainability.md +174 -0
  10. package/content/implement/fallback-patterns.md +190 -0
  11. package/content/implement/human-oversight.md +220 -0
  12. package/content/implement/input-validation.md +212 -0
  13. package/content/implement/monitoring.md +207 -0
  14. package/content/implement/output-sanitization.md +183 -0
  15. package/content/implement/pii-handling.md +207 -0
  16. package/content/implement/prompt-security.md +153 -0
  17. package/content/implement/rag-security.md +230 -0
  18. package/content/implement/rate-limiting.md +217 -0
  19. package/content/implement/supply-chain.md +193 -0
  20. package/content/index/audit-scan.md +403 -0
  21. package/content/index/frameworks.md +82 -0
  22. package/content/index/guardrails.json +23 -0
  23. package/content/index/taxonomy.md +81 -0
  24. package/content/templates/ai-impact-assessment.md +54 -0
  25. package/content/templates/intended-purpose-doc.md +39 -0
  26. package/content/templates/risk-characterization.md +34 -0
  27. package/content/templates/third-party-assessment.md +41 -0
  28. package/content/verify/checklist-audit-logging.md +13 -0
  29. package/content/verify/checklist-bias-monitoring.md +13 -0
  30. package/content/verify/checklist-confidence-scoring.md +13 -0
  31. package/content/verify/checklist-data-integrity.md +12 -0
  32. package/content/verify/checklist-explainability.md +13 -0
  33. package/content/verify/checklist-fallback-patterns.md +13 -0
  34. package/content/verify/checklist-human-oversight.md +14 -0
  35. package/content/verify/checklist-input-validation.md +16 -0
  36. package/content/verify/checklist-monitoring.md +13 -0
  37. package/content/verify/checklist-output-sanitization.md +14 -0
  38. package/content/verify/checklist-pii-handling.md +14 -0
  39. package/content/verify/checklist-prompt-security.md +13 -0
  40. package/content/verify/checklist-rag-security.md +12 -0
  41. package/content/verify/checklist-rate-limiting.md +13 -0
  42. package/content/verify/checklist-supply-chain.md +13 -0
  43. package/lib/annotate.js +53 -0
  44. package/lib/classify.js +185 -0
  45. package/lib/fetch.js +112 -0
  46. package/lib/init.js +122 -0
  47. package/lib/keywords.js +139 -0
  48. package/lib/search.js +76 -0
  49. package/package.json +35 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nayan Kanaparthi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Aigis
2
+
3
+ AI governance guardrails for coding agents. Curated, agent-consumable security and compliance patterns from NIST AI RMF, OWASP Top 10 for LLMs, and ISO/IEC 42001.
4
+
5
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+ [![npm](https://img.shields.io/npm/v/@aigis-ai/cli)](https://www.npmjs.com/package/@aigis-ai/cli)
7
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
8
+
9
+ ## The problem
10
+
11
+ Coding agents hallucinate security patterns and build AI systems without governance controls. When your agent writes an LLM-powered endpoint, it doesn't know about prompt injection, PII redaction, bias monitoring, or the compliance documentation your organization needs.
12
+
13
+ ## What Aigis does
14
+
15
+ Aigis gives your coding agent curated governance patterns it can fetch via a simple CLI. The agent reads the patterns, applies them when writing code, and verifies its own output against checklists — all mapped to real framework control IDs.
16
+
17
+ ```
18
+ Without Aigis With Aigis
19
+ ─────────────────── ─────────────────
20
+ Agent writes LLM code Agent classifies the system
21
+ No input validation Fetches governance patterns
22
+ No PII redaction Writes code with controls built in
23
+ No audit logging Self-verifies against checklists
24
+ Compliance team finds gaps later Compliance documentation generated alongside code
25
+ Rework cycle Ships compliant on first pass
26
+ ```
27
+
28
+ ## Quick start
29
+
30
+ ```bash
31
+ npm install -g @aigis-ai/cli
32
+
33
+ # Set up for your IDE
34
+ aigis init cursor # or: claude-code, windsurf, copilot
35
+
36
+ # Classify your system
37
+ aigis classify --traits uses-llm,accepts-user-input,processes-pii,is-external
38
+
39
+ # Fetch patterns
40
+ aigis get input-validation pii-handling audit-logging
41
+
42
+ # After writing code, verify
43
+ aigis verify input-validation pii-handling audit-logging
44
+
45
+ # Generate compliance documentation (if HIGH/MEDIUM risk)
46
+ aigis template ai-impact-assessment intended-purpose-doc
47
+ ```
48
+
49
+ ## How it works
50
+
51
+ Aigis has three layers:
52
+
53
+ **1. Classify** — Describe what you're building using 22 system traits. Aigis determines the risk tier (HIGH/MEDIUM/LOW) and tells you which governance files to fetch.
54
+
55
+ **2. Implement** — Fetch the relevant pattern files. Each file contains concrete code patterns (Python + JavaScript) for one security/governance concern, tagged with NIST, OWASP, and ISO control IDs.
56
+
57
+ **3. Verify** — After writing code, fetch the matching checklists. The agent evaluates its own code against each check and reports PASS/FAIL with evidence.
58
+
59
+ ## Commands
60
+
61
+ | Command | Purpose |
62
+ |---------|---------|
63
+ | `aigis classify --traits <list>` | Classify system, get risk tier and recommended files |
64
+ | `aigis classify "<description>"` | Same, using natural language (keyword matching) |
65
+ | `aigis get <id> [id...]` | Fetch implementation pattern files |
66
+ | `aigis get <id> --lang py\|js` | Fetch filtered to one language |
67
+ | `aigis verify <id> [id...]` | Fetch verification checklists |
68
+ | `aigis template <id> [id...]` | Fetch compliance documentation templates |
69
+ | `aigis audit --scan` | Get structured prompt for auditing existing codebases |
70
+ | `aigis audit --traits <list>` | Run full audit (classify + all checklists bundled) |
71
+ | `aigis search <query>` | Search content by keyword or control ID |
72
+ | `aigis search --list` | List all available files |
73
+ | `aigis annotate <id> "<note>"` | Attach a local note for future sessions |
74
+ | `aigis init <ide>` | Set up for cursor, claude-code, windsurf, or copilot |
75
+ | `aigis traits` | List all 22 classification traits |
76
+
77
+ ## Classification traits (22)
78
+
79
+ **AI architecture:** uses-llm, uses-rag, uses-finetuned, uses-thirdparty-api, is-agentic, is-multimodal
80
+
81
+ **Data sensitivity:** processes-pii, handles-financial, handles-health, handles-proprietary, handles-minors
82
+
83
+ **Impact scope:** influences-decisions, accepts-user-input, is-external, is-internal, is-high-volume
84
+
85
+ **Output type:** generates-code, generates-content, multi-model-pipeline
86
+
87
+ **Jurisdiction:** jurisdiction-eu, jurisdiction-us-regulated, jurisdiction-global
88
+
89
+ ## Governance content (15 pattern files)
90
+
91
+ Each file covers one security/governance concern with Python + JavaScript code patterns, anti-patterns, edge cases, and cross-references to related files.
92
+
93
+ | File | OWASP | What it covers |
94
+ |------|-------|----------------|
95
+ | input-validation | LLM01 | Sanitization, length limits, prompt separation, schema enforcement, injection detection |
96
+ | output-sanitization | LLM05 | HTML encoding, parameterized queries, code sandboxing, content type validation |
97
+ | pii-handling | LLM02 | PII detection/redaction, data minimization, output filtering, separated storage |
98
+ | prompt-security | LLM07 | No secrets in prompts, minimal prompts, leakage detection, server-side enforcement |
99
+ | human-oversight | LLM06 | Tool allowlists, approval gates, action rate limiting, override mechanisms |
100
+ | supply-chain | LLM03 | Model version pinning, regression testing, fallback providers, version tracking |
101
+ | data-integrity | LLM04 | Data provenance, RAG validation, checksums, distribution monitoring, batch rollback |
102
+ | rag-security | LLM08 | Vector DB access control, tenant isolation, context validation, permission inheritance |
103
+ | confidence-scoring | LLM09 | Confidence metadata, grounding verification, recommendation framing |
104
+ | rate-limiting | LLM10 | Per-user limits, token budgets, cost monitoring, request timeouts |
105
+ | audit-logging | — | Structured entries, trace ID propagation, decision records |
106
+ | bias-monitoring | — | Fairness metadata, distribution monitoring, periodic reports |
107
+ | fallback-patterns | — | Default safe responses, circuit breakers, kill switches |
108
+ | monitoring | — | Key metrics, drift detection, user feedback, incident logging |
109
+ | explainability | — | Decision explanations, model cards, audit-friendly records |
110
+
111
+ ## Compliance templates (4)
112
+
113
+ | Template | Framework | When required |
114
+ |----------|-----------|---------------|
115
+ | ai-impact-assessment | ISO 42001 Clause 8.4 | HIGH risk, EU jurisdiction, decisions about individuals |
116
+ | intended-purpose-doc | NIST MAP 1.1 | HIGH and MEDIUM risk |
117
+ | risk-characterization | NIST MAP 5.1 | HIGH risk |
118
+ | third-party-assessment | GOVERN 6 / LLM03 | Third-party API at MEDIUM or HIGH risk |
119
+
120
+ ## Auditing existing projects
121
+
122
+ Aigis can audit codebases that already exist, not just new code:
123
+
124
+ ```bash
125
+ # Get the structured scan prompt
126
+ aigis audit --scan
127
+
128
+ # The agent scans the codebase following the prompt, detects traits, then:
129
+ aigis audit --traits uses-llm,processes-pii,is-external
130
+
131
+ # Output: classification + all relevant checklists
132
+ # Agent evaluates existing code against each check → gap report
133
+ ```
134
+
135
+ ## Self-improving agents
136
+
137
+ Aigis supports a learning loop where agents get smarter over time:
138
+
139
+ ```bash
140
+ # Agent discovers a workaround during coding
141
+ aigis annotate input-validation "Needs raw body for webhook verification"
142
+
143
+ # Next session, the annotation appears automatically
144
+ aigis get input-validation
145
+ # ... content includes annotation at the bottom
146
+ ```
147
+
148
+ ## Agent-agnostic design
149
+
150
+ Aigis works with any coding agent that can execute shell commands:
151
+
152
+ - **Cursor** — `aigis init cursor` writes `.cursorrules`
153
+ - **Claude Code** — `aigis init claude-code` creates `~/.claude/skills/aigis/SKILL.md`
154
+ - **Windsurf** — `aigis init windsurf` writes `.windsurfrules`
155
+ - **GitHub Copilot** — `aigis init copilot` writes `.github/copilot-instructions.md`
156
+ - **Any agent** — if it can run a terminal command and read stdout, it works
157
+
158
+ ## Framework coverage
159
+
160
+ Aigis maps every code pattern to specific control IDs across three frameworks:
161
+
162
+ - **OWASP Top 10 for LLM Applications (2025)** — all 10 risks covered
163
+ - **NIST AI Risk Management Framework (AI RMF 1.0)** — 25 subcategories mapped
164
+ - **ISO/IEC 42001:2023** — 15 control references mapped
165
+
166
+ Control IDs are in each file's YAML frontmatter, enabling compliance teams to trace code decisions back to framework requirements.
167
+
168
+ ## Architecture
169
+
170
+ ```
171
+ @aigis-ai/cli
172
+ ├── bin/aigis.js # CLI entry point (commander.js)
173
+ ├── lib/
174
+ │ ├── classify.js # Classification engine + guardrails
175
+ │ ├── fetch.js # Content reader + annotation injection
176
+ │ ├── keywords.js # Natural language → trait mapping
177
+ │ ├── search.js # Content search
178
+ │ ├── annotate.js # Local annotation store
179
+ │ └── init.js # IDE setup
180
+ ├── content/
181
+ │ ├── implement/ # 15 governance pattern files
182
+ │ ├── verify/ # 15 verification checklists
183
+ │ ├── templates/ # 4 compliance doc templates
184
+ │ └── index/ # Taxonomy, frameworks index, guardrails, audit scan
185
+ ├── SKILL.md # Portable agent skill file
186
+ └── package.json
187
+ ```
188
+
189
+ No network calls. No telemetry. No LLM API calls. No databases. Everything runs locally, reads local files, prints to stdout.
190
+
191
+ ## Contributing
192
+
193
+ Content is plain markdown with YAML frontmatter, submitted as pull requests. See the existing files in `content/implement/` for the format.
194
+
195
+ To add a new governance pattern:
196
+ 1. Create `content/implement/your-pattern.md` following the existing format
197
+ 2. Create `content/verify/checklist-your-pattern.md` with verification checks
198
+ 3. Add the pattern to the trait-to-file mapping in `content/index/taxonomy.md`
199
+ 4. Add control IDs to the YAML frontmatter
200
+ 5. Submit a PR
201
+
202
+ ## License
203
+
204
+ [MIT](LICENSE)
package/SKILL.md ADDED
@@ -0,0 +1,74 @@
1
+ ---
2
+ name: aigis
3
+ description: AI governance skill for coding agents. Provides framework-aligned security and compliance patterns from NIST AI RMF, OWASP Top 10 for LLMs, and ISO/IEC 42001. Use before building any AI/LLM feature or when auditing existing AI systems.
4
+ ---
5
+
6
+ # Aigis — AI Governance Skill
7
+
8
+ Use the aigis CLI for governance patterns when building or auditing AI/LLM features.
9
+
10
+ ## Quick start — new feature
11
+ \`\`\`bash
12
+ # 1. Classify your system to get relevant controls
13
+ aigis classify --traits uses-llm,accepts-user-input,processes-pii,is-external --json
14
+
15
+ # 2. Fetch implementation patterns for each recommended file
16
+ aigis get input-validation pii-handling prompt-security audit-logging
17
+
18
+ # 3. Write code applying the patterns from the fetched files
19
+
20
+ # 4. After writing code, run verification
21
+ aigis verify input-validation pii-handling prompt-security audit-logging
22
+
23
+ # 5. If risk tier is HIGH or MEDIUM, generate compliance docs
24
+ aigis template ai-impact-assessment intended-purpose-doc
25
+ \`\`\`
26
+
27
+ ## Quick start — audit existing project
28
+ \`\`\`bash
29
+ # 1. Get the structured audit scan prompt
30
+ aigis audit --scan
31
+
32
+ # 2. Follow the scan instructions: inventory the project, detect traits, classify
33
+
34
+ # 3. Run the full audit with detected traits
35
+ aigis audit --traits uses-llm,processes-pii,is-external
36
+
37
+ # 4. Evaluate existing code against each check, produce gap report
38
+ \`\`\`
39
+
40
+ ## When to use
41
+ - Before writing any LLM API call or AI feature (new code)
42
+ - When auditing an existing AI system for governance gaps (existing code)
43
+ - Before processing any sensitive data through an AI system
44
+ - Before deploying any AI feature to production
45
+ - When onboarding to a new AI project to understand what controls exist
46
+
47
+ ## Commands
48
+ - \`aigis classify --traits <comma-separated>\` — get risk tier and relevant files
49
+ - \`aigis classify "<description>"\` — same, using natural language (keyword matching)
50
+ - \`aigis get <file-id> [file-id...]\` — fetch implementation patterns (one or more)
51
+ - \`aigis get <file-id> --lang py|js\` — fetch filtered to one language
52
+ - \`aigis verify <file-id> [file-id...]\` — fetch verification checklists
53
+ - \`aigis template <template-id> [template-id...]\` — fetch compliance documentation templates
54
+ - \`aigis audit --scan\` — get structured audit prompt for scanning existing codebases
55
+ - \`aigis audit --traits <comma-separated>\` — get bundled classification + all checklists for audit
56
+ - \`aigis search <query>\` — search across all content by keyword or control ID
57
+ - \`aigis search --list\` — list all available files
58
+ - \`aigis annotate <file-id> "<note>"\` — attach a local note for future sessions
59
+ - \`aigis annotate --list\` — list all annotations
60
+ - \`aigis init cursor|claude-code|windsurf|copilot\` — set up aigis for your IDE
61
+
62
+ ## Available traits (22)
63
+ AI architecture: uses-llm, uses-rag, uses-finetuned, uses-thirdparty-api, is-agentic, is-multimodal
64
+ Data sensitivity: processes-pii, handles-financial, handles-health, handles-proprietary, handles-minors
65
+ Impact scope: influences-decisions, accepts-user-input, is-external, is-internal, is-high-volume
66
+ Output type: generates-code, generates-content, multi-model-pipeline
67
+ Jurisdiction: jurisdiction-eu, jurisdiction-us-regulated, jurisdiction-global
68
+
69
+ ## Integration
70
+ - Claude Code: place this file in ~/.claude/skills/aigis/SKILL.md
71
+ - Cursor: run \`aigis init cursor\` in your project root
72
+ - Windsurf: run \`aigis init windsurf\` in your project root
73
+ - GitHub Copilot: run \`aigis init copilot\` in your project root
74
+ - Any agent: include aigis usage instructions in system prompt
package/bin/aigis.js ADDED
@@ -0,0 +1,337 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { Command } = require('commander');
4
+ const chalk = require('chalk');
5
+ const { classify } = require('../lib/classify');
6
+ const { get, getTemplate, getAuditScan } = require('../lib/fetch');
7
+ const { verify } = require('../lib/fetch');
8
+ const { search, listAll } = require('../lib/search');
9
+ const { annotate, listAnnotations, clearAnnotation } = require('../lib/annotate');
10
+ const { init } = require('../lib/init');
11
+ const { detectTraitsFromText } = require('../lib/keywords');
12
+
13
+ const program = new Command();
14
+
15
+ program
16
+ .name('aigis')
17
+ .description('AI governance guardrails for coding agents')
18
+ .version('1.0.0');
19
+
20
+ // ============================================================
21
+ // aigis classify
22
+ // ============================================================
23
+ program
24
+ .command('classify')
25
+ .description('Classify an AI system and get recommended governance files')
26
+ .option('--traits <traits>', 'Comma-separated trait IDs')
27
+ .option('--interactive', 'Confirm detected traits before classifying')
28
+ .option('--json', 'Output as JSON')
29
+ .argument('[description]', 'Natural language description (keyword matching)')
30
+ .action((description, opts) => {
31
+ let traits;
32
+
33
+ if (opts.traits) {
34
+ traits = opts.traits.split(',').map(t => t.trim());
35
+ } else if (description) {
36
+ const detected = detectTraitsFromText(description);
37
+ if (opts.interactive) {
38
+ console.log(chalk.bold('\nDetected traits from description:\n'));
39
+ for (const { trait, keyword, confidence } of detected) {
40
+ const icon = confidence === 'high' ? chalk.green('✓') : chalk.yellow('?');
41
+ console.log(` ${icon} ${chalk.cyan(trait)} (matched: "${keyword}")`);
42
+ }
43
+ console.log(chalk.dim('\nTo classify with these traits, run:'));
44
+ console.log(chalk.green(` aigis classify --traits ${detected.map(d => d.trait).join(',')}\n`));
45
+ console.log(chalk.dim('Add or remove traits as needed before running.\n'));
46
+ return;
47
+ }
48
+ traits = detected.map(d => d.trait);
49
+ if (traits.length === 0) {
50
+ console.error(chalk.red('No traits detected from description.'));
51
+ console.log(chalk.dim('Run "aigis traits" to see available traits, or use --traits flag.\n'));
52
+ process.exit(1);
53
+ }
54
+ console.log(chalk.dim(`Detected traits: ${traits.join(', ')}\n`));
55
+ } else {
56
+ console.error(chalk.red('Provide --traits or a quoted description.'));
57
+ console.log(chalk.dim('Example: aigis classify --traits uses-llm,processes-pii'));
58
+ console.log(chalk.dim('Example: aigis classify "customer chatbot with RAG"\n'));
59
+ process.exit(1);
60
+ }
61
+
62
+ let result;
63
+ try {
64
+ result = classify(traits);
65
+ } catch (e) {
66
+ console.error(chalk.red(e.message));
67
+ process.exit(1);
68
+ }
69
+
70
+ if (opts.json) {
71
+ console.log(JSON.stringify(result, null, 2));
72
+ return;
73
+ }
74
+
75
+ // Formatted output
76
+ const tierColor = result.risk_tier === 'HIGH' ? chalk.red : result.risk_tier === 'MEDIUM' ? chalk.yellow : chalk.green;
77
+ console.log(`${chalk.bold('Risk tier:')} ${tierColor.bold(result.risk_tier)}`);
78
+ console.log(`${chalk.bold('Reason:')} ${result.reason}\n`);
79
+
80
+ if (result.warnings.length > 0) {
81
+ for (const w of result.warnings) {
82
+ console.log(chalk.yellow(`⚠ ${w}`));
83
+ }
84
+ console.log('');
85
+ }
86
+
87
+ console.log(chalk.bold(`Implement files (${result.implement_files.length}):`));
88
+ for (const f of result.implement_files) {
89
+ console.log(chalk.green(` aigis get ${f}`));
90
+ }
91
+
92
+ if (result.templates.length > 0) {
93
+ console.log(chalk.bold(`\nTemplates (${result.templates.length}):`));
94
+ for (const t of result.templates) {
95
+ console.log(chalk.yellow(` aigis template ${t}`));
96
+ }
97
+ }
98
+
99
+ if (result.guardrails_fired.length > 0) {
100
+ console.log(chalk.bold('\nGuardrails fired:'));
101
+ for (const g of result.guardrails_fired) {
102
+ console.log(chalk.yellow(` ${g.id}: ${g.action} — ${g.rationale}`));
103
+ }
104
+ }
105
+
106
+ console.log(chalk.bold('\nVerify after implementation:'));
107
+ for (const f of result.implement_files) {
108
+ console.log(chalk.green(` aigis verify ${f}`));
109
+ }
110
+
111
+ console.log(chalk.dim(`\nControls: ${result.controls.owasp.length} OWASP, ${result.controls.nist.length} NIST, ${result.controls.iso.length} ISO`));
112
+ });
113
+
114
+ // ============================================================
115
+ // aigis get
116
+ // ============================================================
117
+ program
118
+ .command('get')
119
+ .description('Fetch implementation pattern files')
120
+ .option('--all', 'Fetch all implement files')
121
+ .option('--lang <language>', 'Filter code to py or js only')
122
+ .option('--no-frontmatter', 'Strip YAML frontmatter')
123
+ .argument('[files...]', 'File IDs to fetch')
124
+ .action((files, opts) => {
125
+ const content = get(files, opts);
126
+ console.log(content);
127
+ });
128
+
129
+ // ============================================================
130
+ // aigis verify
131
+ // ============================================================
132
+ program
133
+ .command('verify')
134
+ .description('Fetch verification checklists')
135
+ .argument('<files...>', 'File IDs to verify')
136
+ .action((files) => {
137
+ const content = verify(files);
138
+ console.log(content);
139
+ });
140
+
141
+ // ============================================================
142
+ // aigis template
143
+ // ============================================================
144
+ program
145
+ .command('template')
146
+ .description('Fetch compliance documentation templates')
147
+ .argument('<templates...>', 'Template IDs')
148
+ .action((templates) => {
149
+ const content = getTemplate(templates);
150
+ console.log(content);
151
+ });
152
+
153
+ // ============================================================
154
+ // aigis audit
155
+ // ============================================================
156
+ program
157
+ .command('audit')
158
+ .description('Audit an existing codebase for governance gaps')
159
+ .option('--scan', 'Get structured scan prompt for the agent')
160
+ .option('--traits <traits>', 'Run audit with detected traits (bundles classify + all checklists)')
161
+ .option('--json', 'Output as JSON')
162
+ .action((opts) => {
163
+ if (opts.scan) {
164
+ const content = getAuditScan();
165
+ console.log(content);
166
+ return;
167
+ }
168
+
169
+ if (opts.traits) {
170
+ const traits = opts.traits.split(',').map(t => t.trim());
171
+ const classification = classify(traits);
172
+
173
+ if (opts.json) {
174
+ const checklists = {};
175
+ for (const f of classification.implement_files) {
176
+ checklists[f] = verify([f]);
177
+ }
178
+ console.log(JSON.stringify({ classification, checklists }, null, 2));
179
+ return;
180
+ }
181
+
182
+ // Formatted audit output
183
+ const tierColor = classification.risk_tier === 'HIGH' ? chalk.red : classification.risk_tier === 'MEDIUM' ? chalk.yellow : chalk.green;
184
+ console.log(chalk.bold('═══ AIGIS GOVERNANCE AUDIT ═══\n'));
185
+ console.log(`${chalk.bold('Risk tier:')} ${tierColor.bold(classification.risk_tier)}`);
186
+ console.log(`${chalk.bold('Controls to assess:')} ${classification.implement_files.length} areas\n`);
187
+
188
+ console.log(chalk.bold('Instructions for agent:'));
189
+ console.log(chalk.dim('Evaluate the existing codebase against each check below.'));
190
+ console.log(chalk.dim('Mark PASS / FAIL / PARTIAL with evidence (file:line or "not found").\n'));
191
+
192
+ for (const f of classification.implement_files) {
193
+ const checklist = verify([f]);
194
+ console.log(checklist);
195
+ console.log('');
196
+ }
197
+
198
+ if (classification.templates.length > 0) {
199
+ console.log(chalk.bold('Required documentation:'));
200
+ for (const t of classification.templates) {
201
+ console.log(chalk.yellow(` aigis template ${t}`));
202
+ }
203
+ }
204
+ return;
205
+ }
206
+
207
+ console.error(chalk.red('Provide --scan or --traits.'));
208
+ console.log(chalk.dim(' aigis audit --scan # get scan prompt'));
209
+ console.log(chalk.dim(' aigis audit --traits uses-llm,... # run audit\n'));
210
+ process.exit(1);
211
+ });
212
+
213
+ // ============================================================
214
+ // aigis search
215
+ // ============================================================
216
+ program
217
+ .command('search')
218
+ .description('Search across all content')
219
+ .option('--list', 'List all available files')
220
+ .argument('[query]', 'Search term')
221
+ .action((query, opts) => {
222
+ if (opts.list) {
223
+ const results = listAll();
224
+ console.log(chalk.bold('Available content:\n'));
225
+ console.log(chalk.bold('Implement files (governance patterns):'));
226
+ for (const r of results.implement) {
227
+ console.log(` ${chalk.cyan(r.id.padEnd(25))} ${r.title}`);
228
+ }
229
+ console.log(chalk.bold('\nTemplates (compliance documentation):'));
230
+ for (const r of results.templates) {
231
+ console.log(` ${chalk.yellow(r.id.padEnd(25))} ${r.title}`);
232
+ }
233
+ console.log(chalk.bold('\nVerify checklists:'));
234
+ console.log(chalk.dim(' (one per implement file, auto-fetched via aigis verify <id>)'));
235
+ return;
236
+ }
237
+
238
+ if (!query) {
239
+ console.error(chalk.red('Provide a search query or use --list.'));
240
+ process.exit(1);
241
+ }
242
+
243
+ const results = search(query);
244
+ if (results.length === 0) {
245
+ console.log(chalk.dim('No results found for "' + query + '"'));
246
+ return;
247
+ }
248
+ console.log(chalk.bold(`Results for "${query}":\n`));
249
+ for (const r of results) {
250
+ console.log(` ${chalk.cyan(r.id.padEnd(25))} ${r.title}`);
251
+ if (r.matched_controls.length > 0) {
252
+ console.log(chalk.dim(` ${''.padEnd(25)} controls: ${r.matched_controls.join(', ')}`));
253
+ }
254
+ }
255
+ });
256
+
257
+ // ============================================================
258
+ // aigis annotate
259
+ // ============================================================
260
+ program
261
+ .command('annotate')
262
+ .description('Attach or manage local notes on content files')
263
+ .option('--list', 'List all annotations')
264
+ .option('--clear', 'Clear annotations for a file')
265
+ .argument('[fileId]', 'File ID to annotate')
266
+ .argument('[note]', 'Annotation text')
267
+ .action((fileId, note, opts) => {
268
+ if (opts.list) {
269
+ const all = listAnnotations();
270
+ if (Object.keys(all).length === 0) {
271
+ console.log(chalk.dim('No annotations yet.'));
272
+ return;
273
+ }
274
+ console.log(chalk.bold('Annotations:\n'));
275
+ for (const [id, notes] of Object.entries(all)) {
276
+ console.log(chalk.cyan(` ${id}:`));
277
+ for (const n of notes) {
278
+ console.log(chalk.dim(` "${n.note}" (${n.date})`));
279
+ }
280
+ }
281
+ return;
282
+ }
283
+
284
+ if (!fileId) {
285
+ console.error(chalk.red('Provide a file ID. Use --list to see annotations.'));
286
+ process.exit(1);
287
+ }
288
+
289
+ if (opts.clear) {
290
+ clearAnnotation(fileId);
291
+ console.log(chalk.green(`Cleared annotations for ${fileId}`));
292
+ return;
293
+ }
294
+
295
+ if (!note) {
296
+ console.error(chalk.red('Provide a note in quotes.'));
297
+ console.log(chalk.dim('Example: aigis annotate input-validation "Needs raw body for webhooks"'));
298
+ process.exit(1);
299
+ }
300
+
301
+ annotate(fileId, note);
302
+ console.log(chalk.green(`Annotation added to ${fileId}`));
303
+ });
304
+
305
+ // ============================================================
306
+ // aigis init
307
+ // ============================================================
308
+ program
309
+ .command('init')
310
+ .description('Set up aigis for your IDE')
311
+ .argument('<ide>', 'IDE to configure: cursor, claude-code, windsurf, copilot')
312
+ .action((ide) => {
313
+ init(ide);
314
+ });
315
+
316
+ // ============================================================
317
+ // aigis traits (convenience)
318
+ // ============================================================
319
+ program
320
+ .command('traits')
321
+ .description('List all available classification traits')
322
+ .action(() => {
323
+ console.log(chalk.bold('Available traits (22):\n'));
324
+ const groups = {
325
+ 'AI architecture': ['uses-llm', 'uses-rag', 'uses-finetuned', 'uses-thirdparty-api', 'is-agentic', 'is-multimodal'],
326
+ 'Data sensitivity': ['processes-pii', 'handles-financial', 'handles-health', 'handles-proprietary', 'handles-minors'],
327
+ 'Impact scope': ['influences-decisions', 'accepts-user-input', 'is-external', 'is-internal', 'is-high-volume'],
328
+ 'Output type': ['generates-code', 'generates-content', 'multi-model-pipeline'],
329
+ 'Jurisdiction': ['jurisdiction-eu', 'jurisdiction-us-regulated', 'jurisdiction-global'],
330
+ };
331
+ for (const [group, traits] of Object.entries(groups)) {
332
+ console.log(chalk.dim(` ${group}:`));
333
+ console.log(` ${traits.map(t => chalk.cyan(t)).join(', ')}\n`);
334
+ }
335
+ });
336
+
337
+ program.parse();