torusguard 1.3.6 โ†’ 2.0.0-alpha

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 (110) hide show
  1. package/.torusguard/.manifest.json +9 -8
  2. package/.torusguard/auth.json +5 -0
  3. package/.torusguard/rules_catalog.json +242 -518
  4. package/.torusguard/runs/report-latest.html +3529 -364
  5. package/.torusguard/runs/run-20260918-105940-audit/manifest.json +2 -1
  6. package/.torusguard/runs/run-20260918-105940-audit/remediation.md +7 -0
  7. package/.torusguard/runs/run-20260919-145701-audit/findings.json +1 -0
  8. package/.torusguard/runs/run-20260919-145701-audit/findings.md +8 -0
  9. package/.torusguard/runs/run-20260919-145701-audit/manifest.json +12 -0
  10. package/.torusguard/runs/run-20260919-145701-audit/summary.md +5 -0
  11. package/.torusguard/runs/run-20260919-151729-audit/findings.json +1 -0
  12. package/.torusguard/runs/run-20260919-151729-audit/findings.md +8 -0
  13. package/.torusguard/runs/run-20260919-151729-audit/manifest.json +13 -0
  14. package/.torusguard/runs/run-20260919-151729-audit/remediation.md +7 -0
  15. package/.torusguard/runs/run-20260919-151729-audit/summary.md +5 -0
  16. package/.torusguard/runs/run-20260919-152340-audit/findings.json +1 -0
  17. package/.torusguard/runs/run-20260919-152340-audit/findings.md +8 -0
  18. package/.torusguard/runs/run-20260919-152340-audit/manifest.json +12 -0
  19. package/.torusguard/runs/run-20260919-152340-audit/summary.md +5 -0
  20. package/.torusguard/runs/run-20260919-152345-audit/findings.json +1 -0
  21. package/.torusguard/runs/run-20260919-152345-audit/findings.md +8 -0
  22. package/.torusguard/runs/run-20260919-152345-audit/manifest.json +12 -0
  23. package/.torusguard/runs/run-20260919-152345-audit/summary.md +5 -0
  24. package/.torusguard/runs/run-20260919-153500-audit/findings.json +1 -0
  25. package/.torusguard/runs/run-20260919-153500-audit/findings.md +8 -0
  26. package/.torusguard/runs/run-20260919-153500-audit/manifest.json +12 -0
  27. package/.torusguard/runs/run-20260919-153500-audit/summary.md +5 -0
  28. package/.torusguard/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
  29. package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  30. package/.torusguard/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
  31. package/.torusguard/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  32. package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
  33. package/.torusguard/scripts/__pycache__/recipes_runner.cpython-314.pyc +0 -0
  34. package/.torusguard/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  35. package/.torusguard/scripts/apply_runner.py +101 -8
  36. package/.torusguard/scripts/audit_runner.py +116 -11
  37. package/.torusguard/scripts/harden_runner.py +122 -68
  38. package/.torusguard/scripts/html_reporter.py +1170 -253
  39. package/.torusguard/scripts/manifest_builder.py +2 -0
  40. package/.torusguard/scripts/recheck_runner.py +2 -1
  41. package/.torusguard/scripts/recipes_runner.py +91 -8
  42. package/.torusguard/scripts/report_sync.py +134 -7
  43. package/.torusguard/scripts/status_runner.py +267 -0
  44. package/.torusguard/snapshots/20260921-182638/go.mod.bak +11 -0
  45. package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
  46. package/README.md +314 -364
  47. package/bin/torusguard.js +190 -20
  48. package/package.json +6 -2
  49. package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
  50. package/skills/torusguard/bootstrap.py +45 -6
  51. package/skills/torusguard/payload/.manifest.json +29 -14
  52. package/skills/torusguard/payload/TORUSGUARD.md +145 -145
  53. package/skills/torusguard/payload/agents/auditor.md +41 -41
  54. package/skills/torusguard/payload/agents/profiler.md +49 -49
  55. package/skills/torusguard/payload/agents/remediator.md +41 -41
  56. package/skills/torusguard/payload/agents/reviewer.md +39 -39
  57. package/skills/torusguard/payload/agents/validator.md +46 -46
  58. package/skills/torusguard/payload/config/scope.json +24 -24
  59. package/skills/torusguard/payload/references/csharp-security.md +41 -41
  60. package/skills/torusguard/payload/references/go-security.md +41 -41
  61. package/skills/torusguard/payload/references/java-security.md +40 -40
  62. package/skills/torusguard/payload/references/polyglot-security-matrix.md +25 -25
  63. package/skills/torusguard/payload/references/rust-security.md +40 -40
  64. package/skills/torusguard/payload/rules/custom/.gitkeep +1 -1
  65. package/skills/torusguard/payload/rules/custom/README.md +30 -30
  66. package/skills/torusguard/payload/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  67. package/skills/torusguard/payload/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  68. package/skills/torusguard/payload/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  69. package/skills/torusguard/payload/scripts/__pycache__/sarif_exporter.cpython-314.pyc +0 -0
  70. package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
  71. package/skills/torusguard/payload/scripts/apply_runner.py +101 -8
  72. package/skills/torusguard/payload/scripts/audit_runner.py +116 -11
  73. package/skills/torusguard/payload/scripts/harden_runner.py +122 -68
  74. package/skills/torusguard/payload/scripts/html_reporter.py +1170 -253
  75. package/skills/torusguard/payload/scripts/manifest_builder.py +2 -0
  76. package/skills/torusguard/payload/scripts/recheck_runner.py +2 -1
  77. package/skills/torusguard/payload/scripts/recipes_runner.py +91 -8
  78. package/skills/torusguard/payload/scripts/report_sync.py +134 -7
  79. package/skills/torusguard/payload/scripts/rules_sync.py +321 -321
  80. package/skills/torusguard/payload/scripts/safety_gate.py +64 -64
  81. package/skills/torusguard/payload/scripts/status_runner.py +267 -0
  82. package/skills/torusguard/payload/skills/torusguard/references/csharp-security.md +41 -41
  83. package/skills/torusguard/payload/skills/torusguard/references/go-security.md +41 -41
  84. package/skills/torusguard/payload/skills/torusguard/references/java-security.md +40 -40
  85. package/skills/torusguard/payload/skills/torusguard/references/polyglot-security-matrix.md +25 -25
  86. package/skills/torusguard/payload/skills/torusguard/references/rust-security.md +40 -40
  87. package/skills/torusguard/payload/templates/audit-report.template.md +54 -54
  88. package/skills/torusguard/payload/templates/authorization.template.md +34 -34
  89. package/skills/torusguard/payload/templates/finding-card.template.md +32 -32
  90. package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -35
  91. package/skills/torusguard/payload/workflows/apply.md +9 -1
  92. package/skills/torusguard/payload/workflows/audit.md +8 -2
  93. package/skills/torusguard/payload/workflows/harden.md +6 -1
  94. package/skills/torusguard/payload/workflows/init.md +7 -1
  95. package/skills/torusguard/payload/workflows/recipes.md +55 -0
  96. package/skills/torusguard/payload/workflows/report.md +59 -55
  97. package/skills/torusguard/payload/workflows/status.md +4 -1
  98. package/skills/torusguard/payload/workflows/torusguard-apply.md +110 -0
  99. package/skills/torusguard/payload/workflows/torusguard-audit.md +105 -0
  100. package/skills/torusguard/payload/workflows/torusguard-authorize.md +96 -0
  101. package/skills/torusguard/payload/workflows/torusguard-exploit-check.md +98 -0
  102. package/skills/torusguard/payload/workflows/torusguard-harden.md +104 -0
  103. package/skills/torusguard/payload/workflows/torusguard-init.md +106 -0
  104. package/skills/torusguard/payload/workflows/torusguard-recheck.md +101 -0
  105. package/skills/torusguard/payload/workflows/torusguard-recipes.md +55 -0
  106. package/skills/torusguard/payload/workflows/torusguard-report.md +105 -0
  107. package/skills/torusguard/payload/workflows/torusguard-status.md +103 -0
  108. package/skills/torusguard/payload/workflows/torusguard-verify.md +100 -0
  109. package/skills/torusguard/payload/workflows/torusguard-web-validate.md +96 -0
  110. package/skills/torusguard/payload/workflows/torusguard.md +19 -0
package/README.md CHANGED
@@ -1,476 +1,426 @@
1
- <div align="center">
2
- <img src="TorusGuard.png" alt="TorusGuard Autonomous Security Engine Banner" width="560" style="max-width: 100%; height: auto; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);">
3
-
4
- # TorusGuard
5
-
6
- ### Autonomous Security Guardrails, Governed Remediation & Living Verification for AI-Built Applications
7
-
8
- <p align="center">
9
- <strong>Zero Telemetry ยท Zero External Python Dependencies ยท Pure Standard-Library Architecture ยท 100% Local-First</strong>
10
- </p>
11
-
12
- [![npm version](https://img.shields.io/badge/npm-v1.3.6-cb3837.svg?style=flat-square&logo=npm)](https://www.npmjs.com/package/torusguard)
13
- [![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-v1.3.6-181717.svg?style=flat-square&logo=github)](https://github.com/githubmofo/TorusGuard/pkgs/npm/torusguard)
14
- [![Release](https://img.shields.io/badge/Release-v1.3.6-blue.svg?style=flat-square)](https://github.com/githubmofo/TorusGuard/releases/latest)
15
- [![Tests](https://img.shields.io/badge/Tests-120%2F120%20Passing-brightgreen.svg?style=flat-square)](harness/runner.py)
16
- [![Security Health](https://img.shields.io/badge/Health%20Score-100%2F100%20Hardened-brightgreen.svg?style=flat-square)](security_report.md)
17
- [![Rules Catalog](https://img.shields.io/badge/Rules%20Catalog-74%20Rules%20%7C%2018%20Families-indigo.svg?style=flat-square)](rules/)
18
- [![Terminal Standard](https://img.shields.io/badge/Terminal-75--col%20Standard-informational.svg?style=flat-square)](.torusguard/scripts/term_ui.py)
19
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)](LICENSE)
20
- [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B%20(Zero%20Deps)-blue.svg?style=flat-square&logo=python&logoColor=white)](https://python.org)
21
- [![Node.js 18+](https://img.shields.io/badge/Node.js-18%2B-339933.svg?style=flat-square&logo=node.js&logoColor=white)](https://nodejs.org)
22
- [![SARIF: v2.1.0](https://img.shields.io/badge/SARIF-v2.1.0%20OASIS-purple.svg?style=flat-square)](.torusguard/schemas/)
23
- [![OWASP: Top 10](https://img.shields.io/badge/OWASP-Top%2010%20Aligned-orange.svg?style=flat-square)](docs/architecture/SECURITY_ARCHITECTURE.md)
24
- [![Privacy](https://img.shields.io/badge/Privacy-100%25%20Local%20Zero--Egress-success.svg?style=flat-square)](docs/overview/security-philosophy.md)
25
- </div>
1
+ <p align="center">
2
+ <img src="TorusGuard.png" alt="TorusGuard Logo" width="200" />
3
+ </p>
4
+
5
+ <h1 align="center">TorusGuard</h1>
6
+
7
+ <p align="center">
8
+ <strong>The Hybrid Governance Security Engine for AI-built web applications.</strong><br>
9
+ <em>Pairs the intelligence of your AI Agent with a deterministic Go CLI to enforce strict security boundaries and patch limits.</em>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
14
+ <a href="https://github.com/githubmofo/TorusGuard/releases"><img src="https://img.shields.io/badge/version-2.0.0--alpha-orange.svg" alt="Version"></a>
15
+ <a href="https://www.npmjs.com/package/torusguard"><img src="https://img.shields.io/badge/npm-v2.0.0--alpha-CB3837?logo=npm&logoColor=white" alt="npm: v2.0.0-alpha"></a>
16
+ <img src="https://img.shields.io/badge/Privacy-Local_First-success" alt="Privacy: Local First">
17
+ <img src="https://img.shields.io/badge/Dependencies-Zero-brightgreen" alt="Dependencies: Zero">
18
+ <img src="https://img.shields.io/badge/SARIF-v2.1.0-6C3483" alt="SARIF">
19
+ <img src="https://img.shields.io/badge/OWASP-Top_10-000000?logo=owasp&logoColor=white" alt="OWASP">
20
+ </p>
21
+
22
+ <p align="center">
23
+ <img src="https://img.shields.io/badge/Unit%20Tests-100%25%20Passing-brightgreen?logo=go&logoColor=white" alt="Unit Tests: 100% Passing">
24
+ <img src="https://img.shields.io/badge/Polyglot%20Tests-36%2F36%20Repos%20Passed-brightgreen?logo=checkmarx&logoColor=white" alt="Polyglot Tests: 36/36 Repos Passed">
25
+ <img src="https://img.shields.io/badge/Tri--Mode%20E2E-16%2F16%20Verified-blue?logo=checkmarx&logoColor=white" alt="Tri-Mode E2E: 16/16 Verified">
26
+ <img src="https://img.shields.io/badge/Vision%20OCR-Tested%20%26%20Verified-blueviolet?logo=tesseract&logoColor=white" alt="Vision OCR: Tested & Verified">
27
+ <img src="https://img.shields.io/badge/Rules%20Verified-74%2F74%20Rules-success" alt="Rules: 74/74 Verified">
28
+ </p>
29
+
30
+ <p align="center">
31
+ <img src="https://img.shields.io/badge/Tri--Mode-CLI%20%7C%20Chat%20%7C%20MCP-blue" alt="Tri-Mode Parity">
32
+ <img src="https://img.shields.io/badge/Go-1.25-00ADD8?logo=go&logoColor=white" alt="Go">
33
+ <img src="https://img.shields.io/badge/Node.js-18+-339933?logo=nodedotjs&logoColor=white" alt="Node.js">
34
+ <img src="https://img.shields.io/badge/Python-3.10+-3776AB?logo=python&logoColor=white" alt="Python">
35
+ <img src="https://img.shields.io/badge/TypeScript-5.0+-3178C6?logo=typescript&logoColor=white" alt="TypeScript">
36
+ <img src="https://img.shields.io/badge/Rust-2021-DEA584?logo=rust&logoColor=white" alt="Rust">
37
+ </p>
26
38
 
27
39
  ---
28
40
 
29
- ## ๐Ÿ›ก๏ธ The Architecture Behind the Emblem
41
+ ## Table of Contents
42
+
43
+ - [What Is TorusGuard?](#what-is-torusguard)
44
+ - [Features](#-features)
45
+ - [Autonomous Architecture](#-autonomous-architecture)
46
+ - [Prerequisites](#-prerequisites)
47
+ - [Installation](#-installation)
48
+ - [Usage](#-usage)
49
+ - [Commands](#-commands)
50
+ - [Project Structure](#-project-structure)
51
+ - [Security Rules (74 Rules, 18 Families)](#-security-rules-74-rules-18-families)
52
+ - [AI Agent Integration](#-ai-agent-integration)
53
+ - [Verified Test Suite & Benchmarks](#-verified-test-suite--mass-benchmarks)
54
+ - [Non-Negotiable Invariants](#-non-negotiable-invariants)
55
+ - [Contributing](#-contributing)
56
+ - [License](#-license)
57
+ - [Documentation](#-documentation)
30
58
 
31
- In the emblem above, the **central golden keyhole shield** represents unbreakable secret protection, authentication integrity, and tenant isolation. It is enveloped by a continuous, interlocking **torus ring**โ€”symbolizing TorusGuard's closed-loop autonomous security lifecycle:
59
+ ---
32
60
 
33
- ```mermaid
34
- flowchart LR
35
- subgraph Torus ["๐Ÿ”„ 360ยฐ Closed-Loop Torus Lifecycle"]
36
- direction LR
37
- Detect["1. Detect (74 AST Rules)"] --> Verify["2. Verify (Evidence & Fingerprints)"]
38
- Verify --> Harden["3. Harden (Ponytail Protocol)"]
39
- Harden --> Apply["4. Apply (Human Gate & Snapshots)"]
40
- Apply --> Recheck["5. Recheck (Differential Closure)"]
41
- Recheck --> Memory["6. Memory (Golden Fix Recipes)"]
42
- Memory -.->|Continuous Guardrail| Detect
43
- end
61
+ ## What Is TorusGuard?
44
62
 
45
- subgraph Shield ["๐Ÿ›ก๏ธ Central Golden Keyhole Shield"]
46
- direction TB
47
- Inv1["Browser-Code Truth: Zero Client Secrets"]
48
- Inv2["Tenant Partitioning: Scoped Lookups"]
49
- Inv3["Zero Bypasses: No verify=False"]
50
- Inv4["Living Source of Truth: security_report.md"]
51
- end
63
+ TorusGuard is a **zero-dependency, single-binary security engine** that scans, hardens, and validates AI-generated codebases. It enforces 74 security rules across 18 architectural families and works in two complementary modes:
52
64
 
53
- Torus === Shield
54
- ```
65
+ - **CLI Mode (Go Binary)** โ€” A deterministic scanner and enforcer that runs in your terminal or CI/CD pipeline.
66
+ - **AI Agent Mode** โ€” Integrates natively with Antigravity, Cursor, Claude Code, Windsurf, VS Code, and other AI coding assistants via slash commands.
55
67
 
56
- > **The Developer Reality:** AI coding assistants (Cursor, Claude Code, Copilot, Windsurf) build software at superhuman speed, but routinely leak private keys into client bundles, drop tenant partition filters, or inject raw user input into LLM system prompts.
57
- > **TorusGuard forms an unbroken local guardrail around your codebase.** It audits static ASTs, runtime-verifies exploitability with inert canaries, synthesizes minimal surgical diffs adhering to the **Ponytail Protocol** ($\le 35$ additions, $\le 25$ deletions), and eliminates hallucinations by maintaining a verifiable single source of truth in `security_report.md`.
68
+ TorusGuard ensures that the code your AI assistant writes is secure *before* it reaches production.
58
69
 
59
70
  ---
60
71
 
61
- ## ๐Ÿ“‘ Table of Contents
62
-
63
- 1. [Developer Overview & Value Proposition](#-developer-overview--value-proposition)
64
- 2. [End-to-End Autonomous Architecture](#-end-to-end-autonomous-architecture)
65
- 3. [Why TorusGuard? (Traditional SAST vs. AI Coding vs. TorusGuard)](#-why-torusguard)
66
- 4. [Installation & Setup Guide (npm & CLI)](#-installation--setup-guide-npm--cli)
67
- 5. [Quickstart: The 5-Step Core Lifecycle](#-quickstart-the-5-step-core-lifecycle)
68
- 6. [Dual-Strategy Command Matrix (CLI & AI Chat Parity)](#-dual-strategy-command-matrix-cli--ai-chat-parity)
69
- 7. [74 Canonical Security Rules Catalog (18 Families Across 6 Pillars)](#-74-canonical-security-rules-catalog-18-families-across-6-pillars)
70
- 8. [Ponytail Remediation Protocol & Rollback Safety](#-ponytail-remediation-protocol--rollback-safety)
71
- 9. [Living Security Report Ground Truth (`security_report.md`)](#-living-security-report-ground-truth-security_reportmd)
72
- 10. [Visual HTML Dashboard & SARIF v2.1.0 Export](#-visual-html-dashboard--sarif-v210-export)
73
- 11. [AI Editor Guardrails Auto-Sync](#-ai-editor-guardrails-auto-sync)
74
- 12. [Monorepo Fleet Support & Git Pre-Commit Diff Guard](#-monorepo-fleet-support--git-pre-commit-diff-guard)
75
- 13. [Verification & Test Harness (120/120 Passing Harness Explained)](#-verification--test-harness)
76
- 14. [Security Policy & Responsible Disclosure](#-security-policy--responsible-disclosure)
77
- 15. [License](#-license)
72
+ ## โœจ Features
73
+
74
+ - **74 Security Rules** across 18 families (Secrets, Auth, SQL Injection, SSRF, CSRF, GraphQL, Supply Chain, and more)
75
+ - **Heuristic AST Scanner** โ€” Polyglot static analysis for Go, JavaScript, TypeScript, and Python
76
+ - **Ponytail Protocol** โ€” Surgical patch bounds (โ‰ค35 additions, โ‰ค25 deletions) to prevent full-file rewrites
77
+ - **Pre-Apply Snapshots** โ€” Automatic `.bak` rollback snapshots before every code modification
78
+ - **SARIF v2.1.0 Export** โ€” Standards-compliant output for GitHub Advanced Security, VS Code, and other SARIF consumers
79
+ - **Dark-Mode HTML Reports** โ€” Single-file visual posture dashboards
80
+ - **Golden Fix Recipes** โ€” Persistent memory of verified security patterns for reuse
81
+ - **SSRF Defense** โ€” Built-in private IP blocking and AWS metadata protection in the web validator
82
+ - **Fail-Closed Cryptography** โ€” No fallback tokens; panics on entropy failure
83
+ - **DoS Resilience** โ€” 10,000-file scan limit and 5-minute context timeout to prevent resource exhaustion
84
+ - **16+ Language Stack Detection** โ€” Go, Rust, Java, C#, PHP, Ruby, Kotlin, Elixir, Dart, Swift, Python, TypeScript, and more
85
+ - **Multi-Modal Vision OCR** โ€” Scans architecture diagrams, mockups, and screenshots (`.png`, `.jpg`, `.webp`) via Tesseract OCR to detect leaked keys, tokens, and credentials
86
+ - **Native MCP Server (Model Context Protocol)** โ€” Exposes standard JSON-RPC 2.0 stdio tools and resources for direct agent integration
87
+ - **Tri-Mode Parity** โ€” Terminal CLI, AI Chat slash commands, and Native MCP Tools share identical governance workflows
78
88
 
79
89
  ---
80
90
 
81
- ## ๐Ÿ’ก Developer Overview & Value Proposition
82
-
83
- When developers use AI coding agents to write features, models optimize for *getting the code to run* rather than *defensive architecture*. Common failure modes include:
84
- - **Exposing Private Credentials:** Leaking `process.env.SUPABASE_SERVICE_ROLE_KEY` or master database connection strings into Next.js `'use client'` bundles.
85
- - **Dropping Tenant Boundaries:** Querying Prisma or Mongoose by record ID without scoping by tenant (`where: { id }` instead of `where: { id, tenantId }`).
86
- - **Prompt Injection Vulnerabilities:** Interpolating untrusted user chat messages directly into system prompts.
87
- - **Destructive AI Rewrites:** When asked to fix a minor bug, AI models rewrite entire 500-line files, introducing fresh regressions and breaking surrounding business logic.
91
+ ## ๐Ÿงช Proven Compatibility
88
92
 
89
- **TorusGuard solves this deterministically:**
90
- - **Zero-Egress Local Execution:** 100% of scanning and patching happens on your machine. Zero code or tokens are transmitted to external servers.
91
- - **Zero Pip Dependencies:** Pure Python standard library (`pathlib`, `re`, `json`, `difflib`, `shutil`). No virtualenv conflicts or broken build wheels.
92
- - **Ponytail Churn Bounds:** Patches are constrained strictly to $\le 35$ additions and $\le 25$ deletions. Surrounding business logic is never rewritten.
93
- - **Human Gate & Instant Undo:** Every change requires interactive approval with syntax-highlighted diffs, backed up byte-for-byte in `.torusguard/snapshots/` with instant 1-command rollback.
93
+ TorusGuardโ€™s static scanner and enforcement binary have been rigorously tested and confirmed compatible across **20 major technology stacks and frameworks**:
94
94
 
95
- ### ๐ŸŒ The Browser-Code Truth Invariant
96
- > **"If the browser receives it, users can inspect it via DevTools."**
97
- > Frontend environment variables, client JavaScript bundles, and React Server Action payloads cannot conceal secrets. TorusGuard strictly enforces that database credentials, service role keys, private API secrets, and tenant boundaries remain exclusively on trusted server runtimes.
95
+ | Ecosystem | Tested Frameworks & Runtimes |
96
+ |-----------|------------------------------|
97
+ | **JavaScript / TypeScript** | React, Next.js, Express, Vue, Angular, SvelteKit, NestJS |
98
+ | **Python** | Django, Flask, FastAPI, raw Python scripts |
99
+ | **Go** | Gin |
100
+ | **Java / C# (.NET)** | Spring Boot, ASP.NET Core, .NET Core Middleware |
101
+ | **Ruby** | Ruby on Rails, Sinatra |
102
+ | **PHP** | Laravel, Symfony |
103
+ | **Rust** | Actix Web |
98
104
 
99
105
  ---
100
106
 
101
- ## ๐Ÿ“ End-to-End Autonomous Architecture
107
+ ## ๐Ÿ—๏ธ Autonomous Architecture
102
108
 
103
- The following flowchart illustrates how TorusGuard safeguards your repository from initial developer input to verified, regression-free output:
109
+ TorusGuard uses a **tri-track architecture** where intelligence, deterministic enforcement, and agent tool execution are cleanly separated across three unified operational modes:
104
110
 
105
111
  ```mermaid
106
112
  flowchart TD
107
- subgraph In ["1. Workspace & AI Context"]
108
- A1["Polyglot Source Tree (16+ Languages)"]
109
- A2["AI Coding Assistant (Cursor / Claude / Antigravity)"]
110
- A3["Git Staged Diffs / Pre-Commit Hook"]
111
- end
112
-
113
- subgraph Core ["2. TorusGuard Engine (100% Local-First & Zero-Egress)"]
114
- direction TB
115
- B1["Static AST Engine: 74 Canonical Rules Across 18 Families"]
116
- B2["Living Ledger Sync: security_report.md (0-100 Score)"]
117
- B3["Ponytail Synthesizer: Minimal Surgical Diffs (&le;35 Add / &le;25 Del)"]
118
- B4["Pre-Apply Snapshot Engine: Byte-for-Byte .bak Backups"]
119
- B5["Human Gate: Interactive Syntax-Highlighted Approval"]
120
- B6["Targeted Differential Re-Scan: Confirmed Fixed State"]
121
-
122
- B1 --> B2 --> B3 --> B4 --> B5 --> B6
123
- end
124
-
125
- subgraph Out ["3. Verified Deliverables & Artifacts"]
126
- C1["Hardened Production Code (Zero Regressions)"]
127
- C2["Self-Contained Dark-Mode HTML Dashboard"]
128
- C3["OASIS SARIF v2.1.0 for CI/CD Pipeline"]
129
- C4["Auto-Synced AI Rules (.cursorrules, CLAUDE.md, etc.)"]
113
+ User([Developer / CI / AI Coding Assistant])
114
+
115
+ User --> ModeA[Mode A: Terminal CLI<br/><code>torusguard &lt;cmd&gt;</code><br/>Deterministic Go Binary]
116
+ User --> ModeB[Mode B: AI Chat Slash Command<br/><code>/torusguard &lt;cmd&gt;</code><br/>Chat Prompt & Workflow Bridge]
117
+ User --> ModeC[Mode C: Native MCP Protocol<br/><code>torusguard_audit / ocr_scan</code><br/>Stdio JSON-RPC 2.0 Agent Tools]
118
+
119
+ ModeA --> Router[Command Router & Dispatcher<br/>cmd/torusguard]
120
+ ModeB --> Router
121
+ ModeC --> Router
122
+
123
+ Router --> Engine
124
+
125
+ subgraph Engine[TorusGuard Core Engine]
126
+ Scanner[Polyglot AST & Heuristic Scanner<br/>74 Rules across 18 Families]
127
+ OCR[Multi-Modal Vision OCR Engine<br/>Tesseract Optical Analysis &le;10MB]
128
+ Harden[Harden Engine<br/>Ponytail Protocol &le;35 add, &le;25 del]
129
+ Apply[Snapshot & Apply Engine<br/>Byte-for-byte Rollback Backups]
130
+ Validate[Runtime Web Validator<br/>SSRF Defense & Audit Probing]
131
+ Recheck[Differential Recheck Engine<br/>Fix Closure Verification]
130
132
  end
131
-
132
- In --> Core --> Out
133
+
134
+ Engine --> Ledger[Living Security Ground Truth<br/><code>security_report.md</code>]
135
+ Engine --> Workspace[(.torusguard/ Workspace State<br/>rules/ &bull; schemas/ &bull; memory/ &bull; snapshots/)]
133
136
  ```
134
137
 
135
- ---
136
-
137
- ## โš”๏ธ Why TorusGuard?
138
+ **Key design decisions:**
139
+ - **Tri-Mode Parity:** The CLI (Mode A), Chat Slash Commands (Mode B), and Native MCP Tools (Mode C) share the exact same underlying governance and validation rules.
140
+ - **Multi-Modal Vision OCR:** Images, architecture diagrams, and screenshots are automatically scanned for leaked secrets using Tesseract OCR, bounded by strict 10MB memory safety limits.
141
+ - **Deterministic Enforcement:** The **Go binary** handles all deterministic operations (AST scanning, bounds checking, snapshotting, reporting).
142
+ - **AI Intelligence:** The **AI agent** handles intelligence-requiring tasks (patch generation, root-cause analysis, remediation formulation).
143
+ - **Living Ground Truth:** All modes synchronize with `security_report.md` to prevent finding drift or hallucination.
144
+ - **Zero-Bypass Guardrails:** Neither human nor AI can bypass Ponytail Protocol bounds (โ‰ค35 additions, โ‰ค25 deletions) or the Human Gate before modifying code.
138
145
 
139
- | Security Dimension | Traditional SAST (SonarQube, Snyk) | Raw AI Coding Agents | TorusGuard v1.3.6 Engine |
140
- |:---|:---:|:---:|:---:|
141
- | **Target Architecture** | Human-written legacy codebases | High-churn AI code generation | **AI-built full-stack applications** |
142
- | **Remediation Model** | PDF reports & Jira tickets | Destructive full-file rewrites | **Ponytail Protocol** ($\le 35$ add, $\le 25$ del) |
143
- | **Fix Preservation** | None (scans from scratch) | Forgets context across chats | **Adaptive Security Memory** & Golden Recipes |
144
- | **Editor Sync** | Heavy background language daemons | Bloated prompt context ($> 2,000$ tokens) | **Stack-Adaptive Rules** ($\le 300$ prompt tokens) |
145
- | **Ground-Truth State** | External proprietary web dashboard | Ephemeral chat context (hallucinates) | **Living Security Ledger** (`security_report.md`) |
146
- | **Pre-Commit Defense** | Slow server-side webhooks | None (commits insecure code) | **Git Pre-Commit Diff Guard** ($< 200\text{ ms}$) |
147
- | **Privacy & Telemetry** | Cloud code upload / SaaS | Third-party cloud LLMs | **100% Local, Zero-Egress Guarantee** |
148
146
 
149
147
  ---
150
148
 
151
- ## ๐Ÿ“ฆ Installation & Setup Guide (npm & CLI)
152
-
153
- TorusGuard is designed to be effortless to adopt in any project. There are no configuration servers, databases, or complex background daemons.
154
-
155
- ### ๐Ÿ“‹ Prerequisites
156
- - **Node.js:** 18.0.0 or higher
157
- - **Python:** 3.10 or higher (**Pure standard library** โ€” **zero `pip` dependencies required**)
149
+ ## ๐Ÿ“‹ Prerequisites
158
150
 
159
- > [!IMPORTANT]
160
- > **Zero Pip Dependencies Guarantee:** TorusGuard's core Python engine relies strictly on the Python standard library (`pathlib`, `re`, `json`, `difflib`, `shutil`, `sys`, `os`, `argparse`, `hashlib`). You **never** need to create a Python virtualenv (`venv`), run `pip install`, or configure external wheels. It works out of the box with your system Python.
151
+ - **Go 1.25+** (to build from source)
152
+ - **Git** (for `git apply` patch operations)
153
+ - **Node.js 18+** (for npm package installation)
161
154
 
162
155
  ---
163
156
 
164
- ### 1. Zero-Install Runner (Recommended)
165
- Run TorusGuard instantly in any repository without installing anything globally:
157
+ ## ๐Ÿš€ Installation
158
+
159
+ ### Option 1: npm (Primary)
166
160
 
167
161
  ```bash
168
- # Run any command directly via npx
169
- npx torusguard init
170
- npx torusguard audit
171
- npx torusguard status
162
+ npm install -g torusguard
172
163
  ```
173
164
 
174
- ### 2. Project Dev Dependency
175
- Lock TorusGuard into your project's `package.json` for all team members and CI/CD pipelines:
165
+ Or use directly without installing:
176
166
 
177
167
  ```bash
178
- npm install -D torusguard
168
+ npx torusguard init
179
169
  ```
180
170
 
181
- Add convenience scripts to your `package.json`:
182
- ```json
183
- {
184
- "scripts": {
185
- "security:audit": "torusguard audit",
186
- "security:harden": "torusguard harden",
187
- "security:recheck": "torusguard recheck",
188
- "security:status": "torusguard status"
189
- }
190
- }
191
- ```
171
+ <a href="https://www.npmjs.com/package/torusguard">
172
+ <img src="https://img.shields.io/badge/npm-v2.0.0--alpha-CB3837?logo=npm&logoColor=white" alt="npm package">
173
+ </a>
192
174
 
193
- ### 3. Global Installation
194
- If you prefer having the `torusguard` binary available system-wide across all terminal sessions:
175
+ ### Option 2: Build from Source (Recommended for Contributors)
195
176
 
196
177
  ```bash
197
- npm install -g torusguard
178
+ git clone https://github.com/githubmofo/TorusGuard.git
179
+ cd TorusGuard
180
+ go build -o torusguard ./cmd/torusguard
198
181
  ```
199
182
 
200
- ### 4. AI Agent Skill Installation
201
- Install TorusGuard as a native AI assistant skill for Cursor, Claude Code, Cline, or Antigravity:
183
+ ### Option 3: Go Install
202
184
 
203
185
  ```bash
204
- npx skills add torusguard
186
+ go install github.com/torusguard/torusguard/cmd/torusguard@latest
205
187
  ```
206
188
 
207
189
  ---
208
190
 
209
- ### ๐Ÿ” What Happens on First Run (`init`)
210
- When you execute `npx torusguard init` in your repository:
211
- 1. **Polyglot Profiling:** Automatically detects 16+ languages (Go, Rust, Java, C#, PHP, Python, TypeScript) and 30+ frameworks without manual configuration.
212
- 2. **Scaffolding:** Creates a local `.torusguard/` directory containing active security rules, schemas, and runners.
213
- 3. **Editor Rules Synchronization:** Automatically compiles compact, language-specific guardrails into `.cursorrules`, `CLAUDE.md`, `.agent/rules/torusguard.md`, and `.windsurfrules` ($\le 300$ prompt tokens).
214
- 4. **Living Ledger Initialization:** Creates `security_report.md` at workspace root to track finding states without hallucination.
215
- 5. **Baseline Policy:** Emits a production-ready `SECURITY.md` for responsible disclosure.
216
-
217
- ---
218
-
219
- ## โšก Quickstart: The 5-Step Core Lifecycle
191
+ ## ๐Ÿ’ป Usage
220
192
 
221
- Run the complete autonomous governance cycle in 60 seconds from your terminal:
193
+ ### Quick Start
222
194
 
223
195
  ```bash
224
- # Step 1: Initialize workspace and profile stack
225
- npx torusguard init
196
+ # Initialize TorusGuard in your project
197
+ torusguard init
226
198
 
227
- # Step 2: Run AST static security audit across 74 rules
228
- npx torusguard audit
199
+ # Run a full security audit
200
+ torusguard audit
229
201
 
230
- # Step 3: Synthesize minimal surgical candidate patches
231
- npx torusguard harden
202
+ # Check workspace posture
203
+ torusguard status
232
204
 
233
- # Step 4: Review syntax-highlighted diffs and apply with rollback backup
234
- npx torusguard apply
205
+ # Generate an HTML report
206
+ torusguard report --html
235
207
 
236
- # Step 5: Differentially recheck modified files to verify fix closure
237
- npx torusguard recheck
208
+ # Generate a SARIF report
209
+ torusguard report --sarif
238
210
  ```
239
211
 
240
- > ๐Ÿ’ก **Prefer AI Chat?** Every step above can be triggered directly in your AI assistant chat using `/torusguard init`, `/torusguard audit`, `/torusguard harden`, `/torusguard apply`, and `/torusguard recheck`!
241
-
242
- ---
243
-
244
- ## โŒจ๏ธ Dual-Strategy Command Matrix (CLI & AI Chat Parity)
245
-
246
- TorusGuard guarantees **100% operational parity** between terminal CLI execution and AI chat slash commands. Terminal outputs strictly adhere to a **75-column visual width** with Unicode emojis and ANSI stripping.
212
+ ### Remediation Workflow
247
213
 
248
- ### ๐Ÿ”„ Core Remediation Lifecycle
214
+ ```bash
215
+ # Validate a candidate patch against Ponytail bounds
216
+ torusguard harden fix.patch
249
217
 
250
- | Lifecycle Stage | Mode A: Terminal CLI | Mode B: AI Chat Command | Governed Action & Primary Artifact |
251
- |:---|:---|:---|:---|
252
- | **1. Init** | `npx torusguard init` | `/torusguard init` | Profiles workspace, activates rules, initializes `.torusguard/` |
253
- | **2. Audit** | `npx torusguard audit` | `/torusguard audit` | 74-rule AST scan, line-shift fingerprints, updates `security_report.md` |
254
- | **3. Harden** | `npx torusguard harden` | `/torusguard harden` | Synthesizes Ponytail diffs ($\le 35$ add, $\le 25$ del) into candidate bundles |
255
- | **4. Apply** | `npx torusguard apply [--yes]` | `/torusguard apply` | Human Gate, pre-apply `.bak` snapshots, Golden Fix distillation |
256
- | **5. Rollback**| `npx torusguard rollback` | `/torusguard rollback` | Instant restoration from pre-apply snapshots in `.torusguard/snapshots/` |
257
- | **6. Recheck** | `npx torusguard recheck` | `/torusguard recheck` | Differential AST re-scan; marks findings `RESOLVED ๐ŸŸข` in living report |
218
+ # Apply the patch with rollback snapshot (requires --yes for Human Gate)
219
+ torusguard apply --yes fix.patch
258
220
 
259
- ### ๐Ÿ“Š Intelligence, Memory & Reporting
221
+ # Verify the fix was applied correctly
222
+ torusguard recheck
260
223
 
261
- | Capability | Mode A: Terminal CLI | Mode B: AI Chat Command | Governed Action & Primary Artifact |
262
- |:---|:---|:---|:---|
263
- | **Status** | `npx torusguard status` | `/torusguard status` | 75-column diagnostic overview of health score, stack, memory & rules |
264
- | **Recipes** | `npx torusguard recipes` | `/torusguard recipes` | Explores verified Golden Fix patterns stored in `.torusguard/memory/` |
265
- | **Report** | `npx torusguard report --html` | `/torusguard report` | Emits single-file dark-mode HTML posture report & OASIS SARIF v2.1.0 |
266
- | **Rules Sync**| `npx torusguard rules sync` | `/torusguard rules sync`| Synchronizes prompt guardrails across Cursor, Claude, Antigravity, Windsurf |
267
- | **Diff Guard**| `npx torusguard diff-guard` | `/torusguard diff-guard`| Audits git diffs for security bypasses; `--install-hook` binds pre-commit |
224
+ # Roll back if something went wrong
225
+ torusguard rollback
226
+ ```
268
227
 
269
- ### ๐Ÿงช Runtime Verification & Bounded Probing
228
+ ### Runtime Validation
270
229
 
271
- | Capability | Mode A: Terminal CLI | Mode B: AI Chat Command | Governed Action & Primary Artifact |
272
- |:---|:---|:---|:---|
273
- | **Authorize** | `npx torusguard authorize` | `/torusguard authorize` | Target domain allowlisting, cryptographic ownership proof, TTL limits |
274
- | **Verify** | `npx torusguard verify` | `/torusguard verify` | Asserts evidence sufficiency & live disk line-shift fingerprint matches |
275
- | **Validate** | `npx torusguard web-validate` | `/torusguard web-validate`| Authorized non-destructive HTTP probing with transparent audit headers |
276
- | **Exploit** | `npx torusguard exploit-check`| `/torusguard exploit-check`| Bounded single-step exploitability confirmation using inert sentinels |
230
+ ```bash
231
+ # Generate authorization token for runtime probing
232
+ torusguard authorize
277
233
 
278
- ---
234
+ # Probe a running application for security headers
235
+ torusguard web-validate
279
236
 
280
- ## ๐Ÿ“‹ 74 Canonical Security Rules Catalog (18 Families Across 6 Pillars)
281
-
282
- TorusGuard's AST scanner inspects polyglot source trees across 74 canonical security rules organized into **6 core security pillars** across 18 families:
283
-
284
- ```text
285
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
286
- โ”‚ 74 CANONICAL RULES ACROSS 6 PILLARS โ”‚
287
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
288
- 1. Secrets & Identity โ”€โ”€โ–บ TG-SEC (7) ยท TG-AUTH (8) ยท TG-CLIENT (2)
289
- 2. Data & Injection Defense โ”€โ”€โ–บ TG-DB (4) ยท TG-INPUT (6) ยท TG-CSRF (2)
290
- 3. AI Agent & LLM Security โ”€โ”€โ–บ TG-AGENT (4)
291
- 4. Network & Real-Time โ”€โ”€โ–บ TG-SSRF (4) ยท TG-WEBHOOK (4) ยท TG-WS (4)
292
- 5. Platform & API Limits โ”€โ”€โ–บ TG-RATE (3) ยท TG-GQL (4) ยท TG-PLATFORM (4)
293
- TG-CACHE (3) ยท TG-EDGE (2)
294
- 6. Supply Chain & Governanceโ”€โ”€โ–บ TG-SUPPLY (6) ยท TG-BIZ (4) ยท TG-DIFF (3)
237
+ # Send bounded inert payloads to test input handling
238
+ torusguard exploit-check
295
239
  ```
296
240
 
297
- | Pillar | Family Prefix | Rules | Critical Invariant Enforced |
298
- |:---|:---|:---:|:---|
299
- | **๐Ÿ”‘ Secrets & Client Bundles** | `TG-SEC`, `TG-CLIENT` | **9** | Zero hardcoded API keys, JWT secrets, private certificates, or server keys in client bundles. |
300
- | **๐Ÿ›ก๏ธ Authentication & Sessions** | `TG-AUTH`, `TG-CSRF` | **10** | Timing-safe string compares, strong password hashing, algorithm verification, SameSite cookies. |
301
- | **๐Ÿ—„๏ธ Database & Input Safety** | `TG-DB`, `TG-INPUT` | **10** | Parameterized SQL queries, multi-tenant isolation (`where: { tenantId }`), path sanitization. |
302
- | **๐Ÿค– AI Agent & LLM Guardrails** | `TG-AGENT` | **4** | Structural user prompt isolation, delimiter wrapping, shell tool sandboxing, MCP least-privilege. |
303
- | **๐ŸŒ Network, Webhooks & WS** | `TG-SSRF`, `TG-WEBHOOK`, `TG-WS` | **12** | Private IP range blocking (`169.254.169.254`), HMAC-SHA256 signature checks, WS origin validation. |
304
- | **โšก Platform, Edge & Governance** | `TG-RATE`, `TG-GQL`, `TG-PLATFORM`, `TG-CACHE`, `TG-EDGE`, `TG-SUPPLY`, `TG-BIZ`, `TG-DIFF` | **29** | Auth rate limiting, GraphQL depth bounds, Helmet headers, lockfile integrity, zero `# nosec` bypasses. |
305
-
306
- <details>
307
- <summary><strong>๐Ÿ” Click to expand full 18-family catalog breakdown</strong></summary>
308
-
309
- <br>
310
-
311
- - **`TG-SEC` (Secrets & API Tokens โ€” 7 rules):** Detects hardcoded JWT secrets, private certificates, cloud API keys, environment variable leakage, and secrets in URL queries or logs.
312
- - **`TG-AUTH` (Authentication & Access Control โ€” 8 rules):** Enforces constant-time string comparisons, strong password hashing (`bcrypt`/`argon2`), JWT algorithm pinning, mass assignment prevention, and server-side role verification.
313
- - **`TG-DB` (Database Partitioning & Injection โ€” 4 rules):** Mandates tenant-scoped queries across Prisma, Mongoose, SQLAlchemy, and GORM; eliminates raw SQL string concatenation.
314
- - **`TG-INPUT` (Input Validation & Traversal โ€” 6 rules):** Enforces safe path sanitization (`path.basename`), command argument escaping, safe DOM text assignments, and server-side file upload bounds.
315
- - **`TG-RATE` (Rate Limiting & Resource Protection โ€” 3 rules):** Enforces rate-limiting middleware on authentication routes, pagination bounds, and request payload size limits.
316
- - **`TG-AGENT` (AI Agent & LLM Defense โ€” 4 rules):** Enforces structural separation of user prompts from system instructions, inert XML delimiters, and containerized tool execution.
317
- - **`TG-SSRF` (Server-Side Request Forgery โ€” 4 rules):** Restricts dynamic outbound HTTP calls, blocks AWS/cloud metadata access (`169.254.169.254`), and enforces request timeouts.
318
- - **`TG-WEBHOOK` (Webhook Verification โ€” 4 rules):** Mandates cryptographic HMAC-SHA256 signature validation before body parsing, replay prevention, and timestamp expiration.
319
- - **`TG-WS` (WebSocket Security โ€” 4 rules):** Enforces handshake authentication, origin validation, channel-level authorization, and frame size caps.
320
- - **`TG-CSRF` (Cross-Site Request Forgery โ€” 2 rules):** Enforces anti-CSRF tokens on state-changing operations and `SameSite` cookie attributes.
321
- - **`TG-GQL` (GraphQL Protection โ€” 4 rules):** Enforces query depth limiting, production introspection suppression, and field-level resolver authorization.
322
- - **`TG-SUPPLY` (Supply Chain Integrity โ€” 6 rules):** Audits dependency lockfile presence, checks against known CVEs, prevents `--no-audit` build flags, and inspects build scripts.
323
- - **`TG-BIZ` (Business Logic Bounds โ€” 4 rules):** Validates negative quantity inputs, coupon/discount boundaries, and race-condition transaction locks.
324
- - **`TG-CACHE` (Cache Isolation โ€” 3 rules):** Enforces `Cache-Control: no-store, private` on authenticated responses and sanitizes unkeyed request headers.
325
- - **`TG-CLIENT` (Client Bundle Hygiene โ€” 2 rules):** Forbids importing private server environment variables into browser bundles and suppresses production source maps.
326
- - **`TG-PLATFORM` (Server Hardening โ€” 4 rules):** Enforces Helmet HTTP security headers, CORS origin whitelisting, cookie `secure` flags, and debug mode suppression.
327
- - **`TG-DIFF` (Polyglot Diff Integrity โ€” 3 rules):** Intercepts security bypass comments (`# nosec`, `InsecureSkipVerify: true`) and asserts Ponytail patch budgets.
328
- - **`TG-EDGE` (Edge & Serverless Limits โ€” 2 rules):** Prevents cross-request memory leaks in Cloudflare Workers and enforces subrequest fan-out limits.
329
-
330
- </details>
331
-
332
241
  ---
333
242
 
334
- ## โœ‚๏ธ Ponytail Remediation Protocol & Rollback Safety
243
+ ## ๐Ÿ”ง Commands
244
+
245
+ | Command | Description |
246
+ | :--------------- | :------------------------------------------------------------- |
247
+ | `init` | Scaffold `.torusguard/` workspace, detect stack, activate rules |
248
+ | `status` | Diagnostic overview of posture, stack, and active rules |
249
+ | `audit` | Static heuristic security scan against active TG-* rules |
250
+ | `verify` | Live disk line match audit and evidence sufficiency check |
251
+ | `harden` | Validate patches against Ponytail Protocol bounds |
252
+ | `apply` | Apply patches with pre-apply `.bak` rollback snapshots |
253
+ | `rollback` | Instant restoration from pre-apply snapshots |
254
+ | `recheck` | Differential re-scan on modified files |
255
+ | `report` | Generate HTML (`--html`) or SARIF (`--sarif`) posture reports |
256
+ | `recipes` | Manage the Golden Fix recipe library |
257
+ | `authorize` | Generate cryptographic auth tokens for runtime probing |
258
+ | `web-validate` | Authorized HTTP probing with `X-TorusGuard-Audit` headers |
259
+ | `ocr-scan` | Run Tesseract OCR secret scan on images/diagrams (<10MB) |
260
+ | `mcp` | Run native Model Context Protocol (MCP) server over stdio |
261
+ | `update` | Self-update the TorusGuard engine |
262
+ | `help` | Show interactive command guide |
335
263
 
336
- Traditional AI coding assistants routinely destroy functional features by attempting full-file rewrites. TorusGuard strictly enforces the **Ponytail Protocol**:
264
+ ---
337
265
 
338
- $$\Delta \text{Lines} \le 35\text{ Additions}, \quad \Delta \text{Lines} \le 25\text{ Deletions}$$
266
+ ## ๐Ÿ“ Project Structure
339
267
 
340
- ### ๐Ÿ›ก๏ธ Pre-Apply Rollback Snapshots
341
- Before modifying a single file on disk, `apply_runner.py` creates a byte-for-byte backup:
342
- ```text
343
- .torusguard/snapshots/<run_id>/<target_file>.bak
344
268
  ```
345
-
346
- If a patch causes unforeseen behavior or test failures, execute an instant 1-command rollback:
347
- ```bash
348
- npx torusguard rollback
269
+ TorusGuard/
270
+ โ”œโ”€โ”€ cmd/torusguard/ # CLI entry point, command router & MCP server
271
+ โ”‚ โ”œโ”€โ”€ main.go # CLI command router
272
+ โ”‚ โ””โ”€โ”€ mcp.go # Model Context Protocol (MCP) JSON-RPC 2.0 stdio server
273
+ โ”œโ”€โ”€ internal/
274
+ โ”‚ โ”œโ”€โ”€ apply/ # Patch application + pre-apply snapshot engine
275
+ โ”‚ โ”œโ”€โ”€ harden/ # Ponytail Protocol bounds enforcement
276
+ โ”‚ โ”œโ”€โ”€ memory/ # Golden Fix recipe persistence
277
+ โ”‚ โ”œโ”€โ”€ recheck/ # Differential re-scan engine
278
+ โ”‚ โ”œโ”€โ”€ report/ # SARIF v2.1.0 + dark-mode HTML generators
279
+ โ”‚ โ”œโ”€โ”€ rules/ # TG-* rule catalog loader
280
+ โ”‚ โ”œโ”€โ”€ scanner/ # Heuristic polyglot security scanner + Tesseract OCR
281
+ โ”‚ โ”‚ โ”œโ”€โ”€ scanner.go # Polyglot code AST & heuristic scanner
282
+ โ”‚ โ”‚ โ””โ”€โ”€ ocr.go # Multi-modal Vision OCR secret detection
283
+ โ”‚ โ”œโ”€โ”€ termui/ # 75-column terminal UI formatting
284
+ โ”‚ โ”œโ”€โ”€ validate/ # authorize / web-validate / exploit-check / verify
285
+ โ”‚ โ””โ”€โ”€ workspace/ # init + polyglot stack detection
286
+ โ”œโ”€โ”€ .torusguard/ # Generated workspace state
287
+ โ”‚ โ”œโ”€โ”€ rules/ # Active security rule definitions
288
+ โ”‚ โ”œโ”€โ”€ schemas/ # JSON schemas for findings, recipes, etc.
289
+ โ”‚ โ”œโ”€โ”€ memory/ # Persistent security context
290
+ โ”‚ โ””โ”€โ”€ snapshots/ # Pre-apply rollback backups
291
+ โ”œโ”€โ”€ docs/ # Architecture and usage documentation
292
+ โ”œโ”€โ”€ bin/ # npm package CLI wrapper
293
+ โ”œโ”€โ”€ go.mod # Go module (github.com/torusguard/torusguard)
294
+ โ””โ”€โ”€ package.json # npm package definition
349
295
  ```
350
- All affected files are immediately restored to their exact pre-patch byte state.
351
296
 
352
297
  ---
353
298
 
354
- ## ๐Ÿ“œ Living Security Report Ground Truth (`security_report.md`)
355
-
356
- To eliminate AI hallucination, TorusGuard maintains `security_report.md` at the workspace root as the single source of truth across all CLI commands and AI chat sessions.
357
-
358
- ### ๐Ÿ”„ Lifecycle State Machine
359
- ```text
360
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
361
- โ”‚ SECURITY REPORT LIFECYCLE STATE MACHINE โ”‚
362
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
363
- [ OPEN ๐Ÿ”ด ] โ”€โ”€(verify)โ”€โ”€โ–บ [ VERIFIED ๐ŸŸ  ] โ”€โ”€(harden)โ”€โ”€โ–บ [ CANDIDATE ๐ŸŸก ]
364
- โ”‚
365
- (apply)
366
- โ”‚
367
- โ–ผ
368
- [ RESOLVED ๐ŸŸข ] โ—„โ”€โ”€(recheck: confirmed)โ”€โ”€ [ APPLIED ๐Ÿ”ต ]
369
- โ”‚
370
- โ””โ”€โ”€(recheck: failed)โ”€โ”€โ–บ [ REGRESSED โŒ ]
371
- ```
372
-
373
- ### ๐Ÿงฎ Posture Health Score (0โ€“100)
374
- The Health Score dynamically reflects the open risk ledger:
375
- $$\text{Penalty} = (25 \times \text{Critical}) + (15 \times \text{High}) + (5 \times \text{Medium}) + (2 \times \text{Low})$$
376
- $$\text{Score} = \max(0, \min(100, 100 - \text{Penalty}))$$
377
-
378
- *When all findings are verified closed via differential recheck, the repository achieves **Health Score: 100/100 ๐ŸŸข Hardened & Secure**.*
299
+ ## ๐Ÿ”’ Security Rules (74 Rules, 18 Families)
300
+
301
+ | Family | Domain | Rules | Core Invariant |
302
+ | :------------- | :------------------------------- | :---: | :------------------------------------------------------- |
303
+ | `TG-SEC` | Core Secrets & API Tokens | 7 | Zero hardcoded API keys or JWT secrets in source |
304
+ | `TG-AUTH` | Authentication & Sessions | 8 | Timing-safe compares, strong hashing, algorithm verify |
305
+ | `TG-DB` | Database Isolation & Injection | 4 | Parameterized queries and tenant partition scoping |
306
+ | `TG-INPUT` | Input Sanitization & Traversal | 6 | Strict path sanitization, safe DOM assignments |
307
+ | `TG-RATE` | Rate Limiting & Resources | 3 | Rate-limiting on auth endpoints, payload size bounds |
308
+ | `TG-AGENT` | AI Agent & LLM Injection | 4 | Structural prompt isolation, tool call schema validation |
309
+ | `TG-SSRF` | Server-Side Request Forgery | 4 | Hostname whitelisting, private IP range blocking |
310
+ | `TG-WEBHOOK` | Inbound Webhook Verification | 4 | HMAC-SHA256 signature verification, replay prevention |
311
+ | `TG-WS` | WebSocket & Real-Time | 4 | Origin verification, handshake auth, frame size limits |
312
+ | `TG-CSRF` | Cross-Site Request Forgery | 2 | SameSite cookies, anti-CSRF token verification |
313
+ | `TG-GQL` | GraphQL Safety | 4 | Query depth limiting, introspection suppression |
314
+ | `TG-SUPPLY` | Supply Chain & Dependencies | 6 | Lockfile integrity, known CVE audits |
315
+ | `TG-BIZ` | Business Logic & Workflows | 4 | Negative amount validation, transaction locks |
316
+ | `TG-CACHE` | Cache Poisoning & Timing | 3 | Cache-control headers, unkeyed header sanitization |
317
+ | `TG-CLIENT` | Client Bundle & Frontend | 2 | Zero private env vars in client bundles |
318
+ | `TG-PLATFORM` | Server Hardening & Headers | 4 | Helmet headers, debug suppression, cookie secure flags |
319
+ | `TG-DIFF` | Polyglot Bypass & Churn | 3 | Block `# nosec`, `InsecureSkipVerify`, churn bounds |
320
+ | `TG-EDGE` | Edge Computing & Serverless | 2 | Subrequest fan-out limits, execution timeouts |
379
321
 
380
322
  ---
381
323
 
382
- ## ๐Ÿ“Š Visual HTML Dashboard & SARIF v2.1.0 Export
324
+ ## ๐Ÿค– AI Agent Integration
383
325
 
384
- Generate a standalone, zero-external-CDN, dark-mode visual posture dashboard:
385
- ```bash
386
- npx torusguard report --html
387
- ```
388
- - **SVG Circular Posture Gauge:** Animated visual health score ($0-100$).
389
- - **7-Stage Closed-Loop Pipeline:** Visual state timeline across all lifecycle phases.
390
- - **Golden Fix Recipes Grid:** Syntax-highlighted unified diffs with Ponytail metrics.
391
- - **Zero-CDN Architecture:** Completely offline-ready; embeds all styles and assets inline.
326
+ TorusGuard works natively inside AI coding assistants. Add the configuration file to your project root and your AI agent automatically enforces TorusGuard security invariants.
392
327
 
393
- To integrate with **GitHub Code Scanning**, export standard SARIF:
394
- ```bash
395
- npx torusguard report > results.sarif
396
- ```
328
+ ### Supported Agents
397
329
 
398
- ---
330
+ | Agent | Configuration File | Status |
331
+ | :------------------- | :-------------------- | :----- |
332
+ | Antigravity (Gemini) | `AGENTS.md` | โœ… Full support |
333
+ | Claude Code | `CLAUDE.md` | โœ… Full support |
334
+ | Cursor | `.cursorrules` | โœ… Full support |
335
+ | Windsurf | `.windsurfrules` | โœ… Full support |
336
+ | VS Code Copilot | `AGENTS.md` | โœ… Full support |
337
+ | Kimi | `SKILL.md` | โœ… Full support |
399
338
 
400
- ## ๐Ÿค– AI Editor Guardrails Auto-Sync
339
+ ### Slash Commands (AI Chat Mode)
401
340
 
402
- TorusGuard compiles project security invariants, golden recipes, and active guardrails into prompt-optimized rule files:
403
- ```bash
404
- npx torusguard rules sync
341
+ ```
342
+ /torusguard init # Initialize workspace
343
+ /torusguard audit # Run security + OCR scan; sync security_report.md
344
+ /torusguard ocr-scan # Scan diagram or image assets for leaked credentials
345
+ /torusguard harden # Formulate remediation patches
346
+ /torusguard apply # Apply patches with Human Gate
347
+ /torusguard recheck # Verify fix closure
348
+ /torusguard report # Generate posture report
349
+ /torusguard status # Check posture overview
350
+ /torusguard full # End-to-end 7-stage pipeline
405
351
  ```
406
352
 
407
- ### Supported AI Editors:
408
- - **Cursor:** Injects non-destructive rules into `.cursorrules`
409
- - **Claude Code:** Injects non-destructive rules into `CLAUDE.md`
410
- - **Antigravity IDE:** Injects non-destructive rules into `.agent/rules/torusguard.md`
411
- - **Windsurf:** Injects non-destructive rules into `.windsurfrules`
412
-
413
- *All rules are compiled under a strict overhead ceiling of $\le 300$ prompt tokens to preserve AI reasoning context.*
414
-
415
- ---
353
+ ### Native MCP Tools (Agent Toolkit Mode)
416
354
 
417
- ## ๐Ÿข Monorepo Fleet Support & Git Pre-Commit Diff Guard
355
+ When configured with `.agents/mcp_config.json` or `mcp_config.json`, AI coding agents gain native tool calling:
418
356
 
419
- TorusGuard automatically discovers and profiles multi-package workspaces:
420
- - **Monorepo Ecosystems:** pnpm workspaces, npm/yarn workspaces, Cargo workspaces, Go multi-module workspaces, Gradle multi-project builds.
421
- - **Universal Polyglot Profiler:** Automatically identifies 16+ languages and maps ORM boundaries independently per sub-package.
422
- - **Pre-Commit Diff Guard:** Run `npx torusguard diff-guard --install-hook` to bind `.git/hooks/pre-commit` and block security bypasses before code is committed.
357
+ - `torusguard_audit`: Deep static AST scan + Vision OCR; writes `security_report.md`
358
+ - `torusguard_ocr_scan`: Dedicated image credential analysis via Tesseract (5-10MB bounds)
359
+ - `torusguard_harden`: Validates remediation diff against Ponytail Protocol bounds
360
+ - `torusguard_recheck`: Differential re-scan confirming fix closure
361
+ - `torusguard_status`: Workspace posture and tech stack inspection
362
+ - `torusguard://security_report`: MCP Resource reading the living security report
423
363
 
424
364
  ---
425
365
 
426
- ## ๐Ÿงช Verification & Test Harness
366
+ ## ๐Ÿงช Verified Test Suite & Mass Benchmarks
427
367
 
428
- ### What Happens When You Run `npm test`?
429
- TorusGuard enforces a strict **100% pass requirement across 120 test suites** before every release.
430
- The test harness runs with **zero third-party dependencies** via standard Python 3:
368
+ TorusGuard undergoes rigorous automated multi-tier testing across polyglot stacks, multi-modal vision assets, and agent communication protocols:
431
369
 
432
- ```bash
433
- npm test
434
- # Equivalent to: python harness/runner.py
435
- ```
370
+ | Testing Tier | Scope & Target Stacks | Pass Rate | Verified Capabilities |
371
+ | :--- | :--- | :---: | :--- |
372
+ | **Go Engine & Unit Tests** | `cmd/torusguard`, `internal/scanner`, `internal/*` | **100% Passing** | Deterministic AST matching, 74 rule patterns, JSON-RPC 2.0 MCP protocol. |
373
+ | **Mass Polyglot Benchmarks** | **20 Enterprise Tech Stacks** (Go, Python, Java, Node, Rust, PHP, C#, Ruby, Svelte, Vue, Angular) | **20/20 Passed** | Framework auto-profiling, heuristic AST analysis, finding deduplication. |
374
+ | **Tri-Mode & Vision E2E** | **16 Diverse Framework Repos** (React, Next.js, Express, Django, FastAPI, Spring Boot, etc.) | **16/16 Passed** | Mode A (CLI) + Mode B (Slash Commands) + Mode C (Native MCP Tools) + Multi-Modal Vision OCR. |
375
+ | **Multi-Modal Vision OCR** | Diagram & Image assets (`.png`, `.jpg`, etc.) via Tesseract v5.4.0 | **100% Recall** | Secrets detection (`TG-SEC-001` - `TG-SEC-007`), 10MB DoS bounding, OCR character substitution tolerance. |
376
+ | **Ponytail Churn Limits** | Surgical patch validation across all 74 rules | **Bounded** | Line bounds (โ‰ค35 additions, โ‰ค25 deletions), zero-bypass verification (`TG-DIFF-001`). |
436
377
 
437
- When a developer runs:
438
- ```bash
439
- npm test
440
- ```
441
- The test harness invokes `python harness/runner.py` directly using the Python standard library. It systematically verifies:
442
- 1. **JSON Schema Validity:** 10 formal schemas (`finding`, `evidence`, `remediation`, `rule`, `lifecycle`, `provenance`, etc.).
443
- 2. **74-Rule Catalog Integrity:** AST detection accuracy across all 18 security families.
444
- 3. **Line-Shift Fingerprinting:** Stable anchor matching across file edits without line number drift.
445
- 4. **Secret Redaction:** Stripe secret keys and JWT tokens safely masked.
446
- 5. **Deterministic Replay:** 3-pass differential validation across Django, DRF, FastAPI, Flask, and SQLAlchemy fixtures.
447
- 6. **Ponytail Patch Churn Bounds:** Verifying line budgets ($\le 35$ additions, $\le 25$ deletions).
448
- 7. **Living Security Report State Transitions:** Discovery (`OPEN ๐Ÿ”ด`), Candidate (`CANDIDATE ๐ŸŸก`), Applied (`APPLIED ๐Ÿ”ต`), and Verified Closure (`RESOLVED ๐ŸŸข`).
378
+ All test environments are completely sandboxed, verified with byte-for-byte assertions, and cleaned up automatically.
449
379
 
450
- ```bash
451
- # Run formal TorusGuard test harness
452
- npm test
380
+ ---
453
381
 
454
- # Expected Output:
455
- # ================================================================================
456
- # SUMMARY: 120 Passed | 0 Failed
457
- # ================================================================================
458
- ```
382
+ ## ๐Ÿ›ก๏ธ Non-Negotiable Invariants
459
383
 
460
- To validate diff guard and monorepo profiling independently:
461
- ```bash
462
- python harness/validate_v0_9_2_diff_and_monorepo.py
463
- ```
384
+ 1. **Browser-Code Truth:** Never expose secrets in frontend bundles.
385
+ 2. **Multi-Tenant Isolation:** Always scope DB lookups by tenant/user ownership.
386
+ 3. **Ponytail Churn Bounds:** Patches โ‰ค35 additions, โ‰ค25 deletions. No full-file rewrites.
387
+ 4. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`.
388
+ 5. **Snapshots Before Edits:** Mandatory `.bak` backup before every modification.
389
+ 6. **Fail-Closed Cryptography:** Panic on entropy failure. No fallback tokens.
390
+ 7. **SSRF Boundary Enforcement:** Block private IPs and cloud metadata before probing.
391
+ 8. **DoS Resilience:** 10,000-file max, 5-minute timeout.
464
392
 
465
393
  ---
466
394
 
467
- ## ๐Ÿ”’ Security Policy & Responsible Disclosure
395
+ ## ๐Ÿค Contributing
468
396
 
469
- If you believe you have discovered a security vulnerability in TorusGuard itself, please report it responsibly and privately through [GitHub Private Vulnerability Reporting](https://github.com/githubmofo/TorusGuard/security/advisories/new) or contact the project maintainers. Do not file public issues for undisclosed security flaws. For complete details, consult [SECURITY.md](SECURITY.md).
397
+ 1. Fork the repository
398
+ 2. Create a feature branch: `git checkout -b feat/your-feature`
399
+ 3. Commit changes: `git commit -m "feat: add your feature"`
400
+ 4. Push to branch: `git push origin feat/your-feature`
401
+ 5. Open a Pull Request
402
+
403
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for community standards.
470
404
 
471
405
  ---
472
406
 
473
407
  ## ๐Ÿ“„ License
474
408
 
475
- TorusGuard is released under the [MIT License](LICENSE).
476
- Copyright (c) 2026 Jenish Lad ([@githubmofo](https://github.com/githubmofo)).
409
+ [MIT](LICENSE) ยฉ 2026 Jenish Lad
410
+
411
+ ---
412
+
413
+ ## ๐Ÿ“š Documentation
414
+
415
+ | Document | Description |
416
+ | :-------------------------------------------------------- | :--------------------------------------- |
417
+ | [Architecture](docs/architecture/ARCHITECTURE.md) | System design and module relationships |
418
+ | [Security Architecture](docs/architecture/SECURITY_ARCHITECTURE.md) | Threat model and security design |
419
+ | [Detection Engine](docs/architecture/DETECTION_ENGINE.md) | Scanner internals and rule matching |
420
+ | [API Specification](docs/architecture/API_SPECIFICATION.md) | CLI argument specification |
421
+ | [Security Philosophy](docs/overview/security-philosophy.md) | Core design principles |
422
+ | [Testing Playbook](docs/usage/testing-playbook.md) | Testing guide and CI integration |
423
+ | [Demo Guide](docs/demo.md) | Quick start and full lifecycle demo |
424
+ | [Roadmap](docs/roadmap.md) | Feature roadmap and release planning |
425
+ | [SECURITY.md](SECURITY.md) | Vulnerability disclosure policy |
426
+ | [CHANGELOG.md](CHANGELOG.md) | Version history and release notes |