torusguard 0.9.5 → 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 (46) 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 +4 -3
  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 +11 -2
  21. package/bin/torusguard.js +99 -5
  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 +66 -2
  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 +4 -3
  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
  45. package/skills/torusguard/payload/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
  46. package/skills/torusguard/payload/scripts/__pycache__/monorepo_detector.cpython-311.pyc +0 -0
@@ -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.
package/README.md CHANGED
@@ -6,8 +6,8 @@
6
6
  **Autonomous Security Guardrails, Governed Remediation, and Authorized Runtime Validation for AI-Built Web Applications.**
7
7
 
8
8
  [![npm version](https://img.shields.io/npm/v/torusguard.svg?style=flat-square&color=cb3837&logo=npm)](https://www.npmjs.com/package/torusguard)
9
- [![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-v0.9.5-181717.svg?style=flat-square&logo=github)](https://github.com/githubmofo/TorusGuard/pkgs/npm/torusguard)
10
- [![Release](https://img.shields.io/badge/Release-v0.9.5-blue.svg?style=flat-square)](https://github.com/githubmofo/TorusGuard/releases/latest)
9
+ [![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-v1.0.0-181717.svg?style=flat-square&logo=github)](https://github.com/githubmofo/TorusGuard/pkgs/npm/torusguard)
10
+ [![Release](https://img.shields.io/badge/Release-v1.0.0-blue.svg?style=flat-square)](https://github.com/githubmofo/TorusGuard/releases/latest)
11
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)](LICENSE)
12
12
  [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg?style=flat-square&logo=python&logoColor=white)](https://python.org)
13
13
  [![Node.js 18+](https://img.shields.io/badge/Node.js-18%2B-339933.svg?style=flat-square&logo=node.js&logoColor=white)](https://nodejs.org)
@@ -143,6 +143,7 @@ When Track 2 is initialized, the complete 11-command palette becomes available i
143
143
  | `/torusguard recheck`<br>*(or `/torusguard-recheck`)* | `skills/torusguard-recheck` | Phase 6 | Executes differential re-audit strictly on modified files to verify fix closure. | No |
144
144
  | `/torusguard report`<br>*(or `/torusguard-report`)* | `skills/torusguard-report` | Phase 7 | Emits executive summary markdown and OASIS SARIF v2.1.0 CI artifacts. | No |
145
145
  | `/torusguard status`<br>*(or `/torusguard-status`)* | `skills/torusguard-status` | Diagnostic | Inspects active security posture, thresholds, and recent run history. | No |
146
+ | `/torusguard memory` | `skills/torusguard` | Intelligence | Inspects, exports, imports, or compacts persistent security memory context. | Yes (`.torusguard/memory/`) |
146
147
  | `/torusguard full` | `skills/torusguard-full` | End-to-End | Orchestrates the entire 7-stage security cycle in one coordinated sequence. | **Yes (Governed)** |
147
148
 
148
149
  ---
@@ -259,6 +260,14 @@ $$\text{Score} = (w_d \cdot D) + (w_e \cdot E) + (w_c \cdot C_{ast}) - P_{fp} -
259
260
  ### 3. Stable Line-Shift Invariant Fingerprinting (`primaryLocationLineHash`)
260
261
  Traditional static tools break finding identity when a developer inserts 2 lines at the top of a file. TorusGuard computes a stable SHA-256 hash across the AST node content, enclosing function scope, and syntactic tokens. Findings maintain permanent tracking identity across Git commits and branch renames.
261
262
 
263
+ ### 4. Adaptive Security Memory Engine (`.torusguard/memory/`)
264
+ Traditional scanners are stateless — they scan, report, and forget. TorusGuard v1.0.0 introduces persistent, local-first intelligence that learns from every audit, fix, and verification:
265
+ * **4-Tier Intelligence Architecture:** Raw event append-log (`events/`) ──► Distilled pattern store (`patterns.json`) ──► Pre-computed context window (`context.json`) ──► Project security profile (`profile.json`).
266
+ * **Structured JSON Cards:** Pre-computes context cards within a strict $\le 2,000$ token budget for instant, hallucination-free injection into AI coding agent prompts.
267
+ * **Confidence Amplification & TTL Decay:** Multi-file fix verifications boost pattern confidence up to 98%, while unconfirmed patterns decay gracefully over 90 days.
268
+ * **Zero-Leakage Guarantee:** Memory is strictly gitignored (`*`), excluded from npm distribution tarballs, and stored only in the user's project.
269
+ * **CLI Memory Management:** Inspect, export, import, or compact memory via `npx torusguard memory`.
270
+
262
271
  ---
263
272
 
264
273
  ## 🛡️ Rule Catalog & Detection Families (71 Canonical Rules)
package/bin/torusguard.js CHANGED
@@ -49,7 +49,7 @@ function printHelp() {
49
49
  console.log(`
50
50
  ${CYAN}╭─────────────────────────────────────────────────────────────────────────╮${RESET}
51
51
  ${CYAN}│${RESET} ${CYAN}│${RESET}
52
- ${CYAN}│${RESET} ${BOLD}${WHITE}🛡️ T O R U S G U A R D C L I${RESET} ${GRAY}v0.9.5${RESET} ${CYAN}│${RESET}
52
+ ${CYAN}│${RESET} ${BOLD}${WHITE}🛡️ T O R U S G U A R D C L I${RESET} ${GRAY}v1.0.0${RESET} ${CYAN}│${RESET}
53
53
  ${CYAN}│${RESET} ${DIM}Autonomous Security Engine for AI-Built Applications${RESET} ${CYAN}│${RESET}
54
54
  ${CYAN}│${RESET} ${CYAN}│${RESET}
55
55
  ${CYAN}╰─────────────────────────────────────────────────────────────────────────╯${RESET}
@@ -59,8 +59,9 @@ function printHelp() {
59
59
  ${CYAN}┌─────────────────────────────────────────────────────────────────────────┐${RESET}
60
60
  ${CYAN}│${RESET} ${BOLD}Commands${RESET} ${CYAN}│${RESET}
61
61
  ${CYAN}├─────────────────────────────────────────────────────────────────────────┤${RESET}
62
- ${CYAN}│${RESET} ${GREEN}init${RESET} Scaffold ${BOLD}.torusguard/${RESET} workspace + unlock 11 slash commands ${CYAN}│${RESET}
63
- ${CYAN}│${RESET} ${GREEN}status${RESET} Display active security posture, rules, and stack info ${CYAN}│${RESET}
62
+ ${CYAN}│${RESET} ${GREEN}init${RESET} Scaffold ${BOLD}.torusguard/${RESET} workspace + unlock 12 slash commands ${CYAN}│${RESET}
63
+ ${CYAN}│${RESET} ${GREEN}status${RESET} Display active security posture, memory, rules, and stack ${CYAN}│${RESET}
64
+ ${CYAN}│${RESET} ${GREEN}memory${RESET} Manage persistent security memory (export, import, decay) ${CYAN}│${RESET}
64
65
  ${CYAN}│${RESET} ${GREEN}audit${RESET} Run static AST security scan on the target project ${CYAN}│${RESET}
65
66
  ${CYAN}│${RESET} ${GREEN}report${RESET} Export OASIS SARIF v2.1.0 structured telemetry ${CYAN}│${RESET}
66
67
  ${CYAN}│${RESET} ${GREEN}help${RESET} Show this interactive command guide ${CYAN}│${RESET}
@@ -73,7 +74,7 @@ function printHelp() {
73
74
 
74
75
  ${BOLD}AI Chat Commands:${RESET}
75
76
  ${DIM}In your AI IDE chat, use any of these slash commands:${RESET}
76
- ${CYAN}/torusguard${RESET} Main orchestrator (status, audit, harden, etc.)
77
+ ${CYAN}/torusguard${RESET} Main orchestrator (status, audit, harden, memory)
77
78
  ${CYAN}/torusguard-audit${RESET} Static AST security scan
78
79
  ${CYAN}/torusguard-harden${RESET} Generate governed fix patches
79
80
  ${CYAN}/torusguard-apply${RESET} Apply patches with rollback snapshots
@@ -100,10 +101,32 @@ if (command === 'status') {
100
101
  const stackDb = cfg.detected_stack?.data_layer || 'Not yet detected';
101
102
  const stackStatus = cfg.detected_stack ? `${GREEN}Detected${RESET}` : `${YELLOW}Pending first audit${RESET}`;
102
103
 
104
+ // Memory telemetry
105
+ const memProfilePath = path.join(cwd, '.torusguard', 'memory', 'profile.json');
106
+ const memContextPath = path.join(cwd, '.torusguard', 'memory', 'context.json');
107
+ let memPatterns = 0;
108
+ let memEvents = 0;
109
+ let memTokens = 0;
110
+ let memFixRate = 'N/A';
111
+ if (fs.existsSync(memProfilePath)) {
112
+ try {
113
+ const prof = JSON.parse(fs.readFileSync(memProfilePath, 'utf-8'));
114
+ memPatterns = prof.active_patterns_count || 0;
115
+ memEvents = prof.total_events || 0;
116
+ memFixRate = prof.fix_rate_percentage !== null && prof.fix_rate_percentage !== undefined ? `${prof.fix_rate_percentage}%` : 'N/A';
117
+ } catch (e) {}
118
+ }
119
+ if (fs.existsSync(memContextPath)) {
120
+ try {
121
+ const ctx = JSON.parse(fs.readFileSync(memContextPath, 'utf-8'));
122
+ memTokens = ctx.token_estimate || 0;
123
+ } catch (e) {}
124
+ }
125
+
103
126
  console.log(`
104
127
  ${CYAN}╭─────────────────────────────────────────────────────────────────────────╮${RESET}
105
128
  ${CYAN}│${RESET} ${CYAN}│${RESET}
106
- ${CYAN}│${RESET} ${BOLD}${WHITE}🛡️ TORUSGUARD SECURITY POSTURE${RESET} ${GRAY}v0.9.5${RESET} ${CYAN}│${RESET}
129
+ ${CYAN}│${RESET} ${BOLD}${WHITE}🛡️ TORUSGUARD SECURITY POSTURE${RESET} ${GRAY}v1.0.0${RESET} ${CYAN}│${RESET}
107
130
  ${CYAN}│${RESET} ${CYAN}│${RESET}
108
131
  ${CYAN}╰─────────────────────────────────────────────────────────────────────────╯${RESET}
109
132
 
@@ -117,6 +140,13 @@ if (command === 'status') {
117
140
  ${CYAN}│${RESET} Stack Detection: ${stackStatus}
118
141
  ${CYAN}└─────────────────────────────────────────────────────────────────────────┘${RESET}
119
142
 
143
+ ${CYAN}┌── Security Memory Engine ───────────────────────────────────────────────┐${RESET}
144
+ ${CYAN}│${RESET} Patterns Learned: ${GREEN}${memPatterns} active patterns${RESET}
145
+ ${CYAN}│${RESET} Events Recorded: ${WHITE}${memEvents} events (local-first log)${RESET}
146
+ ${CYAN}│${RESET} Context Window: ${CYAN}${memTokens} / 2,000 tokens${RESET} (${Math.round((memTokens / 2000) * 100)}% utilized)
147
+ ${CYAN}│${RESET} Fix Velocity Rate: ${YELLOW}${memFixRate}${RESET}
148
+ ${CYAN}└─────────────────────────────────────────────────────────────────────────┘${RESET}
149
+
120
150
  ${CYAN}┌── Governance Telemetry ─────────────────────────────────────────────────┐${RESET}
121
151
  ${CYAN}│${RESET} Rules Catalog: ${GREEN}71 Canonical Security Rules${RESET} (11 families)
122
152
  ${CYAN}│${RESET} Severity Floor: ${YELLOW}${cfg.severity_threshold || 'medium'}${RESET}
@@ -148,6 +178,70 @@ if (command === 'status') {
148
178
  }
149
179
  }
150
180
 
181
+ // Subcommand: memory
182
+ if (command === 'memory') {
183
+ const sub = args[1] || 'status';
184
+ const memScript = path.join(cwd, '.torusguard', 'scripts', 'memory_engine.py');
185
+ const fallbackMemScript = path.join(rootDir, '.torusguard', 'scripts', 'memory_engine.py');
186
+ const actualMemScript = fs.existsSync(memScript) ? memScript : fallbackMemScript;
187
+
188
+ let pyArgs = [actualMemScript];
189
+ if (sub === 'status') {
190
+ pyArgs.push('--action', 'status');
191
+ } else if (sub === 'context') {
192
+ pyArgs.push('--action', 'context');
193
+ } else if (sub === 'distill') {
194
+ pyArgs.push('--action', 'distill');
195
+ } else if (sub === 'decay') {
196
+ pyArgs.push('--action', 'decay');
197
+ const ttlIdx = args.indexOf('--ttl');
198
+ if (ttlIdx !== -1 && args[ttlIdx + 1]) {
199
+ pyArgs.push('--ttl', args[ttlIdx + 1]);
200
+ }
201
+ } else if (sub === 'compact') {
202
+ pyArgs.push('--action', 'compact');
203
+ const ageIdx = args.indexOf('--older-than');
204
+ if (ageIdx !== -1 && args[ageIdx + 1]) {
205
+ pyArgs.push('--older-than', args[ageIdx + 1]);
206
+ }
207
+ } else if (sub === 'export') {
208
+ pyArgs.push('--action', 'export');
209
+ const pathIdx = args.indexOf('--path') !== -1 ? args.indexOf('--path') : args.indexOf('-p');
210
+ if (pathIdx !== -1 && args[pathIdx + 1]) {
211
+ pyArgs.push('--target', args[pathIdx + 1]);
212
+ } else {
213
+ pyArgs.push('--target', 'torusguard-memory-export.json');
214
+ }
215
+ } else if (sub === 'import') {
216
+ pyArgs.push('--action', 'import');
217
+ const pathIdx = args.indexOf('--path') !== -1 ? args.indexOf('--path') : args.indexOf('-p');
218
+ if (pathIdx !== -1 && args[pathIdx + 1]) {
219
+ pyArgs.push('--source', args[pathIdx + 1]);
220
+ } else {
221
+ console.error(`${RED}Error: --path <file> is required for memory import${RESET}`);
222
+ process.exit(1);
223
+ }
224
+ } else if (sub === 'fp') {
225
+ pyArgs.push('--action', 'fp');
226
+ const ruleIdx = args.indexOf('--rule') !== -1 ? args.indexOf('--rule') : args.indexOf('-r');
227
+ if (ruleIdx !== -1 && args[ruleIdx + 1]) {
228
+ pyArgs.push('--rule-id', args[ruleIdx + 1]);
229
+ } else {
230
+ console.error(`${RED}Error: --rule <rule_id> is required for fp suppression${RESET}`);
231
+ process.exit(1);
232
+ }
233
+ const reasonIdx = args.indexOf('--reason');
234
+ if (reasonIdx !== -1 && args[reasonIdx + 1]) {
235
+ pyArgs.push('--reason', args[reasonIdx + 1]);
236
+ }
237
+ } else {
238
+ pyArgs.push('--action', sub, ...args.slice(2));
239
+ }
240
+
241
+ const proc = spawnSync(pythonCmd, pyArgs, { stdio: 'inherit', cwd });
242
+ process.exit(proc.status !== null ? proc.status : 0);
243
+ }
244
+
151
245
  // Locate bootstrap / runner scripts
152
246
  const localBootstrap = path.join(rootDir, 'skills', 'torusguard', 'bootstrap.py');
153
247
  const localInstall = path.join(rootDir, 'install.py');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "torusguard",
3
- "version": "0.9.5",
3
+ "version": "1.0.0",
4
4
  "description": "Security guardrails, governed remediation, and authorized runtime validation for AI-built web applications.",
5
5
  "main": "bin/torusguard.js",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: torusguard
3
- description: "Autonomous security engine: 71 rules across 11 families, governed remediation (Ponytail Protocol), SARIF v2.1.0 exports, and 5-agent authority separation for Python & TypeScript web applications."
4
- version: 0.9.5
3
+ description: "Autonomous security engine: 71 rules across 11 families, governed remediation (Ponytail Protocol), SARIF v2.1.0 exports, and persistent security memory context for Python & TypeScript web applications."
4
+ version: 1.0.0
5
5
  ---
6
6
 
7
7
  # TorusGuard Master Security Router
@@ -11,7 +11,7 @@ version: 0.9.5
11
11
  ---
12
12
 
13
13
  ## ⚡ Workspace Bootstrap Check
14
- 1. **If `.torusguard/` exists on disk:** Full governance active. Route slash commands to local specialist workflows below.
14
+ 1. **If `.torusguard/` exists on disk:** Full governance active. Load `.torusguard/memory/context.json` into prompt context for local-first intelligence. Route commands to specialist workflows below.
15
15
  2. **If `.torusguard/` is absent (Autonomous AI Mode):** Operates standalone in any AI agent (Kimi, Antigravity, VS Code, Cursor). Apply in-memory security invariants:
16
16
  - Server-side auth & tenant scoping (`.filter(tenant=...)`).
17
17
  - Zero client-side secrets (`SUPABASE_SERVICE_ROLE_KEY`, live API keys).
@@ -36,6 +36,7 @@ Load **only** the designated sub-skill on demand to preserve the 1,000–1,500 t
36
36
  | `/torusguard recheck` | `skills/torusguard-recheck/SKILL.md` | `reviewer` |
37
37
  | `/torusguard report` | `skills/torusguard-report/SKILL.md` | `reviewer` |
38
38
  | `/torusguard status` | `skills/torusguard-status/SKILL.md` | `reviewer` |
39
+ | `/torusguard memory` | `skills/torusguard/SKILL.md` | `reviewer` |
39
40
  | `/torusguard full` | `skills/torusguard-full/SKILL.md` | *All* |
40
41
 
41
42
  *Note: Never load all skills simultaneously. Lazy-load strictly on demand.*
@@ -157,7 +157,7 @@ def print_already_initialized(target_root, cfg):
157
157
 
158
158
  {BOLD}▸ Project Root:{RESET} {GREEN}{target_root}{RESET}
159
159
  {BOLD}▸ Workspace:{RESET} {GREEN}.torusguard/{RESET} {DIM}(Already Initialized){RESET}
160
- {BOLD}▸ Version:{RESET} {CYAN}{cfg.get('version', '0.9.5')}{RESET}
160
+ {BOLD}▸ Version:{RESET} {CYAN}{cfg.get('version', '1.0.0')}{RESET}
161
161
  {BOLD}▸ Severity Floor:{RESET} {YELLOW}{cfg.get('severity_threshold', 'medium')}{RESET}
162
162
 
163
163
  {DIM}To refresh templates or re-scaffold, run:{RESET}
@@ -231,6 +231,70 @@ def scaffold_workspace(target_root=None, force=False, full_commands=False):
231
231
  if not gitkeep_rules.exists():
232
232
  gitkeep_rules.write_text("", encoding="utf-8")
233
233
 
234
+ # ── Ensure memory subsystem is initialized (v1.0.0) ────────────────────
235
+ memory_dir = torusguard_target / "memory"
236
+ memory_dir.mkdir(parents=True, exist_ok=True)
237
+ events_dir = memory_dir / "events"
238
+ events_dir.mkdir(parents=True, exist_ok=True)
239
+
240
+ gitkeep_events = events_dir / ".gitkeep"
241
+ if not gitkeep_events.exists():
242
+ gitkeep_events.write_text("", encoding="utf-8")
243
+
244
+ mem_gitignore = memory_dir / ".gitignore"
245
+ if not mem_gitignore.exists():
246
+ mem_gitignore.write_text("*\n", encoding="utf-8")
247
+
248
+ decay_file = memory_dir / "decay.json"
249
+ if not decay_file.exists():
250
+ decay_file.write_text(json.dumps({
251
+ "default_ttl_days": 90,
252
+ "decay_rate": 0.15,
253
+ "last_decay_run": None
254
+ }, indent=2), encoding="utf-8")
255
+
256
+ patterns_file = memory_dir / "patterns.json"
257
+ if not patterns_file.exists():
258
+ patterns_file.write_text("[]", encoding="utf-8")
259
+
260
+ profile_file = memory_dir / "profile.json"
261
+ if not profile_file.exists():
262
+ profile_file.write_text(json.dumps({
263
+ "stack": [],
264
+ "total_events": 0,
265
+ "active_patterns_count": 0,
266
+ "fix_rate_percentage": None,
267
+ "top_vulnerabilities": [],
268
+ "last_updated": None
269
+ }, indent=2), encoding="utf-8")
270
+
271
+ context_file = memory_dir / "context.json"
272
+ if not context_file.exists():
273
+ context_file.write_text(json.dumps({
274
+ "version": "1.0.0",
275
+ "generated_at": None,
276
+ "token_estimate": 0,
277
+ "max_token_budget": 2000,
278
+ "project_profile": {
279
+ "stack": [],
280
+ "total_events": 0,
281
+ "active_patterns_count": 0,
282
+ "fix_rate_percentage": None,
283
+ "top_vulnerabilities": []
284
+ },
285
+ "cards": []
286
+ }, indent=2), encoding="utf-8")
287
+
288
+ # Ensure target project root .gitignore excludes .torusguard/memory/
289
+ root_gitignore = target_root / ".gitignore"
290
+ if root_gitignore.exists():
291
+ try:
292
+ gi_content = root_gitignore.read_text(encoding="utf-8")
293
+ if ".torusguard/memory" not in gi_content:
294
+ root_gitignore.write_text(gi_content.rstrip() + "\n\n# TorusGuard security memory (local only)\n.torusguard/memory/\n", encoding="utf-8")
295
+ except Exception:
296
+ pass
297
+
234
298
  # ── Step 2: Security Profile & Coverage (In-Process, Zero Subprocess) ──
235
299
  # Execute stack detection in-process without spawning child processes (Socket.dev safe)
236
300
  detected_stack = None
@@ -275,7 +339,7 @@ def scaffold_workspace(target_root=None, force=False, full_commands=False):
275
339
  registered_ides = []
276
340
  tg_workflow_content = """---
277
341
  description: TorusGuard Autonomous Security Command Engine — run static security audits, authorized runtime web validation, governed remediation, and SARIF exports.
278
- version: 0.9.5
342
+ version: 1.0.0
279
343
  tools: Read, Grep, Glob, Bash, Edit, Write
280
344
  agent: auditor
281
345
  ---
@@ -8,7 +8,7 @@
8
8
  "agents/validator.md": "79fc4431de5c5507f8730aee6c5c3e61fd238cbf8cf8c7c6aac462eee9761ed6",
9
9
  "config/scope.json": "b198a86186b4c6d5e1af516bf4e3a6afa8878e622ca1d57a5bf72d294f8c6f25",
10
10
  "config/slash-commands.json": "5390f0d26f8117a62e56c58147d3a0d2deab1a20956302b212703281d13fa84e",
11
- "config/torusguard.json": "077bc6a948f9420aded8dba248577ff3ebf054cab64cf538a7a6d05223fe27bc",
11
+ "config/torusguard.json": "b979d6ead31e64a63729e050d820f3e3228d3c825972a60ccae2087e6b27f574",
12
12
  "references/django-security.md": "a15b7eb11b51dd1970d3d65544cf79ebea91fb99dc0e085e58a56532a718dce7",
13
13
  "references/drf-security.md": "c7a7af3acaef895bf4798590acc88b3a2e9831a49eb2d23b4d8f31540ab264cc",
14
14
  "references/express-security.md": "dff1db15e614d29d8c272f9da345b418077e62dc883fe210c7a50c552c76493f",
@@ -28,20 +28,24 @@
28
28
  "schemas/confidence.schema.json": "08b3a564d7370e123dd5bfadde9fb077d2954e36b523685b9e1d7bdd2aa4b8cb",
29
29
  "schemas/evidence.schema.json": "d3dcaa10fd2420a4046ea68836fb836a55d003ada4cdc6682229f232881182bf",
30
30
  "schemas/finding.schema.json": "e0a7c28fa4a5f84bdedb5cf5223da26348250d633479d2dbf7ce3ebd6790a852",
31
+ "schemas/memory-context.schema.json": "6b9e032c55ba87b2517dd1e7ca0043b8e2439e85fa4a6eac6fc6041f3091e571",
32
+ "schemas/memory-event.schema.json": "4f653610e04fd480325d0ec77a4339bea4690f85e1d2fa0bd4f6b654c813c905",
33
+ "schemas/memory-pattern.schema.json": "df4aae2a3034a7c64ec50b3ae27b6ee9296aac7371c2a1938508834e5f778afe",
31
34
  "schemas/provenance.schema.json": "781215801249532414643638b6608dc8f52febc9bca43ae03827b90aecc03256",
32
35
  "schemas/remediation.schema.json": "217cb2743ae1a912dc074382e9f05634da93f2e30a880c03f6020600ef7e43d3",
33
36
  "schemas/retest.schema.json": "773b764082f6d2e8c3656ea105e0ce09febd1020520bf262bbcd17f5924da11e",
34
37
  "schemas/runtime-evidence.schema.json": "dbe13741a7fb68cca2a044d47a644ee0bdaacb83a28621dc2a98bffdd59989a6",
35
- "scripts/diff_guard.py": "227bf56d2e6c9aef293a51ad1a3209782e6d9204dc1775956d372c3a6851a736",
36
- "scripts/finding_scorer.py": "b78c6315f22000fb64f5d4e6ff1f3467439769d3d5507aaa99380453df4eb464",
37
- "scripts/manifest_builder.py": "b759131592966053db17ef710dc5f313127a9583295cb867a39ab22a7c996580",
38
+ "scripts/diff_guard.py": "5937b657c1047c78b7b9f0a36f3438cb699457cdb5ee56136d68b97edf56af42",
39
+ "scripts/finding_scorer.py": "c9f34c9153f5322c92bba824ce199ea281c450cd8edc637e61442c5f556d6183",
40
+ "scripts/manifest_builder.py": "136d5650a97dbb52fdf42c6d55b330a4f9593816e344b07913b0b2ba6b5cc409",
41
+ "scripts/memory_engine.py": "e99d34951b953bf3d96b6fca2413192de76778e6519278d4213fa3a72bc9b05f",
38
42
  "scripts/monorepo_detector.py": "38f1eb948ee2856f175e1212956bce211effdd1327d3a31f7303d32ba9478ebe",
39
- "scripts/run_manager.py": "e853874e4fb0cb697596ea338f71ba7e955f2b41a6fc649733b45fa755e94768",
43
+ "scripts/run_manager.py": "b576fc3be9929ee6a52e67662e67f801e4e9317c158243582911e10c94a07619",
40
44
  "scripts/safety_gate.py": "3379b7534b2590cf563717a448983ad8ed7e8f174f0ad65683d33e8a10f51558",
41
45
  "scripts/sarif_exporter.py": "35c66637413afc4b72d5bd426638447c77231d2a8594dce5addceffd4803a20d",
42
46
  "scripts/stack_detect.py": "99b7bdf9829d58ff5b8c59afd6e8b6429bbb11d830ac73dec491101cbbc41574",
43
- "skills/torusguard/SKILL.md": "31a115886ffb115f2b975c4d0670e780e11ea68201559b24b20d0d0ef456058f",
44
- "skills/torusguard/bootstrap.py": "7e348065a622089ab1d51e9bf4864e5b0022aaee1ccb2ecbf7057c14e792e2c7",
47
+ "skills/torusguard/SKILL.md": "e772e348716aee26e424ec96be5bd6750dbebcefc248bc4dab0df1e6c0e24fcf",
48
+ "skills/torusguard/bootstrap.py": "7c5a13687578a8736aef25cf767d1ef3c8b82dcae0eb7efce41bf131d27a120f",
45
49
  "skills/torusguard/references/auth-and-sessions.md": "34c2843f8c0dbe3574e54f00a39a92a1f431527ec5f69b2d64c84240d424a39e",
46
50
  "skills/torusguard/references/business-logic-and-abuse.md": "0d6088936bc1a01023070332fccef0f2e0734358a5119379055f3d2895c22567",
47
51
  "skills/torusguard/references/cache-and-sensitive-responses.md": "8f920cacde29c50b1f5f98de341a60db0bc607fe8c212a7e618ef7af08c86511",
@@ -66,13 +70,13 @@
66
70
  "skills/torusguard/references/webhook-security.md": "a0c7efb663c664dd840ba99b689cb67d4688643106f8b6e80d18a424c6add386",
67
71
  "skills/torusguard/references/websocket-security.md": "5624a84abd75bbb4eed029cd217e0c794ee452cbecc0730a8ab4d0f371537cd7",
68
72
  "skills/torusguard-apply/SKILL.md": "9436fa5cdefa661677ada22936a3949de06aca276e4f4bb27e0ef5b7ea34edc3",
69
- "skills/torusguard-audit/SKILL.md": "d0e0c21d6c36d9d128ccce6ad628b978ff771d27552ba80e0a4981e18b9f5a51",
73
+ "skills/torusguard-audit/SKILL.md": "f879e280d357ea7f124c647ce39af2b24b79db608c9edd018f26e5312625a8b5",
70
74
  "skills/torusguard-authorize/SKILL.md": "da849585f2e46c08ef528b89737be14647f1109fd365fd27f3f6da57a396724b",
71
75
  "skills/torusguard-exploit-check/SKILL.md": "e9a173e154a88cc9cb929c59d79a65ab13d5cf9567b4112bd7f272746cf9c3f9",
72
76
  "skills/torusguard-full/SKILL.md": "cc97684d37de378e51fefd12f6f9a7cd15cc469ce46079a0599440aa7b073f7b",
73
- "skills/torusguard-harden/SKILL.md": "86a8dee6c614477e2122287752f5c16e3688c0451d0e7ae9bfd2a23802bcdde3",
77
+ "skills/torusguard-harden/SKILL.md": "326fa84bda4832f96b19d73824c3472dfe185247ed3e3db9715dd943d46d9874",
74
78
  "skills/torusguard-init/SKILL.md": "1f7844d66219955581fdb266029eefdc355dbebb5741b848daf0062e606202a2",
75
- "skills/torusguard-recheck/SKILL.md": "4725a9be6a6ddedb3d389d1957c7ce3e0f9ce288107816fce85b5953951e13e5",
79
+ "skills/torusguard-recheck/SKILL.md": "457b2a1cce064a738fbe43f0dba6b4393f1630a82f60698ea5ebe655ec017e50",
76
80
  "skills/torusguard-report/SKILL.md": "bde44d114bdc85c04472644a644a7796ed2f182a23e0c057838a3251e4910a09",
77
81
  "skills/torusguard-status/SKILL.md": "4e71d03c71b240afd7f6108569530b7da3702634c512a74ca8dc3174f3c6b0fb",
78
82
  "skills/torusguard-verify/SKILL.md": "10c19e0926255686351e3b75ae774880cf35562d42bd30b87a877bb8f284fc1f",
@@ -87,6 +91,7 @@
87
91
  "workflows/exploit-check.md": "9684009b835a61d5aca8827a971ee686a24c800425d86ef96f963dd27de845b8",
88
92
  "workflows/harden.md": "509484f844c9dcd10dd14c8bb6e3456021928e6cf6abd374faaf34be8fc34ce2",
89
93
  "workflows/init.md": "3d1668a9f6b87417c31f47c887c495f863595ed4a29074e0c5a8ee1ece1d4a35",
94
+ "workflows/memory.md": "c034f9266380db3c05e9ffed943c2bb4ba73c060507e3508e47b543a035a5873",
90
95
  "workflows/recheck.md": "7d374c29a5585c31b81f84fb32d6a466f2e9cb339726dc0523dba25e57bc5d13",
91
96
  "workflows/report.md": "56b3449cff362172c63093ee6150446d11bf05e3c8143661966dad9d42df1470",
92
97
  "workflows/status.md": "921129646518c592cb47ad8e8ccf3d703e8d11ea6eb89bd21a206f545e022dba",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "../schemas/torusguard-config.schema.json",
3
- "version": "0.9.5",
3
+ "version": "1.0.0",
4
4
  "product": "TorusGuard Security Skill Kit",
5
5
  "severity_threshold": "medium",
6
6
  "auto_detect_stack": true,
@@ -0,0 +1,95 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "torusguard-memory-context.schema.json",
4
+ "title": "TorusGuard Memory Context Window",
5
+ "description": "Pre-computed, token-budgeted context window for AI agent consumption formatted as structured JSON cards.",
6
+ "type": "object",
7
+ "required": ["version", "generated_at", "token_estimate", "max_token_budget", "project_profile", "cards"],
8
+ "properties": {
9
+ "version": {
10
+ "type": "string",
11
+ "description": "TorusGuard engine version (e.g., 1.0.0)."
12
+ },
13
+ "generated_at": {
14
+ "type": "string",
15
+ "format": "date-time",
16
+ "description": "ISO 8601 UTC timestamp when this context window was computed."
17
+ },
18
+ "token_estimate": {
19
+ "type": "integer",
20
+ "minimum": 0,
21
+ "description": "Estimated token count of this context document."
22
+ },
23
+ "max_token_budget": {
24
+ "type": "integer",
25
+ "default": 2000,
26
+ "description": "Maximum allowed tokens for agent context injection (default: 2000)."
27
+ },
28
+ "project_profile": {
29
+ "type": "object",
30
+ "required": ["stack", "total_events", "active_patterns_count"],
31
+ "properties": {
32
+ "stack": {
33
+ "type": "array",
34
+ "items": { "type": "string" },
35
+ "description": "Detected technology stack frameworks/languages."
36
+ },
37
+ "total_events": {
38
+ "type": "integer",
39
+ "minimum": 0
40
+ },
41
+ "active_patterns_count": {
42
+ "type": "integer",
43
+ "minimum": 0
44
+ },
45
+ "fix_rate_percentage": {
46
+ "type": ["number", "null"],
47
+ "minimum": 0,
48
+ "maximum": 100
49
+ },
50
+ "top_vulnerabilities": {
51
+ "type": "array",
52
+ "items": { "type": "string" }
53
+ }
54
+ }
55
+ },
56
+ "cards": {
57
+ "type": "array",
58
+ "description": "Ordered list of high-priority intelligence cards for LLM grounding.",
59
+ "items": {
60
+ "type": "object",
61
+ "required": ["card_id", "card_type", "priority", "title", "summary", "card_data"],
62
+ "properties": {
63
+ "card_id": {
64
+ "type": "string",
65
+ "description": "Unique card identifier (e.g., CARD-001)."
66
+ },
67
+ "card_type": {
68
+ "type": "string",
69
+ "enum": ["pattern", "profile", "regression_watch", "false_positive", "fix_idiom"],
70
+ "description": "Semantic category of this context card."
71
+ },
72
+ "priority": {
73
+ "type": "integer",
74
+ "minimum": 1,
75
+ "maximum": 100,
76
+ "description": "Rank order priority (higher = more relevant/critical)."
77
+ },
78
+ "title": {
79
+ "type": "string",
80
+ "description": "Short, human-readable and agent-scannable card title."
81
+ },
82
+ "summary": {
83
+ "type": "string",
84
+ "description": "One-line operational summary for rapid agent reasoning."
85
+ },
86
+ "card_data": {
87
+ "type": "object",
88
+ "description": "Structured card payload containing rule_id, fix_strategy, confidence, affected_files, etc.",
89
+ "additionalProperties": true
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "torusguard-memory-event.schema.json",
4
+ "title": "TorusGuard Memory Event",
5
+ "description": "Schema for individual memory events recorded during audit/fix/recheck cycles.",
6
+ "type": "object",
7
+ "required": ["event_id", "event_type", "timestamp", "version"],
8
+ "properties": {
9
+ "event_id": {
10
+ "type": "string",
11
+ "description": "Unique event identifier (UUID v4 or timestamp-based)."
12
+ },
13
+ "event_type": {
14
+ "type": "string",
15
+ "enum": ["audit_finding", "fix_applied", "fix_verified", "false_positive", "pattern_learned", "stack_changed"],
16
+ "description": "Category of security event."
17
+ },
18
+ "timestamp": {
19
+ "type": "string",
20
+ "format": "date-time",
21
+ "description": "ISO 8601 UTC timestamp."
22
+ },
23
+ "version": {
24
+ "type": "string",
25
+ "description": "TorusGuard version that recorded this event."
26
+ },
27
+ "rule_id": {
28
+ "type": ["string", "null"],
29
+ "description": "TorusGuard rule ID (e.g., TG-DB-004)."
30
+ },
31
+ "file_path": {
32
+ "type": ["string", "null"],
33
+ "description": "Relative file path within the project."
34
+ },
35
+ "line_number": {
36
+ "type": ["integer", "null"],
37
+ "description": "Line number of the finding."
38
+ },
39
+ "severity": {
40
+ "type": ["string", "null"],
41
+ "enum": ["critical", "high", "medium", "low", "info", null]
42
+ },
43
+ "confidence_score": {
44
+ "type": ["integer", "null"],
45
+ "minimum": 0,
46
+ "maximum": 100
47
+ },
48
+ "code_hash": {
49
+ "type": ["string", "null"],
50
+ "description": "SHA-256 hash of the relevant code snippet for pattern matching."
51
+ },
52
+ "fix_strategy": {
53
+ "type": ["string", "null"],
54
+ "description": "Human-readable description of the fix approach used."
55
+ },
56
+ "verification_result": {
57
+ "type": ["string", "null"],
58
+ "enum": ["fixed", "regressed", "partial", "not_tested", null]
59
+ },
60
+ "suppression_reason": {
61
+ "type": ["string", "null"],
62
+ "description": "Reason for false positive suppression."
63
+ },
64
+ "metadata": {
65
+ "type": "object",
66
+ "description": "Additional event-specific metadata.",
67
+ "additionalProperties": true
68
+ }
69
+ }
70
+ }