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
@@ -1,7 +1,7 @@
1
1
  ---
2
- description: Executive posture reporting, cluster analysis, signed compliance audit, and OASIS SARIF v2.1.0 structured export.
2
+ description: Executive posture reporting, interactive HTML dashboard generation, directory attack surface heatmap, and OASIS SARIF v2.1.0 structured export.
3
3
  tools: Read, Grep, Glob, Bash, Write
4
- version: 1.3.6
4
+ version: 2.2.0
5
5
  agent: reviewer
6
6
  lifecycle-phase: Phase 7 (Reporting & SARIF Export)
7
7
  required-skills:
@@ -11,91 +11,95 @@ scripts-binding:
11
11
  - .torusguard/scripts/report_sync.py
12
12
  - .torusguard/scripts/sarif_exporter.py
13
13
  - .torusguard/scripts/run_manager.py
14
+ - .torusguard/scripts/term_ui.py
14
15
  ---
15
16
 
16
- # /torusguard report — Unified Security Posture Report & SARIF Export
17
+ # /torusguard report — Unified Security Posture Report & SARIF / HTML Export
17
18
 
18
19
  $ARGUMENTS
19
20
 
20
21
  ---
21
22
 
22
23
  ## Objective
23
- Executive posture reporting, cluster analysis, signed compliance audit, and SARIF v2.1.0 export.
24
+ Generate an executive security posture report, interactive dark-mode HTML dashboard (`report.html`), and schema-compliant OASIS SARIF v2.1.0 log (`results.sarif`) with zero network dependencies.
24
25
 
25
26
  ---
26
27
 
27
- ## Mandatory Pre-Flight Context Inspection
28
+ ## Dual Mode Execution Syntax
28
29
 
29
- Inspect run records and reporting parameters before generating release artifacts:
30
- 1. **Active Run Records:** Ensure target run folder contains `findings.json` or `findings.md`.
31
- 2. **SARIF v2.1.0 Schema:** Validate output structure against official OASIS SARIF standard.
32
- 3. **Multi-Analysis Category:** Tag static findings under category `torusguard/static` to prevent CI collision.
33
- 4. **Secret Masking:** Ensure zero unredacted authorization tokens or API keys appear in report.
34
- 5. **Role Boundary:** Enforce reviewer agent sign-off before archiving run results.
30
+ | Target Artifact | Mode A: Terminal CLI | Mode B: AI Chat Slash Command | Output Location |
31
+ | :--- | :--- | :--- | :--- |
32
+ | **Interactive HTML Dashboard** | `npx torusguard report --html` | `/torusguard report --html` or `/torusguard-report` | `report.html` (workspace root) + `.torusguard/runs/report-latest.html` |
33
+ | **OASIS SARIF v2.1.0 Log** | `npx torusguard report --sarif` | `/torusguard report --sarif` | `.torusguard/runs/results-latest.sarif` |
34
+ | **Combined (Both)** | `npx torusguard report --html --sarif` | `/torusguard report --html --sarif` | Both `report.html` and `results-latest.sarif` in a single pass |
35
+ | **Custom Path** | `npx torusguard report --html --out <path>` | `/torusguard report --out <path>` | Specified path + latest run mirror |
36
+ | **Monorepo Subproject** | `npx torusguard report --target <dir> --html` | `/torusguard report --target <dir>` | `<dir>/report.html` |
35
37
 
36
38
  ---
37
39
 
38
- ## When to Use /torusguard report
39
-
40
- | Trigger Scenario | Recommended Action |
41
- | :--- | :--- |
42
- | Concluding a security review cycle or audit milestone | Run `/torusguard report` |
43
- | Exporting SARIF v2.1.0 logs for GitHub Code Scanning | Run `/torusguard report` |
44
- | Sharing executive posture summaries with stakeholders | Run `/torusguard report` |
45
- | Applying code modifications | Run `/torusguard apply` |
46
- | Re-checking modified files | Run `/torusguard recheck` |
47
-
48
- ---
49
-
50
- ## Living Report Invariant
51
- - Executive posture reports incorporate health scoring and metrics from `security_report.md`.
52
- - Emits visual dark-mode HTML (`--html`) and OASIS SARIF v2.1.0 (`--sarif`).
53
-
54
- ## Execution Steps
40
+ ## Mandatory Pre-Flight Context Inspection
55
41
 
56
- 1. **Aggregate Lifecycle Data:** Load all finding cards, verification traces, and recheck logs.
57
- 2. **Export OASIS SARIF v2.1.0:**
58
- ```bash
59
- python .torusguard/scripts/sarif_exporter.py --run <run_dir> --output <run_dir>/results.sarif
60
- ```
61
- 3. **Compile Executive Markdown Report:** Generate `report.md` with executive summary, posture score, and metrics.
62
- 4. **Sign Off Run Manifest:** Update `.torusguard/runs/<run_id>/manifest.json` with final status counts.
63
- 5. **Archive Results:** Confirm artifacts (`report.md`, `results.sarif`, `summary.md`) are saved on disk.
42
+ Inspect run records and reporting parameters before generating release artifacts:
43
+ 1. **Active Run Records:** Ensure target run folder or `.torusguard/runs/` contains valid run records.
44
+ 2. **Dual-Ledger Ground Truth:** Confirm that `security_report.md` at workspace root is in lockstep with findings.
45
+ 3. **SARIF v2.1.0 Schema:** Validate output structure against official OASIS SARIF standard (`sarif-schema-2.1.0.json`).
46
+ 4. **Multi-Analysis Category:** Tag static findings under category `torusguard/static` to prevent CI collisions.
47
+ 5. **Zero External CDN:** Ensure all icons, gauges, and scripts in `report.html` are 100% self-contained and offline-ready.
48
+ 6. **Secret Masking:** Ensure zero unredacted authorization tokens or API keys appear in report text.
64
49
 
65
50
  ---
66
51
 
67
- ## Failure Recovery
52
+ ## Interactive Dashboard Features (v2.2.0)
68
53
 
69
- - **SARIF Schema Error:** Re-run `sarif_exporter.py` with schema validation flag to locate invalid properties.
70
- - **Empty Findings List:** Emit valid clean report indicating zero security vulnerabilities detected.
71
- - **Missing Run Folder:** Point script to latest valid timestamped run in `.torusguard/runs/`.
72
- - **Halt Trigger:** Abort if unredacted private secrets are detected in output text.
54
+ When viewing `report.html` in any browser:
55
+ 1. **Safe Defenses vs Harmed Exposure:** Complete Defended Invariants inventory across all 74 rules in 18 architectural families. Clean codebases earn 100/100 (74 Defended, 0 Harmed).
56
+ 2. **Directory Attack Surface Heatmap:** Visual directory tree of exposure risk. Clicking any directory card filters the findings table to that specific folder.
57
+ 3. **Golden Recipe Explorer:** Distilled, verified fix patterns with before/after code templates and one-click clipboard copying.
58
+ 4. **Prescriptive Next Best Defenses:** Stack-aware security recommendations with copyable `npx torusguard harden` commands.
59
+ 5. **Client-Side Exporters:** Zero-network buttons to download OASIS SARIF v2.1.0 and CSV records directly from browser memory.
60
+ 6. **Multi-Agent AI Prompt Presets:** One-click prompts tailored for Cursor (`.cursorrules`), Claude Code (`CLAUDE.md`), Antigravity, and GitHub Copilot.
61
+ 7. **Print & PDF Styling:** Built-in high-contrast `@media print` layout for boardroom and compliance distribution.
73
62
 
74
63
  ---
75
64
 
76
- ## Hallucination Guard
65
+ ## Execution Steps
77
66
 
78
- - ❌ Never invent vulnerability counts not backed by actual findings in the run ledger.
79
- - ❌ Never generate invalid SARIF JSON with missing physical location URIs.
80
- - ✅ Always export standard-compliant SARIF v2.1.0 with AST line fingerprints.
67
+ 1. **Detect Mode & Arguments:**
68
+ - Parse `--html`, `--sarif`, `--out`, `--target`, and `--run` from `$ARGUMENTS`.
69
+ - If no format flag is specified in chat, default to generating the visual HTML dashboard (`report.html`).
70
+ 2. **Execute Reporter Scripts:**
71
+ - **For SARIF:**
72
+ ```bash
73
+ python .torusguard/scripts/sarif_exporter.py [--output <path>] [--root <target>]
74
+ ```
75
+ - **For HTML:**
76
+ ```bash
77
+ python .torusguard/scripts/html_reporter.py [--out <path>] [--root <target>]
78
+ ```
79
+ 3. **Synchronize Dual Ledger:**
80
+ - Verify `security_report.md` matches `report.html` findings and posture score.
81
+ 4. **Emit 75-Column Visual Summary Card:**
82
+ - Present markdown output card with direct clickable links to both `report.html` and `security_report.md`.
81
83
 
82
84
  ---
83
85
 
84
86
  ## Output Card Format
85
87
 
86
88
  ```markdown
87
- ### 📊 TorusGuard Security Posture Report
88
- - **Run ID:** `run-YYYYMMDD-HHMMSS`
89
- - **Total Findings:** [Count] ([Fixed] Fixed, [Open] Open)
90
- - **Security Posture Score:** [Score]/100
91
- - **SARIF v2.1.0 Export:** `.torusguard/runs/<run_id>/results.sarif`
92
- - **Executive Report:** `.torusguard/runs/<run_id>/report.md`
93
- - **Status:** COMPLETE — report published
89
+ ### 🛡️ TorusGuard Security Posture Report Emitted
90
+ - **Posture Score:** [Score]/100 ([Status Label])
91
+ - **Invariants Defended:** [N] Defended · [M] Harmed (74 Rules)
92
+ - **Living Ledger:** [security_report.md](file:///path/to/security_report.md)
93
+ - **HTML Dashboard:** [report.html](file:///path/to/report.html)
94
+ - **SARIF v2.1.0 Export:** [results-latest.sarif](file:///path/to/results-latest.sarif)
95
+ - **Status:** COMPLETE — dual-ledger synchronized
94
96
  ```
95
97
 
96
98
  ---
97
99
 
98
- ## Next Steps
100
+ ## Failure Recovery
99
101
 
100
- 1. Upload `results.sarif` to GitHub Code Scanning via `.github/workflows/`.
101
- 2. Share `report.md` with engineering stakeholders and project maintainers.
102
+ - **Missing Run Folder:** Auto-discover the latest timestamped run in `.torusguard/runs/`.
103
+ - **Windows File Lock:** `html_reporter.py` uses atomic temporary write swapping with exponential retry.
104
+ - **Missing SARIF Input:** Auto-discovers findings from the latest audit run in `.torusguard/runs/`.
105
+ - **Clean Workspace:** Emits 100/100 posture score with all 74 defended invariants listed.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  description: Read-only diagnostic overview of workspace security posture, active configuration, rules catalog, and run history.
3
3
  tools: Read, Grep, Glob, Bash
4
- version: 1.3.6
4
+ version: 1.4.0
5
5
  agent: reviewer
6
6
  lifecycle-phase: System / Diagnostics
7
7
  required-skills:
@@ -20,6 +20,9 @@ $ARGUMENTS
20
20
  ## Objective
21
21
  Read-only diagnostic overview of workspace security posture, active configuration, and run history.
22
22
 
23
+ Supported CLI flags:
24
+ - `npx torusguard status [--target <dir>]` : Diagnostic check on specified project directory
25
+
23
26
  ---
24
27
 
25
28
  ## Mandatory Pre-Flight Context Inspection
@@ -0,0 +1,110 @@
1
+ ---
2
+ description: Governed patch application with pre-apply rollback snapshots and Human Gate authorization.
3
+ tools: Read, Grep, Glob, Bash, Edit, Write
4
+ version: 1.4.0
5
+ agent: remediator
6
+ lifecycle-phase: Phase 5 (Patch Application)
7
+ required-skills:
8
+ - torusguard-apply
9
+ scripts-binding:
10
+ - .torusguard/scripts/apply_runner.py
11
+ - .torusguard/scripts/report_sync.py
12
+ - .torusguard/scripts/run_manager.py
13
+ - .torusguard/scripts/diff_guard.py
14
+ ---
15
+
16
+ # /torusguard apply — Governed Patch Application & Rollback Snapshot
17
+
18
+ $ARGUMENTS
19
+
20
+ ---
21
+
22
+ ## Objective
23
+ Governed patch application with pre-apply rollback snapshots and Human Gate authorization.
24
+
25
+ Supported CLI flags:
26
+ - `npx torusguard apply [--target <dir>]` : Apply candidate patches with confirmation prompt
27
+ - `npx torusguard apply --diff` : Preview unified diffs without modifying files on disk
28
+ - `npx torusguard apply --selective` : Interactively review and approve patches one by one
29
+ - `npx torusguard apply --verify` : Trigger immediate differential AST recheck post-apply
30
+ - `npx torusguard apply --list-snapshots` : List available historical pre-apply backup snapshots
31
+ - `npx torusguard apply --yes` / `-y` : Non-interactive auto-approval mode
32
+
33
+ ---
34
+
35
+ ## Mandatory Pre-Flight Context Inspection
36
+
37
+ Inspect bundle validity and file safety before modifying disk code:
38
+ 1. **Bundle Verification:** Assert `patch.diff` exists in active run's remediation folder.
39
+ 2. **Pre-Apply Snapshot:** Save a byte-for-byte backup copy (`.bak` or `.torusguard/snapshots/<run_id>/`) prior to editing.
40
+ 3. **Uncommitted Changes:** Check git status; ensure target file has clean baseline.
41
+ 4. **Ponytail Check:** Re-verify that patch additions $\le 35$ and deletions $\le 25$.
42
+ 5. **Human Gate:** Confirm operator approval before committing edits to disk.
43
+ 6. **Workspace Cleanliness:** Verify git working tree has no uncommitted merge conflicts.
44
+ 7. **Execution Privilege:** Verify write access to targeted file locations.
45
+
46
+ ---
47
+
48
+ ## When to Use /torusguard apply
49
+
50
+ | Trigger Scenario | Recommended Action |
51
+ | :--- | :--- |
52
+ | Applying an approved remediation patch to disk | Run `/torusguard apply` |
53
+ | Generating patch diff without modifying disk | Run `/torusguard harden` |
54
+ | Verifying that patch eliminated flaw without regression | Run `/torusguard recheck` |
55
+ | Reverting an applied patch | Restore from `.bak` snapshot |
56
+ | Checking workspace status | Run `/torusguard status` |
57
+
58
+ ---
59
+
60
+ ## Living Report Invariant
61
+ - Applied patches create pre-apply `.bak` snapshots in `.torusguard/snapshots/<run_id>/`.
62
+ - Finding statuses transition in `security_report.md` to `APPLIED 🔵`.
63
+ - Instant rollback available via `npx torusguard rollback`.
64
+
65
+ ## Execution Steps
66
+
67
+ 1. **Load Remediation Bundle:** Read `patch.diff` and metadata from active run directory.
68
+ 2. **Audit Patch Invariants:** Run `python .torusguard/scripts/diff_guard.py <patch.diff>`.
69
+ 3. **Create Rollback Backup:** Copy target file to `.torusguard/runs/<run_id>/.torusguard/snapshots/<run_id>/<filename>.bak`.
70
+ 4. **Apply Minimal Diff:** Execute precise surgical edit using `replace_file_content` or `patch`.
71
+ 5. **Assert Syntax & Integrity:** Check that modified file compiles cleanly without syntax errors.
72
+ 6. **Log Application Ledger:** Record timestamp, original SHA-256, and patched SHA-256 in `apply-log.json`.
73
+
74
+ ---
75
+
76
+ ## Failure Recovery
77
+
78
+ - **Syntax Error After Patch:** Instantly revert target file from `.bak` backup snapshot.
79
+ - **Merge / Context Conflict:** Re-run `/torusguard harden` to regenerate diff against latest disk lines.
80
+ - **Missing Backup File:** Do not apply patch if backup copy cannot be written.
81
+ - **Halt Trigger:** Abort if git working tree is dirty on conflicting lines.
82
+
83
+ ---
84
+
85
+ ## Hallucination Guard
86
+
87
+ - ❌ Never apply code changes without creating an exact pre-apply rollback backup first.
88
+ - ❌ Never touch files not explicitly listed in the approved `patch.diff`.
89
+ - ✅ Always verify syntax compilation immediately after modifying source files.
90
+
91
+ ---
92
+
93
+ ## Output Card Format
94
+
95
+ ```markdown
96
+ ### 🚀 TorusGuard Patch Application
97
+ - **Finding Addressed:** `TG-XXX-HASH`
98
+ - **File Patched:** `src/path/to/file.py`
99
+ - **Rollback Backup:** `.torusguard/runs/<run_id>/.torusguard/snapshots/<run_id>/<file>.bak`
100
+ - **Churn Applied:** +[Additions] / -[Deletions] lines
101
+ - **Syntax Check:** PASSED (clean compile)
102
+ - **Status:** APPLIED — run `/torusguard recheck` to verify fix
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Next Steps
108
+
109
+ 1. Run `/torusguard recheck` to perform differential audit on the modified file.
110
+ 2. Run test suites to verify that business logic and regressions remain intact.
@@ -0,0 +1,105 @@
1
+ ---
2
+ description: Static security AST scanning, stable line-shift invariant fingerprinting, root-cause clustering, and 0-100 confidence scoring.
3
+ tools: Read, Grep, Glob, Bash, Write
4
+ version: 1.4.0
5
+ agent: auditor
6
+ lifecycle-phase: Phase 2 (Static Audit & Clustering)
7
+ required-skills:
8
+ - torusguard-audit
9
+ scripts-binding:
10
+ - .torusguard/scripts/audit_runner.py
11
+ - .torusguard/scripts/report_sync.py
12
+ - .torusguard/scripts/run_manager.py
13
+ - .torusguard/scripts/finding_scorer.py
14
+ ---
15
+
16
+ # /torusguard audit — Static Security Code Scan & Clustering
17
+
18
+ $ARGUMENTS
19
+
20
+ ---
21
+
22
+ ## Objective
23
+ Static security AST scanning, stable fingerprinting, root-cause clustering, throughput telemetry, and 0-100 scoring.
24
+
25
+ Supported CLI flags:
26
+ - `npx torusguard audit [--target <dir>]` : Specify project root directory
27
+ - `npx torusguard audit --watch` / `-w` : Continuous watch mode, re-scanning on file change
28
+ - `npx torusguard audit --sarif` : Automatically export OASIS SARIF v2.1.0 log
29
+ - `npx torusguard audit --severity <critical|high|medium|low>` : Floor filter for findings
30
+
31
+ ---
32
+
33
+ ## Mandatory Pre-Flight Context Inspection
34
+
35
+ Inspect workspace prerequisites before launching static audit:
36
+ 1. **Init State (`torusguard.json`):** Assert repository is initialized.
37
+ 2. **Active Rules (`rules/active/`):** Confirm rule definitions exist.
38
+ 3. **Exclusions:** Assert `node_modules/`, `.venv/`, `dist/`, `.git/` are skipped.
39
+ 4. **Run Folder:** Allocate isolated folder in `.torusguard/runs/`.
40
+ 5. **Syntax Check:** Check for syntax errors before parsing ASTs.
41
+
42
+ ---
43
+
44
+ ## When to Use /torusguard audit
45
+
46
+ | Trigger Scenario | Recommended Action |
47
+ | :--- | :--- |
48
+ | First-time scan of repository or new branch | Run `/torusguard audit` |
49
+ | Pre-commit review and PR security checks | Run `/torusguard audit` |
50
+ | Uninitialized project | Run `/torusguard init` first |
51
+ | Live endpoint or runtime probing | Run `/torusguard web-validate` |
52
+ | Differential check after patch | Run `/torusguard recheck` |
53
+
54
+ ---
55
+
56
+ ## Living Report Invariant
57
+ - Audit discoveries automatically synchronize to `security_report.md` at workspace root.
58
+ - Findings transition into `OPEN 🔴` status with stable invariant fingerprints.
59
+
60
+ ## Execution Steps
61
+
62
+ 1. **Allocate Run Folder:** Run `python .torusguard/scripts/run_manager.py create audit`.
63
+ 2. **Scan Codebase ASTs:** Match active rules against source trees.
64
+ 3. **Compute Stable Fingerprints:** Hash AST context to produce stable IDs.
65
+ 4. **Cluster Root Causes:** Group findings sharing identical sinks.
66
+ 5. **Score Confidence (0–100):** Run `python .torusguard/scripts/finding_scorer.py --run <run_dir>`.
67
+ 6. **Emit Artifacts:** Write `findings.md`, `findings.json`, and `summary.md`.
68
+
69
+ ---
70
+
71
+ ## Failure Recovery
72
+
73
+ - **Zero Rules Active:** Re-run `/torusguard init` to activate rules.
74
+ - **AST Parse Error:** Log syntax error on malformed file, skip, and continue.
75
+ - **Scorer Failure:** Ensure Python 3.10+; verify finding JSON structure.
76
+ - **Halt Trigger:** Abort if run folder cannot be allocated or disk write fails.
77
+
78
+ ---
79
+
80
+ ## Hallucination Guard
81
+
82
+ - ❌ Never invent finding IDs without AST line hashing.
83
+ - ❌ Never flag test fixtures as critical security flaws.
84
+ - ✅ Always calculate scores using `.torusguard/scripts/finding_scorer.py`.
85
+
86
+ ---
87
+
88
+ ## Output Card Format
89
+
90
+ ```markdown
91
+ ### 🔎 TorusGuard Static Audit Results
92
+ - **Run ID:** `run-YYYYMMDD-HHMMSS-audit`
93
+ - **Files Scanned:** [Count] source files
94
+ - **Total Findings:** [Count] ([Critical] Critical, [High] High)
95
+ - **Root Cause Clusters:** [Count] architectural issues
96
+ - **Confidence:** [Score]/100
97
+ - **Artifact:** `.torusguard/runs/<run_id>/findings.md`
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Next Steps
103
+
104
+ 1. Run `/torusguard verify` to validate exploitability and review evidence.
105
+ 2. Run `/torusguard harden` to generate minimal surgical remediation plans.
@@ -0,0 +1,96 @@
1
+ ---
2
+ description: Legal scope definition, target ownership proof verification, and safety boundary enforcement for runtime validation.
3
+ tools: Read, Grep, Glob, Bash, Write
4
+ version: 1.3.6
5
+ agent: reviewer
6
+ lifecycle-phase: Phase 1 (Authorization Gate)
7
+ required-skills:
8
+ - torusguard-authorize
9
+ scripts-binding:
10
+ - .torusguard/scripts/report_sync.py
11
+ - .torusguard/scripts/safety_gate.py
12
+ ---
13
+
14
+ # /torusguard authorize — Legal Scope & Safety Gate
15
+
16
+ $ARGUMENTS
17
+
18
+ ---
19
+
20
+ ## Objective
21
+ Legal scope definition, target ownership proof verification, and safety boundary enforcement.
22
+
23
+ ---
24
+
25
+ ## Mandatory Pre-Flight Context Inspection
26
+
27
+ Inspect authorization parameters and environment safety before executing:
28
+ 1. **Config Record (`.torusguard/config/torusguard.json`):** Assert repository is initialized.
29
+ 2. **Current Scope (`.torusguard/config/scope.json`):** Inspect active allowed targets, paths, and TTL expiry.
30
+ 3. **Environment Classification:** Assert target is local or staging (`localhost`, `127.0.0.1`, `*.local`, `*.staging.*`). Production targets require explicit approval.
31
+ 4. **Destructive Guard:** Ensure state-changing operations (`DELETE`, bulk drops) remain blocked by default.
32
+ 5. **Ownership Proof:** Verify target ownership token or local process binding.
33
+ 6. **TTL Window:** Ensure authorization window does not exceed 24 hours.
34
+
35
+ ---
36
+
37
+ ## When to Use /torusguard authorize
38
+
39
+ | Trigger Scenario | Recommended Action |
40
+ | :--- | :--- |
41
+ | Preparing for live HTTP probes or API validation | Run `/torusguard authorize` |
42
+ | Updating allowed hosts, path prefixes, or rate limits | Run `/torusguard authorize` |
43
+ | Static-only security audit | Skip authorize; run `/torusguard audit` |
44
+ | Checking active legal scope status | Run `/torusguard status` |
45
+ | Expired authorization window | Re-run `/torusguard authorize` |
46
+
47
+ ---
48
+
49
+ ## Execution Steps
50
+
51
+ 1. **Capture Scope Parameters:** Collect target URL, allowed paths, forbidden prefixes, and max request budget.
52
+ 2. **Validate Host Ownership:** Verify target is local or matches authorized test domains.
53
+ 3. **Invoke Safety Gate:**
54
+ ```bash
55
+ python .torusguard/scripts/safety_gate.py check --url <target_url>
56
+ ```
57
+ 4. **Write Scope File (`.torusguard/config/scope.json`):** Save authorized targets, valid TTL timestamp, and request rate caps.
58
+ 5. **Confirm Scope Binding:** Verify `.torusguard/config/scope.json` parses as valid JSON against schema.
59
+
60
+ ---
61
+
62
+ ## Failure Recovery
63
+
64
+ - **Unreachable Host:** Verify local server is running on the specified port.
65
+ - **Production Target Warning:** If target resolves to an external production host, halt and request operator override.
66
+ - **Malformed JSON:** Re-initialize `scope.json` from `.torusguard/schemas/auth-boundary.schema.json`.
67
+ - **Halt Trigger:** Abort immediately if user provides wildcard target (`*`) or third-party domain.
68
+
69
+ ---
70
+
71
+ ## Hallucination Guard
72
+
73
+ - ❌ Never proceed with runtime probing without an explicit, valid `.torusguard/config/scope.json`.
74
+ - ❌ Never authorize destructive HTTP methods (`DELETE`, `DROP`) under default non-destructive policy.
75
+ - ✅ Always validate targets through `.torusguard/scripts/safety_gate.py`.
76
+
77
+ ---
78
+
79
+ ## Output Card Format
80
+
81
+ ```markdown
82
+ ### 🔒 TorusGuard Authorization Gate
83
+ - **Target URL:** [Target Host or URL]
84
+ - **Environment:** [Localhost / Staging / Container]
85
+ - **Allowed Paths:** [Path prefixes or all authorized]
86
+ - **Rate Limit:** [Max requests / concurrency limit]
87
+ - **Scope File:** `.torusguard/config/scope.json`
88
+ - **Status:** AUTHORIZED — ready for `/torusguard web-validate`
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Next Steps
94
+
95
+ 1. Run `/torusguard audit` to scan codebase for AST security vulnerabilities.
96
+ 2. Run `/torusguard web-validate` to begin safe, authorized endpoint validation.
@@ -0,0 +1,98 @@
1
+ ---
2
+ description: Safe, bounded, single-step exploitability confirmation across 5 standard verification statuses.
3
+ tools: Read, Grep, Glob, Bash, Write
4
+ version: 1.3.6
5
+ agent: validator
6
+ lifecycle-phase: Phase 3c (Exploitability Check)
7
+ required-skills:
8
+ - torusguard-exploit-check
9
+ scripts-binding:
10
+ - .torusguard/scripts/report_sync.py
11
+ - .torusguard/scripts/safety_gate.py
12
+ - .torusguard/scripts/finding_scorer.py
13
+ ---
14
+
15
+ # /torusguard exploit-check — Bounded Exploitability Confirmation
16
+
17
+ $ARGUMENTS
18
+
19
+ ---
20
+
21
+ ## Objective
22
+ Safe, bounded, single-step exploitability confirmation across 5 standard verification statuses.
23
+
24
+ ---
25
+
26
+ ## Mandatory Pre-Flight Context Inspection
27
+
28
+ Inspect authorization parameters and probe safety constraints:
29
+ 1. **Scope Check (`scope.json`):** Assert endpoint is authorized.
30
+ 2. **Approved Probes:** Use benign canaries (SQLi math, HTML marker, unauth read).
31
+ 3. **Destructive Ban:** Strictly prohibit drops, DOS, or weaponized payloads.
32
+ 4. **Safety Gate:** Verify probe with `safety_gate.py` prior to dispatch.
33
+ 5. **Bound:** Limit to single non-destructive HTTP request per finding.
34
+ 6. **Audit Trail:** Inject `X-TorusGuard-AuthID` header on all outbound requests.
35
+
36
+ ---
37
+
38
+ ## When to Use /torusguard exploit-check
39
+
40
+ | Trigger Scenario | Recommended Action |
41
+ | :--- | :--- |
42
+ | Confirming whether a flaw is practically exploitable | Run `/torusguard exploit-check` |
43
+ | Upgrading Medium confidence finding to Confirmed | Run `/torusguard exploit-check` |
44
+ | Verifying IDOR or tenant isolation boundaries | Run `/torusguard exploit-check` |
45
+ | Routine endpoint header inspection | Run `/torusguard web-validate` |
46
+ | Applying approved remediation patch | Run `/torusguard apply` |
47
+
48
+ ---
49
+
50
+ ## Execution Steps
51
+
52
+ 1. **Verify Authorization Scope:** Confirm target host and route in `scope.json`.
53
+ 2. **Select Safe Canary:** Choose inert mathematical sentinel or unauth GET.
54
+ 3. **Validate With Safety Gate:**
55
+ ```bash
56
+ python .torusguard/scripts/safety_gate.py check --url <target_url> --payload <canary>
57
+ ```
58
+ 4. **Dispatch Bounded Single Probe:** Send request with header `X-TorusGuard-AuthID`.
59
+ 5. **Classify Status:** Evaluate response against 5 outcomes: `Confirmed`, `Needs Review`, `Not Reproducible`, `Blocked by Controls`, `Out of Scope`.
60
+ 6. **Emit Artifacts:** Write `exploit-check.md` and update `findings.json`.
61
+
62
+ ---
63
+
64
+ ## Failure Recovery
65
+
66
+ - **Connection Refused:** Verify target server is running locally on port.
67
+ - **Safety Gate Block:** If `Manual Only`, halt automated probe and request human review.
68
+ - **Ambiguous Response:** Mark finding as `Needs Review`; never assume exploit without proof.
69
+ - **Halt Trigger:** Abort if probe causes server 500 error or unexpected crash.
70
+
71
+ ---
72
+
73
+ ## Hallucination Guard
74
+
75
+ - ❌ Never classify a vulnerability as `Confirmed` without direct sentinel reflection.
76
+ - ❌ Never execute brute force attacks or automated password spraying.
77
+ - ✅ Always provide reproducible curl commands with redacted credentials.
78
+
79
+ ---
80
+
81
+ ## Output Card Format
82
+
83
+ ```markdown
84
+ ### 🎯 TorusGuard Exploitability Confirmation
85
+ - **Target Route:** `[METHOD] /path`
86
+ - **Finding ID:** `TG-XXX-HASH`
87
+ - **Canary Used:** [Inert Math Sentinel / Unauth Read]
88
+ - **Status:** [Confirmed / Not Reproducible / Blocked]
89
+ - **Evidence:** [Response snippet demonstrating leak or block]
90
+ - **Replay Curl:** `curl -X [METHOD] http://localhost:PORT/path ...`
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Next Steps
96
+
97
+ 1. Run `/torusguard harden` to formulate surgical patch bundles for confirmed flaws.
98
+ 2. Run `/torusguard report` to export findings into SARIF v2.1.0 format.