Repository navigation
Expand file tree
/
Copy pathaudit-agents.js
More file actions
164 lines (142 loc) · 4.43 KB
/
Copy pathaudit-agents.js
File metadata and controls
164 lines (142 loc) · 4.43 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env node
/**
* Master Audit Script: Agent Structure Standardization
* Orchestrates all audit operations (broken refs, structure, deduplication, registries)
* Phase 2 Foundational infrastructure
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import Reporter from './lib/reporting.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Configuration
const CONFIG_PATH = path.join(__dirname, 'config.json');
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
class AgentAudit {
constructor(options = {}) {
this.reporter = new Reporter({
verbose: options.verbose || false,
outputDir: config.reportOutputDir,
format: 'json',
});
this.config = config;
this.results = new Map();
}
/**
* Initialize audit environment
*/
async initialize() {
this.reporter.log('Initializing agent audit system...', 'info');
// Verify directories exist
const dirs = [
config.reportOutputDir,
config.specReportOutputDir,
...config.agentPaths,
...config.skillPaths,
];
for (const dir of dirs) {
if (!fs.existsSync(dir)) {
this.reporter.debug(`Directory not found: ${dir}`);
}
}
this.reporter.log('Audit environment initialized ✓', 'info');
}
/**
* Run all audits
*/
async runAllAudits(_options = {}) {
try {
await this.initialize();
this.reporter.startReport('master-audit', 'Master audit report for agent restructuring');
// Phase 2 Foundational work will implement these
const audits = [
{ name: 'file-scan', description: 'Scan agent and skill files' },
{ name: 'broken-refs', description: 'Identify broken references' },
{ name: 'structure', description: 'Validate agent structure conformance' },
{ name: 'dedup', description: 'Detect duplicate skills' },
{ name: 'registry', description: 'Validate registry schemas' },
{ name: 'compliance', description: 'Check agentskills.io compliance' },
];
for (const audit of audits) {
this.reporter.log(`Running ${audit.name} audit: ${audit.description}`, 'info');
this.reporter.startReport(audit.name, audit.description);
// Implementation in Phase 2 tasks T010-T017
this.reporter.updateStats(audit.name, { status: 'pending', tasksRemaining: 'Phase 2' });
}
this.reporter.log('All audits queued. Phase 2 implementation will complete these.', 'info');
return this.results;
} catch (error) {
this.reporter.log(`Audit failed: ${error.message}`, 'error');
throw error;
}
}
/**
* Run specific audit
*/
async runAudit(auditName, _options = {}) {
this.reporter.log(`Running ${auditName} audit...`, 'info');
// Implementation per Phase 2 task specs
return { status: 'pending', message: 'Phase 2 implementation required' };
}
/**
* Get audit summary
*/
getSummary() {
return this.reporter.generateSummary();
}
/**
* Save all reports
*/
saveReports() {
const reports = Array.from(this.reporter.reports.keys());
for (const reportName of reports) {
this.reporter.saveReport(reportName, `${reportName}.json`);
}
this.reporter.log(`Saved ${reports.length} reports`, 'info');
}
}
/**
* CLI Interface
*/
async function main() {
const args = process.argv.slice(2);
const command = args[0] || 'all';
try {
const audit = new AgentAudit({ verbose: args.includes('--verbose') });
switch (command) {
case 'all':
await audit.runAllAudits();
audit.saveReports();
console.log('\nAudit Summary:');
console.log(JSON.stringify(audit.getSummary(), null, 2));
break;
case 'broken-refs':
await audit.runAudit('broken-refs');
break;
case 'structure':
await audit.runAudit('structure');
break;
case 'dedup':
await audit.runAudit('dedup');
break;
case 'registry':
await audit.runAudit('registry');
break;
case 'compliance':
await audit.runAudit('compliance');
break;
default:
console.error(`Unknown command: ${command}`);
process.exit(1);
}
} catch (error) {
console.error('Fatal error:', error.message);
process.exit(1);
}
}
main().catch((error) => {
console.error('Unhandled error:', error);
process.exit(1);
});
export { AgentAudit };