speclock 5.1.0 → 5.2.1

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
@@ -8,7 +8,7 @@
8
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
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
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-40_tools-green.svg?style=flat-square" alt="MCP 40 tools" /></a>
11
+ <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-42_tools-green.svg?style=flat-square" alt="MCP 42 tools" /></a>
12
12
  </p>
13
13
 
14
14
  <p align="center">
@@ -32,7 +32,7 @@ AI: ⚠️ BLOCKED — violates lock "Never touch the auth system"
32
32
  Should I find another approach?
33
33
  ```
34
34
 
35
- **997 tests. 99.4% pass rate. 0 false positives across 14 suites. Gemini Flash hybrid, Spec Compiler, Code Graph, Typed Constraints, Python SDK, ROS2 integration.**
35
+ **1073 tests. 99.4% pass rate. 0 false positives across 15 suites. Gemini Flash hybrid, Spec Compiler, Code Graph, Typed Constraints, Python SDK, ROS2 integration.**
36
36
 
37
37
  ---
38
38
 
@@ -305,25 +305,118 @@ pip install speclock-sdk
305
305
  ```
306
306
 
307
307
  ```python
308
- from speclock import ConstraintChecker
309
- checker = ConstraintChecker(constraints)
310
- result = checker.check({"metric": "speed_mps", "value": 3.5})
308
+ from speclock import SpecLock
309
+
310
+ sl = SpecLock(project_root=".")
311
+
312
+ # Check text constraints (semantic conflict detection)
313
+ result = sl.check_text("Switch database to MongoDB")
314
+ # → { has_conflict: True, conflicting_locks: [...] }
315
+
316
+ # Check typed constraints (numerical/range/state/temporal)
317
+ result = sl.check_typed(metric="speed_mps", value=3.5)
311
318
  # → violation: speed exceeds 2.0 m/s limit
319
+
320
+ # Combined check (text + typed in one call)
321
+ result = sl.check(action="Increase speed", speed_mps=3.5)
322
+ ```
323
+
324
+ Uses the same `.speclock/brain.json` as the Node.js MCP server — constraints stay in sync across all environments.
325
+
326
+ **ROS2 Guardian Node:** Real-time constraint enforcement for robots and autonomous systems.
327
+
328
+ ```yaml
329
+ # config/constraints.yaml
330
+ constraints:
331
+ - type: range
332
+ metric: joint_position_rad
333
+ min: -3.14
334
+ max: 3.14
335
+ - type: numerical
336
+ metric: velocity_mps
337
+ operator: "<="
338
+ value: 2.0
339
+ - type: state
340
+ metric: system_mode
341
+ forbidden:
342
+ - from: emergency_stop
343
+ to: autonomous
344
+ ```
345
+
346
+ - Subscribes to `/joint_states`, `/cmd_vel`, `/speclock/state_transition`
347
+ - Publishes violations to `/speclock/violations`
348
+ - Triggers emergency stop via `/speclock/emergency_stop`
349
+ - Checks constraints on every incoming ROS2 message at configurable rate
350
+
351
+ ---
352
+
353
+ ## Patch Gateway (v5.1)
354
+
355
+ One API call gates every change. Takes a description + file list, returns ALLOW/WARN/BLOCK:
356
+
357
+ ```
358
+ speclock_review_patch({
359
+ description: "Add social login to auth page",
360
+ files: ["src/auth/login.js"]
361
+ })
362
+
363
+ → { verdict: "BLOCK", riskScore: 85,
364
+ reasons: [{ type: "semantic_conflict", lock: "Never modify auth" }],
365
+ blastRadius: { impactPercent: 28.3 },
366
+ summary: "BLOCKED. 1 constraint conflict. 12 files affected." }
367
+ ```
368
+
369
+ Combines semantic conflict detection + lock-to-file mapping + blast radius + typed constraint awareness into a single risk score (0-100).
370
+
371
+ ---
372
+
373
+ ## AI Patch Firewall (v5.2)
374
+
375
+ Reviews actual diffs, not just descriptions. Catches things intent review misses:
376
+
377
+ ```
378
+ POST /api/v2/gateway/review-diff
379
+ {
380
+ "description": "Remove password column",
381
+ "diff": "diff --git a/migrations/001.sql ..."
382
+ }
383
+
384
+ → { verdict: "BLOCK",
385
+ reviewMode: "unified",
386
+ intentVerdict: "ALLOW", ← description alone looks safe
387
+ diffVerdict: "BLOCK", ← diff reveals destructive schema change
388
+ signals: {
389
+ schemaChange: { score: 12, isDestructive: true },
390
+ interfaceBreak: { score: 10 },
391
+ protectedSymbolEdit: { score: 8 },
392
+ dependencyDrift: { score: 5 },
393
+ publicApiImpact: { score: 0 }
394
+ },
395
+ recommendation: { action: "require_approval" } }
312
396
  ```
313
397
 
314
- **ROS2 Guardian Node:** Real-time constraint enforcement for robots. Subscribes to sensor topics, checks constraints at configurable rate, publishes violations, triggers emergency stop.
398
+ **Signal detection:** Interface breaks (removed/changed exports), protected symbol edits in locked zones, dependency drift (critical package add/remove), schema/migration destructive changes, public API route changes.
399
+
400
+ **Hard escalation rules:** Auto-BLOCK on destructive schema changes, removed API routes, protected symbol edits, or multiple critical findings — regardless of score.
401
+
402
+ **Unified review:** Merges intent (35%) + diff (65%), takes the stronger verdict. Falls back to intent-only when no diff is available.
315
403
 
316
404
  ---
317
405
 
318
- ## REST API v2 (v5.0)
406
+ ## REST API v2
319
407
 
320
- Real-time constraint checking for autonomous systems:
408
+ Real-time constraint checking, patch review, and autonomous systems:
321
409
 
322
410
  ```bash
323
- # Single check
324
- POST /api/v2/check-typed { metric, value, entity }
411
+ # Patch Gateway (v5.1)
412
+ POST /api/v2/gateway/review { description, files, useLLM }
413
+
414
+ # AI Patch Firewall (v5.2)
415
+ POST /api/v2/gateway/review-diff { description, files, diff, options }
416
+ POST /api/v2/gateway/parse-diff { diff }
325
417
 
326
- # Batch check (up to 100)
418
+ # Typed constraint checking
419
+ POST /api/v2/check-typed { metric, value, entity }
327
420
  POST /api/v2/check-batch { checks: [...] }
328
421
 
329
422
  # SSE streaming (real-time violations)
@@ -335,11 +428,12 @@ POST /api/v2/compiler/compile { text, autoApply }
335
428
  # Code Graph
336
429
  GET /api/v2/graph/blast-radius?file=src/core/memory.js
337
430
  GET /api/v2/graph/lock-map
431
+ POST /api/v2/graph/build
338
432
  ```
339
433
 
340
434
  ---
341
435
 
342
- ## 40 MCP Tools
436
+ ## 42 MCP Tools
343
437
 
344
438
  <details>
345
439
  <summary><b>Memory</b> — goal, locks, decisions, notes, deploy facts</summary>
@@ -436,6 +530,17 @@ GET /api/v2/graph/lock-map
436
530
 
437
531
  </details>
438
532
 
533
+ <details>
534
+ <summary><b>Patch Gateway & AI Patch Firewall</b> — change review, diff analysis (v5.1/v5.2)</summary>
535
+
536
+ | Tool | What it does |
537
+ |------|-------------|
538
+ | `speclock_review_patch` | ALLOW/WARN/BLOCK verdict for proposed changes |
539
+ | `speclock_review_patch_diff` | Diff-native review with signal scoring + unified verdict |
540
+ | `speclock_parse_diff` | Parse unified diff into structured changes (debug/inspect) |
541
+
542
+ </details>
543
+
439
544
  ---
440
545
 
441
546
  ## CLI
@@ -508,7 +613,7 @@ The AI opens the file and sees:
508
613
  │ AI Tool (Claude Code, Cursor, Bolt.new...) │
509
614
  └────────────┬──────────────────┬──────────────────┘
510
615
  │ │
511
- MCP Protocol (40 tools) npm File-Based
616
+ MCP Protocol (42 tools) npm File-Based
512
617
  │ (SPECLOCK.md + CLI)
513
618
  │ │
514
619
  ┌────────────▼──────────────────▼──────────────────┐
@@ -571,7 +676,7 @@ The AI opens the file and sees:
571
676
  | Python SDK | 62 | 100% | pip install, constraint checking |
572
677
  | ROS2 Guardian | 26 | 100% | Robot safety constraint enforcement |
573
678
  | Real-World Testers | 105 | 95% | 5 developers, 30+ locks, diverse domains |
574
- | **Total** | **940** | **99.4%** | **14 suites, 15 domains** |
679
+ | **Total** | **940** | **99.4%** | **15 suites, 15 domains** |
575
680
 
576
681
  Tested across: fintech, e-commerce, IoT, healthcare, SaaS, gaming, biotech, aerospace, payments, payroll, robotics, autonomous systems. All 11 Indian payment gateways detected. Zero false positives on UI/cosmetic actions.
577
682
 
@@ -611,4 +716,4 @@ Built by **[Sandeep Roy](https://github.com/sgroy10)**
611
716
 
612
717
  ---
613
718
 
614
- <p align="center"><i>v5.0.0 — 997 tests, 99.4% pass rate, 40 MCP tools, Spec Compiler, Code Graph, Typed Constraints, Python SDK, ROS2, REST API v2. Because remembering isn't enough.</i></p>
719
+ <p align="center"><i>v5.2.0 — 1073 tests, 99.4% pass rate, 42 MCP tools, Patch Gateway, AI Patch Firewall, Spec Compiler, Code Graph, Typed Constraints, Python SDK, ROS2, REST API v2. Because remembering isn't enough.</i></p>
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  "name": "speclock",
4
4
 
5
- "version": "5.1.0",
5
+ "version": "5.2.1",
6
6
 
7
- "description": "AI Constraint Engine for autonomous systems governance. Patch Gateway (ALLOW/WARN/BLOCK change verdicts), Spec Compiler (NL→constraints), Code Graph (blast radius, lock-to-file mapping), Typed constraints (numerical, range, state, temporal), REST API v2, Python SDK, ROS2 integration. 40 MCP tools, Gemini LLM hybrid, HMAC audit chain, RBAC, encryption, SOC 2/HIPAA compliance.",
7
+ "description": "AI Constraint Engine AI Patch Firewall. Diff-native review (interface breaks, protected symbols, dependency drift, schema changes, API impact), Patch Gateway (ALLOW/WARN/BLOCK verdicts), Spec Compiler (NL→constraints), Code Graph (blast radius, lock-to-file mapping), Typed constraints, REST API v2, Python SDK, ROS2 integration. 42 MCP tools, Gemini LLM hybrid, HMAC audit chain, RBAC, encryption, SOC 2/HIPAA compliance.",
8
8
 
9
9
  "type": "module",
10
10
 
package/src/cli/index.js CHANGED
@@ -117,7 +117,7 @@ function refreshContext(root) {
117
117
 
118
118
  function printHelp() {
119
119
  console.log(`
120
- SpecLock v5.1.0 — AI Constraint Engine (Spec Compiler + Code Graph + Typed Constraints + Python SDK + ROS2 + REST API v2 + Gemini LLM + Policy-as-Code + Auth + RBAC + Encryption)
120
+ SpecLock v5.2.1 — AI Constraint Engine (Spec Compiler + Code Graph + Typed Constraints + Python SDK + ROS2 + REST API v2 + Gemini LLM + Policy-as-Code + Auth + RBAC + Encryption)
121
121
  Developed by Sandeep Roy (github.com/sgroy10)
122
122
 
123
123
  Usage: speclock <command> [options]
@@ -9,7 +9,7 @@
9
9
  import { readBrain, readEvents } from "./storage.js";
10
10
  import { verifyAuditChain } from "./audit.js";
11
11
 
12
- const VERSION = "5.1.0";
12
+ const VERSION = "5.2.1";
13
13
 
14
14
  // PHI-related keywords for HIPAA filtering
15
15
  const PHI_KEYWORDS = [