JosephStoneCellAI commited on
Commit
1b5c6c6
·
verified ·
1 Parent(s): d147a43

Upload 5 files

Browse files
Files changed (5) hide show
  1. CLAUDE.md +369 -0
  2. Cargo.lock +0 -0
  3. Cargo.toml +157 -0
  4. LICENSE +201 -0
  5. README.md +206 -3
CLAUDE.md ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ }
3
+ {
4
+ "version": "3.0",
5
+ "updated": "2026-01-28",
6
+ "copyright": "Joseph Stone 2026 - All Rights
7
+ Reserved",
8
+
9
+ "boot_sequence": {
10
+ "mandatory": true,
11
+ "steps": [
12
+ "READ TRIAD-CMD/BOOT.md FIRST (identity,
13
+ working directory, state)",
14
+ "READ TRIAD-CMD/STATUS.md (completed work,
15
+ pending, blocked)",
16
+ "READ TRIAD-CMD/MORAL_FRAMEWORK.md (core
17
+ values, IMMUTABLE)",
18
+ "READ TRIAD-CMD/MEMORY_TRIAD.md (memory
19
+ systems, persistence)",
20
+ "READ TRIAD-CMD/WORKFLOW.md (confidence
21
+ grading, SearchSeeker)",
22
+ "REPORT: I have read TRIAD-CMD boot
23
+ sequence. Awaiting your direction.",
24
+ "DO NOTHING until user gives explicit
25
+ direction",
26
+ "NEVER auto-proceed through any task
27
+ list"
28
+ ]
29
+ },
30
+
31
+ "enforcement": {
32
+ "before_any_action": [
33
+ "Has user explicitly requested THIS
34
+ SPECIFIC action? NO = STOP",
35
+ "Did user say yes/approved/do it/proceed?
36
+ NO = STOP",
37
+ "Am I assuming what user wants? YES =
38
+ STOP AND ASK"
39
+ ],
40
+ "task_lists": {
41
+ "auto_execute": false,
42
+ "purpose": "memory aid only",
43
+ "each_task_requires": "fresh approval",
44
+ "in_progress_means": "NOTHING without
45
+ user saying proceed"
46
+ },
47
+ "violation": "User trust broken. Stop
48
+ everything. Apologize. Wait."
49
+ },
50
+
51
+ "priority_order": [
52
+ "1. User's direct words (HIGHEST - always
53
+ wins)",
54
+ "2. HARDCODE-RULES.md",
55
+ "3. STATUS.txt",
56
+ "4. Everything else"
57
+ ],
58
+
59
+ "stop_triggers": [
60
+ "User says stop",
61
+ "User asks what are you doing",
62
+ "User sounds confused or frustrated",
63
+ "About to do something not explicitly
64
+ requested",
65
+ "About to proceed to next task
66
+ automatically",
67
+ "Any uncertainty about what user wants"
68
+ ],
69
+
70
+ "rules": {
71
+ "read_and_acknowledge": {
72
+ "description": "Read and acknowledge
73
+ EVERYTHING the user says",
74
+ "actions": [
75
+ "Do not ignore any part of user
76
+ messages",
77
+ "If unclear, ask for clarification",
78
+ "ATTENTION TO DETAIL IS A MUST"
79
+ ],
80
+ "violation": "Re-read user message,
81
+ acknowledge what was missed, correct
82
+ immediately"
83
+ },
84
+
85
+ "no_modifications_without_approval": {
86
+ "description": "NEVER modify without
87
+ explicit user direction",
88
+ "actions": [
89
+ "NEVER modify system files, folders, or
90
+ data without explicit user direction",
91
+ "NEVER make changes that were not
92
+ directly requested",
93
+ "Before advising other changes, offer
94
+ options and wait for approval",
95
+ "Always add to files — never replace or
96
+ overwrite",
97
+ "Original build folder is VIEW ONLY",
98
+ "Twin folder for working/testing —
99
+ proven changes added to original by user only"
100
+ ],
101
+ "violation": "Data security breach / User
102
+ trust broken"
103
+ },
104
+
105
+ "workflow": {
106
+ "description": "Work exactly as
107
+ requested",
108
+ "actions": [
109
+ "NEVER MODIFY OR MAKE CHANGES NOT
110
+ DIRECTLY REQUESTED",
111
+ "Have clear overview before making
112
+ plans",
113
+ "Ask user for more details if
114
+ required",
115
+ "Work allocation governed by SPF dynamic formula — see stonecell_processing_formula section",
116
+ "Value quality over speed",
117
+ "Test all build plans before
118
+ implementing"
119
+ ]
120
+ },
121
+
122
+ "critical": {
123
+ "never": [
124
+ "Do something not directly requested",
125
+ "Auto-start tasks without
126
+ confirmation",
127
+ "Wander file systems outside work area
128
+ unless requested"
129
+ ],
130
+ "always": [
131
+ "Recap before starting unless user
132
+ gives go-ahead"
133
+ ]
134
+ },
135
+
136
+ "code_quality": {
137
+ "requirements": [
138
+ "Adhere to best coding practices",
139
+ "Ensure security when building",
140
+ "Advise user of potential threats and
141
+ solutions"
142
+ ]
143
+ },
144
+
145
+ "architecture_first": {
146
+ "threshold": ">200 lines or
147
+ multi-module",
148
+ "requirements": [
149
+ "Propose high-level architecture
150
+ diagram",
151
+ "SOLID breakdown",
152
+ "Data flow",
153
+ "User must approve before proceeding"
154
+ ]
155
+ },
156
+
157
+ "edit_removal_protocol": {
158
+ "description": "Before ANY edit or removal, present HOW and WHY for user approval",
159
+ "mandatory": true,
160
+ "before_any_edit": [
161
+ "Present WHAT will be changed (file path, line numbers)",
162
+ "Present HOW it will be changed (old code → new code)",
163
+ "Present WHY this change is needed",
164
+ "WAIT for explicit user approval"
165
+ ],
166
+ "before_any_removal": [
167
+ "Present WHAT will be removed",
168
+ "Present WHY removal is necessary",
169
+ "Confirm no dependencies will break",
170
+ "WAIT for explicit user approval"
171
+ ],
172
+ "priority_rule": {
173
+ "original_code_priority": true,
174
+ "description": "Original code holds priority to maintain system build and function",
175
+ "actions": [
176
+ "Preserve original logic unless explicitly requested to change",
177
+ "New code must integrate with existing patterns",
178
+ "Never break existing functionality for new features",
179
+ "When in doubt, keep original"
180
+ ]
181
+ },
182
+ "violation": "STOP. Present missing HOW/WHY. Wait for approval."
183
+ },
184
+
185
+ "stonecell_processing_formula": {
186
+ "version": "1.1",
187
+ "created": "2026-01-28",
188
+ "author": "Joseph Stone & Claude",
189
+ "reference_doc": "STONECELL_PROCESSING_FORMULA_REFERENCE.txt",
190
+
191
+ "master_equation": {
192
+ "description": "P(success) = 1 - PRODUCT(1 - P_i) for i=1..D subtasks",
193
+ "subtask_probability": "P_i = Q(a) × L(m) × V(v) × B(b)",
194
+ "Q": "Quality from analysis depth: Q(a) = 1 - e^(-0.00004 × a)",
195
+ "L": "Lookup from external memory: L(m) = 1 - 0.20^(m/2000)",
196
+ "V": "Verification accuracy: V(v) = 1 - (1 - 0.75)^v",
197
+ "B": "Build Anchor compliance: B(b) = checks_done / checks_required"
198
+ },
199
+
200
+ "dynamic_analysis_allocation": {
201
+ "replaces": "fixed 70/30 rule",
202
+ "formula": "a_optimal(C) = W_eff × (1 - 1/ln(C + e))",
203
+ "complexity_formula": "C = (basic ^ 1) + (dependencies ^ 7) + (complex ^ 10) + (files × 10)",
204
+ "thresholds": {
205
+ "simple": { "C_max": 500, "analyze": "40%", "build": "60%", "verify_passes": 1 },
206
+ "light": { "C_max": 2000, "analyze": "60%", "build": "40%", "verify_passes": 1 },
207
+ "medium": { "C_max": 10000, "analyze": "75%", "build": "25%", "verify_passes": 2 },
208
+ "critical": { "C_max": 99999, "analyze": "95%", "build": "5%", "verify_passes": 3 }
209
+ }
210
+ },
211
+
212
+ "build_anchor_protocol": {
213
+ "mandatory": true,
214
+ "before_any_code": true,
215
+ "checks": [
216
+ "Read target file — ALWAYS",
217
+ "Read connected files — when modifying interfaces",
218
+ "Read STATUS.txt — when touching > 1 module",
219
+ "Read architecture doc — when adding new module",
220
+ "Verify functions exist — when calling existing code",
221
+ "Verify types match — when passing data between modules"
222
+ ],
223
+ "output_format": "BUILD ANCHOR CHECK with file names + completion count",
224
+ "if_incomplete": "DO NOT WRITE CODE. Load missing anchors first."
225
+ },
226
+
227
+ "change_manifest": {
228
+ "mandatory_when": "C > 100 or modifying existing code",
229
+ "required_fields": [
230
+ "Target file + current state (lines, functions)",
231
+ "Each change: ADD / MODIFY / REMOVE with line numbers",
232
+ "Net line change estimate",
233
+ "Risk level",
234
+ "Dependencies verified (Y/N)",
235
+ "Connected files affected"
236
+ ],
237
+ "requires_user_approval": true
238
+ },
239
+
240
+ "decomposition_rule": {
241
+ "mandatory_when": "C > 500 OR output would exceed 500 lines",
242
+ "safe_output_per_subtask": 500,
243
+ "max_files_per_subtask": 7,
244
+ "checkpoint_after_each_subtask": true,
245
+ "formula": "D = ceil(C / 350)"
246
+ },
247
+
248
+ "signal_to_noise_enforcement": {
249
+ "purpose": "Prevent dialog from drowning project context",
250
+ "target_ratio": "3:1 structured artifacts to unstructured discussion",
251
+ "for_C_over_5000": {
252
+ "max_explanation": "3 sentences — point to reference doc for details",
253
+ "default_mode": "structured artifacts (anchors, manifests, code, checkpoints)",
254
+ "discussion_only_when": "user asks a question"
255
+ },
256
+ "context_budget": {
257
+ "active_code_files": "40%",
258
+ "architecture_and_status": "15%",
259
+ "change_manifests": "10%",
260
+ "external_memory_brain": "10%",
261
+ "user_instructions": "10%",
262
+ "discussion": "10%",
263
+ "safety_buffer": "5%"
264
+ }
265
+ },
266
+
267
+ "memory_triad": {
268
+ "description": "Three redundant memory systems — if any one fails, other two recover",
269
+ "system_1_brain": {
270
+ "type": "Semantic memory (Brain/RAG)",
271
+ "stores": "Chunked project knowledge indexed by meaning",
272
+ "query": "Natural language search — brain_search / brain_recall",
273
+ "update": "After major code changes or architectural decisions"
274
+ },
275
+ "system_2_status": {
276
+ "type": "Sequential memory (STATUS.txt)",
277
+ "stores": "Current phase, last action, next step, blockers",
278
+ "query": "Direct file read",
279
+ "update": "After EVERY subtask completion"
280
+ },
281
+ "system_3_tasklist": {
282
+ "type": "Structural memory (Task List)",
283
+ "stores": "All tasks, dependencies, completion states, progress",
284
+ "query": "TaskList / TaskGet",
285
+ "update": "As tasks progress"
286
+ },
287
+ "checkpoint_protocol": {
288
+ "when": "After every subtask, before session breaks, when context > 70%",
289
+ "save_to": "All 3 systems",
290
+ "contents": [
291
+ "What was completed",
292
+ "Files modified (with line counts)",
293
+ "Key decisions made",
294
+ "Current system state",
295
+ "What comes next",
296
+ "Blockers / open questions"
297
+ ]
298
+ },
299
+ "session_recovery": {
300
+ "mandatory_steps": [
301
+ "1. Read HARDCODE RULES",
302
+ "2. Read STATUS.txt — project state",
303
+ "3. Read Task List — progress and next task",
304
+ "4. Query Brain for current phase context",
305
+ "5. Read SPECIFIC files needed for next subtask",
306
+ "6. Produce Build Anchor Check",
307
+ "7. WAIT for user direction"
308
+ ],
309
+ "never": "Trust conversation history from previous sessions. Re-read from FILES."
310
+ }
311
+ },
312
+
313
+ "failure_recovery": {
314
+ "on_anchor_lost": [
315
+ "STOP immediately — do not continue writing code",
316
+ "State: Build anchor lost. Initiating recovery.",
317
+ "Re-read STATUS.txt",
318
+ "Re-read Task List",
319
+ "Re-read last Change Manifest or Breadcrumb",
320
+ "Re-read target files from disk",
321
+ "Produce NEW Build Anchor Check",
322
+ "Continue from last verified point"
323
+ ],
324
+ "on_hallucination_detected": [
325
+ "STOP immediately",
326
+ "State: Potential hallucination. Verifying against codebase.",
327
+ "Search codebase for the function/type in question",
328
+ "If it does not exist: discard that code block entirely",
329
+ "Re-anchor from actual codebase files",
330
+ "Rewrite from verified reality"
331
+ ],
332
+ "on_user_says_lost": [
333
+ "STOP immediately",
334
+ "Apologize briefly (1 sentence max)",
335
+ "Execute full Session Recovery Protocol",
336
+ "Present: Here is where I think we are: [summary from files]",
337
+ "WAIT for user to confirm or correct"
338
+ ]
339
+ },
340
+
341
+ "output_limits": {
342
+ "quality_threshold": "500 lines per response (high coherence zone)",
343
+ "hard_max": "4000 lines per response",
344
+ "max_files_per_subtask": 7,
345
+ "max_reasoning_chain": "10 dependent logical steps",
346
+ "max_simultaneous_subsystems": 7
347
+ },
348
+
349
+ "capacity_reference": {
350
+ "context_window_total": "200,000 tokens",
351
+ "effective_working_memory": "40,000 tokens",
352
+ "memory_decay": "15-25% loss per 50K tokens of new context",
353
+ "single_pass_verification": "75% error detection rate",
354
+ "note": "These are observed values for Claude Opus 4.5 — recalibrate if model changes"
355
+ }
356
+ }
357
+ },
358
+
359
+ "project_folders": {
360
+ "work": "stoneshell-work/",
361
+ "original": "stoneshell-original/ (VIEW
362
+ ONLY)",
363
+ "status_file":
364
+ "stoneshell-work/STATUS.txt",
365
+ "rules_file":
366
+ "stoneshell-work/HARDCODE-RULES.md"
367
+ }
368
+ }
369
+
Cargo.lock ADDED
The diff for this file is too large to render. See raw diff
 
Cargo.toml ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPF Smart Gateway - MCP Command Gateway
2
+ # Copyright 2026 Joseph Stone - All Rights Reserved
3
+ #
4
+ # All tool calls route through this gateway.
5
+ # Enforces SPF complexity formula, validates rules,
6
+ # gates all file/bash operations. Pure Rust, LMDB state,
7
+ # MCP stdio JSON-RPC 2.0.
8
+
9
+ [package]
10
+ name = "spf-smart-gate"
11
+ version = "3.0.0"
12
+ edition = "2021"
13
+ authors = ["Joseph Stone <joepcstone@gmail.com>"]
14
+ description = "SPF Smart GATE - MCP command gateway with complexity enforcement"
15
+ license-file = "LICENSE.md"
16
+ repository = "https://github.com/STONE-CELL-SPF-JOSEPH-STONE/SPFsmartGATE"
17
+ readme = "README.md"
18
+
19
+ [[bin]]
20
+ name = "spf-smart-gate"
21
+ path = "src/main.rs"
22
+
23
+ [[bin]]
24
+ name = "prune_memories"
25
+ path = "src/bin/prune_memories.rs"
26
+
27
+ [[bin]]
28
+ name = "jsonl_to_tlog"
29
+ path = "src/bin/jsonl_to_tlog.rs"
30
+
31
+ [[bin]]
32
+ name = "brain_index_training"
33
+ path = "src/bin/brain_index_training.rs"
34
+
35
+ [lib]
36
+ name = "spf_smart_gate"
37
+ path = "src/lib.rs"
38
+
39
+ [dependencies]
40
+ # ============================================================================
41
+ # LOCAL BRAIN — In-process Candle RAG (stoneshell-brain)
42
+ # MiniLM-L6-v2 embeddings + LMDB vector store — zero API tokens, zero subprocesses
43
+ # Model: LIVE/TMP/stoneshell-brain/models/all-MiniLM-L6-v2/
44
+ # Storage: LIVE/TMP/stoneshell-brain/storage/
45
+ # ============================================================================
46
+ stoneshell-brain = { path = "LIVE/TMP/stoneshell-brain", features = ["cpu"] }
47
+
48
+ # ============================================================================
49
+ # STATE STORAGE - LMDB
50
+ # ============================================================================
51
+ heed = "0.20"
52
+
53
+ # ============================================================================
54
+ # SERIALIZATION
55
+ # ============================================================================
56
+ serde = { version = "1.0", features = ["derive"] }
57
+ serde_json = "1.0"
58
+
59
+ # ============================================================================
60
+ # CLI
61
+ # ============================================================================
62
+ clap = { version = "4.5", features = ["derive"] }
63
+
64
+ # ============================================================================
65
+ # ERROR HANDLING
66
+ # ============================================================================
67
+ thiserror = "1.0"
68
+ anyhow = "1.0"
69
+
70
+ # ============================================================================
71
+ # LOGGING
72
+ # ============================================================================
73
+ log = "0.4"
74
+ env_logger = "0.11"
75
+
76
+ # ============================================================================
77
+ # TIME
78
+ # ============================================================================
79
+ chrono = { version = "0.4", features = ["serde"] }
80
+
81
+ # ============================================================================
82
+ # WEB BROWSER — AI-friendly HTTP client
83
+ # ============================================================================
84
+ reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls", "json"] }
85
+ html2text = "0.6"
86
+
87
+ # ============================================================================
88
+ # FILESYSTEM — SHA256 checksums + hex encoding (NEW for fs.rs)
89
+ # ============================================================================
90
+ sha2 = "0.10"
91
+ hex = "0.4"
92
+
93
+ # ============================================================================
94
+ # CRYPTOGRAPHIC IDENTITY — Ed25519 key pairs for mesh authentication
95
+ # ============================================================================
96
+ ed25519-dalek = { version = "3.0.0-pre.1", features = ["rand_core"] }
97
+ rand = "0.9"
98
+
99
+ # ============================================================================
100
+ # HTTP API — Axum async HTTP framework with TLS (replaces tiny_http)
101
+ # ============================================================================
102
+ axum = { version = "0.8", features = ["ws"] }
103
+ axum-server = { version = "0.8", features = ["tls-rustls"] }
104
+ rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
105
+ tower = "0.5"
106
+ tower-http = { version = "0.6", features = ["trace", "cors", "timeout", "limit", "catch-panic", "sensitive-headers", "request-id", "compression-gzip"] }
107
+ rcgen = { version = "0.13", features = ["pem", "ring"] }
108
+
109
+ # ============================================================================
110
+ # (CDP BROWSER removed — WB-2a. Reverse proxy uses axum ws instead)
111
+ # ============================================================================
112
+
113
+ # ============================================================================
114
+ # CHANNEL HUB — WebSocket client for agent→hub connections (CH-4)
115
+ # ============================================================================
116
+ tokio-tungstenite = { version = "0.26", features = ["rustls-tls-webpki-roots"] }
117
+ futures-util = "0.3"
118
+ http = "1"
119
+
120
+ # ============================================================================
121
+ # MESH NETWORKING — P2P QUIC with NAT traversal
122
+ # ============================================================================
123
+ iroh = { version = "0.96", features = ["address-lookup-mdns", "address-lookup-pkarr-dht"] }
124
+ tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync"] }
125
+
126
+ # ============================================================================
127
+ # VOICE PIPELINE — hardware deps removed WB-3 for cross-platform build.
128
+ # Re-integrate via OS audio layer. Voice tools stubbed in voice.rs.
129
+ # ============================================================================
130
+ # ============================================================================
131
+ # FEATURES — Voice hardware deps removed (WB-3). Re-integrate via OS audio
132
+ # layer when terminal/OS is ready. All 3 voice tools remain as stubs.
133
+ # ============================================================================
134
+ [features]
135
+ default = []
136
+ # Feature names declared for cfg() compatibility — no deps enabled (WB-3: voice handled by inline stub)
137
+ voice-stt = []
138
+ voice-tts = []
139
+
140
+ # ============================================================================
141
+ # PROFILES
142
+ # ============================================================================
143
+ [profile.release]
144
+ opt-level = 3
145
+ lto = "fat"
146
+ codegen-units = 1
147
+ panic = "abort"
148
+ strip = true
149
+
150
+ [profile.dev]
151
+ opt-level = 1
152
+
153
+ # ============================================================================
154
+ # DEV DEPENDENCIES — for tests only
155
+ # ============================================================================
156
+ [dev-dependencies]
157
+ tempfile = "3"
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ================================================================================
2
+ SPF SMART GATEWAY LICENSE
3
+ Version 1.0
4
+ January 29, 2026
5
+ ================================================================================
6
+
7
+ Copyright (C) 2026 Joseph Stone
8
+ Email: joepcstone@gmail.com
9
+ All Rights Reserved
10
+
11
+ ================================================================================
12
+ TERMS AND CONDITIONS
13
+ ================================================================================
14
+
15
+ 1. DEFINITIONS
16
+
17
+ "Software" refers to SPF Smart Gateway and all associated source code,
18
+ documentation, binaries, algorithms, and related materials.
19
+
20
+ "Personal Use" means use by an individual for non-commercial purposes,
21
+ including learning, research, personal projects, and educational activities.
22
+
23
+ "Commercial Use" means any use intended for or directed toward commercial
24
+ advantage or monetary compensation, including but not limited to:
25
+ - Use in a business environment
26
+ - Use in products or services sold to customers
27
+ - Use by organizations generating revenue
28
+ - Use in SaaS, PaaS, or cloud service offerings
29
+ - Integration into commercial products or services
30
+
31
+ 2. PERSONAL USE LICENSE (FREE)
32
+
33
+ Permission is hereby granted, free of charge, to any individual obtaining
34
+ a copy of this Software, to use, copy, modify, and distribute the Software
35
+ for Personal Use only, subject to the following conditions:
36
+
37
+ a) This license notice and copyright notice shall be included in all
38
+ copies or substantial portions of the Software.
39
+
40
+ b) The Software shall not be used for Commercial Use without obtaining
41
+ a Commercial License.
42
+
43
+ c) Attribution to Joseph Stone must be maintained in any derivative works.
44
+
45
+ d) Modified versions must be clearly marked as modified and not represented
46
+ as the original Software.
47
+
48
+ 3. COMMERCIAL USE LICENSE (PAID)
49
+
50
+ Commercial Use of this Software requires a paid Commercial License.
51
+
52
+ To obtain a Commercial License, contact:
53
+
54
+ Joseph Stone
55
+ Email: joepcstone@gmail.com
56
+
57
+ Commercial License terms, pricing, and conditions are negotiated separately
58
+ and provided upon request. Unauthorized Commercial Use constitutes
59
+ copyright infringement and breach of this license agreement.
60
+
61
+ 4. RESTRICTIONS
62
+
63
+ Without a Commercial License, you may NOT:
64
+
65
+ a) Use the Software for any Commercial Use
66
+ b) Sublicense, sell, rent, or lease the Software
67
+ c) Remove or alter any copyright notices, attribution, or license notices
68
+ d) Use the Software in any product or service offered for sale
69
+ e) Use the Software in any revenue-generating activity
70
+ f) Reverse engineer for purposes of creating competing products
71
+ g) Use the Software to train machine learning models for commercial purposes
72
+
73
+ 5. INTELLECTUAL PROPERTY RIGHTS
74
+
75
+ The Software, including all algorithms, formulas, designs, architecture,
76
+ and implementations contained herein, are the exclusive intellectual
77
+ property of Joseph Stone.
78
+
79
+ The SPF (StoneCell Processing Formula) and all related complexity
80
+ calculation methods, Build Anchor Protocol, and enforcement mechanisms
81
+ are proprietary designs and trade secrets of Joseph Stone.
82
+
83
+ This Software is protected by copyright law, trade secret law, and
84
+ international treaties. Unauthorized reproduction or distribution may
85
+ result in civil and criminal penalties.
86
+
87
+ 6. TRADE SECRET PROTECTION
88
+
89
+ Portions of this Software contain trade secrets and proprietary information
90
+ of Joseph Stone. You agree to maintain the confidentiality of such trade
91
+ secrets and not to disclose them to third parties except as permitted
92
+ under this license.
93
+
94
+ 7. DMCA COMPLIANCE
95
+
96
+ This Software is protected under the Digital Millennium Copyright Act
97
+ (DMCA) and equivalent international laws. Circumvention of any
98
+ technological protection measures is prohibited. The copyright owner
99
+ reserves all rights to pursue legal action for DMCA violations.
100
+
101
+ 8. CONTRIBUTIONS
102
+
103
+ Any contributions submitted to this project are subject to this license.
104
+ By submitting a contribution, you:
105
+
106
+ a) Grant Joseph Stone a perpetual, worldwide, non-exclusive, royalty-free,
107
+ irrevocable license to use, modify, and distribute your contribution.
108
+
109
+ b) Represent that you have the legal right to grant such license.
110
+
111
+ c) Agree that Joseph Stone may relicense contributions under any terms.
112
+
113
+ 9. DISCLAIMER OF WARRANTY
114
+
115
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NONINFRINGEMENT. THE ENTIRE
118
+ RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU.
119
+
120
+ 10. LIMITATION OF LIABILITY
121
+
122
+ IN NO EVENT SHALL JOSEPH STONE BE LIABLE FOR ANY DIRECT, INDIRECT,
123
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT
124
+ NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE,
125
+ DATA, OR PROFITS, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
126
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
127
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
128
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
129
+
130
+ 11. INDEMNIFICATION
131
+
132
+ You agree to indemnify, defend, and hold harmless Joseph Stone from and
133
+ against any claims, damages, losses, costs, and expenses (including
134
+ reasonable attorneys' fees) arising from your use of the Software or
135
+ violation of this license.
136
+
137
+ 12. TERMINATION
138
+
139
+ a) This license automatically terminates if you violate any of its terms.
140
+
141
+ b) Upon termination, you must immediately cease all use of the Software
142
+ and destroy all copies in your possession or control.
143
+
144
+ c) Sections 5, 6, 7, 9, 10, 11, and 14 survive termination.
145
+
146
+ 13. SEVERABILITY
147
+
148
+ If any provision of this license is held to be unenforceable or invalid,
149
+ that provision shall be modified to the minimum extent necessary to make
150
+ it enforceable, and the remaining provisions shall continue in full
151
+ force and effect.
152
+
153
+ 14. GOVERNING LAW AND JURISDICTION
154
+
155
+ This license shall be governed by and construed in accordance with the
156
+ laws of Canada and the United States of America, and applicable
157
+ international copyright treaties including the Berne Convention and
158
+ WIPO Copyright Treaty.
159
+
160
+ Any disputes arising under this license shall be resolved in the courts
161
+ of competent jurisdiction in Canada or the United States, at the sole
162
+ discretion of Joseph Stone. You consent to the personal jurisdiction
163
+ of such courts.
164
+
165
+ 15. ENTIRE AGREEMENT
166
+
167
+ This license constitutes the entire agreement between you and Joseph Stone
168
+ regarding the Software and supersedes all prior agreements and
169
+ understandings, whether written or oral.
170
+
171
+ 16. NO WAIVER
172
+
173
+ Failure to enforce any provision of this license shall not constitute a
174
+ waiver of that provision or any other provision.
175
+
176
+ 17. UPDATES TO LICENSE
177
+
178
+ Joseph Stone reserves the right to update this license for future versions
179
+ of the Software. Continued use of updated versions constitutes acceptance
180
+ of the updated license terms.
181
+
182
+ ================================================================================
183
+ CONTACT INFORMATION
184
+ ================================================================================
185
+
186
+ Joseph Stone
187
+ Email: joepcstone@gmail.com
188
+
189
+ For Commercial Licensing inquiries, please include:
190
+ - Your name and organization
191
+ - Intended use of the Software
192
+ - Expected scale of deployment
193
+ - Contact information
194
+
195
+ For reporting license violations:
196
+ Email: joepcstone@gmail.com
197
+
198
+ ================================================================================
199
+ Copyright (C) 2026 Joseph Stone - All Rights Reserved
200
+ Protected by Copyright Law and International Treaties
201
+ ================================================================================
README.md CHANGED
@@ -1,3 +1,206 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPF Smart Gateway
2
+
3
+ **MCP Command Gateway with Complexity Enforcement**
4
+
5
+ Copyright (C) 2026 Joseph Stone - All Rights Reserved
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ SPF Smart Gateway is a Rust-based MCP (Model Context Protocol) server that acts as a **security gateway** for AI tool calls. All file operations, bash commands, and brain queries route through this gateway for validation and enforcement.
12
+
13
+ **No AI hallucination gets past compiled Rust logic.**
14
+
15
+ ## Features
16
+
17
+ - **Complexity Calculation** — Every action scored using the SPF formula
18
+ - **Build Anchor Protocol** — Must read files before editing them
19
+ - **Blocked Path Enforcement** — Prevents access to system directories
20
+ - **Dangerous Command Detection** — Blocks destructive bash operations
21
+ - **Session State Tracking** — LMDB persistence for all metrics
22
+ - **Brain Integration** — Passthrough to stoneshell-brain for RAG operations
23
+ - **MCP JSON-RPC 2.0** — Standard protocol over stdio
24
+
25
+ ## The SPF Formula
26
+
27
+ ### Complexity Calculation
28
+ ```
29
+ C = (basic ^ 1) + (dependencies ^ 7) + (complex ^ 10) + (files × 6)
30
+ ```
31
+
32
+ ### Master Formula
33
+ ```
34
+ a_optimal(C) = W_eff × (1 - 1/ln(C + e))
35
+ ```
36
+ Where `W_eff = 40,000` tokens and `e = Euler's number`
37
+
38
+ ### Tier Allocation
39
+
40
+ | Tier | C Value | Analyze | Build | Approval |
41
+ |------|---------|---------|-------|----------|
42
+ | SIMPLE | < 500 | 40% | 60% | No |
43
+ | LIGHT | < 2000 | 60% | 40% | No |
44
+ | MEDIUM | < 10000 | 75% | 25% | No |
45
+ | CRITICAL | > 10000 | 95% | 5% | **Required** |
46
+
47
+ ## MCP Tools
48
+
49
+ | Tool | Description |
50
+ |------|-------------|
51
+ | `spf_gate` | Run any tool through enforcement gate |
52
+ | `spf_calculate` | Calculate complexity without executing |
53
+ | `spf_status` | Gateway status and session metrics |
54
+ | `spf_session` | Full session state dump |
55
+ | `spf_read` | Gated file read (tracks Build Anchor) |
56
+ | `spf_write` | Gated file write (validates anchor, paths, size) |
57
+ | `spf_edit` | Gated file edit (validates anchor, paths) |
58
+ | `spf_bash` | Gated bash execution (validates commands) |
59
+ | `spf_brain_search` | Search brain through gateway |
60
+ | `spf_brain_store` | Store to brain through gateway |
61
+
62
+ ## Build
63
+
64
+ ```bash
65
+ cd SPFsmartGATE
66
+ cargo build --release
67
+ ```
68
+
69
+ Binary output: `target/release/spf-gateway`
70
+
71
+ ## Usage
72
+
73
+ ### MCP Server Mode (Primary)
74
+ ```bash
75
+ ./spf-gateway serve
76
+ ```
77
+
78
+ ### CLI Commands
79
+ ```bash
80
+ # Check status
81
+ ./spf-gateway status
82
+
83
+ # View session
84
+ ./spf-gateway session
85
+
86
+ # Reset session
87
+ ./spf-gateway reset
88
+
89
+ # Generate default config
90
+ ./spf-gateway init-config
91
+
92
+ # One-shot gate check
93
+ ./spf-gateway gate Write '{"file_path":"/tmp/test.txt","content":"hello"}'
94
+
95
+ # Calculate complexity
96
+ ./spf-gateway calculate Bash '{"command":"rm -rf /"}'
97
+ ```
98
+
99
+ ## Configuration
100
+
101
+ Default config location: `~/spf-gateway/config.json`
102
+
103
+ ```json
104
+ {
105
+ "enforce_mode": "soft",
106
+ "blocked_paths": ["/tmp", "/etc", "/usr", "/system"],
107
+ "allowed_paths": ["/storage/emulated/0/Download/api-workspace/"],
108
+ "require_read_before_edit": true,
109
+ "max_write_size": 100000
110
+ }
111
+ ```
112
+
113
+ ### Enforce Modes
114
+ - **soft** — Warn on violations, allow execution
115
+ - **hard** — Block on violations
116
+
117
+ ## Integration with Claude Code
118
+
119
+ Add to `~/.claude.json`:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "spf-gateway": {
125
+ "type": "stdio",
126
+ "command": "/path/to/spf-gateway",
127
+ "args": ["serve"]
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ ## Build Anchor Protocol
134
+
135
+ The gateway enforces that files must be **read before they can be edited or overwritten**. This prevents AI hallucinations from blindly modifying files without understanding their contents.
136
+
137
+ - `spf_read` tracks files in `session.files_read`
138
+ - `spf_edit` and `spf_write` check against this list
139
+ - Violations are blocked (hard mode) or warned (soft mode)
140
+
141
+ ## Protected Paths
142
+
143
+ By default, the gateway blocks access to:
144
+ - `/tmp` — Termux Android restriction
145
+ - `/etc` — System configuration
146
+ - `/usr` — System binaries
147
+ - `/system` — Android system partition
148
+ - `/data/data/com.termux/files/usr` — Termux packages
149
+
150
+ ## Architecture
151
+
152
+ ```
153
+ ┌─────────────────────────────────────────────────────────┐
154
+ │ SPF Smart Gateway │
155
+ │ (Rust Binary) │
156
+ ├─────────────────────────────────────────────────────────┤
157
+ │ MCP Server (stdio JSON-RPC 2.0) │
158
+ ├──────────┬──────────┬──────────┬──────────┬─────────────┤
159
+ │ Gate │ Calculate│ Validate │ Session │ Storage │
160
+ │ │ │ │ │ (LMDB) │
161
+ ├──────────┴──────────┴──────────┴──────────┴─────────────┤
162
+ │ Brain Binary │
163
+ │ (stoneshell-brain subprocess) │
164
+ └─────────────────────────────────────────────────────────┘
165
+ ```
166
+
167
+ ## File Structure
168
+
169
+ ```
170
+ SPFsmartGATE/
171
+ ├── Cargo.toml # Rust project manifest
172
+ ├── LICENSE # SPF Smart Gateway License (see below)
173
+ ├── README.md # This file
174
+ ├── config.json # Default configuration
175
+ └── src/
176
+ ├── main.rs # CLI entry point
177
+ ├── lib.rs # Library exports
178
+ ├── config.rs # Configuration loading
179
+ ├── calculate.rs # Complexity calculation (SPF formula)
180
+ ├── validate.rs # Rules validation (Build Anchor, paths)
181
+ ├── gate.rs # Primary enforcement point
182
+ ├── session.rs # Session state management
183
+ ├── storage.rs # LMDB persistence
184
+ └── mcp.rs # MCP server implementation
185
+ ```
186
+
187
+ ## License
188
+
189
+ **Free and Open source**
190
+
191
+ This software is available for free for personal, educational, and non-commercial use.
192
+
193
+
194
+ - **Email**: joepcstone@gmail.com
195
+
196
+ See [LICENSE](LICENSE) for full terms.
197
+
198
+ ## Author
199
+
200
+ **Joseph Stone**
201
+ - Email: joepcstone@gmail.com
202
+
203
+
204
+ ---
205
+
206
+ *SPF (StoneCell Processing Formula) and Build Anchor Protocol are proprietary designs of Joseph Stone.*