-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcapabilities-audit.ts
More file actions
41 lines (38 loc) · 1.75 KB
/
Copy pathcapabilities-audit.ts
File metadata and controls
41 lines (38 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Deterministic capability audit over descriptors × the capability ledger.
* Usage:
* pnpm capabilities:audit # human table (gaps/stale/missing)
* pnpm capabilities:audit --json # machine-readable report
* pnpm capabilities:audit --stale 90 # override staleness window (days)
* pnpm capabilities:verify # non-zero if any native/embedded cell lacks provenance
*/
import { loadCapabilityLedger } from '../src/core/capabilities/ledger.js';
import { auditCapabilities } from '../src/core/capabilities/audit.js';
import {
renderAuditReport,
verifyLedgerCoverage,
verifyLedgerIntegrity,
} from '../src/core/capabilities/audit-report.js';
import { TARGET_IDS } from '../src/targets/catalog/target-ids.js';
function flagValue(name: string, fallback: number): number {
const idx = process.argv.indexOf(name);
if (idx === -1 || idx + 1 >= process.argv.length) return fallback;
const parsed = Number.parseInt(process.argv[idx + 1], 10);
return Number.isNaN(parsed) ? fallback : parsed;
}
const today = new Date().toISOString().slice(0, 10);
const staleDays = flagValue('--stale', 180);
const ledger = loadCapabilityLedger();
const report = auditCapabilities({ ledger, today, staleDays });
if (process.argv.includes('--verify')) {
const problems = [...verifyLedgerIntegrity(ledger, [...TARGET_IDS]), ...verifyLedgerCoverage(report)];
if (problems.length > 0) {
process.stderr.write(`capabilities:verify failed:\n${problems.map((p) => ` - ${p}`).join('\n')}\n`);
process.exit(1);
}
process.stdout.write('capabilities:verify OK\n');
} else if (process.argv.includes('--json')) {
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
} else {
process.stdout.write(`${renderAuditReport(report)}\n`);
}