torusguard 1.4.0 โ†’ 2.1.0

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 (160) hide show
  1. package/.torusguard/.manifest.json +50 -28
  2. package/.torusguard/auth.json +5 -0
  3. package/.torusguard/rules/container/TG-CONT-001-root-user-execution.md +50 -0
  4. package/.torusguard/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
  5. package/.torusguard/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
  6. package/.torusguard/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
  7. package/.torusguard/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
  8. package/.torusguard/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
  9. package/.torusguard/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
  10. package/.torusguard/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
  11. package/.torusguard/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
  12. package/.torusguard/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
  13. package/.torusguard/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
  14. package/.torusguard/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
  15. package/.torusguard/rules_catalog.json +338 -518
  16. package/.torusguard/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
  17. package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  18. package/.torusguard/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
  19. package/.torusguard/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  20. package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
  21. package/.torusguard/scripts/__pycache__/recipes_runner.cpython-314.pyc +0 -0
  22. package/.torusguard/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  23. package/.torusguard/scripts/manifest_builder.py +1 -1
  24. package/.torusguard/skills/torusguard/SKILL.md +69 -24
  25. package/.torusguard/skills/torusguard/bootstrap.py +57 -24
  26. package/.torusguard/skills/torusguard-ai-guard/SKILL.md +95 -0
  27. package/.torusguard/skills/torusguard-apply/SKILL.md +60 -34
  28. package/.torusguard/skills/torusguard-audit/SKILL.md +73 -24
  29. package/.torusguard/skills/torusguard-authorize/SKILL.md +48 -6
  30. package/.torusguard/skills/torusguard-container/SKILL.md +94 -0
  31. package/.torusguard/skills/torusguard-exploit-check/SKILL.md +50 -6
  32. package/.torusguard/skills/torusguard-full/SKILL.md +62 -19
  33. package/.torusguard/skills/torusguard-git-mine/SKILL.md +92 -0
  34. package/.torusguard/skills/torusguard-harden/SKILL.md +81 -50
  35. package/.torusguard/skills/torusguard-init/SKILL.md +61 -14
  36. package/.torusguard/skills/torusguard-ocr-scan/SKILL.md +94 -0
  37. package/.torusguard/skills/torusguard-recheck/SKILL.md +71 -18
  38. package/.torusguard/skills/torusguard-redos/SKILL.md +91 -0
  39. package/.torusguard/skills/torusguard-report/SKILL.md +50 -9
  40. package/.torusguard/skills/torusguard-status/SKILL.md +63 -10
  41. package/.torusguard/skills/torusguard-verify/SKILL.md +52 -10
  42. package/.torusguard/skills/torusguard-web-validate/SKILL.md +53 -8
  43. package/.torusguard/snapshots/20260921-182638/go.mod.bak +11 -0
  44. package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
  45. package/.torusguard/workflows/ai-guard.md +31 -0
  46. package/.torusguard/workflows/apply.md +32 -55
  47. package/.torusguard/workflows/audit.md +28 -46
  48. package/.torusguard/workflows/authorize.md +27 -50
  49. package/.torusguard/workflows/container.md +29 -0
  50. package/.torusguard/workflows/exploit-check.md +28 -50
  51. package/.torusguard/workflows/git-mine.md +25 -0
  52. package/.torusguard/workflows/harden.md +29 -48
  53. package/.torusguard/workflows/init.md +27 -50
  54. package/.torusguard/workflows/memory.md +18 -23
  55. package/.torusguard/workflows/ocr-scan.md +25 -0
  56. package/.torusguard/workflows/recheck.md +28 -46
  57. package/.torusguard/workflows/redos.md +27 -0
  58. package/.torusguard/workflows/report.md +33 -52
  59. package/.torusguard/workflows/status.md +31 -52
  60. package/.torusguard/workflows/verify.md +29 -49
  61. package/.torusguard/workflows/web-validate.md +22 -45
  62. package/README.md +336 -386
  63. package/package.json +1 -1
  64. package/skills/torusguard/SKILL.md +71 -24
  65. package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
  66. package/skills/torusguard/bootstrap.py +60 -71
  67. package/skills/torusguard/payload/.manifest.json +50 -28
  68. package/skills/torusguard/payload/TORUSGUARD.md +145 -145
  69. package/skills/torusguard/payload/agents/auditor.md +41 -41
  70. package/skills/torusguard/payload/agents/profiler.md +49 -49
  71. package/skills/torusguard/payload/agents/remediator.md +41 -41
  72. package/skills/torusguard/payload/agents/reviewer.md +39 -39
  73. package/skills/torusguard/payload/agents/validator.md +46 -46
  74. package/skills/torusguard/payload/config/scope.json +24 -24
  75. package/skills/torusguard/payload/references/csharp-security.md +41 -41
  76. package/skills/torusguard/payload/references/go-security.md +41 -41
  77. package/skills/torusguard/payload/references/java-security.md +40 -40
  78. package/skills/torusguard/payload/references/polyglot-security-matrix.md +25 -25
  79. package/skills/torusguard/payload/references/rust-security.md +40 -40
  80. package/skills/torusguard/payload/rules/container/TG-CONT-001-root-user-execution.md +50 -0
  81. package/skills/torusguard/payload/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
  82. package/skills/torusguard/payload/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
  83. package/skills/torusguard/payload/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
  84. package/skills/torusguard/payload/rules/custom/.gitkeep +1 -1
  85. package/skills/torusguard/payload/rules/custom/README.md +30 -30
  86. package/skills/torusguard/payload/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
  87. package/skills/torusguard/payload/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
  88. package/skills/torusguard/payload/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
  89. package/skills/torusguard/payload/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
  90. package/skills/torusguard/payload/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
  91. package/skills/torusguard/payload/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
  92. package/skills/torusguard/payload/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
  93. package/skills/torusguard/payload/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
  94. package/skills/torusguard/payload/rules_catalog.json +338 -518
  95. package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
  96. package/skills/torusguard/payload/scripts/manifest_builder.py +1 -1
  97. package/skills/torusguard/payload/scripts/rules_sync.py +321 -321
  98. package/skills/torusguard/payload/scripts/safety_gate.py +64 -64
  99. package/skills/torusguard/payload/skills/torusguard/SKILL.md +69 -24
  100. package/skills/torusguard/payload/skills/torusguard/bootstrap.py +57 -24
  101. package/skills/torusguard/payload/skills/torusguard-ai-guard/SKILL.md +95 -0
  102. package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +60 -34
  103. package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +73 -24
  104. package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +48 -6
  105. package/skills/torusguard/payload/skills/torusguard-container/SKILL.md +94 -0
  106. package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +50 -6
  107. package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +62 -19
  108. package/skills/torusguard/payload/skills/torusguard-git-mine/SKILL.md +92 -0
  109. package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +81 -50
  110. package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +61 -14
  111. package/skills/torusguard/payload/skills/torusguard-ocr-scan/SKILL.md +94 -0
  112. package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +71 -18
  113. package/skills/torusguard/payload/skills/torusguard-redos/SKILL.md +91 -0
  114. package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +50 -9
  115. package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +63 -10
  116. package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +52 -10
  117. package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +53 -8
  118. package/skills/torusguard/payload/templates/audit-report.template.md +54 -54
  119. package/skills/torusguard/payload/templates/authorization.template.md +34 -34
  120. package/skills/torusguard/payload/templates/finding-card.template.md +32 -32
  121. package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -35
  122. package/skills/torusguard/payload/workflows/ai-guard.md +31 -0
  123. package/skills/torusguard/payload/workflows/apply.md +31 -62
  124. package/skills/torusguard/payload/workflows/audit.md +27 -51
  125. package/skills/torusguard/payload/workflows/authorize.md +27 -50
  126. package/skills/torusguard/payload/workflows/container.md +29 -0
  127. package/skills/torusguard/payload/workflows/exploit-check.md +28 -50
  128. package/skills/torusguard/payload/workflows/git-mine.md +25 -0
  129. package/skills/torusguard/payload/workflows/harden.md +28 -52
  130. package/skills/torusguard/payload/workflows/init.md +27 -56
  131. package/skills/torusguard/payload/workflows/memory.md +18 -23
  132. package/skills/torusguard/payload/workflows/ocr-scan.md +25 -0
  133. package/skills/torusguard/payload/workflows/recheck.md +28 -46
  134. package/skills/torusguard/payload/workflows/redos.md +27 -0
  135. package/skills/torusguard/payload/workflows/report.md +39 -62
  136. package/skills/torusguard/payload/workflows/status.md +31 -55
  137. package/skills/torusguard/payload/workflows/verify.md +29 -49
  138. package/skills/torusguard/payload/workflows/web-validate.md +22 -45
  139. package/skills/torusguard/references/csharp-security.md +41 -0
  140. package/skills/torusguard/references/go-security.md +41 -0
  141. package/skills/torusguard/references/java-security.md +40 -0
  142. package/skills/torusguard/references/polyglot-security-matrix.md +25 -0
  143. package/skills/torusguard/references/rust-security.md +40 -0
  144. package/skills/torusguard-ai-guard/SKILL.md +95 -0
  145. package/skills/torusguard-apply/SKILL.md +60 -34
  146. package/skills/torusguard-audit/SKILL.md +73 -24
  147. package/skills/torusguard-authorize/SKILL.md +48 -6
  148. package/skills/torusguard-container/SKILL.md +94 -0
  149. package/skills/torusguard-exploit-check/SKILL.md +50 -6
  150. package/skills/torusguard-full/SKILL.md +62 -19
  151. package/skills/torusguard-git-mine/SKILL.md +92 -0
  152. package/skills/torusguard-harden/SKILL.md +81 -50
  153. package/skills/torusguard-init/SKILL.md +61 -14
  154. package/skills/torusguard-ocr-scan/SKILL.md +94 -0
  155. package/skills/torusguard-recheck/SKILL.md +71 -18
  156. package/skills/torusguard-redos/SKILL.md +91 -0
  157. package/skills/torusguard-report/SKILL.md +50 -9
  158. package/skills/torusguard-status/SKILL.md +63 -10
  159. package/skills/torusguard-verify/SKILL.md +52 -10
  160. package/skills/torusguard-web-validate/SKILL.md +53 -8
package/README.md CHANGED
@@ -1,504 +1,454 @@
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.4.0-cb3837.svg?style=flat-square&logo=npm)](https://www.npmjs.com/package/torusguard)
13
- [![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-v1.4.0-181717.svg?style=flat-square&logo=github)](https://github.com/githubmofo/TorusGuard/pkgs/npm/torusguard)
14
- [![Release](https://img.shields.io/badge/Release-v1.4.0-blue.svg?style=flat-square)](https://github.com/githubmofo/TorusGuard/releases/latest)
15
- [![Tests](https://img.shields.io/badge/Tests-133%2F133%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
- [![Go 1.22+](https://img.shields.io/badge/Go-1.22%2B-00ADD8.svg?style=flat-square&logo=go&logoColor=white)](https://go.dev)
22
- [![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)
23
- [![SARIF: v2.1.0](https://img.shields.io/badge/SARIF-v2.1.0%20OASIS-purple.svg?style=flat-square)](.torusguard/schemas/)
24
- [![OWASP: Top 10](https://img.shields.io/badge/OWASP-Top%2010%20Aligned-orange.svg?style=flat-square)](docs/architecture/SECURITY_ARCHITECTURE.md)
25
- [![Privacy](https://img.shields.io/badge/Privacy-100%25%20Local%20Zero--Egress-success.svg?style=flat-square)](docs/overview/security-philosophy.md)
26
- </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-v2.1.0-orange.svg" alt="Version"></a>
15
+ <a href="https://www.npmjs.com/package/torusguard"><img src="https://img.shields.io/badge/npm-v2.1.0-CB3837?logo=npm&logoColor=white" alt="npm: v2.1.0"></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-86%2F86%20Rules-success" alt="Rules: 86/86 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>
27
38
 
28
39
  ---
29
40
 
30
- > **The Developer Reality:** AI coding assistants (Cursor, Claude Code, Copilot, Windsurf, Antigravity) 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.
31
- > **TorusGuard forms an unbroken local guardrail around your codebase.** It audits static ASTs across 74 rules, 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`.
41
+ ## Table of Contents
42
+
43
+ - [What Is TorusGuard?](#what-is-torusguard)
44
+ - [Features](#-features)
45
+ - [Autonomous Architecture & Workflow](#-autonomous-architecture--workflow)
46
+ - [Prerequisites](#-prerequisites)
47
+ - [Installation](#-installation)
48
+ - [Usage](#-usage)
49
+ - [Commands](#-commands)
50
+ - [Project Structure](#-project-structure)
51
+ - [Security Invariants & Rule Governance](#-security-invariants--rule-governance)
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)
32
58
 
33
59
  ---
34
60
 
35
- ## ๐Ÿ“‘ Table of Contents
36
-
37
- 1. [Developer Overview & Value Proposition](#-developer-overview--value-proposition)
38
- 2. [End-to-End Autonomous Architecture](#-end-to-end-autonomous-architecture)
39
- 3. [Why TorusGuard? (Traditional SAST vs. AI Coding vs. TorusGuard)](#-why-torusguard)
40
- 4. [Installation & Setup Guide (npm, Go & CLI)](#-installation--setup-guide-npm-go--cli)
41
- 5. [Quickstart: The 5-Step Core Lifecycle](#-quickstart-the-5-step-core-lifecycle)
42
- 6. [Dual-Strategy Command Matrix (CLI & AI Chat Parity)](#-dual-strategy-command-matrix-cli--ai-chat-parity)
43
- 7. [Polyglot Go Engine & Native Runner](#-polyglot-go-engine--native-runner)
44
- 8. [Package Self-Update Engine (`update`)](#-package-self-update-engine-update)
45
- 9. [74 Canonical Security Rules Catalog (18 Families Across 6 Pillars)](#-74-canonical-security-rules-catalog-18-families-across-6-pillars)
46
- 10. [Ponytail Remediation Protocol & Rollback Safety](#-ponytail-remediation-protocol--rollback-safety)
47
- 11. [Living Security Report Ground Truth (`security_report.md`)](#-living-security-report-ground-truth-security_reportmd)
48
- 12. [Visual HTML Dashboard & SARIF v2.1.0 Export](#-visual-html-dashboard--sarif-v210-export)
49
- 13. [AI Editor Guardrails Auto-Sync](#-ai-editor-guardrails-auto-sync)
50
- 14. [Monorepo Fleet Support & Git Pre-Commit Diff Guard](#-monorepo-fleet-support--git-pre-commit-diff-guard)
51
- 15. [Verification & Test Harness (133/133 Passing Harness Explained)](#-verification--test-harness)
52
- 16. [Security Policy & Responsible Disclosure](#-security-policy--responsible-disclosure)
53
- 17. [License](#-license)
61
+ ## What Is TorusGuard?
62
+
63
+ TorusGuard is a **zero-dependency, single-binary security engine** that scans, hardens, and validates AI-generated codebases. It enforces 86 security rules across 22 architectural families and works across three unified operational modes (**Tri-Mode Parity**):
64
+
65
+ - **Mode A: Terminal CLI (Go Binary)** โ€” A deterministic scanner and enforcer that runs in your terminal or CI/CD pipeline (`torusguard <command>`).
66
+ - **Mode B: AI Chat Slash Commands** โ€” Integrates natively with Antigravity, Cursor, Claude Code, Windsurf, VS Code, and other AI coding assistants via slash commands (`/torusguard <command>`).
67
+ - **Mode C: Native MCP Tools** โ€” Stdio Model Context Protocol (JSON-RPC 2.0) interface exposing autonomous security tools and living resources directly to AI agents.
68
+
69
+ TorusGuard ensures that the code your AI assistant writes is secure *before* it reaches production.
54
70
 
55
71
  ---
56
72
 
57
- ## ๐Ÿ’ก Developer Overview & Value Proposition
73
+ ## โœจ Features
74
+
75
+ - **86 Security Rules** across 22 families (Secrets, Auth, SQL Injection, SSRF, CSRF, GraphQL, Supply Chain, Containers, Git History, ReDoS, AI & RAG, and more)
76
+ - **First-Principles Security Suite** โ€” Built-in native scanners for Dockerfile/Compose privilege bounds, Git commit log secret mining, exponential regex backtracking, and cross-tenant vector isolation
77
+ - **Heuristic AST Scanner** โ€” Polyglot static analysis for Go, JavaScript, TypeScript, and Python
78
+ - **Line-Level Reflection Module** โ€” Semantic patch synthesis (`find_snippet` / `replace_snippet`) that accurately replaces exact code blocks without brittle line-number offsets
79
+ - **1/9th Token Bounded Context Extraction** โ€” AST context extraction (ยฑ3 lines) via `scanner.ExtractContext` to keep review prompts hyper-efficient and prevent context saturation
80
+ - **Ponytail Protocol** โ€” Surgical patch bounds (โ‰ค35 additions, โ‰ค25 deletions) to prevent full-file rewrites
81
+ - **Pre-Apply Snapshots** โ€” Automatic `.bak` rollback snapshots before every code modification
82
+ - **SARIF v2.1.0 Export** โ€” Standards-compliant output for GitHub Advanced Security, VS Code, and other SARIF consumers
83
+ - **Dark-Mode HTML Reports** โ€” Single-file visual posture dashboards
84
+ - **Golden Fix Recipes** โ€” Persistent memory of verified security patterns for reuse
85
+ - **SSRF Defense** โ€” Built-in private IP blocking and AWS metadata protection in the web validator
86
+ - **Fail-Closed Cryptography** โ€” No fallback tokens; panics on entropy failure
87
+ - **DoS Resilience** โ€” 10,000-file scan limit and 5-minute context timeout to prevent resource exhaustion
88
+ - **16+ Language Stack Detection** โ€” Go, Rust, Java, C#, PHP, Ruby, Kotlin, Elixir, Dart, Swift, Python, TypeScript, and more
89
+ - **Multi-Modal Vision OCR** โ€” Scans architecture diagrams, mockups, and screenshots (`.png`, `.jpg`, `.webp`) via Tesseract OCR to detect leaked keys, tokens, and credentials
90
+ - **Native MCP Server (Model Context Protocol)** โ€” Exposes standard JSON-RPC 2.0 stdio tools and resources for direct agent integration
91
+ - **Tri-Mode Parity** โ€” Terminal CLI, AI Chat slash commands, and Native MCP Tools share identical governance workflows
92
+
93
+ ---
58
94
 
59
- 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:
60
- - **Exposing Private Credentials:** Leaking `process.env.SUPABASE_SERVICE_ROLE_KEY` or master database connection strings into Next.js `'use client'` bundles.
61
- - **Dropping Tenant Boundaries:** Querying Prisma or Mongoose by record ID without scoping by tenant (`where: { id }` instead of `where: { id, tenantId }`).
62
- - **Prompt Injection Vulnerabilities:** Interpolating untrusted user chat messages directly into system prompts.
63
- - **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.
95
+ ## ๐Ÿงช Proven Compatibility
64
96
 
65
- **TorusGuard solves this deterministically:**
66
- - **Zero-Egress Local Execution:** 100% of scanning and patching happens on your machine. Zero code or tokens are transmitted to external servers.
67
- - **Zero Pip Dependencies:** Pure Python standard library (`pathlib`, `re`, `json`, `difflib`, `shutil`). No virtualenv conflicts or broken build wheels.
68
- - **Ponytail Churn Bounds:** Patches are constrained strictly to $\le 35$ additions and $\le 25$ deletions. Surrounding business logic is never rewritten.
69
- - **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.
97
+ TorusGuardโ€™s static scanner and enforcement binary have been rigorously tested and confirmed compatible across **20 major technology stacks and frameworks**:
70
98
 
71
- ### ๐ŸŒ The Browser-Code Truth Invariant
72
- > **"If the browser receives it, users can inspect it via DevTools."**
73
- > 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.
99
+ | Ecosystem | Tested Frameworks & Runtimes |
100
+ |-----------|------------------------------|
101
+ | **JavaScript / TypeScript** | React, Next.js, Express, Vue, Angular, SvelteKit, NestJS |
102
+ | **Python** | Django, Flask, FastAPI, raw Python scripts |
103
+ | **Go** | Gin |
104
+ | **Java / C# (.NET)** | Spring Boot, ASP.NET Core, .NET Core Middleware |
105
+ | **Ruby** | Ruby on Rails, Sinatra |
106
+ | **PHP** | Laravel, Symfony |
107
+ | **Rust** | Actix Web |
74
108
 
75
109
  ---
76
110
 
77
- ## ๐Ÿ“ End-to-End Autonomous Architecture
111
+ ## ๐Ÿ—๏ธ Autonomous Architecture & Workflow
78
112
 
79
- The following flowchart illustrates how TorusGuard safeguards your repository from initial developer input to verified, regression-free output:
113
+ TorusGuard uses a **tri-track architecture** where intelligence, deterministic enforcement, and agent tool execution are cleanly separated across three unified operational modes:
80
114
 
81
115
  ```mermaid
82
116
  flowchart TD
83
- subgraph In ["1. Workspace & AI Context"]
84
- A1["Polyglot Source Tree (16+ Languages)"]
85
- A2["AI Coding Assistant (Cursor / Claude / Antigravity)"]
86
- A3["Git Staged Diffs / Pre-Commit Hook"]
117
+ subgraph Ingress["Unified Tri-Mode Ingress"]
118
+ ModeA["<b>Mode A: Terminal CLI</b><br/><code>torusguard &lt;cmd&gt;</code><br/>Deterministic Single Binary"]
119
+ ModeB["<b>Mode B: AI Chat Slash Commands</b><br/><code>/torusguard &lt;cmd&gt;</code><br/>Cursor &bull; Claude &bull; Windsurf &bull; Antigravity"]
120
+ ModeC["<b>Mode C: Native MCP Tools</b><br/><code>torusguard_*</code> (10 Tools &bull; 2 Resources)<br/>Stdio JSON-RPC 2.0 Agent Server"]
87
121
  end
88
122
 
89
- subgraph Core ["2. TorusGuard Engine (100% Local-First & Zero-Egress)"]
90
- direction TB
91
- B1["Static AST Engine: 74 Canonical Rules Across 18 Families"]
92
- B2["Living Ledger Sync: security_report.md (0-100 Score)"]
93
- B3["Ponytail Synthesizer: Minimal Surgical Diffs (&le;35 Add / &le;25 Del)"]
94
- B4["Pre-Apply Snapshot Engine: Byte-for-Byte .bak Backups"]
95
- B5["Human Gate: Interactive Syntax-Highlighted Approval"]
96
- B6["Targeted Differential Re-Scan: Confirmed Fixed State"]
97
-
98
- B1 --> B2 --> B3 --> B4 --> B5 --> B6
99
- end
123
+ Ingress --> Router["<b>Command Router &amp; Dispatcher</b><br/>cmd/torusguard (21 Commands)"]
100
124
 
101
- subgraph Out ["3. Verified Deliverables & Artifacts"]
102
- C1["Hardened Production Code (Zero Regressions)"]
103
- C2["Self-Contained Dark-Mode HTML Dashboard"]
104
- C3["OASIS SARIF v2.1.0 for CI/CD Pipeline"]
105
- C4["Auto-Synced AI Rules (.cursorrules, CLAUDE.md, etc.)"]
125
+ subgraph Core["TorusGuard Core Security Engine (Go Single Binary)"]
126
+ direction TB
127
+ subgraph Scanners["First-Principles &amp; Multi-Modal Scanner Suite"]
128
+ AST["<b>Polyglot AST &amp; Heuristic Scanner</b><br/>Go &bull; TS/JS &bull; Python &bull; SQL &bull; Auth &bull; SSRF &bull; CSRF"]
129
+ OCR["<b>Multi-Modal Vision OCR Engine</b><br/>Tesseract v5.4.0 &bull; Leaked Keys in PNG/JPG &le;10MB"]
130
+ Container["<b>Container &amp; Dockerfile Auditor</b><br/>Root Execution &bull; Docker Sockets &bull; Build Secrets"]
131
+ GitMine["<b>Git History Secret Miner</b><br/>Past Commits &bull; Diff Logs &bull; Remote Credentials"]
132
+ ReDoS["<b>ReDoS Complexity Analyzer</b><br/>Polynomial &amp; Exponential Backtracking Loops"]
133
+ AIGuard["<b>AI Agent &amp; RAG Vector Guard</b><br/>Prompt Injection &bull; Tenant Vector Contamination"]
134
+ end
135
+
136
+ subgraph Governance["Governance &amp; Remediation Pipeline"]
137
+ Harden["<b>Harden &amp; Line Reflection</b><br/>Ponytail Bounds: &le;35 Add &bull; &le;25 Del"]
138
+ Snapshot["<b>Pre-Apply Snapshot Engine</b><br/>Byte-for-Byte Rollback Backups in .torusguard/snapshots/"]
139
+ HumanGate{"<b>Human Gate Authorization</b><br/>Explicit --yes Confirmation Required"}
140
+ Recheck["<b>Differential Recheck Engine</b><br/>Zero-Regression Fix Closure"]
141
+ end
106
142
  end
107
143
 
108
- In --> Core --> Out
144
+ Router --> Scanners
145
+ Scanners --> Ledger[("<b>Living Security Ledger</b><br/><code>security_report.md</code><br/>Single Source of Truth")]
146
+ Ledger --> Harden
147
+ Harden --> Snapshot
148
+ Snapshot --> HumanGate
149
+ HumanGate -- Approved --> Recheck
150
+ Recheck --> Outputs["<b>Enterprise Outputs</b><br/>OASIS SARIF v2.1.0 &bull; Dark-Mode HTML Report &bull; Golden Fix Distillation"]
151
+
152
+ classDef ingressStyle fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc;
153
+ classDef scannerStyle fill:#0f172a,stroke:#818cf8,stroke-width:2px,color:#f8fafc;
154
+ classDef govStyle fill:#0f172a,stroke:#34d399,stroke-width:2px,color:#f8fafc;
155
+ classDef ledgerStyle fill:#312e81,stroke:#a78bfa,stroke-width:2px,color:#f8fafc;
156
+ classDef outStyle fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#f8fafc;
157
+
158
+ class ModeA,ModeB,ModeC ingressStyle;
159
+ class AST,OCR,Container,GitMine,ReDoS,AIGuard scannerStyle;
160
+ class Harden,Snapshot,HumanGate,Recheck govStyle;
161
+ class Ledger ledgerStyle;
162
+ class Outputs outStyle;
109
163
  ```
110
164
 
111
- ---
165
+ > ๐ŸŒ **Interactive Architecture Visualizations:**
166
+ > - [**System Architecture Diagram** (HTML)](docs/architecture/torusguard-architecture.html) โ€” Dynamic zoomable/pannable pipeline with dark/light themes, live view switching (Tri-Mode Ingress, AST Engine, Multi-Modal Vision OCR, Ponytail Bounds, Fail-Closed Recovery), and SVG/PNG export.
167
+ > - [**Governed Remediation Workflow** (HTML)](docs/architecture/torusguard-governance.workflow.html) โ€” Step-by-step visual trace of the 7-stage remediation loop, safety gates, and automatic rollback path.
112
168
 
113
- ## โš”๏ธ Why TorusGuard?
169
+ **Key design decisions:**
170
+ - **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.
171
+ - **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.
172
+ - **Deterministic Enforcement:** The **Go binary** handles all deterministic operations (AST scanning, bounds checking, snapshotting, reporting).
173
+ - **AI Intelligence:** The **AI agent** handles intelligence-requiring tasks (patch generation, root-cause analysis, remediation formulation).
174
+ - **Living Ground Truth:** All modes synchronize with `security_report.md` to prevent finding drift or hallucination.
175
+ - **Zero-Bypass Guardrails:** Neither human nor AI can bypass Ponytail Protocol bounds (โ‰ค35 additions, โ‰ค25 deletions) or the Human Gate before modifying code.
114
176
 
115
- | Security Dimension | Traditional SAST (SonarQube, Snyk) | Raw AI Coding Agents | TorusGuard v1.3.6 Engine |
116
- |:---|:---:|:---:|:---:|
117
- | **Target Architecture** | Human-written legacy codebases | High-churn AI code generation | **AI-built full-stack applications** |
118
- | **Remediation Model** | PDF reports & Jira tickets | Destructive full-file rewrites | **Ponytail Protocol** ($\le 35$ add, $\le 25$ del) |
119
- | **Fix Preservation** | None (scans from scratch) | Forgets context across chats | **Adaptive Security Memory** & Golden Recipes |
120
- | **Editor Sync** | Heavy background language daemons | Bloated prompt context ($> 2,000$ tokens) | **Stack-Adaptive Rules** ($\le 300$ prompt tokens) |
121
- | **Ground-Truth State** | External proprietary web dashboard | Ephemeral chat context (hallucinates) | **Living Security Ledger** (`security_report.md`) |
122
- | **Pre-Commit Defense** | Slow server-side webhooks | None (commits insecure code) | **Git Pre-Commit Diff Guard** ($< 200\text{ ms}$) |
123
- | **Privacy & Telemetry** | Cloud code upload / SaaS | Third-party cloud LLMs | **100% Local, Zero-Egress Guarantee** |
124
177
 
125
178
  ---
126
179
 
127
- ## ๐Ÿ“ฆ Installation & Setup Guide (npm & CLI)
180
+ ## ๐Ÿ“‹ Prerequisites
128
181
 
129
- TorusGuard is designed to be effortless to adopt in any project. There are no configuration servers, databases, or complex background daemons.
130
-
131
- ### ๐Ÿ“‹ Prerequisites
132
- - **Node.js:** 18.0.0 or higher
133
- - **Python:** 3.10 or higher (**Pure standard library** โ€” **zero `pip` dependencies required**)
134
- - **Go (Optional):** 1.22 or higher (for native Go CLI compilation & Go module workflows)
135
-
136
- > [!IMPORTANT]
137
- > **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.
182
+ - **Go 1.25+** (to build from source)
183
+ - **Git** (for `git apply` patch operations)
184
+ - **Node.js 18+** (for npm package installation)
138
185
 
139
186
  ---
140
187
 
141
- ### 1. Zero-Install Runner (Recommended)
142
- Run TorusGuard instantly in any repository without installing anything globally:
188
+ ## ๐Ÿš€ Installation
143
189
 
144
- ```bash
145
- # Run any command directly via npx
146
- npx torusguard init
147
- npx torusguard audit
148
- npx torusguard status
149
- npx torusguard update
150
- ```
151
-
152
- ### 2. Project Dev Dependency
153
- Lock TorusGuard into your project's `package.json` for all team members and CI/CD pipelines:
190
+ ### Option 1: npm (Primary)
154
191
 
155
192
  ```bash
156
- npm install -D torusguard
157
- ```
158
-
159
- Add convenience scripts to your `package.json`:
160
- ```json
161
- {
162
- "scripts": {
163
- "security:audit": "torusguard audit",
164
- "security:harden": "torusguard harden",
165
- "security:recheck": "torusguard recheck",
166
- "security:status": "torusguard status",
167
- "security:update": "torusguard update"
168
- }
169
- }
193
+ npm install -g torusguard
170
194
  ```
171
195
 
172
- ### 3. Native Go CLI Runner
173
- For Go ecosystem developers, TorusGuard ships with a native Go runner module ([go.mod](go.mod)):
196
+ Or use directly without installing:
174
197
 
175
198
  ```bash
176
- # Run zero-dependency Go CLI entrypoint directly
177
- go run cmd/torusguard/main.go audit
178
-
179
- # Or install globally into your $GOPATH/bin
180
- go install github.com/torusguard/torusguard/cmd/torusguard@latest
181
- torusguard status
199
+ npx torusguard init
182
200
  ```
183
201
 
184
- ### 4. Global NPM Installation
185
- If you prefer having the `torusguard` binary available system-wide across all terminal sessions:
202
+ <a href="https://www.npmjs.com/package/torusguard">
203
+ <img src="https://img.shields.io/badge/npm-v2.1.0-CB3837?logo=npm&logoColor=white" alt="npm package">
204
+ </a>
205
+
206
+ ### Option 2: Build from Source (Recommended for Contributors)
186
207
 
187
208
  ```bash
188
- npm install -g torusguard
209
+ git clone https://github.com/githubmofo/TorusGuard.git
210
+ cd TorusGuard
211
+ go build -o torusguard ./cmd/torusguard
189
212
  ```
190
213
 
191
- ### 5. AI Agent Skill Installation
192
- Install TorusGuard as a native AI assistant skill for Cursor, Claude Code, Cline, or Antigravity:
214
+ ### Option 3: Go Install
193
215
 
194
216
  ```bash
195
- npx skills add torusguard
217
+ go install github.com/torusguard/torusguard/cmd/torusguard@latest
196
218
  ```
197
219
 
198
220
  ---
199
221
 
200
- ### ๐Ÿ” What Happens on First Run (`init`)
201
- When you execute `npx torusguard init` (or `npx torusguard init --template golang`) in your repository:
202
- 1. **Polyglot Profiling:** Automatically detects 16+ languages (Go, Rust, Java, C#, PHP, Python, TypeScript) and 30+ frameworks without manual configuration.
203
- 2. **Scaffolding:** Creates a local `.torusguard/` directory containing active security rules, schemas, and runners.
204
- 3. **Editor Rules Synchronization:** Automatically compiles compact, language-specific guardrails into `.cursorrules`, `CLAUDE.md`, `.agent/rules/torusguard.md`, and `.windsurfrules` ($\le 300$ prompt tokens).
205
- 4. **Living Ledger Initialization:** Creates `security_report.md` at workspace root to track finding states without hallucination.
206
- 5. **Baseline Policy:** Emits a production-ready `SECURITY.md` for responsible disclosure.
207
-
208
- ---
222
+ ## ๐Ÿ’ป Usage
209
223
 
210
- ## โšก Quickstart: The 5-Step Core Lifecycle
211
-
212
- Run the complete autonomous governance cycle in 60 seconds from your terminal:
224
+ ### Quick Start
213
225
 
214
226
  ```bash
215
- # Step 1: Initialize workspace and profile stack (optional: --template golang|nextjs|fastapi)
216
- npx torusguard init
227
+ # Initialize TorusGuard in your project
228
+ torusguard init
217
229
 
218
- # Step 2: Run AST static security audit across 74 rules (optional: --watch, --sarif)
219
- npx torusguard audit
230
+ # Run a full security audit
231
+ torusguard audit
220
232
 
221
- # Step 3: Synthesize minimal surgical candidate patches (optional: --dry-run, --severity high)
222
- npx torusguard harden
233
+ # Check workspace posture
234
+ torusguard status
223
235
 
224
- # Step 4: Review syntax-highlighted diffs and apply with rollback backup (optional: --diff, --selective)
225
- npx torusguard apply
236
+ # Generate an HTML report
237
+ torusguard report --html
226
238
 
227
- # Step 5: Differentially recheck modified files to verify fix closure
228
- npx torusguard recheck
239
+ # Generate a SARIF report
240
+ torusguard report --sarif
229
241
  ```
230
242
 
231
- > ๐Ÿ’ก **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`!
243
+ ### Remediation Workflow
232
244
 
233
- ---
245
+ ```bash
246
+ # Validate a candidate patch against Ponytail bounds
247
+ torusguard harden fix.patch
234
248
 
235
- ## โŒจ๏ธ Dual-Strategy Command Matrix (CLI & AI Chat Parity)
236
-
237
- 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. All commands support `--target <dir>` / `-t <dir>` for monorepo and subproject isolation.
238
-
239
- ### ๐Ÿ”„ Core Remediation Lifecycle
240
-
241
- | Lifecycle Stage | Mode A: Terminal CLI | Mode B: AI Chat Command | Governed Action & Primary Artifact |
242
- |:---|:---|:---|:---|
243
- | **1. Init** | `npx torusguard init [--template <name>] [--audit]` | `/torusguard init` | Profiles workspace, activates rules, scaffolds `.torusguard/` |
244
- | **2. Status** | `npx torusguard status` | `/torusguard status` | 75-column diagnostic overview of health score, stack, memory & rules |
245
- | **3. Audit** | `npx torusguard audit [--watch] [--sarif]` | `/torusguard audit` | 74-rule AST scan, line-shift fingerprints, throughput metrics, living ledger |
246
- | **4. Verify** | `npx torusguard verify` | `/torusguard verify` | Asserts evidence sufficiency & live disk line-shift fingerprint matches |
247
- | **5. Harden** | `npx torusguard harden [--dry-run] [--severity <s\>]` | `/torusguard harden` | Synthesizes Ponytail diffs ($\le 35$ add, $\le 25$ del) into candidate bundles |
248
- | **6. Apply** | `npx torusguard apply [--diff] [--selective] [--yes]` | `/torusguard apply` | Human Gate, pre-apply `.bak` snapshots, Golden Fix distillation |
249
- | **7. Rollback**| `npx torusguard rollback [--run <id>]` | `/torusguard rollback` | Instant restoration from pre-apply snapshots in `.torusguard/snapshots/` |
250
- | **8. Recheck** | `npx torusguard recheck` | `/torusguard recheck` | Differential AST re-scan; marks findings `RESOLVED ๐ŸŸข` in living report |
251
- | **9. Recipes** | `npx torusguard recipes [--search <q>] [--export <p>]`| `/torusguard recipes` | Explores and exports verified Golden Fix patterns from `.torusguard/memory/` |
252
- | **10. Report** | `npx torusguard report --html [--sarif]` | `/torusguard report` | Emits single-file dark-mode HTML posture dashboard & OASIS SARIF v2.1.0 |
253
- | **11. Update** | `npx torusguard update [--install]` | `/torusguard update` | Verifies npm registry for latest versions and provides 1-command upgrade |
254
- | **12. Rules Sync**| `npx torusguard rules sync` | `/torusguard rules sync`| Synchronizes prompt guardrails across Cursor, Claude, Antigravity, Windsurf |
255
- | **13. Diff Guard**| `npx torusguard diff-guard [--install-hook]` | `/torusguard diff-guard`| Audits git diffs for security bypasses; binds pre-commit git hook |
256
- | **14. Authorize** | `npx torusguard authorize` | `/torusguard authorize` | Target domain allowlisting, cryptographic ownership proof, TTL limits |
257
- | **15. Validate** | `npx torusguard web-validate` | `/torusguard web-validate`| Authorized non-destructive HTTP probing with transparent audit headers |
258
- | **16. Exploit** | `npx torusguard exploit-check` | `/torusguard exploit-check`| Bounded single-step exploitability confirmation using inert sentinels |
249
+ # Apply the patch with rollback snapshot (requires --yes for Human Gate)
250
+ torusguard apply --yes fix.patch
259
251
 
260
- ---
252
+ # Verify the fix was applied correctly
253
+ torusguard recheck
261
254
 
262
- ## ๐Ÿน Polyglot Go Engine & Native Runner
255
+ # Roll back if something went wrong
256
+ torusguard rollback
257
+ ```
263
258
 
264
- TorusGuard v1.4.0 introduces native, zero-dependency Go ecosystem support:
259
+ ### Runtime Validation
265
260
 
266
- ### 1. Go AST Invariant Security Rules
267
- - **`TG-INPUT-002` (Raw SQL Concatenation):** Detects unparameterized string concatenation and `fmt.Sprintf` query interpolation in `database/sql`, `sqlx`, and GORM.
268
- - **`TG-INPUT-006` (Path Traversal):** Detects unsanitized file reads (`os.Open`, `os.ReadFile`) using user request parameters.
269
- - **`TG-SSRF-004` (Unbounded HTTP Requests):** Flags `&http.Client{}` and `http.DefaultClient` lacking explicit timeout boundaries to prevent connection pooling denial-of-service.
270
- - **`TG-DIFF-001` (Security Bypasses):** Prevents insecure TLS validation (`InsecureSkipVerify: true`).
271
- - **`TG-SUPPLY-001` (Supply Chain):** Asserts lockfile presence and cryptographic tracking for `go.sum`.
261
+ ```bash
262
+ # Generate authorization token for runtime probing
263
+ torusguard authorize
272
264
 
273
- ### 2. Surgical Ponytail Remediation for Go
274
- Patches for Go follow strict Ponytail line churn limits ($\le 35$ additions, $\le 25$ deletions):
275
- ```go
276
- // Example: TG-SSRF-004 Remediation
277
- - client := &http.Client{}
278
- + client := &http.Client{Timeout: 10 * time.Second}
265
+ # Probe a running application for security headers
266
+ torusguard web-validate
279
267
 
280
- // Example: TG-INPUT-006 Path Traversal Remediation
281
- - data, err := os.ReadFile("/data/" + c.Query("file"))
282
- + data, err := os.ReadFile(filepath.Join("/data", filepath.Base(c.Query("file"))))
268
+ # Send bounded inert payloads to test input handling
269
+ torusguard exploit-check
283
270
  ```
284
271
 
285
272
  ---
286
273
 
287
- ## ๐Ÿ”„ Package Self-Update Engine (`update`)
274
+ ## ๐Ÿ”ง Commands
275
+
276
+ | Command | Description |
277
+ | :--------------- | :------------------------------------------------------------- |
278
+ | `init` | Scaffold `.torusguard/` workspace, detect stack, activate rules |
279
+ | `status` | Diagnostic overview of posture, stack, and active rules |
280
+ | `audit` | Static heuristic security scan against active TG-* rules |
281
+ | `verify` | Live disk line match audit and evidence sufficiency check |
282
+ | `harden` | Validate patches against Ponytail Protocol bounds |
283
+ | `apply` | Apply patches with pre-apply `.bak` rollback snapshots |
284
+ | `rollback` | Instant restoration from pre-apply snapshots |
285
+ | `recheck` | Differential re-scan on modified files |
286
+ | `report` | Generate HTML (`--html`) or SARIF (`--sarif`) posture reports |
287
+ | `recipes` | Manage the Golden Fix recipe library |
288
+ | `authorize` | Generate cryptographic auth tokens for runtime probing |
289
+ | `web-validate` | Authorized HTTP probing with `X-TorusGuard-Audit` headers |
290
+ | `ocr-scan` | Run Tesseract OCR secret scan on images/diagrams (<10MB) |
291
+ | `container` | Audit Dockerfile, compose, and container configurations |
292
+ | `git-mine` | Mine git commit history for leaked secrets & creds |
293
+ | `redos` | Analyze regex patterns for catastrophic backtracking |
294
+ | `ai-guard` | Scan AI/LLM code for prompt injection & RAG flaws |
295
+ | `mcp` | Run native Model Context Protocol (MCP) server over stdio |
296
+ | `update` | Self-update the TorusGuard engine |
297
+ | `help` | Show interactive command guide |
288
298
 
289
- Keep your security guardrails continuously synchronized with the latest threat models:
299
+ ---
290
300
 
291
- ```bash
292
- # Check registry for newer versions
293
- npx torusguard update
301
+ ## ๐Ÿ“ Project Structure
294
302
 
295
- # Automatically upgrade to latest version
296
- npx torusguard update --install
297
303
  ```
298
-
299
- - **Zero-Dependency Registry Check:** Queries `https://registry.npmjs.org/torusguard/latest` natively.
300
- - **SemVer Delta Analysis:** Displays current version against registry latest in standard 75-column cards.
301
- - **Automated Upgrade Flow:** Executes package installation upon user authorization.
302
-
303
- ---
304
-
305
- ## ๐Ÿ“‹ 74 Canonical Security Rules Catalog (18 Families Across 6 Pillars)
306
-
307
- TorusGuard's AST scanner inspects polyglot source trees across 74 canonical security rules organized into **6 core security pillars** across 18 families:
308
-
309
- ```text
310
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
311
- โ”‚ 74 CANONICAL RULES ACROSS 6 PILLARS โ”‚
312
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
313
- 1. Secrets & Identity โ”€โ”€โ–บ TG-SEC (7) ยท TG-AUTH (8) ยท TG-CLIENT (2)
314
- 2. Data & Injection Defense โ”€โ”€โ–บ TG-DB (4) ยท TG-INPUT (6) ยท TG-CSRF (2)
315
- 3. AI Agent & LLM Security โ”€โ”€โ–บ TG-AGENT (4)
316
- 4. Network & Real-Time โ”€โ”€โ–บ TG-SSRF (4) ยท TG-WEBHOOK (4) ยท TG-WS (4)
317
- 5. Platform & API Limits โ”€โ”€โ–บ TG-RATE (3) ยท TG-GQL (4) ยท TG-PLATFORM (4)
318
- TG-CACHE (3) ยท TG-EDGE (2)
319
- 6. Supply Chain & Governanceโ”€โ”€โ–บ TG-SUPPLY (6) ยท TG-BIZ (4) ยท TG-DIFF (3)
304
+ TorusGuard/
305
+ โ”œโ”€โ”€ cmd/torusguard/ # CLI entry point, command router & MCP server
306
+ โ”‚ โ”œโ”€โ”€ main.go # CLI command router
307
+ โ”‚ โ””โ”€โ”€ mcp.go # Model Context Protocol (MCP) JSON-RPC 2.0 stdio server
308
+ โ”œโ”€โ”€ internal/
309
+ โ”‚ โ”œโ”€โ”€ apply/ # Patch application + pre-apply snapshot engine
310
+ โ”‚ โ”œโ”€โ”€ harden/ # Ponytail Protocol bounds enforcement & line-level reflection
311
+ โ”‚ โ”‚ โ”œโ”€โ”€ patch.go # Ponytail Protocol bounds verification
312
+ โ”‚ โ”‚ โ””โ”€โ”€ reflection.go # Line-level reflection & semantic replacement
313
+ โ”‚ โ”œโ”€โ”€ memory/ # Golden Fix recipe persistence
314
+ โ”‚ โ”œโ”€โ”€ recheck/ # Differential re-scan engine
315
+ โ”‚ โ”œโ”€โ”€ report/ # SARIF v2.1.0 + dark-mode HTML generators
316
+ โ”‚ โ”œโ”€โ”€ rules/ # TG-* rule catalog loader
317
+ โ”‚ โ”œโ”€โ”€ scanner/ # Heuristic polyglot security scanner + Tesseract OCR
318
+ โ”‚ โ”‚ โ”œโ”€โ”€ scanner.go # Polyglot code AST & heuristic scanner
319
+ โ”‚ โ”‚ โ””โ”€โ”€ ocr.go # Multi-modal Vision OCR secret detection
320
+ โ”‚ โ”œโ”€โ”€ termui/ # 75-column terminal UI formatting
321
+ โ”‚ โ”œโ”€โ”€ validate/ # authorize / web-validate / exploit-check / verify
322
+ โ”‚ โ””โ”€โ”€ workspace/ # init + polyglot stack detection
323
+ โ”œโ”€โ”€ .torusguard/ # Generated workspace state
324
+ โ”‚ โ”œโ”€โ”€ rules/ # Active security rule definitions
325
+ โ”‚ โ”œโ”€โ”€ schemas/ # JSON schemas for findings, recipes, etc.
326
+ โ”‚ โ”œโ”€โ”€ memory/ # Persistent security context
327
+ โ”‚ โ””โ”€โ”€ snapshots/ # Pre-apply rollback backups
328
+ โ”œโ”€โ”€ docs/ # Architecture and usage documentation
329
+ โ”œโ”€โ”€ bin/ # npm package CLI wrapper
330
+ โ”œโ”€โ”€ go.mod # Go module (github.com/torusguard/torusguard)
331
+ โ””โ”€โ”€ package.json # npm package definition
320
332
  ```
321
333
 
322
- | Pillar | Family Prefix | Rules | Critical Invariant Enforced |
323
- |:---|:---|:---:|:---|
324
- | **๐Ÿ”‘ Secrets & Client Bundles** | `TG-SEC`, `TG-CLIENT` | **9** | Zero hardcoded API keys, JWT secrets, private certificates, or server keys in client bundles. |
325
- | **๐Ÿ›ก๏ธ Authentication & Sessions** | `TG-AUTH`, `TG-CSRF` | **10** | Timing-safe string compares, strong password hashing, algorithm verification, SameSite cookies. |
326
- | **๐Ÿ—„๏ธ Database & Input Safety** | `TG-DB`, `TG-INPUT` | **10** | Parameterized SQL queries, multi-tenant isolation (`where: { tenantId }`), path sanitization. |
327
- | **๐Ÿค– AI Agent & LLM Guardrails** | `TG-AGENT` | **4** | Structural user prompt isolation, delimiter wrapping, shell tool sandboxing, MCP least-privilege. |
328
- | **๐ŸŒ 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. |
329
- | **โšก 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. |
330
-
331
- <details>
332
- <summary><strong>๐Ÿ” Click to expand full 18-family catalog breakdown</strong></summary>
333
-
334
- <br>
335
-
336
- - **`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.
337
- - **`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.
338
- - **`TG-DB` (Database Partitioning & Injection โ€” 4 rules):** Mandates tenant-scoped queries across Prisma, Mongoose, SQLAlchemy, and GORM; eliminates raw SQL string concatenation.
339
- - **`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.
340
- - **`TG-RATE` (Rate Limiting & Resource Protection โ€” 3 rules):** Enforces rate-limiting middleware on authentication routes, pagination bounds, and request payload size limits.
341
- - **`TG-AGENT` (AI Agent & LLM Defense โ€” 4 rules):** Enforces structural separation of user prompts from system instructions, inert XML delimiters, and containerized tool execution.
342
- - **`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.
343
- - **`TG-WEBHOOK` (Webhook Verification โ€” 4 rules):** Mandates cryptographic HMAC-SHA256 signature validation before body parsing, replay prevention, and timestamp expiration.
344
- - **`TG-WS` (WebSocket Security โ€” 4 rules):** Enforces handshake authentication, origin validation, channel-level authorization, and frame size caps.
345
- - **`TG-CSRF` (Cross-Site Request Forgery โ€” 2 rules):** Enforces anti-CSRF tokens on state-changing operations and `SameSite` cookie attributes.
346
- - **`TG-GQL` (GraphQL Protection โ€” 4 rules):** Enforces query depth limiting, production introspection suppression, and field-level resolver authorization.
347
- - **`TG-SUPPLY` (Supply Chain Integrity โ€” 6 rules):** Audits dependency lockfile presence, checks against known CVEs, prevents `--no-audit` build flags, and inspects build scripts.
348
- - **`TG-BIZ` (Business Logic Bounds โ€” 4 rules):** Validates negative quantity inputs, coupon/discount boundaries, and race-condition transaction locks.
349
- - **`TG-CACHE` (Cache Isolation โ€” 3 rules):** Enforces `Cache-Control: no-store, private` on authenticated responses and sanitizes unkeyed request headers.
350
- - **`TG-CLIENT` (Client Bundle Hygiene โ€” 2 rules):** Forbids importing private server environment variables into browser bundles and suppresses production source maps.
351
- - **`TG-PLATFORM` (Server Hardening โ€” 4 rules):** Enforces Helmet HTTP security headers, CORS origin whitelisting, cookie `secure` flags, and debug mode suppression.
352
- - **`TG-DIFF` (Polyglot Diff Integrity โ€” 3 rules):** Intercepts security bypass comments (`# nosec`, `InsecureSkipVerify: true`) and asserts Ponytail patch budgets.
353
- - **`TG-EDGE` (Edge & Serverless Limits โ€” 2 rules):** Prevents cross-request memory leaks in Cloudflare Workers and enforces subrequest fan-out limits.
354
-
355
- </details>
356
-
357
334
  ---
358
335
 
359
- ## โœ‚๏ธ Ponytail Remediation Protocol & Rollback Safety
360
-
361
- Traditional AI coding assistants routinely destroy functional features by attempting full-file rewrites. TorusGuard strictly enforces the **Ponytail Protocol**:
362
-
363
- $$\Delta \text{Lines} \le 35\text{ Additions}, \quad \Delta \text{Lines} \le 25\text{ Deletions}$$
336
+ ## ๐Ÿ”’ Security Invariants & Rule Governance
364
337
 
365
- ### ๐Ÿ›ก๏ธ Pre-Apply Rollback Snapshots
366
- Before modifying a single file on disk, `apply_runner.py` creates a byte-for-byte backup:
367
- ```text
368
- .torusguard/snapshots/<run_id>/<target_file>.bak
369
- ```
338
+ TorusGuard enforces **86 security invariants across 22 architectural families** covering Secrets, Authentication, Multi-Tenant Database Isolation, Input Sanitization, Rate Limiting, AI Agent Prompt Injection, SSRF, Webhooks, WebSockets, CSRF, GraphQL, Supply Chain, Business Logic, Cache Poisoning, Client Bundles, Platform Headers, Polyglot Bypasses, Edge Timeouts, Container & Docker Safety, Git History Secret Mining, Regular Expression Backtracking (ReDoS), and Vector Database RAG Isolation.
370
339
 
371
- If a patch causes unforeseen behavior or test failures, execute an instant 1-command rollback:
372
- ```bash
373
- npx torusguard rollback
374
- ```
375
- All affected files are immediately restored to their exact pre-patch byte state.
340
+ > ๐Ÿ“˜ **Full Rules Catalog & Invariants:**
341
+ > The complete rulebook with formal invariant definitions, severity scores, and testing signatures is maintained in [`AGENTS.md`](AGENTS.md) and the [`rules/`](rules/) directory.
342
+ > You can also explore verified Golden Fix patterns anytime via `torusguard recipes` or stream the live catalog over MCP via `torusguard://rules_catalog`.
376
343
 
377
344
  ---
378
345
 
379
- ## ๐Ÿ“œ Living Security Report Ground Truth (`security_report.md`)
380
-
381
- 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.
382
-
383
- ### ๐Ÿ”„ Lifecycle State Machine
384
- ```text
385
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
386
- โ”‚ SECURITY REPORT LIFECYCLE STATE MACHINE โ”‚
387
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
388
- [ OPEN ๐Ÿ”ด ] โ”€โ”€(verify)โ”€โ”€โ–บ [ VERIFIED ๐ŸŸ  ] โ”€โ”€(harden)โ”€โ”€โ–บ [ CANDIDATE ๐ŸŸก ]
389
- โ”‚
390
- (apply)
391
- โ”‚
392
- โ–ผ
393
- [ RESOLVED ๐ŸŸข ] โ—„โ”€โ”€(recheck: confirmed)โ”€โ”€ [ APPLIED ๐Ÿ”ต ]
394
- โ”‚
395
- โ””โ”€โ”€(recheck: failed)โ”€โ”€โ–บ [ REGRESSED โŒ ]
396
- ```
346
+ ## ๐Ÿค– AI Agent Integration
397
347
 
398
- ### ๐Ÿงฎ Posture Health Score (0โ€“100)
399
- The Health Score dynamically reflects the open risk ledger:
400
- $$\text{Penalty} = (25 \times \text{Critical}) + (15 \times \text{High}) + (5 \times \text{Medium}) + (2 \times \text{Low})$$
401
- $$\text{Score} = \max(0, \min(100, 100 - \text{Penalty}))$$
348
+ TorusGuard works natively inside AI coding assistants. Add the configuration file to your project root and your AI agent automatically enforces TorusGuard security invariants.
402
349
 
403
- *When all findings are verified closed via differential recheck, the repository achieves **Health Score: 100/100 ๐ŸŸข Hardened & Secure**.*
350
+ ### Supported Agents
404
351
 
405
- ---
352
+ | Agent | Configuration File | Status |
353
+ | :------------------- | :-------------------- | :----- |
354
+ | Antigravity (Gemini) | `AGENTS.md` | โœ… Full support |
355
+ | Claude Code | `CLAUDE.md` | โœ… Full support |
356
+ | Cursor | `.cursorrules` | โœ… Full support |
357
+ | Windsurf | `.windsurfrules` | โœ… Full support |
358
+ | VS Code Copilot | `AGENTS.md` | โœ… Full support |
359
+ | Kimi | `SKILL.md` | โœ… Full support |
406
360
 
407
- ## ๐Ÿ“Š Visual HTML Dashboard & SARIF v2.1.0 Export
361
+ ### Slash Commands (AI Chat Mode)
408
362
 
409
- Generate a standalone, zero-external-CDN, dark-mode visual posture dashboard:
410
- ```bash
411
- npx torusguard report --html
412
363
  ```
413
- - **SVG Circular Posture Gauge:** Animated visual health score ($0-100$).
414
- - **7-Stage Closed-Loop Pipeline:** Visual state timeline across all lifecycle phases.
415
- - **Golden Fix Recipes Grid:** Syntax-highlighted unified diffs with Ponytail metrics.
416
- - **Zero-CDN Architecture:** Completely offline-ready; embeds all styles and assets inline.
417
-
418
- To integrate with **GitHub Code Scanning**, export standard SARIF:
419
- ```bash
420
- npx torusguard report > results.sarif
364
+ /torusguard init # Initialize workspace
365
+ /torusguard audit # Run security + OCR scan; sync security_report.md
366
+ /torusguard ocr-scan # Scan diagram or image assets for leaked credentials
367
+ /torusguard harden # Formulate remediation patches
368
+ /torusguard apply # Apply patches with Human Gate
369
+ /torusguard recheck # Verify fix closure
370
+ /torusguard report # Generate posture report
371
+ /torusguard status # Check posture overview
372
+ /torusguard full # End-to-end 7-stage pipeline
421
373
  ```
422
374
 
423
- ---
375
+ ### Native MCP Tools (Agent Toolkit Mode)
424
376
 
425
- ## ๐Ÿค– AI Editor Guardrails Auto-Sync
377
+ When configured with `.agents/mcp_config.json` or `mcp_config.json`, AI coding agents gain native tool calling:
426
378
 
427
- TorusGuard compiles project security invariants, golden recipes, and active guardrails into prompt-optimized rule files:
428
- ```bash
429
- npx torusguard rules sync
430
- ```
379
+ - `torusguard_audit`: Deep static AST scan + Vision OCR; writes `security_report.md`
380
+ - `torusguard_ocr_scan`: Dedicated image credential analysis via Tesseract (5-10MB bounds)
381
+ - `torusguard_container`: Audits container files for root execution, docker socket exposure, and privileged mode
382
+ - `torusguard_git_mine`: Mines git commit history and config for leaked credentials and tokens
383
+ - `torusguard_redos`: Analyzes regex patterns for catastrophic exponential backtracking
384
+ - `torusguard_ai_guard`: Audits AI agent prompt templates, tool registries, and vector database queries
385
+ - `torusguard_verify`: Asserts evidence sufficiency & line-shift invariant fingerprint matches
386
+ - `torusguard_harden`: Validates remediation diff against Ponytail Protocol bounds
387
+ - `torusguard_recheck`: Differential re-scan confirming fix closure
388
+ - `torusguard_status`: Workspace posture and tech stack inspection
389
+ - `torusguard://security_report`: MCP Resource reading the living security report
390
+ - `torusguard://rules_catalog`: MCP Resource exploring verified rules catalog & Golden Fix patterns
431
391
 
432
- ### Supported AI Editors:
433
- - **Cursor:** Injects non-destructive rules into `.cursorrules`
434
- - **Claude Code:** Injects non-destructive rules into `CLAUDE.md`
435
- - **Antigravity IDE:** Injects non-destructive rules into `.agent/rules/torusguard.md`
436
- - **Windsurf:** Injects non-destructive rules into `.windsurfrules`
392
+ ---
437
393
 
438
- *All rules are compiled under a strict overhead ceiling of $\le 300$ prompt tokens to preserve AI reasoning context.*
394
+ ## ๐Ÿงช Verified Test Suite & Mass Benchmarks
439
395
 
440
- ---
396
+ TorusGuard undergoes rigorous automated multi-tier testing across polyglot stacks, multi-modal vision assets, and agent communication protocols:
441
397
 
442
- ## ๐Ÿข Monorepo Fleet Support & Git Pre-Commit Diff Guard
398
+ | Testing Tier | Scope & Target Stacks | Pass Rate | Verified Capabilities |
399
+ | :--- | :--- | :---: | :--- |
400
+ | **Go Engine & Unit Tests** | `cmd/torusguard`, `internal/scanner`, `internal/*` | **100% Passing** | Deterministic AST matching, 74 rule patterns, JSON-RPC 2.0 MCP protocol. |
401
+ | **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. |
402
+ | **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. |
403
+ | **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. |
404
+ | **Ponytail Churn Limits** | Surgical patch validation across all 74 rules | **Bounded** | Line bounds (โ‰ค35 additions, โ‰ค25 deletions), zero-bypass verification (`TG-DIFF-001`). |
443
405
 
444
- TorusGuard automatically discovers and profiles multi-package workspaces:
445
- - **Monorepo Ecosystems:** pnpm workspaces, npm/yarn workspaces, Cargo workspaces, Go multi-module workspaces, Gradle multi-project builds.
446
- - **Universal Polyglot Profiler:** Automatically identifies 16+ languages and maps ORM boundaries independently per sub-package.
447
- - **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.
406
+ All test environments are completely sandboxed, verified with byte-for-byte assertions, and cleaned up automatically.
448
407
 
449
408
  ---
450
409
 
451
- ## ๐Ÿงช Verification & Test Harness
410
+ ## ๐Ÿ›ก๏ธ Non-Negotiable Invariants
452
411
 
453
- ### What Happens When You Run `npm test`?
454
- TorusGuard enforces a strict **100% pass requirement across 133 tests in 21 test suites** before every release.
455
- The test harness runs with **zero third-party dependencies** via standard Python 3:
412
+ 1. **Browser-Code Truth:** Never expose secrets in frontend bundles.
413
+ 2. **Multi-Tenant Isolation:** Always scope DB lookups by tenant/user ownership.
414
+ 3. **Ponytail Churn Bounds:** Patches โ‰ค35 additions, โ‰ค25 deletions. No full-file rewrites.
415
+ 4. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`.
416
+ 5. **Snapshots Before Edits:** Mandatory `.bak` backup before every modification.
417
+ 6. **Fail-Closed Cryptography:** Panic on entropy failure. No fallback tokens.
418
+ 7. **SSRF Boundary Enforcement:** Block private IPs and cloud metadata before probing.
419
+ 8. **DoS Resilience:** 10,000-file max, 5-minute timeout.
456
420
 
457
- ```bash
458
- npm test
459
- # Equivalent to: python harness/runner.py
460
- ```
461
-
462
- When a developer runs:
463
- ```bash
464
- npm test
465
- ```
466
- The test harness invokes `python harness/runner.py` directly using the Python standard library. It systematically verifies:
467
- 1. **JSON Schema Validity:** 10 formal schemas (`finding`, `evidence`, `remediation`, `rule`, `lifecycle`, `provenance`, etc.).
468
- 2. **74-Rule Catalog Integrity:** AST detection accuracy across all 18 security families.
469
- 3. **Polyglot Go Engine:** Go module definition, Go stack detection (Gin, Fiber, GORM), and Go AST rules (`TG-INPUT-002`, `TG-INPUT-006`, `TG-SSRF-004`).
470
- 4. **Line-Shift Fingerprinting:** Stable anchor matching across file edits without line number drift.
471
- 5. **Secret Redaction:** Stripe secret keys and JWT tokens safely masked.
472
- 6. **Deterministic Replay:** 3-pass differential validation across Django, DRF, FastAPI, Flask, and SQLAlchemy fixtures.
473
- 7. **Ponytail Patch Churn Bounds:** Verifying line budgets ($\le 35$ additions, $\le 25$ deletions).
474
- 8. **Deepened Command Verification:** Audit watch loop & SARIF export, Harden dry-run & severity floor, Recipes search & export, Apply diff preview & snapshot ledger, and Bootstrap templates.
475
- 9. **Living Security Report State Transitions:** Discovery (`OPEN ๐Ÿ”ด`), Candidate (`CANDIDATE ๐ŸŸก`), Applied (`APPLIED ๐Ÿ”ต`), and Verified Closure (`RESOLVED ๐ŸŸข`).
476
- 10. **Cryptographic Manifest Parity:** 100% SHA-256 match across all indexed workspace files.
421
+ ---
477
422
 
478
- ```bash
479
- # Run formal TorusGuard test harness
480
- npm test
423
+ ## ๐Ÿค Contributing
481
424
 
482
- # Expected Output:
483
- # ================================================================================
484
- # SUMMARY: 133 Passed | 0 Failed
485
- # ================================================================================
486
- ```
425
+ 1. Fork the repository
426
+ 2. Create a feature branch: `git checkout -b feat/your-feature`
427
+ 3. Commit changes: `git commit -m "feat: add your feature"`
428
+ 4. Push to branch: `git push origin feat/your-feature`
429
+ 5. Open a Pull Request
487
430
 
488
- To validate diff guard and monorepo profiling independently:
489
- ```bash
490
- python harness/validate_v0_9_2_diff_and_monorepo.py
491
- ```
431
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for community standards.
492
432
 
493
433
  ---
494
434
 
495
- ## ๐Ÿ”’ Security Policy & Responsible Disclosure
435
+ ## ๐Ÿ“„ License
496
436
 
497
- 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).
437
+ [MIT](LICENSE) ยฉ 2026 Jenish Lad
498
438
 
499
439
  ---
500
440
 
501
- ## ๐Ÿ“„ License
502
-
503
- TorusGuard is released under the [MIT License](LICENSE).
504
- Copyright (c) 2026 Jenish Lad ([@githubmofo](https://github.com/githubmofo)).
441
+ ## ๐Ÿ“š Documentation
442
+
443
+ | Document | Description |
444
+ | :-------------------------------------------------------- | :--------------------------------------- |
445
+ | [Architecture](docs/architecture/ARCHITECTURE.md) | System design and module relationships |
446
+ | [Security Architecture](docs/architecture/SECURITY_ARCHITECTURE.md) | Threat model and security design |
447
+ | [Detection Engine](docs/architecture/DETECTION_ENGINE.md) | Scanner internals and rule matching |
448
+ | [API Specification](docs/architecture/API_SPECIFICATION.md) | CLI argument specification |
449
+ | [Security Philosophy](docs/overview/security-philosophy.md) | Core design principles |
450
+ | [Testing Playbook](docs/usage/testing-playbook.md) | Testing guide and CI integration |
451
+ | [Demo Guide](docs/demo.md) | Quick start and full lifecycle demo |
452
+ | [Roadmap](docs/roadmap.md) | Feature roadmap and release planning |
453
+ | [SECURITY.md](SECURITY.md) | Vulnerability disclosure policy |
454
+ | [CHANGELOG.md](CHANGELOG.md) | Version history and release notes |