@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.
Files changed (47) hide show
  1. package/CONTRIBUTING.md +53 -0
  2. package/README.md +58 -188
  3. package/SKILL.md +20 -55
  4. package/aigis-ai-cli-2.0.1.tgz +0 -0
  5. package/bin/aigis.js +446 -59
  6. package/content/index/audit-scan.md +21 -207
  7. package/content/index/auto-verify-rules.json +439 -0
  8. package/content/index/context-rules.json +90 -0
  9. package/content/resolvers/triggers.json +229 -0
  10. package/content/{implement → skills/areas}/audit-logging.md +5 -0
  11. package/content/skills/areas/fallback-patterns.md +200 -0
  12. package/content/skills/areas/input-validation.md +380 -0
  13. package/content/skills/areas/pii-handling.md +189 -0
  14. package/content/skills/areas/rate-limiting.md +246 -0
  15. package/content/skills/core.md +62 -0
  16. package/content/skills/infrastructure/logging.md +202 -0
  17. package/content/skills/infrastructure/rate-limiting.md +169 -0
  18. package/content/skills/infrastructure/secrets.md +167 -0
  19. package/content/skills/workflows/fastapi-llm.md +86 -0
  20. package/docs/resolvers.md +114 -0
  21. package/lib/auto-verify.js +378 -0
  22. package/lib/build.js +629 -0
  23. package/lib/checksum.js +39 -0
  24. package/lib/fetch.js +164 -9
  25. package/lib/init.js +141 -93
  26. package/lib/keywords.js +92 -130
  27. package/lib/special-recognizers.js +370 -0
  28. package/package.json +1 -1
  29. package/scripts/baseline-cursorrules.snapshot.txt +30 -0
  30. package/scripts/bootstrap-step-6-bench.js +85 -0
  31. package/scripts/check-content-sync.js +91 -0
  32. package/scripts/triggers.schema.json +50 -0
  33. package/scripts/validate-triggers.js +176 -0
  34. package/content/implement/fallback-patterns.md +0 -190
  35. package/content/implement/input-validation.md +0 -212
  36. package/content/implement/pii-handling.md +0 -207
  37. package/content/implement/rate-limiting.md +0 -217
  38. /package/content/{implement → skills/areas}/bias-monitoring.md +0 -0
  39. /package/content/{implement → skills/areas}/confidence-scoring.md +0 -0
  40. /package/content/{implement → skills/areas}/data-integrity.md +0 -0
  41. /package/content/{implement → skills/areas}/explainability.md +0 -0
  42. /package/content/{implement → skills/areas}/human-oversight.md +0 -0
  43. /package/content/{implement → skills/areas}/monitoring.md +0 -0
  44. /package/content/{implement → skills/areas}/output-sanitization.md +0 -0
  45. /package/content/{implement → skills/areas}/prompt-security.md +0 -0
  46. /package/content/{implement → skills/areas}/rag-security.md +0 -0
  47. /package/content/{implement → skills/areas}/supply-chain.md +0 -0
@@ -0,0 +1,378 @@
1
+ /**
2
+ * auto-verify.js — deterministic scanner for `aigis verify <area> --auto <path>`.
3
+ *
4
+ * Philosophy: heuristic regex over the project's source files. Each rule
5
+ * declares patterns; if ANY pattern matches ANY scanned file, the rule is
6
+ * PASS. Some rules are inverse: presence of the pattern = FAIL (anti-pattern
7
+ * detectors, e.g. `eval(`).
8
+ *
9
+ * Out of scope: AST parsing, cross-file flow analysis. Those would raise
10
+ * confidence but also lock the scanner to specific languages. Regex keeps
11
+ * the scanner language-agnostic for Python, JS, TS, and Go without extra
12
+ * infra.
13
+ *
14
+ * Rules live in content/index/auto-verify-rules.json.
15
+ * Special recognizers (overclaim detectors) live in lib/special-recognizers.js.
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const { REGISTRY: SPECIAL } = require('./special-recognizers');
21
+
22
+ const RULES_PATH = path.join(__dirname, '..', 'content', 'index', 'auto-verify-rules.json');
23
+
24
+ // Default glob: scan typical source files, skip noise.
25
+ const DEFAULT_INCLUDE_EXTS = new Set([
26
+ '.py', '.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs', '.go', '.rb', '.java', '.kt',
27
+ ]);
28
+ const DEFAULT_CONFIG_FILES = new Set([
29
+ 'package.json', 'requirements.txt', 'pyproject.toml', 'Pipfile', 'Pipfile.lock',
30
+ 'poetry.lock', 'go.mod', 'Gemfile', 'Gemfile.lock', 'pom.xml',
31
+ ]);
32
+ const SKIP_DIRS = new Set([
33
+ 'node_modules', '.venv', 'venv', 'env', '__pycache__', '.pytest_cache',
34
+ 'dist', 'build', '.git', '.tox', 'target', 'coverage', '.next', '.nuxt',
35
+ '.cache', '.idea', '.vscode',
36
+ ]);
37
+
38
+ function loadRules() {
39
+ const raw = fs.readFileSync(RULES_PATH, 'utf8');
40
+ const parsed = JSON.parse(raw);
41
+ // Strip _schema_* helper keys so they don't appear as areas
42
+ const cleaned = {};
43
+ for (const [k, v] of Object.entries(parsed)) {
44
+ if (k.startsWith('_schema_')) continue;
45
+ cleaned[k] = v;
46
+ }
47
+ return cleaned;
48
+ }
49
+
50
+ function* walkFiles(rootDir) {
51
+ const stack = [rootDir];
52
+ while (stack.length) {
53
+ const dir = stack.pop();
54
+ let entries;
55
+ try {
56
+ entries = fs.readdirSync(dir, { withFileTypes: true });
57
+ } catch {
58
+ continue;
59
+ }
60
+ for (const entry of entries) {
61
+ const full = path.join(dir, entry.name);
62
+ if (entry.isDirectory()) {
63
+ if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.') && !['', '.'].includes(entry.name)) {
64
+ // Skip hidden and heavy dirs, except allow the root itself
65
+ if (SKIP_DIRS.has(entry.name)) continue;
66
+ if (entry.name.startsWith('.')) continue;
67
+ }
68
+ stack.push(full);
69
+ } else if (entry.isFile()) {
70
+ const ext = path.extname(entry.name);
71
+ if (DEFAULT_INCLUDE_EXTS.has(ext) || DEFAULT_CONFIG_FILES.has(entry.name)) {
72
+ yield full;
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ function loadFiles(rootDir) {
80
+ const files = [];
81
+ for (const p of walkFiles(rootDir)) {
82
+ try {
83
+ const content = fs.readFileSync(p, 'utf8');
84
+ const relPath = path.relative(rootDir, p);
85
+ files.push({ path: relPath, absolutePath: p, content });
86
+ } catch {
87
+ // skip unreadable
88
+ }
89
+ }
90
+ return files;
91
+ }
92
+
93
+ /**
94
+ * Special rule type: exists_path. Returns PASS if any file in the project
95
+ * matches any of the listed path globs. Used for "does a tests/ directory
96
+ * exist" style checks that are filename-based, not content-based.
97
+ */
98
+ function existsPathRule(rule, files) {
99
+ const globs = rule.path_globs || [];
100
+ const evidence = [];
101
+ for (const { path: relPath } of files) {
102
+ for (const g of globs) {
103
+ if (matchesGlob(relPath, g)) {
104
+ evidence.push({ file: relPath, line: 1, snippet: '(path match)', pattern: 0 });
105
+ if (evidence.length >= 5) break;
106
+ }
107
+ }
108
+ if (evidence.length >= 5) break;
109
+ }
110
+ return {
111
+ status: evidence.length > 0 ? 'PASS' : 'FAIL',
112
+ evidence,
113
+ matched_patterns: evidence.length > 0 ? [0] : [],
114
+ total_patterns: 1,
115
+ inverse: false,
116
+ require: 'any',
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Scan files for a rule. Returns { status, evidence, matched } where
122
+ * evidence is an array of { file, line, snippet } for the first handful
123
+ * of matches.
124
+ */
125
+ function scanRule(rule, files) {
126
+ if (rule.type === 'exists_path') {
127
+ return existsPathRule(rule, files);
128
+ }
129
+ // Compile with 'gmi' (case-insensitive) by default. Identifier-level
130
+ // patterns are almost always case-mixed in practice (X-User-Id vs
131
+ // x-user-id; API_KEY vs api_key), and false positives from case-folding
132
+ // on identifier regexes are rare in our use case.
133
+ const flags = rule.case_sensitive ? 'gm' : 'gmi';
134
+ const patterns = (rule.patterns || []).map((p) => {
135
+ try {
136
+ return new RegExp(p, flags);
137
+ } catch {
138
+ return new RegExp(p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), flags);
139
+ }
140
+ });
141
+ const require = rule.require || 'any';
142
+ const inverse = !!rule.inverse;
143
+ const maxEvidence = 5;
144
+
145
+ const matchedPatterns = new Set();
146
+ const evidence = [];
147
+ for (const { path: relPath, content } of files) {
148
+ const lines = content.split('\n');
149
+ for (let i = 0; i < patterns.length; i++) {
150
+ if (matchedPatterns.has(i) && evidence.length >= maxEvidence) continue;
151
+ const re = patterns[i];
152
+ re.lastIndex = 0;
153
+ const matches = content.matchAll(re);
154
+ for (const m of matches) {
155
+ matchedPatterns.add(i);
156
+ if (evidence.length < maxEvidence) {
157
+ // Compute line number from match index
158
+ const before = content.slice(0, m.index);
159
+ const line = (before.match(/\n/g) || []).length + 1;
160
+ const snippet = (lines[line - 1] || '').trim().slice(0, 160);
161
+ evidence.push({ file: relPath, line, snippet, pattern: i });
162
+ }
163
+ if (evidence.length >= maxEvidence) break;
164
+ }
165
+ if (evidence.length >= maxEvidence) break;
166
+ }
167
+ if (evidence.length >= maxEvidence && (require === 'any' || matchedPatterns.size === patterns.length)) break;
168
+ }
169
+
170
+ let passed;
171
+ if (require === 'all') {
172
+ passed = matchedPatterns.size === patterns.length;
173
+ } else {
174
+ passed = matchedPatterns.size >= 1;
175
+ }
176
+ // Inverse rules: presence of pattern = FAIL
177
+ if (inverse) {
178
+ passed = !passed;
179
+ }
180
+
181
+ return {
182
+ status: passed ? 'PASS' : 'FAIL',
183
+ evidence,
184
+ matched_patterns: [...matchedPatterns],
185
+ total_patterns: patterns.length,
186
+ inverse,
187
+ require,
188
+ };
189
+ }
190
+
191
+ function runSpecialRecognizer(name, files, ctx) {
192
+ const fn = SPECIAL[name];
193
+ if (!fn) {
194
+ return {
195
+ flagged: false,
196
+ evidence: [],
197
+ notes: `Unknown recognizer: ${name}`,
198
+ };
199
+ }
200
+ return fn(files, ctx);
201
+ }
202
+
203
+ /**
204
+ * Given a pattern-area id (e.g. 'input-validation') and a project
205
+ * directory, run all AUTO and OVERCLAIM rules and return a structured
206
+ * result the CLI can format.
207
+ */
208
+ function autoVerifyArea(areaId, projectDir) {
209
+ const rules = loadRules();
210
+ const area = rules[areaId];
211
+ if (!area) {
212
+ throw new Error(`No auto-verify rules for pattern area "${areaId}". Known areas: ${Object.keys(rules).join(', ')}`);
213
+ }
214
+
215
+ const files = loadFiles(projectDir);
216
+
217
+ const autoResults = {};
218
+ for (const [checkId, rule] of Object.entries(area.auto || {})) {
219
+ // Optional per-rule file glob override is not implemented here — we scan the
220
+ // default set, then filter by the rule's hint if provided. Simple filter for
221
+ // supply-chain V5 / V3 style where we want e.g. requirements.txt specifically.
222
+ let scanFiles = files;
223
+ if (rule.file_glob) {
224
+ const globs = rule.file_glob.split(',').map((g) => g.trim());
225
+ scanFiles = files.filter((f) => globs.some((g) => matchesGlob(f.path, g)));
226
+ }
227
+ autoResults[checkId] = { ...rule, ...scanRule(rule, scanFiles) };
228
+ }
229
+
230
+ const overclaimResults = {};
231
+ for (const [checkId, entry] of Object.entries(area.overclaim || {})) {
232
+ const recog = runSpecialRecognizer(entry.recognizer, files, {
233
+ rootDir: projectDir, areaId, checkId,
234
+ });
235
+ // An overclaim raises concern only if the corresponding auto rule (also_auto) was PASS.
236
+ const alsoAuto = entry.also_auto;
237
+ let raise = recog.flagged;
238
+ if (alsoAuto && autoResults[alsoAuto] && autoResults[alsoAuto].status !== 'PASS') {
239
+ raise = false; // auto didn't pass, the overclaim question is moot
240
+ }
241
+ overclaimResults[checkId] = {
242
+ desc: entry.desc,
243
+ recognizer: entry.recognizer,
244
+ also_auto: alsoAuto,
245
+ raised: raise,
246
+ flagged: recog.flagged,
247
+ evidence: recog.evidence,
248
+ notes: recog.notes,
249
+ };
250
+ }
251
+
252
+ const judgmentResults = {};
253
+ for (const [checkId, desc] of Object.entries(area.judgment || {})) {
254
+ judgmentResults[checkId] = { desc, status: 'JUDGMENT' };
255
+ }
256
+
257
+ // Summary
258
+ const autoList = Object.entries(autoResults);
259
+ const autoPass = autoList.filter(([, r]) => r.status === 'PASS').length;
260
+ const autoFail = autoList.filter(([, r]) => r.status === 'FAIL').length;
261
+ const overclaimsRaised = Object.values(overclaimResults).filter((r) => r.raised).length;
262
+ const judgmentCount = Object.keys(judgmentResults).length;
263
+
264
+ return {
265
+ area: areaId,
266
+ project_dir: projectDir,
267
+ files_scanned: files.length,
268
+ summary: {
269
+ auto_total: autoList.length,
270
+ auto_pass: autoPass,
271
+ auto_fail: autoFail,
272
+ overclaims_raised: overclaimsRaised,
273
+ judgment_required: judgmentCount,
274
+ },
275
+ auto_checks: autoResults,
276
+ overclaim_checks: overclaimResults,
277
+ judgment_checks: judgmentResults,
278
+ };
279
+ }
280
+
281
+ // Glob matcher supporting `*` and `**`. `**/` at the start matches any number
282
+ // of leading path segments including zero (so `**/foo/**` matches `foo/bar.py`).
283
+ function matchesGlob(filePath, glob) {
284
+ const norm = filePath.replace(/\\/g, '/');
285
+ let pattern = glob.replace(/\\/g, '/');
286
+ // A leading `**/` should optionally match — `**/tests/**` should match both
287
+ // `app/tests/x.py` and `tests/x.py`.
288
+ let reSrc = pattern
289
+ .replace(/[.+^${}()|[\]]/g, '\\$&')
290
+ .replace(/\*\*\//g, '@@GLOBSTAR_SLASH@@')
291
+ .replace(/\*\*/g, '@@GLOBSTAR@@')
292
+ .replace(/\*/g, '[^/]*')
293
+ .replace(/@@GLOBSTAR_SLASH@@/g, '(?:.*/)?')
294
+ .replace(/@@GLOBSTAR@@/g, '.*');
295
+ const re = new RegExp('^' + reSrc + '$');
296
+ return re.test(norm);
297
+ }
298
+
299
+ /**
300
+ * Format a text report for the CLI. Returns a string.
301
+ */
302
+ function formatTextReport(result) {
303
+ const lines = [];
304
+ lines.push(`═══ AUTO-VERIFY: ${result.area} ═══\n`);
305
+ lines.push(`Project: ${result.project_dir}`);
306
+ lines.push(`Files scanned: ${result.files_scanned}`);
307
+ const s = result.summary;
308
+ lines.push(`Auto-verified: ${s.auto_pass}/${s.auto_total} PASS, ${s.auto_fail} FAIL`);
309
+ lines.push(`Overclaim recognizers raised: ${s.overclaims_raised}`);
310
+ lines.push(`Judgment required: ${s.judgment_required} check(s)\n`);
311
+
312
+ // AUTO section
313
+ if (Object.keys(result.auto_checks).length > 0) {
314
+ lines.push('── AUTO CHECKS ──');
315
+ for (const [checkId, r] of Object.entries(result.auto_checks)) {
316
+ const badge = r.status === 'PASS' ? '[PASS]' : '[FAIL]';
317
+ const inv = r.inverse ? ' (inverse: presence of pattern = FAIL)' : '';
318
+ lines.push(`\n${badge} ${checkId}: ${r.desc}${inv}`);
319
+ if (r.evidence.length > 0) {
320
+ for (const e of r.evidence.slice(0, 3)) {
321
+ lines.push(` ${e.file}:${e.line} ${e.snippet}`);
322
+ }
323
+ } else if (r.status === 'FAIL' && !r.inverse) {
324
+ lines.push(` no matches for any of ${r.total_patterns} pattern(s)`);
325
+ } else if (r.status === 'PASS' && r.inverse) {
326
+ lines.push(` no anti-pattern instances found`);
327
+ }
328
+ }
329
+ lines.push('');
330
+ }
331
+
332
+ // OVERCLAIM section
333
+ if (Object.keys(result.overclaim_checks).length > 0) {
334
+ lines.push('── OVERCLAIM RECOGNIZERS ──');
335
+ for (const [checkId, r] of Object.entries(result.overclaim_checks)) {
336
+ const badge = r.raised ? '[OVERCLAIM RAISED]' : '[no signal]';
337
+ lines.push(`\n${badge} ${checkId}: ${r.desc}`);
338
+ lines.push(` recognizer: ${r.recognizer}`);
339
+ lines.push(` ${r.notes}`);
340
+ if (r.evidence.length > 0) {
341
+ for (const e of r.evidence.slice(0, 3)) {
342
+ lines.push(` ${e.file}:${e.line} ${e.snippet}`);
343
+ }
344
+ }
345
+ }
346
+ lines.push('');
347
+ }
348
+
349
+ // JUDGMENT section
350
+ if (Object.keys(result.judgment_checks).length > 0) {
351
+ lines.push('── JUDGMENT REQUIRED (agent must evaluate) ──');
352
+ for (const [checkId, r] of Object.entries(result.judgment_checks)) {
353
+ lines.push(`\n[JUDGMENT] ${checkId}: ${r.desc}`);
354
+ }
355
+ lines.push('');
356
+ }
357
+
358
+ // Footer
359
+ lines.push('═══ SUMMARY ═══');
360
+ lines.push(`Auto-verified: ${s.auto_pass} PASS, ${s.auto_fail} FAIL out of ${s.auto_total} automatic checks`);
361
+ lines.push(`Overclaim flags raised: ${s.overclaims_raised}`);
362
+ lines.push(`Judgment required: ${s.judgment_required} checks`);
363
+ lines.push('');
364
+ lines.push('Interpretation:');
365
+ lines.push(' PASS / FAIL are deterministic based on regex match against project files.');
366
+ lines.push(' Overclaim flags mean the literal checklist wording is satisfied but a stricter');
367
+ lines.push(' operational bar may not be. Mark PARTIAL rather than PASS unless you can');
368
+ lines.push(' rebut the flag with evidence.');
369
+ lines.push(' JUDGMENT checks are not auto-gradable. The agent must evaluate them.');
370
+
371
+ return lines.join('\n');
372
+ }
373
+
374
+ module.exports = {
375
+ autoVerifyArea,
376
+ formatTextReport,
377
+ loadRules,
378
+ };