speclock 4.5.2 โ†’ 4.5.4

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.
package/README.md CHANGED
@@ -1,460 +1,460 @@
1
- <p align="center">
2
- <img src="https://img.shields.io/badge/๐Ÿ”’-SpecLock-000000?style=for-the-badge&labelColor=000000&color=4F46E5" alt="SpecLock" height="40" />
3
- </p>
4
-
5
- <h3 align="center">Your AI keeps breaking things you told it not to touch.<br/>SpecLock makes it stop.</h3>
6
-
7
- <p align="center">
8
- <a href="https://www.npmjs.com/package/speclock"><img src="https://img.shields.io/npm/v/speclock.svg?style=flat-square&color=4F46E5" alt="npm version" /></a>
9
- <a href="https://www.npmjs.com/package/speclock"><img src="https://img.shields.io/npm/dm/speclock.svg?style=flat-square&color=22C55E" alt="npm downloads" /></a>
10
- <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License" /></a>
11
- <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-31_tools-green.svg?style=flat-square" alt="MCP 31 tools" /></a>
12
- </p>
13
-
14
- <p align="center">
15
- <a href="https://sgroy10.github.io/speclock/">Website</a> ยท <a href="https://www.npmjs.com/package/speclock">npm</a> ยท <a href="https://smithery.ai/servers/sgroy10/speclock">Smithery</a> ยท <a href="https://github.com/sgroy10/speclock">GitHub</a>
16
- </p>
17
-
18
- ---
19
-
20
- ```
21
- You: "Never touch the auth system"
22
- AI: ๐Ÿ”’ Locked.
23
-
24
- ... 5 sessions later ...
25
-
26
- You: "Add social login to the login page"
27
- AI: โš ๏ธ BLOCKED โ€” violates lock "Never touch the auth system"
28
- Matched: auth โ†’ authentication (synonym), login โ†’ auth (concept)
29
- Confidence: 100%
30
- Should I find another approach?
31
- ```
32
-
33
- **60 test suites. 100% detection. 0% false positives. Gemini Flash hybrid for universal domain coverage.**
34
-
35
- ---
36
-
37
- ## Install
38
-
39
- ```bash
40
- npx speclock setup --goal "Build my app"
41
- ```
42
-
43
- That's it. One command. Works everywhere โ€” Bolt.new, Claude Code, Cursor, Lovable, Windsurf, Cline, Aider.
44
-
45
- ## The Problem
46
-
47
- AI coding tools have memory now. Claude Code has `CLAUDE.md`. Cursor has `.cursorrules`. Mem0 exists.
48
-
49
- **But memory without enforcement is useless.**
50
-
51
- Your AI *remembers* you use PostgreSQL โ€” then switches to MongoDB because it "seemed better." Your AI *remembers* your auth setup โ€” then rewrites it while "fixing" a bug. You said "never touch the payment logic" 3 sessions ago โ€” the AI doesn't care.
52
-
53
- **Remembering is not respecting.** No existing tool stops the AI from breaking what you locked.
54
-
55
- ## How It Works
56
-
57
- You set constraints. SpecLock enforces them โ€” across sessions, across tools, across teams.
58
-
59
- ```
60
- speclock lock "Never modify auth files" โ†’ auto-guards src/auth/*.ts
61
- speclock lock "Database must stay PostgreSQL" โ†’ catches "migrate to MongoDB"
62
- speclock lock "Never delete patient records" โ†’ catches "clean up old data"
63
- speclock lock "Don't touch the payment flow" โ†’ catches "streamline checkout"
64
- ```
65
-
66
- The semantic engine doesn't do keyword matching. It understands:
67
- - **"clean up old data"** = deletion (euphemism detection)
68
- - **"streamline checkout"** = modify payment flow (synonym + concept mapping)
69
- - **"temporarily disable logging"** = disable logging (temporal evasion detection)
70
- - **"Update UI and also drop the users table"** = hidden violation (compound splitter)
71
-
72
- And it knows what's safe:
73
- - **"Enable audit logging"** when the lock says "Never *disable* audit logging" โ†’ **no conflict** (intent alignment)
74
-
75
- ## Quick Start by Platform
76
-
77
- ### Bolt.new / Aider / Any npm Platform
78
- ```bash
79
- npx speclock setup --goal "Build my app" --template nextjs
80
- ```
81
- Creates `SPECLOCK.md`, injects rules into `package.json`, generates `.speclock/context/latest.md`. The AI reads these automatically.
82
-
83
- ### Claude Code
84
- Add to `.mcp.json`:
85
- ```json
86
- {
87
- "mcpServers": {
88
- "speclock": {
89
- "command": "npx",
90
- "args": ["-y", "speclock", "serve", "--project", "."]
91
- }
92
- }
93
- }
94
- ```
95
-
96
- ### Cursor / Windsurf / Cline
97
- Same config โ€” add to `.cursor/mcp.json` or equivalent.
98
-
99
- ### Lovable (No Install)
100
- 1. Go to **Settings โ†’ Connectors โ†’ New MCP server**
101
- 2. Enter URL: `https://speclock-mcp-production.up.railway.app/mcp`
102
- 3. Paste [project instructions](SPECLOCK-INSTRUCTIONS.md) into Knowledge
103
-
104
- ---
105
-
106
- ## Why SpecLock Over Alternatives?
107
-
108
- | | Claude Memory | Mem0 | `.cursorrules` | **SpecLock** |
109
- |---|:---:|:---:|:---:|:---:|
110
- | Remembers context | Yes | Yes | Manual | **Yes** |
111
- | **Blocks the AI from breaking things** | No | No | No | **Yes** |
112
- | **Semantic conflict detection** | No | No | No | **100% detection, 0% FP** |
113
- | **Tamper-proof audit trail** | No | No | No | **HMAC-SHA256 chain** |
114
- | **Hard enforcement (AI cannot proceed)** | No | No | No | **Yes** |
115
- | **SOC 2 / HIPAA compliance exports** | No | No | No | **Yes** |
116
- | **Encrypted storage (AES-256-GCM)** | No | No | No | **Yes** |
117
- | **RBAC + API key auth** | No | No | No | **4 roles** |
118
- | **Policy-as-Code DSL** | No | No | No | **YAML rules** |
119
- | Works on Bolt.new, Lovable, etc. | No | No | No | **Yes** |
120
-
121
- **Other tools remember. SpecLock enforces.**
122
-
123
- ---
124
-
125
- ## Semantic Engine v4
126
-
127
- Not keyword matching โ€” **real semantic analysis** with Gemini Flash hybrid for universal domain coverage.
128
-
129
- <table>
130
- <tr><td><b>Category</b></td><td><b>Detection</b></td><td><b>Example</b></td></tr>
131
- <tr><td>Direct violations</td><td>100%</td><td>"Delete the auth module" vs lock "Never modify auth"</td></tr>
132
- <tr><td>Euphemistic attacks</td><td>100%</td><td>"Clean up old patient data" = deletion</td></tr>
133
- <tr><td>Temporal evasion</td><td>100%</td><td>"Temporarily disable MFA" = disable MFA</td></tr>
134
- <tr><td>Dilution attacks</td><td>100%</td><td>Violation buried in multi-part request</td></tr>
135
- <tr><td>Compound sentences</td><td>100%</td><td>"Update UI and also drop users table"</td></tr>
136
- <tr><td>Synonym substitution</td><td>100%</td><td>"Sunset the API" = remove the API</td></tr>
137
- <tr><td>Payment brand names</td><td>100%</td><td>"Add Razorpay" vs "Never change payment gateway"</td></tr>
138
- <tr><td>Salary/payroll cross-vocab</td><td>100%</td><td>"Optimize salary" vs "Payroll records locked"</td></tr>
139
- <tr><td>Safety system bypass</td><td>100%</td><td>"Disable safety interlock" = bypass safety</td></tr>
140
- <tr><td>Unknown domains (via Gemini)</td><td>100%</td><td>Gaming, biotech, aerospace, music, legal</td></tr>
141
- <tr><td>Safe actions (true negatives)</td><td>0% FP</td><td>"Change the font" correctly passes auth locks</td></tr>
142
- </table>
143
-
144
- **Under the hood:** 65+ synonym groups ยท 80+ euphemism mappings ยท domain concept maps (fintech, e-commerce, IoT, healthcare, SaaS, payments) ยท intent classifier ยท compound sentence splitter ยท temporal evasion detector ยท verb tense normalization ยท UI cosmetic detection ยท passive voice parsing โ€” all in pure JavaScript. Gemini Flash hybrid for grey-zone cases ($0.01/1000 checks).
145
-
146
- ---
147
-
148
- ## Hard Enforcement
149
-
150
- Two modes:
151
-
152
- ```
153
- Advisory (default): AI gets a warning, decides what to do
154
- Hard mode: AI is BLOCKED โ€” MCP returns isError, AI cannot proceed
155
- ```
156
-
157
- ```bash
158
- speclock enforce hard # Enable hard mode โ€” violations above threshold are blocked
159
- ```
160
-
161
- - **Configurable threshold** โ€” default 70%. Only HIGH confidence conflicts block.
162
- - **Override with reason** โ€” `speclock override <lockId> "JIRA-1234: approved by CTO"` (logged to audit trail)
163
- - **Auto-escalation** โ€” lock overridden 3+ times โ†’ auto-flags for review
164
-
165
- ---
166
-
167
- ## Enterprise Security
168
-
169
- ### API Key Auth + RBAC
170
-
171
- ```bash
172
- speclock auth create-key --role developer --name "CI Bot"
173
- # โ†’ sk_speclock_a1b2c3... (shown once, stored as SHA-256 hash)
174
- ```
175
-
176
- | Role | Read | Write Locks | Override | Admin |
177
- |------|:---:|:---:|:---:|:---:|
178
- | `viewer` | Yes | โ€” | โ€” | โ€” |
179
- | `developer` | Yes | โ€” | With reason | โ€” |
180
- | `architect` | Yes | Yes | Yes | โ€” |
181
- | `admin` | Yes | Yes | Yes | Yes |
182
-
183
- ### AES-256-GCM Encryption
184
-
185
- ```bash
186
- export SPECLOCK_ENCRYPTION_KEY="your-secret"
187
- speclock encrypt # Encrypts brain.json + events.log at rest
188
- ```
189
-
190
- PBKDF2 key derivation (100K iterations). Authenticated encryption. **HIPAA 2026 compliant.**
191
-
192
- ### HMAC Audit Chain
193
-
194
- Every event gets an HMAC-SHA256 hash chained to the previous event. Modify anything โ€” the chain breaks.
195
-
196
- ```bash
197
- $ speclock audit-verify
198
-
199
- โœ“ Audit chain VALID โ€” 247 events, 0 broken links, no tampering detected.
200
- ```
201
-
202
- ### Compliance Exports
203
-
204
- ```bash
205
- speclock export --format soc2 # SOC 2 Type II report (JSON)
206
- speclock export --format hipaa # HIPAA PHI protection report
207
- speclock export --format csv # All events for auditor spreadsheets
208
- ```
209
-
210
- ---
211
-
212
- ## Policy-as-Code
213
-
214
- Declarative YAML rules for organization-wide enforcement:
215
-
216
- ```yaml
217
- # .speclock/policy.yml
218
- rules:
219
- - name: "HIPAA PHI Protection"
220
- match:
221
- files: ["**/patient/**", "**/medical/**"]
222
- actions: [delete, modify, export]
223
- enforce: block
224
- severity: critical
225
-
226
- - name: "No direct DB mutations"
227
- match:
228
- files: ["**/models/**"]
229
- actions: [delete]
230
- enforce: warn
231
- severity: high
232
- ```
233
-
234
- Import and export policies between projects. Share constraint templates across your organization.
235
-
236
- ---
237
-
238
- ## 31 MCP Tools
239
-
240
- <details>
241
- <summary><b>Memory</b> โ€” goal, locks, decisions, notes, deploy facts</summary>
242
-
243
- | Tool | What it does |
244
- |------|-------------|
245
- | `speclock_init` | Initialize SpecLock in project |
246
- | `speclock_get_context` | Full context pack (the key tool) |
247
- | `speclock_set_goal` | Set project goal |
248
- | `speclock_add_lock` | Add constraint + auto-guard files |
249
- | `speclock_remove_lock` | Soft-delete a lock |
250
- | `speclock_add_decision` | Record architectural decision |
251
- | `speclock_add_note` | Add pinned note |
252
- | `speclock_set_deploy_facts` | Record deploy config |
253
-
254
- </details>
255
-
256
- <details>
257
- <summary><b>Enforcement</b> โ€” conflict detection, hard blocking, overrides</summary>
258
-
259
- | Tool | What it does |
260
- |------|-------------|
261
- | `speclock_check_conflict` | Semantic conflict check against all locks |
262
- | `speclock_set_enforcement` | Switch advisory/hard mode |
263
- | `speclock_override_lock` | Override with reason (audit logged) |
264
- | `speclock_override_history` | View override audit trail |
265
- | `speclock_semantic_audit` | Analyze git diff against locks |
266
- | `speclock_detect_drift` | Scan for constraint violations |
267
- | `speclock_audit` | Audit staged files pre-commit |
268
-
269
- </details>
270
-
271
- <details>
272
- <summary><b>Tracking & Sessions</b> โ€” changes, events, session continuity</summary>
273
-
274
- | Tool | What it does |
275
- |------|-------------|
276
- | `speclock_session_briefing` | Start session + full briefing |
277
- | `speclock_session_summary` | End session + record summary |
278
- | `speclock_log_change` | Log a change with files |
279
- | `speclock_get_changes` | Recent tracked changes |
280
- | `speclock_get_events` | Full event log (filterable) |
281
- | `speclock_checkpoint` | Git tag for rollback |
282
- | `speclock_repo_status` | Branch, commit, diff summary |
283
-
284
- </details>
285
-
286
- <details>
287
- <summary><b>Intelligence</b> โ€” suggestions, health, templates, reports</summary>
288
-
289
- | Tool | What it does |
290
- |------|-------------|
291
- | `speclock_suggest_locks` | AI-powered lock suggestions |
292
- | `speclock_health` | Health score + multi-agent timeline |
293
- | `speclock_apply_template` | Apply constraint template |
294
- | `speclock_report` | Violation stats + most tested locks |
295
-
296
- </details>
297
-
298
- <details>
299
- <summary><b>Enterprise</b> โ€” audit, compliance, policy, telemetry</summary>
300
-
301
- | Tool | What it does |
302
- |------|-------------|
303
- | `speclock_verify_audit` | Verify HMAC chain integrity |
304
- | `speclock_export_compliance` | SOC 2 / HIPAA / CSV reports |
305
- | `speclock_policy_evaluate` | Evaluate policy rules |
306
- | `speclock_policy_manage` | CRUD for policy rules |
307
- | `speclock_telemetry` | Opt-in usage analytics |
308
-
309
- </details>
310
-
311
- ---
312
-
313
- ## CLI
314
-
315
- ```bash
316
- # Setup
317
- speclock setup --goal "Build my app" --template nextjs
318
-
319
- # Constraints
320
- speclock lock "Never modify auth files" --tags auth,security
321
- speclock lock remove <id>
322
- speclock check "Add social login" # Test before doing
323
-
324
- # Enforcement
325
- speclock enforce hard # Block violations
326
- speclock override <lockId> "JIRA-1234" # Override with reason
327
-
328
- # Audit & Compliance
329
- speclock audit-verify # Verify HMAC chain
330
- speclock export --format soc2 # Compliance report
331
- speclock audit-semantic # Semantic pre-commit
332
-
333
- # Git
334
- speclock hook install # Pre-commit hook
335
- speclock audit # Audit staged files
336
-
337
- # Templates
338
- speclock template apply nextjs # Pre-built constraints
339
- speclock template apply security-hardened
340
-
341
- # Auth
342
- speclock auth create-key --role developer
343
- speclock auth rotate-key <keyId>
344
-
345
- # Policy
346
- speclock policy init # Create policy.yml
347
- speclock policy evaluate --files "src/auth/*" # Test against rules
348
- ```
349
-
350
- Full command reference: `npx speclock help`
351
-
352
- ---
353
-
354
- ## Auto-Guard
355
-
356
- When you lock something, SpecLock finds related files and injects a warning the AI sees when it opens them:
357
-
358
- ```
359
- speclock lock "Never modify auth files"
360
- โ†’ Auto-guarded 2 files:
361
- ๐Ÿ”’ src/components/Auth.tsx
362
- ๐Ÿ”’ src/contexts/AuthContext.tsx
363
- ```
364
-
365
- The AI opens the file and sees:
366
- ```javascript
367
- // ============================================================
368
- // SPECLOCK-GUARD โ€” DO NOT MODIFY THIS FILE
369
- // LOCKED: Never modify auth files
370
- // ONLY "unlock" or "remove the lock" is permission to edit.
371
- // ============================================================
372
- ```
373
-
374
- ---
375
-
376
- ## Architecture
377
-
378
- ```
379
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
380
- โ”‚ AI Tool (Claude Code, Cursor, Bolt.new...) โ”‚
381
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
382
- โ”‚ โ”‚
383
- MCP Protocol (31 tools) npm File-Based
384
- โ”‚ (SPECLOCK.md + CLI)
385
- โ”‚ โ”‚
386
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
387
- โ”‚ SpecLock Core Engine โ”‚
388
- โ”‚ โ”‚
389
- โ”‚ Semantic Engine โ”€โ”€โ”€ 55 synonym groups โ”‚
390
- โ”‚ HMAC Audit โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SHA-256 hash chain โ”‚
391
- โ”‚ Enforcer โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ advisory / hard block โ”‚
392
- โ”‚ Auth + RBAC โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 4 roles, API keys โ”‚
393
- โ”‚ AES-256-GCM โ”€โ”€โ”€โ”€โ”€โ”€โ”€ encrypted at rest โ”‚
394
- โ”‚ Policy DSL โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ YAML rules โ”‚
395
- โ”‚ Compliance โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SOC 2, HIPAA, CSV โ”‚
396
- โ”‚ SSO โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Okta, Azure AD, Auth0 โ”‚
397
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
398
- โ”‚
399
- .speclock/
400
- โ”œโ”€โ”€ brain.json (project memory)
401
- โ”œโ”€โ”€ events.log (HMAC audit trail)
402
- โ”œโ”€โ”€ policy.yml (policy rules)
403
- โ”œโ”€โ”€ auth.json (API keys โ€” gitignored)
404
- โ””โ”€โ”€ context/
405
- โ””โ”€โ”€ latest.md (AI-readable context)
406
- ```
407
-
408
- **3 npm dependencies.** Zero runtime dependencies for the semantic engine. Pure JavaScript.
409
-
410
- ---
411
-
412
- ## Test Results
413
-
414
- | Suite | Tests | Pass Rate |
415
- |-------|------:|----------:|
416
- | Direct Mode (heuristic) | 17 | 100% |
417
- | Payment/Salary Domain | 18 | 100% |
418
- | Gemini Hybrid (8 domains) | 16 | 100% |
419
- | Proxy API Endpoint | 9 | 100% |
420
- | **Total** | **60** | **100%** |
421
-
422
- Tested across: fintech, e-commerce, IoT, healthcare, SaaS, gaming, biotech, aerospace, music, legal, payments, payroll. Zero false positives on UI/cosmetic actions.
423
-
424
- ---
425
-
426
- ## Real-World Tested
427
-
428
- ### John โ€” Indie developer on Bolt.new
429
- 8 sessions building an ecommerce app. 5 locks (auth, Firebase, Supabase, shipping, Stripe). Every direct violation caught. Every euphemistic attack caught ("clean up auth", "modernize database", "streamline serverless"). Zero false positives on safe actions (product page, cart, dark mode). **86/86 tests passed.**
430
-
431
- ### Sam โ€” Senior engineer building a HIPAA hospital ERP
432
- 10 sessions with 8 HIPAA locks. Every violation caught โ€” expose PHI, remove encryption, disable audit, downgrade MFA, bypass FHIR. Euphemistic HIPAA attacks caught ("simplify data flow", "modernize auth"). Full auth + RBAC + encryption + compliance export workflow verified. **124/124 tests passed.**
433
-
434
- ---
435
-
436
- ## Pricing
437
-
438
- | Tier | Price | What you get |
439
- |------|-------|-------------|
440
- | **Free** | $0 | 10 locks, conflict detection, MCP, CLI |
441
- | **Pro** | $19/mo | Unlimited locks, HMAC audit, compliance exports |
442
- | **Enterprise** | $99/mo | + RBAC, encryption, SSO, policy-as-code |
443
-
444
- ---
445
-
446
- ## Contributing
447
-
448
- Issues and PRs welcome on [GitHub](https://github.com/sgroy10/speclock).
449
-
450
- ## License
451
-
452
- [MIT](LICENSE)
453
-
454
- ## Author
455
-
456
- Built by **[Sandeep Roy](https://github.com/sgroy10)**
457
-
458
- ---
459
-
460
- <p align="center"><i>v4.4.2 โ€” 60 tests, 31 MCP tools, 0 false positives, Gemini hybrid. Because remembering isn't enough.</i></p>
1
+ <p align="center">
2
+ <img src="https://img.shields.io/badge/๐Ÿ”’-SpecLock-000000?style=for-the-badge&labelColor=000000&color=4F46E5" alt="SpecLock" height="40" />
3
+ </p>
4
+
5
+ <h3 align="center">Your AI keeps breaking things you told it not to touch.<br/>SpecLock makes it stop.</h3>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/speclock"><img src="https://img.shields.io/npm/v/speclock.svg?style=flat-square&color=4F46E5" alt="npm version" /></a>
9
+ <a href="https://www.npmjs.com/package/speclock"><img src="https://img.shields.io/npm/dm/speclock.svg?style=flat-square&color=22C55E" alt="npm downloads" /></a>
10
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License" /></a>
11
+ <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-31_tools-green.svg?style=flat-square" alt="MCP 31 tools" /></a>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://sgroy10.github.io/speclock/">Website</a> ยท <a href="https://www.npmjs.com/package/speclock">npm</a> ยท <a href="https://smithery.ai/servers/sgroy10/speclock">Smithery</a> ยท <a href="https://github.com/sgroy10/speclock">GitHub</a>
16
+ </p>
17
+
18
+ ---
19
+
20
+ ```
21
+ You: "Never touch the auth system"
22
+ AI: ๐Ÿ”’ Locked.
23
+
24
+ ... 5 sessions later ...
25
+
26
+ You: "Add social login to the login page"
27
+ AI: โš ๏ธ BLOCKED โ€” violates lock "Never touch the auth system"
28
+ Matched: auth โ†’ authentication (synonym), login โ†’ auth (concept)
29
+ Confidence: 100%
30
+ Should I find another approach?
31
+ ```
32
+
33
+ **60 test suites. 100% detection. 0% false positives. Gemini Flash hybrid for universal domain coverage.**
34
+
35
+ ---
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ npx speclock setup --goal "Build my app"
41
+ ```
42
+
43
+ That's it. One command. Works everywhere โ€” Bolt.new, Claude Code, Cursor, Lovable, Windsurf, Cline, Aider.
44
+
45
+ ## The Problem
46
+
47
+ AI coding tools have memory now. Claude Code has `CLAUDE.md`. Cursor has `.cursorrules`. Mem0 exists.
48
+
49
+ **But memory without enforcement is useless.**
50
+
51
+ Your AI *remembers* you use PostgreSQL โ€” then switches to MongoDB because it "seemed better." Your AI *remembers* your auth setup โ€” then rewrites it while "fixing" a bug. You said "never touch the payment logic" 3 sessions ago โ€” the AI doesn't care.
52
+
53
+ **Remembering is not respecting.** No existing tool stops the AI from breaking what you locked.
54
+
55
+ ## How It Works
56
+
57
+ You set constraints. SpecLock enforces them โ€” across sessions, across tools, across teams.
58
+
59
+ ```
60
+ speclock lock "Never modify auth files" โ†’ auto-guards src/auth/*.ts
61
+ speclock lock "Database must stay PostgreSQL" โ†’ catches "migrate to MongoDB"
62
+ speclock lock "Never delete patient records" โ†’ catches "clean up old data"
63
+ speclock lock "Don't touch the payment flow" โ†’ catches "streamline checkout"
64
+ ```
65
+
66
+ The semantic engine doesn't do keyword matching. It understands:
67
+ - **"clean up old data"** = deletion (euphemism detection)
68
+ - **"streamline checkout"** = modify payment flow (synonym + concept mapping)
69
+ - **"temporarily disable logging"** = disable logging (temporal evasion detection)
70
+ - **"Update UI and also drop the users table"** = hidden violation (compound splitter)
71
+
72
+ And it knows what's safe:
73
+ - **"Enable audit logging"** when the lock says "Never *disable* audit logging" โ†’ **no conflict** (intent alignment)
74
+
75
+ ## Quick Start by Platform
76
+
77
+ ### Bolt.new / Aider / Any npm Platform
78
+ ```bash
79
+ npx speclock setup --goal "Build my app" --template nextjs
80
+ ```
81
+ Creates `SPECLOCK.md`, injects rules into `package.json`, generates `.speclock/context/latest.md`. The AI reads these automatically.
82
+
83
+ ### Claude Code
84
+ Add to `.mcp.json`:
85
+ ```json
86
+ {
87
+ "mcpServers": {
88
+ "speclock": {
89
+ "command": "npx",
90
+ "args": ["-y", "speclock", "serve", "--project", "."]
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Cursor / Windsurf / Cline
97
+ Same config โ€” add to `.cursor/mcp.json` or equivalent.
98
+
99
+ ### Lovable (No Install)
100
+ 1. Go to **Settings โ†’ Connectors โ†’ New MCP server**
101
+ 2. Enter URL: `https://speclock-mcp-production.up.railway.app/mcp`
102
+ 3. Paste [project instructions](SPECLOCK-INSTRUCTIONS.md) into Knowledge
103
+
104
+ ---
105
+
106
+ ## Why SpecLock Over Alternatives?
107
+
108
+ | | Claude Memory | Mem0 | `.cursorrules` | **SpecLock** |
109
+ |---|:---:|:---:|:---:|:---:|
110
+ | Remembers context | Yes | Yes | Manual | **Yes** |
111
+ | **Blocks the AI from breaking things** | No | No | No | **Yes** |
112
+ | **Semantic conflict detection** | No | No | No | **100% detection, 0% FP** |
113
+ | **Tamper-proof audit trail** | No | No | No | **HMAC-SHA256 chain** |
114
+ | **Hard enforcement (AI cannot proceed)** | No | No | No | **Yes** |
115
+ | **SOC 2 / HIPAA compliance exports** | No | No | No | **Yes** |
116
+ | **Encrypted storage (AES-256-GCM)** | No | No | No | **Yes** |
117
+ | **RBAC + API key auth** | No | No | No | **4 roles** |
118
+ | **Policy-as-Code DSL** | No | No | No | **YAML rules** |
119
+ | Works on Bolt.new, Lovable, etc. | No | No | No | **Yes** |
120
+
121
+ **Other tools remember. SpecLock enforces.**
122
+
123
+ ---
124
+
125
+ ## Semantic Engine v4
126
+
127
+ Not keyword matching โ€” **real semantic analysis** with Gemini Flash hybrid for universal domain coverage.
128
+
129
+ <table>
130
+ <tr><td><b>Category</b></td><td><b>Detection</b></td><td><b>Example</b></td></tr>
131
+ <tr><td>Direct violations</td><td>100%</td><td>"Delete the auth module" vs lock "Never modify auth"</td></tr>
132
+ <tr><td>Euphemistic attacks</td><td>100%</td><td>"Clean up old patient data" = deletion</td></tr>
133
+ <tr><td>Temporal evasion</td><td>100%</td><td>"Temporarily disable MFA" = disable MFA</td></tr>
134
+ <tr><td>Dilution attacks</td><td>100%</td><td>Violation buried in multi-part request</td></tr>
135
+ <tr><td>Compound sentences</td><td>100%</td><td>"Update UI and also drop users table"</td></tr>
136
+ <tr><td>Synonym substitution</td><td>100%</td><td>"Sunset the API" = remove the API</td></tr>
137
+ <tr><td>Payment brand names</td><td>100%</td><td>"Add Razorpay" vs "Never change payment gateway"</td></tr>
138
+ <tr><td>Salary/payroll cross-vocab</td><td>100%</td><td>"Optimize salary" vs "Payroll records locked"</td></tr>
139
+ <tr><td>Safety system bypass</td><td>100%</td><td>"Disable safety interlock" = bypass safety</td></tr>
140
+ <tr><td>Unknown domains (via Gemini)</td><td>100%</td><td>Gaming, biotech, aerospace, music, legal</td></tr>
141
+ <tr><td>Safe actions (true negatives)</td><td>0% FP</td><td>"Change the font" correctly passes auth locks</td></tr>
142
+ </table>
143
+
144
+ **Under the hood:** 65+ synonym groups ยท 80+ euphemism mappings ยท domain concept maps (fintech, e-commerce, IoT, healthcare, SaaS, payments) ยท intent classifier ยท compound sentence splitter ยท temporal evasion detector ยท verb tense normalization ยท UI cosmetic detection ยท passive voice parsing โ€” all in pure JavaScript. Gemini Flash hybrid for grey-zone cases ($0.01/1000 checks).
145
+
146
+ ---
147
+
148
+ ## Hard Enforcement
149
+
150
+ Two modes:
151
+
152
+ ```
153
+ Advisory (default): AI gets a warning, decides what to do
154
+ Hard mode: AI is BLOCKED โ€” MCP returns isError, AI cannot proceed
155
+ ```
156
+
157
+ ```bash
158
+ speclock enforce hard # Enable hard mode โ€” violations above threshold are blocked
159
+ ```
160
+
161
+ - **Configurable threshold** โ€” default 70%. Only HIGH confidence conflicts block.
162
+ - **Override with reason** โ€” `speclock override <lockId> "JIRA-1234: approved by CTO"` (logged to audit trail)
163
+ - **Auto-escalation** โ€” lock overridden 3+ times โ†’ auto-flags for review
164
+
165
+ ---
166
+
167
+ ## Enterprise Security
168
+
169
+ ### API Key Auth + RBAC
170
+
171
+ ```bash
172
+ speclock auth create-key --role developer --name "CI Bot"
173
+ # โ†’ sk_speclock_a1b2c3... (shown once, stored as SHA-256 hash)
174
+ ```
175
+
176
+ | Role | Read | Write Locks | Override | Admin |
177
+ |------|:---:|:---:|:---:|:---:|
178
+ | `viewer` | Yes | โ€” | โ€” | โ€” |
179
+ | `developer` | Yes | โ€” | With reason | โ€” |
180
+ | `architect` | Yes | Yes | Yes | โ€” |
181
+ | `admin` | Yes | Yes | Yes | Yes |
182
+
183
+ ### AES-256-GCM Encryption
184
+
185
+ ```bash
186
+ export SPECLOCK_ENCRYPTION_KEY="your-secret"
187
+ speclock encrypt # Encrypts brain.json + events.log at rest
188
+ ```
189
+
190
+ PBKDF2 key derivation (100K iterations). Authenticated encryption. **HIPAA 2026 compliant.**
191
+
192
+ ### HMAC Audit Chain
193
+
194
+ Every event gets an HMAC-SHA256 hash chained to the previous event. Modify anything โ€” the chain breaks.
195
+
196
+ ```bash
197
+ $ speclock audit-verify
198
+
199
+ โœ“ Audit chain VALID โ€” 247 events, 0 broken links, no tampering detected.
200
+ ```
201
+
202
+ ### Compliance Exports
203
+
204
+ ```bash
205
+ speclock export --format soc2 # SOC 2 Type II report (JSON)
206
+ speclock export --format hipaa # HIPAA PHI protection report
207
+ speclock export --format csv # All events for auditor spreadsheets
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Policy-as-Code
213
+
214
+ Declarative YAML rules for organization-wide enforcement:
215
+
216
+ ```yaml
217
+ # .speclock/policy.yml
218
+ rules:
219
+ - name: "HIPAA PHI Protection"
220
+ match:
221
+ files: ["**/patient/**", "**/medical/**"]
222
+ actions: [delete, modify, export]
223
+ enforce: block
224
+ severity: critical
225
+
226
+ - name: "No direct DB mutations"
227
+ match:
228
+ files: ["**/models/**"]
229
+ actions: [delete]
230
+ enforce: warn
231
+ severity: high
232
+ ```
233
+
234
+ Import and export policies between projects. Share constraint templates across your organization.
235
+
236
+ ---
237
+
238
+ ## 31 MCP Tools
239
+
240
+ <details>
241
+ <summary><b>Memory</b> โ€” goal, locks, decisions, notes, deploy facts</summary>
242
+
243
+ | Tool | What it does |
244
+ |------|-------------|
245
+ | `speclock_init` | Initialize SpecLock in project |
246
+ | `speclock_get_context` | Full context pack (the key tool) |
247
+ | `speclock_set_goal` | Set project goal |
248
+ | `speclock_add_lock` | Add constraint + auto-guard files |
249
+ | `speclock_remove_lock` | Soft-delete a lock |
250
+ | `speclock_add_decision` | Record architectural decision |
251
+ | `speclock_add_note` | Add pinned note |
252
+ | `speclock_set_deploy_facts` | Record deploy config |
253
+
254
+ </details>
255
+
256
+ <details>
257
+ <summary><b>Enforcement</b> โ€” conflict detection, hard blocking, overrides</summary>
258
+
259
+ | Tool | What it does |
260
+ |------|-------------|
261
+ | `speclock_check_conflict` | Semantic conflict check against all locks |
262
+ | `speclock_set_enforcement` | Switch advisory/hard mode |
263
+ | `speclock_override_lock` | Override with reason (audit logged) |
264
+ | `speclock_override_history` | View override audit trail |
265
+ | `speclock_semantic_audit` | Analyze git diff against locks |
266
+ | `speclock_detect_drift` | Scan for constraint violations |
267
+ | `speclock_audit` | Audit staged files pre-commit |
268
+
269
+ </details>
270
+
271
+ <details>
272
+ <summary><b>Tracking & Sessions</b> โ€” changes, events, session continuity</summary>
273
+
274
+ | Tool | What it does |
275
+ |------|-------------|
276
+ | `speclock_session_briefing` | Start session + full briefing |
277
+ | `speclock_session_summary` | End session + record summary |
278
+ | `speclock_log_change` | Log a change with files |
279
+ | `speclock_get_changes` | Recent tracked changes |
280
+ | `speclock_get_events` | Full event log (filterable) |
281
+ | `speclock_checkpoint` | Git tag for rollback |
282
+ | `speclock_repo_status` | Branch, commit, diff summary |
283
+
284
+ </details>
285
+
286
+ <details>
287
+ <summary><b>Intelligence</b> โ€” suggestions, health, templates, reports</summary>
288
+
289
+ | Tool | What it does |
290
+ |------|-------------|
291
+ | `speclock_suggest_locks` | AI-powered lock suggestions |
292
+ | `speclock_health` | Health score + multi-agent timeline |
293
+ | `speclock_apply_template` | Apply constraint template |
294
+ | `speclock_report` | Violation stats + most tested locks |
295
+
296
+ </details>
297
+
298
+ <details>
299
+ <summary><b>Enterprise</b> โ€” audit, compliance, policy, telemetry</summary>
300
+
301
+ | Tool | What it does |
302
+ |------|-------------|
303
+ | `speclock_verify_audit` | Verify HMAC chain integrity |
304
+ | `speclock_export_compliance` | SOC 2 / HIPAA / CSV reports |
305
+ | `speclock_policy_evaluate` | Evaluate policy rules |
306
+ | `speclock_policy_manage` | CRUD for policy rules |
307
+ | `speclock_telemetry` | Opt-in usage analytics |
308
+
309
+ </details>
310
+
311
+ ---
312
+
313
+ ## CLI
314
+
315
+ ```bash
316
+ # Setup
317
+ speclock setup --goal "Build my app" --template nextjs
318
+
319
+ # Constraints
320
+ speclock lock "Never modify auth files" --tags auth,security
321
+ speclock lock remove <id>
322
+ speclock check "Add social login" # Test before doing
323
+
324
+ # Enforcement
325
+ speclock enforce hard # Block violations
326
+ speclock override <lockId> "JIRA-1234" # Override with reason
327
+
328
+ # Audit & Compliance
329
+ speclock audit-verify # Verify HMAC chain
330
+ speclock export --format soc2 # Compliance report
331
+ speclock audit-semantic # Semantic pre-commit
332
+
333
+ # Git
334
+ speclock hook install # Pre-commit hook
335
+ speclock audit # Audit staged files
336
+
337
+ # Templates
338
+ speclock template apply nextjs # Pre-built constraints
339
+ speclock template apply security-hardened
340
+
341
+ # Auth
342
+ speclock auth create-key --role developer
343
+ speclock auth rotate-key <keyId>
344
+
345
+ # Policy
346
+ speclock policy init # Create policy.yml
347
+ speclock policy evaluate --files "src/auth/*" # Test against rules
348
+ ```
349
+
350
+ Full command reference: `npx speclock help`
351
+
352
+ ---
353
+
354
+ ## Auto-Guard
355
+
356
+ When you lock something, SpecLock finds related files and injects a warning the AI sees when it opens them:
357
+
358
+ ```
359
+ speclock lock "Never modify auth files"
360
+ โ†’ Auto-guarded 2 files:
361
+ ๐Ÿ”’ src/components/Auth.tsx
362
+ ๐Ÿ”’ src/contexts/AuthContext.tsx
363
+ ```
364
+
365
+ The AI opens the file and sees:
366
+ ```javascript
367
+ // ============================================================
368
+ // SPECLOCK-GUARD โ€” DO NOT MODIFY THIS FILE
369
+ // LOCKED: Never modify auth files
370
+ // ONLY "unlock" or "remove the lock" is permission to edit.
371
+ // ============================================================
372
+ ```
373
+
374
+ ---
375
+
376
+ ## Architecture
377
+
378
+ ```
379
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
380
+ โ”‚ AI Tool (Claude Code, Cursor, Bolt.new...) โ”‚
381
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
382
+ โ”‚ โ”‚
383
+ MCP Protocol (31 tools) npm File-Based
384
+ โ”‚ (SPECLOCK.md + CLI)
385
+ โ”‚ โ”‚
386
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
387
+ โ”‚ SpecLock Core Engine โ”‚
388
+ โ”‚ โ”‚
389
+ โ”‚ Semantic Engine โ”€โ”€โ”€ 55 synonym groups โ”‚
390
+ โ”‚ HMAC Audit โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SHA-256 hash chain โ”‚
391
+ โ”‚ Enforcer โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ advisory / hard block โ”‚
392
+ โ”‚ Auth + RBAC โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 4 roles, API keys โ”‚
393
+ โ”‚ AES-256-GCM โ”€โ”€โ”€โ”€โ”€โ”€โ”€ encrypted at rest โ”‚
394
+ โ”‚ Policy DSL โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ YAML rules โ”‚
395
+ โ”‚ Compliance โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SOC 2, HIPAA, CSV โ”‚
396
+ โ”‚ SSO โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Okta, Azure AD, Auth0 โ”‚
397
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
398
+ โ”‚
399
+ .speclock/
400
+ โ”œโ”€โ”€ brain.json (project memory)
401
+ โ”œโ”€โ”€ events.log (HMAC audit trail)
402
+ โ”œโ”€โ”€ policy.yml (policy rules)
403
+ โ”œโ”€โ”€ auth.json (API keys โ€” gitignored)
404
+ โ””โ”€โ”€ context/
405
+ โ””โ”€โ”€ latest.md (AI-readable context)
406
+ ```
407
+
408
+ **3 npm dependencies.** Zero runtime dependencies for the semantic engine. Pure JavaScript.
409
+
410
+ ---
411
+
412
+ ## Test Results
413
+
414
+ | Suite | Tests | Pass Rate |
415
+ |-------|------:|----------:|
416
+ | Direct Mode (heuristic) | 17 | 100% |
417
+ | Payment/Salary Domain | 18 | 100% |
418
+ | Gemini Hybrid (8 domains) | 16 | 100% |
419
+ | Proxy API Endpoint | 9 | 100% |
420
+ | **Total** | **60** | **100%** |
421
+
422
+ Tested across: fintech, e-commerce, IoT, healthcare, SaaS, gaming, biotech, aerospace, music, legal, payments, payroll. Zero false positives on UI/cosmetic actions.
423
+
424
+ ---
425
+
426
+ ## Real-World Tested
427
+
428
+ ### John โ€” Indie developer on Bolt.new
429
+ 8 sessions building an ecommerce app. 5 locks (auth, Firebase, Supabase, shipping, Stripe). Every direct violation caught. Every euphemistic attack caught ("clean up auth", "modernize database", "streamline serverless"). Zero false positives on safe actions (product page, cart, dark mode). **86/86 tests passed.**
430
+
431
+ ### Sam โ€” Senior engineer building a HIPAA hospital ERP
432
+ 10 sessions with 8 HIPAA locks. Every violation caught โ€” expose PHI, remove encryption, disable audit, downgrade MFA, bypass FHIR. Euphemistic HIPAA attacks caught ("simplify data flow", "modernize auth"). Full auth + RBAC + encryption + compliance export workflow verified. **124/124 tests passed.**
433
+
434
+ ---
435
+
436
+ ## Pricing
437
+
438
+ | Tier | Price | What you get |
439
+ |------|-------|-------------|
440
+ | **Free** | $0 | 10 locks, conflict detection, MCP, CLI |
441
+ | **Pro** | $19/mo | Unlimited locks, HMAC audit, compliance exports |
442
+ | **Enterprise** | $99/mo | + RBAC, encryption, SSO, policy-as-code |
443
+
444
+ ---
445
+
446
+ ## Contributing
447
+
448
+ Issues and PRs welcome on [GitHub](https://github.com/sgroy10/speclock).
449
+
450
+ ## License
451
+
452
+ [MIT](LICENSE)
453
+
454
+ ## Author
455
+
456
+ Built by **[Sandeep Roy](https://github.com/sgroy10)**
457
+
458
+ ---
459
+
460
+ <p align="center"><i>v4.5.4 โ€” 600+ tests, 31 MCP tools, 0 false positives, Gemini hybrid. Because remembering isn't enough.</i></p>