torusguard 1.3.5 → 1.3.6

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 (152) hide show
  1. package/.torusguard/.manifest.json +35 -35
  2. package/.torusguard/runs/report-latest.html +2685 -303
  3. package/.torusguard/runs/results-latest.sarif +20 -0
  4. package/.torusguard/runs/run-20260918-104221-audit/findings.json +1 -0
  5. package/.torusguard/runs/run-20260918-104221-audit/findings.md +8 -0
  6. package/.torusguard/runs/run-20260918-104221-audit/manifest.json +12 -0
  7. package/.torusguard/runs/run-20260918-104221-audit/summary.md +5 -0
  8. package/.torusguard/runs/run-20260918-104236-audit/findings.json +2314 -0
  9. package/.torusguard/runs/run-20260918-104236-audit/findings.md +960 -0
  10. package/.torusguard/runs/run-20260918-104236-audit/manifest.json +12 -0
  11. package/.torusguard/runs/run-20260918-104236-audit/summary.md +5 -0
  12. package/.torusguard/runs/run-20260918-105723-audit/findings.json +2382 -0
  13. package/.torusguard/runs/run-20260918-105723-audit/findings.md +960 -0
  14. package/.torusguard/runs/run-20260918-105723-audit/manifest.json +12 -0
  15. package/.torusguard/runs/run-20260918-105723-audit/summary.md +5 -0
  16. package/.torusguard/runs/run-20260918-105731-audit/findings.json +1 -0
  17. package/.torusguard/runs/run-20260918-105731-audit/findings.md +8 -0
  18. package/.torusguard/runs/run-20260918-105731-audit/manifest.json +12 -0
  19. package/.torusguard/runs/run-20260918-105731-audit/summary.md +5 -0
  20. package/.torusguard/runs/run-20260918-105940-audit/findings.json +1 -0
  21. package/.torusguard/runs/run-20260918-105940-audit/findings.md +8 -0
  22. package/.torusguard/runs/run-20260918-105940-audit/manifest.json +12 -0
  23. package/.torusguard/runs/run-20260918-105940-audit/summary.md +5 -0
  24. package/.torusguard/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
  25. package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  26. package/.torusguard/scripts/__pycache__/diff_guard.cpython-314.pyc +0 -0
  27. package/.torusguard/scripts/__pycache__/finding_scorer.cpython-314.pyc +0 -0
  28. package/.torusguard/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
  29. package/.torusguard/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  30. package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
  31. package/.torusguard/scripts/__pycache__/memory_engine.cpython-314.pyc +0 -0
  32. package/.torusguard/scripts/__pycache__/monorepo_detector.cpython-314.pyc +0 -0
  33. package/.torusguard/scripts/__pycache__/recheck_runner.cpython-314.pyc +0 -0
  34. package/.torusguard/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  35. package/.torusguard/scripts/__pycache__/run_manager.cpython-314.pyc +0 -0
  36. package/.torusguard/scripts/__pycache__/sarif_exporter.cpython-314.pyc +0 -0
  37. package/.torusguard/scripts/__pycache__/stack_detect.cpython-314.pyc +0 -0
  38. package/.torusguard/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
  39. package/.torusguard/scripts/apply_runner.py +11 -5
  40. package/.torusguard/scripts/audit_runner.py +222 -15
  41. package/.torusguard/scripts/harden_runner.py +3 -3
  42. package/.torusguard/scripts/html_reporter.py +2668 -648
  43. package/.torusguard/scripts/recheck_runner.py +3 -3
  44. package/.torusguard/scripts/recipes_runner.py +3 -3
  45. package/.torusguard/scripts/report_sync.py +370 -74
  46. package/.torusguard/scripts/sarif_exporter.py +48 -8
  47. package/.torusguard/scripts/stack_detect.py +44 -2
  48. package/.torusguard/scripts/term_ui.py +1 -1
  49. package/.torusguard/skills/torusguard/SKILL.md +75 -72
  50. package/.torusguard/skills/torusguard-apply/SKILL.md +84 -80
  51. package/.torusguard/skills/torusguard-audit/SKILL.md +87 -83
  52. package/.torusguard/skills/torusguard-authorize/SKILL.md +7 -2
  53. package/.torusguard/skills/torusguard-exploit-check/SKILL.md +7 -2
  54. package/.torusguard/skills/torusguard-full/SKILL.md +7 -2
  55. package/.torusguard/skills/torusguard-harden/SKILL.md +98 -94
  56. package/.torusguard/skills/torusguard-init/SKILL.md +68 -64
  57. package/.torusguard/skills/torusguard-recheck/SKILL.md +81 -77
  58. package/.torusguard/skills/torusguard-report/SKILL.md +93 -72
  59. package/.torusguard/skills/torusguard-status/SKILL.md +62 -58
  60. package/.torusguard/skills/torusguard-verify/SKILL.md +7 -2
  61. package/.torusguard/skills/torusguard-web-validate/SKILL.md +7 -2
  62. package/.torusguard/workflows/apply.md +1 -1
  63. package/.torusguard/workflows/audit.md +1 -1
  64. package/.torusguard/workflows/authorize.md +1 -1
  65. package/.torusguard/workflows/exploit-check.md +1 -1
  66. package/.torusguard/workflows/harden.md +1 -1
  67. package/.torusguard/workflows/init.md +1 -1
  68. package/.torusguard/workflows/memory.md +1 -1
  69. package/.torusguard/workflows/recheck.md +1 -1
  70. package/.torusguard/workflows/report.md +1 -1
  71. package/.torusguard/workflows/status.md +1 -1
  72. package/.torusguard/workflows/verify.md +1 -1
  73. package/.torusguard/workflows/web-validate.md +1 -1
  74. package/README.md +14 -8
  75. package/bin/torusguard.js +56 -20
  76. package/package.json +1 -1
  77. package/skills/torusguard/SKILL.md +1 -1
  78. package/skills/torusguard/bootstrap.py +7 -2
  79. package/skills/torusguard/payload/.manifest.json +35 -35
  80. package/skills/torusguard/payload/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
  81. package/skills/torusguard/payload/scripts/__pycache__/audit_runner.cpython-311.pyc +0 -0
  82. package/skills/torusguard/payload/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  83. package/skills/torusguard/payload/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
  84. package/skills/torusguard/payload/scripts/__pycache__/diff_guard.cpython-314.pyc +0 -0
  85. package/skills/torusguard/payload/scripts/__pycache__/finding_scorer.cpython-311.pyc +0 -0
  86. package/skills/torusguard/payload/scripts/__pycache__/finding_scorer.cpython-314.pyc +0 -0
  87. package/skills/torusguard/payload/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
  88. package/skills/torusguard/payload/scripts/__pycache__/html_reporter.cpython-311.pyc +0 -0
  89. package/skills/torusguard/payload/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  90. package/skills/torusguard/payload/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
  91. package/skills/torusguard/payload/scripts/__pycache__/memory_engine.cpython-311.pyc +0 -0
  92. package/skills/torusguard/payload/scripts/__pycache__/memory_engine.cpython-314.pyc +0 -0
  93. package/skills/torusguard/payload/scripts/__pycache__/monorepo_detector.cpython-311.pyc +0 -0
  94. package/skills/torusguard/payload/scripts/__pycache__/monorepo_detector.cpython-314.pyc +0 -0
  95. package/skills/torusguard/payload/scripts/__pycache__/recheck_runner.cpython-314.pyc +0 -0
  96. package/skills/torusguard/payload/scripts/__pycache__/report_sync.cpython-311.pyc +0 -0
  97. package/skills/torusguard/payload/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  98. package/skills/torusguard/payload/scripts/__pycache__/rules_sync.cpython-311.pyc +0 -0
  99. package/skills/torusguard/payload/scripts/__pycache__/run_manager.cpython-311.pyc +0 -0
  100. package/skills/torusguard/payload/scripts/__pycache__/run_manager.cpython-314.pyc +0 -0
  101. package/skills/torusguard/payload/scripts/__pycache__/sarif_exporter.cpython-314.pyc +0 -0
  102. package/skills/torusguard/payload/scripts/__pycache__/stack_detect.cpython-311.pyc +0 -0
  103. package/skills/torusguard/payload/scripts/__pycache__/stack_detect.cpython-314.pyc +0 -0
  104. package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-311.pyc +0 -0
  105. package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
  106. package/skills/torusguard/payload/scripts/apply_runner.py +11 -5
  107. package/skills/torusguard/payload/scripts/audit_runner.py +222 -15
  108. package/skills/torusguard/payload/scripts/harden_runner.py +3 -3
  109. package/skills/torusguard/payload/scripts/html_reporter.py +2668 -648
  110. package/skills/torusguard/payload/scripts/recheck_runner.py +3 -3
  111. package/skills/torusguard/payload/scripts/recipes_runner.py +3 -3
  112. package/skills/torusguard/payload/scripts/report_sync.py +370 -74
  113. package/skills/torusguard/payload/scripts/sarif_exporter.py +48 -8
  114. package/skills/torusguard/payload/scripts/stack_detect.py +44 -2
  115. package/skills/torusguard/payload/scripts/term_ui.py +1 -1
  116. package/skills/torusguard/payload/skills/torusguard/SKILL.md +1 -1
  117. package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +1 -1
  118. package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +1 -1
  119. package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +1 -1
  120. package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +1 -1
  121. package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +1 -1
  122. package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +1 -1
  123. package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +1 -1
  124. package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +1 -1
  125. package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +40 -23
  126. package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +1 -1
  127. package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +1 -1
  128. package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +1 -1
  129. package/skills/torusguard/payload/workflows/apply.md +1 -1
  130. package/skills/torusguard/payload/workflows/audit.md +1 -1
  131. package/skills/torusguard/payload/workflows/authorize.md +1 -1
  132. package/skills/torusguard/payload/workflows/exploit-check.md +1 -1
  133. package/skills/torusguard/payload/workflows/harden.md +1 -1
  134. package/skills/torusguard/payload/workflows/init.md +1 -1
  135. package/skills/torusguard/payload/workflows/memory.md +1 -1
  136. package/skills/torusguard/payload/workflows/recheck.md +1 -1
  137. package/skills/torusguard/payload/workflows/report.md +1 -1
  138. package/skills/torusguard/payload/workflows/status.md +1 -1
  139. package/skills/torusguard/payload/workflows/verify.md +1 -1
  140. package/skills/torusguard/payload/workflows/web-validate.md +1 -1
  141. package/skills/torusguard-apply/SKILL.md +1 -1
  142. package/skills/torusguard-audit/SKILL.md +1 -1
  143. package/skills/torusguard-authorize/SKILL.md +1 -1
  144. package/skills/torusguard-exploit-check/SKILL.md +1 -1
  145. package/skills/torusguard-full/SKILL.md +1 -1
  146. package/skills/torusguard-harden/SKILL.md +1 -1
  147. package/skills/torusguard-init/SKILL.md +1 -1
  148. package/skills/torusguard-recheck/SKILL.md +1 -1
  149. package/skills/torusguard-report/SKILL.md +40 -23
  150. package/skills/torusguard-status/SKILL.md +1 -1
  151. package/skills/torusguard-verify/SKILL.md +1 -1
  152. package/skills/torusguard-web-validate/SKILL.md +1 -1
@@ -9,6 +9,7 @@ import sys
9
9
  import json
10
10
  import hashlib
11
11
  import argparse
12
+ from pathlib import Path
12
13
  from typing import List, Dict, Any
13
14
 
14
15
  def generate_sarif(findings: List[Dict[str, Any]], run_id: str = "default", category: str = "torusguard/static") -> Dict[str, Any]:
@@ -76,7 +77,7 @@ def generate_sarif(findings: List[Dict[str, Any]], run_id: str = "default", cate
76
77
  "tool": {
77
78
  "driver": {
78
79
  "name": "TorusGuard",
79
- "semanticVersion": "1.3.5",
80
+ "semanticVersion": "1.3.6",
80
81
  "informationUri": "https://github.com/githubmofo/TorusGuard",
81
82
  "rules": list(rules_map.values())
82
83
  }
@@ -95,22 +96,61 @@ def main():
95
96
  parser = argparse.ArgumentParser(description="TorusGuard SARIF v2.1.0 Exporter")
96
97
  parser.add_argument("--input", "-i", help="Path to findings JSON file")
97
98
  parser.add_argument("--output", "-o", help="Output path for sarif.json")
98
- parser.add_argument("--run-id", default="run-default", help="Unique execution Run ID")
99
+ parser.add_argument("--root", "-r", help="Project root override")
100
+ parser.add_argument("--run-id", default=None, help="Unique execution Run ID")
101
+ parser.add_argument("--stdout", action="store_true", help="Print SARIF JSON to stdout")
99
102
  args = parser.parse_args()
100
103
 
104
+ root = Path(args.root).resolve() if args.root else Path.cwd().resolve()
101
105
  findings = []
106
+ run_id = args.run_id or "run-default"
107
+
102
108
  if args.input:
103
- with open(args.input, "r", encoding="utf-8") as f:
104
- findings = json.load(f)
109
+ in_path = Path(args.input)
110
+ if not in_path.is_absolute():
111
+ in_path = (root / in_path).resolve()
112
+ if in_path.is_file():
113
+ with open(in_path, "r", encoding="utf-8") as f:
114
+ findings = json.load(f)
115
+ else:
116
+ # Auto-discover latest audit run findings
117
+ runs_dir = root / ".torusguard" / "runs"
118
+ if runs_dir.is_dir():
119
+ run_folders = sorted(
120
+ [d for d in runs_dir.iterdir() if d.is_dir() and (d / "findings.json").is_file()],
121
+ key=lambda p: p.stat().st_mtime,
122
+ reverse=True
123
+ )
124
+ if run_folders:
125
+ latest_run = run_folders[0]
126
+ run_id = args.run_id or latest_run.name
127
+ findings_file = latest_run / "findings.json"
128
+ try:
129
+ with open(findings_file, "r", encoding="utf-8") as f:
130
+ findings = json.load(f)
131
+ except Exception:
132
+ findings = []
105
133
 
106
- sarif = generate_sarif(findings, run_id=args.run_id)
134
+ sarif = generate_sarif(findings, run_id=run_id)
107
135
 
108
136
  if args.output:
109
- with open(args.output, "w", encoding="utf-8") as f:
137
+ out_path = Path(args.output)
138
+ if not out_path.is_absolute():
139
+ out_path = (root / out_path).resolve()
140
+ out_path.parent.mkdir(parents=True, exist_ok=True)
141
+ with open(out_path, "w", encoding="utf-8") as f:
110
142
  json.dump(sarif, f, indent=2)
111
- print(f"SARIF log written to: {args.output}")
112
- else:
143
+ print(f"[SUCCESS] SARIF log written to: {out_path}")
144
+ elif args.stdout:
113
145
  print(json.dumps(sarif, indent=2))
146
+ else:
147
+ # Default to writing in .torusguard/runs/results-latest.sarif
148
+ default_sarif = root / ".torusguard" / "runs" / "results-latest.sarif"
149
+ default_sarif.parent.mkdir(parents=True, exist_ok=True)
150
+ with open(default_sarif, "w", encoding="utf-8") as f:
151
+ json.dump(sarif, f, indent=2)
152
+ print(f"[SUCCESS] SARIF log written to: {default_sarif}")
153
+
114
154
 
115
155
  if __name__ == "__main__":
116
156
  main()
@@ -221,6 +221,24 @@ def detect_stack(project_root: Path) -> dict[str, Any]:
221
221
  "indicator": "Flask application instantiation"
222
222
  })
223
223
  profile["recommended_references"].append("flask-security.md")
224
+ elif "tornado" in content or "tornado.web" in content:
225
+ add_to_list(profile, "languages_found", "Python")
226
+ profile["ecosystem_family"] = "python"
227
+ add_to_list(profile, "frameworks_found", "Tornado")
228
+ profile["confidence"] = "Confirmed"
229
+ profile["detection_evidence"].append({
230
+ "file": str(py_file.relative_to(project_root)),
231
+ "indicator": "Tornado application"
232
+ })
233
+ elif "starlette" in content:
234
+ add_to_list(profile, "languages_found", "Python")
235
+ profile["ecosystem_family"] = "python"
236
+ add_to_list(profile, "frameworks_found", "Starlette")
237
+ profile["confidence"] = "Confirmed"
238
+ profile["detection_evidence"].append({
239
+ "file": str(py_file.relative_to(project_root)),
240
+ "indicator": "Starlette application"
241
+ })
224
242
 
225
243
  if "sqlalchemy" in content:
226
244
  add_to_list(profile, "data_layers_found", "SQLAlchemy")
@@ -286,11 +304,27 @@ def detect_stack(project_root: Path) -> dict[str, Any]:
286
304
  profile["confidence"] = "Confirmed"
287
305
  profile["detection_evidence"].append({"file": "package.json", "indicator": "express dependency"})
288
306
  profile["recommended_references"].append("express-security.md")
307
+ elif "fastify" in deps:
308
+ add_to_list(profile, "frameworks_found", "Fastify")
309
+ profile["confidence"] = "Confirmed"
310
+ profile["detection_evidence"].append({"file": "package.json", "indicator": "fastify dependency"})
311
+ elif "koa" in deps:
312
+ add_to_list(profile, "frameworks_found", "Koa")
313
+ profile["confidence"] = "Confirmed"
314
+ profile["detection_evidence"].append({"file": "package.json", "indicator": "koa dependency"})
315
+ elif "@remix-run/react" in deps or "@remix-run/node" in deps:
316
+ add_to_list(profile, "frameworks_found", "Remix")
317
+ profile["confidence"] = "Confirmed"
318
+ profile["detection_evidence"].append({"file": "package.json", "indicator": "Remix dependency"})
289
319
  elif "react" in deps:
290
320
  add_to_list(profile, "frameworks_found", "React / Vite")
291
321
  profile["confidence"] = "Confirmed"
292
322
  profile["detection_evidence"].append({"file": "package.json", "indicator": "react dependency"})
293
323
  profile["recommended_references"].append("react-vite-security.md")
324
+ elif "vite" in deps:
325
+ add_to_list(profile, "frameworks_found", "Vite")
326
+ profile["confidence"] = "Confirmed"
327
+ profile["detection_evidence"].append({"file": "package.json", "indicator": "vite dependency"})
294
328
 
295
329
  # ORM / Data layer detection
296
330
  if "@prisma/client" in deps or "prisma" in deps:
@@ -433,6 +467,8 @@ def detect_stack(project_root: Path) -> dict[str, Any]:
433
467
 
434
468
  if "Microsoft.NET.Sdk.Web" in csproj_content or "Microsoft.AspNetCore" in csproj_content or "Swashbuckle" in csproj_content:
435
469
  add_to_list(profile, "frameworks_found", "ASP.NET Core")
470
+ if list(project_root.glob("**/*.razor")) or "Microsoft.AspNetCore.Components" in csproj_content or "blazor" in csproj_content.lower():
471
+ add_to_list(profile, "frameworks_found", "Blazor")
436
472
  if "Microsoft.EntityFrameworkCore" in csproj_content:
437
473
  add_to_list(profile, "data_layers_found", "Entity Framework Core")
438
474
  elif "Dapper" in csproj_content:
@@ -442,11 +478,17 @@ def detect_stack(project_root: Path) -> dict[str, Any]:
442
478
  # G. PHP Ecosystem
443
479
  # -------------------------------------------------------------------------
444
480
  composer_json = project_root / "composer.json"
445
- if composer_json.is_file():
481
+ is_wordpress = (project_root / "wp-config.php").is_file() or (project_root / "wp-load.php").is_file() or (project_root / "wp-content").is_dir()
482
+ if composer_json.is_file() or is_wordpress:
446
483
  add_to_list(profile, "languages_found", "PHP")
447
484
  profile["ecosystem_family"] = "php"
448
485
  profile["confidence"] = "Confirmed"
449
- profile["detection_evidence"].append({"file": "composer.json", "indicator": "PHP Composer manifest"})
486
+ if is_wordpress:
487
+ add_to_list(profile, "frameworks_found", "WordPress")
488
+ add_to_list(profile, "data_layers_found", "MySQL / wpdb")
489
+ profile["detection_evidence"].append({"file": "wp-config.php" if (project_root / "wp-config.php").is_file() else "wp-content", "indicator": "WordPress installation"})
490
+ if composer_json.is_file():
491
+ profile["detection_evidence"].append({"file": "composer.json", "indicator": "PHP Composer manifest"})
450
492
  profile["recommended_rules"].extend(["TG-SEC-*", "TG-INPUT-001", "TG-INPUT-002", "TG-PLATFORM-*"])
451
493
  profile["recommended_references"].append("polyglot-security-matrix.md")
452
494
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- TorusGuard Unified Terminal UI Engine (v1.3.5)
3
+ TorusGuard Unified Terminal UI Engine (v1.3.6)
4
4
  Provides mathematically exact 75-column card formatting, ANSI-stripping,
5
5
  Unicode/emoji visual width calculation, and visual truncation with ellipsis.
6
6
  Pure Python 3.10+ standard library (zero external dependencies).
@@ -1,72 +1,75 @@
1
- ---
2
- name: torusguard
3
- description: Universal autonomous security engine: 71 canonical rules across 11 families, polyglot stack detection across 16+ languages, Ponytail remediation bounds (<=35 add, <=25 del), standardized 75-column terminal UI, SARIF v2.1.0 exports, and persistent security memory context.
4
- version: 1.3.4
5
- ---
6
-
7
- # TorusGuard Master Security Engine & Command Router
8
-
9
- **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.
10
-
11
- ---
12
-
13
- ## Command Catalog: Terminal CLI & AI Chat Parity
14
-
15
- TorusGuard operates with 100% feature parity across both the terminal CLI and AI chat slash commands:
16
-
17
- | Capability | Terminal CLI Command | AI Chat Slash Command | Specialist Skill | Purpose |
18
- | :--- | :--- | :--- | :--- | :--- |
19
- | **Init** | `npx torusguard init` | `/torusguard init` | `skills/torusguard-init` | Stack discovery, rule activation, workspace scaffolding |
20
- | **Status** | `npx torusguard status` | `/torusguard status` | `skills/torusguard-status` | Posture score, active rules, run history, scope check |
21
- | **Audit** | `npx torusguard audit` | `/torusguard audit` | `skills/torusguard-audit` | Static AST scan, invariant fingerprinting, confidence scoring |
22
- | **Verify** | `npx torusguard verify` | `/torusguard verify` | `skills/torusguard-verify` | Evidence sufficiency audit & line match calibration |
23
- | **Harden** | `npx torusguard harden` | `/torusguard harden` | `skills/torusguard-harden` | Ponytail patch formulation ($\le 35$ add, $\le 25$ del) |
24
- | **Apply** | `npx torusguard apply [--yes]` | `/torusguard apply` | `skills/torusguard-apply` | Human Gate review, `.bak` snapshots, patch application |
25
- | **Rollback** | `npx torusguard rollback` | `/torusguard rollback` | `skills/torusguard-apply` | Instant 1-step rollback from pre-apply snapshots |
26
- | **Recheck** | `npx torusguard recheck` | `/torusguard recheck` | `skills/torusguard-recheck` | Targeted differential AST scan, fix closure verification |
27
- | **Recipes** | `npx torusguard recipes` | `/torusguard recipes` | `skills/torusguard-harden` | Explore verified Golden Fix Recipes from persistent memory |
28
- | **Report** | `npx torusguard report --html` | `/torusguard report` | `skills/torusguard-report` | Executive posture reporting, SARIF v2.1.0 & visual HTML |
29
- | **Authorize** | `npx torusguard authorize` | `/torusguard authorize` | `skills/torusguard-authorize`| Legal scope definition & safety boundaries |
30
- | **Validate** | `npx torusguard web-validate` | `/torusguard web-validate` | `skills/torusguard-web-validate`| Authorized non-destructive HTTP probing |
31
- | **Exploit** | `npx torusguard exploit-check` | `/torusguard exploit-check`| `skills/torusguard-exploit-check`| Bounded single-step exploitability confirmation |
32
- | **Full** | `npx torusguard full` | `/torusguard full` | `skills/torusguard-full` | End-to-end 7-stage closed-loop execution |
33
- | **Sync** | `npx torusguard rules sync` | `/torusguard rules sync` | `skills/torusguard-init` | Synchronize rules across AI editors (Cursor, Claude, Antigravity) |
34
-
35
- ---
36
-
37
- ## Non-Negotiable Invariants
38
-
39
- 1. **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.
40
- 2. **Multi-Tenant Isolation:** All database lookups must be scoped by organization or user ownership (`tenant_id`, `organization_id`, `where: { tenantId }`).
41
- 3. **Ponytail Churn Bounds:** Patches must be minimal and surgical ($\le 35$ additions, $\le 25$ deletions). Never perform full-file rewrites.
42
- 4. **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 (`...`).
43
- 5. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`, `[AllowAnonymous]`, or `csrf().disable()`.
44
- 6. **Snapshots Before Edits:** Every code modification must capture a byte-for-byte pre-apply backup in `.torusguard/snapshots/<run_id>/` before touching disk code.
45
-
46
- ---
47
-
48
- ## Workspace Layout Structure
49
- ```
50
- .torusguard/
51
- ├── config/
52
- │ ├── torusguard.json # Detected stack, settings, and rule counts
53
- │ └── scope.json # Authorized runtime validation targets & TTL
54
- ├── memory/
55
- │ ├── context.json # Aggregated security memory context
56
- │ ├── patterns.json # Distilled Golden Fix Recipes
57
- │ └── events.json # Historical audit, apply, and recheck events
58
- ├── rules/
59
- │ └── active/ # Active TG-* rule definitions
60
- ├── runs/
61
- │ └── run-YYYYMMDD-HHMMSS-audit/
62
- │ ├── findings.json # Machine-readable AST findings
63
- │ ├── findings.md # Actionable markdown finding cards
64
- │ ├── remediation.md # Formulated candidate patch catalog
65
- │ ├── diff_summary.md # Summary of applied diffs
66
- │ ├── recheck.md # Differential recheck status transitions
67
- │ ├── report.html # Single-file visual dark-mode HTML report
68
- │ ├── results.sarif # OASIS SARIF v2.1.0 log
69
- │ └── bundles/ # Formulated Ponytail remediation bundles
70
- └── snapshots/
71
- └── run-YYYYMMDD-HHMMSS-audit/ # Pre-apply .bak files for instant rollback
72
- ```
1
+ ---
2
+ name: torusguard
3
+ description: Universal autonomous security engine: 74 canonical rules across 18 families, polyglot stack detection across 16+ languages, Ponytail remediation bounds (<=35 add, <=25 del), standardized 75-column terminal UI, SARIF v2.1.0 exports, and persistent security memory context.
4
+ version: 1.3.6
5
+ ---
6
+
7
+ # TorusGuard Master Security Engine & Command Router
8
+
9
+ **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.
10
+
11
+ ---
12
+
13
+ ## Command Catalog: Terminal CLI & AI Chat Parity
14
+
15
+ TorusGuard operates with 100% feature parity across both the terminal CLI and AI chat slash commands:
16
+
17
+ | Capability | Terminal CLI Command | AI Chat Slash Command | Specialist Skill | Purpose |
18
+ | :--- | :--- | :--- | :--- | :--- |
19
+ | **Init** | `npx torusguard init` | `/torusguard init` | `skills/torusguard-init` | Stack discovery, rule activation, workspace scaffolding |
20
+ | **Status** | `npx torusguard status` | `/torusguard status` | `skills/torusguard-status` | Posture score, active rules, run history, scope check |
21
+ | **Audit** | `npx torusguard audit` | `/torusguard audit` | `skills/torusguard-audit` | Static AST scan, invariant fingerprinting, confidence scoring |
22
+ | **Verify** | `npx torusguard verify` | `/torusguard verify` | `skills/torusguard-verify` | Evidence sufficiency audit & line match calibration |
23
+ | **Harden** | `npx torusguard harden` | `/torusguard harden` | `skills/torusguard-harden` | Ponytail patch formulation ($\le 35$ add, $\le 25$ del) |
24
+ | **Apply** | `npx torusguard apply [--yes]` | `/torusguard apply` | `skills/torusguard-apply` | Human Gate review, `.bak` snapshots, patch application |
25
+ | **Rollback** | `npx torusguard rollback` | `/torusguard rollback` | `skills/torusguard-apply` | Instant 1-step rollback from pre-apply snapshots |
26
+ | **Recheck** | `npx torusguard recheck` | `/torusguard recheck` | `skills/torusguard-recheck` | Targeted differential AST scan, fix closure verification |
27
+ | **Recipes** | `npx torusguard recipes` | `/torusguard recipes` | `skills/torusguard-harden` | Explore verified Golden Fix Recipes from persistent memory |
28
+ | **Report** | `npx torusguard report --html` | `/torusguard report` | `skills/torusguard-report` | Executive posture reporting, SARIF v2.1.0 & visual HTML |
29
+ | **Authorize** | `npx torusguard authorize` | `/torusguard authorize` | `skills/torusguard-authorize`| Legal scope definition & safety boundaries |
30
+ | **Validate** | `npx torusguard web-validate` | `/torusguard web-validate` | `skills/torusguard-web-validate`| Authorized non-destructive HTTP probing |
31
+ | **Exploit** | `npx torusguard exploit-check` | `/torusguard exploit-check`| `skills/torusguard-exploit-check`| Bounded single-step exploitability confirmation |
32
+ | **Full** | `npx torusguard full` | `/torusguard full` | `skills/torusguard-full` | End-to-end 7-stage closed-loop execution |
33
+ | **Sync** | `npx torusguard rules sync` | `/torusguard rules sync` | `skills/torusguard-init` | Synchronize rules across AI editors (Cursor, Claude, Antigravity) |
34
+
35
+ ---
36
+
37
+ ## Non-Negotiable Invariants
38
+
39
+ 1. **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.
40
+ 2. **Multi-Tenant Isolation:** All database lookups must be scoped by organization or user ownership (`tenant_id`, `organization_id`, `where: { tenantId }`).
41
+ 3. **Ponytail Churn Bounds:** Patches must be minimal and surgical ($\le 35$ additions, $\le 25$ deletions). Never perform full-file rewrites.
42
+ 4. **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 (`...`).
43
+ 5. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`, `[AllowAnonymous]`, or `csrf().disable()`.
44
+ 6. **Snapshots Before Edits:** Every code modification must capture a byte-for-byte pre-apply backup in `.torusguard/snapshots/<run_id>/` before touching disk code.
45
+
46
+ ---
47
+
48
+ ## Workspace Layout Structure
49
+ ```
50
+ .torusguard/
51
+ ├── config/
52
+ │ ├── torusguard.json # Detected stack, settings, and rule counts
53
+ │ └── scope.json # Authorized runtime validation targets & TTL
54
+ ├── memory/
55
+ │ ├── context.json # Aggregated security memory context
56
+ │ ├── patterns.json # Distilled Golden Fix Recipes
57
+ │ └── events.json # Historical audit, apply, and recheck events
58
+ ├── rules/
59
+ │ └── active/ # Active TG-* rule definitions
60
+ ├── runs/
61
+ │ └── run-YYYYMMDD-HHMMSS-audit/
62
+ │ ├── findings.json # Machine-readable AST findings
63
+ │ ├── findings.md # Actionable markdown finding cards
64
+ │ ├── remediation.md # Formulated candidate patch catalog
65
+ │ ├── diff_summary.md # Summary of applied diffs
66
+ │ ├── recheck.md # Differential recheck status transitions
67
+ │ ├── report.html # Single-file visual dark-mode HTML report
68
+ │ ├── results.sarif # OASIS SARIF v2.1.0 log
69
+ │ └── bundles/ # Formulated Ponytail remediation bundles
70
+ └── snapshots/
71
+ └── run-YYYYMMDD-HHMMSS-audit/ # Pre-apply .bak files for instant rollback
72
+ ```
73
+
74
+ ## Living Report Ground Truth
75
+ - Read `security_report.md` in the workspace root before taking any action. Update the relevant finding card after completing remediation.
@@ -1,80 +1,84 @@
1
- ---
2
- name: torusguard-apply
3
- description: Apply governed remediation patches to disk with pre-apply rollback snapshots and Human Gate validation via CLI or AI Agent.
4
- version: 1.3.4
5
- workflow: .torusguard/workflows/apply.md
6
- tools: Read, Grep, Glob, Write, replace_file_content, run_command
7
- scripts-binding:
8
- - .torusguard/scripts/apply_runner.py
9
- - .torusguard/scripts/term_ui.py
10
- - .torusguard/scripts/memory_engine.py
11
- ---
12
-
13
- # TorusGuard Apply — Governed Patch Application & Rollback Snapshot
14
-
15
- ## Objective
16
- Safely apply approved remediation bundles to disk source files, creating an automated byte-for-byte pre-apply backup snapshot (`.bak`) in `.torusguard/snapshots/<run_id>/`, asserting syntax validity, and distilling passing patterns into Golden Fix Recipes.
17
-
18
- ---
19
-
20
- ## Two Execution Modes
21
-
22
- ### Mode A: Automated CLI Execution (Interactive or Non-Interactive)
23
- Run the governed patch applier from your terminal:
24
- ```bash
25
- # Interactive Human Gate review (prompts for each patch: [y]es / [n]o / [a]ll / [q]uit)
26
- npx torusguard apply
27
-
28
- # Non-interactive automated application
29
- npx torusguard apply --yes
30
-
31
- # Apply patches from a specific run ID
32
- npx torusguard apply --run run-20260910-121618-audit --yes
33
-
34
- # Emergency rollback from pre-apply snapshot
35
- npx torusguard rollback
36
- # or
37
- npx torusguard apply --rollback
38
- ```
39
- **Under the Hood:** Executes `python .torusguard/scripts/apply_runner.py`.
40
- 1. Reads candidate bundles from `.torusguard/runs/<run_id>/bundles/`.
41
- 2. Creates `.bak` snapshot in `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
42
- 3. Performs line-aware replacement without corrupting concurrent modifications.
43
- 4. Distills the applied fix into a **Golden Fix Recipe** registered in `.torusguard/memory/patterns.json`.
44
- 5. Emits `diff_summary.md` and `apply_plan.md` in the run directory.
45
- 6. Displays pixel-perfect 75-column terminal cards.
46
-
47
- ### Mode B: In-Session AI Chat Agent Application
48
- When applying patches directly within an AI chat session:
49
- 1. **Human Gate Confirmation:** Present the unified diff to the operator and request explicit approval before editing code.
50
- 2. **Pre-Apply Snapshot:** Ensure target file backup is created at `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
51
- 3. **Execute Surgical Edit:** Use `replace_file_content` to apply only the approved lines. Strictly adhere to the formulated Ponytail diff.
52
- 4. **Syntax & Integrity Check:** Verify that the patched file is syntactically valid (e.g. `node --check <file>` or `python -m py_compile <file>`). If syntax fails, immediately restore from `.bak`.
53
- 5. **Memory Registration:** Update persistent memory events in `.torusguard/memory/events.json` with event `fix_applied`.
54
- 6. **Recommend Recheck:** Advise running `/torusguard recheck` or `npx torusguard recheck` to verify closure.
55
-
56
- ---
57
-
58
- ## Rollback Guarantee
59
- If an applied patch introduces unexpected runtime behavior or breaks tests:
60
- ```bash
61
- # Instant one-command rollback of the latest applied run:
62
- npx torusguard rollback
63
-
64
- # Or rollback a specific run:
65
- npx torusguard rollback --run run-20260910-121618-audit
66
- ```
67
- All affected files are restored byte-for-byte from `.torusguard/snapshots/<run_id>/`.
68
-
69
- ---
70
-
71
- ## Output Card Format
72
- ```markdown
73
- ### 🚀 TorusGuard Patch Applied Successfully
74
- - **Target File:** `server/index.js:9`
75
- - **Rule ID:** `TG-SEC-001` (Hardcoded JWT secret)
76
- - **Ponytail Churn:** +1 / -1
77
- - **Rollback Snapshot:** `.torusguard/snapshots/<run_id>/server/index.js.bak`
78
- - **Golden Recipe:** Distilled into persistent memory
79
- - **Next Step:** Run `npx torusguard recheck` or `/torusguard recheck` to verify closure
80
- ```
1
+ ---
2
+ name: torusguard-apply
3
+ description: Apply governed remediation patches to disk with pre-apply rollback snapshots and Human Gate validation via CLI or AI Agent.
4
+ version: 1.3.6
5
+ workflow: .torusguard/workflows/apply.md
6
+ tools: Read, Grep, Glob, Write, replace_file_content, run_command
7
+ scripts-binding:
8
+ - .torusguard/scripts/report_sync.py
9
+ - .torusguard/scripts/apply_runner.py
10
+ - .torusguard/scripts/term_ui.py
11
+ - .torusguard/scripts/memory_engine.py
12
+ ---
13
+
14
+ # TorusGuard Apply — Governed Patch Application & Rollback Snapshot
15
+
16
+ ## Objective
17
+ Safely apply approved remediation bundles to disk source files, creating an automated byte-for-byte pre-apply backup snapshot (`.bak`) in `.torusguard/snapshots/<run_id>/`, asserting syntax validity, and distilling passing patterns into Golden Fix Recipes.
18
+
19
+ ---
20
+
21
+ ## Two Execution Modes
22
+
23
+ ### Mode A: Automated CLI Execution (Interactive or Non-Interactive)
24
+ Run the governed patch applier from your terminal:
25
+ ```bash
26
+ # Interactive Human Gate review (prompts for each patch: [y]es / [n]o / [a]ll / [q]uit)
27
+ npx torusguard apply
28
+
29
+ # Non-interactive automated application
30
+ npx torusguard apply --yes
31
+
32
+ # Apply patches from a specific run ID
33
+ npx torusguard apply --run run-20260910-121618-audit --yes
34
+
35
+ # Emergency rollback from pre-apply snapshot
36
+ npx torusguard rollback
37
+ # or
38
+ npx torusguard apply --rollback
39
+ ```
40
+ **Under the Hood:** Executes `python .torusguard/scripts/apply_runner.py`.
41
+ 1. Reads candidate bundles from `.torusguard/runs/<run_id>/bundles/`.
42
+ 2. Creates `.bak` snapshot in `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
43
+ 3. Performs line-aware replacement without corrupting concurrent modifications.
44
+ 4. Distills the applied fix into a **Golden Fix Recipe** registered in `.torusguard/memory/patterns.json`.
45
+ 5. Emits `diff_summary.md` and `apply_plan.md` in the run directory.
46
+ 6. Displays pixel-perfect 75-column terminal cards.
47
+
48
+ ### Mode B: In-Session AI Chat Agent Application
49
+ When applying patches directly within an AI chat session:
50
+ 1. **Human Gate Confirmation:** Present the unified diff to the operator and request explicit approval before editing code.
51
+ 2. **Pre-Apply Snapshot:** Ensure target file backup is created at `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
52
+ 3. **Execute Surgical Edit:** Use `replace_file_content` to apply only the approved lines. Strictly adhere to the formulated Ponytail diff.
53
+ 4. **Syntax & Integrity Check:** Verify that the patched file is syntactically valid (e.g. `node --check <file>` or `python -m py_compile <file>`). If syntax fails, immediately restore from `.bak`.
54
+ 5. **Memory Registration:** Update persistent memory events in `.torusguard/memory/events.json` with event `fix_applied`.
55
+ 6. **Recommend Recheck:** Advise running `/torusguard recheck` or `npx torusguard recheck` to verify closure.
56
+
57
+ ---
58
+
59
+ ## Rollback Guarantee
60
+ If an applied patch introduces unexpected runtime behavior or breaks tests:
61
+ ```bash
62
+ # Instant one-command rollback of the latest applied run:
63
+ npx torusguard rollback
64
+
65
+ # Or rollback a specific run:
66
+ npx torusguard rollback --run run-20260910-121618-audit
67
+ ```
68
+ All affected files are restored byte-for-byte from `.torusguard/snapshots/<run_id>/`.
69
+
70
+ ---
71
+
72
+ ## Output Card Format
73
+ ```markdown
74
+ ### 🚀 TorusGuard Patch Applied Successfully
75
+ - **Target File:** `server/index.js:9`
76
+ - **Rule ID:** `TG-SEC-001` (Hardcoded JWT secret)
77
+ - **Ponytail Churn:** +1 / -1
78
+ - **Rollback Snapshot:** `.torusguard/snapshots/<run_id>/server/index.js.bak`
79
+ - **Golden Recipe:** Distilled into persistent memory
80
+ - **Next Step:** Run `npx torusguard recheck` or `/torusguard recheck` to verify closure
81
+ ```
82
+
83
+ ## Living Report Ground Truth
84
+ - Read `security_report.md` in the workspace root before taking any action. Update the relevant finding card after completing remediation.