torusguard 0.9.4 → 1.0.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 (44) hide show
  1. package/.torusguard/.manifest.json +15 -10
  2. package/.torusguard/config/torusguard.json +1 -1
  3. package/.torusguard/schemas/memory-context.schema.json +95 -0
  4. package/.torusguard/schemas/memory-event.schema.json +70 -0
  5. package/.torusguard/schemas/memory-pattern.schema.json +65 -0
  6. package/.torusguard/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
  7. package/.torusguard/scripts/__pycache__/finding_scorer.cpython-311.pyc +0 -0
  8. package/.torusguard/scripts/__pycache__/memory_engine.cpython-311.pyc +0 -0
  9. package/.torusguard/scripts/diff_guard.py +71 -11
  10. package/.torusguard/scripts/finding_scorer.py +171 -86
  11. package/.torusguard/scripts/manifest_builder.py +2 -0
  12. package/.torusguard/scripts/memory_engine.py +912 -0
  13. package/.torusguard/scripts/run_manager.py +171 -89
  14. package/.torusguard/skills/torusguard/SKILL.md +12 -7
  15. package/.torusguard/skills/torusguard/bootstrap.py +344 -56
  16. package/.torusguard/skills/torusguard-audit/SKILL.md +25 -25
  17. package/.torusguard/skills/torusguard-harden/SKILL.md +3 -3
  18. package/.torusguard/skills/torusguard-recheck/SKILL.md +3 -3
  19. package/.torusguard/workflows/memory.md +53 -0
  20. package/README.md +12 -2
  21. package/bin/torusguard.js +173 -43
  22. package/package.json +1 -1
  23. package/skills/torusguard/SKILL.md +4 -3
  24. package/skills/torusguard/__pycache__/bootstrap.cpython-311.pyc +0 -0
  25. package/skills/torusguard/bootstrap.py +244 -80
  26. package/skills/torusguard/payload/.manifest.json +15 -10
  27. package/skills/torusguard/payload/config/torusguard.json +1 -1
  28. package/skills/torusguard/payload/schemas/memory-context.schema.json +95 -0
  29. package/skills/torusguard/payload/schemas/memory-event.schema.json +70 -0
  30. package/skills/torusguard/payload/schemas/memory-pattern.schema.json +65 -0
  31. package/skills/torusguard/payload/scripts/diff_guard.py +71 -11
  32. package/skills/torusguard/payload/scripts/finding_scorer.py +171 -86
  33. package/skills/torusguard/payload/scripts/manifest_builder.py +2 -0
  34. package/skills/torusguard/payload/scripts/memory_engine.py +912 -0
  35. package/skills/torusguard/payload/scripts/run_manager.py +171 -89
  36. package/skills/torusguard/payload/skills/torusguard/SKILL.md +12 -7
  37. package/skills/torusguard/payload/skills/torusguard/bootstrap.py +344 -56
  38. package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +25 -25
  39. package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +3 -3
  40. package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +3 -3
  41. package/skills/torusguard/payload/workflows/memory.md +53 -0
  42. package/skills/torusguard-audit/SKILL.md +25 -25
  43. package/skills/torusguard-harden/SKILL.md +3 -3
  44. package/skills/torusguard-recheck/SKILL.md +3 -3
@@ -0,0 +1,53 @@
1
+ ---
2
+ description: TorusGuard Adaptive Security Memory Engine — view memory stats, export/import intelligence, apply TTL decay, and manage false positives.
3
+ tools: Read, Grep, Glob, Bash
4
+ version: 1.0.0
5
+ agent: reviewer
6
+ lifecycle-phase: Intelligence / Memory
7
+ required-skills:
8
+ - torusguard
9
+ scripts-binding:
10
+ - .torusguard/scripts/memory_engine.py
11
+ ---
12
+
13
+ # /torusguard memory — Adaptive Security Memory Engine & Intelligence Management
14
+
15
+ $ARGUMENTS
16
+
17
+ ---
18
+
19
+ ## Objective
20
+ Inspect, manage, export, import, or compact persistent local security memory patterns, context window cards, and false positive suppressions.
21
+
22
+ ---
23
+
24
+ ## Subcommands & Usage
25
+
26
+ | Command | Action | Description |
27
+ | :--- | :--- | :--- |
28
+ | `npx torusguard memory` | Status | Display memory stats, pattern count, and context token estimate |
29
+ | `npx torusguard memory context` | Context Dump | Output the active pre-computed context window cards |
30
+ | `npx torusguard memory fp --rule <RULE_ID>` | False Positive | Suppress rule as false positive across future scans |
31
+ | `npx torusguard memory decay [--ttl 90]` | TTL Decay | Apply confidence decay to stale, unconfirmed patterns |
32
+ | `npx torusguard memory export --path <FILE>` | Export | Export memory bundle for team sharing |
33
+ | `npx torusguard memory import --path <FILE>` | Import | Merge external memory bundle into local project intelligence |
34
+ | `npx torusguard memory compact` | Compaction | Archive raw events older than 30 days into single archive |
35
+
36
+ ---
37
+
38
+ ## Execution Steps
39
+
40
+ 1. **Verify Memory Subsystem:** Confirm `.torusguard/memory/` exists and is shielded by `.gitignore`.
41
+ 2. **Execute Requested Action:** Invoke `.torusguard/scripts/memory_engine.py` with appropriate action flag:
42
+ ```bash
43
+ python .torusguard/scripts/memory_engine.py --action status
44
+ ```
45
+ 3. **Verify Context Token Budget:** Confirm `context.json` remains within token budget ($\le 2,000$ tokens).
46
+ 4. **Display Intelligence Card:** Render summary card to user.
47
+
48
+ ---
49
+
50
+ ## Privacy & Security Invariants
51
+ - Memory files remain strictly local under `.torusguard/memory/` and are always gitignored.
52
+ - Memory files are never packaged into npm release tarballs.
53
+ - Export operations only occur when explicitly invoked by user command.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: torusguard-audit
3
- description: Static security AST scanning, stable fingerprinting, root-cause clustering, and 0–100 confidence scoring.
4
- version: 0.9.2
3
+ description: Static AST scanning, memory pattern boosting, and 0–100 confidence scoring.
4
+ version: 1.0.0
5
5
  workflow: .torusguard/workflows/audit.md
6
6
  tools: Read, Grep, Glob, Write
7
7
  scripts-binding:
@@ -9,36 +9,37 @@ scripts-binding:
9
9
  - .torusguard/scripts/run_manager.py
10
10
  ---
11
11
 
12
- # TorusGuard Audit — Static Code Analysis & Finding Clustering
12
+ # TorusGuard Audit — Static Code Analysis & Memory Scanning
13
13
 
14
14
  ## Objective
15
- Execute static analysis across ASTs, generate line-shift invariant fingerprints, group findings into root causes, compute 0–100 confidence scores, and persist findings to `.torusguard/runs/`.
15
+ Execute static AST analysis, query memory context, compute 0–100 confidence scores with memory boosts, and record findings to runs and memory.
16
16
 
17
17
  ---
18
18
 
19
19
  ## Execution Steps
20
20
 
21
- 1. **Setup Run Directory:** Initialize `.torusguard/runs/run-YYYYMMDD-HHMMSS-audit/` via `run_manager.py`.
22
- 2. **Load Active Rules:** Load rules from `.torusguard/rules/active/` and thresholds from `torusguard.json`.
21
+ 1. **Run Setup:** Initialize `.torusguard/runs/run-YYYYMMDD-HHMMSS-audit/` via `run_manager.py`.
22
+ 2. **Context & Rules:** Load `.torusguard/memory/context.json` for patterns and false positives. Load rules from `.torusguard/rules/active/`.
23
23
  3. **AST Scan Sinks:** Match files against active rules:
24
- - `TG-SEC-*`: Leaked API keys, secrets.
25
- - `TG-INPUT-*`: Unescaped SQL or unvalidated payloads.
26
- - `TG-DB-*`: Unscoped queries omitting tenant filters (`Model.get(id=id)`).
27
- - `TG-AUTH-*`: Missing `HttpOnly`/`Secure` flags; open CORS.
28
- - `TG-CLIENT-*`: Admin credentials in client bundles.
29
- 4. **Stable Fingerprinting:** Compute SHA-256 hash of normalized 3 surrounding AST lines.
30
- 5. **Root-Cause Clustering:** Group findings by root cause (`cluster-tenant-isolation`, `cluster-raw-sql-sink`).
31
- 6. **Confidence Scoring:** Calculate 0–100 score across 5-factor rubric via `finding_scorer.py`.
32
- 7. **Write Run Artifacts:** Persist `findings.md`, `findings.json`, and `summary.md`.
24
+ - `TG-SEC-*`: Secrets and API keys.
25
+ - `TG-INPUT-*`: SQL injection, unvalidated input.
26
+ - `TG-DB-*`: Unscoped tenant queries (`Model.get(id=id)`).
27
+ - `TG-AUTH-*`: Insecure cookies, open CORS.
28
+ - `TG-CLIENT-*`: Client bundle secret leaks.
29
+ 4. **Stable Fingerprinting:** Compute SHA-256 hash of surrounding AST context.
30
+ 5. **Root-Cause Clustering:** Group findings by causal sink (`cluster-tenant-isolation`).
31
+ 6. **Scoring:** Calculate 0–100 score via `finding_scorer.py` (applies memory boost/suppression).
32
+ 7. **Write Artifacts:** Save `findings.json` and sync findings to memory engine.
33
33
 
34
34
  ---
35
35
 
36
36
  ## Confidence Scoring Rubric
37
- - **1. Evidence (35):** AST flow (35), regex match (20), indirect (10).
38
- - **2. Reproduction (25):** Deterministic test (25), simulated (15), hypothesis (0).
37
+ - **1. Evidence (35):** AST flow (35), regex sink (20), heuristic (10).
38
+ - **2. Reproduction (25):** Automated test (25), simulated (15), hypothesis (0).
39
39
  - **3. Corroboration (15):** >=3 files (15), 2 files (10), single (5).
40
- - **4. Environment (15):** Explicit route (15), minor ambiguity (8), unknown (0).
41
- - **5. Review Status (10):** Human verified (10), agent consensus (5), auto (0).
40
+ - **4. Environment (15):** Explicit route (15), ambiguous (8), unknown (0).
41
+ - **5. Review Status (10):** Human confirmed (10), agent verified (5), auto (0).
42
+ - **Memory Modifier:** False positive (-30), regression (+15), recurring (+10).
42
43
  - **Bands:** 90–100 (`Confirmed`), 70–89 (`High`), 50–69 (`Medium`), <50 (`Review`).
43
44
 
44
45
  ---
@@ -46,17 +47,16 @@ Execute static analysis across ASTs, generate line-shift invariant fingerprints,
46
47
  ## Finding Card Format
47
48
  ```markdown
48
49
  ### [TG-DB-004] Missing Tenant Scoping in /invoices/
49
- - **Severity**: High | **Confidence**: 90/100 (Confirmed)
50
+ - **Severity**: High | **Confidence**: 90/100 (Confirmed) | **Memory Boost**: +10
50
51
  - **File**: `views.py:42` | **Cluster**: `cluster-tenant-isolation`
51
- - **Evidence**: Unscoped query leaks records.
52
- - **Remediation**: Scope by `tenant=request.user.tenant`.
52
+ - **Remediation**: Apply `.filter(tenant=request.user.tenant)`.
53
53
  ```
54
54
 
55
55
  ---
56
56
 
57
57
  ## Safety Constraints
58
- - Read-only execution; zero code modifications.
59
- - Exclude build folders (`node_modules/`, `.venv/`, `dist/`).
58
+ - Read-only analysis; zero code modifications during audit.
59
+ - Exclude build directories (`node_modules/`, `.venv/`, `dist/`).
60
60
  - Redact secrets before saving to `findings.md`.
61
61
 
62
62
  ---
@@ -65,6 +65,6 @@ Execute static analysis across ASTs, generate line-shift invariant fingerprints,
65
65
  ```markdown
66
66
  🛡️ [TorusGuard] Static Code Audit Completed
67
67
  - Run ID: run-YYYYMMDD-HHMMSS-audit | Files: <Count> | Findings: <Count>
68
- - Clusters: <Count> identified | Posture: ACTION REQUIRED
68
+ - Clusters: <Count> identified | Memory Patterns Applied: <Count>
69
69
  Next: Run `/torusguard harden` to formulate surgical fixes.
70
70
  ```
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: torusguard-harden
3
3
  description: Package surgical remediation bundles conforming to the Ponytail Protocol (<= 35 additions, <= 25 deletions).
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  workflow: .torusguard/workflows/harden.md
6
6
  tools: Read, Grep, Glob, Write
7
7
  scripts-binding:
@@ -38,8 +38,8 @@ Formulate minimal, surgical code fixes bound by the Ponytail Protocol ($\le 35$
38
38
 
39
39
  1. **Select Finding:** Choose prioritized verified flaw from active run's `findings.md`.
40
40
  2. **Read AST Context:** View target file surrounding lines (±15) using `view_file`.
41
- 3. **Formulate Minimal Fix:** Parameterize SQL, add tenant filters, insert validation schemas.
42
- 4. **Validate Line Churn:** Assert additions $\le 35$ and deletions $\le 25$.
41
+ 3. **Formulate Minimal Fix:** Consult `.torusguard/memory/context.json` for verified idioms; parameterize SQL, add tenant filters.
42
+ 4. **Validate Line Churn:** Assert additions $\le 35$ and deletions $\le 25$ via `diff_guard.py`.
43
43
  5. **Package Bundle:** Write 4 artifacts (`patch.diff`, `plan.md`, `verification.md`, `rollback.md`).
44
44
  6. **Flag Sensitive Paths:** Mark changes touching auth or billing with `Requires Sensitive-Path Sign-Off`.
45
45
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: torusguard-recheck
3
3
  description: Execute targeted differential AST re-scan against modified files, verify fix closure, and assert zero regressions.
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  workflow: .torusguard/workflows/recheck.md
6
6
  tools: Read, Grep, Glob, Write
7
7
  scripts-binding:
@@ -19,10 +19,10 @@ Re-scan only files modified by remediation patches, confirming that targeted vul
19
19
  ## Execution Steps
20
20
 
21
21
  1. **Identify Modified Files:** Read `apply-log.json` from active run directory.
22
- 2. **Execute Differential Scan:** Re-run active `TG-*` rules exclusively against the modified files.
22
+ 2. **Execute Differential Scan:** Re-run active `TG-*` rules exclusively against modified files.
23
23
  3. **Evaluate Finding Status:** Transition finding state according to transition rules below.
24
24
  4. **Assert Regression-Free:** Ensure no new security warnings triggered on altered lines.
25
- 5. **Update State:** Record verified status in `findings.json`.
25
+ 5. **Update State & Memory:** Record status in `findings.json` and sync verified results to memory engine.
26
26
  6. **Emit Recheck Report:** Save summary in `.torusguard/runs/<run_id>/recheck-report.md`.
27
27
 
28
28
  ---