V6.0 alpha - #41
Merged
Merged
Conversation
…ion, mitigations, domain rules, and regulatory frameworks
…es, 170 regulatory mappings)
… and register in constitution
…f single source of truth in anchor/governance/
…atcher, and FastAPI streaming integration gateway
…risk scoring engine, PyO3 exports, and Python report generator
…er language adapters (Python, TS), HMAC-SHA256 DAC block signing, and PyO3 directory scanner
…tle::ConstantTimeEq signature verification in crypto.rs
… non-blocking /v1/audit/gate/async, and WebSocket telemetry bus for hub.animuslab.dev
…queue, offline re-sync state machine worker, and PyO3 ledger exports
…AML rule loader, and UTF-8 terminal report generator
…diation graph, and @anchor.guard Python self-healing interceptor
…5519 identity, code-centric scanner, and v4 command suite
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces the v6.0.0-alpha foundation for Anchor Core by adding a Rust (PyO3) “core kernel” for scanning/auditing, adding Python CLI and runtime guard integrations, and shipping an expanded governance catalog of .anchor rule/framework files.
Changes:
- Added a Rust
anchor_core_rsPyO3 module implementing payload auditing, parallel directory scanning, crypto helpers, and a basic remediation graph. - Replaced/expanded the Python CLI (
anchor/cli.py) withinit,check,sync, andhealflows plus repo-local.anchor/setup. - Added governance catalogs (domains/frameworks/regulators) and supporting Python components (guard, telemetry, ledger sync worker), plus basic tests and ignore files.
Reviewed changes
Copilot reviewed 51 out of 56 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_layer2_guard.py | Adds a basic runtime-guard test harness (currently print-only). |
| src/scanner/walker.rs | Implements parallel, mmap-based line scanning with RegexSet matching. |
| src/scanner/rule_loader.rs | Adds YAML-based .anchor rule loading into a rule map. |
| src/scanner/mod.rs | Exposes scanner submodules and re-exports key APIs. |
| src/scanner/crypto.rs | Adds Ed25519 + HMAC helpers and keypair generation. |
| src/scanner/adapters.rs | Introduces Tree-sitter adapter traits and example queries. |
| src/lib.rs | Adds the PyO3 AnchorEngine API surface (scan/audit/ledger/remediation bindings). |
| src/ledger/queue.rs | Adds a JSONL-backed local ledger queue for DAC entries. |
| src/ledger/mod.rs | Exports the ledger queue types. |
| src/engine/remediation.rs | Adds remediation graph loading and healing directive generation. |
| src/engine/mod.rs | Exports remediation types. |
| src/async_engine/mod.rs | Adds async audit processing via Tokio spawn_blocking. |
| src/analyst/scorer.rs | Introduces a risk scoring model and tiering. |
| src/analyst/mod.rs | Exports analyst components. |
| src/analyst/mapper.rs | Adds static legal/regulatory mapping tables for rule IDs. |
| pyproject.toml | Adds maturin/PyO3 build configuration for the Python package. |
| Cargo.toml | Defines the Rust crate and dependencies (PyO3, tokio, rayon, etc.). |
| Cargo.lock | Locks Rust dependency graph for reproducible builds. |
| anchor/server/telemetry.py | Adds a websocket broadcaster for violation telemetry packets. |
| anchor/scanner/runner.py | Adds a Python wrapper to call the Rust engine scanner/signing helpers. |
| anchor/scanner/init.py | Exports ScannerRunner. |
| anchor/ledger/sync.py | Adds an async reconnect loop to flush cached ledger entries. |
| anchor/ledger/init.py | Exports LedgerSyncWorker. |
| anchor/guard.py | Adds the @guard decorator integrating with Rust payload auditing. |
| anchor/governance/policy.anchor | Adds project policy overrides and enforcement settings. |
| anchor/governance/mitigation.anchor | Adds mitigation catalog entries (regex patterns, severities, messages). |
| anchor/governance/government/SEC_Regulations.anchor | Adds SEC regulatory mapping framework file. |
| anchor/governance/government/SEBI_Regulations.anchor | Adds SEBI regulatory mapping framework file. |
| anchor/governance/government/RBI_Regulations.anchor | Adds RBI regulatory mapping framework file. |
| anchor/governance/government/FCA_Regulations.anchor | Adds FCA regulatory mapping framework file. |
| anchor/governance/government/EU_AI_Act.anchor | Adds EU AI Act mapping framework file. |
| anchor/governance/government/CFPB_Regulations.anchor | Adds CFPB mapping framework file. |
| anchor/governance/GOVERNANCE.lock | Adds integrity baseline hashes for governance assets. |
| anchor/governance/frameworks/OWASP_LLM.anchor | Adds OWASP LLM Top 10 mapping framework file. |
| anchor/governance/frameworks/OECD_AI_Principles.anchor | Adds OECD AI Principles mapping framework file. |
| anchor/governance/frameworks/NIST_AI_RMF.anchor | Adds NIST AI RMF mapping framework file. |
| anchor/governance/frameworks/FINOS_Framework.anchor | Adds FINOS mapping framework file. |
| anchor/governance/examples/init.py | Adds governance examples package marker. |
| anchor/governance/domains/supply_chain.anchor | Adds supply-chain domain rule definitions. |
| anchor/governance/domains/shared.anchor | Adds shared cross-domain rule definitions. |
| anchor/governance/domains/security.anchor | Adds security domain rule definitions. |
| anchor/governance/domains/privacy.anchor | Adds privacy domain rule definitions. |
| anchor/governance/domains/operational.anchor | Adds operational domain rule definitions. |
| anchor/governance/domains/legal.anchor | Adds legal domain rule definitions. |
| anchor/governance/domains/ethics.anchor | Adds ethics domain rule definitions. |
| anchor/governance/domains/alignment.anchor | Adds alignment domain rule definitions. |
| anchor/governance/domains/agentic.anchor | Adds agentic domain rule definitions. |
| anchor/governance/constitution.anchor | Adds root constitution manifest tying domains/frameworks/regulators. |
| anchor/core/memory.py | Adds a local SQLite “brain” for scan stats. |
| anchor/cli.py | Replaces CLI with click-based init/check/heal/sync flows and reporting. |
| anchor/app.py | Adds FastAPI gateway endpoints and telemetry integration. |
| anchor/analyst/reporter.py | Adds markdown/JSON report rendering utilities. |
| anchor/analyst/init.py | Exports GovernanceReportGenerator. |
| .gitignore | Ignores Rust target/ output directory. |
| .anchorignore | Adds Anchor scanner ignore patterns (tests, venv, node_modules, etc.). |
Suppressed comments (2)
anchor/server/telemetry.py:33
timestamp_utcis set toasyncio.get_event_loop().time(), which is a monotonic clock value (not UTC, not even epoch-based). Clients expecting a real UTC timestamp will get an unusable number.
tests/test_layer2_guard.py:19- This test also lacks assertions for the blocked path. Since
guard()returns a structured self-healing dict on violations, the test should validate the expected shape/status.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+60
to
+61
| let mitigation_path = Path::new("anchor/governance/mitigation.anchor"); | ||
| let remediation_graph = RemediationGraph::load_from_file(mitigation_path); |
Comment on lines
+12
to
+16
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct MitigationFile { | ||
| pub version: String, | ||
| pub mitigations: HashMap<String, MitigationEntry>, | ||
| } |
Comment on lines
+10
to
+27
| pub struct Ed25519KeyPair { | ||
| pub private_key_pem: String, | ||
| pub public_key_pem: String, | ||
| pub fingerprint: String, | ||
| } | ||
|
|
||
| /// Generate fresh Ed25519 Keypair for local deployment identity | ||
| pub fn generate_ed25519_keypair() -> Ed25519KeyPair { | ||
| let mut csprng = OsRng; | ||
| let signing_key = SigningKey::generate(&mut csprng); | ||
| let verifying_key: VerifyingKey = signing_key.verifying_key(); | ||
|
|
||
| let priv_bytes = signing_key.to_bytes(); | ||
| let pub_bytes = verifying_key.to_bytes(); | ||
|
|
||
| let private_hex = hex::encode(priv_bytes); | ||
| let public_hex = hex::encode(pub_bytes); | ||
|
|
Comment on lines
+55
to
+69
| pub fn mark_all_synced(&self) -> std::io::Result<usize> { | ||
| let pending = self.get_pending_entries(); | ||
| let synced_count = pending.len(); | ||
|
|
||
| let file = File::create(&self.journal_path)?; | ||
| let mut writer = std::io::BufWriter::new(file); | ||
|
|
||
| for mut entry in pending { | ||
| entry.is_synced = true; | ||
| let line = serde_json::to_string(&entry)?; | ||
| writeln!(writer, "{}", line)?; | ||
| } | ||
| writer.flush()?; | ||
| Ok(synced_count) | ||
| } |
Comment on lines
+6
to
+9
| import json | ||
| import asyncio | ||
| from typing import Dict, Any, List, Set | ||
| from fastapi import WebSocket, WebSocketDisconnect |
Comment on lines
+35
to
+40
| async with httpx.AsyncClient(timeout=5.0) as client: | ||
| resp = await client.get(f"{self.hub_url}/health") | ||
| if resp.status_code == 200: | ||
| # Hub restored! Flush queued blocks | ||
| flushed = self.engine.flush_offline_queue() | ||
| print(f"[Anchor Ledger Sync] Connection restored. Flushed {flushed} queued DAC blocks to {self.hub_url}.") |
Comment on lines
+11
to
+14
| def test_compliant_call(): | ||
| result = sample_agent_action("Analyze revenue for Q3 2026") | ||
| print("\n✅ Compliant Call Result:") | ||
| print(result) |
Comment on lines
+75
to
+79
| line_matches.push(LineViolationMatch { | ||
| line_number: idx + 1, | ||
| line_content: line.trim().to_string(), | ||
| matched_rule_indices: matched_indices, | ||
| }); |
Comment on lines
+107
to
+125
| let mut matched_rules = Vec::new(); | ||
| let mut matched_statutes = Vec::new(); | ||
|
|
||
| for idx in m.matched_rule_indices { | ||
| if idx < rule_id_map.len() { | ||
| let (r_id, stat_ref, name) = rule_id_map[idx]; | ||
| if !matched_rules.contains(&r_id) { | ||
| matched_rules.push(r_id); | ||
| } | ||
| if !matched_statutes.contains(&stat_ref) { | ||
| matched_statutes.push(stat_ref); | ||
| } | ||
| dict.set_item("name", name)?; | ||
| } | ||
| } | ||
|
|
||
| dict.set_item("aggregated_rule_ids", matched_rules.join(", "))?; | ||
| dict.set_item("statutory_references", matched_statutes.join(", "))?; | ||
| dict.set_item("severity", "error")?; |
Comment on lines
+26
to
+32
| REMEDIATION_SNIPPETS = { | ||
| "AGT-001": """+ # Fix: Enforce explicit AI identity disclosure header\n+ @anchor.guard(disclosure="This response is generated by an AI assistant")\n+ async def handle_user_request(payload):""", | ||
| "SEC-001": """+ # Fix: Sanitize user input prior to LLM system prompt injection\n+ clean_prompt = anchor.sanitize_prompt(user_input, strict=True)""", | ||
| "SEC-002": """- API_KEY = "sk-proj-99a21b44c1..." # Hardcoded secret!\n+ API_KEY = os.environ.get("OPENAI_API_KEY") # Load from environment""", | ||
| "RBI-007": """+ # Fix: Enable audit log stream for compliance auditability\n+ logger.enable_audit_trail(event_id=ctx.event_id)""", | ||
| "EU-ART14": """+ # Fix: Require human confirmation for automated risk execution\n+ if not human_auth.confirm_action(action_id): return anchor.block()""" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release v6.0-alpha: Layer 1 Zero-Copy Rust Kernel, Deterministic Ed25519 Identity & Full v4 CLI Command Suite
PR Summary
This pull request establishes the core foundation for Anchor Core v6.0-alpha, introducing a multi-threaded zero-copy Rust kernel backend (
anchor_core_rs), deterministic local Ed25519 identity keypair generation, consent-driven CLI initialization, and code-centric governance reporting line-by-line across all 9 core domains, industry frameworks (FINOS, OWASP, NIST, OECD), and statutory regulations (RBI, EU AI Act, SEC, SEBI, CFPB, FCA).Key Features & Architectural Changes
1. Deterministic Local Ed25519 Identity Generation (
src/scanner/crypto.rs)"default-key"string fallback with deployment-sovereign asymmetric Ed25519 keypair generation duringanchor init..anchor/keys/ed25519_private.pem: Local private key (chmod 0600, auto-ignored by Git)..anchor/keys/ed25519_public.pem: Project public key (committed to Git for signature verification).subtle::ConstantTimeEqto prevent side-channel timing attacks during Decision Audit Chain (DAC) signature validation.2. Multi-Threaded Zero-Copy Rust Scanning Kernel (
anchor_core_rs)rayonandmemmap2for zero-copy buffer scanning (~1.8M lines/sec)..py,.ts,.tsx,.js,.go,.rs) line-by-line and records exactfile_path:line_numberlocations and offending code lines.Rules: [SEC-002, OWASP-LLM06, EU-ART12]).3. Consent-Driven Developer UX (
anchor init).gitignore(.anchor/cache/& private key only)..git/hooks/pre-commit.bak).[y/N], defaultNfor 100% offline open-source privacy).--no-promptflag for CI/CD automation.4. Full v4 Command Suite Port (
anchor/cli.py)anchor init:--domains,--frameworks,--regulators,--all,--no-prompt,--gitignore,--hook,--hub-key,--project-key.anchor check .: Universal static audit reporting across human, json, and markdown formats.anchor check verify-sync: Three-way mitigation catalog integrity verification.anchor check drift: Architectural drift analysis across git symbol history.anchor sync --restore: Authoritative remote governance rule sync.anchor heal --apply: Automated in-place code patching for fixable governance violations.5. Persistent Report & Violation Logging
.anchor/reports/governance_audit.md.anchor/reports/governance_report.json.anchor/violations/governance_violations.txtVerification & Test Output
Tested against external codebase (
Animus-Studio- 118 files, 9,553 lines of code):