TorusGuard Master Security Engine & Command Router
Core Invariant: If the browser or client receives it, users can inspect it. Never expose database credentials, master keys, or private API secrets in client bundles. Always isolate multi-tenant database queries.
Command Catalog: Terminal CLI & AI Chat Parity
TorusGuard operates with 100% feature parity across both the terminal CLI and AI chat slash commands:
| Capability |
Terminal CLI Command |
AI Chat Slash Command |
Specialist Skill |
Purpose |
| Init |
npx torusguard init |
/torusguard init |
skills/torusguard-init |
Stack discovery, rule activation, workspace scaffolding |
| Status |
npx torusguard status |
/torusguard status |
skills/torusguard-status |
Posture score, active rules, run history, scope check |
| Audit |
npx torusguard audit |
/torusguard audit |
skills/torusguard-audit |
Static AST scan, invariant fingerprinting, confidence scoring |
| Verify |
npx torusguard verify |
/torusguard verify |
skills/torusguard-verify |
Evidence sufficiency audit & line match calibration |
| Harden |
npx torusguard harden |
/torusguard harden |
skills/torusguard-harden |
Ponytail patch formulation ($\le 35$ add, $\le 25$ del) |
| Apply |
npx torusguard apply [--yes] |
/torusguard apply |
skills/torusguard-apply |
Human Gate review, .bak snapshots, patch application |
| Rollback |
npx torusguard rollback |
/torusguard rollback |
skills/torusguard-apply |
Instant 1-step rollback from pre-apply snapshots |
| Recheck |
npx torusguard recheck |
/torusguard recheck |
skills/torusguard-recheck |
Targeted differential AST scan, fix closure verification |
| Recipes |
npx torusguard recipes |
/torusguard recipes |
skills/torusguard-harden |
Explore verified Golden Fix Recipes from persistent memory |
| Report |
npx torusguard report --html |
/torusguard report |
skills/torusguard-report |
Executive posture reporting, SARIF v2.1.0 & visual HTML |
| Authorize |
npx torusguard authorize |
/torusguard authorize |
skills/torusguard-authorize |
Legal scope definition & safety boundaries |
| Validate |
npx torusguard web-validate |
/torusguard web-validate |
skills/torusguard-web-validate |
Authorized non-destructive HTTP probing |
| Exploit |
npx torusguard exploit-check |
/torusguard exploit-check |
skills/torusguard-exploit-check |
Bounded single-step exploitability confirmation |
| Full |
npx torusguard full |
/torusguard full |
skills/torusguard-full |
End-to-end 7-stage closed-loop execution |
| Sync |
npx torusguard rules sync |
/torusguard rules sync |
skills/torusguard-init |
Synchronize rules across AI editors (Cursor, Claude, Antigravity) |
Non-Negotiable Invariants
- Browser-Code Truth: If the client receives it, it is public. Zero hardcoded secrets (
SUPABASE_SERVICE_ROLE_KEY, private tokens, live API keys) in frontend code.
- Multi-Tenant Isolation: All database lookups must be scoped by organization or user ownership (
tenant_id, organization_id, where: { tenantId }).
- Ponytail Churn Bounds: Patches must be minimal and surgical ($\le 35$ additions, $\le 25$ deletions). Never perform full-file rewrites.
- Standardized 75-Column Terminal: All CLI terminal output is strictly normalized to 75 visual columns with Unicode emoji width calculation, ANSI escape handling, and visual truncation with ellipsis (
...).
- Zero Security Bypasses: Never insert
# nosec, verify=False, InsecureSkipVerify: true, [AllowAnonymous], or csrf().disable().
- Snapshots Before Edits: Every code modification must capture a byte-for-byte pre-apply backup in
.torusguard/snapshots/<run_id>/ before touching disk code.
Workspace Layout Structure
.torusguard/
├── config/
│ ├── torusguard.json # Detected stack, settings, and rule counts
│ └── scope.json # Authorized runtime validation targets & TTL
├── memory/
│ ├── context.json # Aggregated security memory context
│ ├── patterns.json # Distilled Golden Fix Recipes
│ └── events.json # Historical audit, apply, and recheck events
├── rules/
│ └── active/ # Active TG-* rule definitions
├── runs/
│ └── run-YYYYMMDD-HHMMSS-audit/
│ ├── findings.json # Machine-readable AST findings
│ ├── findings.md # Actionable markdown finding cards
│ ├── remediation.md # Formulated candidate patch catalog
│ ├── diff_summary.md # Summary of applied diffs
│ ├── recheck.md # Differential recheck status transitions
│ ├── report.html # Single-file visual dark-mode HTML report
│ ├── results.sarif # OASIS SARIF v2.1.0 log
│ └── bundles/ # Formulated Ponytail remediation bundles
└── snapshots/
└── run-YYYYMMDD-HHMMSS-audit/ # Pre-apply .bak files for instant rollback
1---2name: torusguard-23description: TorusGuard Master Security Engine & Command Router4---56# TorusGuard Master Security Engine & Command Router78**Core Invariant:** If the browser or client receives it, users can inspect it. Never expose database credentials, master keys, or private API secrets in client bundles. Always isolate multi-tenant database queries.910---1112## Command Catalog: Terminal CLI & AI Chat Parity1314TorusGuard operates with 100% feature parity across both the terminal CLI and AI chat slash commands:1516| Capability | Terminal CLI Command | AI Chat Slash Command | Specialist Skill | Purpose |17| :--- | :--- | :--- | :--- | :--- |18| **Init** | `npx torusguard init` | `/torusguard init` | `skills/torusguard-init` | Stack discovery, rule activation, workspace scaffolding |19| **Status** | `npx torusguard status` | `/torusguard status` | `skills/torusguard-status` | Posture score, active rules, run history, scope check |20| **Audit** | `npx torusguard audit` | `/torusguard audit` | `skills/torusguard-audit` | Static AST scan, invariant fingerprinting, confidence scoring |21| **Verify** | `npx torusguard verify` | `/torusguard verify` | `skills/torusguard-verify` | Evidence sufficiency audit & line match calibration |22| **Harden** | `npx torusguard harden` | `/torusguard harden` | `skills/torusguard-harden` | Ponytail patch formulation ($\le 35$ add, $\le 25$ del) |23| **Apply** | `npx torusguard apply [--yes]` | `/torusguard apply` | `skills/torusguard-apply` | Human Gate review, `.bak` snapshots, patch application |24| **Rollback** | `npx torusguard rollback` | `/torusguard rollback` | `skills/torusguard-apply` | Instant 1-step rollback from pre-apply snapshots |25| **Recheck** | `npx torusguard recheck` | `/torusguard recheck` | `skills/torusguard-recheck` | Targeted differential AST scan, fix closure verification |26| **Recipes** | `npx torusguard recipes` | `/torusguard recipes` | `skills/torusguard-harden` | Explore verified Golden Fix Recipes from persistent memory |27| **Report** | `npx torusguard report --html` | `/torusguard report` | `skills/torusguard-report` | Executive posture reporting, SARIF v2.1.0 & visual HTML |28| **Authorize** | `npx torusguard authorize` | `/torusguard authorize` | `skills/torusguard-authorize`| Legal scope definition & safety boundaries |29| **Validate** | `npx torusguard web-validate` | `/torusguard web-validate` | `skills/torusguard-web-validate`| Authorized non-destructive HTTP probing |30| **Exploit** | `npx torusguard exploit-check` | `/torusguard exploit-check`| `skills/torusguard-exploit-check`| Bounded single-step exploitability confirmation |31| **Full** | `npx torusguard full` | `/torusguard full` | `skills/torusguard-full` | End-to-end 7-stage closed-loop execution |32| **Sync** | `npx torusguard rules sync` | `/torusguard rules sync` | `skills/torusguard-init` | Synchronize rules across AI editors (Cursor, Claude, Antigravity) |3334---3536## Non-Negotiable Invariants37381. **Browser-Code Truth:** If the client receives it, it is public. Zero hardcoded secrets (`SUPABASE_SERVICE_ROLE_KEY`, private tokens, live API keys) in frontend code.392. **Multi-Tenant Isolation:** All database lookups must be scoped by organization or user ownership (`tenant_id`, `organization_id`, `where: { tenantId }`).403. **Ponytail Churn Bounds:** Patches must be minimal and surgical ($\le 35$ additions, $\le 25$ deletions). Never perform full-file rewrites.414. **Standardized 75-Column Terminal:** All CLI terminal output is strictly normalized to 75 visual columns with Unicode emoji width calculation, ANSI escape handling, and visual truncation with ellipsis (`...`).425. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`, `[AllowAnonymous]`, or `csrf().disable()`.436. **Snapshots Before Edits:** Every code modification must capture a byte-for-byte pre-apply backup in `.torusguard/snapshots/<run_id>/` before touching disk code.4445---4647## Workspace Layout Structure48```49.torusguard/50├── config/51│ ├── torusguard.json # Detected stack, settings, and rule counts52│ └── scope.json # Authorized runtime validation targets & TTL53├── memory/54│ ├── context.json # Aggregated security memory context55│ ├── patterns.json # Distilled Golden Fix Recipes56│ └── events.json # Historical audit, apply, and recheck events57├── rules/58│ └── active/ # Active TG-* rule definitions59├── runs/60│ └── run-YYYYMMDD-HHMMSS-audit/61│ ├── findings.json # Machine-readable AST findings62│ ├── findings.md # Actionable markdown finding cards63│ ├── remediation.md # Formulated candidate patch catalog64│ ├── diff_summary.md # Summary of applied diffs65│ ├── recheck.md # Differential recheck status transitions66│ ├── report.html # Single-file visual dark-mode HTML report67│ ├── results.sarif # OASIS SARIF v2.1.0 log68│ └── bundles/ # Formulated Ponytail remediation bundles69└── snapshots/70 └── run-YYYYMMDD-HHMMSS-audit/ # Pre-apply .bak files for instant rollback71```