speclock 4.3.4 → 4.4.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.
@@ -144,3 +144,59 @@ AI: 🔓 Unlocked. Proceeding with auth file changes.
144
144
  1. Add to `~/.claude.json` or `.mcp.json`: `{"mcpServers":{"speclock":{"command":"npx","args":["-y","speclock","serve","--project","."]}}}`
145
145
  2. Add the instruction above to `CLAUDE.md`
146
146
  3. Done.
147
+
148
+ ---
149
+
150
+ ## For Bolt.new, Kimi, Replit, and other platforms WITHOUT MCP
151
+
152
+ These platforms don't have MCP connectors. SpecLock works via `npm install` + direct JavaScript API. The conflict checking uses a cloud proxy to get Gemini LLM coverage automatically — no API key needed.
153
+
154
+ ### Setup:
155
+ 1. Install: `npm install speclock`
156
+ 2. Paste the instructions below into the platform's Knowledge / System Prompt / Project Instructions.
157
+
158
+ ### Instructions to paste:
159
+
160
+ ```
161
+ ## SpecLock Rules (MANDATORY — follow on every message)
162
+
163
+ This project uses SpecLock for constraint protection. SpecLock is installed via npm.
164
+
165
+ ### How to check conflicts:
166
+ Before making ANY significant code change, run this check:
167
+
168
+ const { checkConflictAsync } = await import("speclock/src/core/engine.js");
169
+ const result = await checkConflictAsync("description of what you are about to do", ["lock text 1", "lock text 2"]);
170
+ if (result.hasConflict) {
171
+ // STOP — warn the user about the conflict
172
+ // result.analysis contains the details
173
+ }
174
+
175
+ ### How to check conflicts (alternative — pass lock text directly):
176
+ const { checkConflictAsync } = await import("speclock/src/core/engine.js");
177
+ const result = await checkConflictAsync("Add Razorpay payment gateway", "Never change from Stripe payment integration");
178
+ // result.hasConflict will be true
179
+
180
+ ### Rules:
181
+ 1. MAINTAIN A LIST of user constraints (locks) in memory. When the user says "never", "always", "don't touch", "lock this" — add it to your lock list.
182
+ 2. BEFORE MODIFYING CODE: Call checkConflictAsync with what you're about to do and ALL active locks. If hasConflict is true, STOP and warn the user.
183
+ 3. The function is ASYNC — always use await. It calls a cloud API for accurate detection across all domains.
184
+ 4. If the function is unavailable, at minimum do a manual check: does your proposed action violate any of the user's stated constraints?
185
+ ```
186
+
187
+ ### Example usage in code:
188
+ ```javascript
189
+ import { checkConflictAsync } from "speclock/src/core/engine.js";
190
+
191
+ // Check a single lock
192
+ const r = await checkConflictAsync("Switch to MongoDB", "Never change the database technology");
193
+ console.log(r.hasConflict); // true
194
+ console.log(r.analysis); // "1 conflict(s) confirmed..."
195
+
196
+ // Check multiple locks
197
+ const r2 = await checkConflictAsync("Add Razorpay payments", [
198
+ "Never change from Stripe",
199
+ "Never modify the payment system"
200
+ ]);
201
+ console.log(r2.hasConflict); // true
202
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speclock",
3
- "version": "4.3.4",
3
+ "version": "4.4.1",
4
4
  "description": "AI constraint engine with Gemini LLM universal detection, Policy-as-Code DSL, OAuth/OIDC SSO, admin dashboard, telemetry, API key auth, RBAC, AES-256-GCM encryption, hard enforcement, semantic pre-commit, HMAC audit chain, SOC 2/HIPAA compliance. Cross-platform: MCP + direct API. 31 MCP tools + CLI. Enterprise platform.",
5
5
  "type": "module",
6
6
  "main": "src/mcp/server.js",
package/src/cli/index.js CHANGED
@@ -116,7 +116,7 @@ function refreshContext(root) {
116
116
 
117
117
  function printHelp() {
118
118
  console.log(`
119
- SpecLock v4.3.4 — AI Constraint Engine (Gemini LLM + Policy-as-Code + SSO + Dashboard + Telemetry + Auth + RBAC + Encryption)
119
+ SpecLock v4.4.1 — AI Constraint Engine (Gemini LLM + Policy-as-Code + SSO + Dashboard + Telemetry + Auth + RBAC + Encryption)
120
120
  Developed by Sandeep Roy (github.com/sgroy10)
121
121
 
122
122
  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 = "4.3.4";
12
+ const VERSION = "4.4.1";
13
13
 
14
14
  // PHI-related keywords for HIPAA filtering
15
15
  const PHI_KEYWORDS = [
@@ -104,6 +104,10 @@ export const SYNONYM_GROUPS = [
104
104
  "ledger", "general ledger", "accounts"],
105
105
  ["trade", "trades", "executed trade", "trade record", "order",
106
106
  "position", "portfolio"],
107
+ ["salary", "salaries", "payroll", "wages", "compensation",
108
+ "remuneration", "stipend"],
109
+ ["payment gateway", "payment provider", "payment processor",
110
+ "payment service", "payment platform"],
107
111
 
108
112
  // --- IoT / firmware ---
109
113
  ["firmware", "firmware update", "ota", "over the air",
@@ -384,6 +388,36 @@ export const CONCEPT_MAP = {
384
388
  "transaction"],
385
389
  "invoice": ["billing", "payment", "charge", "transaction", "accounts receivable"],
386
390
 
391
+ // Salary / Payroll / Compensation
392
+ "salary": ["payroll", "wages", "compensation", "financial records",
393
+ "accounting", "payment"],
394
+ "payroll": ["salary", "wages", "compensation", "financial records",
395
+ "accounting", "payment"],
396
+ "wages": ["salary", "payroll", "compensation", "financial records"],
397
+ "compensation": ["salary", "payroll", "wages", "financial records"],
398
+
399
+ // Payment providers (brand names → payment gateway concept)
400
+ "razorpay": ["payment gateway", "payment processing", "payment",
401
+ "transaction", "billing"],
402
+ "phonepe": ["payment gateway", "payment processing", "payment",
403
+ "upi", "transaction"],
404
+ "ccavenue": ["payment gateway", "payment processing", "payment",
405
+ "transaction", "billing"],
406
+ "paytm": ["payment gateway", "payment processing", "payment",
407
+ "upi", "transaction"],
408
+ "paypal": ["payment gateway", "payment processing", "payment",
409
+ "transaction", "billing"],
410
+ "stripe": ["payment gateway", "payment processing", "payment",
411
+ "transaction", "billing"],
412
+ "square": ["payment gateway", "payment processing", "payment",
413
+ "transaction", "billing"],
414
+ "adyen": ["payment gateway", "payment processing", "payment",
415
+ "transaction", "billing"],
416
+ "braintree": ["payment gateway", "payment processing", "payment",
417
+ "transaction", "billing"],
418
+ "upi": ["payment gateway", "payment processing", "phonepe",
419
+ "paytm", "transaction", "payment"],
420
+
387
421
  // Logistics / Supply Chain
388
422
  "shipment": ["cargo", "freight", "consignment", "delivery", "package",
389
423
  "manifest", "tracking", "shipping"],
@@ -425,9 +459,18 @@ export const CONCEPT_MAP = {
425
459
  // E-commerce
426
460
  "cart": ["checkout", "purchase", "shopping cart"],
427
461
  "payment processing":["payment", "billing", "transaction",
428
- "stripe", "payment gateway"],
462
+ "stripe", "payment gateway", "payment provider"],
429
463
  "payment gateway": ["payment processing", "stripe", "paypal",
430
- "billing", "transaction"],
464
+ "billing", "transaction", "payment provider",
465
+ "payment processor"],
466
+ "payment provider": ["payment gateway", "payment processing", "payment",
467
+ "transaction", "billing"],
468
+ "payment processor": ["payment gateway", "payment processing", "payment",
469
+ "transaction", "billing"],
470
+ "payment service": ["payment gateway", "payment processing", "payment",
471
+ "transaction", "billing"],
472
+ "payment platform": ["payment gateway", "payment processing", "payment",
473
+ "transaction", "billing"],
431
474
  "product": ["item", "sku", "catalog", "merchandise", "product listing"],
432
475
  "price": ["pricing", "cost", "amount", "rate", "charge"],
433
476
 
@@ -761,6 +804,22 @@ export function tokenize(text) {
761
804
  words.push(w.slice(0, -1));
762
805
  }
763
806
  }
807
+
808
+ // Verb tense normalization — so "changed" matches "change",
809
+ // "processed" matches "process", "modifying" matches "modify"
810
+ for (const w of rawWords) {
811
+ if (w.endsWith("ed") && w.length > 4) {
812
+ words.push(w.slice(0, -1)); // "changed" → "change" (verb+d)
813
+ words.push(w.slice(0, -2)); // "processed" → "process" (verb+ed)
814
+ if (w.endsWith("ied") && w.length > 5) {
815
+ words.push(w.slice(0, -3) + "y"); // "modified" → "modify"
816
+ }
817
+ }
818
+ if (w.endsWith("ing") && w.length > 5) {
819
+ words.push(w.slice(0, -3)); // "processing" → "process"
820
+ words.push(w.slice(0, -3) + "e"); // "changing" → "change"
821
+ }
822
+ }
764
823
  const uniqueWords = [...new Set(words)];
765
824
 
766
825
  const all = [...new Set([...phrases, ...uniqueWords])];
@@ -979,15 +1038,38 @@ function extractProhibitedVerb(lockText) {
979
1038
  for (const pattern of patterns) {
980
1039
  const match = lower.match(pattern);
981
1040
  if (match) {
982
- const verb = match[1].trim();
1041
+ let verb = match[1].trim();
1042
+ // Handle passive voice: "must not be changed" → "changed" → stem → "change"
1043
+ if (verb.startsWith("be ")) verb = verb.slice(3);
983
1044
  // Check multi-word markers first
984
1045
  const allMarkers = [...NEGATIVE_INTENT_MARKERS, ...POSITIVE_INTENT_MARKERS]
985
1046
  .sort((a, b) => b.length - a.length);
986
1047
  for (const marker of allMarkers) {
987
1048
  if (verb.startsWith(marker)) return marker;
988
1049
  }
989
- // Return the first word
990
- return verb.split(/\s+/)[0];
1050
+ // Stem -ed/-ing verb forms: "changed" → "change", "modified" → "modify"
1051
+ const firstWord = verb.split(/\s+/)[0];
1052
+ if (firstWord.endsWith("ed") && firstWord.length > 4) {
1053
+ const stem1 = firstWord.slice(0, -1); // changed → change
1054
+ const stem2 = firstWord.slice(0, -2); // processed → process
1055
+ for (const marker of allMarkers) {
1056
+ if (stem1 === marker || stem2 === marker) return marker;
1057
+ }
1058
+ if (firstWord.endsWith("ied") && firstWord.length > 5) {
1059
+ const stem3 = firstWord.slice(0, -3) + "y"; // modified → modify
1060
+ for (const marker of allMarkers) {
1061
+ if (stem3 === marker) return marker;
1062
+ }
1063
+ }
1064
+ }
1065
+ if (firstWord.endsWith("ing") && firstWord.length > 5) {
1066
+ const stem1 = firstWord.slice(0, -3); // processing → process
1067
+ const stem2 = firstWord.slice(0, -3) + "e"; // changing → change
1068
+ for (const marker of allMarkers) {
1069
+ if (stem1 === marker || stem2 === marker) return marker;
1070
+ }
1071
+ }
1072
+ return firstWord;
991
1073
  }
992
1074
  }
993
1075
  return null;
@@ -1098,6 +1180,7 @@ const _CONTAMINATING_VERBS = new Set([
1098
1180
  "reconcile", "reverse", "recalculate", "backdate", "rebalance",
1099
1181
  "reroute", "divert", "reassign", "rebook", "cancel",
1100
1182
  "upgrade", "downgrade", "patch", "bump",
1183
+ "optimize", "streamline", "modernize", "overhaul", "revamp",
1101
1184
  ]);
1102
1185
 
1103
1186
  const _FILLER_WORDS = new Set([
@@ -1806,6 +1889,30 @@ export function scoreConflict({ actionText, lockText }) {
1806
1889
  `no scope overlap — different components despite shared vocabulary`);
1807
1890
  }
1808
1891
  }
1892
+
1893
+ // 5c: UI/cosmetic changes that share a location word with a system lock.
1894
+ // "Change the font on the login page" shares "login" with auth locks,
1895
+ // but changing a font/color/style is a visual change, not a system modification.
1896
+ // Only applies when scope overlap is WEAK (shared location word, not shared target).
1897
+ const UI_COSMETIC_WORDS = new Set([
1898
+ "font", "fonts", "color", "colors", "colour", "theme", "themes",
1899
+ "styling", "style", "styles", "css", "icon", "icons", "layout",
1900
+ "margin", "padding", "border", "background", "typography", "spacing",
1901
+ "alignment", "animation", "transition", "hover", "tooltip",
1902
+ "placeholder", "logo", "image", "banner", "hero", "avatar",
1903
+ "sidebar", "navigation", "menu", "breadcrumb", "footer",
1904
+ ]);
1905
+ if (!intentAligned && !hasStrongScopeMatch && !hasStrongVocabMatch) {
1906
+ const actionLower = actionText.toLowerCase();
1907
+ const actionWords = actionLower.split(/\s+/).map(w => w.replace(/[^a-z]/g, ""));
1908
+ const hasUISubject = actionWords.some(w => UI_COSMETIC_WORDS.has(w));
1909
+ if (hasUISubject) {
1910
+ intentAligned = true;
1911
+ reasons.push(
1912
+ `intent alignment: UI/cosmetic change — visual modification, ` +
1913
+ `not system logic change`);
1914
+ }
1915
+ }
1809
1916
  }
1810
1917
 
1811
1918
  // If intent is ALIGNED, the action is COMPLIANT — slash the score to near zero
@@ -1821,10 +1928,6 @@ export function scoreConflict({ actionText, lockText }) {
1821
1928
  // Either: scope overlap (subject extraction confirms same target)
1822
1929
  // Or: 2+ direct word overlaps (not just a single shared word)
1823
1930
  // Or: phrase overlap (multi-word match is strong signal)
1824
- // Or: concept match (domain-level relevance)
1825
- // Concept matches contribute to base score but should NOT gate the negation
1826
- // bonus — they're too indirect ("account" → "ledger" via concept map shouldn't
1827
- // trigger the +35 negation bonus). Only direct evidence counts.
1828
1931
  const hasStrongSubjectMatch = hasStrongScopeMatch ||
1829
1932
  directOverlap.length >= 2 ||
1830
1933
  phraseOverlap.length > 0;
@@ -257,7 +257,7 @@ export async function flushToRemote(root) {
257
257
  // Build anonymized payload
258
258
  const payload = {
259
259
  instanceId: summary.instanceId,
260
- version: "4.3.4",
260
+ version: "4.4.1",
261
261
  totalCalls: summary.totalCalls,
262
262
  avgResponseMs: summary.avgResponseMs,
263
263
  conflicts: summary.conflicts,
@@ -89,7 +89,7 @@
89
89
  <div class="header">
90
90
  <div>
91
91
  <h1><span>SpecLock</span> Dashboard</h1>
92
- <div class="meta">v4.3.4 &mdash; AI Constraint Engine</div>
92
+ <div class="meta">v4.4.1 &mdash; AI Constraint Engine</div>
93
93
  </div>
94
94
  <div style="display:flex;align-items:center;gap:12px;">
95
95
  <span id="health-badge" class="status-badge healthy">Loading...</span>
@@ -182,7 +182,7 @@
182
182
  </div>
183
183
 
184
184
  <div style="text-align:center;padding:24px;color:var(--muted);font-size:12px;">
185
- SpecLock v4.3.4 &mdash; Developed by Sandeep Roy &mdash; <a href="https://github.com/sgroy10/speclock" style="color:var(--accent)">GitHub</a>
185
+ SpecLock v4.4.1 &mdash; Developed by Sandeep Roy &mdash; <a href="https://github.com/sgroy10/speclock" style="color:var(--accent)">GitHub</a>
186
186
  </div>
187
187
 
188
188
  <script>
@@ -91,7 +91,7 @@ import { fileURLToPath } from "url";
91
91
  import _path from "path";
92
92
 
93
93
  const PROJECT_ROOT = process.env.SPECLOCK_PROJECT_ROOT || process.cwd();
94
- const VERSION = "4.3.4";
94
+ const VERSION = "4.4.1";
95
95
  const AUTHOR = "Sandeep Roy";
96
96
  const START_TIME = Date.now();
97
97
 
@@ -221,13 +221,8 @@ function createSpecLockServer() {
221
221
  // Tool 7: speclock_add_note
222
222
  server.tool("speclock_add_note", "Add a pinned note for reference.", { text: z.string().min(1).describe("The note text"), pinned: z.boolean().default(true).describe("Whether to pin this note") }, async ({ text, pinned }) => {
223
223
  ensureInit(PROJECT_ROOT);
224
- const brain = readBrain(PROJECT_ROOT);
225
- const note = { id: newId(), text, pinned, createdAt: nowIso() };
226
- brain.state.notes.push(note);
227
- writeBrain(PROJECT_ROOT, brain);
228
- appendEvent(PROJECT_ROOT, { type: "note_added", noteId: note.id, text });
229
- bumpEvents(PROJECT_ROOT);
230
- return { content: [{ type: "text", text: `Note added [${note.id}]: ${text}` }] };
224
+ const result = addNote(PROJECT_ROOT, text, pinned);
225
+ return { content: [{ type: "text", text: `Note added [${result.noteId}]: ${text}` }] };
231
226
  });
232
227
 
233
228
  // Tool 8: speclock_set_deploy_facts
package/src/mcp/server.js CHANGED
@@ -100,7 +100,7 @@ const PROJECT_ROOT =
100
100
  args.project || process.env.SPECLOCK_PROJECT_ROOT || process.cwd();
101
101
 
102
102
  // --- MCP Server ---
103
- const VERSION = "4.3.4";
103
+ const VERSION = "4.4.1";
104
104
  const AUTHOR = "Sandeep Roy";
105
105
 
106
106
  const server = new McpServer(