@aigis-ai/cli 1.0.3 → 2.0.2
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/README.md +58 -188
- package/SKILL.md +20 -55
- package/aigis-ai-cli-2.0.1.tgz +0 -0
- package/bin/aigis.js +446 -59
- 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/{implement → skills/areas}/audit-logging.md +5 -0
- package/content/skills/areas/fallback-patterns.md +200 -0
- package/content/skills/areas/input-validation.md +380 -0
- package/content/skills/areas/pii-handling.md +189 -0
- package/content/skills/areas/rate-limiting.md +246 -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 → skills/areas}/bias-monitoring.md +0 -0
- /package/content/{implement → skills/areas}/confidence-scoring.md +0 -0
- /package/content/{implement → skills/areas}/data-integrity.md +0 -0
- /package/content/{implement → skills/areas}/explainability.md +0 -0
- /package/content/{implement → skills/areas}/human-oversight.md +0 -0
- /package/content/{implement → skills/areas}/monitoring.md +0 -0
- /package/content/{implement → skills/areas}/output-sanitization.md +0 -0
- /package/content/{implement → skills/areas}/prompt-security.md +0 -0
- /package/content/{implement → skills/areas}/rag-security.md +0 -0
- /package/content/{implement → skills/areas}/supply-chain.md +0 -0
package/bin/aigis.js
CHANGED
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
const { Command } = require('commander');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const { classify } = require('../lib/classify');
|
|
6
|
-
const { get, getTemplate, getAuditScan } = require('../lib/fetch');
|
|
6
|
+
const { get, getTemplate, getAuditScan, getWorkflow, listWorkflows, getInfra, listInfras } = require('../lib/fetch');
|
|
7
|
+
const { buildBrief, buildList, BriefTooLargeError } = require('../lib/build');
|
|
7
8
|
const { verify } = require('../lib/fetch');
|
|
8
9
|
const { search, listAll } = require('../lib/search');
|
|
9
10
|
const { annotate, listAnnotations, clearAnnotation } = require('../lib/annotate');
|
|
10
11
|
const { init } = require('../lib/init');
|
|
11
|
-
const { detectTraitsFromText } = require('../lib/keywords');
|
|
12
|
+
const { detectTraitsFromText, applyConfirmations } = require('../lib/keywords');
|
|
13
|
+
const readline = require('readline');
|
|
12
14
|
|
|
13
15
|
const program = new Command();
|
|
14
16
|
|
|
15
17
|
program
|
|
16
18
|
.name('aigis')
|
|
17
19
|
.description('AI governance guardrails for coding agents')
|
|
18
|
-
.version('
|
|
20
|
+
.version('2.0.0');
|
|
19
21
|
|
|
20
22
|
// ============================================================
|
|
21
23
|
// aigis classify
|
|
@@ -23,56 +25,114 @@ program
|
|
|
23
25
|
program
|
|
24
26
|
.command('classify')
|
|
25
27
|
.description('Classify an AI system and get recommended governance files')
|
|
26
|
-
.option('--traits <traits>', 'Comma-separated trait IDs')
|
|
27
|
-
.option('--
|
|
28
|
-
.option('--
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
|
|
28
|
+
.option('--traits <traits>', 'Comma-separated trait IDs (additive: combines with --description triggers if both passed)')
|
|
29
|
+
.option('--json', 'Output as JSON (also enabled automatically when stdout is not a TTY)')
|
|
30
|
+
.option('--confirm <ids>', 'Comma-separated low-confidence suggestion IDs to confirm (no interactive prompt)')
|
|
31
|
+
.option('--reject <ids>', 'Comma-separated low-confidence suggestion IDs to reject (no interactive prompt)')
|
|
32
|
+
.argument('[description]', 'Natural language description (resolved via content/resolvers/triggers.json)')
|
|
33
|
+
.action(async (description, opts) => {
|
|
34
|
+
// Three modes: --traits only, description only, both (additive).
|
|
35
|
+
if (!opts.traits && !description) {
|
|
36
|
+
console.error(chalk.red('Provide --traits, a quoted description, or both.'));
|
|
37
|
+
console.log(chalk.dim('Example: aigis classify --traits uses-llm,processes-pii'));
|
|
38
|
+
console.log(chalk.dim('Example: aigis classify "customer chatbot with RAG"'));
|
|
39
|
+
console.log(chalk.dim('Example: aigis classify "chatbot" --traits handles-financial (additive)\n'));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
// Auto-enable JSON when stdout is not a TTY (CI, piped, &c.)
|
|
44
|
+
const jsonMode = !!opts.json || !process.stdout.isTTY;
|
|
45
|
+
const traitsFromFlag = opts.traits ? opts.traits.split(',').map(t => t.trim()).filter(Boolean) : [];
|
|
46
|
+
const confirmIds = opts.confirm ? new Set(opts.confirm.split(',').map(s => s.trim()).filter(Boolean)) : null;
|
|
47
|
+
const rejectIds = opts.reject ? new Set(opts.reject.split(',').map(s => s.trim()).filter(Boolean)) : null;
|
|
48
|
+
|
|
49
|
+
let detection = { high_confidence_matches: [], low_confidence_matches: [], traits_auto_applied: [] };
|
|
50
|
+
if (description) {
|
|
51
|
+
detection = detectTraitsFromText(description);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Decide what to do with low-confidence suggestions.
|
|
55
|
+
// Priority: --confirm/--reject flags > interactive prompt (TTY only) > default reject.
|
|
56
|
+
let decisions = {};
|
|
57
|
+
let usedFlags = !!(confirmIds || rejectIds);
|
|
58
|
+
|
|
59
|
+
if (description && detection.low_confidence_matches.length > 0) {
|
|
60
|
+
if (usedFlags) {
|
|
61
|
+
for (const sug of detection.low_confidence_matches) {
|
|
62
|
+
if (confirmIds && confirmIds.has(sug.id)) decisions[sug.id] = 'yes';
|
|
63
|
+
else if (rejectIds && rejectIds.has(sug.id)) decisions[sug.id] = 'no';
|
|
64
|
+
else decisions[sug.id] = 'no';
|
|
42
65
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
} else if (jsonMode) {
|
|
67
|
+
for (const sug of detection.low_confidence_matches) decisions[sug.id] = 'no';
|
|
68
|
+
} else {
|
|
69
|
+
// Interactive prompt
|
|
70
|
+
decisions = await promptLowConfidence(detection);
|
|
47
71
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const resolved = applyConfirmations(detection, decisions);
|
|
75
|
+
// Merge with --traits
|
|
76
|
+
const finalTraits = [...new Set([...resolved.final_traits, ...traitsFromFlag])].sort();
|
|
77
|
+
|
|
78
|
+
// Build a resolver report for transparency (in both JSON and text modes when description was given)
|
|
79
|
+
const resolverReport = description ? {
|
|
80
|
+
input: description,
|
|
81
|
+
high_confidence_matches: detection.high_confidence_matches,
|
|
82
|
+
low_confidence_suggestions: resolved.low_confidence_decisions,
|
|
83
|
+
traits_from_description: resolved.final_traits,
|
|
84
|
+
traits_from_flag: traitsFromFlag,
|
|
85
|
+
final_traits: finalTraits,
|
|
86
|
+
} : null;
|
|
87
|
+
|
|
88
|
+
if (finalTraits.length === 0) {
|
|
89
|
+
const msg = 'No traits resolved from description or --traits flag.';
|
|
90
|
+
if (jsonMode) {
|
|
91
|
+
console.log(JSON.stringify({ error: msg, resolver: resolverReport }, null, 2));
|
|
92
|
+
} else {
|
|
93
|
+
console.error(chalk.red(msg));
|
|
94
|
+
console.log(chalk.dim('Run "aigis traits" to see available traits.\n'));
|
|
53
95
|
}
|
|
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
96
|
process.exit(1);
|
|
60
97
|
}
|
|
61
98
|
|
|
62
99
|
let result;
|
|
63
100
|
try {
|
|
64
|
-
result = classify(
|
|
101
|
+
result = classify(finalTraits);
|
|
65
102
|
} catch (e) {
|
|
66
103
|
console.error(chalk.red(e.message));
|
|
67
104
|
process.exit(1);
|
|
68
105
|
}
|
|
106
|
+
if (resolverReport) result.resolver = resolverReport;
|
|
69
107
|
|
|
70
|
-
if (
|
|
108
|
+
if (jsonMode) {
|
|
71
109
|
console.log(JSON.stringify(result, null, 2));
|
|
72
110
|
return;
|
|
73
111
|
}
|
|
74
112
|
|
|
75
|
-
// Formatted output
|
|
113
|
+
// Formatted output. Show resolver section first if it was used.
|
|
114
|
+
if (resolverReport) {
|
|
115
|
+
console.log(chalk.bold('═══ AIGIS RESOLVER ═══'));
|
|
116
|
+
if (detection.high_confidence_matches.length > 0) {
|
|
117
|
+
console.log(chalk.bold('\nHigh-confidence triggers (auto-applied):'));
|
|
118
|
+
for (const m of detection.high_confidence_matches) {
|
|
119
|
+
console.log(` ${chalk.green('✓')} "${m.phrase}" → ${m.traits.join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (resolved.low_confidence_decisions.length > 0) {
|
|
123
|
+
console.log(chalk.bold('\nLow-confidence decisions:'));
|
|
124
|
+
for (const d of resolved.low_confidence_decisions) {
|
|
125
|
+
const icon = d.user_decision === 'yes' ? chalk.green('✓') : d.user_decision === 'unsure' ? chalk.yellow('?') : chalk.dim('✗');
|
|
126
|
+
console.log(` ${icon} [${d.id}] "${d.phrase}" → ${d.traits.join(', ')} (decision: ${d.user_decision})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (traitsFromFlag.length > 0) {
|
|
130
|
+
console.log(chalk.bold(`\nAdded via --traits flag: ${traitsFromFlag.join(', ')}`));
|
|
131
|
+
}
|
|
132
|
+
console.log(chalk.bold(`\nFinal trait set (${finalTraits.length}): ${finalTraits.join(', ')}\n`));
|
|
133
|
+
console.log(chalk.dim('═══════════════════════\n'));
|
|
134
|
+
}
|
|
135
|
+
|
|
76
136
|
const tierColor = result.risk_tier === 'HIGH' ? chalk.red : result.risk_tier === 'MEDIUM' ? chalk.yellow : chalk.green;
|
|
77
137
|
console.log(`${chalk.bold('Risk tier:')} ${tierColor.bold(result.risk_tier)}`);
|
|
78
138
|
console.log(`${chalk.bold('Reason:')} ${result.reason}\n`);
|
|
@@ -84,7 +144,7 @@ program
|
|
|
84
144
|
console.log('');
|
|
85
145
|
}
|
|
86
146
|
|
|
87
|
-
console.log(chalk.bold(`
|
|
147
|
+
console.log(chalk.bold(`Recommended areas (${result.implement_files.length}):`));
|
|
88
148
|
for (const f of result.implement_files) {
|
|
89
149
|
console.log(chalk.green(` aigis get ${f}`));
|
|
90
150
|
}
|
|
@@ -109,6 +169,12 @@ program
|
|
|
109
169
|
}
|
|
110
170
|
|
|
111
171
|
console.log(chalk.dim(`\nControls: ${result.controls.owasp.length} OWASP, ${result.controls.nist.length} NIST, ${result.controls.iso.length} ISO`));
|
|
172
|
+
|
|
173
|
+
// Workflow suggestion. Step 5 ships only fastapi-llm; future workflows will
|
|
174
|
+
// be matched heuristically against the trait set.
|
|
175
|
+
console.log(chalk.bold('\nSuggested workflow:'));
|
|
176
|
+
console.log(chalk.green(' aigis workflow fastapi-llm'));
|
|
177
|
+
console.log(chalk.dim(' (canonical file layout + wiring contracts; see `aigis workflow --list` for others)'));
|
|
112
178
|
});
|
|
113
179
|
|
|
114
180
|
// ============================================================
|
|
@@ -118,12 +184,18 @@ program
|
|
|
118
184
|
.command('get')
|
|
119
185
|
.description('Fetch implementation pattern files')
|
|
120
186
|
.option('--all', 'Fetch all implement files')
|
|
121
|
-
.option('--lang <language>', 'Filter code to py
|
|
187
|
+
.option('--lang <language>', 'Filter code blocks to one language. Accepts py, python, js, javascript, ts, typescript, go, rust.')
|
|
188
|
+
.option('--context <context>', 'Filter patterns by system context. Accepts web, agentic, rag, batch. Patterns not listed for that context in content/index/context-rules.json are removed.')
|
|
122
189
|
.option('--no-frontmatter', 'Strip YAML frontmatter')
|
|
123
190
|
.argument('[files...]', 'File IDs to fetch')
|
|
124
191
|
.action((files, opts) => {
|
|
125
|
-
|
|
126
|
-
|
|
192
|
+
try {
|
|
193
|
+
const content = get(files, opts);
|
|
194
|
+
console.log(content);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
console.error(chalk.red(err.message));
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
127
199
|
});
|
|
128
200
|
|
|
129
201
|
// ============================================================
|
|
@@ -131,11 +203,46 @@ program
|
|
|
131
203
|
// ============================================================
|
|
132
204
|
program
|
|
133
205
|
.command('verify')
|
|
134
|
-
.description('Fetch verification checklists')
|
|
206
|
+
.description('Fetch verification checklists, or run deterministic auto-verify with --auto')
|
|
135
207
|
.argument('<files...>', 'File IDs to verify')
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
208
|
+
.option('--auto <path>', 'Run deterministic scanner against the project at <path> instead of returning the blank checklist')
|
|
209
|
+
.option('--json', 'Output auto-verify results as JSON (only with --auto)')
|
|
210
|
+
.action((files, opts) => {
|
|
211
|
+
if (!opts.auto) {
|
|
212
|
+
// Backward-compatible behavior: fetch the blank checklist markdown
|
|
213
|
+
const content = verify(files);
|
|
214
|
+
console.log(content);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Auto-verify path
|
|
219
|
+
const { autoVerifyArea, formatTextReport } = require('../lib/auto-verify');
|
|
220
|
+
const projectDir = require('path').resolve(opts.auto);
|
|
221
|
+
if (!require('fs').existsSync(projectDir)) {
|
|
222
|
+
console.error(chalk.red(`Project path does not exist: ${projectDir}`));
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const results = [];
|
|
227
|
+
for (const area of files) {
|
|
228
|
+
try {
|
|
229
|
+
const r = autoVerifyArea(area, projectDir);
|
|
230
|
+
results.push(r);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
console.error(chalk.red(`Error verifying "${area}": ${e.message}`));
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (opts.json) {
|
|
238
|
+
console.log(JSON.stringify(results.length === 1 ? results[0] : results, null, 2));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
for (const r of results) {
|
|
243
|
+
console.log(formatTextReport(r));
|
|
244
|
+
if (results.length > 1) console.log('\n' + '─'.repeat(60) + '\n');
|
|
245
|
+
}
|
|
139
246
|
});
|
|
140
247
|
|
|
141
248
|
// ============================================================
|
|
@@ -150,14 +257,205 @@ program
|
|
|
150
257
|
console.log(content);
|
|
151
258
|
});
|
|
152
259
|
|
|
260
|
+
// ============================================================
|
|
261
|
+
// aigis workflow
|
|
262
|
+
// ============================================================
|
|
263
|
+
program
|
|
264
|
+
.command('workflow')
|
|
265
|
+
.description('Fetch the canonical file layout + wiring contracts for a project type')
|
|
266
|
+
.argument('[type]', 'Workflow type (e.g. fastapi-llm). Omit + use --list to see available.')
|
|
267
|
+
.option('--list', 'List available workflows')
|
|
268
|
+
.action((type, opts) => {
|
|
269
|
+
if (opts.list) {
|
|
270
|
+
const workflows = listWorkflows();
|
|
271
|
+
if (workflows.length === 0) {
|
|
272
|
+
console.log(chalk.dim('No workflow skills found.'));
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
console.log(chalk.bold('Available workflows:\n'));
|
|
276
|
+
for (const w of workflows) console.log(` ${w}`);
|
|
277
|
+
console.log(chalk.dim('\nFetch one with: aigis workflow <type>'));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!type) {
|
|
281
|
+
console.error(chalk.red('Provide a workflow type or pass --list.'));
|
|
282
|
+
console.log(chalk.dim(' aigis workflow fastapi-llm'));
|
|
283
|
+
console.log(chalk.dim(' aigis workflow --list\n'));
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
console.log(getWorkflow(type));
|
|
288
|
+
} catch (err) {
|
|
289
|
+
console.error(chalk.red(err.message));
|
|
290
|
+
const workflows = listWorkflows();
|
|
291
|
+
if (workflows.length > 0) {
|
|
292
|
+
console.log(chalk.dim('\nAvailable workflows: ' + workflows.join(', ')));
|
|
293
|
+
}
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// ============================================================
|
|
299
|
+
// aigis build
|
|
300
|
+
// ============================================================
|
|
301
|
+
program
|
|
302
|
+
.command('build')
|
|
303
|
+
.description('Compose a consolidated governance brief for a feature description')
|
|
304
|
+
.argument('<description>', 'Plain-English description of what you are building (in quotes)')
|
|
305
|
+
.option('--full', 'Force full inlined brief (hard cap at 200k chars)')
|
|
306
|
+
.option('--compact', 'Force compact pointer-only brief (no auto-fallback, no size concern)')
|
|
307
|
+
.option('--list', 'Shape A: print area names + traits + pre-built --confirm/--reject flags only')
|
|
308
|
+
.option('--confirm <ids>', 'Comma-separated low-confidence trigger ids/slugs to confirm (no interactive prompt)')
|
|
309
|
+
.option('--reject <ids>', 'Comma-separated low-confidence trigger ids/slugs to reject (no interactive prompt)')
|
|
310
|
+
.option('--json', 'Output JSON (brief + meta) instead of plain markdown to stdout')
|
|
311
|
+
.action(async (description, opts) => {
|
|
312
|
+
if (opts.full && opts.compact) {
|
|
313
|
+
console.error(chalk.red('Pass --full or --compact, not both.'));
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
if (opts.list && (opts.full || opts.compact)) {
|
|
317
|
+
console.error(chalk.red('--list is independent of --full/--compact; pass only one.'));
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// --list short-circuit (Shape A)
|
|
322
|
+
if (opts.list) {
|
|
323
|
+
try {
|
|
324
|
+
process.stdout.write(buildList({ description }));
|
|
325
|
+
} catch (err) {
|
|
326
|
+
console.error(chalk.red(err.message));
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Decision pipeline matches `aigis classify`: --confirm/--reject flags > interactive (TTY) > non-TTY default-uncertain.
|
|
333
|
+
const confirmIds = opts.confirm ? new Set(opts.confirm.split(',').map((s) => s.trim()).filter(Boolean)) : null;
|
|
334
|
+
const rejectIds = opts.reject ? new Set(opts.reject.split(',').map((s) => s.trim()).filter(Boolean)) : null;
|
|
335
|
+
|
|
336
|
+
if (confirmIds && rejectIds) {
|
|
337
|
+
const overlap = [...confirmIds].filter((x) => rejectIds.has(x));
|
|
338
|
+
if (overlap.length > 0) {
|
|
339
|
+
console.error(chalk.red(`Trigger ${overlap.join(', ')} appears in both --confirm and --reject. Pick one.`));
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// First pass: detect low-conf triggers so we know what to prompt for.
|
|
345
|
+
let firstPass;
|
|
346
|
+
try {
|
|
347
|
+
firstPass = buildList({ description }); // cheap; runs the same pipeline
|
|
348
|
+
} catch (err) {
|
|
349
|
+
console.error(chalk.red(err.message));
|
|
350
|
+
process.exit(1);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Re-run prep to grab the slugs (buildList prints them but we need structured access).
|
|
354
|
+
const { normalizeDescription } = require('../lib/build');
|
|
355
|
+
const { detectTraitsFromText } = require('../lib/keywords');
|
|
356
|
+
const { assignUniqueSlugs } = require('../lib/build');
|
|
357
|
+
const normalized = normalizeDescription(description);
|
|
358
|
+
const det = detectTraitsFromText(normalized);
|
|
359
|
+
const lowConf = assignUniqueSlugs(det.low_confidence_matches);
|
|
360
|
+
|
|
361
|
+
let decisions = {};
|
|
362
|
+
const isTTY = !!process.stdout.isTTY && !!process.stdin.isTTY;
|
|
363
|
+
const usedFlags = !!(confirmIds || rejectIds);
|
|
364
|
+
|
|
365
|
+
if (lowConf.length > 0) {
|
|
366
|
+
if (usedFlags) {
|
|
367
|
+
for (const m of lowConf) {
|
|
368
|
+
if (confirmIds && (confirmIds.has(m.slug) || confirmIds.has(m.id))) decisions[m.slug] = 'yes';
|
|
369
|
+
else if (rejectIds && (rejectIds.has(m.slug) || rejectIds.has(m.id))) decisions[m.slug] = 'no';
|
|
370
|
+
else decisions[m.slug] = 'unsure'; // default-include with uncertainty flag
|
|
371
|
+
}
|
|
372
|
+
} else if (isTTY) {
|
|
373
|
+
decisions = await promptBuildLowConfidence(lowConf);
|
|
374
|
+
} else {
|
|
375
|
+
for (const m of lowConf) decisions[m.slug] = 'unsure';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Pick mode
|
|
380
|
+
let mode = 'auto';
|
|
381
|
+
if (opts.full) mode = 'full';
|
|
382
|
+
else if (opts.compact) mode = 'compact';
|
|
383
|
+
|
|
384
|
+
let result;
|
|
385
|
+
try {
|
|
386
|
+
result = buildBrief({ description, decisions, mode });
|
|
387
|
+
} catch (err) {
|
|
388
|
+
if (err instanceof BriefTooLargeError) {
|
|
389
|
+
console.error(chalk.red(err.message));
|
|
390
|
+
process.exit(2);
|
|
391
|
+
}
|
|
392
|
+
console.error(chalk.red(err.message));
|
|
393
|
+
process.exit(1);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (result.auto_fallback) {
|
|
397
|
+
console.error(chalk.yellow(
|
|
398
|
+
`Brief exceeded ${result.auto_fallback_full_cap.toLocaleString()} chars with full content inlined ` +
|
|
399
|
+
`(${result.auto_fallback_full_chars.toLocaleString()} chars). Falling back to compact mode (pointers only). ` +
|
|
400
|
+
`Run \`aigis build "${result.meta.normalized_description}" --full\` to force full content — you may need to ` +
|
|
401
|
+
`split the build into per-domain runs if the brief is still too large.`
|
|
402
|
+
));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (opts.json) {
|
|
406
|
+
console.log(JSON.stringify({ brief: result.brief, meta: result.meta, mode: result.mode, auto_fallback: result.auto_fallback }, null, 2));
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
process.stdout.write(result.brief);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// ============================================================
|
|
414
|
+
// aigis infra
|
|
415
|
+
// ============================================================
|
|
416
|
+
program
|
|
417
|
+
.command('infra')
|
|
418
|
+
.description('Fetch infrastructure setup content (rate-limiting, secrets, logging)')
|
|
419
|
+
.argument('[area]', 'Infrastructure area (e.g. rate-limiting). Omit + use --list to see available.')
|
|
420
|
+
.option('--list', 'List available infrastructure areas')
|
|
421
|
+
.action((area, opts) => {
|
|
422
|
+
if (opts.list) {
|
|
423
|
+
const infras = listInfras();
|
|
424
|
+
if (infras.length === 0) {
|
|
425
|
+
console.log(chalk.dim('No infrastructure areas found.'));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
console.log(chalk.bold('Available infrastructure areas:\n'));
|
|
429
|
+
for (const i of infras) console.log(` ${i}`);
|
|
430
|
+
console.log(chalk.dim('\nFetch one with: aigis infra <area>'));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (!area) {
|
|
434
|
+
console.error(chalk.red('Provide an infrastructure area or pass --list.'));
|
|
435
|
+
console.log(chalk.dim(' aigis infra rate-limiting'));
|
|
436
|
+
console.log(chalk.dim(' aigis infra --list\n'));
|
|
437
|
+
process.exit(1);
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
console.log(getInfra(area));
|
|
441
|
+
} catch (err) {
|
|
442
|
+
console.error(chalk.red(err.message));
|
|
443
|
+
const infras = listInfras();
|
|
444
|
+
if (infras.length > 0) {
|
|
445
|
+
console.log(chalk.dim('\nAvailable areas: ' + infras.join(', ')));
|
|
446
|
+
}
|
|
447
|
+
process.exit(1);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
153
451
|
// ============================================================
|
|
154
452
|
// aigis audit
|
|
155
453
|
// ============================================================
|
|
156
454
|
program
|
|
157
455
|
.command('audit')
|
|
158
456
|
.description('Audit an existing codebase for governance gaps')
|
|
159
|
-
.option('--scan', 'Get structured
|
|
160
|
-
.option('--traits <traits>', 'Run audit
|
|
457
|
+
.option('--scan', 'Get structured discovery prompt (Phases 1-3: inventory, trait detection, classify handoff)')
|
|
458
|
+
.option('--traits <traits>', 'Run scoped audit: classify + checklists only for recommended areas. Prints deterministic denominator.')
|
|
161
459
|
.option('--json', 'Output as JSON')
|
|
162
460
|
.action((opts) => {
|
|
163
461
|
if (opts.scan) {
|
|
@@ -170,33 +468,62 @@ program
|
|
|
170
468
|
const traits = opts.traits.split(',').map(t => t.trim());
|
|
171
469
|
const classification = classify(traits);
|
|
172
470
|
|
|
471
|
+
// Count checks per scoped area by parsing checklist rows (format: "| V<n> | ...").
|
|
472
|
+
// This gives the deterministic denominator the agent must score against.
|
|
473
|
+
const checklistsByArea = {};
|
|
474
|
+
const perAreaCounts = {};
|
|
475
|
+
let totalChecks = 0;
|
|
476
|
+
for (const f of classification.implement_files) {
|
|
477
|
+
const checklist = verify([f]);
|
|
478
|
+
checklistsByArea[f] = checklist;
|
|
479
|
+
const rowMatches = checklist.match(/^\| V\d+\b/gm) || [];
|
|
480
|
+
perAreaCounts[f] = rowMatches.length;
|
|
481
|
+
totalChecks += rowMatches.length;
|
|
482
|
+
}
|
|
483
|
+
const areasCsv = classification.implement_files.join(', ');
|
|
484
|
+
const scoreLineTemplate = `Score: <P> / ${totalChecks} total checks across ${classification.implement_files.length} recommended areas (areas: ${areasCsv})`;
|
|
485
|
+
|
|
173
486
|
if (opts.json) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
checklists
|
|
177
|
-
|
|
178
|
-
|
|
487
|
+
console.log(JSON.stringify({
|
|
488
|
+
classification,
|
|
489
|
+
checklists: checklistsByArea,
|
|
490
|
+
score_template: {
|
|
491
|
+
total_checks: totalChecks,
|
|
492
|
+
recommended_areas_count: classification.implement_files.length,
|
|
493
|
+
recommended_areas: classification.implement_files,
|
|
494
|
+
per_area_check_count: perAreaCounts,
|
|
495
|
+
score_line_template: scoreLineTemplate,
|
|
496
|
+
},
|
|
497
|
+
}, null, 2));
|
|
179
498
|
return;
|
|
180
499
|
}
|
|
181
500
|
|
|
182
501
|
// Formatted audit output
|
|
183
502
|
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'));
|
|
503
|
+
console.log(chalk.bold('═══ AIGIS GOVERNANCE AUDIT (SCOPED) ═══\n'));
|
|
185
504
|
console.log(`${chalk.bold('Risk tier:')} ${tierColor.bold(classification.risk_tier)}`);
|
|
186
|
-
console.log(`${chalk.bold('
|
|
505
|
+
console.log(`${chalk.bold('Recommended areas:')} ${classification.implement_files.length}`);
|
|
506
|
+
console.log(`${chalk.bold('Areas:')} ${areasCsv}`);
|
|
507
|
+
console.log(`${chalk.bold('Total checks (deterministic denominator):')} ${totalChecks}\n`);
|
|
187
508
|
|
|
188
509
|
console.log(chalk.bold('Instructions for agent:'));
|
|
189
510
|
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")
|
|
511
|
+
console.log(chalk.dim('Mark PASS / FAIL / PARTIAL with evidence (file:line or "not found").'));
|
|
512
|
+
console.log(chalk.dim('At the end of your report, emit this exact line (replace <P> with the PASS count):'));
|
|
513
|
+
console.log(chalk.dim(` ${scoreLineTemplate}\n`));
|
|
191
514
|
|
|
192
515
|
for (const f of classification.implement_files) {
|
|
193
|
-
|
|
194
|
-
console.log(checklist);
|
|
516
|
+
console.log(checklistsByArea[f]);
|
|
195
517
|
console.log('');
|
|
196
518
|
}
|
|
197
519
|
|
|
520
|
+
console.log(chalk.bold('═══ SCORING ═══'));
|
|
521
|
+
console.log(`Denominator: ${totalChecks} total checks across ${classification.implement_files.length} recommended areas.`);
|
|
522
|
+
console.log(`Areas: ${areasCsv}`);
|
|
523
|
+
console.log(`Emit at end of report: ${chalk.bold(scoreLineTemplate)}`);
|
|
524
|
+
|
|
198
525
|
if (classification.templates.length > 0) {
|
|
199
|
-
console.log(chalk.bold('Required documentation:'));
|
|
526
|
+
console.log('\n' + chalk.bold('Required documentation:'));
|
|
200
527
|
for (const t of classification.templates) {
|
|
201
528
|
console.log(chalk.yellow(` aigis template ${t}`));
|
|
202
529
|
}
|
|
@@ -307,10 +634,11 @@ program
|
|
|
307
634
|
// ============================================================
|
|
308
635
|
program
|
|
309
636
|
.command('init')
|
|
310
|
-
.description('Set up aigis for your IDE')
|
|
637
|
+
.description('Set up aigis for your IDE (writes core skill + resolver block)')
|
|
311
638
|
.argument('<ide>', 'IDE to configure: cursor, claude-code, windsurf, copilot')
|
|
312
|
-
.
|
|
313
|
-
|
|
639
|
+
.option('--refresh', 'Overwrite existing aigis content (destructive — use after Aigis updates or to fix a stale resolver block checksum)')
|
|
640
|
+
.action((ide, opts) => {
|
|
641
|
+
init(ide, { refresh: !!opts.refresh });
|
|
314
642
|
});
|
|
315
643
|
|
|
316
644
|
// ============================================================
|
|
@@ -334,4 +662,63 @@ program
|
|
|
334
662
|
}
|
|
335
663
|
});
|
|
336
664
|
|
|
665
|
+
// ── helper: interactive prompt for low-confidence triggers in `aigis build` ──
|
|
666
|
+
// Mirrors promptLowConfidence's vocabulary (y/n/u) but defaults to 'u' (unsure → include with ⚠ flag in brief), per Step 8 design.
|
|
667
|
+
async function promptBuildLowConfidence(lowConf) {
|
|
668
|
+
const decisions = {};
|
|
669
|
+
console.log(chalk.bold('\n═══ AIGIS BUILD — low-confidence triggers ═══'));
|
|
670
|
+
console.log(chalk.dim(`Default for each is "unsure" → trait is included in the brief with a ⚠ flag for the agent to surface to you.\n`));
|
|
671
|
+
|
|
672
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
673
|
+
const ask = (q) => new Promise((res) => rl.question(q, res));
|
|
674
|
+
|
|
675
|
+
for (const m of lowConf) {
|
|
676
|
+
console.log(chalk.bold(` [${m.slug}] "${m.phrase}"`));
|
|
677
|
+
console.log(chalk.dim(` Suggested traits: ${m.traits.join(', ')}`));
|
|
678
|
+
console.log(` ${m.confirmation_prompt}`);
|
|
679
|
+
const ans = (await ask(' (y)es / (n)o / (u)nsure [u]: ')).trim().toLowerCase();
|
|
680
|
+
let decision;
|
|
681
|
+
if (ans === '' || ans === 'u' || ans === 'unsure') decision = 'unsure';
|
|
682
|
+
else if (ans === 'y' || ans === 'yes') decision = 'yes';
|
|
683
|
+
else if (ans === 'n' || ans === 'no') decision = 'no';
|
|
684
|
+
else { console.log(chalk.dim(` (unrecognized — defaulting to 'unsure')`)); decision = 'unsure'; }
|
|
685
|
+
decisions[m.slug] = decision;
|
|
686
|
+
console.log('');
|
|
687
|
+
}
|
|
688
|
+
rl.close();
|
|
689
|
+
return decisions;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// ── helper: interactive prompt for low-confidence resolver suggestions ──
|
|
693
|
+
async function promptLowConfidence(detection) {
|
|
694
|
+
const decisions = {};
|
|
695
|
+
console.log(chalk.bold('\n═══ AIGIS RESOLVER ═══'));
|
|
696
|
+
if (detection.high_confidence_matches.length > 0) {
|
|
697
|
+
console.log(chalk.bold('\nHigh-confidence triggers (auto-applied):'));
|
|
698
|
+
for (const m of detection.high_confidence_matches) {
|
|
699
|
+
console.log(` ${chalk.green('✓')} "${m.phrase}" → ${m.traits.join(', ')}`);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
console.log(chalk.bold(`\nLow-confidence triggers (need your input — ${detection.low_confidence_matches.length}):`));
|
|
703
|
+
|
|
704
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
705
|
+
const ask = (q) => new Promise((res) => rl.question(q, res));
|
|
706
|
+
|
|
707
|
+
for (const sug of detection.low_confidence_matches) {
|
|
708
|
+
console.log(chalk.bold(`\n [${sug.id}] "${sug.phrase}"`));
|
|
709
|
+
console.log(chalk.dim(` Suggested traits: ${sug.traits.join(', ')}`));
|
|
710
|
+
console.log(` ${sug.confirmation_prompt}`);
|
|
711
|
+
const ans = (await ask(' (y)es / (n)o / (u)nsure [n]: ')).trim().toLowerCase();
|
|
712
|
+
let decision;
|
|
713
|
+
if (ans === '' || ans === 'n' || ans === 'no') decision = 'no';
|
|
714
|
+
else if (ans === 'y' || ans === 'yes') decision = 'yes';
|
|
715
|
+
else if (ans === 'u' || ans === 'unsure') decision = 'unsure';
|
|
716
|
+
else { console.log(chalk.dim(` (unrecognized — defaulting to 'no')`)); decision = 'no'; }
|
|
717
|
+
decisions[sug.id] = decision;
|
|
718
|
+
}
|
|
719
|
+
rl.close();
|
|
720
|
+
console.log('');
|
|
721
|
+
return decisions;
|
|
722
|
+
}
|
|
723
|
+
|
|
337
724
|
program.parse();
|