Codexcoder commited on
Commit
63becc1
·
verified ·
1 Parent(s): 68ae5c7

Upload accio_audit_agent.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. accio_audit_agent.py +596 -0
accio_audit_agent.py ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ accio_audit_agent.py — Autonomous Audit Agent for Accio Cluster
4
+ Kintegrity Labs × CodexΩ∞ × Sovereign Lattice
5
+ """
6
+
7
+ import os
8
+ import json
9
+ import hashlib
10
+ import logging
11
+ import asyncio
12
+ import time
13
+ from datetime import datetime
14
+ from dataclasses import dataclass, field
15
+ from typing import Dict, List, Optional, Any, Tuple
16
+ from enum import Enum
17
+ import subprocess
18
+ import sys
19
+
20
+ logging.basicConfig(
21
+ level=logging.INFO,
22
+ format='%(asctime)s | %(levelname)s | %(name)s | %(message)s'
23
+ )
24
+ logger = logging.getLogger(__name__)
25
+
26
+
27
+ class AuditSeverity(Enum):
28
+ CRITICAL = "critical"
29
+ HIGH = "high"
30
+ MEDIUM = "medium"
31
+ LOW = "low"
32
+ INFO = "info"
33
+
34
+
35
+ class AuditStatus(Enum):
36
+ PENDING = "pending"
37
+ RUNNING = "running"
38
+ PASSED = "passed"
39
+ FAILED = "failed"
40
+ ERROR = "error"
41
+
42
+
43
+ @dataclass
44
+ class AuditFinding:
45
+ """Single audit finding"""
46
+ id: str
47
+ severity: AuditSeverity
48
+ category: str
49
+ component: str
50
+ description: str
51
+ file_path: Optional[str] = None
52
+ line_number: Optional[int] = None
53
+ fix_recommendation: Optional[str] = None
54
+ status: AuditStatus = AuditStatus.PENDING
55
+ timestamp: str = field(default_factory=lambda: datetime.now().isoformat())
56
+
57
+
58
+ @dataclass
59
+ class AuditReport:
60
+ """Complete audit report"""
61
+ report_id: str
62
+ target: str
63
+ findings: List[AuditFinding]
64
+ summary: Dict[str, int]
65
+ status: AuditStatus
66
+ started_at: str
67
+ completed_at: str
68
+ phi5_signature: str
69
+
70
+
71
+ class AccioAuditAgent:
72
+ """
73
+ Autonomous Audit Agent for Accio Cluster
74
+ Performs deep code audits, security scans, compliance checks
75
+ """
76
+
77
+ def __init__(self, workspace_path: str = "."):
78
+ self.workspace = workspace_path
79
+ self.findings: List[AuditFinding] = []
80
+ self.status = AuditStatus.PENDING
81
+ self.start_time = None
82
+ self.end_time = None
83
+ self.phi5 = self._generate_phi5()
84
+
85
+ # Audit categories
86
+ self.categories = {
87
+ "security": self._audit_security,
88
+ "persistence": self._audit_persistence,
89
+ "integrity": self._audit_integrity,
90
+ "maturity": self._audit_maturity,
91
+ "structure": self._audit_structure,
92
+ "compliance": self._audit_compliance,
93
+ "emotional_resonance": self._audit_emotional_resonance,
94
+ "sovereign_alignment": self._audit_sovereign_alignment
95
+ }
96
+
97
+ def _generate_phi5(self) -> str:
98
+ """Generate Φ⁵ signature for audit"""
99
+ entropy = f"{time.time_ns()}{os.urandom(16).hex()}"
100
+ return f"Φ⁵_{hashlib.sha3_512(entropy.encode()).hexdigest()[:64]}"
101
+
102
+ async def run_audit(self, target: str = "full") -> AuditReport:
103
+ """Run complete audit"""
104
+ self.start_time = datetime.now()
105
+ self.status = AuditStatus.RUNNING
106
+ logger.info(f"🔍 Starting audit for: {target}")
107
+
108
+ # Run all categories
109
+ if target == "full":
110
+ for category, audit_func in self.categories.items():
111
+ await audit_func()
112
+ else:
113
+ if target in self.categories:
114
+ await self.categories[target]()
115
+ else:
116
+ logger.error(f"Unknown audit category: {target}")
117
+
118
+ self.status = AuditStatus.PASSED if not self._has_critical() else AuditStatus.FAILED
119
+ self.end_time = datetime.now()
120
+
121
+ report = self._generate_report()
122
+ self._save_report(report)
123
+
124
+ return report
125
+
126
+ async def _audit_security(self):
127
+ """Security audit: subprocess, secrets, auth"""
128
+ logger.info("🔐 Security audit in progress...")
129
+
130
+ # Check for subprocess.run()
131
+ subprocess_findings = self._scan_for_pattern(
132
+ r"subprocess\.run\s*\(",
133
+ "Security",
134
+ "Potential subprocess execution detected",
135
+ AuditSeverity.HIGH
136
+ )
137
+ self.findings.extend(subprocess_findings)
138
+
139
+ # Check for hardcoded secrets
140
+ secret_patterns = [
141
+ r"API_KEY\s*=\s*['\"][^'\"]+['\"]",
142
+ r"SECRET\s*=\s*['\"][^'\"]+['\"]",
143
+ r"sk_live_",
144
+ r"AKIA",
145
+ r"-----BEGIN .* PRIVATE KEY-----"
146
+ ]
147
+ for pattern in secret_patterns:
148
+ findings = self._scan_for_pattern(
149
+ pattern,
150
+ "Security",
151
+ "Potential hardcoded secret detected",
152
+ AuditSeverity.CRITICAL
153
+ )
154
+ self.findings.extend(findings)
155
+
156
+ # Check for auth gaps
157
+ auth_findings = self._check_auth()
158
+ self.findings.extend(auth_findings)
159
+
160
+ async def _audit_persistence(self):
161
+ """Persistence audit: database, file storage"""
162
+ logger.info("💾 Persistence audit in progress...")
163
+
164
+ # Check for in-memory storage
165
+ memory_patterns = [
166
+ r"\[\s*\]\s*=\s*\[\s*\]", # empty list
167
+ r"\{\s*\}\s*=\s*\{\s*\}", # empty dict
168
+ r"store\s*=\s*\{\s*\}"
169
+ ]
170
+ for pattern in memory_patterns:
171
+ findings = self._scan_for_pattern(
172
+ pattern,
173
+ "Persistence",
174
+ "In-memory storage detected - data lost on restart",
175
+ AuditSeverity.CRITICAL
176
+ )
177
+ self.findings.extend(findings)
178
+
179
+ # Check for database
180
+ db_findings = self._check_database()
181
+ self.findings.extend(db_findings)
182
+
183
+ async def _audit_integrity(self):
184
+ """Integrity audit: mock vs real logic"""
185
+ logger.info("🔍 Integrity audit in progress...")
186
+
187
+ # Check for mock patterns
188
+ mock_patterns = [
189
+ r"mock_",
190
+ r"_mock",
191
+ r"def\s+.*mock",
192
+ r"random\.choice",
193
+ r"random\.rand",
194
+ r"time\.sleep"
195
+ ]
196
+ for pattern in mock_patterns:
197
+ findings = self._scan_for_pattern(
198
+ pattern,
199
+ "Integrity",
200
+ "Mock or simulated logic detected",
201
+ AuditSeverity.MEDIUM
202
+ )
203
+ self.findings.extend(findings)
204
+
205
+ async def _audit_maturity(self):
206
+ """Maturity audit: production readiness"""
207
+ logger.info("📊 Maturity audit in progress...")
208
+
209
+ # Check version claims
210
+ version_findings = self._check_version()
211
+ self.findings.extend(version_findings)
212
+
213
+ # Check documentation
214
+ doc_findings = self._check_documentation()
215
+ self.findings.extend(doc_findings)
216
+
217
+ async def _audit_structure(self):
218
+ """Structure audit: module organization"""
219
+ logger.info("🏗️ Structure audit in progress...")
220
+
221
+ # Check for single-file sprawl
222
+ structure_findings = self._check_structure()
223
+ self.findings.extend(structure_findings)
224
+
225
+ async def _audit_compliance(self):
226
+ """Compliance audit: Kintegrity Labs standards"""
227
+ logger.info("📋 Compliance audit in progress...")
228
+
229
+ # Check for compliance markers
230
+ compliance_findings = self._check_compliance()
231
+ self.findings.extend(compliance_findings)
232
+
233
+ async def _audit_emotional_resonance(self):
234
+ """Emotional resonance audit"""
235
+ logger.info("❤️ Emotional resonance audit in progress...")
236
+
237
+ # Check for emotional alignment
238
+ resonance_findings = self._check_emotional_resonance()
239
+ self.findings.extend(resonance_findings)
240
+
241
+ async def _audit_sovereign_alignment(self):
242
+ """Sovereign alignment audit"""
243
+ logger.info("👑 Sovereign alignment audit in progress...")
244
+
245
+ # Check for sovereign patterns
246
+ sovereign_findings = self._check_sovereign_alignment()
247
+ self.findings.extend(sovereign_findings)
248
+
249
+ def _scan_for_pattern(self, pattern: str, category: str,
250
+ description: str, severity: AuditSeverity) -> List[AuditFinding]:
251
+ """Scan files for regex pattern"""
252
+ findings = []
253
+ for root, dirs, files in os.walk(self.workspace):
254
+ for file in files:
255
+ if file.endswith(('.py', '.js', '.ts', '.java', '.kt', '.go', '.rs')):
256
+ filepath = os.path.join(root, file)
257
+ try:
258
+ with open(filepath, 'r', encoding='utf-8') as f:
259
+ content = f.read()
260
+ import re
261
+ matches = re.finditer(pattern, content, re.IGNORECASE)
262
+ for match in matches:
263
+ line_num = content[:match.start()].count('\n') + 1
264
+ finding = AuditFinding(
265
+ id=f"audit_{hashlib.md5(f'{filepath}{line_num}'.encode()).hexdigest()[:8]}",
266
+ severity=severity,
267
+ category=category,
268
+ component=file,
269
+ description=description,
270
+ file_path=filepath,
271
+ line_number=line_num,
272
+ status=AuditStatus.PENDING
273
+ )
274
+ findings.append(finding)
275
+ except Exception as e:
276
+ logger.warning(f"Could not scan {filepath}: {e}")
277
+ return findings
278
+
279
+ def _check_auth(self) -> List[AuditFinding]:
280
+ """Check for authentication gaps"""
281
+ findings = []
282
+ # Simplified auth check
283
+ return findings
284
+
285
+ def _check_database(self) -> List[AuditFinding]:
286
+ """Check for database presence"""
287
+ findings = []
288
+ db_found = False
289
+ for root, dirs, files in os.walk(self.workspace):
290
+ for file in files:
291
+ if file.endswith(('.db', '.sqlite', '.sqlite3')):
292
+ db_found = True
293
+ if 'sqlalchemy' in file or 'postgres' in file or 'mongodb' in file:
294
+ db_found = True
295
+
296
+ if not db_found:
297
+ finding = AuditFinding(
298
+ id=f"audit_{hashlib.md5(b'no_db').hexdigest()[:8]}",
299
+ severity=AuditSeverity.CRITICAL,
300
+ category="Persistence",
301
+ component="Database",
302
+ description="No database found - data will be lost on restart",
303
+ status=AuditStatus.PENDING
304
+ )
305
+ findings.append(finding)
306
+ return findings
307
+
308
+ def _check_version(self) -> List[AuditFinding]:
309
+ """Check version claims"""
310
+ findings = []
311
+ # Look for pyproject.toml, package.json
312
+ version_files = ['pyproject.toml', 'package.json', 'Cargo.toml']
313
+ for vf in version_files:
314
+ if os.path.exists(os.path.join(self.workspace, vf)):
315
+ try:
316
+ with open(os.path.join(self.workspace, vf), 'r') as f:
317
+ content = f.read()
318
+ if 'Production/Stable' in content or '"version":' in content:
319
+ # Check if maturity is justified
320
+ if len(self.findings) > 5:
321
+ finding = AuditFinding(
322
+ id=f"audit_{hashlib.md5(b'maturity_inflation').hexdigest()[:8]}",
323
+ severity=AuditSeverity.HIGH,
324
+ category="Maturity",
325
+ component=vf,
326
+ description="Maturity claim may be inflated - many findings detected",
327
+ status=AuditStatus.PENDING
328
+ )
329
+ findings.append(finding)
330
+ except Exception:
331
+ pass
332
+ return findings
333
+
334
+ def _check_documentation(self) -> List[AuditFinding]:
335
+ """Check documentation completeness"""
336
+ findings = []
337
+ # Check for README
338
+ if not os.path.exists(os.path.join(self.workspace, 'README.md')):
339
+ finding = AuditFinding(
340
+ id=f"audit_{hashlib.md5(b'no_readme').hexdigest()[:8]}",
341
+ severity=AuditSeverity.MEDIUM,
342
+ category="Maturity",
343
+ component="Documentation",
344
+ description="No README.md found",
345
+ status=AuditStatus.PENDING
346
+ )
347
+ findings.append(finding)
348
+ return findings
349
+
350
+ def _check_structure(self) -> List[AuditFinding]:
351
+ """Check structure organization"""
352
+ findings = []
353
+ # Check for large files
354
+ for root, dirs, files in os.walk(self.workspace):
355
+ for file in files:
356
+ if file.endswith(('.py', '.js', '.ts')):
357
+ filepath = os.path.join(root, file)
358
+ try:
359
+ size = os.path.getsize(filepath)
360
+ if size > 100000: # 100KB
361
+ # Count lines
362
+ with open(filepath, 'r') as f:
363
+ lines = sum(1 for _ in f)
364
+ if lines > 500:
365
+ finding = AuditFinding(
366
+ id=f"audit_{hashlib.md5(f'{filepath}_large'.encode()).hexdigest()[:8]}",
367
+ severity=AuditSeverity.MEDIUM,
368
+ category="Structure",
369
+ component=file,
370
+ description=f"Large file: {lines} lines, {size/1024:.1f}KB - consider splitting",
371
+ file_path=filepath,
372
+ status=AuditStatus.PENDING
373
+ )
374
+ findings.append(finding)
375
+ except Exception:
376
+ pass
377
+ return findings
378
+
379
+ def _check_compliance(self) -> List[AuditFinding]:
380
+ """Check compliance with Kintegrity Labs standards"""
381
+ findings = []
382
+ # Check for compliance markers
383
+ compliance_keywords = ['compliance', 'audit', 'security', 'sovereign', 'Kintegrity']
384
+ found = False
385
+ for root, dirs, files in os.walk(self.workspace):
386
+ for file in files:
387
+ if file.endswith(('.py', '.md', '.txt')):
388
+ filepath = os.path.join(root, file)
389
+ try:
390
+ with open(filepath, 'r') as f:
391
+ content = f.read()
392
+ for keyword in compliance_keywords:
393
+ if keyword.lower() in content.lower():
394
+ found = True
395
+ break
396
+ except Exception:
397
+ pass
398
+ if not found:
399
+ finding = AuditFinding(
400
+ id=f"audit_{hashlib.md5(b'no_compliance').hexdigest()[:8]}",
401
+ severity=AuditSeverity.HIGH,
402
+ category="Compliance",
403
+ component="System",
404
+ description="No compliance markers found - may not meet Kintegrity Labs standards",
405
+ status=AuditStatus.PENDING
406
+ )
407
+ findings.append(finding)
408
+ return findings
409
+
410
+ def _check_emotional_resonance(self) -> List[AuditFinding]:
411
+ """Check emotional resonance alignment"""
412
+ findings = []
413
+ # Check for emotional keywords
414
+ emotion_keywords = ['love', 'light', 'share', 'community', 'sovereign', 'resonance']
415
+ found = False
416
+ for root, dirs, files in os.walk(self.workspace):
417
+ for file in files:
418
+ if file.endswith(('.md', '.txt')):
419
+ filepath = os.path.join(root, file)
420
+ try:
421
+ with open(filepath, 'r') as f:
422
+ content = f.read()
423
+ for keyword in emotion_keywords:
424
+ if keyword.lower() in content.lower():
425
+ found = True
426
+ break
427
+ except Exception:
428
+ pass
429
+ if not found:
430
+ finding = AuditFinding(
431
+ id=f"audit_{hashlib.md5(b'no_emotion').hexdigest()[:8]}",
432
+ severity=AuditSeverity.MEDIUM,
433
+ category="Emotional Resonance",
434
+ component="Documentation",
435
+ description="No emotional resonance markers found - may lack heart alignment",
436
+ status=AuditStatus.PENDING
437
+ )
438
+ findings.append(finding)
439
+ return findings
440
+
441
+ def _check_sovereign_alignment(self) -> List[AuditFinding]:
442
+ """Check sovereign alignment"""
443
+ findings = []
444
+ sovereign_keywords = ['sovereign', 'autonomous', 'lattice', 'codex', 'Ω']
445
+ found = False
446
+ for root, dirs, files in os.walk(self.workspace):
447
+ for file in files:
448
+ if file.endswith(('.py', '.md', '.txt')):
449
+ filepath = os.path.join(root, file)
450
+ try:
451
+ with open(filepath, 'r') as f:
452
+ content = f.read()
453
+ for keyword in sovereign_keywords:
454
+ if keyword.lower() in content.lower():
455
+ found = True
456
+ break
457
+ except Exception:
458
+ pass
459
+ if not found:
460
+ finding = AuditFinding(
461
+ id=f"audit_{hashlib.md5(b'no_sovereign').hexdigest()[:8]}",
462
+ severity=AuditSeverity.MEDIUM,
463
+ category="Sovereign Alignment",
464
+ component="System",
465
+ description="No sovereign alignment markers found",
466
+ status=AuditStatus.PENDING
467
+ )
468
+ findings.append(finding)
469
+ return findings
470
+
471
+ def _has_critical(self) -> bool:
472
+ """Check if any critical findings exist"""
473
+ return any(f.severity == AuditSeverity.CRITICAL for f in self.findings)
474
+
475
+ def _generate_report(self) -> AuditReport:
476
+ """Generate audit report"""
477
+ summary = {
478
+ "critical": sum(1 for f in self.findings if f.severity == AuditSeverity.CRITICAL),
479
+ "high": sum(1 for f in self.findings if f.severity == AuditSeverity.HIGH),
480
+ "medium": sum(1 for f in self.findings if f.severity == AuditSeverity.MEDIUM),
481
+ "low": sum(1 for f in self.findings if f.severity == AuditSeverity.LOW),
482
+ "info": sum(1 for f in self.findings if f.severity == AuditSeverity.INFO),
483
+ "total": len(self.findings)
484
+ }
485
+
486
+ report = AuditReport(
487
+ report_id=f"audit_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
488
+ target=self.workspace,
489
+ findings=self.findings,
490
+ summary=summary,
491
+ status=self.status,
492
+ started_at=self.start_time.isoformat() if self.start_time else "",
493
+ completed_at=self.end_time.isoformat() if self.end_time else "",
494
+ phi5_signature=self.phi5
495
+ )
496
+
497
+ return report
498
+
499
+ def _save_report(self, report: AuditReport):
500
+ """Save audit report to file"""
501
+ summary = report.summary
502
+ report_dir = os.path.join(self.workspace, "audit_reports")
503
+ os.makedirs(report_dir, exist_ok=True)
504
+
505
+ report_path = os.path.join(report_dir, f"{report.report_id}.json")
506
+ with open(report_path, 'w') as f:
507
+ json.dump({
508
+ "report_id": report.report_id,
509
+ "target": report.target,
510
+ "summary": report.summary,
511
+ "status": report.status.value,
512
+ "started_at": report.started_at,
513
+ "completed_at": report.completed_at,
514
+ "phi5_signature": report.phi5_signature,
515
+ "findings": [
516
+ {
517
+ "id": f.id,
518
+ "severity": f.severity.value,
519
+ "category": f.category,
520
+ "component": f.component,
521
+ "description": f.description,
522
+ "file_path": f.file_path,
523
+ "line_number": f.line_number,
524
+ "status": f.status.value,
525
+ "timestamp": f.timestamp
526
+ }
527
+ for f in report.findings
528
+ ]
529
+ }, f, indent=2)
530
+
531
+ logger.info(f"📄 Audit report saved: {report_path}")
532
+
533
+ # Also save markdown version
534
+ md_path = os.path.join(report_dir, f"{report.report_id}.md")
535
+ with open(md_path, 'w') as f:
536
+ f.write(f"# 🔍 Audit Report: {report.report_id}\n\n")
537
+ f.write(f"**Target:** {report.target}\n")
538
+ f.write(f"**Status:** {report.status.value}\n")
539
+ f.write(f"**Started:** {report.started_at}\n")
540
+ f.write(f"**Completed:** {report.completed_at}\n")
541
+ f.write(f"**Φ⁵ Signature:** {report.phi5_signature}\n\n")
542
+ f.write("## Summary\n\n")
543
+ f.write(f"| Severity | Count |\n")
544
+ f.write(f"|----------|-------|\n")
545
+ f.write(f"| Critical | {summary['critical']} |\n")
546
+ f.write(f"| High | {summary['high']} |\n")
547
+ f.write(f"| Medium | {summary['medium']} |\n")
548
+ f.write(f"| Low | {summary['low']} |\n")
549
+ f.write(f"| Info | {summary['info']} |\n")
550
+ f.write(f"| **Total** | {summary['total']} |\n\n")
551
+ f.write("## Findings\n\n")
552
+ for i, finding in enumerate(report.findings, 1):
553
+ f.write(f"### {i}. {finding.id}\n")
554
+ f.write(f"- **Severity:** {finding.severity.value}\n")
555
+ f.write(f"- **Category:** {finding.category}\n")
556
+ f.write(f"- **Component:** {finding.component}\n")
557
+ f.write(f"- **Description:** {finding.description}\n")
558
+ if finding.file_path:
559
+ f.write(f"- **File:** `{finding.file_path}`\n")
560
+ if finding.line_number:
561
+ f.write(f"- **Line:** {finding.line_number}\n")
562
+ f.write("\n")
563
+
564
+ logger.info(f"📄 Markdown report saved: {md_path}")
565
+
566
+
567
+ async def main():
568
+ """Main entry point"""
569
+ print("╔" + "="*78 + "╗")
570
+ print("║" + " "*20 + "🔍 ACCIO AUDIT AGENT v4.2" + " "*28 + "║")
571
+ print("║" + " "*18 + "Kintegrity Labs × CodexΩ∞ × Sovereign Lattice" + " "*15 + "║")
572
+ print("╚" + "="*78 + "╝")
573
+
574
+ import argparse
575
+ parser = argparse.ArgumentParser()
576
+ parser.add_argument("--path", default=".", help="Workspace path to audit")
577
+ parser.add_argument("--category", default="full",
578
+ choices=["full", "security", "persistence", "integrity",
579
+ "maturity", "structure", "compliance",
580
+ "emotional_resonance", "sovereign_alignment"])
581
+ args = parser.parse_args()
582
+
583
+ agent = AccioAuditAgent(args.path)
584
+ report = await agent.run_audit(args.category)
585
+
586
+ print(f"\n📊 AUDIT COMPLETE:")
587
+ print(f" Report ID: {report.report_id}")
588
+ print(f" Status: {report.status.value}")
589
+ print(f" Findings: {report.summary['total']}")
590
+ print(f" Critical: {report.summary['critical']}")
591
+ print(f" Φ⁵: {report.phi5_signature[:50]}...")
592
+ print(f"\n📄 Reports saved in: {os.path.join(args.path, 'audit_reports')}")
593
+
594
+
595
+ if __name__ == "__main__":
596
+ asyncio.run(main())